This commit is contained in:
cmosher 2011-06-24 17:29:08 +00:00
parent 3e91644957
commit 3dab7ff2d4
2 changed files with 129 additions and 19 deletions

25
segs
View File

@ -1,5 +1,3 @@
0 1
1 0
2 0
3 1
@ -29,6 +27,7 @@
27 1
28 0
29 1
31 1
32 0
33 1
@ -142,6 +141,7 @@
141 1
142 1
143 1
145 1
146 1
147 0
@ -170,6 +170,7 @@
170 0
171 0
172 1
174 1
175 0
176 1
@ -286,6 +287,7 @@
287 1
288 1
289 0
291 1
292 0
293 1
@ -406,6 +408,7 @@
408 0
409 1
410 1
412 1
413 0
414 0
@ -491,6 +494,7 @@
494 1
495 0
496 1
498 0
499 1
500 1
@ -535,6 +539,7 @@
539 0
540 1
541 0
543 1
544 1
545 0
@ -555,6 +560,7 @@
560 0
561 0
562 0
564 1
565 1
566 1
@ -640,7 +646,7 @@
646 1
647 1
648 0
649 1
0649 1
650 0
651 1
652 1
@ -740,6 +746,7 @@
746 1
747 1
748 1
750 1
751 0
752 0
@ -898,12 +905,14 @@
905 1
906 1
907 0
909 1
910 1
911 0
912 0
913 1
914 0
916 1
917 1
918 1
@ -1115,6 +1124,7 @@
1124 0
1125 1
1126 0
1128 0
1129 1
1130 1
@ -1194,6 +1204,8 @@
1204 1
1205 1
1206 1
1209 1
1210 1
1211 1
@ -1246,6 +1258,7 @@
1258 1
1259 1
1260 1
1262 1
1263 0
1264 0
@ -1301,6 +1314,7 @@
1314 1
1315 1
1316 1
1318 1
1319 1
1320 1
@ -1344,7 +1358,9 @@
1358 1
1359 0
1360 0
1362 0
1364 1
1365 0
1366 0
@ -1442,6 +1458,7 @@
1458 1
1459 1
1460 1
1462 1
1463 1
1464 1
@ -1643,6 +1660,7 @@
1660 1
1661 0
1662 1
1664 1
1665 1
1666 0
@ -1680,6 +1698,7 @@
1698 0
1699 0
1700 0
1702 0
1703 0
1704 1

123
v6502.cpp
View File

@ -100,12 +100,12 @@ void setSeg(int iseg, bool up) {
s.pulldown = !up;
}
void recalc(const std::vector<int>& s);
void recalc(const std::set<int>& s);
void setSegRC(int iseg, bool up) {
setSeg(iseg,up);
std::vector<int> s;
s.push_back(iseg);
std::set<int> s;
s.insert(iseg);
recalc(s);
}
@ -136,8 +136,88 @@ bool getGroupValue(const std::set<int>& s) {
return false;
}
void recalc(const std::vector<int>& s) {
/* TODO */
void addToGroup(int n, std::set<int>& s) {
s.insert(n);
if (n==VCC || n==VSS) {
return;
}
seg& sg = segs[n];
for (std::vector<int>::const_iterator itrn = sg.c1c2s.begin(); itrn != sg.c1c2s.end(); ++itrn) {
const trn& t = trns[*itrn];
if (t.on) {
if (t.c1==n) {
addToGroup(t.c2,s);
} else if (t.c2==n) {
addToGroup(t.c1,s);
}
}
}
}
void addRecalc(int n, std::set<int>& rcl) {
if (n==VCC || n==VSS) {
return;
}
rcl.insert(n);
}
void onTrans(trn& t, std::set<int>& rcl) {
if (t.on) {
return;
}
t.on = true;
addRecalc(t.c1,rcl);
}
void offTrans(trn& t, std::set<int>& rcl) {
if (!t.on) {
return;
}
t.on = false;
addRecalc(t.c1,rcl);
addRecalc(t.c2,rcl);
}
void recalcNode(int n, std::set<int>& rcl) {
if (n==VCC || n==VSS) {
return;
}
std::set<int> g;
addToGroup(n,g);
const bool gval = getGroupValue(g);
for (std::set<int>::iterator ig = g.begin(); ig != g.end(); ++ig) {
seg& seg = segs[*ig];
if (seg.state != gval) {
seg.state = gval;
for (std::vector<int>::iterator igate = seg.gates.begin(); igate != seg.gates.end(); ++igate) {
trn& t = trns[*igate];
if (seg.state) {
onTrans(t,rcl);
} else {
offTrans(t,rcl);
}
}
}
}
}
void recalc(const std::set<int>& s) {
std::set<int> list(s);
for (int sane = 0; sane < 1000; ++sane) {
if (!list.size()) {
return;
}
std::cout << "recalc node count: " << list.size() << std::endl;
std::set<int> rcl;
for (std::set<int>::iterator ilist = list.begin(); ilist != list.end(); ++ilist) {
recalcNode(*ilist,rcl);
}
list = rcl;
if (sane >= 999) {
std::cout << "WARNING: hit iteration limit during CPU state recalculation" << std::endl;
}
}
}
void recalcAll() {
@ -155,31 +235,31 @@ void mWrite(unsigned short addr, unsigned char data) {
void putDataToChip(unsigned char data) {
unsigned char x = data;
std::vector<int> s;
std::set<int> s;
setSeg(DB0,x&1);
s.push_back(DB0);
s.insert(DB0);
x >>= 1;
setSeg(DB1,x&1);
s.push_back(DB1);
s.insert(DB1);
x >>= 1;
setSeg(DB2,x&1);
s.push_back(DB2);
s.insert(DB2);
x >>= 1;
setSeg(DB3,x&1);
s.push_back(DB3);
s.insert(DB3);
x >>= 1;
setSeg(DB4,x&1);
s.push_back(DB4);
s.insert(DB4);
x >>= 1;
setSeg(DB5,x&1);
s.push_back(DB5);
s.insert(DB5);
x >>= 1;
setSeg(DB6,x&1);
s.push_back(DB6);
s.insert(DB6);
x >>= 1;
setSeg(DB7,x&1);
s.push_back(DB7);
s.insert(DB7);
recalc(s);
}
@ -203,18 +283,28 @@ void step() {
}
void init() {
std::cout << "initializing CPU..." << std::endl;
segs[VCC].state = true;
std::cout << " 'RESET" << std::endl;
setLow(RES);
std::cout << " 'CLK0" << std::endl;
setLow(CLK0);
std::cout << " RDY" << std::endl;
setHigh(RDY);
std::cout << " 'SO" << std::endl;
setLow(SO);
std::cout << " IRQ" << std::endl;
setHigh(IRQ);
std::cout << " NMI" << std::endl;
setHigh(NMI);
recalcAll();
for (int i(0); i < 8; ++i) {
std::cout << " CLK0" << std::endl;
setHigh(CLK0);
std::cout << " 'CLK0" << std::endl;
setLow(CLK0);
}
std::cout << " RESET" << std::endl;
setHigh(RES);
}
@ -306,7 +396,8 @@ int main(int argc, char *argv[])
*/
/*dump regs
/*dump regs*/
std::cout << "regs: " << std::endl;
pHex(rA());
pHex(rX());
pHex(rY());
@ -315,7 +406,7 @@ int main(int argc, char *argv[])
pHex(rData());
pHexw(rAddr());
std::cout << std::endl;
*/
/**/
return 0;
}