mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2025-01-13 19:29:52 +00:00
Fix several bugs; biggest one in the SpriteStamp routine
This commit is contained in:
parent
98adfe5daa
commit
dec50bc6fc
@ -43,14 +43,14 @@ ScreenY equ 2
|
|||||||
HERO_SPRITE_1 equ SPRITE_16X16+1
|
HERO_SPRITE_1 equ SPRITE_16X16+1
|
||||||
HERO_SLOT equ 0
|
HERO_SLOT equ 0
|
||||||
|
|
||||||
pea HERO_SPRITE_1 ; sprinte id
|
pea HERO_SPRITE_1 ; sprint id
|
||||||
pea VBUFF_SPRITE_START ; vbuff address
|
pea VBUFF_SPRITE_START ; vbuff address
|
||||||
_GTECreateSpriteStamp
|
_GTECreateSpriteStamp
|
||||||
|
|
||||||
; Create sprites
|
; Create sprites
|
||||||
pea HERO_SPRITE_1 ; sprite id
|
pea HERO_SPRITE_1 ; sprite id
|
||||||
pea #10 ; screen x-position (<256)
|
pea #0 ; screen x-position (<256)
|
||||||
pea #8 ; screen y-position (<256)
|
pea #0 ; screen y-position (<256)
|
||||||
pea HERO_SLOT ; sprite slot (0 - 15)
|
pea HERO_SLOT ; sprite slot (0 - 15)
|
||||||
_GTEAddSprite
|
_GTEAddSprite
|
||||||
|
|
||||||
@ -70,7 +70,10 @@ HERO_SLOT equ 0
|
|||||||
|
|
||||||
phx
|
phx
|
||||||
phy
|
phy
|
||||||
pei 0
|
lda 0
|
||||||
|
clc
|
||||||
|
adc #64
|
||||||
|
pha
|
||||||
_GTESetTile
|
_GTESetTile
|
||||||
|
|
||||||
lda 0
|
lda 0
|
||||||
@ -90,10 +93,10 @@ HERO_SLOT equ 0
|
|||||||
bcc :loop
|
bcc :loop
|
||||||
|
|
||||||
; Set the origin of the screen
|
; Set the origin of the screen
|
||||||
|
:skip
|
||||||
|
|
||||||
stz ScreenX
|
stz ScreenX
|
||||||
lda #63
|
stz ScreenY
|
||||||
sta ScreenY
|
|
||||||
|
|
||||||
; Very simple actions
|
; Very simple actions
|
||||||
:evt_loop
|
:evt_loop
|
||||||
@ -128,6 +131,12 @@ HERO_SLOT equ 0
|
|||||||
pei ScreenY
|
pei ScreenY
|
||||||
_GTESetBG0Origin
|
_GTESetBG0Origin
|
||||||
|
|
||||||
|
; Update the sprite each frame for testing
|
||||||
|
; pea HERO_SLOT
|
||||||
|
; pea $0000
|
||||||
|
; pea VBUFF_SPRITE_START
|
||||||
|
; _GTEUpdateSprite
|
||||||
|
|
||||||
_GTERender
|
_GTERender
|
||||||
|
|
||||||
; Debug stuff
|
; Debug stuff
|
||||||
|
@ -143,7 +143,6 @@ _DoPhase1
|
|||||||
|
|
||||||
bit #SPRITE_STATUS_REMOVED
|
bit #SPRITE_STATUS_REMOVED
|
||||||
beq :no_clear
|
beq :no_clear
|
||||||
brk $02
|
|
||||||
|
|
||||||
lda _SpriteBits,y ; Clear from the sprite bitmap
|
lda _SpriteBits,y ; Clear from the sprite bitmap
|
||||||
sta SpriteRemovedFlag ; Stick a non-zero value here
|
sta SpriteRemovedFlag ; Stick a non-zero value here
|
||||||
@ -315,7 +314,7 @@ _AddSprite
|
|||||||
; 3. Checks if the tile is dirty and marks it
|
; 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
|
; 4. If the tile was dirty, save the tile store address to be added to the DirtyTiles list later
|
||||||
TSClearSprite mac
|
TSClearSprite mac
|
||||||
ldy TileStoreLookup+]1,x
|
ldy TileStoreLookup+{]1},x
|
||||||
|
|
||||||
lda TileStore+TS_SPRITE_FLAG,y
|
lda TileStore+TS_SPRITE_FLAG,y
|
||||||
and tmp0
|
and tmp0
|
||||||
|
@ -5,16 +5,16 @@
|
|||||||
;Top equ tmp3
|
;Top equ tmp3
|
||||||
;Bottom equ tmp4
|
;Bottom equ tmp4
|
||||||
|
|
||||||
Origin equ tmp4
|
;Origin equ tmp4
|
||||||
TileTop equ tmp5
|
;TileTop equ tmp5
|
||||||
RowTop equ tmp6
|
RowTop equ tmp6
|
||||||
AreaIndex equ tmp7
|
AreaIndex equ tmp7
|
||||||
|
|
||||||
TileLeft equ tmp8
|
;TileLeft equ tmp8
|
||||||
ColLeft equ tmp9
|
;ColLeft equ tmp9
|
||||||
|
|
||||||
SpriteBit equ tmp10 ; set the bit of the value that if the current sprite index
|
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
|
; 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
|
; tile store indices. The first step is to adjust the sprite coordinates based on the current
|
||||||
@ -122,6 +122,7 @@ _CalcDirtySprite
|
|||||||
txa
|
txa
|
||||||
and #$0003
|
and #$0003
|
||||||
tax
|
tax
|
||||||
|
clc
|
||||||
adc tmp0 ; add to the vertical offset
|
adc tmp0 ; add to the vertical offset
|
||||||
|
|
||||||
; Subtract this value from the SPRITE_DISP address
|
; 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.
|
; location of the upper-left corner of the sprite within the corner tile.
|
||||||
|
|
||||||
txa
|
txa
|
||||||
|
clc
|
||||||
adc _Sprites+SPRITE_CLIP_WIDTH,y ; max width = 8 = 0x08
|
adc _Sprites+SPRITE_CLIP_WIDTH,y ; max width = 8 = 0x08
|
||||||
dec
|
dec
|
||||||
and #$000C
|
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
|
; 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.
|
; from the previous step can be reused and save a load every other step.
|
||||||
TSSetSprite mac
|
TSSetSprite mac
|
||||||
ldy TileStoreLookup+]1,x
|
ldy TileStoreLookup+{]1},x
|
||||||
|
|
||||||
lda SpriteBit
|
lda SpriteBit
|
||||||
ora TileStore+TS_SPRITE_FLAG,y
|
ora TileStore+TS_SPRITE_FLAG,y
|
||||||
|
@ -4,44 +4,24 @@
|
|||||||
; Y = VBUFF address
|
; Y = VBUFF address
|
||||||
; X = Tile Data address
|
; X = Tile Data address
|
||||||
; A = Sprite Flags
|
; 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
|
_DrawSpriteStamp
|
||||||
sty tmp1
|
sty tmp1
|
||||||
stx tmp2
|
stx tmp2
|
||||||
|
xba
|
||||||
and #DISP_MASK ; dispatch to all of the different orientations
|
and #DISP_MASK ; dispatch to all of the different orientations
|
||||||
sta tmp3
|
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
|
phb
|
||||||
pea #^tiledata ; Set the bank to the tile data
|
pea #^tiledata ; Set the bank to the tile data
|
||||||
plb
|
plb
|
||||||
|
|
||||||
|
; X = sprite ID
|
||||||
|
; Y = Tile Data
|
||||||
|
; A = VBUFF address
|
||||||
ldx tmp3
|
ldx tmp3
|
||||||
ldy tmp2
|
ldy tmp2
|
||||||
lda tmp1
|
lda tmp1
|
||||||
@ -53,7 +33,7 @@ _DSSCommon
|
|||||||
ldy tmp2
|
ldy tmp2
|
||||||
lda tmp1
|
lda tmp1
|
||||||
clc
|
clc
|
||||||
adc #4*3
|
adc #3*4
|
||||||
jsr _DrawSprite
|
jsr _DrawSprite
|
||||||
|
|
||||||
lda tmp3
|
lda tmp3
|
||||||
@ -62,7 +42,7 @@ _DSSCommon
|
|||||||
ldy tmp2
|
ldy tmp2
|
||||||
lda tmp1
|
lda tmp1
|
||||||
clc
|
clc
|
||||||
adc #4*6
|
adc #6*4
|
||||||
jsr _DrawSprite
|
jsr _DrawSprite
|
||||||
|
|
||||||
lda tmp3
|
lda tmp3
|
||||||
@ -71,7 +51,7 @@ _DSSCommon
|
|||||||
ldy tmp2
|
ldy tmp2
|
||||||
lda tmp1
|
lda tmp1
|
||||||
clc
|
clc
|
||||||
adc #4*9
|
adc #9*4
|
||||||
jsr _DrawSprite
|
jsr _DrawSprite
|
||||||
|
|
||||||
; Restore bank
|
; Restore bank
|
||||||
@ -81,7 +61,6 @@ _DSSCommon
|
|||||||
;
|
;
|
||||||
; X = _Sprites array offset
|
; X = _Sprites array offset
|
||||||
_DrawSprite
|
_DrawSprite
|
||||||
; ldx _Sprites+SPRITE_DISP,y ; use bits 9, 10, 11, 12 and 13 to dispatch
|
|
||||||
jmp (draw_sprite,x)
|
jmp (draw_sprite,x)
|
||||||
|
|
||||||
draw_sprite dw draw_8x8,draw_8x8h,draw_8x8v,draw_8x8hv
|
draw_sprite dw draw_8x8,draw_8x8h,draw_8x8v,draw_8x8hv
|
||||||
@ -183,6 +162,9 @@ draw_16x8hv
|
|||||||
ply
|
ply
|
||||||
jmp _DrawTile8x8V
|
jmp _DrawTile8x8V
|
||||||
|
|
||||||
|
; X = sprite ID
|
||||||
|
; Y = Tile Data
|
||||||
|
; A = VBUFF address
|
||||||
draw_16x16
|
draw_16x16
|
||||||
clc
|
clc
|
||||||
tax
|
tax
|
||||||
|
@ -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
|
; If MASK == 0, then we can do a PEA. If MASK == $FFFF, then fall back to the simple Dynamic Tile
|
||||||
; code.
|
; 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
|
bne mixed ; a non-zero value may be mixed
|
||||||
|
|
||||||
; This is a solid word
|
; This is a solid word
|
||||||
lda #$00F4 ; PEA instruction
|
lda #$00F4 ; PEA instruction
|
||||||
sta: ]2,y
|
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
|
sta: ]2+1,y ; PEA operand
|
||||||
bra next
|
bra next
|
||||||
|
|
||||||
@ -95,12 +95,12 @@ mixed cmp #$FFFF ; All 1's in the mask is a fully transpare
|
|||||||
|
|
||||||
lda #$0029 ; AND #SPRITE_MASK
|
lda #$0029 ; AND #SPRITE_MASK
|
||||||
sta: $0002,y
|
sta: $0002,y
|
||||||
ldal spritemask+]1,x
|
ldal spritemask+{]1},x
|
||||||
sta: $0003,y
|
sta: $0003,y
|
||||||
|
|
||||||
lda #$0009 ; ORA #SPRITE_DATA
|
lda #$0009 ; ORA #SPRITE_DATA
|
||||||
sta: $0005,y
|
sta: $0005,y
|
||||||
ldal spritedata+]1,x
|
ldal spritedata+{]1},x
|
||||||
sta: $0006,y
|
sta: $0006,y
|
||||||
|
|
||||||
lda #$0D80 ; branch to the prologue (BRA *+15)
|
lda #$0D80 ; branch to the prologue (BRA *+15)
|
||||||
|
@ -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
|
; 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.
|
; 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
|
bne mixed ; a non-zero value may be mixed
|
||||||
|
|
||||||
; This is a solid word
|
; This is a solid word
|
||||||
lda #$00F4 ; PEA instruction
|
lda #$00F4 ; PEA instruction
|
||||||
sta: ]2,y
|
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
|
sta: ]2+1,y ; PEA operand
|
||||||
bra next
|
bra next
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ mixed
|
|||||||
sta: ]2,y
|
sta: ]2,y
|
||||||
lda _JTBL_CACHE ; Get the offset to the exception handler for this column
|
lda _JTBL_CACHE ; Get the offset to the exception handler for this column
|
||||||
ora #{]2&$F000} ; adjust for the current row offset
|
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
|
tay ; This becomes the new address that we use to patch in
|
||||||
|
|
||||||
lda _OP_CACHE
|
lda _OP_CACHE
|
||||||
@ -111,14 +111,14 @@ mixed
|
|||||||
|
|
||||||
lda #$0029 ; AND #SPRITE_MASK
|
lda #$0029 ; AND #SPRITE_MASK
|
||||||
sta: $0006,y
|
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
|
cmp #$FFFF ; All 1's in the mask is a fully transparent sprite word
|
||||||
beq transparent ; so we can use the Tile00011 method
|
beq transparent ; so we can use the Tile00011 method
|
||||||
sta: $0007,y
|
sta: $0007,y
|
||||||
|
|
||||||
lda #$0009 ; ORA #SPRITE_DATA
|
lda #$0009 ; ORA #SPRITE_DATA
|
||||||
sta: $0009,y
|
sta: $0009,y
|
||||||
ldal spritedata+]1,x
|
ldal spritedata+{]1},x
|
||||||
sta: $000A,y
|
sta: $000A,y
|
||||||
|
|
||||||
lda #$0980 ; branch to the prologue (BRA *+11)
|
lda #$0980 ; branch to the prologue (BRA *+11)
|
||||||
|
@ -77,7 +77,7 @@ CopyDynPriSpriteWord MAC
|
|||||||
|
|
||||||
lda #$00A9 ; LDA #DATA
|
lda #$00A9 ; LDA #DATA
|
||||||
sta: $0000,y
|
sta: $0000,y
|
||||||
ldal spritedata+]1,x
|
ldal spritedata+{]1},x
|
||||||
sta: $0001,y
|
sta: $0001,y
|
||||||
|
|
||||||
lda _OP_CACHE
|
lda _OP_CACHE
|
||||||
|
@ -90,14 +90,14 @@ CopyDynPrioMaskedSpriteWord MAC
|
|||||||
lda #$0029 ; AND #SPRITE_MASK
|
lda #$0029 ; AND #SPRITE_MASK
|
||||||
sta: $0002,y
|
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
|
cmp #$FFFF ; All 1's in the mask is a fully transparent sprite word
|
||||||
beq transparent ; so we can use the Tile00011 method
|
beq transparent ; so we can use the Tile00011 method
|
||||||
sta: $0003,y
|
sta: $0003,y
|
||||||
|
|
||||||
lda #$0009 ; ORA #SPRITE_DATA
|
lda #$0009 ; ORA #SPRITE_DATA
|
||||||
sta: $0005,y
|
sta: $0005,y
|
||||||
ldal spritedata+]1,x
|
ldal spritedata+{]1},x
|
||||||
sta: $0006,y
|
sta: $0006,y
|
||||||
|
|
||||||
lda _T_PTR
|
lda _T_PTR
|
||||||
|
@ -93,7 +93,7 @@ pdtf_not_empty
|
|||||||
cpx #16 ; If there are >= 8 elements, then
|
cpx #16 ; If there are >= 8 elements, then
|
||||||
bcs full_chunk ; do a full chunk
|
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)
|
jmp (at_table,x)
|
||||||
at_table da at_exit,at_one,at_two,at_three
|
at_table da at_exit,at_one,at_two,at_three
|
||||||
da at_four,at_five,at_six,at_seven
|
da at_four,at_five,at_six,at_seven
|
||||||
|
Loading…
x
Reference in New Issue
Block a user