refactor: 2 pull bools to 1 enum; remove gate backptr

This commit is contained in:
Christopher Mosher 2013-12-15 00:03:46 -05:00
parent 48249ccb60
commit da174b54cd
5 changed files with 46 additions and 25 deletions

View File

@ -64,10 +64,10 @@ bool Circuit::getValue() {
}
/* otherwise, this test: */
for (auto s : this->segs) {
if (s->pullup) {
if (s->pull == Pull::UP) {
return true;
}
if (s->pulldown) {
if (s->pull == Pull::DOWN) {
return false;
}
if (s->on) {

View File

@ -18,7 +18,7 @@
#define TRACEREG 1
//#define TRACESEG 1
#define TRACESEG 1

View File

@ -22,7 +22,7 @@ v6502: $(OBJS)
clean:
-rm -f v6502 v6502.exe $(OBJS) $(DEPS)
-rm -Rf v6502 v6502.exe $(OBJS) $(DEPS) doxygen

View File

@ -27,10 +27,9 @@ static void pHexw(const unsigned short x) {
void Trace::dumpSegments() const {
for (auto sp : this->s) {
Segment* seg = sp.second.get();
assert(!(seg->pullup && seg->pulldown));
if (seg->pullup) {
if (seg->pull == Pull::UP) {
std::cout << (seg->on ? "U" : "u");
} else if (seg->pulldown) {
} else if (seg->pull == Pull::DOWN) {
std::cout << (seg->on ? "D" : "d");
} else {
std::cout << (seg->on ? "F" : "f");

58
trans.h
View File

@ -8,33 +8,46 @@
#ifndef TRANS_H
#define TRANS_H
#include <string>
#include <set>
#include "ptr_less.h"
#include <set>
#include <string>
class Trans;
enum class Pull { UP, DOWN, FLOAT };
class Segment {
public:
std::string id;
const std::string id;
std::set<Trans*> gates;
std::set<Trans*> c1c2s;
bool on;
bool pulldown;
bool pullup;
bool vss;
bool vcc;
Segment(const std::string& id) : id(id), on(false), pulldown(false), pullup(id[0] == '+'), vss(false), vcc(false) {
Pull pull;
bool on;
Segment(const std::string& id) : id(id), vss(false), vcc(false), pull(id[0]=='+' ? Pull::UP : Pull::FLOAT), on(false) {
}
void set(bool up) {
this->pullup = up;
this->pulldown = !up;
virtual ~Segment() {
}
void set(const bool up) {
this->pull = (up ? Pull::UP : Pull::DOWN);
}
bool operator<(const Segment& that) { return this->id < that.id; }
static unsigned char asByte(Segment* b7, Segment* b6, Segment* b5, Segment* b4, Segment* b3, Segment* b2, Segment* b1, Segment* b0) {
return b7->on << 0x7 | b6->on << 0x6 | b5->on << 0x5 | b4->on << 0x4 | b3->on << 0x3 | b2->on << 0x2 | b1->on << 0x1 | b0->on;
}
@ -43,22 +56,30 @@ public:
return bf->on << 0xf | be->on << 0xe | bd->on << 0xd | bc->on << 0xc | bb->on << 0xb | ba->on << 0xa | b9->on << 0x9 | b8->on << 0x8 | b7->on << 0x7 | b6->on << 0x6 | b5->on << 0x5 | b4->on << 0x4 | b3->on << 0x3 | b2->on << 0x2 | b1->on << 0x1 | b0->on;
}
bool operator<(const Segment& that) { return this->id < that.id; }
private:
Segment(const Segment&) = delete;
Segment& operator=(const Segment&) = delete;
};
typedef std::set<Segment*,ptr_less<Segment>> setpSeg;
class Trans {
public:
Segment* c1;
Segment* gate;
Segment* c2;
bool on;
public:
Trans(Segment* c1, Segment* gate, Segment* c2) : c1(c1), gate(gate), c2(c2), on(false) {
Trans(Segment* c1, Segment* gate, Segment* c2) : c1(c1), c2(c2), on(false) {
c1->c1c2s.insert(this);
gate->gates.insert(this);
c2->c1c2s.insert(this);
@ -68,8 +89,9 @@ public:
}
private:
Trans(const Trans&);
Trans& operator=(const Trans&);
Trans(const Trans&) = delete;
Trans& operator=(const Trans&) = delete;
};
#endif /* TRANS_H */