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 initlib, donelib
20 .import initconio, zerobss, pushax
21 .import _main,__filetab,getfd
22 .import __CODE_LOAD__, __BSS_LOAD__
23 .import __graphmode_used
27 ; ------------------------------------------------------------------------
28 ; Define and export the ZP variables for the runtime
30 .exportzp sp, sreg, regsave
31 .exportzp ptr1, ptr2, ptr3, ptr4
32 .exportzp tmp1, tmp2, tmp3, tmp4
33 .exportzp fntemp, regbank, zpspace
39 sp: .res 2 ; Stack pointer
40 sreg: .res 2 ; Secondary register/high 16 bit for longs
41 regsave: .res 2 ; slot to save/restore (E)AX into
50 fntemp: .res 2 ; Pointer to file name
51 regbank: .res 6 ; 6 byte register bank
53 zpspace = * - zpstart ; Zero page space allocated
57 ; ------------------------------------------------------------------------
63 .word __BSS_LOAD__ - 1
67 ; ------------------------------------------------------------------------
70 rts ; fix for SpartaDOS / OS/A+
71 ; they first call the entry point from AUTOSTRT and
72 ; then the load addess (this rts here).
73 ; We point AUTOSTRT directly after the rts.
77 ; Save the zero page locations we need
94 ; report memory usage and initialize stack pointer
101 jsr getmemtop ; adjust for graphics mode to use
105 stx sp+1 ; Set argument stack ptr
108 ; set left margin to 0
115 ; set keyb to upper/lowercase mode
121 ; Call module constructors
125 ; Initialize conio stuff
132 ; set stdio stream handles
136 sta __filetab ; setup stdin
139 sta __filetab + 2 ; setup stdout
142 sta __filetab + 4 ; setup stderr
144 ; Pass command line if present
155 ldy #4 ; Argument size
156 jsr _main ; call the users code
158 ; Call module destructors. This is also the _exit entry.
160 _exit: jsr donelib ; Run module destructors
162 ; Restore system stuff
165 txs ; Restore stack pointer
167 ; restore left margin
184 ; Copy back the zero page stuff
196 ; *** end of main startup code
199 ; calc. upper memory limit to use
204 beq ignore ; mode 0 doesn't need adjustment
206 bcs ignore ; invalid value
219 .ifdef RESERVE_MOUSE_MEMORY
222 txa ; get upper byte of address
223 and #%11111000 ; make 2k aligned
225 sbc #%00001000 ; reserve 2k
227 adc #3 ; add 4 (C = 1)
235 .ifdef RESERVE_MOUSE_MEMORY
249 ; memory usage of the different graphics modes (0-31)
250 ; values < 0 of "bytes needed" are mappped to 0
251 ; bytes needed ; mode ; val. of MEMTOP
254 .word 0 ;-318 ; 1 ; 40285
255 .word 0 ;-568 ; 2 ; 40535
256 .word 0 ;-558 ; 3 ; 40525
257 .word 0 ;-298 ; 4 ; 40265
258 .word 182 ; 5 ; 39785
259 .word 1182 ; 6 ; 38785
260 .word 3198 ; 7 ; 36769
261 .word 7120 ; 8 ; 32847
262 .word 7146 ; 9 ; 32821
263 .word 7146 ; 10 ; 32821
264 .word 7146 ; 11 ; 32821
265 .word 162 ; 12 ; 39805
266 .word 0 ;-328 ; 13 ; 40295
267 .word 3278 ; 14 ; 36689
268 .word 7120 ; 15 ; 32847
270 .word 0 ;-320 ; 17 ; 40287
271 .word 0 ;-572 ; 18 ; 40539
272 .word 0 ;-560 ; 19 ; 40527
273 .word 0 ;-296 ; 20 ; 40263
274 .word 184 ; 21 ; 39783
275 .word 1192 ; 22 ; 38775
276 .word 3208 ; 23 ; 36759
277 .word 7146 ; 24 ; 32821
278 .word 7146 ; 25 ; 32821
279 .word 7146 ; 26 ; 32821
280 .word 7146 ; 27 ; 32821
281 .word 160 ; 28 ; 39807
282 .word 0 ;-332 ; 29 ; 40299
283 .word 3304 ; 30 ; 36663
284 .word 7146 ; 31 ; 32821
286 ; the program used to get these values (Atari BASIC):
288 ; 110 IF FILE=1 THEN OPEN #1,8,0,"D:FREEMEM.OUT"
289 ; 120 IF FILE<>1 THEN OPEN #1,8,0,"E:"
291 ; 210 FOR I=0 TO 32:GRAPHICS I:GOSUB 1000:G(I)=VAL:NEXT I
293 ; 230 FOR I=0 TO 31:PRINT #1;I;":",G(I);" - ";G(0)-G(I):NEXT I
296 ; 1000 VAL=PEEK(741)+256*PEEK(742)
305 .ifdef RESERVE_MOUSE_MEMORY
312 .word __CODE_LOAD__ + 1