I'm a little confused about something.
There's a routine I use to wait for VBLANK to ensure that things happen only one per frame (I have a MAIN routine loop, and the last line in that loop is 'JSR WAITVBL'. This is the WAITVBL routine:
; A ROUTINE TO WAIT TILL VBLANK
WAITVBL
BIT MSTAT ;IS VBLANK STARTED YET?
BPL WAITVBL
BIT MSTAT ;IS VBLANK STILL STARTED?
BPL WAITVBL
RTS
I took that directly from the Ms. Pac-Man source code.
I found out today that this is not the case. I have a routine that increments an animation counter (supposedly) once per frame. I made sure that no other routines call this animation routine, and it's only called directly before the 'JSR WAITVBL' in the main loop. After putting display statements in the program, I found that it was getting called up to 10 times per frame. I then put in a variable to check against a frame counter called 'RTLOCAL' that is incremented only during the bottom DLI. I add '1' to this new variable each time to ensure that the animation routine only gets processed once per frame. It then works as expected. I just don't understand how this routine can get processed more than once per frame if there is a JSR to a WAITVBL routine directly after it.
How is this possible?
Here is the main routine so far:
RPD
JSR SEEBALL
LDX #$00
JSR PLAYERMOVE
LDX #$02
JSR SHOTMOVE
INX
JSR SHOTMOVE
JSR ANIMATEROB
JSR WAITVBL
JMP RPD
'ANIMATEROB' is the routine in question.
Here is that routine, without the new check I put in:
; ANIMATEROB - ANIMATE THE CURRENT ROBOT
; INPUT: ROBOTCURR - THE ROBOT TO WORK ON
; USES: A, X, Y
ANIMATEROB
LDX ROBOTCURR
LDA ROBOTMOVE,X ;IF THE ROBOT IS MOVING, SKIP TO THE 'ROBOT MOVING' SECTION
BNE ARDIR
LDA ROBOTTYPE,X ;GET THE ROBOT TYPE (01=SKELETON, 02=EYEBALL, 03=ROBOT)
TAY
LDA OFFSETBMP,Y
CLC
ADC ROBOTANIM,X
TAY
LDA STILLBMP,Y
STA ROBOTSTMP,X
INC ROBOTANIM,X
INY
LDA STILLBMP,Y
BPL ARSRTS
LDA #$00
STA ROBOTANIM,X
ARSRTS
CPX #$00
BNE ARDIR
LDX ROBOTANIM
JSR DISPLAYHEX
RTS
ARDIR
RTS
The 'DISPLAYHEX' routine is the one I put in to display what the animation variable contains.
I appreciate the help.
Bob















