Skip to content

Commit

Permalink
Implementing the Classic Mac Toolbox vendor code
Browse files Browse the repository at this point in the history
Code was taken from BlueSCSI's BlueSCSI/BlueSCSI-v2#79
and modified for use in ZuluSCSI.

Changes include the vendor page so the BluSCSI toolbox transfer
application will not work with this build.

Also changed was excluded files from the toolbox's CD changer.
Now subdirectories and common extensions compressed files and documents
are excluded from the list.

All files for the toolbox transfer app are now included.
  • Loading branch information
morio committed Jan 25, 2024
1 parent c80c5bb commit d04e4ad
Show file tree
Hide file tree
Showing 15 changed files with 563 additions and 28 deletions.
1 change: 1 addition & 0 deletions lib/SCSI2SD/src/firmware/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ void scsiDiskInit(void);
void scsiDiskReset(void);
void scsiDiskPoll(void);
int scsiDiskCommand(void);
int doTestUnitReady();

#endif
17 changes: 17 additions & 0 deletions lib/SCSI2SD/src/firmware/mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "disk.h"
#include "inquiry.h"
#include "ZuluSCSI_mode.h"
#include "toolbox.h"

#include <string.h>

Expand Down Expand Up @@ -246,6 +247,15 @@ static const uint8_t AppleVendorPage[] =
'A','P','P','L','E',' ','C','O','M','P','U','T','E','R',',',' ','I','N','C',' ',' ',' '
};

static const uint8_t ToolboxVendorPage[] =
{
0x31, // Page code
42, // Page length
'Z','u','l','u','S','C','S','I',' ','i','s',' ','G','P','L','v','3',' ','F','T','W',
' ','T','o','o','l','b','o','x',' ','v','e','n','d','o','r',' ','p','a','g','e',0x00
};


static void pageIn(int pc, int dataIdx, const uint8_t* pageData, int pageLen)
{
memcpy(&scsiDev.data[dataIdx], pageData, pageLen);
Expand Down Expand Up @@ -525,6 +535,13 @@ static void doModeSense(
idx += sizeof(AppleVendorPage);
}

if (scsiToolboxEnabled() && (pageCode == 0x31 || pageCode == 0x3F))
{
pageFound = 1;
pageIn(pc, idx, ToolboxVendorPage, sizeof(ToolboxVendorPage));
idx += sizeof(ToolboxVendorPage);
}

if (pageCode == 0x38) // Don't send unless requested
{
pageFound = 1;
Expand Down
26 changes: 23 additions & 3 deletions lib/SCSI2SD/src/firmware/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include "tape.h"
#include "mo.h"
#include "vendor.h"

#include <string.h>
#include "toolbox.h"

// Global SCSI device state.
ScsiDevice scsiDev S2S_DMA_ALIGN;
Expand Down Expand Up @@ -287,7 +287,7 @@ static void process_DataOut()
}
}

static const uint8_t CmdGroupBytes[8] = {6, 10, 10, 6, 6, 12, 6, 6};
static const uint8_t CmdGroupBytes[8] = {6, 10, 10, 6, 16, 12, 6, 6};
static void process_Command()
{
int group;
Expand All @@ -302,6 +302,8 @@ static void process_Command()

group = scsiDev.cdb[0] >> 5;
scsiDev.cdbLen = CmdGroupBytes[group];
scsiVendorCommandSetLen(scsiDev.cdb[0], &scsiDev.cdbLen);

if (parityError &&
(scsiDev.boardCfg.flags & S2S_CFG_ENABLE_PARITY))
{
Expand Down Expand Up @@ -610,7 +612,25 @@ static void process_Command()
{
scsiReadBuffer();
}
else if (!scsiModeCommand() && !scsiVendorCommand())
else if (scsiModeCommand())
{
// handled
}
else if (scsiVendorCommand())
{
// handled
}
else if (unlikely(command == 0x00))
{
// TEST UNIT READY
doTestUnitReady();
}
else if (unlikely(!doTestUnitReady()))
{
// This should be last as it can override other commands
// Status and sense codes already set by doTestUnitReady
}
else
{
scsiDev.target->sense.code = ILLEGAL_REQUEST;
scsiDev.target->sense.asc = INVALID_COMMAND_OPERATION_CODE;
Expand Down
2 changes: 1 addition & 1 deletion lib/SCSI2SD/src/firmware/scsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ typedef struct
int savedDataPtr; // Index into data, initially 0.
int dataLen;

uint8_t cdb[12]; // command descriptor block
uint8_t cdb[16]; // command descriptor block
uint8_t cdbLen; // 6, 10, or 12 byte message.
int8_t lun; // Target lun, set by IDENTIFY message.
uint8_t discPriv; // Disconnect priviledge.
Expand Down
28 changes: 28 additions & 0 deletions lib/SCSI2SD/src/firmware/toolbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2023 Eric Helgeson
* Copyright (C) 2024 Rabbit Hole Computing
*
* This file is originally part of BlueSCSI adopted for ZuluSCSI
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
**/

#ifndef S2S_TOOLBOX_H
#define S2S_TOOLBOX_H
#include <inttypes.h>
int8_t scsiToolboxEnabled(void);
void scsiToolboxCBDLen(uint8_t command, uint8_t *command_length);
int scsiToolboxCommand(void);

#endif
12 changes: 12 additions & 0 deletions lib/SCSI2SD/src/firmware/vendor.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "scsi.h"
#include "vendor.h"
#include "diagnostic.h"
#include "toolbox.h"

// Callback after the DATA OUT phase is complete.
static void doAssignDiskParameters(void)
Expand Down Expand Up @@ -80,6 +81,10 @@ int scsiVendorCommand()
scsiDev.phase = DATA_OUT;
scsiDev.postDataOutHook = doWriteBuffer;
}
else if (scsiToolboxEnabled() && scsiToolboxCommand())
{
// already handled
}
else
{
commandHandled = 0;
Expand All @@ -88,3 +93,10 @@ int scsiVendorCommand()
return commandHandled;
}

void scsiVendorCommandSetLen(uint8_t command, uint8_t* command_length)
{
if (scsiToolboxEnabled())
{
scsiToolboxCBDLen(command, command_length);
}
}
3 changes: 2 additions & 1 deletion lib/SCSI2SD/src/firmware/vendor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
#define S2S_VENDOR_H

int scsiVendorCommand(void);

// Set the command length for applicable vendor commands
void scsiVendorCommandSetLen(uint8_t command, uint8_t* command_length);
#endif
7 changes: 1 addition & 6 deletions lib/ZuluSCSI_platform_RP2040/scsi_accel_target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,12 +907,7 @@ void scsi_accel_rp2040_init()
dma_channel_claim(SCSI_DMA_CH_D);
g_channels_claimed = true;
}

#ifndef ZULUSCSI_NETWORK
// Load PIO programs
pio_clear_instruction_memory(SCSI_DMA_PIO);
#endif // ZULUSCSI_NETWORK


// Parity lookup generator
g_scsi_dma.pio_offset_parity = pio_add_program(SCSI_DMA_PIO, &scsi_parity_program);
g_scsi_dma.pio_cfg_parity = scsi_parity_program_get_default_config(g_scsi_dma.pio_offset_parity);
Expand Down
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ lib_deps =
ZuluSCSI_platform_RP2040
SCSI2SD
CUEParser
upload_protocol = cmsis-dap
debug_build_flags =
-O2 -ggdb -g3
; The values can be adjusted down to get a debug build to fit in to SRAM
Expand Down Expand Up @@ -176,7 +177,7 @@ build_flags =
-DZULUSCSI_DAYNAPORT
; These take a large portion of the SRAM and can be adjusted
-DLOGBUFSIZE=8192
-DPREFETCH_BUFFER_SIZE=6144
-DPREFETCH_BUFFER_SIZE=4096
-DSCSI2SD_BUFFER_SIZE=57344
; This controls the depth of 2 x NETWORK_PACKET_MAX_SIZE (1520 bytes)
; For example a queue size of 10 would be 10 x 2 x 1520 = 30400 bytes
Expand Down
Loading

0 comments on commit d04e4ad

Please sign in to comment.