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:
;wait for exact frame so we do not end up on the wrong
;side of the raster
lda #$36 ; make sure that IO regs at $dxxx are visible
lda #$ff ;nr of rasterline we want our irq occur at
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
;acknowledge any pending cia timer interrupts
;this is just so we are 100% safe
The IrqInGame routine looks like this, simply call the player, acknowledge the IRQ and finish via kernal.
jsr MUSIC_PLAYER + 3
;acknowledge VIC irq
Obviously we also must remove the call to the music player in the WaitFrame routine.
Previous Step Next Step