base:moving_sprites
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:moving_sprites [2015-04-17 04:33] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Moving sprites / Sorting movement from VIC update ====== | ||
+ | by Achim | ||
+ | |||
+ | ===== x+msb ===== | ||
+ | |||
+ | Moving sprites can be annoying in terms of msb handling. To avoid the msb issue you usually use tables for moving the sprites and let a small routine update the VIC registers every frame. | ||
+ | < | ||
+ | spritey: | ||
+ | spritex: | ||
+ | spritemsb: | ||
+ | spritecolor: | ||
+ | spritepointer: | ||
+ | </ | ||
+ | Now simple 16bit additions/ | ||
+ | |||
+ | Here's a small routine to update VIC registers. Should be called by an irq. Preferably before VIC starts to draw the next frame. | ||
+ | |||
+ | < | ||
+ | ldx #$07 | ||
+ | ldy #$0e | ||
+ | |||
+ | loop: lda srpitey,x | ||
+ | sta $d001, | ||
+ | lda spritex,x | ||
+ | sta $d000, | ||
+ | lda spritemsb,x | ||
+ | cmp #$01 //no msb=carry clear / msb=carry set | ||
+ | rol $d010 // | ||
+ | |||
+ | lda spritecolor, | ||
+ | sta $d027,x | ||
+ | lda spritepointer, | ||
+ | sta $07f8, | ||
+ | |||
+ | dey | ||
+ | dey | ||
+ | dex | ||
+ | bpl loop | ||
+ | </ | ||
+ | |||
+ | ===== Oldschool: x*2 ===== | ||
+ | This allows to use 8bit calculations for moving the sprite on x axis. No need for a msb table anymore. On the downside sprites can only be moved with 2px/frame. | ||
+ | < | ||
+ | spritey: | ||
+ | spritex: | ||
+ | spritecolor: | ||
+ | spritepointer: | ||
+ | </ | ||
+ | Update VIC registers: | ||
+ | < | ||
+ | ldx #$07 | ||
+ | ldy #$0e | ||
+ | |||
+ | loop: lda srpitey,x | ||
+ | sta $d001, | ||
+ | lda spritex,x | ||
+ | asl // | ||
+ | sta $d000, | ||
+ | rol $d010 // | ||
+ | |||
+ | lda spritecolor, | ||
+ | sta $d027,x | ||
+ | lda spritepointer, | ||
+ | sta $07f8, | ||
+ | |||
+ | dey | ||
+ | dey | ||
+ | dex | ||
+ | bpl loop | ||
+ | </ | ||
base/moving_sprites.txt · Last modified: 2015-04-17 04:33 by 127.0.0.1