refactor; also notices intermittent failures

This commit is contained in:
Christopher Mosher 2013-12-14 00:26:34 -05:00
parent 540862e22b
commit c2a0bd5937
4 changed files with 22 additions and 20 deletions

View File

@ -17,7 +17,7 @@ Circuit::Circuit(Segment* extendFrom, Segment* VSS, Segment* VCC) : VSS(VSS), VC
* This happens recursively, but we don't recurse past ground or voltage supply. * This happens recursively, but we don't recurse past ground or voltage supply.
*/ */
void Circuit::extend(Segment* extendFrom) { void Circuit::extend(Segment* extendFrom) {
const std::pair < std::set<Segment*>::iterator, bool> ret = this->segs.insert(extendFrom); auto ret = this->segs.insert(extendFrom);
if (!ret.second) { if (!ret.second) {
return; return;
} }
@ -34,8 +34,7 @@ void Circuit::extend(Segment* extendFrom) {
* to OFF, so at the time of the very first recalcAll call, *no* other * to OFF, so at the time of the very first recalcAll call, *no* other
* segments will be added here. * segments will be added here.
*/ */
for (std::set<Trans*>::const_iterator iTrn = extendFrom->c1c2s.begin(); iTrn != extendFrom->c1c2s.end(); ++iTrn) { for (auto t : extendFrom->c1c2s) {
const Trans * t(*iTrn);
if (t->on) { if (t->on) {
if (t->c1 == extendFrom) { if (t->c1 == extendFrom) {
extend(t->c2); extend(t->c2);
@ -62,8 +61,7 @@ bool Circuit::getValue() {
for (std::set<Segment*>::const_iterator iSeg = this->segs.begin(); iSeg != this->segs.end(); ++iSeg) { for (auto s : this->segs) {
Segment * s(*iSeg);
if (s->pullup) { if (s->pullup) {
return true; return true;
} }

View File

@ -28,7 +28,7 @@ public:
std::set<Segment*> all() { std::set<Segment*> all() {
std::set<Segment*> s; std::set<Segment*> s;
for (auto i : cache) { for (auto i : this->cache) {
s.insert(i.second.get()); s.insert(i.second.get());
} }
return s; return s;

View File

@ -10,15 +10,19 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
static void pHex(const unsigned char x) { static void pHex(const unsigned long x, const int width) {
std::cout << std::setw(2) << std::setfill('0') << std::hex << (unsigned long) x << std::dec; std::cout << std::setw(width) << std::setfill('0') << std::hex << x << std::dec;
}
static void pHexb(const unsigned char x) {
pHex(x,2);
} }
static void pHexw(const unsigned short x) { static void pHexw(const unsigned short x) {
std::cout << std::setw(4) << std::setfill('0') << std::hex << (unsigned long) x << std::dec; pHex(x,4);
} }
void Trace::dumpSegments() { void Trace::dumpSegments() const {
// for (int i = 0; i < segs.size(); ++i) { // for (int i = 0; i < segs.size(); ++i) {
// seg& s = segs[i]; // seg& s = segs[i];
// if (s.pullup) { // if (s.pullup) {
@ -37,13 +41,13 @@ void Trace::dumpSegments() {
// std::cout << std::endl; // std::cout << std::endl;
} }
void Trace::dumpRegisters() { void Trace::dumpRegisters() const {
std::cout << "A"; std::cout << "A";
pHex(s.rA()); pHexb(s.rA());
std::cout << " X"; std::cout << " X";
pHex(s.rX()); pHexb(s.rX());
std::cout << " Y"; std::cout << " Y";
pHex(s.rY()); pHexb(s.rY());
std::cout << " "; std::cout << " ";
std::cout << (s.c->P7->on ? "N" : "n"); std::cout << (s.c->P7->on ? "N" : "n");
std::cout << (s.c->P6->on ? "V" : "v"); std::cout << (s.c->P6->on ? "V" : "v");
@ -54,7 +58,7 @@ void Trace::dumpRegisters() {
std::cout << (s.c->P1->on ? "Z" : "z"); std::cout << (s.c->P1->on ? "Z" : "z");
std::cout << (s.c->P0->on ? "C" : "c"); std::cout << (s.c->P0->on ? "C" : "c");
std::cout << " S"; std::cout << " S";
pHex(s.rS()); pHexb(s.rS());
std::cout << " PC"; std::cout << " PC";
pHexw(s.rPC()); pHexw(s.rPC());
if (s.c->CLK1OUT->on) { if (s.c->CLK1OUT->on) {
@ -72,7 +76,7 @@ void Trace::dumpRegisters() {
std::cout << " PH- "; std::cout << " PH- ";
} }
std::cout << " DB"; std::cout << " DB";
pHex(s.rData()); pHexb(s.rData());
std::cout << " AB"; std::cout << " AB";
pHexw(s.rAddr()); pHexw(s.rAddr());
std::cout << std::endl; std::cout << std::endl;

View File

@ -15,12 +15,12 @@ public:
Trace(const SegmentCache& s) : s(s) {} Trace(const SegmentCache& s) : s(s) {}
virtual ~Trace() {} virtual ~Trace() {}
void dumpSegments(); void dumpSegments() const;
void dumpRegisters(); void dumpRegisters() const;
private: private:
Trace(const Trace&); Trace(const Trace&) = delete;
Trace& operator=(const Trace&); Trace& operator=(const Trace&) = delete;
const SegmentCache& s; const SegmentCache& s;
}; };