]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/ide/testmisc.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / ide / testmisc.c
1
2 #include <stdio.h>
3 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
7 #include <malloc.h>
8 #include <ctype.h>
9 #include <fcntl.h>
10 #include <dos.h>
11
12 #include <hw/vga/vga.h>
13 #include <hw/pci/pci.h>
14 #include <hw/dos/dos.h>
15 #include <hw/8254/8254.h>               /* 8254 timer */
16 #include <hw/8259/8259.h>               /* 8259 PIC interrupts */
17 #include <hw/vga/vgagui.h>
18 #include <hw/vga/vgatty.h>
19 #include <hw/ide/idelib.h>
20
21 #include "testutil.h"
22 #include "testmbox.h"
23 #include "testcmui.h"
24 #include "testbusy.h"
25 #include "testpiot.h"
26 #include "testrvfy.h"
27 #include "testrdwr.h"
28 #include "testidnt.h"
29 #include "testcdej.h"
30 #include "testpiom.h"
31 #include "testtadj.h"
32 #include "testcdrm.h"
33 #include "testmumo.h"
34 #include "testmisc.h"
35 #include "test.h"
36
37 #include "testnop.h"
38 #include "testpwr.h"
39
40 #ifdef MISC_TEST
41
42 /*-----------------------------------------------------------------*/
43
44 static const char *drive_misc_tests_menustrings[] = {
45         "Show IDE register taskfile",           /* 0 */
46         "Flush cache",
47         "Flush cache ext (LBA48)",
48         "Execute device diagnostic",
49         "CFA Disable Media Card Pass through",
50         "CFA Enable Media Card Pass through"    /* 5*/
51 };
52
53 void do_drive_misc_tests(struct ide_controller *ide,unsigned char which) {
54         struct menuboxbounds mbox;
55         struct vga_msg_box vgabox;
56         char backredraw=1;
57         VGA_ALPHA_PTR vga;
58         unsigned int x,y;
59         int select=-1;
60         char redraw=1;
61         int c;
62
63         /* UI element vars */
64         menuboxbounds_set_def_list(&mbox,/*ofsx=*/4,/*ofsy=*/7,/*cols=*/1);
65         menuboxbounds_set_item_strings_arraylen(&mbox,drive_misc_tests_menustrings);
66
67         while (1) {
68                 if (backredraw) {
69                         vga = vga_alpha_ram;
70                         backredraw = 0;
71                         redraw = 1;
72
73                         for (y=0;y < vga_height;y++) {
74                                 for (x=0;x < vga_width;x++) {
75                                         *vga++ = 0x1E00 + 177;
76                                 }
77                         }
78
79                         vga_moveto(0,0);
80
81                         vga_write_color(0x1F);
82                         vga_write("        IDE controller read/write tests ");
83                         sprintf(tmp,"@%X",ide->base_io);
84                         vga_write(tmp);
85                         if (ide->alt_io != 0) {
86                                 sprintf(tmp," alt %X",ide->alt_io);
87                                 vga_write(tmp);
88                         }
89                         if (ide->irq >= 0) {
90                                 sprintf(tmp," IRQ %d",ide->irq);
91                                 vga_write(tmp);
92                         }
93                         vga_write(which ? " Slave" : " Master");
94                         while (vga_pos_x < vga_width && vga_pos_x != 0) vga_writec(' ');
95
96                         vga_write_color(0xC);
97                         vga_write("WARNING: This code talks directly to your hard disk controller.");
98                         while (vga_pos_x < vga_width && vga_pos_x != 0) vga_writec(' ');
99                         vga_write_color(0xC);
100                         vga_write("         If you value the data on your hard drive do not run this program.");
101                         while (vga_pos_x < vga_width && vga_pos_x != 0) vga_writec(' ');
102                 }
103
104                 if (redraw) {
105                         redraw = 0;
106
107                         vga_moveto(mbox.ofsx,mbox.ofsy - 2);
108                         vga_write_color((select == -1) ? 0x70 : 0x0F);
109                         vga_write("Back to IDE controller main menu");
110                         while (vga_pos_x < (mbox.width+mbox.ofsx) && vga_pos_x != 0) vga_writec(' ');
111
112                         menuboxbound_redraw(&mbox,select);
113                 }
114
115                 c = getch();
116                 if (c == 0) c = getch() << 8;
117
118                 if (c == 27) {
119                         break;
120                 }
121                 else if (c == 13) {
122                         if (select == -1)
123                                 break;
124
125                         switch (select) {
126                                 case 0: /* show IDE register taskfile */
127                                         do_common_show_ide_taskfile(ide,which);
128                                         redraw = backredraw = 1;
129                                         break;
130                                 case 1: /* Flush cache */
131                                         do_ide_flush(ide,which,/*lba48*/0);
132                                         if (!idelib_controller_is_error(ide))
133                                                 vga_msg_box_create(&vgabox,"Success",0,0);
134                                         else
135                                                 common_ide_success_or_error_vga_msg_box(ide,&vgabox);
136
137                                         wait_for_enter_or_escape();
138                                         vga_msg_box_destroy(&vgabox);
139                                         redraw = 1;
140                                         break;
141                                 case 2: /* Flush cache ext */
142                                         do_ide_flush(ide,which,/*lba48*/1);
143                                         if (!idelib_controller_is_error(ide))
144                                                 vga_msg_box_create(&vgabox,"Success",0,0);
145                                         else
146                                                 common_ide_success_or_error_vga_msg_box(ide,&vgabox);
147
148                                         wait_for_enter_or_escape();
149                                         vga_msg_box_destroy(&vgabox);
150                                         redraw = 1;
151                                         break;
152                                 case 3: /* Execute device diagnostic */
153                                         do_ide_device_diagnostic(ide,which);
154                                         if (!idelib_controller_is_error(ide))
155                                                 vga_msg_box_create(&vgabox,"Success",0,0);
156                                         else
157                                                 common_ide_success_or_error_vga_msg_box(ide,&vgabox);
158
159                                         wait_for_enter_or_escape();
160                                         vga_msg_box_destroy(&vgabox);
161                                         redraw = 1;
162                                         break;
163                                 case 4: /* Disable media card pass through */
164                                         do_ide_media_card_pass_through(ide,which,0);
165                                         if (!idelib_controller_is_error(ide))
166                                                 vga_msg_box_create(&vgabox,"Success",0,0);
167                                         else
168                                                 common_ide_success_or_error_vga_msg_box(ide,&vgabox);
169
170                                         wait_for_enter_or_escape();
171                                         vga_msg_box_destroy(&vgabox);
172                                         redraw = 1;
173                                         break;
174                                 case 5: /* Enable media card pass through */
175                                         do_ide_media_card_pass_through(ide,which,1);
176                                         if (!idelib_controller_is_error(ide))
177                                                 vga_msg_box_create(&vgabox,"Success",0,0);
178                                         else
179                                                 common_ide_success_or_error_vga_msg_box(ide,&vgabox);
180
181                                         wait_for_enter_or_escape();
182                                         vga_msg_box_destroy(&vgabox);
183                                         redraw = 1;
184                                         break;
185                         };
186                 }
187                 else if (c == 0x4800) {
188                         if (--select < -1)
189                                 select = mbox.item_max;
190
191                         redraw = 1;
192                 }
193                 else if (c == 0x4B00) { /* left */
194                         redraw = 1;
195                 }
196                 else if (c == 0x4D00) { /* right */
197                         redraw = 1;
198                 }
199                 else if (c == 0x5000) {
200                         if (++select > mbox.item_max)
201                                 select = -1;
202
203                         redraw = 1;
204                 }
205         }
206 }
207
208 #endif /* MISC_TEST */
209