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

Add system presets to set default settings for host platform.

Currently knows "Mac" and "MacPlus".
New presets can be added in ZuluSCSI_presets.cpp.
Petteri Aimonen 2 лет назад
Родитель
Сommit
2b0f3948fe
3 измененных файлов с 122 добавлено и 14 удалено
  1. 34 14
      src/BlueSCSI_disk.cpp
  2. 56 0
      src/BlueSCSI_presets.cpp
  3. 32 0
      src/BlueSCSI_presets.h

+ 34 - 14
src/BlueSCSI_disk.cpp

@@ -9,6 +9,7 @@
 #include "BlueSCSI_disk.h"
 #include "BlueSCSI_log.h"
 #include "BlueSCSI_config.h"
+#include "BlueSCSI_presets.h"
 #include <minIni.h>
 #include <string.h>
 #include <strings.h>
@@ -829,13 +830,18 @@ static void checkDiskGeometryDivisible(image_config_t &img)
 // Set target configuration to default values
 static void scsiDiskConfigDefaults(int target_idx)
 {
+    // Get default values from system preset, if any
+    char presetName[32];
+    ini_gets("SCSI", "System", "", presetName, sizeof(presetName), CONFIGFILE);
+    preset_config_t defaults = getSystemPreset(presetName);
+
     image_config_t &img = g_DiskImages[target_idx];
     img.deviceType = S2S_CFG_FIXED;
-    img.deviceTypeModifier = 0;
-    img.sectorsPerTrack = 63;
-    img.headsPerCylinder = 255;
-    img.quirks = S2S_CFG_QUIRKS_APPLE;
-    img.prefetchbytes = PREFETCH_BUFFER_SIZE;
+    img.deviceTypeModifier = defaults.deviceTypeModifier;
+    img.sectorsPerTrack = defaults.sectorsPerTrack;
+    img.headsPerCylinder = defaults.headsPerCylinder;
+    img.quirks = defaults.quirks;
+    img.prefetchbytes = defaults.prefetchBytes;
     memset(img.vendor, 0, sizeof(img.vendor));
     memset(img.prodId, 0, sizeof(img.prodId));
     memset(img.revision, 0, sizeof(img.revision));
@@ -943,21 +949,35 @@ void s2s_configInit(S2S_BoardCfg* config)
         log("Config file " CONFIGFILE " not found, using defaults");
     }
 
+    // Get default values from system preset, if any
+    char presetName[32];
+    ini_gets("SCSI", "System", "", presetName, sizeof(presetName), CONFIGFILE);
+    preset_config_t defaults = getSystemPreset(presetName);
+
+    if (defaults.presetName)
+    {
+        log("Active configuration (using system preset \"", defaults.presetName, "\"):");
+    }
+    else
+    {
+        log("Active configuration:");
+    }
+
     memset(config, 0, sizeof(S2S_BoardCfg));
     memcpy(config->magic, "BCFG", 4);
     config->flags = 0;
     config->startupDelay = 0;
-    config->selectionDelay = ini_getl("SCSI", "SelectionDelay", 255, CONFIGFILE);
+    config->selectionDelay = ini_getl("SCSI", "SelectionDelay", defaults.selectionDelay, CONFIGFILE);
     config->flags6 = 0;
     config->scsiSpeed = PLATFORM_MAX_SCSI_SPEED;
 
-    int maxSyncSpeed = ini_getl("SCSI", "MaxSyncSpeed", 10, CONFIGFILE);
+    int maxSyncSpeed = ini_getl("SCSI", "MaxSyncSpeed", defaults.maxSyncSpeed, CONFIGFILE);
     if (maxSyncSpeed < 5 && config->scsiSpeed > S2S_CFG_SPEED_ASYNC_50)
         config->scsiSpeed = S2S_CFG_SPEED_ASYNC_50;
     else if (maxSyncSpeed < 10 && config->scsiSpeed > S2S_CFG_SPEED_SYNC_5)
         config->scsiSpeed = S2S_CFG_SPEED_SYNC_5;
 
-    if ((int)config->selectionDelay == 255)
+    if ((int)config->selectionDelay == defaults.selectionDelay)
     {
         debuglog("-- SelectionDelay: ", (int)config->selectionDelay);
     }
@@ -966,7 +986,7 @@ void s2s_configInit(S2S_BoardCfg* config)
         log("-- SelectionDelay: ", (int)config->selectionDelay);
     }
 
-    if (ini_getbool("SCSI", "EnableUnitAttention", false, CONFIGFILE))
+    if (ini_getbool("SCSI", "EnableUnitAttention", defaults.enableUnitAttention, CONFIGFILE))
     {
         log("-- EnableUnitAttention is on");
         config->flags |= S2S_CFG_ENABLE_UNIT_ATTENTION;
@@ -976,7 +996,7 @@ void s2s_configInit(S2S_BoardCfg* config)
         debuglog("-- EnableUnitAttention is off");
     }
 
-    if (ini_getbool("SCSI", "EnableSCSI2", true, CONFIGFILE))
+    if (ini_getbool("SCSI", "EnableSCSI2", defaults.enableSCSI2, CONFIGFILE))
     {
         debuglog("-- EnableSCSI2 is on");
         config->flags |= S2S_CFG_ENABLE_SCSI2;
@@ -986,7 +1006,7 @@ void s2s_configInit(S2S_BoardCfg* config)
         log("-- EnableSCSI2 is off");
     }
 
-    if (ini_getbool("SCSI", "EnableSelLatch", false, CONFIGFILE))
+    if (ini_getbool("SCSI", "EnableSelLatch", defaults.enableSelLatch, CONFIGFILE))
     {
         log("-- EnableSelLatch is on");
         config->flags |= S2S_CFG_ENABLE_SEL_LATCH;
@@ -996,7 +1016,7 @@ void s2s_configInit(S2S_BoardCfg* config)
         debuglog("-- EnableSelLatch is off");
     }
 
-    if (ini_getbool("SCSI", "MapLunsToIDs", false, CONFIGFILE))
+    if (ini_getbool("SCSI", "MapLunsToIDs", defaults.mapLunsToIDs, CONFIGFILE))
     {
         log("-- MapLunsToIDs is on");
         config->flags |= S2S_CFG_MAP_LUNS_TO_IDS;
@@ -1011,7 +1031,7 @@ void s2s_configInit(S2S_BoardCfg* config)
         log("-- Debug is enabled");
     }
 
-    if (ini_getbool("SCSI", "Parity", true, CONFIGFILE))
+    if (ini_getbool("SCSI", "Parity", defaults.enableParity, CONFIGFILE))
     {
         debuglog("-- Parity is enabled");
         config->flags |= S2S_CFG_ENABLE_PARITY;
@@ -1021,7 +1041,7 @@ void s2s_configInit(S2S_BoardCfg* config)
         log("-- Parity is disabled");
     }
 
-    if (ini_getbool("SCSI", "ReinsertCDOnInquiry", 0, CONFIGFILE))
+    if (ini_getbool("SCSI", "ReinsertCDOnInquiry", defaults.reinsertOnInquiry, CONFIGFILE))
     {
         log("-- ReinsertCDOnInquiry is enabled");
     }

+ 56 - 0
src/BlueSCSI_presets.cpp

@@ -0,0 +1,56 @@
+#include "BlueSCSI_presets.h"
+#include "BlueSCSI_disk.h"
+#include "BlueSCSI_log.h"
+#include "BlueSCSI_config.h"
+#include <strings.h>
+
+// Helper function for case-insensitive string compare
+static bool strequals(const char *a, const char *b)
+{
+    return strcasecmp(a, b) == 0;
+}
+
+preset_config_t getSystemPreset(const char *presetName)
+{
+    // Default configuration
+    preset_config_t cfg = {};
+    cfg.quirks = S2S_CFG_QUIRKS_APPLE;
+    cfg.deviceTypeModifier = 0;
+    cfg.sectorsPerTrack = 63;
+    cfg.headsPerCylinder = 255;
+    cfg.prefetchBytes = PREFETCH_BUFFER_SIZE;
+
+    cfg.selectionDelay = 255;
+    cfg.maxSyncSpeed = 10;
+    cfg.enableUnitAttention = false;
+    cfg.enableSCSI2 = true;
+    cfg.enableSelLatch = false;
+    cfg.mapLunsToIDs = false;
+    cfg.enableParity = true;
+    cfg.reinsertOnInquiry = false;
+
+    // System-specific defaults
+    if (strequals(presetName, ""))
+    {
+        // Preset name is empty, use default configuration
+    }
+    else if (strequals(presetName, "Generic"))
+    {
+        cfg.presetName = "Generic";
+        cfg.quirks = S2S_CFG_QUIRKS_NONE;
+    }
+    else if (strequals(presetName, "MacPlus"))
+    {
+        cfg.presetName = "MacPlus";
+        cfg.quirks = S2S_CFG_QUIRKS_APPLE;
+        cfg.enableSelLatch = true;
+        cfg.enableSCSI2 = false;
+        cfg.selectionDelay = 0;
+    }
+    else
+    {
+        log("Unknown preset name ", presetName, ", using default settings");
+    }
+
+    return cfg;
+}

+ 32 - 0
src/BlueSCSI_presets.h

@@ -0,0 +1,32 @@
+// Preset configurations for various system types.
+// Set by "System" config option in config ini.
+
+#pragma once
+
+// The settings set here will be used as defaults but
+// can be overridden by the ini file settings.
+struct preset_config_t {
+    // Informative name of the preset configuration, or NULL for defaults
+    const char *presetName;
+
+    // Default settings that apply per SCSI ID
+    int quirks;
+    int deviceTypeModifier;
+    int sectorsPerTrack;
+    int headsPerCylinder;
+    int prefetchBytes;
+    bool rightAlignStrings;
+    bool reinsertOnInquiry;
+
+    // Default settings that apply to all SCSI IDs
+    int selectionDelay;
+    int maxSyncSpeed;
+    bool enableUnitAttention;
+    bool enableSCSI2;
+    bool enableSelLatch;
+    bool mapLunsToIDs;
+    bool enableParity;
+};
+
+// Fetch a preset configuration, or return the default config if unknown system type.
+preset_config_t getSystemPreset(const char *presetName);