From daf5e2784200055fb78006dd9818b96ac8a0212f Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 19 Mar 2023 15:33:39 +0100 Subject: [PATCH] console switches/leds work --- bus.h | 1 + cpu.cpp | 9 +++------ debugger.cpp | 18 ++++++++++++++++++ main.cpp | 17 +++++++++++++---- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/bus.h b/bus.h index dd2dd81..cacce5e 100644 --- a/bus.h +++ b/bus.h @@ -101,6 +101,7 @@ public: void clearmem(); void set_console_switches(const uint16_t new_state) { console_switches = new_state; } + void set_console_switch(const int bit, const bool state) { console_switches &= ~(1 << bit); console_switches |= state << bit; } uint16_t get_console_switches() { return console_switches; } void set_debug_mode() { console_switches |= 128; } diff --git a/cpu.cpp b/cpu.cpp index 306aad1..478dc7c 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -10,8 +10,6 @@ #include "log.h" #include "utils.h" -uint16_t oldpc = 0; - #define SIGN(x, wm) ((wm) ? (x) & 0x80 : (x) & 0x8000) #define IS_0(x, wm) ((wm) ? ((x) & 0xff) == 0 : (x) == 0) @@ -1264,7 +1262,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) // FILE *fh = fopen("og2-kek.dat", "a+"); // fprintf(fh, "%lu %06o MTPI %06o: %06o\n", mtpi_count, oldpc, a, v); // fclose(fh); - DOLOG(debug, true, "%lu %06o MTPI %06o: %06o", mtpi_count, oldpc, a.addr.value(), v); + DOLOG(debug, true, "%lu %06o MTPI %06o: %06o", mtpi_count, pc-2, a.addr.value(), v); mtpi_count++; @@ -1489,7 +1487,7 @@ bool cpu::misc_operations(const uint16_t instr) return true; case 0b0000000000000100: // IOT - //trap(020); disabled for debugging TODO + trap(020); return true; case 0b0000000000000110: // RTT @@ -2149,7 +2147,6 @@ void cpu::step_b() instruction_count++; uint16_t temp_pc = getPC(); - oldpc = temp_pc; if ((b->getMMR0() & 0160000) == 0) b->setMMR2(temp_pc); @@ -2171,7 +2168,7 @@ void cpu::step_b() if (misc_operations(instr)) return; - DOLOG(warning, true, "UNHANDLED instruction %o", instr); + DOLOG(warning, true, "UNHANDLED instruction %06o @ %06o", instr, temp_pc); trap(010); } diff --git a/debugger.cpp b/debugger.cpp index 2b17e53..f0bb155 100644 --- a/debugger.cpp +++ b/debugger.cpp @@ -222,6 +222,23 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto continue; } + else if (parts[0] == "toggle") { + auto s_it = kv.find("s"); + auto t_it = kv.find("t"); + + if (s_it == kv.end() || t_it == kv.end()) + cnsl->put_string_lf(format("toggle: parameter missing? current switches states: 0o%06o", c->getBus()->get_console_switches())); + else { + int s = std::stoi(s_it->second, nullptr, 8); + int t = std::stoi(t_it->second, nullptr, 8); + + c->getBus()->set_console_switch(s, t); + + cnsl->put_string_lf(format("Set switch %d to %d", s, t)); + } + + continue; + } else if (parts[0] == "setmem") { auto a_it = kv.find("a"); auto v_it = kv.find("v"); @@ -345,6 +362,7 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto cnsl->put_string_lf("mmudump - dump MMU settings (PARs/PDRs)"); cnsl->put_string_lf("setpc - set PC to value"); cnsl->put_string_lf("setmem - set memory (a=) to value (v=), both in octal, one byte"); + cnsl->put_string_lf("toggle - set switch (s=, 0...15 (decimal)) of the front panel to state (t=, 0 or 1)"); continue; } diff --git a/main.cpp b/main.cpp index a40ce57..14bf802 100644 --- a/main.cpp +++ b/main.cpp @@ -49,7 +49,7 @@ void help() printf("-b x enable bootloader (build-in), parameter must be \"rk05\" or \"rl02\"\n"); printf("-n ncurses UI\n"); printf("-d enable debugger\n"); - printf("-s x set console switches state - octal number\n"); + printf("-s x,y set console switche state: set bit x (0...15) to y (0/1)\n"); printf("-t enable tracing (disassemble to stderr, requires -d as well)\n"); printf("-l x log to file x\n"); printf("-L x,y set log level for screen (x) and file (y)\n"); @@ -94,9 +94,18 @@ int main(int argc, char *argv[]) test = optarg; break; - case 's': - console_switches = strtol(optarg, NULL, 8); - break; + case 's': { + char *c = strchr(optarg, ','); + if (!c) + error_exit(false, "-s: parameter missing"); + int bit = atoi(optarg); + int state = atoi(c + 1); + + console_switches &= ~(1 << bit); + console_switches |= state << bit; + + break; + } case '3': mode_34 = true; // switch from 11/70 to 11/34