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, callirq
16 .import __INTERRUPTOR_COUNT__
17 .import __STARTUP_LOAD__, __ZPSAVE_LOAD__
18 .import __RESERVED_MEMORY__
20 .include "zeropage.inc"
23 ; ------------------------------------------------------------------------
28 .word __STARTUP_LOAD__
29 .word __ZPSAVE_LOAD__ - 1
31 ; ------------------------------------------------------------------------
36 rts ; fix for SpartaDOS / OS/A+
37 ; they first call the entry point from AUTOSTRT and
38 ; then the load addess (this rts here).
39 ; We point AUTOSTRT directly after the rts.
43 ; Save the zero page locations we need
63 sta appmsav ; remember old APPMHI value
69 sbc #<__RESERVED_MEMORY__
70 sta APPMHI ; initialize our APPMHI value
71 sta sp ; setup runtime stack part 1
73 sbc #>__RESERVED_MEMORY__
75 sta sp+1 ; setup runtime stack part 2
77 ; If we have IRQ functions, chain our stub into the IRQ vector
79 lda #<__INTERRUPTOR_COUNT__
90 ; Call module constructors
94 ; Set left margin to 0
101 ; Set keyb to upper/lowercase mode
107 ; Initialize conio stuff
112 ; Push arguments and call main
116 ; Call module destructors. This is also the _exit entry.
118 _exit: jsr donelib ; Run module destructors
120 ; Reset the IRQ vector if we chained it.
122 pha ; Save the return code on stack
123 lda #<__INTERRUPTOR_COUNT__
130 ; Restore system stuff
133 txs ; Restore stack pointer
135 ; Restore left margin
152 ; Copy back the zero page stuff
169 ; ------------------------------------------------------------------------
170 ; The IRQ vector jumps here, if condes routines are defined with type 2.
173 cld ; Just to be sure
174 jsr callirq ; Call the functions
175 jmp IRQInd ; Jump to the saved IRQ vector
177 ; ------------------------------------------------------------------------
184 ; *** end of main startup code
198 .word RUNAD ; defined in atari.h
200 .word __STARTUP_LOAD__ + 1