arturo-fixed-files-branch #4
Reference in New Issue
Block a user
Delete Branch "arturo-fixed-files-branch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
CHANGES MADE: HOPE THESE CHANGES DO NOT BREAK SOMEONE ELSE'S BASE CODE.
fetchInstr() — added static_cast to _addrm and _size assignments to suppress -Wconversion warnings raised by the stricter makefile flags.
fetchOperSrc() — added '& 0b111' mask when indexing addrModes[]: (this->*(CPU::addrModes[_addrm & 0b111]))(); Without the mask, _addrm can be up to 0x1F (31), causing an out-of-bounds access on addrModes[] which only has 8 entries (0–7). This caused a segmentation fault when executing two-operand instructions like FMUL.
fetchOperDst() — added '& 0b111' mask (same reason as fetchOperSrc). Necessary for single-operand instructions that call fetchOperDst() directly without fetchOperSrc() running first, where _addrm has not yet been shifted and can exceed 7.
reg() — added '_opers[0] = _alu' after '_alu = &GPR[reg]'. Without this line, _dst was never updated after fetchOperDst() called reg(), leaving _dst as nullptr and causing a segfault inside the instruction body when trying to write the result.
execute() — changed from: (this->(CPU::addrModes[_opcode]))(); // wrong array, out of bounds to:
(this->(CPU::instrMap[_opcode]))(); // correct dispatch table
addrModes has 8 entries; instrMap has 512. Using addrModes with an opcode value caused an out-of-bounds call on any opcode above 7.
Changes in LiveDebug.cpp
runtime.cpu.fetchInstr();
runtime.cpu.fetchOperDst();
to:
runtime.cpu.fetchInstr();
runtime.cpu.execute();
fetchOperDst() only fetches the destination operand, it never calls the instruction itself, leaving _src unfetched for two-operand instructions and causing crashes. execute() correctly dispatches through instrMap[] to the full instruction method, which handles both operand fetches and the operation internally. This makes the Enter key properly step the CPU by one complete instruction cycle.
Changes in Terminal.cpp
newt.c_lflag &=
(ICANON | ECHO);(ICANON | ECHO));with:
newt.c_lflag &= static_cast<tcflag_t>(
The bitwise NOT of (ICANON | ECHO) produces a negative int value which cannot be implicitly converted to tcflag_t (unsigned int). The explicit cast suppresses the -Werror=sign-conversion error introduced when the makefile added -Werror.
result = (u8)ch;
with:
result = static_cast(ch);
C-style casts are flagged by -Werror=old-style-cast. The static_cast the correct C++ equivalent and makes the conversion intent explicit.