Browse Source

Use DIPSW1 to enable Apple quirks mode (#34)

Petteri Aimonen 3 years ago
parent
commit
3ede2e04a8

+ 68 - 0
lib/AzulSCSI_platform_GD32F205/AzulSCSI_platform.cpp

@@ -11,6 +11,7 @@
 extern "C" {
 
 const char *g_azplatform_name = PLATFORM_NAME;
+static bool g_enable_apple_quirks = false;
 
 /*************************/
 /* Timing functions      */
@@ -195,6 +196,12 @@ void azplatform_late_init()
         g_azlog_debug = false;
     }
 
+    if (gpio_input_bit_get(DIP_PORT, DIPSW1_PIN))
+    {
+        azlog("DIPSW1 is ON: enabling Apple quirks by default");
+        g_enable_apple_quirks = true;
+    }
+
     greenpak_load_firmware();
 }
 
@@ -434,6 +441,67 @@ void azplatform_boot_to_main_firmware()
                     "r" (mainprogram_start[1]) : "memory");
 }
 
+/**************************************/
+/* SCSI configuration based on DIPSW1 */
+/**************************************/
+
+void azplatform_config_hook(S2S_TargetCfg *config)
+{
+    if (g_enable_apple_quirks)
+    {
+        if (config->quirks == S2S_CFG_QUIRKS_NONE)
+        {
+            config->quirks = S2S_CFG_QUIRKS_APPLE;
+        }
+
+        if (config->quirks == S2S_CFG_QUIRKS_APPLE)
+        {
+            static const char *driveinfo_fixed[4] = APPLE_DRIVEINFO_FIXED;
+            static const char *driveinfo_removable[4] = APPLE_DRIVEINFO_REMOVABLE;
+            static const char *driveinfo_optical[4] = APPLE_DRIVEINFO_OPTICAL;
+            static const char *driveinfo_floppy[4] = APPLE_DRIVEINFO_FLOPPY;
+            static const char *driveinfo_magopt[4] = APPLE_DRIVEINFO_MAGOPT;
+            static const char *driveinfo_tape[4] = APPLE_DRIVEINFO_TAPE;
+            const char **driveinfo = NULL;
+
+            switch (config->deviceType)
+            {
+                case S2S_CFG_FIXED:         driveinfo = driveinfo_fixed; break;
+                case S2S_CFG_REMOVEABLE:    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_SEQUENTIAL:    driveinfo = driveinfo_tape; break;
+                default:                    driveinfo = driveinfo_fixed; break;
+            }
+
+            if (config->vendor[0] == '\0')
+            {
+                memset(config->vendor, 0, sizeof(config->vendor));
+                strncpy(config->vendor, driveinfo[0], sizeof(config->vendor));
+            }
+
+            if (config->prodId[0] == '\0')
+            {
+                memset(config->prodId, 0, sizeof(config->prodId));
+                strncpy(config->prodId, driveinfo[1], sizeof(config->prodId));
+            }
+
+            if (config->revision[0] == '\0')
+            {
+                memset(config->revision, 0, sizeof(config->revision));
+                strncpy(config->revision, driveinfo[2], sizeof(config->revision));
+            }
+
+            if (config->serial[0] == '\0')
+            {
+                memset(config->serial, 0, sizeof(config->serial));
+                strncpy(config->serial, driveinfo[3], sizeof(config->serial));
+            }
+        }
+    }
+}
+
 /**********************************************/
 /* Mapping from data bytes to GPIO BOP values */
 /**********************************************/

+ 12 - 0
lib/AzulSCSI_platform_GD32F205/AzulSCSI_platform.h

@@ -5,6 +5,7 @@
 
 #include <gd32f20x.h>
 #include <gd32f20x_gpio.h>
+#include <scsi2sd.h>
 #include "AzulSCSI_config.h"
 
 #ifdef __cplusplus
@@ -76,6 +77,17 @@ void azplatform_set_sd_callback(sd_callback_t func, const uint8_t *buffer);
 bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FLASH_PAGE_SIZE]);
 void azplatform_boot_to_main_firmware();
 
+// Configuration customizations based on DIP switch settings
+// When DIPSW1 is on, Apple quirks are enabled by default.
+void azplatform_config_hook(S2S_TargetCfg *config);
+#define AZPLATFORM_CONFIG_HOOK(cfg) azplatform_config_hook(cfg)
+#define APPLE_DRIVEINFO_FIXED     {"AZULSCSI", "APPLE_HDD",         PLATFORM_REVISION, ""}
+#define APPLE_DRIVEINFO_REMOVABLE {"AZULSCSI", "APPLE_REMOVABLE",   PLATFORM_REVISION, ""}
+#define APPLE_DRIVEINFO_OPTICAL   {"AZULSCSI", "APPLE_CD",          PLATFORM_REVISION, ""}
+#define APPLE_DRIVEINFO_FLOPPY    {"AZULSCSI", "APPLE_FLOPPY",      PLATFORM_REVISION, ""}
+#define APPLE_DRIVEINFO_MAGOPT    {"AZULSCSI", "APPLE_MO",          PLATFORM_REVISION, ""}
+#define APPLE_DRIVEINFO_TAPE      {"AZULSCSI", "APPLE_TAPE",        PLATFORM_REVISION, ""}
+
 // Write a single SCSI pin.
 // Example use: SCSI_OUT(ATN, 1) sets SCSI_ATN to low (active) state.
 #define SCSI_OUT(pin, state) \

+ 4 - 0
src/AzulSCSI_disk.cpp

@@ -207,6 +207,10 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
             img.deviceType = S2S_CFG_OPTICAL;
         }
 
+#ifdef AZPLATFORM_CONFIG_HOOK
+        AZPLATFORM_CONFIG_HOOK(&img);
+#endif
+
         setDefaultDriveInfo(target_idx);
 
         return true;