Merge branch 'master' of https://gitlab.com/AluminumTank/radec
This commit is contained in:
commit
c808dd3ec2
@ -1,31 +0,0 @@
|
||||
#include "andGate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
andGate::andGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3) {
|
||||
e = eQueue;
|
||||
delay = d;
|
||||
in1 = wire1;
|
||||
in2 = wire2;
|
||||
out = wire3;
|
||||
}
|
||||
int andGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
}
|
||||
}
|
||||
else if(in1->getValue(evTime) == 1 && in2->getValue(evTime) == 1){
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int andGate::getDelay()
|
||||
{
|
||||
return delay;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef AND
|
||||
#define AND
|
||||
#include "gate.h"
|
||||
#include "event.h"
|
||||
#include "wire.h"
|
||||
|
||||
class andGate : public gate {
|
||||
public:
|
||||
andGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !AND
|
@ -1,16 +0,0 @@
|
||||
#include "event.h"
|
||||
|
||||
event::event(int num, int value, int setTime, wire * output){
|
||||
evNum = num;
|
||||
evValue = value;
|
||||
evTime = setTime;
|
||||
out = output;
|
||||
}
|
||||
|
||||
bool operator<(const event &e1, const event &e2) {
|
||||
if(e1.evTime == e2.evTime) {
|
||||
return e1.evNum > e2.evNum;
|
||||
}
|
||||
return e1.evTime > e2.evTime;
|
||||
}
|
||||
|
16
src/event.h
16
src/event.h
@ -1,16 +0,0 @@
|
||||
#ifndef EVENT
|
||||
#define EVENT
|
||||
|
||||
using namespace std;
|
||||
#include "wire.h"
|
||||
|
||||
class event {
|
||||
public:
|
||||
event(int num, int value, int setTime, wire * output);
|
||||
friend bool operator<(const event &e1, const event &e2);
|
||||
private:
|
||||
int evNum, evValue, evTime;
|
||||
wire *out;
|
||||
};
|
||||
|
||||
#endif // !EVENT
|
19
src/gate.h
19
src/gate.h
@ -1,19 +0,0 @@
|
||||
#ifndef GATE
|
||||
#define GATE
|
||||
|
||||
#include "event.h"
|
||||
|
||||
class wire;
|
||||
|
||||
class gate {
|
||||
public:
|
||||
gate();
|
||||
virtual void evaluate(int) = 0;
|
||||
|
||||
protected:
|
||||
wire *in1, *in2, *out;
|
||||
priority_queue<event> *e;
|
||||
int delay;
|
||||
};
|
||||
|
||||
#endif // !GATE
|
@ -1,31 +0,0 @@
|
||||
#include "nandGate.h"
|
||||
|
||||
nandGate::nandGate(priority_queue<event> *eQueue, int d, wire * wire1, wire * wire2, wire * wire3)
|
||||
{
|
||||
in1 = wire1;
|
||||
in2 = wire2;
|
||||
out = wire3;
|
||||
delay = d;
|
||||
e = eQueue;
|
||||
}
|
||||
|
||||
void nandGate::evaluate(int evTime)
|
||||
{
|
||||
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int nandGate::getDelay()
|
||||
{
|
||||
return delay;
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#ifndef NAND
|
||||
#define NAND
|
||||
#include "gate.h"
|
||||
#include "event.h"
|
||||
#include "wire.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class nandGate : public gate {
|
||||
public:
|
||||
nandGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2, wire* wire3);
|
||||
void evaluate(int time);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !NAND
|
@ -1,32 +0,0 @@
|
||||
#include "norGate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
norGate::norGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3) {
|
||||
e = eQueue;
|
||||
delay = d;
|
||||
in1 = wire1;
|
||||
in2 = wire2;
|
||||
out = wire3;
|
||||
}
|
||||
|
||||
void norGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) == 1 || in2->getValue(evTime) == 1) {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
}
|
||||
}
|
||||
else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) {
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int norGate::getDelay()
|
||||
{
|
||||
return delay;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef NOR
|
||||
#define NOR
|
||||
#include "gate.h"
|
||||
#include "event.h"
|
||||
#include "wire.h"
|
||||
|
||||
class norGate : public gate {
|
||||
public:
|
||||
norGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !NOR
|
@ -1,31 +0,0 @@
|
||||
#include "notGate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
notGate::notGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2) {
|
||||
e = eQueue;
|
||||
delay = d;
|
||||
in1 = wire1;
|
||||
out = wire2;
|
||||
|
||||
}
|
||||
|
||||
void notGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) == 0) {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int notGate::getDelay()
|
||||
{
|
||||
return delay;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#ifndef NOT
|
||||
#define NOT
|
||||
#include "gate.h"
|
||||
#include "wire.h"
|
||||
#include "event.h"
|
||||
|
||||
class notGate : public gate {
|
||||
public:
|
||||
notGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !NOT
|
@ -1,32 +0,0 @@
|
||||
#include "orGate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
orGate::orGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3) {
|
||||
e = eQueue;
|
||||
delay = d;
|
||||
in1 = wire1;
|
||||
in2 = wire2;
|
||||
out = wire3;
|
||||
}
|
||||
|
||||
void orGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) == 1 || in2->getValue(evTime) == 1) {
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
}
|
||||
}
|
||||
else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int orGate::getDelay()
|
||||
{
|
||||
return delay;
|
||||
}
|
15
src/orGate.h
15
src/orGate.h
@ -1,15 +0,0 @@
|
||||
#ifndef OR
|
||||
#define OR
|
||||
#include "gate.h"
|
||||
#include "event.h"
|
||||
#include "wire.h"
|
||||
|
||||
class orGate : public gate {
|
||||
public:
|
||||
orGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !OR
|
39
src/wire.cpp
39
src/wire.cpp
@ -1,39 +0,0 @@
|
||||
#include "Wire.h"
|
||||
|
||||
Wire::Wire(int number, bool io, string inName)
|
||||
{
|
||||
WireNumber = number;
|
||||
isPrint = io;
|
||||
name = inName;
|
||||
value = -1;
|
||||
lastEvent = 0;
|
||||
history.insert(history.begin(), 60, -1);
|
||||
}
|
||||
|
||||
int wire::getValue(int time) const
|
||||
{
|
||||
for (auto i = history.begin() + time; i != history.begin(); i--) {
|
||||
if (i[0] != -1) {
|
||||
return i[0];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void wire::setValue(int newValue, int setTime)
|
||||
{
|
||||
history[setTime] = newValue;
|
||||
if (lastEvent < setTime) {
|
||||
lastEvent = setTime;
|
||||
}
|
||||
}
|
||||
|
||||
int wire::getNumber() const
|
||||
{
|
||||
return wireNumber;
|
||||
}
|
||||
|
||||
void wire::addGate(gate * newGate)
|
||||
{
|
||||
gates.push_back(newGate);
|
||||
}
|
30
src/wire.h
30
src/wire.h
@ -1,30 +0,0 @@
|
||||
#ifndef WIRE
|
||||
#define WIRE
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class gate;
|
||||
|
||||
class wire {
|
||||
public:
|
||||
wire(int number, bool io, string inName = "");
|
||||
|
||||
int getValue(int time) const;
|
||||
void setValue(int newValue, int setTime);
|
||||
|
||||
int getNumber() const;
|
||||
void addGate(gate* newGate);
|
||||
|
||||
private:
|
||||
int wireNumber, value, lastEvent;
|
||||
vector<int> history;
|
||||
string name;
|
||||
bool isPrint;
|
||||
vector<gate*> gates;
|
||||
};
|
||||
|
||||
#endif // !WIRE
|
@ -1,34 +0,0 @@
|
||||
#include "xnorGate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
xnorGate::xnorGate(priority_queue<event> *eQueue, int d, wire* wire1,
|
||||
wire* wire2, wire* wire3) {
|
||||
e = eQueue;
|
||||
delay = d;
|
||||
in1 = wire1;
|
||||
in2 = wire2;
|
||||
out = wire3;
|
||||
}
|
||||
|
||||
void xnorGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) != -1 && in2->getValue(evTime) != -1) {
|
||||
if (in1->getValue(evTime) == in2->getValue(evTime)) {
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int xnorGate::getDelay()
|
||||
{
|
||||
return delay;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef XNOR
|
||||
#define XNOR
|
||||
#include "gate.h"
|
||||
#include "event.h"
|
||||
#include "wire.h"
|
||||
|
||||
class xnorGate : public gate {
|
||||
public:
|
||||
xnorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !XNOR
|
@ -1,34 +0,0 @@
|
||||
#include "xorGate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
xorGate::xorGate(priority_queue<event> *eQueue, int d, wire* wire1,
|
||||
wire* wire2, wire* wire3) {
|
||||
e = eQueue;
|
||||
delay = d;
|
||||
in1 = wire1;
|
||||
in2 = wire2;
|
||||
out = wire3;
|
||||
}
|
||||
|
||||
void xorGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) != -1 && in2->getValue(evTime) != -1) {
|
||||
if (in1->getValue(evTime) != in2->getValue(evTime)) {
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int xorGate::getDelay()
|
||||
{
|
||||
return delay;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef XOR
|
||||
#define XOR
|
||||
#include "gate.h"
|
||||
#include "event.h"
|
||||
#include "wire.h"
|
||||
|
||||
class xorGate : public gate {
|
||||
public:
|
||||
xorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||
wire* wire3);
|
||||
void evaluate(int evTime);
|
||||
int getDelay();
|
||||
};
|
||||
|
||||
#endif // !XOR
|
Loading…
Reference in New Issue
Block a user