Jelajahi Sumber

Fix read capacity/sector size issue

This should fix the issue while keeping multi-bin/cue support.
It should report a sector size of 512 for the issue ticket: https://github.com/ZuluSCSI/ZuluSCSI-firmware/issues/545
Multi-bin/cue file capacity seems to be right on along with ISOs.

Single bin/cue on ZuluSCSI was about 2MB larger the size reported by
PowerCD on an alcohol 120% virtual drive of the same Quake image.
Not sure where the discrepancy is coming from.
J. Morio Sakaguchi 7 bulan lalu
induk
melakukan
4a07ec69e1
3 mengubah file dengan 16 tambahan dan 37 penghapusan
  1. 2 2
      platformio.ini
  2. 7 28
      src/ZuluSCSI_cdrom.cpp
  3. 7 7
      src/ZuluSCSI_disk.cpp

+ 2 - 2
platformio.ini

@@ -1,8 +1,8 @@
 ; PlatformIO Project Configuration File https://docs.platformio.org/page/projectconf.html
 
 [platformio]
-;default_envs = ZuluSCSIv1_0, ZuluSCSIv1_0_mini, ZuluSCSIv1_1_plus, ZuluSCSI_RP2040, ZuluSCSI_RP2040_Audio, ZuluSCSI_Pico, ZuluSCSI_Pico_DaynaPORT, ZuluSCSI_Pico_2, ZuluSCSI_Pico_2_DaynaPORT, ZuluSCSI_Blaster
-default_envs = ZuluSCSI_RP2040
+default_envs = ZuluSCSIv1_0, ZuluSCSIv1_0_mini, ZuluSCSIv1_1_plus, ZuluSCSI_RP2040, ZuluSCSI_RP2040_Audio, ZuluSCSI_Pico, ZuluSCSI_Pico_DaynaPORT, ZuluSCSI_Pico_2, ZuluSCSI_Pico_2_DaynaPORT, ZuluSCSI_Blaster
+
 [env]
 build_flags =
     -DBUILD_ENV=$PIOENV

+ 7 - 28
src/ZuluSCSI_cdrom.cpp

@@ -2020,30 +2020,9 @@ static bool doReadCapacity(uint32_t lba, uint8_t pmi)
 {
     image_config_t &img = *(image_config_t*)scsiDev.target->cfg;
 
-    CUEParser parser;
-    if (!loadCueSheet(img, parser))
-    // uint32_t capacity = img.get_capacity_lba();
-    // if (capacity > 0)
-    {
-        // basic image, let the disk handler resolve
-        return false;
-    }
-
-    // find the last track on the disk
-    CUETrackInfo lasttrack = {0};
-    const CUETrackInfo *trackinfo;
-    uint64_t prev_capacity = 0;
-    while ((trackinfo = parser.next_track(prev_capacity)) != NULL)
+    uint32_t capacity = img.get_capacity_lba();
+    if (capacity > 0)
     {
-        lasttrack = *trackinfo;
-        cdromSelectBinFileForTrack(img, trackinfo);
-        prev_capacity = img.file.size();
-    }
-
-    uint32_t capacity = 0;
-    if (lasttrack.track_number != 0)
-    {
-        capacity = getLeadOutLBA(&lasttrack);
         capacity--; // shift to last addressable LBA
         if (pmi && lba && lba > capacity)
         {
@@ -2057,15 +2036,15 @@ static bool doReadCapacity(uint32_t lba, uint8_t pmi)
     {
         logmsg("WARNING: unable to find capacity of device ID ", (int) 7 & img.scsiId);
     }
-
+    uint32_t bytes_per_sector  = scsiDev.target->liveCfg.bytesPerSector;
     scsiDev.data[0] = capacity >> 24;
     scsiDev.data[1] = capacity >> 16;
     scsiDev.data[2] = capacity >> 8;
     scsiDev.data[3] = capacity;
-    scsiDev.data[4] = 0;
-    scsiDev.data[5] = 0;
-    scsiDev.data[6] = 0x08; // rest of code assumes 2048 here
-    scsiDev.data[7] = 0x00;
+    scsiDev.data[4] = bytes_per_sector >> 24;
+    scsiDev.data[5] = bytes_per_sector >> 16;
+    scsiDev.data[6] = bytes_per_sector >> 8;
+    scsiDev.data[7] = bytes_per_sector;
     scsiDev.dataLen = 8;
     scsiDev.phase = DATA_IN;
     return true;

+ 7 - 7
src/ZuluSCSI_disk.cpp

@@ -212,19 +212,22 @@ uint32_t image_config_t::get_capacity_lba()
                 bin_file.close();
             }
             if (last_track.track_number != 0)
-                return last_track.data_start + prev_capacity / last_track.sector_length;
+                return last_track.data_start  + prev_capacity / last_track.sector_length;
             else
                 return 0;
         }
         else
         {
             // Single bin file
-            track = parser.next_track();
-            return track->data_start + bin_container.size() / track->sector_length;
+            while((track = parser.next_track()) != nullptr)
+            {
+                last_track = *track;
+            }
+            return last_track.track_number == 0 ? 0 : last_track.data_start + (bin_container.size() - last_track.file_offset) / last_track.sector_length;
         }
     }
     else
-        return file.size() / bytesPerSector;
+        return file.size() / scsiDev.target->liveCfg.bytesPerSector;
 
 }
 
@@ -1560,9 +1563,6 @@ static void doReadCapacity()
         scsiDev.data[7] = bytesPerSector;
         scsiDev.dataLen = 8;
         scsiDev.phase = DATA_IN;
-
-        // \todo get rid of me
-        dbgmsg("doReadCapacity - disk.cpp highest block: ", highestBlock, " bytes per sector: ", bytesPerSector);
     }
     else
     {