Demonstration of C1Pjs loading and running *without* a web server

file:///pcjs/configs/c1p/machines/8kb/large/debugger/demo.html (your root directory may vary)
This commit is contained in:
Jeff Parsons 2014-10-29 16:41:32 -07:00 committed by jeffpar
commit f2e092e57c
10 changed files with 408 additions and 317 deletions

View file

@ -63,13 +63,13 @@ function C1PROM(parmsROM)
* we ask our server-side ROM image converter to return the corresponding JSON-encoded data,
* in compact form (ie, minimal whitespace, no ASCII data comments, etc).
*/
var sFileExt = str.getExtension(this.sImage);
var sFileExt = str.getExtension(this.sImage);
if (sFileExt != "json" && sFileExt != "hex") {
/**
* TODO: This code was using a deprecated parameter (compact=1); make sure things still work.
*
*
* TODO: Convert this code to use the new shared File API definitions and weblib functions; eg:
*
*
* sFileURL = web.getHost() + DumpAPI.ENDPOINT + "?" + DumpAPI.QUERY.FILE + "=" + this.sImage;
*/
sFileURL = "http://" + window.location.host + "/api/v1/dump?file=" + this.sImage;
@ -154,7 +154,7 @@ C1PROM.prototype.setByte = function(addr, addrFrom)
C1PROM.prototype.convertImage = function(sImageName, sImageData, nErrorCode)
{
if (nErrorCode) {
this.println("ROM load error (" + nErrorCode + ")");
this.println("Error loading ROM \"" + sImageName + "\" (" + nErrorCode + ")");
return;
}
if (sImageData[0] == "[") {
@ -168,7 +168,7 @@ C1PROM.prototype.convertImage = function(sImageName, sImageData, nErrorCode)
//
// System exceptions throw an object with a message property, whereas exceptions I throw myself do not (they're just strings)
//
this.println("ROM data error: " + (e.message || e));
this.println("Error processing ROM \"" + sImageName + "\": " + (e.message || e));
return;
}
}
@ -192,7 +192,7 @@ C1PROM.prototype.convertImage = function(sImageName, sImageData, nErrorCode)
C1PROM.prototype.copyImage = function()
{
/*
* The Computer object may give us the address of the ROM image before we've finished downloading the image,
* The Computer object may give us the address of the ROM image before we've finished downloading the image,
* so both setBuffer() and convertImage() call copyImage(), which in turn will copy the image ONLY when both
* pieces are in place. At that point, the component becomes "ready", in much the same way that other components
* (eg, CPU and Screen) become "ready" when all their prerequisites are satisfied.

View file

@ -180,10 +180,14 @@ web.loadResource = function(sURL, fAsync, data, componentNotify, fnNotify, pNoti
* pending, any debugging activity means most of them simply get dropped on floor, so what may actually be
* happening are mis-notifications rather than redundant notifications.
*
xmlHTTP.onreadystatechange = undefined;
* xmlHTTP.onreadystatechange = undefined;
*/
sURLData = xmlHTTP.responseText;
if (xmlHTTP.status == 200) {
/*
* The normal "success" case is an HTTP status code of 200, but when testing with files loaded
* from the local file system (ie, when using the "file:" protocol), we have to be a bit more "flexible".
*/
if (xmlHTTP.status == 200 || !xmlHTTP.status && sURLData.length && web.getHostProtocol() == "file:") {
Component.log("xmlHTTP.onreadystatechange(" + sURL + "): returned " + sURLData.length + " bytes");
}
else {
@ -284,6 +288,16 @@ web.getHostURL = function()
return (window? window.location.href : null);
};
/**
* getHostProtocol()
*
* @return {string}
*/
web.getHostProtocol = function()
{
return (window? window.location.protocol : "file:");
};
/**
* getUserAgent()
*