Move sprite blitter totally into app code

This commit is contained in:
Lucas Scharenbroich
2023-06-02 15:56:13 -05:00
parent 377ac1f788
commit 91454c9481
2 changed files with 122 additions and 28 deletions

View File

@@ -110,14 +110,14 @@ FTblTmp equ 228
_GTESetAddress _GTESetAddress
; Get the address of a low-level routine that can be used to draw a tile directly to the graphics screen ; Get the address of a low-level routine that can be used to draw a tile directly to the graphics screen
pea rawDrawTile ; pea rawDrawTile
_GTEGetAddress ; _GTEGetAddress
lda 1,s ; lda 1,s
sta drawTilePatch+1 ; sta drawTilePatch+1
lda 2,s ; lda 2,s
sta drawTilePatch+2 ; sta drawTilePatch+2
pla ; pla
plx ; plx
; Initialize the graphics screen playfield (256x160). The NES is 240 lines high, so 160 ; Initialize the graphics screen playfield (256x160). The NES is 240 lines high, so 160
; is a reasonable compromise. ; is a reasonable compromise.
@@ -1268,16 +1268,16 @@ DLUT4 db $00,$01,$10,$11 ; CHR_ROM[0] = xx, CHR_ROM[8] = 00
db $20,$21,$30,$31 ; CHR_ROM[0] = xx, CHR_ROM[8] = 10 db $20,$21,$30,$31 ; CHR_ROM[0] = xx, CHR_ROM[8] = 10
db $22,$23,$32,$33 ; CHR_ROM[0] = xx, CHR_ROM[8] = 11 db $22,$23,$32,$33 ; CHR_ROM[0] = xx, CHR_ROM[8] = 11
;MLUT dw $FF,$F0,$0F,$00 MLUT4 db $FF,$F0,$0F,$00
; dw $F0,$F0,$00,$00 db $F0,$F0,$00,$00
; dw $0F,$00,$0F,$00 db $0F,$00,$0F,$00
; dw $00,$00,$00,$00 db $00,$00,$00,$00
; Inverted mask for using eor/and/eor rendering ; Inverted mask for using eor/and/eor rendering
MLUT4 db $00,$0F,$F0,$FF ;MLUT4 db $00,$0F,$F0,$FF
db $0F,$0F,$FF,$FF ; db $0F,$0F,$FF,$FF
db $F0,$FF,$F0,$FF ; db $F0,$FF,$F0,$FF
db $FF,$FF,$FF,$FF ; db $FF,$FF,$FF,$FF
; Extracted tiles ; Extracted tiles
TileBuff ds 128 TileBuff ds 128

View File

@@ -944,7 +944,11 @@ drawOAMSprites
phk phk
plb plb
pha pha ; Save the phase indicator
tdc ; Keep a copy of the second page of GTE direct page space
clc
adc #$0100
sta GTE_DP2+1
lda DPSave lda DPSave
tcd tcd
@@ -1014,10 +1018,10 @@ drawSprites
mx %11 mx %11
oam_loop oam_loop
phx ; Save x phx ; Save x
lda OAM_COPY,x ; Y-coordinate lda OAM_COPY,x ; Y-coordinate
inc ; Compensate for PPU delayed scanline inc ; Compensate for PPU delayed scanline
rep #$30 rep #$30
and #$00FF and #$00FF
@@ -1044,31 +1048,35 @@ oam_loop
lda OAM_COPY+2,x lda OAM_COPY+2,x
pha pha
bit #$0040 ; horizontal flip bit #$0040 ; horizontal flip
bne :hflip bne :hflip
lda OAM_COPY,x ; Load the tile index into the high byte (x256) lda OAM_COPY,x ; Load the tile index into the high byte (x256)
and #$FF00 and #$FF00
lsr ; multiple by 128 lsr ; multiple by 128
tax tax
bra :noflip bra :noflip
:hflip :hflip
lda OAM_COPY,x ; Load the tile index into the high byte (x256) lda OAM_COPY,x ; Load the tile index into the high byte (x256)
and #$FF00 and #$FF00
lsr ; multiple by 128 lsr ; multiple by 128
adc #64 ; horizontal flip adc #64 ; horizontal flip
tax tax
:noflip :noflip
; sta swizzle ; store a pointer to the swizzle table to use
pla pla
asl asl
and #$0146 ; Set the vflip bit, priority, and palette select bits and #$0146 ; Set the vflip bit, priority, and palette select bits
drawTilePatch phd
jsl $000000 ; Draw the tile on the graphics screen GTE_DP2 pea $0000
pld
jsr drawTileToScreen
pld
;drawTilePatch
; jsl $000000 ; Draw the tile on the graphics screen
sep #$30 sep #$30
plx ; Restore the counter plx ; Restore the counter
@@ -1092,13 +1100,99 @@ drawTilePatch
; Temporary tile space on the direct page ; Temporary tile space on the direct page
tmp_tile_data equ 80 tmp_tile_data equ 80
DP2_TILEDATA_AND_BANK01_BANKS equ 172
;USER_TILE_RECORD equ 178 ;USER_TILE_RECORD equ 178
USER_TILE_ID equ 178 ; copy of the tile id in the tile store USER_TILE_ID equ 178 ; copy of the tile id in the tile store
;USER_TILE_CODE_PTR equ 180 ; pointer to the code bank in which to patch ;USER_TILE_CODE_PTR equ 180 ; pointer to the code bank in which to patch
USER_TILE_ADDR equ 184 ; address in the tile data bank (set on entry) USER_TILE_ADDR equ 184 ; address in the tile data bank (set on entry)
USER_FREE_SPACE equ 186 ; a few bytes of scratch space USER_FREE_SPACE equ 186 ; a few bytes of scratch space
USER_SCREEN_ADDR equ 190
LDA_IND_LONG_IDX equ $B7 LDA_IND_LONG_IDX equ $B7
ORA_IND_LONG_IDX equ $17
SHR_LINE_WIDTH equ 160
; Draw a tile to the graphics screen
;
; D = GTE Page 2
; X = tile address
; Y = screen address
; A = tile control bits; h ($0100), v ($0040) and palette select ($0006)
jne mac
beq *+5
jmp ]1
<<<
jeq mac
bne *+5
jmp ]1
<<<
drawTileToScreen
stx USER_TILE_ADDR
sty USER_SCREEN_ADDR
phb
pei DP2_TILEDATA_AND_BANK01_BANKS
plb
pha
and #$0006 ; Isolate the palette selection bits
clc
adc #$0008 ; Sprite palettes are in the second half
xba
clc
adc #W11_T0
sta USER_FREE_SPACE
lda #^W11_T0
sta USER_FREE_SPACE+2 ; Set the pointer to the right swizzle table
pla
bit #$0040
beq :no_prio
bit #$0100
; jeq :drawPriorityToScreen
; jmp :drawPriorityToScreenV
:no_prio
bit #$0100
; jne :drawTileToScreenV
]line equ 0
lup 8
ldx USER_TILE_ADDR
ldy: {]line*4}+2,x ; Load the tile data lookup value
lda: {]line*4}+32+2,x ; Load the mask value
ldx USER_SCREEN_ADDR
andl $010000+{]line*SHR_LINE_WIDTH}+2,x ; Mask against the screen
db ORA_IND_LONG_IDX,USER_FREE_SPACE ; Insert the actual tile data
stal $010000+{]line*SHR_LINE_WIDTH}+2,x
ldx USER_TILE_ADDR
ldy: {]line*4},x ; Load the tile data lookup value
lda: {]line*4}+32,x ; Load the mask value
ldx USER_SCREEN_ADDR
andl $010000+{]line*SHR_LINE_WIDTH},x ; Mask against the screen
db ORA_IND_LONG_IDX,USER_FREE_SPACE ; Insert the actual tile data
stal $010000+{]line*SHR_LINE_WIDTH},x
]line equ ]line+1
--^
plb
plb ; Restore initial data bank
rts
:drawTileToScreenV
:drawPriorityToScreen
:drawPriorityToScreenV
plb
plb ; Restore initial data bank
rts
; Assume that when the tile is updated, it includes a full 10-bit value with the ; Assume that when the tile is updated, it includes a full 10-bit value with the
; palette bits included with the lookup bits ; palette bits included with the lookup bits
@@ -1123,4 +1217,4 @@ NESTileBlitter
]line equ ]line+1 ]line equ ]line+1
--^ --^
lda #1 ; Request tmp_tile_data be copied to tile store lda #1 ; Request tmp_tile_data be copied to tile store
rtl rtl