NoIRQ1: jsr callmain
-; Back from main (this is also the _exit entry). Reset the IRQ vector if
-; we chained it.
+; 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.
-_exit: lda #<__IRQFUNC_COUNT__
+_exit: sta ST
+ lda #<__IRQFUNC_COUNT__
beq NoIRQ2
lda IRQInd+1
ldx IRQInd+2
; Call module destructors. This is also the _exit entry.
-_exit: jsr donelib ; Run module destructors
+_exit: sta ST ; Place return code into ST
+ jsr donelib ; Run module destructors
; Restore system stuff