Snippets

ScorpionIlluminati Sprite List Update Revision #2

Created by ScorpionIlluminati last modified
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)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.