mvac7 / SDCC_PT3player_Lib

SDCC PT3 Player (Vortex Tracker) Library for MSX
21 stars 2 forks source link

BUG in control of playback at the end of the song. #16

Closed mvac7 closed 3 years ago

mvac7 commented 3 years ago

If it is in loop-off mode, at the end of the song playback stops but if PT3_Resume() is executed, it tries to play a wrong pattern. It should be initialized by going to the beginning of the sequence.

mvac7 commented 3 years ago

I have modified the control of the end of the sequence so that it does not generate unexpected sounds (IFSTOP) and allows to resume the playback at the beginning of the song (in _CHECKLOOP).

PL2:    
  LD   IX,#_ChanA
  LD   HL,(#_AYREGS+AR_TonA)
  CALL CHREGS
  LD   (#_AYREGS+AR_TonA),HL
  LD   A,(#_AYREGS+AR_AmplC)
  LD   (#_AYREGS+AR_AmplA),A
  LD   IX,#_ChanB
  LD   HL,(#_AYREGS+AR_TonB)
  CALL CHREGS
  LD   (#_AYREGS+AR_TonB),HL
  LD   A,(#_AYREGS+AR_AmplC)
  LD   (#_AYREGS+AR_AmplB),A
  LD   IX,#_ChanC
  LD   HL,(#_AYREGS+AR_TonC)
  CALL CHREGS
  LD   (#_AYREGS+AR_TonC),HL

  LD   HL,(#_Ns_Base)    ;Ns_Base_AddToNs
  LD   A,H
  ADD  A,L
  LD   (#_AYREGS+AR_Noise),A

  ld   A,(#_PT3_AddToEn)
  LD   E,A
  ADD  A,A
  SBC  A,A
  LD   D,A
  LD   HL,(#_EnvBase)
  ADD  HL,DE
  LD   DE,(#_CurESld)
  ADD  HL,DE
  LD  (#_AYREGS+AR_Env),HL

  XOR  A
  LD   HL,#_CurEDel
  OR   (HL)
  JR   Z,IFSTOP
  ;RET  Z

  DEC  (HL)
  ;RET  NZ
  JR   NZ,IFSTOP

  LD   A,(#_PT3_Env_Del)
  LD   (HL),A
  LD   HL,(#_PT3_ESldAdd)
  ADD  HL,DE
  LD   (#_CurESld),HL

  RET

IFSTOP:  
  LD   HL,#_PT3state
  BIT  1,(HL)   ; pause mode
  JP   Z,MUTE

  RET

;CHECKLP
CHECK_LOOP: 
  LD   HL,#_PT3state
  ;SET  7,(HL)   ;loop control
  BIT  4,(HL)   ;loop bit 
  RET  NZ

;=0 - No loop
  RES  1,(HL) ;set pause mode

;  POP  HL
;  LD   HL,#_DelyCnt
;  INC  (HL)
;  LD   HL,#_ChanA+CHNPRM_NtSkCn
;  INC  (HL)

  ret  
;  JP   MUTE