Programming Examples
Appendix B
B-29
SWInterruptNumber = Interrupt 0x8;
if (SWInterruptNumber > 0xf) SWInterrupt= 0x60;
/* Save the old interrupt handler vector, and install the new one */
/* Need to disable interrupts when changing vectors */
disable ();
OldInterruptServiceRoutine = getvect(SWInterruptNumber);
setvect(SWInterruptNumber, InterruptServiceRoutine);
/* Enable the interrupt by setting the appropriate bit in the PICMask to 0 */
PICMask = inportb(PICP1);
delay(50);
/* Delay for PIC to settle */
outportb(PICP1, PICMask & ~(1 << (InterruptNumber % 8)));
delay(50);
/* Delay for PIC to settle */
enable ();
/* Re–enable interrupts */
}
/***************************************************************************
**
** void InterruptServiceRoutine (void)
**
** This routine is an example of how a host might want to service
** interrupts from a KTX. It assumes that the host has enabled the KTX
** scanner to interrupt on input change-of-state and at the end of each
** pass through the scan list. It assumes that more than one interrupt
** can be received at a time, i.e., that because the KTX interrupts are
** asynchronous to each other there may be more than one interrupt
** pending.
**
** INPUTS
** KTX dualport and hardware status register.
**
** OUTPUT
** KTX dualport and hardware status changed
**
***************************************************************************/
void interrupt InterruptServiceRoutine(void)
{
UBYTE temp;
/*============================================================================
**
** Verify it was the KTX that caused the interrupt by reading the
** status register.
**
==============================================================================*/
/**** Bit 0 of status reg == 1 when KTX ****/
/**** is the source of a host interrupt ****/
if (!(dp–>status_reg & 1))
return;
/**** Clear bit 0 of the status reg by ****/
/**** writing to acknowledge register. ****/
dp–>host_ack_of_ktx_int_reg = ACKNOWLEDGE_KTX;
/*============================================================================
**
** Service the COS interrupt first, since it can happen most often...
** 1) make sure it’s enabled
** 2) if so, see if we got a COS interrupt
** 3) if so, acknowledge it and check for COS overrun
**
==============================================================================*/
if (dp–>config_data.enable_cos_detect &&
(dp–>COS_link_address != COS_ACKNOWLEDGE)) {