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 | I think i can make this better...
***********************************************************************************************************************************************************************************************************
*Before*
***********************************************************************************************************************************************************************************************************
; *************************************************************
; Removes a sprite from the sprite table
; d0 - which sprite to remove
; *************************************************************
RemoveSprite:
clr.w d1 ; clear register d0
move.b (sprite_count), d1 ; sprint count in d0
cmp.b #0, d1 ; are there any sprites in the table?
beq.s SkipRemoveSprite ; if not 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 sprites y position into table
move.b #0, (a0)+ ; move sprites demensions into table
move.b #0, (a0)+ ; index of next sprite is d5(sprite_count +1)
move.b #0, (a0)+ ; save sprites special bits
move.b #0, (a0)+ ; save sprites tile id in table
move.w #0, (a0)+ ; save sprites x position in table
subq #8, a0 ; go back to start of deleted sprite data for sorting subroutine
; to start sorting the index from the correct position
subq #1, (sprite_count) ; increment sprite counter by 1
bsr.s SortSpriteTableByAddress ; sort the sprite list
SkipRemoveSprite:
rts
; *************************************************************
; Sorts the sprite table by sprite id
; d0 - sprite id to start sorting from
; *************************************************************
SortSpriteTableByIndex:
clr.w d1 ; clear register d0
move.b (sprite_count), d1 ; sprint count in d0
cmp.b #0, d1 ; are there any sprites in the table?
beq.s SkipSortSpriteTableByIndex ; if not 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
move.w (a0), (a1) ; copy address to calculate end address
lsl.w #03, d1 ; calculate sprite table offset by current sprite in sprite list
add.w d1, (a1) ; last sprite in sprite table
lea (a0), a2 ; store copy of start address of sprite table in scratch for loop
addi.w #8, (a2) ; temporary scratch for data to move
SortSpriteTableByIndexLoop:
move.w (a2)+, (a0)+ ; save sprites y position into new cell
move.b (a2)+, (a0)+ ; save sprites demensions into new cell in table
move.b (a2)+, (a0)+ ; index of next sprite
move.b (a2)+, (a0)+ ; save sprites special bits
move.b (a2)+, (a0)+ ; save sprites tile id in table
move.w (a2)+, (a0)+ ; save sprites x position in table
cmpa a0, a1 ; 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 d1 ; clear register d0
move.b (sprite_count), d1 ; sprint count in d0
cmp.b #0, d1 ; are there any sprites in the table?
beq.s SkipSortSpriteTableByAddress ; if not branch
move.w (a0), (a1) ; copy address to calculate end address
lsl.w #03, d1 ; calculate starting sprite address in sprite table offset
; (sprite count * sprite size)
add.w d1, (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.w (a2)+, (a0)+ ; save sprites y position into new cell
move.b (a2)+, (a0)+ ; save sprites demensions into new cell in table
move.b (a2)+, (a0)+ ; index of next sprite
move.b (a2)+, (a0)+ ; save sprites special bits
move.b (a2)+, (a0)+ ; save sprites tile id in table
move.w (a2)+, (a0)+ ; save sprites x position in table
cmpa a0, a1 ; did we sort all the sprites?
bne.s SortSpriteTableByAddressLoop ; if not branch
SkipSortSpriteTableByAddress:
rts
***********************************************************************************************************************************************************************************************************
*After*
***********************************************************************************************************************************************************************************************************
; *************************************************************
; Removes a sprite from the sprite table
; d0 - which sprite to remove
; *************************************************************
RemoveSprite:
clr.w d1 ; clear register d0
move.b (sprite_count), d1 ; sprint count in d0
; cmp.b #0, d1 ; are there any sprites in the table?
beq.s SkipRemoveSprite ; if not 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.l #0, (a0)+ ; copy high bits of sprite in sprites table
move.l #0, (a0)+ ; copy low bits of sprite in sprite table
lsr.w #$03, 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 d0
move.b (sprite_count), d1 ; sprint count in d0
; cmp.b #0, d1 ; are there any sprites in the table?
beq.s SkipSortSpriteTableByIndex ; if not 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 d1 ; clear register d0
move.b (sprite_count), d1 ; sprint count in d0
; cmp.b #0, d1 ; are there any sprites in the table?
beq.s SkipSortSpriteTableByAddress ; if not branch
move.w (a0), (a1) ; copy address to calculate end address
lsl.w #03, d1 ; calculate starting sprite address in sprite table offset
; (sprite count * sprite size)
add.w d1, (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
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.