Skip to content

Commit

Permalink
Add support for switching ROMs in the web interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
nelhage committed Jun 2, 2011
1 parent b59ba9a commit 643f62e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
10 changes: 10 additions & 0 deletions beta.html
Expand Up @@ -11,6 +11,11 @@
<script language="javascript" type="text/javascript" src="tests/litmus.js"></script>
<link rel="stylesheet" type="text/css" href="termlib/term_styles.css" />
<link rel="stylesheet" type="text/css" href="beta.css" />
<script language="javascript" type="text/javascript">
betaROMs.push(new BetaROM("Lab 8", lab8_rom));
betaROMs.push(new BetaROM("litmus", litmus_rom));
betaROMs.push(new BetaROM("hello", hello_rom));
</script>
</head>
<body onload="initBeta();">
<div id='beta'>
Expand All @@ -19,6 +24,11 @@
<div id='controls'>
<input id='resetbutton' type="button" value="reset" onclick='resetBeta();'/>
<input id='playplausebutton' type="button" value="run" onclick='playPauseBeta();'/>
Load ROM:
<select id='romselector'>
<option></option>
</select>
<input id='loadrombutton' type="button" value="Go!" onclick='loadROM();'/>
<div id='betapc'>
</div>
</div>
Expand Down
32 changes: 29 additions & 3 deletions betaweb.js
@@ -1,5 +1,11 @@
var betaTerm;
var betaDiv;
var betaROMs = [];

function BetaROM(name, rom) {
this.name = name;
this.rom = rom;
}

function initBeta() {
betaTerm = new Terminal( {handler: termHandler, initHandler: initTerm} );
Expand All @@ -8,13 +14,33 @@ function initBeta() {

betaDiv = document.getElementById('termDiv');
betaDiv.onmousedown = mouseHandler;

var select = document.getElementById('romselector');
var i, option;
while (select.firstChild)
select.removeChild(select.firstChild);
for (i = 0; i < betaROMs.length; i++) {
option = document.createElement('option');
option.value = i;
option.appendChild(document.createTextNode(betaROMs[i].name));
select.appendChild(option);
}

resetBeta();
}

function resetBeta() {
function loadROM() {
var select = document.getElementById('romselector');
var rom = betaROMs[select.children[select.selectedIndex].value];
resetBeta(rom)
}

function resetBeta(rom) {
if (rom === undefined)
rom = betaROMs[0];
betaTerm.clear();

MMU.load(lab8_rom);
MMU.load(rom.rom);
CPU.reset({timer: true,
write: function(ch){
if (ch == 10)
Expand All @@ -23,7 +49,7 @@ function resetBeta() {
betaTerm.type(String.fromCharCode(ch));
},
halt: function() {
term.type("--- Program terminated ----");
betaTerm.type("--- Program terminated ----");
}});
playPauseBeta();
}
Expand Down

0 comments on commit 643f62e

Please sign in to comment.