2 ; Startup code for cc65 (ATARI version)
4 ; Contributing authors:
9 ; This must be the *first* file on the linker command line
13 .constructor initsp,26
15 .import getargs, argc, argv
16 .import initlib, donelib
17 .import zerobss, pushax
18 .import _main,__filetab,getfd
19 .import __CODE_LOAD__, __BSS_LOAD__
23 ; ------------------------------------------------------------------------
24 ; Define and export the ZP variables for the runtime
26 .exportzp sp, sreg, regsave
27 .exportzp ptr1, ptr2, ptr3, ptr4
28 .exportzp tmp1, tmp2, tmp3, tmp4
29 .exportzp fntemp, regbank, zpspace
35 sp: .res 2 ; Stack pointer
36 sreg: .res 2 ; Secondary register/high 16 bit for longs
37 regsave: .res 2 ; slot to save/restore (E)AX into
46 fntemp: .res 2 ; Pointer to file name
47 regbank: .res 6 ; 6 byte register bank
49 zpspace = * - zpstart ; Zero page space allocated
53 ; ------------------------------------------------------------------------
59 .word __BSS_LOAD__ - 1
63 ; ------------------------------------------------------------------------
66 rts ; fix for SpartaDOS / OS/A+
67 ; they first call the entry point from AUTOSTRT and
68 ; then the load addess (this rts here).
69 ; We point AUTOSTRT directly after the rts.
73 ; Save the zero page locations we need
93 sta appmsav ; remember old APPMHI value
98 sta APPMHI ; initialize our APPMHI value
102 ; Call module constructors
106 ; set left margin to 0
113 ; set keyb to upper/lowercase mode
119 ; Initialize conio stuff
124 ; set stdio stream handles
128 sta __filetab ; setup stdin
131 sta __filetab + 2 ; setup stdout
134 sta __filetab + 4 ; setup stderr
136 ; Pass command line if present
147 ldy #4 ; Argument size
148 jsr _main ; call the users code
150 ; Call module destructors. This is also the _exit entry.
152 _exit: jsr donelib ; Run module destructors
154 ; Restore system stuff
157 txs ; Restore stack pointer
159 ; restore left margin
176 ; Copy back the zero page stuff
188 ; *** end of main startup code
213 .word __CODE_LOAD__ + 1