--- BasiliskII/src/sony.cpp 1999/10/03 14:16:25 1.1 +++ BasiliskII/src/sony.cpp 2000/07/22 16:07:18 1.8 @@ -1,7 +1,7 @@ /* * sony.cpp - Replacement .Sony driver (floppy drives) * - * Basilisk II (C) 1997-1999 Christian Bauer + * Basilisk II (C) 1997-2000 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,8 +42,10 @@ #define DEBUG 0 #include "debug.h" + +// Check for inserted disks by polling? #ifdef AMIGA -#define DISK_INSERT_CHECK 1 // Check for inserted disks (problem: on most hardware, disks are not ejected and automatically remounted) +#define DISK_INSERT_CHECK 1 #else #define DISK_INSERT_CHECK 0 #endif @@ -123,8 +125,8 @@ static DriveInfo *first_drive_info; uint32 SonyDiskIconAddr; uint32 SonyDriveIconAddr; -// Flag: accRun called for the first time, run PatchAfterStartup() -static bool periodic_first_time = false; +// Flag: Control(accRun) has been called, interrupt routine is now active +static bool acc_run_called = false; /* @@ -216,6 +218,41 @@ bool SonyMountVolume(void *fh) /* + * Mount volumes for which the to_be_mounted flag is set + * (called during interrupt time) + */ + +static void mount_mountable_volumes(void) +{ + DriveInfo *info = first_drive_info; + while (info != NULL) { + +#if DISK_INSERT_CHECK + // Disk in drive? + if (!ReadMacInt8(info->status + dsDiskInPlace)) { + + // No, check if disk was inserted + if (SysIsDiskInserted(info->fh)) + SonyMountVolume(info->fh); + } +#endif + + // Mount disk if flagged + if (info->to_be_mounted) { + D(bug(" mounting drive %d\n", info->num)); + M68kRegisters r; + r.d[0] = info->num; + r.a[0] = 7; // diskEvent + Execute68kTrap(0xa02f, &r); // PostEvent() + info->to_be_mounted = false; + } + + info = info->next; + } +} + + +/* * Driver Open() routine */ @@ -226,7 +263,7 @@ int16 SonyOpen(uint32 pb, uint32 dce) // Set up DCE WriteMacInt32(dce + dCtlPosition, 0); WriteMacInt16(dce + dCtlQHdr + qFlags, ReadMacInt16(dce + dCtlQHdr + qFlags) & 0xff00 | 3); // Version number, must be >=3 or System 8 will replace us - periodic_first_time = true; + acc_run_called = false; // Install driver again with refnum -2 (HD20) uint32 utab = ReadMacInt32(0x11c); @@ -354,38 +391,12 @@ int16 SonyControl(uint32 pb, uint32 dce) case 9: // Track cache return noErr; - case 65: { // Periodic action ("insert" disks on startup and check for disk changes) - DriveInfo *info = first_drive_info; - while (info != NULL) { - - // Disk in drive? - if (!ReadMacInt8(info->status + dsDiskInPlace)) { - -#if DISK_INSERT_CHECK - // No, check if disk was inserted - if (SysIsDiskInserted(info->fh)) - SonyMountVolume(info->fh); -#endif - } - - // Mount disk if flagged - if (info->to_be_mounted) { - D(bug(" mounting drive %d\n", info->num)); - M68kRegisters r; - r.d[0] = info->num; - r.a[0] = 7; // diskEvent - Execute68kTrap(0xa02f, &r); // PostEvent() - info->to_be_mounted = false; - } - - info = info->next; - } - if (periodic_first_time) { - periodic_first_time = false; - PatchAfterStartup(); // Install patches after system startup - } + case 65: // Periodic action (accRun, "insert" disks on startup) + mount_mountable_volumes(); + PatchAfterStartup(); // Install patches after system startup + WriteMacInt16(dce + dCtlFlags, ReadMacInt16(dce + dCtlFlags) & ~0x2000); // Disable periodic action + acc_run_called = true; return noErr; - } } // Drive valid? @@ -438,7 +449,7 @@ int16 SonyControl(uint32 pb, uint32 dce) WriteMacInt32(pb + csParam, 0x0104); // External drive return noErr; - case 'SC': { // Format and write to disk + case 0x5343: { // Format and write to disk ('SC'), used by DiskCopy if (!ReadMacInt8(info->status + dsDiskInPlace)) return offLinErr; if (info->read_only) @@ -485,18 +496,18 @@ int16 SonyStatus(uint32 pb, uint32 dce) return paramErr; case 8: // Get drive status - memcpy(Mac2HostAddr(pb + csParam), Mac2HostAddr(info->status), 22); + Mac2Mac_memcpy(pb + csParam, info->status, 22); return noErr; case 10: // Get disk type WriteMacInt32(pb + csParam, ReadMacInt32(info->status + dsMFMDrive) & 0xffffff00 | 0xfe); return noErr; - case 'DV': // Duplicator version supported + case 0x4456: // Duplicator version supported ('DV') WriteMacInt16(pb + csParam, 0x0410); return noErr; - case 'SC': // Get address header format byte + case 0x5343: // Get address header format byte ('SC') WriteMacInt8(pb + csParam, 0x22); // 512 bytes/sector return noErr; @@ -505,3 +516,16 @@ int16 SonyStatus(uint32 pb, uint32 dce) return statusErr; } } + + +/* + * Driver interrupt routine (1Hz) - check for volumes to be mounted + */ + +void SonyInterrupt(void) +{ + if (!acc_run_called) + return; + + mount_mountable_volumes(); +}