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
101 .if .defined(__ATARIXL__)
104 .import __RAM_BELOW_ROM_START__
105 .import __RAM_BELOW_ROM_SIZE__
106 .import __RAM_BELOW_ROM_LAST__
108 lda #<__RAM_BELOW_ROM_LAST__
109 ldx #>__RAM_BELOW_ROM_LAST__
111 lda #<(__RAM_BELOW_ROM_SIZE__ - (__RAM_BELOW_ROM_LAST__ - __RAM_BELOW_ROM_START__))
112 ldx #>(__RAM_BELOW_ROM_SIZE__ - (__RAM_BELOW_ROM_LAST__ - __RAM_BELOW_ROM_START__))
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
165 .if .defined(__ATARIXL__)
167 ; Atari XL target stuff...
179 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
183 ; Reopen it in Graphics 0
199 ; add error checking here...
215 ; *** end of main startup code
217 ; ------------------------------------------------------------------------
224 .if .not .defined(__ATARIXL__)
230 .word RUNAD ; defined in atari.inc
232 .word __STARTUP_LOAD__ + 1