2 ; Startup code for cc65 (PET version)
4 ; This must be the *first* file on the linker command line
8 .import __hinit, initconio, zerobss, push0, doatexit
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
22 sp = $02 ; stack pointer
23 sreg = $04 ; secondary register/high 16 bit for longs
24 regsave = $06 ; slot to save/restore (E)AX into
33 regbank = $16 ; 6 byte register bank
34 zpspace = $1A ; Zero page space allocated
36 ; ------------------------------------------------------------------------
37 ; BASIC header with a SYS call
40 .word Head ; Load address
42 .word 1000 ; Line number
43 .byte $9E,"1037" ; SYS 1037
44 .byte $00 ; End of BASIC line
45 @Next: .word 0 ; BASIC end marker
48 ; ------------------------------------------------------------------------
53 sta zpsave,y ; Save the zero page locations we need
61 ; Switch to second charset
64 ; sta $E84C ; See PET FAQ
71 ; Save system stuff and setup the stack
74 stx spsave ; Save the system stack ptr
79 sta sp+1 ; Set argument stack ptr
85 ; Initialize conio stuff
89 ; Pass an empty command line
94 ldy #4 ; Argument size
95 jsr _main ; call the users code
97 ; fall thru to exit...
99 _exit: jsr doatexit ; call exit functions
102 txs ; Restore stack pointer
104 ; Copy back the zero page stuff