Picked up all the last-minute changes from the gh-pages branch (where I discovered a race condition between machines)

This commit is contained in:
Jeff Parsons 2016-08-19 13:03:30 -07:00
commit 23e78b971c
11 changed files with 965 additions and 946 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -133,9 +133,10 @@ function SerialPort8080(parmsSerial) {
this.connection = this.sendData = null;
/*
* Export all functions required by initConnection(); currently, this is the bare minimum, with no flow control.
* Export all functions required by initConnection(); currently, this is the bare minimum (no flow control yet).
*/
this['exports'] = {
'connect': this.initConnection,
'receiveData': this.receiveData
};
}
@ -421,13 +422,18 @@ SerialPort8080.prototype.initBus = function(cmp, bus, cpu, dbg)
* receiveData(data): called when we have data to transmit; aliased internally to sendData(data)
*
* For now, we're not going to worry about communication in the other direction, because when the target component
* performs its own initConnection(), it will find our receiveByte(b) function, at which point communication in both
* performs its own initConnection(), it will find our receiveData() function, at which point communication in both
* directions should be established.
*
* For added robustness, if the target machine initializes much more slowly than we do, and our connection attempt
* fails, that's OK, because when it finally initializes, its initConnection() will call our initConnection();
* if we've already initialized, no harm done.
*
* @this {SerialPort8080}
*/
SerialPort8080.prototype.initConnection = function()
{
if (!this.connection) {
var sConnection = this.cmp.getMachineParm("connection");
if (sConnection) {
var asParts = sConnection.split('->');
@ -439,13 +445,21 @@ SerialPort8080.prototype.initConnection = function()
if (this.connection) {
var exports = this.connection['exports'];
if (exports) {
var fnConnect = exports['connect'];
if (fnConnect) fnConnect.call(this.connection);
this.sendData = exports['receiveData'];
if (this.sendData) {
this.status(this.idMachine + '.' + sSourceID + " connected to " + sTargetID);
return;
}
}
}
this.notice("Unable to establish connection: " + sConnection);
}
/*
* Changed from notice() to status() because sometimes a connection fails simply because one of us is a laggard.
*/
this.status("Unable to establish connection: " + sConnection);
}
}
};
@ -462,11 +476,10 @@ SerialPort8080.prototype.powerUp = function(data, fRepower)
if (!fRepower) {
/*
* We needed to wait until now to make our first inter-machine connection attempt;
* doing this in initBus() was still too early, because initBus() is called in the context
* of onInit() processing for all machines of the same type (eg, PCx86), and if we're
* trying to connect to the port of a machine of a DIFFERENT type (eg, PC8080), it may not
* have been initialized yet.
* This is as late as we can currently wait to make our first inter-machine connection attempt;
* even so, the target machine's initialization process may still be ongoing, so any connection
* may be not fully resolved until the target machine performs its own initConnection(), which will
* in turn invoke our initConnection() again.
*/
this.initConnection();

View file

@ -143,9 +143,10 @@ function SerialPort(parmsSerial) {
this.connection = this.sendData = null;
/*
* Export all functions required by initConnection(); currently, this is the bare minimum, with no flow control.
* Export all functions required by initConnection(); currently, this is the bare minimum (no flow control yet).
*/
this['exports'] = {
'connect': this.initConnection,
'receiveData': this.receiveData
};
}
@ -482,13 +483,18 @@ SerialPort.prototype.initBus = function(cmp, bus, cpu, dbg)
* receiveData(data): called when we have data to transmit; aliased internally to sendData(data)
*
* For now, we're not going to worry about communication in the other direction, because when the target component
* performs its own initConnection(), it will find our receiveByte(b) function, at which point communication in both
* performs its own initConnection(), it will find our receiveData() function, at which point communication in both
* directions should be established.
*
* For added robustness, if the target machine initializes much more slowly than we do, and our connection attempt
* fails, that's OK, because when it finally initializes, its initConnection() will call our initConnection();
* if we've already initialized, no harm done.
*
* @this {SerialPort}
*/
SerialPort.prototype.initConnection = function()
{
if (!this.connection) {
var sConnection = this.cmp.getMachineParm("connection");
if (sConnection) {
var asParts = sConnection.split('->');
@ -500,13 +506,21 @@ SerialPort.prototype.initConnection = function()
if (this.connection) {
var exports = this.connection['exports'];
if (exports) {
var fnConnect = exports['connect'];
if (fnConnect) fnConnect.call(this.connection);
this.sendData = exports['receiveData'];
if (this.sendData) {
this.status(this.idMachine + '.' + sSourceID + " connected to " + sTargetID);
return;
}
}
}
this.notice("Unable to establish connection: " + sConnection);
}
/*
* Changed from notice() to status() because sometimes a connection fails simply because one of us is a laggard.
*/
this.status("Unable to establish connection: " + sConnection);
}
}
};
@ -523,11 +537,10 @@ SerialPort.prototype.powerUp = function(data, fRepower)
if (!fRepower) {
/*
* We needed to wait until now to make our first inter-machine connection attempt;
* doing this in initBus() was still too early, because initBus() is called in the context
* of onInit() processing for all machines of the same type (eg, PCx86), and if we're
* trying to connect to the port of a machine of a DIFFERENT type (eg, PC8080), it may not
* have been initialized yet.
* This is as late as we can currently wait to make our first inter-machine connection attempt;
* even so, the target machine's initialization process may still be ongoing, so any connection
* may be not fully resolved until the target machine performs its own initConnection(), which will
* in turn invoke our initConnection() again.
*/
this.initConnection();

View file

@ -226,17 +226,9 @@ Component.subclass = function(subclass, superclass, methods, statics)
* various resources used by that machine.
*/
if (window) {
if (!window['PCjs']) {
window['PCjs'] = {
'Machines': {},
'Components': []
};
}
/*
* Alias the new global objects above to their original property names, to minimize code changes.
*/
Component.machines = window['PCjs']['Machines'];
Component.components = window['PCjs']['Components'];
if (!window['PCjs']) window['PCjs'] = {};
Component.machines = window['PCjs']['Machines'] || (window['PCjs']['Machines'] = {});
Component.components = window['PCjs']['Components'] || (window['PCjs']['Components'] = []);
}
else {
/*

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long