2 ; Startup code for cc65 (Plus/4 version)
4 ; This must be the *first* file on the linker command line
8 .import initlib, donelib
9 .import push0, _main, zerobss
10 .import MEMTOP, RESTOR, BSOUT, CLRCH
12 .include "zeropage.inc"
16 ; ------------------------------------------------------------------------
17 ; BASIC header with a SYS call
22 .word Head ; Load address
24 .word 1000 ; Line number
25 .byte $9E,"4109" ; SYS 4109
26 .byte $00 ; End of BASIC line
27 @Next: .word 0 ; BASIC end marker
30 ; ------------------------------------------------------------------------
35 sta zpsave,x ; save the zero page locations we need
43 ; Switch to second charset
52 ; Save system stuff and setup the stack
55 stx spsave ; save system stk ptr
58 jsr MEMTOP ; Get top memory
59 cpy #$80 ; We can only use the low 32K :-(
64 sty sp+1 ; set argument stack ptr
66 ; Call module constructors
70 ; Pass an empty command line
75 ldy #4 ; Argument size
76 jsr _main ; call the users code
78 ; Call module destructors. This is also the _exit entry.
80 _exit: jsr donelib ; Run module destructors
82 ; Restore system stuff
87 ; Copy back the zero page stuff
95 ; Reset changed vectors