]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/8259/test.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / 8259 / test.c
1 /* test.c
2  *
3  * 8259 programmable interrupt controller test program.
4  * (C) 2009-2012 Jonathan Campbell.
5  * Hackipedia DOS library.
6  *
7  * This code is licensed under the LGPL.
8  * <insert LGPL legal text here>
9  *
10  * Compiles for intended target environments:
11  *   - MS-DOS [pure DOS mode, or Windows or OS/2 DOS Box] */
12
13 /* NTS: As of 2011/02/27 the 8254 routines no longer do cli/sti for us, we are expected
14  *      to do them ourself. This is for performance reasons as well as for sanity reasons
15  *      should we ever need to use the subroutines from within an interrupt handler */
16
17 #include <stdio.h>
18 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <fcntl.h>
22 #include <dos.h>
23
24 #include <hw/8259/8259.h>
25
26 void polltest() {
27         unsigned char ann[128],anni,cc;
28         int pat;
29
30         printf("Polling test. Interrupts that occur will be announced. Hit ESC to exit.\n");
31         while (1) {
32                 _cli();
33                 anni = 0;
34                 pat = 3200;
35                 do {
36                         cc = p8259_poll(0);
37                         if (cc & 0x80) {
38                                 ann[anni++] = cc & 7;
39                                 if (anni >= sizeof(anni)) break;
40                         }
41                         else {
42                                 break;
43                         }
44
45                         cc = p8259_poll(8);
46                         if (cc & 0x80) {
47                                 ann[anni++] = (cc & 7) + 8;
48                                 if (anni >= sizeof(anni)) break;
49                         }
50                         else {
51                                 break;
52                         }
53                 } while (--pat != 0);
54                 _sti();
55
56                 /* we ate interrupts, so we need to reissue them */
57                 for (cc=0;cc < anni;cc++) {
58                         union REGS regs;
59                         switch (ann[cc]) {
60                                 case 0:         just_int86(0x08,&regs,&regs); break;
61                                 case 1:         just_int86(0x09,&regs,&regs); break;
62                                 case 2:         just_int86(0x0A,&regs,&regs); break;
63                                 case 3:         just_int86(0x0B,&regs,&regs); break;
64                                 case 4:         just_int86(0x0C,&regs,&regs); break;
65                                 case 5:         just_int86(0x0D,&regs,&regs); break;
66                                 case 6:         just_int86(0x0E,&regs,&regs); break;
67                                 case 7:         just_int86(0x0F,&regs,&regs); break;
68
69                                 case 8:         just_int86(0x70,&regs,&regs); break;
70                                 case 9:         just_int86(0x71,&regs,&regs); break;
71                                 case 10:        just_int86(0x72,&regs,&regs); break;
72                                 case 11:        just_int86(0x73,&regs,&regs); break;
73                                 case 12:        just_int86(0x74,&regs,&regs); break;
74                                 case 13:        just_int86(0x75,&regs,&regs); break;
75                                 case 14:        just_int86(0x76,&regs,&regs); break;
76                                 case 15:        just_int86(0x77,&regs,&regs); break;
77                         };
78                 }
79
80                 /* print them out */
81                 if (anni != 0) {
82                         for (cc=0;cc < anni;cc++) printf("%u ",ann[cc]);
83                         printf("\n");
84                 }
85
86                 if (kbhit()) {
87                         if (getch() == 27)
88                                 break;
89                 }
90         }
91 }
92
93 void irrisr() {
94         unsigned short irr,isr;
95
96         printf("Reading IRR/ISR hit ESC to quit\n");
97         while (1) {
98                 if (kbhit()) {
99                         if (getch() == 27)
100                                 break;
101                 }
102
103                 _cli();
104                 do {
105                         irr  = p8259_read_IRR(0);
106                         irr |= p8259_read_IRR(8) << 8;
107                         isr  = p8259_read_ISR(0);
108                         isr |= p8259_read_ISR(8) << 8;
109                 } while ((irr|isr) == 0);
110                 _sti();
111
112                 if ((irr|isr) != 0) printf("IRR=%04x ISR=%04x\n",irr,isr);
113         }
114 }
115
116 int main() {
117         int c;
118
119         printf("8259 test program\n");
120         if (!probe_8259()) {
121                 printf("There does not appear to be a PIC on your system\n");
122                 return 1;
123         }
124         printf("Slave PIC: %s\n",p8259_slave_present ? "yes" : "no");
125
126         while (1) {
127                 printf("  1: 8259 poll test\n");
128                 printf("  2: 8259 IRR/ISR\n");
129                 printf("ESC: quit\n");
130
131                 c = getch();
132                 if (c == '1') {
133                         polltest();
134                 }
135                 else if (c == '2') {
136                         irrisr();
137                 }
138                 else if (c == 27) {
139                         break;
140                 }
141         }
142
143         return 0;
144 }
145