blob: f45676e2f2c7325345b1e9fe0c171810df61c9c9 [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// 16bit code to access floppy drives.
2//
Kevin O'Connorc892b132009-08-11 21:59:37 -04003// Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05004// Copyright (C) 2002 MandrakeSoft S.A.
5//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05006// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05007
Kevin O'Connor9521e262008-07-04 13:04:29 -04008#include "biosvar.h" // SET_BDA
Kevin O'Connor135f3f62013-09-14 23:57:26 -04009#include "block.h" // struct drive_s
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040010#include "bregs.h" // struct bregs
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040011#include "config.h" // CONFIG_FLOPPY
Kevin O'Connor9dea5902013-09-14 20:23:54 -040012#include "malloc.h" // malloc_fseg
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040013#include "output.h" // dprintf
Kevin O'Connor4d8510c2016-02-03 01:28:20 -050014#include "pcidevice.h" // pci_find_class
Kevin O'Connor031ef552010-12-27 19:26:57 -050015#include "pci_ids.h" // PCI_CLASS_BRIDGE_ISA
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040016#include "pic.h" // pic_eoi1
Kevin O'Connor41639f82013-09-14 19:37:36 -040017#include "romfile.h" // romfile_loadint
Kevin O'Connor8b7861c2013-09-15 02:29:06 -040018#include "rtc.h" // rtc_read
Kevin O'Connor3df600b2013-09-14 19:28:55 -040019#include "stacks.h" // yield
Kevin O'Connor135f3f62013-09-14 23:57:26 -040020#include "std/disk.h" // DISK_RET_SUCCESS
Kevin O'Connorfa9c66a2013-09-14 19:10:40 -040021#include "string.h" // memset
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040022#include "util.h" // timer_calc
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050023
Kevin O'Connor4ade5232013-09-18 21:41:48 -040024#define PORT_FD_BASE 0x03f0
25#define PORT_FD_DOR 0x03f2
26#define PORT_FD_STATUS 0x03f4
27#define PORT_FD_DATA 0x03f5
28#define PORT_FD_DIR 0x03f7
29
Kevin O'Connor7b184d82009-08-23 11:56:55 -040030#define FLOPPY_SIZE_CODE 0x02 // 512 byte sectors
31#define FLOPPY_DATALEN 0xff // Not used - because size code is 0x02
32#define FLOPPY_MOTOR_TICKS 37 // ~2 seconds
33#define FLOPPY_FILLBYTE 0xf6
34#define FLOPPY_GAPLEN 0x1B
35#define FLOPPY_FORMAT_GAPLEN 0x6c
Kevin O'Connor068cb4f2013-03-03 11:05:19 -050036#define FLOPPY_PIO_TIMEOUT 1000
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050037
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050038// New diskette parameter table adding 3 parameters from IBM
39// Since no provisions are made for multiple drive types, most
40// values in this table are ignored. I set parameters for 1.44M
41// floppy here
Kevin O'Connor89a2f962013-02-18 23:36:03 -050042struct floppy_ext_dbt_s diskette_param_table2 VARFSEG = {
Kevin O'Connor44c631d2008-03-02 11:24:36 -050043 .dbt = {
Kevin O'Connor7b184d82009-08-23 11:56:55 -040044 .specify1 = 0xAF, // step rate 12ms, head unload 240ms
45 .specify2 = 0x02, // head load time 4ms, DMA used
46 .shutoff_ticks = FLOPPY_MOTOR_TICKS, // ~2 seconds
47 .bps_code = FLOPPY_SIZE_CODE,
Kevin O'Connor44c631d2008-03-02 11:24:36 -050048 .sectors = 18,
Kevin O'Connor7b184d82009-08-23 11:56:55 -040049 .interblock_len = FLOPPY_GAPLEN,
50 .data_len = FLOPPY_DATALEN,
51 .gap_len = FLOPPY_FORMAT_GAPLEN,
52 .fill_byte = FLOPPY_FILLBYTE,
53 .settle_time = 0x0F, // 15ms
54 .startup_time = 0x08, // 1 second
Kevin O'Connor44c631d2008-03-02 11:24:36 -050055 },
56 .max_track = 79, // maximum track
57 .data_rate = 0, // data transfer rate
58 .drive_type = 4, // drive type in cmos
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050059};
60
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040061struct floppyinfo_s {
62 struct chs_s chs;
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -050063 u8 floppy_size;
64 u8 data_rate;
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040065};
66
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -050067#define FLOPPY_SIZE_525 0x01
68#define FLOPPY_SIZE_350 0x02
69
70#define FLOPPY_RATE_500K 0x00
71#define FLOPPY_RATE_300K 0x01
72#define FLOPPY_RATE_250K 0x02
73#define FLOPPY_RATE_1M 0x03
74
Kevin O'Connor89a2f962013-02-18 23:36:03 -050075struct floppyinfo_s FloppyInfo[] VARFSEG = {
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040076 // Unknown
77 { {0, 0, 0}, 0x00, 0x00},
78 // 1 - 360KB, 5.25" - 2 heads, 40 tracks, 9 sectors
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -050079 { {2, 40, 9}, FLOPPY_SIZE_525, FLOPPY_RATE_300K},
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040080 // 2 - 1.2MB, 5.25" - 2 heads, 80 tracks, 15 sectors
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -050081 { {2, 80, 15}, FLOPPY_SIZE_525, FLOPPY_RATE_500K},
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040082 // 3 - 720KB, 3.5" - 2 heads, 80 tracks, 9 sectors
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -050083 { {2, 80, 9}, FLOPPY_SIZE_350, FLOPPY_RATE_250K},
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040084 // 4 - 1.44MB, 3.5" - 2 heads, 80 tracks, 18 sectors
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -050085 { {2, 80, 18}, FLOPPY_SIZE_350, FLOPPY_RATE_500K},
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040086 // 5 - 2.88MB, 3.5" - 2 heads, 80 tracks, 36 sectors
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -050087 { {2, 80, 36}, FLOPPY_SIZE_350, FLOPPY_RATE_1M},
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040088 // 6 - 160k, 5.25" - 1 heads, 40 tracks, 8 sectors
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -050089 { {1, 40, 8}, FLOPPY_SIZE_525, FLOPPY_RATE_250K},
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040090 // 7 - 180k, 5.25" - 1 heads, 40 tracks, 9 sectors
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -050091 { {1, 40, 9}, FLOPPY_SIZE_525, FLOPPY_RATE_300K},
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040092 // 8 - 320k, 5.25" - 2 heads, 40 tracks, 8 sectors
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -050093 { {2, 40, 8}, FLOPPY_SIZE_525, FLOPPY_RATE_250K},
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040094};
95
Kevin O'Connor77d227b2009-10-22 21:48:39 -040096struct drive_s *
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -050097init_floppy(int floppyid, int ftype)
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -040098{
99 if (ftype <= 0 || ftype >= ARRAY_SIZE(FloppyInfo)) {
100 dprintf(1, "Bad floppy type %d\n", ftype);
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400101 return NULL;
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400102 }
103
Kevin O'Connor1902c942013-10-26 11:48:06 -0400104 struct drive_s *drive = malloc_fseg(sizeof(*drive));
105 if (!drive) {
Kevin O'Connord7e998f2010-02-15 22:48:28 -0500106 warn_noalloc();
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400107 return NULL;
Kevin O'Connord7e998f2010-02-15 22:48:28 -0500108 }
Kevin O'Connor1902c942013-10-26 11:48:06 -0400109 memset(drive, 0, sizeof(*drive));
110 drive->cntl_id = floppyid;
111 drive->type = DTYPE_FLOPPY;
112 drive->blksize = DISK_SECTOR_SIZE;
113 drive->floppy_type = ftype;
114 drive->sectors = (u64)-1;
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400115
Kevin O'Connor1902c942013-10-26 11:48:06 -0400116 memcpy(&drive->lchs, &FloppyInfo[ftype].chs
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400117 , sizeof(FloppyInfo[ftype].chs));
Kevin O'Connor1902c942013-10-26 11:48:06 -0400118 return drive;
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500119}
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400120
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500121static void
122addFloppy(int floppyid, int ftype)
123{
Kevin O'Connor1902c942013-10-26 11:48:06 -0400124 struct drive_s *drive = init_floppy(floppyid, ftype);
125 if (!drive)
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500126 return;
127 char *desc = znprintf(MAXDESCSIZE, "Floppy [drive %c]", 'A' + floppyid);
Kevin O'Connor0cd70052011-07-02 14:04:19 -0400128 struct pci_device *pci = pci_find_class(PCI_CLASS_BRIDGE_ISA); /* isa-to-pci bridge */
Kevin O'Connor03e589c2011-07-09 14:35:37 -0400129 int prio = bootprio_find_fdc_device(pci, PORT_FD_BASE, floppyid);
Kevin O'Connor1902c942013-10-26 11:48:06 -0400130 boot_add_floppy(drive, desc, prio);
Kevin O'Connor51fd0a12009-09-12 13:20:14 -0400131}
132
133void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500134floppy_setup(void)
Kevin O'Connor3bbcc142008-04-13 17:07:33 -0400135{
Kevin O'Connoref719892012-11-26 11:14:00 -0500136 memcpy(&diskette_param_table, &diskette_param_table2
137 , sizeof(diskette_param_table));
138 SET_IVT(0x1E, SEGOFF(SEG_BIOS
139 , (u32)&diskette_param_table2 - BUILD_BIOS_ADDR));
140
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400141 if (! CONFIG_FLOPPY)
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400142 return;
Kevin O'Connor35192dd2008-06-08 19:18:33 -0400143 dprintf(3, "init floppy drives\n");
Kevin O'Connor88c00ee2008-05-18 00:14:13 -0400144
Kevin O'Connor897fb112013-02-07 23:32:48 -0500145 if (CONFIG_QEMU) {
Kevin O'Connor8b7861c2013-09-15 02:29:06 -0400146 u8 type = rtc_read(CMOS_FLOPPY_DRIVE_TYPE);
Kevin O'Connor897fb112013-02-07 23:32:48 -0500147 if (type & 0xf0)
148 addFloppy(0, type >> 4);
149 if (type & 0x0f)
150 addFloppy(1, type & 0x0f);
151 } else {
Kevin O'Connor8b73b832012-11-26 11:18:11 -0500152 u8 type = romfile_loadint("etc/floppy0", 0);
153 if (type)
154 addFloppy(0, type);
155 type = romfile_loadint("etc/floppy1", 0);
156 if (type)
157 addFloppy(1, type);
Kevin O'Connor88c00ee2008-05-18 00:14:13 -0400158 }
Kevin O'Connor88c00ee2008-05-18 00:14:13 -0400159
Kevin O'Connorcc9e1bf2010-07-28 21:31:38 -0400160 enable_hwirq(6, FUNC16(entry_0e));
Kevin O'Connor3bbcc142008-04-13 17:07:33 -0400161}
162
Kevin O'Connora3855ad2009-08-16 21:59:40 -0400163// Find a floppy type that matches a given image size.
164int
165find_floppy_type(u32 size)
166{
167 int i;
168 for (i=1; i<ARRAY_SIZE(FloppyInfo); i++) {
169 struct chs_s *c = &FloppyInfo[i].chs;
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400170 if (c->cylinder * c->head * c->sector * DISK_SECTOR_SIZE == size)
Kevin O'Connora3855ad2009-08-16 21:59:40 -0400171 return i;
172 }
173 return -1;
174}
175
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500176
177/****************************************************************
178 * Low-level floppy IO
179 ****************************************************************/
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500180
Kevin O'Connor402f9a42013-12-07 12:48:11 -0500181u8 FloppyDOR VARLOW;
182
Nikolay Nikolov3ddb42f2018-02-04 17:26:56 +0200183static inline u8
184floppy_dor_read(void)
185{
186 return GET_LOW(FloppyDOR);
187}
188
Kevin O'Connor402f9a42013-12-07 12:48:11 -0500189static inline void
190floppy_dor_write(u8 val)
191{
192 outb(val, PORT_FD_DOR);
193 SET_LOW(FloppyDOR, val);
194}
195
Nikolay Nikolov5157a782018-02-04 17:26:57 +0200196static inline void
197floppy_dor_mask(u8 off, u8 on)
198{
199 floppy_dor_write((floppy_dor_read() & ~off) | on);
200}
201
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500202static void
Kevin O'Connor6e529bd2013-03-02 20:30:50 -0500203floppy_disable_controller(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500204{
Kevin O'Connor402f9a42013-12-07 12:48:11 -0500205 dprintf(2, "Floppy_disable_controller\n");
206 floppy_dor_write(0x00);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500207}
208
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500209static int
Kevin O'Connor6e529bd2013-03-02 20:30:50 -0500210floppy_wait_irq(void)
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500211{
Kevin O'Connor6e529bd2013-03-02 20:30:50 -0500212 u8 frs = GET_BDA(floppy_recalibration_status);
213 SET_BDA(floppy_recalibration_status, frs & ~FRS_IRQ);
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500214 for (;;) {
Kevin O'Connor6e529bd2013-03-02 20:30:50 -0500215 if (!GET_BDA(floppy_motor_counter)) {
Kevin O'Connorb66456c2013-12-04 10:31:51 -0500216 warn_timeout();
Kevin O'Connor6e529bd2013-03-02 20:30:50 -0500217 floppy_disable_controller();
218 return DISK_RET_ETIMEOUT;
219 }
Kevin O'Connore51316d2012-06-10 09:09:22 -0400220 frs = GET_BDA(floppy_recalibration_status);
Kevin O'Connor6e529bd2013-03-02 20:30:50 -0500221 if (frs & FRS_IRQ)
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500222 break;
Kevin O'Connor94c749c2012-05-28 11:44:02 -0400223 // Could use yield_toirq() here, but that causes issues on
Kevin O'Connor7a98fd02010-01-17 13:00:49 -0500224 // bochs, so use yield() instead.
225 yield();
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500226 }
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500227
Kevin O'Connor6e529bd2013-03-02 20:30:50 -0500228 SET_BDA(floppy_recalibration_status, frs & ~FRS_IRQ);
229 return DISK_RET_SUCCESS;
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500230}
231
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500232// Floppy commands
233#define FCF_WAITIRQ 0x10000
234#define FC_CHECKIRQ (0x08 | (0<<8) | (2<<12))
Kevin O'Connor8615f622013-12-11 19:38:15 -0500235#define FC_SEEK (0x0f | (2<<8) | (0<<12) | FCF_WAITIRQ)
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500236#define FC_RECALIBRATE (0x07 | (1<<8) | (0<<12) | FCF_WAITIRQ)
237#define FC_READID (0x4a | (1<<8) | (7<<12) | FCF_WAITIRQ)
238#define FC_READ (0xe6 | (8<<8) | (7<<12) | FCF_WAITIRQ)
239#define FC_WRITE (0xc5 | (8<<8) | (7<<12) | FCF_WAITIRQ)
240#define FC_FORMAT (0x4d | (5<<8) | (7<<12) | FCF_WAITIRQ)
Kevin O'Connor9ba374c2013-03-02 18:37:04 -0500241
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500242// Send the specified command and it's parameters to the floppy controller.
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400243static int
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500244floppy_pio(int command, u8 *param)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500245{
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500246 dprintf(9, "Floppy pio command %x\n", command);
247 // Send command and parameters to controller.
Kevin O'Connor018bdd72013-07-20 18:22:57 -0400248 u32 end = timer_calc(FLOPPY_PIO_TIMEOUT);
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500249 int send = (command >> 8) & 0xf;
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500250 int i = 0;
251 for (;;) {
252 u8 sts = inb(PORT_FD_STATUS);
253 if (!(sts & 0x80)) {
Kevin O'Connor018bdd72013-07-20 18:22:57 -0400254 if (timer_check(end)) {
Kevin O'Connorb66456c2013-12-04 10:31:51 -0500255 warn_timeout();
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500256 floppy_disable_controller();
257 return DISK_RET_ETIMEOUT;
258 }
Kevin O'Connorca087772014-11-29 13:04:46 -0500259 yield();
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500260 continue;
261 }
262 if (sts & 0x40) {
263 floppy_disable_controller();
264 return DISK_RET_ECONTROLLER;
265 }
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500266 if (i == 0)
267 outb(command & 0xff, PORT_FD_DATA);
268 else
269 outb(param[i-1], PORT_FD_DATA);
270 if (i++ >= send)
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500271 break;
272 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500273
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500274 // Wait for command to complete.
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500275 if (command & FCF_WAITIRQ) {
Kevin O'Connor6e529bd2013-03-02 20:30:50 -0500276 int ret = floppy_wait_irq();
277 if (ret)
278 return ret;
Kevin O'Connor06ad44e2008-04-05 19:30:02 -0400279 }
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500280
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500281 // Read response from controller.
Kevin O'Connor018bdd72013-07-20 18:22:57 -0400282 end = timer_calc(FLOPPY_PIO_TIMEOUT);
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500283 int receive = (command >> 12) & 0xf;
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500284 i = 0;
285 for (;;) {
286 u8 sts = inb(PORT_FD_STATUS);
287 if (!(sts & 0x80)) {
Kevin O'Connor018bdd72013-07-20 18:22:57 -0400288 if (timer_check(end)) {
Kevin O'Connorb66456c2013-12-04 10:31:51 -0500289 warn_timeout();
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500290 floppy_disable_controller();
291 return DISK_RET_ETIMEOUT;
292 }
Kevin O'Connorca087772014-11-29 13:04:46 -0500293 yield();
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500294 continue;
295 }
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500296 if (i >= receive) {
297 if (sts & 0x40) {
298 floppy_disable_controller();
299 return DISK_RET_ECONTROLLER;
300 }
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500301 break;
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500302 }
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500303 if (!(sts & 0x40)) {
304 floppy_disable_controller();
305 return DISK_RET_ECONTROLLER;
306 }
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500307 param[i++] = inb(PORT_FD_DATA);
Kevin O'Connor068cb4f2013-03-03 11:05:19 -0500308 }
Kevin O'Connor9ba374c2013-03-02 18:37:04 -0500309
310 return DISK_RET_SUCCESS;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500311}
312
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500313static int
314floppy_enable_controller(void)
315{
Kevin O'Connor402f9a42013-12-07 12:48:11 -0500316 dprintf(2, "Floppy_enable_controller\n");
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500317 SET_BDA(floppy_motor_counter, FLOPPY_MOTOR_TICKS);
Kevin O'Connor402f9a42013-12-07 12:48:11 -0500318 floppy_dor_write(0x00);
319 floppy_dor_write(0x0c);
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500320 int ret = floppy_wait_irq();
321 if (ret)
322 return ret;
323
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500324 u8 param[2];
325 return floppy_pio(FC_CHECKIRQ, param);
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500326}
327
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500328// Activate a drive and send a command to it.
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500329static int
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500330floppy_drive_pio(u8 floppyid, int command, u8 *param)
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500331{
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500332 // Enable controller if it isn't running.
Nikolay Nikolov3ddb42f2018-02-04 17:26:56 +0200333 if (!(floppy_dor_read() & 0x04)) {
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500334 int ret = floppy_enable_controller();
335 if (ret)
336 return ret;
337 }
338
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500339 // reset the disk motor timeout value of INT 08
340 SET_BDA(floppy_motor_counter, FLOPPY_MOTOR_TICKS);
341
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500342 // Turn on motor of selected drive, DMA & int enabled, normal operation
Kevin O'Connor402f9a42013-12-07 12:48:11 -0500343 floppy_dor_write((floppyid ? 0x20 : 0x10) | 0x0c | floppyid);
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500344
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500345 // Send command.
346 int ret = floppy_pio(command, param);
347 if (ret)
348 return ret;
349
350 // Check IRQ command is needed after irq commands with no results
351 if ((command & FCF_WAITIRQ) && ((command >> 12) & 0xf) == 0)
352 return floppy_pio(FC_CHECKIRQ, param);
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500353 return DISK_RET_SUCCESS;
354}
355
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500356
357/****************************************************************
Kevin O'Connor8615f622013-12-11 19:38:15 -0500358 * Floppy media sense and seeking
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500359 ****************************************************************/
360
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500361static int
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400362floppy_drive_recal(u8 floppyid)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500363{
Kevin O'Connor402f9a42013-12-07 12:48:11 -0500364 dprintf(2, "Floppy_drive_recal %d\n", floppyid);
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500365 // send Recalibrate command to controller
366 u8 param[2];
367 param[0] = floppyid;
368 int ret = floppy_drive_pio(floppyid, FC_RECALIBRATE, param);
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500369 if (ret)
370 return ret;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500371
Kevin O'Connore51316d2012-06-10 09:09:22 -0400372 u8 frs = GET_BDA(floppy_recalibration_status);
373 SET_BDA(floppy_recalibration_status, frs | (1<<floppyid));
Kevin O'Connor8615f622013-12-11 19:38:15 -0500374 SET_BDA(floppy_track[floppyid], 0);
Kevin O'Connor1f711d22013-03-02 21:26:54 -0500375 return DISK_RET_SUCCESS;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500376}
377
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500378static int
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -0500379floppy_drive_readid(u8 floppyid, u8 data_rate, u8 head)
380{
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -0500381 // Set data rate.
382 outb(data_rate, PORT_FD_DIR);
383
384 // send Read Sector Id command
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500385 u8 param[7];
386 param[0] = (head << 2) | floppyid; // HD DR1 DR2
387 int ret = floppy_drive_pio(floppyid, FC_READID, param);
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -0500388 if (ret)
389 return ret;
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500390 if (param[0] & 0xc0)
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -0500391 return -1;
392 return 0;
393}
394
395static int
Kevin O'Connor1902c942013-10-26 11:48:06 -0400396floppy_media_sense(struct drive_s *drive_gf)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500397{
Kevin O'Connor1902c942013-10-26 11:48:06 -0400398 u8 ftype = GET_GLOBALFLAT(drive_gf->floppy_type), stype = ftype;
399 u8 floppyid = GET_GLOBALFLAT(drive_gf->cntl_id);
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -0500400
401 u8 data_rate = GET_GLOBAL(FloppyInfo[stype].data_rate);
402 int ret = floppy_drive_readid(floppyid, data_rate, 0);
403 if (ret) {
404 // Attempt media sense.
405 for (stype=1; ; stype++) {
406 if (stype >= ARRAY_SIZE(FloppyInfo))
407 return DISK_RET_EMEDIA;
408 if (stype==ftype
409 || (GET_GLOBAL(FloppyInfo[stype].floppy_size)
410 != GET_GLOBAL(FloppyInfo[ftype].floppy_size))
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400411 || (GET_GLOBAL(FloppyInfo[stype].chs.head)
412 > GET_GLOBAL(FloppyInfo[ftype].chs.head))
413 || (GET_GLOBAL(FloppyInfo[stype].chs.cylinder)
414 > GET_GLOBAL(FloppyInfo[ftype].chs.cylinder))
415 || (GET_GLOBAL(FloppyInfo[stype].chs.sector)
416 > GET_GLOBAL(FloppyInfo[ftype].chs.sector)))
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -0500417 continue;
418 data_rate = GET_GLOBAL(FloppyInfo[stype].data_rate);
419 ret = floppy_drive_readid(floppyid, data_rate, 0);
420 if (!ret)
421 break;
422 }
423 }
Kevin O'Connor402f9a42013-12-07 12:48:11 -0500424 dprintf(2, "Floppy_media_sense on drive %d found rate %d\n"
425 , floppyid, data_rate);
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -0500426
427 u8 old_data_rate = GET_BDA(floppy_media_state[floppyid]) >> 6;
428 SET_BDA(floppy_last_data_rate, (old_data_rate<<2) | (data_rate<<6));
429 u8 media = (stype == 1 ? 0x04 : (stype == 2 ? 0x05 : 0x07));
430 u8 fms = (data_rate<<6) | FMS_MEDIA_DRIVE_ESTABLISHED | media;
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400431 if (GET_GLOBAL(FloppyInfo[stype].chs.cylinder)
432 < GET_GLOBAL(FloppyInfo[ftype].chs.cylinder))
Kevin O'Connore7c5a7e2013-03-03 13:59:58 -0500433 fms |= FMS_DOUBLE_STEPPING;
434 SET_BDA(floppy_media_state[floppyid], fms);
435
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400436 return DISK_RET_SUCCESS;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500437}
438
Kevin O'Connor8615f622013-12-11 19:38:15 -0500439// Prepare a floppy for a data transfer.
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400440static int
Kevin O'Connor8615f622013-12-11 19:38:15 -0500441floppy_prep(struct drive_s *drive_gf, u8 cylinder)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500442{
Kevin O'Connor1902c942013-10-26 11:48:06 -0400443 u8 floppyid = GET_GLOBALFLAT(drive_gf->cntl_id);
Kevin O'Connor8615f622013-12-11 19:38:15 -0500444 if (!(GET_BDA(floppy_recalibration_status) & (1<<floppyid)) ||
445 !(GET_BDA(floppy_media_state[floppyid]) & FMS_MEDIA_DRIVE_ESTABLISHED)) {
446 // Recalibrate drive.
447 int ret = floppy_drive_recal(floppyid);
448 if (ret)
449 return ret;
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500450
Kevin O'Connor8615f622013-12-11 19:38:15 -0500451 // Sense media.
452 ret = floppy_media_sense(drive_gf);
453 if (ret)
454 return ret;
455 }
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500456
Kevin O'Connor8615f622013-12-11 19:38:15 -0500457 // Seek to cylinder if needed.
458 u8 lastcyl = GET_BDA(floppy_track[floppyid]);
459 if (cylinder != lastcyl) {
460 u8 param[2];
461 param[0] = floppyid;
462 param[1] = cylinder;
463 int ret = floppy_drive_pio(floppyid, FC_SEEK, param);
464 if (ret)
465 return ret;
466 SET_BDA(floppy_track[floppyid], cylinder);
467 }
468
469 return DISK_RET_SUCCESS;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500470}
471
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500472
473/****************************************************************
Kevin O'Connor7b9f2972013-09-18 21:04:03 -0400474 * Floppy DMA transfer
Kevin O'Connorc8494052013-03-03 10:27:30 -0500475 ****************************************************************/
476
477// Perform a floppy transfer command (setup DMA and issue PIO).
478static int
Kevin O'Connor8615f622013-12-11 19:38:15 -0500479floppy_dma_cmd(struct disk_op_s *op, int count, int command, u8 *param)
Kevin O'Connorc8494052013-03-03 10:27:30 -0500480{
Kevin O'Connor7b9f2972013-09-18 21:04:03 -0400481 // Setup DMA controller
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500482 int isWrite = command != FC_READ;
Kevin O'Connor8615f622013-12-11 19:38:15 -0500483 int ret = dma_floppy((u32)op->buf_fl, count, isWrite);
Kevin O'Connor7b9f2972013-09-18 21:04:03 -0400484 if (ret)
Kevin O'Connorc8494052013-03-03 10:27:30 -0500485 return DISK_RET_EBOUNDARY;
486
Kevin O'Connor7b9f2972013-09-18 21:04:03 -0400487 // Invoke floppy controller
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400488 u8 floppyid = GET_GLOBALFLAT(op->drive_fl->cntl_id);
Kevin O'Connor8615f622013-12-11 19:38:15 -0500489 ret = floppy_drive_pio(floppyid, command, param);
Kevin O'Connorc8494052013-03-03 10:27:30 -0500490 if (ret)
491 return ret;
492
493 // Populate floppy_return_status in BDA
494 int i;
495 for (i=0; i<7; i++)
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500496 SET_BDA(floppy_return_status[i], param[i]);
Kevin O'Connorc8494052013-03-03 10:27:30 -0500497
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500498 if (param[0] & 0xc0) {
499 if (param[1] & 0x02)
Kevin O'Connorc8494052013-03-03 10:27:30 -0500500 return DISK_RET_EWRITEPROTECT;
Kevin O'Connor8413b322013-03-09 20:07:38 -0500501 dprintf(1, "floppy error: %02x %02x %02x %02x %02x %02x %02x\n"
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500502 , param[0], param[1], param[2], param[3]
503 , param[4], param[5], param[6]);
Kevin O'Connorc8494052013-03-03 10:27:30 -0500504 return DISK_RET_ECONTROLLER;
505 }
506
Kevin O'Connorc8494052013-03-03 10:27:30 -0500507 return DISK_RET_SUCCESS;
508}
509
510
511/****************************************************************
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400512 * Floppy handlers
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500513 ****************************************************************/
514
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400515static struct chs_s
516lba2chs(struct disk_op_s *op)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500517{
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400518 struct chs_s res = { };
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400519
Kevin O'Connor302a6e82013-12-07 11:46:37 -0500520 u32 tmp = op->lba;
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400521 u16 nls = GET_GLOBALFLAT(op->drive_fl->lchs.sector);
Kevin O'Connor302a6e82013-12-07 11:46:37 -0500522 res.sector = (tmp % nls) + 1;
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400523
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400524 tmp /= nls;
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400525 u16 nlh = GET_GLOBALFLAT(op->drive_fl->lchs.head);
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400526 res.head = tmp % nlh;
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400527
528 tmp /= nlh;
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400529 res.cylinder = tmp;
530
531 return res;
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400532}
533
534// diskette controller reset
535static int
536floppy_reset(struct disk_op_s *op)
537{
Kevin O'Connor5bb75522013-03-03 15:32:31 -0500538 SET_BDA(floppy_recalibration_status, 0);
539 SET_BDA(floppy_media_state[0], 0);
540 SET_BDA(floppy_media_state[1], 0);
541 SET_BDA(floppy_track[0], 0);
542 SET_BDA(floppy_track[1], 0);
543 SET_BDA(floppy_last_data_rate, 0);
544 floppy_disable_controller();
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500545 return floppy_enable_controller();
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500546}
547
548// Read Diskette Sectors
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400549static int
550floppy_read(struct disk_op_s *op)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500551{
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400552 struct chs_s chs = lba2chs(op);
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400553 int ret = floppy_prep(op->drive_fl, chs.cylinder);
Kevin O'Connorb7558a32013-12-17 18:15:46 -0500554 if (ret)
555 return ret;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500556
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500557 // send read-normal-data command to controller
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400558 u8 floppyid = GET_GLOBALFLAT(op->drive_fl->cntl_id);
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500559 u8 param[8];
560 param[0] = (chs.head << 2) | floppyid; // HD DR1 DR2
561 param[1] = chs.cylinder;
562 param[2] = chs.head;
563 param[3] = chs.sector;
564 param[4] = FLOPPY_SIZE_CODE;
565 param[5] = chs.sector + op->count - 1; // last sector to read on track
566 param[6] = FLOPPY_GAPLEN;
567 param[7] = FLOPPY_DATALEN;
Kevin O'Connorb7558a32013-12-17 18:15:46 -0500568 return floppy_dma_cmd(op, op->count * DISK_SECTOR_SIZE, FC_READ, param);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500569}
570
571// Write Diskette Sectors
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400572static int
573floppy_write(struct disk_op_s *op)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500574{
Kevin O'Connor8ab9a342013-09-28 23:34:49 -0400575 struct chs_s chs = lba2chs(op);
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400576 int ret = floppy_prep(op->drive_fl, chs.cylinder);
Kevin O'Connorb7558a32013-12-17 18:15:46 -0500577 if (ret)
578 return ret;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500579
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500580 // send write-normal-data command to controller
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400581 u8 floppyid = GET_GLOBALFLAT(op->drive_fl->cntl_id);
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500582 u8 param[8];
583 param[0] = (chs.head << 2) | floppyid; // HD DR1 DR2
584 param[1] = chs.cylinder;
585 param[2] = chs.head;
586 param[3] = chs.sector;
587 param[4] = FLOPPY_SIZE_CODE;
588 param[5] = chs.sector + op->count - 1; // last sector to write on track
589 param[6] = FLOPPY_GAPLEN;
590 param[7] = FLOPPY_DATALEN;
Kevin O'Connorb7558a32013-12-17 18:15:46 -0500591 return floppy_dma_cmd(op, op->count * DISK_SECTOR_SIZE, FC_WRITE, param);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500592}
593
594// Verify Diskette Sectors
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400595static int
596floppy_verify(struct disk_op_s *op)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500597{
Kevin O'Connor8615f622013-12-11 19:38:15 -0500598 struct chs_s chs = lba2chs(op);
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400599 int ret = floppy_prep(op->drive_fl, chs.cylinder);
Kevin O'Connorb7558a32013-12-17 18:15:46 -0500600 if (ret)
601 return ret;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500602
Kevin O'Connor8615f622013-12-11 19:38:15 -0500603 // This command isn't implemented - just return success.
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400604 return DISK_RET_SUCCESS;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500605}
606
607// format diskette track
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400608static int
609floppy_format(struct disk_op_s *op)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500610{
Kevin O'Connorb84899e2013-12-11 19:15:45 -0500611 struct chs_s chs = lba2chs(op);
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400612 int ret = floppy_prep(op->drive_fl, chs.cylinder);
Kevin O'Connorb7558a32013-12-17 18:15:46 -0500613 if (ret)
614 return ret;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500615
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500616 // send format-track command to controller
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400617 u8 floppyid = GET_GLOBALFLAT(op->drive_fl->cntl_id);
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500618 u8 param[7];
Kevin O'Connorb84899e2013-12-11 19:15:45 -0500619 param[0] = (chs.head << 2) | floppyid; // HD DR1 DR2
Kevin O'Connorcd891f12013-12-11 18:32:12 -0500620 param[1] = FLOPPY_SIZE_CODE;
621 param[2] = op->count; // number of sectors per track
622 param[3] = FLOPPY_FORMAT_GAPLEN;
623 param[4] = FLOPPY_FILLBYTE;
Kevin O'Connor8615f622013-12-11 19:38:15 -0500624 return floppy_dma_cmd(op, op->count * 4, FC_FORMAT, param);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500625}
626
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400627int
Kevin O'Connor17856452015-07-07 14:56:20 -0400628floppy_process_op(struct disk_op_s *op)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500629{
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400630 if (!CONFIG_FLOPPY)
631 return 0;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500632
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400633 switch (op->command) {
634 case CMD_RESET:
635 return floppy_reset(op);
636 case CMD_READ:
637 return floppy_read(op);
638 case CMD_WRITE:
639 return floppy_write(op);
640 case CMD_VERIFY:
641 return floppy_verify(op);
642 case CMD_FORMAT:
643 return floppy_format(op);
644 default:
Kevin O'Connoraf5aabb2009-08-16 18:48:38 -0400645 return DISK_RET_EPARAM;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500646 }
647}
648
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500649
650/****************************************************************
651 * HW irqs
652 ****************************************************************/
653
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500654// INT 0Eh Diskette Hardware ISR Entry Point
Kevin O'Connor19786762008-03-05 21:09:59 -0500655void VISIBLE16
Kevin O'Connor1297e5d2012-06-02 20:30:58 -0400656handle_0e(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500657{
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400658 if (! CONFIG_FLOPPY)
Kevin O'Connorff5e0052012-12-07 11:25:58 -0500659 return;
660 debug_isr(DEBUG_ISR_0e);
Kevin O'Connor40967022008-07-21 22:23:05 -0400661
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500662 // diskette interrupt has occurred
Kevin O'Connore51316d2012-06-10 09:09:22 -0400663 u8 frs = GET_BDA(floppy_recalibration_status);
Kevin O'Connor6e529bd2013-03-02 20:30:50 -0500664 SET_BDA(floppy_recalibration_status, frs | FRS_IRQ);
Kevin O'Connor40967022008-07-21 22:23:05 -0400665
Kevin O'Connoraa7c2342013-07-14 15:07:21 -0400666 pic_eoi1();
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500667}
668
669// Called from int08 handler.
670void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500671floppy_tick(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500672{
Kevin O'Connor0a0e42e2009-08-16 12:09:44 -0400673 if (! CONFIG_FLOPPY)
Kevin O'Connor40967022008-07-21 22:23:05 -0400674 return;
675
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500676 // time to turn off drive(s)?
677 u8 fcount = GET_BDA(floppy_motor_counter);
678 if (fcount) {
679 fcount--;
680 SET_BDA(floppy_motor_counter, fcount);
681 if (fcount == 0)
682 // turn motor(s) off
Nikolay Nikolov5157a782018-02-04 17:26:57 +0200683 floppy_dor_mask(0xf0, 0);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500684 }
685}