2 ; Startup code for cc65 (C64 version)
6 .exportzp init_load_, init_run_
7 .export __STARTUP__ : absolute = 1 ; Mark as startup
9 .import initlib, donelib
10 .import move_init, zerobss, callmain
11 .import RESTOR, BSOUT, CLRCH
12 .import __HIMEM__ ; from configure file
15 .include "zeropage.inc"
19 ; ------------------------------------------------------------------------
22 ; Two zero-page pointers are needed before any zero-page stuff is saved.
23 ; Choose locations that are not used by anything.
33 ; Switch to the second charset.
38 ; Switch off the BASIC ROM.
41 sta mmusave ; Save the memory configuration
43 ora #$06 ; Enable Kernal+I/O, disable BASIC
47 stx spsave ; Save the system stack ptr
49 ; Allow some re-entrancy by skipping the next task if it already was done.
50 ; This often can let us rerun the program without reloading it.
55 ; Move the INIT segment from where it was loaded (over ZPSAVE and BSS)
56 ; into where it must be run (in the heap).
59 dec moveinit ; set to false
61 ; Save space by putting the rest of the start-up code in the INIT segment,
62 ; which can be re-used by the heap.
66 ; Back from main() [this is also the exit() entry]. Run the module destructors.
68 _exit: pha ; Save the return code on stack
71 ; Copy back the zero-page stuff.
79 ; Place the program return code into BASIC's status variable.
84 ; Restore the system stuff.
87 txs ; Restore stack pointer
89 stx $01 ; Restore memory configuration
96 ; ------------------------------------------------------------------------
102 ; Save the zero-page locations that we need.
110 ; Clear the BSS data.
119 stx sp+1 ; Set argument stack ptr
121 ; Call the module constructors.
125 ; Push the command-line arguments; and, call main().
130 ; ------------------------------------------------------------------------