From f82aa627c4995c5b81b70701b68a686509d200a7 Mon Sep 17 00:00:00 2001 From: Arturo Date: Tue, 31 Mar 2026 01:19:00 -0600 Subject: [PATCH] Fix execute() dispatch, addrModes mask, reg() operand ptr, cast warnings, and Enter key step --- src/spider/runtime/cpu/CPU.cpp | 9 ++++++--- src/spider/runtime/debug/LiveDebug.cpp | 18 ++++++++---------- src/spider/runtime/util/Terminal.cpp | 13 +++++++++++-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/spider/runtime/cpu/CPU.cpp b/src/spider/runtime/cpu/CPU.cpp index 1a796b1..26a66c0 100644 --- a/src/spider/runtime/cpu/CPU.cpp +++ b/src/spider/runtime/cpu/CPU.cpp @@ -80,7 +80,7 @@ namespace spider { _opers[1] = _opers[0]; // call specific addressing mode - (this->*(CPU::addrModes[_addrm]))(); + (this->*(CPU::addrModes[_addrm & 0b111]))(); // mask added here too } void CPU::fetchOperSrc() { @@ -88,17 +88,19 @@ namespace spider { _alu = &ALU1; // call specific addressing mode - (this->*(CPU::addrModes[_addrm]))(); + (this->*(CPU::addrModes[_addrm & 0b111]))(); // mask keeps index within 0-7 // modify the _addrm register _addrm = static_cast((_addrm >> 3) & 0x1F); _addrm++; } + void CPU::execute() { - (this->*(CPU::addrModes[_opcode]))(); + (this->*(CPU::instrMap[_opcode]))(); // no null check needed } + // Addressing Modes // /** @@ -145,6 +147,7 @@ namespace spider { // get byte u8 reg = (_reel->readU8(RI) >> sh) & 0xF; _alu = &GPR[reg]; + _opers[0] = _alu; // explicitly sets _opers[0] = _dst RI += use; // store no-op diff --git a/src/spider/runtime/debug/LiveDebug.cpp b/src/spider/runtime/debug/LiveDebug.cpp index ddb6192..0c81c3f 100644 --- a/src/spider/runtime/debug/LiveDebug.cpp +++ b/src/spider/runtime/debug/LiveDebug.cpp @@ -330,18 +330,16 @@ namespace spider { int liveDebugMain() { Terminal t; Runtime runtime(1024); + + InstrReelFixed fix(100); - runtime.ram[0] = 0xFF; - runtime.ram[1] = 0xEE; - runtime.ram[2] = 0xDD; - runtime.ram[3] = 0xCC; - runtime.ram[4] = 0xBB; - runtime.ram[5] = 0xAA; - runtime.ram[6] = 0x99; - runtime.ram[7] = 0x88; - fix.writeU16(0, 0b0000111); + + + runtime.hookReel(&fix, false); + + bool running = true, update = true; u64 ramScroll = 0; u8 key = Terminal::UNKNOWN; @@ -388,7 +386,7 @@ namespace spider { case Terminal::ENTER: update = true; runtime.cpu.fetchInstr(); - runtime.cpu.fetchOperDst(); + runtime.cpu.execute(); // looks up instrMap[_opcode] & calls the correct instruction method (e.g. FMUL) break; default: break; diff --git a/src/spider/runtime/util/Terminal.cpp b/src/spider/runtime/util/Terminal.cpp index 55a589d..bcc6b47 100644 --- a/src/spider/runtime/util/Terminal.cpp +++ b/src/spider/runtime/util/Terminal.cpp @@ -11,8 +11,15 @@ #include #include #include +#include //This was missing, +//The ioctl, TIOCGWINSZ and winsize used in getSize() live in that header, but it was never included. #endif + +//the Linux includes at the top are inside #if SPIDER_OS_LINUX which IS defined, +//but getSize() is inside #if SPIDER_DISTRO_DESKTOP which is NOT defined, +//so the compiler sees the ioctl call without the include that would have covered it. + #if defined(SPIDER_DISTRO_DESKTOP) namespace spider { @@ -218,7 +225,8 @@ namespace spider { struct termios oldt, newt; tcgetattr(STDIN_FILENO, &oldt); newt = oldt; - newt.c_lflag &= ~(ICANON | ECHO); + //newt.c_lflag &= ~(ICANON | ECHO); + newt.c_lflag &= static_cast(~(ICANON | ECHO)); //added this line tcsetattr(STDIN_FILENO, TCSANOW, &newt); u8 result = Terminal::UNKNOWN; @@ -247,7 +255,8 @@ namespace spider { } } else if (ch == 10) result = Terminal::ENTER; else if (ch == 127) result = Terminal::BACKSPACE; - else result = (u8)ch; + else result = static_cast(ch); //added this line + //else result = (u8)ch; tcsetattr(STDIN_FILENO, TCSANOW, &oldt); return result;