NoIRQ1: jsr callmain
-; Back from main (this is also the _exit entry). Store the return code into
-; ST, where it is accessible from BASIC. Reset the IRQ vector if we chained
-; it.
+; Back from main (this is also the _exit entry). Reset the IRQ vector if we
+; chained it.
-_exit: sta ST
+_exit: pha ; Save the return code on stack
lda #<__IRQFUNC_COUNT__
beq NoIRQ2
lda IRQInd+1
lda mmusave
sta MMU_CR
+; Place the program return code into ST
+
+ pla
+ sta ST
+
; Done, restore kernal vectors in an attempt to cleanup
jmp RESTOR
; Call module destructors. This is also the _exit entry.
-_exit: jsr donelib ; Run module destructors
+_exit: pha ; Save the return code on stack
+ jsr donelib ; Run module destructors
; Restore system stuff
dex
bpl L2
+; Store the return code into ST
+
+ pla
+ sta ST
+
; Reset changed vectors
jmp RESTOR
; Call module destructors. This is also the _exit entry.
-_exit: sta ST ; Place return code into ST
+_exit: pha ; Save the return code
jsr donelib ; Run module destructors
; Restore system stuff
dex
bpl L2
+; Place the program return code into ST
+
+ pla
+ sta ST
+
; Reset changed vectors, back to basic
jmp RESTOR
; Call module destructors. This is also the _exit entry and the default entry
; point for the break vector.
-_exit: lda #$00
+_exit: pha ; Save the return code on stack
+ lda #$00
sta irqcount ; Disable custom irq handlers
jsr donelib ; Run module destructors
bne @L0
.endif
+; Place the program return code into ST
+
+ pla
+ ldy #ST
+ sta (sysp0),y
+
; Setup the welcome code at the stack bottom in the system bank.
ldy #$FF
; Call module destructors. This is also the _exit entry and the default entry
; point for the break vector.
-_exit: lda #$00
+_exit: pha ; Save the return code
+ lda #$00
sta irqcount ; Disable custom irq handlers
jsr donelib ; Run module destructors
bne @L0
.endif
+; Place the program return code into ST
+
+ pla
+ ldy #ST
+ sta (sysp0),y
+
; Setup the welcome code at the stack bottom in the system bank.
ldy #$FF
; Call module destructors. This is also the _exit entry.
-_exit: jsr donelib ; Run module destructors
+_exit: pha ; Save the return code on stack
+ jsr donelib ; Run module destructors
; Restore system stuff
dex
bpl L2
+; Store the program return code into ST
+
+ pla
+ sta ST
+
; Back to basic
rts
; Back from main (this is also the _exit entry). Run module destructors.
-_exit: lda #0
+_exit: pha ; Save the return code
+ lda #0
sta irqcount ; Disable custom IRQ handlers
jsr donelib ; Run module destructors
dex
bpl L2
+; Place the program return code into ST
+
+ pla
+ sta ST
+
; Enable the ROM, reset changed vectors and return to BASIC
sta ENABLE_ROM
; Call module destructors. This is also the _exit entry.
-_exit: jsr donelib ; Run module destructors
+_exit: pha ; Save the return code on stack
+ jsr donelib ; Run module destructors
; Restore system stuff
dex
bpl L2
+; Place the program return code into ST
+
+ pla
+ sta ST
+
; Reset changed vectors, back to basic
jmp RESTOR