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.
57 .if .defined(__ATARIXL__)
70 .if .not .defined(__ATARIXL__)
75 sta APPMHI_save ; remember old APPMHI value
81 sbc #<__RESERVED_MEMORY__
82 sta APPMHI ; initialize our APPMHI value
83 sta sp ; setup runtime stack part 1
85 sbc #>__RESERVED_MEMORY__
87 sta sp+1 ; setup runtime stack part 2
91 lda #<(__RAM_START__ + __RAM_SIZE__ - 1)
93 lda #>(__RAM_START__ + __RAM_SIZE__ - 1)
98 ; Call module constructors
103 .if .defined(__ATARIXL__)
106 .import __RAM_BELOW_ROM_START__
107 .import __RAM_BELOW_ROM_SIZE__
108 .import __RAM_BELOW_ROM_LAST__
110 lda #<__RAM_BELOW_ROM_LAST__
111 ldx #>__RAM_BELOW_ROM_LAST__
113 lda #<(__RAM_BELOW_ROM_SIZE__ - (__RAM_BELOW_ROM_LAST__ - __RAM_BELOW_ROM_START__))
114 ldx #>(__RAM_BELOW_ROM_SIZE__ - (__RAM_BELOW_ROM_LAST__ - __RAM_BELOW_ROM_START__))
119 ; Set left margin to 0
126 ; Set keyb to upper/lowercase mode
132 ; Initialize conio stuff
137 ; Push arguments and call main
141 ; Call module destructors. This is also the _exit entry.
143 _exit: jsr donelib ; Run module destructors
145 ; Restore system stuff
148 txs ; Restore stack pointer
150 ; Restore left margin
167 .if .defined(__ATARIXL__)
169 ; Atari XL target stuff...
181 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
185 ; Reopen it in Graphics 0
201 ; add error checking here...
217 ; *** end of main startup code
219 ; ------------------------------------------------------------------------
226 .if .not .defined(__ATARIXL__)
232 .word RUNAD ; defined in atari.inc