Kaynağa Gözat

scsi: re-work switchNext to work with more than just CD's.

Eric Helgeson 1 yıl önce
ebeveyn
işleme
bfc39368ac

+ 1 - 1
src/BlueSCSI_Toolbox.cpp

@@ -211,7 +211,7 @@ void onSetNextCD(const char * img_dir)
     next_cd.getName(name, sizeof(name));
     next_cd.close();
     snprintf(full_path, (MAX_FILE_PATH * 2), "%s/%s", img_dir, name);
-    cdromSwitchNextImage(img, full_path);
+    switchNextImage(img, full_path);
 }
 
 FsFile gFile; // global so we can keep it open while transferring.

+ 2 - 51
src/BlueSCSI_cdrom.cpp

@@ -1181,7 +1181,7 @@ void cdromPerformEject(image_config_t &img)
         debuglog("------ CDROM open tray on ID ", (int)target);
         img.ejected = true;
         img.cdrom_events = 3; // Media removal
-        cdromSwitchNextImage(img, nullptr); // Switch media for next time
+        switchNextImage(img); // Switch media for next time
     }
     else
     {
@@ -1199,7 +1199,7 @@ void cdromReinsertFirstImage(image_config_t &img)
         debuglog("---- Restarting from first CD-ROM image for ID ", (int)target);
         img.image_index = -1;
         img.current_image[0] = '\0';
-        cdromSwitchNextImage(img, nullptr);
+        switchNextImage(img);
     }
     else if (img.ejected)
     {
@@ -1208,55 +1208,6 @@ void cdromReinsertFirstImage(image_config_t &img)
     }
 }
 
-// Check if we have multiple CD-ROM images to cycle when drive is ejected.
-bool cdromSwitchNextImage(image_config_t &img, const char* next_filename)
-{
-    // Check if we have a next image to load, so that drive is closed next time the host asks.
-    char filename[MAX_FILE_PATH];
-    int target_idx = img.scsiId & S2S_CFG_TARGET_ID_BITS;
-    if (next_filename == nullptr)
-    {
-        scsiDiskGetNextImageName(img, filename, sizeof(filename));
-    }
-    else
-    {
-        strncpy(filename, next_filename, MAX_FILE_PATH);
-    }
-
-    if (filename[0] != '\0')
-    {
-#ifdef ENABLE_AUDIO_OUTPUT
-    // if in progress for this device, terminate audio playback immediately (Annex C)
-    audio_stop(target_idx);
-    // Reset position tracking for the new image
-    audio_get_status_code(target_idx); // trash audio status code
-#endif
-        log("Switching to next CD-ROM image for ", target_idx, ": ", filename);
-        img.file.close();
-        bool status = scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0,
-                                           getBlockSize(filename, target_idx, 2048));
-
-        if (status)
-        {
-            if (next_filename != nullptr)
-            {
-                // present the drive as ejected until the host queries it again,
-                // to make sure host properly detects the media change
-                img.ejected = true;
-                img.reinsert_after_eject = true;
-                img.cdrom_events = 2; // New Media
-            }
-            return true;
-        }
-    }
-    else
-    {
-        log("Could not switch to CD-ROM image as provide filename was empty.");
-    }
-
-    return false;
-}
-
 static void doGetEventStatusNotification(bool immed)
 {
     image_config_t &img = *(image_config_t*)scsiDev.target->cfg;

+ 0 - 3
src/BlueSCSI_cdrom.h

@@ -21,9 +21,6 @@ void cdromPerformEject(image_config_t &img);
 // Reinsert ejected CD-ROM and restart from first image
 void cdromReinsertFirstImage(image_config_t &img);
 
-// Switch to next CD-ROM image if multiple have been configured
-bool cdromSwitchNextImage(image_config_t &img, const char* filename);
-
 // Check if the currently loaded cue sheet for the image can be parsed
 // and print warnings about unsupported track types
 bool cdromValidateCueSheet(image_config_t &img);

+ 46 - 1
src/BlueSCSI_disk.cpp

@@ -762,9 +762,11 @@ int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
         int dirlen = getImgDir(target_idx, dirname);
         if (!dirlen)
         {
-            // If image_directory set but ImgDir is not look for an well known ImgDir
+            // If image_directory set but ImgDir is not look for a well known ImgDir
             if(img.deviceType == S2S_CFG_OPTICAL)
                 strcpy(dirname, "CDX");
+            else if(img.deviceType == S2S_CFG_ZIP100)
+                strcpy(dirname, "ZPX");
             else
                 strcpy(dirname, "HDX");
             dirname[2] = '0' + target_idx;
@@ -853,6 +855,49 @@ void scsiDiskLoadConfig(int target_idx)
     }
 }
 
+// Check if we have multiple drive images to cycle when drive is ejected.
+bool switchNextImage(image_config_t &img, const char* next_filename)
+{
+    // Check if we have a next image to load, so that drive is closed next time the host asks.
+    char filename[MAX_FILE_PATH];
+    int target_idx = img.scsiId & S2S_CFG_TARGET_ID_BITS;
+    if (next_filename == nullptr)
+    {
+        scsiDiskGetNextImageName(img, filename, sizeof(filename));
+    }
+    else
+    {
+        strncpy(filename, next_filename, MAX_FILE_PATH);
+    }
+
+    if (filename[0] != '\0')
+    {
+        log("Switching to next image for ", target_idx, ": ", filename);
+        img.file.close();
+        int block_size = getBlockSize(filename, target_idx, (img.deviceType == S2S_CFG_OPTICAL) ? 2048 : 512);
+        bool status = scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0, block_size);
+
+        if (status)
+        {
+            if (next_filename != nullptr && img.deviceType == S2S_CFG_OPTICAL)
+            {
+                // present the drive as ejected until the host queries it again,
+                // to make sure host properly detects the media change
+                img.ejected = true;
+                img.reinsert_after_eject = true;
+                img.cdrom_events = 2; // New Media
+            }
+            return true;
+        }
+    }
+    else
+    {
+        log("Could not switch to image as provide filename was empty.");
+    }
+
+    return false;
+}
+
 bool scsiDiskCheckAnyImagesConfigured()
 {
     for (int i = 0; i < S2S_MAX_TARGETS; i++)

+ 3 - 0
src/BlueSCSI_disk.h

@@ -143,3 +143,6 @@ void scsiDiskStartWrite(uint32_t lba, uint32_t blocks);
 
 // Returns true if there is at least one network device active
 bool scsiDiskCheckAnyNetworkDevicesConfigured();
+
+// Switch to next Drive image if multiple have been configured
+bool switchNextImage(image_config_t &img, const char* next_filename = nullptr);