2 ; Startup code for cc65 (C128 version)
4 ; This must be the *first* file on the linker command line
8 .import __hinit, initconio, doneconio, zerobss
9 .import push0, doatexit, _main
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,"7181" ; SYS 7181
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
66 ; Get the current MMU setting and save it. Set new memory config.
68 lda MMU_CR ; Get current memory configuration...
69 pha ; ...and save it for later
70 lda #$0E ; Bank0 with kernal ROM
77 ; Save system stuff and setup the stack
83 stx spsave ; save system stk ptr
94 ; Initialize conio stuff
98 ; Pass an empty command line
103 ldy #4 ; Argument size
104 jsr _main ; call the users code
106 ; fall thru to exit...
108 _exit: jsr doatexit ; call exit functions
110 ; Reset the conio stuff
114 ; Reset stack and the MMU
116 ldx spsave ; Patched at runtime
118 lda mmusave ; Patched at runtime
121 ; Copy back the zero page stuff