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>
27 /* returns: -1 if user said to cancel
29 * 1 if still busy, but user said to proceed */
30 int do_ide_controller_user_wait_busy_timeout_controller(struct ide_controller *ide,unsigned int timeout) {
36 /* use the alt status register if possible, else the base I/O.
37 * the alt status register is said not to clear pending interrupts */
38 idelib_controller_update_status(ide);
39 if (idelib_controller_is_busy(ide)) {
40 unsigned long show_countdown = (unsigned long)timeout * 10UL; /* ms -> 100us units */
43 idelib_controller_update_status(ide);
44 if (!idelib_controller_is_busy(ide)) break;
46 /* if the drive&controller is busy then show the dialog and wait for non-busy
47 * or until the user forces us to proceed */
48 if (show_countdown > 0UL) {
49 if (--show_countdown == 0UL) {
55 t8254_wait(t8254_us2ticks(100)); /* wait 100us (0.0001 seconds) */
62 /* returns: -1 if user said to cancel
64 * 1 if still busy, but user said to proceed */
65 int do_ide_controller_user_wait_busy_controller(struct ide_controller *ide) {
66 struct vga_msg_box vgabox;
72 /* use the alt status register if possible, else the base I/O.
73 * the alt status register is said not to clear pending interrupts */
74 idelib_controller_update_status(ide);
75 if (idelib_controller_is_busy(ide)) {
76 unsigned long show_countdown = 500000UL / 100UL; /* 0.5s / 100us units */
77 /* if the drive&controller is busy then show the dialog and wait for non-busy
78 * or until the user forces us to proceed */
81 idelib_controller_update_status(ide);
82 if (!idelib_controller_is_busy(ide)) break;
84 /* if the drive&controller is busy then show the dialog and wait for non-busy
85 * or until the user forces us to proceed */
86 if (show_countdown > 0UL) {
87 if (--show_countdown == 0UL)
88 vga_msg_box_create(&vgabox,"IDE controller busy, waiting...\n\nHit ESC to cancel, spacebar to proceed anyway",0,0);
91 if (show_countdown == 0UL && kbhit()) { /* if keyboard input and we're showing prompt */
93 if (c == 0) c = getch() << 8;
105 t8254_wait(t8254_us2ticks(100)); /* wait 100us (0.0001 seconds) */
108 if (show_countdown == 0UL)
109 vga_msg_box_destroy(&vgabox);
115 /* returns: -2 if an error happened
116 * -1 if user said to cancel
118 * 1 if still busy, but user said to proceed */
119 int do_ide_controller_user_wait_drive_drq(struct ide_controller *ide) {
120 struct vga_msg_box vgabox;
126 /* NTS: We ignore the Drive Ready Bit, because logically, that bit reflects
127 * when the drive is ready for another command. Obviously if we're waiting
128 * for DATA related to a command, then the command is not complete!
129 * I'm also assuming there are dumbshit IDE controller and hard drive
130 * implementations dumb enough to return such confusing state. */
131 /* use the alt status register if possible, else the base I/O.
132 * the alt status register is said not to clear pending interrupts */
133 idelib_controller_update_status(ide);
134 if (!idelib_controller_is_drq_ready(ide)) {
135 unsigned long show_countdown = 500000UL / 100UL; /* 0.5s / 100us units */
138 idelib_controller_update_status(ide);
139 if (idelib_controller_is_drq_ready(ide))
141 else if (idelib_controller_is_error(ide)) {
146 /* if the drive&controller is busy then show the dialog and wait for non-busy
147 * or until the user forces us to proceed */
148 if (show_countdown > 0UL) {
149 if (--show_countdown == 0UL)
150 vga_msg_box_create(&vgabox,"Waiting for Data Request from IDE device\n\nHit ESC to cancel, spacebar to proceed anyway",0,0);
153 if (show_countdown == 0UL && kbhit()) { /* if keyboard input and we're showing prompt */
155 if (c == 0) c = getch() << 8;
167 t8254_wait(t8254_us2ticks(100)); /* wait 100us (0.0001 seconds) */
170 if (show_countdown == 0UL)
171 vga_msg_box_destroy(&vgabox);
177 /* returns: -1 if user said to cancel
179 * 1 if still busy, but user said to proceed */
180 int do_ide_controller_user_wait_irq(struct ide_controller *ide,uint16_t count) {
181 struct vga_msg_box vgabox;
187 if (ide->irq_fired < count) {
188 unsigned long show_countdown = 500000UL / 100UL; /* 0.5s / 100us units */
191 if (ide->irq_fired >= count)
194 /* if the drive&controller is busy then show the dialog and wait for non-busy
195 * or until the user forces us to proceed */
196 if (show_countdown > 0UL) {
197 if (--show_countdown == 0UL)
198 vga_msg_box_create(&vgabox,"Waiting for IDE IRQ\n\nHit ESC to cancel, spacebar to proceed anyway",0,0);
201 if (show_countdown == 0UL && kbhit()) { /* if keyboard input and we're showing prompt */
203 if (c == 0) c = getch() << 8;
215 t8254_wait(t8254_us2ticks(100)); /* wait 100us (0.0001 seconds) */
218 if (show_countdown == 0UL)
219 vga_msg_box_destroy(&vgabox);
225 /* returns: -1 if user said to cancel
227 * 1 if still busy, but user said to proceed */
228 int do_ide_controller_user_wait_drive_ready(struct ide_controller *ide) {
229 struct vga_msg_box vgabox;
235 /* use the alt status register if possible, else the base I/O.
236 * the alt status register is said not to clear pending interrupts */
237 idelib_controller_update_status(ide);
238 if (!idelib_controller_is_drive_ready(ide)) {
239 unsigned long show_countdown = 500000UL / 100UL; /* 0.5s / 100us units */
241 /* if the drive&controller is busy then show the dialog and wait for non-busy
242 * or until the user forces us to proceed */
245 idelib_controller_update_status(ide);
246 if (idelib_controller_is_drive_ready(ide))
248 else if (idelib_controller_is_error(ide))
249 break; /* this is possible too?? or is VirtualBox fucking with us when the CD-ROM drive is on Primary slave? */
251 if (show_countdown > 0UL) {
252 if (--show_countdown == 0UL)
253 vga_msg_box_create(&vgabox,"IDE device not ready, waiting...\n\nHit ESC to cancel, spacebar to proceed anyway",0,0);
256 if (show_countdown == 0UL && kbhit()) { /* if keyboard input and we're showing prompt */
258 if (c == 0) c = getch() << 8;
270 t8254_wait(t8254_us2ticks(100)); /* wait 100us (0.0001 seconds) */
273 if (show_countdown == 0UL)
274 vga_msg_box_destroy(&vgabox);