mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
fix exit() now actually correctly setting the return code in A
also, moved some cleanup stuff such as CLRCHN from exit() to the cleanup routine that is always called. finally, also call the cleanup routine when %option no_sysinit is used
This commit is contained in:
parent
242a3eec63
commit
19a2110ba2
@ -133,7 +133,6 @@ internal class ProgramAndVarsGen(
|
||||
pha""")
|
||||
}
|
||||
|
||||
// make sure that on the cx16 and c64, basic rom is banked in again when we exit the program
|
||||
when(compTarget.name) {
|
||||
"cx16" -> {
|
||||
if(options.floats)
|
||||
@ -143,17 +142,11 @@ internal class ProgramAndVarsGen(
|
||||
}
|
||||
"c64" -> {
|
||||
asmgen.out(" jsr p8b_main.p8s_start | lda #31 | sta $01")
|
||||
if(!options.noSysInit)
|
||||
asmgen.out(" jmp sys.cleanup_at_exit")
|
||||
else
|
||||
asmgen.out(" rts")
|
||||
}
|
||||
"c128" -> {
|
||||
asmgen.out(" jsr p8b_main.p8s_start | lda #0 | sta ${"$"}ff00")
|
||||
if(!options.noSysInit)
|
||||
asmgen.out(" jmp sys.cleanup_at_exit")
|
||||
else
|
||||
asmgen.out(" rts")
|
||||
}
|
||||
else -> asmgen.jmp("p8b_main.p8s_start")
|
||||
}
|
||||
|
@ -252,9 +252,9 @@ save_SCRATCH_ZPWORD2 .word 0
|
||||
}}
|
||||
}
|
||||
|
||||
inline asmsub exit(ubyte returnvalue @A) {
|
||||
asmsub exit(ubyte returnvalue @A) {
|
||||
; -- immediately exit the program with a return code in the A register
|
||||
; TODO
|
||||
; TODO where to store A as exit code?
|
||||
%asm {{
|
||||
ldx prog8_lib.orig_stackpointer
|
||||
txs
|
||||
|
@ -373,7 +373,13 @@ asmsub init_system_phase2() {
|
||||
asmsub cleanup_at_exit() {
|
||||
; executed when the main subroutine does rts
|
||||
%asm {{
|
||||
jmp sys.enable_runstop_and_charsetswitch
|
||||
lda #0
|
||||
sta $ff00 ; default bank 15
|
||||
jsr cbm.CLRCHN ; reset i/o channels
|
||||
jsr enable_runstop_and_charsetswitch
|
||||
_exitcode = *+1
|
||||
lda #0 ; exit code possibly modified in exit()
|
||||
rts
|
||||
}}
|
||||
}
|
||||
|
||||
@ -754,16 +760,13 @@ _longcopy
|
||||
}}
|
||||
}
|
||||
|
||||
inline asmsub exit(ubyte returnvalue @A) {
|
||||
asmsub exit(ubyte returnvalue @A) {
|
||||
; -- immediately exit the program with a return code in the A register
|
||||
%asm {{
|
||||
lda #0
|
||||
sta $ff00 ; default bank 15
|
||||
jsr cbm.CLRCHN ; reset i/o channels
|
||||
jsr sys.enable_runstop_and_charsetswitch
|
||||
sta cleanup_at_exit._exitcode
|
||||
ldx prog8_lib.orig_stackpointer
|
||||
txs
|
||||
rts ; return to original caller
|
||||
jmp cleanup_at_exit
|
||||
}}
|
||||
}
|
||||
|
||||
|
@ -372,7 +372,13 @@ asmsub init_system_phase2() {
|
||||
asmsub cleanup_at_exit() {
|
||||
; executed when the main subroutine does rts
|
||||
%asm {{
|
||||
jmp sys.enable_runstop_and_charsetswitch
|
||||
lda #31
|
||||
sta $01 ; bank the kernal in
|
||||
jsr cbm.CLRCHN ; reset i/o channels
|
||||
jsr enable_runstop_and_charsetswitch
|
||||
_exitcode = *+1
|
||||
lda #0 ; exit code possibly modified in exit()
|
||||
rts
|
||||
}}
|
||||
}
|
||||
|
||||
@ -752,16 +758,13 @@ _longcopy
|
||||
}}
|
||||
}
|
||||
|
||||
inline asmsub exit(ubyte returnvalue @A) {
|
||||
asmsub exit(ubyte returnvalue @A) {
|
||||
; -- immediately exit the program with a return code in the A register
|
||||
%asm {{
|
||||
lda #31
|
||||
sta $01 ; bank the kernal in
|
||||
jsr cbm.CLRCHN ; reset i/o channels
|
||||
jsr sys.enable_runstop_and_charsetswitch
|
||||
sta cleanup_at_exit._exitcode
|
||||
ldx prog8_lib.orig_stackpointer
|
||||
txs
|
||||
rts ; return to original caller
|
||||
jmp cleanup_at_exit
|
||||
}}
|
||||
}
|
||||
|
||||
|
@ -1239,6 +1239,9 @@ asmsub cleanup_at_exit() {
|
||||
lda #4
|
||||
sta $01 ; rom bank 4 (basic)
|
||||
stz $2d ; hack to reset machine code monitor bank to 0
|
||||
jsr cbm.CLRCHN ; reset i/o channels
|
||||
_exitcode = *+1
|
||||
lda #0 ; exit code possibly modified in exit()
|
||||
rts
|
||||
}}
|
||||
}
|
||||
@ -1602,10 +1605,10 @@ save_SCRATCH_ZPWORD2 .word 0
|
||||
asmsub exit(ubyte returnvalue @A) {
|
||||
; -- immediately exit the program with a return code in the A register
|
||||
%asm {{
|
||||
jsr cbm.CLRCHN ; reset i/o channels
|
||||
sta cleanup_at_exit._exitcode
|
||||
ldx prog8_lib.orig_stackpointer
|
||||
txs
|
||||
rts ; return to original caller
|
||||
jmp cleanup_at_exit
|
||||
}}
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,8 @@ asmsub init_system_phase2() {
|
||||
asmsub cleanup_at_exit() {
|
||||
; executed when the main subroutine does rts
|
||||
%asm {{
|
||||
_exitcode = *+1
|
||||
lda #0 ; exit code possibly modified in exit()
|
||||
rts
|
||||
}}
|
||||
}
|
||||
@ -345,12 +347,13 @@ save_SCRATCH_ZPWORD2 .word 0
|
||||
}}
|
||||
}
|
||||
|
||||
inline asmsub exit(ubyte returnvalue @A) {
|
||||
asmsub exit(ubyte returnvalue @A) {
|
||||
; -- immediately exit the program with a return code in the A register
|
||||
%asm {{
|
||||
sta cleanup_at_exit._exitcode
|
||||
ldx prog8_lib.orig_stackpointer
|
||||
txs
|
||||
rts ; return to original caller
|
||||
jmp cleanup_at_exit
|
||||
}}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
keep Bool alive longer until codegen? (don't replace by UBYTE so quickly?)
|
||||
[on branch 'booleans']: keep Bool alive longer until codegen? (don't replace by UBYTE so quickly?)
|
||||
|
||||
...
|
||||
|
||||
|
@ -1,17 +1,21 @@
|
||||
%import textio
|
||||
%zeropage basicsafe
|
||||
%option no_sysinit
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
sub1()
|
||||
}
|
||||
|
||||
cx16.r0 = 500
|
||||
if cx16.r0 in 127 to 5555
|
||||
sub sub1() {
|
||||
cx16.r0++
|
||||
|
||||
|
||||
cx16.r0 = 50
|
||||
if cx16.r0 in 5555 downto 127
|
||||
sub2()
|
||||
}
|
||||
sub sub2() {
|
||||
cx16.r0++
|
||||
|
||||
sub3()
|
||||
}
|
||||
sub sub3() {
|
||||
cx16.r0++
|
||||
sys.exit(42)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user