2 ; Startup code for cc65 (C128 version)
4 ; This must be the *first* file on the linker command line
8 .import initlib, donelib
9 .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,"7181" ; SYS 7181
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
73 ; Get the current MMU setting and save it. Set new memory config.
75 lda MMU_CR ; Get current memory configuration...
76 pha ; ...and save it for later
77 lda #$0E ; Bank0 with kernal ROM
84 ; Save system stuff and setup the stack
90 stx spsave ; save system stk ptr
97 ; Call module constructors
101 ; Initialize conio stuff
105 ; Pass an empty command line
110 ldy #4 ; Argument size
111 jsr _main ; call the users code
113 ; Call module destructors. This is also the _exit entry.
115 _exit: jsr donelib ; Run module destructors
117 ; Reset the conio stuff
121 ; Reset stack and the MMU
123 ldx spsave ; Patched at runtime
125 lda mmusave ; Patched at runtime
128 ; Copy back the zero page stuff