changes to pygen
This commit is contained in:
@@ -22,7 +22,7 @@ namespace spider {
|
||||
RE{}, RN{}, RV{}, RM{},
|
||||
ALU0{}, ALU1{},
|
||||
_dst(nullptr), _src(nullptr),
|
||||
_instr(0), _addrm(0), _size(0),
|
||||
_opcode(0), _addrm(0), _size(0),
|
||||
_store(0), _post(&CPU::imp),
|
||||
_ram(nullptr), _reel(nullptr) {
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace spider {
|
||||
|
||||
void CPU::fetchInstr() {
|
||||
u16 i = _reel->readU16(RI);
|
||||
_instr = (i >> 7) & 0x1FF;
|
||||
_opcode = (i >> 7) & 0x1FF;
|
||||
_addrm = (i >> 2) & 0x1F;
|
||||
_size = i & 0x3;
|
||||
RI += 2;
|
||||
@@ -79,7 +79,7 @@ namespace spider {
|
||||
_opers[1] = _opers[0];
|
||||
|
||||
// call specific addressing mode
|
||||
(this->*(CPU::addrModes[_addrm & 0x7]))();
|
||||
(this->*(CPU::addrModes[_addrm]))();
|
||||
}
|
||||
|
||||
void CPU::fetchOperSrc() {
|
||||
@@ -87,13 +87,17 @@ namespace spider {
|
||||
_alu = &ALU1;
|
||||
|
||||
// call specific addressing mode
|
||||
(this->*(CPU::addrModes[_addrm & 0x7]))();
|
||||
(this->*(CPU::addrModes[_addrm]))();
|
||||
|
||||
// modify the _addrm register
|
||||
_addrm >>= 3;
|
||||
_addrm++;
|
||||
}
|
||||
|
||||
void CPU::execute() {
|
||||
(this->*(CPU::addrModes[_opcode]))();
|
||||
}
|
||||
|
||||
// Addressing Modes //
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,10 @@ namespace spider {
|
||||
static constexpr const u64 FLAG_EXCEPTION = 0b0000000000000000000000000000000000000000000000000000000000001000;
|
||||
static constexpr const u64 FLAG_MEMORY_MODE = 0b0000000000000000000000000000000000000000000000000000000000110000;
|
||||
|
||||
public: // Map of addressing modes
|
||||
public: // Map of addressing modes & Instructions
|
||||
|
||||
static CPU::Fn addrModes[];
|
||||
static CPU::Fn instrMap[];
|
||||
|
||||
public: // General Purpose Registers
|
||||
union {
|
||||
@@ -61,7 +62,7 @@ namespace spider {
|
||||
};
|
||||
|
||||
// Holds the current instruction opcode
|
||||
u16 _instr : 9;
|
||||
u16 _opcode : 9;
|
||||
|
||||
// Holds the current addressing modes,
|
||||
// before they were used
|
||||
@@ -163,6 +164,23 @@ namespace spider {
|
||||
*/
|
||||
void fetchOperSrc();
|
||||
|
||||
/**
|
||||
* Executes an opcode, by means of directly
|
||||
* accessing the instruction map and
|
||||
* calling that function pointer.
|
||||
*/
|
||||
void execute();
|
||||
|
||||
/**
|
||||
* Executes an opcode, by means of using
|
||||
* a large switch statement. Only suitable
|
||||
* for environments where the instruction
|
||||
* map is not possible.
|
||||
*
|
||||
* This has yet to be proved!!!
|
||||
*/
|
||||
void executeSwLk();
|
||||
|
||||
public: // Addressing Modes
|
||||
|
||||
/**
|
||||
@@ -862,4 +880,4 @@ namespace spider {
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "CPU.hpp"
|
||||
#include <spider/runtime/cpu/CPU.hpp>
|
||||
|
||||
namespace spider {
|
||||
|
||||
@@ -25,18 +25,16 @@ namespace spider {
|
||||
// Version 1 — Lookup table of member-function pointers
|
||||
// =============================================================
|
||||
|
||||
/** Pointer-to-member type for a zero-argument CPU instruction. */
|
||||
using CPUInstr = void (CPU::*)();
|
||||
|
||||
/**
|
||||
* Instruction dispatch table (512 entries, 9-bit opcode space).
|
||||
*
|
||||
* Usage:
|
||||
* u16 opcode = fetch();
|
||||
* CPUInstr fn = InstrMap[opcode];
|
||||
* CPU::Fn fn = InstrMap[opcode];
|
||||
* if (fn) (cpu.*fn)();
|
||||
*/
|
||||
CPUInstr InstrMap[512] = {
|
||||
CPU::Fn CPU::instrMap[] = {
|
||||
&CPU::NOP, // 0x000 — No Operation
|
||||
&CPU::SPDR, // 0x001 — Will place the Spider version of the interpreter in RA
|
||||
&CPU::MMODE, // 0x002 — Set Memory Mode
|
||||
@@ -563,10 +561,10 @@ CPUInstr InstrMap[512] = {
|
||||
* but expressed as a switch so the compiler can choose the best
|
||||
* lowering strategy (jump table, binary search, etc.).
|
||||
*
|
||||
* @param opcode 9-bit instruction opcode (0x000 – 0x1FF).
|
||||
* @param opcode 9-bit instruction opcode (0x000 - 0x1FF).
|
||||
*/
|
||||
void CPU::execute(u16 opcode) {
|
||||
switch (opcode) {
|
||||
void CPU::executeSwLk() {
|
||||
switch (_opcode) {
|
||||
|
||||
// ── System ──────────────────────────────────────
|
||||
case 0x000: NOP(); break;
|
||||
Reference in New Issue
Block a user