1
0
mirror of https://github.com/pkimpel/retro-b5500.git synced 2026-02-14 20:16:18 +00:00
Files
pkimpel.retro-b5500/webUI/B5500Util.js
paul.kimpel@digm.com 8b0d19deba Release emulator version 1.00:
1. Implement new system and disk subsystem configuration mechanism.
2. Implement initial Mark-XIII Cold Start card deck for use with new configuration interfaces.
3. Deprecate use of B5500ColdLoader.html script (replaced by new configuration mechanism and Cold Start deck), but correct and enhance IndexedDB database detection, creation, and deletion in it.
4. Implement "Application Cache" support to allow emulator to run off-line in a browser.
5. Implement web-font support and update all UIs to use DejaVu Sans and DejaVu Sans Mono from downloaded .woff or .ttf font files.
6. Rework some code in Processor OPDC, DESC, and indexDescriptor routines, attempting to resolve Flag Bit errors (issue #23). This appears to result in some improvement, but we still see them occasionally under load.
7. Line Printer:
    - Implement new line printer driver with more realistic UI and operator controls.
    - Implement Algol Glyphs option to render special Algol characters in Unicode.
    - Implement support for optional "greenbar" shading on the "paper".
8. SPO:
    - Redesign SPO driver to accept input from a text <input> element instead of capturing keystrokes directly from the window or "paper" <iframe>. This was done to allow input from tablet and mobile devices that will not pop up a keyboard unless an input-like element has the focus.
    - Implement Unicode Algol Glyphs support on output.
    - Intelligently resize "paper" area when SPO window is resized.
    - Accept "_" as a substitute for "~" as end-of-message on input.
9. Card Punch:
    - Implement Unicode Algol Glyphs support on output.
    - Implement stacker-full annunciators in UI.
10. Card Reader:
    - Implement Unicode Algol Glyphs support on input.
    - Accept "_" as a substitute for "~" on input.
11. Disk:
    - Adapt B5500DiskUnit driver to new configuration mechanism.
    - Implement support for Model-IB (slow) disk and non-DFX disk storage configurations; support up to 20 EUs.
    - Implement check for DKA readiness in cc.load() if not doing card-load-select.
12. Datacom:
    - Rework datacom driver keystroke handling for compatibility with Google Chrome.
    - Correct typo (line 437) in B5500DatacomUnit reported by Peter Grootswagers (issue #28).
13. Magnetic Tape:    
    - Implement more granular tape reel animation in B5500MagTapeDrive.
    - Open the tape loader window on top of its device window.
14. Correct color of NOT READY lamps in peripheral device UIs; convert <progress> bars to <meter> elements.
15. More intelligently resize peripheral UI controls when their window is resized.
16. Implement lamp test during power-on in B5500Console.
17. Illuminate NOT READY light on Console at power-on if certain minimum configuration requirements are not met.
18. Set all HTML <meta> Content-Type character sets to UTF-8 (were ISO-8859-1); correct problem with FireFox requiring the character set to be specified within the first 1024 characters of an HTML file.
19. Clean up and refactor CSS style sheets
20. Split Javascript code out from B5500Console.html to new B5500Console.js.
21. Refactor common UI routines into webUI\B5500Util.js.
22. Move images and fonts to new webUI/resources directory; rearrange files in webUI/tool, tools, tests, source directories of repo.
23. Make significant wiki updates to document the new features in this release.
2014-09-29 15:28:56 +00:00

190 lines
6.8 KiB
JavaScript

/***********************************************************************
* retro-b5500/emulator B5500Util.js
************************************************************************
* Copyright (c) 2012-2014, Nigel Williams and Paul Kimpel.
* Licensed under the MIT License, see
* http://www.opensource.org/licenses/mit-license.php
************************************************************************
* B5500 emulator common Javascript utilities module.
************************************************************************
* 2014-07-26 P.Kimpel
* Original version, from various existing scripts.
***********************************************************************/
"use strict";
/**************************************/
function B5500Util() {
/* Constructor for the B5500Util object */
// Nothing to construct at present...
}
/**************************************/
B5500Util.xlateASCIIToAlgolRex = // For translation of BIC-as-ASCII to Unicode Algol glyphs
/[^\r\n\xA0 "#$%&()*+,\-./0-9:;<=>?@A-Z\[\]a-z\u00D7\u2190\u2260\u2264\u2265]/g;
B5500Util.xlateASCIIToAlgolGlyph = {
"!": "\u2260", // not-equal
"_": "\u2190", // Sid McHarg's left-arrow
"{": "\u2264", // less-than-or-equal
"|": "\u00D7", // multiply (x)
"}": "\u2265", // greater-than-or-equal
"~": "\u2190"}; // left-arrow
B5500Util.xlateAlgolToASCIIRex = // For translation of Unicode Algol glyphs to BIC-as-ASCII
/[^\r\n\xA0 !"#$%&()*+,\-./0-9:;<=>?@A-Z\[\]a-z{|}~]/g;
B5500Util.xlateAlgolToASCIIGlyph = {
"_": "~", // Sid McHarg's left-arrow
"\u00D7": "|", // multiply (x)
"\u2190": "~", // left-arrow
"\u2260": "!", // not-equal
"\u2264": "{", // less-than-or-equal
"\u2265": "}"}; // greater-than-or-equal
/**************************************/
B5500Util.$$ = function $$(e) {
return document.getElementById(e);
};
/**************************************/
B5500Util.hasClass = function hasClass(e, name) {
/* returns true if element "e" has class "name" in its class list */
var classes = e.className;
if (!e) {
return false;
} else if (classes == name) {
return true;
} else {
return (classes.search("\\b" + name + "\\b") >= 0);
}
};
/**************************************/
B5500Util.addClass = function addClass(e, name) {
/* Adds a class "name" to the element "e"s class list */
if (!B5500Util.hasClass(e, name)) {
e.className += (" " + name);
}
};
/**************************************/
B5500Util.removeClass = function removeClass(e, name) {
/* Removes the class "name" from the element "e"s class list */
e.className = e.className.replace(new RegExp("\\b" + name + "\\b\\s*", "g"), "");
};
/**************************************/
B5500Util.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;
}
}
/********************************
// Original version:
// extends 'from' object with members from 'to'. If 'to' is null, a deep clone of 'from' is returned
function extend(from, to)
{
if (from == null || typeof from != "object") return from;
if (from.constructor != Object && from.constructor != Array) return from;
if (from.constructor == Date || from.constructor == RegExp || from.constructor == Function ||
from.constructor == String || from.constructor == Number || from.constructor == Boolean)
return new from.constructor(from);
to = to || new from.constructor();
for (var name in from)
{
to[name] = typeof to[name] == "undefined" ? extend(from[name], null) : to[name];
}
return to;
}
********************************/
};
/**************************************/
B5500Util.xlateToAlgolChar = function xlateToAlgolChar(c) {
/* Translates one BIC-as-ASCII Algol glyph character to Unicode */
return B5500Util.xlateASCIIToAlgolGlyph[c] || "?";
};
/**************************************/
B5500Util.xlateASCIIToAlgol = function xlateASCIIToAlgol(text) {
/* Translates the BIC-as-ASCII characters in "text" to equivalent Unicode glyphs */
return text.replace(B5500Util.xlateASCIIToAlgolRex, B5500Util.xlateToAlgolChar);
};
/**************************************/
B5500Util.xlateToASCIIChar = function xlateToASCIIChar(c) {
/* Translates one Unicode Algol glyph to its BIC-as-ASCII equivalent */
return B5500Util.xlateAlgolToASCIIGlyph[c] || "?";
};
/**************************************/
B5500Util.xlateAlgolToASCII = function xlateAlgolToASCII(text) {
/* Translates the Unicode characters in "text" equivalent BIC-as-ASCII glyphs */
return text.replace(B5500Util.xlateAlgolToASCIIRex, B5500Util.xlateToASCIIChar);
};
/**************************************/
B5500Util.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;
}
}
};