2 ; Startup code for cc65 (ATARI version)
4 ; Contributing authors:
9 ; This must be the *first* file on the linker command line
13 .import getargs, argc, argv
14 .import __hinit, initconio, zerobss, pushax, doatexit
15 .import _main,__filetab,getfd
16 .import __CODE_LOAD__, __BSS_LOAD__
20 ; ------------------------------------------------------------------------
21 ; Define and export the ZP variables for the runtime
23 .exportzp sp, sreg, regsave
24 .exportzp ptr1, ptr2, ptr3, ptr4
25 .exportzp tmp1, tmp2, tmp3, tmp4
26 .exportzp fntemp, regbank, zpspace
28 sp = $D2 ; (2bytes) stack pointer
29 sreg = $D4 ; (2bytes) secondary register/high 16 bit for longs
30 regsave = $D6 ; (4bytes) slot to save/restore (E)AX into
39 fntemp = $E6 ; (2bytes) pointer to file name
40 regbank = $E8 ; (6bytes) 6 byte register bank
41 zpspace = $EE - sp ; Zero page space allocated
43 ; ------------------------------------------------------------------------
49 .word __BSS_LOAD__ - 1
53 ; ------------------------------------------------------------------------
56 rts ; fix for SpartaDOS / OS/A+
57 ; they first call the entry point from AUTOSTRT and
58 ; then the load addess (this rts here).
59 ; We point AUTOSTRT directly after the rts.
63 ; Save the zero page locations we need
80 ; report memory usage and initialize stack pointer
91 sta sp+1 ; Set argument stack ptr
94 ; set left margin to 0
101 ; set keyb to upper/lowercase mode
107 ; Initialize the heap
111 ; Initialize conio stuff
118 ; set stdio stream handles
122 sta __filetab ; setup stdin
125 sta __filetab + 2 ; setup stdout
128 sta __filetab + 4 ; setup stderr
130 ; Pass command line if present
141 ldy #4 ; Argument size
142 jsr _main ; call the users code
144 ; fall thru to exit...
146 _exit: jsr doatexit ; call exit functions
149 txs ; Restore stack pointer
151 ; restore left margin
168 ; Copy back the zero page stuff
194 .word __CODE_LOAD__ + 1