From ca8fa1e5ee66aa4b7c3692fcd2fd9c2dbe31a283 Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Tue, 31 Mar 2015 13:50:21 -0700 Subject: [PATCH] Assorted changes after upgrading WebStorm and Node --- modules/pcjs/bin/pcjs | 2 +- modules/pcjs/lib/debugger.js | 4 +- modules/pcjs/lib/x86seg.js | 70 +++++++------- notes.md | 175 +++++++++++++++++++++++++++++++++++ package.json | 2 +- 5 files changed, 210 insertions(+), 43 deletions(-) diff --git a/modules/pcjs/bin/pcjs b/modules/pcjs/bin/pcjs index 0a5d32fdf..59f4b7b94 100644 --- a/modules/pcjs/bin/pcjs +++ b/modules/pcjs/bin/pcjs @@ -330,7 +330,7 @@ function doCommand(sCmd) var onCommand = function (cmd, context, filename, callback) { var result = false; - var match = cmd.match(/\(\s*(.*)\s*\)/); + var match = cmd.match(/^\(?\s*(.*?)\s*\)?$/); if (match) { result = doCommand(match[1]); } diff --git a/modules/pcjs/lib/debugger.js b/modules/pcjs/lib/debugger.js index e641bf3dd..1de62cd2a 100644 --- a/modules/pcjs/lib/debugger.js +++ b/modules/pcjs/lib/debugger.js @@ -1737,7 +1737,7 @@ if (DEBUGGER) { n = cpu.getDS(); cch = 4; break; } - if (I386 && !cch) { + if (I386 && this.cpu.model >= X86.MODEL_80386 && !cch) { switch(iReg) { case Debugger.REG_EAX: n = cpu.regEAX; cch = 8; @@ -2502,7 +2502,7 @@ if (DEBUGGER) { if (sel == this.cpu.getDS()) return this.cpu.segDS; if (sel == this.cpu.getES()) return this.cpu.segES; if (sel == this.cpu.getSS()) return this.cpu.segSS; - if (I386) { + if (I386 && this.cpu.model >= X86.MODEL_80386) { if (sel == this.cpu.getFS()) return this.cpu.segFS; if (sel == this.cpu.getGS()) return this.cpu.segGS; } diff --git a/modules/pcjs/lib/x86seg.js b/modules/pcjs/lib/x86seg.js index 6b1ee3c72..33904852d 100644 --- a/modules/pcjs/lib/x86seg.js +++ b/modules/pcjs/lib/x86seg.js @@ -97,7 +97,7 @@ function X86Seg(cpu, id, sName, fProt) X86Seg.ID = { NULL: 0, // "NULL" CODE: 1, // "CS" - DATA: 2, // "DS", "ES" + DATA: 2, // "DS", "ES", "FS", "GS" STACK: 3, // "SS" TSS: 4, // "TSS" LDT: 5, // "LDT" @@ -105,10 +105,6 @@ X86Seg.ID = { DEBUG: 7 // "DBG" }; -/* - * Class methods - */ - /** * loadReal(sel, fSuppress) * @@ -119,7 +115,7 @@ X86Seg.ID = { * @param {boolean} [fSuppress] is true to suppress any errors * @return {number} base address of selected segment, or ADDR_INVALID if error (TODO: No error conditions exist yet) */ -X86Seg.loadReal = function loadReal(sel, fSuppress) +X86Seg.prototype.loadReal = function loadReal(sel, fSuppress) { this.sel = sel & 0xffff; this.dataSize = this.addrSize = 2; @@ -150,7 +146,7 @@ X86Seg.loadReal = function loadReal(sel, fSuppress) * @param {boolean} [fSuppress] is true to suppress any errors, cycle assessment, etc * @return {number} base address of selected segment, or ADDR_INVALID if error */ -X86Seg.loadProt = function loadProt(sel, fSuppress) +X86Seg.prototype.loadProt = function loadProt(sel, fSuppress) { var addrDT; var addrDTLimit; @@ -201,7 +197,7 @@ X86Seg.loadProt = function loadProt(sel, fSuppress) * @param {number} nIDT * @return {number} address from selected vector, or ADDR_INVALID if error (TODO: No error conditions exist yet) */ -X86Seg.loadIDTReal = function loadIDTReal(nIDT) +X86Seg.prototype.loadIDTReal = function loadIDTReal(nIDT) { var cpu = this.cpu; /* @@ -230,7 +226,7 @@ X86Seg.loadIDTReal = function loadIDTReal(nIDT) * @param {number} nIDT * @return {number} address from selected vector, or ADDR_INVALID if error (TODO: No error conditions exist yet) */ -X86Seg.loadIDTProt = function loadIDTProt(nIDT) +X86Seg.prototype.loadIDTProt = function loadIDTProt(nIDT) { var cpu = this.cpu; cpu.assert(nIDT >= 0 && nIDT < 256); @@ -256,7 +252,7 @@ X86Seg.loadIDTProt = function loadIDTProt(nIDT) * @param {boolean} [fSuppress] is true to suppress any errors * @return {number} corresponding physical address if valid, or ADDR_INVALID if error (TODO: No error conditions exist yet) */ -X86Seg.checkReadReal = function checkReadReal(off, cb, fSuppress) +X86Seg.prototype.checkReadReal = function checkReadReal(off, cb, fSuppress) { return (this.base + off)|0; }; @@ -273,7 +269,7 @@ X86Seg.checkReadReal = function checkReadReal(off, cb, fSuppress) * @param {boolean} [fSuppress] is true to suppress any errors * @return {number} corresponding physical address if valid, or ADDR_INVALID if error (TODO: No error conditions exist yet) */ -X86Seg.checkWriteReal = function checkWriteReal(off, cb, fSuppress) +X86Seg.prototype.checkWriteReal = function checkWriteReal(off, cb, fSuppress) { return (this.base + off)|0; }; @@ -287,12 +283,12 @@ X86Seg.checkWriteReal = function checkWriteReal(off, cb, fSuppress) * @param {boolean} [fSuppress] is true to suppress any errors * @return {number} corresponding physical address if valid, or ADDR_INVALID if not */ -X86Seg.checkReadProt = function checkReadProt(off, cb, fSuppress) +X86Seg.prototype.checkReadProt = function checkReadProt(off, cb, fSuppress) { if (off + cb <= this.limit) { return (this.base + off)|0; } - return X86Seg.checkReadProtDisallowed.call(this, off, cb, fSuppress); + return this.checkReadProtDisallowed(off, cb, fSuppress); }; /** @@ -304,12 +300,12 @@ X86Seg.checkReadProt = function checkReadProt(off, cb, fSuppress) * @param {boolean} [fSuppress] is true to suppress any errors * @return {number} corresponding physical address if valid, ADDR_INVALID if not */ -X86Seg.checkReadProtDown = function checkReadProtDown(off, cb, fSuppress) +X86Seg.prototype.checkReadProtDown = function checkReadProtDown(off, cb, fSuppress) { if (off + cb > this.limit) { return (this.base + off)|0; } - return X86Seg.checkReadProtDisallowed.call(this, off, cb, fSuppress); + return this.checkReadProtDisallowed(off, cb, fSuppress); }; /** @@ -321,7 +317,7 @@ X86Seg.checkReadProtDown = function checkReadProtDown(off, cb, fSuppress) * @param {boolean} [fSuppress] is true to suppress any errors * @return {number} corresponding physical address if valid, ADDR_INVALID if not */ -X86Seg.checkReadProtDisallowed = function checkReadProtDisallowed(off, cb, fSuppress) +X86Seg.prototype.checkReadProtDisallowed = function checkReadProtDisallowed(off, cb, fSuppress) { if (!fSuppress) { X86.fnFault.call(this.cpu, X86.EXCEPTION.GP_FAULT, 0); @@ -338,12 +334,12 @@ X86Seg.checkReadProtDisallowed = function checkReadProtDisallowed(off, cb, fSupp * @param {boolean} [fSuppress] is true to suppress any errors * @return {number} corresponding physical address if valid, ADDR_INVALID if not */ -X86Seg.checkWriteProt = function checkWriteProt(off, cb, fSuppress) +X86Seg.prototype.checkWriteProt = function checkWriteProt(off, cb, fSuppress) { if (off + cb <= this.limit) { return (this.base + off)|0; } - return X86Seg.checkWriteProtDisallowed.call(this, off, cb, fSuppress); + return this.checkWriteProtDisallowed(off, cb, fSuppress); }; /** @@ -355,12 +351,12 @@ X86Seg.checkWriteProt = function checkWriteProt(off, cb, fSuppress) * @param {boolean} [fSuppress] is true to suppress any errors * @return {number} corresponding physical address if valid, ADDR_INVALID if not */ -X86Seg.checkWriteProtDown = function checkWriteProtDown(off, cb, fSuppress) +X86Seg.prototype.checkWriteProtDown = function checkWriteProtDown(off, cb, fSuppress) { if (off + cb > this.limit) { return (this.base + off)|0; } - return X86Seg.checkWriteProtDisallowed.call(this, off, cb, fSuppress); + return this.checkWriteProtDisallowed(off, cb, fSuppress); }; /** @@ -372,7 +368,7 @@ X86Seg.checkWriteProtDown = function checkWriteProtDown(off, cb, fSuppress) * @param {boolean} [fSuppress] is true to suppress any errors * @return {number} corresponding physical address if valid, ADDR_INVALID if not */ -X86Seg.checkWriteProtDisallowed = function checkWriteProtDisallowed(off, cb, fSuppress) +X86Seg.prototype.checkWriteProtDisallowed = function checkWriteProtDisallowed(off, cb, fSuppress) { if (!fSuppress) { X86.fnFault.call(this.cpu, X86.EXCEPTION.GP_FAULT, 0); @@ -404,7 +400,7 @@ X86Seg.checkWriteProtDisallowed = function checkWriteProtDisallowed(off, cb, fSu * @param {boolean} fNest is true if nesting, false if un-nesting * @return {boolean} true if successful, false if error */ -X86Seg.switchTSS = function switchTSS(selNew, fNest) +X86Seg.prototype.switchTSS = function switchTSS(selNew, fNest) { var cpu = this.cpu; cpu.assert(this === cpu.segCS); @@ -474,10 +470,6 @@ X86Seg.switchTSS = function switchTSS(selNew, fNest) return true; }; -/* - * Object methods - */ - /** * loadAcc(sel, fGDT) * @@ -634,7 +626,7 @@ X86Seg.prototype.loadDesc8 = function(addrDesc, sel, fSuppress) cpu.assert(!(acc & 0x1f)); } else if (type == X86.DESC.ACC.TYPE.GATE_TASK) { - if (!X86Seg.switchTSS.call(this, base & 0xffff, true)) { + if (!this.switchTSS(base & 0xffff, true)) { base = X86.ADDR_INVALID; break; } @@ -843,29 +835,29 @@ X86Seg.prototype.updateMode = function(fProt) } this.fExpDown = false; if (fProt) { - this.load = X86Seg.loadProt; - this.loadIDT = X86Seg.loadIDTProt; - this.checkRead = X86Seg.checkReadProt; - this.checkWrite = X86Seg.checkWriteProt; + this.load = this.loadProt; + this.loadIDT = this.loadIDTProt; + this.checkRead = this.checkReadProt; + this.checkWrite = this.checkWriteProt; if (this.acc & X86.DESC.ACC.TYPE.SEG) { /* * If the READABLE bit of CODE_READABLE is not set, then disallow reads */ if ((this.acc & X86.DESC.ACC.TYPE.CODE_READABLE) == X86.DESC.ACC.TYPE.CODE_EXECONLY) { - this.checkWrite = X86Seg.checkReadProtDisallowed; + this.checkWrite = this.checkReadProtDisallowed; } /* * If the CODE bit is set, or the the WRITABLE bit is not set, then disallow writes */ if ((this.acc & X86.DESC.ACC.TYPE.CODE) || !(this.acc & X86.DESC.ACC.TYPE.WRITABLE)) { - this.checkWrite = X86Seg.checkWriteProtDisallowed; + this.checkWrite = this.checkWriteProtDisallowed; } /* * If the CODE bit is not set *and* the EXPDOWN bit is set, then invert the limit check */ if ((this.acc & (X86.DESC.ACC.TYPE.CODE | X86.DESC.ACC.TYPE.EXPDOWN)) == X86.DESC.ACC.TYPE.EXPDOWN) { - if (this.checkRead == X86Seg.checkReadProt) this.checkRead = X86Seg.checkReadProtDown; - if (this.checkWrite == X86Seg.checkWriteProt) this.checkWrite = X86Seg.checkWriteProtDown; + if (this.checkRead == this.checkReadProt) this.checkRead = this.checkReadProtDown; + if (this.checkWrite == this.checkWriteProt) this.checkWrite = this.checkWriteProtDown; this.fExpDown = true; } } @@ -879,10 +871,10 @@ X86Seg.prototype.updateMode = function(fProt) this.addrMask = (0xffffffff|0); } } else { - this.load = X86Seg.loadReal; - this.loadIDT = X86Seg.loadIDTReal; - this.checkRead = X86Seg.checkReadReal; - this.checkWrite = X86Seg.checkWriteReal; + this.load = this.loadReal; + this.loadIDT = this.loadIDTReal; + this.checkRead = this.checkReadReal; + this.checkWrite = this.checkWriteReal; this.limit = 0xffff; this.cpl = this.dpl = 0; this.addrDesc = X86.ADDR_INVALID; diff --git a/notes.md b/notes.md index cf5b2fcd6..9b2250354 100644 --- a/notes.md +++ b/notes.md @@ -47,3 +47,178 @@ You can also do this with files from other branches, and such. `man git-checkout The rest of the Internet will tell you to use `git reset --hard`, but this resets all uncommitted changes you’ve made in your working copy. Type this with care. + +Node "Cheat Sheet" +=== + +Installing Node (and NPM) +--- +I downloaded the latest Node installation package for my MacBook from [nodejs.org](http://nodejs.org/), +which provided the usual `node` and `npm` commands. Here are the versions they reported: + + [~/Sites/pcjs] node -v + v0.10.26 + [~/Sites/pcjs] npm -v + 1.4.3 + +I also installed a Node helper on my MacBook called `n` that makes it easy to keep Node up-to-date, per this tip on +[stackoverflow](http://stackoverflow.com/questions/8191459/how-to-update-node-js-npm-and-all-other-dependencies): + +1) Clear NPM's cache: + + [~/Sites/pcjs] sudo npm cache clean -f + +2) Install a little helper called 'n': + + [~/Sites/pcjs] sudo npm install -g n + +3) Install latest stable NodeJS version: + + [~/Sites/pcjs] sudo n stable + +Alternatively pick a specific version and install like so: + + [~/Sites/pcjs] sudo n 0.8.20 + +I'm not sure I like the generic name for this command ("n"); what would have been wrong with "node-update" +or "update-node"? Oh well. + +Next, I wanted to make sure `npm` was up-to-date. According to +[FAQ on npmjs.org](https://npmjs.org/doc/faq.html#How-do-I-update-npm), that's as easy as: + + [~/Sites/pcjs] sudo npm update npm -g + +although occasionally `npm` won't be able to update itself, in which case the fallback is: + + [~/Sites/pcjs] curl https://npmjs.org/install.sh | sh + +So, I made sure `npm` itself, along with `n` and all my other globally installed packages, were up-to-date, +and then I used `n` to make sure I was running the latest stable version of Node: + + [~/Sites/pcjs] sudo npm update -g + [~/Sites/pcjs] sudo n stable + [~/Sites/pcjs] node -v + v0.10.26 + +I've also seen suggestions to run this command before the preceding commands, but I don't know how often this is +recommended: + + [~/Sites/pcjs] sudo npm cache clean -f + +Next, I ran `npm init`: + + [~/Sites/pcjs] npm adduser + Username: jeffpar + Password: + Email: (this IS public) jeff@pcjs.org + npm http PUT http://registry.npmjs.org/-/user/org.couchdb.user:jeffpar + npm http 201 http://registry.npmjs.org/-/user/org.couchdb.user:jeffpar + + [~/Sites/pcjs] npm init + This utility will walk you through creating a package.json file. + It only covers the most common items, and tries to guess sane defaults. + + See `npm help json` for definitive documentation on these fields + and exactly what they do. + + Use `npm install --save` afterwards to install a package and + save it as a dependency in the package.json file. + + Press ^C at any time to quit. + name: (pcjs) + version: (0.0.0) 0.1.0 + description: Node-enabled version of PCjs + entry point: (server.js) + test command: + git repository: (git://github.com/jeffpar/pcjs.git) + keywords: pcjs,ibm pc,emulator + author: Jeff Parsons + license: (ISC) + About to write to /Users/Jeff/Sites/pcjs/package.json: + + { + "name": "pcjs", + "version": "0.1.0", + "description": "Node-enabled version of PCjs", + "main": "server.js", + "directories": { + "doc": "docs", + "test": "tests" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git://github.com/jeffpar/pcjs.git" + }, + "keywords": [ + "pcjs", + "ibm", + "pc", + "emulator" + ], + "author": "Jeff Parsons ", + "license": "ISC", + "bugs": { + "url": "https://github.com/jeffpar/pcjs/issues" + }, + "homepage": "http://www.pcjs.org/" + } + + Is this ok? (yes) + +Next, I installed `express` using `npm install --save express`: + + [~/Sites/pcjs] npm install --save express + npm http GET http://registry.npmjs.org/express + ... + express@3.4.8 node_modules/express + ├── methods@0.1.0 + ├── merge-descriptors@0.0.1 + ├── range-parser@0.0.4 + ├── cookie-signature@1.0.1 + ├── fresh@0.2.0 + ├── debug@0.7.4 + ├── buffer-crc32@0.2.1 + ├── cookie@0.1.0 + ├── mkdirp@0.3.5 + ├── commander@1.3.2 (keypress@0.1.0) + ├── send@0.1.4 (mime@1.2.11) + └── connect@2.12.0 (uid2@0.0.3, pause@0.0.1, qs@0.6.6, bytes@0.2.1, raw-body@1.1.2, batch@0.5.0, negotiator@0.3.0, multiparty@2.2.0) + +This added the following lines to my "package.json" file: + + "dependencies": { + "express": "~3.4.8" + } + +Then I created a test "server.js" in the root of the project: + + var http = require("http"); + var express = require("express"); + var app = express(); + app.get("/", function(req, res) { + res.end("Testing"); + }); + http.createServer(app).listen(3000); + +and ran `node server.js` and verified that all was working as expected. + +Updating Node (and NPM) +--- + +So as per above, I ran: + + [~/Sites/pcjs] sudo n stable + +which reported: + + install : v0.12.1 + mkdir : /usr/local/n/versions/0.12.1 + fetch : http://nodejs.org/dist/v0.12.1/node-v0.12.1-darwin-x64.tar.gz + installed : v0.12.1 + +Then I ran: + + [~/Sites/pcjs] sudo npm update -g diff --git a/package.json b/package.json index 9e7ef6dab..8e89b7120 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "bugs": { "url": "https://github.com/jeffpar/pcjs/issues" }, - "homepage": "https://github.com/jeffpar/pcjs", + "homepage": "http://www.pcjs.org/", "dependencies": { "express": "~3.4.8", "express-slash": "^1.0.0",