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 ; Place the startup code in a special segment.
24 ; BASIC header with a SYS call
26 .word Head ; Load address
28 .word 1000 ; Line number
29 .byte $9E,"4109" ; SYS 4109
30 .byte $00 ; End of BASIC line
31 @Next: .word 0 ; BASIC end marker
33 ; ------------------------------------------------------------------------
38 sta zpsave,x ; save the zero page locations we need
46 ; Switch to second charset
55 ; Save system stuff and setup the stack
58 stx spsave ; save system stk ptr
61 jsr MEMTOP ; Get top memory
62 cpy #$80 ; We can only use the low 32K :-(
67 sty sp+1 ; set argument stack ptr
69 ; Call module constructors
73 ; Push arguments and call main()
77 ; Call module destructors. This is also the _exit entry.
79 _exit: jsr donelib ; Run module destructors
81 ; Restore system stuff
86 ; Copy back the zero page stuff
94 ; Reset changed vectors