Fix initialization bug in TileStore

This commit is contained in:
Lucas Scharenbroich 2022-06-01 13:55:04 -05:00
parent b022162036
commit a938639c1b
4 changed files with 79 additions and 44 deletions

View File

@ -39,6 +39,19 @@ ScreenY equ 2
pea #TSZelda
_GTELoadTileSet
; Set the palette
ldx #11*2
:ploop
lda palette,x
stal $E19E00,x
dex
dex
bpl :ploop
bra sprt
palette dw $0000,$08C1,$0C41,$0F93,$0777,$0FDA,$00A0,$0000,$0D20,$0FFF,$023E
sprt
; Create stamps for the sprites we are going to use
HERO_SPRITE_1 equ SPRITE_16X16+1
HERO_SLOT equ 0
@ -49,8 +62,8 @@ HERO_SLOT equ 0
; Create sprites
pea HERO_SPRITE_1 ; sprite id
pea #0 ; screen x-position (<256)
pea #0 ; screen y-position (<256)
pea #11 ; screen x-position (<256)
pea #23 ; screen y-position (<256)
pea HERO_SLOT ; sprite slot (0 - 15)
_GTEAddSprite
@ -59,44 +72,62 @@ HERO_SLOT equ 0
pea VBUFF_SPRITE_START ; and use this stamp
_GTEUpdateSprite
; Manually fill in the 41x26 tiles of the TileStore with a test pattern.
; Manually fill in the 41x26 tiles of the TileStore with a test pattern of trees
;
; Tile 65 Tile 66
; Tile 97 Tile 98
ldx #0
ldy #0
stz 0 ; X
stz 2 ; Y
:loop
phx
phy
:tloop
ldx 0
ldy 2
phx
phy
lda 0
clc
adc #64
pha
pea #65
inx
phx
phy
pea #66
iny
phx
phy
pea #98
dex
phx
phy
pea #97
_GTESetTile
_GTESetTile
_GTESetTile
_GTESetTile
lda 0
inc
and #$001F
inc
sta 0
cmp #40
bcc :tloop
ply
plx
inx
cpx #41
bcc :loop
stz 0
lda 2
inc
inc
sta 2
cmp #25
bcc :tloop
ldx #0
iny
cpy #26
bcc :loop
; Set the screen coordinates
; Set the origin of the screen
:skip
stz ScreenX
stz ScreenY
lda #8
sta ScreenX
sta ScreenY
; Very simple actions
:evt_loop
@ -138,6 +169,7 @@ HERO_SLOT equ 0
; _GTEUpdateSprite
_GTERender
brl :evt_loop
; Debug stuff
ldx #$100

View File

@ -174,7 +174,7 @@ _DoPhase1
bit #SPRITE_STATUS_MOVED
beq :no_move
; jsr _ClearSpriteFromTileStore
jsr _ClearSpriteFromTileStore
ldy tmpY
; Anything else (MOVED, UPDATED, ADDED) will need to have the VBUFF information updated and the

View File

@ -80,20 +80,7 @@ InitTiles
:row equ tmp1
:vbuff equ tmp2
; Fill in the TileStoreYTable. This is just a table of offsets into the Tile Store for each row. There
; are 26 rows with a stride of 41
ldy #0
lda #0
:yloop
sta TileStoreYTable,y
clc
adc #41*2
iny
iny
cpy #26*2
bcc :yloop
; Next, initialize the Tile Store itself
; Initialize the Tile Store
ldx #TILE_STORE_SIZE-2
lda #25
@ -105,7 +92,7 @@ InitTiles
:loop
; The first set of values in the Tile Store are changed during each frame based on the actions
; The first set of values in the Tile Store that are changed during each frame based on the actions
; that are happening
lda #0
@ -114,12 +101,26 @@ InitTiles
sta TileStore+TS_SPRITE_FLAG,x ; no sprites are set at the beginning
sta TileStore+TS_DIRTY,x ; none of the tiles are dirty
; Set the default tile rendering functions
lda EngineMode
bit #ENGINE_MODE_DYN_TILES+ENGINE_MODE_TWO_LAYER
beq :fast
; ldal TileProcs
; sta TileStore+TS_BASE_TILE_DISP,x
bra :out
:fast
ldal FastTileProcs
sta TileStore+TS_BASE_TILE_DISP,x
:out
; lda DirtyTileProcs ; Fill in with the first dispatch address
; stal TileStore+TS_DIRTY_TILE_DISP,x
;
; lda TileProcs ; Same for non-dirty, non-sprite base case
; stal TileStore+TS_BASE_TILE_DISP,x
; The next set of values are constants that are simply used as cached parameters to avoid needing to
; calculate any of these values during tile rendering

View File

@ -14,6 +14,8 @@ TS_CODE_ADDR_HIGH equ TILE_STORE_SIZE*5
TS_WORD_OFFSET equ TILE_STORE_SIZE*6 ; const value, word offset value for this tile if LDA (dp),y instructions re used
TS_BASE_ADDR equ TILE_STORE_SIZE*7 ; const value, because there are two rows of tiles per bank, this is set to $0000 ot $8000.
TS_SCREEN_ADDR equ TILE_STORE_SIZE*8 ; cached value of on-screen location of tile. Used for DirtyRender.
; TODO: Move these arrays into the K bank to support direct dispatch via jmp (abs,x)
TS_BASE_TILE_COPY equ TILE_STORE_SIZE*9 ; derived from TS_TILE_ID to optimize tile copy to support sprite rendering
TS_BASE_TILE_DISP equ TILE_STORE_SIZE*10 ; derived from TS_TILE_ID to optimize base (non-sprite) tile dispatch in the Render function
TS_DIRTY_TILE_DISP equ TILE_STORE_SIZE*11 ; derived from TS_TILE_ID to optimize dirty tile dispatch in the Render function
@ -43,9 +45,9 @@ SPRITE_STATUS equ {MAX_SPRITES*0}
SPRITE_ID equ {MAX_SPRITES*2}
SPRITE_X equ {MAX_SPRITES*4}
SPRITE_Y equ {MAX_SPRITES*6}
VBUFF_ADDR equ {MAX_SPRITES*8} ; Base address of the sprite's stamp in the data/mask banks
; These values are cached / calculated during the rendering process
VBUFF_ADDR equ {MAX_SPRITES*8} ; Base address of the sprite's stamp in the data/mask banks
TS_LOOKUP_INDEX equ {MAX_SPRITES*10} ; The index from the TileStoreLookup table that corresponds to the top-left corner of the sprite
TS_COVERAGE_SIZE equ {MAX_SPRITES*12} ; Representation of how many TileStore tiles (NxM) are covered by this sprite
OLD_TS_LOOKUP_INDEX equ {MAX_SPRITES*14} ; Copy of the values to support diffing