3 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
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>
38 static const char *drive_main_pio_mode_strings[] = {
39 "16-bit PIO (standard)", /* 0 */
41 "32-bit PIO (VLB sync)",
45 void do_drive_pio_mode(struct ide_controller *ide,unsigned char which) {
46 struct menuboxbounds mbox;
55 menuboxbounds_set_def_list(&mbox,/*ofsx=*/4,/*ofsy=*/7,/*cols=*/1);
56 menuboxbounds_set_item_strings_arraylen(&mbox,drive_main_pio_mode_strings);
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);
63 /* select the drive we want */
64 idelib_controller_drive_select(ide,which,/*head*/0,IDELIB_DRIVE_SELECT_MODE_CHS);
66 /* in case the IDE controller is busy for that time */
67 c = do_ide_controller_user_wait_busy_controller(ide);
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);
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);
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);
84 /* for completeness, clear pending IRQ */
85 idelib_controller_ack_irq(ide);
87 /* match selection to PIO mode */
88 if (ide->pio_width == 16)
90 else if (ide->pio_width == 32)
92 else if (ide->pio_width == 33)
101 for (y=0;y < vga_height;y++) {
102 for (x=0;x < vga_width;x++) {
103 *vga++ = 0x1E00 + 177;
109 vga_write_color(0x1F);
110 vga_write(" IDE controller ");
111 sprintf(tmp,"@%X",ide->base_io);
113 if (ide->alt_io != 0) {
114 sprintf(tmp," alt %X",ide->alt_io);
118 sprintf(tmp," IRQ %d",ide->irq);
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]");
128 vga_write(" [16-bit]");
129 while (vga_pos_x < vga_width && vga_pos_x != 0) vga_writec(' ');
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(' ');
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(' ');
147 menuboxbound_redraw(&mbox,select);
151 if (c == 0) c = getch() << 8;
157 unsigned char doexit = 0;
168 if (confirm_pio32_warning(ide)) {
173 case 2: /* 32-bit VLB */
174 if (confirm_pio32_warning(ide)) {
179 case 3: /* Autodetect */
180 redraw = backredraw = 1;
181 ide_pio_autodetect(ide,which);
182 if (ide->pio_width == 16)
184 else if (ide->pio_width == 32)
186 else if (ide->pio_width == 33)
196 else if (c == 0x4800) {
198 select = mbox.item_max;
202 else if (c == 0x4B00) { /* left */
205 else if (c == 0x4D00) { /* right */
208 else if (c == 0x5000) {
209 if (++select > mbox.item_max)
217 #endif /* PIO_MODE_MENU */