Allow a machine's 'resume' property to be set by the web page, not just the machine file

This commit is contained in:
Jeff Parsons 2017-01-28 23:22:16 -08:00 • committed by Jeff Parsons
commit 7157c7e7b8
9 changed files with 52 additions and 38 deletions

View file

@ -250,13 +250,13 @@ h.Wd=function(a,b,c,d,e,f){this.o=f&65535;this.a=this.a&~X.va|f>>16-X.S.va&X.va;
h.yg=function(a){this.a=this.a&~X.Ta|a&X.Ta;this.i=this.i&60|(a&X.va)>>X.S.va;if(!(this.a&X.wa)){a=!0;var b,c=this.b[(this.a&X.Ma)>>X.S.Ma],d=c.V,e,f,g;this.a&=~X.Xa;switch(this.a&X.ra){case Pg.fe:this.l&Qg.Sc&&(this.a&=X.Xa|X.ra|X.va);this.l=c.status|this.g&Z.Rb|(d&&512==d.N?Qg.Id:0);break;case Pg.Sb:(this.f&Z.Hd)==Z.ce&&(b=this.f&Z.vb,c=(this.f&Z.ee)<<2,this.g=this.f&Z.de?this.g+b:this.g-b,this.f=this.g=this.g&Z.vb|c);break;case Pg.Qd:this.l=this.g;break;case Pg.Od:b=this.Gb;case Pg.je:b||(b=this.gc),
e=this.f>>Z.S.vb,f=this.f&Z.Rb?1:0,g=this.f&Z.ed,!d||e>=d.N||g>=d.P?this.a=this.a|Y.ya|X.tb:(a=65536-this.l&65535,d=(this.i&Og.vc)<<16|this.o,a=b.call(this,c,e,f,g,a,d,2,!1,this.Wd.bind(this)))}a&&(this.a=this.a|X.Xa|X.wa,this.a&X.tc&&oc(this.c,this.jb))}};h.mf=function(){return this.o};h.wg=function(a){this.o=a&Rg.Ta};h.qf=function(){return this.f};h.zg=function(a){this.f=a};h.rf=function(){return this.l};h.Ag=function(a){this.l=a};h.nf=function(){return this.i};
h.xg=function(a){this.i=a&Og.vc;this.a=this.a&~X.va|(this.i&3)<<X.S.va};var X=D.Zd,Rg=D.Xd,Z=D.$d,Qg=D.Qb,Og=D.Yd,Y=D.Qc,Pg=D.ra,Sg={},Ng=(Sg[63744]=[null,null,L.prototype.pf,L.prototype.yg,"RLCS"],Sg[63746]=[null,null,L.prototype.mf,L.prototype.wg,"RLBA"],Sg[63748]=[null,null,L.prototype.qf,L.prototype.zg,"RLDA"],Sg[63750]=[null,null,L.prototype.rf,L.prototype.Ag,"RLMP"],Sg[63752]=[null,null,L.prototype.nf,L.prototype.xg,"RLBE"],Sg);
function Tg(a,b,c){q.call(this,"Computer",a,33554432);this.j.O=!1;this.D=null;Ug(this,b);this.w=Tc(this,"autoPower",a,6);this.g=0;this.J=+a.busWidth||+a.buswidth;this.s=this.o=this.v=null;this.l=this.I=!1;this.i=this.h=null;this.H=this.B=this.C=!1;this.K=Tc(this,"url")||"";(Math.random()+.1).toString(36);this.b=Vg(this);if(this.c=za("CPU",this.id)){this.F=za("Debugger",this.id);this.u=new Sb({id:this.Na+".bus",busWidth:this.J},this.c,this.F);var d,e=xa(this.id);if((this.f=za("Panel",this.id))&&this.f.gb)for(b=
0;b<e.length;b++)d=e[b],d.G=this.f.G,d.Z=this.f.Z,d.gb=this.f.gb;this.Z(hb+" v1.32.2\nCopyright \u00a9 2012-2017 Jeff Parsons <Jeff@pcjs.org>\nLicense: GPL version 3 or later <http://gnu.org/licenses/gpl.html>");this.Z("Portions adapted from the PDP-11/70 Emulator by Paul Nankervis <http://skn.noip.me/pdp11/pdp11.html>");for(b=0;b<e.length;b++)d=e[b],d.ha&&d.ha(this,this.u,this.c,this.F);this.a=Tc(this,"resume",a,4,Wg);var f;b=null;if(a=Tc(this,"state")||(f=!0,a.state))this.v=b=a,f||(this.l=!0,this.a=
Wg),this.a&&(this.i=new E(this,"1.32.2"),Xg(this.i)?b=null:delete this.i);!b&&this.a&&(b=Yg(this))&&(this.l=!0);if(b){var g=this;Oa(b,null,!0,function(a,b,c){c?(g.o=null,g.l=!1,g.G("Unable to load machine state from server (error "+c+(b?": "+Ka(b):"")+")")):(g.s=b,g.I=!0);B(g)})}else B(this);this.m.power||(this.w=!0);!c&&this.w&&Zg(this,this.Fb)}else u("Unable to find CPU component")}n(Tg,q);
function Ug(a,b){if(!b){var c;if("object"==typeof resources&&(c=resources.parms))try{b=eval("("+c+")")}catch(d){u(d.message+" ("+c+")")}}a.D=b}function Tc(a,b,c,d,e){var f=b.toLowerCase(),f=Wa(b)||Wa(f);void 0===f&&a.D&&(f=a.D[b]);void 0===f&&c&&(f=c[b]);void 0===f&&"object"==typeof resources&&resources[b]&&(f=b);void 0===f&&(f=e);if("string"==typeof f&&d)switch(d){case 4:f=+f;isNaN(f)&&(f=e||0);break;case 6:f="true"==f}return f}
function Tg(a,b,c){q.call(this,"Computer",a,33554432);this.j.O=!1;this.D=null;Ug(this,b);this.w=Tc(this,"autoPower",a,6);this.g=0;this.J=+a.busWidth||+a.buswidth;this.s=this.i=this.v=null;this.o=this.I=!1;this.l=this.h=null;this.H=this.B=this.C=!1;this.K=Tc(this,"url")||"";(Math.random()+.1).toString(36);this.b=Vg(this);if(this.c=za("CPU",this.id)){this.F=za("Debugger",this.id);this.u=new Sb({id:this.Na+".bus",busWidth:this.J},this.c,this.F);var d,e=xa(this.id);if((this.f=za("Panel",this.id))&&this.f.gb)for(b=
0;b<e.length;b++)d=e[b],d.G=this.f.G,d.Z=this.f.Z,d.gb=this.f.gb;this.Z(hb+" v1.32.2\nCopyright \u00a9 2012-2017 Jeff Parsons <Jeff@pcjs.org>\nLicense: GPL version 3 or later <http://gnu.org/licenses/gpl.html>");this.Z("Portions adapted from the PDP-11/70 Emulator by Paul Nankervis <http://skn.noip.me/pdp11/pdp11.html>");for(b=0;b<e.length;b++)d=e[b],d.ha&&d.ha(this,this.u,this.c,this.F);b=null;d=Tc(this,"resume",a);void 0!==d&&(1<d.length?b=this.i=d:this.a=parseInt(d,10));var f;if(a=Tc(this,"state")||
(f=!0,a.state))this.v=b=a,f||(this.o=!0,this.a=Wg),this.a&&(this.l=new E(this,"1.32.2"),Xg(this.l)?b=null:delete this.l);!b&&this.a&&(b=Yg(this))&&(this.o=!0);if(b){var g=this;Oa(b,null,!0,function(a,b,c){c?(g.i=null,g.o=!1,g.G("Unable to load machine state from server (error "+c+(b?": "+Ka(b):"")+")")):(g.s=b,g.I=!0);B(g)})}else B(this);this.m.power||(this.w=!0);!c&&this.w&&Zg(this,this.Fb)}else u("Unable to find CPU component")}n(Tg,q);
function Ug(a,b){if(!b){var c;if("object"==typeof resources&&(c=resources.parms))try{b=eval("("+c+")")}catch(d){u(d.message+" ("+c+")")}}a.D=b}function Tc(a,b,c,d){var e=b.toLowerCase(),e=Wa(b)||Wa(e);void 0===e&&a.D&&(e=a.D[b]);void 0===e&&c&&(e=c[b]);void 0===e&&"object"==typeof resources&&resources[b]&&(e=b);void 0===e&&(e=void 0);if("string"==typeof e&&d)switch(d){case 4:e=+e;isNaN(e)&&(e=0);break;case 6:e="true"==e}return e}
function Zg(a,b,c){for(var d=xa(a.id),e=0;e<=d.length;e++){var f=e<d.length?d[e]:a;if(!Aa(f)){Aa(f,function(){Zg(a,b,c)});return}}b.call(a,c)}function $g(a,b){var c=new E(a,"1.32.2",ah);if(Xg(c)&&bh(c)){var d=c.get(ch),e=b?b.get(ch):"unknown";d!=e&&(a.G("Machine state may be out-of-date\n("+d+" vs. "+e+")\nCheck your browser's local storage limits"),b||c.clear())}}h=Tg.prototype;
h.Fb=function(a){void 0===a&&(a=this.a||(this.s?dh:Wg));if(!this.g){this.g++;var b=!1,c=!1;this.C=!1;var d=this.i||new E(this,"1.32.2");if(a==eh)b=!0;else if(a>Wg){if(Xg(d,this.s)){this.h=new E(this,"1.32.2",fh);Xg(this.h)&&(ih(this,d),a=jh,kh(this.h));this.h.set(ch,Na());lh(this.h);var e=this.a&&!this.l;if(a==dh||wa("Click OK to restore the previous "+hb+" machine state, or CANCEL to reset the machine.")){if(c=bh(d)){var f=d.get("code"),g=d.get("data");f&&("ok"==f?Xg(d,g):("error"==f&&"no machine state"!=
g?(this.G("Error: "+g),"unable to verify user"==g&&(Ua(mh,""),this.b=null)):this.Z(f+": "+g),kh(d),Xg(d)?(c=bh(d),e=!0):c=!1))}e&&$g(this,c?d:null)}else a==jh&&d.clear()}else $g(this);delete this.s;delete this.i}e=xa(this.id);for(f=0;f<e.length;f++)g=e[f],g!==this&&g!=this.c&&(c=nh(this,g,d,b,c));b=[d,a,c];a!=eh?Zg(this,this.md,b):this.md(b)}};
h.Fb=function(a){void 0===a&&(a=this.a||(this.s?dh:Wg));if(!this.g){this.g++;var b=!1,c=!1;this.C=!1;var d=this.l||new E(this,"1.32.2");if(a==eh)b=!0;else if(a>Wg){if(Xg(d,this.s)){this.h=new E(this,"1.32.2",fh);Xg(this.h)&&(ih(this,d),a=jh,kh(this.h));this.h.set(ch,Na());lh(this.h);var e=this.a&&!this.o;if(a==dh||wa("Click OK to restore the previous "+hb+" machine state, or CANCEL to reset the machine.")){if(c=bh(d)){var f=d.get("code"),g=d.get("data");f&&("ok"==f?Xg(d,g):("error"==f&&"no machine state"!=
g?(this.G("Error: "+g),"unable to verify user"==g&&(Ua(mh,""),this.b=null)):this.Z(f+": "+g),kh(d),Xg(d)?(c=bh(d),e=!0):c=!1))}e&&$g(this,c?d:null)}else a==jh&&d.clear()}else $g(this);delete this.s;delete this.l}e=xa(this.id);for(f=0;f<e.length;f++)g=e[f],g!==this&&g!=this.c&&(c=nh(this,g,d,b,c));b=[d,a,c];a!=eh?Zg(this,this.md,b):this.md(b)}};
function nh(a,b,c,d,e){if(!b.j.O){b.j.O=!0;var f=null;try{if(e&&((f=c.get(b.id))||(f=c.get(b.id.replace(/[a-z0-9]\./i,".")))),"string"===typeof f&&(f=null),!b.ja(f,d)&&f&&(u("Unable to restore state for "+b.type),a.v&&!a.I?(c.clear(),a.a=Wg,window&&window.location.reload()):a.C=!0,b.ja(null),e=!1),!d&&b.Zc){var g=b.Zc.split("|");for(a=0;a<g.length;a++)b.status(g[a])}}catch(k){u("Error restoring state for "+b.type+" ("+k.message+")")}}return e}
h.md=function(a){var b=a[0],c=0>a[1];a=a[2];this.H=!0;this.j.O=!0;var d=this.m.power;d&&(d.textContent="Shutdown");this.c&&(nh(this,this.c,b,c,a),Kb(this,-2),this.c.Y());this.C&&(ih(this,b),b.clear());!c&&this.h&&(this.h.clear(),delete this.h);this.g=0};
function ih(a,b){if(wa("There may be a problem with your "+hb+" machine.\n\nTo help us diagnose it, click OK to send this "+hb+" machine state to http://www.pcjs.org.")){var c=a.K;a=a.b||"";b=b.toString();var d={};d.app=hb;d.ver="1.32.2";d.url=c;d.user=a;d.type="bug";d.data=b;Oa("http://www.pcjs.org/api/v1/report",d,!0)}}
@ -265,12 +265,12 @@ function oh(a,b,c){var d,e="none";if(a.g)return null;a.g--;var f=new E(a,"1.32.2
h.start=function(a,b){for(var c=xa(this.id),d=0;d<c.length;d++){var e=c[d];"CPU"!=e.type&&e!==this&&e.start&&e.start(a,b)}Kb(this,-1)};h.stop=function(a,b){for(var c=xa(this.id),d=0;d<c.length;d++){var e=c[d];"CPU"!=e.type&&e!==this&&e.stop&&e.stop(a,b)}Kb(this,-1)};
function Kb(a,b){if(a.c){var c=a.c,d=b||0,e=c.m.speed;e&&(0>=d||30<=(c.Lc+=d))&&(e.textContent=c.j.L?c.Oa.toFixed(2)+"Mhz":"Stopped",c.Lc=0)}if(a.f&&(a=a.f,b=b||0,a.l)){c=a.c.j.L;d=!!(a.c.g&8);if(0>=b||60<=(a.i+=b)){for(e=0;e<a.c.b.length;e++)Ab(a,"R"+e,a.c.b[e]);e=zc(a.c);Ab(a,"PS",e);Ab(a,"NF",e&8?1:0,1);Ab(a,"ZF",e&4?1:0,1);Ab(a,"VF",e&2?1:0,1);Ab(a,"CF",e&1?1:0,1);a.i=0}-1>b?a.U=a.c.b[7]:0<b&&c&&!d&&(a.U=a.c.Ea);wb(a,a.U);nb(a,a.f);b=a.c;b=b.bb?b.qa&16?1:2:4;Pb(a,"B22",b&1);Pb(a,"B18",b&2);Pb(a,
"B16",b&4)}}
h.ka=function(a,b,c){var d=this;switch(b){case "power":return this.m[b]=c,c.onclick=function(){d.g||(d.j.O?oh(d,!1,!0):Zg(d,d.Fb))},!0;case "reset":return this.m[b]=c,c.onclick=function(){if(d.j.O&&!d.g)if(d.a&&!d.o){var a=wa("Click OK to save changes to this "+hb+" machine.\n\nWARNING: If you CANCEL, all disk changes will be discarded.");oh(d,a,!0);!a&&d.v?window&&window.location.reload():(a||(d.B=!0),d.Fb(Wg),d.B=!1)}else d.reset(),d.c&&d.c.Y()},!0;case "save":if(Ha(Qa(),"pcjs.org"))c.parentNode.removeChild(c);else return this.m[b]=
c,c.onclick=function(){var a=Vg(d,!0);if(a){var b=!!(d.a&&!d.o||d.v),c=oh(d,b);b?sh(d,a,c):d.G("Resume disabled, machine state not saved")}},!0}return!1};function Vg(a,b){var c=a.b;c||((c=Ta(mh),void 0!==c)?!c&&b&&(b=null,window&&(b=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=b)&&((c=uh(a,c))||a.G("The user ID is invalid.")):b&&a.G("Browser local storage is not available"));return c}
h.ka=function(a,b,c){var d=this;switch(b){case "power":return this.m[b]=c,c.onclick=function(){d.g||(d.j.O?oh(d,!1,!0):Zg(d,d.Fb))},!0;case "reset":return this.m[b]=c,c.onclick=function(){if(d.j.O&&!d.g)if(d.a&&!d.i){var a=wa("Click OK to save changes to this "+hb+" machine.\n\nWARNING: If you CANCEL, all disk changes will be discarded.");oh(d,a,!0);!a&&d.v?window&&window.location.reload():(a||(d.B=!0),d.Fb(Wg),d.B=!1)}else d.reset(),d.c&&d.c.Y()},!0;case "save":if(Ha(Qa(),"pcjs.org"))c.parentNode.removeChild(c);else return this.m[b]=
c,c.onclick=function(){var a=Vg(d,!0);if(a){var b=!!(d.a&&!d.i||d.v),c=oh(d,b);b?sh(d,a,c):d.G("Resume disabled, machine state not saved")}},!0}return!1};function Vg(a,b){var c=a.b;c||((c=Ta(mh),void 0!==c)?!c&&b&&(b=null,window&&(b=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=b)&&((c=uh(a,c))||a.G("The user ID is invalid.")):b&&a.G("Browser local storage is not available"));return c}
function uh(a,b){a.b=null;b=Oa(Qa()+"/api/v1/user?req=verify&user="+b);var c=b[1];if(!b[0]&&c)try{b=eval("("+c+")"),b.code&&"ok"==b.code&&(Ua(mh,b.data),a.b=b.data)}catch(d){u(d.message+" ("+c+")")}return a.b}function Yg(a){var b=null;a.b&&(b=Qa()+"/api/v1/user?req=load&user="+a.b+"&state="+vh(a,"1.32.2"));return b}
function sh(a,b,c){if(c){var d={req:"store"};d.user=b;d.state=vh(a,"1.32.2");d.data=c;b=Oa(Qa()+"/api/v1/user",d);d=b[0];if(b[1]){if(d){var e=d.indexOf("\n");0<e&&(d=d.substr(0,e));d.indexOf("Error: ")||(d=d.substr(7))}d='{"code":'+b[1]+',"data":"'+d+'"}'}b=JSON.parse(d);b&&"ok"==b.code?a.G("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.G(c),Ua(mh,""),a.b=null)}}
function Vf(a){var b;a=xa(a.id);for(var c=0;c<a.length;c++){var d=a[c];if(b)b==d&&(b=null);else if("RAM"==d.type)return d}return null}function $c(a){if(a.gb){var b=0,c=0;window&&(b=window.scrollX,c=window.scrollY);a.gb.focus();window&&window.scrollTo(b,c)}}var fh="failsafe",ah="validate",ch="timestamp",ph="version",qh="url",rh="browser",mh="user",eh=-1,Wg=0,dh=1,jh=2,th=3;
Za(function(){for(var a=A(document,x+"-machine"),b=0;b<a.length;b++)for(var c=a[b],d=v(c),c=A(c,x,"computer"),e=0;e<c.length;e++){var f=c[e],g=v(f),g=new Tg(g,d,!0);w(g,f);g.w&&Zg(g,g.Fb)}});$a.show.push(function(){for(var a=A(document,x,"computer"),b=0;b<a.length;b++){var c=v(a[b]);(c=za("Computer",c.id))&&c.H&&!c.j.O&&c.Fb(eh)}});$a.exit.push(function(){for(var a=A(document,x,"computer"),b=0;b<a.length;b++){var c=v(a[b]);(c=za("Computer",c.id))&&c.j.O&&oh(c,!(!c.a||c.o),!0)}});
Za(function(){for(var a=A(document,x+"-machine"),b=0;b<a.length;b++)for(var c=a[b],d=v(c),c=A(c,x,"computer"),e=0;e<c.length;e++){var f=c[e],g=v(f),g=new Tg(g,d,!0);w(g,f);g.w&&Zg(g,g.Fb)}});$a.show.push(function(){for(var a=A(document,x,"computer"),b=0;b<a.length;b++){var c=v(a[b]);(c=za("Computer",c.id))&&c.H&&!c.j.O&&c.Fb(eh)}});$a.exit.push(function(){for(var a=A(document,x,"computer"),b=0;b<a.length;b++){var c=v(a[b]);(c=za("Computer",c.id))&&c.j.O&&oh(c,!(!c.a||c.i),!0)}});
function E(a,b,c){this.id=a.id;this.a="";this.c={};this.b=this.m=!1;this.key=vh(a,b,c);kh(this,a.he)}h=E.prototype;h.set=function(a,b){try{this.c[a]=b}catch(c){}};h.get=function(a){return this.c[a]||null};h.data=function(){return this.c};function Xg(a,b){return b?(a.a=b,a.b=!0,a.m=!1,!0):a.b?!0:Ra()&&(b=Ta(a.key))?(a.a=b,a.b=!0):!1}function bh(a){var b=!0;if(!a.m)try{a.c=JSON.parse(a.a),a.m=!0}catch(c){u(c.message||c),b=!1}return b}
function lh(a){var b=!0;if(Ra()){var c=JSON.stringify(a.c);Ua(a.key,c)||(u("Unable to store "+c.length+" bytes in browser local storage"),b=!1)}return b}h.toString=function(){return this.c?JSON.stringify(this.c):this.a};function kh(a,b){a.a="";a.c={};a.b=a.m=!1;b&&a.set("parms",b)}
h.clear=function(a){kh(this);var b=[];try{for(var c=0,d=window.localStorage.length;c<d;c++)b.push(window.localStorage.key(c))}catch(e){}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(e){}b.splice(c,1);c=0}};function vh(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}var wh=0;