Преглед на файлове

Change scsiDiskGetImageNameFromConfig to scsiDiskGetNextImageName.

The goal here is to help support alternate image fetch strategies by making the function responsible for advancing the image, rather than callers manipulating image_index directly.
saybur преди 2 години
родител
ревизия
93dbb9ebd5
променени са 3 файла, в които са добавени 32 реда и са изтрити 14 реда
  1. 1 6
      src/BlueSCSI_cdrom.cpp
  2. 26 5
      src/BlueSCSI_disk.cpp
  3. 5 3
      src/BlueSCSI_disk.h

+ 1 - 6
src/BlueSCSI_cdrom.cpp

@@ -859,14 +859,9 @@ void cdromReinsertFirstImage(image_config_t &img)
 bool cdromSwitchNextImage(image_config_t &img)
 {
     // Check if we have a next image to load, so that drive is closed next time the host asks.
-    img.image_index++;
     char filename[MAX_FILE_PATH];
     int target_idx = img.scsiId & 7;
-    if (!scsiDiskGetImageNameFromConfig(img, filename, sizeof(filename)))
-    {
-        img.image_index = 0;
-        scsiDiskGetImageNameFromConfig(img, filename, sizeof(filename));
-    }
+    scsiDiskGetNextImageName(img, filename, sizeof(filename));
 
 #ifdef ENABLE_AUDIO_OUTPUT
     // if in progress for this device, terminate audio playback immediately (Annex C)

+ 26 - 5
src/BlueSCSI_disk.cpp

@@ -530,19 +530,40 @@ static void scsiDiskLoadConfig(int target_idx, const char *section)
     if (tmp[0]) memcpy(img.serial, tmp, sizeof(img.serial));
 }
 
-// Check if image file name is overridden in config
-bool scsiDiskGetImageNameFromConfig(image_config_t &img, char *buf, size_t buflen)
+int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
 {
     int target_idx = img.scsiId & 7;
 
+    img.image_index++;
+    if (img.image_index > 9)
+    {
+        img.image_index = 0;
+    }
+
     char section[6] = "SCSI0";
     section[4] = '0' + target_idx;
 
     char key[5] = "IMG0";
     key[3] = '0' + img.image_index;
 
-    ini_gets(section, key, "", buf, buflen, CONFIGFILE);
-    return buf[0] != '\0';
+    int ret = ini_gets(section, key, "", buf, buflen, CONFIGFILE);
+    if (buf[0] != '\0')
+    {
+        return ret;
+    }
+    else if (img.image_index > 0)
+    {
+        // there may be more than one image but we've ran out of new ones
+        // wrap back to the first image
+        img.image_index = 9;
+        return scsiDiskGetNextImageName(img, buf, buflen);
+    }
+    else
+    {
+        // images are not defined in config
+        img.image_index = 0;
+        return 0;
+    }
 }
 
 void scsiDiskLoadConfig(int target_idx)
@@ -562,7 +583,7 @@ void scsiDiskLoadConfig(int target_idx)
     // Check if we have image specified by name
     char filename[MAX_FILE_PATH];
     image_config_t &img = g_DiskImages[target_idx];
-    if (scsiDiskGetImageNameFromConfig(img, filename, sizeof(filename)))
+    if (scsiDiskGetNextImageName(img, filename, sizeof(filename)))
     {
         int blocksize = (img.deviceType == S2S_CFG_OPTICAL) ? 2048 : 512;
         log("-- Opening '", filename, "' for id:", target_idx, ", specified in " CONFIGFILE);

+ 5 - 3
src/BlueSCSI_disk.h

@@ -108,9 +108,11 @@ bool scsiDiskActivateRomDrive();
 // Returns true if there is at least one image active
 bool scsiDiskCheckAnyImagesConfigured();
 
-// Check if image file name is overridden in config,
-// including image index for multi-image CD-ROM emulation
-bool scsiDiskGetImageNameFromConfig(image_config_t &img, char *buf, size_t buflen);
+// Gets the next image filename for the target, if configured for multiple
+// images. As a side effect this advances image tracking to the next image.
+// Returns the length of the new image filename, or 0 if the target is not
+// configured for multiple images.
+int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen);
 
 // Get pointer to extended image configuration based on target idx
 image_config_t &scsiDiskGetImageConfig(int target_idx);