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, _main, 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 ; Pass an empty command line
83 ldy #4 ; Argument size
84 jsr _main ; call the users code
86 ; Call module destructors. This is also the _exit entry.
88 _exit: jsr donelib ; Run module destructors
90 ; Restore system stuff
95 ; Copy back the zero page stuff
103 ; Reset changed vectors