Эх сурвалжийг харах

Add ReinsertAfterEject config option (defaults to on)

Previously when multiple images have been configured,
the next image has been automatically inserted after ejection.

Now with eject button support, some users may want to reinsert
only after pressing the button again. This config option allows
that.

Default behavior remains as before.

Also improved log messages of ejection button behavior.
Petteri Aimonen 2 жил өмнө
parent
commit
39ff2f7329

+ 17 - 4
src/BlueSCSI_cdrom.cpp

@@ -818,9 +818,22 @@ void cdromPerformEject(image_config_t &img)
     // terminate audio playback if active on this target (MMC-1 Annex C)
     audio_stop(target);
 #endif
-    debuglog("------ CDROM open tray on ID ", (int)target);
-    img.ejected = true;
-    img.cdrom_events = 3; // Media removal
+    if (!img.ejected)
+    {
+        debuglog("------ CDROM open tray on ID ", (int)target);
+        img.ejected = true;
+        img.cdrom_events = 3; // Media removal
+    }
+    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
+        }
+    }
 }
 
 // Reinsert any ejected CDROMs on reboot
@@ -905,7 +918,7 @@ static void doGetEventStatusNotification(bool immed)
         scsiDev.phase = DATA_IN;
         img.cdrom_events = 0;
 
-        if (img.ejected)
+        if (img.ejected && img.reinsert_after_eject)
         {
             // We are now reporting to host that the drive is open.
             // Simulate a "close" for next time the host polls.

+ 15 - 4
src/BlueSCSI_disk.cpp

@@ -466,6 +466,7 @@ static void scsiDiskLoadConfig(int target_idx, const char *section)
     img.rightAlignStrings = ini_getbool(section, "RightAlignStrings", 0, CONFIGFILE);
     img.prefetchbytes = ini_getl(section, "PrefetchBytes", img.prefetchbytes, CONFIGFILE);
     img.reinsert_on_inquiry = ini_getbool(section, "ReinsertCDOnInquiry", 0, CONFIGFILE);
+    img.reinsert_after_eject = ini_getbool(section, "ReinsertAfterEject", 1, CONFIGFILE);
     img.ejectButton = ini_getl(section, "EjectButton", 0, CONFIGFILE);
 
     char tmp[32];
@@ -547,7 +548,7 @@ image_config_t &scsiDiskGetImageConfig(int target_idx)
 
 static void diskEjectAction(uint8_t buttonId)
 {
-    log("Eject button pressed for channel ", buttonId);
+    bool found = false;
     for (uint8_t i = 0; i < S2S_MAX_TARGETS; i++)
     {
         image_config_t &img = g_DiskImages[i];
@@ -555,10 +556,17 @@ static void diskEjectAction(uint8_t buttonId)
         {
             if (img.deviceType == S2S_CFG_OPTICAL)
             {
+                found = true;
+                log("Eject button ", (int)buttonId, " pressed, passing to CD drive SCSI", (int)i);
                 cdromPerformEject(img);
             }
         }
     }
+
+    if (!found)
+    {
+        log("Eject button ", (int)buttonId, " pressed, but no drives with EjectButton=", (int)buttonId, " setting found!");
+    }
 }
 
 uint8_t diskEjectButtonUpdate(bool immediate)
@@ -904,9 +912,12 @@ static int doTestUnitReady()
         scsiDev.target->sense.asc = MEDIUM_NOT_PRESENT;
         scsiDev.phase = STATUS;
 
-        // We are now reporting to host that the drive is open.
-        // Simulate a "close" for next time the host polls.
-        cdromSwitchNextImage(img);
+        if (img.reinsert_after_eject)
+        {
+            // We are now reporting to host that the drive is open.
+            // Simulate a "close" for next time the host polls.
+            cdromSwitchNextImage(img);
+        }
     }
     else if (unlikely(!(blockDev.state & DISK_PRESENT)))
     {

+ 2 - 1
src/BlueSCSI_disk.h

@@ -51,7 +51,8 @@ struct image_config_t: public S2S_TargetCfg
     // For CD-ROM drive ejection
     bool ejected;
     uint8_t cdrom_events;
-    bool reinsert_on_inquiry;
+    bool reinsert_on_inquiry; // Reinsert on Inquiry command (to reinsert automatically after boot)
+    bool reinsert_after_eject; // Reinsert next image after ejection
 
     // selects a physical button channel that will cause an eject action
     // default option of '0' disables this functionality