1
0
mirror of https://github.com/pkimpel/retro-220.git synced 2026-01-13 15:18:24 +00:00
pkimpel.retro-220/webUI/B220Util.js
Paul Kimpel 936aadf6ee Commit retro-220 emulator version 0.05:
1. Remove Application Cache mechanism (has been deprecated as a web standard).
2. Replace internal bindMethod() utility function with standard Javascript object.bind().
3. Automatically reset Digit Check Alarm when bits are corrected in registers.
4. Correct setting of Overflow Toggle in IFL.
5. Terminate magnetic tape data transfer if AST toggle gets reset.
6. Correct way Processor was released by magnetic tape TCU.
7. Correct construction of preface word in memory for mag tape MRR.
8. Correct determination of mag tape "remote" status to allow tape to be unloaded immediately after a rewind.
9. Fix bug in BCS detecting the switch setting.
10. Modify behavior of Reset/Transfer switch to allow recovery after a tape malfunction.
11. Correct formatting of HIGH lamp on Control Console.
12. Remove extraneous whitespace from B220FramePaper sub-window markup.
2018-01-12 08:40:49 -08:00

156 lines
5.2 KiB
JavaScript

/***********************************************************************
* retro-220/webUI B220Util.js
************************************************************************
* Copyright (c) 2017, Paul Kimpel.
* Licensed under the MIT License, see
* http://www.opensource.org/licenses/mit-license.php
************************************************************************
* Burroughs 220 Emulator common Javascript utilities module.
************************************************************************
* 2017-01-01 P.Kimpel
* Original version, from retro-205 D205Util.js
***********************************************************************/
"use strict";
/**************************************/
function B220Util() {
/* Constructor for the B220Util object */
// Nothing to construct at present...
}
/**************************************/
B220Util.xlateASCIIToAlgolRex = // For translation of 220-ASCII to Algol-ASCII glyphs
/[^\r\n\xA0 $()*+,-./0-9=@A-Za-z]/g;
B220Util.xlateASCIIToAlgolGlyph = {
"#": "=",
"%": "(",
"&": "+",
"<": ")",
"\u00A4": ")"}; // the lozenge (¤)
B220Util.xlateAlgolToASCIIRex = // For translation of Algol-ASCII glyphs to 220-ASCII
/[^\r\n\xA0 #$%&*,-./0-9<@A-Za-z\xA4]/g;
B220Util.xlateAlgolToASCIIGlyph = {
"=": "#",
"(": "%",
"+": "&",
")": "\u00A4"}; // the lozenge (¤)
/**************************************/
B220Util.$$ = function $$(e) {
return document.getElementById(e);
};
/**************************************/
B220Util.hasClass = function hasClass(e, name) {
/* returns true if element "e" has class "name" in its class list */
return e.classList.contains(name);
};
/**************************************/
B220Util.addClass = function addClass(e, name) {
/* Adds a class "name" to the element "e"s class list */
e.classList.add(name);
};
/**************************************/
B220Util.removeClass = function removeClass(e, name) {
/* Removes the class "name" from the element "e"s class list */
e.classList.remove(name);
};
/**************************************/
B220Util.deepCopy = function deepCopy(source, dest) {
/* Performs a deep copy of the object "source" into the object "dest".
If "dest" is null or undefined, simply returns a deep copy of "source".
Note that this routine clones the primitive Javascript types, basic
objects (hash tables), Arrays, Dates, RegExps, and Functions. Other
types may be supported by extending the switch statement. Also note
this is a static function.
Adapted (with thanks) from the "extend" routine by poster Kamarey on 2011-03-26 at
http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-an-object
*/
var constr;
var copy;
var name;
if (source === null) {
return source;
} else if (!(source instanceof Object)) {
return source;
} else {
constr = source.constructor;
if (constr !== Object && constr !== Array) {
return source;
} else {
switch (constr) {
case String:
case Number:
case Boolean:
case Date:
case Function:
case RegExp:
copy = new constr(source);
break;
default:
copy = dest || new constr();
break;
}
for (name in source) {
copy[name] = deepCopy(source[name], null);
}
return copy;
}
}
};
/**************************************/
B220Util.xlateToAlgolChar = function xlateToAlgolChar(c) {
/* Translates one BIC-as-ASCII Algol glyph character to Unicode */
return B220Util.xlateASCIIToAlgolGlyph[c] || "?";
};
/**************************************/
B220Util.xlateASCIIToAlgol = function xlateASCIIToAlgol(text) {
/* Translates the BIC-as-ASCII characters in "text" to equivalent Unicode glyphs */
return text.replace(B220Util.xlateASCIIToAlgolRex, B220Util.xlateToAlgolChar);
};
/**************************************/
B220Util.xlateToASCIIChar = function xlateToASCIIChar(c) {
/* Translates one Unicode Algol glyph to its BIC-as-ASCII equivalent */
return B220Util.xlateAlgolToASCIIGlyph[c] || "?";
};
/**************************************/
B220Util.xlateAlgolToASCII = function xlateAlgolToASCII(text) {
/* Translates the Unicode characters in "text" equivalent BIC-as-ASCII glyphs */
return text.replace(B220Util.xlateAlgolToASCIIRex, B220Util.xlateToASCIIChar);
};
/**************************************/
B220Util.xlateDOMTreeText = function xlateDOMTreeText(n, xlate) {
/* If Node "n" is a text node, translates its value using the "xlate"
function. For all other Node types, translates all subordinate text nodes */
var kid;
if (n.nodeType == Node.TEXT_NODE) {
n.nodeValue = xlate(n.nodeValue);
} else {
kid = n.firstChild;
while (kid) {
xlateDOMTreeText(kid, xlate);
kid = kid.nextSibling;
}
}
};