From 3c41e97b0fe717d07e5f925ab0a518d7f5a5bca4 Mon Sep 17 00:00:00 2001 From: Lucas Scharenbroich Date: Wed, 8 Jun 2022 17:34:23 -0500 Subject: [PATCH] Move dispatch table into K bank and save 9 cycles per tile in dispatch --- src/Core.s | 1 - src/Tiles.s | 11 ++++++++--- src/tiles/FastRenderer.s | 17 ++++++----------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Core.s b/src/Core.s index 619f4ac..f102699 100644 --- a/src/Core.s +++ b/src/Core.s @@ -46,7 +46,6 @@ ToolStartUp rts MasterId ds 2 -;UserId ds 2 ; Fatal error handler invoked by the _Err macro PgmDeath tax diff --git a/src/Tiles.s b/src/Tiles.s index d423e49..8a24c61 100644 --- a/src/Tiles.s +++ b/src/Tiles.s @@ -111,7 +111,7 @@ InitTiles bra :out :fast ldal FastTileProcs - sta TileStore+TS_BASE_TILE_DISP,x + stal K_TS_BASE_TILE_DISP,x :out ; lda DirtyTileProcs ; Fill in with the first dispatch address @@ -213,7 +213,9 @@ _SetTile :fast ldal FastTileProcs,x - sta TileStore+TS_BASE_TILE_DISP,y + tyx + stal K_TS_BASE_TILE_DISP,x + :out jmp _PushDirtyTileY ; on the next call to _ApplyTiles @@ -412,4 +414,7 @@ b_12_3 stpbit 12;3;]4 b_13_3 stpbit 13;3;]4 b_14_3 stpbit 14;3;]4 b_15_3 endbit 15;3;]4 - <<< \ No newline at end of file + <<< + +; Store some tables in the K bank that will be used exclusively for jmp (abs,x) dispatch +K_TS_BASE_TILE_DISP ds TILE_STORE_SIZE \ No newline at end of file diff --git a/src/tiles/FastRenderer.s b/src/tiles/FastRenderer.s index 00b46af..4363625 100644 --- a/src/tiles/FastRenderer.s +++ b/src/tiles/FastRenderer.s @@ -13,25 +13,20 @@ 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_BASE_TILE_DISP,x ; go to the tile copy routine (just basics) - stal nsf_patch+1 +; lda TileStore+TS_BASE_TILE_DISP,x ; go to the tile copy routine (just basics) +; stal nsf_patch+1 lda TileStore+TS_TILE_ADDR,x ; load the address of this tile's data (pre-calculated) plb ; set the code field bank -nsf_patch jmp $0000 + jmp (K_TS_BASE_TILE_DISP,x) + +;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. FastTileProcs dw _TBCopyDataFast,_TBCopyDataFast,_TBCopyDataFast,_TBCopyDataFast + ; dw _TBCopyDataFast,_TBCopyDataFast,_TBCopyDataVFast,_TBCopyDataVFast -; NOTE: Inlining the dispatch would eliminate a JSR,RTS,LDX, and JMP (abs,x) because the exit code -; could jump directly to the target address. Net savings of 20 cycles per tile. For a 16x16 -; sprite with a 3x3 block coverage this is 180 cycles per frame per block... This would also -; preserve a register -; -; For comparison, a fast one sprite copy takes 22 cycles per word, so this would save -; about 1/2 block of render time per tile. -; ; Need to determine if the sprite or tile data is on top, as that will decide whether the ; sprite or tile data is copied into the temporary buffer first. Also, if TWO_LAYER is set ; then the mask information must be copied as well....This is the last decision point.