done reading trans network

This commit is contained in:
Christopher Mosher 2013-12-12 08:37:45 -05:00
parent e8ae299597
commit 654d0510c8
8 changed files with 30 additions and 30 deletions

View File

@ -11,7 +11,7 @@ cpu.o: cpu.cpp cpu.h addressbus.h nodes.h
nodes.o: nodes.cpp nodes.h
trans.o: trans.cpp trans.h SegmentCache.h
trans.o: trans.cpp trans.h
SegmentCache.o: SegmentCache.cpp SegmentCache.h
@ -20,3 +20,4 @@ TransNetwork.o: TransNetwork.cpp TransNetwork.h trans.h
clean:
-rm *.o
-rm v6502
-rm v6502.exe

View File

@ -9,7 +9,6 @@
#include <memory>
#include <string>
#include <map>
#include <algorithm>
Segment* SegmentCache::getOrAdd(std::string& id) {
if (this->cache.find(id) == this->cache.end()) {

View File

@ -7,21 +7,16 @@
#include "TransNetwork.h"
#include "trans.h"
#include "SegmentCache.h"
#include <memory>
#include <iostream>
TransNetwork::TransNetwork(std::istream& readFromHere) {
SegmentCache segs;
TransNetwork::TransNetwork(std::istream& in) {
std::string c1, gate, c2;
readFromHere >> c1 >> gate >> c2;
while (readFromHere.good()) {
Trans trans(segs.getOrAdd(c1), segs.getOrAdd(gate), segs.getOrAdd(c2));
std::cout << trans;
readFromHere >> c1 >> gate >> c2;
in >> c1 >> gate >> c2;
while (in.good()) {
this->transes.insert(std::make_shared<Trans>(this->segs.getOrAdd(c1), this->segs.getOrAdd(gate), this->segs.getOrAdd(c2)));
in >> c1 >> gate >> c2;
}
std::cout << std::endl << "done" << std::endl;
}
TransNetwork::~TransNetwork() {

View File

@ -8,9 +8,15 @@
#ifndef TRANSNETWORK_H
#define TRANSNETWORK_H
#include "trans.h"
#include "SegmentCache.h"
#include <istream>
class TransNetwork {
private:
SegmentCache segs;
std::set<std::shared_ptr<Trans>> transes;
public:
TransNetwork(std::istream& readFromHere);
virtual ~TransNetwork();

14
cpu.cpp
View File

@ -110,13 +110,13 @@ addressBus(addressBus) {
for (int i = 0; i != trns.size(); ++i) {
trn& t = trns[i];
if (t.c1 == n->VSS) {
t.c1 = t.c2;
t.c2 = n->VSS;
} else if (t.c1 == n->VCC) {
t.c1 = t.c2;
t.c2 = n->VCC;
}
// if (t.c1 == n->VSS) {
// t.c1 = t.c2;
// t.c2 = n->VSS;
// } else if (t.c1 == n->VCC) {
// t.c1 = t.c2;
// t.c2 = n->VCC;
// }
segs[t.gate].gates.push_back(i);
segs[t.c1].c1c2s.push_back(i);
segs[t.c2].c1c2s.push_back(i);

View File

@ -6,5 +6,3 @@
*/
#include "trans.h"
#include "SegmentCache.h"
#include <istream>

13
trans.h
View File

@ -9,23 +9,21 @@
#define TRANS_H
#include <string>
#include <vector>
#include <iostream>
#include <set>
class Trans;
class SegmentCache;
class Segment {
public:
std::string id;
std::vector<Trans*> gates;
std::vector<Trans*> c1c2s;
std::set<Trans*> gates;
std::set<Trans*> c1c2s;
bool pullup;
bool pulldown;
bool on;
Segment(std::string& id) : id(id) {
Segment(std::string& id) : id(id), on(false), pulldown(false), pullup(id[0] == '+') {
}
};
@ -39,6 +37,9 @@ private:
public:
Trans(Segment* c1, Segment* gate, Segment* c2) : on(false), c1(c1), gate(gate), c2(c2) {
c1->c1c2s.insert(this);
gate->gates.insert(this);
c2->c1c2s.insert(this);
}
virtual ~Trans() {

View File

@ -37,7 +37,7 @@
// }
//}
int main(int argc, char *argv[]) {
int xxxmain(int argc, char *argv[]) {
std::ifstream if_trans("transistors");
if (!if_trans.is_open()) {
std::cerr << "error opening file: transistors" << std::endl;
@ -46,7 +46,7 @@ int main(int argc, char *argv[]) {
TransNetwork n(if_trans);
}
int xxxmain(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
AddressBus mem;
CPU cpu(mem);