Fixed command-line interface

This commit is contained in:
Jeff Parsons 2014-11-02 01:22:39 -07:00 • committed by jeffpar
commit 63b0d5829e
15 changed files with 99 additions and 60 deletions

View file

@ -245,12 +245,6 @@ function loadMachine(sFile)
} }
console.log(obj['id'] + " object created"); console.log(obj['id'] + " object created");
if (fDebug) {
/*
* TODO: Determine why a simple "console.log(obj)" call fails on the Video object
*/
console.log(JSON.stringify(obj));
}
aComponents[i].objects.push(obj); aComponents[i].objects.push(obj);
if (obj.type == "Debugger") { if (obj.type == "Debugger") {

View file

@ -38,6 +38,7 @@ if (typeof module !== 'undefined') {
var web = require("../../shared/lib/weblib"); var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component"); var Component = require("../../shared/lib/component");
var State = require("./state"); var State = require("./state");
var Debugger = require("./debugger");
} }
/** /**

View file

@ -74,6 +74,7 @@ if (typeof module !== 'undefined') {
var Component = require("../../shared/lib/component"); var Component = require("../../shared/lib/component");
var Bus = require("./bus"); var Bus = require("./bus");
var State = require("./state"); var State = require("./state");
var Debugger = require("./debugger");
} }
/** /**

View file

@ -36,6 +36,7 @@ if (typeof module !== 'undefined') {
var str = require("../../shared/lib/strlib"); var str = require("../../shared/lib/strlib");
var usr = require("../../shared/lib/usrlib"); var usr = require("../../shared/lib/usrlib");
var Component = require("../../shared/lib/component"); var Component = require("../../shared/lib/component");
var Debugger = require("./debugger");
} }
/** /**

View file

@ -164,6 +164,7 @@ if (typeof module !== 'undefined') {
var DiskAPI = require("../../shared/lib/diskapi"); var DiskAPI = require("../../shared/lib/diskapi");
var DumpAPI = require("../../shared/lib/dumpapi"); var DumpAPI = require("../../shared/lib/dumpapi");
var Component = require("../../shared/lib/component"); var Component = require("../../shared/lib/component");
var Debugger = require("./debugger");
} }
/** /**

View file

@ -41,6 +41,7 @@ if (typeof module !== 'undefined') {
var Disk = require("./disk"); var Disk = require("./disk");
var Computer = require("./computer"); var Computer = require("./computer");
var State = require("./state"); var State = require("./state");
var Debugger = require("./debugger");
} }
/* /*

View file

@ -40,6 +40,7 @@ if (typeof module !== 'undefined') {
var ChipSet = require("./chipset"); var ChipSet = require("./chipset");
var Disk = require("./disk"); var Disk = require("./disk");
var State = require("./state"); var State = require("./state");
var Debugger = require("./debugger");
} }
/** /**
@ -2430,22 +2431,26 @@ HDC.prototype.readByte = function(drive, done, fAutoInc)
*/ */
if (done) { if (done) {
var hdc = this; var hdc = this;
drive.disk.seek(drive.wCylinder, drive.bHead, drive.bSector + drive.bSectorBias, false, function(sector, fAsync) { if (drive.disk) {
var b = -1; drive.disk.seek(drive.wCylinder, drive.bHead, drive.bSector + drive.bSectorBias, false, function(sector, fAsync) {
if ((drive.sector = sector)) { if ((drive.sector = sector)) {
drive.ibSector = 0; drive.ibSector = 0;
/* /*
* We "pre-advance" bSector et al now, instead of waiting to advance it right before the seek(). * We "pre-advance" bSector et al now, instead of waiting to advance it right before the seek().
* This allows the initial call to readByte() to perform a seek without triggering an unwanted advance. * This allows the initial call to readByte() to perform a seek without triggering an unwanted advance.
*/ */
hdc.advanceSector(drive); hdc.advanceSector(drive);
b = drive.disk.read(drive.sector, drive.ibSector); b = drive.disk.read(drive.sector, drive.ibSector);
drive.ibSector += inc; drive.ibSector += inc;
} else { } else {
drive.errorCode = HDC.XTC.DATA.ERR.NO_SECTOR; drive.errorCode = HDC.XTC.DATA.ERR.NO_SECTOR;
} }
done(b, fAsync); done(b, fAsync);
}); });
return b;
}
drive.errorCode = HDC.XTC.DATA.ERR.NO_SECTOR;
done(b, false);
} }
return b; return b;
}; };
@ -2487,9 +2492,11 @@ HDC.prototype.writeByte = function(drive, b)
* hence the bSectorBias below. I could change how sector numbers are stored in the image, * hence the bSectorBias below. I could change how sector numbers are stored in the image,
* but it seems preferable to keep the image format consistent and controller-independent. * but it seems preferable to keep the image format consistent and controller-independent.
*/ */
drive.disk.seek(drive.wCylinder, drive.bHead, drive.bSector + drive.bSectorBias, true, function(sector, fAsync) { if (drive.disk) {
drive.sector = sector; drive.disk.seek(drive.wCylinder, drive.bHead, drive.bSector + drive.bSectorBias, true, function(sector, fAsync) {
}); drive.sector = sector;
});
}
if (!drive.sector) { if (!drive.sector) {
drive.errorCode = HDC.XTC.DATA.ERR.NO_SECTOR; drive.errorCode = HDC.XTC.DATA.ERR.NO_SECTOR;
b = -1; b = -1;

View file

@ -39,6 +39,7 @@ if (typeof module !== 'undefined') {
var ChipSet = require("./chipset"); var ChipSet = require("./chipset");
var State = require("./state"); var State = require("./state");
var CPU = require("./cpu"); var CPU = require("./cpu");
var Debugger = require("./debugger");
} }
/** /**

View file

@ -51,6 +51,7 @@
if (typeof module !== 'undefined') { if (typeof module !== 'undefined') {
var str = require("../../shared/lib/strlib"); var str = require("../../shared/lib/strlib");
var Component = require("../../shared/lib/component"); var Component = require("../../shared/lib/component");
var Debugger = require("./debugger");
} }
/** /**
* @class DataView * @class DataView

View file

@ -38,6 +38,7 @@ if (typeof module !== 'undefined') {
var Component = require("../../shared/lib/component"); var Component = require("../../shared/lib/component");
var SerialPort = require("./serial"); var SerialPort = require("./serial");
var State = require("./state"); var State = require("./state");
var Debugger = require("./debugger");
} }
/** /**

View file

@ -36,6 +36,7 @@ if (typeof module !== 'undefined') {
var web = require("../../shared/lib/weblib"); var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component"); var Component = require("../../shared/lib/component");
var ChipSet = require("./chipset"); var ChipSet = require("./chipset");
var Debugger = require("./debugger");
var State = require("./state"); var State = require("./state");
} }

View file

@ -102,6 +102,7 @@ if (typeof module !== 'undefined') {
var ChipSet = require("./chipset"); var ChipSet = require("./chipset");
var Keyboard = require("./keyboard"); var Keyboard = require("./keyboard");
var State = require("./state"); var State = require("./state");
var Debugger = require("./debugger");
} }
/** /**

View file

@ -46,6 +46,7 @@ if (typeof module !== 'undefined') {
var X86Mods = require("./x86mods"); var X86Mods = require("./x86mods");
var X86OpXX = require("./x86opxx"); var X86OpXX = require("./x86opxx");
var X86Op0F = require("./x86op0f"); var X86Op0F = require("./x86op0f");
var Debugger = require("./debugger");
} }
/** /**

View file

@ -67,7 +67,7 @@ function X86Seg(cpu, sName, fProt)
/** /**
* loadReal(sel, fSuppress) * loadReal(sel, fSuppress)
* *
* This is the default real-mode load() function. * The default segment load() function for real-mode.
* *
* @this {X86Seg} * @this {X86Seg}
* @param {number} sel * @param {number} sel
@ -77,7 +77,7 @@ function X86Seg(cpu, sName, fProt)
X86Seg.loadReal = function loadReal(sel, fSuppress) X86Seg.loadReal = function loadReal(sel, fSuppress)
{ {
this.sel = sel; this.sel = sel;
this.limit = 0xffff; // TODO: Consider NOT setting the limit field in real-mode (unless it's required for, say, LOADALL support?) this.limit = 0xffff;
this.cpl = this.dpl = 0; this.cpl = this.dpl = 0;
return this.base = sel << 4; return this.base = sel << 4;
}; };
@ -85,8 +85,8 @@ X86Seg.loadReal = function loadReal(sel, fSuppress)
/** /**
* loadProt(sel, fSuppress) * loadProt(sel, fSuppress)
* *
* This replaces the segment's default load() function whenever the segment is notified (eg, by the CPU's setProtMode() * This replaces the segment's default load() function whenever the segment is notified via updateAccess() by the
* function) the processor is now in protected-mode. * CPU's setProtMode() that the processor is now in protected-mode.
* *
* Segments in protected-mode are referenced by selectors, which are indexes into descriptor tables (GDT, LDT, IDT) whose * Segments in protected-mode are referenced by selectors, which are indexes into descriptor tables (GDT, LDT, IDT) whose
* descriptors are 4-word (8-byte) entries: * descriptors are 4-word (8-byte) entries:

View file

@ -118,14 +118,6 @@
/* global window: true, setTimeout: false, clearTimeout: false, SITEHOST: false */ /* global window: true, setTimeout: false, clearTimeout: false, SITEHOST: false */
/*
* We must defer loading the Component module until the function(s) requiring it are
* called; otherwise, we create an initialization cycle in which Component requires weblib
* and weblib requires Component.
*
* In an ideal world, weblib would not be dependent on Component, but we really want to use
* its logging functions.
*/
if (typeof module !== 'undefined') { if (typeof module !== 'undefined') {
var Component; var Component;
require("./defines"); require("./defines");
@ -135,6 +127,49 @@ if (typeof module !== 'undefined') {
var web = {}; var web = {};
/*
* We must defer loading the Component module until the function(s) requiring it are
* called; otherwise, we create an initialization cycle in which Component requires weblib
* and weblib requires Component.
*
* In an ideal world, weblib would not be dependent on Component, but we really want to use
* its I/O functions. The simplest solution is to create wrapper functions.
*/
/**
* log(s, type)
*
* For diagnostic output only. DEBUG must be true (or "--debug" specified via the command-line)
* for Component.log() to display anything.
*
* @param {string} [s] is the message text
* @param {string} [type] is the message type
*/
web.log = function(s, type)
{
if (typeof module !== 'undefined') {
if (!Component) Component = require("./component");
}
Component.log(s, type);
};
/**
* notice(s, fPrintOnly, id)
*
* If Component.notice() calls web.alertUser(), it will fall back to web.log() if all else fails.
*
* @param {string} s is the message text
* @param {boolean} [fPrintOnly]
* @param {string} [id] is the caller's ID, if any
*/
web.notice = function(s, fPrintOnly, id)
{
if (typeof module !== 'undefined') {
if (!Component) Component = require("./component");
}
Component.notice(s, fPrintOnly, id);
};
/** /**
* loadResource(sURL, fAsync, data, componentNotify, fnNotify, pNotify) * loadResource(sURL, fAsync, data, componentNotify, fnNotify, pNotify)
* *
@ -188,11 +223,11 @@ web.loadResource = function(sURL, fAsync, data, componentNotify, fnNotify, pNoti
* from the local file system (ie, when using the "file:" protocol), we have to be a bit more "flexible". * 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:") { if (xmlHTTP.status == 200 || !xmlHTTP.status && sURLData.length && web.getHostProtocol() == "file:") {
Component.log("xmlHTTP.onreadystatechange(" + sURL + "): returned " + sURLData.length + " bytes"); web.log("xmlHTTP.onreadystatechange(" + sURL + "): returned " + sURLData.length + " bytes");
} }
else { else {
nErrorCode = xmlHTTP.status || -1; nErrorCode = xmlHTTP.status || -1;
Component.log("xmlHTTP.onreadystatechange(" + sURL + "): error code " + nErrorCode); web.log("xmlHTTP.onreadystatechange(" + sURL + "): error code " + nErrorCode);
} }
if (fnNotify) { if (fnNotify) {
if (!componentNotify) { if (!componentNotify) {
@ -212,12 +247,12 @@ web.loadResource = function(sURL, fAsync, data, componentNotify, fnNotify, pNoti
sData += p + '=' + encodeURIComponent(data[p]); sData += p + '=' + encodeURIComponent(data[p]);
} }
sData = sData.replace(/%20/g, '+'); sData = sData.replace(/%20/g, '+');
Component.log("web.loadResource(POST " + sURL + "): " + sData.length + " bytes"); web.log("web.loadResource(POST " + sURL + "): " + sData.length + " bytes");
xmlHTTP.open("POST", sURL, fAsync); xmlHTTP.open("POST", sURL, fAsync);
xmlHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHTTP.send(sData); xmlHTTP.send(sData);
} else { } else {
Component.log("web.loadResource(GET " + sURL + ")"); web.log("web.loadResource(GET " + sURL + ")");
xmlHTTP.open("GET", sURL, fAsync); xmlHTTP.open("GET", sURL, fAsync);
xmlHTTP.send(); xmlHTTP.send();
} }
@ -225,10 +260,10 @@ web.loadResource = function(sURL, fAsync, data, componentNotify, fnNotify, pNoti
if (!fAsync) { if (!fAsync) {
sURLData = xmlHTTP.responseText; sURLData = xmlHTTP.responseText;
if (xmlHTTP.status == 200) { if (xmlHTTP.status == 200) {
Component.log("web.loadResource(" + sURL + "): returned " + sURLData.length + " bytes"); web.log("web.loadResource(" + sURL + "): returned " + sURLData.length + " bytes");
} else { } else {
nErrorCode = xmlHTTP.status || -1; nErrorCode = xmlHTTP.status || -1;
Component.log("web.loadResource(" + sURL + "): error code " + nErrorCode); web.log("web.loadResource(" + sURL + "): error code " + nErrorCode);
} }
if (fnNotify) { if (fnNotify) {
if (!componentNotify) { if (!componentNotify) {
@ -315,11 +350,7 @@ web.getUserAgent = function()
*/ */
web.alertUser = function(sMessage) web.alertUser = function(sMessage)
{ {
if (window) { if (window) window.alert(sMessage); else web.log(sMessage);
window.alert(sMessage);
} else {
console.log(sMessage);
}
}; };
/** /**
@ -393,7 +424,7 @@ web.hasLocalStorage = function() {
*/ */
web.logLocalStorageError = function(e) web.logLocalStorageError = function(e)
{ {
Component.log(e.message, "localStorage error"); web.log(e.message, "localStorage error");
}; };
/** /**
@ -504,13 +535,9 @@ web.isUserAgent = function(s)
{ {
if (window) { if (window) {
var userAgent = web.getUserAgent(); var userAgent = web.getUserAgent();
web.log("agent: " + userAgent);
/* /*
* Here's one case where we have to be careful with Component, because when isUserAgent() is called by * Yes, it would be pointless to use the conditional (?) operator below, if not for the Google Closure
* the init code below, component.js hasn't been loaded yet. The simplest solution is to remove the call.
*
* if (Component) Component.log("agent: " + userAgent);
*
* And yes, it would be pointless to use the conditional (?) operator below, if not for the Google Closure
* Compiler (v20130823) failing to detect the entire expression as a boolean. * Compiler (v20130823) failing to detect the entire expression as a boolean.
*/ */
return (s == "iOS" && userAgent.match(/(iPod|iPhone|iPad)/) && userAgent.match(/AppleWebKit/) || s == "MSIE" && userAgent.match(/(MSIE|Trident)/) || (userAgent.indexOf(s) >= 0))? true : false; return (s == "iOS" && userAgent.match(/(iPod|iPhone|iPad)/) && userAgent.match(/AppleWebKit/) || s == "MSIE" && userAgent.match(/(MSIE|Trident)/) || (userAgent.indexOf(s) >= 0))? true : false;
@ -596,7 +623,7 @@ web.onClickRepeat = function(e, msDelay, msRepeat, fn)
} }
}; };
e.onmousedown = function() { e.onmousedown = function() {
// Component.println("onMouseDown()"); // web.log("onMouseDown()");
if (!fIgnoreMouseEvents) { if (!fIgnoreMouseEvents) {
if (!timer) { if (!timer) {
ms = msDelay; ms = msDelay;
@ -605,21 +632,21 @@ web.onClickRepeat = function(e, msDelay, msRepeat, fn)
} }
}; };
e.ontouchstart = function() { e.ontouchstart = function() {
// Component.println("onTouchStart()"); // web.log("onTouchStart()");
if (!timer) { if (!timer) {
ms = msDelay; ms = msDelay;
fnRepeat(); fnRepeat();
} }
}; };
e.onmouseup = e.onmouseout = function() { e.onmouseup = e.onmouseout = function() {
// Component.println("onMouseUp()/onMouseOut()"); // web.log("onMouseUp()/onMouseOut()");
if (timer) { if (timer) {
clearTimeout(timer); clearTimeout(timer);
timer = null; timer = null;
} }
}; };
e.ontouchend = e.ontouchcancel = function() { e.ontouchend = e.ontouchcancel = function() {
// Component.println("onTouchEnd()/onTouchCancel()"); // web.log("onTouchEnd()/onTouchCancel()");
if (timer) { if (timer) {
clearTimeout(timer); clearTimeout(timer);
timer = null; timer = null;
@ -722,7 +749,7 @@ web.doPageEvent = function(afn)
afn[i](); afn[i]();
} }
} catch(e) { } catch(e) {
Component.notice("An unexpected exception occurred:\n\n" + e.message + "\n\nPlease send this information to Jeff@pcjs.org. Thanks."); web.notice("An unexpected exception occurred:\n\n" + e.message + "\n\nPlease send this information to Jeff@pcjs.org. Thanks.");
} }
} }
}; };