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
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 ; ugly hack for now: set stdio stream handles
120 ; until we know where to go with fd<->iocb relation
121 ; this won't stay here!
127 ; Pass command line if present
138 ldy #4 ; Argument size
139 jsr _main ; call the users code
141 ; fall thru to exit...
143 _exit: jsr doatexit ; call exit functions
146 txs ; Restore stack pointer
148 ; restore left margin
165 ; Copy back the zero page stuff
191 .word __CODE_LOAD__ + 1