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 we need
34 ; Switch to second charset
39 ; Switch off the BASIC ROM
42 pha ; Remember the value
44 ora #$06 ; Enable kernal+I/O, disable basic
51 ; Save system settings and setup 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 module constructors
68 ; Push arguments and call main
72 ; Back from main (This is also the _exit entry). Run 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 ST
90 ; Restore system stuff
93 txs ; Restore stack pointer
95 stx $01 ; Restore memory configuration
101 ; ------------------------------------------------------------------------