[comp.sys.cbm] Simplify C64 interrupts!

Geoffrey.Welsh@isishq.FIDONET.ORG (Geoffrey Welsh) (12/12/88)

 > From: js9b+@andrew.cmu.edu (Jon C. Slenk)
 > Message-ID: <AXc3X7y00Xo8A3GlBH@andrew.cmu.edu>
 
 > The program I use now wedges itself into the IRQ that happens
 > every 60/50th of a
 > sec. It checks to see if the cause was the raster line
 > position. If it is, it
 > goes to my routine...
 
   This is not a direct solution to your problem, but it may help clear 

things up a bit.
 
   On the C64, there are only two chips that can generate an IRQ: the 

VIC-II and CIA #1. Normally (i.e. by default at power-up), the 1/60 
second interrupt is generated by timer A in CIA #1. Normally this would 
be more accurate a timebase than raster interrupts (which, by the way, 
were accurate enough in the PET), but K1 and some K2 ROMs loaded the 
wrong values into the timer anyway, mucking up whatever gain that might 
have provided.
 
   Anyway, my suggestion, if you're not already doing so, is to shut 

down CIA #1 IRQ generation completely and turn on only VIC-II interrupts. 
In this way, (1) you don't have to check which chip generated the interrupt 
- you KNOW it was the VIC and, if you don't have spite collision and/or 

light pen interrupts, you KNOW it was a raster interrupt; (2) you eliminate 
the possibility that CIA-generated interrupts will happen while you're 
running a raster interrupt. If you enable interrupts while servicing 
a raster interrupt, you'll end up nesting interrupts (potentially locking 
up the machine); if you don't, then you may be missing normal system 
interrupt services; (3) you now have timer A in CIA #1 to play with 
if you want and, if you're into masochism, you can even use it to generate 
IRQs.
 
   So: Turn off CIA #1 IRQs; enable only raster IRQs on the VIC chip; 

when you get an IRQ: JSR to the normal IRQ service routines (for keyboard 
scan, system clock, and whatever else) and THEN do whatever you wanted 
to do in the raster interrupt.
 
NOTE: You probably won't be able to scroll the screen in a single 1/60th 
of a second. If you use the above simplified IRQ service approach, 
that simply means that TI will miss a jiffy, the keyboard will miss 
a single scan, whatever. If both the CIA and the VIC are generating 
IRQs, it is possible that the IRQ service routine won't be called when 
the next IRQ comes up - if you want to discuss the causes for that 
feel free to netmail me, but I don't want to stretch this message too 
much longer. There are ways to beat that, but I think I've bored the 
comp.sys.cbm readership with enough technobabble already.
 
   Geoff ( watmath!isishq!izot )


--  
 Geoffrey Welsh - via FidoNet node 1:221/162
     UUCP: ...!watmath!isishq!Geoffrey.Welsh
 Internet: Geoffrey.Welsh@isishq.FIDONET.ORG