mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2024-09-27 20:56:59 +00:00
Add modular dispatch for copy routines; add initial support for tile priority bit
This commit is contained in:
parent
955cf4a580
commit
7af4a216a0
@ -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_COUNT equ 160 ; Local copy of dirty tile count to avoid banking
|
||||||
DP2_DIRTY_TILE_CALLBACK equ 162
|
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
|
SPRITE_VBUFF_PTR equ 224 ; 32 bytes of adjusted pointers to VBuffArray addresses
|
||||||
; End direct page values
|
; End direct page values
|
||||||
|
|
||||||
|
@ -601,6 +601,10 @@ _CacheSpriteBanks
|
|||||||
ora #^TileStore
|
ora #^TileStore
|
||||||
sta TileStoreBankAndTileDataBank
|
sta TileStoreBankAndTileDataBank
|
||||||
|
|
||||||
|
xba
|
||||||
|
ldx #$100
|
||||||
|
sta DP2_TILEDATA_AND_TILESTORE_BANKS,x ; put a reversed copy in the second direct page
|
||||||
|
|
||||||
lda #>TileStore
|
lda #>TileStore
|
||||||
and #$FF00
|
and #$FF00
|
||||||
ora #^TileStore
|
ora #^TileStore
|
||||||
|
37
src/Tiles.s
37
src/Tiles.s
@ -112,6 +112,10 @@ InitTiles
|
|||||||
:fast
|
:fast
|
||||||
ldal FastTileProcs
|
ldal FastTileProcs
|
||||||
stal K_TS_BASE_TILE_DISP,x
|
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
|
:out
|
||||||
|
|
||||||
; lda DirtyTileProcs ; Fill in with the first dispatch address
|
; 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
|
; functionality. Sometimes it is simple, but in cases of the sprites overlapping Dynamic Tiles and other cases
|
||||||
; it can be more involved.
|
; it can be more involved.
|
||||||
|
|
||||||
|
lda EngineMode
|
||||||
|
bit #ENGINE_MODE_DYN_TILES+ENGINE_MODE_TWO_LAYER
|
||||||
|
beq :fast
|
||||||
|
|
||||||
lda TileStore+TS_TILE_ID,y
|
lda TileStore+TS_TILE_ID,y
|
||||||
and #TILE_VFLIP_BIT+TILE_HFLIP_BIT ; get the lookup value
|
and #TILE_VFLIP_BIT+TILE_HFLIP_BIT ; get the lookup value
|
||||||
xba
|
xba
|
||||||
@ -199,10 +207,6 @@ _SetTile
|
|||||||
; ldal CopyTileProcs,x
|
; ldal CopyTileProcs,x
|
||||||
; sta TileStore+TS_DIRTY_TILE_COPY,y
|
; 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
|
lda TileStore+TS_TILE_ID,y ; Get the non-sprite dispatch address
|
||||||
and #TILE_CTRL_MASK
|
and #TILE_CTRL_MASK
|
||||||
xba
|
xba
|
||||||
@ -212,10 +216,30 @@ _SetTile
|
|||||||
bra :out
|
bra :out
|
||||||
|
|
||||||
:fast
|
: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
|
ldal FastTileProcs,x
|
||||||
tyx
|
tyx
|
||||||
stal K_TS_BASE_TILE_DISP,x
|
stal K_TS_BASE_TILE_DISP,x
|
||||||
|
|
||||||
|
plx
|
||||||
|
ldal FastTileCopy,x
|
||||||
|
tyx
|
||||||
|
stal K_TS_COPY_TILE_DATA,x
|
||||||
|
|
||||||
:out
|
:out
|
||||||
jmp _PushDirtyTileY ; on the next call to _ApplyTiles
|
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
|
; 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
|
|
||||||
|
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
|
@ -30,15 +30,30 @@ _TBCopyTileDataAndMaskToCBuffV
|
|||||||
_CopyTileDataToDP2
|
_CopyTileDataToDP2
|
||||||
]line equ 0
|
]line equ 0
|
||||||
lup 8
|
lup 8
|
||||||
ldal tiledata+{]line*4},x
|
lda tiledata+{]line*4},y
|
||||||
sta tmp_tile_data+{]line*4}
|
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
|
sta tmp_tile_data+{]line*4}+2
|
||||||
]line equ ]line+1
|
]line equ ]line+1
|
||||||
--^
|
--^
|
||||||
rts
|
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
|
_TBCopyTileDataToCBuff
|
||||||
]line equ 0
|
]line equ 0
|
||||||
lup 8
|
lup 8
|
||||||
|
@ -67,6 +67,19 @@ _TBCopyData
|
|||||||
|
|
||||||
_TBCopyDataVFast
|
_TBCopyDataVFast
|
||||||
tax
|
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
|
_TBCopyDataV
|
||||||
]src equ 7
|
]src equ 7
|
||||||
]dest equ 0
|
]dest equ 0
|
||||||
|
@ -9,7 +9,6 @@ _RenderTileFast
|
|||||||
lda TileStore+TS_SPRITE_FLAG,x ; any sprites on this line?
|
lda TileStore+TS_SPRITE_FLAG,x ; any sprites on this line?
|
||||||
bne SpriteDispatch
|
bne SpriteDispatch
|
||||||
|
|
||||||
NoSpriteFast
|
|
||||||
lda TileStore+TS_CODE_ADDR_HIGH,x ; load the bank of the target code field line
|
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.
|
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
|
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
|
; The TS_BASE_TILE_DISP routines will come from this table when ENGINE_MODE_TWO_LAYER and
|
||||||
; ENGINE_MODE_DYN_TILES are both off.
|
; ENGINE_MODE_DYN_TILES are both off.
|
||||||
FastTileProcs dw _TBCopyDataFast,_TBCopyDataFast,_TBCopyDataFast,_TBCopyDataFast
|
FastTileProcs dw _TBCopyDataFast,_TBCopyDataFast,_TBCopyDataVFast,_TBCopyDataVFast
|
||||||
|
FastTileCopy dw _CopyTileDataToDP2,_CopyTileDataToDP2,_CopyTileDataToDP2V,_CopyTileDataToDP2V
|
||||||
; dw _TBCopyDataFast,_TBCopyDataFast,_TBCopyDataVFast,_TBCopyDataVFast
|
FastSpriteSub dw FastSpriteOver,FastSpriteUnder
|
||||||
|
|
||||||
; Need to determine if the sprite or tile data is on top, as that will decide whether the
|
; 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
|
; 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.
|
; then the mask information must be copied as well....This is the last decision point.
|
||||||
|
|
||||||
SpriteDispatch
|
SpriteDispatch
|
||||||
; jmp (K_TS_SPRITE_TILE_DISP,x)
|
jmp (K_TS_SPRITE_TILE_DISP,x)
|
||||||
|
|
||||||
|
FastSpriteOver
|
||||||
txy
|
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
|
; This handles sprite with the tile above
|
||||||
OneSpriteFastUnder
|
OneSpriteFastUnder
|
||||||
@ -82,13 +87,18 @@ _CopySpriteDataToDP2
|
|||||||
; Y = tile store address
|
; Y = tile store address
|
||||||
OneSpriteFast
|
OneSpriteFast
|
||||||
sta sprite_ptr0
|
sta sprite_ptr0
|
||||||
ldx TileStore+TS_TILE_ADDR,y
|
tyx
|
||||||
jsr _CopyTileDataToDP2 ; preserves Y
|
ldy TileStore+TS_TILE_ADDR,x
|
||||||
lda TileStore+TS_CODE_ADDR_HIGH,y ; load the bank of the target code field line
|
|
||||||
|
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.
|
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
|
ldx sprite_ptr0 ; address of sprite vbuff info
|
||||||
lda TileStore+TS_CODE_ADDR_LOW,y ; load the address of the code field
|
|
||||||
tay
|
|
||||||
plb
|
plb
|
||||||
|
|
||||||
]line equ 0
|
]line equ 0
|
||||||
@ -145,17 +155,7 @@ TwoSpritesFast
|
|||||||
|
|
||||||
ply ; Pop off CODE_ADDR_LOW
|
ply ; Pop off CODE_ADDR_LOW
|
||||||
plb ; Set the CODE_ADDR_HIGH bank
|
plb ; Set the CODE_ADDR_HIGH bank
|
||||||
|
jmp _CopyDP2ToCodeField
|
||||||
]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
|
|
||||||
|
|
||||||
ThreeSpriteLine mac
|
ThreeSpriteLine mac
|
||||||
; and [sprite_ptr2],y
|
; and [sprite_ptr2],y
|
||||||
@ -198,17 +198,7 @@ ThreeSpritesFast
|
|||||||
|
|
||||||
ply ; Pop off CODE_ADDR_LOW
|
ply ; Pop off CODE_ADDR_LOW
|
||||||
plb ; Set the CODE_ADDR_HIGH bank
|
plb ; Set the CODE_ADDR_HIGH bank
|
||||||
|
jmp _CopyDP2ToCodeField
|
||||||
]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
|
|
||||||
|
|
||||||
FourSpriteLine mac
|
FourSpriteLine mac
|
||||||
; and [sprite_ptr3],y
|
; and [sprite_ptr3],y
|
||||||
@ -255,6 +245,9 @@ FourSpritesFast
|
|||||||
ply ; Pop off CODE_ADDR_LOW
|
ply ; Pop off CODE_ADDR_LOW
|
||||||
plb ; Set the CODE_ADDR_HIGH bank
|
plb ; Set the CODE_ADDR_HIGH bank
|
||||||
|
|
||||||
|
; Fall through
|
||||||
|
|
||||||
|
_CopyDP2ToCodeField
|
||||||
]line equ 0
|
]line equ 0
|
||||||
lup 8
|
lup 8
|
||||||
lda tmp_tile_data+{]line*4}
|
lda tmp_tile_data+{]line*4}
|
||||||
@ -264,4 +257,4 @@ FourSpritesFast
|
|||||||
]line equ ]line+1
|
]line equ ]line+1
|
||||||
--^
|
--^
|
||||||
plb ; Reset to the bank in the top byte of CODE_ADDR_HIGH
|
plb ; Reset to the bank in the top byte of CODE_ADDR_HIGH
|
||||||
rts
|
rts
|
||||||
|
Loading…
Reference in New Issue
Block a user