#!/usr/bin/env node /** * @fileoverview Test the Int36 class * @author Jeff Parsons * @copyright © Jeff Parsons 2012-2017 * @suppress {missingProperties} * * This file is part of PCjs, a computer emulation software project at . * * 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 . * * 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 * . * * 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("../../shared/lib/defines"); var Int36 = require("../../shared/lib/int36"); var i36Reg = new Int36(); /** * dumpInt36(i36) * * @param {Int36} i36 * @return {string} */ function dumpInt36(i36) { return i36.toString() + " (" + i36.toString(8, true) + ")"; } /** * test(sCmd, fREPL) * * @param {string} sCmd * @param {boolean} [fREPL] * @return {*} */ function test(sCmd, fREPL) { var aTokens = sCmd.split(' '); var sOp = aTokens[0]; var sNum1 = aTokens[1] && aTokens[1].replace(/,/g, ''); var sNum2 = aTokens[2]; var i36Op = new Int36(+sNum1); switch(sOp) { case "set": i36Reg = new Int36(+sNum1, +sNum2); break; case "add": i36Reg.add(i36Op); break; case "sub": i36Reg.sub(i36Op); break; case "mul": i36Reg.mul(i36Op); break; case "div": i36Reg.div(i36Op); break; case "print": break; default: console.log("unrecognized command: " + sCmd); return false; } console.log(sOp + (sNum1? (" " + dumpInt36(i36Op)) : "") + ": " + dumpInt36(i36Reg)); 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*([\S\s]*?)\s*\)?$/); if (match && match[1]) result = test(match[1], true); callback(null, result); }; test("set -34,359,738,368"); test("add 1"); test("sub 1"); test("sub 1"); test("add 1"); test("add 0"); repl.start({ prompt: "int36> ", input: process.stdin, output: process.stdout, eval: onCommand });