]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/ide/testpiom.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / ide / testpiom.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 "test.h"
32
33 #include "testnop.h"
34 #include "testpwr.h"
35
36 #ifdef PIO_MODE_MENU
37
38 static const char *drive_main_pio_mode_strings[] = {
39         "16-bit PIO (standard)",                /* 0 */
40         "32-bit PIO",
41         "32-bit PIO (VLB sync)",
42         "Autodetect"
43 };
44
45 void do_drive_pio_mode(struct ide_controller *ide,unsigned char which) {
46         struct menuboxbounds mbox;
47         char backredraw=1;
48         VGA_ALPHA_PTR vga;
49         unsigned int x,y;
50         int select=-1;
51         char redraw=1;
52         int c;
53
54         /* UI element vars */
55         menuboxbounds_set_def_list(&mbox,/*ofsx=*/4,/*ofsy=*/7,/*cols=*/1);
56         menuboxbounds_set_item_strings_arraylen(&mbox,drive_main_pio_mode_strings);
57
58         /* most of the commands assume a ready controller. if it's stuck,
59          * we'd rather the user have a visual indication that it's stuck that way */
60         c = do_ide_controller_user_wait_busy_controller(ide);
61         if (c != 0) return;
62
63         /* select the drive we want */
64         idelib_controller_drive_select(ide,which,/*head*/0,IDELIB_DRIVE_SELECT_MODE_CHS);
65
66         /* in case the IDE controller is busy for that time */
67         c = do_ide_controller_user_wait_busy_controller(ide);
68         if (c != 0) return;
69
70         /* read back: did the drive select take effect? if not, it might not be there. another common sign is the head/drive select reads back 0xFF */
71         c = do_ide_controller_drive_check_select(ide,which);
72         if (c < 0) return;
73
74         /* it might be a CD-ROM drive, which in some cases might not raise the Drive Ready bit */
75         do_ide_controller_atapi_device_check_post_host_reset(ide);
76
77         /* wait for the drive to indicate readiness */
78         /* NTS: If the drive never becomes ready even despite our reset hacks, there's a strong
79          *      possibility that the device doesn't exist. This can happen for example if there
80          *      is a master attached but no slave. */
81         c = do_ide_controller_user_wait_drive_ready(ide);
82         if (c < 0) return;
83
84         /* for completeness, clear pending IRQ */
85         idelib_controller_ack_irq(ide);
86
87         /* match selection to PIO mode */
88         if (ide->pio_width == 16)
89                 select = 0;
90         else if (ide->pio_width == 32)
91                 select = 1;
92         else if (ide->pio_width == 33)
93                 select = 2;
94
95         while (1) {
96                 if (backredraw) {
97                         vga = vga_alpha_ram;
98                         backredraw = 0;
99                         redraw = 1;
100
101                         for (y=0;y < vga_height;y++) {
102                                 for (x=0;x < vga_width;x++) {
103                                         *vga++ = 0x1E00 + 177;
104                                 }
105                         }
106
107                         vga_moveto(0,0);
108
109                         vga_write_color(0x1F);
110                         vga_write("        IDE controller ");
111                         sprintf(tmp,"@%X",ide->base_io);
112                         vga_write(tmp);
113                         if (ide->alt_io != 0) {
114                                 sprintf(tmp," alt %X",ide->alt_io);
115                                 vga_write(tmp);
116                         }
117                         if (ide->irq >= 0) {
118                                 sprintf(tmp," IRQ %d",ide->irq);
119                                 vga_write(tmp);
120                         }
121                         vga_write(which ? " Slave" : " Master");
122                         vga_write(" << PIO mode");
123                         if (ide->pio_width == 33)
124                                 vga_write(" [32-bit VLB]");
125                         else if (ide->pio_width == 32)
126                                 vga_write(" [32-bit]");
127                         else
128                                 vga_write(" [16-bit]");
129                         while (vga_pos_x < vga_width && vga_pos_x != 0) vga_writec(' ');
130
131                         vga_write_color(0xC);
132                         vga_write("WARNING: This code talks directly to your hard disk controller.");
133                         while (vga_pos_x < vga_width && vga_pos_x != 0) vga_writec(' ');
134                         vga_write_color(0xC);
135                         vga_write("         If you value the data on your hard drive do not run this program.");
136                         while (vga_pos_x < vga_width && vga_pos_x != 0) vga_writec(' ');
137                 }
138
139                 if (redraw) {
140                         redraw = 0;
141
142                         vga_moveto(mbox.ofsx,mbox.ofsy - 2);
143                         vga_write_color((select == -1) ? 0x70 : 0x0F);
144                         vga_write("Back to IDE drive main menu");
145                         while (vga_pos_x < (mbox.width+mbox.ofsx) && vga_pos_x != 0) vga_writec(' ');
146
147                         menuboxbound_redraw(&mbox,select);
148                 }
149
150                 c = getch();
151                 if (c == 0) c = getch() << 8;
152
153                 if (c == 27) {
154                         break;
155                 }
156                 else if (c == 13) {
157                         unsigned char doexit = 0;
158
159                         if (select == -1)
160                                 break;
161
162                         switch (select) {
163                                 case 0: /* 16-bit */
164                                         doexit = 1;
165                                         ide->pio_width = 16;
166                                         break;
167                                 case 1: /* 32-bit */
168                                         if (confirm_pio32_warning(ide)) {
169                                                 ide->pio_width = 32;
170                                                 doexit = 1;
171                                         }
172                                         break;
173                                 case 2: /* 32-bit VLB */
174                                         if (confirm_pio32_warning(ide)) {
175                                                 ide->pio_width = 33;
176                                                 doexit = 1;
177                                         }
178                                         break;
179                                 case 3: /* Autodetect */
180                                         redraw = backredraw = 1;
181                                         ide_pio_autodetect(ide,which);
182                                         if (ide->pio_width == 16)
183                                                 select = 0;
184                                         else if (ide->pio_width == 32)
185                                                 select = 1;
186                                         else if (ide->pio_width == 33)
187                                                 select = 2;
188                                         break;
189                         };
190
191                         if (doexit)
192                                 break;
193                         else
194                                 redraw = 1;
195                 }
196                 else if (c == 0x4800) {
197                         if (--select < -1)
198                                 select = mbox.item_max;
199
200                         redraw = 1;
201                 }
202                 else if (c == 0x4B00) { /* left */
203                         redraw = 1;
204                 }
205                 else if (c == 0x4D00) { /* right */
206                         redraw = 1;
207                 }
208                 else if (c == 0x5000) {
209                         if (++select > mbox.item_max)
210                                 select = -1;
211
212                         redraw = 1;
213                 }
214         }
215 }
216
217 #endif /* PIO_MODE_MENU */
218