I've seen a lot of C++ simulators implementing logic gates, but absolutely all of them use the wrapped bitwise operations of the programming language itself. I have tried to omit the use of a bitwise operator and mimic what a transistor really does at its basic level until it reaches a really functional logical gate (just using branching states). I would appreciate any kind of feedback on how this can be improved because I have an OR gate for which I need to use the C++ OR bitwise (|) operator, for which also I have an approach using 3 NAND logic gates, but I think maybe the starting idea is wrong as how I modeled the transistor and the overall composition of the electronic schema. Maybe I'll need to implement electric flow output probes to be able to virtualize the transistor itself correctly. The overall scope of this is to create a full working 8bit CPU from scratch in C++.
Electronic schema profile:
class ElectricSchema
{
public:
NotGate* m_NotGate;
AndGate* m_AndGate;
NandGate* m_NandGate;
OrGate* m_OrGate;
XorGate* m_XorGate;
HalfAdder* m_HalfAdder;
FullAdder* m_FullAdder;
// 512 bit adder
FullAdder* m_BusAdder512[512];
private:
bool m_voltageRail;
public:
ElectricSchema() : m_voltageRail(false) {}
ElectricSchema(bool voltage) : m_voltageRail(voltage) {};
~ElectricSchema() {}
const bool& getVoltageRail() const { return m_voltageRail; }
};
Transistor profile:
class Transistor
{
private:
bool m_collecterPinIn;
bool m_basePinIn;
bool m_emitterPinOut;
public:
Transistor() : m_collecterPinIn(schema.getVoltageRail()), m_basePinIn(false), m_emitterPinOut(false){}
Transistor(bool collecter, bool base, bool emitter) : m_collecterPinIn(schema.getVoltageRail()), m_basePinIn(base), m_emitterPinOut(emitter)
{
if(collecter == false) { m_emitterPinOut = false; }
else if(base == true) { m_emitterPinOut = true; }
else { m_emitterPinOut = false; }
}
~Transistor(){}
const bool& getCollecterPinIn() const { return m_collecterPinIn; }
const bool& getBasePinIn() const { return m_basePinIn; }
const bool& getEmitterPinOut() { updateInternalStates(); return m_emitterPinOut; }
bool& setCollecterPinIn() { return m_collecterPinIn; }
bool& setBasePinIn() { return m_basePinIn; }
private:
void updateInternalStates()
{
if(m_collecterPinIn == false) { m_emitterPinOut = false; }
else if(m_basePinIn == true) { m_emitterPinOut = true; }
else { m_emitterPinOut = false; }
}
};
Full code is around 1600 lines of code: https://godbolt.org/z/McnjY5T1d