Преглед изворни кода

Simplify CD Image swtiching

Eric Helgeson пре 2 година
родитељ
комит
13901a66fa
4 измењених фајлова са 45 додато и 53 уклоњено
  1. 6 51
      src/BlueSCSI_Toolbox.cpp
  2. 34 0
      src/BlueSCSI_cdrom.cpp
  3. 4 1
      src/BlueSCSI_cdrom.h
  4. 1 1
      src/BlueSCSI_disk.cpp

+ 6 - 51
src/BlueSCSI_Toolbox.cpp

@@ -18,6 +18,7 @@
 **/
 #include "BlueSCSI_Toolbox.h"
 #include "BlueSCSI_disk.h"
+#include "BlueSCSI_cdrom.h"
 #include "BlueSCSI_log.h"
 #include <minIni.h>
 #include <SdFat.h>
@@ -46,7 +47,7 @@ static void doCountFiles(const char * dir_name)
         file.getName(name, 32 + 1);
         file.close();
         // only count valid files.
-        if(name[0] != '.')
+        if(!scsiDiskFilenameValid(name))
         {
             file_count = file_count + 1;
             if(file_count > 100) {
@@ -81,7 +82,7 @@ void onListFiles(const char * dir_name) {
         file.getName(name, MAX_MAC_PATH + 1);
         uint64_t size = file.fileSize();
         file.close();
-        if(name[0] == '.')
+        if(!scsiDiskFilenameValid(name))
             continue;
         file_entry[0] = index;
         file_entry[1] = isDir;
@@ -120,9 +121,9 @@ File get_file_from_index(uint8_t index, const char * dir_name)
       file_test.close();
       break;
     }
-    file_test.getName(name, 32 + 1);
+    file_test.getName(name, MAX_MAC_PATH + 1);
 
-    if(name[0] == '.')
+    if(!scsiDiskFilenameValid(name))
       continue;
     if (count == index)
     {
@@ -166,59 +167,13 @@ void onSetNextCD()
 
     uint8_t file_index = scsiDev.cdb[1];
     uint8_t cd_scsi_id = scsiDev.cdb[2];
-    char section[6] = "SCSI0";
-    char key[5] = "IMG0";
-    section[4] = '0' + cd_scsi_id;
 
     image_config_t &img = *(image_config_t*)scsiDev.target->cfg;
-    debuglog("img.image_index: ", img.image_index);
-    int next_image_id = img.image_index + 1;
-
-    if(img.image_index == 0)
-    { // have to check if we have a 0, if not set the current image to 0 so we can cycle back.
-        ini_gets(section, key, "", name, sizeof(name), CONFIGFILE);
-        if(strlen(name) == 0)
-        {
-            img.file.getName(name, MAX_FILE_PATH);
-            log("Nothing in IMG0, so put the current image in it: ", name);
-            ini_puts(section, key, name, CONFIGFILE);
-        }
-        else
-        {
-            log("Something  in IMG0: ", name);
-        }
-    }
-
-    debuglog("next_image_id: ", next_image_id);
-    if(next_image_id > 9)
-        next_image_id = 0;
-
-    key[3] = '0' + next_image_id;
     File next_cd = get_file_from_index(file_index, CD_IMG_DIR);
-    if(!next_cd.isFile())
-    {
-        log("not a file?");
-        next_cd.close();
-        scsiDev.status = CHECK_CONDITION;
-        scsiDev.target->sense.code = ILLEGAL_REQUEST;
-        //SCSI_ASC_INVALID_FIELD_IN_CDB
-        scsiDev.phase = STATUS;
-        return;
-    }
     next_cd.getName(name, sizeof(name));
     next_cd.close();
     snprintf(full_path, (MAX_FILE_PATH * 2), "%s/%s", CD_IMG_DIR, name);
-    debuglog("full_path: ", full_path);
-    debuglog("key: ", key, " section: ", section);
-    // If file doesnt exist, ini_puts() will create it.
-    if(!ini_puts(section, key, full_path, CONFIGFILE))
-    {
-        scsiDev.status = CHECK_CONDITION;
-        scsiDev.target->sense.code = ILLEGAL_REQUEST;
-        //SCSI_ASC_INVALID_FIELD_IN_CDB
-        scsiDev.phase = STATUS;
-        return;
-    }
+    cdromSwitch(img, full_path);
 }
 
 File gFile; // global so we can keep it open while transfering.

+ 34 - 0
src/BlueSCSI_cdrom.cpp

@@ -1239,6 +1239,40 @@ bool cdromSwitchNextImage(image_config_t &img)
     return false;
 }
 
+// Check if we have multiple CD-ROM images to cycle when drive is ejected.
+bool cdromSwitch(image_config_t &img, const char* filename)
+{
+    // Check if we have a next image to load, so that drive is closed next time the host asks.
+    int target_idx = img.scsiId & S2S_CFG_TARGET_ID_BITS;
+
+#ifdef ENABLE_AUDIO_OUTPUT
+    // if in progress for this device, terminate audio playback immediately (Annex C)
+    audio_stop(target_idx);
+    // Reset position tracking for the new image
+    audio_get_status_code(target_idx); // trash audio status code
+#endif
+
+    if (filename[0] != '\0')
+    {
+        log("Switching to next CD-ROM image for ", target_idx, ": ", filename);
+        img.file.close();
+        bool status = scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0, 2048);
+
+        if (status)
+        {
+            img.ejected = false;
+            img.cdrom_events = 2; // New media
+            return true;
+        }
+    }
+    else
+    {
+        log("Could not switch to CD-ROM image as provide filename was empty.");
+    }
+
+    return false;
+}
+
 static void doGetEventStatusNotification(bool immed)
 {
     image_config_t &img = *(image_config_t*)scsiDev.target->cfg;

+ 4 - 1
src/BlueSCSI_cdrom.h

@@ -31,4 +31,7 @@ bool cdromValidateCueSheet(image_config_t &img);
 // Audio playback status
 // boolean flag is true if just basic mechanism status (playback true/false)
 // is desired, or false if historical audio status codes should be returned
-void cdromGetAudioPlaybackStatus(uint8_t *status, uint32_t *current_lba, bool current_only);
+void cdromGetAudioPlaybackStatus(uint8_t *status, uint32_t *current_lba, bool current_only);
+
+// switch to a given filename for the cd.
+bool cdromSwitch(image_config_t &img, const char* filename);

+ 1 - 1
src/BlueSCSI_disk.cpp

@@ -506,7 +506,7 @@ bool scsiDiskFilenameValid(const char* name)
         {
             if (strcasecmp(extension, ignore_exts[i]) == 0)
             {
-                // ignore these without log message
+                debuglog("-- Ignoring compressed file ", name);
                 return false;
             }
         }