Ever noticed how the music gets stuck when the next stage is built? Especially notable if you use '1' to skip through stages.
That's amended in this step. It boils down to having a raster interrupt which calls the music player.
In the current version the music player routine was called in the game main loop routine. This is all fine and dandy as long as it happens once per frame. However building a new screen may take more time than that. And that's when the music gets out of sync.
The solution is rather easy here: Install a raster IRQ and put the music player call in there. Now it doesn't matter how long the screen buildup takes, the music routine will be called at a steady pace.
We start by replacing the call to ReleaseTitleIRQ with SetGameIRQ.
SetGameIRQ looks like the average IRQ setup routine:
!zone SetGameIRQ
SetGameIRQ
;wait for exact frame so we do not end up on the wrong
;side of the raster
jsr WaitFrame
sei
lda #$36 ; make sure that IO regs at $dxxx are visible
sta PROCESSOR_PORT
lda #$ff ;nr of rasterline we want our irq occur at
sta $d012
lda #$1b ;MSB of d011 is the MSB of the requested rasterline
sta $d011 ;as rastercounter goes from 0-312
;set irq vector to point to our routine
lda # sta $0314
lda #>IrqInGame
sta $0315
;acknowledge any pending cia timer interrupts
;this is just so we are 100% safe
lda $dc0d
lda $dd0d
cli
rts
The IrqInGame routine looks like this, simply call the player, acknowledge the IRQ and finish via kernal.
!zone IrqInGame
IrqInGame
!ifdef MUSIC_PLAYING{
;play music
jsr MUSIC_PLAYER + 3
}
;acknowledge VIC irq
lda $d019
sta $d019
JMP $ea31
Obviously we also must remove the call to the music player in the WaitFrame routine.
Done!