/* Copyright (c) 2010 Brian Silverman, Barry Silverman, Ed Spittles Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 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 THE SOFTWARE. */ var centerx=300, centery=300; var zoom=1; var dragMouseX, dragMouseY, moved; var statbox; // Some constants for the graphics presentation // the canvas is embedded in an 800x600 clipping div // which gives rise to some of the 300 and 400 values in the code // there are also some 600 values // the 6502D chip coords are in the box (216,179) to (8983,9807) // we have 4 canvases all the same size, now 2000 pixels square // chip background - the layout // overlay - a red/white transparency to show logic high or low // hilite - to show the selected polygon // hitbuffer - abusing color values to return which polygon is under a point // we no longer use a scaling transform - we now scale the chip data at // the point of drawing line segments // if the canvas is any smaller than chip coordinates there will be // rounding artifacts, and at high zoom there will be anti-aliasing on edges. var grMaxZoom=12; var grChipSize=10000; var grCanvasSize=2000; var grLineWidth=1; // Index of layerNames corresponds to index into drawLayers var layernames = ['metal', 'switched diffusion', 'inputdiode', 'grounded diffusion', 'powered diffusion', 'polysilicon']; var colors = ['rgba(128,128,192,0.4)','#FFFF00','#FF00FF','#4DFF4D', '#FF4D4D','#801AC0','rgba(128,0,255,0.75)']; var drawlayers = [true, true, true, true, true, true]; // some modes and parameters which can be passed in from the URL query var moveHereFirst; var expertMode=false var animateChipLayout = true; var userCode=[]; var userResetLow; var userResetHigh; var headlessSteps=1000; var noSimulation=false; var testprogram=[]; var testprogramAddress; ///////////////////////// // // Drawing Setup // ///////////////////////// // try to present a meaningful page before starting expensive work function setup(){ statbox = document.getElementById('status'); setStatus('loading 6502...'); setTimeout(setup_part2, 0); } function setup_part2(){ frame = document.getElementById('frame'); statbox = document.getElementById('status'); setupParams(); updateExpertMode(expertMode); setupNodes(); setupTransistors(); detectOldBrowser(); setStatus('loading graphics...'); setTimeout(setup_part3, 0); } function setup_part3(){ if(chipLayoutIsVisible){ // if user requests no chip layout, we can skip all canvas operations // which saves a lot of memory and allows us to run on small systems updateChipLayoutVisibility(true); } setStatus('resetting 6502...'); setTimeout(setup_part4, 0); } function setup_part4(){ setupTable(); setupNodeNameList(); logThese=signalSet(loglevel); loadProgram(); if(noSimulation){ running=undefined; setStatus('Ready!'); } else { initChip(); document.getElementById('stop').style.visibility = 'hidden'; go(); } } function detectOldBrowser(){ if(!("getBoundingClientRect" in document.documentElement)){ // simplify these functions (and adjust layout window position) localx= function(el, gx){ return gx-el.offsetLeft; } localy= function(el, gy){ return gy-el.offsetTop; } document.getElementById('plain').style["float"]="right"; document.getElementById('chip').style.left=0; document.getElementById('chip').style.top=0; document.getElementById('chip').style.border=0; } } function setupParams(){ if(location.search=="") return var queryParts=location.search.slice(1).split('&'); var panx; var pany; var zoom; var userAddress; for(var i=0;i0) console.log('malformed parameters',params); break; } var name=params[0]; var value=params[1].replace(/\/$/,""); // chrome sometimes adds trailing slash // be (relatively) forgiving in what we accept // // user interface mode control if(name=="loglevel" && parseInt(value)!=NaN){ updateLoglevel(value); } else if(name=="expert" && value.indexOf("t")==0){ updateExpertMode(true); } else if(name=="headlesssteps" && parseInt(value)!=NaN){ headlessSteps=parseInt(value); } else if(name=="graphics" && value.indexOf("f")==0){ updateChipLayoutVisibility(false); } else if(name=="canvas" && parseInt(value)!=NaN){ grCanvasSize=value; // suppress simulation (for layout viewing only on slow browsers) } else if(name=="nosim" && value.indexOf("t")==0){ noSimulation=true; } else // place the graphics window at a point of interest if(name=="panx" && parseInt(value)!=NaN){ panx=parseInt(value); } else if(name=="pany" && parseInt(value)!=NaN){ pany=parseInt(value); } else if(name=="zoom" && parseInt(value)!=NaN){ zoom=parseInt(value); } else // load a test program: Address, Data and Reset if(name=="a" && parseInt(value,16)!=NaN){ userAddress=parseInt(value,16); } else if(name=="d" && value.match(/[0-9a-fA-F]*/)[0].length==value.length){ for(var j=0;j>8)%256; } else // run a test program, and optionally check against a golden checksum if(name=="steps" && parseInt(value)!=NaN){ userSteps=parseInt(value); running=true; } else if(name=="checksum" && parseInt(value,16)!=NaN){ goldenChecksum=(0x100000000+parseInt(value,16)).toString(16).slice(-8); } else { if(loglevel>0) console.log('unrecognised parameters:',params); break; } } if(panx!=null && pany!=null && zoom!=null) moveHereFirst=[panx,pany,zoom]; } function updateChipLayoutAnimation(isOn){ // simulation is much faster if we don't update the chip layout on every step animateChipLayout=isOn; document.getElementById('animateModeCheckbox').checked = animateChipLayout; } ///////////////////////// // // User Interface // ///////////////////////// // these keyboard actions are primarily for the chip display function handleKey(e){ var c = e.charCode; c = String.fromCharCode(c); if('<>?npZzx'.indexOf(c)==-1) return; if((c=='Z'||c=='x'||c=='<') && zoom>1) setZoom(zoom/1.2); else if((c=='z'||c=='>') && zoom