Changed the last embedPC() parameter from sStateFile to sParms, although for backward compatibility, if sParms is not a JSON object definition (ie, beginning with a brace), it continues to be treated as a state filename.

This change allows us to pass any number of additional properties to embedPC(), which in turn can override properties contained in the XML file; the only property overrides currently supported are 'state' (which overrides any 'state' property set in the XML's <computer> element) and 'automount' (which overrides any 'automount' property set in the XML's <fdc> element).  The goal is to make it easier to reuse XML machine definitions, by allowing commonly altered component attributes to be overridden.
This commit is contained in:
Jeff Parsons 2016-01-18 16:11:08 -08:00
commit 12b760f912
28 changed files with 2187 additions and 2059 deletions

View file

@ -82,7 +82,7 @@ if (NODE) {
* @param {Object} [parmsMachine]
* @param {boolean} [fSuspended]
*
* The Computer component has no required (parmsComputer) properties, but does
* The Computer component has no required (parmsComputer) properties, but it does
* support the following:
*
* autoPower: true to automatically power the computer (default), false to wait;
@ -102,6 +102,16 @@ if (NODE) {
*
* state: the path to JSON-encoded state file (see details regarding 'state' below)
*
* The parmsMachine object, if provided, may contain any of:
*
* url: the location of the machine XML file
*
* autoMount: if set, this should override any 'autoMount' property in the FDC's
* parmsFDC object.
*
* state: if set, this should override any 'state' property in the Computer's
* parmsComputer object.
*
* If a predefined state is supplied AND it's successfully loaded, then resume behavior
* defaults to '1' (ie, resume enabled without prompting).
*
@ -141,7 +151,9 @@ function Computer(parmsComputer, parmsMachine, fSuspended) {
this.sStateData = null;
this.fStateData = false; // remembers if sStateData was loaded
this.fServerState = false;
this.url = parmsMachine? parmsMachine['url'] : null;
this.parmsMachine = parmsMachine;
this.url = this.getMachineParm('url') || "";
/*
* Generate a random number x (where 0 <= x < 1), add 0.1 so that it's guaranteed to be
@ -230,7 +242,7 @@ function Computer(parmsComputer, parmsMachine, fSuspended) {
* localStorage (in other words, it prevents fAllowResume from being true, and forcing resume off).
*/
var fAllowResume;
var sState = Component.parmsURL && Component.parmsURL['state'] || (fAllowResume = true) && parmsComputer['state'];
var sState = Component.parmsURL && Component.parmsURL['state'] || this.getMachineParm('state') || (fAllowResume = true) && parmsComputer['state'];
if (sState) {
sStatePath = this.sStatePath = sState;
@ -318,6 +330,17 @@ Computer.prototype.getMachineID = function()
return this.sMachineID;
};
/**
* getMachineParm(sParm)
*
* @param {string} sParm
* @return {string|undefined}
*/
Computer.prototype.getMachineParm = function(sParm)
{
return this.parmsMachine && this.parmsMachine[sParm];
};
/**
* getUserID()
*

View file

@ -142,22 +142,11 @@ function FDC(parmsFDC) {
this['dmaWrite'] = this.dmaWrite;
this['dmaFormat'] = this.dmaFormat;
this.configMount = null;
if (parmsFDC['autoMount']) {
this.configMount = parmsFDC['autoMount'];
if (typeof this.configMount == "string") {
try {
/*
* The most likely source of any exception will be right here, where we're parsing
* the JSON-encoded diskette data.
*/
this.configMount = eval("(" + parmsFDC['autoMount'] + ")");
} catch (e) {
Component.error("FDC auto-mount error: " + e.message + " (" + parmsFDC['autoMount'] + ")");
this.configMount = null;
}
}
}
/*
* We record any 'autoMount' object now, but we no longer parse it until initBus(), because the Computer's
* getMachineParm() service may have an override for us.
*/
this.configMount = parmsFDC['autoMount'] || null;
/*
* The following array keeps track of every disk image we've ever mounted. Each entry in the
@ -533,6 +522,23 @@ FDC.prototype.initBus = function(cmp, bus, cpu, dbg)
this.chipset = cmp.getMachineComponent("ChipSet");
this.configMount = this.cmp.getMachineParm('autoMount') || this.configMount;
if (this.configMount) {
if (typeof this.configMount == "string") {
try {
/*
* The most likely source of any exception will be right here, where we're parsing
* the JSON-encoded diskette data.
*/
this.configMount = eval("(" + this.configMount + ")");
} catch (e) {
Component.error("FDC auto-mount error: " + e.message + " (" + this.configMount + ")");
this.configMount = null;
}
}
}
/*
* If we didn't need auto-mount support, we could defer controller initialization until we received a powerUp() notification,
* at which point reset() would call initController(), or restore() would restore the controller; in that case, all we'd need