Thanks! I do know C, but I've been playing with the JS version, so i'll stick with that for now. (:
I may have spoken a bit too soon. It seems that although the states the simulator goes through are different (i checksum a list of all high nodes), the output is the same. At least up to the 10k cycles i was testing just now. I do occasionally see different values in some registers (X, Y, SP) but it doesn't seem to have affected the program's execution (the PC and memory match).
I'm using nodejs and a small shim script to run the simulator from the command line. The program being executed by the chip is just the small one included in testprogram.js.
Code:
V6502DIR=../visual6502
cat \
$V6502DIR/segdefs.js \
$V6502DIR/transdefs.js \
$V6502DIR/nodenames.js \
$V6502DIR/chipsim.js \
$V6502DIR/macros.js \
$V6502DIR/wires.js \
$V6502DIR/testprogram.js \
shim.js | node -
shim.js:
Code:
golden = 'cdf976ab';
now = Date.now;
function setCellValue() {}
function selectCell() {}
function refresh() {}
function setStatus(a, b, c) {
var chk = adler32(activeNodes());
if (chk == golden) chk += ' OK';
console.log((a+' '+b+' '+c).replace('‑', '-').replace(/ Hz:.*/, '')+' '+chk);
}
consolebox = {};
userCode = [];
userResetLow = undefined;
userResetHigh = undefined;
function activeNodes() {
var list = [];
for (var n in nodes) {
if (nodes[n].state)
list.push(parseInt(n));
}
// by default, list.sort() compares as string (even when given numbers)
list.sort(function(a, b) {
return a < b ? -1 : 1;
});
return list.join(',');
}
function shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}
setupNodes();
setupTransistors();
loadProgram();
initChip();
for (var i = 0; i < 10000; i++) {
halfStep();
cycle++;
chipStatus();
}
chipStatus();
console.log('memory', memory.slice(0, 32).join(','));
Shuffle test locations:
Code:
// in macros.js, replace
recalcNodeList(allNodes());
// with
var list = allNodes(); shuffle(list);
recalcNodeList(list);
// and in chipsim.js, just insert the call at the top of the function
function recalcNodeList(list){
shuffle(list);
With no shuffles, the last lines of the simulation are:
Code:
halfcyc:10000 phi0:0 AB:000f D:f2 RnW:0 PC:0014 A:16 X:b3 Y:4d SP:fb Nv-BdIzc cdf976ab OK
memory 169,0,32,16,0,76,2,0,0,0,0,0,0,0,0,242,232,136,230,15,56,105,2,96,,,,,,,,
The 242 is the number the test program is incrementing.
And here are some examples with both shuffles enabled:
Code:
halfcyc:10000 phi0:0 AB:000f D:f2 RnW:0 PC:0014 A:16 X:b3 Y:4d SP:fb Nv-BdIzc 597c751f
memory 169,0,32,16,0,76,2,0,0,0,0,0,0,0,0,242,232,136,230,15,56,105,2,96,,,,,,,,
halfcyc:10000 phi0:0 AB:000f D:f2 RnW:0 PC:0014 A:16 X:56 Y:8d SP:fb Nv-BdIzc 14b177ac
memory 169,0,32,16,0,76,2,0,0,0,0,0,0,0,0,242,232,136,230,15,56,105,2,96,,,,,,,,
halfcyc:10000 phi0:0 AB:000f D:f2 RnW:0 PC:0014 A:16 X:b3 Y:4d SP:fb Nv-BdIzc 3b7571a4
memory 169,0,32,16,0,76,2,0,0,0,0,0,0,0,0,242,232,136,230,15,56,105,2,96,,,,,,,,
halfcyc:10000 phi0:0 AB:000f D:f2 RnW:0 PC:0014 A:16 X:c3 Y:8d SP:fb Nv-BdIzc 842d700e
memory 169,0,32,16,0,76,2,0,0,0,0,0,0,0,0,242,232,136,230,15,56,105,2,96,,,,,,,,
halfcyc:10000 phi0:0 AB:000f D:f2 RnW:0 PC:0014 A:16 X:c3 Y:7d SP:1f Nv-BdIzc a62275c9
memory 169,0,32,16,0,76,2,0,0,0,0,0,0,0,0,242,232,136,230,15,56,105,2,96,,,,,,,,
I'm assuming this isn't caused by the way I've pulled the simulator out of the rest of the code. But that is entirely possible. Perhaps i'll check against the C version.
I'm not convinced i know what's going on at all here. Intuitively it makes sense to me that different converged states could lead to the same behaviors (some state information just gets discarded), but it is kind of disconcerting to see different values showing up in the registers.
Update before i actually post: it happens in the C version too. Like with the JS version, it doesn't seem to actually cause the simulation to diverge (aside from X, Y, and occasionally SP containing garbage). I took it out to 100k and 1m cycles and it seemed like it was behaving?
Code:
halfcyc:100017 phi0:0 AB:0016 D:69 RnW:1 PC:0016 A:EB X:FA Y:06 SP:FB P:15 IR:69
169,0,32,16,0,76,2,0,0,0,0,0,0,0,0,58,232,136,230,15,56,105,2,96,0,0,0,0,0,0,0,0
halfcyc:100017 phi0:0 AB:0016 D:69 RnW:1 PC:0016 A:EB X:7A Y:CC SP:38 P:15 IR:69
169,0,32,16,0,76,2,0,0,0,0,0,0,0,0,58,232,136,230,15,56,105,2,96,0,0,0,0,0,0,0,0
The four tests i ran at 1m cycles actually all came out identical:
Code:
halfcyc:1000017 phi0:0 AB:01FD D:10 RnW:1 PC:0004 A:43 X:C1 Y:3F SP:10 P:14 IR:20
169,0,32,16,0,76,2,0,0,0,0,0,0,0,0,1,232,136,230,15,56,105,2,96,0,0,0,0,0,0,0,0