;
.export __STARTUP__ : absolute = 1 ; Mark as startup
- .export _exit, start
+ .export _exit, start, excexit, SP_save
.import initlib, donelib
.import callmain, zerobss
.import __RESERVED_MEMORY__
- .import __RAM_START__, __RAM_SIZE__
+ .import __MAIN_START__, __MAIN_SIZE__
+ .import __LOWCODE_RUN__, __LOWCODE_SIZE__
.ifdef __ATARIXL__
.import __STACKSIZE__
.import sram_init
.ifdef __ATARIXL__
- lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
+ lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
+ ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
sta sp
- lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
- sta sp+1
+ stx sp+1
.else
; Report the memory usage.
lda APPMHI
+ ldx APPMHI+1
sta APPMHI_save ; remember old APPMHI value
- lda APPMHI+1
- sta APPMHI_save+1
+ stx APPMHI_save+1
sec
lda MEMTOP
; Call the module destructors. This is also the exit() entry.
-_exit: jsr donelib ; Run module destructors
+_exit: ldx SP_save
+ txs ; Restore stack pointer
; Restore the system stuff.
- ldx SP_save
- txs ; Restore stack pointer
+excexit:jsr donelib ; Run module destructors; 'excexit' is called from the exec routine
; Restore the left margin.
; Restore APPMHI.
lda APPMHI_save
+ ldx APPMHI_save+1
sta APPMHI
- lda APPMHI_save+1
- sta APPMHI+1
+ stx APPMHI+1
.ifdef __ATARIXL__
lda RAMTOP_save
sta RAMTOP
lda MEMTOP_save
+ ldx MEMTOP_save+1
sta MEMTOP
- lda MEMTOP_save+1
- sta MEMTOP+1
+ stx MEMTOP+1
; Issue a GRAPHICS 0 call (copied'n'pasted from the TGI drivers), in
.ifndef __ATARIXL__
APPMHI_save: .res 2
.endif
+
+; ------------------------------------------------------------------------
+
+.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
+.assert (__LOWCODE_RUN__ + __LOWCODE_SIZE__ <= $4000 || __LOWCODE_RUN__ > $7FFF || __LOWCODE_SIZE__ = 0), warning, "'lowcode area' reaches into $4000..$7FFF bank memory window"
+; check for LOWBSS_SIZE = 0 not needed since the only file which uses LOWBSS (irq.s) also uses LOWCODE
+; check for LOWCODE_RUN > $7FFF is mostly for cartridges, where this segment is loaded high (into cart ROM)
+; 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