Explorar o código

Implement hardware select mode of specific device

On the ZuluSCSI v1.2 there is an option to select ST32430N.
This now loads the specific device vendor nad product strings.
Morio %!s(int64=2) %!d(string=hai) anos
pai
achega
9e3bdc853d

+ 16 - 15
lib/ZuluSCSI_platform_GD32F205/platform_hw_config.cpp

@@ -24,14 +24,10 @@
 #include "platform_hw_config.h"
 #include <ZuluSCSI_config.h>
 #include <ZuluSCSI_log.h>
+#include <ZuluSCSI_settings.h>
 
 HardwareConfig g_hw_config;
 
-S2S_CFG_TYPE hw_config_selected_device()
-{
-    return g_hw_config.device_type();
-};
-
 bool hw_config_is_active()
 {
     return g_hw_config.is_active();
@@ -63,37 +59,40 @@ void HardwareConfig::init_state(bool is_active)
 {
     m_is_active = is_active;
     m_scsi_id = (gpio_input_port_get(DIPSW_SCSI_ID_BIT_PORT) & DIPSW_SCSI_ID_BIT_PINS) >> DIPSW_SCSI_ID_BIT_SHIFT;
+    m_device_preset = DEV_PRESET_NONE;
     logmsg("SCSI ID set via DIP switch to ", m_scsi_id);
-    
+    scsi_device_settings_t &cfg_dev = *g_scsi_settings.getDevice(m_scsi_id);
+
     uint8_t rotary_select = (gpio_input_port_get(DIPROT_DEVICE_SEL_BIT_PORT) & DIPROT_DEVICE_SEL_BIT_PINS) >> DIPROT_DEVICE_SEL_BIT_SHIFT;
     switch (rotary_select)
     {
     case 0:
-        m_device_type = S2S_CFG_FIXED;
+         cfg_dev.deviceType = S2S_CFG_FIXED;
     break;
     case 1:
-        m_device_type = S2S_CFG_OPTICAL;
+        cfg_dev.deviceType = S2S_CFG_OPTICAL;
     break;
     case 2:
-        m_device_type = S2S_CFG_FLOPPY_14MB;
+        cfg_dev.deviceType = S2S_CFG_FLOPPY_14MB;
     break;
     case 3:
-        m_device_type = S2S_CFG_REMOVABLE;
+        cfg_dev.deviceType = S2S_CFG_REMOVABLE;
     break;
     case 4:
-        m_device_type = S2S_CFG_MO;
+        cfg_dev.deviceType = S2S_CFG_MO;
     break;
     case 5:
-        m_device_type = S2S_CFG_FIXED;
+        m_device_preset = DEV_PRESET_ST32430N;
+        cfg_dev.deviceType = S2S_CFG_FIXED;
     break;
     case 6:
-        m_device_type = S2S_CFG_SEQUENTIAL;
+        cfg_dev.deviceType = S2S_CFG_SEQUENTIAL;
     break;
     default:
-        m_device_type = S2S_CFG_FIXED;
+        cfg_dev.deviceType = S2S_CFG_FIXED;
     }
     
-    if (m_device_type == S2S_CFG_OPTICAL)
+    if (cfg_dev.deviceType == S2S_CFG_OPTICAL)
     {
         m_blocksize = DEFAULT_BLOCKSIZE_OPTICAL;
     }
@@ -101,6 +100,8 @@ void HardwareConfig::init_state(bool is_active)
     {
         m_blocksize = RAW_FALLBACK_BLOCKSIZE;
     }
+
+//    initDeviceSettingsPreset(m_scsi_id, m_device_preset);
 }
 
 #endif // ZULUSCSI_HARDWARE_CONFIG

+ 6 - 3
lib/ZuluSCSI_platform_GD32F205/platform_hw_config.h

@@ -26,6 +26,7 @@
 
 #pragma once
 #include <scsi2sd.h>
+#include <ZuluSCSI_settings.h>
 
 // C wrappers
 #ifdef __cplusplus
@@ -54,15 +55,17 @@ public:
     // get the device type
     // @returns the device type
     const S2S_CFG_TYPE& device_type() const {return m_device_type;}
-    const uint8_t& scsi_id()    const {return m_scsi_id;}
-    const bool& is_active()     const {return m_is_active;}
-    const int blocksize()       const {return m_blocksize;}
+    const uint8_t& scsi_id()          const {return m_scsi_id;}
+    const bool& is_active()           const {return m_is_active;}
+    const int blocksize()             const {return m_blocksize;}
+    const scsi_device_preset_t device_preset() const {return m_device_preset;}
 
 protected:
     S2S_CFG_TYPE m_device_type;
     uint8_t m_scsi_id;
     bool m_is_active;
     int m_blocksize;
+    scsi_device_preset_t m_device_preset;
 };
 
 

+ 1 - 2
lib/ZuluSCSI_platform_GD32F205/scsiPhy.cpp

@@ -156,7 +156,7 @@ static void selectPhyMode()
     int oldmode = g_scsi_phy_mode;
 
     // Read overriding setting from configuration file
-    int wanted_mode = getSystemSetting()->phyMode;
+    int wanted_mode = g_scsi_settings.getSystem()->phyMode;
 
     // Default: software GPIO bitbang, available on all revisions
     g_scsi_phy_mode = PHY_MODE_PIO;
@@ -193,7 +193,6 @@ static void selectPhyMode()
     {
         logmsg("SCSI PHY operating mode: ", g_scsi_phy_mode_names[g_scsi_phy_mode]);
     }
-    getSystemSetting()->phyMode = g_scsi_phy_mode;
 }
 
 extern "C" void scsiPhyReset(void)

+ 1 - 2
lib/ZuluSCSI_platform_GD32F450/scsiPhy.cpp

@@ -153,7 +153,7 @@ static void selectPhyMode()
     int default_mode = PHY_MODE_BEST_AVAILABLE;
 
     // Read overriding setting from configuration file
-    int wanted_mode = getSystemSetting()->deviceType;
+    int wanted_mode = getSystemSettings()->deviceType;
 
     // Default: software GPIO bitbang, available on all revisions
     g_scsi_phy_mode = PHY_MODE_PIO;
@@ -190,7 +190,6 @@ static void selectPhyMode()
     {
         logmsg("SCSI PHY operating mode: ", g_scsi_phy_mode_names[g_scsi_phy_mode]);
     }
-    getSystemSetting()->deviceType = g_scsi_phy_mode;
 }
 
 extern "C" void scsiPhyReset(void)

+ 2 - 2
src/ImageBackingStore.cpp

@@ -66,7 +66,7 @@ ImageBackingStore::ImageBackingStore(const char *filename, uint32_t scsi_block_s
         uint32_t sectorCount = SD.card()->sectorCount();
         if (m_endsector >= sectorCount)
         {
-            logmsg("Limiting RAW image mapping to SD card sector count: ", (int)sectorCount);
+            logmsg("---- Limiting RAW image mapping to SD card sector count: ", (int)sectorCount);
             m_endsector = sectorCount - 1;
         }
     }
@@ -114,7 +114,7 @@ ImageBackingStore::ImageBackingStore(const char *filename, uint32_t scsi_block_s
                 // If the drive was formatted using those versions, you may have problems accessing it with newer firmware.
                 // The old behavior can be restored with setting  [SCSI] UseFATAllocSize = 1 in config file.
 
-                if (getSystemSetting()->useFATAllocSize)
+                if (g_scsi_settings.getSystem()->useFATAllocSize)
                 {
                     sectorcount = allocsize;
                 }

+ 1 - 1
src/QuirksCheck.cpp

@@ -85,7 +85,7 @@ static bool isValidMacintoshImage(image_config_t *img)
 static void macQuirksSanityCheck(image_config_t *img)
 {
 
-    if(getDeviceSettings(img->scsiId & 7)->disableMacSanityCheck)
+    if(g_scsi_settings.getDevice(img->scsiId & 7)->disableMacSanityCheck)
     {
         dbgmsg("---- Skipping Mac sanity check due to DisableMacSanityCheck");
         return;

+ 11 - 6
src/ZuluSCSI.cpp

@@ -502,7 +502,6 @@ bool findHDDImages()
         {
           logmsg("-- Loading ROM drive from ", fullname, " for id:", id);
           imageReady = scsiDiskProgramRomDrive(fullname, id, blk, type);
-          
           if (imageReady)
           {
             foundImage = true;
@@ -511,10 +510,9 @@ bool findHDDImages()
         else if(id < NUM_SCSIID && lun < NUM_SCSILUN) {
           logmsg("-- Opening ", fullname, " for id:", id, " lun:", lun);
 
-          const char* devPresetName = getDevicePresetName(id);
-          if (devPresetName[0])
+          if (g_scsi_settings.getDevicePreset(id) != DEV_PRESET_NONE)
           {
-              logmsg("---- Using device preset: ", devPresetName);
+              logmsg("---- Using device preset: ", g_scsi_settings.getDevicePresetName(id));
           }
 
           imageReady = scsiDiskOpenHDDImage(id, fullname, id, lun, blk, type);
@@ -649,11 +647,18 @@ static void reinitSCSI()
   if (g_hw_config.is_active())
   {
     bool success;
+    uint8_t scsiId = g_hw_config.scsi_id();
+    g_scsi_settings.initDevicePreset(scsiId, g_hw_config.device_preset());
+
     logmsg("Direct/Raw mode enabled, using hardware switches for configuration");
-    success = scsiDiskOpenHDDImage(g_hw_config.scsi_id(), "RAW:0:0xFFFFFFFF", g_hw_config.scsi_id(), 0,
+    success = scsiDiskOpenHDDImage(scsiId, "RAW:0:0xFFFFFFFF",scsiId, 0,
                                    g_hw_config.blocksize(), g_hw_config.device_type());
     if (success)
     {
+      if (g_scsi_settings.getDevicePreset(scsiId) != DEV_PRESET_NONE)
+      {
+        logmsg("---- Using device preset: ", g_scsi_settings.getDevicePresetName(scsiId));
+      }
       blinkStatus(BLINK_STATUS_OK);
     }
     delay(250);
@@ -741,7 +746,7 @@ extern "C" void zuluscsi_setup(void)
     
     char presetName[32];
     ini_gets("SCSI", "System", "", presetName, sizeof(presetName), CONFIGFILE);
-    scsi_system_settings_t *cfg = initSystemSetting(presetName);
+    scsi_system_settings_t *cfg = g_scsi_settings.initSystem(presetName);
     int boot_delay_ms = cfg->initPreDelay;
     if (boot_delay_ms > 0)
     {

+ 59 - 36
src/ZuluSCSI_disk.cpp

@@ -225,10 +225,47 @@ void setNameFromImage(image_config_t &img, const char *filename) {
     strncpy(img.prodId, image_name+8, 8);
 }
 
+// Load values for target image configuration from given section if they exist.
+// Otherwise keep current settings.
+static void scsiDiskSetImageConfig(uint8_t target_idx)
+{
+    image_config_t &img = g_DiskImages[target_idx];
+    scsi_system_settings_t *devSys = g_scsi_settings.getSystem();
+    scsi_device_settings_t *devCfg = g_scsi_settings.getDevice(target_idx);
+    img.scsiId = target_idx;
+    memset(img.vendor, 0, sizeof(img.vendor));
+    memset(img.prodId, 0, sizeof(img.prodId));
+    memset(img.revision, 0, sizeof(img.revision));
+    memset(img.serial, 0, sizeof(img.serial));
+
+    img.deviceType = devCfg->deviceType;
+    img.deviceTypeModifier = devCfg->deviceTypeModifier;
+    img.sectorsPerTrack = devCfg->sectorsPerTrack;
+    img.headsPerCylinder = devCfg->headsPerCylinder;
+    img.quirks = devSys->quirks;
+    img.rightAlignStrings = devCfg->rightAlignStrings;
+    img.name_from_image = devCfg->nameFromImage;
+    img.prefetchbytes = devCfg->prefetchBytes;
+    img.reinsert_on_inquiry = devCfg->reinsertOnInquiry;
+    img.reinsert_after_eject = devCfg->reinsertAfterEject;
+    img.ejectButton = devCfg->ejectButton;
+#ifdef ENABLE_AUDIO_OUTPUT
+    uint16_t vol = devCfg->vol;
+    // Set volume on both channels
+    audio_set_volume(target_idx, (vol << 8) | vol);
+#endif
+
+    memcpy(img.vendor, devCfg->vendor, sizeof(img.vendor));
+    memcpy(img.prodId, devCfg->prodId, sizeof(img.prodId));
+    memcpy(img.revision, devCfg->revision, sizeof(img.revision));
+    memcpy(img.serial, devCfg->serial, sizeof(img.serial));
+}
+
 bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int scsi_lun, int blocksize, S2S_CFG_TYPE type)
 {
     image_config_t &img = g_DiskImages[target_idx];
     img.cuesheetfile.close();
+    scsiDiskSetImageConfig(target_idx);
     img.file = ImageBackingStore(filename, blocksize);
 
     if (img.file.isOpen())
@@ -426,42 +463,16 @@ static void scsiDiskCheckDir(char * dir_name, int target_idx, image_config_t* im
     }
 }
 
+
 // Load values for target configuration from given section if they exist.
 // Otherwise keep current settings.
 static void scsiDiskSetConfig(int target_idx)
 {
   
     image_config_t &img = g_DiskImages[target_idx];
-    scsi_system_settings_t *devSys = getSystemSetting();
-    scsi_device_settings_t *devCfg = getDeviceSettings(target_idx);
     img.scsiId = target_idx;
-    memset(img.vendor, 0, sizeof(img.vendor));
-    memset(img.prodId, 0, sizeof(img.prodId));
-    memset(img.revision, 0, sizeof(img.revision));
-    memset(img.serial, 0, sizeof(img.serial));
-
-    img.deviceType = devCfg->deviceType;
-    img.deviceTypeModifier = devCfg->deviceTypeModifier;
-    img.sectorsPerTrack = devCfg->sectorsPerTrack;
-    img.headsPerCylinder = devCfg->headsPerCylinder;
-    img.quirks = devSys->quirks;
-    img.rightAlignStrings = devCfg->rightAlignStrings;
-    img.name_from_image = devCfg->nameFromImage;
-    img.prefetchbytes = devCfg->prefetchBytes;
-    img.reinsert_on_inquiry = devCfg->reinsertOnInquiry;
-    img.reinsert_after_eject = devCfg->reinsertAfterEject;
-    img.ejectButton = devCfg->ejectButton;
-#ifdef ENABLE_AUDIO_OUTPUT
-    uint16_t vol = devCfg->vol;
-    // Set volume on both channels
-    audio_set_volume(target_idx, (vol << 8) | vol);
-#endif
-
-    memcpy(img.vendor, devCfg->vendor, sizeof(img.vendor));
-    memcpy(img.prodId, devCfg->prodId, sizeof(img.prodId));
-    memcpy(img.revision, devCfg->revision, sizeof(img.revision));
-    memcpy(img.serial, devCfg->serial, sizeof(img.serial));
 
+    scsiDiskSetImageConfig(target_idx);
 
     char section[6] = "SCSI0";
     section[4] += target_idx;
@@ -697,13 +708,26 @@ int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
 void scsiDiskLoadConfig(int target_idx)
 {
     // Get values from system preset, if any
-    char presetName[32];
+    char presetName[32] = {};
 
     // Get values from device preset, if any
     char section[6] = "SCSI0";
     section[4] = '0' + target_idx;
-    ini_gets(section, "Device", "", presetName, sizeof(presetName), CONFIGFILE);
-    initDeviceSettings(target_idx, presetName);
+#ifdef ZULUSCSI_HARDWARE_CONFIG
+    const char *hwDevicePresetName = g_scsi_settings.getDevicePresetName(target_idx);
+    if (g_hw_config.is_active())
+    {
+        if (strlen(hwDevicePresetName) < sizeof(presetName))
+        {
+            strncpy(presetName, hwDevicePresetName, sizeof(presetName) - 1);
+        }
+    }
+    else
+#endif
+    {
+        ini_gets(section, "Device", "", presetName, sizeof(presetName), CONFIGFILE);
+    }
+    g_scsi_settings.initDevicePName(target_idx, presetName);
 
     // Then settings specific to target ID
     scsiDiskSetConfig(target_idx);
@@ -804,7 +828,6 @@ bool scsiDiskCheckAnyNetworkDevicesConfigured()
             return true;
         }
     }
-
     return false;
 }
 
@@ -829,11 +852,11 @@ void s2s_configInit(S2S_BoardCfg* config)
 
     // Get default values from system preset, if any
     ini_gets("SCSI", "System", "", tmp, sizeof(tmp), CONFIGFILE);
-    scsi_system_settings_t *sysCfg = initSystemSetting(tmp);
-    const char* sysPresetName = getSystemPresetName(); 
-    if (sysPresetName[0])
+    scsi_system_settings_t *sysCfg = g_scsi_settings.initSystem(tmp);
+
+    if (g_scsi_settings.getSystemPreset() != SYS_PRESET_NONE)
     {
-        logmsg("Active configuration (using system preset \"", sysPresetName, "\"):");
+        logmsg("Active configuration (using system preset \"", g_scsi_settings.getSystemPresetName(), "\"):");
     }
     else
     {

+ 112 - 74
src/ZuluSCSI_settings.cpp

@@ -20,17 +20,21 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 **/
 
-#include "ZuluSCSI_settings.h"
+
 #include "ZuluSCSI_disk.h"
 #include "ZuluSCSI_audio.h"
 #include "ZuluSCSI_log.h"
 #include "ZuluSCSI_config.h"
+#include "ZuluSCSI_settings.h"
 #include <strings.h>
 #include <minIni.h>
 #include <minIni_cache.h>
 
 // SCSI system and device settings
-static scsi_settings_t scsiSetting;
+ZuluSCSISettings g_scsi_settings;
+
+const char *systemPresetName[] = {"", "Mac", "MacPlus", "MPC3000"};
+const char *devicePresetName[] = {"", "ST32430N"};
 
 // Helper function for case-insensitive string compare
 static bool strequals(const char *a, const char *b)
@@ -79,16 +83,22 @@ static void formatDriveInfoField(char *field, int fieldsize, bool align_right)
     }
 }
 
+const char **ZuluSCSISettings::deviceInitST32430N(uint8_t scsiId)
+{
+    static const char *st32430n[4] = {"SEAGATE", devicePresetName[DEV_PRESET_ST32430N], PLATFORM_REVISION, ""};
+    m_dev[scsiId].deviceType = S2S_CFG_FIXED;
+    m_devPreset[scsiId] = DEV_PRESET_ST32430N;
+    return st32430n;
+}
+
 
-// Set default drive vendor / product info after the image file
-// is loaded and the device type is known.
-static void setDefaultDriveInfo(uint8_t scsiId, const char *presetName)
+void ZuluSCSISettings::setDefaultDriveInfo(uint8_t scsiId, const char *presetName)
 {
     char section[6] = "SCSI0";
     section[4] += scsiId;
 
-    scsi_device_settings_t &cfg = scsiSetting.dev[scsiId];
-    scsi_device_settings_t &cfgDefault = scsiSetting.dev[SCSI_SETTINGS_SYS_IDX];
+    scsi_device_settings_t &cfgDev = m_dev[scsiId];
+    scsi_device_settings_t &cfgDefault = m_dev[SCSI_SETTINGS_SYS_IDX];
 
     static const char *driveinfo_fixed[4]     = DRIVEINFO_FIXED;
     static const char *driveinfo_removable[4] = DRIVEINFO_REMOVABLE;
@@ -108,70 +118,84 @@ static void setDefaultDriveInfo(uint8_t scsiId, const char *presetName)
 
     const char **driveinfo = NULL;
     bool known_preset = false;
-    scsi_system_settings_t& cfgSys = scsiSetting.sys;
+    scsi_system_settings_t& cfgSys = m_sys;
 
-    strncpy(scsiSetting.presetName[scsiId], presetName, sizeof(scsiSetting.presetName[scsiId]));
-    // Make sure string is null terminated
-    scsiSetting.presetName[scsiId][sizeof(scsiSetting.presetName[scsiId])-1] = '\0';
 
-    if (strequals("", presetName))
+#ifdef ZULUSCSI_HARDWARE_CONFIG
+    if (g_hw_config.is_active() && g_hw_config.device_preset() ==  DEV_PRESET_NONE)
     {
         // empty preset, use default
         known_preset = true;
+        m_devPreset[scsiId] = DEV_PRESET_NONE;
     }
-
-    if (strequals("ST32430N", presetName))
+    else if (g_hw_config.is_active() && g_hw_config.device_preset() ==  DEV_PRESET_ST32430N)
     {
-        static const char *st32430n[4] = {"SEAGATE", "STN32F30N", PLATFORM_REVISION, ""};
-        driveinfo = st32430n;
+        driveinfo = deviceInitST32430N(scsiId);
         known_preset = true;
     }
-    else if (cfgSys.quirks == S2S_CFG_QUIRKS_APPLE)
+    else
+#endif //ZULUSCSI_HARDWARE_CONFIG
+    if (strequals(devicePresetName[DEV_PRESET_NONE], presetName))
     {
-        // Use default drive IDs that are recognized by Apple machines
-        switch (cfg.deviceType)
-        {
-            case S2S_CFG_FIXED:         driveinfo = apl_driveinfo_fixed; break;
-            case S2S_CFG_REMOVABLE:     driveinfo = apl_driveinfo_removable; break;
-            case S2S_CFG_OPTICAL:       driveinfo = apl_driveinfo_optical; break;
-            case S2S_CFG_FLOPPY_14MB:   driveinfo = apl_driveinfo_floppy; break;
-            case S2S_CFG_MO:            driveinfo = apl_driveinfo_magopt; break;
-            case S2S_CFG_NETWORK:       driveinfo = apl_driveinfo_network; break;
-            case S2S_CFG_SEQUENTIAL:    driveinfo = apl_driveinfo_tape; break;
-            default:                    driveinfo = apl_driveinfo_fixed; break;
-        }
+        // empty preset, use default
+        known_preset = true;
+        m_devPreset[scsiId] = DEV_PRESET_NONE;
     }
-    else
+    else if (strequals(devicePresetName[DEV_PRESET_ST32430N], presetName))
     {
-        // Generic IDs
-        switch (cfg.deviceType)
-        {
-            case S2S_CFG_FIXED:         driveinfo = driveinfo_fixed; break;
-            case S2S_CFG_REMOVABLE:     driveinfo = driveinfo_removable; break;
-            case S2S_CFG_OPTICAL:       driveinfo = driveinfo_optical; break;
-            case S2S_CFG_FLOPPY_14MB:   driveinfo = driveinfo_floppy; break;
-            case S2S_CFG_MO:            driveinfo = driveinfo_magopt; break;
-            case S2S_CFG_NETWORK:       driveinfo = driveinfo_network; break;
-            case S2S_CFG_SEQUENTIAL:    driveinfo = driveinfo_tape; break;
-            default:                    driveinfo = driveinfo_fixed; break;
-        }
+        driveinfo = deviceInitST32430N(scsiId);
+        known_preset = true;
     }
 
     if (!known_preset)
     {
-        scsiSetting.presetName[scsiId][0] = '\0';
+        m_devPreset[scsiId] = DEV_PRESET_NONE;
         logmsg("Unknown Device preset name ", presetName, ", using default settings");
     }
 
+    if (m_devPreset[scsiId] == DEV_PRESET_NONE)
+    {
+            if (cfgSys.quirks == S2S_CFG_QUIRKS_APPLE)
+        {
+            // Use default drive IDs that are recognized by Apple machines
+            switch (cfgDev.deviceType)
+            {
+                case S2S_CFG_FIXED:         driveinfo = apl_driveinfo_fixed; break;
+                case S2S_CFG_REMOVABLE:     driveinfo = apl_driveinfo_removable; break;
+                case S2S_CFG_OPTICAL:       driveinfo = apl_driveinfo_optical; break;
+                case S2S_CFG_FLOPPY_14MB:   driveinfo = apl_driveinfo_floppy; break;
+                case S2S_CFG_MO:            driveinfo = apl_driveinfo_magopt; break;
+                case S2S_CFG_NETWORK:       driveinfo = apl_driveinfo_network; break;
+                case S2S_CFG_SEQUENTIAL:    driveinfo = apl_driveinfo_tape; break;
+                default:                    driveinfo = apl_driveinfo_fixed; break;
+            }
+        }
+        else
+        {
+            // Generic IDs
+            switch (cfgDev.deviceType)
+            {
+                case S2S_CFG_FIXED:         driveinfo = driveinfo_fixed; break;
+                case S2S_CFG_REMOVABLE:     driveinfo = driveinfo_removable; break;
+                case S2S_CFG_OPTICAL:       driveinfo = driveinfo_optical; break;
+                case S2S_CFG_FLOPPY_14MB:   driveinfo = driveinfo_floppy; break;
+                case S2S_CFG_MO:            driveinfo = driveinfo_magopt; break;
+                case S2S_CFG_NETWORK:       driveinfo = driveinfo_network; break;
+                case S2S_CFG_SEQUENTIAL:    driveinfo = driveinfo_tape; break;
+                default:                    driveinfo = driveinfo_fixed; break;
+            }
+        }
+    }
+
     // If the scsi string has not been set system wide use default scsi string
     if (!cfgDefault.vendor[0] && driveinfo[0][0])
-        strncpy(cfg.vendor, driveinfo[0], sizeof(cfg.vendor));
-    if (!cfgDefault.prodId[0] &&driveinfo[1][0])
-        strncpy(cfg.prodId, driveinfo[1], sizeof(cfg.prodId));
-    if (!cfgDefault.revision[0] &&driveinfo[2][0])
-        strncpy(cfg.revision, driveinfo[2], sizeof(cfg.revision));
-    if (!cfgDefault.serial[0] &&driveinfo[3][0])
-        strncpy(cfg.serial, driveinfo[3], sizeof(cfg.serial));
+        strncpy(cfgDev.vendor, driveinfo[0], sizeof(cfgDev.vendor));
+    if (!cfgDefault.prodId[0] && driveinfo[1][0])
+        strncpy(cfgDev.prodId, driveinfo[1], sizeof(cfgDev.prodId));
+    if (!cfgDefault.revision[0] && driveinfo[2][0])
+        strncpy(cfgDev.revision, driveinfo[2], sizeof(cfgDev.revision));
+    if (!cfgDefault.serial[0] && driveinfo[3][0])
+        strncpy(cfgDev.serial, driveinfo[3], sizeof(cfgDev.serial));
 }
 
 // Read device settings
@@ -226,10 +250,10 @@ static void readIniSCSIDeviceSetting(scsi_device_settings_t &cfg, const char *se
     }
 }
 
-scsi_system_settings_t *initSystemSetting(const char *presetName)
+scsi_system_settings_t *ZuluSCSISettings::initSystem(const char *presetName)
 {
-    scsi_system_settings_t &cfgSys = scsiSetting.sys;
-    scsi_device_settings_t &cfgDev = scsiSetting.dev[SCSI_SETTINGS_SYS_IDX];
+    scsi_system_settings_t &cfgSys = m_sys;
+    scsi_device_settings_t &cfgDev = m_dev[SCSI_SETTINGS_SYS_IDX];
     // This is a hack to figure out if apple quirks is on via a dip switch
     S2S_TargetCfg img;
 
@@ -269,34 +293,32 @@ scsi_system_settings_t *initSystemSetting(const char *presetName)
     cfgDev.disableMacSanityCheck = false;
 
     // System-specific defaults
-    strncpy(scsiSetting.presetName[SCSI_SETTINGS_SYS_IDX],
-            presetName,
-            sizeof(scsiSetting.presetName[SCSI_SETTINGS_SYS_IDX]));
-    // Make sure string is null terminated
-    scsiSetting.presetName[SCSI_SETTINGS_SYS_IDX][sizeof(scsiSetting.presetName[SCSI_SETTINGS_SYS_IDX])-1] = '\0';
 
-    if (strequals(presetName, ""))
+    if (strequals(systemPresetName[SYS_PRESET_NONE], ""))
     {
         // Preset name is empty, use default configuration
+        m_sysPreset = SYS_PRESET_NONE;
     }
-    else if (strequals(presetName, "Mac"))
+    else if (strequals(systemPresetName[SYS_PRESET_MAC], "Mac"))
     {
+        m_sysPreset = SYS_PRESET_MAC;
         cfgSys.quirks = S2S_CFG_QUIRKS_APPLE;
     }
-    else if (strequals(presetName, "MacPlus"))
+    else if (strequals(systemPresetName[SYS_PRESET_MACPLUS], "MacPlus"))
     {
+        m_sysPreset = SYS_PRESET_MACPLUS;
         cfgSys.quirks = S2S_CFG_QUIRKS_APPLE;
         cfgSys.enableSelLatch = true;
         cfgSys.enableSCSI2 = false;
         cfgSys.selectionDelay = 0;
     }
-    else if (strequals(presetName, "MPC3000"))
+    else if (strequals(systemPresetName[SYS_PRESET_MPC3000], "MPC3000"))
     {
         cfgSys.initPreDelay = 600;
     }
     else
     {
-        scsiSetting.presetName[SCSI_SETTINGS_SYS_IDX][0] = '\0';
+        m_sysPreset = SYS_PRESET_NONE;
         logmsg("Unknown System preset name ", presetName, ", using default settings");
     }
 
@@ -327,12 +349,12 @@ scsi_system_settings_t *initSystemSetting(const char *presetName)
     return &cfgSys;
 }
 
-scsi_device_settings_t* initDeviceSettings(uint8_t scsiId, const char *presetName)
+scsi_device_settings_t* ZuluSCSISettings::initDevicePName(uint8_t scsiId, const char *presetName)
 {
-    scsi_device_settings_t& cfg = scsiSetting.dev[scsiId];
+    scsi_device_settings_t& cfg = m_dev[scsiId];
 
     // Write default configuration from system setting initialization
-    memcpy(&cfg, &scsiSetting.dev[SCSI_SETTINGS_SYS_IDX], sizeof(cfg));
+    memcpy(&cfg, &m_dev[SCSI_SETTINGS_SYS_IDX], sizeof(cfg));
     
     char section[6] = "SCSI0";
     section[4] += scsiId;
@@ -370,22 +392,38 @@ scsi_device_settings_t* initDeviceSettings(uint8_t scsiId, const char *presetNam
     return &cfg;
 }
 
-scsi_system_settings_t* getSystemSetting()
+scsi_device_settings_t *ZuluSCSISettings::initDevicePreset(uint8_t scsiId, const scsi_device_preset_t preset)
+{
+    return initDevicePName(scsiId, devicePresetName[preset]);
+}
+
+
+scsi_system_settings_t *ZuluSCSISettings::getSystem()
+{
+    return &m_sys;
+}
+
+scsi_device_settings_t *ZuluSCSISettings::getDevice(uint8_t scsiId)
+{
+    return &m_dev[scsiId];
+}
+
+scsi_system_preset_t ZuluSCSISettings::getSystemPreset()
 {
-    return &scsiSetting.sys;
+    return m_sysPreset;
 }
 
-scsi_device_settings_t *getDeviceSettings(uint8_t scsiId)
+const char* ZuluSCSISettings::getSystemPresetName()
 {
-    return &scsiSetting.dev[scsiId];
+    return systemPresetName[m_sysPreset];
 }
 
-const char* getSystemPresetName()
+scsi_device_preset_t ZuluSCSISettings::getDevicePreset(uint8_t scsiId)
 {
-    return scsiSetting.presetName[SCSI_SETTINGS_SYS_IDX];
+    return m_devPreset[scsiId];
 }
 
-const char* getDevicePresetName(uint8_t scsiId)
+const char* ZuluSCSISettings::getDevicePresetName(uint8_t scsiId)
 {
-    return scsiSetting.presetName[scsiId];
+    return devicePresetName[m_devPreset[scsiId]];
 }

+ 67 - 31
src/ZuluSCSI_settings.h

@@ -20,15 +20,32 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 **/
 #pragma once
+#ifdef __cplusplus
+
 #include <stdint.h>
 
 // Index 8 is the system defaults
 // Index 0-7 represent device settings
 #define SCSI_SETTINGS_SYS_IDX 8
 
+typedef enum
+{
+    SYS_PRESET_NONE = 0,
+    SYS_PRESET_MAC,
+    SYS_PRESET_MACPLUS,
+    SYS_PRESET_MPC3000
+} scsi_system_preset_t;
+
+typedef enum
+{
+    DEV_PRESET_NONE = 0,
+    DEV_PRESET_ST32430N
+} scsi_device_preset_t;
+
+
 // This struct should only have new settings added to the end
 // as it maybe saved and restored directly from flash memory
-struct __attribute__((__packed__)) scsi_system_settings_t 
+typedef struct __attribute__((__packed__)) scsi_system_settings_t
 {
     // Settings for host compatibility 
     uint8_t quirks;
@@ -44,11 +61,11 @@ struct __attribute__((__packed__)) scsi_system_settings_t
     bool mapLunsToIDs;
     bool enableParity;
     bool useFATAllocSize;
-};
+} scsi_system_settings_t;
 
 // This struct should only have new setting added to the end
 // as it maybe saved and restored directly from flash memory
-struct __attribute__((__packed__)) scsi_device_settings_t
+typedef struct __attribute__((__packed__)) scsi_device_settings_t
 {
     // Settings that can be set on all or specific device
     int prefetchBytes;
@@ -69,42 +86,61 @@ struct __attribute__((__packed__)) scsi_device_settings_t
     bool reinsertOnInquiry;
     bool reinsertAfterEject;
     bool disableMacSanityCheck;
-};
+} scsi_device_settings_t;
 
 
-struct scsi_settings_t {
-    // Informative name of the preset configuration, or NULL for defaults
-    // The last presetName is for the System preset name. The rest are for
-    // corresponding SCSI Ids.
-    char presetName[9][32];
+class ZuluSCSISettings
+{
+public:
+    // Initialize settings for all devices with a preset configuration,
+    //  or return the default config if unknown system type.
+    // Then overwrite any settings with those in the CONFIGFILE
+    scsi_system_settings_t *initSystem(const char *presetName);
 
-    // These are setting for host compatibility
-    scsi_system_settings_t sys;
+    // Copy any shared device setting done the initSystemSettings as default settings, 
+    // or return the default config if unknown device type.
+    // Then overwrite any settings with those in the CONFIGFILE
+    scsi_device_settings_t *initDevicePName(uint8_t scsiId, const char *presetName);
+    scsi_device_settings_t *initDevicePreset(uint8_t scsiId, const scsi_device_preset_t preset);
+    // return the system settings struct to read values
+    scsi_system_settings_t *getSystem();
 
-    // The last dev will be copied over the other dev scsi Id for device defaults.
-    // It is set during when the system settings are initialized
-    scsi_device_settings_t dev[9];
-};
+    // return the device settings struct to read values
+    scsi_device_settings_t *getDevice(uint8_t scsiId);
+
+    // return the system preset enum
+    scsi_system_preset_t getSystemPreset();
 
+    // return the system preset name
+    const char* getSystemPresetName();
 
-// Initialize settings for all devices with a preset configuration,
-//  or return the default config if unknown system type.
-// Then overwrite any settings with those in the CONFIGFILE
-scsi_system_settings_t *initSystemSetting(const char *presetName);
+    // return the device preset enum
+    scsi_device_preset_t getDevicePreset(uint8_t scsiId);
 
-// Copy any shared device setting done the initSystemSettings as default settings, 
-// or return the default config if unknown device type.
-// Then overwrite any settings with those in the CONFIGFILE
-scsi_device_settings_t *initDeviceSettings(uint8_t scsiId, const char *presetName);
+    // return the device preset name
+    const char* getDevicePresetName(uint8_t scsiId);
 
-// return the system settings struct to read values
-scsi_system_settings_t *getSystemSetting();
+protected:
+    // Set default drive vendor / product info after the image file
+    // is loaded and the device type is known.
+    void setDefaultDriveInfo(uint8_t scsiId, const char *presetName);
 
-// return the device settings struct to read values
-scsi_device_settings_t *getDeviceSettings(uint8_t scsiId);
+    // Settings for the specific device
+    const char **deviceInitST32430N(uint8_t scsiId);
 
-// return the system preset name
-const char* getSystemPresetName();
+    // Informative name of the preset configuration, or NULL for defaults
+    // The last presetName is for the System preset name. The rest are for
+    // corresponding SCSI Ids.
+    scsi_system_preset_t m_sysPreset;
+    scsi_device_preset_t m_devPreset[8];
+
+    // These are setting for host compatibility
+    scsi_system_settings_t m_sys;
+
+    // The last dev will be copied over the other dev scsi Id for device defaults.
+    // It is set during when the system settings are initialized
+    scsi_device_settings_t m_dev[9];
+} ;
 
-// return the device preset name
-const char* getDevicePresetName(uint8_t scsiId);
+extern ZuluSCSISettings g_scsi_settings;
+#endif // __cplusplus

+ 4 - 0
zuluscsi.ini

@@ -36,6 +36,10 @@
 #InitiatorImageHandling = 0 # 0: skip exisitng images, 1: create new image with incrementing suffix, 2: overwrite exising image
 
 # Settings that can be specified either per-device or for all devices.
+
+# Select a device preset to apply default settings
+# Known systems: "ST32430N"
+#Device = "ST32430N"
 #Vendor = "QUANTUM"
 #Product = "FIREBALL1"
 #Version = "1.0"