Make sprite pre-calc rotines more specific and fix x,y argument ordering in AddSprite
This commit is contained in:
parent
2af4dddb8e
commit
31ca627c14
29
src/Sprite.s
29
src/Sprite.s
|
@ -150,7 +150,7 @@ ROW_BYTES equ 384 ; VBUFF_TILE_ROW_BYTES
|
||||||
; a. If it is not marked in the DirtyTile list
|
; a. If it is not marked in the DirtyTile list
|
||||||
; * Clear its bit from the TileStore's TS_SPRITE_FLAG
|
; * Clear its bit from the TileStore's TS_SPRITE_FLAG
|
||||||
; * Add the tile to the DirtyTile list
|
; * Add the tile to the DirtyTile list
|
||||||
;t
|
;
|
||||||
; 2. If a sprite is marked as SPRITE_STATUS_REMOVED, then
|
; 2. If a sprite is marked as SPRITE_STATUS_REMOVED, then
|
||||||
; A. Clear its bit from the SpriteBits bitmap
|
; A. Clear its bit from the SpriteBits bitmap
|
||||||
; B. For each tile the sprite overlaps with:
|
; B. For each tile the sprite overlaps with:
|
||||||
|
@ -384,7 +384,7 @@ _AddSprite
|
||||||
|
|
||||||
sta _Sprites+SPRITE_ID,x ; Keep a copy of the full descriptor
|
sta _Sprites+SPRITE_ID,x ; Keep a copy of the full descriptor
|
||||||
|
|
||||||
lda #SPRITE_STATUS_ADDED
|
lda #SPRITE_STATUS_ADDED ; Used to initialize the SPRITE_STATUS
|
||||||
sta _Sprites+SPRITE_STATUS,x
|
sta _Sprites+SPRITE_STATUS,x
|
||||||
|
|
||||||
stz _Sprites+VBUFF_ADDR,x ; Clear the VBUFF address, just to initialize it
|
stz _Sprites+VBUFF_ADDR,x ; Clear the VBUFF address, just to initialize it
|
||||||
|
@ -407,8 +407,10 @@ _AddSprite
|
||||||
lda _SpriteBits,x ; Get the bit flag for this sprite slot
|
lda _SpriteBits,x ; Get the bit flag for this sprite slot
|
||||||
tsb SpriteMap ; Mark it in the sprite map bit field
|
tsb SpriteMap ; Mark it in the sprite map bit field
|
||||||
|
|
||||||
jsr _PrecalcAllSpriteInfo ; Cache sprite property values
|
jsr _PrecalcSpriteSize ; Cache sprite property values
|
||||||
jmp _InsertSprite ; Insert it into the sorted list
|
jsr _PrecalcSpriteBounds
|
||||||
|
|
||||||
|
jmp _InsertSprite ; Insert it into the sorted list
|
||||||
|
|
||||||
; _SortSprite
|
; _SortSprite
|
||||||
;
|
;
|
||||||
|
@ -905,26 +907,19 @@ _CacheSpriteBanks
|
||||||
; Precalculate some cached values for a sprite. These are *only* to make other part of code,
|
; Precalculate some cached values for a sprite. These are *only* to make other part of code,
|
||||||
; specifically the draw/erase routines more efficient.
|
; specifically the draw/erase routines more efficient.
|
||||||
;
|
;
|
||||||
; There are variations of this routine based on whether we are adding a new sprite, updating
|
|
||||||
; it's tile information, or changing its position.
|
|
||||||
;
|
|
||||||
; X = sprite index
|
; X = sprite index
|
||||||
_PrecalcAllSpriteInfo
|
_PrecalcSpriteVBuff
|
||||||
jsr _PrecalcSpriteState
|
|
||||||
jmp _PrecalcSpritePos
|
|
||||||
|
|
||||||
_PrecalcSpriteState
|
|
||||||
lda _Sprites+SPRITE_ID,x
|
lda _Sprites+SPRITE_ID,x
|
||||||
; and #$3E00
|
|
||||||
xba
|
xba
|
||||||
and #$0006
|
and #$0006
|
||||||
|
|
||||||
tay
|
tay
|
||||||
lda _Sprites+VBUFF_ADDR,x
|
lda _Sprites+VBUFF_ADDR,x
|
||||||
clc
|
clc
|
||||||
adc _stamp_step,y
|
adc _stamp_step,y
|
||||||
sta _Sprites+SPRITE_DISP,x
|
sta _Sprites+SPRITE_DISP,x
|
||||||
|
rts
|
||||||
|
|
||||||
|
_PrecalcSpriteSize
|
||||||
; Set the sprite's width and height
|
; Set the sprite's width and height
|
||||||
lda #4
|
lda #4
|
||||||
sta _Sprites+SPRITE_WIDTH,x
|
sta _Sprites+SPRITE_WIDTH,x
|
||||||
|
@ -948,7 +943,7 @@ _PrecalcSpriteState
|
||||||
|
|
||||||
; Clip the sprite's bounding box to the play field size and also set a flag if the sprite
|
; Clip the sprite's bounding box to the play field size and also set a flag if the sprite
|
||||||
; is fully off-screen or not
|
; is fully off-screen or not
|
||||||
_PrecalcSpritePos
|
_PrecalcSpriteBounds
|
||||||
lda _Sprites+SPRITE_X,x
|
lda _Sprites+SPRITE_X,x
|
||||||
bpl :pos_x
|
bpl :pos_x
|
||||||
lda #0
|
lda #0
|
||||||
|
@ -1077,7 +1072,7 @@ _UpdateSprite
|
||||||
ora #SPRITE_STATUS_UPDATED
|
ora #SPRITE_STATUS_UPDATED
|
||||||
sta _Sprites+SPRITE_STATUS,x
|
sta _Sprites+SPRITE_STATUS,x
|
||||||
|
|
||||||
jmp _PrecalcSpriteState ; Cache stuff and return
|
jmp _PrecalcSpriteVBuff ; Cache stuff and return
|
||||||
|
|
||||||
; Move a sprite to a new location. If the tile ID of the sprite needs to be changed, then
|
; Move a sprite to a new location. If the tile ID of the sprite needs to be changed, then
|
||||||
; a full remove/add cycle needs to happen
|
; a full remove/add cycle needs to happen
|
||||||
|
@ -1113,5 +1108,5 @@ _MoveSprite
|
||||||
ora #SPRITE_STATUS_MOVED
|
ora #SPRITE_STATUS_MOVED
|
||||||
sta _Sprites+SPRITE_STATUS,x
|
sta _Sprites+SPRITE_STATUS,x
|
||||||
|
|
||||||
jsr _PrecalcSpritePos ; Can be specialized to only update (x,y) values
|
jsr _PrecalcSpriteBounds ; Can be specialized to only update (x,y) values
|
||||||
jmp _SortSprite ; Update the sprite's sorted position
|
jmp _SortSprite ; Update the sprite's sorted position
|
||||||
|
|
10
src/Tool.s
10
src/Tool.s
|
@ -360,13 +360,13 @@ _TSAddSprite
|
||||||
|
|
||||||
_TSEntry
|
_TSEntry
|
||||||
|
|
||||||
lda :spriteY,s
|
|
||||||
and #$00FF
|
|
||||||
xba
|
|
||||||
sta :spriteY,s
|
|
||||||
lda :spriteX,s
|
lda :spriteX,s
|
||||||
and #$00FF
|
and #$00FF
|
||||||
ora :spriteY,s
|
xba
|
||||||
|
sta :spriteX,s
|
||||||
|
lda :spriteY,s
|
||||||
|
and #$00FF
|
||||||
|
ora :spriteX,s
|
||||||
tay
|
tay
|
||||||
|
|
||||||
lda :spriteSlot,s
|
lda :spriteSlot,s
|
||||||
|
|
Loading…
Reference in New Issue