[comp.sys.amiga.tech] !CIA Allocation Bug!

kodiak@amiga.UUCP (Robert R. Burns) (01/11/89)

In articles, folks (most recently Karl Lehenbauer) write:
>#define CIAINTBIT CIAICRB_TA
>...
>if ((CIAResource = (struct Library *)OpenResource(CIAANAME)) == NULL)
>...
>if ((OldCIAInterrupt = AddICRVector(CIAResource,CIAINTBIT,&CIATimerInterrupt))
>...

Let me say this again (though I didn't say it the first time).  The hardware
manual incorrectly identifies CIA usage.  Here is the correct allocation:

    CIAA (int 2)
	timerA      keyboard handshake
	timerB      uSec timer.device
	TOD         60Hz timer.device
    CIAB (int 6)
	timerA      Commodore serial communication, usually not used
	timerB      not used
	TOD         graphics.library beam counter

This example code incorrectly allocates CIAA timerA.  The keyboard is
arguably "broken" in the sense that it does not preclude that from happening
-- but in any event, the keyboard expects timerA for its exclusive use.
The keyboard.device code on the amiga side handshakes key acquisition to the
keyboard processor using a mechanism such that if the timer is running, the
handshake may not be properly generated.  Furthermore, under 1.4 the
keyboard.device will be using the timer itself, and the AddICRVector would
begin to (correctly) fail.

so, use...

if ((CIAResource = (struct Library *)OpenResource(CIABNAME)) == NULL)
						     ^

and do it carefully, because your interrupt code is now at a much higher
priority (6 vs. 2).

-- 
Bob Burns, amiga!kodiak                   _
| /_  _|. _ |      Commodore __          |_) _ |_  _ )'
|<(_)(_)|(_\|<      /\ |  ||| _` /\      |_)(_\| )(_\ |
| \ Software    ___/..\|\/|||__|/..\___           Faith