Pārlūkot izejas kodu

Right-align vendor strings for Apple (#34)

Changes:
- Add option RightAlignStrings to config
- Enable it by default if Quirks = 1 (Apple)
- Always preserve leading spaces in vendor / product fields
Petteri Aimonen 3 gadi atpakaļ
vecāks
revīzija
fae92f27ba

+ 1 - 0
azulscsi.ini

@@ -22,6 +22,7 @@ MapLunsToIDs = 0 # For Philips P2000C simulate multiple LUNs
 #TypeModifier = 0  # Affects only INQUIRY response
 #SectorsPerTrack = 63
 #HeadsPerCylinder = 255
+#RightAlignStrings = 0 # Right-align SCSI vendor / product strings, defaults on if Quirks = 1
 
 # Settings can be overriden for individual devices.
 [SCSI2]

+ 1 - 1
lib/AzulSCSI_platform_GD32F205/AzulSCSI_platform.h

@@ -81,7 +81,7 @@ void azplatform_boot_to_main_firmware();
 // 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_FIXED     {"SEAGATE",  "ST225N",            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, ""}

+ 19 - 7
src/AzulSCSI_disk.cpp

@@ -36,6 +36,11 @@ struct image_config_t: public S2S_TargetCfg
     // For CD-ROM drive ejection
     bool ejected;
     uint8_t cdrom_events;
+
+    // Right-align vendor / product type strings (for Apple)
+    // Standard SCSI uses left alignment
+    // This field uses -1 for default when field is not set in .ini
+    int rightAlignStrings;
 };
 
 static image_config_t g_DiskImages[S2S_MAX_TARGETS];
@@ -53,6 +58,7 @@ static void formatDriveInfoField(char *field, int fieldsize, bool align_right)
 {
     if (align_right)
     {
+        // Right align and trim spaces on either side
         int dst = fieldsize - 1;
         for (int src = fieldsize - 1; src >= 0; src--)
         {
@@ -70,15 +76,13 @@ static void formatDriveInfoField(char *field, int fieldsize, bool align_right)
     }
     else
     {
+        // Left align, preserve spaces in case config tries to manually right-align
         int dst = 0;
         for (int src = 0; src < fieldsize; src++)
         {
             char c = field[src];
             if (c < 0x20 || c > 0x7E) c = 0x20;
-            if (c != 0x20 || dst != 0)
-            {
-                field[dst++] = c;
-            }
+            field[dst++] = c;
         }
         while (dst < fieldsize)
         {
@@ -158,9 +162,16 @@ static void setDefaultDriveInfo(int target_idx)
         img.serial[7] = nibble[(sd_sn >>  0) & 0xF];
     }
 
-    formatDriveInfoField(img.vendor, sizeof(img.vendor), false);
-    formatDriveInfoField(img.prodId, sizeof(img.prodId), false);
-    formatDriveInfoField(img.revision, sizeof(img.revision), false);
+    int rightAlign = img.rightAlignStrings;
+    if (rightAlign < 0)
+    {
+        // Default value based on quirks
+        rightAlign = (img.quirks == S2S_CFG_QUIRKS_APPLE);
+    }
+
+    formatDriveInfoField(img.vendor, sizeof(img.vendor), rightAlign);
+    formatDriveInfoField(img.prodId, sizeof(img.prodId), rightAlign);
+    formatDriveInfoField(img.revision, sizeof(img.revision), rightAlign);
     formatDriveInfoField(img.serial, sizeof(img.serial), true);
 }
 
@@ -244,6 +255,7 @@ static void scsiDiskLoadConfig(int target_idx, const char *section)
     img.sectorsPerTrack = ini_getl(section, "SectorsPerTrack", img.sectorsPerTrack, CONFIGFILE);
     img.headsPerCylinder = ini_getl(section, "HeadsPerCylinder", img.headsPerCylinder, CONFIGFILE);
     img.quirks = ini_getl(section, "Quirks", img.quirks, CONFIGFILE);
+    img.rightAlignStrings = ini_getbool(section, "RightAlignStrings", -1, CONFIGFILE);
     
     char tmp[32];
     memset(tmp, 0, sizeof(tmp));