base:dysp_d017
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
base:dysp_d017 [2016-04-22 14:14] – compyx | base:dysp_d017 [2016-04-22 15:19] – added a screenshot compyx | ||
---|---|---|---|
Line 7: | Line 7: | ||
Anyway, a DYSP can be done in many ways, the way I'm describing below is probably the easiest way, since it keeps the timing for each raster line constant by ' | Anyway, a DYSP can be done in many ways, the way I'm describing below is probably the easiest way, since it keeps the timing for each raster line constant by ' | ||
+ | {{: | ||
==== Assembling the code ==== | ==== Assembling the code ==== | ||
Line 67: | Line 68: | ||
The trick to variable Y-positioning is to stretch the first line of a sprite until we reach the Y-position where we want the sprite to display, then displaying 19 lines of the sprite (not stretching the sprite(s)), and then stretching the last line of the sprite until the loop ends. | The trick to variable Y-positioning is to stretch the first line of a sprite until we reach the Y-position where we want the sprite to display, then displaying 19 lines of the sprite (not stretching the sprite(s)), and then stretching the last line of the sprite until the loop ends. | ||
- | Suppose we would want to display three sprites, each one one pixel lower than the next. ' | + | Suppose we would want to display three sprites, each one one pixel lower than the next. ' |
< | < | ||
Sprites | Sprites | ||
--------------- | --------------- | ||
- | A00 | + | A00 |
A01 | A01 | ||
A02 | A02 | ||
Line 80: | Line 81: | ||
A20 | A20 | ||
A20 | A20 | ||
- | A20 | + | A20 |
</ | </ | ||
- | === Limitations ==== | + | ==== Generating the $d017 values ==== |
+ | |||
+ | Generating the correct $d017 value is quite simple, but takes some cycles. | ||
+ | |||
+ | * fill $d017 table with $ff (all sprites are stretched) | ||
+ | * for each SPRITE: | ||
+ | - get Y-position of SPRITE | ||
+ | - mask out bits in $d017 table, starting at Y-position, for 19 lines | ||
+ | * next SPRITE | ||
+ | |||
+ | In pseudo-code, | ||
+ | < | ||
+ | ; fill $d017 table with $ff | ||
+ | ldx #0 | ||
+ | lda #$ff | ||
+ | - sta $1000,x | ||
+ | inx | ||
+ | cpx #64 | ||
+ | bne - | ||
+ | |||
+ | ; render sprite 0 | ||
+ | ldy sprite0_y | ||
+ | ldx #0 | ||
+ | - lda $1000,x | ||
+ | and # | ||
+ | sta $1000,x | ||
+ | iny | ||
+ | inx | ||
+ | cpx #19 ; repeat 19 times | ||
+ | bne - | ||
+ | |||
+ | ; more code ... | ||
+ | |||
+ | ; render sprite 7 | ||
+ | ldy sprite7_y | ||
+ | ldx #0 | ||
+ | - lda $1000,x | ||
+ | and # | ||
+ | sta $1000,x | ||
+ | iny | ||
+ | inx | ||
+ | cpx #19 | ||
+ | bne - | ||
+ | </ | ||
+ | |||
+ | ==== Limitations ==== | ||
This of course means we can only use 19 pixels high sprites, lines 0 and 20 are cleared so we don't see the stretched sprite data. | This of course means we can only use 19 pixels high sprites, lines 0 and 20 are cleared so we don't see the stretched sprite data. | ||
Line 90: | Line 136: | ||
===== The Code ===== | ===== The Code ===== | ||
+ | |||
+ | Putting it all together, we end up with the code below. I use two sinus tables for the X-movement, giving us 344 pixels total movement (actually a little less to avoid the DMA sprite access bug in the right border) and a single sinus for the Y movement. | ||
+ | |||
+ | Again, this code is not up to (my) demo standards: change the border color to non-black and you'll see the border-opening bugs at the start of the routine. | ||
<code 6502tasm> | <code 6502tasm> |
base/dysp_d017.txt · Last modified: 2016-04-26 13:52 by compyx