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
33 sp: .res 2 ; Stack pointer
34 sreg: .res 2 ; Secondary register/high 16 bit for longs
35 regsave: .res 2 ; slot to save/restore (E)AX into
44 fntemp: .res 2 ; Pointer to file name
45 regbank: .res 6 ; 6 byte register bank
47 zpspace = * - zpstart ; Zero page space allocated
51 ; ------------------------------------------------------------------------
57 .word __BSS_LOAD__ - 1
61 ; ------------------------------------------------------------------------
64 rts ; fix for SpartaDOS / OS/A+
65 ; they first call the entry point from AUTOSTRT and
66 ; then the load addess (this rts here).
67 ; We point AUTOSTRT directly after the rts.
71 ; Save the zero page locations we need
88 ; report memory usage and initialize stack pointer
95 jsr getmemtop ; adjust for graphics mode to use
99 stx sp+1 ; Set argument stack ptr
102 ; set left margin to 0
109 ; set keyb to upper/lowercase mode
115 ; Initialize the heap
119 ; Initialize conio stuff
126 ; set stdio stream handles
130 sta __filetab ; setup stdin
133 sta __filetab + 2 ; setup stdout
136 sta __filetab + 4 ; setup stderr
138 ; Pass command line if present
149 ldy #4 ; Argument size
150 jsr _main ; call the users code
152 ; fall thru to exit...
154 _exit: jsr doatexit ; call exit functions
157 txs ; Restore stack pointer
159 ; restore left margin
176 ; Copy back the zero page stuff
188 ; *** end of main startup code
191 ; calc. upper memory limit to use
196 beq ignore ; mode 0 doesn't need adjustment
198 bcs ignore ; invalid value
225 ; memory usage of the different graphics modes (0-31)
226 ; values < 0 of "bytes needed" are mappped to 0
227 ; bytes needed ; mode ; val. of MEMTOP
230 .word 0 ;-318 ; 1 ; 40285
231 .word 0 ;-568 ; 2 ; 40535
232 .word 0 ;-558 ; 3 ; 40525
233 .word 0 ;-298 ; 4 ; 40265
234 .word 182 ; 5 ; 39785
235 .word 1182 ; 6 ; 38785
236 .word 3198 ; 7 ; 36769
237 .word 7120 ; 8 ; 32847
238 .word 7146 ; 9 ; 32821
239 .word 7146 ; 10 ; 32821
240 .word 7146 ; 11 ; 32821
241 .word 162 ; 12 ; 39805
242 .word 0 ;-328 ; 13 ; 40295
243 .word 3278 ; 14 ; 36689
244 .word 7120 ; 15 ; 32847
246 .word 0 ;-320 ; 17 ; 40287
247 .word 0 ;-572 ; 18 ; 40539
248 .word 0 ;-560 ; 19 ; 40527
249 .word 0 ;-296 ; 20 ; 40263
250 .word 184 ; 21 ; 39783
251 .word 1192 ; 22 ; 38775
252 .word 3208 ; 23 ; 36759
253 .word 7146 ; 24 ; 32821
254 .word 7146 ; 25 ; 32821
255 .word 7146 ; 26 ; 32821
256 .word 7146 ; 27 ; 32821
257 .word 160 ; 28 ; 39807
258 .word 0 ;-332 ; 29 ; 40299
259 .word 3304 ; 30 ; 36663
260 .word 7146 ; 31 ; 32821
262 ; the program used to get these values (Atari BASIC):
264 ; 110 IF FILE=1 THEN OPEN #1,8,0,"D:FREEMEM.OUT"
265 ; 120 IF FILE<>1 THEN OPEN #1,8,0,"E:"
267 ; 210 FOR I=0 TO 32:GRAPHICS I:GOSUB 1000:G(I)=VAL:NEXT I
269 ; 230 FOR I=0 TO 31:PRINT #1;I;":",G(I);" - ";G(0)-G(I):NEXT I
272 ; 1000 VAL=PEEK(741)+256*PEEK(742)
285 .word __CODE_LOAD__ + 1