mirror of
https://github.com/cmosher01/v6502cpp.git
synced 2025-04-14 09:36:59 +00:00
refactor: add vss and vcc bools to seg
This commit is contained in:
parent
c2a0bd5937
commit
a10889ecd8
23
Circuit.cpp
23
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;
|
||||
|
@ -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<Segment*> segs;
|
||||
Segment* VSS;
|
||||
Segment* VCC;
|
||||
};
|
||||
|
||||
#endif /* CIRCUIT_H */
|
||||
|
@ -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<Segment*> s) {
|
||||
StateCalculator::recalc(s,n->VSS,n->VCC);
|
||||
StateCalculator::recalc(s);
|
||||
}
|
||||
|
||||
void Cpu6502::initPins() {
|
||||
|
@ -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 {
|
||||
|
@ -10,9 +10,6 @@
|
||||
#include "trans.h"
|
||||
#include <set>
|
||||
|
||||
StateCalculator::StateCalculator(Segment* VSS, Segment* VCC) : VSS(VSS), VCC(VCC) {
|
||||
}
|
||||
|
||||
//void StateCalculator::recalcAll() {
|
||||
// std::set<int> 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<Segment*> 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<Segment*>& segs, Segment* VSS, Segment* VCC) {
|
||||
void StateCalculator::recalc(const std::set<Segment*>& segs) {
|
||||
int sanity(0);
|
||||
|
||||
std::set<Segment*> changed(segs);
|
||||
@ -44,7 +41,7 @@ void StateCalculator::recalc(const std::set<Segment*>& 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<Segment*>& 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);
|
||||
}
|
||||
}
|
||||
|
@ -15,15 +15,14 @@ class Trans;
|
||||
|
||||
class StateCalculator {
|
||||
public:
|
||||
static void recalc(const std::set<Segment*>& rSeg, Segment* VSS, Segment* VCC);
|
||||
static void recalc(Segment* seg, Segment* VSS, Segment* VCC);
|
||||
static void recalc(const std::set<Segment*>& rSeg);
|
||||
static void recalc(Segment* seg);
|
||||
|
||||
private:
|
||||
std::set<Segment*> segs;
|
||||
Segment* VSS;
|
||||
Segment* VCC;
|
||||
|
||||
StateCalculator(Segment* VSS, Segment* VCC);
|
||||
StateCalculator() {
|
||||
}
|
||||
|
||||
virtual ~StateCalculator() {
|
||||
}
|
||||
|
@ -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 */
|
||||
|
5
trans.h
5
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) {
|
||||
|
23
v6502.cpp
23
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user