Fix restore code field bug. SMB demo can use renderer

This commit is contained in:
Lucas Scharenbroich 2023-06-26 14:15:20 -05:00
parent eb548343a7
commit 6a0b8cbdc1
3 changed files with 28 additions and 17 deletions

View File

@ -160,7 +160,9 @@ ExtFuncBlock
; Special NES renderer that externalizes the sprite rendering in order to exceed the internal limit of 16 sprites ; Special NES renderer that externalizes the sprite rendering in order to exceed the internal limit of 16 sprites
_RenderNES _RenderNES
jsr _ApplyBG0YPos ; jsr _ApplyBG0YPos
; jsr _ApplyBG0XPosPre
jsr _ApplyBG0YPosLite
jsr _ApplyBG0XPosPre jsr _ApplyBG0XPosPre
; Callback to update the tilestore with any new tiles ; Callback to update the tilestore with any new tiles
@ -182,7 +184,8 @@ _RenderNES
lda #16*2 lda #16*2
sta tmp2 ; lines_left_x2 sta tmp2 ; lines_left_x2
lda #0 ; Xmod164 lda #0 ; Xmod164
jsr _ApplyBG0XPosAlt ; jsr _ApplyBG0XPosAlt
jsr _ApplyBG0XPosAltLite
lda tmp4 ; :exit_offset lda tmp4 ; :exit_offset
stal nesTopOffset stal nesTopOffset
@ -194,7 +197,8 @@ _RenderNES
asl asl
sta tmp2 ; lines_left_x2 sta tmp2 ; lines_left_x2
lda StartXMod164 ; Xmod164 lda StartXMod164 ; Xmod164
jsr _ApplyBG0XPosAlt ; jsr _ApplyBG0XPosAlt
jsr _ApplyBG0XPosAltLite
lda tmp4 lda tmp4
stal nesBottomOffset stal nesBottomOffset
@ -246,7 +250,8 @@ _RenderNES
sta tmp2 ; :lines_left_x2 sta tmp2 ; :lines_left_x2
ldal nesTopOffset ldal nesTopOffset
sta tmp4 ; :exit_offset sta tmp4 ; :exit_offset
jsr _RestoreBG0OpcodesAlt ; jsr _RestoreBG0OpcodesAlt
jsr _RestoreBG0OpcodesAltLite
lda #16*2 lda #16*2
sta tmp1 ; :virt_line_x2 sta tmp1 ; :virt_line_x2
@ -257,7 +262,8 @@ _RenderNES
sta tmp2 ; lines_left_x2 sta tmp2 ; lines_left_x2
ldal nesBottomOffset ldal nesBottomOffset
sta tmp4 ; :exit_offset sta tmp4 ; :exit_offset
jsr _RestoreBG0OpcodesAlt ; jsr _RestoreBG0OpcodesAlt
jsr _RestoreBG0OpcodesAltLite
; lda StartYMod208 ; Restore the fields back to their original state ; lda StartYMod208 ; Restore the fields back to their original state
; ldx ScreenHeight ; ldx ScreenHeight

View File

@ -442,7 +442,8 @@ _UTDPatch jsl UserHook1 ; Call the users code
cmp #0 cmp #0
beq :done beq :done
jmp FastCopyTmpDataA ; Non-zero value to continue additional work ; jmp FastCopyTmpDataA ; Non-zero value to continue additional work
jmp LiteCopyTmpDataA
:done :done
rts rts

View File

@ -245,9 +245,9 @@ _ApplyBG0XPosAltLite
; to account for the position of the BRL instruction ; to account for the position of the BRL instruction
tax tax
lda Col2CodeOffset-2,x ; offset from _LOOP (0 to 249 step 3) lda Col2CodeOffset-2,x ; offset from base
clc clc
adc #-_ENTRY_JMP+3 adc #-{_ENTRY_JMP+3}
sta :opcode sta :opcode
; Now update the code field to get ready to execute. We set the bank register to the code ; Now update the code field to get ready to execute. We set the bank register to the code
@ -323,11 +323,13 @@ _ApplyBG0XPosAltLite
ldy :entry_jmp_addr ldy :entry_jmp_addr
lda #$82 lda #$82
:do_setopcode_e jsr $0000 ; Copy in the BRL opcode into the entry point :do_setopcode_e jsr $0000 ; Copy in the BRL opcode into the entry point
rep #$20
ldx :exit_address ldx :exit_address
inx
ldy :low_save_addr ldy :low_save_addr
:do_save_entry_e jsr $0000 ; Copy a word from offset x to y iny
:do_save_entry_e jsr $0000 ; Copy a byte from offset x to y
rep #$20
ldy :exit_address ldy :exit_address
lda :exit_bra lda :exit_bra
@ -366,12 +368,12 @@ _ApplyBG0XPosAltLite
tax tax
lda Col2CodeOffset,x lda Col2CodeOffset,x
clc clc
adc #-_ENTRY_JMP+3 ; In this case it gets loaded in the X-register adc #-{_ENTRY_JMP+3} ; In this case it gets loaded in the X-register
sta :opcode sta :opcode
lda Col2CodeOffset-2,x lda Col2CodeOffset-2,x
clc clc
adc #-_ENTRY_ODD+3 adc #-{_ENTRY_ODD+3}
sta :odd_entry_offset sta :odd_entry_offset
; Main loop ; Main loop
@ -448,11 +450,13 @@ _ApplyBG0XPosAltLite
ldy :exit_odd_addr ldy :exit_odd_addr
iny iny
:do_save_high_byte jsr $0000 ; Copy high byte of the exit location into the odd handling path :do_save_high_byte jsr $0000 ; Copy high byte of the exit location into the odd handling path
rep #$20
ldx :exit_address ldx :exit_address
inx
ldy :low_save_addr ldy :low_save_addr
:do_save_entry_o jsr $0000 ; Save the low word of the exit into a save location for restore later iny
:do_save_entry_o jsr $0000 ; Save the low byte of the exit operand into a save location for restore later
rep #$20
ldy :exit_address ldy :exit_address
lda :exit_bra lda :exit_bra
@ -629,8 +633,8 @@ CopyXToYPrep mac
<<< <<<
]line equ 199 ]line equ 199
lup 200 lup 200
lda {]line*_LINE_SIZE},x lda: {]line*_LINE_SIZE},x
sta {]line*_LINE_SIZE},y sta: {]line*_LINE_SIZE},y
]line equ ]line-1 ]line equ ]line-1
--^ --^
x2y_bottom rts x2y_bottom rts
@ -646,7 +650,7 @@ LiteSetConstPrep mac
]line equ 199 ]line equ 199
lup 200 lup 200
sta {]line*_LINE_SIZE},y sta: {]line*_LINE_SIZE},y
]line equ ]line-1 ]line equ ]line-1
--^ --^
lsc_bottom rts lsc_bottom rts