From e2e5ea1b77f1ede73b3df5b23417ded51bcfa02c Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Tue, 3 May 2016 12:53:57 -0700 Subject: [PATCH] Sync PC8080 Bus changes with PCjs --- modules/pc8080/lib/memory.js | 2 +- modules/pcjs/lib/bus.js | 44 ++++++++++++++++++++---------------- modules/pcjs/lib/memory.js | 6 ++--- modules/pcjs/lib/ram.js | 2 -- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/modules/pc8080/lib/memory.js b/modules/pc8080/lib/memory.js index 46881ac65..b2d2c09c0 100644 --- a/modules/pc8080/lib/memory.js +++ b/modules/pc8080/lib/memory.js @@ -194,7 +194,7 @@ Memory.TYPE = { VIDEO: 3, CTRL: 4, COLORS: ["black", "blue", "green", "cyan"], - NAMES: ["N/A", "RAM", "ROM", "VID", "H/W"] + NAMES: ["NONE", "RAM", "ROM", "VID", "H/W"] }; /* diff --git a/modules/pcjs/lib/bus.js b/modules/pcjs/lib/bus.js index 697447700..9137d6202 100644 --- a/modules/pcjs/lib/bus.js +++ b/modules/pcjs/lib/bus.js @@ -378,48 +378,51 @@ Bus.prototype.powerUp = function(data, fRepower) */ Bus.prototype.addMemory = function(addr, size, type, controller) { - var iBlock = addr >>> this.nBlockShift; - while (size > 0 && iBlock < this.aMemBlocks.length) { + var addrNext = addr; + var sizeLeft = size; + var iBlock = addrNext >>> this.nBlockShift; + + while (sizeLeft > 0 && iBlock < this.aMemBlocks.length) { var block = this.aMemBlocks[iBlock]; var addrBlock = iBlock * this.nBlockSize; - var sizeBlock = this.nBlockSize - (addr - addrBlock); - if (sizeBlock > size) sizeBlock = size; + var sizeBlock = this.nBlockSize - (addrNext - addrBlock); + if (sizeBlock > sizeLeft) sizeBlock = sizeLeft; if (block && block.size) { if (block.type == type && block.controller == controller) { /* * Where there is already a similar block with a non-zero size, we allow the allocation only if: * - * 1) addr + size <= block.addr (the request precedes the used portion of the current block), or - * 2) addr >= block.addr + block.used (the request follows the used portion of the current block) + * 1) addrNext + sizeLeft <= block.addr (the request precedes the used portion of the current block), or + * 2) addrNext >= block.addr + block.used (the request follows the used portion of the current block) */ - if (addr + size <= block.addr) { - block.used += (block.addr - addr); - block.addr = addr; + if (addrNext + sizeLeft <= block.addr) { + block.used += (block.addr - addrNext); + block.addr = addrNext; return true; } - if (addr >= block.addr + block.used) { - var sizeAvail = block.size - (addr - addrBlock); - if (sizeAvail > size) sizeAvail = size; - block.used = addr - block.addr + sizeAvail; - addr = addrBlock + this.nBlockSize; - size -= sizeAvail; + if (addrNext >= block.addr + block.used) { + var sizeAvail = block.size - (addrNext - addrBlock); + if (sizeAvail > sizeLeft) sizeAvail = sizeLeft; + block.used = addrNext - block.addr + sizeAvail; + addrNext = addrBlock + this.nBlockSize; + sizeLeft -= sizeAvail; iBlock++; continue; } } - return this.reportError(Bus.ERROR.ADD_MEM_INUSE, addr, size); + return this.reportError(Bus.ERROR.ADD_MEM_INUSE, addrNext, sizeLeft); } - var blockNew = new Memory(addr, sizeBlock, this.nBlockSize, type, controller); + var blockNew = new Memory(addrNext, sizeBlock, this.nBlockSize, type, controller); blockNew.copyBreakpoints(this.dbg, block); this.aMemBlocks[iBlock++] = blockNew; - addr = addrBlock + this.nBlockSize; - size -= sizeBlock; + addrNext = addrBlock + this.nBlockSize; + sizeLeft -= sizeBlock; } - if (size <= 0) { + if (sizeLeft <= 0) { /* * If all addMemory() calls happened ONLY during device initialization, the following code would not * be necessary; unfortunately, the Video component can add and remove physical memory blocks during video @@ -430,6 +433,7 @@ Bus.prototype.addMemory = function(addr, size, type, controller) * to warrant it. */ this.cpu.flushPageBlocks(); + this.status(Math.floor(size / 1024) + "Kb " + Memory.TYPE.NAMES[type] + " at " + str.toHex(addr)); return true; } return this.reportError(Bus.ERROR.ADD_MEM_BADRANGE, addr, size); diff --git a/modules/pcjs/lib/memory.js b/modules/pcjs/lib/memory.js index 4d84f9ba9..f76e2f520 100644 --- a/modules/pcjs/lib/memory.js +++ b/modules/pcjs/lib/memory.js @@ -110,7 +110,7 @@ function Memory(addr, used, size, type, controller, cpu) this.controller = null; this.cpu = cpu; // if a CPU reference is provided, then this must be an UNPAGED Memory block allocation this.copyBreakpoints(); // initialize the block's Debugger info (eg, breakpoint totals); the caller will reinitialize - + /* * TODO: Study the impact of dirty block tracking. As noted in the paged block handlers (eg, writeBytePLE), * the original purposes were to allow saveMemory() to save only dirty blocks, and to enable the Video component @@ -244,8 +244,8 @@ Memory.TYPE = { CTRL: 4, UNPAGED: 5, PAGED: 6, - NAMES: ["NONE", "RAM", "ROM", "VIDEO", "H/W", "UNPAGED", "PAGED"], - COLORS: ["black", "blue", "green", "cyan"] + COLORS: ["black", "blue", "green", "cyan"], + NAMES: ["NONE", "RAM", "ROM", "VIDEO", "H/W", "UNPAGED", "PAGED"] }; /* diff --git a/modules/pcjs/lib/ram.js b/modules/pcjs/lib/ram.js index 4aface59b..8a6ec7157 100644 --- a/modules/pcjs/lib/ram.js +++ b/modules/pcjs/lib/ram.js @@ -169,8 +169,6 @@ RAM.prototype.reset = function() if (this.bus.addMemory(this.addrRAM, this.sizeRAM, Memory.TYPE.RAM)) { this.fAllocated = true; - this.status(Math.floor(this.sizeRAM / 1024) + "Kb allocated"); - /* * NOTE: I'm specifying MAXDEBUG for status() messages because I'm not yet sure I want these * messages buried in the app, since they're seen only when a Control Panel is active. Another