2 ; Startup code for cc65 (C16 version)
4 ; This must be the *first* file on the linker command line
6 ; Note: The C16 is actually the Plus/4 with just 16KB of memory. So many
7 ; things are similar here, and we even use the plus4.inc include file.
11 .import initlib, donelib
12 .import push0, callmain, zerobss
13 .import MEMTOP, RESTOR, BSOUT, CLRCH
15 .include "zeropage.inc"
16 .include "../plus4/plus4.inc"
19 ; ------------------------------------------------------------------------
20 ; Create an empty LOWCODE segment to avoid linker warnings
24 ; ------------------------------------------------------------------------
25 ; Place the startup code in a special segment.
29 ; BASIC header with a SYS call
31 .word Head ; Load address
33 .word 1000 ; Line number
34 .byte $9E,"4109" ; SYS 4109
35 .byte $00 ; End of BASIC line
36 @Next: .word 0 ; BASIC end marker
38 ; ------------------------------------------------------------------------
43 sta zpsave,x ; save the zero page locations we need
51 ; Switch to second charset
60 ; Save system stuff and setup the stack
63 stx spsave ; save system stk ptr
66 jsr MEMTOP ; Get top memory
67 cpy #$80 ; We can only use the low 32K :-(
72 sty sp+1 ; set argument stack ptr
74 ; Call module constructors
78 ; Push arguments and call main()
82 ; Call module destructors. This is also the _exit entry.
84 _exit: jsr donelib ; Run module destructors
86 ; Restore system stuff
91 ; Copy back the zero page stuff
99 ; Reset changed vectors