From 3b88e4c53c0b232f92abd64a1046462292ac2f69 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 3 Nov 2016 15:50:19 -0700 Subject: [PATCH] Memory can now be explicitly "zeroed" with any byte pattern (but the default is still zero); note that memory blocks are still always zero-initialized when first created --- modules/pdp11/lib/bus.js | 7 ++++--- modules/pdp11/lib/memory.js | 10 ++++++---- modules/pdp11/lib/ram.js | 7 ++++++- versions/pdpjs/1.30.2/pdp11-dbg.js | 2 +- versions/pdpjs/1.30.2/pdp11.js | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/modules/pdp11/lib/bus.js b/modules/pdp11/lib/bus.js index a39b61a1b..a69972c09 100644 --- a/modules/pdp11/lib/bus.js +++ b/modules/pdp11/lib/bus.js @@ -664,13 +664,14 @@ BusPDP11.prototype.cleanMemory = function(addr, size) }; /** - * zeroMemory(addr, size) + * zeroMemory(addr, size, pattern) * * @this {BusPDP11} * @param {number} addr * @param {number} size + * @param {number} [pattern] */ -BusPDP11.prototype.zeroMemory = function(addr, size) +BusPDP11.prototype.zeroMemory = function(addr, size, pattern) { var off = addr & this.nBlockLimit; var iBlock = addr >>> this.nBlockShift; @@ -682,7 +683,7 @@ BusPDP11.prototype.zeroMemory = function(addr, size) if (i >= 0) block = this.aIOPrevBlocks[i]; } } - if (block) block.zero(off, size); + if (block) block.zero(off, size, pattern); size -= this.nBlockSize; iBlock++; off = 0; diff --git a/modules/pdp11/lib/memory.js b/modules/pdp11/lib/memory.js index 96b047c3d..44d689153 100644 --- a/modules/pdp11/lib/memory.js +++ b/modules/pdp11/lib/memory.js @@ -385,7 +385,7 @@ MemoryPDP11.prototype = { return false; }, /** - * zero(off, len) + * zero(off, len, pattern) * * Zeros the block. Supporting off and len parameters is probably overkill, and makes more * work in the non-TYPEDARRAY, non-BYTEARRAY case, but that's not the typical case. The other @@ -394,19 +394,21 @@ MemoryPDP11.prototype = { * @this {MemoryPDP11} * @param {number} [off] (optional starting byte offset within block) * @param {number} [len] (optional maximum number of bytes; default is the entire block) + * @param {number} [pattern] */ - zero: function(off, len) { + zero: function(off, len, pattern) { var i; off = off || 0; + pattern &= 0xff; /* * NOTE: If len happens to be larger than the block, that's OK, because we also bounds-check the index. */ if (len === undefined) len = this.size; Component.assert(off >= 0 && off < this.size); if ((TYPEDARRAYS || BYTEARRAYS) && this.ab) { - for (i = off; len-- && i < this.ab.length; i++) this.ab[i] = 0; + for (i = off; len-- && i < this.ab.length; i++) this.ab[i] = pattern; } else { - for (i = off; len-- && i < this.size; i++) this.writeByteDirect(off, 0, this.addr + off); + for (i = off; len-- && i < this.size; i++) this.writeByteDirect(off, pattern, this.addr + off); } }, /** diff --git a/modules/pdp11/lib/ram.js b/modules/pdp11/lib/ram.js index 1f07716ca..1a52af5a9 100644 --- a/modules/pdp11/lib/ram.js +++ b/modules/pdp11/lib/ram.js @@ -239,7 +239,12 @@ RAMPDP11.prototype.initRAM = function() RAMPDP11.prototype.reset = function() { if (this.fAllocated) { - this.bus.zeroMemory(this.addrRAM, this.sizeRAM); + /* + * TODO: Add a configuration parameter for selecting the byte pattern on reset? + * Note that when memory blocks are originally created, they are currently always + * zero-initialized, so this would only affect resets. + */ + this.bus.zeroMemory(this.addrRAM, this.sizeRAM, 0); if (this.abInit) { this.loadImage(this.abInit, this.addrLoad, this.addrExec, this.addrRAM, true); } diff --git a/versions/pdpjs/1.30.2/pdp11-dbg.js b/versions/pdpjs/1.30.2/pdp11-dbg.js index 37e99b13e..9698c72ed 100644 --- a/versions/pdpjs/1.30.2/pdp11-dbg.js +++ b/versions/pdpjs/1.30.2/pdp11-dbg.js @@ -165,7 +165,7 @@ function og(a){if(!tb(a)){if(a.A){if(!a.f||!a.w)return;a.g||(a.g=a.f.length);if( Xa(function(){for(var a=D(document,"pdp11","rom"),b=0;b>>a.la;0>>a.la;0=b.length)break;for(var h=h+2,m=b[h++]&255|(b[h++]&255)<<8,n=b[h++]&255|(b[h++]&255)<<8,l=l+((m&255)+(m>>8)+(n&255)+(n>>8)),r=h,t=m-=6;0=b.length)break;l+=b[h++]&255;if(l&255)break;if(t)for(;t--;)a.b.qb(n++,b[r++]&255);else n&1?a.b.ha():ud(a.b,n,f);g=!0}else h++;else h+=2}if(!g&&(null==c&&(c=e),null!=c)){for(e=0;e>>a.c;0>>a.c;0=b.length)break;for(var k=k+2,n=b[k++]&255|(b[k++]&255)<<8,p=b[k++]&255|(b[k++]&255)<<8,l=l+((n&255)+(n>>8)+(p&255)+(p>>8)),t=k,w=n-=6;0=b.length)break;l+=b[k++]&255;if(l&255)break;if(w)for(;w--;)a.a.Xa(p++,b[t++]&255);else p&1?G(a.a):zc(a.a,p,f);g=!0}else k++;else k+=2}if(!g&&(null==c&&(c=e),null!=c)){for(e=0;e