From 7af4a216a0b8e2ac26bbd8789ec33e89088bc809 Mon Sep 17 00:00:00 2001 From: Lucas Scharenbroich Date: Sun, 12 Jun 2022 05:28:12 -0500 Subject: [PATCH] Add modular dispatch for copy routines; add initial support for tile priority bit --- src/Defs.s | 3 ++ src/Sprite.s | 4 +++ src/Tiles.s | 37 ++++++++++++++++++++---- src/blitter/TileProcs.s | 19 +++++++++++-- src/blitter/Tiles00000.s | 13 +++++++++ src/tiles/FastRenderer.s | 61 ++++++++++++++++++---------------------- 6 files changed, 96 insertions(+), 41 deletions(-) diff --git a/src/Defs.s b/src/Defs.s index cf0a499..06062f7 100644 --- a/src/Defs.s +++ b/src/Defs.s @@ -150,6 +150,9 @@ _TILE_ID equ 158 ; Copy of the tile descriptor DP2_DIRTY_TILE_COUNT equ 160 ; Local copy of dirty tile count to avoid banking DP2_DIRTY_TILE_CALLBACK equ 162 +; Some pre-defined bank values +DP2_TILEDATA_AND_TILESTORE_BANKS equ 164 + SPRITE_VBUFF_PTR equ 224 ; 32 bytes of adjusted pointers to VBuffArray addresses ; End direct page values diff --git a/src/Sprite.s b/src/Sprite.s index 7a2b76c..f8eb9d6 100644 --- a/src/Sprite.s +++ b/src/Sprite.s @@ -601,6 +601,10 @@ _CacheSpriteBanks ora #^TileStore sta TileStoreBankAndTileDataBank + xba + ldx #$100 + sta DP2_TILEDATA_AND_TILESTORE_BANKS,x ; put a reversed copy in the second direct page + lda #>TileStore and #$FF00 ora #^TileStore diff --git a/src/Tiles.s b/src/Tiles.s index 8a24c61..802e236 100644 --- a/src/Tiles.s +++ b/src/Tiles.s @@ -112,6 +112,10 @@ InitTiles :fast ldal FastTileProcs stal K_TS_BASE_TILE_DISP,x + ldal FastTileCopy + stal K_TS_COPY_TILE_DATA,x + ldal FastSpriteSub + stal K_TS_SPRITE_TILE_DISP,x :out ; lda DirtyTileProcs ; Fill in with the first dispatch address @@ -189,6 +193,10 @@ _SetTile ; functionality. Sometimes it is simple, but in cases of the sprites overlapping Dynamic Tiles and other cases ; it can be more involved. + lda EngineMode + bit #ENGINE_MODE_DYN_TILES+ENGINE_MODE_TWO_LAYER + beq :fast + lda TileStore+TS_TILE_ID,y and #TILE_VFLIP_BIT+TILE_HFLIP_BIT ; get the lookup value xba @@ -199,10 +207,6 @@ _SetTile ; ldal CopyTileProcs,x ; sta TileStore+TS_DIRTY_TILE_COPY,y - lda EngineMode - bit #ENGINE_MODE_DYN_TILES+ENGINE_MODE_TWO_LAYER - beq :fast - lda TileStore+TS_TILE_ID,y ; Get the non-sprite dispatch address and #TILE_CTRL_MASK xba @@ -212,10 +216,30 @@ _SetTile bra :out :fast + tyx + lda TileStore+TS_TILE_ID,y ; First, check if the sprites are over or under + bit #TILE_PRIORITY_BIT + beq :fast_over + ldal FastSpriteSub+2 + bra :fast_under +:fast_over ldal FastSpriteSub +:fast_under stal K_TS_SPRITE_TILE_DISP,x + + lda TileStore+TS_TILE_ID,y ; Now, set the draw and copy routines based on H/V bits + and #TILE_VFLIP_BIT+TILE_HFLIP_BIT ; get the lookup value + xba + tax + phx + ldal FastTileProcs,x tyx stal K_TS_BASE_TILE_DISP,x + plx + ldal FastTileCopy,x + tyx + stal K_TS_COPY_TILE_DATA,x + :out jmp _PushDirtyTileY ; on the next call to _ApplyTiles @@ -417,4 +441,7 @@ b_15_3 endbit 15;3;]4 <<< ; 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 + +K_TS_BASE_TILE_DISP ds TILE_STORE_SIZE ; draw the tile without a sprite +K_TS_COPY_TILE_DATA ds TILE_STORE_SIZE ; copy the tile into temp storage (used when tile below sprite) +K_TS_SPRITE_TILE_DISP ds TILE_STORE_SIZE ; select the sprite routine for this tile \ No newline at end of file diff --git a/src/blitter/TileProcs.s b/src/blitter/TileProcs.s index f40b634..46cc548 100644 --- a/src/blitter/TileProcs.s +++ b/src/blitter/TileProcs.s @@ -30,15 +30,30 @@ _TBCopyTileDataAndMaskToCBuffV _CopyTileDataToDP2 ]line equ 0 lup 8 - ldal tiledata+{]line*4},x + lda tiledata+{]line*4},y sta tmp_tile_data+{]line*4} - ldal tiledata+{]line*4}+2,x + lda tiledata+{]line*4}+2,y sta tmp_tile_data+{]line*4}+2 ]line equ ]line+1 --^ rts +_CopyTileDataToDP2V +]src equ 7 +]dest equ 0 + lup 8 + lda tiledata+{]src*4},y + sta tmp_tile_data+{]dest*4} + + lda tiledata+{]src*4}+2,y + sta tmp_tile_data+{]dest*4}+2 +]src equ ]src-1 +]dest equ ]dest+1 + --^ + rts + + _TBCopyTileDataToCBuff ]line equ 0 lup 8 diff --git a/src/blitter/Tiles00000.s b/src/blitter/Tiles00000.s index 7fa74bd..0d3f6e8 100644 --- a/src/blitter/Tiles00000.s +++ b/src/blitter/Tiles00000.s @@ -67,6 +67,19 @@ _TBCopyData _TBCopyDataVFast tax +]src equ 7 +]dest equ 0 + lup 8 + ldal tiledata+{]src*4},x + sta: $0004+{]dest*$1000},y + ldal tiledata+{]src*4}+2,x + sta: $0001+{]dest*$1000},y +]src equ ]src-1 +]dest equ ]dest+1 + --^ + plb + rts + _TBCopyDataV ]src equ 7 ]dest equ 0 diff --git a/src/tiles/FastRenderer.s b/src/tiles/FastRenderer.s index 14dcd90..e6f2ce0 100644 --- a/src/tiles/FastRenderer.s +++ b/src/tiles/FastRenderer.s @@ -9,7 +9,6 @@ _RenderTileFast lda TileStore+TS_SPRITE_FLAG,x ; any sprites on this line? bne SpriteDispatch -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 @@ -19,19 +18,25 @@ NoSpriteFast ; 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 +FastTileProcs dw _TBCopyDataFast,_TBCopyDataFast,_TBCopyDataVFast,_TBCopyDataVFast +FastTileCopy dw _CopyTileDataToDP2,_CopyTileDataToDP2,_CopyTileDataToDP2V,_CopyTileDataToDP2V +FastSpriteSub dw FastSpriteOver,FastSpriteUnder ; 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. SpriteDispatch -; jmp (K_TS_SPRITE_TILE_DISP,x) + jmp (K_TS_SPRITE_TILE_DISP,x) +FastSpriteOver txy - SpriteBitsToVBuffAddrs OneSpriteFastUnder;TwoSpritesFast;ThreeSpritesFast;FourSpritesFast + SpriteBitsToVBuffAddrs OneSpriteFast;TwoSpritesFast;ThreeSpritesFast;FourSpritesFast + +FastSpriteUnder + txy + SpriteBitsToVBuffAddrs OneSpriteFastUnder;OneSpriteFastUnder;OneSpriteFastUnder;OneSpriteFastUnder + ; This handles sprite with the tile above OneSpriteFastUnder @@ -82,13 +87,18 @@ _CopySpriteDataToDP2 ; Y = tile store address OneSpriteFast sta sprite_ptr0 - ldx TileStore+TS_TILE_ADDR,y - jsr _CopyTileDataToDP2 ; preserves Y - lda TileStore+TS_CODE_ADDR_HIGH,y ; load the bank of the target code field line + tyx + ldy TileStore+TS_TILE_ADDR,x + + pei DP2_TILEDATA_AND_TILESTORE_BANKS + plb + jsr (K_TS_COPY_TILE_DATA,x) + plb + + 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 ldx sprite_ptr0 ; address of sprite vbuff info - lda TileStore+TS_CODE_ADDR_LOW,y ; load the address of the code field - tay plb ]line equ 0 @@ -145,17 +155,7 @@ TwoSpritesFast ply ; Pop off CODE_ADDR_LOW plb ; Set the CODE_ADDR_HIGH bank - -]line equ 0 - lup 8 - lda tmp_tile_data+{]line*4} - sta: $0004+{]line*$1000},y - lda tmp_tile_data+{]line*4}+2 - sta: $0001+{]line*$1000},y -]line equ ]line+1 - --^ - plb ; Reset to the bank in the top byte of CODE_ADDR_HIGH - rts + jmp _CopyDP2ToCodeField ThreeSpriteLine mac ; and [sprite_ptr2],y @@ -198,17 +198,7 @@ ThreeSpritesFast ply ; Pop off CODE_ADDR_LOW plb ; Set the CODE_ADDR_HIGH bank - -]line equ 0 - lup 8 - lda tmp_tile_data+{]line*4} - sta: $0004+{]line*$1000},y - lda tmp_tile_data+{]line*4}+2 - sta: $0001+{]line*$1000},y -]line equ ]line+1 - --^ - plb ; Reset to the bank in the top byte of CODE_ADDR_HIGH - rts + jmp _CopyDP2ToCodeField FourSpriteLine mac ; and [sprite_ptr3],y @@ -255,6 +245,9 @@ FourSpritesFast ply ; Pop off CODE_ADDR_LOW plb ; Set the CODE_ADDR_HIGH bank +; Fall through + +_CopyDP2ToCodeField ]line equ 0 lup 8 lda tmp_tile_data+{]line*4} @@ -264,4 +257,4 @@ FourSpritesFast ]line equ ]line+1 --^ plb ; Reset to the bank in the top byte of CODE_ADDR_HIGH - rts \ No newline at end of file + rts