Help with Timer Interrupt

Basic and Machine Language

Moderator: Moderators

daved1818
Vic 20 Newbie
Posts: 2
Joined: Thu Feb 08, 2018 2:22 pm

Help with Timer Interrupt

Postby daved1818 » Thu Feb 08, 2018 2:41 pm

Hi

I'm new to the forums and the VIC-20 was my second computer (first was ZX81). I never got beyond BASIC programming, all my M/C was on later machines, so after 36 years I thought I'd try some M/C on the VIC.

I am having some trouble getting interrupts working properly though, I have written the following code to test a VIA 2, T2 interrupt but it gets stuck in the interrupt routine. Instead of returning to the main loop once the RTI is called it jumps straight back to $FF72. I am debugging in VICE but it doesn't show what the 6522s are doing so it doesn't help much. I know it will be something simple but I can't see it for the life of me and I've tried google.

Grateful for any assistance, thanks.

Dave

Code posted below.

Code: Select all

*=$1046

start
        sei             ;disable interrupts

        lda #<my_irq
        ldx #>my_irq
        sta $314
        stx $315       ;set up interrupt address


        ldy #$FF
        sty $9218
        sty $9219       ;set V2 T2 counter

        lda #$7f        ;clear all via#2 interrupt enable bits
        sta $921e

        lda #$a0        ;enable T2 interrupt on via#2
        sta $921e       

        lda $921b       ;read aux control
        and #$df        ;clear T2 control bit
        sta $921b      ;so T2 is one shot counter

        cli             ;now enable interrupts


loop
        lda #$ff
        sta $900f
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        jmp loop


my_irq

        ;is it from V2 T2
        lda $921d
        and #$20
        beq my_irq_end

        lda #$0
        sta $900f       ;set border/screen colour

        lda #$FF
        sta $9218       ;set V2 T2 counter
        sta $9219       ;this write should clear int flag

my_irq_end
        pla
        tay
        pla
        tax
        pla
        rti


daved1818
Vic 20 Newbie
Posts: 2
Joined: Thu Feb 08, 2018 2:22 pm

Re: Help with Timer Interrupt

Postby daved1818 » Thu Feb 08, 2018 5:05 pm

Arghh! looked at this so many times before realising I'd updated the wrong number when changing from VIA 1 to 2. I had changed the second digit to 2 rather than the 3rd. Ie, changed $9118 to $9218 instead of $9128. Hours wasted trying to understand why it wasn't working. I blame my old eyes!

CurtisP
Vic 20 Dabbler
Posts: 91
Joined: Tue Mar 08, 2005 8:24 pm

Re: Help with Timer Interrupt

Postby CurtisP » Thu Feb 08, 2018 7:53 pm

daved1818 wrote:Arghh! looked at this so many times before realising I'd updated the wrong number when changing from VIA 1 to 2. I had changed the second digit to 2 rather than the 3rd. Ie, changed $9118 to $9218 instead of $9128. Hours wasted trying to understand why it wasn't working. I blame my old eyes!

If you are stuck on a bug more than fifteen minutes, then it's usually best to walk away for an hour or more and come back with fresh eyes.

Glad you found it.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests