Re: How to use timer 2 and timer 3 interrupts with raster interrupts?
Timer 2 and 3 need to be reloaded after countdown.
Initialization:
sei ldx CINV ldy CINV+1 stx oldcinv sty oldcinv+1 ldx #<userirqint ldy #>userirqint stx CINV sty CINV+1
ldx #<period ldy #>period stx T3LO sty T3HI lda #<rasterline sta RASTER lda #[T3 | RAS | >rasterline] sta IRQMSK cli
Interrupt service routine:
userirqint: lda #T3 and IRQCR ; and IRQMSK beq ?skipt3 ; ora #RAS sta IRQCR
ldx #<period ldy #>period stx T3LO sty T3HI
nop ;do something
pla tay pla tax pla rti ?skipt3
lda #RAS and IRQCR ; and IRQMSK beq ?skipraster ; ora #T3 sta IRQCR
lda #<rasterline sta RASTER lda #[T3 | RAS | >rasterline] sta IRQMSK
nop ;do something
?exit pla tay pla tax pla rti ?skipraster
jmp (oldcinv)
If T3 IRQ shouldn't disturb in RASTER routine then I'm enabling IRQ earlier and moving RASTER service prior to T3:
userirqint: lda #T3 and IRQCR ; and IRQMSK beq ?skipt3 ; ora #RAS sta IRQCR
ldx #<period ldy #>period stx T3LO sty T3HI
cli nop ;do something
pla tay pla tax pla rti ?skipt3
Equates:
CINV = $314
T3LO = $FF04 T3HI = $FF05 T3 = 1 << 6 T2 = 1 << 4 T1 = 1 << 3 LP = 1 << 2 RAS = 1 << 1 IRQCR = $FF09 IRQMSK = $FF0A RASTER = $FF0B
|