| 1 | #include "VDPCommandRegViewer.h" |
| 2 | #include "CommClient.h" |
| 3 | |
| 4 | VDPCommandRegViewer::VDPCommandRegViewer(QWidget* parent) |
| 5 | : QDialog(parent) |
| 6 | { |
| 7 | setupUi(this); |
| 8 | statusregs = regs + 64; |
| 9 | |
| 10 | connect(lineEdit_r44, &QLineEdit::editingFinished, this, &VDPCommandRegViewer::on_lineEdit_r44_editingFinished); |
| 11 | connect(lineEdit_r45, &QLineEdit::editingFinished, this, &VDPCommandRegViewer::on_lineEdit_r45_editingFinished); |
| 12 | connect(lineEdit_r46, &QLineEdit::editingFinished, this, &VDPCommandRegViewer::on_lineEdit_r46_editingFinished); |
| 13 | connect(comboBox_cmd, qOverload<int>(&QComboBox::currentIndexChanged), this, &VDPCommandRegViewer::on_comboBox_cmd_currentIndexChanged); |
| 14 | connect(comboBox_operator, qOverload<int>(&QComboBox::currentIndexChanged), this, &VDPCommandRegViewer::on_comboBox_operator_currentIndexChanged); |
| 15 | connect(syncPushButton, &QPushButton::clicked, this, &VDPCommandRegViewer::on_syncPushButton_clicked); |
| 16 | connect(launchPushButton, &QPushButton::clicked, this, &VDPCommandRegViewer::on_launchPushButton_clicked); |
| 17 | |
| 18 | // create the needed groups |
| 19 | grp_sx = new view88to16(lineEdit_r32, lineEdit_r33, lineEdit_sx); |
| 20 | connect(lineEdit_r32, &QLineEdit::editingFinished, grp_sx, &view88to16::finishRL); |
| 21 | connect(lineEdit_r33, &QLineEdit::editingFinished, grp_sx, &view88to16::finishRH); |
| 22 | connect(lineEdit_sx, &QLineEdit::editingFinished, grp_sx, &view88to16::finishRW); |
| 23 | grp_sy = new view88to16(lineEdit_r34, lineEdit_r35, lineEdit_sy); |
| 24 | connect(lineEdit_r34, &QLineEdit::editingFinished, grp_sy, &view88to16::finishRL); |
| 25 | connect(lineEdit_r35, &QLineEdit::editingFinished, grp_sy, &view88to16::finishRH); |
| 26 | connect(lineEdit_sy, &QLineEdit::editingFinished, grp_sy, &view88to16::finishRW); |
| 27 | grp_dx = new view88to16(lineEdit_r36, lineEdit_r37, lineEdit_dx); |
| 28 | connect(lineEdit_r36, &QLineEdit::editingFinished, grp_dx, &view88to16::finishRL); |
| 29 | connect(lineEdit_r37, &QLineEdit::editingFinished, grp_dx, &view88to16::finishRH); |
| 30 | connect(lineEdit_dx, &QLineEdit::editingFinished, grp_dx, &view88to16::finishRW); |
| 31 | grp_dy = new view88to16(lineEdit_r38, lineEdit_r39, lineEdit_dy); |
| 32 | connect(lineEdit_r38, &QLineEdit::editingFinished, grp_dy, &view88to16::finishRL); |
| 33 | connect(lineEdit_r39, &QLineEdit::editingFinished, grp_dy, &view88to16::finishRH); |
| 34 | connect(lineEdit_dy, &QLineEdit::editingFinished, grp_dy, &view88to16::finishRW); |
| 35 | grp_nx = new view88to16(lineEdit_r40, lineEdit_r41, lineEdit_nx); |
| 36 | connect(lineEdit_r40, &QLineEdit::editingFinished, grp_nx, &view88to16::finishRL); |
| 37 | connect(lineEdit_r41, &QLineEdit::editingFinished, grp_nx, &view88to16::finishRH); |
| 38 | connect(lineEdit_nx, &QLineEdit::editingFinished, grp_nx, &view88to16::finishRW); |
| 39 | grp_ny = new view88to16(lineEdit_r42, lineEdit_r43, lineEdit_ny); |
| 40 | connect(lineEdit_r42, &QLineEdit::editingFinished, grp_ny, &view88to16::finishRL); |
| 41 | connect(lineEdit_r43, &QLineEdit::editingFinished, grp_ny, &view88to16::finishRH); |
| 42 | connect(lineEdit_ny, &QLineEdit::editingFinished, grp_ny, &view88to16::finishRW); |
| 43 | |
| 44 | grp_sx->setRW(QString("0")); |
| 45 | grp_sy->setRW(QString("0")); |
| 46 | grp_dx->setRW(QString("0")); |
| 47 | grp_dy->setRW(QString("0")); |
| 48 | grp_nx->setRW(QString("0")); |
| 49 | grp_ny->setRW(QString("0")); |
| 50 | |
| 51 | grp_l_sx = new view88to16(label_r_32, label_r_33, label_r_sx); |
| 52 | grp_l_sy = new view88to16(label_r_34, label_r_35, label_r_sy); |
| 53 | grp_l_dx = new view88to16(label_r_36, label_r_37, label_r_dx); |
| 54 | grp_l_dy = new view88to16(label_r_38, label_r_39, label_r_dy); |
| 55 | grp_l_nx = new view88to16(label_r_40, label_r_41, label_r_nx); |
| 56 | grp_l_ny = new view88to16(label_r_42, label_r_43, label_r_ny); |
| 57 | |
| 58 | //Connect the checkboxes |
| 59 | QList<QCheckBox*> list = this->findChildren<QCheckBox*>(); |
| 60 | for (auto* item : list) { |
| 61 | connect(item, &QCheckBox::stateChanged, |
| 62 | this, &VDPCommandRegViewer::R45BitChanged); |
| 63 | } |
| 64 | |
| 65 | lineEdit_r44->setText(hexValue(0, 2)); |
| 66 | lineEdit_r45->setText(hexValue(0, 2)); |
| 67 | lineEdit_r46->setText(hexValue(0, 2)); |
| 68 | R46 = 0; |
| 69 | comboBox_cmd->setCurrentIndex(0); |
| 70 | //decodeR46(R46); |
| 71 | //on_comboBox_cmd_currentIndexChanged(); |
| 72 | |
| 73 | //get initiale data |
| 74 | refresh(); |
| 75 | } |
| 76 | |
| 77 | void VDPCommandRegViewer::on_lineEdit_r45_editingFinished() |
| 78 | { |
| 79 | //for now simply recheck all the checkBoxes and recreate R45 |
| 80 | auto val = stringToValue<int>(lineEdit_r45->text()); |
| 81 | int r45 = 0; |
| 82 | for (auto* item : findChildren<QCheckBox*>()) { |
| 83 | int order = QString(item->objectName().right(1)).toInt(); |
| 84 | if (val && *val & (1 << order)) { |
| 85 | r45 = r45 | (1 << order); |
| 86 | item->setChecked(true); |
| 87 | } else { |
| 88 | item->setChecked(false); |
| 89 | } |
| 90 | } |
| 91 | lineEdit_r45->setText(hexValue(r45, 2)); |
| 92 | label_arg->setText(QString("%1").arg(r45, 8, 2, QChar('0'))); |
| 93 | } |
| 94 | |
| 95 | void VDPCommandRegViewer::on_comboBox_cmd_currentIndexChanged(int index) |
| 96 | { |
| 97 | if ((index < 7 || index > 9) && index != 11 && index != 5) { |
| 98 | comboBox_operator->setEnabled(false); |
| 99 | comboBox_operator->setCurrentIndex(5); |
| 100 | } else { |
| 101 | if (!comboBox_operator->isEnabled()) { |
| 102 | comboBox_operator->setCurrentIndex(R46 & 15); |
| 103 | } |
| 104 | comboBox_operator->setEnabled(true); |
| 105 | } |
| 106 | R46 = (15 & R46) + 16 * index; |
| 107 | decodeR46(R46); |
| 108 | lineEdit_r46->setText(hexValue(R46, 2)); |
| 109 | } |
| 110 | |
| 111 | void VDPCommandRegViewer::on_comboBox_operator_currentIndexChanged(int index) |
| 112 | { |
| 113 | //if the cmd disables the combox then no influence on R45 |
| 114 | if (!comboBox_operator->isEnabled()) return; |
| 115 | |
| 116 | R46 = index + (R46 & 0xF0); |
| 117 | decodeR46(R46); |
| 118 | lineEdit_r46->setText(hexValue(R46, 2)); |
| 119 | } |
| 120 | |
| 121 | void VDPCommandRegViewer::decodeR46(int val) |
| 122 | { |
| 123 | static const QString words[16] = { |
| 124 | "-", "VDP", "VRAM", "CPU", "Byte", "Dot", "Stop", "Invalid", |
| 125 | "Point", "Pset", "Search", "Line", "Logical move", "High-speed move" |
| 126 | }; |
| 127 | static const int dest[16] = { |
| 128 | 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2 //refers to words |
| 129 | }; |
| 130 | static const int srce[16] = { |
| 131 | 0, 0, 0, 0, 2, 1, 1, 1, 1, 2, 2, 3, 1, 2, 2, 3 //refers to words |
| 132 | }; |
| 133 | static const int data[16] = { |
| 134 | 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4 //refers to words |
| 135 | }; |
| 136 | static const int cnam[16] = { |
| 137 | 6, 7, 7, 7, 8, 9,10,11,12,12,12,12,13,13,13,13 //refers to words |
| 138 | }; |
| 139 | static const QString oper[16] = { |
| 140 | "IMP", "AND", "OR", "EOR", "NOT", "---", "---", "---", |
| 141 | "TIMP", "TAND", "TOR", "TEOR", "TNOT", "---", "---", "---", |
| 142 | }; |
| 143 | static const int argbold[16] = { |
| 144 | 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x26, 0x2D, |
| 145 | 0x2C, 0x2C, 0x1C, 0x2C, 0x2C, 0x3C, 0x2C, 0x2C, |
| 146 | }; |
| 147 | static const int regbold[16] = { |
| 148 | 0x00, 0x00, 0x00, 0x00, 0x83, 0xCC, 0xC3, 0xFC, |
| 149 | 0xFC, 0xBF, 0xB3, 0xFC, 0xFC, 0xBF, 0xAE, 0xFC, |
| 150 | }; |
| 151 | |
| 152 | int operat = (val >> 0) & 15; |
| 153 | int cmd = (val >> 4) & 15; |
| 154 | |
| 155 | QString explication = QString( |
| 156 | "Command: <b>%1</b> " |
| 157 | "Destination: <b>%2</b> " |
| 158 | "Source: <b>%3</b><br>" |
| 159 | "Data: <b>%4</b> " |
| 160 | "Operation: <b>%5</b>"). |
| 161 | arg(words[cnam[cmd]]). |
| 162 | arg(words[dest[cmd]]). |
| 163 | arg(words[srce[cmd]]). |
| 164 | arg(words[data[cmd]]). |
| 165 | arg(oper[operat]); |
| 166 | label_expl1->setText(explication); |
| 167 | |
| 168 | //a Normal and a Bold font |
| 169 | QFont fontN; |
| 170 | QFont fontB; |
| 171 | fontB.setBold(true); |
| 172 | //set the checkbox font in bold if command uses the corresponding bit |
| 173 | for (int b = 0; b < 7; ++b) { |
| 174 | auto* item = findChild<QCheckBox*>(QString("checkBoxBit_%1").arg(b)); |
| 175 | item->setFont((argbold[cmd] & (1 << b)) ? fontB : fontN); |
| 176 | } |
| 177 | labelSX ->setFont((regbold[cmd] & 0x01) ? fontB : fontN); |
| 178 | labelSY ->setFont((regbold[cmd] & 0x02) ? fontB : fontN); |
| 179 | labelDX ->setFont((regbold[cmd] & 0x04) ? fontB : fontN); |
| 180 | labelDY ->setFont((regbold[cmd] & 0x08) ? fontB : fontN); |
| 181 | labelNX ->setFont((regbold[cmd] & 0x10) ? fontB : fontN); |
| 182 | labelNY ->setFont((regbold[cmd] & 0x20) ? fontB : fontN); |
| 183 | labelCOLOR->setFont((regbold[cmd] & 0x40) ? fontB : fontN); |
| 184 | labelARG ->setFont((regbold[cmd] & 0x80) ? fontB : fontN); |
| 185 | |
| 186 | //TODO: create basic equivalent |
| 187 | //TODO: warn about wrong stuff (majorant < minorant when line drawing for instance) |
| 188 | } |
| 189 | |
| 190 | void VDPCommandRegViewer::on_syncPushButton_clicked() |
| 191 | { |
| 192 | syncRegToCmd(); |
| 193 | } |
| 194 | |
| 195 | void VDPCommandRegViewer::on_launchPushButton_clicked() |
| 196 | { |
| 197 | uint8_t newregs[64] = {}; |
| 198 | newregs[32] = stringToValue<uint8_t>(lineEdit_r32->text()).value_or(255); |
| 199 | newregs[33] = stringToValue<uint8_t>(lineEdit_r33->text()).value_or(255); |
| 200 | newregs[34] = stringToValue<uint8_t>(lineEdit_r34->text()).value_or(255); |
| 201 | newregs[35] = stringToValue<uint8_t>(lineEdit_r35->text()).value_or(255); |
| 202 | newregs[36] = stringToValue<uint8_t>(lineEdit_r36->text()).value_or(255); |
| 203 | newregs[37] = stringToValue<uint8_t>(lineEdit_r37->text()).value_or(255); |
| 204 | newregs[38] = stringToValue<uint8_t>(lineEdit_r38->text()).value_or(255); |
| 205 | newregs[39] = stringToValue<uint8_t>(lineEdit_r39->text()).value_or(255); |
| 206 | newregs[40] = stringToValue<uint8_t>(lineEdit_r40->text()).value_or(255); |
| 207 | newregs[41] = stringToValue<uint8_t>(lineEdit_r41->text()).value_or(255); |
| 208 | newregs[42] = stringToValue<uint8_t>(lineEdit_r42->text()).value_or(255); |
| 209 | newregs[43] = stringToValue<uint8_t>(lineEdit_r43->text()).value_or(255); |
| 210 | newregs[44] = stringToValue<uint8_t>(lineEdit_r44->text()).value_or(255); |
| 211 | newregs[45] = stringToValue<uint8_t>(lineEdit_r45->text()).value_or(255); |
| 212 | newregs[46] = stringToValue<uint8_t>(lineEdit_r46->text()).value_or(255); |
| 213 | |
| 214 | auto* req = new WriteDebugBlockCommand("{VDP regs}", 32, 15, newregs); |
| 215 | CommClient::instance().sendCommand(req); |
| 216 | } |
| 217 | |
| 218 | void VDPCommandRegViewer::on_lineEdit_r44_editingFinished() |
| 219 | { |
| 220 | auto val = stringToValue<int>(lineEdit_r44->text()); |
| 221 | label_color->setText(QString("%1 %2"). |
| 222 | arg((val.value_or(-1) >> 4) & 15, 4, 2, QChar('0')). |
| 223 | arg((val.value_or(-1) >> 0) & 15, 4, 2, QChar('0'))); |
| 224 | } |
| 225 | |
| 226 | void VDPCommandRegViewer::R45BitChanged(int /*state*/) |
| 227 | { |
| 228 | //for now simply recheck all the checkBoxes and recreate R45 |
| 229 | int r45 = 0; |
| 230 | for (auto* item : findChildren<QCheckBox*>()) { |
| 231 | if (item->isChecked()) { |
| 232 | int order = QString(item->objectName().right(1)).toInt(); |
| 233 | r45 = r45 | (1 << order); |
| 234 | } |
| 235 | } |
| 236 | lineEdit_r45->setText(hexValue(r45, 2)); |
| 237 | label_arg->setText(QString("%1").arg(r45, 8, 2, QChar('0'))); |
| 238 | } |
| 239 | |
| 240 | void VDPCommandRegViewer::on_lineEdit_r46_editingFinished() |
| 241 | { |
| 242 | if (auto val = stringToValue<uint8_t>(lineEdit_r46->text())) { |
| 243 | lineEdit_r46->setText(hexValue(*val, 2)); |
| 244 | R46 = *val; |
| 245 | decodeR46(R46); |
| 246 | comboBox_operator->setCurrentIndex(R46 & 15); |
| 247 | comboBox_cmd->setCurrentIndex((R46 >> 4) & 15); // this might hide the operator again :-) |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | void VDPCommandRegViewer::refresh() |
| 252 | { |
| 253 | //new SimpleHexRequest("{VDP regs}",0,64,regs, *this); |
| 254 | //new SimpleHexRequest("{VDP status regs}",0,16,regs, *this); |
| 255 | // now combined in one request: |
| 256 | new SimpleHexRequest( |
| 257 | "debug_bin2hex " |
| 258 | "[ debug read_block {VDP regs} 0 64 ]" |
| 259 | "[ debug read_block {VDP status regs} 0 16 ]", |
| 260 | 64 + 16, regs, *this); |
| 261 | } |
| 262 | |
| 263 | |
| 264 | void VDPCommandRegViewer::syncRegToCmd() |
| 265 | { |
| 266 | grp_sx->setRL(hexValue(regs[32], 2)); |
| 267 | grp_sx->setRH(hexValue(regs[33], 2)); |
| 268 | grp_sy->setRL(hexValue(regs[34], 2)); |
| 269 | grp_sy->setRH(hexValue(regs[35], 2)); |
| 270 | grp_dx->setRL(hexValue(regs[36], 2)); |
| 271 | grp_dx->setRH(hexValue(regs[37], 2)); |
| 272 | grp_dy->setRL(hexValue(regs[38], 2)); |
| 273 | grp_dy->setRH(hexValue(regs[39], 2)); |
| 274 | grp_nx->setRL(hexValue(regs[40], 2)); |
| 275 | grp_nx->setRH(hexValue(regs[41], 2)); |
| 276 | grp_ny->setRL(hexValue(regs[42], 2)); |
| 277 | grp_ny->setRH(hexValue(regs[43], 2)); |
| 278 | |
| 279 | lineEdit_r44->setText(hexValue(regs[44], 2)); |
| 280 | on_lineEdit_r44_editingFinished(); |
| 281 | lineEdit_r45->setText(hexValue(regs[45], 2)); |
| 282 | on_lineEdit_r45_editingFinished(); |
| 283 | lineEdit_r46->setText(hexValue(regs[46], 2)); |
| 284 | on_lineEdit_r46_editingFinished(); |
| 285 | } |
| 286 | |
| 287 | void VDPCommandRegViewer::DataHexRequestReceived() |
| 288 | { |
| 289 | grp_l_sx->setRL(hexValue(regs[32], 2)); |
| 290 | grp_l_sx->setRH(hexValue(regs[33], 2)); |
| 291 | grp_l_sy->setRL(hexValue(regs[34], 2)); |
| 292 | grp_l_sy->setRH(hexValue(regs[35], 2)); |
| 293 | grp_l_dx->setRL(hexValue(regs[36], 2)); |
| 294 | grp_l_dx->setRH(hexValue(regs[37], 2)); |
| 295 | grp_l_dy->setRL(hexValue(regs[38], 2)); |
| 296 | grp_l_dy->setRH(hexValue(regs[39], 2)); |
| 297 | grp_l_nx->setRL(hexValue(regs[40], 2)); |
| 298 | grp_l_nx->setRH(hexValue(regs[41], 2)); |
| 299 | grp_l_ny->setRL(hexValue(regs[42], 2)); |
| 300 | grp_l_ny->setRH(hexValue(regs[43], 2)); |
| 301 | label_r_44->setText(hexValue(regs[44], 2)); |
| 302 | label_r_45->setText(hexValue(regs[45], 2)); |
| 303 | label_r_46->setText(hexValue(regs[46], 2)); |
| 304 | if (autoSyncRadioButton->isChecked()) syncRegToCmd(); |
| 305 | } |