pcjs/versions/pdp11/1.24.2/pdp11.js

110 lines
45 KiB
JavaScript

(function(){var m;function aa(a){var b=16,c;if(a){b||(b=16);if("$"==a.charAt(0))b=16,a=a.substr(1);else if("0x"==a.substr(0,2))b=16,a=a.substr(2);else{var d=a.charAt(a.length-1).toLowerCase();"h"==d?(b=16,d=null):"."==d&&(b=10,d=null);null==d&&(a=a.substr(0,a.length-1))}var f,d=a,e=b;(e&&10!=e?16==e?null!==d.match(/^[0-9a-f]+$/i):2==e&&null!==d.match(/^[01]+$/i):null!==d.match(/^[0-9]+$/))&&!isNaN(f=parseInt(a,b))&&(c=f|0)}return c}
function n(a,b){var c="";void 0===b?b=8:8<b&&(b=8);if(null==a||isNaN(a))for(;0<b--;)c="?"+c;else for(;0<b--;){var d=a&15,d=d+(0<=d&&9>=d?48:55),c=String.fromCharCode(d)+c;a>>=4}return c}function ba(a){var b=a,c=a.lastIndexOf("/");0<=c&&(b=a.substr(c+1));c=b.indexOf("&");0<c&&(b=b.substr(0,c));return b}function ca(a){var b="",c=a.lastIndexOf(".");0<=c&&(b=a.substr(c+1).toLowerCase());return b}function da(){var a=p();return-1!==a.indexOf("pcjs.org",a.length-8)}
var ea={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};function fa(a){return a.replace(/[&<>"']/g,function(a){return ea[a]})}var q=Date.now||function(){return+new Date};function ga(){function a(a){return(10>a?"0":"")+a}var b=new Date;return b.getFullYear()+"-"+a(b.getMonth()+1)+"-"+a(b.getDate())+" "+a(b.getHours())+":"+a(b.getMinutes())+":"+a(b.getSeconds())}
function r(a,b,c,d){var f=0,e=null,h=null;if("object"==typeof resources&&(e=resources[a]))return d&&d(a,e,f),[e,f];if(c&&"function"==typeof resources)return resources(a,function(b,c){d&&d(a,b,c)}),h;var g=window.XMLHttpRequest?new window.XMLHttpRequest:new window.ActiveXObject("Microsoft.XMLHTTP");c&&(g.onreadystatechange=function(){4===g.readyState&&(e=g.responseText,200==g.status||!g.status&&e.length&&"file:"==(window?window.location.protocol:"file:")||(f=g.status||-1),d&&d(a,e,f))});if(b&&"object"==
typeof b){var k="",l;for(l in b)b.hasOwnProperty(l)&&(k&&(k+="&"),k+=l+"="+encodeURIComponent(b[l]));k=k.replace(/%20/g,"+");g.open("POST",a,!!c);g.setRequestHeader("Content-type","application/x-www-form-urlencoded");g.send(k)}else g.open("GET",a,!!c),"bytes"==b&&g.overrideMimeType("text/plain; charset=x-user-defined"),g.send();c||(e=g.responseText,200!=g.status&&(f=g.status||-1),d&&d(a,e,f),h=[e,f]);return h}function p(){return"http://"+(window?window.location.host:"www.pcjs.org")}
function t(a){window&&window.alert(a)}function ha(a){var b=!1;window&&(b=window.confirm(a));return b}var ia=null;function ja(){if(null==ia){var a=!1;if(window)try{window.localStorage.setItem("PCjs.localStorage","PCjs.localStorage"),a="PCjs.localStorage"==window.localStorage.getItem("PCjs.localStorage"),window.localStorage.removeItem("PCjs.localStorage")}catch(b){a=!1}ia=a}return ia}function ka(a){var b;if(window)try{b=window.localStorage.getItem(a)}catch(c){}return b}
function la(a,b){try{return window.localStorage.setItem(a,b),!0}catch(c){}return!1}function ma(a){if(window){var b=window?window.navigator.userAgent:"";return"iOS"==a&&b.match(/(iPod|iPhone|iPad)/)&&b.match(/AppleWebKit/)||"MSIE"==a&&b.match(/(MSIE|Trident)/)||0<=b.indexOf(a)?!0:!1}return!1}var u={init:[],show:[],exit:[]},na=!1,oa=!1,pa=!0;function qa(a,b){if(window){var c=window[a];window[a]="function"!==typeof c?b:function(){c&&c();b()}}}function v(a){u.init.push(a)}
function ra(a){if(pa)try{for(var b=0;b<a.length;b++)a[b]()}catch(c){t(""+("An unexpected exception occurred:\n\n"+c.message+"\n\nPlease send this information to support@pcjs.org. Thanks."))}}function sa(a){!pa&&a?(pa=!0,na&&ta("init"),oa&&ta("show")):pa=a}function ta(a){u[a]&&ra(u[a])}qa("onload",function(){na=!0;ra(u.init)});qa("onpageshow",function(){oa=!0;ra(u.show)});qa(ma("Opera")||ma("iOS")?"onunload":"onbeforeunload",function(){ra(u.exit)});
function w(a,b,c){this.type=a;b||(b={id:"",name:""});this.id=b.id||"";this.name=b.name;this.Na=b.comment;this.cb=b;b=this.id.indexOf(".");0>b?this.va=this.id:(this.Oa=this.id.substr(0,b),this.va=this.id.substr(b+1));this[a]=c;this.h={fa:!1,ia:!1,Ba:!1,w:!1,da:!1};this.sa=null;this.h.da=!1;this.o={};this.B=null;x.push(this)}var ua=void 0,va={};
if(window){ua||(ua=window.location.search.substr(1));for(var wa,xa=/\+/g,ya=/([^&=]+)=?([^&]*)/g;wa=ya.exec(ua);)va[decodeURIComponent(wa[1].replace(xa," "))]=decodeURIComponent(wa[2].replace(xa," "))}function za(a){function b(){}if(window){if(!a)throw new TypeError;if(Object.create)return Object.create(a);var c=typeof a;if("object"!==c&&"function"!==c)throw new TypeError;}b.prototype=a;return new b}
function y(a,b){b||(b=w);a.prototype=za(b.prototype);a.prototype.constructor=a;a.prototype.parent=b.prototype}if(window){window.PCjs||(window.PCjs={});var Aa=window.PCjs.Machines||(window.PCjs.Machines={}),x=window.PCjs.Components||(window.PCjs.Components=[])}else Aa={},x=[];function Ba(a,b,c){Aa[a]&&b&&(Aa[a][b]=c)}function A(a){var b,c=[];a&&(a=0<(b=a.indexOf("."))?a.substr(0,b+1):"");for(b=0;b<x.length;b++){var d=x[b];a&&d.id.indexOf(a)||c.push(d)}return c}
function Ca(a,b){var c;if(void 0!==a){var d;b&&(b=0<(d=b.indexOf("."))?b.substr(0,d+1):"");for(d=0;d<x.length;d++)if(c)c==x[d]&&(c=null);else if(!(a!=x[d].type||b&&x[d].id.indexOf(b)))return x[d]}return null}function B(a){var b=null;if(a=a.getAttribute("data-value"))try{b=eval("("+a+")")}catch(c){t(c.message+" ("+a+")")}return b}
function C(a,b){for(var c=D(b.parentNode,"pdp11-control"),d=0;d<c.length;d++)for(var f=c[d].childNodes,e=0;e<f.length;e++){var h=f[e];if(1===h.nodeType){var g=h.getAttribute("class");if(g)for(var k=g.split(" "),l=0;l<k.length;l++)switch(g=k[l],g){case "pdp11-binding":(g=B(h))&&g.binding&&a.L(g.type,g.binding,h,g.value),l=k.length}}}}
function D(a,b,c){c&&(b+="-"+c+"-object");if(a.getElementsByClassName)return a.getElementsByClassName(b);var d;c=[];a=a.getElementsByTagName("*");var f=new RegExp("(^| )"+b+"( |$)");b=0;for(d=a.length;b<d;b++)f.test(a[b].className)&&c.push(a[b]);return c}
w.prototype={constructor:w,parent:null,toString:function(){return this.name?this.name:this.id||this.type},L:function(a,b,c){switch(b){case "clear":return this.o[b]||(this.o[b]=c,c.onclick=function(a){return function(){a.o.print&&(a.o.print.value="")}}(this)),!0;case "print":return this.o[b]||(this.xa=this.o[b]=c,c.value="",this.K=function(a){return function(b,c){8192<a.value.length&&(a.value=a.value.substr(a.value.length-4096));a.value+=(void 0!==c?c+": ":"")+(b||"")+"\n";a.scrollTop=a.scrollHeight}}(c),
this.A=function(a){this.K(a,this.va)}),!0;default:return!1}},log:function(){},K:function(){},status:function(a){this.K(this.va+": "+a)},A:function(a,b,c){c=c||this.type;b||t((c?c+": ":"")+a)},Y:function(){return this.h.w=!0},X:function(a,b){b&&(this.h.w=!1);return!0}};function Da(a,b){if(a.h.Ba)return a.h.ia&&(a.h.ia=!1),a.h.Ba=!1;if(a.h.da)return a.K(a.toString()+" error"),!1;a.h.ia=b;return a.h.ia}function E(a){if(!a.h.da&&(a.h.fa=!0,a.h.fa)){var b=a.sa;a.sa=null;b&&b()}}
function Ea(a,b){b&&(a.h.fa?b():a.sa=b);return a.h.fa}var Fa="undefined"!==typeof ArrayBuffer;function Ga(a){w.call(this,"Panel",a,Ga)}y(Ga);m=Ga.prototype;m.L=function(a,b,c,d){return this.l&&this.l.L(a,b,c,d)||this.a&&this.a.L(a,b,c,d)?!0:this.parent.L.call(this,a,b,c,d)};m.ga=function(a,b,c,d){this.l=a;this.u=b;this.a=c;this.B=d};m.Y=function(a,b){b||Ha();return!0};m.X=function(){return!0};m.ea=function(){};
function Ha(){for(var a=!1,b=D(document,"pdp11","panel"),c=0;c<b.length;c++){var d=b[c],f=B(d),e;a:{e=f.id;if(void 0!==e)for(var h=void 0,h=0;h<x.length;h++)if(x[h].id===e){e=x[h];break a}e=null}e||(a=!0,e=new Ga(f));C(e,d);a&&E(e)}}v(Ha);
function Ia(a,b,c){w.call(this,"Bus",a,Ia);this.a=b;this.B=c;this.g=a.busWidth||16;this.j=Math.pow(2,this.g);this.u=this.j-1|0;this.f=16>=this.g?10:20>=this.g?12:24>=this.g?14:15;this.c=1<<this.f;this.l=this.c>>2;this.m=this.c-1;this.i=this.j/this.c|0;a=new F;Ja(a,this.B);this.b=Array(this.i);for(b=0;b<this.i;b++)this.b[b]=a;E(this)}y(Ia);Ia.prototype.reset=function(){};Ia.prototype.Y=function(a,b){b||this.reset();return!0};
function Ka(a,b,c,d){for(var f=b,e=c,h=f>>>a.f;0<e&&h<a.b.length;){var g=a.b[h],k=h*a.c,l=a.c-(f-k);l>e&&(l=e);if(g&&g.size){if(g.type==d){if(f+e<=g.ha)return g.ta+=g.ha-f,g.ha=f,!0;if(f>=g.ha+g.ta){l=g.size-(f-k);l>e&&(l=e);g.ta=f-g.ha+l;f=k+a.c;e-=l;h++;continue}}return La(1,f,e)}f=new F(f,l,a.c,d);Ja(f,a.B,g);a.b[h++]=f;f=k+a.c;e-=l}return 0>=e?(a.status(Math.floor(c/1024)+"Kb "+Ma[d]+" at "+("0x"+n(b,4))),!0):La(2,b,c)}
function La(a,b,c){t("Memory block error ("+a+": "+n(b)+","+n(c)+")");return!1}var Na;if(Fa){var Oa=new ArrayBuffer(2);(new DataView(Oa)).setUint16(0,256,!0);Na=256===(new Uint16Array(Oa))[0]}else Na=!1;var Pa=Na;
function F(a,b,c,d){this.id=Qa+=2;this.a=null;this.ha=a;this.ta=b;this.size=c||0;this.type=d||Ra;this.o=d==Sa;Ja(this);this.W=this.Za=!1;if(c)if(Fa)this.c=new ArrayBuffer(c),this.f=new DataView(this.c,0,c),this.b=new Uint8Array(this.c,0,c),this.j=new Uint16Array(this.c,0,c>>1),this.a=new Int32Array(this.c,0,c>>2),Ta(this,Pa?Ua:Va);else{this.a=Array(c>>2);for(a=0;a<this.a.length;a++)this.a[a]=0;Ta(this,Wa)}else Ta(this)}var Ra=0,Sa=2,Ma=["NONE","RAM","ROM","VID","H/W"],Qa=0;
F.prototype={constructor:F,parent:null,save:function(){var a,b;if(Fa)for(a=Array(this.size>>2),b=0;b<a.length;b++)a[b]=this.f.getInt32(b<<2,!0);else a=this.a;return a},restore:function(a){if(a&&this.size==a.length<<2){var b;if(Fa)for(b=0;b<a.length;b++)this.f.setInt32(b<<2,a[b],!0);else this.a=a;return this.W=!0}return!1},m:function(){return 255},s:function(){},J:function(a,b){return this.l(a++,b++)|this.l(a,b)<<8},$:function(a,b,c){this.u(a++,b&255,c++);this.u(a,b>>8,c)},G:function(a){return this.a[a>>
2]>>>((a&3)<<3)&255},P:function(a){var b=a>>2;a=(a&3)<<3;var c=this.a[b]>>a;return 24>a?c&65535:c&255|(this.a[b+1]&255)<<8},U:function(a,b){var c=a>>2,d=(a&3)<<3;this.a[c]=this.a[c]&~(255<<d)|b<<d;this.W=!0},ca:function(a,b){var c=a>>2,d=(a&3)<<3;24>d?this.a[c]=this.a[c]&~(65535<<d)|b<<d:(this.a[c]=this.a[c]&16777215|b<<24,c++,this.a[c]=this.a[c]&-256|b>>8);this.W=!0},C:function(a,b){return this.D(a,b)},I:function(a,b){return this.N(a,b)},S:function(a,b,c){this.o||this.Xa(a,b,c)},Z:function(a,b,c){this.o||
this.aa(a,b,c)},v:function(a){return this.b[a]},F:function(a){return this.b[a]},H:function(a){return this.f.getUint16(a,!0)},O:function(a){return a&1?this.b[a]|this.b[a+1]<<8:this.j[a>>1]},R:function(a,b){this.b[a]=b;this.W=!0},T:function(a,b){this.b[a]=b;this.W=!0},V:function(a,b){this.f.setUint16(a,b,!0);this.W=!0},ba:function(a,b){a&1?(this.b[a]=b,this.b[a+1]=b>>8):this.j[a>>1]=b;this.W=!0}};function Ja(a,b,c){a.B=b;a.g=a.i=0;c&&((a.g=c.g)&&Xa(a,Ya,!1),(a.i=c.i)&&Za(a,Ya,!1))}
function Za(a,b,c){c&&a.i||(a.u=!a.o&&b[2]||a.s);if(c||void 0===c)a.Xa=b[2]||a.s,a.aa=b[3]||a.$}function Xa(a,b,c){c&&a.g||(a.l=b[0]||a.m);if(c||void 0===c)a.D=b[0]||a.m,a.N=b[1]||a.J}function Ta(a,b){b||(b=$a);Xa(a,b,void 0);Za(a,b,void 0)}var $a=[],Wa=[F.prototype.G,F.prototype.P,F.prototype.U,F.prototype.ca],Ya=[F.prototype.C,F.prototype.I,F.prototype.S,F.prototype.Z];if(Fa)var Va=[F.prototype.v,F.prototype.H,F.prototype.R,F.prototype.V],Ua=[F.prototype.F,F.prototype.O,F.prototype.T,F.prototype.ba];
function ab(a,b){w.call(this,"CPU",a,ab);var c=a.multiplier||1;this.Ca=a.cycles||b;this.T=c;this.wa=Math.round(this.Ca/1E4)/100;this.R=this.wa*this.T;this.h.M=!1;this.h.Ka=!1;this.h.Ia=a.autoStart;this.h.Ja=!1;this.h.qa=!1;this.oa=this.S=0;this.pa=a.csStart;this.$=a.csInterval;this.aa=a.csStop;this.la=[];this.bb=this.Fa.bind(this);E(this)}y(ab);var bb=["power","reset"];m=ab.prototype;
m.ga=function(a,b,c,d){this.l=a;this.u=b;this.B=d;for(b=0;b<bb.length;b++)(c=this.o[bb[b]])&&this.l.L(null,bb[b],c);this.Z=null;a=cb(a,"autoStart");null!=a&&(this.h.Ia="true"==a?!0:"false"==a?!1:!!a);E(this)};m.reset=function(){};m.save=function(){return null};m.restore=function(){return!1};m.Y=function(a,b){if(!b){if(a&&this.restore){db(this);if(!this.restore(a))return!1;eb(this)}else this.reset();this.K("No debugger detected")}fb(this);return!0};m.X=function(a){return a?this.save():!0};
function gb(a){(a.h.Ia||void 0===a.o.run)&&a.Fa()}m.La=function(){return 0};function eb(a){void 0===a.pa&&(a.pa=0);void 0===a.$&&(a.$=-1);void 0===a.aa&&(a.aa=-1);a.h.qa=0<=a.pa&&0<a.$;a.h.qa&&(a.oa=0,a.S=a.pa-a.N)}function hb(a,b,c,d){a.o[b]&&(void 0===c&&(a.h.da=!0,a.A("Value for "+b+" is invalid"),G(a)),c=!a.h.M||a.h.Ja?n(c,d):"--------".substr(0,d),a.o[b].textContent!=c&&(a.o[b].textContent=c))}
m.L=function(a,b,c){var d=this;a=!1;switch(b){case "power":case "reset":this.o[b]=c;a=!0;break;case "run":this.o[b]=c;c.onclick=function(){var a;if(a=d.l)if(a=d.l,a.h.w)a=!0;else{var b=null,c,g=A(a.id);for(c=0;c<g.length&&(b=g[c],b===a||b.h.fa);c++);if(c==g.length)for(c=0;c<g.length&&(b=g[c],b===a||b.h.w);c++);c==g.length&&(b=a);t("The "+b.type+" component ("+b.id+") is not "+(b.h.fa?"powered yet":"ready yet"+(b.sa?" (waiting for notification)":""))+".");a=!1}a&&(d.h.M?G(d):d.Fa())};a=!0;break;case "speed":this.o[b]=
c;a=!0;break;case "setSpeed":this.o[b]=c,c.onclick=function(){ib(d,d.T<<1)},c.textContent=this.R.toFixed(2)+"Mhz",a=!0}return a};function jb(a,b,c){a.N+=b;c&&(a.J=a.G=0)}function kb(a,b){var c=1;b&&1<a.T&&a.H&&(c=a.H/a.wa);a.Sa=Math.round(1E3/30);a.ka=Math.floor(a.Ca/30*c);b||(a.ba=a.ka);a.Da=0}function lb(a){return a.N+a.F+a.J-a.G}function db(a){a.H=0;a.Ta=0;a.N=a.F=a.J=a.G=0;eb(a);ib(a,1)}
function ib(a,b){if(void 0!==b){.8>a.H/a.R&&(b=1);a.T=b;var c=a.wa*a.T;if(a.R!=c){a.R=c;var c=a.R.toFixed(2)+"Mhz",d=a.o.setSpeed;d&&(d.textContent=c);a.K("target speed: "+c)}}jb(a,a.F);a.F=0;a.D=q();a.I=0;kb(a)}function mb(a){a.J-=a.G;a.G=0}
m.Fa=function(){if(Da(this,!0)){if(!this.h.M){ib(this);this.l&&this.l.start(this.D,lb(this));this.h.M=!0;this.h.Ka=!0;this.Z&&this.Z.start();var a=this.o.run;a&&(a.textContent="Halt");this.l&&this.l.ea(!0)}this.Da>=this.Ca&&kb(this,!0);this.ca=0;this.na=q();this.I&&(a=this.na-this.I,a>this.Sa&&(this.D+=a,this.D>this.na&&(this.D=this.na)));try{do{for(var b=this.h.qa?1:this.ka,c=this.la.length-1;0<=c;c--){var d=this.la[c];0>d[0]||b>d[0]&&(b=d[0])}this.Wa(b);for(var f=this.J-this.G,a=f,e=this.la.length-
1;0<=e;e--){var h=this.la[e];0>h[0]||(h[0]-=a,0>=h[0]&&(h[0]=-1,h[1]()))}this.ca+=f;this.F+=f;jb(this,0,!0);a=f;if(this.h.qa){var g=!1;this.oa=this.oa+this.La()|0;this.S-=a;0>=this.S&&(this.S+=this.$,g=!0);0<=this.aa&&this.aa<=lb(this)&&(this.$=this.aa=-1,eb(this),G(this),g=!0);g&&this.K(lb(this)+" cycles: checksum="+n(this.oa))}this.ba-=f;if(0>=this.ba){this.ba+=this.ka;15<=++this.Ta&&(this.l&&this.l.ea(),this.Ta=0);break}}while(this.h.M)}catch(k){G(this);fb(this);this.l&&this.l.stop(q(),lb(this));
Da(this,!1);b=k.stack||k.message;this.h.da=!0;this.A(b);return}b=setTimeout;c=this.bb;this.I=q();d=this.Sa;this.ca&&(d=Math.round(d*this.ca/this.ka));d=d-(this.I-this.na);if(f=this.I-this.D)this.H=Math.round(this.F/(10*f))/100,864E5<=f&&(this.N=0,ib(this));if(0>d||this.H<this.R)-1E3>d&&(this.D-=d),d=0;this.Da+=this.ca;this.I+=d;b(c,d)}else fb(this),this.l&&this.l.stop(q(),lb(this))};m.Wa=function(){return 0};
function G(a){a.h.ia&&(a.h.Ba=!0);mb(a);jb(a,a.F);a.F=0;if(a.h.M){a.h.M=!1;a.Z&&a.Z.stop();var b=a.o.run;b&&(b.textContent="Run")}a.h.ra=void 0}function fb(a){a.l&&a.l.ea(void 0)}
function nb(a){this.ab=+a.model||1170;ab.call(this,a,1E6);db(this);this.h.ra=this.h.Ya=!1;this.Ma=0;this.g=65536;this.c=this.b=32768;this.f=65535;this.i=15;this.a=[0,0,0,0,0,0,0,0];this.Va=[0,0,0,0,0,0];this.U=[0,0,0,0];this.memory=[];this.s=[];this.Ea=this.Ua=0;this.O=2;this.P=255;this.m=0;this.V=-1;this.Ra=this.ya=this.Qa=this.j=this.ua=this.C=this.v=0;this.ma=[7,7,7,7];this.Aa=[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0],[65535,65535,65535,65535,65535,65535,65535,65535,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]];this.fb=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}y(nb,ab);m=nb.prototype;m.reset=function(){this.h.M&&G(this);ob(this);db(this);this.h.da=!1;this.parent.reset.call(this)};
function ob(a){a.P=255;a.s=[];a.Ua=0;a.v=a.C=a.ua=a.Qa=0;a.ma[0]=a.ma[1]=a.ma[3]=7;a.ya=0}m.La=function(){return 0};m.save=function(){var a=new H(this);I(a,0,[]);I(a,1,[this.Pa,this.N,this.T]);for(var b=this.u,c=0,d=[],f=0;f<b.i;f++){var e=b.b[f];if(e.W||e.Za){d[c++]=f;var h=c++;a:if(e=e.save()){for(var g=0,k=0,l=[];g<e.length;){for(var Q=e[g],z=g+1;z<e.length&&e[z]===Q;)z++;l[k++]=z-g;l[k++]=Q;g=z}if(l.length<e.length){e=l;break a}}d[h]=e}}I(a,2,d);return a.data()};
m.restore=function(a){var b=a[1];this.Pa=b[0];this.N=b[1];ib(this,b[3]);a:{b=this.u;a=a[2];var c;for(c=0;c<a.length-1;c+=2){var d=a[c],f=a[c+1];if(f&&f.length<b.l){for(var e=0,h=Array(b.l),g=0;g<f.length-1;)for(var k=f[g++],l=f[g++];k--;)h[e++]=l;f=h}e=b.b[d];if(!e||!e.restore(f)){t("Unable to restore memory block "+d);b=!1;break a}}b=!0}return b};
m.L=function(a,b,c){var d=!1;switch(b){case "PC":case "PSW":case "IF":case "SF":case "ZF":case "CF":this.o[b]=c;this.Ma++;d=!0;break;default:d=this.parent.L.call(this,a,b,c)}return d};m.ea=function(a){this.Ma&&(a||!this.h.M||this.h.Ja)&&(a=this.i&-14|0|(this.eb&255?0:4)|(this.eb&256?1:0),hb(this,"PSW",a,4),hb(this,"SF",a&8?1:0,1),hb(this,"ZF",a&4?1:0,1),hb(this,"CF",a&1?1:0,1));if(a=this.o.speed)a.textContent=this.h.M&&this.H?this.H.toFixed(2)+"Mhz":"Stopped"};
function pb(a,b){var c,d;a.b=b<<12;a.f=~b&4;a.c=b<<14;a.g=b<<16;if((b^a.i)&2048)for(c=0;6>c;c++)d=a.a[c],a.a[c]=a.Va[c],a.Va[c]=d;(a.j=b>>14&3)!==(d=a.i>>14&3)&&(a.U[d]=a.a[6],a.a[6]=a.U[a.j]);a.O=2;a.i=b}
function J(a,b){var c,d,f=0;0>a.V?(a.i=a.i&63728|a.b>>12&8|a.c>>14&2|a.g>>16&1,a.f&65535||(a.i|=4),a.V=a.i):a.j||(b=4,f=1);a.v&57344||(a.C=63222);a.j=0;0<=(c=K(a,b|65536))&&0<=(d=K(a,b+2&65535|65536))&&(pb(a,d&53247|a.V>>2&12288),f&&(a.a[6]=4),0<=L(a,a.V)&&0<=L(a,a.a[7])&&(a.a[7]=c));a.m=0;return a.V=-1}
function qb(a,b,c){var d,f,e,h=0;if(c&a.Qa){d=b>>13&a.ma[a.j];f=a.Aa[a.j][d];e=(a.Aa[a.j][d+16]<<6)+(b&8191)&4194303;if(a.ua&16){if(3932160<=e&&4186112>e){e=e&262143;var g=e>>13&31;31>g?a.ua&32&&(e=a.fb[g]+(e&8190)&4194302,3932160<=e&&4186112>e&&console.log("panic(898)")):e|=4186112}}else e&=262143,253952<=e&&(e|=4186112);if(3932160>e&&(3915776<=e||e&1&&!(c&1)))return J(a,4);switch(f&7){case 1:h=4096;case 2:f|=128;c&4&&(h=8192);break;case 4:h=4096;case 5:c&4&&(h=4096);case 6:f|=c&4?192:128;break;
default:h=32768}32512!==(f&32520)&&(f&8?f&32512&&(b&8128)<(f>>2&8128)&&(h|=16384):(b&8128)>(f>>2&8128)&&(h|=16384));a.Aa[a.j][d]=f;if(4194170!==e||a.j)a.ya=a.j,a.Ra=d;if(h){if(h&57344)return 0<=a.V&&(h|=128),a.v&57344||(a.v=a.v|h|a.ya<<5|a.Ra<<1),J(a,168);a.v&61440||!(4191360>e||4194239<e)||(a.v|=4096,a.v&512&&(a.m|=2))}}else if(e=b&65535,57344<=e)e|=4186112;else if(e&1&&!(c&1))return J(a,4);return e}function M(a,b){return 4194304<=b?a.a[b-4194304]:3932160<=b?-1:0<=b?a.memory[b>>1]:b}
function N(a,b,c){c&=65535;return 4194304<=b?a.a[b-4194304]=c:3932160<=b?-1:0<=b?a.memory[b>>1]=c:b}function O(a,b){var c;return 4194304<=b?a.a[b-4194304]&255:3932160<=b?-1:0<=b?(c=a.memory[b>>1],b&1&&(c=c>>8),c&255):b}function P(a,b,c){c&=255;return 4194304<=b?a.a[b-4194304]=a.a[b-4194304]&65280|c:3932160<=b?-1:0<=b?b&1?a.memory[b>>1]=c<<8|a.memory[b>>1]&255:a.memory[b>>1]=a.memory[b>>1]&65280|c:b}function K(a,b){return M(a,qb(a,b,2))}
function rb(a){var b=K(a,a.a[6]|65536);0<=b&&(a.a[6]=a.a[6]+2&65535);return b}function L(a,b){var c,d;a.a[6]=d=a.a[6]-2&65535;a.v&57344||(a.C=a.C<<8|246);if(!a.j&&d<=a.P&&4<d){if(d<=a.P-32)return a.a[6]=4,J(a,4);a.m|=4}return 0<=(c=qb(a,d|65536,4))?N(a,c,b):c}
function R(a,b,c){var d,f,e=b&7;switch(b>>3&7){case 0:return J(a,4);case 1:if(6===e&&!a.j&&c&4&&(a.a[6]<=a.P||65534<=a.a[6])){if(a.a[6]<=a.P-32||65534<=a.a[6])return a.a[6]=4,J(a,4);a.m|=4}return 7===e?a.a[e]:a.a[e]|65536;case 2:f=2;d=a.a[e];7!==e&&(d|=65536,6>e&&c&1&&(f=1));break;case 3:f=2;d=a.a[e];7!==e&&(d|=65536);if(0>(d=K(a,d)))return d;d|=65536;break;case 4:f=-2;6>e&&c&1&&(f=-1);d=a.a[e]+f&65535;7!==e&&(d|=65536);break;case 5:f=-2;d=a.a[e]-2&65535;7!==e&&(d|=65536);if(0>(d=K(a,d)))return d;
d|=65536;break;case 6:if(0>(d=K(a,a.a[7])))return d;a.a[7]=a.a[7]+2&65535;d=d+a.a[e]&65535;return d|65536;case 7:if(0>(d=K(a,a.a[7])))return d;a.a[7]=a.a[7]+2&65535;d=d+a.a[e]&65535;return 0>(d=K(a,d|65536))?d:d|65536}a.a[e]=a.a[e]+f&65535;a.v&57344||(a.C=a.C<<8|f<<3&248|e);if(6===e&&!a.j&&c&4&&0>=f&&(a.a[6]<=a.P||65534<=a.a[6])){if(a.a[6]<=a.P-32)return a.a[6]=4,J(a,4);a.m|=4}return d}function S(a,b,c){var d;return b&56?(0<=(d=R(a,b,c))&&(d=qb(a,d,c)),d):4194304+(b&7)}
function T(a,b){var c;b&56?0<=(c=S(a,b,2))&&(c=M(a,c)):c=a.a[b&7];return c}function U(a,b){var c;b&56?0<=(c=S(a,b,3))&&(c=O(a,c)):c=a.a[b&7]&255;return c}function V(a,b){return((b&128?b|65280:b&255)<<1)+a&65535}
m.Wa=function(a){this.h.ra=!0;this.h.Ya=!1;this.h.Ka=!1;this.J=this.G=a;this.Pa&256?(mb(this),a=!1):a=!0;if(a){do{var b,c,d,f,e;if(this.O)if(1===this.O)this.O=2;else{this.O=0;e=-1;b=this.Ua&224;if(0<(a=this.s.length))for(;0<a--;){if(0<this.s[a].za){this.s[a].za--;this.O=2;break}if(this.s[a].Ga){if(!this.s[a].Ga()){this.s.splice(a,1);e--;continue}this.s[a].Ga=null}this.s[a].$a>b&&(b=this.s[a].$a,e=a)}b>(this.i&224)&&(0>e?J(this,160):(J(this,this.s[e].gb),this.s.splice(e,1)))}this.v&57344||(this.C=
0);this.m=this.i&16;if(0<=(a=K(this,this.a[7])))switch(this.a[7]=this.a[7]+2&65535,a&61440){case 4096:0<=(b=T(this,a>>6))&&(a&56?0<=(d=S(this,a,4))&&0<=N(this,d,b)&&(this.b=this.f=b,this.c=0):(this.b=this.f=this.a[a&7]=b,this.c=0));break;case 8192:0<=(b=T(this,a>>6))&&0<=(c=T(this,a))&&(this.b=this.f=this.g=a=b-c,this.c=(b^c)&(b^a));break;case 12288:0<=(b=T(this,a>>6))&&0<=(c=T(this,a))&&(this.b=this.f=b&c,this.c=0);break;case 16384:0<=(b=T(this,a>>6))&&(a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=c&~b,
0<=N(this,d,a)&&(this.b=this.f=a,this.c=0)):(this.b=this.f=a=this.a[a&7]&=~b,this.c=0));break;case 20480:0<=(b=T(this,a>>6))&&(a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=c|b,0<=N(this,d,a)&&(this.b=this.f=a,this.c=0)):(this.b=this.f=a=this.a[a&7]|=b,this.c=0));break;case 24576:0<=(b=T(this,a>>6))&&(a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=b+c,0<=N(this,d,a)&&(this.b=this.f=this.g=a,this.c=(b^a)&(c^a))):(e=a&7,c=this.a[e],this.a[e]=(a=b+c)&65535,this.b=this.f=this.g=a,this.c=(b^a)&(c^a)));break;case 36864:0<=
(b=U(this,a>>6))&&(a&56?0<=(d=S(this,a,5))&&0<=P(this,d,b)&&(this.b=this.f=b<<8,this.c=0):(b&128&&(b|=65280),this.b=this.f=this.a[a&7]=b,this.c=0));break;case 40960:0<=(b=U(this,a>>6))&&0<=(c=U(this,a))&&(a=b-c,this.b=this.f=this.g=a<<8,this.c=((b^c)&(b^a))<<8);break;case 45056:0<=(b=U(this,a>>6))&&0<=(c=U(this,a))&&(this.b=this.f=(b&c)<<8,this.c=0);break;case 49152:0<=(b=U(this,a>>6))&&0<=(c=O(this,d=S(this,a,7)))&&(a=c&~b,0<=P(this,d,a)&&(this.b=this.f=a<<8,this.c=0));break;case 53248:0<=(b=U(this,
a>>6))&&0<=(c=O(this,d=S(this,a,7)))&&(a=c|b,0<=P(this,d,a)&&(this.b=this.f=a<<8,this.c=0));break;case 57344:0<=(b=T(this,a>>6))&&(a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=c-b,0<=N(this,d,a)&&(this.b=this.f=this.g=a,this.c=(b^c)&(c^a))):(e=a&7,c=this.a[e],this.a[e]=(a=c-b)&65535,this.b=this.f=this.g=a,this.c=(b^c)&(c^a)));break;default:switch(a&65024){case 2048:0<=(f=R(this,a,0))&&(e=a>>6&7,0<=L(this,this.a[e])&&(this.a[e]=this.a[7],this.a[7]=f&65535));break;case 28672:0<=(b=T(this,a))&&(e=a>>6&7,b&
32768&&(b|=-65536),c=this.a[e],c&32768&&(c|=-65536),a=~~(b*c),this.a[e]=a>>16&65535,this.a[e|1]=a&65535,this.b=a>>16,this.f=this.b|a,this.g=this.c=0,-32768>a||32767<a)&&(this.g=65536);break;case 29184:0<=(b=T(this,a))&&(b?(e=a>>6&7,c=this.a[e]<<16|this.a[e|1],this.g=this.c=0,b&32768&&(b|=-65536),a=~~(c/b),-32768<=a&&32767>=a?(this.a[e]=a&65535,this.a[e|1]=c-a*b&65535,this.f=a>>16|a,this.b=a>>16):(this.c=32768,this.f=a>>15|a,this.b=c>>16,-1===b&&65534===this.a[e]&&(this.a[e]=this.a[e|1]=1))):(this.f=
this.b=0,this.c=32768,this.g=65536));break;case 29696:0<=(b=T(this,a))&&(e=a>>6&7,a=this.a[e],a&32768&&(a|=4294901760),this.g=this.c=0,b&=63,b&32?(b=64-b,16<b&&(b=16),this.g=a<<17-b,a=a>>b):b&&(16<b?(this.c=a,a=0):(this.g=a=a<<b,(c=a>>15&65535)&&65535!==c&&(this.c=32768))),this.a[e]=a&65535,this.b=this.f=a);break;case 30208:if(0<=(b=T(this,a))){e=a>>6&7;c=this.a[e]<<16|this.a[e|1];this.g=this.c=0;b&=63;if(b&32)b=64-b,32<b&&(b=32),a=c>>b-1,this.g=a<<16,a>>=1,c&2147483648&&(a|=4294967295<<32-b);else if(b){if(a=
c<<b-1,this.g=a>>15,a<<=1,32<b&&(b=32),c>>=32-b)c|=4294967295<<b&4294967295,4294967295!==c&&(this.c=32768)}else a=c;this.a[e]=a>>16&65535;this.a[e|1]=a&65535;this.b=a>>16;this.f=a>>16|a}break;case 30720:a&56?0<=(c=M(this,d=S(this,a,6)))&&(c^=this.a[a>>6&7],0<=N(this,d,c)&&(this.b=this.f=c,this.c=0)):(this.b=this.f=c=this.a[a&7]^=this.a[a>>6&7],this.c=0);break;case 32256:e=a>>6&7;if(this.a[e]=this.a[e]-1&65535)this.a[7]=this.a[7]-((a&63)<<1)&65535;break;default:switch(a&65280){case 256:this.a[7]=V(this.a[7],
a);break;case 512:this.f&65535&&(this.a[7]=V(this.a[7],a));break;case 768:this.f&65535||(this.a[7]=V(this.a[7],a));break;case 1024:(this.b&32768)===(this.c&32768)&&(this.a[7]=V(this.a[7],a));break;case 1280:(this.b&32768)!==(this.c&32768)&&(this.a[7]=V(this.a[7],a));break;case 1536:this.f&65535&&(this.b&32768)===(this.c&32768)&&(this.a[7]=V(this.a[7],a));break;case 1792:this.f&65535&&(this.b&32768)===(this.c&32768)||(this.a[7]=V(this.a[7],a));break;case 32768:this.b&32768||(this.a[7]=V(this.a[7],
a));break;case 33280:!(this.g&65536)&&this.f&65535&&(this.a[7]=V(this.a[7],a));break;case 33024:this.b&32768&&(this.a[7]=V(this.a[7],a));break;case 33536:if(this.g&65536||!(this.f&65535))this.a[7]=V(this.a[7],a);break;case 33792:this.c&32768||(this.a[7]=V(this.a[7],a));break;case 34048:this.c&32768&&(this.a[7]=V(this.a[7],a));break;case 34304:this.g&65536||(this.a[7]=V(this.a[7],a));break;case 34560:this.g&65536&&(this.a[7]=V(this.a[7],a));break;case 34816:J(this,24);break;case 35072:J(this,28);break;
default:switch(a&65472){case 64:0<=(f=R(this,a,0))&&(this.a[7]=f&65535);break;case 192:a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=c<<8|c>>8,0<=N(this,d,a)&&(this.b=this.f=c&65280,this.c=this.g=0)):(e=a&7,c=this.a[e],this.a[e]=(c<<8|c>>8)&65535,this.b=this.f=c&65280,this.c=this.g=0);break;case 2560:a&56?0<=(d=S(this,a,4))&&0<=N(this,d,0)&&(this.b=this.g=this.c=this.f=0):this.b=this.g=this.c=this.f=this.a[a&7]=0;break;case 2624:0<=(c=M(this,d=S(this,a,6)))&&(a=~c,0<=N(this,d,a)&&(this.b=this.f=a,this.g=
65536,this.c=0));break;case 2688:a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=c+1,0<=N(this,d,a)&&(this.b=this.f=a,this.c=a&(a^c))):(e=a&7,c=this.a[e],a=c+1,this.a[e]=a&65535,this.b=this.f=a,this.c=a&(a^c));break;case 2752:a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=c-1,0<=N(this,d,a)&&(this.b=this.f=a,this.c=(a^c)&c)):(e=a&7,c=this.a[e],a=c-1,this.a[e]=a&65535,this.b=this.f=a,this.c=(a^c)&c);break;case 2816:0<=(c=M(this,d=S(this,a,6)))&&(a=-c,0<=N(this,d,a)&&(this.g=this.b=this.f=a,this.c=a&c));break;case 2880:0<=
(c=M(this,d=S(this,a,6)))&&(a=c+(this.g>>16&1),0<=N(this,d,a)&&(this.g=this.b=this.f=a,this.c=a&(a^c)));break;case 2944:0<=(c=M(this,d=S(this,a,6)))&&(a=c-(this.g>>16&1),0<=N(this,d,a)&&(this.g=this.b=this.f=a,this.c=(a^c)&c));break;case 3008:0<=(c=T(this,a))&&(this.b=this.f=c,this.g=this.c=0);break;case 3072:a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=(this.g&65536|c)>>1,0<=N(this,d,a)&&(this.g=c<<16,this.b=this.f=a,this.c=a^this.g>>1)):(e=a&7,c=this.a[e],a=(this.g&65536|c)>>1,this.a[e]=a&65535,this.g=
c<<16,this.b=this.f=a,this.c=a^this.g>>1);break;case 3136:a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=c<<1|this.g>>16&1,0<=N(this,d,a)&&(this.g=this.b=this.f=a,this.c=a^c)):(e=a&7,c=this.a[e],a=c<<1|this.g>>16&1,this.a[e]=a&65535,this.g=this.b=this.f=a,this.c=a^c);break;case 3200:a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=c&32768|c>>1,0<=N(this,d,a)&&(this.g=c<<16,this.b=this.f=a,this.c=this.b^this.g>>1)):(e=a&7,c=this.a[e],a=c&32768|c>>1,this.a[e]=a&65535,this.g=c<<16,this.b=this.f=a,this.c=this.b^this.g>>
1);break;case 3264:a&56?0<=(c=M(this,d=S(this,a,6)))&&(a=c<<1,0<=N(this,d,a)&&(this.g=this.b=this.f=a,this.c=a^c)):(e=a&7,c=this.a[e],a=c<<1,this.a[e]=a&65535,this.g=this.b=this.f=a,this.c=a^c);break;case 3328:f=this.a[7]+((a&63)<<1)&65535;0<=(b=K(this,f|65536))&&(this.a[7]=this.a[5],this.a[5]=b,this.a[6]=f+2&65535);break;case 3392:a&56?0<=(f=R(this,a,0))&&(61440!==(this.i&61440)&&(f&=65535),this.j=this.i>>12&3,0<=(b=K(this,f))&&(this.j=this.i>>14&3,0<=L(this,b)&&(this.b=this.f=b,this.c=0))):(e=a&
7,b=6!==e||(this.i>>2&12288)===(this.i&12288)?this.a[e]:this.U[this.i>>12&3],0<=L(this,b)&&(this.b=this.f=b,this.c=0));break;case 3456:0<=(c=rb(this))&&((this.v&57344||(this.C=22),a&56)?0<=(f=R(this,a,0))&&(f&=65535,this.j=this.i>>12&3,0<=(d=qb(this,f,4))&&(this.j=this.i>>14&3,0<=N(this,d,c)&&(this.b=this.f=c,this.c=0))):(e=a&7,6!==e||(this.i>>2&12288)===(this.i&12288)?this.a[e]=c:this.U[this.i>>12&3]=c,this.b=this.f=c,this.c=0));break;case 3520:0<=(d=S(this,a,4))&&(a=-(this.b>>15&1),0<=N(this,d,
a)&&(this.f=a,this.c=0));break;case 35328:a&56?0<=(d=S(this,a,5))&&0<=P(this,d,0)&&(this.b=this.g=this.c=this.f=0):(this.a[a&7]&=65280,this.b=this.g=this.c=this.f=0);break;case 35392:0<=(c=O(this,d=S(this,a,7)))&&(a=~c,0<=P(this,d,a)&&(this.b=this.f=a<<8,this.g=65536,this.c=0));break;case 35456:0<=(c=O(this,d=S(this,a,7)))&&(a=c+1,0<=P(this,d,a)&&(this.b=this.f=a<<8,this.c=(a&(a^c))<<8));break;case 35520:0<=(c=O(this,d=S(this,a,7)))&&(a=c-1,0<=P(this,d,a)&&(this.b=this.f=a<<8,this.c=((a^c)&c)<<8));
break;case 35584:0<=(c=O(this,d=S(this,a,7)))&&(a=-c,0<=P(this,d,a)&&(this.g=this.b=this.f=a<<8,this.c=(a&c)<<8));break;case 35648:0<=(c=O(this,d=S(this,a,7)))&&(a=c+(this.g>>16&1),0<=P(this,d,a)&&(this.b=this.f=this.g=a<<8,this.c=(a&(a^c))<<8));break;case 35712:0<=(c=O(this,d=S(this,a,7)))&&(a=c-(this.g>>16&1),0<=P(this,d,a)&&(this.b=this.f=this.g=a<<8,this.c=((a^c)&c)<<8));break;case 35776:0<=(c=U(this,a))&&(this.b=this.f=c<<8,this.g=this.c=0);break;case 35840:0<=(c=O(this,d=S(this,a,7)))&&(a=((this.g&
65536)>>8|c)>>1,0<=P(this,d,a)&&(this.g=c<<16,this.b=this.f=a<<8,this.c=this.b^this.g>>1));break;case 35904:0<=(c=O(this,d=S(this,a,7)))&&(a=c<<1|this.g>>16&1,0<=P(this,d,a)&&(this.g=this.b=this.f=a<<8,this.c=(a^c)<<8));break;case 35968:0<=(c=O(this,d=S(this,a,7)))&&(a=c&128|c>>1,0<=P(this,d,a)&&(this.g=c<<16,this.b=this.f=a<<8,this.c=this.b^this.g>>1));break;case 36032:0<=(c=O(this,d=S(this,a,7)))&&(a=c<<1,0<=P(this,d,a)&&(this.g=this.b=this.f=a<<8,this.c=(a^c)<<8));break;case 36160:a&56?0<=(f=R(this,
a,0))&&(this.j=this.i>>12&3,0<=(b=K(this,f|65536))&&(this.j=this.i>>14&3,0<=L(this,b)&&(this.b=this.f=b,this.c=0))):(e=a&7,b=6!==e||(this.i>>2&12288)===(this.i&12288)?this.a[e]:this.U[this.i>>12&3],0<=L(this,b)&&(this.b=this.f=b,this.c=0));break;case 36224:0<=(c=rb(this))&&((this.v&57344||(this.C=22),a&56)?0<=(f=R(this,a,0))&&(this.j=this.i>>12&3,0<=(d=qb(this,f|65536,4))&&(this.j=this.i>>14&3,0<=N(this,d,c)&&(this.b=this.f=c,this.c=0))):(e=a&7,6!==e||(this.i>>2&12288)===(this.i&12288)?this.a[e]=
c:this.U[this.i>>12&3]=c,this.b=this.f=c,this.c=0));break;default:switch(a&65528){case 128:0<=(b=rb(this))&&(e=a&7,this.a[7]=this.a[e],this.a[e]=b);break;case 152:this.i&49152||(this.i=this.i&63519|(a&7)<<5,this.O=1);break;case 160:case 168:a&1&&(this.g=0);a&2&&(this.c=0);a&4&&(this.f=1);a&8&&(this.b=0);break;case 176:case 184:a&1&&(this.g=65536);a&2&&(this.c=32768);a&4&&(this.f=0);a&8&&(this.b=32768);break;default:switch(a){case 0:49152&this.i?J(this,4):(this.Ea=3,mb(this),console.log("HALT at "+
this.a[7].toString(8)));break;case 1:e=0;if(0<(a=this.s.length))for(;0<a--;)e+=this.s[a].za,this.s[a].za=0;0===e&&0===this.Ea&&(this.Ea=2,mb(this));break;case 3:J(this,12);break;case 4:J(this,16);break;case 5:this.i&49152||ob(this);break;case 2:case 6:d=this.a[6];0<=(f=K(this,d|65536))&&(d=d+2&65535,0<=(b=K(this,d|65536))&&(this.a[6]=d+2&65535,b&=63743,this.i&49152&&(b=b&63519|this.i&63712),this.a[7]=f,pb(this,b),this.m&=-17,2===a&&(this.m|=this.i&16)));break;default:J(this,8)}}}}}}this.m&&(this.m&
2?J(this,168):this.m&4?J(this,4):this.m&16&&J(this,12),this.m=0)}while(0<this.G)}return this.h.ra?this.J-this.G:void 0===this.h.ra?0:-1};v(function(){for(var a=D(document,"pdp11","cpu"),b=0;b<a.length;b++){var c=a[b],d=B(c),d=new nb(d);C(d,c)}});
function W(a){w.call(this,"ROM",a,W);this.b=null;this.j=a.addr;this.c=a.size;this.l=a.writable;this.f=a.alias;this.g=a.file;this.m=ba(this.g);if(this.g){a=this.g;var b=ca(this.m);"json"!=b&&"hex"!=b&&(a=p()+"/api/v1/dump?file="+this.g+"&format=bytes&decimal=true");var c=this;r(a,null,!0,function(a,b,e){sb(c,a,b,e)})}}y(W);W.prototype.ga=function(a,b,c,d){this.u=b;this.a=c;this.B=d;tb(this)};W.prototype.Y=function(){this.i&&(this.B&&this.B.a(this.id,this.j,this.c,this.i),delete this.i);return!0};
W.prototype.X=function(){return!0};
function sb(a,b,c,d){if(d)a.A("Unable to load system ROM (error "+d+": "+b+")");else{Ba(a.Oa,b,c);if("["==c.charAt(0)||"{"==c.charAt(0))try{var f=eval("("+c+")"),e=f.bytes,h=f.data;if(e)a.b=e;else if(h)for(a.b=Array(4*h.length),d=c=0;c<h.length;c++)a.b[d++]=h[c]&255,a.b[d++]=h[c]>>8&255,a.b[d++]=h[c]>>16&255,a.b[d++]=h[c]>>24&255;else a.b=f;a.i=f.symbols;if(!a.b.length){t("Empty ROM: "+b);return}if(1==a.b.length){t(a.b[0]);return}}catch(g){a.A("ROM data error: "+g.message);return}else for(b=c.replace(/\n/gm,
" ").replace(/ +$/,"").split(" "),a.b=Array(b.length),f=0;f<b.length;f++)a.b[f]=aa(b[f]);tb(a)}}
function tb(a){if(!Ea(a))if(!a.g)E(a);else if(a.b&&a.u){a.c||(a.c=a.b.length);if(a.b.length!=a.c){var b="ROM size (0x"+n(a.b.length)+") does not match specified size ("+("0x"+n(a.c))+")";a.h.da=!0;a.A(b)}else{b=a.j;if(Ka(a.u,b,a.c,a.l?1:Sa)){var c;for(c=0;c<a.b.length;c++){var d=a.u,f=b+c;d.b[(f&d.u)>>>d.f].Xa(f&d.m,a.b[c]&255,f)}b=!0}else b=!1;if(b){b=[];"number"==typeof a.f?b.push(a.f):null!=a.f&&a.f.length&&(b=a.f);for(c=0;c<b.length;c++){for(var e=a,d=b[c],f=e.u,h=e.c,g=[],k=e.j>>>f.f;0<h&&k<
f.b.length;)g.push(f.b[k++]),h-=f.c;f=e.u;e=e.c;h=0;for(d>>>=f.f;0<e&&d<f.b.length;){k=g[h++];if(!k)break;f.b[d++]=k;e-=f.c}}delete a.b}}E(a)}}v(function(){for(var a=D(document,"pdp11","rom"),b=0;b<a.length;b++){var c=a[b],d=B(c),d=new W(d);C(d,c)}});function ub(a){w.call(this,"RAM",a,ub);this.f=a.addr;this.c=a.size;this.b=!1}y(ub);m=ub.prototype;m.ga=function(a,b,c,d){this.u=b;this.a=c;this.B=d;E(this)};m.Y=function(a,b){b||this.reset();return!0};m.X=function(a){return a?this.save():!0};
m.reset=function(){!this.b&&this.c&&Ka(this.u,this.f,this.c,1)&&(this.b=!0);this.b||t("No RAM allocated")};m.save=function(){return null};m.restore=function(){return!0};v(function(){for(var a=D(document,"pdp11","ram"),b=0;b<a.length;b++){var c=a[b],d=B(c),d=new ub(d);C(d,c)}});function vb(a){w.call(this,"Keyboard",a,vb);E(this)}y(vb);vb.prototype.L=function(){return!1};vb.prototype.ga=function(a,b,c,d){this.l=a;this.a=c;this.B=d;this.Z=null};
v(function(){for(var a=D(document,"pdp11","keyboard"),b=0;b<a.length;b++){var c=a[b],d=B(c),d=new vb(d);C(d,c)}});
function wb(a,b,c){w.call(this,"Computer",a,wb);this.h.w=!1;xb(this,b);this.v=cb(this,"autoPower",a);this.f=0;this.H=a.busWidth||a.buswidth;this.b=X;this.m=null;this.j=this.F=!1;this.I=cb(this,"url")||"";(Math.random()+.1).toString(36);this.c=yb(this);if(this.a=Ca("CPU",this.id)){this.B=Ca("Debugger",this.id);this.u=new Ia({id:this.Oa+".bus",busWidth:this.H},this.a,this.B);var d,f=A(this.id);if((this.g=Ca("Panel",this.id))&&this.g.xa)for(b=0;b<f.length;b++)d=f[b],d.A=this.g.A,d.K=this.g.K,d.xa=this.g.xa;
this.K("PDP11 v1.24.2\nCopyright \u00a9 2012-2016 Jeff Parsons <Jeff@pcjs.org>\nLicense: GPL version 3 or later <http://gnu.org/licenses/gpl.html>");for(b=0;b<f.length;b++)d=f[b],d.ga&&d.ga(this,this.u,this.a,this.B);b=null;d=a.resume;void 0!==d&&(1<d.length?b=this.l=d:this.b=parseInt(d,10));var e;if(a=cb(this,"state")||(e=!0,a.state))b=this.C=a,e||(this.j=!0,this.b=X),this.b&&(this.s=new H(this,"1.24.2"),Y(this.s)?b=null:delete this.s);!b&&this.b&&(b=zb(this))&&(this.j=!0);if(b){var h=this;r(b,null,
!0,function(a,b,c){c?(h.l=null,h.j=!1,h.A("Unable to load machine state from server (error "+c+(b?": "+(String.prototype.trim?b.trim():b.replace(/^\s+|\s+$/g,"")):"")+")")):(h.m=b,h.F=!0);E(h)})}else E(this);this.o.power||(this.v=!0);!c&&this.v&&Ab(this,this.ja)}else t("Unable to find CPU component")}y(wb);var X=0;function xb(a,b){if(!b){var c;if("object"==typeof resources&&(c=resources.parms))try{b=eval("("+c+")")}catch(d){t(d.message+" ("+c+")")}}a.G=b}
function cb(a,b,c){var d=b.toLowerCase(),d=va[b]||va[d];void 0===d&&a.G&&(d=a.G[b]);void 0===d&&c&&(d=c[b]);void 0===d&&"object"==typeof resources&&resources[b]&&(d=b);return d}function Ab(a,b,c){for(var d=A(a.id),f=0;f<=d.length;f++){var e=f<d.length?d[f]:a;if(!Ea(e)){Ea(e,function(){Ab(a,b,c)});return}}b.call(a,c)}
function Bb(a,b){var c=new H(a,"1.24.2","validate");if(Y(c)&&Cb(c)){var d=Z(c,"timestamp"),f=b?Z(b,"timestamp"):"unknown";d!=f&&(a.A("Machine state may be out-of-date\n("+d+" vs. "+f+")\nCheck your browser's local storage limits"),b||c.clear())}}m=wb.prototype;
m.ja=function(a){void 0===a&&(a=this.b||(this.m?1:X));if(!this.f){this.f++;var b=!1,c=!1;this.D=!1;var d=this.s||new H(this,"1.24.2");if(-1==a)b=!0;else if(a>X){if(Y(d,this.m)){this.i=new H(this,"1.24.2","failsafe");Y(this.i)&&(Db(this,d),a=2,Eb(this.i));I(this.i,"timestamp",ga());Fb(this.i);var f=this.b&&!this.j;if(1==a||ha("Click OK to restore the previous PDP11 machine state, or CANCEL to reset the machine.")){if(c=Cb(d)){var e=Z(d,"code"),h=Z(d,"data");e&&("ok"==e?Y(d,h):("error"==e&&"no machine state"!=
h?(this.A("Error: "+h),"unable to verify user"==h&&(la("user",""),this.c=null)):this.K(e+": "+h),Eb(d),Y(d)?(c=Cb(d),f=!0):c=!1))}f&&Bb(this,c?d:null)}else 2==a&&d.clear()}else Bb(this);delete this.m;delete this.s}f=A(this.id);for(e=0;e<f.length;e++)h=f[e],h!==this&&h!=this.a&&(c=Gb(this,h,d,b,c));b=[d,a,c];-1!=a?Ab(this,this.Ha,b):this.Ha(b)}};
function Gb(a,b,c,d,f){if(!b.h.w){b.h.w=!0;if(b.Y){var e=null;f&&((e=Z(c,b.id))||(e=Z(c,b.id.replace(/[a-z0-9]\./i,"."))));"string"===typeof e&&(e=null);!b.Y(e,d)&&e&&(t("Unable to restore state for "+b.type),a.C&&!a.F?(c.clear(),a.b=X,window&&window.location.reload()):a.D=!0,b.Y(null),f=!1)}if(!d&&b.Na)for(a=b.Na.split("|"),c=0;c<a.length;c++)b.status(a[c])}return f}
m.Ha=function(a){var b=a[0],c=0>a[1];a=a[2];this.J=!0;this.h.w=!0;var d=this.o.power;d&&(d.textContent="Shutdown");this.a&&(Gb(this,this.a,b,c,a),gb(this.a));this.D&&(Db(this,b),b.clear());!c&&this.i&&(this.i.clear(),delete this.i);this.f=0};
function Db(a,b){if(ha("There may be a problem with your PDP11 machine.\n\nTo help us diagnose it, click OK to send this PDP11 machine state to http://www.pcjs.org.")){var c=a.c||"",d=b.toString(),f={app:"PDP11",ver:"1.24.2"};f.url=a.I;f.user=c;f.type="bug";f.data=d;r("http://www.pcjs.org/api/v1/report",f,!0)}}
function Hb(a,b,c){var d,f="none";if(a.f)return null;a.f--;var e=new H(a,"1.24.2"),h=new H(a,"1.24.2","validate"),g=ga();I(h,"timestamp",g);I(e,"timestamp",g);I(e,"version","1.24.2");I(e,"url",window?window.location.href:null);I(e,"browser",window?window.navigator.userAgent:"");a.a&&a.a.X&&(c&&G(a.a),d=a.a.X(b,c),"object"===typeof d&&I(e,a.a.id,d),c&&(a.a.h.w=!1,!1===d&&(f=null)));for(var g=A(a.id),k=0;k<g.length;k++){var l=g[k];l.h.w&&(l.X&&(d=l.X(b,c),"object"===typeof d&&I(e,l.id,d)),c&&(l.h.w=
!1,!1===d&&(f=null)))}f&&(c?(g=d=!1,b?(a.c&&Ib(a,a.c,e.toString()),Fb(h)&&Fb(e)||(f=null,d=g=!0)):a.b&&(d=!0,g=3==a.b),d&&e.clear(g)):f=e.toString());c&&(a.h.w=!1,b=a.o.power)&&(b.textContent="Power");a.f=0;return f}m.reset=function(){this.u&&this.u.reset&&this.u.reset();for(var a=A(this.id),b=0;b<a.length;b++){var c=a[b];c!==this&&c!==this.u&&c.reset&&c.reset()}};m.start=function(a,b){for(var c=A(this.id),d=0;d<c.length;d++){var f=c[d];"CPU"!=f.type&&f!==this&&f.start&&f.start(a,b)}};
m.stop=function(a,b){for(var c=A(this.id),d=0;d<c.length;d++){var f=c[d];"CPU"!=f.type&&f!==this&&f.stop&&f.stop(a,b)}};
m.L=function(a,b,c){var d=this;switch(b){case "power":return this.o[b]=c,c.onclick=function(){d.f||(d.h.w?Hb(d,!1,!0):Ab(d,d.ja))},!0;case "reset":return this.o[b]=c,c.onclick=function(){if(d.h.w&&!d.f)if(d.b&&!d.l){var a=ha("Click OK to save changes to this PDP11 machine.\n\nWARNING: If you CANCEL, all disk changes will be discarded.");Hb(d,a,!0);!a&&d.C?window&&window.location.reload():d.ja(X)}else d.reset(),d.a&&gb(d.a)},!0;case "save":if(da()){c.parentNode.removeChild(c);break}this.o[b]=c;c.onclick=
function(){var a=yb(d,!0);if(a){var b=!!(d.b&&!d.l||d.C),c=Hb(d,b);b?Ib(d,a,c):d.A("Resume disabled, machine state not saved")}};return!0}return!1};function yb(a,b){var c=a.c;c||(c=ka("user"),void 0!==c?!c&&b&&(c=null,window&&(c=window.prompt("Saving machine states on the pcjs.org server is currently unsupported.\n\nIf you're running your own server, enter your user ID below.","")),c&&((c=Jb(a,c))||a.A("The user ID is invalid."))):b&&a.A("Browser local storage is not available"));return c}
function Jb(a,b){a.c=null;var c=r(p()+"/api/v1/user?req=verify&user="+b),d=c[1];if(!c[0]&&d)try{c=eval("("+d+")"),c.code&&"ok"==c.code&&(la("user",c.data),a.c=c.data)}catch(f){t(f.message+" ("+d+")")}return a.c}function zb(a){var b=null;a.c&&(b=p()+"/api/v1/user?req=load&user="+a.c+"&state="+Kb(a,"1.24.2"));return b}
function Ib(a,b,c){if(c){var d={req:"store"};d.user=b;d.state=Kb(a,"1.24.2");d.data=c;b=r(p()+"/api/v1/user",d);d=b[0];if(b[1]){if(d){var f=d.indexOf("\n");0<f&&(d=d.substr(0,f));d.indexOf("Error: ")||(d=d.substr(7))}d='{"code":'+b[1]+',"data":"'+d+'"}'}b=JSON.parse(d);b&&"ok"==b.code?a.A("Machine state saved to server"):c&&(c=b&&b.data||"unable to save machine state",c="error"==b.code?"Error: "+c:"Error "+b.code+": "+c,a.A(c),la("user",""),a.c=null)}}
m.ea=function(a){this.a&&this.a.ea(a);this.g&&this.g.ea(a)};v(function(){for(var a=D(document,"pdp11-machine"),b=0;b<a.length;b++)for(var c=a[b],d=B(c),c=D(c,"pdp11","computer"),f=0;f<c.length;f++){var e=c[f],h=B(e),h=new wb(h,d,!0);C(h,e);h.v&&Ab(h,h.ja)}});u.show.push(function(){for(var a=D(document,"pdp11","computer"),b=0;b<a.length;b++){var c=B(a[b]);(c=Ca("Computer",c.id))&&c.J&&!c.h.w&&c.ja(-1)}});
u.exit.push(function(){for(var a=D(document,"pdp11","computer"),b=0;b<a.length;b++){var c=B(a[b]);(c=Ca("Computer",c.id))&&c.h.w&&Hb(c,!(!c.b||c.l),!0)}});function H(a,b,c){this.id=a.id;this.key=Kb(a,b,c);this.B=a.B;Eb(this,a.cb)}function Kb(a,b,c){a=a.id;if(b){var d=b.indexOf(".");0<d&&(a+=".v"+b.substr(0,d))}c&&(a+="."+c);return a}
H.prototype={constructor:H,value:function(){return this[this.id]},data:function(){return this[this.id]},toString:function(){var a=this[this.id];return"string"==typeof a?a:JSON.stringify(a)},clear:function(a){Eb(this);var b=[];try{for(var c=0,d=window.localStorage.length;c<d;c++)b.push(window.localStorage.key(c))}catch(f){}for(c=0;c<b.length;c++)if((d=b[c])&&(a||d.substr(0,this.key.length)==this.key)){try{window.localStorage.removeItem(d)}catch(f){}b.splice(c,1);c=0}}};
function Eb(a,b){a[a.id]={};b&&I(a,"parms",b);a.a=!1}function Fb(a){var b=!0;if(ja()){var c=JSON.stringify(a[a.id]);la(a.key,c)||(t("Unable to store "+c.length+" bytes in browser local storage"),b=!1)}return b}function Cb(a){var b=!0;try{a[a.id]=JSON.parse(a[a.id])}catch(c){t(c.message||c),b=!1}return b}function Y(a,b){return b?(a[a.id]=b,a.a=!0):a.a?!0:ja()&&(b=ka(a.key))?(a[a.id]=b,a.a=!0):!1}function Z(a,b){return a[a.id][b]||null}function I(a,b,c){try{a[a.id][b]=c}catch(d){}}var Lb=0;
function Mb(a,b,c,d,f,e){f("Loading "+a+"...");r(a,null,!0,function(h,g,k){k?(g||(g="unable to load "+a+" ("+k+")"),e(g,null)):Nb(g,a,b,c,d,f,e)})}
function Nb(a,b,c,d,f,e,h){function g(a,e){if(e)h(e,null);else{if(c){Ba(c,b,a);var g=b;g&&0>g.indexOf("/")&&"/"==window.location.pathname.slice(-1)&&(g=window.location.pathname+g);d?"}"==d.slice(-1)?(d=d.slice(0,-1),1<d.length&&(d+=",")):d='{state:"'+d+'",':d="{";d+='url:"'+g+'"}';"object"==typeof resources&&(g=null);a=a.replace(/(<machine[^>]*\sid=)(['"]).*?\2/,"$1$2"+c+"$2"+(d?" parms='"+d+"'":"")+(g?' url="'+g+'"':""))}f||(a=a.replace(/(<xsl:variable name="APPCLASS">).*?(<\/xsl:variable>)/,"$1pdp11$2"));
g=null;if("<"==a.charAt(0))try{f||(a=a.replace(/<!DOCTYPE(.|[\r\n])*]>\s*/g,"")),window.ActiveXObject||"ActiveXObject"in window?(g=new window.ActiveXObject("Microsoft.XMLDOM"),g.async=!1,g.loadXML(a)):g=(new window.DOMParser).parseFromString(a,"text/xml")}catch(z){g=null,a=z.message}else a="unrecognized XML: "+(255<a.length?a.substr(0,255)+"...":a);h(a,g)}}a?f?Ob(a,e,g):g(a,null):h("no data"+(b?" for file: "+b:""),null)}
function Ob(a,b,c){var d;if(d=/<([a-z]+)\s+ref="(.*?)"(.*?)\/>/g.exec(a)){var f=d[2];b("Loading "+f+"...");r(f,null,!0,function(e,h,g){if(g||!h)c(a,"unable to resolve XML reference: "+d[0]+" ("+g+")");else{if(e=d[3])if(g=h.match(new RegExp("<"+d[1]+"[^>]*>"))){for(var k=g[0],l,Q=/( [a-z]+=)(['"])(.*?)\2/g;l=Q.exec(e);)k=0>k.indexOf(l[1])?k.replace(">",l[0]+">"):k.replace(new RegExp(l[1]+"(['\"])(.*?)\\1"),l[0]);g[0]!=k&&(h=h.replace(g[0],k))}else{c(a,"missing <"+d[1]+"> in "+f);return}h=h.replace(/<\?xml[^>]*>[\r\n]*/,
"");a=a.replace(d[0],h);Ob(a,b,c)}})}else c(a,null)}
function Pb(a,b,c,d){function f(a){if(void 0===g){var b=h&&D(h,"machine-warning");g=b&&b[0]||h}g&&(g.innerHTML=fa(a))}function e(a){f("Error: "+a);k&&(--Lb||sa(!0));k=!1}var h,g,k=!0;Lb++;Aa[a]={};try{if(h=document.getElementById(a)){var l;if("object"==typeof resources&&(l=resources.css)){var Q=document.head||document.getElementsByTagName("head")[0],z=document.createElement("style");z.type="text/css";z.styleSheet?z.styleSheet.cssText=l:z.appendChild(document.createTextNode(l));Q.appendChild(z)}c||
(c="/versions/pdp11/1.24.2/components.xsl");l=function(d,g){g?Mb(c,null,null,!1,f,function(d,k){if(k)if(Ba(a,c,d),f("Processing "+b+"..."),window.ActiveXObject||"ActiveXObject"in window){var l=g.transformNode(k);l?(h.outerHTML=l,--Lb||sa(!0)):e("transformNodeToObject failed")}else document.implementation&&document.implementation.createDocument?(l=new XSLTProcessor,l.importStylesheet(k),(l=l.transformToFragment(g,document))?h.parentNode?(h.parentNode.replaceChild(l,h),--Lb||sa(!0)):e("invalid machine element: "+
a):e("transformToFragment failed")):e("unable to transform XML: unsupported browser");else e(d)}):e(d)};"<"!=b.charAt(0)?Mb(b,a,d,!0,f,l):Nb(b,null,a,d,!1,f,l)}else e("missing machine element: "+a)}catch(Qb){e(Qb.message)}return k}window.embedPDP11=function(a,b,c,d){sa(!1);return Pb(a,b,c,d)};window.enableEvents=sa;window.sendEvent=ta;})();