Moved IRQ hooking / unhooking from startup code to constructor / destructor to avoid linking in the hooking / unhooking code (and callirq) for the majority of cc65 prorams not linking in interruptors.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5985 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -104,6 +104,7 @@ S_OBJS= _scrsize.o \
|
||||
home.o \
|
||||
initcwd.o \
|
||||
iobuf.o \
|
||||
irq.o \
|
||||
isdevice.o \
|
||||
joy_stat_stddrv.o \
|
||||
joy_stddrv.o \
|
||||
|
||||
@@ -5,75 +5,72 @@
|
||||
;
|
||||
|
||||
.export _exit, done, return
|
||||
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
||||
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
||||
.import zerobss
|
||||
.import initlib, donelib
|
||||
.import callmain, callirq
|
||||
.import __LC_START__, __LC_LAST__ ; Linker generated
|
||||
.import __INIT_RUN__, __INIT_SIZE__ ; Linker generated
|
||||
.import __ZPSAVE_RUN__ ; Linker generated
|
||||
.import __INTERRUPTOR_COUNT__ ; Linker generated
|
||||
.import initlib, donelib
|
||||
.import callmain
|
||||
.import __LC_START__, __LC_LAST__ ; Linker generated
|
||||
.import __INIT_RUN__, __INIT_SIZE__ ; Linker generated
|
||||
.import __ZPSAVE_RUN__ ; Linker generated
|
||||
|
||||
.include "zeropage.inc"
|
||||
.include "apple2.inc"
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.segment "STARTUP"
|
||||
|
||||
; ProDOS TechRefMan, chapter 5.2.1:
|
||||
; "For maximum interrupt efficiency, a system program should not
|
||||
; use more than the upper 3/4 of the stack."
|
||||
ldx #$FF
|
||||
txs ; Init stack pointer
|
||||
txs ; Init stack pointer
|
||||
|
||||
; Switch in LC bank 2 for W/O
|
||||
bit $C081
|
||||
bit $C081
|
||||
; Switch in LC bank 2 for W/O
|
||||
bit $C081
|
||||
bit $C081
|
||||
|
||||
; Set source start address
|
||||
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
||||
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
||||
sta $9B
|
||||
sty $9C
|
||||
; Set source start address
|
||||
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
||||
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
||||
sta $9B
|
||||
sty $9C
|
||||
|
||||
; Set source last address
|
||||
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
|
||||
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
|
||||
sta $96
|
||||
sty $97
|
||||
; Set source last address
|
||||
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
|
||||
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
|
||||
sta $96
|
||||
sty $97
|
||||
|
||||
; Set destination last address
|
||||
lda #<__LC_LAST__
|
||||
ldy #>__LC_LAST__
|
||||
sta $94
|
||||
sty $95
|
||||
; Set destination last address
|
||||
lda #<__LC_LAST__
|
||||
ldy #>__LC_LAST__
|
||||
sta $94
|
||||
sty $95
|
||||
|
||||
; Call into Applesoft Block Transfer Utility - which handles zero
|
||||
; sized blocks well - to move content of the LC memory area
|
||||
jsr $D396 ; BLTU + 3
|
||||
; Call into Applesoft Block Transfer Utility - which handles zero
|
||||
; sized blocks well - to move content of the LC memory area
|
||||
jsr $D396 ; BLTU + 3
|
||||
|
||||
; Set source start address
|
||||
lda #<__ZPSAVE_RUN__
|
||||
ldy #>__ZPSAVE_RUN__
|
||||
sta $9B
|
||||
sty $9C
|
||||
; Set source start address
|
||||
lda #<__ZPSAVE_RUN__
|
||||
ldy #>__ZPSAVE_RUN__
|
||||
sta $9B
|
||||
sty $9C
|
||||
|
||||
; Set source last address
|
||||
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
||||
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
||||
sta $96
|
||||
sty $97
|
||||
; Set source last address
|
||||
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
||||
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
||||
sta $96
|
||||
sty $97
|
||||
|
||||
; Set destination last address
|
||||
lda #<(__INIT_RUN__ + __INIT_SIZE__)
|
||||
ldy #>(__INIT_RUN__ + __INIT_SIZE__)
|
||||
sta $94
|
||||
sty $95
|
||||
; Set destination last address
|
||||
lda #<(__INIT_RUN__ + __INIT_SIZE__)
|
||||
ldy #>(__INIT_RUN__ + __INIT_SIZE__)
|
||||
sta $94
|
||||
sty $95
|
||||
|
||||
; Call into Applesoft Block Transfer Utility - which handles moving
|
||||
; overlapping blocks upwards well - to move the INIT segment
|
||||
jsr $D396 ; BLTU + 3
|
||||
; Call into Applesoft Block Transfer Utility - which handles moving
|
||||
; overlapping blocks upwards well - to move the INIT segment
|
||||
jsr $D396 ; BLTU + 3
|
||||
|
||||
; Delegate all further processing to keep the STARTUP segment small
|
||||
jsr init
|
||||
@@ -81,24 +78,14 @@
|
||||
; Avoid re-entrance of donelib. This is also the _exit entry
|
||||
_exit: ldx #<exit
|
||||
lda #>exit
|
||||
jsr reset ; Setup RESET vector
|
||||
jsr reset ; Setup RESET vector
|
||||
|
||||
; Switch in ROM in case it wasn't already switched in by a RESET
|
||||
bit $C082
|
||||
bit $C082
|
||||
|
||||
; Call module destructors
|
||||
jsr donelib
|
||||
|
||||
; Check for valid interrupt vector table entry number
|
||||
lda int_num
|
||||
beq exit
|
||||
|
||||
; Deallocate interrupt vector table entry
|
||||
dec i_param ; Adjust parameter count
|
||||
jsr $BF00 ; MLI call entry point
|
||||
.byte $41 ; Dealloc interrupt
|
||||
.addr i_param
|
||||
|
||||
; Restore the original RESET vector
|
||||
exit: ldx #$02
|
||||
: lda rvsave,x
|
||||
@@ -122,8 +109,6 @@ exit: ldx #$02
|
||||
; We're done
|
||||
jmp (done)
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.segment "INIT"
|
||||
|
||||
; Save the zero page locations we need
|
||||
@@ -148,11 +133,11 @@ init: ldx #zpspace-1
|
||||
; address of a routine that ... closes the files."
|
||||
ldx #<_exit
|
||||
lda #>_exit
|
||||
jsr reset ; Setup RESET vector
|
||||
jsr reset ; Setup RESET vector
|
||||
|
||||
; Check for ProDOS
|
||||
ldy $BF00 ; MLI call entry point
|
||||
cpy #$4C ; Is MLI present? (JMP opcode)
|
||||
ldy $BF00 ; MLI call entry point
|
||||
cpy #$4C ; Is MLI present? (JMP opcode)
|
||||
bne basic
|
||||
|
||||
; Check ProDOS system bit map
|
||||
@@ -179,80 +164,20 @@ basic: lda HIMEM
|
||||
: sta sp
|
||||
stx sp+1
|
||||
|
||||
; Check for interruptors
|
||||
lda #<__INTERRUPTOR_COUNT__
|
||||
beq :+
|
||||
|
||||
; Check for ProDOS
|
||||
cpy #$4C ; Is MLI present? (JMP opcode)
|
||||
bne prterr
|
||||
|
||||
; Allocate interrupt vector table entry
|
||||
jsr $BF00 ; MLI call entry point
|
||||
.byte $40 ; Alloc interrupt
|
||||
.addr i_param
|
||||
bcs prterr
|
||||
|
||||
; Enable interrupts as old ProDOS versions (i.e. 1.1.1)
|
||||
; jump to SYS and BIN programs with interrupts disabled
|
||||
cli
|
||||
; Enable interrupts as old ProDOS versions (i.e. 1.1.1)
|
||||
; jump to SYS and BIN programs with interrupts disabled
|
||||
cli
|
||||
|
||||
; Call module constructors
|
||||
: jsr initlib
|
||||
jsr initlib
|
||||
|
||||
; Switch in LC bank 2 for R/O
|
||||
bit $C080
|
||||
; Switch in LC bank 2 for R/O
|
||||
bit $C080
|
||||
|
||||
; Push arguments and call main()
|
||||
jmp callmain
|
||||
|
||||
; Print error message and return
|
||||
prterr: ldx #msglen-1
|
||||
: lda errmsg,x
|
||||
jsr $FDED ; COUT
|
||||
dex
|
||||
bpl :-
|
||||
rts
|
||||
|
||||
errmsg: .ifdef __APPLE2ENH__
|
||||
.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 'o'|$80, 'l'|$80, 'l'|$80, 'a'|$80, ' '|$80, 'o'|$80
|
||||
.byte 't'|$80, ' '|$80, 'd'|$80, 'e'|$80, 'l'|$80, 'i'|$80
|
||||
.byte 'a'|$80, 'F'|$80, $8D
|
||||
.else
|
||||
.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 'O'|$80, 'L'|$80, 'L'|$80, 'A'|$80, ' '|$80, 'O'|$80
|
||||
.byte 'T'|$80, ' '|$80, 'D'|$80, 'E'|$80, 'L'|$80, 'I'|$80
|
||||
.byte 'A'|$80, 'F'|$80, $8D
|
||||
.endif
|
||||
|
||||
msglen = * - errmsg
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.segment "LOWCODE"
|
||||
|
||||
; ProDOS TechRefMan, chapter 6.2:
|
||||
; "Each installed routine must begin with a CLD instruction."
|
||||
intptr: cld
|
||||
|
||||
; Call interruptors and check for success
|
||||
jsr callirq
|
||||
bcc :+
|
||||
|
||||
; ProDOS TechRefMan, chapter 6.2:
|
||||
; "When the routine that can process the interrupt is called, it
|
||||
; should ... return (via an RTS) with the carry flag clear."
|
||||
clc
|
||||
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
|
||||
|
||||
; Setup RESET vector
|
||||
reset: stx SOFTEV
|
||||
@@ -266,37 +191,24 @@ quit: jsr $BF00 ; MLI call entry point
|
||||
.byte $65 ; Quit
|
||||
.word q_param
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.rodata
|
||||
|
||||
; MLI parameter list for quit
|
||||
q_param:.byte $04 ; param_count
|
||||
.byte $00 ; quit_type
|
||||
.word $0000 ; reserved
|
||||
.byte $00 ; reserved
|
||||
.word $0000 ; reserved
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; MLI parameter list for quit
|
||||
q_param:.byte $04 ; param_count
|
||||
.byte $00 ; quit_type
|
||||
.word $0000 ; reserved
|
||||
.byte $00 ; reserved
|
||||
.word $0000 ; reserved
|
||||
|
||||
.data
|
||||
|
||||
; MLI parameter list for (de)alloc interrupt
|
||||
i_param:.byte $02 ; param_count
|
||||
int_num:.byte $00 ; int_num
|
||||
.addr intptr ; int_code
|
||||
|
||||
; Location to jump to when we're done
|
||||
done: .addr DOSWARM
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.segment "ZPSAVE"
|
||||
|
||||
zpsave: .res zpspace
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.bss
|
||||
|
||||
rvsave: .res 3
|
||||
|
||||
94
libsrc/apple2/irq.s
Normal file
94
libsrc/apple2/irq.s
Normal file
@@ -0,0 +1,94 @@
|
||||
;
|
||||
; Oliver Schmidt, 2012-11-17
|
||||
;
|
||||
; IRQ handling (Apple2 version)
|
||||
;
|
||||
|
||||
.export initirq, doneirq
|
||||
.import callirq, __dos_type, _exit
|
||||
|
||||
.include "zeropage.inc"
|
||||
.include "apple2.inc"
|
||||
|
||||
.segment "INIT"
|
||||
|
||||
initirq:
|
||||
; Check for ProDOS
|
||||
lda __dos_type
|
||||
beq prterr
|
||||
|
||||
; Allocate interrupt vector table entry
|
||||
jsr $BF00 ; MLI call entry point
|
||||
.byte $40 ; Alloc interrupt
|
||||
.addr i_param
|
||||
bcs prterr
|
||||
rts
|
||||
|
||||
; Print error message and exit
|
||||
prterr: ldx #msglen-1
|
||||
: lda errmsg,x
|
||||
jsr $FDED ; COUT
|
||||
dex
|
||||
bpl :-
|
||||
jmp _exit
|
||||
|
||||
errmsg: .ifdef __APPLE2ENH__
|
||||
.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 'o'|$80, 'l'|$80, 'l'|$80, 'a'|$80, ' '|$80, 'o'|$80
|
||||
.byte 't'|$80, ' '|$80, 'd'|$80, 'e'|$80, 'l'|$80, 'i'|$80
|
||||
.byte 'a'|$80, 'F'|$80, $8D
|
||||
.else
|
||||
.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 'O'|$80, 'L'|$80, 'L'|$80, 'A'|$80, ' '|$80, 'O'|$80
|
||||
.byte 'T'|$80, ' '|$80, 'D'|$80, 'E'|$80, 'L'|$80, 'I'|$80
|
||||
.byte 'A'|$80, 'F'|$80, $8D
|
||||
.endif
|
||||
|
||||
msglen = * - errmsg
|
||||
|
||||
.code
|
||||
|
||||
doneirq:
|
||||
; Check for valid interrupt vector table entry number which
|
||||
; IS necessary as this gets called even if initirq failed.
|
||||
lda int_num
|
||||
beq :+
|
||||
|
||||
; Deallocate interrupt vector table entry
|
||||
dec i_param ; Adjust parameter count
|
||||
jsr $BF00 ; MLI call entry point
|
||||
.byte $41 ; Dealloc interrupt
|
||||
.addr i_param
|
||||
: rts
|
||||
|
||||
.segment "LOWCODE"
|
||||
|
||||
intptr:
|
||||
; ProDOS TechRefMan, chapter 6.2:
|
||||
; "Each installed routine must begin with a CLD instruction."
|
||||
cld
|
||||
|
||||
; Call interruptors and check for success
|
||||
jsr callirq
|
||||
bcc :+
|
||||
|
||||
; ProDOS TechRefMan, chapter 6.2:
|
||||
; "When the routine that can process the interrupt is called, it
|
||||
; should ... return (via an RTS) with the carry flag clear."
|
||||
clc
|
||||
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
|
||||
|
||||
.data
|
||||
|
||||
; MLI parameter list for (de)alloc interrupt
|
||||
i_param:.byte $02 ; param_count
|
||||
int_num:.byte $00 ; int_num
|
||||
.addr intptr ; int_code
|
||||
@@ -4,8 +4,8 @@
|
||||
; void rebootafterexit (void);
|
||||
;
|
||||
|
||||
.constructor initreboot
|
||||
.export _rebootafterexit
|
||||
.constructor initreboot, 11
|
||||
.export _rebootafterexit
|
||||
.import done, return
|
||||
|
||||
_rebootafterexit := return
|
||||
|
||||
Reference in New Issue
Block a user