104 lines
2.3 KiB
C++
104 lines
2.3 KiB
C++
#ifndef MACHINE_H
|
|
#define MACHINE_H
|
|
|
|
#include <atomic>
|
|
#include <cstdint>
|
|
#include <istream>
|
|
#include <thread>
|
|
|
|
#include "Device.h"
|
|
|
|
const int MAX_ADDRESS = 0xFFFFF;
|
|
const int MAX_DEVICES = 256;
|
|
|
|
class Machine {
|
|
private:
|
|
uint8_t memory[MAX_ADDRESS + 1];
|
|
Device* devices[MAX_DEVICES];
|
|
|
|
// registers
|
|
int A; // Accumulator (24-bit)
|
|
int X; // Index (24-bit)
|
|
int L; // Linkage (24-bit)
|
|
int B; // Base (24-bit)
|
|
int S; // General purpose (24-bit)
|
|
int T; // General purpose (24-bit)
|
|
double F; // Floating point accumulator (48-bit)
|
|
int PC; // Program Counter (24-bit)
|
|
int SW; // Status Word (24-bit)
|
|
|
|
// timer simulation
|
|
std::atomic<bool> running;
|
|
std::thread* timerThread;
|
|
int speed; // kHz
|
|
|
|
public:
|
|
Machine();
|
|
~Machine();
|
|
|
|
// getters
|
|
int getA() const;
|
|
int getX() const;
|
|
int getL() const;
|
|
int getB() const;
|
|
int getS() const;
|
|
int getT() const;
|
|
double getF() const;
|
|
int getPC() const;
|
|
int getSW() const;
|
|
|
|
// setters
|
|
void setA(int val);
|
|
void setX(int val);
|
|
void setL(int val);
|
|
void setB(int val);
|
|
void setS(int val);
|
|
void setT(int val);
|
|
void setF(double val);
|
|
void setPC(int val);
|
|
void setSW(int val);
|
|
|
|
// condition codes for SW
|
|
void setCC_less();
|
|
void setCC_equal();
|
|
void setCC_greater();
|
|
int getCC() const;
|
|
|
|
// 0=A, 1=X, 2=L, 3=B, 4=S, 5=T, 6=F, 8=PC, 9=SW
|
|
int getReg(int reg) const;
|
|
void setReg(int reg, int val);
|
|
|
|
int getByte(int addr) const;
|
|
void setByte(int addr, int val);
|
|
|
|
int getWord(int addr) const;
|
|
void setWord(int addr, int val);
|
|
|
|
Device* getDevice(int num);
|
|
void setDevice(int num, Device* device);
|
|
|
|
// error handling
|
|
void notImplemented(const char* mnemonic);
|
|
void invalidOpcode(int opcode);
|
|
void invalidAddressing();
|
|
|
|
// execution
|
|
int fetch();
|
|
void execute();
|
|
bool execF1(int opcode);
|
|
bool execF2(int opcode, int operand);
|
|
bool execSICF3F4(int opcode, int ni, int operand);
|
|
|
|
// timer simulation
|
|
void start();
|
|
void stop();
|
|
void step();
|
|
bool isRunning() const;
|
|
int getSpeed() const;
|
|
void setSpeed(int kHz);
|
|
|
|
// loader
|
|
bool loadSection(std::istream& r);
|
|
};
|
|
|
|
#endif // MACHINE_H
|