-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
127 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//--------------------------------------------------------------------------- | ||
// | ||
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi | ||
// | ||
// Copyright (C) 2024 Uwe Seimet | ||
// | ||
//--------------------------------------------------------------------------- | ||
|
||
#include "tape_executor.h" | ||
#include <spdlog/spdlog.h> | ||
#include "shared/memory_util.h" | ||
|
||
using namespace spdlog; | ||
using namespace memory_util; | ||
|
||
void TapeExecutor::Rewind() | ||
{ | ||
vector<uint8_t> cdb(6); | ||
|
||
initiator_executor->Execute(scsi_command::rewind, cdb, { }, 0, 300); | ||
} | ||
|
||
int TapeExecutor::ReadWrite(span<uint8_t> buffer, bool is_write) | ||
{ | ||
vector<uint8_t> cdb(6); | ||
cdb[2] = static_cast<uint8_t>(default_length >> 16); | ||
cdb[3] = static_cast<uint8_t>(default_length >> 8); | ||
cdb[4] = static_cast<uint8_t>(default_length); | ||
|
||
int status = initiator_executor->Execute(is_write ? scsi_command::write_6 : scsi_command::read_6, cdb, buffer, | ||
default_length, 300); | ||
if (!status) { | ||
return default_length; | ||
} | ||
|
||
fill_n(cdb.begin(), cdb.size(), 0); | ||
cdb[4] = 14; | ||
initiator_executor->Execute(scsi_command::request_sense, cdb, buffer, 14, 3); | ||
|
||
if (buffer[2] & 0x80) { | ||
debug("Hit filemark"); | ||
return 0; | ||
} | ||
|
||
if (!(buffer[0] & 0x80)) { | ||
error("VALID is not set"); | ||
return -1; | ||
} | ||
|
||
default_length -= GetInt32(buffer, 3); | ||
|
||
debug("Found block with {} byte(s)", default_length); | ||
|
||
cdb[2] = static_cast<uint8_t>(default_length >> 16); | ||
cdb[3] = static_cast<uint8_t>(default_length >> 8); | ||
cdb[4] = static_cast<uint8_t>(default_length); | ||
|
||
status = initiator_executor->Execute(is_write ? scsi_command::write_6 : scsi_command::read_6, cdb, buffer, | ||
default_length, 300); | ||
if (!status) { | ||
return default_length; | ||
} | ||
|
||
fill_n(cdb.begin(), cdb.size(), 0); | ||
cdb[4] = 14; | ||
initiator_executor->Execute(scsi_command::request_sense, cdb, buffer, 14, 3); | ||
spdlog::error(buffer[2] & 0x0f); | ||
spdlog::error(buffer[12]); | ||
// TODO Print sense data | ||
|
||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//--------------------------------------------------------------------------- | ||
// | ||
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi | ||
// | ||
// Copyright (C) 2024 Uwe Seimet | ||
// | ||
//--------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
#include "s2pdump_executor.h" | ||
|
||
using namespace std; | ||
|
||
class TapeExecutor : public S2pDumpExecutor | ||
{ | ||
|
||
public: | ||
|
||
TapeExecutor(Bus &b, int i, logger &l) : S2pDumpExecutor(b, i, l) | ||
{ | ||
} | ||
|
||
void Rewind(); | ||
int ReadWrite(span<uint8_t>, bool); | ||
|
||
private: | ||
|
||
unique_ptr<S2pDumpExecutor> s2pdump_executor; | ||
|
||
int default_length = 0xffffff; | ||
}; |