From 3f279230d9356ac8a2274133dfbcf187b0ef79e8 Mon Sep 17 00:00:00 2001 From: Troy Date: Thu, 8 Sep 2022 22:02:55 -0400 Subject: [PATCH] cleanup Apple Mode Page handling --- src/BlueSCSI.cpp | 50 ++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/src/BlueSCSI.cpp b/src/BlueSCSI.cpp index 991364d..e9f244c 100644 --- a/src/BlueSCSI.cpp +++ b/src/BlueSCSI.cpp @@ -1520,6 +1520,7 @@ byte onVerify(SCSI_DEVICE *dev, const byte *cdb) */ byte onModeSense(SCSI_DEVICE *dev, const byte *cdb) { + const byte apple_magic[] = "APPLE COMPUTER, INC "; int pageCode = cdb[2] & 0x3F; int pageControl = cdb[2] >> 6; byte dbd = cdb[1] & 0x8; @@ -1633,18 +1634,12 @@ byte onModeSense(SCSI_DEVICE *dev, const byte *cdb) if(pageCode != SCSI_SENSE_MODE_ALL) break; case SCSI_SENSE_MODE_VENDOR_APPLE: { - const byte apple_magic[0x24] = { - 0x23, - 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x08, 0x00, 0x30, 0x16, 0x41, 0x50, 0x50, - 0x4C, 0x45, 0x20, 0x43, 0x4F, 0x4D, 0x50, 0x55, - 0x54, 0x45, 0x52, 0x2C, 0x20, 0x49, 0x4E, 0x43, - 0x20, 0x20, 0x20 - }; if(pageControl != 1) { - memcpy(&m_buf[0], apple_magic, sizeof(apple_magic)); + m_buf[a + 0] = SCSI_SENSE_MODE_VENDOR_APPLE; + m_buf[a + 1] = sizeof(apple_magic); // Page length + memcpy(&m_buf[a + 2], apple_magic, sizeof(apple_magic)); + a += sizeof(apple_magic) + 2; } - a = sizeof(apple_magic); if(pageCode != SCSI_SENSE_MODE_ALL) break; } break; // Don't want SCSI_SENSE_MODE_ALL falling through to error condition @@ -1701,18 +1696,12 @@ byte onModeSense(SCSI_DEVICE *dev, const byte *cdb) case SCSI_SENSE_MODE_VENDOR_APPLE: { - const byte apple_magic[0x24] = { - 0x23, - 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x08, 0x00, 0x30, 0x16, 0x41, 0x50, 0x50, - 0x4C, 0x45, 0x20, 0x43, 0x4F, 0x4D, 0x50, 0x55, - 0x54, 0x45, 0x52, 0x2C, 0x20, 0x49, 0x4E, 0x43, - 0x20, 0x20, 0x20 - }; if(pageControl != 1) { - memcpy(&m_buf[0], apple_magic, sizeof(apple_magic)); + m_buf[a + 0] = SCSI_SENSE_MODE_VENDOR_APPLE; + m_buf[a + 1] = sizeof(apple_magic); // Page length + memcpy(&m_buf[a + 2], apple_magic, sizeof(apple_magic)); + a += sizeof(apple_magic) + 2; } - a = sizeof(apple_magic); if(pageCode != SCSI_SENSE_MODE_ALL) break; } break; // Don't want SCSI_SENSE_MODE_ALL falling through to error condition @@ -1724,17 +1713,16 @@ byte onModeSense(SCSI_DEVICE *dev, const byte *cdb) break; } } - if(pageCode != SCSI_SENSE_MODE_VENDOR_APPLE) { - if(cdb[0] == SCSI_MODE_SENSE10) - { - m_buf[1] = a - 2; - m_buf[7] = block_descriptor_length; // block descriptor length - } - else - { - m_buf[0] = a - 1; - m_buf[3] = block_descriptor_length; // block descriptor length - } + + if(cdb[0] == SCSI_MODE_SENSE10) + { + m_buf[1] = a - 2; + m_buf[7] = block_descriptor_length; // block descriptor length + } + else + { + m_buf[0] = a - 1; + m_buf[3] = block_descriptor_length; // block descriptor length } writeDataPhase(length < a ? length : a, m_buf);