[bug]direct keypresses to correct places: graphics, memtable, input box

This commit is contained in:
BigEd 2010-11-05 17:38:47 +00:00
parent 294918789a
commit 0842501bb7
3 changed files with 23 additions and 12 deletions

View File

@ -60,8 +60,8 @@ $().ready(function(){
<a href="http://www.e-tradition.net/bytes/6502/disassembler.html">e-tradition disassembler</a>&nbsp; <a href="http://www.e-tradition.net/bytes/6502/disassembler.html">e-tradition disassembler</a>&nbsp;
</span> </span>
<div class="frame" id="frame"> <div class="frame" id="frame">
<div class="leftcolumn"> <div class="leftcolumn" id="leftcolumn">
<div id="chipsurround"> <div id="chipsurround" tabindex="1">
<div class="chip" id="chip"> <div class="chip" id="chip">
<span id="waiting">Please wait, graphics initialising...</span> <span id="waiting">Please wait, graphics initialising...</span>
<canvas class="chip" id="chipbg"></canvas> <canvas class="chip" id="chipbg"></canvas>
@ -116,7 +116,7 @@ $().ready(function(){
</div> <!-- status --> </div> <!-- status -->
<div id="memtablediv"> <div id="memtablediv">
<table class="memtable" id="memtable"></table> <table class="memtable" id="memtable" tabindex="2"></table>
</div> </div>
</div> <!-- righttopdiv --> </div> <!-- righttopdiv -->

View File

@ -93,7 +93,6 @@ function setup_part3(){
// which saves a lot of memory and allows us to run on small systems // which saves a lot of memory and allows us to run on small systems
updateChipLayoutVisibility(true); updateChipLayoutVisibility(true);
} }
window.onkeypress = function(e){handleKey(e);}
setStatus('resetting 6502...'); setStatus('resetting 6502...');
setTimeout(setup_part4, 0); setTimeout(setup_part4, 0);
} }
@ -209,6 +208,8 @@ function updateChipLayoutAnimation(isOn){
// //
///////////////////////// /////////////////////////
// these keyboard actions are primarily for the chip display
function handleKey(e){ function handleKey(e){
var c = e.charCode; var c = e.charCode;
c = String.fromCharCode(c); c = String.fromCharCode(c);
@ -216,17 +217,21 @@ function handleKey(e){
if((c=='Z'||c=='x'||c=='<') && zoom>1) setZoom(zoom/1.2); if((c=='Z'||c=='x'||c=='<') && zoom>1) setZoom(zoom/1.2);
else if((c=='z'||c=='>') && zoom<grMaxZoom) setZoom(zoom*1.2); else if((c=='z'||c=='>') && zoom<grMaxZoom) setZoom(zoom*1.2);
else if(c=='?') setZoom(1); else if(c=='?') setZoom(1);
// FIXME these keys are for the simulator (but not when focus is in a textbox)
else if(c=='n') stepForward(); else if(c=='n') stepForward();
else if(c=='p') stepBack(); else if(c=='p') stepBack();
} }
// handler for mousedown events over chip display
// must handle click-to-select (and focus), and drag to pan
function mouseDown(e){ function mouseDown(e){
chipsurround.focus();
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)}; chipsurround.onmousemove = function(e){mouseMove(e)};
window.onmouseup = function(e){mouseUp(e)}; chipsurround.onmouseup = function(e){mouseUp(e)};
} }
function mouseMove(e){ function mouseMove(e){
@ -247,8 +252,8 @@ function mouseMove(e){
function mouseUp(e){ function mouseUp(e){
if(!moved) handleClick(e); if(!moved) handleClick(e);
window.onmousemove = undefined; chipsurround.onmousemove = undefined;
window.onmouseup = undefined; chipsurround.onmouseup = undefined;
} }
function setZoom(n){ function setZoom(n){
@ -307,17 +312,20 @@ function updateExpertMode(isOn){
document.getElementById('layoutControlPanel').style.display = 'block'; document.getElementById('layoutControlPanel').style.display = 'block';
} }
var chipsurround;
function updateChipLayoutVisibility(isOn){ function updateChipLayoutVisibility(isOn){
chipLayoutIsVisible=isOn; chipLayoutIsVisible=isOn;
if(chipLayoutIsVisible) { if(chipLayoutIsVisible) {
document.getElementById('chipsurround').style.display = 'block'; chipsurround=document.getElementById('chipsurround');
chipsurround.style.display = 'block';
if(expertMode) if(expertMode)
document.getElementById('layoutControlPanel').style.display = 'block'; document.getElementById('layoutControlPanel').style.display = 'block';
document.getElementById('nochip').style.display = 'none'; document.getElementById('nochip').style.display = 'none';
//document.getElementById('logstreamscroller').style.height="260px"; //document.getElementById('logstreamscroller').style.height="260px";
// allow the display to update while we load the graphics
updateChipLayoutAnimation(true); updateChipLayoutAnimation(true);
setStatus('loading graphics...'); setStatus('loading graphics...');
// allow the browser to respond while we load the graphics
setTimeout(setupChipLayoutGraphics, 0); setTimeout(setupChipLayoutGraphics, 0);
} else { } else {
// cannot animate the layout if there is no canvas // cannot animate the layout if there is no canvas
@ -342,7 +350,10 @@ function setupChipLayoutGraphics(){
setStatus('Ready!'); // would prefer chipStatus but it's not idempotent setStatus('Ready!'); // would prefer chipStatus but it's not idempotent
if(moveHereFirst!=null) if(moveHereFirst!=null)
moveHere(moveHereFirst); moveHere(moveHereFirst);
hilite.onmousedown = function(e){mouseDown(e);} // grant focus to the chip display to enable zoom keys
chipsurround.focus();
chipsurround.onmousedown = function(e){mouseDown(e);};
chipsurround.onkeypress = function(e){handleKey(e);};
} }
// utility function to save graphics pan and zoom // utility function to save graphics pan and zoom

View File

@ -73,7 +73,7 @@ function selectCell(n){
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);}; table.onkeydown = function(e){cellKeydown(e);};
} }
function unselectCell(){ function unselectCell(){