lda MEMSIZE+1
sta sp+1 ; Set argument stack ptr
-; Call module constructors
-
- jsr initlib
-
; If we have IRQ functions, chain our stub into the IRQ vector
lda #<__INTERRUPTOR_COUNT__
stx IRQVec+1
cli
+; Call module constructors
+
+NoIRQ1: jsr initlib
+
; Push arguments and call main()
-NoIRQ1: jsr callmain
+ jsr callmain
; Call module destructors. This is also the _exit entry.
-_exit: pha ; Save the return code on stack
+_exit: pha ; Save the return code on stack
+ jsr donelib
+
+; Reset the IRQ vector if we chained it.
+
lda #<__INTERRUPTOR_COUNT__
beq NoIRQ2
lda IRQInd+1
stx IRQVec+1
cli
-; Run module destructors
-
-NoIRQ2: jsr donelib ; Run module destructors
-
; Copy back the zero page stuff
- ldx #zpspace-1
+NoIRQ2: ldx #zpspace-1
L2: lda zpsave,x
sta sp,x
dex
jsr zerobss
-; Call module constructors
-
- jsr initlib
-
; Initialize irqcount, which means that from now own custom linked in IRQ
; handlers (via condes) will be called.
lda #.lobyte(__INTERRUPTOR_COUNT__*2)
sta irqcount
+; Call module constructors
+
+ jsr initlib
+
; Push arguments and call main()
jsr callmain
; Back from main (this is also the _exit entry). Run module destructors.
_exit: pha ; Save the return code
+ jsr donelib ; Run module destructors
+
+; Disable chained IRQ handlers
+
lda #0
sta irqcount ; Disable custom IRQ handlers
- jsr donelib ; Run module destructors
; Copy back the zero page stuff