mirror of
https://github.com/akuker/RASCSI.git
synced 2025-04-09 12:38:27 +00:00
Removed duplicate code, implemented Verify16
This commit is contained in:
parent
1e0f51488e
commit
c7f869e75c
@ -37,8 +37,7 @@ public:
|
||||
|
||||
// Implemented optional commands
|
||||
virtual void Verify10(SASIDEV *) = 0;
|
||||
// TODO Implement
|
||||
// virtual void Verify16(SASIDEV *) = 0;
|
||||
virtual void Verify16(SASIDEV *) = 0;
|
||||
virtual void ModeSense(SASIDEV *) override = 0;
|
||||
virtual void ModeSense10(SASIDEV *) override = 0;
|
||||
virtual void ModeSelect(SASIDEV *) override = 0;
|
||||
|
@ -431,24 +431,8 @@ void Disk::ReassignBlocks(SASIDEV *controller)
|
||||
void Disk::Read6(SASIDEV *controller)
|
||||
{
|
||||
// Get record number and block number
|
||||
DWORD record = ctrl->cmd[1] & 0x1f;
|
||||
record <<= 8;
|
||||
record |= ctrl->cmd[2];
|
||||
record <<= 8;
|
||||
record |= ctrl->cmd[3];
|
||||
ctrl->blocks = ctrl->cmd[4];
|
||||
if (ctrl->blocks == 0) {
|
||||
ctrl->blocks = 0x100;
|
||||
}
|
||||
|
||||
// Check capacity
|
||||
uint32_t capacity = GetBlockCount();
|
||||
if (record > capacity || record + ctrl->blocks > capacity) {
|
||||
ostringstream s;
|
||||
s << "Media capacity of " << capacity << " blocks exceeded: "
|
||||
<< "Trying to read block " << record << ", block count " << ctrl->blocks;
|
||||
LOGWARN("%s", s.str().c_str());
|
||||
controller->Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::LBA_OUT_OF_RANGE);
|
||||
uint64_t record;
|
||||
if (!GetStartAndCount(controller, record, ctrl->blocks, RW6)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -474,7 +458,7 @@ void Disk::Read10(SASIDEV *controller)
|
||||
{
|
||||
// Get record number and block number
|
||||
uint64_t record;
|
||||
if (!GetStartAndCount(controller, record, ctrl->blocks, false)) {
|
||||
if (!GetStartAndCount(controller, record, ctrl->blocks, RW10)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -498,7 +482,7 @@ void Disk::Read16(SASIDEV *controller)
|
||||
{
|
||||
// Get record number and block number
|
||||
uint64_t record;
|
||||
if (!GetStartAndCount(controller, record, ctrl->blocks, true)) {
|
||||
if (!GetStartAndCount(controller, record, ctrl->blocks, RW16)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -564,24 +548,8 @@ BOOL DiskTrack::Write(const BYTE *buf, int sec)
|
||||
void Disk::Write6(SASIDEV *controller)
|
||||
{
|
||||
// Get record number and block number
|
||||
DWORD record = ctrl->cmd[1] & 0x1f;
|
||||
record <<= 8;
|
||||
record |= ctrl->cmd[2];
|
||||
record <<= 8;
|
||||
record |= ctrl->cmd[3];
|
||||
ctrl->blocks = ctrl->cmd[4];
|
||||
if (ctrl->blocks == 0) {
|
||||
ctrl->blocks = 0x100;
|
||||
}
|
||||
|
||||
// Check capacity
|
||||
uint32_t capacity = GetBlockCount();
|
||||
if (record > capacity || record + ctrl->blocks > capacity) {
|
||||
ostringstream s;
|
||||
s << "Media capacity of " << capacity << " blocks exceeded: "
|
||||
<< "Trying to write block " << record << ", block count " << ctrl->blocks;
|
||||
LOGWARN("%s", s.str().c_str());
|
||||
controller->Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::LBA_OUT_OF_RANGE);
|
||||
uint64_t record;
|
||||
if (!GetStartAndCount(controller, record, ctrl->blocks, RW6)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -605,7 +573,7 @@ void Disk::Write10(SASIDEV *controller)
|
||||
{
|
||||
// Get record number and block number
|
||||
uint64_t record;
|
||||
if (!GetStartAndCount(controller, record, ctrl->blocks, false)) {
|
||||
if (!GetStartAndCount(controller, record, ctrl->blocks, RW10)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -629,7 +597,7 @@ void Disk::Write16(SASIDEV *controller)
|
||||
{
|
||||
// Get record number and block number
|
||||
uint64_t record;
|
||||
if (!GetStartAndCount(controller, record, ctrl->blocks, true)) {
|
||||
if (!GetStartAndCount(controller, record, ctrl->blocks, RW16)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -654,14 +622,8 @@ void Disk::Write16(SASIDEV *controller)
|
||||
// VERIFY
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
void Disk::Verify10(SASIDEV *controller)
|
||||
void Disk::Verify(SASIDEV *controller, uint64_t record)
|
||||
{
|
||||
// Get record number and block number
|
||||
uint64_t record;
|
||||
GetStartAndCount(controller, record, ctrl->blocks, false);
|
||||
|
||||
LOGDEBUG("%s VERIFY command record=%08X blocks=%d",__PRETTY_FUNCTION__, (unsigned int)record, (int)ctrl->blocks);
|
||||
|
||||
// if BytChk=0
|
||||
if ((ctrl->cmd[1] & 0x02) == 0) {
|
||||
Seek(controller);
|
||||
@ -683,6 +645,28 @@ void Disk::Verify10(SASIDEV *controller)
|
||||
controller->DataOut();
|
||||
}
|
||||
|
||||
void Disk::Verify10(SASIDEV *controller)
|
||||
{
|
||||
// Get record number and block number
|
||||
uint64_t record;
|
||||
GetStartAndCount(controller, record, ctrl->blocks, RW10);
|
||||
|
||||
LOGDEBUG("%s VERIFY(10) command record=%08X blocks=%d",__PRETTY_FUNCTION__, (unsigned int)record, (int)ctrl->blocks);
|
||||
|
||||
Verify(controller, record);
|
||||
}
|
||||
|
||||
void Disk::Verify16(SASIDEV *controller)
|
||||
{
|
||||
// Get record number and block number
|
||||
uint64_t record;
|
||||
GetStartAndCount(controller, record, ctrl->blocks, RW16);
|
||||
|
||||
LOGDEBUG("%s VERIFY(16) command record=%08X blocks=%d",__PRETTY_FUNCTION__, (unsigned int)record, (int)ctrl->blocks);
|
||||
|
||||
Verify(controller, record);
|
||||
}
|
||||
|
||||
void Disk::Inquiry(SASIDEV *controller)
|
||||
{
|
||||
// Find a valid unit
|
||||
@ -1997,7 +1981,7 @@ bool Disk::Format(const DWORD *cdb)
|
||||
// READ
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
int Disk::Read(const DWORD *cdb, BYTE *buf, DWORD block)
|
||||
int Disk::Read(const DWORD *cdb, BYTE *buf, uint64_t block)
|
||||
{
|
||||
ASSERT(buf);
|
||||
|
||||
@ -2484,39 +2468,53 @@ bool Disk::PlayAudioTrack(const DWORD *cdb)
|
||||
// Get start sector and sector count for a READ/WRITE(10/16) operation
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
bool Disk::GetStartAndCount(SASIDEV *controller, uint64_t& start, uint32_t& count, bool rw64)
|
||||
bool Disk::GetStartAndCount(SASIDEV *controller, uint64_t& start, uint32_t& count, access_mode mode)
|
||||
{
|
||||
start = ctrl->cmd[2];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[3];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[4];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[5];
|
||||
if (rw64) {
|
||||
if (mode == RW6) {
|
||||
start = ctrl->cmd[1] & 0x1f;
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[6];
|
||||
start |= ctrl->cmd[2];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[7];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[8];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[9];
|
||||
}
|
||||
start |= ctrl->cmd[3];
|
||||
|
||||
if (rw64) {
|
||||
count = ctrl->cmd[10];
|
||||
count <<= 8;
|
||||
count |= ctrl->cmd[11];
|
||||
count <<= 8;
|
||||
count |= ctrl->cmd[12];
|
||||
count <<= 8;
|
||||
count |= ctrl->cmd[13];
|
||||
count = ctrl->cmd[4];
|
||||
if (!count) {
|
||||
count= 0x100;
|
||||
}
|
||||
}
|
||||
else {
|
||||
count = ctrl->cmd[7];
|
||||
count <<= 8;
|
||||
count |= ctrl->cmd[8];
|
||||
start = ctrl->cmd[2];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[3];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[4];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[5];
|
||||
if (mode == RW16) {
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[6];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[7];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[8];
|
||||
start <<= 8;
|
||||
start |= ctrl->cmd[9];
|
||||
}
|
||||
|
||||
if (mode == RW16) {
|
||||
count = ctrl->cmd[10];
|
||||
count <<= 8;
|
||||
count |= ctrl->cmd[11];
|
||||
count <<= 8;
|
||||
count |= ctrl->cmd[12];
|
||||
count <<= 8;
|
||||
count |= ctrl->cmd[13];
|
||||
}
|
||||
else {
|
||||
count = ctrl->cmd[7];
|
||||
count <<= 8;
|
||||
count |= ctrl->cmd[8];
|
||||
}
|
||||
}
|
||||
|
||||
// Check capacity
|
||||
|
@ -127,6 +127,8 @@ private:
|
||||
class Disk : public BlockDevice
|
||||
{
|
||||
private:
|
||||
enum access_mode { RW6, RW10, RW16 };
|
||||
|
||||
bool sector_size_configurable;
|
||||
int configured_sector_size;
|
||||
|
||||
@ -186,7 +188,9 @@ public:
|
||||
void Write6(SASIDEV *);
|
||||
void Write10(SASIDEV *) override;
|
||||
void Write16(SASIDEV *) override;
|
||||
void Verify(SASIDEV *, uint64_t);
|
||||
void Verify10(SASIDEV *) override;
|
||||
void Verify16(SASIDEV *) override;
|
||||
void Seek(SASIDEV *);
|
||||
void Seek6(SASIDEV *);
|
||||
void Seek10(SASIDEV *);
|
||||
@ -211,7 +215,7 @@ public:
|
||||
virtual bool PlayAudioMSF(const DWORD *cdb); // PLAY AUDIO MSF command
|
||||
virtual bool PlayAudioTrack(const DWORD *cdb); // PLAY AUDIO TRACK command
|
||||
|
||||
virtual int Read(const DWORD *cdb, BYTE *buf, DWORD block); // READ command
|
||||
virtual int Read(const DWORD *cdb, BYTE *buf, uint64_t block);
|
||||
virtual int ModeSense10(const DWORD *cdb, BYTE *buf); // MODE SENSE(10) command
|
||||
int ReadDefectData10(const DWORD *cdb, BYTE *buf); // READ DEFECT DATA(10) command
|
||||
int SelectCheck(const DWORD *cdb); // SELECT check
|
||||
@ -225,7 +229,7 @@ public:
|
||||
void SetConfiguredSectorSize(int);
|
||||
uint32_t GetBlockCount() const;
|
||||
void SetBlockCount(DWORD);
|
||||
bool GetStartAndCount(SASIDEV *, uint64_t&, uint32_t&, bool);
|
||||
bool GetStartAndCount(SASIDEV *, uint64_t&, uint32_t&, access_mode);
|
||||
|
||||
// TODO Try to get rid of this method, which is called by SASIDEV (but must not)
|
||||
virtual bool ModeSelect(const DWORD *cdb, const BYTE *buf, int length);// MODE SELECT command
|
||||
|
@ -214,7 +214,7 @@ int SCSIDaynaPort::Inquiry(const DWORD *cdb, BYTE *buf)
|
||||
// - The SCSI/Link apparently has about 6KB buffer space for packets.
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
int SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, DWORD block)
|
||||
int SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, uint64_t block)
|
||||
{
|
||||
int rx_packet_size = 0;
|
||||
bool send_message_to_host;
|
||||
|
@ -67,7 +67,7 @@ public:
|
||||
// commands
|
||||
int Inquiry(const DWORD *cdb, BYTE *buffer) override;
|
||||
// INQUIRY command
|
||||
int Read(const DWORD *cdb, BYTE *buf, DWORD block) override;
|
||||
int Read(const DWORD *cdb, BYTE *buf, uint64_t block) override;
|
||||
// READ command
|
||||
bool Write(const DWORD *cdb, const BYTE *buf, DWORD block) override;
|
||||
// WRITE command
|
||||
|
@ -634,7 +634,7 @@ int SCSICD::Inquiry(const DWORD *cdb, BYTE *buf)
|
||||
// READ
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
int SCSICD::Read(const DWORD *cdb, BYTE *buf, DWORD block)
|
||||
int SCSICD::Read(const DWORD *cdb, BYTE *buf, uint64_t block)
|
||||
{
|
||||
ASSERT(buf);
|
||||
|
||||
|
@ -96,7 +96,7 @@ public:
|
||||
|
||||
// commands
|
||||
int Inquiry(const DWORD *cdb, BYTE *buf) override; // INQUIRY command
|
||||
int Read(const DWORD *cdb, BYTE *buf, DWORD block) override; // READ command
|
||||
int Read(const DWORD *cdb, BYTE *buf, uint64_t block) override; // READ command
|
||||
int ReadToc(const DWORD *cdb, BYTE *buf); // READ TOC command
|
||||
|
||||
bool Dispatch(SCSIDEV *);
|
||||
|
Loading…
x
Reference in New Issue
Block a user