Fix issues preventing BG1 per-line offsets from working

This commit is contained in:
Lucas Scharenbroich 2022-07-16 16:42:41 -05:00
parent 0ab7fa9d81
commit 23f3626293
6 changed files with 52 additions and 10 deletions

View File

@ -114,6 +114,9 @@ _GTERefresh MAC
_GTERenderDirty MAC _GTERenderDirty MAC
UserTool $2700+GTEToolNum UserTool $2700+GTEToolNum
<<< <<<
_GTESetBG1Displacement MAC
UserTool $2800+GTEToolNum
<<<
; EngineMode definitions ; EngineMode definitions
; Script definition ; Script definition
@ -137,6 +140,8 @@ ENGINE_MODE_BNK0_BUFF equ $0004
; Render flags ; Render flags
RENDER_ALT_BG1 equ $0001 RENDER_ALT_BG1 equ $0001
RENDER_BG1_HORZ_OFFSET equ $0002
RENDER_BG1_VERT_OFFSET equ $0004
; Tile constants ; Tile constants
; TILE_RESERVED_BIT equ $8000 ; TILE_RESERVED_BIT equ $8000

View File

@ -168,6 +168,8 @@ ENGINE_MODE_BNK0_BUFF equ $0004
; Render flags ; Render flags
RENDER_ALT_BG1 equ $0001 RENDER_ALT_BG1 equ $0001
RENDER_BG1_HORZ_OFFSET equ $0002
RENDER_BG1_VERT_OFFSET equ $0004
; DirtyBits definitions ; DirtyBits definitions
DIRTY_BIT_BG0_X equ $0001 DIRTY_BIT_BG0_X equ $0001
@ -260,6 +262,7 @@ _stamp_step EXT
VBuffVertTableSelect EXT VBuffVertTableSelect EXT
VBuffHorzTableSelect EXT VBuffHorzTableSelect EXT
Overlays EXT Overlays EXT
BG1YCache EXT
; Tool error codes ; Tool error codes
NO_TIMERS_AVAILABLE equ 10 NO_TIMERS_AVAILABLE equ 10

View File

@ -133,8 +133,9 @@ _DoTimers
sbc LastTick sbc LastTick
stx LastTick stx LastTick
; We don't want times to fire excessively. If the timer hasn't been evaluated for over ; We don't want timers to fire excessively. If the timer hasn't been evaluated for over
; one second, then just skip processing and wait for the next call. ; one second, then just skip processing and wait for the next call.
cmp #60 cmp #60
bcc :do_timer bcc :do_timer
:exit rts :exit rts

View File

@ -91,6 +91,7 @@ _CallTable
adrl _TSFillTileStore-1 adrl _TSFillTileStore-1
adrl _TSRefresh-1 adrl _TSRefresh-1
adrl _TSRenderDirty-1 adrl _TSRenderDirty-1
adrl _TSSetBG1Displacement-1
_CTEnd _CTEnd
_GTEAddSprite MAC _GTEAddSprite MAC
UserTool $1000+GTEToolNum UserTool $1000+GTEToolNum
@ -616,11 +617,11 @@ _TSAddTimer
lda :callback+2,s lda :callback+2,s
tax tax
lda :callback,s lda :numTicks,s
tay tay
lda :flags,s lda :flags,s
lsr ; put low bit into carry ror ; put low bit into carry
lda :numTicks,s lda :callback,s
jsr _AddTimer jsr _AddTimer
sta :output,s sta :output,s
ldx #0 ldx #0
@ -735,6 +736,18 @@ _TSRefresh
jsr _Refresh jsr _Refresh
_TSExit #0;#0 _TSExit #0;#0
; SetBG1Displacement(offset)
_TSSetBG1Displacement
:offset equ FirstParam+0
_TSEntry
lda :offset,s
and #$001E
sta BG1OffsetIndex
_TSExit #0;#2
; Insert the GTE code ; Insert the GTE code
put Math.s put Math.s

View File

@ -80,7 +80,12 @@ _CopyToBG1
bcc :cloop bcc :cloop
ldy #164 ldy #164
lda [:srcptr] ; Duplicate the last byte in the extra space at the end of the line lda [:srcptr] ; Duplicate the last couple of words in the extra space at the end of the line
sta [:dstptr],y
ldy #2
lda [:srcptr],y
ldy #166
sta [:dstptr],y sta [:dstptr],y
lda :srcptr lda :srcptr
@ -237,10 +242,21 @@ _ApplyBG1YPos
asl asl
tax tax
lda RenderFlags
bit #RENDER_BG1_HORZ_OFFSET ; Are we using horizontal displacement?
beq :no_displacement
lda :ytbl_idx ; Read from this location in the BG1YTable
asl
jsr CopyBG1YTableToBG1Addr2
bra :next_step
:no_displacement
lda :ytbl_idx ; Read from this location in the BG1YTable lda :ytbl_idx ; Read from this location in the BG1YTable
asl asl
jsr CopyBG1YTableToBG1Addr ; or CopyBG1YTableToBG1Addr2 jsr CopyBG1YTableToBG1Addr ; or CopyBG1YTableToBG1Addr2
:next_step
lda :virt_line ; advance to the virtual line after the segment we just lda :virt_line ; advance to the virtual line after the segment we just
clc ; filled in clc ; filled in
adc :draw_count adc :draw_count
@ -347,8 +363,10 @@ CopyBG1YTableToBG1Addr2
phy ; save the registers phy ; save the registers
phx phx
phb phb
pha
jsr _SetDataBank ; Set to toolbox data bank
jsr _SetDataBank ; restore access to this bank pla
ldy BG1OffsetIndex ; Get the offset and save the values ldy BG1OffsetIndex ; Get the offset and save the values
jsr SaveBG1OffsetValues jsr SaveBG1OffsetValues
@ -485,6 +503,4 @@ ApplyBG1OffsetValues
sta BG1_ADDR+$1000,y sta BG1_ADDR+$1000,y
:do01 ldal BG1YCache+00 :do01 ldal BG1YCache+00
sta: BG1_ADDR+$0000,y sta: BG1_ADDR+$0000,y
:none rts :none rts
BG1YCache ds 32

View File

@ -375,10 +375,14 @@ BG1YTable ENT
]step = ]step+256 ]step = ]step+256
--^ --^
BG1YCache ENT
ds 32
; Repeat ; Repeat
BG1YOffsetTable ENT BG1YOffsetTable ENT
lup 26 lup 2
dw 1,1,1,2,2,2,2,2,1,1,1,0,0,0,0,0 dw 1,1,1,2,2,2,2,2,1,1,1,0,0,0,0,0
; dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
--^ --^
; Other Toolset variables ; Other Toolset variables