2 ; Startup code for cc65 (Plus/4 version)
4 ; This must be the *first* file on the linker command line
8 .import initlib, donelib
10 .import initconio, doneconio, zerobss
13 .include "../cbm/cbm.inc"
15 ; ------------------------------------------------------------------------
16 ; Define and export the ZP variables for the C64 runtime
18 .exportzp sp, sreg, regsave
19 .exportzp ptr1, ptr2, ptr3, ptr4
20 .exportzp tmp1, tmp2, tmp3, tmp4
21 .exportzp regbank, zpspace
26 sp: .res 2 ; Stack pointer
27 sreg: .res 2 ; Secondary register/high 16 bit for longs
28 regsave: .res 2 ; slot to save/restore (E)AX into
37 regbank: .res 6 ; 6 byte register bank
39 zpspace = * - zpstart ; Zero page space allocated
43 ; ------------------------------------------------------------------------
44 ; BASIC header with a SYS call
47 .word Head ; Load address
49 .word 1000 ; Line number
50 .byte $9E,"4109" ; SYS 4109
51 .byte $00 ; End of BASIC line
52 @Next: .word 0 ; BASIC end marker
55 ; ------------------------------------------------------------------------
60 sta zpsave,x ; save the zero page locations we need
68 ; Switch to second charset
77 ; Save system stuff and setup the stack
80 stx spsave ; save system stk ptr
83 jsr MEMTOP ; Get top memory
84 cpy #$80 ; We can only use the low 32K :-(
89 sty sp+1 ; set argument stack ptr
91 ; Call module constructors
95 ; Initialize conio stuff
99 ; Pass an empty command line
104 ldy #4 ; Argument size
105 jsr _main ; call the users code
107 ; Call module destructors. This is also the _exit entry.
109 _exit: jsr donelib ; Run module destructors
111 ; Restore system stuff
116 ; Reset the conio stuff
120 ; Copy back the zero page stuff
128 ; Reset changed vectors