Snippets
Created by
ScorpionIlluminati
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | ; *************************************************************
; ClearSprite
; Clears the sprite counter
; *************************************************************
ClearSprites:
move.b #0, (sprite_count) ; set sprite count to 0
rts
; *************************************************************
; AddSprite
; Adds a sprite to the sprite table and increments counter
; d0 - sprites y position
; d1 - width and height tile bits
; d2 - special (flipping, palette index, priority)
; d3 - tile id
; d4 - sprites x position
; *************************************************************
AddSprite:
clr.w d5 ; clear register d5
move.b (sprite_count), d5 ; sprint count in d5
cmp.b #79, d5 ; are there too many sprites in the table already?
bgt.s SkipAddSprite ; if not branch
clr.w d6 ; clear register d6
move.b d5, d6 ; d6 is used to calculate the sprite table offset
lsl.w #$03, d6 ; calculate sprite table offset (sprite count * sprite size)
lea (spritelist_table), a0 ; sprite table in a0
add.w d6, a0 ; increment address by offset
move.w d0, (a0)+ ; move sprites y position into table
move.b d1, (a0)+ ; move sprites demensions into table
addq.l #1, d5 ; increment d5(sprite_count) by 1
move.b d5, (a0)+ ; index of next sprite is d5(sprite_count +1)
move.b d2, (a0)+ ; save sprites special bits
move.b d3, (a0)+ ; save sprites tile id in table
move.w d4, (a0)+ ; save sprites x position in table
addq #1, (sprite_count) ; increment sprite counter by 1
SkipAddSprite:
rts
; *************************************************************
; Updates and draws the sprite table
; *************************************************************
UpdateSprites:
move.b (sprite_count), d0 ; load sprite counter into d0
beq.s SkipRemoveSprite ; if there are no sprites to update branch
and.l #0x000000FF, d0
mulu.w #SizeSpriteDesc, d0 ; Offset into sprite table
swap d0 ; To upper word
or.l #vdp_write_sprite_table, d0 ; Add to write address
move.l d0, vdp_control ; Set read address
lea (spritelist_table), a0 ; sprite table in a0
move.l (a0)+, vdp_data ; 8 bytes of data
move.l (a0)+, vdp_data
rts
; *************************************************************
; Removes a sprite from the sprite table
; d0 - which sprite to remove
; *************************************************************
RemoveSprite:
clr.w d1 ; clear register d1
move.b (sprite_count), d1 ; sprint count in d1
beq.s SkipRemoveSprite ; if there are no sprites to remove branch
lsl.w #$03, d0 ; calculate sprite table offset (sprite count * sprite size)
lea (spritelist_table), a0 ; sprite table in a0
add.w d0, a0 ; increment address by offset
move.w #0, (a0)+ ; move sprite offscreen
;move.l #0, (a0)+ ; copy low bits of sprite in sprite table
subq.w #02, d0 ; revert offset to sprite id
bsr.s SortSpriteTableByIndex ; sort the sprite list
subq.b #1, (sprite_count) ; increment sprite counter by 1
SkipRemoveSprite:
rts
; *************************************************************
; Sorts the sprite table by sprite id
; d0 - sprite id to start sorting from
; *************************************************************
SortSpriteTableByIndex:
clr.w d1 ; clear register d1
move.b (sprite_count), d1 ; sprint count in d1
beq.s SkipSortSpriteTableByIndex ; if there are no sprites to sort, branch
lsl.w #$03, d0 ; calculate starting sprite address in sprite table offset
; (sprite id * sprite size)
lea (spritelist_table), a0 ; sprite table in a0
add.w d0, a0 ; increment address by offset
sub.b d1, d0 ; d0 is now loop counter
lea (a0), a1 ; store copy of start address of sprite table in scratch for loop
addi.w #8, (a1) ; move pointer to next record in sprite list to "move down" an index
SortSpriteTableByIndexLoop:
move.l (a1)+, (a0)+ ; copy high bits of sprite into new cell
move.l (a1)+, (a0)+ ; copy low bits of sprite into new cell
subq.b #1, d0 ; did we sort all the sprites?
bne.s SortSpriteTableByIndexLoop ; if not branch
SkipSortSpriteTableByIndex:
rts
; *************************************************************
; Sorts the sprite table by address
; a0 - address in sprite table to start sorting from
; *************************************************************
SortSpriteTableByAddress:
clr.w d0 ; clear register d0
move.b (sprite_count), d0 ; sprint count in d0
beq.s SkipSortSpriteTableByAddress ; if there are no sprites to sort, branch
move.w (a0), (a1) ; copy address to calculate end address
lsl.w #03, d0 ; calculate starting sprite address in sprite table offset
; (sprite count * sprite size)
add.w d0, (a1) ; address of last sprite in sprite table
lea (a0), a2 ; store copy of start address in sprite table in scratch for loop
addi.w #8, (a2) ; temporary scratch for data to move
SortSpriteTableByAddressLoop:
move.l (a2)+, (a0)+ ; copy high bits of sprite into new cell
move.l (a2)+, (a0)+ ; copy low bits of sprite into new cell
cmpa a0, a1 ; did we sort all the sprites?
bne.s SortSpriteTableByAddressLoop ; if not branch
SkipSortSpriteTableByAddress:
rts
; *************************************************************
; gets the sprite's x position from sprite table
; d0 - sprite id to get x position
; *************************************************************
getSpritePosXFromSpriteTable:
lsl.w #$03, d0 ; calculate sprite table offset (sprite count * sprite size)
lea (spritelist_table), a0 ; sprite table in a0
add.w d0, a0 ; increment address by offset
addq #5, a0 ; add 5 bytes to address (y position word+2, width/height byte+1,
; special byte+1, tile+1)
move.w d0, (a0) ; store x position in d0
rts
; *************************************************************
; sets the sprite's x position from sprite table
; d0 - sprite id to set x position
; d1 - sprites new x position
; *************************************************************
SetSpritePosXFromSpriteTable:
lsl.w #$03, d0 ; calculate sprite table offset (sprite count * sprite size)
lea (spritelist_table), a0 ; sprite table in a0
add.w d0, a0 ; increment address by offset
addq #5, a0 ; add 5 bytes to address (y position word+2, width/height byte+1,
; special byte+1, tile+1)
move.w (a0), d1 ; store new x position
rts
; *************************************************************
; gets the sprite's y position from sprite table
; d0 - sprite id to get y position
; *************************************************************
getSpritePosYFromSpriteTable:
lsl.w #$03, d0 ; calculate sprite table offset (sprite count * sprite size)
lea (spritelist_table), a0 ; sprite table in a0
add.w d0, a0 ; increment address by offset
move.w d0, (a0) ; store y position in d0
rts
; *************************************************************
; sets the sprite's y position from sprite table
; d0 - sprite id to set y position
; d1 - sprites new y position
; *************************************************************
SetSpritePosYFromSpriteTable:
lsl.w #$03, d0 ; calculate sprite table offset (sprite count * sprite size)
lea (spritelist_table), a0 ; sprite table in a0
add.w d0, a0 ; increment address by offset
move.w (a0), d1 ; store new y position
rts
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.