2 ; Startup code for cc65 (Apple2 version)
4 ; This must be the *first* file on the linker command line
8 .import initlib, donelib
10 .import __STARTUP_LOAD__, __BSS_LOAD__ ; Linker generated
13 .include "zeropage.inc"
16 ; ------------------------------------------------------------------------
17 ; The executable header
21 .word __STARTUP_LOAD__ ; Start address
22 .word __BSS_LOAD__ - __STARTUP_LOAD__ ; Size
24 ; ------------------------------------------------------------------------
25 ; Place the startup code in a special segment.
31 sta zpsave,x ; Save the zero page locations we need
39 ; Save system stuff and setup the stack
42 stx spsave ; Save the system stack ptr
47 sta sp+1 ; Set argument stack ptr
49 ; Call module constructors
53 ; Initialize conio stuff
58 ; Set up to use Apple ROM $C000-$CFFF
62 ; Push arguments and call main()
66 ; Call module destructors. This is also the _exit entry.
70 ; Restore system stuff
72 lda #$ff ; Reset text mode
76 txs ; Restore stack pointer
78 ; Copy back the zero page stuff
86 ; Reset changed vectors, back to basic
90 ; ------------------------------------------------------------------------