Skip to content

Commit

Permalink
Merge branch 'eric/relPrep'
Browse files Browse the repository at this point in the history
  • Loading branch information
erichelgeson committed May 21, 2024
2 parents ed6ee1f + 98972d9 commit 19633f4
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 111 deletions.
1 change: 1 addition & 0 deletions lib/BlueSCSI_platform_RP2040/BlueSCSI_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern "C" {
extern const char *g_platform_name;
#define PLATFORM_NAME "BlueSCSI"
#define PLATFORM_REVISION "2.0"
#define PLATFORM_TOOLBOX_API 0
#define PLATFORM_INQUIRY PLATFORM_NAME " v" BLUESCSI_FW_VERSION
#define PLATFORM_MAX_SCSI_SPEED S2S_CFG_SPEED_SYNC_10
#define PLATFORM_OPTIMAL_MIN_SD_WRITE_SIZE 32768
Expand Down
3 changes: 1 addition & 2 deletions lib/SCSI2SD/src/firmware/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#define GEOMETRY_H

#include "config.h"
// TODO #include "sd.h"
#define SD_SECTOR_SIZE 512
#include "sd.h"

typedef enum
{
Expand Down
24 changes: 22 additions & 2 deletions lib/SCSI2SD/src/firmware/inquiry.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ static const uint8_t AscImpOperatingDefinition[] =
'S','C','S','I','-','2'
};

static const uint8_t IOMegaVendorInquiry[] =
{
'0', '8', '/', '2', '0', '/', '9', '6', 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
'(', 'c', ')', ' ', 'C', 'o', 'p', 'y', 'r', 'i', 'g', 'h', 't', ' ', 'I', 'O',
'M', 'E', 'G', 'A', ' ', '1', '9', '9', '5', ' '
};

void s2s_scsiInquiry()
{
uint8_t evpd = scsiDev.cdb[1] & 1; // enable vital product data.
Expand Down Expand Up @@ -200,6 +210,7 @@ void s2s_scsiInquiry()

case S2S_CFG_FLOPPY_14MB:
case S2S_CFG_REMOVEABLE:
case S2S_CFG_ZIP100:
scsiDev.data[1] |= 0x80; // Removable bit.
break;

Expand Down Expand Up @@ -248,10 +259,19 @@ uint32_t s2s_getStandardInquiry(
sizeof(cfg->prodId) +
sizeof(cfg->revision);

if(cfg->deviceType == S2S_CFG_ZIP100) {
memcpy(&out[size], IOMegaVendorInquiry, sizeof(IOMegaVendorInquiry));
size += sizeof(IOMegaVendorInquiry);
out[7] = 0x00; // Disable sync and linked commands
out[4] = 0x75; // 117 length
}
// Mac Daynaport Driver does not like this added.
if(cfg->deviceType != S2S_CFG_NETWORK) {
memcpy(&out[36], PLATFORM_INQUIRY, sizeof(PLATFORM_INQUIRY));
// IOMega already has a vendor inquiry
if(cfg->deviceType != S2S_CFG_NETWORK && cfg->deviceType != S2S_CFG_ZIP100) {
memcpy(&out[size], PLATFORM_INQUIRY, sizeof(PLATFORM_INQUIRY));
size += sizeof(PLATFORM_INQUIRY);
out[size] = PLATFORM_TOOLBOX_API;
size += 1;
}
return size;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/SCSI2SD/src/firmware/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#include "cdrom.h"
// #include "debug.h"
// #include "log.h"
#include "bluescsi_toolbox.h"
#include "mo.h"
#include "network.h"
#include "tape.h"
#include "mo.h"
#include "vendor.h"
#include "bluescsi_toolbox.h"

#include <string.h>

Expand Down Expand Up @@ -546,7 +546,7 @@ static void process_Command()
// Newer initiators won't be specifying 0 anyway.
if (allocLength == 0) allocLength = 4;

// If we receve a stand alone REQUEST SENSE to a bad LUN we still need to respond
// If we receive a stand-alone REQUEST SENSE to a bad LUN we still need to respond
// with LUN not supported. SCSI-2 Spec 7.5.3.
if (scsiDev.lun && scsiDev.lastStatus != CHECK_CONDITION)
{
Expand Down Expand Up @@ -604,7 +604,7 @@ static void process_Command()

enter_Status(CHECK_CONDITION);
}
else if (scsiDev.lun)
else if (scsiDev.lun && (command < 0xD0))
{
scsiDev.target->sense.code = ILLEGAL_REQUEST;
scsiDev.target->sense.asc = LOGICAL_UNIT_NOT_SUPPORTED;
Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ build_flags =
; -DSCSI2SD_BUFFER_SIZE=57344

; Experimental Audio build
; Rquires seperate hardware and overclock.
; For expermeination only, do not use.
; Requires separate hardware and overclock.
; For experimentation only, do not use.
[env:BlueSCSI_Pico_Audio]
extends = env:BlueSCSI_Pico
build_flags =
Expand Down
2 changes: 2 additions & 0 deletions src/BlueSCSI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ const char * typeToChar(int deviceType)
return "Tape";
case S2S_CFG_REMOVEABLE:
return "Removable";
case S2S_CFG_ZIP100:
return "ZIP100";
default:
return "Unknown";
}
Expand Down
36 changes: 25 additions & 11 deletions src/BlueSCSI_Toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,20 @@ static void doCountFiles(const char * dir_name)
file.close();
break;
}
file.getName(name, MAX_FILE_PATH);
bool isDir = file.isDirectory();
size_t len = file.getName(name, MAX_FILE_PATH);
file.close();
if (isDir)
continue;
// truncate filename the same way listing does, before validating name
if (len > MAX_MAC_PATH)
name[MAX_MAC_PATH] = 0x0;
debuglog("TOOLBOX COUNT FILES: truncated filename is '", name, "'");
// only count valid files.
if(toolboxFilenameValid(name))
{
file_count = file_count + 1;
if(file_count > 100) {
if(file_count > MAX_FILE_LISTING_FILES) {
scsiDev.status = CHECK_CONDITION;
scsiDev.target->sense.code = ILLEGAL_REQUEST;
scsiDev.target->sense.asc = OPEN_RETRO_SCSI_TOO_MANY_FILES;
Expand All @@ -91,15 +98,17 @@ void onListFiles(const char * dir_name) {
FsFile dir;
FsFile file;

memset(scsiDev.data, 0, 4096);
int ENTRY_SIZE = 40;
memset(scsiDev.data, 0, ENTRY_SIZE * (MAX_FILE_LISTING_FILES + 1));
char name[MAX_FILE_PATH] = {0};
uint8_t index = 0;
byte file_entry[ENTRY_SIZE] = {0};

dir.open(dir_name);
dir.rewindDirectory();
uint8_t index = 0;
byte file_entry[40] = {0};
while (file.openNext(&dir, O_RDONLY))
{
memset(name, 0, MAX_FILE_PATH);
memset(file_entry, 0, ENTRY_SIZE);
uint8_t isDir = file.isDirectory() ? 0x00 : 0x01;
int len = file.getName(name, MAX_FILE_PATH);
if (len > MAX_MAC_PATH)
Expand All @@ -122,10 +131,11 @@ void onListFiles(const char * dir_name) {
file_entry[39] = (size) & 0xff;
memcpy(&(scsiDev.data[ENTRY_SIZE * index]), file_entry, ENTRY_SIZE);
index = index + 1;
if (index >= MAX_FILE_LISTING_FILES) break;
}
dir.close();

scsiDev.dataLen = 4096;
scsiDev.dataLen = ENTRY_SIZE * index;
scsiDev.phase = DATA_IN;
}

Expand All @@ -145,8 +155,11 @@ FsFile get_file_from_index(uint8_t index, const char * dir_name)
file_test.close();
break;
}
file_test.getName(name, MAX_FILE_PATH);

// truncate filename the same way listing does, before validating name
size_t len = file_test.getName(name, MAX_FILE_PATH);
if (len > MAX_MAC_PATH)
name[MAX_MAC_PATH] = 0x0;
if(!toolboxFilenameValid(name))
{
file_test.close();
Expand Down Expand Up @@ -184,6 +197,7 @@ void onListDevices()
}
}
scsiDev.dataLen = NUM_SCSIID;
scsiDev.phase = DATA_IN;
}

void onSetNextCD(const char * img_dir)
Expand All @@ -197,10 +211,10 @@ void onSetNextCD(const char * img_dir)
next_cd.getName(name, sizeof(name));
next_cd.close();
snprintf(full_path, (MAX_FILE_PATH * 2), "%s/%s", img_dir, name);
cdromSwitch(img, full_path);
switchNextImage(img, full_path);
}

FsFile gFile; // global so we can keep it open while transfering.
FsFile gFile; // global so we can keep it open while transferring.
void onGetFile10(char * dir_name) {
uint8_t index = scsiDev.cdb[1];

Expand Down Expand Up @@ -232,7 +246,7 @@ void onGetFile10(char * dir_name) {
}

/*
Prepares a file for receving. The file name is null terminated in the scsi data.
Prepares a file for receiving. The file name is null terminated in the scsi data.
*/
void onSendFilePrep(char * dir_name)
{
Expand Down
3 changes: 3 additions & 0 deletions src/BlueSCSI_Toolbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#pragma once

#define MAX_MAC_PATH 32
#define ENTRY_SIZE 40
#define MAX_FILE_LISTING_FILES 100

#define CD_IMG_DIR "CD%d"

#define BLUESCSI_TOOLBOX_COUNT_FILES 0xD2
Expand Down
67 changes: 2 additions & 65 deletions src/BlueSCSI_cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ void cdromPerformEject(image_config_t &img)
debuglog("------ CDROM open tray on ID ", (int)target);
img.ejected = true;
img.cdrom_events = 3; // Media removal
cdromSwitchNextImage(img); // Switch media for next time
switchNextImage(img); // Switch media for next time
}
else
{
Expand All @@ -1199,7 +1199,7 @@ void cdromReinsertFirstImage(image_config_t &img)
debuglog("---- Restarting from first CD-ROM image for ID ", (int)target);
img.image_index = -1;
img.current_image[0] = '\0';
cdromSwitchNextImage(img);
switchNextImage(img);
}
else if (img.ejected)
{
Expand All @@ -1208,69 +1208,6 @@ void cdromReinsertFirstImage(image_config_t &img)
}
}

// Check if we have multiple CD-ROM images to cycle when drive is ejected.
bool cdromSwitchNextImage(image_config_t &img)
{
// Check if we have a next image to load, so that drive is closed next time the host asks.
char filename[MAX_FILE_PATH];
int target_idx = img.scsiId & S2S_CFG_TARGET_ID_BITS;
scsiDiskGetNextImageName(img, filename, sizeof(filename));

if (filename[0] != '\0')
{
#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
log("Switching to next CD-ROM image for ", target_idx, ": ", filename);
img.file.close();
bool status = scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0,
getBlockSize(filename, target_idx, 2048));

if (status)
{
return true;
}
}

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;

if (filename[0] != '\0')
{
#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
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;
Expand Down
6 changes: 0 additions & 6 deletions src/BlueSCSI_cdrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ void cdromPerformEject(image_config_t &img);
// Reinsert ejected CD-ROM and restart from first image
void cdromReinsertFirstImage(image_config_t &img);

// Switch to next CD-ROM image if multiple have been configured
bool cdromSwitchNextImage(image_config_t &img);

// Check if the currently loaded cue sheet for the image can be parsed
// and print warnings about unsupported track types
bool cdromValidateCueSheet(image_config_t &img);
Expand All @@ -32,6 +29,3 @@ bool cdromValidateCueSheet(image_config_t &img);
// 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);

// switch to a given filename for the cd.
bool cdromSwitch(image_config_t &img, const char* filename);
8 changes: 4 additions & 4 deletions src/BlueSCSI_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <BlueSCSI_platform.h>

// Use variables for version number
#define FW_VER_NUM "2024.04.03"
#define FW_VER_SUFFIX "dev"
#define FW_VER_NUM "2024.05.22"
#define FW_VER_SUFFIX "dev" // 3 char only - 'dev' or 'rel'
#define BLUESCSI_FW_VERSION FW_VER_NUM "-" FW_VER_SUFFIX

// Configuration and log file paths
Expand Down Expand Up @@ -68,7 +68,7 @@
#define APPLE_DRIVEINFO_TAPE {"BlueSCSI", "APPLE_TAPE", "", ""}

// Default Iomega ZIP drive information
#define IOMEGA_DRIVEINFO_ZIP100 {"IOMEGA", "ZIP 100", "E.08", ""}
#define IOMEGA_DRIVEINFO_ZIP100 {"IOMEGA", "ZIP 100", "D.13", ""}
#define IOMEGA_DRIVEINFO_ZIP250 {"IOMEGA", "ZIP 250", "42.S", ""}
#define IOMEGA_DRIVEINFO_JAZ {"iomega", "jaz", "", ""}

Expand All @@ -93,4 +93,4 @@ int getImgDir(int scsiId, char* dirname);

int getImg(int scsiId, int img_index, char* filename);

int getToolBoxSharedDir(char * dir_name);
int getToolBoxSharedDir(char * dir_name);
Loading

0 comments on commit 19633f4

Please sign in to comment.