diff --git a/Makefile b/Makefile index 08225bd..fc88e53 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ cpu.o: cpu.cpp cpu.h addressbus.h nodes.h nodes.o: nodes.cpp nodes.h -trans.o: trans.cpp trans.h SegmentCache.h +trans.o: trans.cpp trans.h SegmentCache.o: SegmentCache.cpp SegmentCache.h @@ -20,3 +20,4 @@ TransNetwork.o: TransNetwork.cpp TransNetwork.h trans.h clean: -rm *.o -rm v6502 + -rm v6502.exe diff --git a/SegmentCache.cpp b/SegmentCache.cpp index 1a2bcad..934a0be 100644 --- a/SegmentCache.cpp +++ b/SegmentCache.cpp @@ -9,7 +9,6 @@ #include #include #include -#include Segment* SegmentCache::getOrAdd(std::string& id) { if (this->cache.find(id) == this->cache.end()) { diff --git a/TransNetwork.cpp b/TransNetwork.cpp index 337e6c8..298d9a4 100644 --- a/TransNetwork.cpp +++ b/TransNetwork.cpp @@ -7,21 +7,16 @@ #include "TransNetwork.h" #include "trans.h" -#include "SegmentCache.h" +#include #include -TransNetwork::TransNetwork(std::istream& readFromHere) { - SegmentCache segs; - +TransNetwork::TransNetwork(std::istream& in) { std::string c1, gate, c2; - readFromHere >> c1 >> gate >> c2; - while (readFromHere.good()) { - Trans trans(segs.getOrAdd(c1), segs.getOrAdd(gate), segs.getOrAdd(c2)); - std::cout << trans; - - readFromHere >> c1 >> gate >> c2; + in >> c1 >> gate >> c2; + while (in.good()) { + this->transes.insert(std::make_shared(this->segs.getOrAdd(c1), this->segs.getOrAdd(gate), this->segs.getOrAdd(c2))); + in >> c1 >> gate >> c2; } - std::cout << std::endl << "done" << std::endl; } TransNetwork::~TransNetwork() { diff --git a/TransNetwork.h b/TransNetwork.h index 21f7ac3..caad451 100644 --- a/TransNetwork.h +++ b/TransNetwork.h @@ -8,9 +8,15 @@ #ifndef TRANSNETWORK_H #define TRANSNETWORK_H +#include "trans.h" +#include "SegmentCache.h" #include class TransNetwork { +private: + SegmentCache segs; + std::set> transes; + public: TransNetwork(std::istream& readFromHere); virtual ~TransNetwork(); diff --git a/cpu.cpp b/cpu.cpp index 0a10264..a4d3a38 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -110,13 +110,13 @@ addressBus(addressBus) { for (int i = 0; i != trns.size(); ++i) { trn& t = trns[i]; - if (t.c1 == n->VSS) { - t.c1 = t.c2; - t.c2 = n->VSS; - } else if (t.c1 == n->VCC) { - t.c1 = t.c2; - t.c2 = n->VCC; - } +// if (t.c1 == n->VSS) { +// t.c1 = t.c2; +// t.c2 = n->VSS; +// } else if (t.c1 == n->VCC) { +// t.c1 = t.c2; +// t.c2 = n->VCC; +// } segs[t.gate].gates.push_back(i); segs[t.c1].c1c2s.push_back(i); segs[t.c2].c1c2s.push_back(i); diff --git a/trans.cpp b/trans.cpp index ef07706..7b92dd8 100644 --- a/trans.cpp +++ b/trans.cpp @@ -6,5 +6,3 @@ */ #include "trans.h" -#include "SegmentCache.h" -#include diff --git a/trans.h b/trans.h index 8d38152..0e4dabc 100644 --- a/trans.h +++ b/trans.h @@ -9,23 +9,21 @@ #define TRANS_H #include -#include -#include +#include class Trans; -class SegmentCache; class Segment { public: std::string id; - std::vector gates; - std::vector c1c2s; + std::set gates; + std::set c1c2s; bool pullup; bool pulldown; bool on; - Segment(std::string& id) : id(id) { + Segment(std::string& id) : id(id), on(false), pulldown(false), pullup(id[0] == '+') { } }; @@ -39,6 +37,9 @@ private: public: Trans(Segment* c1, Segment* gate, Segment* c2) : on(false), c1(c1), gate(gate), c2(c2) { + c1->c1c2s.insert(this); + gate->gates.insert(this); + c2->c1c2s.insert(this); } virtual ~Trans() { diff --git a/v6502.cpp b/v6502.cpp index e06f515..653461f 100644 --- a/v6502.cpp +++ b/v6502.cpp @@ -37,7 +37,7 @@ // } //} -int main(int argc, char *argv[]) { +int xxxmain(int argc, char *argv[]) { std::ifstream if_trans("transistors"); if (!if_trans.is_open()) { std::cerr << "error opening file: transistors" << std::endl; @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) { TransNetwork n(if_trans); } -int xxxmain(int argc, char *argv[]) { +int main(int argc, char *argv[]) { AddressBus mem; CPU cpu(mem);