Moved bridge code from Disk to Bridge class

This commit is contained in:
Uwe Seimet 2021-08-22 23:35:16 +02:00
parent ac437fdebb
commit ca66b6fae0
4 changed files with 85 additions and 100 deletions

View File

@ -27,7 +27,6 @@
#include "controllers/sasidev_ctrl.h"
#include "controllers/scsidev_ctrl.h"
#include "exceptions.h"
#include "scsi_host_bridge.h"
#include "disk.h"
#include <sstream>
@ -476,13 +475,6 @@ void Disk::Read6(SASIDEV *controller)
void Disk::Read10(SASIDEV *controller)
{
// TODO Move to subclass
// Receive message if host bridge
if (IsBridge()) {
CmdGetMessage10(controller);
return;
}
// Get record number and block number
uint64_t record;
if (!GetStartAndCount(controller, record, ctrl->blocks, false)) {
@ -614,13 +606,6 @@ void Disk::Write6(SASIDEV *controller)
void Disk::Write10(SASIDEV *controller)
{
// TODO Move to subclass
// Send message with host bridge
if (ctrl->device->IsBridge()) {
CmdSendMessage10(controller);
return;
}
// Get record number and block number
uint64_t record;
if (!GetStartAndCount(controller, record, ctrl->blocks, false)) {
@ -667,74 +652,6 @@ void Disk::Write16(SASIDEV *controller)
controller->DataOut();
}
//---------------------------------------------------------------------------
//
// GET MESSAGE(10)
//
//---------------------------------------------------------------------------
void Disk::CmdGetMessage10(SASIDEV *controller)
{
// Reallocate buffer (because it is not transfer for each block)
if (ctrl->bufsize < 0x1000000) {
free(ctrl->buffer);
ctrl->bufsize = 0x1000000;
ctrl->buffer = (BYTE *)malloc(ctrl->bufsize);
}
// TODO Move code to subclass
ctrl->length = ((SCSIBR*)ctrl->device)->SendMessage10(ctrl->cmd, ctrl->buffer);
if (ctrl->length <= 0) {
// Failure (Error)
controller->Error();
return;
}
// Set next block
ctrl->blocks = 1;
ctrl->next = 1;
// Data in phase
controller->DataIn();
}
//---------------------------------------------------------------------------
//
// SEND MESSAGE(10)
//
// This Send Message command is used by the X68000 host driver
//
//---------------------------------------------------------------------------
void Disk::CmdSendMessage10(SASIDEV *controller)
{
// Reallocate buffer (because it is not transfer for each block)
if (ctrl->bufsize < 0x1000000) {
free(ctrl->buffer);
ctrl->bufsize = 0x1000000;
ctrl->buffer = (BYTE *)malloc(ctrl->bufsize);
}
// Set transfer amount
ctrl->length = ctrl->cmd[6];
ctrl->length <<= 8;
ctrl->length |= ctrl->cmd[7];
ctrl->length <<= 8;
ctrl->length |= ctrl->cmd[8];
if (ctrl->length <= 0) {
// Failure (Error)
controller->Error();
return;
}
// Set next block
ctrl->blocks = 1;
ctrl->next = 1;
// Data out phase
controller->DataOut();
}
//---------------------------------------------------------------------------
//
// VERIFY

View File

@ -196,8 +196,6 @@ public:
void Release10(SASIDEV *);
// Command helpers
void CmdSendMessage10(SASIDEV *);
void CmdGetMessage10(SASIDEV *);
void Verify(SASIDEV *); // VERIFY command
virtual int Inquiry(const DWORD *cdb, BYTE *buf) = 0; // INQUIRY command
virtual int WriteCheck(DWORD block); // WRITE check

View File

@ -162,15 +162,11 @@ bool SCSIBR::TestUnitReady(const DWORD* /*cdb*/)
//---------------------------------------------------------------------------
int SCSIBR::GetMessage10(const DWORD *cdb, BYTE *buf)
{
int func;
int total_len;
int i;
// Type
int type = cdb[2];
// Function number
func = cdb[3];
int func = cdb[3];
// Phase
int phase = cdb[9];
@ -209,8 +205,8 @@ int SCSIBR::GetMessage10(const DWORD *cdb, BYTE *buf)
case 3: // Simultaneous acquisition of multiple packets (size + buffer simultaneously)
// Currently the maximum number of packets is 10
// Isn't it too fast if I increase more?
total_len = 0;
for (i = 0; i < 10; i++) {
int total_len = 0;
for (int i = 0; i < 10; i++) {
ReceivePacket();
*buf++ = (BYTE)(packet_len >> 8);
*buf++ = (BYTE)packet_len;
@ -249,7 +245,7 @@ int SCSIBR::GetMessage10(const DWORD *cdb, BYTE *buf)
// SEND MESSAGE(10)
//
//---------------------------------------------------------------------------
BOOL SCSIBR::SendMessage10(const DWORD *cdb, BYTE *buf)
bool SCSIBR::SendMessage10(const DWORD *cdb, BYTE *buf)
{
ASSERT(cdb);
ASSERT(buf);
@ -274,17 +270,17 @@ BOOL SCSIBR::SendMessage10(const DWORD *cdb, BYTE *buf)
case 1: // Ethernet
// Do not process if TAP is invalid
if (!m_bTapEnable) {
return FALSE;
return false;
}
switch (func) {
case 0: // MAC address setting
SetMacAddr(buf);
return TRUE;
return true;
case 1: // Send packet
SendPacket(buf, len);
return TRUE;
return true;
}
break;
@ -292,18 +288,90 @@ BOOL SCSIBR::SendMessage10(const DWORD *cdb, BYTE *buf)
switch (phase) {
case 0: // issue command
WriteFs(func, buf);
return TRUE;
return true;
case 1: // additional data writing
WriteFsOpt(buf, len);
return TRUE;
return true;
}
break;
}
// Error
ASSERT(FALSE);
return FALSE;
return false;
}
//---------------------------------------------------------------------------
//
// GET MESSAGE(10)
//
//---------------------------------------------------------------------------
void SCSIBR::Read10(SASIDEV *controller)
{
SASIDEV::ctrl_t *ctrl = controller->GetWorkAddr();
// Reallocate buffer (because it is not transfer for each block)
if (ctrl->bufsize < 0x1000000) {
free(ctrl->buffer);
ctrl->bufsize = 0x1000000;
ctrl->buffer = (BYTE *)malloc(ctrl->bufsize);
}
// TODO Move code to subclass
ctrl->length = ((SCSIBR*)ctrl->device)->GetMessage10(ctrl->cmd, ctrl->buffer);
if (ctrl->length <= 0) {
// Failure (Error)
controller->Error();
return;
}
// Set next block
ctrl->blocks = 1;
ctrl->next = 1;
// Data in phase
controller->DataIn();
}
//---------------------------------------------------------------------------
//
// SEND MESSAGE(10)
//
// This Send Message command is used by the X68000 host driver
//
//---------------------------------------------------------------------------
void SCSIBR::Write10(SASIDEV *controller)
{
SASIDEV::ctrl_t *ctrl = controller->GetWorkAddr();
// Reallocate buffer (because it is not transfer for each block)
if (ctrl->bufsize < 0x1000000) {
free(ctrl->buffer);
ctrl->bufsize = 0x1000000;
ctrl->buffer = (BYTE *)malloc(ctrl->bufsize);
}
// Set transfer amount
ctrl->length = ctrl->cmd[6];
ctrl->length <<= 8;
ctrl->length |= ctrl->cmd[7];
ctrl->length <<= 8;
ctrl->length |= ctrl->cmd[8];
if (ctrl->length <= 0) {
// Failure (Error)
controller->Error();
return;
}
// Set next block
ctrl->blocks = 1;
ctrl->next = 1;
// Data out phase
controller->DataOut();
}
//---------------------------------------------------------------------------

View File

@ -39,7 +39,9 @@ public:
int Inquiry(const DWORD *cdb, BYTE *buf) override; // INQUIRY command
bool TestUnitReady(const DWORD *cdb) override; // TEST UNIT READY command
int GetMessage10(const DWORD *cdb, BYTE *buf); // GET MESSAGE10 command
BOOL SendMessage10(const DWORD *cdb, BYTE *buf); // SEND MESSAGE10 command
bool SendMessage10(const DWORD *cdb, BYTE *buf); // SEND MESSAGE10 command
void Write10(SASIDEV *) override;
void Read10(SASIDEV *) override;
private:
int GetMacAddr(BYTE *buf); // Get MAC address