blob: 9131d98b8bfe7fe3a178183051377bce554ef88c [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// 16bit code to access floppy drives.
2//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4// Copyright (C) 2002 MandrakeSoft S.A.
5//
6// This file may be distributed under the terms of the GNU GPLv3 license.
7
8#include "types.h" // u8
9#include "disk.h" // DISK_RET_SUCCESS
10#include "config.h" // CONFIG_FLOPPY_SUPPORT
11#include "biosvar.h" // struct bregs
12#include "util.h" // irq_disable
13#include "cmos.h" // inb_cmos
14
15#define BX_FLOPPY_ON_CNT 37 /* 2 seconds */
16
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050017// New diskette parameter table adding 3 parameters from IBM
18// Since no provisions are made for multiple drive types, most
19// values in this table are ignored. I set parameters for 1.44M
20// floppy here
Kevin O'Connor44c631d2008-03-02 11:24:36 -050021struct floppy_ext_dbt_s diskette_param_table2 VISIBLE = {
22 .dbt = {
23 .specify1 = 0xAF,
24 .specify2 = 0x02, // head load time 0000001, DMA used
25 .shutoff_ticks = 0x25,
26 .bps_code = 0x02,
27 .sectors = 18,
28 .interblock_len = 0x1B,
29 .data_len = 0xFF,
30 .gap_len = 0x6C,
31 .fill_byte = 0xF6,
32 .settle_time = 0x0F,
33 .startup_time = 0x08,
34 },
35 .max_track = 79, // maximum track
36 .data_rate = 0, // data transfer rate
37 .drive_type = 4, // drive type in cmos
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050038};
39
40// Oddities:
41// Return codes vary greatly - AL not cleared consistenlty, BDA return
42// status not set consistently, sometimes panics.
43// Extra outb(0x000a, 0x02) in read?
44// Does not disable interrupts on failure paths.
45// numfloppies used before set in int_1308
46// int_1305 verifies track but doesn't use it?
47
48static inline void
49set_diskette_current_cyl(u8 drive, u8 cyl)
50{
51 if (drive)
52 SET_BDA(floppy_track1, cyl);
53 else
54 SET_BDA(floppy_track0, cyl);
55}
56
57static u16
58get_drive_type(u8 drive)
59{
60 // check CMOS to see if drive exists
61 u8 drive_type = inb_cmos(CMOS_FLOPPY_DRIVE_TYPE);
62 if (drive == 0)
63 drive_type >>= 4;
64 else
65 drive_type &= 0x0f;
66 return drive_type;
67}
68
69static u16
70floppy_media_known(u8 drive)
71{
72 if (!(GET_BDA(floppy_recalibration_status) & (1<<drive)))
73 return 0;
74 u8 v = GET_BDA(floppy_media_state[drive]);
75 if (!(v & FMS_MEDIA_DRIVE_ESTABLISHED))
76 return 0;
77 return 1;
78}
79
80static void
81floppy_reset_controller()
82{
83 // Reset controller
84 u8 val8 = inb(PORT_FD_DOR);
85 outb(val8 & ~0x04, PORT_FD_DOR);
86 outb(val8 | 0x04, PORT_FD_DOR);
87
88 // Wait for controller to come out of reset
89 while ((inb(PORT_FD_STATUS) & 0xc0) != 0x80)
90 ;
91}
92
93static void
94floppy_prepare_controller(u8 drive)
95{
96 CLEARBITS_BDA(floppy_recalibration_status, FRS_TIMEOUT);
97
98 // turn on motor of selected drive, DMA & int enabled, normal operation
99 u8 prev_reset = inb(PORT_FD_DOR) & 0x04;
100 u8 dor = 0x10;
101 if (drive)
102 dor = 0x20;
103 dor |= 0x0c;
104 dor |= drive;
105 outb(dor, PORT_FD_DOR);
106
107 // reset the disk motor timeout value of INT 08
108 SET_BDA(floppy_motor_counter, BX_FLOPPY_ON_CNT);
109
110 // wait for drive readiness
111 while ((inb(PORT_FD_STATUS) & 0xc0) != 0x80)
112 ;
113
114 if (prev_reset == 0) {
115 irq_enable();
116 u8 v;
117 do {
118 v = GET_BDA(floppy_recalibration_status);
119 } while ((v & FRS_TIMEOUT) == 0);
120 irq_disable();
121
122 v &= ~FRS_TIMEOUT;
123 SET_BDA(floppy_recalibration_status, v);
124 }
125}
126
127static u8
128floppy_pio(u8 *cmd, u8 cmdlen)
129{
130 floppy_prepare_controller(cmd[1] & 1);
131
132 // send command to controller
133 u8 i;
134 for (i=0; i<cmdlen; i++)
135 outb(cmd[i], PORT_FD_DATA);
136
137 irq_enable();
138 u8 v;
139 do {
140 if (!GET_BDA(floppy_motor_counter)) {
141 irq_disable();
142 floppy_reset_controller();
143 return DISK_RET_ETIMEOUT;
144 }
145 v = GET_BDA(floppy_recalibration_status);
146 } while (!(v & FRS_TIMEOUT));
147 irq_disable();
148
149 v &= ~FRS_TIMEOUT;
150 SET_BDA(floppy_recalibration_status, v);
151
152 if ((inb(PORT_FD_STATUS) & 0xc0) != 0xc0)
153 BX_PANIC("int13_diskette: ctrl not ready\n");
154
155 return 0;
156}
157
158static u8
159floppy_cmd(struct bregs *regs, u16 count, u8 *cmd, u8 cmdlen)
160{
161 // es:bx = pointer to where to place information from diskette
162 // port 04: DMA-1 base and current address, channel 2
163 // port 05: DMA-1 base and current count, channel 2
164 u16 page = regs->es >> 12; // upper 4 bits
165 u16 base_es = regs->es << 4; // lower 16bits contributed by ES
166 u16 base_address = base_es + regs->bx; // lower 16 bits of address
167 // contributed by ES:BX
168 if (base_address < base_es)
169 // in case of carry, adjust page by 1
170 page++;
171
172 // check for 64K boundary overrun
173 u16 last_addr = base_address + count;
174 if (last_addr < base_address)
175 return DISK_RET_EBOUNDARY;
176
177 u8 mode_register = 0x4a; // single mode, increment, autoinit disable,
178 if (cmd[0] == 0xe6)
179 // read
180 mode_register = 0x46;
181
Kevin O'Connor44c631d2008-03-02 11:24:36 -0500182 //DEBUGF("floppy dma c2\n");
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500183 outb(0x06, PORT_DMA1_MASK_REG);
184 outb(0x00, PORT_DMA1_CLEAR_FF_REG); // clear flip-flop
185 outb(base_address, PORT_DMA_ADDR_2);
186 outb(base_address>>8, PORT_DMA_ADDR_2);
187 outb(0x00, PORT_DMA1_CLEAR_FF_REG); // clear flip-flop
188 outb(count, PORT_DMA_CNT_2);
189 outb(count>>8, PORT_DMA_CNT_2);
190
191 // port 0b: DMA-1 Mode Register
192 // transfer type=write, channel 2
193 outb(mode_register, PORT_DMA1_MODE_REG);
194
195 // port 81: DMA-1 Page Register, channel 2
196 outb(page, PORT_DMA_PAGE_2);
197
198 outb(0x02, PORT_DMA1_MASK_REG); // unmask channel 2
199
200 u8 ret = floppy_pio(cmd, cmdlen);
201 if (ret)
202 return ret;
203
204 // read 7 return status bytes from controller
205 u8 i;
206 for (i=0; i<7; i++) {
207 u8 v = inb(PORT_FD_DATA);
208 cmd[i] = v;
209 SET_BDA(floppy_return_status[i], v);
210 }
211
212 return 0;
213}
214
215static void
216floppy_drive_recal(u8 drive)
217{
218 // send Recalibrate command (2 bytes) to controller
219 u8 data[12];
220 data[0] = 0x07; // 07: Recalibrate
221 data[1] = drive; // 0=drive0, 1=drive1
222 floppy_pio(data, 2);
223
224 SETBITS_BDA(floppy_recalibration_status, 1<<drive);
225 set_diskette_current_cyl(drive, 0);
226}
227
228static u16
229floppy_media_sense(u8 drive)
230{
231 u16 rv;
232 u8 config_data, media_state;
233
234 floppy_drive_recal(drive);
235
236 // for now cheat and get drive type from CMOS,
237 // assume media is same as drive type
238
239 // ** config_data **
240 // Bitfields for diskette media control:
241 // Bit(s) Description (Table M0028)
242 // 7-6 last data rate set by controller
243 // 00=500kbps, 01=300kbps, 10=250kbps, 11=1Mbps
244 // 5-4 last diskette drive step rate selected
245 // 00=0Ch, 01=0Dh, 10=0Eh, 11=0Ah
246 // 3-2 {data rate at start of operation}
247 // 1-0 reserved
248
249 // ** media_state **
250 // Bitfields for diskette drive media state:
251 // Bit(s) Description (Table M0030)
252 // 7-6 data rate
253 // 00=500kbps, 01=300kbps, 10=250kbps, 11=1Mbps
254 // 5 double stepping required (e.g. 360kB in 1.2MB)
255 // 4 media type established
256 // 3 drive capable of supporting 4MB media
257 // 2-0 on exit from BIOS, contains
258 // 000 trying 360kB in 360kB
259 // 001 trying 360kB in 1.2MB
260 // 010 trying 1.2MB in 1.2MB
261 // 011 360kB in 360kB established
262 // 100 360kB in 1.2MB established
263 // 101 1.2MB in 1.2MB established
264 // 110 reserved
265 // 111 all other formats/drives
266
267 switch (get_drive_type(drive)) {
268 case 1:
269 // 360K 5.25" drive
270 config_data = 0x00; // 0000 0000
271 media_state = 0x25; // 0010 0101
272 rv = 1;
273 break;
274 case 2:
275 // 1.2 MB 5.25" drive
276 config_data = 0x00; // 0000 0000
277 media_state = 0x25; // 0010 0101 // need double stepping??? (bit 5)
278 rv = 1;
279 break;
280 case 3:
281 // 720K 3.5" drive
282 config_data = 0x00; // 0000 0000 ???
283 media_state = 0x17; // 0001 0111
284 rv = 1;
285 break;
286 case 4:
287 // 1.44 MB 3.5" drive
288 config_data = 0x00; // 0000 0000
289 media_state = 0x17; // 0001 0111
290 rv = 1;
291 break;
292 case 5:
293 // 2.88 MB 3.5" drive
294 config_data = 0xCC; // 1100 1100
295 media_state = 0xD7; // 1101 0111
296 rv = 1;
297 break;
298 //
299 // Extended floppy size uses special cmos setting
300 case 6:
301 // 160k 5.25" drive
302 config_data = 0x00; // 0000 0000
303 media_state = 0x27; // 0010 0111
304 rv = 1;
305 break;
306 case 7:
307 // 180k 5.25" drive
308 config_data = 0x00; // 0000 0000
309 media_state = 0x27; // 0010 0111
310 rv = 1;
311 break;
312 case 8:
313 // 320k 5.25" drive
314 config_data = 0x00; // 0000 0000
315 media_state = 0x27; // 0010 0111
316 rv = 1;
317 break;
318 default:
319 // not recognized
320 config_data = 0x00; // 0000 0000
321 media_state = 0x00; // 0000 0000
322 rv = 0;
323 }
324
325 SET_BDA(floppy_last_data_rate, config_data);
326 SET_BDA(floppy_media_state[drive], media_state);
327 return rv;
328}
329
330static inline void
331floppy_ret(struct bregs *regs, u8 code)
332{
333 regs->ah = code;
334 SET_BDA(floppy_last_status, code);
335 set_cf(regs, code);
336}
337
338static inline void
339floppy_fail(struct bregs *regs, u8 code)
340{
341 regs->al = 0; // no sectors read
342 floppy_ret(regs, code);
343}
344
345static u16
346check_drive(struct bregs *regs, u8 drive)
347{
348 // see if drive exists
349 if (drive > 1 || !get_drive_type(drive)) {
350 floppy_fail(regs, DISK_RET_ETIMEOUT);
351 return 1;
352 }
353
354 // see if media in drive, and type is known
355 if (floppy_media_known(drive) == 0 && floppy_media_sense(drive) == 0) {
356 floppy_fail(regs, DISK_RET_EMEDIA);
357 return 1;
358 }
359 return 0;
360}
361
362// diskette controller reset
363static void
364floppy_1300(struct bregs *regs, u8 drive)
365{
366 if (drive > 1) {
367 floppy_ret(regs, DISK_RET_EPARAM);
368 return;
369 }
370 if (!get_drive_type(drive)) {
371 floppy_ret(regs, DISK_RET_ETIMEOUT);
372 return;
373 }
374 set_diskette_current_cyl(drive, 0); // current cylinder
375 floppy_ret(regs, DISK_RET_SUCCESS);
376}
377
378// Read Diskette Status
379static void
380floppy_1301(struct bregs *regs, u8 drive)
381{
382 u8 v = GET_BDA(floppy_last_status);
383 regs->ah = v;
384 set_cf(regs, v);
385}
386
387// Read Diskette Sectors
388static void
389floppy_1302(struct bregs *regs, u8 drive)
390{
391 if (check_drive(regs, drive))
392 return;
393
394 u8 num_sectors = regs->al;
395 u8 track = regs->ch;
396 u8 sector = regs->cl;
397 u8 head = regs->dh;
398
399 if (head > 1 || sector == 0 || num_sectors == 0
400 || track > 79 || num_sectors > 72) {
401 BX_INFO("int13_diskette: read/write/verify: parameter out of range\n");
402 floppy_fail(regs, DISK_RET_EPARAM);
403 return;
404 }
405
406 // send read-normal-data command (9 bytes) to controller
407 u8 data[12];
408 data[0] = 0xe6; // e6: read normal data
409 data[1] = (head << 2) | drive; // HD DR1 DR2
410 data[2] = track;
411 data[3] = head;
412 data[4] = sector;
413 data[5] = 2; // 512 byte sector size
414 data[6] = sector + num_sectors - 1; // last sector to read on track
415 data[7] = 0; // Gap length
416 data[8] = 0xff; // Gap length
417
418 u16 ret = floppy_cmd(regs, (num_sectors * 512) - 1, data, 9);
419 if (ret) {
420 floppy_fail(regs, ret);
421 return;
422 }
423
424 if (data[0] & 0xc0) {
425 floppy_fail(regs, DISK_RET_ECONTROLLER);
426 return;
427 }
428
429 // ??? should track be new val from return_status[3] ?
430 set_diskette_current_cyl(drive, track);
431 // AL = number of sectors read (same value as passed)
432 floppy_ret(regs, DISK_RET_SUCCESS);
433}
434
435// Write Diskette Sectors
436static void
437floppy_1303(struct bregs *regs, u8 drive)
438{
439 if (check_drive(regs, drive))
440 return;
441
442 u8 num_sectors = regs->al;
443 u8 track = regs->ch;
444 u8 sector = regs->cl;
445 u8 head = regs->dh;
446
447 if (head > 1 || sector == 0 || num_sectors == 0
448 || track > 79 || num_sectors > 72) {
449 BX_INFO("int13_diskette: read/write/verify: parameter out of range\n");
450 floppy_fail(regs, DISK_RET_EPARAM);
451 return;
452 }
453
454 // send write-normal-data command (9 bytes) to controller
455 u8 data[12];
456 data[0] = 0xc5; // c5: write normal data
457 data[1] = (head << 2) | drive; // HD DR1 DR2
458 data[2] = track;
459 data[3] = head;
460 data[4] = sector;
461 data[5] = 2; // 512 byte sector size
462 data[6] = sector + num_sectors - 1; // last sector to write on track
463 data[7] = 0; // Gap length
464 data[8] = 0xff; // Gap length
465
466 u8 ret = floppy_cmd(regs, (num_sectors * 512) - 1, data, 9);
467 if (ret) {
468 floppy_fail(regs, ret);
469 return;
470 }
471
472 if (data[0] & 0xc0) {
473 if (data[1] & 0x02) {
474 regs->ax = 0x0300;
475 set_cf(regs, 1);
476 return;
477 }
478 BX_PANIC("int13_diskette_function: read error\n");
479 }
480
481 // ??? should track be new val from return_status[3] ?
482 set_diskette_current_cyl(drive, track);
483 // AL = number of sectors read (same value as passed)
484 floppy_ret(regs, DISK_RET_SUCCESS);
485}
486
487// Verify Diskette Sectors
488static void
489floppy_1304(struct bregs *regs, u8 drive)
490{
491 if (check_drive(regs, drive))
492 return;
493
494 u8 num_sectors = regs->al;
495 u8 track = regs->ch;
496 u8 sector = regs->cl;
497 u8 head = regs->dh;
498
499 if (head > 1 || sector == 0 || num_sectors == 0
500 || track > 79 || num_sectors > 72) {
501 BX_INFO("int13_diskette: read/write/verify: parameter out of range\n");
502 floppy_fail(regs, DISK_RET_EPARAM);
503 return;
504 }
505
506 // ??? should track be new val from return_status[3] ?
507 set_diskette_current_cyl(drive, track);
508 // AL = number of sectors verified (same value as passed)
509 floppy_ret(regs, DISK_RET_SUCCESS);
510}
511
512// format diskette track
513static void
514floppy_1305(struct bregs *regs, u8 drive)
515{
516 DEBUGF("floppy f05\n");
517
518 if (check_drive(regs, drive))
519 return;
520
521 u8 num_sectors = regs->al;
522 u8 head = regs->dh;
523
524 if (head > 1 || num_sectors == 0 || num_sectors > 18) {
525 BX_INFO("int13_diskette: read/write/verify: parameter out of range\n");
526 floppy_fail(regs, DISK_RET_EPARAM);
527 return;
528 }
529
530 // send format-track command (6 bytes) to controller
531 u8 data[12];
532 data[0] = 0x4d; // 4d: format track
533 data[1] = (head << 2) | drive; // HD DR1 DR2
534 data[2] = 2; // 512 byte sector size
535 data[3] = num_sectors; // number of sectors per track
536 data[4] = 0; // Gap length
537 data[5] = 0xf6; // Fill byte
538
539 u8 ret = floppy_cmd(regs, (num_sectors * 4) - 1, data, 6);
540 if (ret) {
541 floppy_fail(regs, ret);
542 return;
543 }
544
545 if (data[0] & 0xc0) {
546 if (data[1] & 0x02) {
547 regs->ax = 0x0300;
548 set_cf(regs, 1);
549 return;
550 }
551 BX_PANIC("int13_diskette_function: read error\n");
552 }
553
554 set_diskette_current_cyl(drive, 0);
555 floppy_ret(regs, 0);
556}
557
558// read diskette drive parameters
559static void
560floppy_1308(struct bregs *regs, u8 drive)
561{
562 DEBUGF("floppy f08\n");
563
564 u8 drive_type = inb_cmos(CMOS_FLOPPY_DRIVE_TYPE);
565 u8 num_floppies = 0;
566 if (drive_type & 0xf0)
567 num_floppies++;
568 if (drive_type & 0x0f)
569 num_floppies++;
570
571 if (drive > 1) {
572 regs->ax = 0;
573 regs->bx = 0;
574 regs->cx = 0;
575 regs->dx = 0;
576 regs->es = 0;
577 regs->di = 0;
578 regs->dl = num_floppies;
579 set_cf(regs, 0);
580 return;
581 }
582
583 if (drive == 0)
584 drive_type >>= 4;
585 else
586 drive_type &= 0x0f;
587
588 regs->bh = 0;
589 regs->bl = drive_type;
590 regs->ah = 0;
591 regs->al = 0;
592 regs->dl = num_floppies;
593
594 switch (drive_type) {
595 case 0: // none
596 regs->cx = 0;
597 regs->dh = 0; // max head #
598 break;
599
600 case 1: // 360KB, 5.25"
601 regs->cx = 0x2709; // 40 tracks, 9 sectors
602 regs->dh = 1; // max head #
603 break;
604
605 case 2: // 1.2MB, 5.25"
606 regs->cx = 0x4f0f; // 80 tracks, 15 sectors
607 regs->dh = 1; // max head #
608 break;
609
610 case 3: // 720KB, 3.5"
611 regs->cx = 0x4f09; // 80 tracks, 9 sectors
612 regs->dh = 1; // max head #
613 break;
614
615 case 4: // 1.44MB, 3.5"
616 regs->cx = 0x4f12; // 80 tracks, 18 sectors
617 regs->dh = 1; // max head #
618 break;
619
620 case 5: // 2.88MB, 3.5"
621 regs->cx = 0x4f24; // 80 tracks, 36 sectors
622 regs->dh = 1; // max head #
623 break;
624
625 case 6: // 160k, 5.25"
626 regs->cx = 0x2708; // 40 tracks, 8 sectors
627 regs->dh = 0; // max head #
628 break;
629
630 case 7: // 180k, 5.25"
631 regs->cx = 0x2709; // 40 tracks, 9 sectors
632 regs->dh = 0; // max head #
633 break;
634
635 case 8: // 320k, 5.25"
636 regs->cx = 0x2708; // 40 tracks, 8 sectors
637 regs->dh = 1; // max head #
638 break;
639
640 default: // ?
641 BX_PANIC("floppy: int13: bad floppy type\n");
642 }
643
644 /* set es & di to point to 11 byte diskette param table in ROM */
645 regs->es = SEG_BIOS;
Kevin O'Connor44c631d2008-03-02 11:24:36 -0500646 regs->di = (u16)&diskette_param_table2;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500647 /* disk status not changed upon success */
648}
649
650// read diskette drive type
651static void
652floppy_1315(struct bregs *regs, u8 drive)
653{
654 DEBUGF("floppy f15\n");
655 if (drive > 1) {
656 regs->ah = 0; // only 2 drives supported
657 // set_diskette_ret_status here ???
658 set_cf(regs, 1);
659 return;
660 }
661 u8 drive_type = get_drive_type(drive);
662
663 regs->ah = (drive_type != 0);
664 set_cf(regs, 0);
665}
666
667// get diskette change line status
668static void
669floppy_1316(struct bregs *regs, u8 drive)
670{
671 DEBUGF("floppy f16\n");
672 if (drive > 1) {
673 floppy_ret(regs, DISK_RET_EPARAM);
674 return;
675 }
676 floppy_ret(regs, DISK_RET_ECHANGED);
677}
678
679static void
680floppy_13XX(struct bregs *regs, u8 drive)
681{
Kevin O'Connorb792b3c2008-02-29 00:20:32 -0500682 BX_INFO("int13_diskette: unsupported AH=%02x\n", regs->ah);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500683 floppy_ret(regs, DISK_RET_EPARAM);
684}
685
686void
687floppy_13(struct bregs *regs, u8 drive)
688{
Kevin O'Connorb792b3c2008-02-29 00:20:32 -0500689 if (! CONFIG_FLOPPY_SUPPORT) {
690 // Minimal stubs
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500691 switch (regs->ah) {
692 case 0x01: floppy_1301(regs, drive); break;
693 default: floppy_13XX(regs, drive); break;
694 }
Kevin O'Connorb792b3c2008-02-29 00:20:32 -0500695 return;
696 }
697 switch (regs->ah) {
698 case 0x00: floppy_1300(regs, drive); break;
699 case 0x01: floppy_1301(regs, drive); break;
700 case 0x02: floppy_1302(regs, drive); break;
701 case 0x03: floppy_1303(regs, drive); break;
702 case 0x04: floppy_1304(regs, drive); break;
703 case 0x05: floppy_1305(regs, drive); break;
704 case 0x08: floppy_1308(regs, drive); break;
705 case 0x15: floppy_1315(regs, drive); break;
706 case 0x16: floppy_1316(regs, drive); break;
707 default: floppy_13XX(regs, drive); break;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500708 }
709}
710
711// INT 0Eh Diskette Hardware ISR Entry Point
712void VISIBLE
713handle_0e(struct bregs *regs)
714{
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500715 //debug_enter(regs);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500716 if ((inb(PORT_FD_STATUS) & 0xc0) != 0xc0) {
717 outb(0x08, PORT_FD_DATA); // sense interrupt status
718 while ((inb(PORT_FD_STATUS) & 0xc0) != 0xc0)
719 ;
720 do {
721 inb(PORT_FD_DATA);
722 } while ((inb(PORT_FD_STATUS) & 0xc0) == 0xc0);
723 }
724 eoi_master_pic();
725 // diskette interrupt has occurred
726 SETBITS_BDA(floppy_recalibration_status, FRS_TIMEOUT);
727}
728
729// Called from int08 handler.
730void
731floppy_tick()
732{
733 // time to turn off drive(s)?
734 u8 fcount = GET_BDA(floppy_motor_counter);
735 if (fcount) {
736 fcount--;
737 SET_BDA(floppy_motor_counter, fcount);
738 if (fcount == 0)
739 // turn motor(s) off
740 outb(inb(PORT_FD_DOR) & 0xcf, PORT_FD_DOR);
741 }
742}