Sona 0.50 Source

Sona 0.50/src-z80/stream_pause.z80

;****************************************************************************
; The code below is for pausing/unpausing BGM, but... it turned into a mess
; for no real reason, and made an assumption that shouldn't hold true (that
; SFX would not play while paused, completely forgot about games that play a
; jingle while pausing), so needs to be somewhat redone. The gist of what it
; attempts to do is there, at least.
;
; Keeping this around as an experimental feature for now.
;****************************************************************************

;****************************************************************************
; PauseSoundCmd [CMD_PAUSE]
; Pauses all sound playback.
;----------------------------------------------------------------------------
; continues in EndOfCommand
;****************************************************************************

PauseSoundCmd:
    call    GetChanOwnedByBgm           ; Get list of channels owned by BGM
    
    ld      a, l                        ; Mute FM channels owned by BGM
    and     $77                         ;
    ld      e, a                        ; BUG?: this causes the channels to
    call    StopFmByMask                ; mute which will break long notes
                                        ; that don't get keyed off and are,
                                        ; expected to remain playing across
                                        ; long stretches of the track, we'll
                                        ; need to readjust this code to deal
                                        ; with this possibility
    
    ; to-do: mute BGM owned channels
    
    ld      a, Z80OP_XOR_A              ; Replace the instruction that checks
    ld      (BgmTickCheck), a           ; if BGM ticked with one that will
                                        ; cause the flags to be set "wrong"
                                        ; (i.e. comparison always fails)
                                        ; Picked whatever would need the
                                        ; least amount of changes to the
                                        ; code to make it work.
    
    jp      EndOfCommand                ; Pop command off the queue

;****************************************************************************
; UnpauseSoundCmd [CMD_UNPAUSE]
; Resumes playback after it had been paused.
;----------------------------------------------------------------------------
; continues in EndOfCommand
;****************************************************************************

UnpauseSoundCmd:
    call    GetChanOwnedByBgm           ; Get list of channels owned by BGM
    
    ld      a, l                        ; Tell BGM loop to restore every FM
    and     $77                         ; channel owned by BGM on the next
    ld      b, a                        ; tick (which should undo any changes
    ld      a, (FmChanToReload)         ; we've done while pausing)
    or      b                           ;
    ld      (FmChanToReload), a         ; BUG?: this causes the channels to
                                        ; mute on "restore" which will break
                                        ; long notes that didn't get keyed
                                        ; off, we'll need to readjust the
                                        ; loading instrument code to reflect
                                        ; this possibility
    
    ; to-do: restore PSG if needed
    ; to-do: restore PCM if needed
    
    ld      a, Z80OP_OR_A               ; Restore the BGM check
    ld      (BgmTickCheck), a
    
    xor     a                           ; Reset BGM tick counter to prevent
    ld      (BgmTicksHi), a             ; any accumulated ticks from being
                                        ; processed all at once (we only
                                        ; touch the integer part but it
                                        ; doesn't matter much)
    
    jp      EndOfCommand                ; Pop command off the queue