From 4367cbe489d6bc4de3bdcc0ca113de8401aa6b9c Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 20 Mar 2022 12:30:08 +0100 Subject: [PATCH] -d switch --- cpu.cpp | 22 ++++++++++++++-------- cpu.h | 5 ++++- main.cpp | 11 ++++++++--- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/cpu.cpp b/cpu.cpp index 573b6f5..fa0fbdf 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -30,6 +30,11 @@ void cpu::reset() runMode = resetFlag = haltFlag = false; } +void cpu::setDisassemble(const bool state) +{ + disas = state; +} + uint16_t cpu::getRegister(const int nr, const bool prev_mode) const { if (nr < 6) @@ -295,15 +300,15 @@ bool cpu::double_operand_instructions(const uint16_t instr) if (operation == 0b111) return additional_double_operand_instructions(instr); - const uint8_t src = (instr >> 6) & 63; - const uint8_t src_mode = (src >> 3) & 7; - const uint8_t src_reg = src & 7; + const uint8_t src = (instr >> 6) & 63; + const uint8_t src_mode = (src >> 3) & 7; + const uint8_t src_reg = src & 7; - uint16_t src_value; + uint16_t src_value = 0; - const uint8_t dst = instr & 63; - const uint8_t dst_mode = (dst >> 3) & 7; - const uint8_t dst_reg = dst & 7; + const uint8_t dst = instr & 63; + const uint8_t dst_mode = (dst >> 3) & 7; + const uint8_t dst_reg = dst & 7; switch(operation) { case 0b001: // MOV/MOVB Move Word/Byte @@ -1509,7 +1514,8 @@ bool cpu::step() if (getPC() & 1) busError(); - disassemble(); + if (disas) + disassemble(); b -> setMMR2(getPC()); uint16_t instr = b->readWord(getPC()); diff --git a/cpu.h b/cpu.h index abbad00..e0dcbce 100644 --- a/cpu.h +++ b/cpu.h @@ -10,8 +10,9 @@ class cpu { private: + bool disas { false }; uint16_t regs0_5[2][6]; // R0...5, selected by bit 11 in PSW, - uint16_t sp[3+1]; // stackpointers, MF../MT.. select via 12/13 from PSW, others via 14/15 + uint16_t sp[3 + 1]; // stackpointers, MF../MT.. select via 12/13 from PSW, others via 14/15 uint16_t pc { 0 }; uint16_t psw { 0 }, fpsr { 0 }; uint16_t stackLimitRegister { 0 }; @@ -44,6 +45,8 @@ public: explicit cpu(bus *const b); ~cpu(); + void setDisassemble(const bool state); + bus *getBus() { return b; } void reset(); diff --git a/main.cpp b/main.cpp index 019f095..80ad287 100644 --- a/main.cpp +++ b/main.cpp @@ -217,6 +217,7 @@ void help() printf("-p 123 set CPU start pointer to decimal(!) value\n"); printf("-L f.bin load file into memory at address given by -p (and run it)\n"); printf("-n ncurses UI\n"); + printf("-d enable disassemble\n"); } int main(int argc, char *argv[]) @@ -231,13 +232,17 @@ int main(int argc, char *argv[]) bool testMode = false, testCases = false; int opt = -1; - while((opt = getopt(argc, argv, "hm:T:R:p:nL:")) != -1) + while((opt = getopt(argc, argv, "hm:T:R:p:ndL:")) != -1) { switch(opt) { case 'h': help(); return 1; + case 'd': + c->setDisassemble(true); + break; + case 'n': withUI = true; break; @@ -336,7 +341,7 @@ int main(int argc, char *argv[]) icount++; - if (icount % 1000 == 0) { + if ((icount & 4095) == 0) { if (poll(fds, 1, 0) == 1 && fds[0].revents) { int ch = 0; @@ -352,7 +357,7 @@ int main(int argc, char *argv[]) tty_->sendChar(ch); } - if (icount % 100000 == 0 && withUI) { + if ((icount & 262143) == 0 && withUI) { unsigned long now = get_ms(); mvwprintw(w_main_b -> win, 0, 24, "%.1f/s ", icount * 1000.0 / (now - start)); mvwprintw(w_main_b -> win, 0, 42, "%06o", b->get_switch_register());