I've read the primer on IRQ's and I guess I'm just not getting it. If I have a SBC that has two VIA's and a video processor that supports an interrupt on each vertical blank, how does the CPU know which component triggered the interrupt? And, how would I tell the CPU that the video interrupt would always have priority?
Thanks
Multiple IRQ's with a video processor
Multiple IRQ's with a video processor
Cat; the other white meat.
-
DerTrueForce
- Posts: 483
- Joined: 04 Jun 2016
- Location: Australia
Re: Multiple IRQ's with a video processor
You read the Status Registers or Interrupt Flag Registers. There should be at least a bit in a register in an IRQ-enabled device that says "I've interrupted." A bit like a raised hand in a classroom.
You'd set the priority by the order in which you read the registers and clear the interrupts.
You'd set the priority by the order in which you read the registers and clear the interrupts.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Multiple IRQ's with a video processor
That was one of the first articles I ever wrote, and I know my writing has improved since then. There's too much to do to take the time to re-write it though. Anyway, to expand on DerTrueForce's answer, see the half-dozen paragraphs or so starting two paragraphs above this short piece of example code:
and also the area around this diagram:

If you want the video interrupt to be of such high priority that it can cut in on the servicing of other interrupts before those other ones' ISRs get a chance to turn off such interrupts and re-enable interrupting, you can put the video on the NMI input. We're often told to reserve the NMI for something drastic like power going down; but in most systems the people on 6502.org are making, what happens in the last milliseconds before power is gone is of no concern. If you have a system that remembers things when it's off, it probably has batteries and can turn itself off in an orderly fashion. Otherwise, if you accidentally pull the power cord, there's no time to store anything useful on a disc anyway.
Code: Select all
ISR: BIT VIA1_STATUS ; Check 6522 VIA1's status register without loading.
BMI SERVICE_VIA1 ; If it caused the interrupt, branch to service it.
BIT VIA2_STATUS ; Otherwise, check VIA2's status register.
BMI SERVICE_VIA2 ; If that one did the interrupt, branch to service it.
JMP SERVICE_ACIA ; If both VIAs say "not me," it had to be the 6551 ACIA.
;------------- ; (Don't forget that the last ISR instruction to be
; executed must be RTI, not RTS.)
If you want the video interrupt to be of such high priority that it can cut in on the servicing of other interrupts before those other ones' ISRs get a chance to turn off such interrupts and re-enable interrupting, you can put the video on the NMI input. We're often told to reserve the NMI for something drastic like power going down; but in most systems the people on 6502.org are making, what happens in the last milliseconds before power is gone is of no concern. If you have a system that remembers things when it's off, it probably has batteries and can turn itself off in an orderly fashion. Otherwise, if you accidentally pull the power cord, there's no time to store anything useful on a disc anyway.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Multiple IRQ's with a video processor
Ah, OK. I think I get it.
So for each VIA, for example, I would check the IFR ($0D) and if bit 7 is true (using BIT) then that VIA triggered an interrupt. Then, I would just simply check the VIA's in order of importance.
Now since my graphics processor doesn't really have a status register (Propeller), I could either make one or just use the NMI since I want it to be top priority always.
Thanks
So for each VIA, for example, I would check the IFR ($0D) and if bit 7 is true (using BIT) then that VIA triggered an interrupt. Then, I would just simply check the VIA's in order of importance.
Now since my graphics processor doesn't really have a status register (Propeller), I could either make one or just use the NMI since I want it to be top priority always.
Thanks
Cat; the other white meat.
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Multiple IRQ's with a video processor
cbmeeks wrote:
So for each VIA, for example, I would check the IFR ($0D) and if bit 7 is true (using BIT) then that VIA triggered an interrupt. Then, I would just simply check the VIA's in order of importance.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: Multiple IRQ's with a video processor
And keep in mind, that interrupt handling really needs to be short. In a worst case scenario the video interrupt would occur just after a VIA interrupt. So even with having polled the video interrupt flags first you must be sure to still have enough time to service the video interrupt after any of the VIAs got serviced.
6502 sources on GitHub: https://github.com/Klaus2m5
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Multiple IRQ's with a video processor
If you put the video interrupt on NMI, it can cut in on the servicing of other interrupts; so in that case it doesn't matter if the other ISRs are short or not.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Multiple IRQ's with a video processor
True, but NMI has the disadvantage that it cannot be temporarily suspended by SEI or after a reset.
6502 sources on GitHub: https://github.com/Klaus2m5
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Multiple IRQ's with a video processor
Hopefully the video chip has a reset input also, and it won't produce any interrupts until it is again set up to do so.
For suspending interrupts, instead of SEI, you can tell the IC not to interrupt until further notice, or mask NMIs in hardware with a separate gate, maybe a NAND gate. [Edited to fix "an AND" to say "a NAND".]
For suspending interrupts, instead of SEI, you can tell the IC not to interrupt until further notice, or mask NMIs in hardware with a separate gate, maybe a NAND gate. [Edited to fix "an AND" to say "a NAND".]
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Multiple IRQ's with a video processor
GARTHWILSON wrote:
For suspending interrupts, instead of SEI, you can tell the IC not to interrupt until further notice, or mask NMIs in hardware with a separate gate, maybe an AND gate.
Shift to the left,
Shift to the right,
Mask in, Mask Out,
BYTE! BYTE! BYTE!
Shift to the right,
Mask in, Mask Out,
BYTE! BYTE! BYTE!
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Multiple IRQ's with a video processor
You're right! That's what I get for writing too late at night. I'll fix it.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?