A technique I have been using to determine how many cycles I have "left" in my main game loop is to program a nested loop with x and y, and make it long enough that it slows down my frame rate, then decreasing it gradually until the framerate is normal again. Here is my loop with some hardcoded values:
Then the actual # of cycles this would take would be:
xLoopCycles = 2 + 2*255 + 3*254 + 2 = 1276
y loop cycles = 17 * xLoopCycles + 2 + 2*17 + 3*16 + 2
total: 21778
Does this look right? I guess there's a possibility my branches are crossing a page boundary---how would I determine if this is the case? I suppose looking at a listing of my code?
Code:
;the following loops are used to measure how much time we have left in the main loop.
ldy #17 ;2
:
ldx #$ff ;2
:
dex ;2 * 255
bne :- ;3 * 254 (taken) + 2 (not taken)
dey ;2 * 17
bne :-- ;3 * 16 (taken) + 2 (not taken)
ldy #17 ;2
:
ldx #$ff ;2
:
dex ;2 * 255
bne :- ;3 * 254 (taken) + 2 (not taken)
dey ;2 * 17
bne :-- ;3 * 16 (taken) + 2 (not taken)
Then the actual # of cycles this would take would be:
xLoopCycles = 2 + 2*255 + 3*254 + 2 = 1276
y loop cycles = 17 * xLoopCycles + 2 + 2*17 + 3*16 + 2
total: 21778
Does this look right? I guess there's a possibility my branches are crossing a page boundary---how would I determine if this is the case? I suppose looking at a listing of my code?