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__
17 .import __graphmode_used
21 ; ------------------------------------------------------------------------
22 ; Define and export the ZP variables for the runtime
24 .exportzp sp, sreg, regsave
25 .exportzp ptr1, ptr2, ptr3, ptr4
26 .exportzp tmp1, tmp2, tmp3, tmp4
27 .exportzp fntemp, regbank, zpspace
29 sp = $D2 ; (2bytes) stack pointer
30 sreg = $D4 ; (2bytes) secondary register/high 16 bit for longs
31 regsave = $D6 ; (4bytes) slot to save/restore (E)AX into
40 fntemp = $E6 ; (2bytes) pointer to file name
41 regbank = $E8 ; (6bytes) 6 byte register bank
42 zpspace = $EE - sp ; Zero page space allocated
44 ; ------------------------------------------------------------------------
50 .word __BSS_LOAD__ - 1
54 ; ------------------------------------------------------------------------
57 rts ; fix for SpartaDOS / OS/A+
58 ; they first call the entry point from AUTOSTRT and
59 ; then the load addess (this rts here).
60 ; We point AUTOSTRT directly after the rts.
64 ; Save the zero page locations we need
81 ; report memory usage and initialize stack pointer
88 jsr getmemtop ; adjust for graphics mode to use
92 stx sp+1 ; Set argument stack ptr
95 ; set left margin to 0
102 ; set keyb to upper/lowercase mode
108 ; Initialize the heap
112 ; Initialize conio stuff
119 ; set stdio stream handles
123 sta __filetab ; setup stdin
126 sta __filetab + 2 ; setup stdout
129 sta __filetab + 4 ; setup stderr
131 ; Pass command line if present
142 ldy #4 ; Argument size
143 jsr _main ; call the users code
145 ; fall thru to exit...
147 _exit: jsr doatexit ; call exit functions
150 txs ; Restore stack pointer
152 ; restore left margin
169 ; Copy back the zero page stuff
181 ; *** end of main startup code
184 ; calc. upper memory limit to use
189 beq ignore ; mode 0 doesn't need adjustment
191 bcs ignore ; invalid value
216 ; memory usage of the different graphics modes (0-31)
217 ; values < 0 of "bytes needed" are mappped to 0
218 ; bytes needed ; mode ; val. of MEMTOP
221 .word 0 ;-318 ; 1 ; 40285
222 .word 0 ;-568 ; 2 ; 40535
223 .word 0 ;-558 ; 3 ; 40525
224 .word 0 ;-298 ; 4 ; 40265
225 .word 182 ; 5 ; 39785
226 .word 1182 ; 6 ; 38785
227 .word 3198 ; 7 ; 36769
228 .word 7120 ; 8 ; 32847
229 .word 7146 ; 9 ; 32821
230 .word 7146 ; 10 ; 32821
231 .word 7146 ; 11 ; 32821
232 .word 162 ; 12 ; 39805
233 .word 0 ;-328 ; 13 ; 40295
234 .word 3278 ; 14 ; 36689
235 .word 7120 ; 15 ; 32847
237 .word 0 ;-320 ; 17 ; 40287
238 .word 0 ;-572 ; 18 ; 40539
239 .word 0 ;-560 ; 19 ; 40527
240 .word 0 ;-296 ; 20 ; 40263
241 .word 184 ; 21 ; 39783
242 .word 1192 ; 22 ; 38775
243 .word 3208 ; 23 ; 36759
244 .word 7146 ; 24 ; 32821
245 .word 7146 ; 25 ; 32821
246 .word 7146 ; 26 ; 32821
247 .word 7146 ; 27 ; 32821
248 .word 160 ; 28 ; 39807
249 .word 0 ;-332 ; 29 ; 40299
250 .word 3304 ; 30 ; 36663
251 .word 7146 ; 31 ; 32821
253 ; the program used to get these values (Atari BASIC):
255 ; 110 IF FILE=1 THEN OPEN #1,8,0,"D:FREEMEM.OUT"
256 ; 120 IF FILE<>1 THEN OPEN #1,8,0,"E:"
258 ; 210 FOR I=0 TO 32:GRAPHICS I:GOSUB 1000:G(I)=VAL:NEXT I
260 ; 230 FOR I=0 TO 31:PRINT #1;I;":",G(I);" - ";G(0)-G(I):NEXT I
263 ; 1000 VAL=PEEK(741)+256*PEEK(742)
276 .word __CODE_LOAD__ + 1