-; 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: pha ; Save the return code on stack
lda #<__IRQFUNC_COUNT__
beq NoIRQ2
lda IRQInd+1
lda #<__IRQFUNC_COUNT__
beq NoIRQ2
lda IRQInd+1
+; Place the program return code into ST
+
+ pla
+ sta ST
+
; Done, restore kernal vectors in an attempt to cleanup
jmp RESTOR
; Done, restore kernal vectors in an attempt to cleanup
jmp RESTOR
; Call module destructors. This is also the _exit entry.
; 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
+; Store the return code into ST
+
+ pla
+ sta ST
+
; Reset changed vectors
jmp RESTOR
; Reset changed vectors
jmp RESTOR
; Call module destructors. This is also the _exit entry.
; 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
jsr donelib ; Run module destructors
; Restore system stuff
+; Place the program return code into ST
+
+ pla
+ sta ST
+
; Reset changed vectors, back to basic
jmp RESTOR
; 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.
; Call module destructors. This is also the _exit entry and the default entry
; point for the break vector.
+_exit: pha ; Save the return code on stack
+ lda #$00
sta irqcount ; Disable custom irq handlers
jsr donelib ; Run module destructors
sta irqcount ; Disable custom irq handlers
jsr donelib ; Run module destructors
+; 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
; 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.
; Call module destructors. This is also the _exit entry and the default entry
; point for the break vector.
+_exit: pha ; Save the return code
+ lda #$00
sta irqcount ; Disable custom irq handlers
jsr donelib ; Run module destructors
sta irqcount ; Disable custom irq handlers
jsr donelib ; Run module destructors
+; 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
; Setup the welcome code at the stack bottom in the system bank.
ldy #$FF
; Call module destructors. This is also the _exit entry.
; 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
+; Store the program return code into ST
+
+ pla
+ sta ST
+
; Back from main (this is also the _exit entry). Run module destructors.
; Back from main (this is also the _exit entry). Run module destructors.
+_exit: pha ; Save the return code
+ lda #0
sta irqcount ; Disable custom IRQ handlers
jsr donelib ; Run module destructors
sta irqcount ; Disable custom IRQ handlers
jsr donelib ; Run module destructors
+; Place the program return code into ST
+
+ pla
+ sta ST
+
; Enable the ROM, reset changed vectors and return to BASIC
sta ENABLE_ROM
; Enable the ROM, reset changed vectors and return to BASIC
sta ENABLE_ROM
; Call module destructors. This is also the _exit entry.
; 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
+; Place the program return code into ST
+
+ pla
+ sta ST
+
; Reset changed vectors, back to basic
jmp RESTOR
; Reset changed vectors, back to basic
jmp RESTOR