From a10889ecd87fc937a86299c15602a758c66a29b9 Mon Sep 17 00:00:00 2001 From: Christopher Mosher Date: Sat, 14 Dec 2013 01:04:55 -0500 Subject: [PATCH] refactor: add vss and vcc bools to seg --- Circuit.cpp | 23 +++++++++++++---------- Circuit.h | 8 +------- Cpu6502.cpp | 4 ++-- SegmentCache.cpp | 3 +++ StateCalculator.cpp | 17 +++++++---------- StateCalculator.h | 9 ++++----- TransNetwork.h | 4 ++-- trans.h | 5 ++++- v6502.cpp | 23 +++++++++++++---------- 9 files changed, 49 insertions(+), 47 deletions(-) diff --git a/Circuit.cpp b/Circuit.cpp index 56081f8..b6ef4e7 100644 --- a/Circuit.cpp +++ b/Circuit.cpp @@ -8,7 +8,7 @@ #include "Circuit.h" #include "trans.h" -Circuit::Circuit(Segment* extendFrom, Segment* VSS, Segment* VCC) : VSS(VSS), VCC(VCC) { +Circuit::Circuit(Segment* extendFrom) { extend(extendFrom); } @@ -21,7 +21,7 @@ void Circuit::extend(Segment* extendFrom) { if (!ret.second) { return; } - if (extendFrom == this->VCC || extendFrom == this->VSS) { + if (extendFrom->vss || extendFrom->vcc) { return; } @@ -52,15 +52,18 @@ void Circuit::extend(Segment* extendFrom) { */ bool Circuit::getValue() { /* If group contains ground, it's OFF, */ - if (contains(this->VSS)) { - return false; - }/* otherwise, if group contains voltage supply, it's ON. */ - else if (contains(this->VCC)) { - return true; + for (auto s : this->segs) { + if (s->vss) { + return false; + } } - - - + /* otherwise, if group contains voltage supply, it's ON. */ + for (auto s : this->segs) { + if (s->vcc) { + return true; + } + } + /* otherwise, this test: */ for (auto s : this->segs) { if (s->pullup) { return true; diff --git a/Circuit.h b/Circuit.h index a55ac17..edfb112 100644 --- a/Circuit.h +++ b/Circuit.h @@ -14,7 +14,7 @@ class Segment; class Circuit { public: - Circuit(Segment* extendFrom, Segment* VSS, Segment* VCC); + Circuit(Segment* extendFrom); virtual ~Circuit() { } @@ -29,13 +29,7 @@ private: void extend(Segment* extendFrom); - bool contains(Segment* s) const { - return this->segs.find(s) != this->segs.end(); - } - std::set segs; - Segment* VSS; - Segment* VCC; }; #endif /* CIRCUIT_H */ diff --git a/Cpu6502.cpp b/Cpu6502.cpp index fc55950..9616172 100644 --- a/Cpu6502.cpp +++ b/Cpu6502.cpp @@ -69,11 +69,11 @@ void Cpu6502::setSeg(Segment* s, bool on) { } void Cpu6502::recalc(Segment* s) { - StateCalculator::recalc(s,n->VSS,n->VCC); + StateCalculator::recalc(s); } void Cpu6502::recalc(std::set s) { - StateCalculator::recalc(s,n->VSS,n->VCC); + StateCalculator::recalc(s); } void Cpu6502::initPins() { diff --git a/SegmentCache.cpp b/SegmentCache.cpp index 872bc71..74935d4 100644 --- a/SegmentCache.cpp +++ b/SegmentCache.cpp @@ -42,6 +42,9 @@ void SegmentCache::initCommon() { get("-pch0"), get("-pch1"), get("-pch2"), get("-pch3"), get("-pch4"), get("-pch5"), get("-pch6"), get("-pch7"), get("+Pout0"), get("+Pout1"), get("+Pout2"), get("+Pout3"), get("+Pout4"), /*no P5 */get("+Pout6"), get("+Pout7"), get("-s0"), get("-s1"), get("-s2"), get("-s3"), get("-s4"), get("-s5"), get("-s6"), get("-s7")); + + this->c->VSS->vss = true; + this->c->VCC->vcc = true; } unsigned char SegmentCache::rData() const { diff --git a/StateCalculator.cpp b/StateCalculator.cpp index 857c38f..33c7fd4 100644 --- a/StateCalculator.cpp +++ b/StateCalculator.cpp @@ -10,9 +10,6 @@ #include "trans.h" #include -StateCalculator::StateCalculator(Segment* VSS, Segment* VCC) : VSS(VSS), VCC(VCC) { -} - //void StateCalculator::recalcAll() { // std::set riSeg; // for (int iSeg = 0; iSeg < segs.size(); ++iSeg) { @@ -21,10 +18,10 @@ StateCalculator::StateCalculator(Segment* VSS, Segment* VCC) : VSS(VSS), VCC(VCC // recalc(riSeg); //} -void StateCalculator::recalc(Segment* seg, Segment* VSS, Segment* VCC) { +void StateCalculator::recalc(Segment* seg) { std::set rSeg; rSeg.insert(seg); - recalc(rSeg, VSS, VCC); + recalc(rSeg); } /* @@ -35,7 +32,7 @@ void StateCalculator::recalc(Segment* seg, Segment* VSS, Segment* VCC) { */ #define SANE (100) -void StateCalculator::recalc(const std::set& segs, Segment* VSS, Segment* VCC) { +void StateCalculator::recalc(const std::set& segs) { int sanity(0); std::set changed(segs); @@ -44,7 +41,7 @@ void StateCalculator::recalc(const std::set& segs, Segment* VSS, Segme throw "ERROR: reached maximum iteration limit while recalculating CPU state"; } - StateCalculator c(VSS, VCC); + StateCalculator c; for (auto s : changed) { c.recalcNode(s); } @@ -61,8 +58,8 @@ void StateCalculator::recalc(const std::set& segs, Segment* VSS, Segme * to riSegChanged. */ void StateCalculator::recalcNode(Segment* seg) { - if (!(seg == this->VSS || seg == this->VCC)) { - Circuit c(seg, this->VSS, this->VCC); + if (!(seg->vss || seg->vcc)) { + Circuit c(seg); for (auto s : c) { setSeg(s, c.getValue()); } @@ -87,7 +84,7 @@ void StateCalculator::setTrans(Trans* t, const bool on) { } void StateCalculator::addRecalc(Segment* seg) { - if (!(seg == this->VSS || seg == this->VCC)) { + if (!(seg->vss || seg->vcc)) { this->segs.insert(seg); } } diff --git a/StateCalculator.h b/StateCalculator.h index f624287..2eebcd7 100644 --- a/StateCalculator.h +++ b/StateCalculator.h @@ -15,15 +15,14 @@ class Trans; class StateCalculator { public: - static void recalc(const std::set& rSeg, Segment* VSS, Segment* VCC); - static void recalc(Segment* seg, Segment* VSS, Segment* VCC); + static void recalc(const std::set& rSeg); + static void recalc(Segment* seg); private: std::set segs; - Segment* VSS; - Segment* VCC; - StateCalculator(Segment* VSS, Segment* VCC); + StateCalculator() { + } virtual ~StateCalculator() { } diff --git a/TransNetwork.h b/TransNetwork.h index 838df67..c41a0a3 100644 --- a/TransNetwork.h +++ b/TransNetwork.h @@ -22,8 +22,8 @@ public: virtual ~TransNetwork(); private: - TransNetwork(const TransNetwork&); - TransNetwork& operator=(const TransNetwork&); + TransNetwork(const TransNetwork&) = delete; + TransNetwork& operator=(const TransNetwork&) = delete; }; #endif /* TRANSNETWORK_H */ diff --git a/trans.h b/trans.h index 345c658..8d1c4c2 100644 --- a/trans.h +++ b/trans.h @@ -23,7 +23,10 @@ public: bool pulldown; bool on; - Segment(const std::string& id) : id(id), on(false), pulldown(false), pullup(id[0] == '+') { + bool vss; + bool vcc; + + Segment(const std::string& id) : id(id), on(false), pulldown(false), pullup(id[0] == '+'), vss(false), vcc(false) { } void set(bool up) { diff --git a/v6502.cpp b/v6502.cpp index c8c2b9d..801b475 100644 --- a/v6502.cpp +++ b/v6502.cpp @@ -32,17 +32,7 @@ //} int main(int argc, char *argv[]) { - std::ifstream if_trans("transistors"); - if (!if_trans.is_open()) { - std::cerr << "error opening file: transistors" << std::endl; - exit(EXIT_FAILURE); - } - TransNetwork tn(if_trans); AddressBus mem; - Trace trace(tn.segs); - Cpu6502 cpu(tn,mem,trace); - - /* Load some test program into memory */ mem.write(0x0200, 0xEA); // NOP @@ -61,6 +51,19 @@ int main(int argc, char *argv[]) { + std::ifstream if_trans("transistors"); + if (!if_trans.is_open()) { + std::cerr << "error opening file: transistors" << std::endl; + exit(EXIT_FAILURE); + } + TransNetwork tn(if_trans); + Trace trace(tn.segs); + Cpu6502 cpu(tn,mem,trace); + + + + + /* turn on the CPU */ std::cout << "----------------------------------------" << std::endl; std::cout << "begin power-up..." << std::endl;