fix variable init order mistake in program startup

reset multiply bit at end of verafx.muls
This commit is contained in:
Irmen de Jong 2024-09-28 18:12:21 +02:00
parent c78b7b1a24
commit 1541ad2160
10 changed files with 32 additions and 34 deletions

View File

@ -470,6 +470,9 @@ internal class ProgramAndVarsGen(
} }
private fun entrypointInitialization() { private fun entrypointInitialization() {
// zero out the BSS area first, before setting the variable init values
asmgen.out(" jsr prog8_lib.program_startup_clear_bss")
// initialize block-level (global) variables at program start // initialize block-level (global) variables at program start
blockVariableInitializers.forEach { blockVariableInitializers.forEach {
if (it.value.isNotEmpty()) if (it.value.isNotEmpty())
@ -521,8 +524,7 @@ internal class ProgramAndVarsGen(
arrayVariable2asm(varname, it.alloc.dt, it.value, null) arrayVariable2asm(varname, it.alloc.dt, it.value, null)
} }
// zero out the BSS area asmgen.out("+")
asmgen.out("+ jsr prog8_lib.program_startup_clear_bss")
} }
private class ZpStringWithInitial( private class ZpStringWithInitial(

View File

@ -29,10 +29,7 @@ sys {
; TODO ; TODO
%asm {{ %asm {{
sei sei
cld
clc
; TODO reset screen mode etc etc ; TODO reset screen mode etc etc
clv
cli cli
rts rts
}} }}
@ -40,7 +37,10 @@ sys {
asmsub init_system_phase2() { asmsub init_system_phase2() {
%asm {{ %asm {{
rts ; no phase 2 steps on the Atari cld
clc
clv
rts
}} }}
} }

View File

@ -360,7 +360,6 @@ asmsub init_system() {
; Uppercase charset is activated. ; Uppercase charset is activated.
%asm {{ %asm {{
sei sei
cld
lda #0 lda #0
sta $ff00 ; select default bank 15 sta $ff00 ; select default bank 15
jsr cbm.IOINIT jsr cbm.IOINIT
@ -373,8 +372,6 @@ asmsub init_system() {
lda #0 lda #0
sta c64.BGCOL0 sta c64.BGCOL0
jsr disable_runstop_and_charsetswitch jsr disable_runstop_and_charsetswitch
clc
clv
cli cli
rts rts
}} }}
@ -382,7 +379,10 @@ asmsub init_system() {
asmsub init_system_phase2() { asmsub init_system_phase2() {
%asm {{ %asm {{
rts ; no phase 2 steps on the C128 cld
clc
clv
rts
}} }}
} }

View File

@ -357,7 +357,6 @@ asmsub init_system() {
; Uppercase charset is activated. ; Uppercase charset is activated.
%asm {{ %asm {{
sei sei
cld
lda #%00101111 lda #%00101111
sta $00 sta $00
lda #%00100111 lda #%00100111
@ -372,8 +371,6 @@ asmsub init_system() {
lda #0 lda #0
sta c64.BGCOL0 sta c64.BGCOL0
jsr disable_runstop_and_charsetswitch jsr disable_runstop_and_charsetswitch
clc
clv
cli cli
rts rts
}} }}
@ -381,7 +378,10 @@ asmsub init_system() {
asmsub init_system_phase2() { asmsub init_system_phase2() {
%asm {{ %asm {{
rts ; no phase 2 steps on the C64 cld
clc
clv
rts
}} }}
} }

View File

@ -1370,7 +1370,6 @@ asmsub init_system() {
tax tax
tay tay
jsr cx16.mouse_config ; disable mouse jsr cx16.mouse_config ; disable mouse
cld
lda cx16.VERA_DC_VIDEO lda cx16.VERA_DC_VIDEO
and #%00000111 ; retain chroma + output mode and #%00000111 ; retain chroma + output mode
sta P8ZP_SCRATCH_REG sta P8ZP_SCRATCH_REG
@ -1400,8 +1399,6 @@ asmsub init_system() {
lda #0 lda #0
tax tax
tay tay
clc
clv
cli cli
rts rts
}} }}
@ -1417,6 +1414,9 @@ asmsub init_system_phase2() {
lda #PROG8_VARSHIGH_RAMBANK lda #PROG8_VARSHIGH_RAMBANK
sta $00 ; select ram bank sta $00 ; select ram bank
cli cli
cld
clc
clv
rts rts
}} }}
} }

View File

@ -179,6 +179,7 @@ verafx {
ldx cx16.VERA_DATA0 ldx cx16.VERA_DATA0
stx cx16.r0s+1 stx cx16.r0s+1
stz cx16.VERA_FX_CTRL ; Cache write disable stz cx16.VERA_FX_CTRL ; Cache write disable
stz cx16.VERA_FX_MULT ; $9F2C reset multiply bit
stz cx16.VERA_CTRL ; reset DCSEL stz cx16.VERA_CTRL ; reset DCSEL
rts rts
}} }}

View File

@ -104,13 +104,10 @@ asmsub init_system() {
; Uppercase charset is activated. ; Uppercase charset is activated.
%asm {{ %asm {{
sei sei
cld
lda #142 lda #142
jsr cbm.CHROUT ; uppercase jsr cbm.CHROUT ; uppercase
lda #147 lda #147
jsr cbm.CHROUT ; clear screen jsr cbm.CHROUT ; clear screen
clc
clv
cli cli
rts rts
}} }}
@ -118,7 +115,10 @@ asmsub init_system() {
asmsub init_system_phase2() { asmsub init_system_phase2() {
%asm {{ %asm {{
rts ; no phase 2 steps on the PET cld
clc
clv
rts
}} }}
} }

View File

@ -18,8 +18,6 @@ program_startup_clear_bss .proc
lda #0 lda #0
jsr prog8_lib.memset jsr prog8_lib.memset
.endif .endif
clv
clc
rts rts
.pend .pend

View File

@ -1,6 +1,9 @@
TODO TODO
==== ====
Commit "tweak program start initialization and fix cleanup at exit for atari and pet compiler targets #04cb684f" causing programs to crash (assem, rockrunner)
Improve register load order in subroutine call args assignments: Improve register load order in subroutine call args assignments:
in certain situations, the "wrong" order of evaluation of function call arguments is done which results in certain situations, the "wrong" order of evaluation of function call arguments is done which results
in overwriting registers that already got their value, which requires a lot of stack juggling (especially on plain 6502 cpu!) in overwriting registers that already got their value, which requires a lot of stack juggling (especially on plain 6502 cpu!)

View File

@ -1,20 +1,14 @@
%import textio %import textio
%import verafx
%zeropage basicsafe %zeropage basicsafe
%option no_sysinit %option no_sysinit
main { main {
ubyte @shared @nozp value1 = 99
word @shared w1 = -30 ubyte @shared @requirezp value2 = 42
word @shared w2 = -40
uword @shared uw1 = 9999
uword @shared uw2 = 4
sub start() { sub start() {
cx16.r0 = 12345 txt.print_ub(value1)
txt.print_uw(verafx.mult16(uw1, uw2)) txt.nl()
txt.spc() txt.print_ub(value2)
txt.print_uw(uw1 * uw2)
txt.nl() txt.nl()
} }
} }