mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2025-01-14 10:29:48 +00:00
Stub in more tile rendering functions; does not crash but renders incorrectly
This commit is contained in:
parent
90124b04bc
commit
652729081e
@ -15,6 +15,22 @@ _Deref MAC
|
|||||||
plb ; restore the caller's data bank register
|
plb ; restore the caller's data bank register
|
||||||
<<<
|
<<<
|
||||||
|
|
||||||
|
_Mul128 mac
|
||||||
|
asl
|
||||||
|
asl
|
||||||
|
asl
|
||||||
|
asl
|
||||||
|
asl
|
||||||
|
asl
|
||||||
|
asl
|
||||||
|
<<<
|
||||||
|
; xba ; Naive is 7 ASL instructions = 14 cycles
|
||||||
|
; lsr ; By using XBA, we can save a couple cycles
|
||||||
|
; bcc *+5
|
||||||
|
; ora #$8000
|
||||||
|
; and #$007F
|
||||||
|
|
||||||
|
|
||||||
_Mul4096 mac
|
_Mul4096 mac
|
||||||
xba
|
xba
|
||||||
asl
|
asl
|
||||||
@ -184,6 +200,8 @@ next
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ _UpdateBG0TileMap
|
|||||||
|
|
||||||
ldx :BlkX
|
ldx :BlkX
|
||||||
ldy :BlkY
|
ldy :BlkY
|
||||||
jsr RenderTile
|
jsr CopyTile
|
||||||
|
|
||||||
lda :BlkX
|
lda :BlkX
|
||||||
inc
|
inc
|
||||||
@ -470,5 +470,6 @@ _UpdateBG0TileMap
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ Col2CodeOffset lup 82
|
|||||||
--^
|
--^
|
||||||
dw CODE_TOP
|
dw CODE_TOP
|
||||||
|
|
||||||
; A parallel table to Col2CodeOffset that hold the offset to the exception handler address for each column
|
; A parallel table to Col2CodeOffset that holds the offset to the exception handler address for each column
|
||||||
SNIPPET_SIZE equ 32
|
SNIPPET_SIZE equ 32
|
||||||
]step equ 0
|
]step equ 0
|
||||||
JTableOffset lup 82
|
JTableOffset lup 82
|
||||||
@ -250,3 +250,4 @@ BG1YOffsetTable lup 26
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -595,14 +595,29 @@ epilogue_1 tsc
|
|||||||
; start lda (00),y ; 6
|
; start lda (00),y ; 6
|
||||||
; and #MASK ; 3
|
; and #MASK ; 3
|
||||||
; ora #DATA ; 3 = 12 cycles to load the data
|
; ora #DATA ; 3 = 12 cycles to load the data
|
||||||
; pha ; 4
|
|
||||||
; bcs alt_exit ; 2/3
|
; bcs alt_exit ; 2/3
|
||||||
; out jmp next ; 3 Fast-path completes in 5 additional cycles
|
; pha ; 4
|
||||||
|
; out brl next ; 4 Fast-path completes in 5 additional cycles
|
||||||
|
;
|
||||||
|
; alt_exit bvs r_edge ; 2/3
|
||||||
|
; clc ; 2
|
||||||
|
; brl l_jmp_rtn ; 3
|
||||||
|
; r_edge rep #$41
|
||||||
|
; brl r_jmp_rtn ; 3
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; For dynamic masked tiles, we re-write bytes 2 - 8 as this, which mostly
|
||||||
|
; avoids an execution speed pentaly for having to fill in the two extra bytes
|
||||||
|
; with an instruction
|
||||||
|
;
|
||||||
|
; start lda (00),y ; 6
|
||||||
|
; and $80,x ; 5
|
||||||
|
; ora $00,x ; 5 = 16 cycles to load the data
|
||||||
|
; bcc *+4 ;
|
||||||
|
; bcs alt_exit ; 2/3
|
||||||
|
; pha
|
||||||
|
; ...
|
||||||
|
|
||||||
; alt_exit clc ; 2
|
|
||||||
; bvs r_edge ; 2/3 Need to switch if doing the left edge
|
|
||||||
; jmp exit_rtn ; 3
|
|
||||||
; r_edge jmp entry_rtn ; 3
|
|
||||||
|
|
||||||
ds \,$00 ; pad to the next page boundary
|
ds \,$00 ; pad to the next page boundary
|
||||||
]index equ 0
|
]index equ 0
|
||||||
@ -626,3 +641,10 @@ top
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +26,16 @@
|
|||||||
; | +----------- M : Apply tile mask
|
; | +----------- M : Apply tile mask
|
||||||
; +----------------- Reserved
|
; +----------------- Reserved
|
||||||
;
|
;
|
||||||
|
; Each logical tile (corresponding to each Tile ID) actually takes up 128 bytes of memory in the
|
||||||
|
; tile bank
|
||||||
|
;
|
||||||
|
; +0 : 32 bytes of tile data
|
||||||
|
; +32 : 32 bytes of tile mask
|
||||||
|
; +64 : 32 bytes of horizontally flipped tile data
|
||||||
|
; +96 : 32 bytes of horizontally flipped tile mask
|
||||||
|
;
|
||||||
|
; It is simply too slow to try to horizontally reverse the pixel data on the fly. This still allows
|
||||||
|
; for up to 512 tiles to be stored in a single bank, which should be sufficient.
|
||||||
|
|
||||||
TILE_ID_MASK equ $01FF
|
TILE_ID_MASK equ $01FF
|
||||||
TILE_MASK_BIT equ $1000
|
TILE_MASK_BIT equ $1000
|
||||||
@ -52,7 +62,8 @@ RenderTile
|
|||||||
phx ; Save the tile offset
|
phx ; Save the tile offset
|
||||||
|
|
||||||
tax
|
tax
|
||||||
and #TILE_ID_MASK ; Mask out the ID and save just tha
|
and #TILE_ID_MASK ; Mask out the ID and save just that
|
||||||
|
_Mul128 ; multiplied by 128
|
||||||
pha
|
pha
|
||||||
|
|
||||||
txa
|
txa
|
||||||
@ -120,12 +131,6 @@ FillPEAOpcode
|
|||||||
|
|
||||||
CopyTileMem
|
CopyTileMem
|
||||||
CopyTileMem0
|
CopyTileMem0
|
||||||
asl ; Each tile takes up 64 bytes, 32 bytes for the
|
|
||||||
asl ; 8x8 data and 32 bytes for the 8x8 mask.
|
|
||||||
asl
|
|
||||||
asl
|
|
||||||
asl
|
|
||||||
asl
|
|
||||||
tax
|
tax
|
||||||
|
|
||||||
ldal tiledata+0,x ; The low word goes in the *next* instruction
|
ldal tiledata+0,x ; The low word goes in the *next* instruction
|
||||||
@ -179,24 +184,16 @@ CopyTileMem0
|
|||||||
; ]1 = address of tile data
|
; ]1 = address of tile data
|
||||||
; ]2 = address of tile mask
|
; ]2 = address of tile mask
|
||||||
; ]3 = address of target in code field
|
; ]3 = address of target in code field
|
||||||
;
|
|
||||||
; This is a relatively efficient way to handle the three different modes. Focus on this and
|
|
||||||
; then we will adjust the setup code...
|
|
||||||
CopyTileMemM
|
|
||||||
_X_REG equ tiletmp
|
_X_REG equ tiletmp
|
||||||
_Y_REG equ tiletmp+2
|
_Y_REG equ tiletmp+2
|
||||||
_T_PTR equ tiletmp+4 ; Copy of the tile address pointer
|
_T_PTR equ tiletmp+4 ; Copy of the tile address pointer
|
||||||
_BASE_ADDR equ tiletmp+6 ; Copy of BTableLow for this tile
|
_BASE_ADDR equ tiletmp+6 ; Copy of BTableLow for this tile
|
||||||
|
|
||||||
|
CopyTileMemM
|
||||||
|
|
||||||
stx _X_REG ; Save these values as we will need to reload them
|
stx _X_REG ; Save these values as we will need to reload them
|
||||||
sty _Y_REG ; at certain points
|
sty _Y_REG ; at certain points
|
||||||
|
|
||||||
asl ; Each tile takes up 64 bytes, 32 bytes for the
|
|
||||||
asl ; 8x8 data and 32 bytes for the 8x8 mask.
|
|
||||||
asl
|
|
||||||
asl
|
|
||||||
asl
|
|
||||||
asl
|
|
||||||
sta _T_PTR
|
sta _T_PTR
|
||||||
tax
|
tax
|
||||||
|
|
||||||
@ -219,6 +216,32 @@ _BASE_ADDR equ tiletmp+6 ; Copy of BTab
|
|||||||
|
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
CopyTileMemMV
|
||||||
|
|
||||||
|
stx _X_REG ; Save these values as we will need to reload them
|
||||||
|
sty _Y_REG ; at certain points
|
||||||
|
sta _T_PTR
|
||||||
|
tax
|
||||||
|
|
||||||
|
CopyMaskedWord tiledata+0;tiledata+32+0;$7003
|
||||||
|
CopyMaskedWord tiledata+2;tiledata+32+2;$7000
|
||||||
|
CopyMaskedWord tiledata+4;tiledata+32+4;$6003
|
||||||
|
CopyMaskedWord tiledata+6;tiledata+32+6;$6000
|
||||||
|
CopyMaskedWord tiledata+8;tiledata+32+8;$5003
|
||||||
|
CopyMaskedWord tiledata+10;tiledata+32+10;$5000
|
||||||
|
CopyMaskedWord tiledata+12;tiledata+32+12;$4003
|
||||||
|
CopyMaskedWord tiledata+14;tiledata+32+14;$4000
|
||||||
|
CopyMaskedWord tiledata+16;tiledata+32+16;$3003
|
||||||
|
CopyMaskedWord tiledata+18;tiledata+32+18;$3000
|
||||||
|
CopyMaskedWord tiledata+20;tiledata+32+20;$2003
|
||||||
|
CopyMaskedWord tiledata+22;tiledata+32+22;$2000
|
||||||
|
CopyMaskedWord tiledata+24;tiledata+32+24;$1003
|
||||||
|
CopyMaskedWord tiledata+28;tiledata+32+26;$1000
|
||||||
|
CopyMaskedWord tiledata+30;tiledata+32+28;$0003
|
||||||
|
CopyMaskedWord tiledata+32;tiledata+32+30;$0000
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
TilePatterns dw $0000,$1111,$2222,$3333
|
TilePatterns dw $0000,$1111,$2222,$3333
|
||||||
dw $4444,$5555,$6666,$7777
|
dw $4444,$5555,$6666,$7777
|
||||||
dw $8888,$9999,$AAAA,$BBBB
|
dw $8888,$9999,$AAAA,$BBBB
|
||||||
@ -269,12 +292,6 @@ ClearTile sep #$20
|
|||||||
|
|
||||||
; Copy a tile, but vertically flip the data
|
; Copy a tile, but vertically flip the data
|
||||||
CopyTileMemV
|
CopyTileMemV
|
||||||
asl ; Each tile takes up 64 bytes, 32 bytes for the
|
|
||||||
asl ; 8x8 data and 32 bytes for the 8x8 mask.
|
|
||||||
asl
|
|
||||||
asl
|
|
||||||
asl
|
|
||||||
asl
|
|
||||||
tax
|
tax
|
||||||
|
|
||||||
ldal tiledata+0,x ; The low word goes in the *next* instruction
|
ldal tiledata+0,x ; The low word goes in the *next* instruction
|
||||||
@ -368,10 +385,11 @@ solid
|
|||||||
pla
|
pla
|
||||||
rts
|
rts
|
||||||
|
|
||||||
; Not implemented yet, fallback to regular tile rendering
|
|
||||||
solid_hflip
|
solid_hflip
|
||||||
plx
|
plx
|
||||||
pla
|
pla
|
||||||
|
clc
|
||||||
|
adc #64 ; Advance to the flipped version
|
||||||
brl CopyTileMem
|
brl CopyTileMem
|
||||||
|
|
||||||
solid_vflip
|
solid_vflip
|
||||||
@ -379,10 +397,11 @@ solid_vflip
|
|||||||
pla
|
pla
|
||||||
brl CopyTileMemV
|
brl CopyTileMemV
|
||||||
|
|
||||||
; Not implemented, fallback to just vertical flips
|
|
||||||
solid_hvflip
|
solid_hvflip
|
||||||
plx
|
plx
|
||||||
pla
|
pla
|
||||||
|
clc
|
||||||
|
adc #64 ; Advance to the flipped version
|
||||||
brl CopyTileMemV
|
brl CopyTileMemV
|
||||||
|
|
||||||
masked
|
masked
|
||||||
@ -391,16 +410,34 @@ masked
|
|||||||
brl CopyTileMemM
|
brl CopyTileMemM
|
||||||
|
|
||||||
masked_hflip
|
masked_hflip
|
||||||
|
plx
|
||||||
|
pla
|
||||||
|
clc
|
||||||
|
adc #64 ; Advance to the flipped version
|
||||||
|
brl CopyTileMemM
|
||||||
|
|
||||||
masked_vflip
|
masked_vflip
|
||||||
|
plx
|
||||||
|
pla
|
||||||
|
brl CopyTileMemMV
|
||||||
|
|
||||||
masked_hvflip
|
masked_hvflip
|
||||||
|
plx
|
||||||
|
pla
|
||||||
|
clc
|
||||||
|
adc #64 ; Advance to the flipped version
|
||||||
|
brl CopyTileMemMV
|
||||||
|
|
||||||
dynamic
|
dynamic
|
||||||
dyn_masked
|
dyn_masked
|
||||||
|
plx
|
||||||
|
pla
|
||||||
rts
|
rts
|
||||||
; CopyTile
|
; CopyTile
|
||||||
;
|
;
|
||||||
; A low-level function that copies 8x8 tiles directly into the code field space.
|
; A low-level function that copies 8x8 tiles directly into the code field space.
|
||||||
;
|
;
|
||||||
; A = Tile ID (0 - 1023)
|
; A = Tile ID (0 - 511)
|
||||||
; X = Tile column (0 - 40)
|
; X = Tile column (0 - 40)
|
||||||
; Y = Tile row (0 - 25)
|
; Y = Tile row (0 - 25)
|
||||||
CopyTile
|
CopyTile
|
||||||
@ -429,14 +466,27 @@ CopyTile
|
|||||||
asl ; there are two columns per tile, so multiple by 4
|
asl ; there are two columns per tile, so multiple by 4
|
||||||
asl ; asl will clear the carry bit
|
asl ; asl will clear the carry bit
|
||||||
tax
|
tax
|
||||||
lda Col2CodeOffset,x
|
lda BTableLow,y
|
||||||
|
sta _BASE_ADDR ; Used in masked tile renderer
|
||||||
clc
|
clc
|
||||||
adc BTableLow,y
|
adc Col2CodeOffset,x
|
||||||
tay
|
tay
|
||||||
|
|
||||||
|
; Optimization note: We could make a Tile2CodeOffset table that is pre-reversed, which should simplify
|
||||||
|
; the code starting after the 'rep #$20' to just be this. Saves around 16 cycles / tile...
|
||||||
|
;
|
||||||
|
; There would need to be a similar modification made to the JTable as well.
|
||||||
|
;
|
||||||
|
; txa
|
||||||
|
; asl
|
||||||
|
; tax
|
||||||
|
; lda BTableLow,y
|
||||||
|
; sta _BASE_ADDR ; Used in masked tile renderer
|
||||||
|
; adc Col2CodeOffset,x
|
||||||
|
|
||||||
plb ; set the bank
|
plb ; set the bank
|
||||||
pla ; pop the tile ID
|
pla ; pop the tile ID
|
||||||
jsr CopyTileMem0
|
jsr RenderTile
|
||||||
|
|
||||||
plx ; pop the x-register
|
plx ; pop the x-register
|
||||||
plb ; restore the data bank and return
|
plb ; restore the data bank and return
|
||||||
@ -449,3 +499,23 @@ CopyTile
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user