Snippets

ScorpionIlluminati New Spritelist Code RC 1

Created by ScorpionIlluminati
; *************************************************************
; ClearSprite
; Clears the sprite counter
; a0 address of sprite counter
; *************************************************************
ClearSprites:
    move.b #0, (a0)                                                            ; set sprite list 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
; a0 - spritelist
; a1 - spritelist counter
; *************************************************************
AddSprite:
    clr.w d5                                                                   ; clear register d5
    move.b (a0), d5                                                            ; sprint list counter 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)
    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
    move.b d5, (a0)                                                            ; store new sprite list counter
SkipAddSprite:
    rts

; *************************************************************
; Updates and draws the sprite table
; d0 - spritelist counter
; a0 - spritelist
; *************************************************************
UpdateSprites:
	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
	move.l (a0)+, vdp_data                                                     ; 8 bytes of data
	move.l (a0)+, vdp_data
    rts

Comments (0)

HTTPS SSH

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