Browse Source

Switch CD-ROM image on ejection, not on insertion

This makes for more consistent behavior when eject button is used.
It doesn't matter what way the drive is opened or closed, the image
is always switched when the tray is ejected.
Petteri Aimonen 2 years ago
parent
commit
db5640fa54
3 changed files with 26 additions and 18 deletions
  1. 20 16
      src/BlueSCSI_cdrom.cpp
  2. 5 1
      src/BlueSCSI_cdrom.h
  3. 1 1
      src/BlueSCSI_disk.cpp

+ 20 - 16
src/BlueSCSI_cdrom.cpp

@@ -1149,6 +1149,20 @@ bool cdromValidateCueSheet(image_config_t &img)
 /* Ejection and image switching logic */
 /* Ejection and image switching logic */
 /**************************************/
 /**************************************/
 
 
+// Close CDROM tray and note media change event
+void cdromCloseTray(image_config_t &img)
+{
+    if (img.ejected)
+    {
+        uint8_t target = img.scsiId & 7;
+        debuglog("------ CDROM close tray on ID ", (int)target);
+        img.ejected = false;
+        img.cdrom_events = 2; // New media
+    }
+}
+
+// Eject CDROM tray if closed, close if open
+// Switch image on ejection.
 void cdromPerformEject(image_config_t &img)
 void cdromPerformEject(image_config_t &img)
 {
 {
     uint8_t target = img.scsiId & 7;
     uint8_t target = img.scsiId & 7;
@@ -1161,16 +1175,11 @@ void cdromPerformEject(image_config_t &img)
         debuglog("------ CDROM open tray on ID ", (int)target);
         debuglog("------ CDROM open tray on ID ", (int)target);
         img.ejected = true;
         img.ejected = true;
         img.cdrom_events = 3; // Media removal
         img.cdrom_events = 3; // Media removal
+        cdromSwitchNextImage(img); // Switch media for next time
     }
     }
     else
     else
     {
     {
-        debuglog("------ CDROM close tray on ID ", (int)target);
-        if (!cdromSwitchNextImage(img))
-        {
-            // Reinsert the single image
-            img.ejected = false;
-            img.cdrom_events = 2; // New media
-        }
+        cdromCloseTray(img);
     }
     }
 }
 }
 
 
@@ -1189,9 +1198,7 @@ void cdromReinsertFirstImage(image_config_t &img)
     else if (img.ejected)
     else if (img.ejected)
     {
     {
         // Reinsert the single image
         // Reinsert the single image
-        debuglog("---- Closing CD-ROM tray");
-        img.ejected = false;
-        img.cdrom_events = 2; // New media
+        cdromCloseTray(img);
     }
     }
 }
 }
 
 
@@ -1218,8 +1225,6 @@ bool cdromSwitchNextImage(image_config_t &img)
 
 
         if (status)
         if (status)
         {
         {
-            img.ejected = false;
-            img.cdrom_events = 2; // New media
             return true;
             return true;
         }
         }
     }
     }
@@ -1257,7 +1262,7 @@ static void doGetEventStatusNotification(bool immed)
         {
         {
             // We are now reporting to host that the drive is open.
             // We are now reporting to host that the drive is open.
             // Simulate a "close" for next time the host polls.
             // Simulate a "close" for next time the host polls.
-            cdromSwitchNextImage(img);
+            cdromCloseTray(img);
         }
         }
     }
     }
     else
     else
@@ -1851,12 +1856,11 @@ extern "C" int scsiCDRomCommand()
             int start = scsiDev.cdb[4] & 1;
             int start = scsiDev.cdb[4] & 1;
             if (start)
             if (start)
             {
             {
-                debuglog("------ CDROM close tray on ID ", (int)(img.scsiId & 7));
-                img.ejected = false;
-                img.cdrom_events = 2; // New media
+                cdromCloseTray(img);
             }
             }
             else
             else
             {
             {
+                // Eject and switch image
                 cdromPerformEject(img);
                 cdromPerformEject(img);
             }
             }
         }
         }

+ 5 - 1
src/BlueSCSI_cdrom.h

@@ -11,7 +11,11 @@
 // Called by scsi.c from SCSI2SD
 // Called by scsi.c from SCSI2SD
 extern "C" int scsiCDRomCommand(void);
 extern "C" int scsiCDRomCommand(void);
 
 
-// Eject the given CD-ROM
+// Close CDROM tray and note media change event
+void cdromCloseTray(image_config_t &img);
+
+// Eject CDROM tray if closed, close if open
+// Switch image on ejection.
 void cdromPerformEject(image_config_t &img);
 void cdromPerformEject(image_config_t &img);
 
 
 // Reinsert ejected CD-ROM and restart from first image
 // Reinsert ejected CD-ROM and restart from first image

+ 1 - 1
src/BlueSCSI_disk.cpp

@@ -1120,7 +1120,7 @@ static int doTestUnitReady()
         {
         {
             // We are now reporting to host that the drive is open.
             // We are now reporting to host that the drive is open.
             // Simulate a "close" for next time the host polls.
             // Simulate a "close" for next time the host polls.
-            cdromSwitchNextImage(img);
+            cdromCloseTray(img);
         }
         }
     }
     }
     else if (unlikely(!(blockDev.state & DISK_PRESENT)))
     else if (unlikely(!(blockDev.state & DISK_PRESENT)))