--- /dev/null
+/*\r
+\r
+Name:\r
+MDMA.C\r
+\r
+Description:\r
+Some general purpose IRQ routines\r
+\r
+Portability:\r
+\r
+MSDOS: BC(y) Watcom(y) DJGPP(y)\r
+Win95: n\r
+Os2: n\r
+Linux: n\r
+\r
+(y) - yes\r
+(n) - no (not possible or not useful)\r
+(?) - may be possible, but not tested\r
+\r
+*/\r
+#include <dos.h>\r
+#include <conio.h>\r
+#include "mirq.h"\r
+\r
+#define OCR1 0x20 /* 8259-1 Operation control register */\r
+#define IMR1 0x21 /* 8259-1 Mask register */\r
+\r
+#define OCR2 0xA0 /* 8259-2 Operation control register */\r
+#define IMR2 0xA1 /* 8259-2 Mask register */\r
+\r
+\r
+BOOL MIrq_IsEnabled(UBYTE irqno)\r
+/*\r
+ Returns true if the specified hardware irq is enabled.\r
+*/\r
+{\r
+ UBYTE imr=(irqno>7) ? IMR2 : IMR1; /* interrupt mask register */\r
+ UBYTE msk=1<<(irqno&7); /* interrupt mask */\r
+ return((inportb(imr) & msk) == 0);\r
+}\r
+\r
+\r
+BOOL MIrq_OnOff(UBYTE irqno,UBYTE onoff)\r
+/*\r
+ Use to enable or disable the specified irq.\r
+*/\r
+{\r
+ UBYTE imr=(irqno>7) ? IMR2 : IMR1; /* interrupt mask register */\r
+ UBYTE ocr=(irqno>7) ? OCR2 : OCR1; /* ocr */\r
+ UBYTE msk=1<<(irqno&7); /* interrupt mask */\r
+ UBYTE eoi=0x60|(irqno&7); /* specific end-of-interrupt */\r
+ BOOL oldstate;\r
+\r
+ /* save current setting of this irq */\r
+ oldstate=((inportb(imr) & msk) == 0);\r
+\r
+ if(onoff){\r
+ outportb(imr,inportb(imr) & ~msk);\r
+ outportb(ocr,eoi);\r
+ if(irqno>7) MIrq_OnOff(2,1);\r
+ }\r
+ else{\r
+ outportb(imr,inportb(imr) | msk);\r
+ }\r
+\r
+ return oldstate;\r
+}\r
+\r
+\r
+void MIrq_EOI(UBYTE irqno)\r
+/*\r
+ Clears the specified interrupt request at the interrupt controller.\r
+*/\r
+{\r
+ outportb(0x20,0x20);\r
+ if(irqno>7) outportb(0xa0,0x20);\r
+}\r
+\r
+\r
+PVI MIrq_SetHandler(UBYTE irqno,PVI handler)\r
+{\r
+#ifdef __DJGPP__\r
+ _go32_dpmi_seginfo seginfo;\r
+#endif\r
+ PVI oldvect;\r
+ int vecno=(irqno>7) ? irqno+0x68 : irqno+0x8;\r
+#ifdef __DJGPP__\r
+ _go32_dpmi_get_protected_mode_interrupt_vector(vecno, &seginfo);\r
+ oldvect = seginfo.pm_offset;\r
+ seginfo.pm_offset = handler;\r
+ seginfo.pm_selector = _go32_my_cs();\r
+ _go32_dpmi_allocate_iret_wrapper(&seginfo);\r
+ _go32_dpmi_set_protected_mode_interrupt_vector(vecno, &seginfo);\r
+#else\r
+ oldvect=_dos_getvect(vecno);\r
+ _dos_setvect(vecno,handler);\r
+#endif\r
+ return oldvect;\r
+}\r