2 ; Startup code for cc65 (Apple2 version)
4 ; This must be the *first* file on the linker command line
8 .import initlib, donelib
14 ; ------------------------------------------------------------------------
15 ; Define and export the ZP variables for the C64 runtime
17 .exportzp sp, sreg, regsave
18 .exportzp ptr1, ptr2, ptr3, ptr4
19 .exportzp tmp1, tmp2, tmp3, tmp4
20 .exportzp regbank, zpspace
22 ; These zero page entries overlap with the sweet-16 registers in
23 ; the standard apple2 linker config. They must be changed if sweet-16
29 sp: .res 2 ; Stack pointer
30 sreg: .res 2 ; Secondary register/high 16 bit for longs
31 regsave: .res 2 ; slot to save/restore (E)AX into
40 regbank: .res 6 ; 6 byte register bank
42 zpspace = * - zpstart ; Zero page space allocated
46 ; ------------------------------------------------------------------------
51 sta zpsave,x ; Save the zero page locations we need
59 ; Save system stuff and setup the stack
62 stx spsave ; Save the system stack ptr
67 sta sp+1 ; Set argument stack ptr
69 ; Call module constructors
73 ; Initialize conio stuff
78 ; Set up to use Apple ROM $C000-$CFFF
82 ; Pass an empty command line
87 ldy #4 ; Argument size
88 jsr _main ; call the users code
90 ; Call module destructors. This is also the _exit entry.
94 ; Restore system stuff
96 lda #$ff ; Reset text mode
100 txs ; Restore stack pointer
102 ; Copy back the zero page stuff
110 ; Reset changed vectors, back to basic