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.
*/
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) {
return;
}
@ -34,8 +34,7 @@ void Circuit::extend(Segment* extendFrom) {
* to OFF, so at the time of the very first recalcAll call, *no* other
* segments will be added here.
*/
for (std::set<Trans*>::const_iterator iTrn = extendFrom->c1c2s.begin(); iTrn != extendFrom->c1c2s.end(); ++iTrn) {
const Trans * t(*iTrn);
for (auto t : extendFrom->c1c2s) {
if (t->on) {
if (t->c1 == extendFrom) {
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) {
Segment * s(*iSeg);
for (auto s : this->segs) {
if (s->pullup) {
return true;
}

View File

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

View File

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

View File

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