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__, __BSS_LOAD__
17 .import __RESERVED_MEMORY__
18 .import __RAM_START__, __RAM_SIZE__
19 .if .defined(__ATARIXL__)
23 .include "save_area.inc"
26 .include "zeropage.inc"
29 ; ------------------------------------------------------------------------
36 .if .defined(__ATARIXL__)
40 .word __STARTUP_LOAD__
41 .word __BSS_LOAD__ - 1
43 ; ------------------------------------------------------------------------
48 rts ; fix for SpartaDOS / OS/A+
49 ; they first call the entry point from AUTOSTRT and
50 ; then the load addess (this rts here).
51 ; We point AUTOSTRT directly after the rts.
55 .if .defined(__ATARIXL__)
68 .if .not .defined(__ATARIXL__)
73 sta APPMHI_save ; remember old APPMHI value
79 sbc #<__RESERVED_MEMORY__
80 sta APPMHI ; initialize our APPMHI value
81 sta sp ; setup runtime stack part 1
83 sbc #>__RESERVED_MEMORY__
85 sta sp+1 ; setup runtime stack part 2
89 lda #<(__RAM_START__ + __RAM_SIZE__ - 1)
91 lda #>(__RAM_START__ + __RAM_SIZE__ - 1)
96 ; Call module constructors
100 ; Set left margin to 0
107 ; Set keyb to upper/lowercase mode
113 ; Initialize conio stuff
118 ; Push arguments and call main
122 ; Call module destructors. This is also the _exit entry.
124 _exit: jsr donelib ; Run module destructors
126 ; Restore system stuff
129 txs ; Restore stack pointer
131 ; Restore left margin
148 .if .defined(__ATARIXL__)
150 ; Atari XL target stuff...
162 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
166 ; Reopen it in Graphics 0
182 ; add error checking here...
198 ; *** end of main startup code
200 ; ------------------------------------------------------------------------
207 .if .not .defined(__ATARIXL__)
213 .word RUNAD ; defined in atari.inc
215 .word __STARTUP_LOAD__ + 1