Groundwork for loading local disk images in PCjs

This commit is contained in:
Jeff Parsons 2014-11-09 18:57:13 -08:00 committed by jeffpar
commit 43860a588c
20 changed files with 1355 additions and 1157 deletions

View file

@ -163,18 +163,18 @@ C1PComputer.prototype.stop = function(msStart, nCycles)
/**
* @this {C1PComputer}
* @param {string|null} c is the class of the HTML control (eg, "input", "output")
* @param {string|null} t is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} s is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "reset")
* @param {Object} e is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string|null} sHTMLClass is the class of the HTML control (eg, "input", "output")
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "reset")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PComputer.prototype.setBinding = function(c, t, s, e)
C1PComputer.prototype.setBinding = function(sHTMLClass, sHTMLType, sBinding, control)
{
switch(s) {
switch(sBinding) {
case "reset":
this.bindings[s] = e;
e.onclick = function(computer) {
this.bindings[sBinding] = control;
control.onclick = function(computer) {
return function() {
computer.reset();
};

View file

@ -502,19 +502,19 @@ C1PCPU.prototype.reset = function(fPowerOn)
/**
* @this {C1PCPU}
* @param {string|null} c is the class of the HTML control (eg, "input", "output")
* @param {string|null} t is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} s is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "run")
* @param {Object} e is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string|null} sHTMLClass is the class of the HTML control (eg, "input", "output")
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "run")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PCPU.prototype.setBinding = function(c, t, s, e)
C1PCPU.prototype.setBinding = function(sHTMLClass, sHTMLType, sBinding, control)
{
var fBound = false;
switch(s) {
switch(sBinding) {
case "run":
this.bindings[s] = e;
e.onclick = function(cpu) {
this.bindings[sBinding] = control;
control.onclick = function(cpu) {
return function() {
if (!cpu.aFlags.fRunning)
cpu.run();
@ -527,12 +527,12 @@ C1PCPU.prototype.setBinding = function(c, t, s, e)
case "A": case "X": case "Y": case "S": case "PC":
case "C": case "Z": case "I": case "D": case "B": case "V": case "N":
case "speed":
this.bindings[s] = e;
this.bindings[sBinding] = control;
fBound = true;
break;
case "setSpeed":
this.bindings[s] = e;
e.onclick = function(cpu) {
this.bindings[sBinding] = control;
control.onclick = function(cpu) {
return function() {
var speed = (cpu.speed >= cpu.SPEED_MAX? cpu.SPEED_SLOW : cpu.speed+1);
cpu.setSpeed(speed, true);

View file

@ -657,21 +657,23 @@ C1PDiskController.prototype.resetDrive = function(iDrive, iDriveType, nMaxTracks
/**
* @this {C1PDiskController}
* @param {string|null} c is the class of the HTML control (eg, "input", "output")
* @param {string|null} t is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} s is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "listDisk")
* @param {Object} e is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string|null} sHTMLClass is the class of the HTML control (eg, "input", "output")
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "listDisk")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PDiskController.prototype.setBinding = function(c, t, s, e)
C1PDiskController.prototype.setBinding = function(sHTMLClass, sHTMLType, sBinding, control)
{
switch(s) {
switch(sBinding) {
case "listDisk":
this.bindings[s] = e;
this.bindings[sBinding] = control;
return true;
case "loadDisk":
this.bindings[s] = e;
e.onclick = function(controller) {
this.bindings[sBinding] = control;
control.onclick = function(controller) {
return function() {
if (controller.bindings["listDisk"]) {
var sFilePath = controller.bindings["listDisk"].value;
@ -698,6 +700,7 @@ C1PDiskController.prototype.setBinding = function(c, t, s, e)
};
}(this);
return true;
default:
break;
}

View file

@ -388,38 +388,38 @@ C1PKeyboard.prototype.reset = function()
/**
* @this {C1PKeyboard}
* @param {string|null} c is the class of the HTML control (eg, "input", "output")
* @param {string|null} t is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} s is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "esc", "ctrl-c")
* @param {Object} e is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string|null} sHTMLClass is the class of the HTML control (eg, "input", "output")
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "esc", "ctrl-c")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PKeyboard.prototype.setBinding = function(c, t, s, e)
C1PKeyboard.prototype.setBinding = function(sHTMLClass, sHTMLType, sBinding, control)
{
/*
* I want to bind to the first caller (ie, the Screen), not subsequent ones (eg, the Panel)
*/
if (this.bindings[s] === undefined) {
switch(s) {
if (this.bindings[sBinding] === undefined) {
switch(sBinding) {
case "keyDown":
this.bindings[s] = e;
e.onkeydown = function(kbd) {
this.bindings[sBinding] = control;
control.onkeydown = function(kbd) {
return function(event) {
return kbd.keyEvent(event, true);
};
}(this);
return true;
case "keyPress":
this.bindings[s] = e;
e.onkeypress = function(kbd) {
this.bindings[sBinding] = control;
control.onkeypress = function(kbd) {
return function(event) {
return kbd.keyPress(event);
};
}(this);
return true;
case "keyUp":
this.bindings[s] = e;
e.onkeyup = function(kbd) {
this.bindings[sBinding] = control;
control.onkeyup = function(kbd) {
return function(event) {
return kbd.keyEvent(event, false);
};
@ -436,8 +436,8 @@ C1PKeyboard.prototype.setBinding = function(c, t, s, e)
* other injected keys, I'll need to avoid clearing the injection buffer on a reset;
* currently, reset() resets everything.
*/
this.bindings[s] = e;
e.onclick = function(kbd) {
this.bindings[sBinding] = control;
control.onclick = function(kbd) {
return function(event) {
if (DEBUG) kbd.println("keyPressSimulate(break)");
if (kbd.cmp) kbd.cmp.reset(true);
@ -445,15 +445,15 @@ C1PKeyboard.prototype.setBinding = function(c, t, s, e)
}(this);
return true;
default:
if (this.aButtonCodeMap[s] !== undefined) {
this.bindings[s] = e;
e.onclick = function(kbd, sButton, charCode) {
if (this.aButtonCodeMap[sBinding] !== undefined) {
this.bindings[sBinding] = control;
control.onclick = function(kbd, sButton, charCode) {
return function(event) {
if (DEBUG) kbd.println("keyPressSimulate(" + sButton + ")");
if (kbd.cpu) kbd.cpu.setFocus();
return !kbd.keyPressSimulate(charCode);
};
}(this, s, this.aButtonCodeMap[s]);
}(this, sBinding, this.aButtonCodeMap[sBinding]);
return true;
}
break;

View file

@ -100,64 +100,73 @@ C1PSerialPort.prototype.start = function()
/**
* @this {C1PSerialPort}
* @param {string|null} c is the class of the HTML control (eg, "input", "output")
* @param {string|null} t is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} s is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "listSerial")
* @param {Object} e is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string|null} sHTMLClass is the class of the HTML control (eg, "input", "output")
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "listSerial")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PSerialPort.prototype.setBinding = function(c, t, s, e)
C1PSerialPort.prototype.setBinding = function(sHTMLClass, sHTMLType, sBinding, control)
{
switch(s) {
case "listSerial":
this.bindings[s] = e;
return true;
case "loadSerial":
this.bindings[s] = e;
e.onclick = function(serial) {
return function() {
if (serial.bindings["listSerial"]) {
var sFile = serial.bindings["listSerial"].value;
// serial.println("loading " + sFile + "...");
web.loadResource(sFile, true, null, serial, serial.loadFile);
}
};
}(this);
return true;
case "uploadSerial":
// Check for availability of FileReader
if (window.FileReader && window.File && window.FileList && window.Blob ) {
var serial = this;
this.bindings[s] = e;
var serial = this;
// Enable "Load Local File" button only if a file is actually selected
e.addEventListener('change', function () {
var fieldset = e.children[0];
switch(sBinding) {
case "listSerial":
this.bindings[sBinding] = control;
return true;
case "loadSerial":
this.bindings[sBinding] = control;
control.onclick = function(event) {
if (serial.bindings["listSerial"]) {
var sFile = serial.bindings["listSerial"].value;
// serial.println("loading " + sFile + "...");
web.loadResource(sFile, true, null, serial, serial.loadFile);
}
};
return true;
case "uploadSerial":
/*
* Check for availability of FileReader
*/
if (window.FileReader && window.File && window.FileList && window.Blob) {
this.bindings[sBinding] = control;
/*
* Enable "Load Local File" button only if a file is actually selected
*/
control.addEventListener('change', function() {
var fieldset = control.children[0];
var files = fieldset.children[0].files;
var submit = fieldset.children[1];
submit.disabled = (files.length == 0);
});
e.onsubmit = function (event) {
control.onsubmit = function(event) {
var file = event.currentTarget[1].files[0];
var reader = new FileReader();
reader.onload = function () {
// serial.println("uploading " + file.name + "...");
reader.onload = function() {
// serial.println("loading " + file.name + "...");
serial.loadFile(file.name, reader.result.toString(), 0);
};
reader.readAsText(file);
// Prevent reloading of web page after form submission
/*
* Prevent reloading of web page after form submission
*/
return false;
};
}
else {
this.println("FileReader support not available, disabling local file upload");
e.parentNode.removeChild(e);
this.println("FileReader support not available, disabling local file load");
control.parentNode.removeChild(control);
}
return true;
default:
break;
}

View file

@ -172,18 +172,18 @@ C1PVideo.prototype.reset = function(fPowerOn)
/**
* @this {C1PVideo}
* @param {string|null} c is the class of the HTML control (eg, "input", "output")
* @param {string|null} t is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} s is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "refresh")
* @param {Object} e is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string|null} sHTMLClass is the class of the HTML control (eg, "input", "output")
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "refresh")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PVideo.prototype.setBinding = function(c, t, s, e)
C1PVideo.prototype.setBinding = function(sHTMLClass, sHTMLType, sBinding, control)
{
switch(s) {
switch(sBinding) {
case "refresh":
this.bindings[s] = e;
e.onclick = function(video) {
this.bindings[sBinding] = control;
control.onclick = function(video) {
return function() {
if (DEBUG) video.println("refreshScreen()");
video.initScreen();