6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 21, 2024 2:16 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Sun Jan 14, 2018 7:08 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1228
Location: Soddy-Daisy, TN USA
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

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 14, 2018 8:08 pm 
Offline

Joined: Sat Jun 04, 2016 10:22 pm
Posts: 483
Location: Australia
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.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 14, 2018 9:30 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8510
Location: Southern California
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:

Code:
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.)


and also the area around this diagram:
Image

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?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 15, 2018 4:42 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1228
Location: Soddy-Daisy, TN USA
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

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 15, 2018 6:17 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8390
Location: Midwestern USA
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.

It depends on how you are using the VIA. If only one interrupt has been enabled a "blind" BIT instruction to test for a VIA interrupt is sufficient. If two or more interrupts are enabled you'd have to load the IFR into the accumulator and start testing bits to determine what interrupted (with one exception if only two interrupts are enabled). With the 65C02 or 65C816 you can use BIT # to nondestructively test individual bits after loading the IFR into .A, and act accordingly.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 16, 2018 8:03 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 16, 2018 8:09 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8510
Location: Southern California
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?


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 16, 2018 8:16 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 16, 2018 9:05 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8510
Location: Southern California
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".]

_________________
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?


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 16, 2018 1:19 pm 
Offline
User avatar

Joined: Mon Dec 08, 2008 6:32 pm
Posts: 143
Location: Brighton, England
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.


To DISABLE interrupts, you would need an OR gate or a NAND gate, as you want to hold the output high when interrupts are disabled. An AND can only force the output low. While this would disable NMI, since NMI is edge-triggered and not level-triggered, it would also cause an NMI as you disabled it!

_________________
Shift to the left,
Shift to the right,
Mask in, Mask Out,
BYTE! BYTE! BYTE!


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 16, 2018 8:26 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8510
Location: Southern California
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?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: