| 1 | #include "VDPDataStore.h" |
| 2 | #include "CommClient.h" |
| 3 | |
| 4 | // static vector to feed PaletteDialog and be used when VDP colors aren't selected |
| 5 | static const uint8_t defaultPalette[32] = { |
| 6 | // RB G |
| 7 | 0x00, 0, |
| 8 | 0x00, 0, |
| 9 | 0x11, 6, |
| 10 | 0x33, 7, |
| 11 | 0x17, 1, |
| 12 | 0x27, 3, |
| 13 | 0x51, 1, |
| 14 | 0x27, 6, |
| 15 | 0x71, 1, |
| 16 | 0x73, 3, |
| 17 | 0x61, 6, |
| 18 | 0x64, 6, |
| 19 | 0x11, 4, |
| 20 | 0x65, 2, |
| 21 | 0x55, 5, |
| 22 | 0x77, 7, |
| 23 | }; |
| 24 | |
| 25 | class VDPDataStoreVersionCheck : public SimpleCommand |
| 26 | { |
| 27 | public: |
| 28 | VDPDataStoreVersionCheck(VDPDataStore& dataStore_) |
| 29 | : SimpleCommand("debug desc {physical VRAM}") |
| 30 | , dataStore(dataStore_) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | void replyOk(const QString& /*message*/) override |
| 35 | { |
| 36 | dataStore.debuggableNameVRAM = "physical VRAM"; |
| 37 | dataStore.refresh(); |
| 38 | delete this; |
| 39 | } |
| 40 | void replyNok(const QString& /*message*/) override |
| 41 | { |
| 42 | dataStore.debuggableNameVRAM = "VRAM"; |
| 43 | dataStore.refresh(); |
| 44 | delete this; |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | VDPDataStore& dataStore; |
| 49 | }; |
| 50 | |
| 51 | class VDPDataStoreVRAMSizeCheck : public SimpleCommand |
| 52 | { |
| 53 | public: |
| 54 | VDPDataStoreVRAMSizeCheck(VDPDataStore& dataStore_) |
| 55 | : SimpleCommand("debug size {" + QString::fromStdString(*dataStore_.debuggableNameVRAM) + "}") |
| 56 | , dataStore(dataStore_) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | void replyOk(const QString& message) override |
| 61 | { |
| 62 | //printf("dataStore.vramSize %i\n",dataStore.vramSize); |
| 63 | dataStore.vramSize = message.toInt(); |
| 64 | //printf("dataStore.vramSize %i\n",dataStore.vramSize); |
| 65 | dataStore.refresh2(); |
| 66 | delete this; |
| 67 | } |
| 68 | void replyNok(const QString& /*message*/) override |
| 69 | { |
| 70 | delete this; |
| 71 | } |
| 72 | |
| 73 | private: |
| 74 | VDPDataStore& dataStore; |
| 75 | }; |
| 76 | |
| 77 | class VDPDataStoreDebuggableChecks : public SimpleCommand |
| 78 | { |
| 79 | public: |
| 80 | VDPDataStoreDebuggableChecks(VDPDataStore& dataStore_) |
| 81 | : SimpleCommand("debug_check_debuggables {{VDP register latch status} {VDP palette latch status} " |
| 82 | "{VDP data latch value} {VRAM access status}}") |
| 83 | , dataStore(dataStore_) |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | void replyOk(const QString& message) override |
| 88 | { |
| 89 | assert(message.size() == 7); |
| 90 | QStringList s = message.split(' '); |
| 91 | dataStore.registerLatchAvailable = s[0] == '1'; |
| 92 | dataStore.paletteLatchAvailable = s[1] == '1'; |
| 93 | dataStore.dataLatchAvailable = s[2] == '1'; |
| 94 | dataStore.vramAccessStatusAvailable = s[3] == '1'; |
| 95 | dataStore.refresh3(); |
| 96 | delete this; |
| 97 | } |
| 98 | void replyNok(const QString& /*message*/) override |
| 99 | { |
| 100 | dataStore.refresh3(); |
| 101 | delete this; |
| 102 | } |
| 103 | |
| 104 | private: |
| 105 | VDPDataStore& dataStore; |
| 106 | }; |
| 107 | |
| 108 | static constexpr unsigned MAX_VRAM_SIZE = 0x30000; |
| 109 | static constexpr unsigned MAX_TOTAL_SIZE = MAX_VRAM_SIZE + 32 + 16 + 64 + 2 + 3 + 1; |
| 110 | |
| 111 | VDPDataStore::VDPDataStore() |
| 112 | : vram(MAX_TOTAL_SIZE) |
| 113 | { |
| 114 | CommClient::instance().sendCommand(new VDPDataStoreVersionCheck(*this)); |
| 115 | } |
| 116 | |
| 117 | VDPDataStore& VDPDataStore::instance() |
| 118 | { |
| 119 | static VDPDataStore oneInstance; |
| 120 | return oneInstance; |
| 121 | } |
| 122 | |
| 123 | void VDPDataStore::refresh() |
| 124 | { |
| 125 | if (!debuggableNameVRAM) { |
| 126 | // This can happen when the data store was used before |
| 127 | // connecting to openMSX |
| 128 | CommClient::instance().sendCommand(new |
| 129 | VDPDataStoreVersionCheck(*this)); |
| 130 | } else { |
| 131 | refresh1(); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void VDPDataStore::refresh1() |
| 136 | { |
| 137 | CommClient::instance().sendCommand(new VDPDataStoreVRAMSizeCheck(*this)); |
| 138 | } |
| 139 | |
| 140 | void VDPDataStore::refresh2() |
| 141 | { |
| 142 | CommClient::instance().sendCommand(new VDPDataStoreDebuggableChecks(*this)); |
| 143 | } |
| 144 | |
| 145 | void VDPDataStore::refresh3() |
| 146 | { |
| 147 | QString req = QString( |
| 148 | "debug_bin2hex " |
| 149 | "[debug read_block {" + QString::fromStdString(*debuggableNameVRAM) + "} 0 " + QString::number(vramSize) + "]" |
| 150 | "[debug read_block {VDP palette} 0 32]" |
| 151 | "[debug read_block {VDP status regs} 0 16]" |
| 152 | "[debug read_block {VDP regs} 0 64]" |
| 153 | "[debug read_block {VRAM pointer} 0 2]%1%2%3%4") |
| 154 | .arg(registerLatchAvailable ? "[debug read_block {VDP register latch status} 0 1]" : "") |
| 155 | .arg(paletteLatchAvailable ? "[debug read_block {VDP palette latch status} 0 1]" : "") |
| 156 | .arg(dataLatchAvailable ? "[debug read_block {VDP data latch value} 0 1]" : "") |
| 157 | .arg(vramAccessStatusAvailable ? "[debug read_block {VRAM access status} 0 1]" : ""); |
| 158 | |
| 159 | int total = MAX_TOTAL_SIZE - MAX_VRAM_SIZE + vramSize - !registerLatchAvailable |
| 160 | - !paletteLatchAvailable - !dataLatchAvailable - !vramAccessStatusAvailable; |
| 161 | new SimpleHexRequest(req, total, &vram[0], *this); |
| 162 | } |
| 163 | |
| 164 | void VDPDataStore::DataHexRequestReceived() |
| 165 | { |
| 166 | emit dataRefreshed(); |
| 167 | } |
| 168 | |
| 169 | const uint8_t* VDPDataStore::getVramPointer() const |
| 170 | { |
| 171 | return &vram[0]; |
| 172 | } |
| 173 | const uint8_t* VDPDataStore::getDefaultPalettePointer() const |
| 174 | { |
| 175 | return defaultPalette; |
| 176 | } |
| 177 | const uint8_t* VDPDataStore::getPalettePointer() const |
| 178 | { |
| 179 | return &vram[vramSize]; |
| 180 | } |
| 181 | const uint8_t* VDPDataStore::getStatusRegsPointer() const |
| 182 | { |
| 183 | return &vram[vramSize + 32]; |
| 184 | } |
| 185 | const uint8_t* VDPDataStore::getRegsPointer() const |
| 186 | { |
| 187 | return &vram[vramSize + 32 + 16]; |
| 188 | } |
| 189 | const uint8_t* VDPDataStore::getVdpVramPointer() const |
| 190 | { |
| 191 | return &vram[vramSize + 32 + 16 + 64]; |
| 192 | } |
| 193 | |
| 194 | size_t VDPDataStore::getVRAMSize() const |
| 195 | { |
| 196 | return vramSize; |
| 197 | } |