Added more scripting support to PCx86 (eg, for loading disks, typing keys, and waiting for both to finish)

This commit is contained in:
Jeff Parsons 2017-07-25 10:30:29 -07:00 committed by Jeff Parsons
commit 1b987df6e2
9 changed files with 1251 additions and 1186 deletions

View file

@ -763,7 +763,7 @@ class Component {
* Component.processScript(idMachine, sScript)
*
* @param {string} idMachine
* @param {string} sScript
* @param {string} [sScript]
* @return {boolean}
*/
static processScript(idMachine, sScript)
@ -848,7 +848,7 @@ class Component {
}
if (!fSuccess) {
Component.alertUser("Script error: " + sCommand + (fnCommand? " failed" : " unrecognized"));
Component.alertUser("Script error: '" + sCommand + "' command " + (fnCommand? " failed" : " unrecognized"));
break;
}
}

View file

@ -623,15 +623,47 @@ function findMachineComponent(idMachine, sType)
}
/**
* processMachineScript(idMachine, sScript)
* commandMachine(control, fSingle, idMachine, sComponent, sCommand, sValue)
*
* Use Component methods to find the requested component for a specific machine, and if the component is found,
* then check its 'exports' table for an entry matching the specified command string, and if an entry is found, then
* the corresponding function is called with the specified data.
*
* @param {Object} control
* @param {boolean} fSingle
* @param {string} idMachine
* @param {string} sScript
* @param {string} sComponent
* @param {string} sCommand
* @param {string} [sValue]
* @return {boolean}
*/
function processMachineScript(idMachine, sScript)
function commandMachine(control, fSingle, idMachine, sComponent, sCommand, sValue)
{
return Component.processScript(idMachine, sScript);
if (sCommand == "script") {
if (Component.processScript(idMachine, sValue)) {
if (fSingle) control.disabled = true;
return true;
}
return false;
}
if (sComponent) {
var component = Component.getComponentByType(sComponent, idMachine + ".machine");
if (component) {
var exports = component['exports'];
if (exports) {
var fnCommand = exports[sCommand];
if (fnCommand) {
if (fnCommand.call(component, sValue)) {
if (fSingle) control.disabled = true;
return true;
}
return false;
}
}
}
}
console.log("unimplemented: commandMachine('" + idMachine + "','" + sComponent + "','" + sCommand + "','" + sValue + "')");
return false;
}
/**
@ -655,8 +687,7 @@ if (APPNAME == "PDPjs") {
window['embedPDP11'] = embedPDP11;
}
window['findMachineComponent'] = findMachineComponent;
window['processMachineScript'] = processMachineScript;
window['commandMachine'] = commandMachine;
window['enableEvents'] = Web.enablePageEvents;
window['sendEvent'] = Web.sendPageEvent;

View file

@ -87,59 +87,6 @@ function addStickyMachine(idMachine, sPosition)
};
}
/**
* commandMachine(control, fSingle, idMachine, sComponent, sCommand, sValue)
*
* Note that this script is not compiled into any of the machines, since "sticky machines" are feature of the PCjs
* website rather than of the machines. And since the machines are compiled, all their code and data is completely
* opaque to us, except for those functions explicitly exported by embed.js.
*
* So now, in addition to the functions for embedding machines on a webpage, embed.js includes a few new functions:
*
* findMachineComponent()
* processMachineScript()
*
* which uses existing Component methods to find the requested component for a specific machine, and if the
* component is found, then its 'exports' table is checked for an entry matching the specified command string, and if
* an entry is found, then the corresponding function is called with the specified data.
*
* @param {Object} control
* @param {boolean} fSingle
* @param {string} idMachine
* @param {string} sComponent
* @param {string} sCommand
* @param {string} [sValue]
* @return {boolean}
*/
function commandMachine(control, fSingle, idMachine, sComponent, sCommand, sValue)
{
if (sCommand == "script" && window.processMachineScript) {
if (window.processMachineScript(idMachine, sValue)) {
if (fSingle) control.disabled = true;
return true;
}
return false;
}
if (sComponent && window.findMachineComponent) {
var component = window.findMachineComponent(idMachine, sComponent);
if (component) {
var exports = component['exports'];
if (exports) {
var fnCommand = exports[sCommand];
if (fnCommand) {
if (fnCommand.call(component, sValue)) {
if (fSingle) control.disabled = true;
return true;
}
return false;
}
}
}
}
console.log("unimplemented: commandMachine('" + idMachine + "','" + sComponent + "','" + sCommand + "','" + sValue + "')");
return false;
}
/**
* findTop(obj)
*