Sync PC8080 Bus changes with PCjs

This commit is contained in:
Jeff Parsons 2016-05-03 12:53:57 -07:00
commit e2e5ea1b77
4 changed files with 28 additions and 26 deletions

View file

@ -194,7 +194,7 @@ Memory.TYPE = {
VIDEO: 3, VIDEO: 3,
CTRL: 4, CTRL: 4,
COLORS: ["black", "blue", "green", "cyan"], COLORS: ["black", "blue", "green", "cyan"],
NAMES: ["N/A", "RAM", "ROM", "VID", "H/W"] NAMES: ["NONE", "RAM", "ROM", "VID", "H/W"]
}; };
/* /*

View file

@ -378,48 +378,51 @@ Bus.prototype.powerUp = function(data, fRepower)
*/ */
Bus.prototype.addMemory = function(addr, size, type, controller) Bus.prototype.addMemory = function(addr, size, type, controller)
{ {
var iBlock = addr >>> this.nBlockShift; var addrNext = addr;
while (size > 0 && iBlock < this.aMemBlocks.length) { var sizeLeft = size;
var iBlock = addrNext >>> this.nBlockShift;
while (sizeLeft > 0 && iBlock < this.aMemBlocks.length) {
var block = this.aMemBlocks[iBlock]; var block = this.aMemBlocks[iBlock];
var addrBlock = iBlock * this.nBlockSize; var addrBlock = iBlock * this.nBlockSize;
var sizeBlock = this.nBlockSize - (addr - addrBlock); var sizeBlock = this.nBlockSize - (addrNext - addrBlock);
if (sizeBlock > size) sizeBlock = size; if (sizeBlock > sizeLeft) sizeBlock = sizeLeft;
if (block && block.size) { if (block && block.size) {
if (block.type == type && block.controller == controller) { 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: * 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 * 1) addrNext + sizeLeft <= 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) * 2) addrNext >= block.addr + block.used (the request follows the used portion of the current block)
*/ */
if (addr + size <= block.addr) { if (addrNext + sizeLeft <= block.addr) {
block.used += (block.addr - addr); block.used += (block.addr - addrNext);
block.addr = addr; block.addr = addrNext;
return true; return true;
} }
if (addr >= block.addr + block.used) { if (addrNext >= block.addr + block.used) {
var sizeAvail = block.size - (addr - addrBlock); var sizeAvail = block.size - (addrNext - addrBlock);
if (sizeAvail > size) sizeAvail = size; if (sizeAvail > sizeLeft) sizeAvail = sizeLeft;
block.used = addr - block.addr + sizeAvail; block.used = addrNext - block.addr + sizeAvail;
addr = addrBlock + this.nBlockSize; addrNext = addrBlock + this.nBlockSize;
size -= sizeAvail; sizeLeft -= sizeAvail;
iBlock++; iBlock++;
continue; 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); blockNew.copyBreakpoints(this.dbg, block);
this.aMemBlocks[iBlock++] = blockNew; this.aMemBlocks[iBlock++] = blockNew;
addr = addrBlock + this.nBlockSize; addrNext = addrBlock + this.nBlockSize;
size -= sizeBlock; sizeLeft -= sizeBlock;
} }
if (size <= 0) { if (sizeLeft <= 0) {
/* /*
* If all addMemory() calls happened ONLY during device initialization, the following code would not * 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 * 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. * to warrant it.
*/ */
this.cpu.flushPageBlocks(); this.cpu.flushPageBlocks();
this.status(Math.floor(size / 1024) + "Kb " + Memory.TYPE.NAMES[type] + " at " + str.toHex(addr));
return true; return true;
} }
return this.reportError(Bus.ERROR.ADD_MEM_BADRANGE, addr, size); return this.reportError(Bus.ERROR.ADD_MEM_BADRANGE, addr, size);

View file

@ -110,7 +110,7 @@ function Memory(addr, used, size, type, controller, cpu)
this.controller = null; this.controller = null;
this.cpu = cpu; // if a CPU reference is provided, then this must be an UNPAGED Memory block allocation 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 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), * 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 * 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, CTRL: 4,
UNPAGED: 5, UNPAGED: 5,
PAGED: 6, 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"]
}; };
/* /*

View file

@ -169,8 +169,6 @@ RAM.prototype.reset = function()
if (this.bus.addMemory(this.addrRAM, this.sizeRAM, Memory.TYPE.RAM)) { if (this.bus.addMemory(this.addrRAM, this.sizeRAM, Memory.TYPE.RAM)) {
this.fAllocated = true; 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 * 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 * messages buried in the app, since they're seen only when a Control Panel is active. Another