Fixed line endings and Copyright notices

This commit is contained in:
Barry Silverman 2010-09-18 12:56:48 -04:00
parent d3223a9478
commit 6dd7e9c24e
9 changed files with 12643 additions and 12621 deletions

View File

@ -1,208 +1,208 @@
/* /*
Copyright (c) 2010 Brian Silverman, Barry Silverman Copyright (c) 2010 Brian Silverman, Barry Silverman
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
var ctrace = false; var ctrace = false;
var ridx = 0; var ridx = 0;
function recalcNodeList(list){ function recalcNodeList(list){
var n = list[0]; var n = list[0];
var recalclist = new Array(); var recalclist = new Array();
for(var j=0;j<100;j++){ // loop limiter for(var j=0;j<100;j++){ // loop limiter
if(list.length==0) return; if(list.length==0) return;
if(ctrace) console.log(j, list); if(ctrace) console.log(j, list);
for(var i in list) recalcNode(list[i], recalclist); for(var i in list) recalcNode(list[i], recalclist);
list = recalclist; list = recalclist;
recalclist = new Array(); recalclist = new Array();
} }
console.log(n,'looping...'); console.log(n,'looping...');
} }
function recalcNode(node, recalclist){ function recalcNode(node, recalclist){
if(node==ngnd) return; if(node==ngnd) return;
if(node==npwr) return; if(node==npwr) return;
var group = getNodeGroup(node); var group = getNodeGroup(node);
var newv = getNodeValue(group); var newv = getNodeValue(group);
if(ctrace) console.log('recalc', node, group); if(ctrace) console.log('recalc', node, group);
for(var i in group){ for(var i in group){
var n = nodes[group[i]]; var n = nodes[group[i]];
if(n.state!=newv && ctrace) console.log(group[i], n.state, newv); if(n.state!=newv && ctrace) console.log(group[i], n.state, newv);
n.state = newv; n.state = newv;
for(var t in n.gates) recalcTransistor(n.gates[t], recalclist); for(var t in n.gates) recalcTransistor(n.gates[t], recalclist);
} }
} }
function recalcTransistor(tn, recalclist){ function recalcTransistor(tn, recalclist){
var t = transistors[tn]; var t = transistors[tn];
if(isNodeHigh(t.gate)) turnTransistorOn(t, recalclist); if(isNodeHigh(t.gate)) turnTransistorOn(t, recalclist);
else turnTransistorOff(t, recalclist); else turnTransistorOff(t, recalclist);
} }
function turnTransistorOn(t, recalclist){ function turnTransistorOn(t, recalclist){
if(t.on) return; if(t.on) return;
if(ctrace) console.log(t.name, 'on', t.gate, t.c1, t.c2); if(ctrace) console.log(t.name, 'on', t.gate, t.c1, t.c2);
t.on = true; t.on = true;
addRecalcNode(t.c1, recalclist); addRecalcNode(t.c1, recalclist);
addRecalcNode(t.c2, recalclist); addRecalcNode(t.c2, recalclist);
} }
function turnTransistorOff(t, recalclist){ function turnTransistorOff(t, recalclist){
if(!t.on) return; if(!t.on) return;
if(ctrace) console.log(t.name, 'off', t.gate, t.c1, t.c2); if(ctrace) console.log(t.name, 'off', t.gate, t.c1, t.c2);
t.on = false; t.on = false;
floatnode(t.c1); floatnode(t.c1);
floatnode(t.c2); floatnode(t.c2);
addRecalcNode(t.c1, recalclist); addRecalcNode(t.c1, recalclist);
addRecalcNode(t.c2, recalclist); addRecalcNode(t.c2, recalclist);
} }
function floatnode(nn){ function floatnode(nn){
if(nn==ngnd) return; if(nn==ngnd) return;
if(nn==npwr) return; if(nn==npwr) return;
var n = nodes[nn]; var n = nodes[nn];
if(n.state=='gnd') n.state = 'fl'; if(n.state=='gnd') n.state = 'fl';
if(n.state=='pd') n.state = 'fl'; if(n.state=='pd') n.state = 'fl';
if(n.state=='vcc') n.state = 'fh'; if(n.state=='vcc') n.state = 'fh';
if(n.state=='pu') n.state = 'fh'; if(n.state=='pu') n.state = 'fh';
if(ctrace) console.log('floating', nn, 'to', n.state); if(ctrace) console.log('floating', nn, 'to', n.state);
} }
function addRecalcNode(nn, recalclist){ function addRecalcNode(nn, recalclist){
if(nn==ngnd) return; if(nn==ngnd) return;
if(nn==npwr) return; if(nn==npwr) return;
if(arrayContains(recalclist, nn)) return; if(arrayContains(recalclist, nn)) return;
recalclist.push(nn); recalclist.push(nn);
// setAdd(recalclist, nn); // setAdd(recalclist, nn);
} }
function getNodeGroup(i){ function getNodeGroup(i){
var group = new Array(); var group = new Array();
addNodeToGroup(i, group); addNodeToGroup(i, group);
return group; return group;
} }
function addNodeToGroup(i, group){ function addNodeToGroup(i, group){
if(arrayContains(group, i)) return; if(arrayContains(group, i)) return;
group.push(i); group.push(i);
if(i==ngnd) return; if(i==ngnd) return;
if(i==npwr) return; if(i==npwr) return;
for(var t in nodes[i].c1c2s) addNodeTransistor(i, nodes[i].c1c2s[t], group); for(var t in nodes[i].c1c2s) addNodeTransistor(i, nodes[i].c1c2s[t], group);
} }
function addNodeTransistor(node, t, group){ function addNodeTransistor(node, t, group){
var tr = transistors[t]; var tr = transistors[t];
if(!tr.on) return; if(!tr.on) return;
var other; var other;
if(tr.c1==node) other=tr.c2; if(tr.c1==node) other=tr.c2;
if(tr.c2==node) other=tr.c1; if(tr.c2==node) other=tr.c1;
addNodeToGroup(other, group); addNodeToGroup(other, group);
} }
function getNodeValue(group){ function getNodeValue(group){
if(arrayContains(group, ngnd)) return 'gnd'; if(arrayContains(group, ngnd)) return 'gnd';
if(arrayContains(group, npwr)) return 'vcc'; if(arrayContains(group, npwr)) return 'vcc';
var flstate; var flstate;
for(var i in group){ for(var i in group){
var nn = group[i]; var nn = group[i];
var n = nodes[nn]; var n = nodes[nn];
if(n.pullup) return 'pu'; if(n.pullup) return 'pu';
if(n.pulldown) return 'pd'; if(n.pulldown) return 'pd';
if((n.state=='fl')&&(flstate==undefined)) flstate = 'fl'; if((n.state=='fl')&&(flstate==undefined)) flstate = 'fl';
if(n.state=='fh') flstate = 'fh'; if(n.state=='fh') flstate = 'fh';
} }
if(flstate==undefined) console.log(group); if(flstate==undefined) console.log(group);
return flstate; return flstate;
} }
function isNodeHigh(nn){ function isNodeHigh(nn){
return arrayContains(['vcc','pu','fh'], nodes[nn].state); return arrayContains(['vcc','pu','fh'], nodes[nn].state);
} }
function saveString(name, str){ function saveString(name, str){
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.onreadystatechange=function(){}; request.onreadystatechange=function(){};
request.open('PUT', 'save.php?name='+name, true); request.open('PUT', 'save.php?name='+name, true);
request.setRequestHeader('Content-Type', 'text/plain'); request.setRequestHeader('Content-Type', 'text/plain');
request.send(str); request.send(str);
} }
function allNodes(){ function allNodes(){
var res = new Array(); var res = new Array();
for(var i in nodes) if((i!=npwr)&&(i!=ngnd)) res.push(i); for(var i in nodes) if((i!=npwr)&&(i!=ngnd)) res.push(i);
return res; return res;
} }
function stateString(){ function stateString(){
var codes = {gnd: 'g', vcc: 'v', pu: 'p', pd: 'd', fh: 'f', fl: 'l'}; var codes = {gnd: 'g', vcc: 'v', pu: 'p', pd: 'd', fh: 'f', fl: 'l'};
var res = ''; var res = '';
for(var i=0;i<1725;i++){ for(var i=0;i<1725;i++){
var n = nodes[i]; var n = nodes[i];
if(n==undefined) res+='x'; if(n==undefined) res+='x';
else if(i==ngnd) res+='g'; else if(i==ngnd) res+='g';
else if(i==npwr) res+='v'; else if(i==npwr) res+='v';
else res+= codes[n.state]; else res+= codes[n.state];
} }
return res; return res;
} }
function showState(str){ function showState(str){
var codes = {g: 'gnd', v: 'vcc', p: 'pu', d: 'pd', f: 'fh', l: 'fl'}; var codes = {g: 'gnd', v: 'vcc', p: 'pu', d: 'pd', f: 'fh', l: 'fl'};
for(var i=0;i<str.length;i++){ for(var i=0;i<str.length;i++){
if(str[i]=='x') continue; if(str[i]=='x') continue;
nodes[i].state = codes[str[i]]; nodes[i].state = codes[str[i]];
var gates = nodes[i].gates; var gates = nodes[i].gates;
for(var t in gates) transistors[gates[t]].on = isNodeHigh(i); for(var t in gates) transistors[gates[t]].on = isNodeHigh(i);
} }
refresh(); refresh();
} }
function setPd(name){ function setPd(name){
var nn = nodenames[name]; var nn = nodenames[name];
nodes[nn].pullup = false; nodes[nn].pullup = false;
nodes[nn].pulldown = true; nodes[nn].pulldown = true;
} }
function setHigh(name){ function setHigh(name){
var nn = nodenames[name]; var nn = nodenames[name];
nodes[nn].pullup = true; nodes[nn].pullup = true;
nodes[nn].pulldown = false; nodes[nn].pulldown = false;
recalcNodeList([nn]); recalcNodeList([nn]);
} }
function setLow(name){ function setLow(name){
var nn = nodenames[name]; var nn = nodenames[name];
nodes[nn].pullup = false; nodes[nn].pullup = false;
nodes[nn].pulldown = true; nodes[nn].pulldown = true;
recalcNodeList([nn]); recalcNodeList([nn]);
} }
function setAdd(arr, el){ function setAdd(arr, el){
var idx = ridx%(arr.length+1); var idx = ridx%(arr.length+1);
ridx+=131; ridx+=131;
ridx%=123; ridx%=123;
arr.splice(idx, 0, el); arr.splice(idx, 0, el);
return arr; return arr;
} }
function arrayContains(arr, el){return arr.indexOf(el)!=-1;} function arrayContains(arr, el){return arr.indexOf(el)!=-1;}

View File

@ -1,36 +1,36 @@
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
<title>6502</title> <title>6502</title>
<style type="text/css">@import "wires.css";</style> <style type="text/css">@import "wires.css";</style>
<script src="segdefs.js"></script> <script src="segdefs.js"></script>
<script src="transdefs.js"></script> <script src="transdefs.js"></script>
<script src="nodenames.js"></script> <script src="nodenames.js"></script>
<script src="wires.js"></script> <script src="wires.js"></script>
<script src="chipsim.js"></script> <script src="chipsim.js"></script>
<script src="memtable.js"></script> <script src="memtable.js"></script>
<script src="macros.js"></script> <script src="macros.js"></script>
</head> </head>
<body onload="setup();"> <body onload="setup();">
<p class="title">The 6502</p> <p class="title">The 6502</p>
<div class="frame" id="frame"> <div class="frame" id="frame">
<div class="chip"> <div class="chip">
<canvas class="chip" id="chipbg"></canvas> <canvas class="chip" id="chipbg"></canvas>
<canvas class="chip" id="overlay"></canvas> <canvas class="chip" id="overlay"></canvas>
<canvas class="chip" id="hilite"></canvas> <canvas class="chip" id="hilite"></canvas>
<canvas class="chip" id="hitbuffer"></canvas> <canvas class="chip" id="hitbuffer"></canvas>
</div> </div>
<div class = "buttons"> <div class = "buttons">
<a href ="javascript:stopChip()"id="stop"><img class="navstop" src="images/stop.png"></a> <a href ="javascript:stopChip()"id="stop"><img class="navstop" src="images/stop.png"></a>
<a href ="javascript:runChip()" id="start"><img class="navplay" src="images/play.png"></a> <a href ="javascript:runChip()" id="start"><img class="navplay" src="images/play.png"></a>
<a href ="javascript:resetChip()"><img class="navbutton" src="images/up.png"></a> <a href ="javascript:resetChip()"><img class="navbutton" src="images/up.png"></a>
<a href ="javascript:stepBack()"><img class="navbutton" src="images/prev.png"></a> <a href ="javascript:stepBack()"><img class="navbutton" src="images/prev.png"></a>
<a href ="javascript:stepForward()"><img class="navbutton" src="images/next.png"></a> <a href ="javascript:stepForward()"><img class="navbutton" src="images/next.png"></a>
</div> </div>
<p class="status" id="status">x: 0<br>y: 0</p> <p class="status" id="status">x: 0<br>y: 0</p>
<table class="memtable" id="memtable"></table> <table class="memtable" id="memtable"></table>
</div> </div>
</body> </body>
</html> </html>

View File

@ -1,89 +1,89 @@
/* /*
Copyright (c) 2010 Brian Silverman, Barry Silverman Copyright (c) 2010 Brian Silverman, Barry Silverman
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
var table; var table;
var selected; var selected;
function setupTable(){ function setupTable(){
table = document.getElementById('memtable'); table = document.getElementById('memtable');
for(var r=0;r<32;r++){ for(var r=0;r<32;r++){
var row = document.createElement('tr'); var row = document.createElement('tr');
table.appendChild(row); table.appendChild(row);
var col = document.createElement('td'); var col = document.createElement('td');
col.appendChild(document.createTextNode(hexWord(r*16)+':')); col.appendChild(document.createTextNode(hexWord(r*16)+':'));
col.onmousedown = unselectCell; col.onmousedown = unselectCell;
row.appendChild(col); row.appendChild(col);
for(var c=0;c<16;c++){ for(var c=0;c<16;c++){
col = document.createElement('td'); col = document.createElement('td');
col.addr = r*16+c; col.addr = r*16+c;
col.val = 0; col.val = 0;
col.onmousedown = function(e){handleCellClick(e);}; col.onmousedown = function(e){handleCellClick(e);};
col.appendChild(document.createTextNode('00')); col.appendChild(document.createTextNode('00'));
row.appendChild(col); row.appendChild(col);
} }
} }
} }
function handleCellClick(e){ function handleCellClick(e){
var c = e.target; var c = e.target;
selectCell(c.addr); selectCell(c.addr);
} }
function cellKeydown(e){ function cellKeydown(e){
var c = e.keyCode; var c = e.keyCode;
if(c==13) unselectCell(); if(c==13) unselectCell();
else if(c==32) selectCell((selected+1)%0x200); else if(c==32) selectCell((selected+1)%0x200);
else if(c==8) selectCell((selected+0x1ff)%0x200); else if(c==8) selectCell((selected+0x1ff)%0x200);
else if((c>=48)&&(c<58)) setCellValue(selected, getCellValue(selected)*16+c-48); else if((c>=48)&&(c<58)) setCellValue(selected, getCellValue(selected)*16+c-48);
else if((c>=65)&&(c<71)) setCellValue(selected, getCellValue(selected)*16+c-55); else if((c>=65)&&(c<71)) setCellValue(selected, getCellValue(selected)*16+c-55);
mWrite(selected, getCellValue(selected)); mWrite(selected, getCellValue(selected));
} }
function setCellValue(n, val){ function setCellValue(n, val){
val%=256; val%=256;
cellEl(n).val=val; cellEl(n).val=val;
cellEl(n).innerHTML=hexByte(val); cellEl(n).innerHTML=hexByte(val);
} }
function getCellValue(n){return cellEl(n).val;} function getCellValue(n){return cellEl(n).val;}
function selectCell(n){ function selectCell(n){
unselectCell(); unselectCell();
if(n>=0x200) return; if(n>=0x200) return;
cellEl(n).style.background = '#ff8'; cellEl(n).style.background = '#ff8';
selected = n; selected = n;
window.onkeydown = function(e){cellKeydown(e);}; window.onkeydown = function(e){cellKeydown(e);};
} }
function unselectCell(){ function unselectCell(){
if(selected==undefined) return; if(selected==undefined) return;
cellEl(selected).style.background = '#fff'; cellEl(selected).style.background = '#fff';
selected = undefined; selected = undefined;
window.onkeydown = undefined; window.onkeydown = undefined;
} }
function cellEl(n){ function cellEl(n){
var r = n>>4; var r = n>>4;
var c = n%16; var c = n%16;
var e = table.children[r].children[c+1]; var e = table.children[r].children[c+1];
return e; return e;
} }

View File

@ -1,117 +1,117 @@
/* /*
Copyright (c) 2010 Brian Silverman, Barry Silverman Copyright (c) 2010 Brian Silverman, Barry Silverman
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
var nodenames ={ var nodenames ={
db1: 82, db1: 82,
db0: 1005, db0: 1005,
db3: 650, db3: 650,
db2: 945, db2: 945,
db5: 175, db5: 175,
db4: 1393, db4: 1393,
db7: 1349, db7: 1349,
db6: 1591, db6: 1591,
a1: 1234, a1: 1234,
ab1: 451, ab1: 451,
ab2: 1340, ab2: 1340,
a2: 978, a2: 978,
s2: 81, s2: 81,
a5: 858, a5: 858,
a4: 727, a4: 727,
a7: 1653, a7: 1653,
a6: 1136, a6: 1136,
so: 1672, so: 1672,
sync: 539, sync: 539,
vcc: 657, vcc: 657,
clk1out: 1163, clk1out: 1163,
p2: 1421, p2: 1421,
p3: 439, p3: 439,
p0: 687, p0: 687,
p1: 1444, p1: 1444,
p6: 77, p6: 77,
p7: 1370, p7: 1370,
p4: 1119, p4: 1119,
p5: 0, p5: 0,
pcl3: 1359, pcl3: 1359,
pcl2: 655, pcl2: 655,
pcl1: 1022, pcl1: 1022,
pcl0: 1139, pcl0: 1139,
pcl7: 1611, pcl7: 1611,
pcl6: 377, pcl6: 377,
pcl5: 622, pcl5: 622,
pcl4: 900, pcl4: 900,
clk0: 1171, clk0: 1171,
s3: 1532, s3: 1532,
res: 159, res: 159,
s1: 183, s1: 183,
s0: 1403, s0: 1403,
s7: 1435, s7: 1435,
s6: 1212, s6: 1212,
s5: 1098, s5: 1098,
s4: 1702, s4: 1702,
rw: 1156, rw: 1156,
x2: 1, x2: 1,
x3: 1648, x3: 1648,
x0: 1216, x0: 1216,
x1: 98, x1: 98,
x6: 448, x6: 448,
x7: 777, x7: 777,
x4: 85, x4: 85,
x5: 589, x5: 589,
rdy: 89, rdy: 89,
clk2out: 421, clk2out: 421,
nmi: 1297, nmi: 1297,
ab12: 1237, ab12: 1237,
ab13: 349, ab13: 349,
ab10: 1443, ab10: 1443,
ab11: 399, ab11: 399,
ab14: 672, ab14: 672,
ab15: 195, ab15: 195,
ab0: 268, ab0: 268,
a0: 737, a0: 737,
a3: 162, a3: 162,
ab3: 211, ab3: 211,
ab4: 435, ab4: 435,
ab5: 736, ab5: 736,
ab6: 887, ab6: 887,
ab7: 1493, ab7: 1493,
ab8: 230, ab8: 230,
ab9: 148, ab9: 148,
pch7: 205, pch7: 205,
pch6: 1551, pch6: 1551,
pch5: 49, pch5: 49,
pch4: 948, pch4: 948,
pch3: 584, pch3: 584,
pch2: 502, pch2: 502,
pch1: 292, pch1: 292,
pch0: 1670, pch0: 1670,
irq: 103, irq: 103,
vss: 558, vss: 558,
y1: 1148, y1: 1148,
y0: 64, y0: 64,
y3: 305, y3: 305,
y2: 573, y2: 573,
y5: 615, y5: 615,
y4: 989, y4: 989,
y7: 843, y7: 843,
y6: 115, y6: 115,
cclk: 943 cclk: 943
} }

View File

@ -1,18 +1,18 @@
<?php <?php
$filename = $_REQUEST['name']; $filename = $_REQUEST['name'];
file_put_contents($filename, file_get_contents("php://input")); file_put_contents($filename, file_get_contents("php://input"));
function file_put_contents($filename, $data) { function file_put_contents($filename, $data) {
$f = @fopen($filename, 'w'); $f = @fopen($filename, 'w');
if ($f) { if ($f) {
$bytes = fwrite($f, $data); $bytes = fwrite($f, $data);
fclose($f); fclose($f);
return $bytes; return $bytes;
} }
return false; return false;
} }
?> ?>

16481
segdefs.js

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

136
wires.css
View File

@ -1,68 +1,68 @@
body { body {
background: white; background: white;
color: black; color: black;
font-family: cursive; font-family: cursive;
font-size: 30px; font-size: 30px;
} }
div.frame { div.frame {
margin-left: 10px; margin-left: 10px;
position: relative; position: relative;
width: 1150px; width: 1150px;
height: 600px; height: 600px;
} }
div.chip { div.chip {
background: lightgray; background: lightgray;
border: 2px solid gray; border: 2px solid gray;
position: absolute; position: absolute;
width: 800px; width: 800px;
height: 600px; height: 600px;
overflow: hidden; overflow: hidden;
} }
canvas.chip { canvas.chip {
position: absolute; position: absolute;
width: 600px; width: 600px;
height: 600px; height: 600px;
} }
div.buttons{ div.buttons{
position: absolute; position: absolute;
top: -5px; top: -5px;
left: 820px; left: 820px;
} }
p.status { p.status {
position: absolute; position: absolute;
left: 820px; left: 820px;
top: 20px; top: 20px;
font-family: monospace; font-family: monospace;
font-size: 12px; font-size: 12px;
} }
img.navbutton{ img.navbutton{
margin-left: -5px; margin-left: -5px;
border: 0px; border: 0px;
} }
img.navplay{ img.navplay{
margin-left: -5px; margin-left: -5px;
border: 0px; border: 0px;
} }
img.navstop{ img.navstop{
position: absolute; position: absolute;
left: -5px; left: -5px;
top: 9px; top: 9px;
border: 0px; border: 0px;
} }
table.memtable { table.memtable {
position: absolute; position: absolute;
top: 63px; top: 63px;
left: 820px; left: 820px;
font-family: monospace; font-family: monospace;
font-size: 12px; font-size: 12px;
border-spacing: 0px; border-spacing: 0px;
} }

676
wires.js
View File

@ -1,338 +1,338 @@
/* /*
Copyright (c) 2010 Brian Silverman, Barry Silverman Copyright (c) 2010 Brian Silverman, Barry Silverman
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
var frame, chipbg, overlay, hilite, hitbuffer, ctx; var frame, chipbg, overlay, hilite, hitbuffer, ctx;
var centerx=300, centery=300; var centerx=300, centery=300;
var zoom=1; var zoom=1;
var dragMouseX, dragMouseY, moved; var dragMouseX, dragMouseY, moved;
var statbox; var statbox;
var colors = ['rgba(128,128,128,0.4)','#FFFF00','#FF00FF','#4DFF4D', var colors = ['rgba(128,128,128,0.4)','#FFFF00','#FF00FF','#4DFF4D',
'#FF4D4D','#801AC0','rgba(128,0,255,0.75)']; '#FF4D4D','#801AC0','rgba(128,0,255,0.75)'];
var nodes = new Array(); var nodes = new Array();
var transistors = {}; var transistors = {};
var ngnd = nodenames['vss']; var ngnd = nodenames['vss'];
var npwr = nodenames['vcc']; var npwr = nodenames['vcc'];
///////////////////////// /////////////////////////
// //
// Drawing Setup // Drawing Setup
// //
///////////////////////// /////////////////////////
function setup(){ function setup(){
frame = document.getElementById('frame'); frame = document.getElementById('frame');
statbox = document.getElementById('status'); statbox = document.getElementById('status');
setupNodes(); setupNodes();
setupTransistors(); setupTransistors();
setupBackground(); setupBackground();
setupOverlay(); setupOverlay();
setupHilite(); setupHilite();
setupHitBuffer(); setupHitBuffer();
recenter(); recenter();
refresh(); refresh();
setupTable(); setupTable();
window.onkeypress = function(e){handleKey(e);} window.onkeypress = function(e){handleKey(e);}
hilite.onmousedown = function(e){mouseDown(e);} hilite.onmousedown = function(e){mouseDown(e);}
initChip(); initChip();
document.getElementById('stop').style.visibility = 'hidden'; document.getElementById('stop').style.visibility = 'hidden';
go(); go();
} }
function setupNodes(){ function setupNodes(){
for(var i in segdefs){ for(var i in segdefs){
var seg = segdefs[i]; var seg = segdefs[i];
var w = seg[0]; var w = seg[0];
if(nodes[w]==undefined) if(nodes[w]==undefined)
nodes[w] = {segs: new Array(), num: w, pullup: seg[1]=='+', nodes[w] = {segs: new Array(), num: w, pullup: seg[1]=='+',
state: 'fl', gates: new Array(), c1c2s: new Array()}; state: 'fl', gates: new Array(), c1c2s: new Array()};
if(w==ngnd) continue; if(w==ngnd) continue;
if(w==npwr) continue; if(w==npwr) continue;
nodes[w].segs.push(seg.slice(3)); nodes[w].segs.push(seg.slice(3));
} }
} }
function setupTransistors(){ function setupTransistors(){
for(i in transdefs){ for(i in transdefs){
var tdef = transdefs[i]; var tdef = transdefs[i];
var name = tdef[0]; var name = tdef[0];
var gate = tdef[1]; var gate = tdef[1];
var c1 = tdef[2]; var c1 = tdef[2];
var c2 = tdef[3]; var c2 = tdef[3];
var trans = {name: name, on: false, gate: gate, c1: c1, c2: c2}; var trans = {name: name, on: false, gate: gate, c1: c1, c2: c2};
nodes[gate].gates.push(name); nodes[gate].gates.push(name);
nodes[c1].c1c2s.push(name); nodes[c1].c1c2s.push(name);
nodes[c2].c1c2s.push(name); nodes[c2].c1c2s.push(name);
transistors[name] = trans; transistors[name] = trans;
} }
} }
function setupBackground(){ function setupBackground(){
chipbg = document.getElementById('chipbg'); chipbg = document.getElementById('chipbg');
chipbg.width = 4000; chipbg.width = 4000;
chipbg.height = 4000; chipbg.height = 4000;
var ctx = chipbg.getContext('2d'); var ctx = chipbg.getContext('2d');
ctx.scale(chipbg.width/10000, chipbg.height/10000); ctx.scale(chipbg.width/10000, chipbg.height/10000);
ctx.fillStyle = '#000000'; ctx.fillStyle = '#000000';
ctx.strokeStyle = 'rgba(255,255,255,0.5)'; ctx.strokeStyle = 'rgba(255,255,255,0.5)';
ctx.lineWidth = 4; ctx.lineWidth = 4;
ctx.fillRect(0,0,10000,10000); ctx.fillRect(0,0,10000,10000);
var start = now(); var start = now();
for(var i in segdefs){ for(var i in segdefs){
var seg = segdefs[i]; var seg = segdefs[i];
var c = seg[2]; var c = seg[2];
ctx.fillStyle = colors[c]; ctx.fillStyle = colors[c];
drawSeg(ctx, segdefs[i].slice(3)); drawSeg(ctx, segdefs[i].slice(3));
ctx.fill(); ctx.fill();
if((c==0)||(c==6)) ctx.stroke(); if((c==0)||(c==6)) ctx.stroke();
} }
// console.log('time to draw: ', now() - start, ' ms'); // console.log('time to draw: ', now() - start, ' ms');
} }
function setupOverlay(){ function setupOverlay(){
overlay = document.getElementById('overlay'); overlay = document.getElementById('overlay');
overlay.width = 4000; overlay.width = 4000;
overlay.height = 4000; overlay.height = 4000;
ctx = overlay.getContext('2d'); ctx = overlay.getContext('2d');
ctx.scale(overlay.width/10000, overlay.height/10000); ctx.scale(overlay.width/10000, overlay.height/10000);
} }
function setupHilite(){ function setupHilite(){
hilite = document.getElementById('hilite'); hilite = document.getElementById('hilite');
hilite.width = 4000; hilite.width = 4000;
hilite.height = 4000; hilite.height = 4000;
var ctx = hilite.getContext('2d'); var ctx = hilite.getContext('2d');
ctx.scale(hilite.width/10000, hilite.height/10000); ctx.scale(hilite.width/10000, hilite.height/10000);
} }
function setupHitBuffer(){ function setupHitBuffer(){
hitbuffer = document.getElementById('hitbuffer'); hitbuffer = document.getElementById('hitbuffer');
hitbuffer.width = 4000; hitbuffer.width = 4000;
hitbuffer.height = 4000; hitbuffer.height = 4000;
hitbuffer.style.visibility = 'hidden'; hitbuffer.style.visibility = 'hidden';
var ctx = hitbuffer.getContext('2d'); var ctx = hitbuffer.getContext('2d');
ctx.scale(hitbuffer.width/10000, hitbuffer.height/10000); ctx.scale(hitbuffer.width/10000, hitbuffer.height/10000);
for(i in nodes) hitBufferNode(ctx, i, nodes[i].segs); for(i in nodes) hitBufferNode(ctx, i, nodes[i].segs);
} }
function hitBufferNode(ctx, i, w){ function hitBufferNode(ctx, i, w){
var low = hexdigit(i&0xf); var low = hexdigit(i&0xf);
var mid = hexdigit((i>>4)&0xf); var mid = hexdigit((i>>4)&0xf);
var high = hexdigit((i>>8)&0xf); var high = hexdigit((i>>8)&0xf);
ctx.fillStyle = '#'+high+'F'+mid+'F'+low+'F'; ctx.fillStyle = '#'+high+'F'+mid+'F'+low+'F';
for(i in w) { for(i in w) {
drawSeg(ctx, w[i]); drawSeg(ctx, w[i]);
ctx.fill(); ctx.fill();
} }
} }
function hexdigit(n){return '0123456789ABCDEF'.charAt(n);} function hexdigit(n){return '0123456789ABCDEF'.charAt(n);}
///////////////////////// /////////////////////////
// //
// Drawing Runtime // Drawing Runtime
// //
///////////////////////// /////////////////////////
function refresh(){ function refresh(){
ctx.clearRect(0,0,10000,10000); ctx.clearRect(0,0,10000,10000);
for(i in nodes){ for(i in nodes){
if(isNodeHigh(i)) overlayNode(nodes[i].segs); if(isNodeHigh(i)) overlayNode(nodes[i].segs);
} }
} }
function overlayNode(w){ function overlayNode(w){
ctx.fillStyle = 'rgba(255,0,64,0.4)'; ctx.fillStyle = 'rgba(255,0,64,0.4)';
for(i in w) { for(i in w) {
drawSeg(ctx, w[i]); drawSeg(ctx, w[i]);
ctx.fill(); ctx.fill();
} }
} }
function hiliteNode(n){ function hiliteNode(n){
var ctx = hilite.getContext('2d'); var ctx = hilite.getContext('2d');
ctx.clearRect(0,0,10000,10000); ctx.clearRect(0,0,10000,10000);
ctx.fillStyle = 'rgba(255,255,255,0.7)'; ctx.fillStyle = 'rgba(255,255,255,0.7)';
if(n==-1) return; if(n==-1) return;
if(isNodeHigh(n[0])) if(isNodeHigh(n[0]))
ctx.fillStyle = 'rgba(255,0,0,0.7)'; ctx.fillStyle = 'rgba(255,0,0,0.7)';
for(var i in n){ for(var i in n){
var segs = nodes[n[i]].segs; var segs = nodes[n[i]].segs;
for(var s in segs){drawSeg(ctx, segs[s]); ctx.fill();} for(var s in segs){drawSeg(ctx, segs[s]); ctx.fill();}
} }
} }
function drawSeg(ctx, seg){ function drawSeg(ctx, seg){
var dx = 400; var dx = 400;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(seg[0]+dx, 10000-seg[1]) ctx.moveTo(seg[0]+dx, 10000-seg[1])
for(var i=2;i<seg.length;i+=2) ctx.lineTo(seg[i]+dx, 10000-seg[i+1]); for(var i=2;i<seg.length;i+=2) ctx.lineTo(seg[i]+dx, 10000-seg[i+1]);
ctx.lineTo(seg[0]+dx, 10000-seg[1]) ctx.lineTo(seg[0]+dx, 10000-seg[1])
} }
///////////////////////// /////////////////////////
// //
// User Interface // User Interface
// //
///////////////////////// /////////////////////////
function handleKey(e){ function handleKey(e){
var c = e.charCode; var c = e.charCode;
c = String.fromCharCode(c); c = String.fromCharCode(c);
if('<>?np'.indexOf(c)==-1) return; if('<>?np'.indexOf(c)==-1) return;
if(c=='<' && zoom>1) setZoom(zoom/1.2); if(c=='<' && zoom>1) setZoom(zoom/1.2);
else if(c=='>' && zoom<16) setZoom(zoom*1.2); else if(c=='>' && zoom<16) setZoom(zoom*1.2);
else if(c=='?') setZoom(1); else if(c=='?') setZoom(1);
else if(c=='n') stepForward(); else if(c=='n') stepForward();
else if(c=='p') stepBack(); else if(c=='p') stepBack();
} }
function mouseDown(e){ function mouseDown(e){
e.preventDefault(); e.preventDefault();
moved=false; moved=false;
dragMouseX = e.clientX; dragMouseX = e.clientX;
dragMouseY = e.clientY; dragMouseY = e.clientY;
window.onmousemove = function(e){mouseMove(e)}; window.onmousemove = function(e){mouseMove(e)};
window.onmouseup = function(e){mouseUp(e)}; window.onmouseup = function(e){mouseUp(e)};
} }
function mouseMove(e){ function mouseMove(e){
moved = true; moved = true;
if(zoom==1) return; if(zoom==1) return;
var dx = e.clientX-dragMouseX; var dx = e.clientX-dragMouseX;
var dy = e.clientY-dragMouseY; var dy = e.clientY-dragMouseY;
dragMouseX = e.clientX; dragMouseX = e.clientX;
dragMouseY = e.clientY; dragMouseY = e.clientY;
centerx-=dx/zoom; centerx-=dx/zoom;
centerx = Math.max(centerx, 400/zoom); centerx = Math.max(centerx, 400/zoom);
centerx = Math.min(centerx, 600-400/zoom); centerx = Math.min(centerx, 600-400/zoom);
centery-=dy/zoom; centery-=dy/zoom;
centery = Math.max(centery, 300/zoom); centery = Math.max(centery, 300/zoom);
centery = Math.min(centery, 600-300/zoom); centery = Math.min(centery, 600-300/zoom);
recenter(); recenter();
} }
function mouseUp(e){ function mouseUp(e){
if(!moved) handleClick(e); if(!moved) handleClick(e);
window.onmousemove = undefined; window.onmousemove = undefined;
window.onmouseup = undefined; window.onmouseup = undefined;
} }
function setZoom(n){ function setZoom(n){
zoom = n; zoom = n;
setChipStyle({ setChipStyle({
width: 600*n+'px', width: 600*n+'px',
height: 600*n+'px' height: 600*n+'px'
}); });
recenter(); recenter();
} }
function recenter(){ function recenter(){
var top = -centery*zoom+300; var top = -centery*zoom+300;
top = Math.min(top, 0); top = Math.min(top, 0);
top = Math.max(top, -600*(zoom-1)); top = Math.max(top, -600*(zoom-1));
var left = -centerx*zoom+400; var left = -centerx*zoom+400;
left = Math.min(left, 0); left = Math.min(left, 0);
left = Math.max(left, (zoom==1)?100:-600*zoom+800); left = Math.max(left, (zoom==1)?100:-600*zoom+800);
setChipStyle({ setChipStyle({
top: top+'px', top: top+'px',
left: left+'px', left: left+'px',
}); });
} }
function handleClick(e){ function handleClick(e){
var x = localx(hilite, e.clientX)/zoom; var x = localx(hilite, e.clientX)/zoom;
var y = localy(hilite, e.clientY)/zoom; var y = localy(hilite, e.clientY)/zoom;
var w = findNodeNumber(x,y); var w = findNodeNumber(x,y);
if(e.shiftKey) hiliteNode(getNodeGroup(w)); if(e.shiftKey) hiliteNode(getNodeGroup(w));
else {var a=new Array(); a.push(w); hiliteNode(a);} else {var a=new Array(); a.push(w); hiliteNode(a);}
var cx = Math.round(x*10000/600); var cx = Math.round(x*10000/600);
var cy = Math.round(y*10000/600); var cy = Math.round(y*10000/600);
if(w==-1) setStatus('x:',cx,'<br>','y:',cy); if(w==-1) setStatus('x:',cx,'<br>','y:',cy);
else {setStatus('x:',cx, 'y:', cy,'<br>','node:',w, nodeName(w));} else {setStatus('x:',cx, 'y:', cy,'<br>','node:',w, nodeName(w));}
} }
function findNodeNumber(x,y){ function findNodeNumber(x,y){
var ctx = hitbuffer.getContext('2d'); var ctx = hitbuffer.getContext('2d');
var pixels = ctx.getImageData(x*4000/600, y*4000/600, 2, 2).data; var pixels = ctx.getImageData(x*4000/600, y*4000/600, 2, 2).data;
if(pixels[0]==0) return -1; if(pixels[0]==0) return -1;
var high = pixels[0]>>4; var high = pixels[0]>>4;
var mid = pixels[1]>>4; var mid = pixels[1]>>4;
var low = pixels[2]>>4; var low = pixels[2]>>4;
return (high<<8)+(mid<<4)+low; return (high<<8)+(mid<<4)+low;
} }
///////////////////////// /////////////////////////
// //
// Etc. // Etc.
// //
///////////////////////// /////////////////////////
function setChipStyle(props){ function setChipStyle(props){
for(var i in props){ for(var i in props){
chipbg.style[i] = props[i]; chipbg.style[i] = props[i];
overlay.style[i] = props[i]; overlay.style[i] = props[i];
hilite.style[i] = props[i]; hilite.style[i] = props[i];
hitbuffer.style[i] = props[i]; hitbuffer.style[i] = props[i];
} }
} }
function localx(el, gx){ function localx(el, gx){
var lx = gx+window.pageXOffset; var lx = gx+window.pageXOffset;
while(el.offsetLeft!=undefined){ while(el.offsetLeft!=undefined){
lx-=el.offsetLeft+el.clientLeft; lx-=el.offsetLeft+el.clientLeft;
el = el.parentNode; el = el.parentNode;
} }
return lx; return lx;
} }
function localy(el, gy){ function localy(el, gy){
var ly = gy+window.pageYOffset; var ly = gy+window.pageYOffset;
while(el.offsetTop!=undefined){ while(el.offsetTop!=undefined){
ly-=el.offsetTop+el.clientTop; ly-=el.offsetTop+el.clientTop;
el = el.parentNode; el = el.parentNode;
} }
return ly; return ly;
} }
function setStatus(){ function setStatus(){
var res = ''; var res = '';
for(var i=0;i<arguments.length;i++) res=res+arguments[i]+' '; for(var i=0;i<arguments.length;i++) res=res+arguments[i]+' ';
statbox.innerHTML = res; statbox.innerHTML = res;
} }
function nodeName(n) { function nodeName(n) {
for(var i in nodenames){ for(var i in nodenames){
if(nodenames[i]==n) return i; if(nodenames[i]==n) return i;
} }
return ''; return '';
} }
function now(){return new Date().getTime();} function now(){return new Date().getTime();}