2 ; Startup code for cc65 (C64 version)
6 .export __STARTUP__ : absolute = 1 ; Mark as startup
8 .import initlib, donelib
9 .import zerobss, callmain
11 .import __MAIN_START__, __MAIN_SIZE__ ; Linker generated
12 .import __STACKSIZE__ ; from configure file
15 .include "zeropage.inc"
19 ; ------------------------------------------------------------------------
26 ; Switch off the BASIC ROM.
29 sta mmusave ; Save the memory configuration
31 ora #$06 ; Enable Kernal+I/O, disable BASIC
35 stx spsave ; Save the system stack ptr
37 ; Save space by putting some of the start-up code in the ONCE segment,
38 ; which can be re-used by the BSS segment, the heap and the C stack.
46 ; Push the command-line arguments; and, call main().
50 ; Back from main() [this is also the exit() entry]. Run the module destructors.
52 _exit: pha ; Save the return code on stack
55 ; Copy back the zero-page stuff.
63 ; Place the program return code into BASIC's status variable.
68 ; Restore the system stuff.
71 txs ; Restore stack pointer
73 stx $01 ; Restore memory configuration
80 ; ------------------------------------------------------------------------
86 ; Save the zero-page locations that we need.
96 lda #<(__MAIN_START__ + __MAIN_SIZE__)
97 ldx #>(__MAIN_START__ + __MAIN_SIZE__)
99 stx sp+1 ; Set argument stack ptr
101 ; Switch to the second charset.
106 ; Call the module constructors.
111 ; ------------------------------------------------------------------------