1
0
mirror of https://github.com/pkimpel/retro-b5500.git synced 2026-02-11 10:55:09 +00:00
Files
pkimpel.retro-b5500/webUI/B5500TestLoader.html
paul 0857237ea9 Commit further development of test-file loader: use DataView instead
of Uint16Array to avoid littleendian issues.
2012-09-16 01:49:55 +00:00

135 lines
4.4 KiB
HTML

<!DOCTYPE html>
<head>
<title>B5500 Test Loader</title>
<meta name="Author" content="Paul Kimpel">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
<link id=defaultStyleSheet rel=stylesheet type="text/css" href="B5500DistributionAndDisplay.css">
<script src="../emulator/B5500SystemConfiguration.js"></script>
<script src="../emulator/B5500CentralControl.js"></script>
<script src="../emulator/B5500Processor.js"></script>
<script>
"use strict";
window.onload = function() {
var cc = new B5500CentralControl();
function store(addr, word) {
/* Stores a 48-bit word at the specified B5500 address.
Invalid addresses are ignored */
var modNr = addr >>> 12;
var modAddr = addr & 0x0FFF;
if (modNr < 8 && cc.MemMod[modNr]) {
cc.MemMod[modNr][modAddr] = word;
}
}
function fileLoader_onLoad(ev) {
/* Handle the onload event for an ArrayBuffer FileReader */
var addr = 0; // starting B5500 memory address
var buf = ev.target.result;
var bytes = buf.byteLength;
var data = new DataView(buf); // use DataView() to avoid problems with littleendians.
var power = 0x10000000000;
var word = 0;
var x = 0;
while (bytes > 6) {
store(addr, data.getUint32(x, false)*0x10000 + data.getUint16(x+4, false));
x += 6;
bytes -= 6;
if (++addr > 0x7FFF) {
break;
}
}
// Store any partial word that may be left
while (bytes > 0) {
word += data.getUint8(x, false)*power;
x++;
bytes--;
power /= 0x100;
}
store(addr, word);
document.getElementById("RunBtn").disabled = false;
alert("File loaded: " + buf.byteLength + " bytes, last addr = @" + addr.toString(8));
}
function fileSelector_onChange(ev) {
/* Handle the <input type=file> onchange event when a file is selected */
var f = ev.target.files[0];
var reader = new FileReader();
reader.onload = fileLoader_onLoad;
document.getElementById("RunBtn").disabled = true;
reader.readAsArrayBuffer(f);
}
function runBtn_onClick(ev) {
/* Driver to initiate Processor module */
cc.clear();
cc.loadTimer = null;
cc.LOFF = 0;
cc.P1.C = 0x10; // execute from address @20
cc.P1.access(0x30); // P = [C]
cc.P1.T = cc.fieldIsolate(cc.P, 0, 12);
cc.P1.TROF = 1;
cc.P1.L = 1; // advance L to the next syllable
// Now start scheduling P1 on the Javascript thread
cc.P1.procTime = new Date().getTime()*1000;
cc.P1.scheduler = setTimeout(cc.P1.schedule, 0);
}
function checkBrowser() {
/* Checks whether this browser can support the necessary stuff */
var missing = "";
if (!window.File) {missing += ", File"}
if (!window.FileReader) {missing += ", FileReader"}
if (!window.FileList) {missing += ", FileList"}
if (!window.Blob) {missing += ", Blob"}
if (!window.ArrayBuffer) {missing += ", ArrayBuffer"}
if (!window.DataView) {missing += ", DataView"}
if (missing.length == 0) {
return false;
} else {
alert("No can do... your browser does not support the following features:\n" + missing.substring(2));
return true;
}
}
/* Start of window.onload() */
if (checkBrowser()) {
return;
}
cc.powerOn();
document.getElementById("FileSelector").addEventListener("change", fileSelector_onChange, false);
document.getElementById("RunBtn").addEventListener("click", runBtn_onClick, false);
}
</script>
</head>
<body>
<div style="position:relative; width:100%">
<div style="position:absolute; left:0; top:0; width:auto">
retro-B5500 Test Loader
</div>
<div style="position:absolute; top:0; right:0; width:auto">
<input id=FileSelector type=file size=60>
&nbsp;
<input id=RunBtn type=button value=Run disabled>
</div>
</div>
</body>
</html>