]> git.sur5r.net Git - cc65/blobdiff - libsrc/c64/crt0.s
Place the return code into ST
[cc65] / libsrc / c64 / crt0.s
index 7144d61aecd56d985fadab5f73a65a7b4d49149d..98f391c28ea8388dd68a2927769bdb6680bd1b42 100644 (file)
@@ -82,7 +82,7 @@ L1:   lda     sp,x
 
 ; 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
@@ -100,6 +100,11 @@ L2:        lda     zpsave,x
        dex
                bpl     L2
 
+; Place the program return code into ST
+
+       pla
+       sta     ST
+
 ; Reset changed vectors, back to basic
 
        jmp     RESTOR