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 initlib, donelib, callmain
16 .import zerobss, pushax
17 .import _main, __filetab, getfd
18 .import __LOWCODE_LOAD__, __BSS_LOAD__
19 .import __RESERVED_MEMORY__
24 .include "zeropage.inc"
28 ; ------------------------------------------------------------------------
33 .word __LOWCODE_LOAD__
34 .word __BSS_LOAD__ - 1
36 ; ------------------------------------------------------------------------
41 rts ; fix for SpartaDOS / OS/A+
42 ; they first call the entry point from AUTOSTRT and
43 ; then the load addess (this rts here).
44 ; We point AUTOSTRT directly after the rts.
48 ; Save the zero page locations we need
68 sta appmsav ; remember old APPMHI value
74 sbc #<__RESERVED_MEMORY__
75 sta APPMHI ; initialize our APPMHI value
77 sbc #>__RESERVED_MEMORY__
80 ; Call module constructors
87 ; set left margin to 0
94 ; set keyb to upper/lowercase mode
100 ; Initialize conio stuff
105 ; set stdio stream handles
109 sta __filetab + (0 * .sizeof(_FILE)); setup stdin
112 sta __filetab + (1 * .sizeof(_FILE)); setup stdout
115 sta __filetab + (2 * .sizeof(_FILE)); setup stderr
117 ; Push arguments and call main
121 ; Call module destructors. This is also the _exit entry.
123 _exit: jsr donelib ; Run module destructors
125 ; Restore system stuff
128 txs ; Restore stack pointer
130 ; restore left margin
147 ; Copy back the zero page stuff
164 ; *** end of main startup code
191 .word __LOWCODE_LOAD__ + 1