Interruptor support
git-svn-id: svn://svn.cc65.org/cc65/trunk@3492 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -4,168 +4,169 @@
|
|||||||
; This must be the *first* file on the linker command line
|
; This must be the *first* file on the linker command line
|
||||||
;
|
;
|
||||||
|
|
||||||
.export _exit
|
.export _exit
|
||||||
.import zerobss
|
.import zerobss
|
||||||
.import initlib, donelib
|
.import initlib, donelib
|
||||||
.import callmain, callirq
|
.import callmain, callirq
|
||||||
.import COUT
|
.import COUT
|
||||||
.import __STARTUP_LOAD__, __BSS_LOAD__ ; Linker generated
|
.import __STARTUP_LOAD__, __BSS_LOAD__ ; Linker generated
|
||||||
.import __INTERRUPTOR_COUNT__ ; Linker generated
|
.import __INTERRUPTOR_COUNT__ ; Linker generated
|
||||||
|
|
||||||
.include "zeropage.inc"
|
.include "zeropage.inc"
|
||||||
.include "apple2.inc"
|
.include "apple2.inc"
|
||||||
.include "mli.inc"
|
.include "mli.inc"
|
||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
|
|
||||||
.segment "EXEHDR"
|
.segment "EXEHDR"
|
||||||
|
|
||||||
.addr __STARTUP_LOAD__ ; Start address
|
.addr __STARTUP_LOAD__ ; Start address
|
||||||
.word __BSS_LOAD__ - __STARTUP_LOAD__ ; Size
|
.word __BSS_LOAD__ - __STARTUP_LOAD__ ; Size
|
||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
|
|
||||||
.segment "STARTUP"
|
.segment "STARTUP"
|
||||||
|
|
||||||
; ProDOS TechRefMan, chapter 5.2.1:
|
; ProDOS TechRefMan, chapter 5.2.1:
|
||||||
; "For maximum interrupt efficiency, a system program should not
|
; "For maximum interrupt efficiency, a system program should not
|
||||||
; use more than the upper 3/4 of the stack."
|
; use more than the upper 3/4 of the stack."
|
||||||
ldx #$FF
|
ldx #$FF
|
||||||
txs ; Init stack pointer
|
txs ; Init stack pointer
|
||||||
|
|
||||||
; Delegate all further processing to keep STARTUP small
|
; Delegate all further processing to keep STARTUP small
|
||||||
jsr init
|
jsr init
|
||||||
|
|
||||||
; Avoid re-entrance of donelib. This is also the _exit entry
|
; Avoid re-entrance of donelib. This is also the _exit entry
|
||||||
_exit: ldx #<exit
|
_exit: ldx #<exit
|
||||||
lda #>exit
|
lda #>exit
|
||||||
jsr reset ; Setup RESET vector
|
jsr reset ; Setup RESET vector
|
||||||
|
|
||||||
; Check for valid interrupt vector table entry number
|
; Check for valid interrupt vector table entry number
|
||||||
lda intnum
|
lda intnum
|
||||||
beq :+
|
beq :+
|
||||||
|
|
||||||
; Deallocate interrupt vector table entry
|
; Deallocate interrupt vector table entry
|
||||||
dec params ; Adjust parameter count
|
dec params ; Adjust parameter count
|
||||||
jsr ENTRY
|
jsr ENTRY
|
||||||
.byte $41 ; Dealloc interrupt
|
.byte $41 ; Dealloc interrupt
|
||||||
.addr params
|
.addr params
|
||||||
|
|
||||||
; Call module destructors
|
; Call module destructors
|
||||||
: jsr donelib
|
: jsr donelib
|
||||||
|
|
||||||
; Restore the original RESET vector
|
; Restore the original RESET vector
|
||||||
exit: ldx #$02
|
exit: ldx #$02
|
||||||
: lda rvsave,x
|
: lda rvsave,x
|
||||||
sta SOFTEV,x
|
sta SOFTEV,x
|
||||||
dex
|
dex
|
||||||
bpl :-
|
bpl :-
|
||||||
|
|
||||||
; Copy back the zero page stuff
|
; Copy back the zero page stuff
|
||||||
ldx #zpspace-1
|
ldx #zpspace-1
|
||||||
: lda zpsave,x
|
: lda zpsave,x
|
||||||
sta sp,x
|
sta sp,x
|
||||||
dex
|
dex
|
||||||
bpl :-
|
bpl :-
|
||||||
|
|
||||||
; ProDOS TechRefMan, chapter 5.2.1:
|
; ProDOS TechRefMan, chapter 5.2.1:
|
||||||
; "System programs should set the stack pointer to $FF at the
|
; "System programs should set the stack pointer to $FF at the
|
||||||
; warm-start entry point."
|
; warm-start entry point."
|
||||||
ldx #$FF
|
ldx #$FF
|
||||||
txs ; Re-init stack pointer
|
txs ; Re-init stack pointer
|
||||||
|
|
||||||
; Back to DOS
|
; Back to DOS
|
||||||
jmp DOSWARM
|
jmp DOSWARM
|
||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
|
|
||||||
.segment "INIT"
|
.segment "INIT"
|
||||||
|
|
||||||
; Save the zero page locations we need
|
; Save the zero page locations we need
|
||||||
init: ldx #zpspace-1
|
init: ldx #zpspace-1
|
||||||
: lda sp,x
|
: lda sp,x
|
||||||
sta zpsave,x
|
sta zpsave,x
|
||||||
dex
|
dex
|
||||||
bpl :-
|
bpl :-
|
||||||
|
|
||||||
; Save the original RESET vector
|
; Save the original RESET vector
|
||||||
ldx #$02
|
ldx #$02
|
||||||
: lda SOFTEV,x
|
: lda SOFTEV,x
|
||||||
sta rvsave,x
|
sta rvsave,x
|
||||||
dex
|
dex
|
||||||
bpl :-
|
bpl :-
|
||||||
|
|
||||||
; ProDOS TechRefMan, chapter 5.3.5:
|
; ProDOS TechRefMan, chapter 5.3.5:
|
||||||
; "Your system program should place in the RESET vector the
|
; "Your system program should place in the RESET vector the
|
||||||
; address of a routine that ... closes the files."
|
; address of a routine that ... closes the files."
|
||||||
ldx #<_exit
|
ldx #<_exit
|
||||||
lda #>_exit
|
lda #>_exit
|
||||||
jsr reset ; Setup RESET vector
|
jsr reset ; Setup RESET vector
|
||||||
|
|
||||||
; Clear the BSS data
|
; Clear the BSS data
|
||||||
jsr zerobss
|
jsr zerobss
|
||||||
|
|
||||||
; Setup the stack
|
; Setup the stack
|
||||||
lda HIMEM
|
lda HIMEM
|
||||||
sta sp
|
sta sp
|
||||||
lda HIMEM+1
|
lda HIMEM+1
|
||||||
sta sp+1 ; Set argument stack ptr
|
sta sp+1 ; Set argument stack ptr
|
||||||
|
|
||||||
; Call module constructors
|
; Call module constructors
|
||||||
jsr initlib
|
jsr initlib
|
||||||
|
|
||||||
; Check for interruptors
|
; Check for interruptors
|
||||||
lda #<__INTERRUPTOR_COUNT__
|
lda #<__INTERRUPTOR_COUNT__
|
||||||
beq :+
|
beq :+
|
||||||
|
|
||||||
; Check for ProDOS
|
; Check for ProDOS
|
||||||
lda ENTRY
|
lda ENTRY
|
||||||
cmp #$4C ; Is MLI present? (JMP opcode)
|
cmp #$4C ; Is MLI present? (JMP opcode)
|
||||||
bne prterr
|
bne prterr
|
||||||
|
|
||||||
; Allocate interrupt vector table entry
|
; Allocate interrupt vector table entry
|
||||||
jsr ENTRY
|
jsr ENTRY
|
||||||
.byte $40 ; Alloc interrupt
|
.byte $40 ; Alloc interrupt
|
||||||
.addr params
|
.addr params
|
||||||
bcs prterr
|
bcs prterr
|
||||||
|
|
||||||
; Push arguments and call main()
|
; Push arguments and call main()
|
||||||
: jmp callmain
|
: jmp callmain
|
||||||
|
|
||||||
; Print error message and return
|
; Print error message and return
|
||||||
prterr: ldx #msglen-1
|
prterr: ldx #msglen-1
|
||||||
: lda errmsg,x
|
: lda errmsg,x
|
||||||
jsr COUT
|
jsr COUT
|
||||||
dex
|
dex
|
||||||
bpl :-
|
bpl :-
|
||||||
rts
|
rts
|
||||||
|
|
||||||
errmsg: .ifdef __APPLE2ENH__
|
errmsg: .ifdef __APPLE2ENH__
|
||||||
.byte $8D, 't'|$80, 'p'|$80, 'u'|$80, 'r'|$80, 'r'|$80
|
.byte $8D, 't'|$80, 'p'|$80, 'u'|$80, 'r'|$80, 'r'|$80
|
||||||
.byte 'e'|$80, 't'|$80, 'n'|$80, 'i'|$80, ' '|$80, 'c'|$80
|
.byte 'e'|$80, 't'|$80, 'n'|$80, 'i'|$80, ' '|$80, 'c'|$80
|
||||||
.byte 'o'|$80, 'l'|$80, 'l'|$80, 'a'|$80, ' '|$80, 'o'|$80
|
.byte 'o'|$80, 'l'|$80, 'l'|$80, 'a'|$80, ' '|$80, 'o'|$80
|
||||||
.byte 't'|$80, ' '|$80, 'd'|$80, 'e'|$80, 'l'|$80, 'i'|$80
|
.byte 't'|$80, ' '|$80, 'd'|$80, 'e'|$80, 'l'|$80, 'i'|$80
|
||||||
.byte 'a'|$80, 'F'|$80, $8D
|
.byte 'a'|$80, 'F'|$80, $8D
|
||||||
.else
|
.else
|
||||||
.byte $8D, 'T'|$80, 'P'|$80, 'U'|$80, 'R'|$80, 'R'|$80
|
.byte $8D, 'T'|$80, 'P'|$80, 'U'|$80, 'R'|$80, 'R'|$80
|
||||||
.byte 'E'|$80, 'T'|$80, 'N'|$80, 'I'|$80, ' '|$80, 'C'|$80
|
.byte 'E'|$80, 'T'|$80, 'N'|$80, 'I'|$80, ' '|$80, 'C'|$80
|
||||||
.byte 'O'|$80, 'L'|$80, 'L'|$80, 'A'|$80, ' '|$80, 'O'|$80
|
.byte 'O'|$80, 'L'|$80, 'L'|$80, 'A'|$80, ' '|$80, 'O'|$80
|
||||||
.byte 'T'|$80, ' '|$80, 'D'|$80, 'E'|$80, 'L'|$80, 'I'|$80
|
.byte 'T'|$80, ' '|$80, 'D'|$80, 'E'|$80, 'L'|$80, 'I'|$80
|
||||||
.byte 'A'|$80, 'F'|$80, $8D
|
.byte 'A'|$80, 'F'|$80, $8D
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
msglen = * - errmsg
|
msglen = * - errmsg
|
||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
|
|
||||||
.segment "LOWCODE"
|
.segment "LOWCODE"
|
||||||
|
|
||||||
; ProDOS TechRefMan, chapter 6.2:
|
; ProDOS TechRefMan, chapter 6.2:
|
||||||
; "Each installed routine must begin with a CLD instruction"
|
; "Each installed routine must begin with a CLD instruction."
|
||||||
intrpt: cld
|
intrpt: cld
|
||||||
|
|
||||||
; Call interruptors
|
; Call interruptors and check for success
|
||||||
jsr callirq
|
jsr callirq
|
||||||
|
bcc :+
|
||||||
|
|
||||||
; ProDOS TechRefMan, chapter 6.2:
|
; ProDOS TechRefMan, chapter 6.2:
|
||||||
; "When the routine that can process the interrupt is called, it
|
; "When the routine that can process the interrupt is called, it
|
||||||
@@ -173,25 +174,31 @@ intrpt: cld
|
|||||||
clc
|
clc
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
; ProDOS TechRefMan, chapter 6.2:
|
||||||
|
; "When a routine that cannot process the interrupt is called,
|
||||||
|
; it should return (via an RTS) with the cary flag set ..."
|
||||||
|
: sec
|
||||||
|
rts
|
||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
|
|
||||||
.code
|
.code
|
||||||
|
|
||||||
; Setup RESET vector
|
; Setup RESET vector
|
||||||
reset: stx SOFTEV
|
reset: stx SOFTEV
|
||||||
sta SOFTEV+1
|
sta SOFTEV+1
|
||||||
eor #$A5
|
eor #$A5
|
||||||
sta PWREDUP
|
sta PWREDUP
|
||||||
rts
|
rts
|
||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
|
|
||||||
.data
|
.data
|
||||||
|
|
||||||
zpsave: .res zpspace
|
zpsave: .res zpspace
|
||||||
|
|
||||||
rvsave: .res 3
|
rvsave: .res 3
|
||||||
|
|
||||||
params: .byte $02 ; Parameter count
|
params: .byte $02 ; Parameter count
|
||||||
intnum: .byte $00 ; Interrupt number
|
intnum: .byte $00 ; Interrupt number
|
||||||
.addr intrpt ; Interrupt handler
|
.addr intrpt ; Interrupt handler
|
||||||
Reference in New Issue
Block a user