Moving sprites: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 14: | Line 14: | ||
SetSprX: | SetSprX: | ||
addi.w #SCB4,d0 | addi.w #SCB4,d0 | ||
move.w d0,VRAM_ADDR | move.w d0,VRAM_ADDR ; Set VRAM address to SCB4+sprite # | ||
lsl.w #7,d1 | lsl.w #7,d1 ; Put position value to the left | ||
move.w d1,VRAM_RW | move.w d1,VRAM_RW | ||
rts | rts | ||
Line 24: | Line 24: | ||
A value of $1F0 sets the sprite to Y=0, $110 sets it at 224 (right out of the visible area). | A value of $1F0 sets the sprite to Y=0, $110 sets it at 224 (right out of the visible area). | ||
Example: writing $ | Example: writing $F100 ((496-14)<<7) at VRAM address $8205, puts sprite #5 at 14 pixels from the top. | ||
Be aware that the vertical position word also holds the size and the sticky bit of the sprite. | |||
ASM routine to set the Y position of a given sprite: | ASM routine to set the Y position of a given sprite: | ||
Line 32: | Line 34: | ||
SetSprY: | SetSprY: | ||
addi.w #SCB3,d0 | addi.w #SCB3,d0 | ||
move.w d0,VRAM_ADDR | move.w d0,VRAM_ADDR ; Set VRAM address to SCB3+sprite # | ||
neg.w d1 | neg.w d1 ; Do 496-position | ||
addi.w #496,d1 | addi.w #496,d1 | ||
lsl.w #7,d1 | lsl.w #7,d1 ; Put position value to the left | ||
move.w VRAM_RW,d2 | move.w VRAM_RW,d2 ; Read VRAM | ||
andi.w #$007F,d2 ; | andi.w #$007F,d2 ; Preserve the sticky bit and size attributes | ||
or.w d1,d2 | or.w d1,d2 ; Change position value | ||
move.w d2,VRAM_RW | move.w d2,VRAM_RW | ||
rts | rts |
Revision as of 15:18, 10 November 2011
Sprites can be moved individually if they're not stuck together. If they are, the sprite block can be moved by only setting the driving sprite's position. The chained sprites will move accordingly.
Like every location in VRAM, these positions can be updated mid-frame to create scanline effects.
Horizontal position
The horizontal (X) position is set in VRAM, in SCB4. It's relative to the left screen border.
Example: writing $0010 to $8402, puts sprite #2 at 16 pixels from the left.
ASM routine to set the X position of a given sprite:
;D0: Sprite # ;D1: X position SetSprX: addi.w #SCB4,d0 move.w d0,VRAM_ADDR ; Set VRAM address to SCB4+sprite # lsl.w #7,d1 ; Put position value to the left move.w d1,VRAM_RW rts
Vertical position
The vertical (Y) position is set in VRAM, in SCB3. It's reversed (496-Y), and relative to the top screen border. A value of $1F0 sets the sprite to Y=0, $110 sets it at 224 (right out of the visible area).
Example: writing $F100 ((496-14)<<7) at VRAM address $8205, puts sprite #5 at 14 pixels from the top.
Be aware that the vertical position word also holds the size and the sticky bit of the sprite.
ASM routine to set the Y position of a given sprite:
;D0: Sprite # ;D1: Y position SetSprY: addi.w #SCB3,d0 move.w d0,VRAM_ADDR ; Set VRAM address to SCB3+sprite # neg.w d1 ; Do 496-position addi.w #496,d1 lsl.w #7,d1 ; Put position value to the left move.w VRAM_RW,d2 ; Read VRAM andi.w #$007F,d2 ; Preserve the sticky bit and size attributes or.w d1,d2 ; Change position value move.w d2,VRAM_RW rts
Example
Animates ~100 individual and grouped sprites.
Source and romset: nyanmvs.zip