Jump to content
  • Advertisement
  • entries
  • comments
  • views

A C64 Game - Step 63

Sign in to follow this  


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

          ;wait for exact frame so we do not end up on the wrong
          ;side of the raster
          jsr WaitFrame
          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

The IrqInGame routine looks like this, simply call the player, acknowledge the IRQ and finish via kernal.

!zone 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.



Previous Step Next Step

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!