]> icculus.org git repositories - btb/d2x.git/blob - arch/dos/mm_snd/mirq.c
improved automake config. make dist, VPATH builds, ...
[btb/d2x.git] / arch / dos / mm_snd / mirq.c
1 /*
2
3 Name:
4 MDMA.C
5
6 Description:
7 Some general purpose IRQ routines
8
9 Portability:
10
11 MSDOS:  BC(y)   Watcom(y)       DJGPP(y)
12 Win95:  n
13 Os2:    n
14 Linux:  n
15
16 (y) - yes
17 (n) - no (not possible or not useful)
18 (?) - may be possible, but not tested
19
20 */
21 #include <dos.h>
22 #include <conio.h>
23 #include "mirq.h"
24
25 #define OCR1    0x20                    /* 8259-1 Operation control register */
26 #define IMR1    0x21                    /* 8259-1 Mask register */
27
28 #define OCR2    0xA0                    /* 8259-2 Operation control register */
29 #define IMR2    0xA1                    /* 8259-2 Mask register */
30
31
32 BOOL MIrq_IsEnabled(UBYTE irqno)
33 /*
34         Returns true if the specified hardware irq is enabled.
35 */
36 {
37         UBYTE imr=(irqno>7) ? IMR2 : IMR1;              /* interrupt mask register */
38         UBYTE msk=1<<(irqno&7);                                 /* interrupt mask */
39         return((inportb(imr) & msk) == 0);
40 }
41
42
43 BOOL MIrq_OnOff(UBYTE irqno,UBYTE onoff)
44 /*
45         Use to enable or disable the specified irq.
46 */
47 {
48         UBYTE imr=(irqno>7) ? IMR2 : IMR1;              /* interrupt mask register */
49         UBYTE ocr=(irqno>7) ? OCR2 : OCR1;              /* ocr */
50         UBYTE msk=1<<(irqno&7);                                 /* interrupt mask */
51         UBYTE eoi=0x60|(irqno&7);                               /* specific end-of-interrupt */
52         BOOL oldstate;
53
54         /* save current setting of this irq */
55         oldstate=((inportb(imr) & msk) == 0);
56
57         if(onoff){
58                 outportb(imr,inportb(imr) & ~msk);
59                 outportb(ocr,eoi);
60                 if(irqno>7) MIrq_OnOff(2,1);
61         }
62         else{
63                 outportb(imr,inportb(imr) | msk);
64         }
65
66         return oldstate;
67 }
68
69
70 void MIrq_EOI(UBYTE irqno)
71 /*
72         Clears the specified interrupt request at the interrupt controller.
73 */
74 {
75         UBYTE ocr=(irqno>7) ? OCR2 : OCR1;               /* ocr */
76         UBYTE eoi=0x60|(irqno&7);                        /* specific end-of-interrupt */
77
78         outportb(ocr,eoi);
79         if(irqno>7) outportb(OCR1,0x20);
80 }
81
82
83 PVI MIrq_SetHandler(UBYTE irqno,PVI handler)
84 {
85 #ifdef __DJGPP__
86         _go32_dpmi_seginfo seginfo;
87 #endif
88         PVI oldvect;
89         int vecno=(irqno>7) ? irqno+0x68 : irqno+0x8;
90 #ifdef __DJGPP__
91         _go32_dpmi_get_protected_mode_interrupt_vector(vecno, &seginfo);
92         oldvect = (PVI)seginfo.pm_offset;
93         seginfo.pm_offset = (int)handler;
94         seginfo.pm_selector = _go32_my_cs();
95         _go32_dpmi_allocate_iret_wrapper(&seginfo);
96         _go32_dpmi_set_protected_mode_interrupt_vector(vecno, &seginfo);
97 #else
98         oldvect=_dos_getvect(vecno);
99         _dos_setvect(vecno,handler);
100 #endif
101         return oldvect;
102 }