Selaa lähdekoodia

BlueSCSI users expect things to be configured by convention not by
lines in ini files. This change allows users to create two types of
ImgDirs for CD or HD images by adding images to a folder at the
root of the image named /CDX/, or /HDX/ (X being the scsi id).
Images will be cycled through when ejected.

Also cleaned up line endings and log messages to be consistant.
Continued moving config to central location.

Eric Helgeson 2 vuotta sitten
vanhempi
sitoutus
dd12606728
4 muutettua tiedostoa jossa 105 lisäystä ja 59 poistoa
  1. 1 1
      src/BlueSCSI_cdrom.cpp
  2. 64 41
      src/BlueSCSI_config.cpp
  3. 5 1
      src/BlueSCSI_config.h
  4. 35 16
      src/BlueSCSI_disk.cpp

+ 1 - 1
src/BlueSCSI_cdrom.cpp

@@ -1219,7 +1219,7 @@ bool cdromSwitchNextImage(image_config_t &img)
 
     if (filename[0] != '\0')
     {
-        log("Switching to next CD-ROM image for ", target_idx, ": ", filename);
+        log("Switching to next CD-ROM image for SCSI ID: ", target_idx, ": ", filename);
         img.file.close();
         bool status = scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0,
                                            getBlockSize(filename, target_idx, 2048));

+ 64 - 41
src/BlueSCSI_config.cpp

@@ -1,41 +1,64 @@
-/** 
- * Copyright (C) 2023 Eric Helgeson
- * 
- * This file is part of BlueSCSI
- * 
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version. 
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details. 
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
-**/
-
-#include "minIni.h"
-#include "BlueSCSI_config.h"
-
-int getBlockSize(char *filename, int scsiId, int default_size)
-{
-  char section[6] = "SCSI0";
-  section[4] = '0' + scsiId;
-
-  default_size = ini_getl(section, "BlockSize", default_size, CONFIGFILE);
-  // Parse block size (HD00_NNNN)
-  const char *blksize = strchr(filename, '_');
-  if (blksize)
-  {
-    int blktmp = strtoul(blksize + 1, NULL, 10);
-    if (blktmp == 256 || blktmp == 512 || blktmp == 1024 ||
-        blktmp == 2048 || blktmp == 4096 || blktmp == 8192)
-    {
-      return blktmp;
-    }
-  }
-  return default_size;
-}
+/** 
+ * Copyright (C) 2023 Eric Helgeson
+ * 
+ * This file is part of BlueSCSI
+ * 
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version. 
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+**/
+
+#include "minIni.h"
+#include "BlueSCSI_config.h"
+
+int getBlockSize(char *filename, int scsiId, int default_size)
+{
+  char section[6] = "SCSI0";
+  section[4] = '0' + scsiId;
+
+  default_size = ini_getl(section, "BlockSize", default_size, CONFIGFILE);
+  // Parse block size (HD00_NNNN)
+  const char *blksize = strchr(filename, '_');
+  if (blksize)
+  {
+    int blktmp = strtoul(blksize + 1, NULL, 10);
+    if (blktmp == 256 || blktmp == 512 || blktmp == 1024 ||
+        blktmp == 2048 || blktmp == 4096 || blktmp == 8192)
+    {
+      return blktmp;
+    }
+  }
+  return default_size;
+}
+
+int getImgDir(int scsiId, char* dirname)
+{
+  char section[6] = "SCSI0";
+  section[4] = '0' + scsiId;
+
+  char key[] = "ImgDir";
+  int dirlen = ini_gets(section, key, "", dirname, sizeof(dirname), CONFIGFILE);
+  return dirlen;
+}
+
+
+int getImg(int scsiId, int img_index, char* filename)
+{
+  char section[6] = "SCSI0";
+  section[4] = '0' + scsiId;
+
+  char key[] = "IMG0";
+  key[3] = '0' + img_index;
+
+  int dirlen = ini_gets(section, key, "", filename, sizeof(filename), CONFIGFILE);
+  return dirlen;
+}

+ 5 - 1
src/BlueSCSI_config.h

@@ -80,4 +80,8 @@
  * @scsiId - ID of the device we're looking to get the block size for
  * @default_size - if block size cant be determined use this value
 */
-int getBlockSize(char *filename, int scsiId, int default_size);
+int getBlockSize(char *filename, int scsiId, int default_size);
+
+int getImgDir(int scsiId, char* dirname);
+
+int getImg(int scsiId, int img_index, char* filename);

+ 35 - 16
src/BlueSCSI_disk.cpp

@@ -545,11 +545,30 @@ static void scsiDiskLoadConfig(int target_idx, const char *section)
     if (strlen(section) == 5 && strncmp(section, "SCSI", 4) == 0) // allow within target [SCSIx] blocks only
     {
         ini_gets(section, "ImgDir", "", tmp, sizeof(tmp), CONFIGFILE);
+        getImgDir(target_idx, tmp);
         if (tmp[0])
         {
             log("-- SCSI", target_idx, " using image directory \'", tmp, "'");
             img.image_directory = true;
         }
+        else
+        {
+            strcpy(tmp, "CDX");
+            tmp[2] = '0' + target_idx;
+            if(SD.exists(tmp))
+            {
+                log("-- SCSI ID: ", target_idx, " using Optical image directory \'", tmp, "'");
+                img.deviceType = S2S_CFG_OPTICAL;
+                img.image_directory = true;
+            }
+            strcpy(tmp, "HDX");
+            tmp[2] = '0' + target_idx;
+            if(SD.exists(tmp))
+            {
+                log("-- SCSI ID: ", target_idx, " using Drive image directory \'", tmp, "'");
+                img.image_directory = true;
+            }
+        }
     }
 }
 
@@ -563,7 +582,7 @@ static int findNextImageAfter(image_config_t &img,
     FsFile dir;
     if (dirname[0] == '\0')
     {
-        log("Image directory name invalid for ID", (img.scsiId & 7));
+        log("Image directory name invalid for ID", (img.scsiId & S2S_CFG_TARGET_ID_BITS));
         return 0;
     }
     if (!dir.open(dirname))
@@ -631,10 +650,7 @@ static int findNextImageAfter(image_config_t &img,
 
 int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
 {
-    int target_idx = img.scsiId & 7;
-
-    char section[6] = "SCSI0";
-    section[4] = '0' + target_idx;
+    int target_idx = img.scsiId & S2S_CFG_TARGET_ID_BITS;
 
     // sanity check: is provided buffer is long enough to store a filename?
     assert(buflen >= MAX_FILE_PATH);
@@ -643,14 +659,20 @@ int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
     {
         // image directory was found during startup
         char dirname[MAX_FILE_PATH];
-        char key[] = "ImgDir";
-        int dirlen = ini_gets(section, key, "", dirname, sizeof(dirname), CONFIGFILE);
+        int dirlen = getImgDir(target_idx, dirname);
         if (!dirlen)
         {
-            // If image_directory set but ImageDir is not, could be used to
-            // indicate an image directory configured via folder structure.
-            // Not implemented, so treat this as equivalent to missing ImageDir
-            return 0;
+            // If image_directory set but ImgDir is not look for an well known ImgDir
+            if(img.deviceType == S2S_CFG_OPTICAL)
+                strcpy(dirname, "CDX");
+            else
+                strcpy(dirname, "HDX");
+            dirname[2] = '0' + target_idx;
+            if(!SD.exists(dirname))
+            {
+                debuglog("ERROR: Looking for ", dirname, " to load images, but was not found.");
+                return 0;
+            }
         }
 
         // find the next filename
@@ -684,10 +706,7 @@ int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
             img.image_index = 0;
         }
 
-        char key[5] = "IMG0";
-        key[3] = '0' + img.image_index;
-
-        int ret = ini_gets(section, key, "", buf, buflen, CONFIGFILE);
+        int ret = getImg(target_idx, img.image_index, buf);
         if (buf[0] != '\0')
         {
             return ret;
@@ -729,7 +748,7 @@ void scsiDiskLoadConfig(int target_idx)
     if (scsiDiskGetNextImageName(img, filename, sizeof(filename)))
     {
         int blocksize = getBlockSize(filename, target_idx, (img.deviceType == S2S_CFG_OPTICAL) ? 2048 : 512);
-        log("-- Opening '", filename, "' for id:", target_idx, ", specified in " CONFIGFILE);
+        log("-- Opening '", filename, "' for ID:", target_idx);
         scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0, blocksize);
     }
 }