2 ; Startup code for cc65 (ATARI version)
4 ; Contributing authors:
11 .export __STARTUP__ : absolute = 1 ; Mark as startup
12 .export _exit, start, excexit, SP_save
14 .import initlib, donelib
15 .import callmain, zerobss
16 .import __RESERVED_MEMORY__
17 .import __MAIN_START__, __MAIN_SIZE__
18 .import __LOWCODE_RUN__, __LOWCODE_SIZE__
24 .forceimport sramprep ; force inclusion of the "shadow RAM preparation" load chunk
25 .include "save_area.inc"
28 .include "zeropage.inc"
31 ; ------------------------------------------------------------------------
35 rts ; fix for SpartaDOS / OS/A+
36 ; They first call the entry point from AUTOSTRT; and
37 ; then, the load address (this rts here).
38 ; We point AUTOSTRT directly after the rts.
59 lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
60 ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
66 ; Report the memory usage.
70 sta APPMHI_save ; remember old APPMHI value
75 sbc #<__RESERVED_MEMORY__
76 sta APPMHI ; initialize our APPMHI value
77 sta sp ; set up runtime stack part 1
79 sbc #>__RESERVED_MEMORY__
81 sta sp+1 ; set up runtime stack part 2
85 ; Call the module constructors.
89 ; Set the left margin to 0.
96 ; Set the keyboard to upper-/lower-case mode.
102 ; Initialize the conio stuff.
105 sty CH ; remove keypress which might be in the input buffer
107 ; Push the command-line arguments; and, call main().
111 ; Call the module destructors. This is also the exit() entry.
114 txs ; Restore stack pointer
116 ; Restore the system stuff.
118 excexit:jsr donelib ; Run module destructors; 'excexit' is called from the exec routine
120 ; Restore the left margin.
125 ; Restore the kb mode.
139 ; Atari XL target stuff...
151 ; Issue a GRAPHICS 0 call (copied'n'pasted from the TGI drivers), in
152 ; order to restore screen memory to its default location just
157 ; Reopen it in Graphics 0
173 ; No error checking here, shouldn't happen(TM); and, no way to
182 ; Turn on the cursor.
191 ; *** end of main startup code
193 ; ------------------------------------------------------------------------
204 ; ------------------------------------------------------------------------
206 .segment "LOWCODE" ; have at least one (empty) segment of LOWCODE, so that the next line works even if the program doesn't make use of this segment
207 .assert (__LOWCODE_RUN__ + __LOWCODE_SIZE__ <= $4000 || __LOWCODE_RUN__ > $7FFF || __LOWCODE_SIZE__ = 0), warning, "'lowcode area' reaches into $4000..$7FFF bank memory window"
208 ; check for LOWBSS_SIZE = 0 not needed since the only file which uses LOWBSS (irq.s) also uses LOWCODE
209 ; check for LOWCODE_RUN > $7FFF is mostly for cartridges, where this segment is loaded high (into cart ROM)
210 ; there is a small chance that if the user loads the program really high, LOWCODE is above $7FFF, but LOWBSS is below -- no warning emitted in this case