mirror of
https://github.com/cmosher01/v6502cpp.git
synced 2024-10-31 16:05:31 +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 "Circuit.h"
|
||||||
#include "trans.h"
|
#include "trans.h"
|
||||||
|
|
||||||
Circuit::Circuit(Segment* extendFrom, Segment* VSS, Segment* VCC) : VSS(VSS), VCC(VCC) {
|
Circuit::Circuit(Segment* extendFrom) {
|
||||||
extend(extendFrom);
|
extend(extendFrom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ void Circuit::extend(Segment* extendFrom) {
|
|||||||
if (!ret.second) {
|
if (!ret.second) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (extendFrom == this->VCC || extendFrom == this->VSS) {
|
if (extendFrom->vss || extendFrom->vcc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,15 +52,18 @@ void Circuit::extend(Segment* extendFrom) {
|
|||||||
*/
|
*/
|
||||||
bool Circuit::getValue() {
|
bool Circuit::getValue() {
|
||||||
/* If group contains ground, it's OFF, */
|
/* If group contains ground, it's OFF, */
|
||||||
if (contains(this->VSS)) {
|
for (auto s : this->segs) {
|
||||||
return false;
|
if (s->vss) {
|
||||||
}/* otherwise, if group contains voltage supply, it's ON. */
|
return false;
|
||||||
else if (contains(this->VCC)) {
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
/* 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) {
|
for (auto s : this->segs) {
|
||||||
if (s->pullup) {
|
if (s->pullup) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -14,7 +14,7 @@ class Segment;
|
|||||||
|
|
||||||
class Circuit {
|
class Circuit {
|
||||||
public:
|
public:
|
||||||
Circuit(Segment* extendFrom, Segment* VSS, Segment* VCC);
|
Circuit(Segment* extendFrom);
|
||||||
|
|
||||||
virtual ~Circuit() {
|
virtual ~Circuit() {
|
||||||
}
|
}
|
||||||
@ -29,13 +29,7 @@ private:
|
|||||||
|
|
||||||
void extend(Segment* extendFrom);
|
void extend(Segment* extendFrom);
|
||||||
|
|
||||||
bool contains(Segment* s) const {
|
|
||||||
return this->segs.find(s) != this->segs.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<Segment*> segs;
|
std::set<Segment*> segs;
|
||||||
Segment* VSS;
|
|
||||||
Segment* VCC;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CIRCUIT_H */
|
#endif /* CIRCUIT_H */
|
||||||
|
@ -69,11 +69,11 @@ void Cpu6502::setSeg(Segment* s, bool on) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Cpu6502::recalc(Segment* s) {
|
void Cpu6502::recalc(Segment* s) {
|
||||||
StateCalculator::recalc(s,n->VSS,n->VCC);
|
StateCalculator::recalc(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cpu6502::recalc(std::set<Segment*> s) {
|
void Cpu6502::recalc(std::set<Segment*> s) {
|
||||||
StateCalculator::recalc(s,n->VSS,n->VCC);
|
StateCalculator::recalc(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cpu6502::initPins() {
|
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("-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("+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"));
|
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 {
|
unsigned char SegmentCache::rData() const {
|
||||||
|
@ -10,9 +10,6 @@
|
|||||||
#include "trans.h"
|
#include "trans.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
StateCalculator::StateCalculator(Segment* VSS, Segment* VCC) : VSS(VSS), VCC(VCC) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//void StateCalculator::recalcAll() {
|
//void StateCalculator::recalcAll() {
|
||||||
// std::set<int> riSeg;
|
// std::set<int> riSeg;
|
||||||
// for (int iSeg = 0; iSeg < segs.size(); ++iSeg) {
|
// for (int iSeg = 0; iSeg < segs.size(); ++iSeg) {
|
||||||
@ -21,10 +18,10 @@ StateCalculator::StateCalculator(Segment* VSS, Segment* VCC) : VSS(VSS), VCC(VCC
|
|||||||
// recalc(riSeg);
|
// recalc(riSeg);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void StateCalculator::recalc(Segment* seg, Segment* VSS, Segment* VCC) {
|
void StateCalculator::recalc(Segment* seg) {
|
||||||
std::set<Segment*> rSeg;
|
std::set<Segment*> rSeg;
|
||||||
rSeg.insert(seg);
|
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)
|
#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);
|
int sanity(0);
|
||||||
|
|
||||||
std::set<Segment*> changed(segs);
|
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";
|
throw "ERROR: reached maximum iteration limit while recalculating CPU state";
|
||||||
}
|
}
|
||||||
|
|
||||||
StateCalculator c(VSS, VCC);
|
StateCalculator c;
|
||||||
for (auto s : changed) {
|
for (auto s : changed) {
|
||||||
c.recalcNode(s);
|
c.recalcNode(s);
|
||||||
}
|
}
|
||||||
@ -61,8 +58,8 @@ void StateCalculator::recalc(const std::set<Segment*>& segs, Segment* VSS, Segme
|
|||||||
* to riSegChanged.
|
* to riSegChanged.
|
||||||
*/
|
*/
|
||||||
void StateCalculator::recalcNode(Segment* seg) {
|
void StateCalculator::recalcNode(Segment* seg) {
|
||||||
if (!(seg == this->VSS || seg == this->VCC)) {
|
if (!(seg->vss || seg->vcc)) {
|
||||||
Circuit c(seg, this->VSS, this->VCC);
|
Circuit c(seg);
|
||||||
for (auto s : c) {
|
for (auto s : c) {
|
||||||
setSeg(s, c.getValue());
|
setSeg(s, c.getValue());
|
||||||
}
|
}
|
||||||
@ -87,7 +84,7 @@ void StateCalculator::setTrans(Trans* t, const bool on) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StateCalculator::addRecalc(Segment* seg) {
|
void StateCalculator::addRecalc(Segment* seg) {
|
||||||
if (!(seg == this->VSS || seg == this->VCC)) {
|
if (!(seg->vss || seg->vcc)) {
|
||||||
this->segs.insert(seg);
|
this->segs.insert(seg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,14 @@ class Trans;
|
|||||||
|
|
||||||
class StateCalculator {
|
class StateCalculator {
|
||||||
public:
|
public:
|
||||||
static void recalc(const std::set<Segment*>& rSeg, Segment* VSS, Segment* VCC);
|
static void recalc(const std::set<Segment*>& rSeg);
|
||||||
static void recalc(Segment* seg, Segment* VSS, Segment* VCC);
|
static void recalc(Segment* seg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::set<Segment*> segs;
|
std::set<Segment*> segs;
|
||||||
Segment* VSS;
|
|
||||||
Segment* VCC;
|
|
||||||
|
|
||||||
StateCalculator(Segment* VSS, Segment* VCC);
|
StateCalculator() {
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~StateCalculator() {
|
virtual ~StateCalculator() {
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ public:
|
|||||||
virtual ~TransNetwork();
|
virtual ~TransNetwork();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TransNetwork(const TransNetwork&);
|
TransNetwork(const TransNetwork&) = delete;
|
||||||
TransNetwork& operator=(const TransNetwork&);
|
TransNetwork& operator=(const TransNetwork&) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* TRANSNETWORK_H */
|
#endif /* TRANSNETWORK_H */
|
||||||
|
5
trans.h
5
trans.h
@ -23,7 +23,10 @@ public:
|
|||||||
bool pulldown;
|
bool pulldown;
|
||||||
bool on;
|
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) {
|
void set(bool up) {
|
||||||
|
23
v6502.cpp
23
v6502.cpp
@ -32,17 +32,7 @@
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
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;
|
AddressBus mem;
|
||||||
Trace trace(tn.segs);
|
|
||||||
Cpu6502 cpu(tn,mem,trace);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Load some test program into memory */
|
/* Load some test program into memory */
|
||||||
mem.write(0x0200, 0xEA); // NOP
|
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 */
|
/* turn on the CPU */
|
||||||
std::cout << "----------------------------------------" << std::endl;
|
std::cout << "----------------------------------------" << std::endl;
|
||||||
std::cout << "begin power-up..." << std::endl;
|
std::cout << "begin power-up..." << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user