mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2025-01-11 20:30:14 +00:00
Set dirty render to the correct direct page and several small cleanups
This commit is contained in:
parent
885feafb39
commit
182ebfd566
@ -115,18 +115,18 @@ OKTOROK_SLOT_4 equ 4
|
||||
_GTEUpdateSprite
|
||||
|
||||
; Add 4 octoroks
|
||||
pea OKTOROK_ID
|
||||
lda OktorokX
|
||||
pha
|
||||
lda OktorokY
|
||||
pha
|
||||
pea OKTOROK_SLOT_1
|
||||
_GTEAddSprite
|
||||
; pea OKTOROK_ID
|
||||
; lda OktorokX
|
||||
; pha
|
||||
; lda OktorokY
|
||||
; pha
|
||||
; pea OKTOROK_SLOT_1
|
||||
; _GTEAddSprite
|
||||
|
||||
pea OKTOROK_SLOT_1
|
||||
pea $0000 ; with these flags (h/v flip)
|
||||
pea OKTOROK_VBUFF ; and use this stamp
|
||||
_GTEUpdateSprite
|
||||
; pea OKTOROK_SLOT_1
|
||||
; pea $0000 ; with these flags (h/v flip)
|
||||
; pea OKTOROK_VBUFF ; and use this stamp
|
||||
; _GTEUpdateSprite
|
||||
|
||||
; Draw the initial screen
|
||||
|
||||
@ -166,7 +166,6 @@ EvtLoop
|
||||
bne :not_q
|
||||
brl Exit
|
||||
:not_q
|
||||
brl EvtLoop
|
||||
|
||||
cmp #'d'
|
||||
bne :not_d
|
||||
@ -229,28 +228,28 @@ EvtLoop
|
||||
|
||||
; Based on the frame count, move an oktorok
|
||||
|
||||
jsr _GetVBLTicks
|
||||
pha
|
||||
and #$0003
|
||||
asl
|
||||
tax
|
||||
; jsr _GetVBLTicks
|
||||
; pha
|
||||
; and #$0003
|
||||
; asl
|
||||
; tax
|
||||
|
||||
pla
|
||||
and #$007C
|
||||
lsr
|
||||
tay
|
||||
; pla
|
||||
; and #$007C
|
||||
; lsr
|
||||
; tay
|
||||
|
||||
lda OktorokX,x
|
||||
clc
|
||||
adc OktorokDelta,y
|
||||
; lda OktorokX,x
|
||||
; clc
|
||||
; adc OktorokDelta,y
|
||||
|
||||
phx
|
||||
; phx
|
||||
|
||||
ldy OktorokY,x
|
||||
tax
|
||||
pla
|
||||
inc
|
||||
inc
|
||||
; ldy OktorokY,x
|
||||
; tax
|
||||
; pla
|
||||
; inc
|
||||
; inc
|
||||
; jsl MoveSprite
|
||||
|
||||
|
||||
|
@ -126,9 +126,9 @@ SET_DYN_TILE equ $0006
|
||||
CALLBACK equ $0010
|
||||
|
||||
; ReadControl return value bits
|
||||
PAD_BUTTON_B equ $01
|
||||
PAD_BUTTON_A equ $02
|
||||
PAD_KEY_DOWN equ $04
|
||||
PAD_BUTTON_B equ $0100
|
||||
PAD_BUTTON_A equ $0200
|
||||
PAD_KEY_DOWN equ $0400
|
||||
ENGINE_MODE_TWO_LAYER equ $0001
|
||||
ENGINE_MODE_DYN_TILES equ $0002
|
||||
ENGINE_MODE_BNK0_BUFF equ $0004
|
||||
|
@ -271,7 +271,7 @@ _ReadControl pea $0000 ; low byte = key code, high byte
|
||||
and #$80
|
||||
beq :BNotDown
|
||||
|
||||
lda #PAD_BUTTON_B
|
||||
lda #>PAD_BUTTON_B
|
||||
ora 2,s
|
||||
sta 2,s
|
||||
|
||||
@ -280,7 +280,7 @@ _ReadControl pea $0000 ; low byte = key code, high byte
|
||||
and #$80
|
||||
beq :ANotDown
|
||||
|
||||
lda #PAD_BUTTON_A
|
||||
lda #>PAD_BUTTON_A
|
||||
ora 2,s
|
||||
sta 2,s
|
||||
|
||||
@ -296,7 +296,7 @@ _ReadControl pea $0000 ; low byte = key code, high byte
|
||||
beq :KbdDown
|
||||
sta LastKey
|
||||
|
||||
lda #PAD_KEY_DOWN ; set the keydown flag
|
||||
lda #>PAD_KEY_DOWN ; set the keydown flag
|
||||
ora 2,s
|
||||
sta 2,s
|
||||
bra :KbdDown
|
||||
|
22
src/Render.s
22
src/Render.s
@ -157,20 +157,27 @@ _ApplyTiles
|
||||
; In this renderer, we assume that there is no scrolling, so no need to update any information about
|
||||
; the BG0/BG1 positions
|
||||
_RenderDirty
|
||||
lda LastRender ; If the full renderer was last called, we assume that
|
||||
bne :norecalc ; the scroll positions have likely changed, so recalculate
|
||||
jsr _RecalcTileScreenAddrs ; them to make sure sprites draw at the correct screen address
|
||||
lda LastRender ; If the full renderer was last called, we assume that
|
||||
bne :norecalc ; the scroll positions have likely changed, so recalculate
|
||||
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
|
||||
:norecalc
|
||||
|
||||
; jsr _RenderSprites
|
||||
; jsr _ApplyDirtyTiles
|
||||
jsr _RenderSprites
|
||||
jsr _ApplyDirtyTiles
|
||||
|
||||
lda #1
|
||||
sta LastRender
|
||||
rts
|
||||
|
||||
_ApplyDirtyTiles
|
||||
phd ; save the current direct page
|
||||
tdc
|
||||
clc
|
||||
adc #$100 ; move to the next page
|
||||
tcd
|
||||
|
||||
bra :begin
|
||||
|
||||
:loop
|
||||
@ -180,13 +187,14 @@ _ApplyDirtyTiles
|
||||
|
||||
; Call the generic dispatch with the Tile Store record pointer at by the Y-register.
|
||||
|
||||
phb
|
||||
jsr _RenderDirtyTile
|
||||
plb
|
||||
|
||||
; Loop again until the list of dirty tiles is empty
|
||||
|
||||
:begin ldy DirtyTileCount
|
||||
bne :loop
|
||||
|
||||
pld ; Move back to the original direct page
|
||||
stz DirtyTileCount ; Reset the dirty tile count
|
||||
rts
|
||||
|
||||
|
@ -218,10 +218,6 @@ tmp_out
|
||||
|
||||
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
|
||||
lda _SpriteBits,y
|
||||
sta SpriteBit
|
||||
|
124
src/Tiles.s
124
src/Tiles.s
@ -167,49 +167,98 @@ InitTiles
|
||||
rts
|
||||
|
||||
; Reset all of the tile proc values in the playfield.
|
||||
ResetVisibleTiles
|
||||
_ResetVisibleTiles
|
||||
:col equ tmp0
|
||||
: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
|
||||
sta :row
|
||||
lda ScreenTileWidth
|
||||
sta :col
|
||||
|
||||
:loop
|
||||
lda EngineMode
|
||||
bit #ENGINE_MODE_DYN_TILES+ENGINE_MODE_TWO_LAYER
|
||||
beq :fast
|
||||
bit #ENGINE_MODE_TWO_LAYER
|
||||
beq :dyn
|
||||
; ldal TileProcs
|
||||
; sta TileStore+TS_BASE_TILE_DISP,x
|
||||
bra :out
|
||||
:fast
|
||||
lda #0 ; Initialize with Tile 0
|
||||
ldy #FastProcs
|
||||
phy
|
||||
ldx TileStoreLookup,y
|
||||
lda TileStore+TS_TILE_ID,x
|
||||
jsr _CalcTileProcIndex
|
||||
ldy #DirtyProcs
|
||||
jsr _SetTileProcs
|
||||
bra :out
|
||||
|
||||
: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
|
||||
ply
|
||||
|
||||
iny
|
||||
iny
|
||||
dec :col
|
||||
bpl :hop
|
||||
dec :row
|
||||
bpl :loop
|
||||
|
||||
lda ScreenTileWidth
|
||||
sta :col
|
||||
:hop
|
||||
|
||||
dex
|
||||
dex
|
||||
lda 1,s ; Move to the next row
|
||||
clc
|
||||
adc #2*TS_LOOKUP_SPAN
|
||||
sta 1,s
|
||||
tay
|
||||
|
||||
dec :row
|
||||
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
|
||||
|
||||
; 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.
|
||||
|
||||
; Calculate the base tile proc selector from the tile Id
|
||||
stz procIdx
|
||||
|
||||
lda #TILE_PRIORITY_BIT
|
||||
bit newTileId
|
||||
beq :low_priority
|
||||
lda #4
|
||||
lda newTileId
|
||||
jsr _CalcTileProcIndex
|
||||
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
|
||||
|
||||
|
@ -46,10 +46,10 @@ Counter equ tmp3
|
||||
lda (NextColPtr),y ; Need to recalculate each time since the wrap-around could
|
||||
clc ; happen anywhere
|
||||
adc (RowAddrPtr) ;
|
||||
tax ; NOTE: Try to rework to use new TileStore2DLookup array
|
||||
tax ; NOTE: Try to rework to use new TileStoreLookup array
|
||||
|
||||
lda OnScreenAddr
|
||||
sta TileStore+TS_SCREEN_ADDR,x
|
||||
sta TileStore+TS_SCREEN_ADDR,x
|
||||
|
||||
clc
|
||||
adc #4 ; Go to the next tile
|
||||
|
@ -116,6 +116,7 @@ DirtySpriteUnder mac
|
||||
|
||||
; Special routine for a single sprite
|
||||
OneSpriteDirtyOverA
|
||||
|
||||
ldy TileStore+TS_TILE_ADDR,x
|
||||
lda TileStore+TS_SCREEN_ADDR,x
|
||||
ldx sprite_ptr0
|
||||
|
Loading…
x
Reference in New Issue
Block a user