base:dysp_cycle_table
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
base:dysp_cycle_table [2016-04-26 14:35] – ; compyx | base:dysp_cycle_table [2016-04-26 14:56] – compyx | ||
---|---|---|---|
Line 47: | Line 47: | ||
</ | </ | ||
+ | By altering the branch instruction to skip a variable amount of bytes of code, we can determine the number of cycles the loop must waste on a raster line. Generally speaking, the more sprites we have on a line, the more cycles the VIC eats, which means we have to branch further to skip more cycles. | ||
+ | |||
+ | The "cpx #$e0 ... bit $ea" code is used to waste cycles with an accuracy of a single cycle, I use the same trick to time VSP's (with a few more "cpx #$e0" instructions). | ||
+ | |||
+ | Here's how it works (simplified): | ||
+ | <code 6502tasm> | ||
+ | ; here we waste 2 + 2 + 3 = 7 cycles: | ||
+ | .1000 bpl $1002 | ||
+ | .1002 cpx #$e0 ; 2 | ||
+ | .1004 cpx #$e0 ; 2 | ||
+ | .1006 bit $ea ; 3 | ||
+ | |||
+ | ; adjusting the branch, we can waste 6 cycles: | ||
+ | .1000 bpl $1003 ; we branch into the argument of CPX #$e0 at $1003 | ||
+ | .1002 cpx #$e0 ; which means we execute CPX #$e0 at $1003, | ||
+ | .1004 cpx #$e0 ; then CPX #$24 at $1005 | ||
+ | .1006 bit $ea ; and finally NOP at $1007 | ||
+ | |||
+ | ; so, for the above code , the CPU executes this: | ||
+ | .1000 bpl $1003 | ||
+ | ; .1002 gets skipped | ||
+ | .1003 cpx #$e0 ; 2 | ||
+ | .1005 cpx #$24 ; 2 | ||
+ | .1007 | ||
+ | </ | ||
+ | |||
+ | So for each additional byte we branch over, we either end at BIT $24 (3 cycles) or NOP (2 cycles). | ||
base/dysp_cycle_table.txt · Last modified: 2016-04-26 15:47 by compyx