2012-01-21 12:28:23 +00:00
|
|
|
;
|
2015-08-26 23:29:39 +00:00
|
|
|
; 2012-01-18, Oliver Schmidt
|
|
|
|
; 2015-08-22, Greg King
|
2012-01-19 00:24:13 +00:00
|
|
|
;
|
|
|
|
; void __fastcall__ set_irq (irq_handler f, void *stack_addr, size_t stack_size);
|
|
|
|
; void reset_irq (void);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _set_irq, _reset_irq
|
|
|
|
.interruptor clevel_irq, 1 ; Export as low priority IRQ handler
|
2017-10-23 16:57:28 +00:00
|
|
|
.import popax, __ZP_START__, jmpvec
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.macpack generic
|
2012-01-19 00:24:13 +00:00
|
|
|
|
|
|
|
|
2012-11-04 15:23:05 +00:00
|
|
|
; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
irqvec: jmp $00FF ; Patched at runtime
|
2012-11-04 15:23:05 +00:00
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
irqsp: .res 2
|
2012-11-04 15:23:05 +00:00
|
|
|
|
|
|
|
zpsave: .res zpsavespace
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
|
|
|
2015-08-26 23:29:39 +00:00
|
|
|
.code
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc _set_irq
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Keep clevel_irq from being called right now
|
|
|
|
sei
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Set irq stack pointer to stack_addr + stack_size
|
|
|
|
sta irqsp
|
|
|
|
stx irqsp+1
|
|
|
|
jsr popax
|
|
|
|
add irqsp
|
|
|
|
sta irqsp
|
|
|
|
txa
|
|
|
|
adc irqsp+1
|
|
|
|
sta irqsp+1
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Set irq vector to irq_handler
|
|
|
|
jsr popax
|
|
|
|
sta irqvec+1
|
|
|
|
stx irqvec+2 ; Set the user vector
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Restore interrupt requests and return
|
|
|
|
cli
|
|
|
|
rts
|
2012-01-19 00:24:13 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc _reset_irq
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #$00
|
|
|
|
sta irqvec+2 ; High byte is enough
|
|
|
|
rts
|
2012-01-19 00:24:13 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc clevel_irq
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Is C level interrupt request vector set?
|
|
|
|
lda irqvec+2 ; High byte is enough
|
|
|
|
bne @L1
|
|
|
|
clc ; Interrupt not handled
|
|
|
|
rts
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Save our zero page locations
|
|
|
|
@L1: ldx #.sizeof(::zpsave)-1
|
2015-08-26 23:29:39 +00:00
|
|
|
@L2: lda <__ZP_START__,x
|
2013-05-09 11:56:54 +00:00
|
|
|
sta zpsave,x
|
|
|
|
dex
|
|
|
|
bpl @L2
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2017-10-23 16:57:28 +00:00
|
|
|
; Save jmpvec
|
|
|
|
lda jmpvec+1
|
|
|
|
pha
|
|
|
|
lda jmpvec+2
|
|
|
|
pha
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Set C level interrupt stack
|
|
|
|
lda irqsp
|
|
|
|
ldx irqsp+1
|
|
|
|
sta sp
|
|
|
|
stx sp+1
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Call C level interrupt request handler
|
|
|
|
jsr irqvec
|
2012-01-19 11:54:26 +00:00
|
|
|
|
2017-10-23 16:57:28 +00:00
|
|
|
; Mark interrupt handled / not handled
|
|
|
|
lsr
|
|
|
|
|
|
|
|
; Restore our zero page content
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #.sizeof(::zpsave)-1
|
2017-10-23 16:57:28 +00:00
|
|
|
@L3: lda zpsave,x
|
|
|
|
sta <__ZP_START__,x
|
2013-05-09 11:56:54 +00:00
|
|
|
dex
|
|
|
|
bpl @L3
|
2012-01-19 00:24:13 +00:00
|
|
|
|
2017-10-23 16:57:28 +00:00
|
|
|
; Restore jmpvec and return
|
|
|
|
pla
|
|
|
|
sta jmpvec+2
|
|
|
|
pla
|
|
|
|
sta jmpvec+1
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2012-01-19 00:24:13 +00:00
|
|
|
|
|
|
|
.endproc
|