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
12 .include "../cbm/cbm.inc"
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
25 sp: .res 2 ; Stack pointer
26 sreg: .res 2 ; Secondary register/high 16 bit for longs
27 regsave: .res 2 ; slot to save/restore (E)AX into
36 regbank: .res 6 ; 6 byte register bank
38 zpspace = * - zpstart ; Zero page space allocated
42 ; ------------------------------------------------------------------------
43 ; BASIC header with a SYS call
46 .word Head ; Load address
48 .word 1000 ; Line number
49 .byte $9E,"4109" ; SYS 4109
50 .byte $00 ; End of BASIC line
51 @Next: .word 0 ; BASIC end marker
54 ; ------------------------------------------------------------------------
59 sta zpsave,x ; save the zero page locations we need
67 ; Switch to second charset
76 ; Save system stuff and setup the stack
79 stx spsave ; save system stk ptr
82 jsr MEMTOP ; Get top memory
83 cpy #$80 ; We can only use the low 32K :-(
88 sty sp+1 ; set argument stack ptr
90 ; Call module constructors
94 ; Pass an empty command line
99 ldy #4 ; Argument size
100 jsr _main ; call the users code
102 ; Call module destructors. This is also the _exit entry.
104 _exit: jsr donelib ; Run module destructors
106 ; Restore system stuff
111 ; Copy back the zero page stuff
119 ; Reset changed vectors