3 * Floppy Disk Access Code
9 #include <tpl_drv_disk.h>
16 // --- Current Version
17 #define FDD_VERSION ((0<<8)|(75))
20 #define FDD_SEEK_TIMEOUT 10 // Timeout for a seek operation
21 #define MOTOR_ON_DELAY 500 // Miliseconds
22 #define MOTOR_OFF_DELAY 2000 // Miliseconds
23 #define FDD_MAX_READWRITE_ATTEMPTS 16
27 * \brief Representation of a floppy drive
29 typedef struct sFloppyDrive
32 volatile int motorState; //2 - On, 1 - Spinup, 0 - Off
37 tIOCache *CacheHandle;
42 * \brief Cached Sector
47 Uint16 sector; // Allows 32Mb of addressable space (Plenty for FDD)
52 static const char *cFDD_TYPES[] = {"None", "360kB 5.25\"", "1.2MB 5.25\"", "720kB 3.5\"", "1.44MB 3.5\"", "2.88MB 3.5\"" };
53 static const int cFDD_SIZES[] = { 0, 360*1024, 1200*1024, 720*1024, 1440*1024, 2880*1024 };
54 static const short cPORTBASE[] = { 0x3F0, 0x370 };
56 static const char *cFDD_STATUSES[] = {NULL, "Error", "Invalid command", "Drive not ready"};
63 PORT_MAINSTATUS = 0x4,
70 #define CMD_FLAG_MULTI_TRACK 0x80 //!< Multitrack
71 #define CMD_FLAG_MFM_ENCODING 0x40 //!< MFM Encoding Mode (Always set for read/write/format/verify)
72 #define CMD_FLAG_SKIP_MODE 0x20 //!< Skip Mode (don't use)
74 CMD_READ_TRACK = 0x02,
76 CMD_SENSE_STATUS = 0x04,
77 CMD_WRITE_DATA = 0x05,
79 CMD_RECALIBRATE = 0x07,
80 CMD_SENSE_INTERRUPT = 0x08,
81 CMD_WRITE_DEL_DATA = 0x09,
82 CMD_READ_SECTOR_ID = 0x0A,
84 CMD_READ_DEL_DATA = 0x0C,
85 CMD_FORMAT_TRACK = 0x0D,
87 CMD_SEEK_TRACK = 0x0F,
90 CMD_LOCK = 0x14, //!< Save controller parameters
97 int FDD_Install(char **Arguments);
98 void FDD_UnloadModule();
100 char *FDD_ReadDir(tVFS_Node *Node, int pos);
101 tVFS_Node *FDD_FindDir(tVFS_Node *dirNode, const char *Name);
102 int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data);
103 Uint64 FDD_ReadFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer);
104 // --- Functions for IOCache/DrvUtil
105 Uint FDD_ReadSectors(Uint64 SectorAddr, Uint Count, void *Buffer, Uint Disk);
106 // --- Raw Disk Access
107 int FDD_ReadSector(Uint32 disk, Uint64 lba, void *Buffer);
108 int FDD_WriteSector(Uint32 Disk, Uint64 LBA, void *Buffer);
110 void FDD_IRQHandler(int Num);
111 inline void FDD_WaitIRQ();
112 void FDD_SensInt(int base, Uint8 *sr0, Uint8 *cyl);
113 int FDD_int_SendByte(int base, Uint8 Byte);
114 int FDD_int_GetByte(int base, Uint8 *Byte);
115 int FDD_Reset(int id);
116 void FDD_Recalibrate(int disk);
117 int FDD_Reconfigure(int ID);
118 int FDD_int_SeekTrack(int disk, int head, int track);
119 void FDD_int_TimerCallback(void *Arg);
120 void FDD_int_StopMotor(void *Arg);
121 void FDD_int_StartMotor(int Disk);
122 int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt);
125 MODULE_DEFINE(0, FDD_VERSION, FDD, FDD_Install, NULL, "x86_ISADMA", NULL);
126 t_floppyDevice gFDD_Devices[2];
128 volatile int gbFDD_IrqFired = 0;
129 tDevFS_Driver gFDD_DriverInfo = {
134 .ACLs = &gVFS_ACL_EveryoneRX,
135 .Flags = VFS_FFLAG_DIRECTORY,
136 .ReadDir = FDD_ReadDir,
137 .FindDir = FDD_FindDir,
144 * \fn int FDD_Install(char **Arguments)
145 * \brief Installs floppy driver
147 int FDD_Install(char **Arguments)
150 char **args = Arguments;
152 // Determine Floppy Types (From CMOS)
155 gFDD_Devices[0].type = data >> 4;
156 gFDD_Devices[1].type = data & 0xF;
157 gFDD_Devices[0].track[0] = -1;
158 gFDD_Devices[1].track[1] = -1;
163 if(strcmp(*args, "disable")==0)
164 return MODULE_ERR_NOTNEEDED;
168 Log_Log("FDD", "Detected Disk 0: %s and Disk 1: %s", cFDD_TYPES[data>>4], cFDD_TYPES[data&0xF]);
171 return MODULE_ERR_NOTNEEDED;
174 // Install IRQ6 Handler
175 IRQ_AddHandler(6, FDD_IRQHandler);
177 // Ensure the FDD version is 0x90
180 FDD_int_SendByte(cPORTBASE[0], CMD_VERSION);
181 FDD_int_GetByte(cPORTBASE[0], &tmp);
183 Log_Error("FDD", "Version(0x%2x) != 0x90", tmp);
184 return MODULE_ERR_NOTNEEDED;
191 // Reset Primary FDD Controller
192 if( FDD_Reset(0) != 0 ) {
193 return MODULE_ERR_MISC;
196 // Initialise Root Node
197 gFDD_DriverInfo.RootNode.CTime = gFDD_DriverInfo.RootNode.MTime
198 = gFDD_DriverInfo.RootNode.ATime = now();
200 // Initialise Child Nodes
201 gFDD_Devices[0].Node.Inode = 0;
202 gFDD_Devices[0].Node.Flags = 0;
203 gFDD_Devices[0].Node.NumACLs = 0;
204 gFDD_Devices[0].Node.Read = FDD_ReadFS;
205 gFDD_Devices[0].Node.Write = NULL;//FDD_WriteFS;
206 memcpy(&gFDD_Devices[1].Node, &gFDD_Devices[0].Node, sizeof(tVFS_Node));
208 gFDD_Devices[1].Node.Inode = 1;
211 gFDD_Devices[0].Node.Size = cFDD_SIZES[data >> 4];
212 gFDD_Devices[1].Node.Size = cFDD_SIZES[data & 0xF];
214 // Create Sector Cache
215 if( cFDD_SIZES[data >> 4] )
217 gFDD_Devices[0].CacheHandle = IOCache_Create(
218 FDD_WriteSector, 0, 512,
219 gFDD_Devices[0].Node.Size / (512*4)
220 ); // Cache is 1/4 the size of the disk
222 if( cFDD_SIZES[data & 15] )
224 gFDD_Devices[1].CacheHandle = IOCache_Create(
225 FDD_WriteSector, 0, 512,
226 gFDD_Devices[1].Node.Size / (512*4)
227 ); // Cache is 1/4 the size of the disk
230 // Register with devfs
231 DevFS_AddDevice(&gFDD_DriverInfo);
233 return MODULE_ERR_OK;
237 * \brief Prepare the module for removal
239 void FDD_UnloadModule()
242 DevFS_DelDevice( &gFDD_DriverInfo );
243 Mutex_Acquire(&glFDD);
245 Time_RemoveTimer(gFDD_Devices[i].timer);
246 FDD_int_StopMotor((void *)(Uint)i);
248 Mutex_Release(&glFDD);
253 * \fn char *FDD_ReadDir(tVFS_Node *Node, int pos)
254 * \brief Read Directory
256 char *FDD_ReadDir(tVFS_Node *UNUSED(Node), int Pos)
258 char name[2] = "0\0";
260 if(Pos >= 2 || Pos < 0) return NULL;
262 if(gFDD_Devices[Pos].type == 0) return VFS_SKIP;
270 * \fn tVFS_Node *FDD_FindDir(tVFS_Node *Node, const char *filename);
271 * \brief Find File Routine (for vfs_node)
273 tVFS_Node *FDD_FindDir(tVFS_Node *UNUSED(Node), const char *Filename)
277 ENTER("sFilename", Filename);
279 // Sanity check string
280 if(Filename == NULL) {
285 // Check string length (should be 1)
286 if(Filename[0] == '\0' || Filename[1] != '\0') {
291 // Get First character
292 i = Filename[0] - '0';
294 // Check for 1st disk and if it is present return
295 if(i == 0 && gFDD_Devices[0].type != 0) {
296 LEAVE('p', &gFDD_Devices[0].Node);
297 return &gFDD_Devices[0].Node;
300 // Check for 2nd disk and if it is present return
301 if(i == 1 && gFDD_Devices[1].type != 0) {
302 LEAVE('p', &gFDD_Devices[1].Node);
303 return &gFDD_Devices[1].Node;
311 static const char *casIOCTLS[] = {DRV_IOCTLNAMES,DRV_DISK_IOCTLNAMES,NULL};
313 * \fn int FDD_IOCtl(tVFS_Node *Node, int id, void *data)
314 * \brief Stub ioctl function
316 int FDD_IOCtl(tVFS_Node *UNUSED(Node), int ID, void *Data)
320 BASE_IOCTLS(DRV_TYPE_DISK, "FDD", FDD_VERSION, casIOCTLS);
322 case DISK_IOCTL_GETBLOCKSIZE: return 512;
330 * \fn Uint64 FDD_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
331 * \brief Read Data from a disk
333 Uint64 FDD_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
337 ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
344 if(Node->Inode != 0 && Node->Inode != 1) {
349 ret = DrvUtil_ReadBlock(Offset, Length, Buffer, FDD_ReadSectors, 512, Node->Inode);
355 * \brief Reads \a Count contiguous sectors from a disk
356 * \param SectorAddr Address of the first sector
357 * \param Count Number of sectors to read
358 * \param Buffer Destination Buffer
359 * \param Disk Disk Number
360 * \return Number of sectors read
361 * \note Used as a ::DrvUtil_ReadBlock helper
363 Uint FDD_ReadSectors(Uint64 SectorAddr, Uint Count, void *Buffer, Uint Disk)
368 if( FDD_ReadSector(Disk, SectorAddr, Buffer) != 1 )
371 Buffer = (void*)( (tVAddr)Buffer + 512 );
378 int FDD_int_ReadWriteSector(Uint32 Disk, Uint64 SectorAddr, int Write, void *Buffer)
383 int lba = SectorAddr;
384 Uint8 st0=0, st1=0, st2=0, bps=0; // Status Values
386 ENTER("iDisk XSectorAddr pBuffer", Disk, SectorAddr, Buffer);
388 base = cPORTBASE[Disk >> 1];
390 LOG("Calculating Disk Dimensions");
392 if(FDD_int_GetDims(gFDD_Devices[Disk].type, lba, &cyl, &head, &sec, &spt) != 1)
397 LOG("Cyl=%i, Head=%i, Sector=%i", cyl, head, sec);
399 Mutex_Acquire(&glFDD); // Lock to stop the motor stopping on us
400 Time_RemoveTimer(gFDD_Devices[Disk].timer); // Remove Old Timer
401 // Start motor if needed
402 if(gFDD_Devices[Disk].motorState != 2) FDD_int_StartMotor(Disk);
403 Mutex_Release(&glFDD);
405 LOG("Wait for the motor to spin up");
408 while(gFDD_Devices[Disk].motorState == 1) Threads_Yield();
410 LOG("Acquire Spinlock");
411 Mutex_Acquire(&glFDD);
415 outb(base + CALIBRATE_DRIVE, 0);
417 while(FDD_int_SeekTrack(Disk, head, (Uint8)cyl) == 0 && i++ < FDD_SEEK_TIMEOUT )
419 if( i > FDD_SEEK_TIMEOUT ) {
420 Mutex_Release(&glFDD);
424 //FDD_SensInt(base, NULL, NULL); // Wait for IRQ
427 // Read Data from DMA
428 LOG("Setting DMA for read");
429 DMA_SetChannel(2, 512, !Write); // Read/Write 512 Bytes from channel 2
431 LOG("Sending command");
433 for( i = 0; i < FDD_MAX_READWRITE_ATTEMPTS; i ++ )
436 FDD_int_SendByte(base, CMD_WRITE_DATA|CMD_FLAG_MFM_ENCODING);
438 FDD_int_SendByte(base, CMD_READ_DATA|CMD_FLAG_MFM_ENCODING);
439 FDD_int_SendByte(base, (head << 2) | (Disk&1));
440 FDD_int_SendByte(base, (Uint8)cyl);
441 FDD_int_SendByte(base, (Uint8)head);
442 FDD_int_SendByte(base, (Uint8)sec);
443 FDD_int_SendByte(base, 0x02); // Bytes Per Sector (Real BPS=128*2^{val})
444 FDD_int_SendByte(base, spt); // SPT
445 FDD_int_SendByte(base, 0x1B); // Gap Length (27 is default)
446 FDD_int_SendByte(base, 0xFF); // Data Length
451 DMA_WriteData(2, 512, Buffer);
452 LOG("Waiting for Data to be written");
456 LOG("Waiting for data to be read");
459 DMA_ReadData(2, 512, Buffer);
462 // Clear Input Buffer
463 LOG("Clearing Input Buffer");
465 FDD_int_GetByte(base, &st0);
466 FDD_int_GetByte(base, &st1);
467 FDD_int_GetByte(base, &st2);
469 // Cylinder, Head and Sector (mutilated in some way)
470 FDD_int_GetByte(base, NULL); // Cylinder
471 FDD_int_GetByte(base, NULL); // Head
472 FDD_int_GetByte(base, NULL); // Sector
473 // Should be the BPS set above (0x02)
474 FDD_int_GetByte(base, &bps);
479 LOG("Error (st0 & 0xC0) \"%s\"", cFDD_STATUSES[st0 >> 6]);
483 if(st0 & 0x08) { LOG("Drive not ready"); continue; }
484 if(st1 & 0x80) { LOG("End of Cylinder"); continue; }
485 if(st1 & 0x20) { LOG("CRC Error"); continue; }
486 if(st1 & 0x10) { LOG("Controller Timeout"); continue; }
487 if(st1 & 0x04) { LOG("No Data Found"); continue; }
488 if(st1 & 0x01 || st2 & 0x01) {
489 LOG("No Address mark found");
492 if(st2 & 0x40) { LOG("Deleted address mark"); continue; }
493 if(st2 & 0x20) { LOG("CRC error in data"); continue; }
494 if(st2 & 0x10) { LOG("Wrong Cylinder"); continue; }
495 if(st2 & 0x04) { LOG("uPD765 sector not found"); continue; }
496 if(st2 & 0x02) { LOG("Bad Cylinder"); continue; }
499 LOG("Returned BPS = 0x%02x, not 0x02", bps);
504 LOG("Floppy not writable");
505 // Return error without triggering the attempt count check
506 i = FDD_MAX_READWRITE_ATTEMPTS+1;
515 LOG("Realeasing Spinlock and setting motor to stop");
516 Mutex_Release(&glFDD);
518 if(i == FDD_MAX_READWRITE_ATTEMPTS) {
519 Log_Warning("FDD", "Exceeded %i attempts in %s the disk",
520 FDD_MAX_READWRITE_ATTEMPTS,
521 (Write ? "writing to" : "reading from")
525 // Don't turn the motor off now, wait for a while
526 gFDD_Devices[Disk].timer = Time_CreateTimer(MOTOR_OFF_DELAY, FDD_int_StopMotor, (void*)(tVAddr)Disk);
529 if( i < FDD_MAX_READWRITE_ATTEMPTS ) {
540 * \fn int FDD_ReadSector(Uint32 Disk, Uint64 SectorAddr, void *Buffer)
541 * \brief Read a sector from disk
542 * \todo Make real-hardware safe (account for read errors)
544 int FDD_ReadSector(Uint32 Disk, Uint64 SectorAddr, void *Buffer)
548 ENTER("iDisk XSectorAddr pBuffer", Disk, SectorAddr, Buffer);
550 if( IOCache_Read( gFDD_Devices[Disk].CacheHandle, SectorAddr, Buffer ) == 1 ) {
555 // Pass to general function
556 ret = FDD_int_ReadWriteSector(Disk, SectorAddr, 0, Buffer);
559 IOCache_Add( gFDD_Devices[Disk].CacheHandle, SectorAddr, Buffer );
564 LOG("Reading failed");
571 * \fn int FDD_WriteSector(Uint32 Disk, Uint64 LBA, void *Buffer)
572 * \brief Write a sector to the floppy disk
573 * \note Not Implemented
575 int FDD_WriteSector(Uint32 Disk, Uint64 LBA, void *Buffer)
577 Log_Warning("FDD", "Read Only at the moment");
582 * \fn int FDD_int_SeekTrack(int disk, int track)
583 * \brief Seek disk to selected track
585 int FDD_int_SeekTrack(int disk, int head, int track)
590 base = cPORTBASE[disk>>1];
592 // Check if seeking is needed
593 if(gFDD_Devices[disk].track[head] == track)
597 FDD_int_SendByte(base, CMD_SEEK_TRACK);
598 FDD_int_SendByte(base, (head<<2)|(disk&1));
599 FDD_int_SendByte(base, track); // Send Seek command
601 FDD_SensInt(base, &sr0, &cyl); // Wait for IRQ
602 if((sr0 & 0xF0) != 0x20) {
603 LOG("sr0 = 0x%x", sr0);
604 return 0; //Check Status
606 if(cyl != track) return 0;
608 // Set Track in structure
609 gFDD_Devices[disk].track[head] = track;
611 LOG("Time_Delay(100)");
612 // Wait for Head to settle
619 * \fn int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt)
620 * \brief Get Dimensions of a disk
622 int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt)
658 //Log("1440k - lba=%i(0x%x), *s=%i,*c=%i,*h=%i", lba, lba, *s, *c, *h);
676 * \fn void FDD_IRQHandler(int Num)
677 * \brief Handles IRQ6
679 void FDD_IRQHandler(int Num)
686 * \brief Wait for an IRQ6
688 inline void FDD_WaitIRQ()
691 while(!gbFDD_IrqFired) Threads_Yield();
695 void FDD_SensInt(int base, Uint8 *sr0, Uint8 *cyl)
697 FDD_int_SendByte(base, CMD_SENSE_INTERRUPT);
698 FDD_int_GetByte(base, sr0);
699 FDD_int_GetByte(base, cyl);
703 * void FDD_int_SendByte(int base, char byte)
704 * \brief Sends a command to the controller
706 int FDD_int_SendByte(int base, Uint8 byte)
708 tTime end = now() + 1000; // 1s
710 while( (inb(base + PORT_MAINSTATUS) & 0xC0) != 0x80 && now() < end )
711 Threads_Yield(); //Delay
715 outb(base + PORT_DATA, byte);
716 // Log_Debug("FDD", "FDD_int_SendByte: Sent 0x%02x to 0x%x", byte, base);
721 Log_Warning("FDD", "FDD_int_SendByte: Timeout sending byte 0x%x to base 0x%x", byte, base);
727 * int FDD_int_GetByte(int base, char byte)
728 * \brief Receive data from fdd controller
730 int FDD_int_GetByte(int base, Uint8 *value)
732 tTime end = now() + 1000; // 1s
734 while( (inb(base + PORT_MAINSTATUS) & 0xd0) != 0xd0 && now() < end )
739 Uint8 tmp = inb(base + PORT_DATA);
740 if(value) *value = tmp;
741 // Log_Debug("FDD", "FDD_int_GetByte: Read 0x%02x from 0x%x", *value, base);
746 Log_Warning("FDD", "FDD_int_GetByte: Timeout reading byte from base 0x%x", base);
752 * \brief Recalibrate the specified disk
754 void FDD_Recalibrate(int disk)
756 ENTER("idisk", disk);
758 LOG("Starting Motor");
759 FDD_int_StartMotor(disk);
761 while(gFDD_Devices[disk].motorState == 1) Threads_Yield();
763 LOG("Sending Calibrate Command");
764 FDD_int_SendByte(cPORTBASE[disk>>1], CMD_RECALIBRATE);
765 FDD_int_SendByte(cPORTBASE[disk>>1], disk&1);
767 LOG("Waiting for IRQ");
769 FDD_SensInt(cPORTBASE[disk>>1], NULL, NULL);
771 LOG("Stopping Motor");
772 gFDD_Devices[disk].timer = Time_CreateTimer(MOTOR_OFF_DELAY, FDD_int_StopMotor, (void*)(Uint)disk);
777 * \brief Reconfigure the controller
779 int FDD_Reconfigure(int ID)
781 Uint16 base = cPORTBASE[ID];
785 FDD_int_SendByte(base, CMD_CONFIGURE);
786 FDD_int_SendByte(base, 0);
787 // Implied seek enabled, FIFO Enabled, Drive Polling Disabled, data buffer threshold 8 bytes
788 FDD_int_SendByte(base, (1 << 6) | (0 << 5) | (0 << 4) | 7);
789 FDD_int_SendByte(base, 0); // Precompensation - use default
792 FDD_int_SendByte(base, CMD_LOCK|CMD_FLAG_MULTI_TRACK);
793 FDD_int_GetByte(base, NULL);
800 * \brief Reset the specified FDD controller
802 int FDD_Reset(int id)
804 Uint16 base = cPORTBASE[id];
810 outb(base + PORT_DIGOUTPUT, 0); // Disable FDC
811 // Wait 4 microseconds - or use 1 thread delay
814 outb(base + PORT_DIGOUTPUT, 8|4); // Re-enable FDC (DMA and Enable)
817 outb(base + PORT_DATARATE, 0); // Set data rate to 500K/s
823 LOG("4x SenseInterrupt");
824 FDD_SensInt(base, NULL, NULL);
825 FDD_SensInt(base, NULL, NULL);
826 FDD_SensInt(base, NULL, NULL);
827 FDD_SensInt(base, NULL, NULL);
830 FDD_int_SendByte(base, CMD_SPECIFY); // Step and Head Load Times
831 FDD_int_SendByte(base, 0xDF); // Step Rate Time, Head Unload Time (Nibble each)
832 FDD_int_SendByte(base, 0x02); // Head Load Time >> 1
835 LOG("Recalibrate disks (16x seek)");
837 while(FDD_int_SeekTrack(0, 0, 1) == 0 && retries --); // set track
838 if(retries < 0) LEAVE_RET('i', -1);
841 while(FDD_int_SeekTrack(0, 1, 1) == 0 && retries --); // set track
842 if(retries < 0) LEAVE_RET('i', -1);
844 LOG("Recalibrating Disk");
845 FDD_Recalibrate((id<<1)|0);
846 FDD_Recalibrate((id<<1)|1);
852 * \fn void FDD_int_TimerCallback()
853 * \brief Called by timer
855 void FDD_int_TimerCallback(void *Arg)
857 int disk = (Uint)Arg;
859 if(gFDD_Devices[disk].motorState == 1)
860 gFDD_Devices[disk].motorState = 2;
861 Time_RemoveTimer(gFDD_Devices[disk].timer);
862 gFDD_Devices[disk].timer = -1;
867 * \fn void FDD_int_StartMotor(char disk)
868 * \brief Starts FDD Motor
870 void FDD_int_StartMotor(int disk)
873 state = inb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT );
874 state |= 1 << (4+disk);
875 outb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT, state );
876 gFDD_Devices[disk].motorState = 1;
877 gFDD_Devices[disk].timer = Time_CreateTimer(MOTOR_ON_DELAY, FDD_int_TimerCallback, (void*)(Uint)disk);
881 * \fn void FDD_int_StopMotor(int disk)
882 * \brief Stops FDD Motor
884 void FDD_int_StopMotor(void *Arg)
886 Uint8 state, disk = (Uint)Arg;
887 if( Mutex_IsLocked(&glFDD) ) return ;
888 ENTER("iDisk", disk);
890 state = inb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT );
891 state &= ~( 1 << (4+disk) );
892 outb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT, state );
893 gFDD_Devices[disk].motorState = 0;