Snippets

ScorpionIlluminati Sort Subroutine In Assembly Draft #1

Created by ScorpionIlluminati last modified
; *************************************************************
; Removes a sprite from the sprite table
; d0 - which sprite to remove
; *************************************************************
RemoveSprite:
    lea (spritelist_table), a0                                                 ; sprite table in a0
    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 SkipRemoveSprite                                                       ; if not branch
    lsl.w #$03, d0                                                             ; calculate sprite table offset (sprite count * sprite size)
    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 #1, (sprite_count)                                                    ; increment sprite counter by 1
    bsr SortSpriteTableByAddress
SkipRemoveSprite:
    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 SkipSortSpriteTableByAddress                                           ; if not branch
    move.w (a0), (a1)                                                          ; address in sprite table to start sort
    lsl.w #03, d1                                                              ; sprite table offset
    add.w d1, (a1)                                                             ; last sprite in sprite table
    lea a0, (a2)                                                               ; store copy of address in sprite table to start sort
    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 SortSpriteTableByAddressLoop                                           ; if not branch
SkipSortSpriteTableByAddress:
    rts

Comments (0)

HTTPS SSH

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