From ffa565a8b41c91fca6c3865204f520f47ce65b14 Mon Sep 17 00:00:00 2001 From: Tony Kuker Date: Sat, 15 Jan 2022 05:13:06 +0000 Subject: [PATCH] Initialize the framebuffer to blue and implement a couple more commands --- src/raspberrypi/.vscode/settings.json | 52 +++- src/raspberrypi/controllers/sasidev_ctrl.cpp | 70 +++++- src/raspberrypi/controllers/sasidev_ctrl.h | 12 +- src/raspberrypi/controllers/scsidev_ctrl.h | 8 +- src/raspberrypi/devices/scsi_powerview.cpp | 251 +++++++++++-------- src/raspberrypi/devices/scsi_powerview.h | 97 ++----- 6 files changed, 281 insertions(+), 209 deletions(-) diff --git a/src/raspberrypi/.vscode/settings.json b/src/raspberrypi/.vscode/settings.json index f04eecef..f38d2577 100644 --- a/src/raspberrypi/.vscode/settings.json +++ b/src/raspberrypi/.vscode/settings.json @@ -14,6 +14,56 @@ "regex": "cpp", "*.tcc": "cpp", "numeric": "cpp", - "sstream": "cpp" + "sstream": "cpp", + "atomic": "cpp", + "bit": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "optional": "cpp", + "random": "cpp", + "string": "cpp", + "system_error": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ranges": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" } } \ No newline at end of file diff --git a/src/raspberrypi/controllers/sasidev_ctrl.cpp b/src/raspberrypi/controllers/sasidev_ctrl.cpp index c45943ec..42245753 100644 --- a/src/raspberrypi/controllers/sasidev_ctrl.cpp +++ b/src/raspberrypi/controllers/sasidev_ctrl.cpp @@ -1202,7 +1202,7 @@ bool SASIDEV::XferOut(bool cont) case SASIDEV::eCmdInvalid: break; - case SASIDEV::eCmdWriteFrameBuffer: + case SASIDEV::eCmdPvWriteFrameBuffer: LOGDEBUG("Writing Frame Buffer ($%02X) in %s. Length: %08X (%d)", (WORD)ctrl.cmd[0] , __PRETTY_FUNCTION__, ctrl.offset, ctrl.offset); LOGDEBUG(" %02X%02X%02X%02X %02X%02X%02X%02X", ctrl.buffer[0],ctrl.buffer[1],ctrl.buffer[2],ctrl.buffer[3],ctrl.buffer[4],ctrl.buffer[5],ctrl.buffer[6],ctrl.buffer[7]); @@ -1220,11 +1220,65 @@ bool SASIDEV::XferOut(bool cont) return true; break; + case SASIDEV::eCmdPvWriteColorPalette: + LOGDEBUG("Writing Color Palette ($%02X) in %s. Length: %08X (%d)", (WORD)ctrl.cmd[0] , __PRETTY_FUNCTION__, ctrl.offset, ctrl.offset); + LOGDEBUG(" %02X%02X%02X%02X %02X%02X%02X%02X", ctrl.buffer[0],ctrl.buffer[1],ctrl.buffer[2],ctrl.buffer[3],ctrl.buffer[4],ctrl.buffer[5],ctrl.buffer[6],ctrl.buffer[7]); + + if (device->IsPowerView()) { + if (!((SCSIPowerView*)device)->WriteColorPalette(ctrl.cmd, ctrl.buffer, ctrl.offset)) { + // write failed + return false; + } + + // If normal, work setting + ctrl.offset = 0; + break; + } + + return true; + break; + + + + + case SASIDEV::eCmdPvWriteConfig: + LOGDEBUG("Writing Configuration ($%02X) in %s. Length: %08X (%d)", (WORD)ctrl.cmd[0] , __PRETTY_FUNCTION__, ctrl.offset, ctrl.offset); + LOGDEBUG(" %02X%02X%02X%02X %02X%02X%02X%02X", ctrl.buffer[0],ctrl.buffer[1],ctrl.buffer[2],ctrl.buffer[3],ctrl.buffer[4],ctrl.buffer[5],ctrl.buffer[6],ctrl.buffer[7]); + + if (device->IsPowerView()) { + if (!((SCSIPowerView*)device)->WriteConfiguration(ctrl.cmd, ctrl.buffer, ctrl.offset)) { + // write failed + return false; + } + + // If normal, work setting + ctrl.offset = 0; + break; + } + + return true; + break; - case SASIDEV::eCmdUnknownPowerViewC8: - case SASIDEV::eCmdUnknownPowerViewC9: - case SASIDEV::eCmdUnknownPowerViewCB: case SASIDEV::eCmdUnknownPowerViewCC: + LOGDEBUG("Writing Unknown CC ($%02X) in %s. Length: %08X (%d)", (WORD)ctrl.cmd[0] , __PRETTY_FUNCTION__, ctrl.offset, ctrl.offset); + LOGDEBUG(" %02X%02X%02X%02X %02X%02X%02X%02X", ctrl.buffer[0],ctrl.buffer[1],ctrl.buffer[2],ctrl.buffer[3],ctrl.buffer[4],ctrl.buffer[5],ctrl.buffer[6],ctrl.buffer[7]); + + if (device->IsPowerView()) { + if (!((SCSIPowerView*)device)->WriteUnknownCC(ctrl.cmd, ctrl.buffer, ctrl.offset)) { + // write failed + return false; + } + + // If normal, work setting + ctrl.offset = 0; + break; + } + + return true; + break; + + + case SASIDEV::eCmdPvReadConfig: LOGDEBUG("Finished receiving a Powerview Command ($%02X) in %s. Length: %08X (%d)", (WORD)ctrl.cmd[0] , __PRETTY_FUNCTION__, ctrl.offset, ctrl.offset); LOGDEBUG(" %02X%02X%02X%02X %02X%02X%02X%02X", ctrl.buffer[0],ctrl.buffer[1],ctrl.buffer[2],ctrl.buffer[3],ctrl.buffer[4],ctrl.buffer[5],ctrl.buffer[6],ctrl.buffer[7]); @@ -1304,10 +1358,10 @@ void SASIDEV::FlushUnit() } break; - case SASIDEV::eCmdUnknownPowerViewC8: - case SASIDEV::eCmdUnknownPowerViewC9: - case SASIDEV::eCmdWriteFrameBuffer: - case SASIDEV::eCmdUnknownPowerViewCB: + case SASIDEV::eCmdPvReadConfig: + case SASIDEV::eCmdPvWriteConfig: + case SASIDEV::eCmdPvWriteFrameBuffer: + case SASIDEV::eCmdPvWriteColorPalette: case SASIDEV::eCmdUnknownPowerViewCC: LOGDEBUG("%s Received PowerView flush %02X", __PRETTY_FUNCTION__, (WORD)ctrl.cmd[0]); break; diff --git a/src/raspberrypi/controllers/sasidev_ctrl.h b/src/raspberrypi/controllers/sasidev_ctrl.h index 43aa5fa1..63bd532d 100644 --- a/src/raspberrypi/controllers/sasidev_ctrl.h +++ b/src/raspberrypi/controllers/sasidev_ctrl.h @@ -81,10 +81,14 @@ private: eCmdWriteLong16 = 0x9F, eCmdInvalid = 0xC2, eCmdSasiCmdAssign = 0x0E, - eCmdUnknownPowerViewC8 = 0xC8, - eCmdUnknownPowerViewC9 = 0xC9, - eCmdWriteFrameBuffer = 0xCA, - eCmdUnknownPowerViewCB = 0xCB, + eCmdPvReadConfig = 0xC8, + eCmdPvWriteConfig = 0xC9, + eCmdPvWriteFrameBuffer = 0xCA, + eCmdPvWriteColorPalette = 0xCB, + // eCmdPvReadConfig = 0xC8, + // eCmdPvWriteConfig = 0xC9, + // eCmdPvWriteFrameBuffer = 0xCA, + // eCmdPvWriteColorPalette = 0xCB, eCmdUnknownPowerViewCC = 0xCC }; diff --git a/src/raspberrypi/controllers/scsidev_ctrl.h b/src/raspberrypi/controllers/scsidev_ctrl.h index 5668bd25..6ec3e325 100644 --- a/src/raspberrypi/controllers/scsidev_ctrl.h +++ b/src/raspberrypi/controllers/scsidev_ctrl.h @@ -70,10 +70,10 @@ public: eCmdReadCapacity16_ReadLong16 = 0x9E, eCmdWriteLong16 = 0x9F, eCmdReportLuns = 0xA0, - eCmdUnknownPowerViewC8 = 0xC8, - eCmdUnknownPowerViewC9 = 0xC9, - eCmdWriteFrameBuffer = 0xCA, - eCmdUnknownPowerViewCB = 0xCB, + eCmdPvReadConfig = 0xC8, + eCmdPvWriteConfig = 0xC9, + eCmdPvWriteFrameBuffer = 0xCA, + eCmdPvWriteColorPalette = 0xCB, eCmdUnknownPowerViewCC = 0xCC, }; diff --git a/src/raspberrypi/devices/scsi_powerview.cpp b/src/raspberrypi/devices/scsi_powerview.cpp index 1fb65bc5..8c9756bc 100644 --- a/src/raspberrypi/devices/scsi_powerview.cpp +++ b/src/raspberrypi/devices/scsi_powerview.cpp @@ -20,6 +20,7 @@ #include "scsi_powerview.h" #include +#include #include "exceptions.h" #include @@ -29,6 +30,7 @@ #include "disk.h" #include #include "log.h" +#include "controllers/scsidev_ctrl.h" static unsigned char reverse_table[256]; @@ -42,10 +44,14 @@ const BYTE SCSIPowerView::m_inquiry_response[] = { SCSIPowerView::SCSIPowerView() : Disk("SCPV") { - AddCommand(SCSIDEV::eCmdUnknownPowerViewC8, "Unknown PowerViewC8", &SCSIPowerView::UnknownCommandC8); - AddCommand(SCSIDEV::eCmdUnknownPowerViewC9, "Unknown PowerViewC9", &SCSIPowerView::UnknownCommandC9); - AddCommand(SCSIDEV::eCmdWriteFrameBuffer, "Unknown PowerViewCA", &SCSIPowerView::CmdWriteFramebuffer); - AddCommand(SCSIDEV::eCmdUnknownPowerViewCB, "Unknown PowerViewCB", &SCSIPowerView::UnknownCommandCB); + // AddCommand(SCSIDEV::eCmdPvReadConfig, "Read PowerView Config", &SCSIPowerView::CmdPvReadConfig); + // AddCommand(SCSIDEV::eCmdPvWriteConfig, "Write PowerView Config", &SCSIPowerView::CmdPvWriteConfig); + // AddCommand(SCSIDEV::eCmdPvWriteFrameBuffer, "Write Framebuffer", &SCSIPowerView::CmdWriteFramebuffer); + // AddCommand(SCSIDEV::eCmdPvWriteColorPalette, "Write Color Palette", &SCSIPowerView::CmdWriteColorPalette); + AddCommand(SCSIDEV::eCmdPvReadConfig, "Unknown PowerViewC8", &SCSIPowerView::CmdReadConfig); + AddCommand(SCSIDEV::eCmdPvWriteConfig, "Unknown PowerViewC9", &SCSIPowerView::CmdWriteConfig); + AddCommand(SCSIDEV::eCmdPvWriteFrameBuffer, "Unknown PowerViewCA", &SCSIPowerView::CmdWriteFramebuffer); + AddCommand(SCSIDEV::eCmdPvWriteColorPalette, "Unknown PowerViewCB", &SCSIPowerView::CmdWriteColorPalette); AddCommand(SCSIDEV::eCmdUnknownPowerViewCC, "Unknown PowerViewCC", &SCSIPowerView::UnknownCommandCC); struct fb_var_screeninfo fbinfo; @@ -100,6 +106,8 @@ SCSIPowerView::SCSIPowerView() : Disk("SCPV") this->m_powerview_resolution_x = 624; this->m_powerview_resolution_y = 840; + ClearFrameBuffer(); + } SCSIPowerView::~SCSIPowerView() @@ -110,7 +118,7 @@ SCSIPowerView::~SCSIPowerView() // delete m_tap; // } - munmap(this->fb, this->fbsize); + munmap(this->fb, this->fbsize); close(this->fbfd); for (auto const& command : commands) { @@ -124,6 +132,34 @@ void SCSIPowerView::AddCommand(SCSIDEV::scsi_command opcode, const char* name, v } +void SCSIPowerView::ClearFrameBuffer(){ + + + // For each row + for (DWORD idx_row_y = 0; idx_row_y < 800; idx_row_y++){ + + + // For each column + for (DWORD idx_col_x = 0; idx_col_x < 800; idx_col_x++){ + + // int loc = (col * (this->fbbpp / 8)) + (row * this->fblinelen); + uint32_t loc = ((idx_col_x) * (this->fbbpp / 8)) + ((idx_row_y) * fblinelen); + + // LOGDEBUG("!!! x:%d y:%d !! pix_idx:%06X pix_byte:%04X pix_bit:%02X pixel: %02X, loc:%08X",idx_col_x, idx_row_y, pixel_byte_idx, pixel_byte, pixel_bit, pixel, loc); + + *(this->fb + loc + 0) = 0xFF; + *(this->fb + loc + 1) = 0x00; + *(this->fb + loc + 2) = 0x00; + + // for(int i=0 ; i< (this->fbbpp/8); i++){ + // *(this->fb + loc + i) = 0xFF; + // } + } + } + + +} + void SCSIPowerView::dump_command(SASIDEV *controller){ LOGWARN(" %02X %02X %02X %02X %02X %02X %02X %02X [%02X] \n", @@ -145,10 +181,11 @@ void SCSIPowerView::dump_command(SASIDEV *controller){ //--------------------------------------------------------------------------- // -// Unknown Command C8 +// PowerView Read Configuration Parameter // //--------------------------------------------------------------------------- -void SCSIPowerView::UnknownCommandC8(SASIDEV *controller) +// void SCSIPowerView::CmdPvReadConfig(SASIDEV *controller) +void SCSIPowerView::CmdReadConfig(SASIDEV *controller) { // Set transfer amount @@ -162,9 +199,32 @@ void SCSIPowerView::UnknownCommandC8(SASIDEV *controller) return; } - ctrl->buffer[0] = 0x01; - ctrl->buffer[1] = 0x09; - ctrl->buffer[2] = 0x08; + // Response to "C8 00 00 31 83 00 01 00" is "00" + if(ctrl->cmd[4] == 0x83){ + + if(ctrl->length != 1){ + LOGWARN("%s Received unexpected length: %02X %02X %02X %02X %02X %02X", __PRETTY_FUNCTION__, ctrl->cmd[0], ctrl->cmd[1], ctrl->cmd[2], ctrl->cmd[3], ctrl->cmd[4], ctrl->cmd[5]); + } + } + // Response to "C8 00 00 31 00 00 03 00" is "01 09 08" + else if(ctrl->cmd[4] == 0x00){ + if(ctrl->length != 3){ + LOGWARN("%s Received unexpected length: %02X %02X %02X %02X %02X %02X", __PRETTY_FUNCTION__, ctrl->cmd[0], ctrl->cmd[1], ctrl->cmd[2], ctrl->cmd[3], ctrl->cmd[4], ctrl->cmd[5]); + } + } + // Response to "C8 00 00 31 82 00 01 00" is "01" + else if(ctrl->cmd[4] == 0x82){ + ctrl->buffer[0] = 0x01; + if(ctrl->length != 1){ + LOGWARN("%s Received unexpected length: %02X %02X %02X %02X %02X %02X", __PRETTY_FUNCTION__, ctrl->cmd[0], ctrl->cmd[1], ctrl->cmd[2], ctrl->cmd[3], ctrl->cmd[4], ctrl->cmd[5]); + } + } + else{ + LOGWARN("%s Unhandled command received: %02X %02X %02X %02X %02X %02X", __PRETTY_FUNCTION__, ctrl->cmd[0], ctrl->cmd[1], ctrl->cmd[2], ctrl->cmd[3], ctrl->cmd[4], ctrl->cmd[5]); + ctrl->buffer[0] = 0x00; + ctrl->buffer[1] = 0x00; + ctrl->buffer[2] = 0x00; + } // Set next block ctrl->blocks = 1; @@ -179,17 +239,18 @@ void SCSIPowerView::UnknownCommandC8(SASIDEV *controller) // Unknown Command C9 // //--------------------------------------------------------------------------- -void SCSIPowerView::UnknownCommandC9(SASIDEV *controller) +// void SCSIPowerView::CmdPvWriteConfig(SASIDEV *controller) +void SCSIPowerView::CmdWriteConfig(SASIDEV *controller) { // Set transfer amount ctrl->length = ctrl->cmd[6]; - LOGWARN("%s Message Length %d", __PRETTY_FUNCTION__, (int)ctrl->length); - dump_command(controller); + LOGTRACE("%s Message Length %d", __PRETTY_FUNCTION__, (int)ctrl->length); + // dump_command(controller); // LOGWARN("Controller: %08X ctrl: %08X", (DWORD)controller->GetCtrl(), (DWORD)ctrl); // if (ctrl->length <= 0) { // // Failure (Error) - // controller->Error(); + // controller->Error(); // return; // } @@ -233,21 +294,21 @@ void SCSIPowerView::CmdWriteFramebuffer(SASIDEV *controller) // else { // ctrl->length = ctrl->cmd[7] * 2; // } - LOGDEBUG("%s Message Length %d [%08X]", __PRETTY_FUNCTION__, (int)ctrl->length, (unsigned int)ctrl->length); - LOGDEBUG(" %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X [%02X %02X]\n", - ctrl->cmd[0], - ctrl->cmd[1], - ctrl->cmd[2], - ctrl->cmd[3], - ctrl->cmd[4], - ctrl->cmd[5], - ctrl->cmd[6], - ctrl->cmd[7], - ctrl->cmd[8], - ctrl->cmd[9], - ctrl->cmd[10], - ctrl->cmd[11], - ctrl->cmd[12]); + LOGTRACE("%s Message Length %d [%08X]", __PRETTY_FUNCTION__, (int)ctrl->length, (unsigned int)ctrl->length); + // LOGDEBUG(" %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X [%02X %02X]\n", + // ctrl->cmd[0], + // ctrl->cmd[1], + // ctrl->cmd[2], + // ctrl->cmd[3], + // ctrl->cmd[4], + // ctrl->cmd[5], + // ctrl->cmd[6], + // ctrl->cmd[7], + // ctrl->cmd[8], + // ctrl->cmd[9], + // ctrl->cmd[10], + // ctrl->cmd[11], + // ctrl->cmd[12]); if (ctrl->length <= 0) { @@ -269,14 +330,14 @@ void SCSIPowerView::CmdWriteFramebuffer(SASIDEV *controller) // Unknown Command CB // //--------------------------------------------------------------------------- -void SCSIPowerView::UnknownCommandCB(SASIDEV *controller) +void SCSIPowerView::CmdWriteColorPalette(SASIDEV *controller) { // Set transfer amount ctrl->length = ctrl->cmd[6]; ctrl->length = ctrl->length * 4; - LOGWARN("%s Message Length %d", __PRETTY_FUNCTION__, (int)ctrl->length); - dump_command(controller); + LOGTRACE("%s Message Length %d", __PRETTY_FUNCTION__, (int)ctrl->length); + // dump_command(controller); if (ctrl->length <= 0) { // Failure (Error) controller->Error(); @@ -302,8 +363,8 @@ void SCSIPowerView::UnknownCommandCC(SASIDEV *controller) // Set transfer amount // ctrl->length = ctrl->cmd[6]; ctrl->length = 0x8bb; - LOGWARN("%s Message Length %d", __PRETTY_FUNCTION__, (int)ctrl->length); - dump_command(controller); + LOGTRACE("%s Message Length %d", __PRETTY_FUNCTION__, (int)ctrl->length); + // dump_command(controller); if (ctrl->length <= 0) { // Failure (Error) controller->Error(); @@ -392,32 +453,6 @@ int SCSIPowerView::Inquiry(const DWORD *cdb, BYTE *buf) // // READ // -// Command: 08 00 00 LL LL XX (LLLL is data length, XX = c0 or 80) -// Function: Read a packet at a time from the device (standard SCSI Read) -// Type: Input; the following data is returned: -// LL LL NN NN NN NN XX XX XX ... CC CC CC CC -// where: -// LLLL is normally the length of the packet (a 2-byte -// big-endian hex value), including 4 trailing bytes -// of CRC, but excluding itself and the flag field. -// See below for special values -// NNNNNNNN is a 4-byte flag field with the following meanings: -// FFFFFFFF a packet has been dropped (?); in this case -// the length field appears to be always 4000 -// 00000010 there are more packets currently available -// in SCSI/Link memory -// 00000000 this is the last packet -// XX XX ... is the actual packet -// CCCCCCCC is the CRC -// -// Notes: -// - When all packets have been retrieved successfully, a length field -// of 0000 is returned; however, if a packet has been dropped, the -// SCSI/Link will instead return a non-zero length field with a flag -// of FFFFFFFF when there are no more packets available. This behaviour -// seems to continue until a disable/enable sequence has been issued. -// - The SCSI/Link apparently has about 6KB buffer space for packets. -// //--------------------------------------------------------------------------- int SCSIPowerView::Read(const DWORD *cdb, BYTE *buf, uint64_t block) { @@ -426,6 +461,50 @@ int SCSIPowerView::Read(const DWORD *cdb, BYTE *buf, uint64_t block) } +bool SCSIPowerView::WriteConfiguration(const DWORD *cdb, const BYTE *buf, const DWORD length) +{ + + std::stringstream ss; + ss << std::hex; + + for( DWORD i(0) ; i < length; ++i ){ + ss << std::setw(2) << std::setfill('0') << (int)buf[i]; + } + + LOGDEBUG("%s Received Config Write of length %d: %s",__PRETTY_FUNCTION__, length, ss.str().c_str()); + + return true; + +} + +bool SCSIPowerView::WriteUnknownCC(const DWORD *cdb, const BYTE *buf, const DWORD length) +{ + + if(length > sizeof(unknown_cc_data)){ + LOGERROR("%s Received Unknown CC data that is larger (%d bytes) than allocated size (%d bytes)", __PRETTY_FUNCTION__, length, sizeof(unknown_cc_data)); + return false; + } + + LOGINFO("%s Unknown CC of size %ul received", __PRETTY_FUNCTION__, length); + memcpy(unknown_cc_data, buf, length); + unknown_cc_data_length = length; + return true; +} + + +bool SCSIPowerView::WriteColorPalette(const DWORD *cdb, const BYTE *buf, const DWORD length) +{ + if(length > sizeof(color_palette)){ + LOGERROR("%s Received Color Palette that is larger (%d bytes) than allocated size (%d bytes)", __PRETTY_FUNCTION__, length, sizeof(color_palette)); + return false; + } + + LOGINFO("%s Color Palette of size %ul received", __PRETTY_FUNCTION__, length); + memcpy(color_palette, buf, length); + color_palette_length = length; + return true; +} + bool SCSIPowerView::WriteFrameBuffer(const DWORD *cdb, const BYTE *buf, const DWORD length) { @@ -454,7 +533,7 @@ bool SCSIPowerView::WriteFrameBuffer(const DWORD *cdb, const BYTE *buf, const DW uint32_t offset = (uint32_t)ctrl->cmd[3] + ((uint32_t)ctrl->cmd[2] << 8) + ((uint32_t)ctrl->cmd[1] << 16); - LOGDEBUG("%s act length %ul offset:%06X (%f) wid:%06X height:%06X", __PRETTY_FUNCTION__, length, offset, ((float)offset/(screen_width*screen_height)), update_width_x_bytes, update_height_y_bytes); + LOGDEBUG("%s act length %u offset:%06X (%f) wid:%06X height:%06X", __PRETTY_FUNCTION__, length, offset, ((float)offset/(screen_width*screen_height)), update_width_x_bytes, update_height_y_bytes); uint32_t offset_row = (uint32_t)((offset*8) / this->screen_width)/2; uint32_t offset_col = (uint32_t)(((offset*8)/2) % this->screen_width); @@ -487,56 +566,6 @@ bool SCSIPowerView::WriteFrameBuffer(const DWORD *cdb, const BYTE *buf, const DW } } - - // LOGWARN("%s start row: %06X col: %06X", __PRETTY_FUNCTION__, (unsigned int)offset_row, (unsigned int)offset_col); - - // for (DWORD pixel_x = offset_col; pixel_x < (offset_col + (update_width_x_bytes * 8)); offset_col++){ - // for (DWORD pixel_y = offset_row; pixel_y < offset_row + (update_height_y_bytes); offset_row++){ - - // BYTE pixel_byte = (pixel_y * update_height_y_bytes) + (pixel_x/8); - // int pixel_bit = (pixel_x % 8); - // pixel_value = ((buf[pixel_byte]) << pixel_bit) != 0; - - // int loc = (pixel_x * (this->fbbpp / 8)) + (pixel_y * m_powerview_resolution_x); - - // // int idx = (pixel_y * update_width_x_bytes * 8); - // // pixel_value = buf[] - - // *(this->fb + loc) = (pixel_bit) ? 0 : 255; - // *(this->fb + loc + 1) = (pixel_bit) ? 0 : 255; - // // *(this->fb + loc + 2) = (j & (1 << bit)) ? 0 : 255; - - - // } - - - // } - - - - - // for (DWORD i = 0; i < length; i++) { - // unsigned char j = reverse_table[buf[i]]; - - // for (int bit = 0; bit < 8; bit++) { - // int loc = (offset_col * (this->fbbpp / 8)) + (offset_row * this->fblinelen); - // offset_col++; - // // if (col % this->screen_width == 0) { - // if (offset_col % update_width_x == 0) { - // offset_col = 0; - // offset_row++; - // } - - // *(this->fb + loc) = (j & (1 << bit)) ? 0 : 255; - // *(this->fb + loc + 1) = (j & (1 << bit)) ? 0 : 255; - // *(this->fb + loc + 2) = (j & (1 << bit)) ? 0 : 255; - // } - // } - // } - - // catch(const exception& e) { - // LOGWARN("Exception!!!!!!!!!"); - // } return true; } diff --git a/src/raspberrypi/devices/scsi_powerview.h b/src/raspberrypi/devices/scsi_powerview.h index a988677b..0dfb6f8e 100644 --- a/src/raspberrypi/devices/scsi_powerview.h +++ b/src/raspberrypi/devices/scsi_powerview.h @@ -67,55 +67,35 @@ public: int Read(const DWORD *cdb, BYTE *buf, uint64_t block) override; bool Write(const DWORD *cdb, const BYTE *buf, const DWORD length); bool WriteFrameBuffer(const DWORD *cdb, const BYTE *buf, const DWORD length); - // int WriteCheck(DWORD block) override; // WRITE check - - // int RetrieveStats(const DWORD *cdb, BYTE *buffer); - // bool EnableInterface(const DWORD *cdb); - - // void SetMacAddr(const DWORD *cdb, BYTE *buffer); // Set MAC address - - - void UnknownCommandC8(SASIDEV *controller); - void UnknownCommandC9(SASIDEV *controller); + bool WriteColorPalette(const DWORD *cdb, const BYTE *buf, const DWORD length); + bool WriteConfiguration(const DWORD *cdb, const BYTE *buf, const DWORD length); + bool WriteUnknownCC(const DWORD *cdb, const BYTE *buf, const DWORD length); + + void CmdReadConfig(SASIDEV *controller); + void CmdWriteConfig(SASIDEV *controller); void CmdWriteFramebuffer(SASIDEV *controller); - void UnknownCommandCB(SASIDEV *controller); + void CmdWriteColorPalette(SASIDEV *controller); void UnknownCommandCC(SASIDEV *controller); - // void TestUnitReady(SASIDEV *) override; - // void Read6(SASIDEV *) override; - // void Write6(SASIDEV *) override; - // void RetrieveStatistics(SASIDEV *); - // void SetInterfaceMode(SASIDEV *); - // void SetMcastAddr(SASIDEV *); - // void EnableInterface(SASIDEV *); - bool Dispatch(SCSIDEV *) override; bool ReceiveBuffer(int len, BYTE *buffer); - // const int DAYNAPORT_BUFFER_SIZE = 0x1000000; - // static const BYTE CMD_SCSILINK_STATS = 0x09; - // static const BYTE CMD_SCSILINK_ENABLE = 0x0E; - // static const BYTE CMD_SCSILINK_SET = 0x0C; - // static const BYTE CMD_SCSILINK_SETMODE = 0x80; - // static const BYTE CMD_SCSILINK_SETMAC = 0x40; - - // // When we're reading the Linux tap device, most of the messages will not be for us, so we - // // need to filter through those. However, we don't want to keep re-reading the packets - // // indefinitely. So, we'll pick a large-ish number that will cause the emulated DaynaPort - // // to respond with "no data" after MAX_READ_RETRIES tries. - // static const int MAX_READ_RETRIES = 50; - - // // The READ response has a header which consists of: - // // 2 bytes - payload size - // // 4 bytes - status flags - // static const DWORD DAYNAPORT_READ_HEADER_SZ = 2 + 4; + void ClearFrameBuffer(); private: uint32_t screen_width; uint32_t screen_height; + // The maximum color depth is 16 bits + BYTE color_palette[0x10000]; + int color_palette_length = 0; + + BYTE unknown_cc_data[0x10000]; + int unknown_cc_data_length = 0; + + int fbfd; char *fb; int fbwidth; @@ -125,49 +105,4 @@ private: int fbbpp; static const BYTE m_inquiry_response[]; - // typedef struct __attribute__((packed)) { - // BYTE operation_code; - // BYTE misc_cdb_information; - // BYTE logical_block_address; - // uint16_t length; - // BYTE format; - // } scsi_cmd_daynaport_write_t; - - // enum read_data_flags_t : uint32_t { - // e_no_more_data = 0x00000000, - // e_more_data_available = 0x00000001, - // e_dropped_packets = 0xFFFFFFFF, - // }; - - // typedef struct __attribute__((packed)) { - // uint32_t length; - // read_data_flags_t flags; - // BYTE pad; - // BYTE data[ETH_FRAME_LEN + sizeof(uint32_t)]; // Frame length + 4 byte CRC - // } scsi_resp_read_t; - - // typedef struct __attribute__((packed)) { - // BYTE mac_address[6]; - // uint32_t frame_alignment_errors; - // uint32_t crc_errors; - // uint32_t frames_lost; - // } scsi_resp_link_stats_t; - - // scsi_resp_link_stats_t m_scsi_link_stats = { - // .mac_address = { 0x00, 0x80, 0x19, 0x10, 0x98, 0xE3 },//MAC address of @PotatoFi's DayanPort - // .frame_alignment_errors = 0, - // .crc_errors = 0, - // .frames_lost = 0, - // }; - - // const BYTE m_daynacom_mac_prefix[3] = { 0x00, 0x80, 0x19 }; - - // CTapDriver *m_tap; - // // TAP driver - // bool m_bTapEnable; - // // TAP valid flag - // BYTE m_mac_addr[6]; - // // MAC Address - // static const BYTE m_bcast_addr[6]; - // static const BYTE m_apple_talk_addr[6]; };