2 ; Startup code for cc65 (C64 version)
6 .export __STARTUP__ : absolute = 1 ; Mark as startup
7 .import initlib, donelib
10 .import RESTOR, BSOUT, CLRCH
11 .import __RAM_START__, __RAM_SIZE__ ; Linker generated
12 .import __STACKSIZE__ ; Linker generated
15 .include "zeropage.inc"
19 ; ------------------------------------------------------------------------
26 ; Save the zero-page locations that we need.
34 ; Switch to the second charset.
39 ; Switch off the BASIC ROM.
42 pha ; Remember the value
44 ora #$06 ; Enable Kernal+I/O, disable BASIC
51 ; Save some system settings; and, set up the stack.
54 sta mmusave ; Save the memory configuration
57 stx spsave ; Save the system stack ptr
59 lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
61 lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
62 sta sp+1 ; Set argument stack ptr
64 ; Call the module constructors.
68 ; Push the command-line arguments; and, call main().
72 ; Back from main() [this is also the exit() entry]. Run the module destructors.
74 _exit: pha ; Save the return code on stack
77 ; Copy back the zero-page stuff.
85 ; Place the program return code into BASIC's status variable.
90 ; Restore the system stuff.
93 txs ; Restore stack pointer
95 stx $01 ; Restore memory configuration
101 ; ------------------------------------------------------------------------