diff --git a/js/chipsim.js b/js/chipsim.js index 2156a90..7098771 100644 --- a/js/chipsim.js +++ b/js/chipsim.js @@ -175,7 +175,7 @@ function showState(str){ var gates = nodes[i].gates; for(var t in gates) transistors[gates[t]].on = isNodeHigh(i); } - refresh(); +// refresh(); } diff --git a/js/macros.js b/js/macros.js index 2526c18..640daf8 100644 --- a/js/macros.js +++ b/js/macros.js @@ -100,7 +100,7 @@ function initChip(){ for(var i=0;i<8;i++){setHigh('clk0'), setLow('clk0');} setHigh('res'); for(var i=0;i<18;i++){resetStep();} - refresh(); +// refresh(); cycle = 0; trace = Array(); chipStatus(); @@ -118,7 +118,7 @@ function halfStep(){ var clk = isNodeHigh(nodenames['clk0']); if (clk) {setLow('clk0'); handleBusRead(); } else {setHigh('clk0'); handleBusWrite();} - refresh(); +// refresh(); } function resetStep(){ diff --git a/js/wires.js b/js/wires.js index b5f8bb1..9a445c8 100644 --- a/js/wires.js +++ b/js/wires.js @@ -57,21 +57,8 @@ function setup_part2(){ statbox = document.getElementById('status'); setupNodes(); setupTransistors(); - setupLayerVisibility(); - setupBackground(); - setupOverlay(); - setupHilite(); - setupHitBuffer(); - recenter(); - refresh(); setupTable(); - window.onkeypress = function(e){handleKey(e);} - hilite.onmousedown = function(e){mouseDown(e);} setStatus('resetting 6502...'); - setTimeout(setup_part3, 0); -} - -function setup_part3(){ initChip(); document.getElementById('stop').style.visibility = 'hidden'; go(); @@ -105,219 +92,11 @@ function setupTransistors(){ } } -function setupLayerVisibility(){ - var x=document.getElementById('updateShow'); - for (var i=0;i>4)&0xf); - var high = hexdigit((i>>8)&0xf); - ctx.fillStyle = '#'+high+'F'+mid+'F'+low+'F'; - for(i in w) { - drawSeg(ctx, w[i]); - ctx.fill(); - } -} function hexdigit(n){return '0123456789ABCDEF'.charAt(n);} -///////////////////////// -// -// Drawing Runtime -// -///////////////////////// - -function refresh(){ - ctx.clearRect(0,0,10000,10000); - for(i in nodes){ - if(isNodeHigh(i)) overlayNode(nodes[i].segs); - } -} - -function overlayNode(w){ - ctx.fillStyle = 'rgba(255,0,64,0.4)'; - for(i in w) { - drawSeg(ctx, w[i]); - ctx.fill(); - } -} - -function hiliteNode(n){ - var ctx = hilite.getContext('2d'); - ctx.clearRect(0,0,10000,10000); - ctx.fillStyle = 'rgba(255,255,255,0.7)'; - if(n==-1) return; - if(isNodeHigh(n[0])) - ctx.fillStyle = 'rgba(255,0,0,0.7)'; - - for(var i in n){ - var segs = nodes[n[i]].segs; - for(var s in segs){drawSeg(ctx, segs[s]); ctx.fill();} - } -} - - -function drawSeg(ctx, seg){ - if(noGraphics) return; - var dx = 400; - ctx.beginPath(); - ctx.moveTo(seg[0]+dx, 10000-seg[1]) - for(var i=2;i?np'.indexOf(c)==-1) return; - if(c=='<' && zoom>1) setZoom(zoom/1.2); - else if(c=='>' && zoom<16) setZoom(zoom*1.2); - else if(c=='?') setZoom(1); - else if(c=='n') stepForward(); - else if(c=='p') stepBack(); -} - -function mouseDown(e){ - e.preventDefault(); - moved=false; - dragMouseX = e.clientX; - dragMouseY = e.clientY; - window.onmousemove = function(e){mouseMove(e)}; - window.onmouseup = function(e){mouseUp(e)}; -} - -function mouseMove(e){ - moved = true; - if(zoom==1) return; - var dx = e.clientX-dragMouseX; - var dy = e.clientY-dragMouseY; - dragMouseX = e.clientX; - dragMouseY = e.clientY; - centerx-=dx/zoom; - centerx = Math.max(centerx, 400/zoom); - centerx = Math.min(centerx, 600-400/zoom); - centery-=dy/zoom; - centery = Math.max(centery, 300/zoom); - centery = Math.min(centery, 600-300/zoom); - recenter(); -} - -function mouseUp(e){ - if(!moved) handleClick(e); - window.onmousemove = undefined; - window.onmouseup = undefined; -} - -function setZoom(n){ - zoom = n; - setChipStyle({ - width: 600*n+'px', - height: 600*n+'px' - }); - recenter(); -} - -function recenter(){ - var top = -centery*zoom+300; - top = Math.min(top, 0); - top = Math.max(top, -600*(zoom-1)); - var left = -centerx*zoom+400; - left = Math.min(left, 0); - left = Math.max(left, (zoom==1)?100:-600*zoom+800); - setChipStyle({ - top: top+'px', - left: left+'px', - }); -} - -function handleClick(e){ - var x = localx(hilite, e.clientX)/zoom; - var y = localy(hilite, e.clientY)/zoom; - var w = findNodeNumber(x,y); - if(e.shiftKey) hiliteNode(getNodeGroup(w)); - else {var a=new Array(); a.push(w); hiliteNode(a);} - var cx = Math.round(x*10000/600); - var cy = Math.round(y*10000/600); - if(w==-1) setStatus('x:',cx,'
','y:',cy); - else {setStatus('x:',cx, 'y:', cy,'
','node:',w, nodeName(w));} -} - -function findNodeNumber(x,y){ - var ctx = hitbuffer.getContext('2d'); - var pixels = ctx.getImageData(x*4000/600, y*4000/600, 2, 2).data; - if(pixels[0]==0) return -1; - var high = pixels[0]>>4; - var mid = pixels[1]>>4; - var low = pixels[2]>>4; - return (high<<8)+(mid<<4)+low; -} - -function updateShow(layer, on){ - drawlayers[layer]=on; - setupBackground(); -} - ///////////////////////// // // Etc. @@ -326,7 +105,7 @@ function updateShow(layer, on){ function setChipStyle(props){ for(var i in props){ - chipbg.style[i] = props[i]; +// chipbg.style[i] = props[i]; overlay.style[i] = props[i]; hilite.style[i] = props[i]; hitbuffer.style[i] = props[i];