From d0325802013bb67dcee4862401e34b7175104dc3 Mon Sep 17 00:00:00 2001 From: BigEd Date: Sat, 18 Sep 2010 17:46:24 +0000 Subject: [PATCH] improve load sequencing, add layer choosing, link to python sim, add keyboard tips, add example nmi test, tweak navbuttons, enhance chipstatus output --- chipsim.js | 2 + index.html | 45 ++++++++++++++++---- macros.js | 119 ++++++++++++++++++++++++++++++++++++++++++++++------- wires.js | 44 ++++++++++++++++---- 4 files changed, 179 insertions(+), 31 deletions(-) diff --git a/chipsim.js b/chipsim.js index 9842c45..ffa0f30 100644 --- a/chipsim.js +++ b/chipsim.js @@ -21,6 +21,8 @@ */ var ctrace = false; +var noGraphics = false; +var loglevel = 3; var ridx = 0; function recalcNodeList(list){ diff --git a/index.html b/index.html index e3e6e06..c876891 100644 --- a/index.html +++ b/index.html @@ -8,12 +8,26 @@ +
- -

The 6502

+ +
+The Visual 6502

+ +If the chip does not load, try another browser: Chrome, Safari, or Firefox +
+
+Hit '>' to zoom in, '<' to zoom out +
+Right-click to scroll around +
+Enter your own program into the array of RAM +
+
+
@@ -22,15 +36,30 @@
- - - - - +
+ + +
+
+ + + +

x: 0
y: 0

+
Show: + (metal) + (diff) + (diode) + (diff0) + (diff1) + (poly) +
+
+
+In addition to this JavaScript project, see our Python-based simulator which may be easier to customize, verify, and apply to the study of long programs.
+
- diff --git a/macros.js b/macros.js index cec2a70..dcba25e 100644 --- a/macros.js +++ b/macros.js @@ -39,11 +39,55 @@ function go(n){ } function steps(){ - if(running) step(); - setTimeout(steps, 200); + if(running) { + step(); + setTimeout(steps, 0); // schedule the next poll + } } +function testNMI(n){ + initChip(); + + mWrite(0x0000, 0x38); // set carry + mWrite(0x0001, 0x4c); // jump to test code + mWrite(0x0002, 0x06); + mWrite(0x0003, 0x23); + + mWrite(0x22ff, 0x38); // set carry + mWrite(0x2300, 0xea); + mWrite(0x2301, 0xea); + mWrite(0x2302, 0xea); + mWrite(0x2303, 0xea); + mWrite(0x2304, 0xb0); // branch carry set to self + mWrite(0x2305, 0xfe); + + mWrite(0x2306, 0xb0); // branch carry set to self + mWrite(0x2307, 0x01); + mWrite(0x2308, 0x00); // brk should be skipped + mWrite(0x2309, 0xa9); // anything + mWrite(0x230a, 0xde); // anything + mWrite(0x230b, 0xb0); // branch back with page crossing + mWrite(0x230c, 0xf2); + + mWrite(0xc018, 0x40); // nmi handler + + mWrite(0xfffa, 0x18); // nmi vector + mWrite(0xfffb, 0xc0); + mWrite(0xfffc, 0x00); // reset vector + mWrite(0xfffd, 0x00); + + for(var i=0;i', - 'A:', hexByte(readA()), - 'X:', hexByte(readX()), - 'Y:', hexByte(readY()), - 'P:', hexByte(readP()) - ); - selectCell(pc); + var ab = readAddressBus(); + var machine1 = + ' halfcyc:' + cycle + + ' phi0:' + readBit('clk0') + + ' AB:' + hexWord(ab) + + ' D:' + hexByte(readDataBus()) + + ' RnW:' + readBit('rw'); + var machine2 = + ' PC:' + hexWord(readPC()) + + ' A:' + hexByte(readA()) + + ' X:' + hexByte(readX()) + + ' Y:' + hexByte(readY()) + + ' SP:' + hexByte(readSP()) + + ' ' + readPstring(); + var machine3 = + ' Sync:' + readBit('sync') + ' IRQ:' + readBit('irq') + + ' NMI:' + readBit('nmi'); + var machine4 = + ' IR:' + hexByte(255 - readBits('notir', 8)) + + ' idl:' + hexByte(255 - readBits('idl', 8)) + + ' alu:' + hexByte(255 - readBits('alu', 8)) + + ' TCstate:' + readBit('clock1') + readBit('clock2') + + readBit('t2') + readBit('t3') + readBit('t4') + readBit('t5'); + var machine5 = + ' notRdy0:' + readBit('notRdy0') + + ' fetch:' + readBit('fetch') + + ' clearIR:' + readBit('clearIR') + + ' D1x1:' + readBit('D1x1'); + setStatus(machine1 + "
" + machine2); + if (loglevel>2) { + console.log(machine1 + " " + machine2 + " " + machine3 + " " + machine4 + " " + machine5); + } + selectCell(ab); } function getMem(){ diff --git a/wires.js b/wires.js index f136bb0..1430a96 100644 --- a/wires.js +++ b/wires.js @@ -26,8 +26,10 @@ var zoom=1; var dragMouseX, dragMouseY, moved; var statbox; -var colors = ['rgba(128,128,128,0.4)','#FFFF00','#FF00FF','#4DFF4D', +var layernames = ['metal', 'diff', 'inputdiode', 'diff0', 'diff1', 'poly']; +var colors = ['rgba(128,128,192,0.4)','#FFFF00','#FF00FF','#4DFF4D', '#FF4D4D','#801AC0','rgba(128,0,255,0.75)']; +var drawlayers = [true, true, false, false, false, false]; var nodes = new Array(); var transistors = {}; @@ -42,11 +44,19 @@ var npwr = nodenames['vcc']; // ///////////////////////// +// 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'); setupNodes(); setupTransistors(); + setupLayerVisibility(); setupBackground(); setupOverlay(); setupHilite(); @@ -56,6 +66,11 @@ function setup(){ 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(); @@ -89,8 +104,17 @@ function setupTransistors(){ } } +function setupLayerVisibility(){ + var x=document.getElementById('updateShow'); + for (var i=0;i