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

This commit is contained in:
Jeff 2016-11-03 15:50:19 -07:00 committed by Jeff Parsons
commit 3b88e4c53c
5 changed files with 18 additions and 10 deletions

View file

@ -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;

View file

@ -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);
}
},
/**

View file

@ -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);
}

View file

@ -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.length;b++){var c=a[b],d=B(c),d=new ng(d);C(d,c)}});
function qg(a){u.call(this,"RAM",a,qg);this.ia=this.g=null;this.A=a.addr;this.C=a.size;this.La=a.load;this.Ka=a.exec;this.v=!1;this.f=a.file;this.D=sa(this.f);if(this.f){a=this.f;var b=ta(this.D);"json"!=b&&"hex"!=b&&(a=Ga()+"/api/v1/dump?file="+this.f+"&format=bytes&decimal=true");var c=this;Ea(a,null,!0,function(a,b,f){f?(c.O("Unable to load RAM resource (error "+f+": "+a+")"),c.f=null):(nb(c.Qa,a,b),(a=Fa(a,b))?(c.g=a.ea,c.ia=a.ia,null==c.La&&(c.La=a.La),null==c.Ka&&(c.Ka=a.Ka)):c.f=null);rg(c)})}}
z(qg);qg.prototype.Ea=function(a,b,c,d){this.w=b;this.b=c;this.i=d;rg(this)};qg.prototype.Ha=function(){this.ia&&(this.i&&pg(this.i,this.id,this.A,this.C,this.ia),delete this.ia);return!0};qg.prototype.Ga=function(){return!0};function rg(a){if(a.w&&(!a.v&&a.C&&tc(a.w,a.A,a.C,1)&&(a.v=!0),!tb(a))){if(!a.v)q("No RAM allocated");else if(a.f){if(!a.g||!a.w)return;Lg(a,a.g,a.La,a.Ka,a.A)}H(a)}}
qg.prototype.reset=function(){if(this.v){for(var a=this.w,b=this.A,c=this.C,d=b&a.w,b=b>>>a.la;0<c&&b<a.W.length;){var e=a.W[b];if(e.controller&&a.g&&a.g.length==a.v.length){var f=a.g.indexOf(e);0<=f&&(e=a.v[f])}if(e){var f=c,g,d=d||0;void 0===f&&(f=e.size);if(wb&&e.G)for(g=d;f--&&g<e.G.length;g++)e.G[g]=0;else for(g=d;f--&&g<e.size;g++)e.$b(d,0,e.F+d)}c-=a.ya;b++;d=0}this.g&&Lg(this,this.g,this.La,this.Ka,this.A,!0)}};
qg.prototype.reset=function(){if(this.v){for(var a=this.w,b=this.A,c=this.C,d=b&a.w,b=b>>>a.la;0<c&&b<a.W.length;){var e=a.W[b];if(e.controller&&a.g&&a.g.length==a.v.length){var f=a.g.indexOf(e);0<=f&&(e=a.v[f])}if(e){var f=c,g=0,h,d=d||0,g=g&255;void 0===f&&(f=e.size);if(wb&&e.G)for(h=d;f--&&h<e.G.length;h++)e.G[h]=g;else for(h=d;f--&&h<e.size;h++)e.$b(d,g,e.F+d)}c-=a.ya;b++;d=0}this.g&&Lg(this,this.g,this.La,this.Ka,this.A,!0)}};
function Lg(a,b,c,d,e,f){var g=!1;if(null==c)for(var h=0;h<b.length-1;){var l=b[h]&255|(b[h+1]&255)<<8;if(l)if(l&255){if(1!=l)break;if(h+6>=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<m&&h<b.length;)l+=b[h++]&255,m--;if(m||h>=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<b.length;e++)a.b.qb(c+
e,b[e]);null!=d&&ud(a.b,d,f);g=!0}return g}Xa(function(){for(var a=D(document,"pdp11","ram"),b=0;b<a.length;b++){var c=a[b],d=B(c),d=new qg(d);C(d,c)}});function Mg(a){u.call(this,"Keyboard",a,Mg,65536);H(this)}z(Mg);Mg.prototype.ta=function(){return!1};Mg.prototype.Ea=function(a,b,c,d){this.A=a;this.b=c;this.i=d};Xa(function(){for(var a=D(document,"pdp11","keyboard"),b=0;b<a.length;b++){var c=a[b],d=B(c),d=new Mg(d);C(d,c)}});
function Y(a){this.N=a.baudReceive||9600;this.R=a.baudTransmit||9600;this.da=a.upperCase;this.v=this.D=null;this.S=a.tabSize;this.P=a.charBOL;this.H=0;u.call(this,"SerialPort",a,Y,8388608);var b=a.binding;if("console"==b)this.D="";else{var c;a=Ng;b&&(void 0===c&&(c="Panel"),(c=qb(c,this.id))&&(b=c.G[b])&&this.ta(null,a,b))}this.J=this.L=null;this.exports={connect:this.wc,receiveData:this.ic}}z(Y);var Ng="buffer";k=Y.prototype;

View file

@ -155,7 +155,7 @@ function Ve(a){if(!Wa(a)){if(a.l){if(!a.b||!a.h)return;a.c||(a.c=a.b.length);if(
Ha(function(){for(var a=D(document,"pdp11","rom"),b=0;b<a.length;b++){var c=a[b],d=B(c),d=new Ue(d);C(d,c)}});
function We(a){x.call(this,"RAM",a,We);this.X=this.c=null;this.l=a.addr;this.i=a.size;this.ga=a.load;this.fa=a.exec;this.f=!1;this.b=a.file;this.m=q(this.b);if(this.b){a=this.b;var b=la(this.m);"json"!=b&&"hex"!=b&&(a=v()+"/api/v1/dump?file="+this.b+"&format=bytes&decimal=true");var c=this;r(a,null,!0,function(a,b,f){f?(c.F("Unable to load RAM resource (error "+f+": "+a+")"),c.b=null):(Sa(c.oa,a,b),(a=ta(a,b))?(c.c=a.K,c.X=a.X,null==c.ga&&(c.ga=a.ga),null==c.fa&&(c.fa=a.fa)):c.b=null);Xe(c)})}}z(We);
We.prototype.ia=function(a,b,c,d){this.h=b;this.a=c;this.D=d;Xe(this)};We.prototype.la=function(){this.X&&(this.D&&this.D.a(this.id,this.l,this.i,this.X),delete this.X);return!0};We.prototype.ka=function(){return!0};function Xe(a){if(a.h&&(!a.f&&a.i&&Eb(a.h,a.l,a.i,1)&&(a.f=!0),!Wa(a))){if(!a.f)u("No RAM allocated");else if(a.b){if(!a.c||!a.h)return;Ye(a,a.c,a.ga,a.fa,a.l)}F(a)}}
We.prototype.reset=function(){if(this.f){for(var a=this.h,b=this.l,c=this.i,d=b&a.l,b=b>>>a.c;0<c&&b<a.h.length;){var e=a.h[b];if(e.controller&&a.i&&a.i.length==a.v.length){var f=a.i.indexOf(e);0<=f&&(e=a.v[f])}if(e){var f=c,g,d=d||0;void 0===f&&(f=e.size);if(Ya&&e.o)for(g=d;f--&&g<e.o.length;g++)e.o[g]=0;else for(g=d;f--&&g<e.size;g++)e.Eb(d,0,e.Ja+d)}c-=a.b;b++;d=0}this.c&&Ye(this,this.c,this.ga,this.fa,this.l,!0)}};
We.prototype.reset=function(){if(this.f){for(var a=this.h,b=this.l,c=this.i,d=b&a.l,b=b>>>a.c;0<c&&b<a.h.length;){var e=a.h[b];if(e.controller&&a.i&&a.i.length==a.v.length){var f=a.i.indexOf(e);0<=f&&(e=a.v[f])}if(e){var f=c,g=0,k,d=d||0,g=g&255;void 0===f&&(f=e.size);if(Ya&&e.o)for(k=d;f--&&k<e.o.length;k++)e.o[k]=g;else for(k=d;f--&&k<e.size;k++)e.Eb(d,g,e.Ja+d)}c-=a.b;b++;d=0}this.c&&Ye(this,this.c,this.ga,this.fa,this.l,!0)}};
function Ye(a,b,c,d,e,f){var g=!1;if(null==c)for(var k=0;k<b.length-1;){var l=b[k]&255|(b[k+1]&255)<<8;if(l)if(l&255){if(1!=l)break;if(k+6>=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<n&&k<b.length;)l+=b[k++]&255,n--;if(n||k>=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<b.length;e++)a.a.Xa(c+
e,b[e]);null!=d&&zc(a.a,d,f);g=!0}return g}Ha(function(){for(var a=D(document,"pdp11","ram"),b=0;b<a.length;b++){var c=a[b],d=B(c),d=new We(d);C(d,c)}});function Ze(a){x.call(this,"Keyboard",a,Ze);F(this)}z(Ze);Ze.prototype.$=function(){return!1};Ze.prototype.ia=function(a,b,c,d){this.l=a;this.a=c;this.D=d};Ha(function(){for(var a=D(document,"pdp11","keyboard"),b=0;b<a.length;b++){var c=a[b],d=B(c),d=new Ze(d);C(d,c)}});
function Z(a){this.C=a.baudReceive||9600;this.I=a.baudTransmit||9600;this.R=a.upperCase;this.f=this.m=null;this.J=a.tabSize;this.G=a.charBOL;this.s=0;x.call(this,"SerialPort",a,Z);var b=a.binding;if("console"==b)this.m="";else{var c;a=$e;b&&(void 0===c&&(c="Panel"),(c=Ua(c,this.id))&&(b=c.o[b])&&this.$(null,a,b))}this.v=this.A=null;this.exports={connect:this.Kb,receiveData:this.yb}}z(Z);var $e="buffer";h=Z.prototype;