some progress

This commit is contained in:
aljazbrodar. 2025-12-04 14:49:32 +01:00
parent 618e4dd361
commit 5c6d1b22f6
7 changed files with 65 additions and 13 deletions

View file

@ -1,5 +1,6 @@
#include "machine.h"
#include "device.h"
#include "opcode.h"
#include <stdexcept>
using namespace std;
@ -95,15 +96,55 @@ void Machine::setDevice(int num, Device* device) {
void Machine::notImplemented(string mnemonic) {
throw std::runtime_error("Instruction: " + mnemonic + " is not yet implemented.");
std::cerr << "Instruction: " << mnemonic << " is not yet implemented." << endl;
}
void Machine::invalidOpcode(int opcode) {
throw std::runtime_error("Invalid opcode: " + to_string(opcode));
std::cerr << "Invalid opcode: " << to_string(opcode) << endl;
}
void Machine::invalidAddressing() {
throw std::runtime_error("Invalid addressing used.");
std::cerr << "Invalid addressing used." << endl;
}
// Nalozi in vrni en bajt z naslova PC
// in ga poveca za 1
int Machine::fetch() {
int address = getReg(8);
setReg(8, address + 1);
return readByte(address);
}
void Machine::execute() {
int opcode = fetch();
int operand;
switch (opcode) {
// Format 1
case Opcode::FIX:
case Opcode::FLOAT:
case Opcode::NORM:
execF1(opcode);
break;
// Format 2
case Opcode::ADDR:
case Opcode::CLEAR:
case Opcode::DIVR:
case Opcode::MULR:
case Opcode::RMO:
case Opcode::SHIFTL:
case Opcode::SHIFTR:
case Opcode::SUBR:
operand = fetch();
execF2(opcode, operand);
break;
// Format 3/4 (SIC/XE)
default:
decode_F3_F4(opcode);
break;
}
}
@ -113,3 +154,6 @@ void Machine::invalidAddressing() {