mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2024-06-01 00:41:49 +00:00
Add in the special Tile 0 render routines
This commit is contained in:
parent
7af4a216a0
commit
d3da96a834
|
@ -152,6 +152,7 @@ DP2_DIRTY_TILE_CALLBACK equ 162
|
||||||
|
|
||||||
; Some pre-defined bank values
|
; Some pre-defined bank values
|
||||||
DP2_TILEDATA_AND_TILESTORE_BANKS equ 164
|
DP2_TILEDATA_AND_TILESTORE_BANKS equ 164
|
||||||
|
DP2_SPRITEDATA_AND_TILESTORE_BANKS equ 166
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -605,6 +605,13 @@ _CacheSpriteBanks
|
||||||
ldx #$100
|
ldx #$100
|
||||||
sta DP2_TILEDATA_AND_TILESTORE_BANKS,x ; put a reversed copy in the second direct page
|
sta DP2_TILEDATA_AND_TILESTORE_BANKS,x ; put a reversed copy in the second direct page
|
||||||
|
|
||||||
|
lda #>spritedata
|
||||||
|
and #$FF00
|
||||||
|
ora #^TileStore
|
||||||
|
xba
|
||||||
|
ldx #$100
|
||||||
|
sta DP2_SPRITEDATA_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
|
||||||
|
|
14
src/Tiles.s
14
src/Tiles.s
|
@ -110,9 +110,11 @@ InitTiles
|
||||||
; sta TileStore+TS_BASE_TILE_DISP,x
|
; sta TileStore+TS_BASE_TILE_DISP,x
|
||||||
bra :out
|
bra :out
|
||||||
:fast
|
:fast
|
||||||
ldal FastTileProcs
|
lda #_TBConstTile0 ; Use the special tile 0 routines
|
||||||
|
; ldal FastTileProcs
|
||||||
stal K_TS_BASE_TILE_DISP,x
|
stal K_TS_BASE_TILE_DISP,x
|
||||||
ldal FastTileCopy
|
lda #_TBConstTileDataToDP2
|
||||||
|
; ldal FastTileCopy
|
||||||
stal K_TS_COPY_TILE_DATA,x
|
stal K_TS_COPY_TILE_DATA,x
|
||||||
ldal FastSpriteSub
|
ldal FastSpriteSub
|
||||||
stal K_TS_SPRITE_TILE_DISP,x
|
stal K_TS_SPRITE_TILE_DISP,x
|
||||||
|
@ -226,6 +228,8 @@ _SetTile
|
||||||
:fast_under stal K_TS_SPRITE_TILE_DISP,x
|
: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
|
lda TileStore+TS_TILE_ID,y ; Now, set the draw and copy routines based on H/V bits
|
||||||
|
bit #TILE_ID_MASK ; unless it's the special Tile 0
|
||||||
|
beq :fast_0
|
||||||
and #TILE_VFLIP_BIT+TILE_HFLIP_BIT ; get the lookup value
|
and #TILE_VFLIP_BIT+TILE_HFLIP_BIT ; get the lookup value
|
||||||
xba
|
xba
|
||||||
tax
|
tax
|
||||||
|
@ -239,6 +243,12 @@ _SetTile
|
||||||
ldal FastTileCopy,x
|
ldal FastTileCopy,x
|
||||||
tyx
|
tyx
|
||||||
stal K_TS_COPY_TILE_DATA,x
|
stal K_TS_COPY_TILE_DATA,x
|
||||||
|
bra :out
|
||||||
|
:fast_0
|
||||||
|
lda #_TBConstTile0 ; Use the special tile 0 routines
|
||||||
|
stal K_TS_BASE_TILE_DISP,x
|
||||||
|
lda #_TBConstTileDataToDP2
|
||||||
|
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
|
||||||
|
|
|
@ -107,3 +107,38 @@ _TBCopyTileMaskToCBuffV
|
||||||
--^
|
--^
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
; Tile 0 specializations
|
||||||
|
; _TBConstTile
|
||||||
|
;
|
||||||
|
; A specialized routine that fills in a tile with a single constant value. It's intended to be used to
|
||||||
|
; fill in solid colors, so there are no specialized horizontal or verical flipped variants
|
||||||
|
_TBConstTile0 tax
|
||||||
|
lda #0
|
||||||
|
_TBConstTileX sta: $0001,y
|
||||||
|
sta: $0004,y
|
||||||
|
sta $1001,y
|
||||||
|
sta $1004,y
|
||||||
|
sta $2001,y
|
||||||
|
sta $2004,y
|
||||||
|
sta $3001,y
|
||||||
|
sta $3004,y
|
||||||
|
sta $4001,y
|
||||||
|
sta $4004,y
|
||||||
|
sta $5001,y
|
||||||
|
sta $5004,y
|
||||||
|
sta $6001,y
|
||||||
|
sta $6004,y
|
||||||
|
sta $7001,y
|
||||||
|
sta $7004,y
|
||||||
|
plb
|
||||||
|
rts
|
||||||
|
; jmp _TBFillPEAOpcode
|
||||||
|
|
||||||
|
_TBConstTileDataToDP2
|
||||||
|
]line equ 0
|
||||||
|
lup 8
|
||||||
|
stz tmp_tile_data+{]line*4}
|
||||||
|
stz tmp_tile_data+{]line*4}+2
|
||||||
|
]line equ ]line+1
|
||||||
|
--^
|
||||||
|
rts
|
||||||
|
|
|
@ -80,7 +80,7 @@ _PopDirtyTile2 ; alternate entry point
|
||||||
; for each dirty tile. This is an unrolled loop, so we avoid the need to track a register and
|
; for each dirty tile. This is an unrolled loop, so we avoid the need to track a register and
|
||||||
; decrement on each iteration.
|
; decrement on each iteration.
|
||||||
;
|
;
|
||||||
; Also, if we are handling less that 8 dirty tiles, we use a code path that does not
|
; Also, if we are handling less than 8 dirty tiles, we use a code path that does not
|
||||||
; need to use an index register
|
; need to use an index register
|
||||||
;
|
;
|
||||||
; Bank = Tile Store
|
; Bank = Tile Store
|
||||||
|
|
|
@ -7,14 +7,15 @@
|
||||||
; and then copied into the code field
|
; and then copied into the code field
|
||||||
_RenderTileFast
|
_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 :sprites
|
||||||
|
|
||||||
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
|
||||||
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)
|
||||||
plb ; set the code field bank
|
plb ; set the code field bank
|
||||||
jmp (K_TS_BASE_TILE_DISP,x) ; go to the tile copy routine (just basics)
|
jmp (K_TS_BASE_TILE_DISP,x) ; go to the tile copy routine
|
||||||
|
:sprites jmp (K_TS_SPRITE_TILE_DISP,x) ; go to the sprite+tile routine
|
||||||
|
|
||||||
; 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.
|
||||||
|
@ -22,22 +23,25 @@ FastTileProcs dw _TBCopyDataFast,_TBCopyDataFast,_TBCopyDataVFast,_TBCopyDataV
|
||||||
FastTileCopy dw _CopyTileDataToDP2,_CopyTileDataToDP2,_CopyTileDataToDP2V,_CopyTileDataToDP2V
|
FastTileCopy dw _CopyTileDataToDP2,_CopyTileDataToDP2,_CopyTileDataToDP2V,_CopyTileDataToDP2V
|
||||||
FastSpriteSub dw FastSpriteOver,FastSpriteUnder
|
FastSpriteSub dw FastSpriteOver,FastSpriteUnder
|
||||||
|
|
||||||
; Need to determine if the sprite or tile data is on top, as that will decide whether the
|
; Optimized routines to render sprites on top of the tile data and update the code field
|
||||||
; sprite or tile data is copied into the temporary buffer first. Also, if TWO_LAYER is set
|
; assuming that the opcode will never need to be reset, e.g. all of the instructions are
|
||||||
; then the mask information must be copied as well....This is the last decision point.
|
; PEA opcodes, so only the operands need to be set.
|
||||||
|
;
|
||||||
SpriteDispatch
|
; Since the sprite is drawn on top of the tile, the first step is to copy the tile data
|
||||||
jmp (K_TS_SPRITE_TILE_DISP,x)
|
; into the direct page temporary space, then dispatch to the appropriate sprite rendering
|
||||||
|
; subroutine
|
||||||
FastSpriteOver
|
FastSpriteOver
|
||||||
txy
|
txy
|
||||||
SpriteBitsToVBuffAddrs OneSpriteFast;TwoSpritesFast;ThreeSpritesFast;FourSpritesFast
|
SpriteBitsToVBuffAddrs OneSpriteFast;TwoSpritesFast;ThreeSpritesFast;FourSpritesFast
|
||||||
|
|
||||||
|
; Optimized routines for drawing sprites underneath the tile. In this case, the sprite is drawn first,
|
||||||
|
; so we have to calculate the sprite dispatch subrotine to copy the sprite data into the direct
|
||||||
|
; page space and then merge it with the tile data at the end.
|
||||||
FastSpriteUnder
|
FastSpriteUnder
|
||||||
|
rts
|
||||||
txy
|
txy
|
||||||
SpriteBitsToVBuffAddrs OneSpriteFastUnder;OneSpriteFastUnder;OneSpriteFastUnder;OneSpriteFastUnder
|
SpriteBitsToVBuffAddrs OneSpriteFastUnder;OneSpriteFastUnder;OneSpriteFastUnder;OneSpriteFastUnder
|
||||||
|
|
||||||
|
|
||||||
; This handles sprite with the tile above
|
; This handles sprite with the tile above
|
||||||
OneSpriteFastUnder
|
OneSpriteFastUnder
|
||||||
tax
|
tax
|
||||||
|
@ -88,17 +92,17 @@ _CopySpriteDataToDP2
|
||||||
OneSpriteFast
|
OneSpriteFast
|
||||||
sta sprite_ptr0
|
sta sprite_ptr0
|
||||||
tyx
|
tyx
|
||||||
ldy TileStore+TS_TILE_ADDR,x
|
|
||||||
|
|
||||||
pei DP2_TILEDATA_AND_TILESTORE_BANKS
|
ldy TileStore+TS_TILE_ADDR,x ; load the tile address
|
||||||
plb
|
pei DP2_TILEDATA_AND_TILESTORE_BANKS ; copy the tile. Setting the bank
|
||||||
jsr (K_TS_COPY_TILE_DATA,x)
|
plb ; saves 16 cycles and costs 14, so it's
|
||||||
plb
|
jsr (K_TS_COPY_TILE_DATA,x) ; a small win, but we really do it to be
|
||||||
|
plb ; able to preserve the X register
|
||||||
|
|
||||||
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
|
||||||
ldx sprite_ptr0 ; address of sprite vbuff info
|
ldx sprite_ptr0
|
||||||
plb
|
plb
|
||||||
|
|
||||||
]line equ 0
|
]line equ 0
|
||||||
|
@ -115,7 +119,7 @@ OneSpriteFast
|
||||||
]line equ ]line+1
|
]line equ ]line+1
|
||||||
--^
|
--^
|
||||||
plb
|
plb
|
||||||
rts
|
rts
|
||||||
|
|
||||||
TwoSpriteLine mac
|
TwoSpriteLine mac
|
||||||
; and [sprite_ptr1],y
|
; and [sprite_ptr1],y
|
||||||
|
@ -127,35 +131,51 @@ TwoSpriteLine mac
|
||||||
<<<
|
<<<
|
||||||
|
|
||||||
TwoSpritesFast
|
TwoSpritesFast
|
||||||
ldx TileStore+TS_TILE_ADDR,y
|
tyx ; save for after compositing the sprites
|
||||||
lda TileStore+TS_CODE_ADDR_HIGH,y ; load the bank of the target code field line
|
|
||||||
pha ; and put on the stack for later. Has TileStore bank in high byte.
|
|
||||||
lda TileStore+TS_CODE_ADDR_LOW,y ; load the address of the code field
|
|
||||||
pha ; Need to pop it later....
|
|
||||||
|
|
||||||
sep #$20 ; set the sprite data bank
|
ldy TileStore+TS_TILE_ADDR,x
|
||||||
lda #^spritedata
|
pei DP2_TILEDATA_AND_TILESTORE_BANKS
|
||||||
pha
|
|
||||||
plb
|
plb
|
||||||
rep #$20
|
jsr (K_TS_COPY_TILE_DATA,x)
|
||||||
|
plb
|
||||||
|
|
||||||
|
pei DP2_SPRITEDATA_AND_TILESTORE_BANKS
|
||||||
|
plb ; set the sprite data bank
|
||||||
|
|
||||||
]line equ 0
|
]line equ 0
|
||||||
lup 8
|
lup 8
|
||||||
ldy #{]line*SPRITE_PLANE_SPAN}
|
ldy #{]line*SPRITE_PLANE_SPAN}
|
||||||
ldal tiledata+{]line*4},x
|
lda tmp_tile_data+{]line*4}
|
||||||
TwoSpriteLine
|
TwoSpriteLine
|
||||||
sta tmp_tile_data+{]line*4}
|
sta tmp_tile_data+{]line*4}
|
||||||
|
|
||||||
ldy #{]line*SPRITE_PLANE_SPAN}+2
|
ldy #{]line*SPRITE_PLANE_SPAN}+2
|
||||||
ldal tiledata+{]line*4}+2,x
|
lda tmp_tile_data+{]line*4}+2
|
||||||
TwoSpriteLine
|
TwoSpriteLine
|
||||||
sta tmp_tile_data+{]line*4}+2
|
sta tmp_tile_data+{]line*4}+2
|
||||||
]line equ ]line+1
|
]line equ ]line+1
|
||||||
--^
|
--^
|
||||||
|
|
||||||
ply ; Pop off CODE_ADDR_LOW
|
plb ; restore access to data bank
|
||||||
|
|
||||||
|
; Fall through
|
||||||
|
_CopyDP2ToCodeField
|
||||||
|
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
|
||||||
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
|
||||||
|
@ -170,34 +190,32 @@ ThreeSpriteLine mac
|
||||||
<<<
|
<<<
|
||||||
|
|
||||||
ThreeSpritesFast
|
ThreeSpritesFast
|
||||||
ldx TileStore+TS_TILE_ADDR,y
|
tyx ; save for after compositing the sprites
|
||||||
lda TileStore+TS_CODE_ADDR_HIGH,y ; load the bank of the target code field line
|
|
||||||
pha ; and put on the stack for later. Has TileStore bank in high byte.
|
|
||||||
lda TileStore+TS_CODE_ADDR_LOW,y ; load the address of the code field
|
|
||||||
pha ; Need to pop it later....
|
|
||||||
|
|
||||||
sep #$20 ; set the sprite data bank
|
ldy TileStore+TS_TILE_ADDR,x
|
||||||
lda #^spritedata
|
pei DP2_TILEDATA_AND_TILESTORE_BANKS
|
||||||
pha
|
|
||||||
plb
|
plb
|
||||||
rep #$20
|
jsr (K_TS_COPY_TILE_DATA,x)
|
||||||
|
plb
|
||||||
|
|
||||||
|
pei DP2_SPRITEDATA_AND_TILESTORE_BANKS
|
||||||
|
plb ; set the sprite data bank
|
||||||
|
|
||||||
]line equ 0
|
]line equ 0
|
||||||
lup 8
|
lup 8
|
||||||
ldy #{]line*SPRITE_PLANE_SPAN}
|
ldy #{]line*SPRITE_PLANE_SPAN}
|
||||||
ldal tiledata+{]line*4},x
|
lda tmp_tile_data+{]line*4}
|
||||||
ThreeSpriteLine
|
ThreeSpriteLine
|
||||||
sta tmp_tile_data+{]line*4}
|
sta tmp_tile_data+{]line*4}
|
||||||
|
|
||||||
ldy #{]line*SPRITE_PLANE_SPAN}+2
|
ldy #{]line*SPRITE_PLANE_SPAN}+2
|
||||||
ldal tiledata+{]line*4}+2,x
|
lda tmp_tile_data+{]line*4}+2
|
||||||
ThreeSpriteLine
|
ThreeSpriteLine
|
||||||
sta tmp_tile_data+{]line*4}+2
|
sta tmp_tile_data+{]line*4}+2
|
||||||
]line equ ]line+1
|
]line equ ]line+1
|
||||||
--^
|
--^
|
||||||
|
|
||||||
ply ; Pop off CODE_ADDR_LOW
|
plb
|
||||||
plb ; Set the CODE_ADDR_HIGH bank
|
|
||||||
jmp _CopyDP2ToCodeField
|
jmp _CopyDP2ToCodeField
|
||||||
|
|
||||||
FourSpriteLine mac
|
FourSpriteLine mac
|
||||||
|
@ -216,45 +234,30 @@ FourSpriteLine mac
|
||||||
<<<
|
<<<
|
||||||
|
|
||||||
FourSpritesFast
|
FourSpritesFast
|
||||||
ldx TileStore+TS_TILE_ADDR,y
|
tyx ; save for after compositing the sprites
|
||||||
lda TileStore+TS_CODE_ADDR_HIGH,y ; load the bank of the target code field line
|
|
||||||
pha ; and put on the stack for later. Has TileStore bank in high byte.
|
|
||||||
lda TileStore+TS_CODE_ADDR_LOW,y ; load the address of the code field
|
|
||||||
pha ; Need to pop it later....
|
|
||||||
|
|
||||||
sep #$20 ; set the sprite data bank
|
ldy TileStore+TS_TILE_ADDR,x
|
||||||
lda #^spritedata
|
pei DP2_TILEDATA_AND_TILESTORE_BANKS
|
||||||
pha
|
|
||||||
plb
|
plb
|
||||||
rep #$20
|
jsr (K_TS_COPY_TILE_DATA,x)
|
||||||
|
plb
|
||||||
|
|
||||||
|
pei DP2_SPRITEDATA_AND_TILESTORE_BANKS
|
||||||
|
plb ; set the sprite data bank
|
||||||
|
|
||||||
]line equ 0
|
]line equ 0
|
||||||
lup 8
|
lup 8
|
||||||
ldy #{]line*SPRITE_PLANE_SPAN}
|
ldy #{]line*SPRITE_PLANE_SPAN}
|
||||||
ldal tiledata+{]line*4},x
|
lda tmp_tile_data+{]line*4}
|
||||||
FourSpriteLine
|
FourSpriteLine
|
||||||
sta tmp_tile_data+{]line*4}
|
sta tmp_tile_data+{]line*4}
|
||||||
|
|
||||||
ldy #{]line*SPRITE_PLANE_SPAN}+2
|
ldy #{]line*SPRITE_PLANE_SPAN}+2
|
||||||
ldal tiledata+{]line*4}+2,x
|
lda tmp_tile_data+{]line*4}+2
|
||||||
FourSpriteLine
|
FourSpriteLine
|
||||||
sta tmp_tile_data+{]line*4}+2
|
sta tmp_tile_data+{]line*4}+2
|
||||||
]line equ ]line+1
|
]line equ ]line+1
|
||||||
--^
|
--^
|
||||||
|
|
||||||
ply ; Pop off CODE_ADDR_LOW
|
plb
|
||||||
plb ; Set the CODE_ADDR_HIGH bank
|
jmp _CopyDP2ToCodeField
|
||||||
|
|
||||||
; Fall through
|
|
||||||
|
|
||||||
_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
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user