merged
This commit is contained in:
parent
18a14d204c
commit
717568b6d0
30 changed files with 4093 additions and 209 deletions
|
|
@ -4,18 +4,18 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
#include "constants.h"
|
||||
#include "device.h"
|
||||
#include "input_device.h"
|
||||
#include "output_device.h"
|
||||
#include "file_device.h"
|
||||
#include "opcode.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#define MEMORY_SIZE 65536
|
||||
#define NUM_DEVICES 256
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
using std::string;
|
||||
using std::cerr;
|
||||
|
|
@ -26,30 +26,32 @@ using std::cout;
|
|||
class Machine {
|
||||
public:
|
||||
Machine();
|
||||
Machine(int speedHz) : Machine() { this->speedHz = speedHz; _instructionsTable = instructions; }
|
||||
~Machine();
|
||||
|
||||
// Accessor methods for registers
|
||||
int getA() const { return A; }
|
||||
void setA(int value) { A = value; }
|
||||
void setA(int value) { A = toSIC24(value); }
|
||||
|
||||
int getB() const { return B; }
|
||||
void setB(int value) { B = value; }
|
||||
void setB(int value) { B = toSIC24(value); }
|
||||
|
||||
int getX() const { return X; }
|
||||
void setX(int value) { X = value; }
|
||||
void setX(int value) { X = toSIC24(value); }
|
||||
|
||||
int getL() const { return L; }
|
||||
void setL(int value) { L = value; }
|
||||
void setL(int value) { L = toSIC24(value); }
|
||||
|
||||
int getS() const { return S; }
|
||||
void setS(int value) { S = value; }
|
||||
void setS(int value) { S = toSIC24(value); }
|
||||
|
||||
int getT() const { return T; }
|
||||
void setT(int value) { T = value; }
|
||||
void setT(int value) { T = toSIC24(value); }
|
||||
|
||||
// PC is an address → don't mask to 24 unless you want 24-bit addressing
|
||||
int getPC() const { return PC; }
|
||||
void setPC(int value) { PC = value; }
|
||||
|
||||
// status word: keep as-is
|
||||
int getSW() const { return SW; }
|
||||
void setSW(int value) { SW = value; }
|
||||
|
||||
|
|
@ -76,14 +78,19 @@ 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();
|
||||
|
||||
bool execF1(int opcode);
|
||||
bool execF2(int opcode, int operand);
|
||||
bool execSICF3F4(int opcode, int ni, int operand);
|
||||
// Execution and speed control
|
||||
int getSpeed() const;
|
||||
void setSpeed(int Hz);
|
||||
void start();
|
||||
void stop();
|
||||
void tick();
|
||||
void halt();
|
||||
bool isStopped() const { return _stopped; }
|
||||
void reset();
|
||||
|
||||
// error handling methods
|
||||
void notImplemented(string mnemonic);
|
||||
|
|
@ -92,6 +99,22 @@ public:
|
|||
void divisionByZero(int opcode);
|
||||
void undefinedHandler(int opcode);
|
||||
|
||||
bool getExtendedMode() const { return _exex_mode; }
|
||||
void enableExtendedMode();
|
||||
void disableExtendedMode();
|
||||
|
||||
|
||||
int* getVectorRegister(int regNum);
|
||||
void setVectorRegister(int regNum, const int* values);
|
||||
|
||||
const int* getVA() const { return VA; }
|
||||
const int* getVS() const { return VS; }
|
||||
const int* getVT() const { return VT; }
|
||||
void setVA(const int* values);
|
||||
void setVS(const int* values);
|
||||
void setVT(const int* values);
|
||||
|
||||
|
||||
private:
|
||||
// registers
|
||||
int A, B, X, L, S, T, PC, SW;
|
||||
|
|
@ -104,42 +127,23 @@ 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> speedHz{10}; // Default 10 Hz
|
||||
|
||||
bool execF1(int opcode);
|
||||
bool execF2(int opcode, int operand);
|
||||
bool execSICF3F4(int opcode, int ni, int x, int b, int p, int e, int operand);
|
||||
|
||||
|
||||
// Extended mode
|
||||
bool _stopped{false};
|
||||
bool _exex_mode{false};
|
||||
InstructionInfo* _instructionsTable;
|
||||
int VA[VECTOR_REG_SIZE], VS[VECTOR_REG_SIZE], VT[VECTOR_REG_SIZE]; // vector operation registers
|
||||
};
|
||||
|
||||
// Convert integer to 24-bit signed SIC representation
|
||||
inline int toSIC24(int value) {
|
||||
value &= 0xFFFFFF;
|
||||
if (value & 0x800000) {
|
||||
value -= 0x1000000;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
inline int setCC(int sw, int cc) {
|
||||
sw &= ~CC_MASK;
|
||||
sw |= (cc & CC_MASK);
|
||||
return sw;
|
||||
}
|
||||
|
||||
inline int sic_comp(int a, int b, int sw) {
|
||||
int sa = toSIC24(a);
|
||||
int sb = toSIC24(b);
|
||||
|
||||
int cc;
|
||||
if (sa < sb) {
|
||||
cc = CC_LT;
|
||||
} else if (sa == sb) {
|
||||
cc = CC_EQ;
|
||||
} else {
|
||||
cc = CC_GT;
|
||||
}
|
||||
|
||||
return setCC(sw, cc);
|
||||
}
|
||||
|
||||
inline int getCC(int sw) {
|
||||
return sw & CC_MASK;
|
||||
}
|
||||
|
||||
|
||||
#endif // MACHINE_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue