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__)
25 .include "zeropage.inc"
27 .include "save_area.inc"
29 ; ------------------------------------------------------------------------
36 .if .defined(__ATARIXL__)
40 .word __STARTUP_LOAD__
41 .if .defined(__ATARIXL__)
42 .word __BSS_LOAD__ - 1
44 .word __ZPSAVE_LOAD__ - 1
47 ; ------------------------------------------------------------------------
52 rts ; fix for SpartaDOS / OS/A+
53 ; they first call the entry point from AUTOSTRT and
54 ; then the load addess (this rts here).
55 ; We point AUTOSTRT directly after the rts.
59 .if .not .defined(__ATARIXL__) ; already done in previous load chunk
61 ; Save the zero page locations we need
84 .if .not .defined(__ATARIXL__)
89 sta appmsav ; remember old APPMHI value
95 sbc #<__RESERVED_MEMORY__
96 sta APPMHI ; initialize our APPMHI value
97 sta sp ; setup runtime stack part 1
99 sbc #>__RESERVED_MEMORY__
101 sta sp+1 ; setup runtime stack part 2
105 lda #<(__RAM_START__ + __RAM_SIZE__ - 1)
107 lda #>(__RAM_START__ + __RAM_SIZE__ - 1)
112 ; Call module constructors
116 ; Set left margin to 0
123 ; Set keyb to upper/lowercase mode
129 ; Initialize conio stuff
134 ; Push arguments and call main
138 ; Call module destructors. This is also the _exit entry.
140 _exit: jsr donelib ; Run module destructors
142 ; Restore system stuff
145 txs ; Restore stack pointer
147 ; Restore left margin
157 .if .not .defined(__ATARIXL__)
168 ; Atari XL target stuff...
185 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
188 ldx #$50 ; take any IOCB, hopefully free (@@@ fixme)
190 ; Reopen it in Graphics 0
212 ; Copy back the zero page stuff
229 ; *** end of main startup code
231 ; ------------------------------------------------------------------------
241 .word RUNAD ; defined in atari.h
243 .word __STARTUP_LOAD__ + 1