diff --git a/libsrc/pet/crt0.s b/libsrc/pet/crt0.s index 1d5641a7c..1e63617c2 100644 --- a/libsrc/pet/crt0.s +++ b/libsrc/pet/crt0.s @@ -70,10 +70,6 @@ L1: lda sp,x 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__ @@ -89,13 +85,21 @@ L1: lda sp,x 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 @@ -105,13 +109,9 @@ _exit: pha ; Save the return code on stack 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 diff --git a/libsrc/plus4/crt0.s b/libsrc/plus4/crt0.s index 42833b87a..c5ce0c7a1 100644 --- a/libsrc/plus4/crt0.s +++ b/libsrc/plus4/crt0.s @@ -80,16 +80,16 @@ L1: lda sp,x 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 @@ -97,9 +97,12 @@ L1: lda sp,x ; 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