Fixed zeroMemory() to properly zero any block(s) that originally underlaid the IOPAGE block(s), rather than trying to zero the IOPAGE block itself (which would be a bad idea)

This commit is contained in:
Jeff 2016-11-03 15:36:37 -07:00 committed by Jeff Parsons
commit 97de321daa
4 changed files with 105 additions and 99 deletions

View file

@ -80,8 +80,8 @@ function BusPDP11(parmsBus, cpu, dbg)
* It is managed by setIOPageRange(). reset() establishes the default (16).
*/
this.nIOPageRange = 0; // zero means no IOPAGE access (yet)
this.prevIOPageBlocks = []; // this saves any memory blocks we had to replace with IOPAGE blocks
this.realIOPageBlocks = null; // this saves the memory blocks allocated for IOPAGE, so we can reuse them
this.aIOPrevBlocks = []; // this saves any previous blocks we had to replace with IOPAGE blocks
this.aIOPageBlocks = null; // this saves the memory blocks allocated for IOPAGE, so we can reuse them
/*
* Compute all BusPDP11 memory block parameters now, based on the width of the bus.
@ -452,7 +452,7 @@ BusPDP11.prototype.setIOPageRange = function(nRange)
var addr;
if (this.nIOPageRange) {
addr = (1 << this.nIOPageRange) - BusPDP11.IOPAGE_LENGTH;
this.setMemoryBlocks(addr, BusPDP11.IOPAGE_LENGTH, this.prevIOPageBlocks);
this.setMemoryBlocks(addr, BusPDP11.IOPAGE_LENGTH, this.aIOPrevBlocks);
this.nIOPageRange = 0;
}
if (nRange) {
@ -460,12 +460,12 @@ BusPDP11.prototype.setIOPageRange = function(nRange)
addr = (1 << nRange);
this.nBusLimit = this.nBusMask = (addr - 1);
addr -= BusPDP11.IOPAGE_LENGTH;
this.prevIOPageBlocks = this.getMemoryBlocks(addr, BusPDP11.IOPAGE_LENGTH);
if (this.realIOPageBlocks) {
this.setMemoryBlocks(addr, BusPDP11.IOPAGE_LENGTH, this.realIOPageBlocks);
this.aIOPrevBlocks = this.getMemoryBlocks(addr, BusPDP11.IOPAGE_LENGTH);
if (this.aIOPageBlocks) {
this.setMemoryBlocks(addr, BusPDP11.IOPAGE_LENGTH, this.aIOPageBlocks);
} else {
this.addMemory(addr, BusPDP11.IOPAGE_LENGTH, MemoryPDP11.TYPE.CONTROLLER, this);
this.realIOPageBlocks = this.getMemoryBlocks(addr, BusPDP11.IOPAGE_LENGTH);
this.aIOPageBlocks = this.getMemoryBlocks(addr, BusPDP11.IOPAGE_LENGTH);
}
}
}
@ -675,7 +675,14 @@ BusPDP11.prototype.zeroMemory = function(addr, size)
var off = addr & this.nBlockLimit;
var iBlock = addr >>> this.nBlockShift;
while (size > 0 && iBlock < this.aMemBlocks.length) {
this.aMemBlocks[iBlock].zero(off, size);
var block = this.aMemBlocks[iBlock];
if (block.controller) {
if (this.aIOPageBlocks && this.aIOPageBlocks.length == this.aIOPrevBlocks.length) {
var i = this.aIOPageBlocks.indexOf(block);
if (i >= 0) block = this.aIOPrevBlocks[i];
}
}
if (block) block.zero(off, size);
size -= this.nBlockSize;
iBlock++;
off = 0;

View file

@ -174,10 +174,9 @@ function MemoryPDP11(bus, addr, used, size, type, controller)
a = this.ab = new Array(this.size);
} else {
/*
* NOTE: This is the default mode of operation (!TYPEDARRAYS && !BYTEARRAYS), because it
* seems to provide the best performance; and although in theory, that performance might
* come at twice the overhead of TYPEDARRAYS, it's increasingly likely that the JavaScript
* runtime will notice that all we ever store are 32-bit values, and optimize accordingly.
* NOTE: This used to be the default mode of operation (!TYPEDARRAYS && !BYTEARRAYS), because
* it seemed to provide the best performance; however, that was then, and this is now. TYPEDARRAYS
* is more efficient.
*/
a = this.adw = new Array(this.size >> 2);
}
@ -389,8 +388,8 @@ MemoryPDP11.prototype = {
* zero(off, len)
*
* Zeros the block. Supporting off and len parameters is probably overkill, and makes more
* work in the non-TYPEDARRAY, non-BYTEARRAY case, because there all we have is an array of DWORDs,
* but that's not the typical case.
* work in the non-TYPEDARRAY, non-BYTEARRAY case, but that's not the typical case. The other
* exception is controller-based blocks, which may not have any array backing at all.
*
* @this {MemoryPDP11}
* @param {number} [off] (optional starting byte offset within block)
@ -404,7 +403,7 @@ MemoryPDP11.prototype = {
*/
if (len === undefined) len = this.size;
Component.assert(off >= 0 && off < this.size);
if (TYPEDARRAYS || BYTEARRAYS) {
if ((TYPEDARRAYS || BYTEARRAYS) && this.ab) {
for (i = off; len-- && i < this.ab.length; i++) this.ab[i] = 0;
} else {
for (i = off; len-- && i < this.size; i++) this.writeByteDirect(off, 0, this.addr + off);