v1.37.1: Fixed a CPU bug wherein resetting a running CPU could result in multiple runCPU() timeout handlers being created (there should never be more than one outstanding runCPU() setTimeout request); also modified the Keyboard component to use a CPU-driven timer instead of setTimeout() for keystroke injection, so that stopping/starting the CPU won't interfere with the injection process
This commit is contained in:
parent
f874063366
commit
22728fb7e9
289 changed files with 1354 additions and 1176 deletions
71
modules/shared/bin/printf
Normal file
71
modules/shared/bin/printf
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/env node
|
||||
/**
|
||||
* @fileoverview Test the sprintf() function
|
||||
* @author <a href="mailto:Jeff@pcjs.org">Jeff Parsons</a>
|
||||
* @copyright © Jeff Parsons 2012-2017
|
||||
* @suppress {missingProperties}
|
||||
*
|
||||
* This file is part of PCjs, a computer emulation software project at <http://pcjs.org/>.
|
||||
*
|
||||
* PCjs is free software: you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* PCjs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with PCjs. If not,
|
||||
* see <http://www.gnu.org/licenses/gpl.html>.
|
||||
*
|
||||
* You are required to include the above copyright notice in every modified copy of this work
|
||||
* and to display that copyright notice when the software starts running; see COPYRIGHT in
|
||||
* <http://pcjs.org/modules/shared/lib/defines.js>.
|
||||
*
|
||||
* Some PCjs files also attempt to load external resource files, such as character-image files,
|
||||
* ROM files, and disk image files. Those external resource files are not considered part of PCjs
|
||||
* for purposes of the GNU General Public License, and the author does not claim any copyright
|
||||
* as to their contents.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
var repl = require("repl");
|
||||
var Defines = require("../lib/defines");
|
||||
var Str = require("../lib/strlib");
|
||||
|
||||
/**
|
||||
* printf(sFormat, sValue)
|
||||
*
|
||||
* @param {string} sFormat
|
||||
* @param {number} sValue
|
||||
* @return {boolean}
|
||||
*/
|
||||
function printf(sFormat, sValue)
|
||||
{
|
||||
console.log('printf("' + sFormat + '", ' + sValue + "): '" + Str.sprintf(sFormat, +sValue) + "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* onCommand(cmd, context, filename, callback)
|
||||
*
|
||||
* @param {string} cmd
|
||||
* @param {Object} context
|
||||
* @param {string} filename
|
||||
* @param {function(Object|null, Object)} callback
|
||||
*/
|
||||
var onCommand = function (cmd, context, filename, callback)
|
||||
{
|
||||
var result = false;
|
||||
var match = cmd.match(/([^ ]*) *(.*?)\s*$/);
|
||||
if (match && match[1]) result = printf(match[1], match[2]);
|
||||
callback(null, result);
|
||||
};
|
||||
|
||||
repl.start({
|
||||
prompt: "printf> ",
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
eval: onCommand
|
||||
});
|
||||
|
|
@ -599,6 +599,70 @@ class Str {
|
|||
return fPadLeft? (sPadding + s).slice(-cch) : (s + sPadding).slice(0, cch);
|
||||
}
|
||||
|
||||
/**
|
||||
* sprintf(format, ...)
|
||||
*
|
||||
* Copied from the CCjs project (/ccjs/lib/stdio.js) and extended. Far from complete let alone sprintf-compatible,
|
||||
* but it's a start.
|
||||
*
|
||||
* @param {string} format
|
||||
* @param {...} args
|
||||
* @return {string}
|
||||
*/
|
||||
static sprintf(format, ...args)
|
||||
{
|
||||
var parts = format.split(/%([-+ 0#]?)([0-9]*)(\.?)([0-9]*)([hlL]?)([A-Za-z%])/);
|
||||
var buffer = "";
|
||||
var partIndex = 0;
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
|
||||
var arg = args[i], d, s;
|
||||
buffer += parts[partIndex++];
|
||||
var flags = parts[partIndex];
|
||||
var minimum = +parts[partIndex+1] || 0;
|
||||
var precision = +parts[partIndex+3] || 0;
|
||||
var conversion = parts[partIndex+5];
|
||||
|
||||
switch(conversion) {
|
||||
case 'd':
|
||||
case 'f':
|
||||
d = Math.trunc(arg);
|
||||
s = d + "";
|
||||
if (precision) {
|
||||
minimum -= (precision + 1);
|
||||
}
|
||||
if (s.length < minimum) {
|
||||
if (flags == '0') {
|
||||
if (d < 0) minimum--;
|
||||
s = ("0000000000" + Math.abs(d)).slice(-minimum);
|
||||
if (d < 0) s = '-' + s;
|
||||
} else {
|
||||
s = (" " + s).slice(-minimum);
|
||||
}
|
||||
}
|
||||
if (precision) {
|
||||
d = Math.trunc((arg - Math.trunc(arg)) * Math.pow(10, precision));
|
||||
s += '.' + ("0000000000" + Math.abs(d)).slice(-precision);
|
||||
}
|
||||
buffer += s;
|
||||
break;
|
||||
case 's':
|
||||
buffer += arg;
|
||||
break;
|
||||
default:
|
||||
/*
|
||||
* The supported ANSI C set of conversions: "dioxXucsfeEgGpn%"
|
||||
*/
|
||||
buffer += "(unrecognized printf conversion %" + conversion + ")";
|
||||
break;
|
||||
}
|
||||
|
||||
partIndex += 6;
|
||||
}
|
||||
buffer += parts[partIndex];
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* stripLeadingZeros(s, fPad)
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue