Stub in more tile rendering functions; does not crash but renders incorrectly

This commit is contained in:
Lucas Scharenbroich 2021-08-13 11:38:06 -05:00
parent 90124b04bc
commit 652729081e
5 changed files with 150 additions and 38 deletions

View File

@ -15,6 +15,22 @@ _Deref MAC
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
xba
asl
@ -184,6 +200,8 @@ next

View File

@ -314,7 +314,7 @@ _UpdateBG0TileMap
ldx :BlkX
ldy :BlkY
jsr RenderTile
jsr CopyTile
lda :BlkX
inc
@ -470,5 +470,6 @@ _UpdateBG0TileMap

View File

@ -22,7 +22,7 @@ Col2CodeOffset lup 82
--^
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
]step equ 0
JTableOffset lup 82
@ -250,3 +250,4 @@ BG1YOffsetTable lup 26

View File

@ -595,14 +595,29 @@ epilogue_1 tsc
; start lda (00),y ; 6
; and #MASK ; 3
; ora #DATA ; 3 = 12 cycles to load the data
; pha ; 4
; 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
]index equ 0
@ -626,3 +641,10 @@ top

View File

@ -26,6 +26,16 @@
; | +----------- M : Apply tile mask
; +----------------- 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_MASK_BIT equ $1000
@ -52,7 +62,8 @@ RenderTile
phx ; Save the tile offset
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
txa
@ -120,12 +131,6 @@ FillPEAOpcode
CopyTileMem
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
ldal tiledata+0,x ; The low word goes in the *next* instruction
@ -179,24 +184,16 @@ CopyTileMem0
; ]1 = address of tile data
; ]2 = address of tile mask
; ]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
_Y_REG equ tiletmp+2
_T_PTR equ tiletmp+4 ; Copy of the tile address pointer
_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
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
tax
@ -219,6 +216,32 @@ _BASE_ADDR equ tiletmp+6 ; Copy of BTab
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
dw $4444,$5555,$6666,$7777
dw $8888,$9999,$AAAA,$BBBB
@ -269,12 +292,6 @@ ClearTile sep #$20
; Copy a tile, but vertically flip the data
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
ldal tiledata+0,x ; The low word goes in the *next* instruction
@ -368,10 +385,11 @@ solid
pla
rts
; Not implemented yet, fallback to regular tile rendering
solid_hflip
plx
pla
clc
adc #64 ; Advance to the flipped version
brl CopyTileMem
solid_vflip
@ -379,10 +397,11 @@ solid_vflip
pla
brl CopyTileMemV
; Not implemented, fallback to just vertical flips
solid_hvflip
plx
pla
clc
adc #64 ; Advance to the flipped version
brl CopyTileMemV
masked
@ -391,16 +410,34 @@ masked
brl CopyTileMemM
masked_hflip
plx
pla
clc
adc #64 ; Advance to the flipped version
brl CopyTileMemM
masked_vflip
plx
pla
brl CopyTileMemMV
masked_hvflip
plx
pla
clc
adc #64 ; Advance to the flipped version
brl CopyTileMemMV
dynamic
dyn_masked
plx
pla
rts
; CopyTile
;
; 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)
; Y = Tile row (0 - 25)
CopyTile
@ -429,14 +466,27 @@ CopyTile
asl ; there are two columns per tile, so multiple by 4
asl ; asl will clear the carry bit
tax
lda Col2CodeOffset,x
lda BTableLow,y
sta _BASE_ADDR ; Used in masked tile renderer
clc
adc BTableLow,y
adc Col2CodeOffset,x
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
pla ; pop the tile ID
jsr CopyTileMem0
jsr RenderTile
plx ; pop the x-register
plb ; restore the data bank and return
@ -449,3 +499,23 @@ CopyTile