; Mark Keates
; Freddy Offenga
; Christian Groessler
; Mark Keates
; Freddy Offenga
; Christian Groessler
- .export __STARTUP__ : absolute = 1 ; Mark as startup
+ .export __STARTUP__ : absolute = 1 ; Mark as startup
- .import initlib, donelib, callmain
- .import zerobss, pushax
- .import _main, __filetab, getfd
+ .import initlib, donelib
+ .import callmain, zerobss, callirq
+ .import __INTERRUPTOR_COUNT__
.import __STARTUP_LOAD__, __ZPSAVE_LOAD__
.import __RESERVED_MEMORY__
.import __STARTUP_LOAD__, __ZPSAVE_LOAD__
.import __RESERVED_MEMORY__
- .include "zeropage.inc"
+ .include "zeropage.inc"
.include "atari.inc"
; ------------------------------------------------------------------------
.include "atari.inc"
; ------------------------------------------------------------------------
; Save the zero page locations we need
; Save the zero page locations we need
L1: lda sp,x
sta zpsave,x
dex
L1: lda sp,x
sta zpsave,x
dex
lda APPMHI
sta appmsav ; remember old APPMHI value
lda APPMHI
sta appmsav ; remember old APPMHI value
sta APPMHI+1
sta sp+1 ; setup runtime stack part 2
sta APPMHI+1
sta sp+1 ; setup runtime stack part 2
+; If we have IRQ functions, chain our stub into the IRQ vector
+
+ lda #<__INTERRUPTOR_COUNT__
+ beq NoIRQ1
+ lda VVBLKI
+ ldx VVBLKI+1
+ sta IRQInd+1
+ stx IRQInd+2
+ lda #6
+ ldy #<IRQStub
+ ldx #>IRQStub
+ jsr SETVBV
+
; Call module constructors
; Call module constructors
lda LMARGN
sta old_lmargin
ldy #0
sty LMARGN
lda LMARGN
sta old_lmargin
ldy #0
sty LMARGN
-; set keyb to upper/lowercase mode
+; Set keyb to upper/lowercase mode
ldx SHFLOK
stx old_shflok
ldx SHFLOK
stx old_shflok
sty CH
; Push arguments and call main
sty CH
; Push arguments and call main
_exit: jsr donelib ; Run module destructors
_exit: jsr donelib ; Run module destructors
+; Reset the IRQ vector if we chained it.
+
+ pha ; Save the return code on stack
+ lda #<__INTERRUPTOR_COUNT__
+ beq NoIRQ2
+ lda #6
+ ldy IRQInd+1
+ ldx IRQInd+2
+ jsr SETVBV
+
- ldx spsave
- txs ; Restore stack pointer
+NoIRQ2: ldx spsave
+ txs ; Restore stack pointer
lda old_lmargin
sta LMARGN
lda old_lmargin
sta LMARGN
lda old_shflok
sta SHFLOK
lda old_shflok
sta SHFLOK
+; ------------------------------------------------------------------------
+; The IRQ vector jumps here, if condes routines are defined with type 2.
+
+IRQStub:
+ cld ; Just to be sure
+ jsr callirq ; Call the functions
+ jmp IRQInd ; Jump to the saved IRQ vector
+
+; ------------------------------------------------------------------------
+; Data
+
+.data
+
+IRQInd: jmp $0000
+
; *** end of main startup code
; *** end of main startup code