Disk in current drive can now be saved as an IMG file, and groundwork has been laid for saving an entire machine

This commit is contained in:
Jeff Parsons 2016-02-12 14:14:56 -08:00
commit 9c2ec7a20b
17 changed files with 1684 additions and 1549 deletions

View file

@ -12,7 +12,7 @@
<keyboard ref="/devices/pc/keyboard/keyboard-minimal.xml"/>
<debugger id="debugger"/>
<panel ref="/devices/pc/panel/wide.xml"/>
<fdc ref="/disks/pc/compiled/library.xml" width="320px"/>
<fdc ref="/disks/pc/compiled/library.xml"/>
<chipset id="chipset" model="5160" sw1="01001001" pos="left" padleft="8px" padbottom="8px">
<control type="switches" label="SW1" binding="sw1" left="0px"/>
<control type="description" binding="swdesc" left="0px"/>

View file

@ -9,6 +9,7 @@ machines:
uncompiled: true
autopower: false
build: build-pc
sitemap: false
---
Build Your Own PC

View file

@ -5,7 +5,7 @@
<disk path="">None</disk>
<disk path="/disks/pc/cpm/1.1b/cpm86-disk1.json">CP/M-86 (Disk 1)</disk>
<disk path="/disks/pc/cpm/1.1b/cpm86-disk2.json">CP/M-86 (Disk 2)</disk>
<disk path="/disks/pc/diags/ibm/2.20/5150_5155_5160_ADVDIAG_220.json">IBM Advanced Diagnostics 2.20</disk>
<disk path="/disks/pc/diags/ibm/2.20/5150_5155_5160_ADVDIAG_220.json">IBM Diagnostics 2.20</disk>
<disk path="/disks/pc/dos/ibm/1.00/PCDOS100.json">PC-DOS 1.00</disk>
<disk path="/disks/pc/dos/ibm/1.10/PCDOS110.json">PC-DOS 1.10</disk>
<disk path="/disks/pc/dos/ibm/2.00/PCDOS200-DISK1.json">PC-DOS 2.00 (Disk 1)</disk>
@ -109,7 +109,7 @@
<disk path="/disks/pc/dos/compaq/3.31/COMPAQ-DOS331-DISK3.json">COMPAQ MS-DOS 3.31 (Disk 3)</disk>
<disk path="/disks/pc/dos/compaq/3.31/COMPAQ-DOS331-DISK4.json">COMPAQ MS-DOS 3.31 (Disk 4)</disk>
<disk path="/disks/pc/dos/compaq/3.31/COMPAQ-DOS331-DISK5.json">COMPAQ MS-DOS 3.31 (Disk 5)</disk>
<disk path="/disks/pc/dos/compaq/3.31/COMPAQ-DOS331-DIAG.json">COMPAQ MS-DOS 3.31 (Diagnostics)</disk>
<disk path="/disks/pc/dos/compaq/3.31/COMPAQ-DOS331-DIAG.json">COMPAQ MS-DOS 3.31 (Diags)</disk>
<disk path="/disks/pc/os2/ibm/1.0/OS210-INSTALL.json">IBM OS/2 1.0 (1.44M Install)</disk>
<disk path="/disks/pc/os2/ibm/1.0/OS210-DISK1.json">IBM OS/2 1.0 (1.44M Disk 1)</disk>
<disk path="/disks/pc/os2/ibm/1.0/OS210-DISK2.json">IBM OS/2 1.0 (1.44M Disk 2)</disk>
@ -119,8 +119,8 @@
<disk path="/disks/pc/os2/ibm/1.1/OS211-DISK02.json">IBM OS/2 1.1 (1.44M Disk 2)</disk>
<disk path="/disks/pc/os2/ibm/1.1/OS211-DISK03.json">IBM OS/2 1.1 (1.44M Disk 3)</disk>
<disk path="/disks/pc/os2/ibm/1.1/OS211-DISK04.json">IBM OS/2 1.1 (1.44M Disk 4)</disk>
<disk path="/disks/pc/os2/ibm/1.1/OS211-DEVICES.json">IBM OS/2 1.1 (1.44M Devices Disk)</disk>
<disk path="/disks/pc/os2/ibm/1.1/OS211-PRINTERS.json">IBM OS/2 1.1 (1.44M Printers Disk)</disk>
<disk path="/disks/pc/os2/ibm/1.1/OS211-DEVICES.json">IBM OS/2 1.1 (1.44M Devices)</disk>
<disk path="/disks/pc/os2/ibm/1.1/OS211-PRINTERS.json">IBM OS/2 1.1 (1.44M Printers)</disk>
<disk path="/disks/pc/os2/ibm/1.3/OS213-DISK01.json">IBM OS/2 1.3 (1.44M Disk 1)</disk>
<disk path="/disks/pc/os2/ibm/1.3/OS213-DISK02.json">IBM OS/2 1.3 (1.44M Disk 2)</disk>
<disk path="/disks/pc/os2/ibm/1.3/OS213-DISK03.json">IBM OS/2 1.3 (1.44M Disk 3)</disk>
@ -428,7 +428,8 @@
<disk path="/apps/pc/1992/moria/disk.json">Moria 5.5</disk>
<disk path="/tests/pc/vga/VGABIN.json">VGA Tests (Black Book)</disk>
</control>
<control type="button" binding="loadDrive" padright="8px">Load</control>
<control type="button" binding="loadDrive">Load</control>
<control type="button" binding="saveDrive" padright="8px">Save</control>
<control type="description" binding="descDisk" padright="8px"/>
<control type="file" binding="mountDrive"/>
</fdc>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/versions/pcjs/1.20.9/manifest.xsl"?>
<manifest type="software">
<title>IBM Advanced Diagnostics</title>
<title>IBM Diagnostics</title>
<version>2.20</version>
<type>Diagnostics</type>
<category>Hardware Tests</category>

View file

@ -24,6 +24,6 @@
<name>COMPAQ MS-DOS 3.31 (Disk 5)</name>
</disk>
<disk id="disk06" size="368640" chs="40:2:9" img="archive/COMPAQ-DOS331-DIAG.img" href="/disks/pc/dos/compaq/3.31/COMPAQ-DOS331-DIAG.json" md5="6fc3678180e8d8c2ff5e1c3d99f14d08" md5json="a5e0a418db4fe09c13cfd86635753a05">
<name>COMPAQ MS-DOS 3.31 (Diagnostics)</name>
<name>COMPAQ MS-DOS 3.31 (Diags)</name>
</disk>
</manifest>

View file

@ -85,7 +85,8 @@
<manifest ref="/apps/pc/1992/moria/manifest.xml" disk="disk01"/>
<disk path="/tests/pc/vga/VGABIN.json">VGA Tests (Black Book)</disk>
</control>
<control type="button" binding="loadDrive" padright="8px">Load</control>
<control type="button" binding="loadDrive">Load</control>
<control type="button" binding="saveDrive" padright="8px">Save</control>
<control type="description" binding="descDisk" padright="8px"/>
<control type="file" binding="mountDrive"/>
</fdc>

View file

@ -18,9 +18,9 @@
<name>IBM OS/2 1.1 (1.44M Disk 4)</name>
</disk>
<disk id="disk05" size="1474560" chs="80:2:18" img="archive/OS211-DEVICES.img" href="/disks/pc/os2/ibm/1.1/OS211-DEVICES.json" md5="9d3dfde0206b562beae90cab21f9eba5" md5json="2cb39da33b61e762b87259b59bf5ccf5">
<name>IBM OS/2 1.1 (1.44M Devices Disk)</name>
<name>IBM OS/2 1.1 (1.44M Devices)</name>
</disk>
<disk id="disk06" size="1474560" chs="80:2:18" img="archive/OS211-PRINTERS.img" href="/disks/pc/os2/ibm/1.1/OS211-PRINTERS.json" md5="36cd9ea1e7184872548598dae4b60cb8" md5json="3ddd4aa8468a17a42aa247cf7b447a65">
<name>IBM OS/2 1.1 (1.44M Printers Disk)</name>
<name>IBM OS/2 1.1 (1.44M Printers)</name>
</disk>
</manifest>

View file

@ -228,6 +228,7 @@
<xsl:when test="$url != ''"><div class="{$APPCLASS}-reference">[<a href="{$url}">XML</a>]</div></xsl:when>
<xsl:otherwise/>
</xsl:choose>
<xsl:if test="$MACHINECLASS = 'pc'"><div class="{$APPCLASS}-reference" style="padding-left:8px">[<a href="#" onclick="savePC('{$machine}');">Save Machine</a>]</div></xsl:if>
<div class="{$APPCLASS}-copyright">
<a href="http://{$SITEHOST}" target="_blank">PCjs</a> v<xsl:value-of select="$APPVERSION"/> © 2012-2016 by <a href="http://twitter.com/jeffpar" target="_blank">@jeffpar</a>
</div>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1198,6 +1198,9 @@ Disk.prototype.doneLoad = function(sURL, sDiskData, nErrorCode)
if (DEBUG && this.messageEnabled()) {
this.printMessage('doneLoad("' + this.sDiskPath + '")');
}
Component.addMachineResource(this.controller.idMachine, sURL, sDiskData);
try {
/*
* The following code was a hack to turn on write-protection for a disk image if there was
@ -1839,55 +1842,22 @@ Disk.prototype.getClusterEntry = function(dir, iCluster, iByte)
*
* @this {Disk}
* @param {number} pba (physical block address)
* @return {Object} sector
* @return {Object|null} sector
*/
Disk.prototype.getSector = function(pba)
{
var nSectorsPerCylinder = this.nHeads * this.nSectors;
var iCylinder = (pba / nSectorsPerCylinder) | 0;
this.assert(iCylinder < this.nCylinders);
var nSectorsRemaining = (pba % nSectorsPerCylinder);
var iHead = (nSectorsRemaining / this.nSectors) | 0;
/*
* PBA numbers are 0-based, but the sector numbers in CHS addressing are 1-based, so add one to iSector
*/
var iSector = (nSectorsRemaining % this.nSectors) + 1;
return this.seek(iCylinder, iHead, iSector);
};
/**
* updateSector(file, pba, off)
*
* Like getSector(), this must convert a PBA into CHS values; consider factoring that conversion code out.
*
* @this {Disk}
* @param {Object} file
* @param {number} pba (physical block address from the file's apba)
* @param {number} off (file offset corresponding to the given pba of the given file)
* @return {boolean} true if successfully updated, false if not
*/
Disk.prototype.updateSector = function(file, pba, off)
{
var nSectorsPerCylinder = this.nHeads * this.nSectors;
var iCylinder = (pba / nSectorsPerCylinder) | 0;
var nSectorsRemaining = (pba % nSectorsPerCylinder);
var iHead = (nSectorsRemaining / this.nSectors) | 0;
var iSector = (nSectorsRemaining % this.nSectors);
var cylinder, head, sector;
if ((cylinder = this.aDiskData[iCylinder]) && (head = cylinder[iHead]) && (sector = head[iSector])) {
this.assert(sector['sector'] == iSector +1);
if (sector['file']) {
if (DEBUG && this.messageEnabled()) {
this.printMessage('"' + sector['file'].sPath + '" cross-linked at offset ' + sector['file'].offFile + ' with "' + file.sPath + '" at offset ' + off);
}
return false;
}
sector['file'] = file;
sector.offFile = off;
return true;
if (iCylinder < this.nCylinders) {
var nSectorsRemaining = (pba % nSectorsPerCylinder);
var iHead = (nSectorsRemaining / this.nSectors) | 0;
/*
* PBA numbers are 0-based, but the sector numbers in CHS addressing are 1-based, so add one to iSector
*/
var iSector = (nSectorsRemaining % this.nSectors) + 1;
return this.seek(iCylinder, iHead, iSector);
}
if (DEBUG && this.messageEnabled()) this.printMessage("unable to map PBA " + pba + " to CHS");
return false;
return null;
};
/**
@ -1943,6 +1913,41 @@ Disk.prototype.getSectorString = function(sector, off, len)
return s;
};
/**
* updateSector(file, pba, off)
*
* Like getSector(), this must convert a PBA into CHS values; consider factoring that conversion code out.
*
* @this {Disk}
* @param {Object} file
* @param {number} pba (physical block address from the file's apba)
* @param {number} off (file offset corresponding to the given pba of the given file)
* @return {boolean} true if successfully updated, false if not
*/
Disk.prototype.updateSector = function(file, pba, off)
{
var nSectorsPerCylinder = this.nHeads * this.nSectors;
var iCylinder = (pba / nSectorsPerCylinder) | 0;
var nSectorsRemaining = (pba % nSectorsPerCylinder);
var iHead = (nSectorsRemaining / this.nSectors) | 0;
var iSector = (nSectorsRemaining % this.nSectors);
var cylinder, head, sector;
if ((cylinder = this.aDiskData[iCylinder]) && (head = cylinder[iHead]) && (sector = head[iSector])) {
this.assert(sector['sector'] == iSector +1);
if (sector['file']) {
if (DEBUG && this.messageEnabled()) {
this.printMessage('"' + sector['file'].sPath + '" cross-linked at offset ' + sector['file'].offFile + ' with "' + file.sPath + '" at offset ' + off);
}
return false;
}
sector['file'] = file;
sector.offFile = off;
return true;
}
if (DEBUG && this.messageEnabled()) this.printMessage("unable to map PBA " + pba + " to CHS");
return false;
};
/**
* initSector(sector, iCylinder, iHead, iSector, cbSector, dwPattern)
*
@ -2497,6 +2502,7 @@ Disk.prototype.write = function(sector, ibSector, b)
var dwPattern = sector['pattern'];
var idw = ibSector >> 2;
var nShift = (ibSector & 0x3) << 3;
/*
* Ensure every byte up to the specified byte is properly initialized.
*/
@ -2520,6 +2526,26 @@ Disk.prototype.write = function(sector, ibSector, b)
return null;
};
/**
* encodeAsBase64()
*
* @this {Disk}
* @return {string}
*/
Disk.prototype.encodeAsBase64 = function()
{
/*
* Gross, but simple; more importantly, it works -- at least for disks of typical floppy magnitude.
*/
var s = "", pba = 0, sector;
while ((sector = this.getSector(pba++))) {
for (var off = 0, len = sector['length']; off < len; off++) {
s += String.fromCharCode(this.getSectorData(sector, off, 1));
}
}
return btoa(s);
};
/**
* save()
*

View file

@ -467,6 +467,37 @@ FDC.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
};
return true;
case "saveDrive":
this.bindings[sBinding] = control;
control.onclick = function onClickLoadDrive(event) {
var controlDrives = fdc.bindings["listDrives"];
if (controlDrives && controlDrives.options && fdc.aDrives) {
var iDriveSelected = str.parseInt(controlDrives.value, 10);
var drive = fdc.aDrives[iDriveSelected];
if (drive) {
if (drive.disk) {
if (DEBUG) fdc.println("saving disk " + drive.disk.sDiskPath + "...");
var uri = "data:application/octet-stream;base64," + drive.disk.encodeAsBase64();
var link = document.createElement('a');
if (typeof link.download == 'string') {
link.href = uri;
link.download = drive.disk.sDiskFile.replace(".json", ".img");
document.body.appendChild(link); // Firefox requires the link to be in the body (?)
link.click();
document.body.removeChild(link);
} else {
window.open(uri);
}
} else {
fdc.notice("No disk loaded in drive");
}
} else {
fdc.notice("No drive selected");
}
}
};
return true;
case "mountDrive":
if (this.fLocalDisks) {
this.bindings[sBinding] = control;
@ -1229,10 +1260,10 @@ FDC.prototype.loadSelectedDrive = function(sDisketteName, sDiskettePath, file)
sDiskettePath = window.prompt("Enter the URL of a remote disk image.", "") || "";
if (!sDiskettePath) return;
sDisketteName = str.getBaseName(sDiskettePath);
this.println("Attempting to load " + sDiskettePath + " as \"" + sDisketteName + "\"");
if (DEBUG) this.println("Attempting to load " + sDiskettePath + " as \"" + sDisketteName + "\"");
}
this.println("loading disk " + sDiskettePath + "...");
if (DEBUG) this.println("loading disk " + sDiskettePath + "...");
while (this.loadDiskette(iDrive, sDisketteName, sDiskettePath, false, file)) {
if (!window.confirm("Click OK to reload the original disk.\n(WARNING: All disk changes will be discarded)")) {

View file

@ -225,6 +225,9 @@ ROM.prototype.doneLoad = function(sURL, sROMData, nErrorCode)
this.notice("Unable to load system ROM (error " + nErrorCode + ": " + sURL + ")");
return;
}
Component.addMachineResource(this.idMachine, sURL, sROMData);
if (sROMData.charAt(0) == "[" || sROMData.charAt(0) == "{") {
try {
/*

View file

@ -3724,6 +3724,9 @@ Video.prototype.doneLoad = function(sURL, sFontData, nErrorCode)
this.notice("Unable to load font ROM (error " + nErrorCode + ": " + sURL + ")");
return;
}
Component.addMachineResource(this.idMachine, sURL, sFontData);
try {
/*
* The most likely source of any exception will be right here, where we're parsing the JSON-encoded data.

View file

@ -229,6 +229,7 @@
<xsl:when test="$url != ''"><div class="{$APPCLASS}-reference">[<a href="{$url}">XML</a>]</div></xsl:when>
<xsl:otherwise/>
</xsl:choose>
<xsl:if test="$MACHINECLASS = 'pc'"><div class="{$APPCLASS}-reference" style="padding-left:8px">[<a href="#" onclick="savePC('{$machine}');">Save Machine</a>]</div></xsl:if>
<div class="{$APPCLASS}-copyright">
<a href="http://{$SITEHOST}" target="_blank">PCjs</a> v<xsl:value-of select="$APPVERSION"/> © 2012-2016 by <a href="http://twitter.com/jeffpar" target="_blank">@jeffpar</a>
</div>

View file

@ -215,7 +215,7 @@ Component.subclass = function(subclass, superclass, methods, statics)
* This enables any component to locate another component by ID (see Component.getComponentByID())
* or by type (see Component.getComponentByType()).
*/
Component.all = [];
Component.components = [];
/**
* Component.add(component)
@ -225,11 +225,57 @@ Component.all = [];
Component.add = function(component)
{
/*
* This just generates a lot of useless noise, handy in the early days, not so much these days...
* This just generates a lot of useless noise, handy in the early days, not so much these days....
*
* if (DEBUG) Component.log("Component.add(" + component.type + "," + component.id + ")");
*/
Component.all[Component.all.length] = component;
Component.components.push(component);
};
/*
* Every machine on the page are now recorded as well, by their machine ID. We then record the various resources
* used by that machine.
*/
Component.machines = {};
/**
* Component.addMachine(idMachine)
*
* @param {string} idMachine
*/
Component.addMachine = function(idMachine)
{
Component.machines[idMachine] = {};
};
/**
* Component.addMachineResource(idMachine, sName, data)
*
* @param {string} idMachine
* @param {string} sName (name of the resource)
* @param {*} data
*/
Component.addMachineResource = function(idMachine, sName, data)
{
Component.assert(Component.machines[idMachine]);
if (Component.machines[idMachine]) {
if (!Component.machines[idMachine][sName]) {
Component.machines[idMachine][sName] = [];
}
Component.machines[idMachine][sName].push(data);
}
};
/**
* Component.getMachineResources(idMachine, sName)
*
* @param {string} idMachine
* @param {string} sName (name of the resource)
* @return {Array|undefined}
*/
Component.getMachineResources = function(idMachine, sName)
{
return Component.machines[idMachine] && Component.machines[idMachine][sName];
};
/**
@ -343,8 +389,8 @@ Component.error = function(s)
/**
* Component.getComponents(idRelated)
*
* We could store components as properties of an 'all' object, using the component's ID,
* and change this linear lookup into a property lookup, but some components may have no ID.
* We could store components as properties, using the component's ID, and change
* this linear lookup into a property lookup, but some components may have no ID.
*
* @param {string} [idRelated] of related component
* @return {Array} of components
@ -366,8 +412,8 @@ Component.getComponents = function(idRelated)
else
idRelated = "";
}
for (i = 0; i < Component.all.length; i++) {
var component = Component.all[i];
for (i = 0; i < Component.components.length; i++) {
var component = Component.components[i];
if (!idRelated || !component.id.indexOf(idRelated)) {
aComponents.push(component);
}
@ -378,8 +424,8 @@ Component.getComponents = function(idRelated)
/**
* Component.getComponentByID(id, idRelated)
*
* We could store components as properties of an 'all' object, using the component's ID,
* and change this linear lookup into a property lookup, but some components may have no ID.
* We could store components as properties, using the component's ID, and change
* this linear lookup into a property lookup, but some components may have no ID.
*
* @param {string} id of the desired component
* @param {string} [idRelated] of related component
@ -397,9 +443,9 @@ Component.getComponentByID = function(id, idRelated)
if (idRelated && (i = idRelated.indexOf('.')) > 0) {
id = idRelated.substr(0, i + 1) + id;
}
for (i = 0; i < Component.all.length; i++) {
if (Component.all[i].id === id) {
return Component.all[i];
for (i = 0; i < Component.components.length; i++) {
if (Component.components[i].id === id) {
return Component.components[i];
}
}
Component.log("Component ID '" + id + "' not found", "warning");
@ -431,13 +477,13 @@ Component.getComponentByType = function(sType, idRelated, componentPrev)
idRelated = "";
}
}
for (i = 0; i < Component.all.length; i++) {
for (i = 0; i < Component.components.length; i++) {
if (componentPrev) {
if (componentPrev == Component.all[i]) componentPrev = null;
if (componentPrev == Component.components[i]) componentPrev = null;
continue;
}
if (sType == Component.all[i].type && (!idRelated || !Component.all[i].id.indexOf(idRelated))) {
return Component.all[i];
if (sType == Component.components[i].type && (!idRelated || !Component.components[i].id.indexOf(idRelated))) {
return Component.components[i];
}
}
Component.log("Component type '" + sType + "' not found", "warning");

View file

@ -35,7 +35,7 @@
/* global document: true, window: true, XSLTProcessor: false, APPNAME: false, APPVERSION: false, DEBUG: true */
if (NODE) {
var Component;
var Component = require("./component");
var str = require("./strlib");
var web = require("./weblib");
}
@ -52,8 +52,8 @@ if (NODE) {
* notification events at the start of the embedding process (web.enablePageEvents(false)) and
* re-enable them at the end (web.enablePageEvents(true)).
*/
var cMachines = 0;
var fAsync = true;
var cAsyncMachines = 0;
/**
* loadXML(sFile, idMachine, sParms, fResolve, display, done)
@ -305,27 +305,28 @@ function resolveXML(sXML, display, done)
}
/**
* embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sParms)
* embedMachine(sName, sVersion, idMachine, sXMLFile, sXSLFile, sParms)
*
* This allows to you embed a machine on a web page, by transforming the machine XML into HTML.
*
* @param {string} sName is the app name (eg, "PCjs")
* @param {string} sVersion is the app version (eg, "1.15.7")
* @param {string} idElement
* @param {string} idMachine
* @param {string} sXMLFile
* @param {string} sXSLFile
* @param {string} [sParms]
* @return {boolean} true if successful, false if error
*/
function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sParms)
function embedMachine(sName, sVersion, idMachine, sXMLFile, sXSLFile, sParms)
{
var eMachine, eWarning, fSuccess = true;
cMachines++;
cAsyncMachines++;
Component.addMachine(idMachine);
var doneMachine = function() {
Component.assert(cMachines > 0);
if (!--cMachines) {
Component.assert(cAsyncMachines > 0);
if (!--cAsyncMachines) {
if (fAsync) web.enablePageEvents(true);
}
};
@ -358,7 +359,7 @@ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sParms)
};
try {
eMachine = document.getElementById(idElement);
eMachine = document.getElementById(idMachine);
if (eMachine) {
var sAppClass = sName.toLowerCase(); // eg, "pcjs" or "c1pjs"
if (!sXSLFile) {
@ -380,6 +381,7 @@ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sParms)
displayError(sXML);
return;
}
Component.addMachineResource(idMachine, 'xml', sXML);
/*
* Non-COMPILED kludge to extract the version number from the stylesheet path in the machine XML file;
* we don't need this code in COMPILED (non-DEBUG) releases, because APPVERSION is hard-coded into them.
@ -393,82 +395,75 @@ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sParms)
displayError(sXSL);
return;
}
if (xsl) {
/*
* The <machine> template in components.xsl now generates a "machine div" that makes
* the div we required the caller of embedMachine() to provide redundant, so instead
* of appending this fragment to the caller's node, we REPLACE the caller's node.
* This works only because because we ALSO inject the caller's "machine div" ID into
* the fragment's ID during parseXML().
*
* eMachine.innerHTML = sFragment;
*
* Also, if the transform function fails, make sure you're using the appropriate
* "components.xsl" and not a "machine.xsl", because the latter will not produce valid
* embeddable HTML (and is the most common cause of failure at this final stage).
*/
displayMessage("Processing " + sXMLFile + "...");
/*
* Beginning with Microsoft Edge and the corresponding release of Windows 10, all the
* 'ActiveXObject' crud has gone away; but of course, this code must remain in place if
* we want to continue supporting older Internet Explorer browsers (ie, back to IE9).
*/
if (window.ActiveXObject || 'ActiveXObject' in window) { // second test is required for IE11 on Windows 8.1
var sFragment = xml['transformNode'](xsl);
if (sFragment) {
eMachine.outerHTML = sFragment;
Component.addMachineResource(idMachine, 'xsl', sXSL);
/*
* The <machine> template in components.xsl now generates a "machine div" that makes
* the div we required the caller of embedMachine() to provide redundant, so instead
* of appending this fragment to the caller's node, we REPLACE the caller's node.
* This works only because because we ALSO inject the caller's "machine div" ID into
* the fragment's ID during parseXML().
*
* eMachine.innerHTML = sFragment;
*
* Also, if the transform function fails, make sure you're using the appropriate
* "components.xsl" and not a "machine.xsl", because the latter will not produce valid
* embeddable HTML (and is the most common cause of failure at this final stage).
*/
displayMessage("Processing " + sXMLFile + "...");
/*
* Beginning with Microsoft Edge and the corresponding release of Windows 10, all the
* 'ActiveXObject' crud has gone away; but of course, this code must remain in place if
* we want to continue supporting older Internet Explorer browsers (ie, back to IE9).
*/
if (window.ActiveXObject || 'ActiveXObject' in window) { // second test is required for IE11 on Windows 8.1
var sFragment = xml['transformNode'](xsl);
if (sFragment) {
eMachine.outerHTML = sFragment;
doneMachine();
} else {
displayError("transformNodeToObject failed");
}
}
else if (document.implementation && document.implementation.createDocument) {
var xsltProcessor = new XSLTProcessor();
xsltProcessor['importStylesheet'](xsl);
var eFragment = xsltProcessor['transformToFragment'](xml, document);
if (eFragment) {
/*
* This fails in Microsoft Edge...
*
var machine = eFragment.getElementById(idMachine);
if (!machine) {
displayError("machine generation failed: " + idMachine);
} else
*/
if (eMachine.parentNode) {
eMachine.parentNode.replaceChild(eFragment, eMachine);
doneMachine();
} else {
displayError("transformNodeToObject failed");
}
}
else if (document.implementation && document.implementation.createDocument) {
var xsltProcessor = new XSLTProcessor();
xsltProcessor['importStylesheet'](xsl);
var eFragment = xsltProcessor['transformToFragment'](xml, document);
if (eFragment) {
/*
* This fails in Microsoft Edge...
*
var machine = eFragment.getElementById(idElement);
if (!machine) {
displayError("machine generation failed: " + idElement);
} else
*/
if (eMachine.parentNode) {
eMachine.parentNode.replaceChild(eFragment, eMachine);
doneMachine();
} else {
displayError("invalid machine element: " + idElement);
}
} else {
displayError("transformToFragment failed");
displayError("invalid machine element: " + idMachine);
}
} else {
/*
* Perhaps I should have performed this test at the outset; on the other hand, I'm
* not aware of any browsers don't support one or both of the above XSLT transformation
* methods, so treat this as a bug.
*/
displayError("unable to transform XML: unsupported browser");
displayError("transformToFragment failed");
}
} else {
displayError("failed to load XSL file: " + sXSLFile);
/*
* Perhaps I should have performed this test at the outset; on the other hand, I'm
* not aware of any browsers don't support one or both of the above XSLT transformation
* methods, so treat this as a bug.
*/
displayError("unable to transform XML: unsupported browser");
}
};
if (xml) {
loadXML(sXSLFile, null, null, false, displayMessage, transformXML);
} else {
displayError("failed to load XML file: " + sXMLFile);
}
loadXML(sXSLFile, null, null, false, displayMessage, transformXML);
};
if (sXMLFile.charAt(0) != '<') {
loadXML(sXMLFile, idElement, sParms, true, displayMessage, loadXSL);
loadXML(sXMLFile, idMachine, sParms, true, displayMessage, loadXSL);
} else {
parseXML(sXMLFile, null, idElement, sParms, false, displayMessage, loadXSL);
parseXML(sXMLFile, null, idMachine, sParms, false, displayMessage, loadXSL);
}
} else {
displayError("missing machine element: " + idElement);
displayError("missing machine element: " + idMachine);
}
} catch(e) {
displayError(e.message);
@ -477,32 +472,54 @@ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sParms)
}
/**
* embedC1P(idElement, sXMLFile, sXSLFile)
* embedC1P(idMachine, sXMLFile, sXSLFile)
*
* @param {string} idElement
* @param {string} idMachine
* @param {string} sXMLFile
* @param {string} sXSLFile
* @return {boolean} true if successful, false if error
*/
function embedC1P(idElement, sXMLFile, sXSLFile)
function embedC1P(idMachine, sXMLFile, sXSLFile)
{
if (fAsync) web.enablePageEvents(false);
return embedMachine("C1Pjs", APPVERSION, idElement, sXMLFile, sXSLFile);
return embedMachine("C1Pjs", APPVERSION, idMachine, sXMLFile, sXSLFile);
}
/**
* embedPC(idElement, sXMLFile, sXSLFile, sParms)
* embedPC(idMachine, sXMLFile, sXSLFile, sParms)
*
* @param {string} idElement
* @param {string} idMachine
* @param {string} sXMLFile
* @param {string} sXSLFile
* @param {string} [sParms]
* @return {boolean} true if successful, false if error
*/
function embedPC(idElement, sXMLFile, sXSLFile, sParms)
function embedPC(idMachine, sXMLFile, sXSLFile, sParms)
{
if (fAsync) web.enablePageEvents(false);
return embedMachine("PCjs", APPVERSION, idElement, sXMLFile, sXSLFile, sParms);
return embedMachine("PCjs", APPVERSION, idMachine, sXMLFile, sXSLFile, sParms);
}
/**
* savePC(idMachine)
*
* @param {string} idMachine
* @return {boolean} true if successful, false if error
*/
function savePC(idMachine)
{
var cmp = Component.getComponentByType("Computer", idMachine);
var dbg = Component.getComponentByType("Debugger", idMachine);
if (cmp) {
var sPCJSFile = "/versions/pcjs/" + XMLVERSION + "/pc" + (dbg? "-dbg" : "") + ".js";
var sPCJSCode = web.loadResource(sPCJSFile);
/*
* Next, we need to enumerate the FDC drives and "dump" the disks in them....
*/
return true;
}
web.alertUser("Unable to identify machine '" + idMachine + "'");
return false;
}
/**
@ -511,6 +528,7 @@ function embedPC(idElement, sXMLFile, sXSLFile, sParms)
*/
if (APPNAME == "PCjs") {
window['embedPC'] = embedPC;
window['savePC'] = savePC;
}
if (APPNAME == "C1Pjs") {