2 ; Startup code for cc65 (ATARI version)
4 ; Contributing authors:
12 .export __STARTUP__ : absolute = 1 ; Mark as startup
14 .import initlib, donelib
15 .import callmain, zerobss
16 .import __STARTUP_LOAD__, __ZPSAVE_LOAD__, __BSS_LOAD__
17 .import __RESERVED_MEMORY__
18 .import __RAM_START__, __RAM_SIZE__
21 .if .defined(__ATARIXL__)
26 .include "zeropage.inc"
28 .include "save_area.inc"
30 ; ------------------------------------------------------------------------
37 .if .defined(__ATARIXL__)
41 .word __STARTUP_LOAD__
42 .if .defined(__ATARIXL__)
43 .word __BSS_LOAD__ - 1
45 .word __ZPSAVE_LOAD__ - 1
48 ; ------------------------------------------------------------------------
53 rts ; fix for SpartaDOS / OS/A+
54 ; they first call the entry point from AUTOSTRT and
55 ; then the load addess (this rts here).
56 ; We point AUTOSTRT directly after the rts.
60 .if .not .defined(__ATARIXL__) ; already done in previous load chunk
62 ; Save the zero page locations we need
85 .if .not .defined(__ATARIXL__)
90 sta appmsav ; remember old APPMHI value
96 sbc #<__RESERVED_MEMORY__
97 sta APPMHI ; initialize our APPMHI value
98 sta sp ; setup runtime stack part 1
100 sbc #>__RESERVED_MEMORY__
102 sta sp+1 ; setup runtime stack part 2
106 lda #<(__RAM_START__ + __RAM_SIZE__ - 1)
108 lda #>(__RAM_START__ + __RAM_SIZE__ - 1)
113 ; Call module constructors
117 ; Set left margin to 0
124 ; Set keyb to upper/lowercase mode
130 ; Initialize conio stuff
135 ; Push arguments and call main
139 ; Call module destructors. This is also the _exit entry.
141 _exit: jsr donelib ; Run module destructors
143 ; Restore system stuff
146 txs ; Restore stack pointer
148 ; Restore left margin
158 .if .not .defined(__ATARIXL__)
169 ; Atari XL target stuff...
185 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
189 ; Reopen it in Graphics 0
205 ; add error checking here...
213 ; Copy back the zero page stuff
230 ; *** end of main startup code
232 ; ------------------------------------------------------------------------
239 .if .not .defined(__ATARIXL__)
244 .word RUNAD ; defined in atari.h
246 .word __STARTUP_LOAD__ + 1