Просмотр исходного кода

Fixes hard coded block sizes in multiple locations.
Adds BlockSize ini param and new default bytesPerSector preset.
Fixes #45

Eric Helgeson 2 лет назад
Родитель
Сommit
c8f223cdf3
6 измененных файлов с 55 добавлено и 13 удалено
  1. 1 11
      src/BlueSCSI.cpp
  2. 2 1
      src/BlueSCSI_cdrom.cpp
  3. 41 0
      src/BlueSCSI_config.cpp
  4. 7 0
      src/BlueSCSI_config.h
  5. 3 1
      src/BlueSCSI_disk.cpp
  6. 1 0
      src/BlueSCSI_presets.h

+ 1 - 11
src/BlueSCSI.cpp

@@ -336,17 +336,7 @@ bool findHDDImages()
           }
         }
 
-        // Parse block size (HD00_NNNN)
-        const char *blksize = strchr(name, '_');
-        if (blksize)
-        {
-          int blktmp = strtoul(blksize + 1, NULL, 10);
-          if (blktmp == 256 || blktmp == 512 || blktmp == 1024 ||
-              blktmp == 2048 || blktmp == 4096 || blktmp == 8192)
-          {
-            blk = blktmp;
-          }
-        }
+        blk = getBlockSize(name, id, blk);
 
         // Add the directory name to get the full file path
         char fullname[MAX_FILE_PATH * 2 + 2] = {0};

+ 2 - 1
src/BlueSCSI_cdrom.cpp

@@ -1221,7 +1221,8 @@ bool cdromSwitchNextImage(image_config_t &img)
     {
         log("Switching to next CD-ROM image for ", target_idx, ": ", filename);
         img.file.close();
-        bool status = scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0, 2048);
+        bool status = scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0,
+                                           getBlockSize(filename, target_idx, 2048));
 
         if (status)
         {

+ 41 - 0
src/BlueSCSI_config.cpp

@@ -0,0 +1,41 @@
+/** 
+ * 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;
+}

+ 7 - 0
src/BlueSCSI_config.h

@@ -74,3 +74,10 @@
 #ifndef PREFETCH_BUFFER_SIZE
 #define PREFETCH_BUFFER_SIZE 8192
 #endif
+
+/**
+ * @filename - name of the file to be evaluated for block size
+ * @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);

+ 3 - 1
src/BlueSCSI_disk.cpp

@@ -497,6 +497,7 @@ static void scsiDiskConfigDefaults(int target_idx)
     img.deviceTypeModifier = defaults.deviceTypeModifier;
     img.sectorsPerTrack = defaults.sectorsPerTrack;
     img.headsPerCylinder = defaults.headsPerCylinder;
+    img.bytesPerSector = defaults.bytesPerSector;
     img.quirks = defaults.quirks;
     img.prefetchbytes = defaults.prefetchBytes;
     img.reinsert_on_inquiry = false;
@@ -516,6 +517,7 @@ static void scsiDiskLoadConfig(int target_idx, const char *section)
     img.deviceTypeModifier = ini_getl(section, "TypeModifier", img.deviceTypeModifier, CONFIGFILE);
     img.sectorsPerTrack = ini_getl(section, "SectorsPerTrack", img.sectorsPerTrack, CONFIGFILE);
     img.headsPerCylinder = ini_getl(section, "HeadsPerCylinder", img.headsPerCylinder, CONFIGFILE);
+    img.bytesPerSector = ini_getl(section, "BlockSize", img.bytesPerSector, CONFIGFILE);
     img.quirks = ini_getl(section, "Quirks", img.quirks, CONFIGFILE);
     img.rightAlignStrings = ini_getbool(section, "RightAlignStrings", 0, CONFIGFILE);
     img.prefetchbytes = ini_getl(section, "PrefetchBytes", img.prefetchbytes, CONFIGFILE);
@@ -726,7 +728,7 @@ void scsiDiskLoadConfig(int target_idx)
     img.image_index = IMAGE_INDEX_MAX;
     if (scsiDiskGetNextImageName(img, filename, sizeof(filename)))
     {
-        int blocksize = (img.deviceType == S2S_CFG_OPTICAL) ? 2048 : 512;
+        int blocksize = getBlockSize(filename, target_idx, (img.deviceType == S2S_CFG_OPTICAL) ? 2048 : 512);
         log("-- Opening '", filename, "' for id:", target_idx, ", specified in " CONFIGFILE);
         scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0, blocksize);
     }

+ 1 - 0
src/BlueSCSI_presets.h

@@ -14,6 +14,7 @@ struct preset_config_t {
     int deviceTypeModifier;
     int sectorsPerTrack;
     int headsPerCylinder;
+    int bytesPerSector;
     int prefetchBytes;
     bool rightAlignStrings;
     bool reinsertOnInquiry;