User Tools

Site Tools


base:dysp_cycle_table

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
base:dysp_cycle_table [2016-04-26 14:56] compyxbase:dysp_cycle_table [2016-04-26 15:23] compyx
Line 73: Line 73:
 </code> </code>
  
-So for each additional byte we branch over, we either end at BIT $24 (3 cycles) or NOP (2 cycles). +So for each additional byte we branch over, we either end at BIT $EA (3 cycles) or NOP (2 cycles). Now we can waste anywhere between 0 (no sprites) and 17 cycles (all 8 sprites). 
 + 
 + 
 +==== Calculating how many cycles we use ==== 
 + 
 +=== cycle table == 
 + 
 +To determine how many cycles we need to waste, we need to know how many cycles each combination of sprites uses. That's where the 'cycles' table comes in, it gives us the amount of cycles sprites use for each 'sprite enable'/$d015 value. I used a little tool to determine those values, using brute force: for each combination I adjusted the cycle-delay until I got the proper value. 
 + 
 +The tool is also on [[https://github.com/Compyx/dysp-timer|GitHub]], but be warned, the code is a little messy. 
 + 
 +=== sprite enable table === 
 + 
 +Now to determine which values to pick from the 'cycles' table and store in the 'timing' table, we need yet another table, which I call the 'sprite enable' table. This table is cleared each frame, and then populated using ORA for each sprite: 
 + 
 +For each sprite, at the proper Y-position, we ORA 21 values of the sprite enable table with the bit value for that particular sprite: $01 for sprite 0, $02 for sprite 1, up to $80 for sprite 7. 
 + 
 +An illustration might help: suppose we have sprite 0 at Y-offset 0, sprite 1 at Y-offset 3 and sprite 2 at Y-offset 5: 
 + 
 +<code> 
 +          Sprite ORA values  Sprite enable 
 +Y-offset  spr0   spr1  spr2  table result 
 +--------  -----  ----  ----  ------------- 
 +00          01                 01 
 +01          01                 01 
 +02          01                 01 
 +03          01    02           03 
 +04          01    02           03 
 +05          01    02    04     07 
 +06          01    02    04     07 
 +</code> 
 + 
 +Using this result, we can use the 'sprite enable' table values as an index into the cycles table to get the 
 +proper value for the 'timing' table used in the border-loop: 
 +<code 6502tasm> 
 +        ldx #0 
 +-       ldy sprite_enable,
 +        lda cycles,y 
 +        sta timing,x 
 +        inx 
 +        cpx #DYSP_HEIGHT 
 +        bne - 
 +        rts 
 +</code> 
  
  
base/dysp_cycle_table.txt · Last modified: 2016-04-26 15:47 by compyx