2 ; Startup code for cc65 (PET version)
4 ; This must be the *first* file on the linker command line
8 .import initlib, donelib
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,"1037" ; SYS 1037
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
71 ; sta $E84C ; See PET FAQ
78 ; Save system stuff and setup the stack
81 stx spsave ; Save the system stack ptr
86 sta sp+1 ; Set argument stack ptr
88 ; Call module constructors
92 ; Pass an empty command line
97 ldy #4 ; Argument size
98 jsr _main ; call the users code
100 ; Call module destructors. This is also the _exit entry.
102 _exit: jsr donelib ; Run module destructors
104 ; Restore system stuff
107 txs ; Restore stack pointer
109 ; Copy back the zero page stuff