JimDrew wrote:
What I can't tell is what happens when you clear the IER bit when a IRF bit (and IRQ) are set. Does the IRQ get cleared even though this event already occurred?
If you clear an IER bit then the corresponding IFR bit will not contribute to generating an IRQ but the condition itself if not cleared. You have to reset the flag or access the appropriate register (e.g for timer flags) to clear the condition.
For example in my SXB interrupt handler
Code:
lda VIA1_IFR ; Is VIA1 the source?
bpl VIA1Handled ; No.
pha
and #%01000000 ; Is Timer1 the source?
beq VIA1T1Handled ; No
lda VIA1_T1CL ; Clear the interrupt
inc JIFFY ; Bump jiffy counter
lda JIFFY
cmp #TIMER_HZ ; Reached a second?
bne VIA1T1Handled ; No.
stz JIFFY ; Reset jiffy counter
inc TIME+0 ; And bump main timer
bne VIA1T1Handled
inc TIME+1
bne VIA1T1Handled
inc TIME+2
bne VIA1T1Handled
inc TIME+3
VIA1T1Handled:
pla ; Is Timer2 the source
and #%00100000
beq VIA1T2Handled ; No.
lda VIA1_T2CL ; Clear the interrupt
lda #%00100000 ; Disable T2 interrupt
sta VIA1_IER
lda #TX_LOCK ; Unlock TX hardware
trb LOCKS
VIA1T2Handled: