Permalink
Browse files

Add a register display.

  • Loading branch information...
nelhage committed Jun 4, 2011
1 parent 59ad2f6 commit 7a218c8698fb6076f7668b24d669898e75885583
Showing with 84 additions and 21 deletions.
  1. +17 −1 beta.css
  2. +29 −3 beta.html
  3. +38 −17 betaweb.js
@@ -20,7 +20,23 @@
float: right;
}
#registers {
font-family: mono;
}
#PC {
text-align: center;
font-family: mono;
}
#regtab {
margin: auto;
border-collapse: collapse;
}
#regtab td, #regtab th {
border: 1px solid black;
}
#regtab th {
padding-left: 1em;
}
@@ -10,9 +10,9 @@
<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"));
betaROMs.push(new BetaROM("litmus", "litmus"));
betaROMs.push(new BetaROM("hello", "hello"));
BETA.ROMs.push(new BetaROM("Lab 8", "lab8"));
BETA.ROMs.push(new BetaROM("litmus", "litmus"));
BETA.ROMs.push(new BetaROM("hello", "hello"));
</script>
</head>
<body onload="initBeta();">
@@ -38,6 +38,32 @@
<div id='PC'>
PC: <span id='pcval'>00000000</span>
</div>
<table id='regtab'>
<tr>
<th>R0:</th><td>00000000</td> <th>R1:</th><td>00000000</td> <th>R2:</th><td>00000000</td> <th>R3:</th><td>00000000</td>
</tr>
<tr>
<th>R4:</th><td>00000000</td> <th>R5:</th><td>00000000</td> <th>R6:</th><td>00000000</td> <th>R7:</th><td>00000000</td>
</tr>
<tr>
<th>R8:</th><td>00000000</td> <th>R9:</th><td>00000000</td> <th>R10:</th><td>00000000</td> <th>R11:</th><td>00000000</td>
</tr>
<tr>
<th>R12:</th><td>00000000</td> <th>R13:</th><td>00000000</td> <th>R14:</th><td>00000000</td> <th>R15:</th><td>00000000</td>
</tr>
<tr>
<th>R16:</th><td>00000000</td> <th>R17:</th><td>00000000</td> <th>R18:</th><td>00000000</td> <th>R19:</th><td>00000000</td>
</tr>
<tr>
<th>R20:</th><td>00000000</td> <th>R21:</th><td>00000000</td> <th>R22:</th><td>00000000</td> <th>R23:</th><td>00000000</td>
</tr>
<tr>
<th>R24:</th><td>00000000</td> <th>R25:</th><td>00000000</td> <th>R26:</th><td>00000000</td> <th>R27:</th><td>00000000</td>
</tr>
<tr>
<th>R28:</th><td>00000000</td> <th>R29:</th><td>00000000</td> <th>R30:</th><td>00000000</td> <th>R31:</th><td>00000000</td>
</tr>
</table>
</div>
<div id="rightcol">
</div>
@@ -1,10 +1,16 @@
var betaTerm;
var betaDiv;
var betaROMs = [];
var BETA = {
term: null,
div: null,
ROMs: [],
regCells: [],
};
function toHex(x) {
if (x < 0) x += 0x80000000;
return x.toString(16);
var str = x.toString(16);
while (str.length < 8)
str = '0' + str;
return str;
}
function BetaROM(desc, path) {
@@ -48,24 +54,35 @@ BetaROM.prototype.load = function (success, fail) {
}
function initBeta() {
betaTerm = new Terminal( {handler: termHandler, initHandler: initTerm} );
betaTerm.charMode = true;
betaTerm.open();
BETA.term = new Terminal( {handler: termHandler, initHandler: initTerm} );
BETA.term.charMode = true;
BETA.term.open();
betaDiv = document.getElementById('termDiv');
betaDiv.onmousedown = mouseHandler;
BETA.div = document.getElementById('termDiv');
BETA.div.onmousedown = mouseHandler;
var select = document.getElementById('romselector');
var i, option;
var i, j, option;
while (select.firstChild)
select.removeChild(select.firstChild);
for (i = 0; i < betaROMs.length; i++) {
for (i = 0; i < BETA.ROMs.length; i++) {
option = document.createElement('option');
option.value = i;
option.appendChild(document.createTextNode(betaROMs[i].desc));
option.appendChild(document.createTextNode(BETA.ROMs[i].desc));
select.appendChild(option);
}
var table = document.getElementById('regtab');
var rows = table.rows;
var cells;
for (i = 0; i < rows.length; i++){
cells = rows[i].cells;
for (j = 0; j < cells.length; j++) {
if (cells[j].nodeName == 'TD')
BETA.regCells.push(cells[j]);
}
}
$.ajaxSetup({
beforeSend: function (xhr, settings) {
xhr.overrideMimeType('text/plain; charset=x-user-defined');
@@ -77,7 +94,7 @@ function initBeta() {
function loadROM() {
var select = document.getElementById('romselector');
var rom = betaROMs[select.children[select.selectedIndex].value];
var rom = BETA.ROMs[select.children[select.selectedIndex].value];
rom.load(function() {
resetBeta(rom);
}, function (rom, err) {
@@ -86,18 +103,18 @@ function loadROM() {
}
function resetBeta(rom) {
betaTerm.clear();
BETA.term.clear();
MMU.load(rom.rom);
CPU.reset({timer: true,
write: function(ch){
if (ch == 10)
betaTerm.newLine();
BETA.term.newLine();
else
betaTerm.type(String.fromCharCode(ch));
BETA.term.type(String.fromCharCode(ch));
},
halt: function() {
betaTerm.type("--- Program terminated ----");
BETA.term.type("--- Program terminated ----");
refreshDisplay();
}});
playPauseBeta();
@@ -114,6 +131,7 @@ function playPauseBeta() {
function refreshDisplay() {
var div = document.getElementById('pcval');
var button = document.getElementById('playpausebutton');
var i;
if (CPU.halt) {
div.textContent = "<stopped>";
@@ -128,6 +146,9 @@ function refreshDisplay() {
button.value = "run";
}
}
for (i = 0; i < 31; i++)
BETA.regCells[i].textContent = toHex(CPU.regs[i]);
}
function initTerm() {

0 comments on commit 7a218c8

Please sign in to comment.