Set dirty render to the correct direct page and several small cleanups

This commit is contained in:
Lucas Scharenbroich 2022-07-06 14:55:27 -05:00
parent 885feafb39
commit 182ebfd566
8 changed files with 131 additions and 95 deletions

View File

@ -115,18 +115,18 @@ OKTOROK_SLOT_4 equ 4
_GTEUpdateSprite _GTEUpdateSprite
; Add 4 octoroks ; Add 4 octoroks
pea OKTOROK_ID ; pea OKTOROK_ID
lda OktorokX ; lda OktorokX
pha ; pha
lda OktorokY ; lda OktorokY
pha ; pha
pea OKTOROK_SLOT_1 ; pea OKTOROK_SLOT_1
_GTEAddSprite ; _GTEAddSprite
pea OKTOROK_SLOT_1 ; pea OKTOROK_SLOT_1
pea $0000 ; with these flags (h/v flip) ; pea $0000 ; with these flags (h/v flip)
pea OKTOROK_VBUFF ; and use this stamp ; pea OKTOROK_VBUFF ; and use this stamp
_GTEUpdateSprite ; _GTEUpdateSprite
; Draw the initial screen ; Draw the initial screen
@ -166,7 +166,6 @@ EvtLoop
bne :not_q bne :not_q
brl Exit brl Exit
:not_q :not_q
brl EvtLoop
cmp #'d' cmp #'d'
bne :not_d bne :not_d
@ -229,28 +228,28 @@ EvtLoop
; Based on the frame count, move an oktorok ; Based on the frame count, move an oktorok
jsr _GetVBLTicks ; jsr _GetVBLTicks
pha ; pha
and #$0003 ; and #$0003
asl ; asl
tax ; tax
pla ; pla
and #$007C ; and #$007C
lsr ; lsr
tay ; tay
lda OktorokX,x ; lda OktorokX,x
clc ; clc
adc OktorokDelta,y ; adc OktorokDelta,y
phx ; phx
ldy OktorokY,x ; ldy OktorokY,x
tax ; tax
pla ; pla
inc ; inc
inc ; inc
; jsl MoveSprite ; jsl MoveSprite

View File

@ -126,9 +126,9 @@ SET_DYN_TILE equ $0006
CALLBACK equ $0010 CALLBACK equ $0010
; ReadControl return value bits ; ReadControl return value bits
PAD_BUTTON_B equ $01 PAD_BUTTON_B equ $0100
PAD_BUTTON_A equ $02 PAD_BUTTON_A equ $0200
PAD_KEY_DOWN equ $04 PAD_KEY_DOWN equ $0400
ENGINE_MODE_TWO_LAYER equ $0001 ENGINE_MODE_TWO_LAYER equ $0001
ENGINE_MODE_DYN_TILES equ $0002 ENGINE_MODE_DYN_TILES equ $0002
ENGINE_MODE_BNK0_BUFF equ $0004 ENGINE_MODE_BNK0_BUFF equ $0004

View File

@ -271,7 +271,7 @@ _ReadControl pea $0000 ; low byte = key code, high byte
and #$80 and #$80
beq :BNotDown beq :BNotDown
lda #PAD_BUTTON_B lda #>PAD_BUTTON_B
ora 2,s ora 2,s
sta 2,s sta 2,s
@ -280,7 +280,7 @@ _ReadControl pea $0000 ; low byte = key code, high byte
and #$80 and #$80
beq :ANotDown beq :ANotDown
lda #PAD_BUTTON_A lda #>PAD_BUTTON_A
ora 2,s ora 2,s
sta 2,s sta 2,s
@ -296,7 +296,7 @@ _ReadControl pea $0000 ; low byte = key code, high byte
beq :KbdDown beq :KbdDown
sta LastKey sta LastKey
lda #PAD_KEY_DOWN ; set the keydown flag lda #>PAD_KEY_DOWN ; set the keydown flag
ora 2,s ora 2,s
sta 2,s sta 2,s
bra :KbdDown bra :KbdDown

View File

@ -157,20 +157,27 @@ _ApplyTiles
; In this renderer, we assume that there is no scrolling, so no need to update any information about ; In this renderer, we assume that there is no scrolling, so no need to update any information about
; the BG0/BG1 positions ; the BG0/BG1 positions
_RenderDirty _RenderDirty
lda LastRender ; If the full renderer was last called, we assume that lda LastRender ; If the full renderer was last called, we assume that
bne :norecalc ; the scroll positions have likely changed, so recalculate bne :norecalc ; the scroll positions have likely changed, so recalculate
jsr _RecalcTileScreenAddrs ; them to make sure sprites draw at the correct screen address jsr _RecalcTileScreenAddrs ; them to make sure sprites draw at the correct screen address
jsr _ResetVisibleTiles ; Switch the tile procs to the dirty tile rendering functions
; jsr _ClearSpritesFromCodeField ; Restore the tiles to their non-sprite versions ; jsr _ClearSpritesFromCodeField ; Restore the tiles to their non-sprite versions
:norecalc :norecalc
; jsr _RenderSprites jsr _RenderSprites
; jsr _ApplyDirtyTiles jsr _ApplyDirtyTiles
lda #1 lda #1
sta LastRender sta LastRender
rts rts
_ApplyDirtyTiles _ApplyDirtyTiles
phd ; save the current direct page
tdc
clc
adc #$100 ; move to the next page
tcd
bra :begin bra :begin
:loop :loop
@ -180,13 +187,14 @@ _ApplyDirtyTiles
; Call the generic dispatch with the Tile Store record pointer at by the Y-register. ; Call the generic dispatch with the Tile Store record pointer at by the Y-register.
phb
jsr _RenderDirtyTile jsr _RenderDirtyTile
plb
; Loop again until the list of dirty tiles is empty ; Loop again until the list of dirty tiles is empty
:begin ldy DirtyTileCount :begin ldy DirtyTileCount
bne :loop bne :loop
pld ; Move back to the original direct page
stz DirtyTileCount ; Reset the dirty tile count
rts rts

View File

@ -218,10 +218,6 @@ tmp_out
mdsOut rts mdsOut rts
; NOTE: The VBuffArray table is set up so that each sprite's vbuff address is stored in a
; parallel structure to the Tile Store. This allows up to use the same TileStoreLookup
; offset to index into the array of 16 sprite VBUFF addresses that are bound to a given tile
_MarkDirtySpriteTiles _MarkDirtySpriteTiles
lda _SpriteBits,y lda _SpriteBits,y
sta SpriteBit sta SpriteBit

View File

@ -167,49 +167,98 @@ InitTiles
rts rts
; Reset all of the tile proc values in the playfield. ; Reset all of the tile proc values in the playfield.
ResetVisibleTiles _ResetVisibleTiles
:col equ tmp0 :col equ tmp0
:row equ tmp1 :row equ tmp1
jsr _OriginToTileStore ; Get the (col,row) of the tile in the upper-left corner of the playfield
clc
txa
adc TileStoreLookupYTable,y ; Get the offset into the Tile Store lookup table
tay
pha ; Save for later
lda ScreenTileHeight lda ScreenTileHeight
sta :row sta :row
lda ScreenTileWidth lda ScreenTileWidth
sta :col sta :col
:loop :loop
lda EngineMode phy
bit #ENGINE_MODE_DYN_TILES+ENGINE_MODE_TWO_LAYER ldx TileStoreLookup,y
beq :fast lda TileStore+TS_TILE_ID,x
bit #ENGINE_MODE_TWO_LAYER jsr _CalcTileProcIndex
beq :dyn ldy #DirtyProcs
; ldal TileProcs
; sta TileStore+TS_BASE_TILE_DISP,x
bra :out
:fast
lda #0 ; Initialize with Tile 0
ldy #FastProcs
jsr _SetTileProcs jsr _SetTileProcs
bra :out ply
:dyn lda #0 ; Initialize with Tile 0
ldy #FastProcs
jsr _SetTileProcs
:out
; The next set of values are constants that are simply used as cached parameters to avoid needing to
; calculate any of these values during tile rendering
iny
iny
dec :col dec :col
bpl :hop bpl :loop
dec :row
lda ScreenTileWidth lda ScreenTileWidth
sta :col sta :col
:hop
dex lda 1,s ; Move to the next row
dex clc
adc #2*TS_LOOKUP_SPAN
sta 1,s
tay
dec :row
bpl :loop bpl :loop
pla ; pop the saved value
rts
; Helper method to calculate the index into the tile proc table given a TileID
; Calculate the base tile proc selector from the tile Id
_CalcTileProcIndex
bit #TILE_PRIORITY_BIT ; 4 if !0, 0 otherwise
beq :low_priority
bit #TILE_ID_MASK ; 2 if !0, 0 otherwise
beq :is_zero_a
bit #TILE_VFLIP_BIT ; 1 if !0, 0 otherwise
beq :no_flip_a
lda #7
rts
:no_flip_a lda #6
rts
:is_zero_a bit #TILE_VFLIP_BIT
beq :no_flip_b
lda #5
rts
:no_flip_b lda #4
rts
:low_priority bit #TILE_ID_MASK ; 2 if !0, 0 otherwise
beq :is_zero_b
bit #TILE_VFLIP_BIT ; 1 if !0, 0 otherwise
beq :no_flip_c
lda #3
rts
:no_flip_c lda #2
rts
:is_zero_b bit #TILE_VFLIP_BIT
beq :no_flip_d
lda #1
rts
:no_flip_d lda #0
rts rts
; Set a tile value in the tile backing store. Mark dirty if the value changes ; Set a tile value in the tile backing store. Mark dirty if the value changes
@ -254,27 +303,10 @@ _SetTile
; it can be more involved. ; it can be more involved.
; Calculate the base tile proc selector from the tile Id ; Calculate the base tile proc selector from the tile Id
stz procIdx
lda #TILE_PRIORITY_BIT lda newTileId
bit newTileId jsr _CalcTileProcIndex
beq :low_priority
lda #4
sta procIdx sta procIdx
:low_priority
lda #TILE_ID_MASK
bit newTileId
beq :is_zero
lda #2
tsb procIdx
:is_zero
lda #TILE_VFLIP_BIT
bit newTileId
beq :no_vflip
lda #1
tsb procIdx
:no_vflip
; Now integrate with the engine mode indicator ; Now integrate with the engine mode indicator

View File

@ -46,10 +46,10 @@ Counter equ tmp3
lda (NextColPtr),y ; Need to recalculate each time since the wrap-around could lda (NextColPtr),y ; Need to recalculate each time since the wrap-around could
clc ; happen anywhere clc ; happen anywhere
adc (RowAddrPtr) ; adc (RowAddrPtr) ;
tax ; NOTE: Try to rework to use new TileStore2DLookup array tax ; NOTE: Try to rework to use new TileStoreLookup array
lda OnScreenAddr lda OnScreenAddr
sta TileStore+TS_SCREEN_ADDR,x sta TileStore+TS_SCREEN_ADDR,x
clc clc
adc #4 ; Go to the next tile adc #4 ; Go to the next tile

View File

@ -116,6 +116,7 @@ DirtySpriteUnder mac
; Special routine for a single sprite ; Special routine for a single sprite
OneSpriteDirtyOverA OneSpriteDirtyOverA
ldy TileStore+TS_TILE_ADDR,x ldy TileStore+TS_TILE_ADDR,x
lda TileStore+TS_SCREEN_ADDR,x lda TileStore+TS_SCREEN_ADDR,x
ldx sprite_ptr0 ldx sprite_ptr0