;
.export _exit
- .import __hinit, initconio, zerobss, push0, doatexit
+ .import initlib, donelib
+ .import zerobss, push0
.import _main
.include "pet.inc"
lda MEMSIZE+1
sta sp+1 ; Set argument stack ptr
-; Initialize the heap
+; Call module constructors
- jsr __hinit
-
-; Initialize conio stuff
-
- jsr initconio
+ jsr initlib
; Pass an empty command line
ldy #4 ; Argument size
jsr _main ; call the users code
-; fall thru to exit...
+; Call module destructors. This is also the _exit entry.
+
+_exit: jsr donelib ; Run module destructors
-_exit: jsr doatexit ; call exit functions
+; Restore system stuff
ldx spsave
txs ; Restore stack pointer