2 ; Startup code for cc65 (ATARI version)
4 ; Contributing authors:
9 ; This must be the *first* file on the linker command line
12 RESERVE_MOUSE_MEMORY = 1 ; for P/M
14 .ifdef RESERVE_MOUSE_MEMORY
18 .import getargs, argc, argv
19 .import __hinit, initconio, zerobss, pushax, doatexit
20 .import _main,__filetab,getfd
21 .import __CODE_LOAD__, __BSS_LOAD__
22 .import __graphmode_used
26 ; ------------------------------------------------------------------------
27 ; Define and export the ZP variables for the runtime
29 .exportzp sp, sreg, regsave
30 .exportzp ptr1, ptr2, ptr3, ptr4
31 .exportzp tmp1, tmp2, tmp3, tmp4
32 .exportzp fntemp, regbank, zpspace
38 sp: .res 2 ; Stack pointer
39 sreg: .res 2 ; Secondary register/high 16 bit for longs
40 regsave: .res 2 ; slot to save/restore (E)AX into
49 fntemp: .res 2 ; Pointer to file name
50 regbank: .res 6 ; 6 byte register bank
52 zpspace = * - zpstart ; Zero page space allocated
56 ; ------------------------------------------------------------------------
62 .word __BSS_LOAD__ - 1
66 ; ------------------------------------------------------------------------
69 rts ; fix for SpartaDOS / OS/A+
70 ; they first call the entry point from AUTOSTRT and
71 ; then the load addess (this rts here).
72 ; We point AUTOSTRT directly after the rts.
76 ; Save the zero page locations we need
93 ; report memory usage and initialize stack pointer
100 jsr getmemtop ; adjust for graphics mode to use
104 stx sp+1 ; Set argument stack ptr
107 ; set left margin to 0
114 ; set keyb to upper/lowercase mode
120 ; Initialize the heap
124 ; Initialize conio stuff
131 ; set stdio stream handles
135 sta __filetab ; setup stdin
138 sta __filetab + 2 ; setup stdout
141 sta __filetab + 4 ; setup stderr
143 ; Pass command line if present
154 ldy #4 ; Argument size
155 jsr _main ; call the users code
157 ; fall thru to exit...
159 _exit: jsr doatexit ; call exit functions
162 txs ; Restore stack pointer
164 ; restore left margin
181 ; Copy back the zero page stuff
193 ; *** end of main startup code
196 ; calc. upper memory limit to use
201 beq ignore ; mode 0 doesn't need adjustment
203 bcs ignore ; invalid value
216 .ifdef RESERVE_MOUSE_MEMORY
219 txa ; get upper byte of address
220 and #%11111000 ; make 2k aligned
222 sbc #%00001000 ; reserve 2k
224 adc #3 ; add 4 (C = 1)
232 .ifdef RESERVE_MOUSE_MEMORY
246 ; memory usage of the different graphics modes (0-31)
247 ; values < 0 of "bytes needed" are mappped to 0
248 ; bytes needed ; mode ; val. of MEMTOP
251 .word 0 ;-318 ; 1 ; 40285
252 .word 0 ;-568 ; 2 ; 40535
253 .word 0 ;-558 ; 3 ; 40525
254 .word 0 ;-298 ; 4 ; 40265
255 .word 182 ; 5 ; 39785
256 .word 1182 ; 6 ; 38785
257 .word 3198 ; 7 ; 36769
258 .word 7120 ; 8 ; 32847
259 .word 7146 ; 9 ; 32821
260 .word 7146 ; 10 ; 32821
261 .word 7146 ; 11 ; 32821
262 .word 162 ; 12 ; 39805
263 .word 0 ;-328 ; 13 ; 40295
264 .word 3278 ; 14 ; 36689
265 .word 7120 ; 15 ; 32847
267 .word 0 ;-320 ; 17 ; 40287
268 .word 0 ;-572 ; 18 ; 40539
269 .word 0 ;-560 ; 19 ; 40527
270 .word 0 ;-296 ; 20 ; 40263
271 .word 184 ; 21 ; 39783
272 .word 1192 ; 22 ; 38775
273 .word 3208 ; 23 ; 36759
274 .word 7146 ; 24 ; 32821
275 .word 7146 ; 25 ; 32821
276 .word 7146 ; 26 ; 32821
277 .word 7146 ; 27 ; 32821
278 .word 160 ; 28 ; 39807
279 .word 0 ;-332 ; 29 ; 40299
280 .word 3304 ; 30 ; 36663
281 .word 7146 ; 31 ; 32821
283 ; the program used to get these values (Atari BASIC):
285 ; 110 IF FILE=1 THEN OPEN #1,8,0,"D:FREEMEM.OUT"
286 ; 120 IF FILE<>1 THEN OPEN #1,8,0,"E:"
288 ; 210 FOR I=0 TO 32:GRAPHICS I:GOSUB 1000:G(I)=VAL:NEXT I
290 ; 230 FOR I=0 TO 31:PRINT #1;I;":",G(I);" - ";G(0)-G(I):NEXT I
293 ; 1000 VAL=PEEK(741)+256*PEEK(742)
302 .ifdef RESERVE_MOUSE_MEMORY
309 .word __CODE_LOAD__ + 1