Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit

Permalink
Started refactoring some of the Device classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpar committed Jun 26, 2018
1 parent 64d0197 commit a3c7da6
Show file tree
Hide file tree
Showing 33 changed files with 1,636 additions and 1,400 deletions.
2 changes: 2 additions & 0 deletions _data/machines.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"folder": "devices",
"creator": "new LEDs",
"scripts": [
"./modules/devices/lib/stdio.js",
"./modules/devices/device.js",
"./modules/devices/input.js",
"./modules/devices/led.js",
Expand Down Expand Up @@ -314,6 +315,7 @@
"folder": "devices",
"creator": "new TMS1500",
"scripts": [
"./modules/devices/lib/stdio.js",
"./modules/devices/device.js",
"./modules/devices/input.js",
"./modules/devices/led.js",
Expand Down
12 changes: 12 additions & 0 deletions devices/dec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
layout: page
title: Miscellaneous DEC Devices
permalink: /devices/dec/
---

Miscellaneous DEC Devices
-------------------------

This directory contains miscellaneous devices from Digital Equipment Corp.

* [DEC ROMs](rom/)
2 changes: 1 addition & 1 deletion devices/roms/dec/README.md → devices/dec/rom/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: page
title: DEC ROMs
permalink: /devices/roms/dec/
permalink: /devices/dec/rom/
---

Digital Equipment Corp. (DEC) ROMs
Expand Down
2 changes: 1 addition & 1 deletion devices/pc8080/rom/vt100/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ He then describes the memory map as follows:
E52 H H L 0x0800
E56 H L L 0x0000

The above PCB chip locations correspond to the following [DEC ROMs](/devices/roms/dec/):
The above PCB chip locations correspond to the following [DEC ROMs](/devices/dec/rom/):

* E56: [23-061E2.bin](https://web.archive.org/web/20140723115846/http://www.dunnington.u-net.com/public/DECROMs/23-061E2.bin)
* E52: [23-032E2.bin](https://web.archive.org/web/20140723115846/http://www.dunnington.u-net.com/public/DECROMs/23-032E2.bin)
Expand Down
12 changes: 0 additions & 12 deletions devices/roms/README.md

This file was deleted.

1 change: 1 addition & 0 deletions modules/devices/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"Machine": true,
"MACHINE": true,
"ROM": true,
"StdIO": true,
"Time": true,
"VERSION": true
}
Expand Down
207 changes: 49 additions & 158 deletions modules/devices/README.md

Large diffs are not rendered by default.

191 changes: 21 additions & 170 deletions modules/devices/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var VERSION = "";
* @property {Object} bindings [added by addBindings()]
* @property {string} sCommandPrev
*/
class Device {
class Device extends StdIO {
/**
* Device()
*
Expand Down Expand Up @@ -97,6 +97,7 @@ class Device {
*/
constructor(idMachine, idDevice, version, config)
{
super();
this.config = config || {};
this.idMachine = idMachine;
this.idDevice = idDevice;
Expand Down Expand Up @@ -707,13 +708,15 @@ class Device {
{
let nErrorCode = 0, sResource = null;

if (DEBUG) {
if (this.getHost() == "pcjs:8088") {
/*
* The larger resources we put on archive.pcjs.org should also be available locally.
* The larger resources that I've put on archive.pcjs.org are assumed to also be available locally
* whenever the hostname is "pcjs"; otherwise, use "localhost" when debugging locally.
*
* NOTE: "http://archive.pcjs.org" is now "https://s3-us-west-2.amazonaws.com/archive.pcjs.org"
* NOTE: http://archive.pcjs.org is currently redirected to https://s3-us-west-2.amazonaws.com/archive.pcjs.org
*/
sURL = sURL.replace(/^(http:\/\/archive\.pcjs\.org|https:\/\/s3-us-west-2\.amazonaws\.com\/archive\.pcjs\.org)(\/.*)\/([^/]*)$/, "$2/archive/$3");
sURL = sURL.replace(/^(http:\/\/archive\.pcjs\.org|https:\/\/[a-z0-9-]+\.amazonaws\.com\/archive\.pcjs\.org)(\/.*)\/([^/]*)$/, "$2/archive/$3");
sURL = sURL.replace(/^https:\/\/jeffpar\.github\.io\/(pcjs-[a-z]+|private-[a-z]+)\/(.*)$/, "/$1/$2");
}

let device = this;
Expand Down Expand Up @@ -904,53 +907,21 @@ class Device {
*/
print(s)
{
if (this.isCategoryOn(Device.CATEGORY.BUFFER)) {
Device.PrintBuffer += s;
return;
}
let element = this.findBinding(Device.BINDING.PRINT, true);
if (element) {
element.value += s;
/*
* Prevent the <textarea> from getting too large; otherwise, printing becomes slower and slower.
*/
if (!DEBUG && element.value.length > 8192) {
element.value = element.value.substr(element.value.length - 4096);
}
element.scrollTop = element.scrollHeight;
}
if (DEBUG || !element) {
let i = s.lastIndexOf('\n');
if (i >= 0) {
console.log(Device.PrintBuffer + s.substr(0, i));
Device.PrintBuffer = "";
s = s.substr(i + 1);
if (!this.isCategoryOn(Device.CATEGORY.BUFFER)) {
let element = this.findBinding(Device.BINDING.PRINT, true);
if (element) {
element.value += s;
/*
* Prevent the <textarea> from getting too large; otherwise, printing becomes slower and slower.
*/
if (!DEBUG && element.value.length > 8192) {
element.value = element.value.substr(element.value.length - 4096);
}
element.scrollTop = element.scrollHeight;
return;
}
Device.PrintBuffer += s;
}
}

/**
* println(s)
*
* @this {Device}
* @param {string} s
*/
println(s)
{
this.print(s + '\n');
}

/**
* printf(format, ...args)
*
* @this {Device}
* @param {string} format
* @param {...} args
*/
printf(format, ...args)
{
this.print(this.sprintf(format, ...args));
super.print(s);
}

/**
Expand Down Expand Up @@ -1042,106 +1013,6 @@ class Device {
return cPrev;
}

/**
* sprintf(format, ...args)
*
* Copied from the CCjs project (https://github.com/jeffpar/ccjs/blob/master/lib/stdio.js) and extended.
*
* Far from complete, let alone sprintf-compatible, but it's adequate for the handful of sprintf-style format
* specifiers that I use.
*
* @this {Device}
* @param {string} format
* @param {...} args
* @returns {string}
*/
sprintf(format, ...args)
{
let buffer = "";
let aParts = format.split(/%([-+ 0#]?)([0-9]*)(\.?)([0-9]*)([hlL]?)([A-Za-z%])/);

let iArg = 0, iPart;
for (iPart = 0; iPart < aParts.length - 7; iPart += 7) {

buffer += aParts[iPart];

let arg = args[iArg++];
let flags = aParts[iPart+1];
let minimum = +aParts[iPart+2] || 0;
let precision = +aParts[iPart+4] || 0;
let conversion = aParts[iPart+6];
let ach = null, s;

switch(conversion) {
case 'd':
/*
* We could use "arg |= 0", but there may be some value to supporting integers > 32 bits.
*/
arg = Math.trunc(arg);
/* falls through */

case 'f':
s = Math.trunc(arg) + "";
if (precision) {
minimum -= (precision + 1);
}
if (s.length < minimum) {
if (flags == '0') {
if (arg < 0) minimum--;
s = ("0000000000" + Math.abs(arg)).slice(-minimum);
if (arg < 0) s = '-' + s;
} else {
s = (" " + s).slice(-minimum);
}
}
if (precision) {
arg = Math.round((arg - Math.trunc(arg)) * Math.pow(10, precision));
s += '.' + ("0000000000" + Math.abs(arg)).slice(-precision);
}
buffer += s;
break;

case 'c':
arg = String.fromCharCode(arg);
/* falls through */

case 's':
while (arg.length < minimum) {
if (flags == '-') {
arg += ' ';
} else {
arg = ' ' + arg;
}
}
buffer += arg;
break;

case 'X':
ach = Device.HexUpperCase;
/* falls through */

case 'x':
if (!ach) ach = Device.HexLowerCase;
s = "";
do {
s = ach[arg & 0xf] + s;
arg >>>= 4;
} while (--minimum > 0 || arg);
buffer += s;
break;

default:
/*
* The supported ANSI C set of conversions: "dioxXucsfeEgGpn%"
*/
buffer += "(unrecognized printf conversion %" + conversion + ")";
break;
}
}

buffer += aParts[iPart];
return buffer;
}
}

Device.BINDING = {
Expand Down Expand Up @@ -1192,23 +1063,3 @@ Device.Handlers = {};
* @type {Object}
*/
Device.Machines = {};

/**
* Category is a global string that contains zero or more Device.CATEGORY strings; see setCategory().
*
* @type {string}
*/
Device.Category = "";

/**
* PrintBuffer is a global string that buffers partial lines for our print services when using console.log().
*
* @type {string}
*/
Device.PrintBuffer = "";

/*
* Handy global constants
*/
Device.HexLowerCase = "0123456789abcdef";
Device.HexUpperCase = "0123456789ABCDEF";
Loading

0 comments on commit a3c7da6

Please sign in to comment.