Fix several bugs; biggest one in the SpriteStamp routine

This commit is contained in:
Lucas Scharenbroich 2022-05-31 22:53:33 -05:00
parent 98adfe5daa
commit dec50bc6fc
9 changed files with 51 additions and 59 deletions

View File

@ -43,14 +43,14 @@ ScreenY equ 2
HERO_SPRITE_1 equ SPRITE_16X16+1
HERO_SLOT equ 0
pea HERO_SPRITE_1 ; sprinte id
pea HERO_SPRITE_1 ; sprint id
pea VBUFF_SPRITE_START ; vbuff address
_GTECreateSpriteStamp
; Create sprites
pea HERO_SPRITE_1 ; sprite id
pea #10 ; screen x-position (<256)
pea #8 ; screen y-position (<256)
pea #0 ; screen x-position (<256)
pea #0 ; screen y-position (<256)
pea HERO_SLOT ; sprite slot (0 - 15)
_GTEAddSprite
@ -70,7 +70,10 @@ HERO_SLOT equ 0
phx
phy
pei 0
lda 0
clc
adc #64
pha
_GTESetTile
lda 0
@ -90,10 +93,10 @@ HERO_SLOT equ 0
bcc :loop
; Set the origin of the screen
:skip
stz ScreenX
lda #63
sta ScreenY
stz ScreenY
; Very simple actions
:evt_loop
@ -128,6 +131,12 @@ HERO_SLOT equ 0
pei ScreenY
_GTESetBG0Origin
; Update the sprite each frame for testing
; pea HERO_SLOT
; pea $0000
; pea VBUFF_SPRITE_START
; _GTEUpdateSprite
_GTERender
; Debug stuff

View File

@ -143,7 +143,6 @@ _DoPhase1
bit #SPRITE_STATUS_REMOVED
beq :no_clear
brk $02
lda _SpriteBits,y ; Clear from the sprite bitmap
sta SpriteRemovedFlag ; Stick a non-zero value here
@ -315,7 +314,7 @@ _AddSprite
; 3. Checks if the tile is dirty and marks it
; 4. If the tile was dirty, save the tile store address to be added to the DirtyTiles list later
TSClearSprite mac
ldy TileStoreLookup+]1,x
ldy TileStoreLookup+{]1},x
lda TileStore+TS_SPRITE_FLAG,y
and tmp0

View File

@ -5,16 +5,16 @@
;Top equ tmp3
;Bottom equ tmp4
Origin equ tmp4
TileTop equ tmp5
;Origin equ tmp4
;TileTop equ tmp5
RowTop equ tmp6
AreaIndex equ tmp7
TileLeft equ tmp8
ColLeft equ tmp9
;TileLeft equ tmp8
;ColLeft equ tmp9
SpriteBit equ tmp10 ; set the bit of the value that if the current sprite index
VBuffOrigin equ tmp11
; VBuffOrigin equ tmp11
; Marks a sprite as dirty. The work here is mapping from local screen coordinates to the
; tile store indices. The first step is to adjust the sprite coordinates based on the current
@ -122,6 +122,7 @@ _CalcDirtySprite
txa
and #$0003
tax
clc
adc tmp0 ; add to the vertical offset
; Subtract this value from the SPRITE_DISP address
@ -136,6 +137,7 @@ _CalcDirtySprite
; location of the upper-left corner of the sprite within the corner tile.
txa
clc
adc _Sprites+SPRITE_CLIP_WIDTH,y ; max width = 8 = 0x08
dec
and #$000C
@ -184,7 +186,7 @@ _MarkDirtySpriteTiles
; The second macro is the same as the first, but the VBUFF calculation is moved up so that the value
; from the previous step can be reused and save a load every other step.
TSSetSprite mac
ldy TileStoreLookup+]1,x
ldy TileStoreLookup+{]1},x
lda SpriteBit
ora TileStore+TS_SPRITE_FLAG,y

View File

@ -4,44 +4,24 @@
; Y = VBUFF address
; X = Tile Data address
; A = Sprite Flags
DISP_VFLIP equ $0004 ; hard code these because they are internal values
DISP_HFLIP equ $0002
DISP_MASK equ $0018 ; Preserve the size bits
_DrawSpriteStamp
sty tmp1
stx tmp2
xba
and #DISP_MASK ; dispatch to all of the different orientations
sta tmp3
jmp _DSSCommon
; Function to render a sprite from a sprite definition into the internal data buffers
;
; X = sprite index
; _DrawSpriteSheet
DISP_VFLIP equ $0004 ; hard code these because they are internal values
DISP_HFLIP equ $0002
DISP_MASK equ $0018 ; Isolate the size bits
; phx
;
; lda _Sprites+VBUFF_ADDR,x
; sta tmp1
;
; lda _Sprites+TILE_DATA_OFFSET,x
; sta tmp2
;
; lda _Sprites+SPRITE_DISP,x
; and #DISP_MASK ; dispatch to all of the different orientations
; sta tmp3
;
; jsr _DSSCommon
;
; plx
; rts
_DSSCommon
; Set bank
phb
pea #^tiledata ; Set the bank to the tile data
plb
; X = sprite ID
; Y = Tile Data
; A = VBUFF address
ldx tmp3
ldy tmp2
lda tmp1
@ -53,7 +33,7 @@ _DSSCommon
ldy tmp2
lda tmp1
clc
adc #4*3
adc #3*4
jsr _DrawSprite
lda tmp3
@ -62,7 +42,7 @@ _DSSCommon
ldy tmp2
lda tmp1
clc
adc #4*6
adc #6*4
jsr _DrawSprite
lda tmp3
@ -71,7 +51,7 @@ _DSSCommon
ldy tmp2
lda tmp1
clc
adc #4*9
adc #9*4
jsr _DrawSprite
; Restore bank
@ -81,7 +61,6 @@ _DSSCommon
;
; X = _Sprites array offset
_DrawSprite
; ldx _Sprites+SPRITE_DISP,y ; use bits 9, 10, 11, 12 and 13 to dispatch
jmp (draw_sprite,x)
draw_sprite dw draw_8x8,draw_8x8h,draw_8x8v,draw_8x8hv
@ -183,6 +162,9 @@ draw_16x8hv
ply
jmp _DrawTile8x8V
; X = sprite ID
; Y = Tile Data
; A = VBUFF address
draw_16x16
clc
tax

View File

@ -70,13 +70,13 @@ CopyDynSpriteWord MAC
;
; If MASK == 0, then we can do a PEA. If MASK == $FFFF, then fall back to the simple Dynamic Tile
; code.
ldal spritemask+]1,x ; load the mask value
ldal spritemask+{]1},x ; load the mask value
bne mixed ; a non-zero value may be mixed
; This is a solid word
lda #$00F4 ; PEA instruction
sta: ]2,y
ldal spritedata+]1,x ; load the sprite data
ldal spritedata+{]1},x ; load the sprite data
sta: ]2+1,y ; PEA operand
bra next
@ -95,12 +95,12 @@ mixed cmp #$FFFF ; All 1's in the mask is a fully transpare
lda #$0029 ; AND #SPRITE_MASK
sta: $0002,y
ldal spritemask+]1,x
ldal spritemask+{]1},x
sta: $0003,y
lda #$0009 ; ORA #SPRITE_DATA
sta: $0005,y
ldal spritedata+]1,x
ldal spritedata+{]1},x
sta: $0006,y
lda #$0D80 ; branch to the prologue (BRA *+15)

View File

@ -82,13 +82,13 @@ CopyDynMaskedSpriteWord MAC
; If MASK == 0, then we can do a PEA. If MASK == $FFFF, then fall back to the simple Dynamic Tile
; code and eliminate the constanct AND/ORA instructions.
ldal spritemask+]1,x ; load the mask value
ldal spritemask+{]1},x ; load the mask value
bne mixed ; a non-zero value may be mixed
; This is a solid word
lda #$00F4 ; PEA instruction
sta: ]2,y
ldal spritedata+]1,x ; load the sprite data
ldal spritedata+{]1},x ; load the sprite data
sta: ]2+1,y ; PEA operand
bra next
@ -99,7 +99,7 @@ mixed
sta: ]2,y
lda _JTBL_CACHE ; Get the offset to the exception handler for this column
ora #{]2&$F000} ; adjust for the current row offset
sta: ]2+1,y
sta: {]2}+1,y
tay ; This becomes the new address that we use to patch in
lda _OP_CACHE
@ -111,14 +111,14 @@ mixed
lda #$0029 ; AND #SPRITE_MASK
sta: $0006,y
ldal spritemask+]1,x
ldal spritemask+{]1},x
cmp #$FFFF ; All 1's in the mask is a fully transparent sprite word
beq transparent ; so we can use the Tile00011 method
sta: $0007,y
lda #$0009 ; ORA #SPRITE_DATA
sta: $0009,y
ldal spritedata+]1,x
ldal spritedata+{]1},x
sta: $000A,y
lda #$0980 ; branch to the prologue (BRA *+11)

View File

@ -77,7 +77,7 @@ CopyDynPriSpriteWord MAC
lda #$00A9 ; LDA #DATA
sta: $0000,y
ldal spritedata+]1,x
ldal spritedata+{]1},x
sta: $0001,y
lda _OP_CACHE

View File

@ -90,14 +90,14 @@ CopyDynPrioMaskedSpriteWord MAC
lda #$0029 ; AND #SPRITE_MASK
sta: $0002,y
ldal spritemask+]1,x
ldal spritemask+{]1},x
cmp #$FFFF ; All 1's in the mask is a fully transparent sprite word
beq transparent ; so we can use the Tile00011 method
sta: $0003,y
lda #$0009 ; ORA #SPRITE_DATA
sta: $0005,y
ldal spritedata+]1,x
ldal spritedata+{]1},x
sta: $0006,y
lda _T_PTR

View File

@ -93,7 +93,7 @@ pdtf_not_empty
cpx #16 ; If there are >= 8 elements, then
bcs full_chunk ; do a full chunk
stz DP2_DIRTY_TILE_COUNT ; Otherwise, this pass will handle them all
; stz DP2_DIRTY_TILE_COUNT ; Otherwise, this pass will handle them all
jmp (at_table,x)
at_table da at_exit,at_one,at_two,at_three
da at_four,at_five,at_six,at_seven