From fd07ead8ed7406c4064037ddf0060be75f0834a8 Mon Sep 17 00:00:00 2001 From: Lucas Scharenbroich Date: Wed, 18 May 2022 21:39:39 -0500 Subject: [PATCH] Get tile data to display from code field --- src/Render.s | 2 +- src/Tiles.s | 36 +++++++++++++++++------------------- src/blitter/Blitter.s | 1 - src/tiles/DirtyTileQueue.s | 19 +++++++++++++++++++ src/tiles/FastRenderer.s | 6 ++++-- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/Render.s b/src/Render.s index cb95762..d86fff1 100644 --- a/src/Render.s +++ b/src/Render.s @@ -102,7 +102,7 @@ _ApplyTilesFast lda DirtyTileCount ; Cache the dirty tile count sta DP2_DIRTY_TILE_COUNT - jsr _PopDirtyTile2 + jsr _PopDirtyTilesFast stz DirtyTileCount diff --git a/src/Tiles.s b/src/Tiles.s index 5758bb2..125150e 100644 --- a/src/Tiles.s +++ b/src/Tiles.s @@ -175,15 +175,15 @@ InitTiles _SetTile pha jsr _GetTileStoreOffset0 ; Get the address of the X,Y tile position - tax + tay pla - cmpl TileStore+TS_TILE_ID,x ; Only set to dirty if the value changed + cmp TileStore+TS_TILE_ID,y ; Only set to dirty if the value changed beq :nochange - stal TileStore+TS_TILE_ID,x ; Value is different, store it. + sta TileStore+TS_TILE_ID,y ; Value is different, store it. jsr _GetTileAddr - stal TileStore+TS_TILE_ADDR,x ; Committed to drawing this tile, so get the address of the tile in the tiledata bank for later + sta TileStore+TS_TILE_ADDR,y ; Committed to drawing this tile, so get the address of the tile in the tiledata bank for later ; Set the standard renderer procs for this tile. ; @@ -196,35 +196,33 @@ _SetTile ; functionality. Sometimes it is simple, but in cases of the sprites overlapping Dynamic Tiles and other cases ; it can be more involved. - ldal TileStore+TS_TILE_ID,x + lda TileStore+TS_TILE_ID,y and #TILE_VFLIP_BIT+TILE_HFLIP_BIT ; get the lookup value xba - tay -; lda DirtyTileProcs,y -; stal TileStore+TS_DIRTY_TILE_DISP,x + tax +; ldal DirtyTileProcs,x +; sta TileStore+TS_DIRTY_TILE_DISP,y -; lda CopyTileProcs,y -; stal TileStore+TS_DIRTY_TILE_COPY,x +; ldal CopyTileProcs,x +; sta TileStore+TS_DIRTY_TILE_COPY,y lda EngineMode bit #ENGINE_MODE_DYN_TILES+ENGINE_MODE_TWO_LAYER beq :fast - ldal TileStore+TS_TILE_ID,x ; Get the non-sprite dispatch address + lda TileStore+TS_TILE_ID,y ; Get the non-sprite dispatch address and #TILE_CTRL_MASK xba - tay -; lda TileProcs,y -; stal TileStore+TS_BASE_TILE_DISP,x + tax +; ldal TileProcs,x +; sta TileStore+TS_BASE_TILE_DISP,y bra :out :fast - lda FastTileProcs,y - stal TileStore+TS_BASE_TILE_DISP,x + ldal FastTileProcs,x + sta TileStore+TS_BASE_TILE_DISP,y :out - - txa ; Add this tile to the list of dirty tiles to refresh - jmp _PushDirtyTileX ; on the next call to _ApplyTiles + jmp _PushDirtyTileY ; on the next call to _ApplyTiles :nochange rts diff --git a/src/blitter/Blitter.s b/src/blitter/Blitter.s index d490e3c..4b149bc 100644 --- a/src/blitter/Blitter.s +++ b/src/blitter/Blitter.s @@ -74,7 +74,6 @@ _BltRange tsc ; save the stack pointer stal stk_save+1 - bra blt_return blt_entry jml $000000 ; Jump into the blitter code $XX/YY00 blt_return _R0W0 diff --git a/src/tiles/DirtyTileQueue.s b/src/tiles/DirtyTileQueue.s index 7e4fcca..df9bdb2 100644 --- a/src/tiles/DirtyTileQueue.s +++ b/src/tiles/DirtyTileQueue.s @@ -38,6 +38,24 @@ _PushDirtyTileX txa ; Make sure TileStore offset is returned in the accumulator rts +; alternate entry point if the Y-register is already set +_PushDirtyTileY + lda TileStore+TS_DIRTY,y + bne :occupied2 + + inc ; any non-zero value will work + sta TileStore+TS_DIRTY,y ; and is 1 cycle faster than loading a constant value + + tya + ldy DirtyTileCount ; 4 + sta DirtyTiles,y ; 6 + iny ; 2 + iny ; 2 + sty DirtyTileCount ; 4 = 18 + rts +:occupied2 + tya ; Make sure TileStore offset is returned in the accumulator + rts ; Remove a dirty tile from the list and return it in state ready to be rendered. It is important ; that the core rendering functions *only* use _PopDirtyTile to get a list of tiles to update, ; because this routine merges the tile IDs stored in the Tile Store with the Sprite @@ -68,6 +86,7 @@ _PopDirtyTile2 ; alternate entry point ; Bank = Tile Store ; D = Page 2 _PopDirtyTilesFast +; brk $EE ldx DP2_DIRTY_TILE_COUNT ; This is pre-multiplied by 2 bne pdtf_not_empty ; If there are no items, exit at_exit rts diff --git a/src/tiles/FastRenderer.s b/src/tiles/FastRenderer.s index b285ecc..67d2518 100644 --- a/src/tiles/FastRenderer.s +++ b/src/tiles/FastRenderer.s @@ -13,9 +13,11 @@ NoSpriteFast lda TileStore+TS_CODE_ADDR_HIGH,x ; load the bank of the target code field line pha ; and put on the stack for later. Has TileStore bank in high byte. ldy TileStore+TS_CODE_ADDR_LOW,x ; load the address of the code field - lda TileStore+TS_TILE_ADDR,x ; load the address of this tile's data (pre-calculated) + lda TileStore+TS_TILE_ADDR,x ; load the address of this tile's data (pre-calculated) + lda TileStore+TS_BASE_TILE_DISP,x ; go to the tile copy routine (just basics) + stal nsf_patch+1 plb ; set the code field bank - jmp (TileStore+TS_BASE_TILE_DISP,x) ; go to the tile copy routine (just basics) +nsf_patch jmp $0000 ; The TS_BASE_TILE_DISP routines will come from this table when ENGINE_MODE_TWO_LAYER and ; ENGINE_MODE_DYN_TILES are both off.