/* IRQSTAT Reports IRQ status */

#include <stdio.h>
#include <conio.h>
#include <dos.h>

#define NUMPORTS 2

typedef struct {
               unsigned int number;
               char* name;
               } irqport;

unsigned int    status,
               bit,
               p8259;

static irqport  port[] = {{0x21,"0x21"},
                         {0xA1,"0xA1"}};

static char     free[] = "FREE",
                               used[] = "used";

static char*    ibm[] =
                       {"Timer",
                        "Keyboard",
                        "2nd 8259",
                        "COM2",
                        "COM1",
                        "LPT2",
                        "Floppy Disk",
                        "LPT1",
                        "Clock",
                        "Redirected IRQ2",
                        "(reserved)",
                        "(reserved)",
                        "(reserved)",
                        "Coprocessor",
                        "Hard Disk",
                        "(reserved)"};

static char*    oem[] = {"",
                        "",
                        "Autofax Imager",
                        "",
                        "",
                        "MS Bus Mouse",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        ""};

main()
{
       clrscr();
       printf("IRQSTAT -- Reports IRQ Status for IRQ 0-15\n\n");
       printf("\t8259  IRQ  Status   Assignments\n");
       printf("\t----  ---  ------   -----------\n");

       /* display status of 8259 IRQs */

       for (p8259 = 0; p8259 < NUMPORTS; p8259++) {

               /* get 8259 status port information */

               status = inp(port[p8259].number);

               for (bit = 0; bit <= 7; bit++) {
                       printf("\t%-4s  %3d  %6s   %-15s\n",
                       ((bit == 0) ? port[p8259].name : ""),
                       (bit + (p8259 * 8)),
                       ((status >> bit) & 1) ? free : used,
                       ibm[(bit + (p8259 * 8))]);
               }

               if ((p8259 + 1) < NUMPORTS) printf("\n");
       }

       exit(0);
}