2 ; Startup code for cc65 (C64 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,"2061" ; SYS 2061
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
70 ; Save system stuff and setup the stack
73 stx spsave ; Save the system stack ptr
76 sta mmusave ; Save the memory configuration
79 ora #$06 ; Enable kernal+I/O, disable basic
85 sta sp+1 ; Set argument stack ptr
91 ; Initialize conio stuff
95 ; Pass an empty command line
100 ldy #4 ; Argument size
101 jsr _main ; call the users code
103 ; fall thru to exit...
105 _exit: jsr doatexit ; call exit functions
108 txs ; Restore stack pointer
110 sta $01 ; Restore memory configuration
112 ; Copy back the zero page stuff
120 ; Reset changed vectors, back to basic