From f0ca2fba808c8a05c6c6dc421d271301206d0a97 Mon Sep 17 00:00:00 2001 From: Eric Helgeson Date: Wed, 9 Jun 2021 19:28:12 -0500 Subject: [PATCH] Allow for easier use of files - Just define what you know. HD == hard drive - min file name req. * Defaults to SCSI ID 0, LUN 0, 512 block size. HD1 == SCSI ID 1, LUN 0, 512 HD11 == SCSI ID 1, LUN 1, 512 HD11_1024 == SCSI ID 1, LUN 1, 1024 HD System 7.0.1 Apps.dsk == ID 0, LUN 0, 512 * suffix no longer required --- src/BlueSCSI.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/BlueSCSI.cpp b/src/BlueSCSI.cpp index f0d5b8f..c6521b6 100644 --- a/src/BlueSCSI.cpp +++ b/src/BlueSCSI.cpp @@ -427,17 +427,35 @@ void setup() file.close(); String file_name = String(name); file_name.toLowerCase(); - if(file_name.startsWith("hd") && file_name.endsWith(".hda")) { - int id = name[HDIMG_ID_POS] - '0'; - int lun = name[HDIMG_LUN_POS] - '0'; - int blk = name[HDIMG_BLK_POS] - '0'; - if(blk == 2) { - blk = 256; - } else if(blk == 1) { - blk = 1024; - } else { - blk = 512; + if(file_name.startsWith("hd")) { + // Defaults for Hard Disks + int id = 0; + int lun = 0; + int blk = 512; + + // Positionally read in and coerase the chars to integers. + // We only require the minimum and read in the next if provided. + int file_name_length = file_name.length(); + if(file_name_length > 2) // HD[N] + id = name[HDIMG_ID_POS] - '0' || 0; + if(file_name_length > 3) // HD0[N] + lun = name[HDIMG_LUN_POS] - '0' || 0; + int blk1, blk2, blk3, blk4 = 0; + if(file_name_length > 8) { // HD00_[111] + blk1 = name[HDIMG_BLK_POS] - '0'; + blk2 = name[HDIMG_BLK_POS+1] - '0'; + blk3 = name[HDIMG_BLK_POS+2] - '0'; + if(file_name_length > 9) // HD00_NNN[1] + blk4 = name[HDIMG_BLK_POS+3] - '0'; } + if(blk1 == 2 && blk2 == 5 && blk3 == 6) { + blk = 256; + } else if(blk1 == 1 && blk2 == 0 && blk3 == 2 && blk4 == 4) { + blk = 1024; + } else if(blk1 == 2 && blk2 == 0 && blk3 == 4 && blk4 == 8) { + blk = 2048; + } + if(id < NUM_SCSIID && lun < NUM_SCSILUN) { HDDIMG *h = &img[id][lun]; imageReady = hddimageOpen(h,name,id,lun,blk);