added new instructions and new test

This commit is contained in:
zanostro 2025-11-12 12:13:26 +01:00
parent d4754a048d
commit 6b3f4989ae
6 changed files with 142 additions and 38 deletions

View file

@ -5,6 +5,9 @@
#include <iostream>
#include <vector>
#include <memory>
#include <atomic>
#include <mutex>
#include "constants.h"
#include "device.h"
@ -23,6 +26,7 @@ using std::cout;
class Machine {
public:
Machine();
Machine(int speedkHz) : Machine() { this->speedkHz = speedkHz; }
~Machine();
int getA() const { return A; }
@ -74,7 +78,6 @@ public:
// Set a file device at index `num` using the provided filename.
void setFileDevice(int num, const std::string &filename);
// Fetch and execute instructions
int fetch();
void execute();
@ -83,6 +86,12 @@ public:
bool execF2(int opcode, int operand);
bool execSICF3F4(int opcode, int ni, int x, int b, int p, int e, int operand);
// Execution and speed control
int getSpeed() const;
void setSpeed(int kHz);
void start();
void stop();
// error handling methods
void notImplemented(string mnemonic);
void invalidOpcode(int opcode);
@ -102,6 +111,11 @@ private:
std::vector<std::shared_ptr<Device>> devices;
// fallback device returned when device slot is empty/invalid
Device fallbackDevice;
// Execution control
std::atomic<bool> running{false};
std::atomic<int> speedkHz{1}; // Default 1 kHz
void tick(); // simulate a clock tick
};