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:
ol.sc
2013-02-12 22:39:38 +00:00
parent 1607b05104
commit 7c9171ee87
36 changed files with 886 additions and 732 deletions

View File

@@ -79,6 +79,7 @@ OBJS = bllhdr.o \
exec.o \
exehdr.o \
extzp.o \
irq.o \
joy_stat_stddrv.o \
joy_stddrv.o \
kbhit.o \

View File

@@ -15,31 +15,29 @@
; on the front of the fully linked binary (see EXEHDR segment.)
;
.include "lynx.inc"
.export _exit
.export __STARTUP__ : absolute = 1 ; Mark as startup
.export _exit
.export __STARTUP__ : absolute = 1 ; Mark as startup
.import callirq, initlib, donelib
.import zerobss
.import callmain
.import _main
.import __INTERRUPTOR_COUNT__
.import __RAM_START__, __RAM_SIZE__, __STACKSIZE__
.import initlib, donelib
.import zerobss
.import callmain
.import _main
.import __RAM_START__, __RAM_SIZE__, __STACKSIZE__
.include "zeropage.inc"
.include "extzp.inc"
.include "zeropage.inc"
.include "extzp.inc"
.include "lynx.inc"
; ------------------------------------------------------------------------
; Mikey and Suzy init data, reg offsets and data
.rodata
SuzyInitReg: .byte $28,$2a,$04,$06,$92,$83,$90
SuzyInitData: .byte $7f,$7f,$00,$00,$24,$f3,$01
MikeyInitReg: .byte $00,$01,$08,$09,$20,$28,$30,$38,$44,$50,$8a,$8b,$8c,$92,$93
MikeyInitData: .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$29
SuzyInitReg: .byte $28,$2a,$04,$06,$92,$83,$90
SuzyInitData: .byte $7f,$7f,$00,$00,$24,$f3,$01
MikeyInitReg: .byte $00,$01,$08,$09,$20,$28,$30,$38,$44,$50,$8a,$8b,$8c,$92,$93
MikeyInitData: .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$29
; ------------------------------------------------------------------------
; Actual code
@@ -50,116 +48,89 @@ MikeyInitData: .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$2
sei
cld
ldx #$FF
ldx #$FF
txs
; init bank switching
lda #$C
sta MAPCTL ; $FFF9
lda #$C
sta MAPCTL ; $FFF9
; disable all timer interrupts
lda #$80
trb TIM0CTLA
trb TIM1CTLA
trb TIM2CTLA
trb TIM3CTLA
trb TIM5CTLA
trb TIM6CTLA
trb TIM7CTLA
lda #$80
trb TIM0CTLA
trb TIM1CTLA
trb TIM2CTLA
trb TIM3CTLA
trb TIM5CTLA
trb TIM6CTLA
trb TIM7CTLA
; disable TX/RX IRQ, set to 8E1
lda #%11101
sta SERCTL
lda #%11101
sta SERCTL
; clear all pending interrupts
lda INTSET
sta INTRST
lda INTSET
sta INTRST
; setup the stack
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp+1
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp+1
; Init Mickey
ldx #.sizeof(MikeyInitReg)-1
mloop: ldy MikeyInitReg,x
lda MikeyInitData,x
sta $fd00,y
ldx #.sizeof(MikeyInitReg)-1
mloop: ldy MikeyInitReg,x
lda MikeyInitData,x
sta $fd00,y
dex
bpl mloop
bpl mloop
; these are RAM-shadows of read only regs
ldx #$1b
stx __iodat
dex ; $1A
stx __iodir
ldx #$d
stx __viddma
ldx #$1b
stx __iodat
dex ; $1A
stx __iodir
ldx #$d
stx __viddma
; Init Suzy
ldx #.sizeof(SuzyInitReg)-1
sloop: ldy SuzyInitReg,x
lda SuzyInitData,x
sta $fc00,y
ldx #.sizeof(SuzyInitReg)-1
sloop: ldy SuzyInitReg,x
lda SuzyInitData,x
sta $fc00,y
dex
bpl sloop
bpl sloop
lda #$24
sta __sprsys
lda #$24
sta __sprsys
cli
; Clear the BSS data
jsr zerobss
; If we have IRQ functions, set the IRQ vector
; as Lynx is a console there is not much point in releasing the IRQ
lda #<__INTERRUPTOR_COUNT__
beq NoIRQ1
lda #<IRQStub
ldx #>IRQStub
sei
sta INTVECTL
stx INTVECTH
cli
jsr zerobss
; Call module constructors
NoIRQ1: jsr initlib
jsr initlib
; Push arguments and call main
jsr callmain
jsr callmain
; Call module destructors. This is also the _exit entry.
_exit: jsr donelib ; Run module destructors
_exit: jsr donelib ; Run module destructors
; Endless loop
noret: bra noret
.segment "CODE"
IRQStub:
phy
phx
pha
cld
jsr callirq
lda INTSET
sta INTRST
pla
plx
ply
rti
noret: bra noret

46
libsrc/lynx/irq.s Normal file
View File

@@ -0,0 +1,46 @@
;
; IRQ handling (Lynx version)
;
.export initirq, doneirq
.import callirq
.include "lynx.inc"
; ------------------------------------------------------------------------
.segment "INIT"
initirq:
lda #<IRQStub
ldx #>IRQStub
sei
sta INTVECTL
stx INTVECTH
cli
rts
; ------------------------------------------------------------------------
.code
doneirq:
; as Lynx is a console there is not much point in releasing the IRQ
rts
; ------------------------------------------------------------------------
.segment "LOWCODE"
IRQStub:
phy
phx
pha
cld
jsr callirq
lda INTSET
sta INTRST
pla
plx
ply
rti