mirror of
https://github.com/hulkholden/n64js.git
synced 2025-04-02 10:51:54 -04:00
523 lines
402 KiB
JavaScript
523 lines
402 KiB
JavaScript
var Y6=31,Z8=0,l8=1,d8=2,a8=3,r8=4,s8=5,uq=6,gq=7,i8=8,m6=9,D6=10,K8=11,U0=12,k0=13,G6=14,_J=15,t8=16,SJ=17;var xq=20,pq=21,mq=22,nq=23,oq=24,cq=25,nZ=26,oZ=27,cZ=28,lZ=29,e8=30,lq=31,dq=2,dZ=0,aZ=1,aq=2,rq=3,rZ=4,sZ=5;var iZ=8,tZ=9,eZ=10,JK=11,qK=12,QK=13;var YK=15;function XK(J){switch(J){case 67:case 68:case 70:case 72:case 73:case 76:case 80:case 83:case 85:case 87:case 88:case 89:case 96:return 0;case 66:return 2;case 55:case 65:case 69:case 71:case 74:case 75:case 78:return 1}return 1}function WK(J){const q=String.fromCharCode(J),Q=qz.get(q);if(Q)return Q;return`unknown code ${q}`}var X8=0,qJ=1,ZK=2;var KK=69;var qz=new Map([["N","Game Pak"],["D","64DD Disk"],["C","Expandable Game: Game Pak Part"],["E","Expandable Game: 64DD Disk Part"],["Z","Aleck64 Game Pak"]]);function $K(J,q,Q){const Y=q.sp_mem.subRegion(4096,4096);J.setControlU64(U0,0x00000000_34000000n),J.setControlU64(t8,0x00000000_7006e463n),J.setControlU64(m6,0x00000000_00005000n),J.setControlU64(k0,0x00000000_0000005cn),J.setControlU64(_J,0x00000000_00000b22n),J.setControlU64(r8,0x00000000_007ffff0n),J.setControlU64(G6,0xffffffff_ffffffffn),J.setControlU64(i8,0xffffffff_ffffffffn),J.setControlU64(e8,0xffffffff_ffffffffn),J.cop1ControlChanged();const Z=0x00000000_00000000n;if(J.setRegU64(0,Z),J.setRegU64(1,Z),J.setRegU64(2,0xffffffff_d1731be9n),J.setRegU64(3,0xffffffff_d1731be9n),J.setRegU64(4,0x00000000_00001be9n),J.setRegU64(5,0xffffffff_f45231e5n),J.setRegU64(6,0xffffffff_a4001f0cn),J.setRegU64(7,0xffffffff_a4001f08n),J.setRegU64(8,0x00000000_000000c0n),J.setRegU64(9,Z),J.setRegU64(10,0x00000000_00000040n),J.setRegU64(11,0xffffffff_a4000040n),J.setRegU64(16,Z),J.setRegU64(17,Z),J.setRegU64(18,Z),J.setRegU64(19,Z),J.setRegU64(20,BigInt(Q.tvType)),J.setRegU64(21,Z),J.setRegU64(23,0x00000000_00000006n),J.setRegU64(24,Z),J.setRegU64(25,0xffffffff_d73f2993n),J.setRegU64(26,Z),J.setRegU64(27,Z),J.setRegU64(28,Z),J.setRegU64(29,0xffffffff_a4001ff0n),J.setRegU64(30,Z),J.setRegU64(31,0xffffffff_a4001554n),Q.tvType==X8){switch(Q.cic){case"6102":J.setRegU64(5,0xffffffff_c0f1d859n),J.setRegU64(14,0x00000000_2de108ean),J.setRegU64(24,Z);break;case"6103":J.setRegU64(5,0xffffffff_d4646273n),J.setRegU64(14,0x00000000_1af99984n),J.setRegU64(24,Z);break;case"6105":J.setRegU64(5,0xffffffff_decaaad1n),J.setRegU64(14,0x00000000_0cf85c13n),J.setRegU64(24,0x00000000_00000002n);break;case"6106":J.setRegU64(5,0xffffffff_b04dc903n),J.setRegU64(14,0x00000000_1af99984n),J.setRegU64(24,0x00000000_00000002n);break;default:break}J.setRegU64(20,Z),J.setRegU64(23,0x00000000_00000006n),J.setRegU64(31,0xffffffff_a4001554n)}else{switch(Q.cic){case"6102":J.setRegU64(5,0xffffffff_c95973d5n),J.setRegU64(14,0x00000000_2449a366n);break;case"6103":J.setRegU64(5,0xffffffff_95315a28n),J.setRegU64(14,0x00000000_5baca1dfn);break;case"6105":J.setRegU64(5,0x00000000_5493fb9an),J.setRegU64(14,0xffffffff_c2c20384n);break;case"6106":J.setRegU64(5,0xffffffff_e067221fn),J.setRegU64(14,0x00000000_5cd2b70fn);break;default:break}J.setRegU64(20,0x00000000_00000001n),J.setRegU64(23,Z),J.setRegU64(24,0x00000000_00000003n),J.setRegU64(31,0xffffffff_a4001550n)}switch(Q.cic){case"6101":J.setRegU64(22,0x00000000_0000003fn);break;case"6102":J.setRegU64(1,0x00000000_00000001n),J.setRegU64(2,0x00000000_0ebda536n),J.setRegU64(3,0x00000000_0ebda536n),J.setRegU64(4,0x00000000_0000a536n),J.setRegU64(12,0xffffffff_ed10d0b3n),J.setRegU64(13,0x00000000_1402a4ccn),J.setRegU64(15,0x00000000_3103e121n),J.setRegU64(22,0x00000000_0000003fn),J.setRegU64(25,0xffffffff_9debb54fn);break;case"6103":J.setRegU64(1,0x00000000_00000001n),J.setRegU64(2,0x00000000_49a5ee96n),J.setRegU64(3,0x00000000_49a5ee96n),J.setRegU64(4,0x00000000_0000ee96n),J.setRegU64(12,0xffffffff_ce9dfbf7n),J.setRegU64(13,0xffffffff_ce9dfbf7n),J.setRegU64(15,0x00000000_18b63d28n),J.setRegU64(22,0x00000000_00000078n),J.setRegU64(25,0xffffffff_825b21c9n);break;case"6105":Y.set32(0,1007534016),Y.set32(4,Q.tvType==X8?3181905916:2376599548),Y.set32(8,632096704),Y.set32(12,822608000),Y.set32(16,1426128892),Y.set32(20,1007534016),Y.set32(24,2376597540),Y.set32(28,1007398912),J.setRegU64(1,Z),J.setRegU64(2,0xffffffff_f58b0fbfn),J.setRegU64(3,0xffffffff_f58b0fbfn),J.setRegU64(4,0x00000000_00000fbfn),J.setRegU64(12,0xffffffff_9651f81en),J.setRegU64(13,0x00000000_2d42aac5n),J.setRegU64(15,0x00000000_56584d60n),J.setRegU64(22,0x00000000_00000091n),J.setRegU64(25,0xffffffff_cdce565fn);break;case"6106":J.setRegU64(1,Z),J.setRegU64(2,0xffffffff_a95930a4n),J.setRegU64(3,0xffffffff_a95930a4n),J.setRegU64(4,0x00000000_000030a4n),J.setRegU64(12,0xffffffff_bcb59510n),J.setRegU64(13,0xffffffff_bcb59510n),J.setRegU64(15,0x00000000_7a3c07f4n),J.setRegU64(22,0x00000000_00000085n),J.setRegU64(25,0x00000000_465e3f72n);break;default:break}J.pc=2751463488}class W8{constructor(){this.buttons=0,this.stick_x=0,this.stick_y=0}}class sq{constructor(){this.inputs=[new W8,new W8,new W8,new W8]}handleKey(J,q,Q){switch(q){case"a":this.setButton(J,4096,Q);break;case"s":this.setButton(J,32768,Q);break;case"x":this.setButton(J,16384,Q);break;case"z":this.setButton(J,8192,Q);break;case"y":this.setButton(J,8192,Q);break;case"c":this.setButton(J,32,Q);break;case"v":this.setButton(J,16,Q);break;case"t":this.setButton(J,2048,Q);break;case"g":this.setButton(J,1024,Q);break;case"f":this.setButton(J,512,Q);break;case"h":this.setButton(J,256,Q);break;case"i":this.setButton(J,8,Q);break;case"k":this.setButton(J,4,Q);break;case"j":this.setButton(J,2,Q);break;case"l":this.setButton(J,1,Q);break;case"ArrowLeft":this.setStickX(J,Q?-80:0);break;case"ArrowRight":this.setStickX(J,Q?80:0);break;case"ArrowDown":this.setStickY(J,Q?-80:0);break;case"ArrowUp":this.setStickY(J,Q?80:0);break}}setStickX(J,q){this.inputs[J].stick_x=q}setStickY(J,q){this.inputs[J].stick_y=q}setButton(J,q,Q){let Y=this.inputs[J].buttons;if(Q)Y|=q;else Y&=~q;this.inputs[J].buttons=Y}}function zK(J,q){v0=J,QJ=q}function HK(){if(v0)v0.html("")}function M(J){if(QJ)J=`${QJ()}: ${J}`;if(console.log(J),v0)v0.append(`${J}<br>`),v0.scrollTop(v0[0].scrollHeight)}function FK(J){if(QJ)J=`${QJ()}: ${J}`;if(console.warn(J),v0)v0.append(`<font color="yellow">${J}</font><br>`),v0.scrollTop(v0[0].scrollHeight)}function jK(J){if(v0)v0.append(J)}var v0,QJ;function NK(J,q){var Q=J.toString();while(Q.length<q)Q="0"+Q;return Q}function B(J,q){let Q;if(typeof J=="bigint"){const Z=q?(1n<<BigInt(q))-1n:0xffff_ffff_ffff_ffffn;Q=J&Z}else{const Z=q&&q<32?(1<<q)-1:4294967295;Q=(Number(J)&Z)>>>0}let Y=Q.toString(16);if(q){const Z=q>>2;while(Y.length<Z)Y="0"+Y}return Y}function M0(J){return"0x"+B(J,8)}function r(J){return"0x"+B(J,16)}function N(J){return"0x"+B(J,32)}function y6(J){return"0x"+B(J,64)}function GK(){n6=void 0,Z6=void 0}function PK(){return n6||Z6?!0:!1}function LK(J){let Q=J;for(let Y of[n6,Z6]){if(!Y)continue;if(!Y.tick())Q=0;let Z=Math.floor(Y.getAvailableBytes()/8);Z=Math.max(0,Z-100),Q=Math.min(Q,Z)}return Q}var n6=null,Z6=null;function MK(J,q,Q){let Y=11,Z=VK;for(let K=0;K<Q;K++){q[K]=Y+5*J[K]&15,Y=Z[q[K]];const X=q[K]>>3&1;let z=((X==1?~q[K]:q[K])&7)%3==1?X:1-X;if(Z==UK){if(q[K]==1||q[K]==9)z=1;if(q[K]==11||q[K]==14)z=0}Z=z==1?UK:VK}}var VK=[4,7,10,7,14,5,14,1,12,15,8,15,6,3,6,9],UK=[4,1,10,7,14,5,14,1,12,9,8,5,6,3,12,9];var CK=function(J,q,Q){let Y=0;for(let Z=0;Z<Q;Z++){const K=J[q+Z];for(let X=0;X<8;X++)Y=(Y<<1|K>>>7-X&1)^(Y&128?133:0)}for(let Z=8;Z!==0;Z--)Y=Y<<1^(Y&128?133:0);return Y&255},DK=function(J){let q=0;for(let Q=0;Q<16;Q++)q=(q<<1|J>>>15-Q&1)^(q&16?21:0);return q&31};var Yz=5,YJ=64,OK=63,yK=0,Zz=1,Kz=2,Xz=3,Wz=4,$z=5,zz=6,Hz=7,Fz=8,IK=255,jz=0,Nz=253,AK=254,Gz=255,hK=0,iq=1,EK=2,wK=16,Pz=128,Lz=192,kK=1280;var Vz=64,Uz=128;class tq{constructor(J,q){this.hardware=J,this.pifRam=this.hardware.pif_mem.subRegion(1984,64);const Q=new ZJ(q[0]);Q.present=!0,Q.attachControllerPack(J.mempacks[0]),this.channels=[Q,new ZJ(q[1]),new ZJ(q[2]),new ZJ(q[3]),new BK(J)]}get controlByte(){return this.pifRam.getU8(OK)}set controlByte(J){this.pifRam.set8(OK,J)}cpuRead(J){}cpuWrite(J){}dmaWrite(J,q){if(this.pifRam.copy(0,J,q,YJ),this.controlByte&1)this.controlByte&=~1,this.configure()}dmaRead(J,q){if(this.controlByte&2)this.processCICChallenge();else this.execute();J.copy(q,this.pifRam,0,YJ)}processCICChallenge(){const J=new Uint8Array(30),q=new Uint8Array(30);for(let Q=0;Q<15;++Q)J[Q*2+0]=this.pifRam.u8[48+Q]>>>4&15,J[Q*2+1]=this.pifRam.u8[48+Q]>>>0&15;MK(J,q,30);for(let Q=0;Q<15;++Q)this.pifRam.u8[48+Q]=(q[Q*2]<<4)+q[Q*2+1];this.pifRam.u8[46]=0,this.pifRam.u8[47]=0}configure(){for(let Q of this.channels)Q.init();let J=0,q=0;while(J<YJ&&q<Yz){const Q=this.pifRam.u8.subarray(J),Y=Q[0];if(J++,Y==AK)break;if(Y==Gz)continue;if(Y==jz){q++;continue}if(Y==Nz){this.channels[q].reset=!0,q++;continue}if(J>=YJ)break;const Z=Q[1];if(J++,Z==AK)break;const K=Y&63,X=J;J+=K;const W=Z&63,z=J;if(J+=W,J>=YJ)break;const F=this.pifRam.u8.subarray(X,X+K),j=this.pifRam.u8.subarray(z,z+W);this.channels[q].joybusConfigure(Q,K,W,F,j),q++}}execute(){for(let J of this.channels){if(J.reset)continue;if(J.skip)continue;const q=J.frame[0],Q=J.frame[1];if(q&128)continue;if(q&64)continue;const Y=q&63,Z=Q&63,K=J.joybusCommand(Y,Z,J.txBuf,J.rxBuf);if(K<Z)J.frame[1]|=Uz;if(K>Z)J.frame[1]|=Vz}}}class eq{constructor(){this.init()}expectTx(J,q,Q){if(q!=Q)M(`${J}: got tx ${q} but expect ${Q}`)}init(){this.frame=0,this.tx=0,this.rx=0,this.txBuf=null,this.rxBuf=null,this.skip=!0,this.reset=!1}joybusConfigure(J,q,Q,Y,Z){this.frame=J,this.tx=q,this.rx=Q,this.txBuf=Y,this.rxBuf=Z,this.skip=!1}}class ZJ extends eq{constructor(J){super();this.inputs=J,this.present=!1,this.attachment=hK,this.memory=null,this.rumbleActive=!1}attachControllerPack(J){this.attachment=iq,this.memory=J}joybusCommand(J,q,Q,Y){if(!this.present)return 0;const Z=Q[0];switch(Z){case IK:return this.getStatus(J,q,Q,Y);case yK:return this.getStatus(J,q,Q,Y);case Zz:return this.readController(J,q,Q,Y);case Kz:return this.readAccessory(J,q,Q,Y);case Xz:return this.writeAccessory(J,q,Q,Y)}return n64js.halt("Unknown controller command "+Z),0}getStatus(J,q,Q,Y){return this.expectTx("kCmdGetStatus",J,1),Y[0]=kK>>>8,Y[1]=kK&255,Y[2]=this.attachment==hK?2:1,3}readController(J,q,Q,Y){this.expectTx("kCmdControllerRead",J,1);let Z=this.inputs.buttons,K=this.inputs.stick_x,X=this.inputs.stick_y;if(Z6)Z6.sync32(3203395597,"input"),Z=Z6.reflect32(Z),K=Z6.reflect32(K),X=Z6.reflect32(X);return Y[0]=Z>>>8,Y[1]=Z&255,Y[2]=K,Y[3]=X,4}readAccessory(J,q,Q,Y){this.expectTx("kCmdControllerAccessoryRead",J,3);const Z=Q[1]<<8|Q[2]&224;if((Q[2]&31)!=DK(Z))return 0;switch(this.attachment){case iq:const X=this.memory.data;for(let W=0,z=Z;W<q-1;W++,z++)Y[W]=z<X.length?X[z]:0;break;case EK:for(let W=0,z=Z;W<q-1;W++,z++){let F;if(z<32768)F=0;else if(z<36864)F=128;else F=this.rumbleActive?255:0;Y[W]=F}break;default:return 0}return Y[q-1]=CK(Y,0,q-1),q}writeAccessory(J,q,Q,Y){this.expectTx("kCmdControllerAccessoryWrite",J,35);const Z=Q[1]<<8|Q[2]&224;if((Q[2]&31)!=DK(Z))return 0;switch(this.attachment){case iq:const X=this.memory.data;this.memory.dirty=!0;for(let W=0,z=Z;W<J-3;W++,z++)if(z<X.length)X[z]=Q[3+W];break;case EK:if(Z>=49152)this.rumbleActive=Q[3]&1;break;default:return 0}return Y[q-1]=CK(Q,3,J-3),q}}class BK extends eq{constructor(J){super();this.hardware=J}joybusCommand(J,q,Q,Y){const Z=Q[0];switch(Z){case IK:return this.getStatus(J,q,Q,Y);case yK:return this.getStatus(J,q,Q,Y);case Wz:return this.readEeprom(J,q,Q,Y);case $z:return this.writeEeprom(J,q,Q,Y);case zz:return this.rtcStatus(J,q,Q,Y);case Hz:return this.rtcRead(J,q,Q,Y);case Fz:return this.rtcWrite(J,q,Q,Y)}return n64js.halt(`Unknown cartridge command: ${Z}`),0}getEepromID(){switch(this.hardware.saveType){case"Eeprom4k":return Pz;case"Eeprom16k":return Lz}return 0}getEeprom(){switch(this.hardware.saveType){case"Eeprom4k":case"Eeprom16k":return this.hardware.saveMem}return null}getStatus(J,q,Q,Y){this.expectTx("kCmdGetStatus",J,1);const Z=this.getEepromID();if(!Z)return 0;return Y[0]=Z>>>8,Y[1]=Z&255,Y[2]=0,3}readEeprom(J,q,Q,Y){this.expectTx("kCmdEepromRead",J,2);const Z=this.getEeprom();if(!Z)return 0;const K=Q[1]*8;for(let X=0;X<q;++X)Y[X]=Z.u8[K+X];return q}writeEeprom(J,q,Q,Y){this.expectTx("kCmdEepromWrite",J,10);const Z=this.getEeprom();if(!Z)return 0;const K=Q[1]*8;for(let X=0;X<J-2;++X)Z.u8[K+X]=Q[2+X];return this.hardware.saveDirty=!0,Y[0]=0,1}rtcStatus(J,q,Q,Y){return Y[0]=wK>>>8,Y[1]=wK&255,Y[2]=0,3}rtcRead(J,q,Q,Y){return n64js.warn("rtc read unhandled"),0}rtcWrite(J,q,Q,Y){return n64js.warn("rtc write unhandled"),0}}function a(J,q){if(!J)throw new RK(q)}class RK{constructor(J){this.message=J}toString(){return"AssertException: "+this.message}}function $8(J){return J>>>26&63}function z8(J){return J>>>16&31}function H8(J){return J&63}function f0(J){return J>>>21&31}function bK(J){return J>>>16&3}function u0(J){return J&63}function P6(J){return J>>>6&31}function J0(J){return J>>>11&31}function K6(J){return J>>>16&31}function q0(J){return(J&65535)<<16>>16}function R0(J){return J>>>6&31}function R(J){return J>>>11&31}function A(J){return J>>>16&31}function D(J){return J>>>21&31}function F8(J){return J&63}function Mz(J){return J&67108863}function L6(J){return J&65535}function b(J){return(J&65535)<<16>>16}function u(J){return J>>>21&31}function C0(J,q){return J+4+q0(q)*4>>>0}function I6(J,q){return(J&4026531840|Mz(q)*4)>>>0}var Oz=function(J){return q0(J)&65535},TK=function(J){return q0(J)<<16>>16},hz=function(J){return SK[H8(J.opcode)](J)},Ez=function(J){return vK[f0(J.opcode)](J)},wz=function(J){switch(a((J.opcode>>>18&7)===0,"cc bit is not 0"),bK(J.opcode)){case 0:return`BC1F !c ? --> ${J.branchAddress}`;case 1:return`BC1T c ? --> ${J.branchAddress}`;case 2:return`BC1FL !c ? --> ${J.branchAddress}`;case 3:return`BC1TL c ? --> ${J.branchAddress}`}return"???"},vJ=function(J,q){var Q=q.toUpperCase();switch(u0(J.opcode)){case 0:return`ADD.${Q} ${J.fd(q)} = ${J.fs(q)} + ${J.ft(q)}`;case 1:return`SUB.${Q} ${J.fd(q)} = ${J.fs(q)} - ${J.ft(q)}`;case 2:return`MUL.${Q} ${J.fd(q)} = ${J.fs(q)} * ${J.ft(q)}`;case 3:return`DIV.${Q} ${J.fd(q)} = ${J.fs(q)} / ${J.ft(q)}`;case 4:return`SQRT.${Q} ${J.fd(q)} = sqrt(${J.fs(q)})`;case 5:return`ABS.${Q} ${J.fd(q)} = abs(${J.fs(q)})`;case 6:return`MOV.${Q} ${J.fd(q)} = ${J.fs(q)}`;case 7:return`NEG.${Q} ${J.fd(q)} = -${J.fs(q)}`;case 8:return`ROUND.L.${Q} ${J.fd("l")} = round.l(${J.fs(q)})`;case 9:return`TRUNC.L.${Q} ${J.fd("l")} = trunc.l(${J.fs(q)})`;case 10:return`CEIL.L.${Q} ${J.fd("l")} = ceil.l(${J.fs(q)})`;case 11:return`FLOOR.L.${Q} ${J.fd("l")} = floor.l(${J.fs(q)})`;case 12:return`ROUND.W.${Q} ${J.fd("w")} = round.w(${J.fs(q)})`;case 13:return`TRUNC.W.${Q} ${J.fd("w")} = trunc.w(${J.fs(q)})`;case 14:return`CEIL.W.${Q} ${J.fd("w")} = ceil.w(${J.fs(q)})`;case 15:return`FLOOR.W.${Q} ${J.fd("w")} = floor.w(${J.fs(q)})`;case 32:return`CVT.S.${Q} ${J.fd("s")} = (s)${J.fs(q)}`;case 33:return`CVT.D.${Q} ${J.fd("d")} = (d)${J.fs(q)}`;case 36:return`CVT.W.${Q} ${J.fd("w")} = (w)${J.fs(q)}`;case 37:return`CVT.L.${Q} ${J.fd("l")} = (l)${J.fs(q)}`;case 48:return`C.F.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 49:return`C.UN.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 50:return`C.EQ.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 51:return`C.UEQ.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 52:return`C.OLT.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 53:return`C.ULT.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 54:return`C.OLE.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 55:return`C.ULE.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 56:return`C.SF.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 57:return`C.NGLE.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 58:return`C.SEQ.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 59:return`C.NGL.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 60:return`C.LT.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 61:return`C.NGE.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 62:return`C.LE.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`;case 63:return`C.NGT.${Q} c = ${J.fs(q)} cmp ${J.ft(q)}`}return`Cop1.${q}${B(u0(J.opcode),8)}?`},kz=function(J){return vJ(J,"s")},Cz=function(J){return vJ(J,"d")},Dz=function(J){return vJ(J,"w")},yz=function(J){return vJ(J,"l")},Iz=function(J){return fK[f0(J.opcode)](J)},Bz=function(J){return f,uK[f0(J.opcode)](J)},Rz=function(J){return gK[f0(J.opcode)](J)},bz=function(J){switch(F8(J.opcode)){case 1:return"TLBR";case 2:return"TLBWI";case 6:return"TLBWR";case 8:return"TLBP";case 24:return"ERET"}return"Unk"},Tz=function(J){return xK[z8(J.opcode)](J)};function fJ(J,q,Q){const Y=new _K(J,q,Q),Z=pK[$8(q)](Y);return{instruction:Y,disassembly:Z,isJumpTarget:!1}}function mK(J,q,Q){const Y=[],Z=new Set;for(let K=J;K<q;K+=4){const X=n64js.getInstruction(K),W=fJ(K,X,Q);if(W.instruction.target)Z.add(W.instruction.target);Y.push(W)}for(let K of Y)if(Z.has(K.instruction.address))K.isJumpTarget=!0;return Y}window.n64js=window.n64js||{};var JQ=["r0","at","v0","v1","a0","a1","a2","a3","t0","t1","t2","t3","t4","t5","t6","t7","s0","s1","s2","s3","s4","s5","s6","s7","t8","t9","k0","k1","gp","sp","s8","ra"],j8=["Index","Rand","EntryLo0","EntryLo1","Context","PageMask","Wired","?7","BadVAddr","Count","EntryHi","Compare","SR","Cause","EPC","PrID","Config","LLAddr","WatchLo","WatchHi","XContext","?21","?22","?23","?24","?25","ECC","CacheErr","TagLo","TagHi","ErrorEPC","?31"],qQ=["f00","f01","f02","f03","f04","f05","f06","f07","f08","f09","f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20","f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31"],Az=["GR00","GR01","GR02","GR03","GR04","GR05","GR06","GR07","GR08","GR09","GR10","GR11","GR12","GR13","GR14","GR15","GR16","GR17","GR18","GR19","GR20","GR21","GR22","GR23","GR24","GR25","GR26","GR27","GR28","GR29","GR30","GR31"];class _K{constructor(J,q,Q){this.address=J,this.opcode=q,this.srcRegs={},this.dstRegs={},this.target="",this.memory=null,this.outputHTML=Q}get rt_d(){const J=this.cop0RegName(A);return this.dstRegs[J]=1,this.makeRegSpan(J)}get rd(){const J=this.cop0RegName(R);return this.dstRegs[J]=1,this.makeRegSpan(J)}get rt(){const J=this.cop0RegName(A);return this.srcRegs[J]=1,this.makeRegSpan(J)}get rs(){const J=this.cop0RegName(D);return this.srcRegs[J]=1,this.makeRegSpan(J)}get sa(){return R0(this.opcode)}cop0RegName(J){return JQ[J(this.opcode)]}writesRA(){return this.dstRegs[Y6]=1,""}ft_d(J){const q=this.cop1RegName(K6,J);return this.dstRegs[q]=1,this.makeFPRegSpan(q)}fs_d(J){const q=this.cop1RegName(J0,J);return this.dstRegs[q]=1,this.makeFPRegSpan(q)}fd(J){const q=this.cop1RegName(P6,J);return this.dstRegs[q]=1,this.makeFPRegSpan(q)}ft(J){const q=this.cop1RegName(K6,J);return this.srcRegs[q]=1,this.makeFPRegSpan(q)}fs(J){const q=this.cop1RegName(J0,J);return this.srcRegs[q]=1,this.makeFPRegSpan(q)}cop1RegName(J,q){const Q=J(this.opcode),Y=q?`-${q}`:"";return qQ[Q]+Y}get gt_d(){const J=this.cop2RegName(A);return this.dstRegs[J]=1,this.makeRegSpan(J)}get gd(){const J=this.cop2RegName(R);return this.dstRegs[J]=1,this.makeRegSpan(J)}get gt(){const J=this.cop2RegName(A);return this.srcRegs[J]=1,this.makeRegSpan(J)}get gs(){const J=this.cop2RegName(D);return this.srcRegs[J]=1,this.makeRegSpan(J)}cop2RegName(J){return Az[J(this.opcode)]}get imm(){return`0x${B(L6(this.opcode),16)}`}get branchAddress(){return this.target=C0(this.address,this.opcode),this.makeLabelText(this.target)}get jumpAddress(){return this.target=I6(this.address,this.opcode),this.makeLabelText(this.target)}get base(){const J=this.cop0RegName(u);return this.srcRegs[J]=1,this.makeRegSpan(J)}get offsetU16(){return`0x${B(Oz(this.opcode),16)}`}get offsetS16(){return`0x${B(TK(this.opcode),16)}`}memaccess(J){return this.memory={reg:u(this.opcode),offset:TK(this.opcode),mode:J},`[${this.base}+${this.offsetU16}]`}memload(){return this.memaccess("load")}memstore(){return this.memaccess("store")}makeLabelText(J){if(this.outputHTML)return`<span class="dis-address-jump">${B(J,32)}</span>`;return B(J,32)}makeRegSpan(J){if(this.outputHTML)return`<span class="dis-reg-${J}">${J}</span>`;return J}makeFPRegSpan(J){const q=J.replace("-",".");if(this.outputHTML)return`<span class="dis-reg-${J}">${q}</span>`;return q}}var SK=[(J)=>{if(J.opcode===0)return"NOP";return`SLL ${J.rd} = ${J.rt} << ${J.sa}`},(J)=>"Unk",(J)=>`SRL ${J.rd} = ${J.rt} >>> ${J.sa}`,(J)=>`SRA ${J.rd} = ${J.rt} >> ${J.sa}`,(J)=>`SLLV ${J.rd} = ${J.rt} << ${J.rs}`,(J)=>"Unk",(J)=>`SRLV ${J.rd} = ${J.rt} >>> ${J.rs}`,(J)=>`SRAV ${J.rd} = ${J.rt} >> ${J.rs}`,(J)=>`JR ${J.rs}`,(J)=>`JALR ${J.rd}, ${J.rs}`,(J)=>"Unk",(J)=>"Unk",(J)=>`SYSCALL ${B(J.opcode>>6&1048575,20)}`,(J)=>`BREAK ${B(J.opcode>>6&1048575,20)}`,(J)=>"Unk",(J)=>"SYNC",(J)=>`MFHI ${J.rd} = MultHi`,(J)=>`MTHI MultHi = ${J.rs}`,(J)=>`MFLO ${J.rd} = MultLo`,(J)=>`MTLO MultLo = ${J.rs}`,(J)=>`DSLLV ${J.rd} = ${J.rt} << ${J.rs}`,(J)=>"Unk",(J)=>`DSRLV ${J.rd} = ${J.rt} >>> ${J.rs}`,(J)=>`DSRAV ${J.rd} = ${J.rt} >> ${J.rs}`,(J)=>`MULT ${J.rs} * ${J.rt}`,(J)=>`MULTU ${J.rs} * ${J.rt}`,(J)=>`DIV ${J.rs} / ${J.rt}`,(J)=>`DIVU ${J.rs} / ${J.rt}`,(J)=>`DMULT ${J.rs} * ${J.rt}`,(J)=>`DMULTU ${J.rs} * ${J.rt}`,(J)=>`DDIV ${J.rs} / ${J.rt}`,(J)=>`DDIVU ${J.rs} / ${J.rt}`,(J)=>`ADD ${J.rd} = ${J.rs} + ${J.rt}`,(J)=>`ADDU ${J.rd} = ${J.rs} + ${J.rt}`,(J)=>`SUB ${J.rd} = ${J.rs} - ${J.rt}`,(J)=>`SUBU ${J.rd} = ${J.rs} - ${J.rt}`,(J)=>`AND ${J.rd} = ${J.rs} & ${J.rt}`,(J)=>{if(A(J.opcode)===0)if(D(J.opcode)===0)return`CLEAR ${J.rd} = 0`;else return`MOV ${J.rd} = ${J.rs}`;return`OR ${J.rd} = ${J.rs} | ${J.rt}`},(J)=>`XOR ${J.rd} = ${J.rs} ^ ${J.rt}`,(J)=>`NOR ${J.rd} = ~( ${J.rs} | ${J.rt} )`,(J)=>"Unk",(J)=>"Unk",(J)=>`SLT ${J.rd} = ${J.rs} < ${J.rt}`,(J)=>`SLTU ${J.rd} = ${J.rs} < ${J.rt}`,(J)=>`DADD ${J.rd} = ${J.rs} + ${J.rt}`,(J)=>`DADDU ${J.rd} = ${J.rs} + ${J.rt}`,(J)=>`DSUB ${J.rd} = ${J.rs} - ${J.rt}`,(J)=>`DSUBU ${J.rd} = ${J.rs} - ${J.rt}`,(J)=>`TGE trap( ${J.rs} >= ${J.rt} )`,(J)=>`TGEU trap( ${J.rs} >= ${J.rt} )`,(J)=>`TLT trap( ${J.rs} < ${J.rt} )`,(J)=>`TLTU trap( ${J.rs} < ${J.rt} )`,(J)=>`TEQ trap( ${J.rs} == ${J.rt} )`,(J)=>"Unk",(J)=>`TNE trap( ${J.rs} != ${J.rt} )`,(J)=>"Unk",(J)=>`DSLL ${J.rd} = ${J.rt} << ${J.sa}`,(J)=>"Unk",(J)=>`DSRL ${J.rd} = ${J.rt} >>> ${J.sa}`,(J)=>`DSRA ${J.rd} = ${J.rt} >> ${J.sa}`,(J)=>`DSLL32 ${J.rd} = ${J.rt} << (32+${J.sa})`,(J)=>"Unk",(J)=>`DSRL32 ${J.rd} = ${J.rt} >>> (32+${J.sa})`,(J)=>`DSRA32 ${J.rd} = ${J.rt} >> (32+${J.sa})`];if(SK.length!=64)throw"Oops, didn't build the special table correctly";var vK=[(J)=>`MFC0 ${J.rt} <- ${j8[J0(J.opcode)]}`,(J)=>`DMFC0 ${J.rt} <- ${j8[J0(J.opcode)]}`,(J)=>"Unk",(J)=>"Unk",(J)=>`MTC0 ${J.rt} -> ${j8[J0(J.opcode)]}`,(J)=>`DMTC0 ${J.rt} -> ${j8[J0(J.opcode)]}`,(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",bz,(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk"];if(vK.length!=32)throw"Oops, didn't build the cop0 table correctly";var fK=[(J)=>`MFC1 ${J.rt_d} = ${J.fs()}`,(J)=>`DMFC1 ${J.rt_d} = ${J.fs()}`,(J)=>`CFC1 ${J.rt_d} = CCR${R(J.opcode)}`,(J)=>`DCFC1 ${J.rt_d} = CCR${R(J.opcode)}`,(J)=>`MTC1 ${J.fs_d()} = ${J.rt}`,(J)=>`DMTC1 ${J.fs_d()} = ${J.rt}`,(J)=>`CTC1 CCR${R(J.opcode)} = ${J.rt}`,(J)=>`DCTC1 CCR${R(J.opcode)} = ${J.rt}`,wz,(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",kz,Cz,(J)=>"Unk",(J)=>"Unk",Dz,yz,(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk"];if(fK.length!=32)throw"Oops, didn't build the cop1 table correctly";var uK=[(J)=>`MFC2 ${J.rt_d} = ${J.fs()}`,(J)=>`DMFC2 ${J.rt_d} = ${J.fs()}`,(J)=>`CFC2 ${J.rt_d} = CCR${R(J.opcode)}`,(J)=>`DCFC2 ${J.rt_d} = CCR${R(J.opcode)}`,(J)=>`MTC2 ${J.fs_d()} = ${J.rt}`,(J)=>`DMTC2 ${J.fs_d()} = ${J.rt}`,(J)=>`CTC2 CCR${R(J.opcode)} = ${J.rt}`,(J)=>`DCTC2 CCR${R(J.opcode)} = ${J.rt}`,(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk"];if(uK.length!=32)throw"Oops, didn't build the cop2 table correctly";var gK=[(J)=>`MFC3 ${J.rt_d} = ${J.fs()}`,(J)=>`DMFC3 ${J.rt_d} = ${J.fs()}`,(J)=>`CFC3 ${J.rt_d} = CCR${R(J.opcode)}`,(J)=>`DCFC3 ${J.rt_d} = CCR${R(J.opcode)}`,(J)=>`MTC3 ${J.fs_d()} = ${J.rt}`,(J)=>`DMTC3 ${J.fs_d()} = ${J.rt}`,(J)=>`CTC3 CCR${R(J.opcode)} = ${J.rt}`,(J)=>`DCTC3 CCR${R(J.opcode)} = ${J.rt}`,(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk"];if(gK.length!=32)throw"Oops, didn't build the cop3 table correctly";var xK=[(J)=>`BLTZ ${J.rs} < 0 --> ${J.branchAddress}`,(J)=>`BGEZ ${J.rs} >= 0 --> ${J.branchAddress}`,(J)=>`BLTZL ${J.rs} < 0 --> ${J.branchAddress}`,(J)=>`BGEZL ${J.rs} >= 0 --> ${J.branchAddress}`,(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>`TGEI ${J.rs} >= ${J.rt} --> trap `,(J)=>`TGEIU ${J.rs} >= ${J.rt} --> trap `,(J)=>`TLTI ${J.rs} < ${J.rt} --> trap `,(J)=>`TLTIU ${J.rs} < ${J.rt} --> trap `,(J)=>`TEQI ${J.rs} == ${J.rt} --> trap `,(J)=>"Unk",(J)=>`TNEI ${J.rs} != ${J.rt} --> trap `,(J)=>"Unk",(J)=>`BLTZAL ${J.rs} < 0 --> ${J.branchAddress}${J.writesRA()}`,(J)=>`BGEZAL ${J.rs} >= 0 --> ${J.branchAddress}${J.writesRA()}`,(J)=>`BLTZALL ${J.rs} < 0 --> ${J.branchAddress}${J.writesRA()}`,(J)=>`BGEZALL ${J.rs} >= 0 --> ${J.branchAddress}${J.writesRA()}`,(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk"];if(xK.length!=32)throw"Oops, didn't build the special table correctly";var pK=[hz,Tz,(J)=>`J --> ${J.jumpAddress}`,(J)=>`JAL --> ${J.jumpAddress}${J.writesRA()}`,(J)=>{if(D(J.opcode)==A(J.opcode))return`B --> ${J.branchAddress}`;return`BEQ ${J.rs} == ${J.rt} --> ${J.branchAddress}`},(J)=>`BNE ${J.rs} != ${J.rt} --> ${J.branchAddress}`,(J)=>`BLEZ ${J.rs} <= 0 --> ${J.branchAddress}`,(J)=>`BGTZ ${J.rs} > 0 --> ${J.branchAddress}`,(J)=>`ADDI ${J.rt_d} = ${J.rs} + ${J.imm}`,(J)=>`ADDIU ${J.rt_d} = ${J.rs} + ${J.imm}`,(J)=>`SLTI ${J.rt_d} = (${J.rs} < ${J.imm})`,(J)=>`SLTIU ${J.rt_d} = (${J.rs} < ${J.imm})`,(J)=>`ANDI ${J.rt_d} = ${J.rs} & ${J.imm}`,(J)=>`ORI ${J.rt_d} = ${J.rs} | ${J.imm}`,(J)=>`XORI ${J.rt_d} = ${J.rs} ^ ${J.imm}`,(J)=>`LUI ${J.rt_d} = ${J.imm} << 16`,Ez,Iz,Bz,Rz,(J)=>`BEQL ${J.rs} == ${J.rt} --> ${J.branchAddress}`,(J)=>`BNEL ${J.rs} != ${J.rt} --> ${J.branchAddress}`,(J)=>`BLEZL ${J.rs} <= 0 --> ${J.branchAddress}`,(J)=>`BGTZL ${J.rs} > 0 --> ${J.branchAddress}`,(J)=>`DADDI ${J.rt_d} = ${J.rs} + ${J.imm}`,(J)=>`DADDIU ${J.rt_d} = ${J.rs} + ${J.imm}`,(J)=>`LDL ${J.rt_d} <- ${J.memload()}`,(J)=>`LDR ${J.rt_d} <- ${J.memload()}`,(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>"Unk",(J)=>`LB ${J.rt_d} <- ${J.memload()}`,(J)=>`LH ${J.rt_d} <- ${J.memload()}`,(J)=>`LWL ${J.rt_d} <- ${J.memload()}`,(J)=>`LW ${J.rt_d} <- ${J.memload()}`,(J)=>`LBU ${J.rt_d} <- ${J.memload()}`,(J)=>`LHU ${J.rt_d} <- ${J.memload()}`,(J)=>`LWR ${J.rt_d} <- ${J.memload()}`,(J)=>`LWU ${J.rt_d} <- ${J.memload()}`,(J)=>`SB ${J.rt} -> ${J.memstore()}`,(J)=>`SH ${J.rt} -> ${J.memstore()}`,(J)=>`SWL ${J.rt} -> ${J.memstore()}`,(J)=>`SW ${J.rt} -> ${J.memstore()}`,(J)=>`SDL ${J.rt} -> ${J.memstore()}`,(J)=>`SDR ${J.rt} -> ${J.memstore()}`,(J)=>`SWR ${J.rt} -> ${J.memstore()}`,(J)=>`CACHE ${B(A(J.opcode),8)}, ${J.memaccess()}`,(J)=>`LL ${J.rt_d} <- ${J.memload()}`,(J)=>`LWC1 ${J.ft_d()} <- ${J.memload()}`,(J)=>"Unk",(J)=>"Unk",(J)=>`LLD ${J.rt_d} <- ${J.memload()}`,(J)=>`LDC1 ${J.ft_d()} <- ${J.memload()}`,(J)=>`LDC2 ${J.gt_d} <- ${J.memload()}`,(J)=>`LD ${J.rt_d} <- ${J.memload()}`,(J)=>`SC ${J.rt} -> ${J.memstore()}`,(J)=>`SWC1 ${J.ft()} -> ${J.memstore()}`,(J)=>"BREAKPOINT",(J)=>"Unk",(J)=>`SCD ${J.rt} -> ${J.memstore()}`,(J)=>`SDC1 ${J.ft()} -> ${J.memstore()}`,(J)=>`SDC2 ${J.gt} -> ${J.memstore()}`,(J)=>`SD ${J.rt} -> ${J.memstore()}`];if(pK.length!=64)throw"Oops, didn't build the simple table correctly";var sK=function(J){return J&63},_z=function(J){return J>>>6&31},o6=function(J){return J>>>11&31},gJ=function(J){return J>>>16&31},uJ=function(J){return J>>>21&31},Sz=function(J){return J>>>26&63},nK=function(J){return J>>>21&31},vz=function(J){return J>>>16&31},KJ=function(J){return J>>>7&15},oK=function(J){return(J&127)<<25>>25},cK=function(J){return J>>>21&15},fz=function(J){return J>>>11&31},uz=function(J){return J>>>16&31},gz=function(J){return J>>>11&31},xz=function(J){return J>>>6&31},pz=function(J){return J&67108863},QQ=function(J){return J&65535},mz=function(J){return QQ(J)<<16>>16},lK=function(J){return J>>>21&31},dK=function(J){return QQ(J)<<16>>16},nz=function(J){return J&65535},oz=function(J,q){return J+4+mz(q)*4},cz=function(J,q){return J&4026531840|pz(q)*4},aK=function(J){return B(J,16)},N8=function(J){return J},JH=function(J){return ez[sK(J.opcode)](J)},B6=function(J){return`unknown: ${N(J.opcode)}`};function XJ(J,q){const Q=new iK(J,q),Y=YH[Sz(q)](Q);return{address:J,instruction:Q,disassembly:Y,isJumpTarget:!1}}function xJ(J,q,Q){return ZQ(J,q,q,Q-q)}function ZQ(J,q,Q,Y){const Z=[],K=new Set,X=J.length-1;for(let W=0;W<Y;W+=4){const z=J.getU32(Q+W&X),F=XJ(q+W,z);if(F.instruction.target)K.add(F.instruction.target);Z.push(F)}for(let W of Z)if(K.has(W.instruction.address))W.isJumpTarget=!0;return Z}function tK(J,q,Q,Y){let Z="";for(let K=0;K<Y;K+=4)Z+=`${B(q+K,16)}: ${B(J.getU32(Q+K),32)}\n`;return Z}var YQ=["r0","at","v0","v1","a0","a1","a2","a3","t0","t1","t2","t3","t4","t5","t6","t7","s0","s1","s2","s3","s4","s5","s6","s7","t8","t9","k0","k1","gp","sp","s8","ra"],lz=31,rK=["SP_MEM_ADDR_REG","SP_DRAM_ADDR_REG","SP_RD_LEN_REG","SP_WR_LEN_REG","SP_STATUS_REG","SP_DMA_FULL_REG","SP_DMA_BUSY_REG","SP_SEMAPHORE_REG","DPC_START_REG","DPC_END_REG","DPC_CURRENT_REG","DPC_STATUS_REG","DPC_CLOCK_REG","DPC_BUFBUSY_REG","DPC_PIPEBUSY_REG","DPC_TMEM_REG"],dz=["VCO","VCC","VCE","VCE"],az=["All","All1","0q","1q","0h","1h","2h","3h","0","1","2","3","4","5","6","7"];class iK{constructor(J,q){this.address=J,this.opcode=q,this.srcRegs={},this.dstRegs={},this.target="",this.memory=null}get rd(){const J=this.gprName(o6);return this.dstRegs[J]=1,N8(J)}get rt(){const J=this.gprName(gJ);return this.srcRegs[J]=1,N8(J)}get rs(){const J=this.gprName(uJ);return this.srcRegs[J]=1,N8(J)}get rt_d(){const J=this.gprName(gJ);return this.dstRegs[J]=1,N8(J)}get c0reg(){const J=o6(this.opcode);if(J<rK.length)return rK[J];return`c0reg${J}`}get cop2E(){return`${cK(this.opcode)}`}get cop2DE(){return`${fz(this.opcode)}`}get cop2VD(){return`V${xz(this.opcode)}`}get cop2VT(){return`V${uz(this.opcode)}`}get cop2VS(){return`V${gz(this.opcode)}`}get cop2VecSelect(){return az[cK(this.opcode)]}get c2flag(){return dz[o6(this.opcode)&3]}get sa(){return _z(this.opcode)}gprName(J){return YQ[J(this.opcode)]}writesRA(){return this.dstRegs[lz]=1,""}get imm(){return`0x${B(QQ(this.opcode),16)}`}get branchAddress(){return this.target=oz(this.address,this.opcode),aK(this.target)}get jumpAddress(){return this.target=cz(this.address,this.opcode),aK(this.target)}get base(){const J=this.gprName(lK);return this.srcRegs[J]=1,N8(J)}get offsetU16(){return`0x${B(nz(this.opcode),16)}`}get offsetS16(){return`0x${B(dK(this.opcode),16)}`}memload(){return this.memaccess("load")}memstore(){return this.memaccess("store")}memaccess(J){return this.memory={reg:lK(this.opcode),offset:dK(this.opcode),mode:J},`[${this.base}+${this.offsetU16}]`}get vmemEl(){return`E${KJ(this.opcode)}`}vmemEls(J){return`[${KJ(this.opcode)}..${KJ(this.opcode)+J-1&15}]`}get vmemVT(){return`V${vz(this.opcode)}`}get vmemBase(){const J=this.gprName(nK);return this.srcRegs[J]=1,N8(J)}vmemload(J){return this.vmemaccess("load",J)}vmemstore(J){return this.vmemaccess("store",J)}vmemaccess(J,q){return q=q||1,this.memory={reg:nK(this.opcode),offset:oK(this.opcode)*q,mode:J},`[${this.vmemBase}${this.sprintVOffset(q)}]`}sprintVOffset(J){const q=oK(this.opcode)*J;return(q>=0?"+":"")+q.toString()}}var rz=(()=>{let J=[];for(let q=0;q<64;q++)J[q]=B6;return J[0]=(q)=>{if(q.opcode===0)return"NOP";return`SLL ${q.rd} = ${q.rt} << ${q.sa}`},J[2]=(q)=>`SRL ${q.rd} = ${q.rt} >>> ${q.sa}`,J[3]=(q)=>`SRA ${q.rd} = ${q.rt} >> ${q.sa}`,J[4]=(q)=>`SLLV ${q.rd} = ${q.rt} << ${q.rs}`,J[6]=(q)=>`SRLV ${q.rd} = ${q.rt} >>> ${q.rs}`,J[7]=(q)=>`SRAV ${q.rd} = ${q.rt} >> ${q.rs}`,J[8]=(q)=>`JR ${q.rs}`,J[9]=(q)=>`JALR ${q.rd}, ${q.rs}`,J[13]=(q)=>`BREAK ${B(q.opcode>>6&1048575,20)}`,J[32]=(q)=>`ADD ${q.rd} = ${q.rs} + ${q.rt}`,J[33]=(q)=>`ADDU ${q.rd} = ${q.rs} + ${q.rt}`,J[34]=(q)=>`SUB ${q.rd} = ${q.rs} - ${q.rt}`,J[35]=(q)=>`SUBU ${q.rd} = ${q.rs} - ${q.rt}`,J[36]=(q)=>`AND ${q.rd} = ${q.rs} & ${q.rt}`,J[37]=(q)=>`OR ${q.rd} = ${q.rs} | ${q.rt}`,J[38]=(q)=>`XOR ${q.rd} = ${q.rs} ^ ${q.rt}`,J[39]=(q)=>`NOR ${q.rd} = ~( ${q.rs} | ${q.rt} )`,J[42]=(q)=>`SLT ${q.rd} = ${q.rs} < ${q.rt}`,J[43]=(q)=>`SLTU ${q.rd} = ${q.rs} < ${q.rt}`,J})(),sz=(()=>{let J=[];for(let q=0;q<32;q++)J.push(B6);return J[0]=(q)=>`BLTZ ${q.rs} < 0 --> ${q.branchAddress}`,J[1]=(q)=>`BGEZ ${q.rs} >= 0 --> ${q.branchAddress}`,J[16]=(q)=>`BLTZAL ${q.rs} < 0 --> ${q.branchAddress}${q.writesRA()}`,J[17]=(q)=>`BGEZAL ${q.rs} >= 0 --> ${q.branchAddress}${q.writesRA()}`,J})(),iz=(()=>{let J=[];for(let q=0;q<32;q++)J.push(B6);return J[0]=(q)=>`MFC0 ${q.rt_d} <- ${q.c0reg}`,J[4]=(q)=>`MTC0 ${q.rt} -> ${q.c0reg}`,J})(),tz=(()=>{let J=[];for(let q=0;q<32;q++)J.push(B6);J[0]=(q)=>`MFC2 ${q.rt_d} = ${o6(q.opcode)}[${KJ(q.opcode)}]`,J[2]=(q)=>`CFC2 ${q.rt_d} = ${q.c2flag}`,J[4]=(q)=>`MTC2 V${o6(q.opcode)}[${KJ(q.opcode)}] = ${q.rt}`,J[6]=(q)=>`CTC2 ${q.c2flag} = ${q.rt}`;for(let q=16;q<32;q++)J[q]=JH;return J})(),ez=(()=>{let J=[];for(let q=0;q<64;q++)J.push(B6);return J[0]=(q)=>`VMULF ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[1]=(q)=>`VMULU ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[2]=(q)=>`VRNDP ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[3]=(q)=>`VMULQ ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[4]=(q)=>`VMUDL ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[5]=(q)=>`VMUDM ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[6]=(q)=>`VMUDN ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[7]=(q)=>`VMUDH ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[8]=(q)=>`VMACF ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[9]=(q)=>`VMACU ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[10]=(q)=>`VRNDN ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[11]=(q)=>`VMACQ ${q.cop2VD}, ACC = oddify(ACC)`,J[12]=(q)=>`VMADL ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[13]=(q)=>`VMADM ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[14]=(q)=>`VMADN ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[15]=(q)=>`VMADH ${q.cop2VD} = ${q.cop2VS} * ${q.cop2VT}[${q.cop2VecSelect}]`,J[16]=(q)=>`VADD ${q.cop2VD} = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[17]=(q)=>`VSUB ${q.cop2VD} = ${q.cop2VS} - ${q.cop2VT}[${q.cop2VecSelect}]`,J[18]=(q)=>`VSUT ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[19]=(q)=>`VABS ${q.cop2VD} = sign(${q.cop2VS}) * ${q.cop2VT}[${q.cop2VecSelect}]`,J[20]=(q)=>`VADDC ${q.cop2VD} = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[21]=(q)=>`VSUBC ${q.cop2VD} = ${q.cop2VS} - ${q.cop2VT}[${q.cop2VecSelect}]`,J[22]=(q)=>`VADDB ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[23]=(q)=>`VSUBB ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[24]=(q)=>`VACCB ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[25]=(q)=>`VSUCB ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[26]=(q)=>`VSAD ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[27]=(q)=>`VSAC ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[28]=(q)=>`VSUM ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[29]=(q)=>`VSAR ${q.cop2VD}, ${q.cop2VS}, ${q.cop2VT}[${q.cop2E}]`,J[30]=(q)=>`V30 ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[31]=(q)=>`V31 ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[32]=(q)=>`VLT ${q.cop2VD}, CC = cmpLT(${q.cop2VS}, ${q.cop2VT}[${q.cop2VecSelect}])`,J[33]=(q)=>`VEQ ${q.cop2VD}, CC = cmpEQ(${q.cop2VS}, ${q.cop2VT}[${q.cop2VecSelect}])`,J[34]=(q)=>`VNE ${q.cop2VD}, CC = cmpNE(${q.cop2VS}, ${q.cop2VT}[${q.cop2VecSelect}])`,J[35]=(q)=>`VGE ${q.cop2VD}, CC = cmpGE(${q.cop2VS}, ${q.cop2VT}[${q.cop2VecSelect}])`,J[36]=(q)=>`VCL ${q.cop2VD}, ACC = ${q.cop2VS} clip ${q.cop2VT}[${q.cop2VecSelect}]`,J[37]=(q)=>`VCH ${q.cop2VD}, ACC = ${q.cop2VS} clip ${q.cop2VT}[${q.cop2VecSelect}]`,J[38]=(q)=>`VCR ${q.cop2VD}, ACC = ${q.cop2VS} crimp ${q.cop2VT}[${q.cop2VecSelect}]`,J[39]=(q)=>`VMRG ${q.cop2VD} = VCC ? ${q.cop2VS} : ${q.cop2VT}[${q.cop2VecSelect}]`,J[40]=(q)=>`VAND ${q.cop2VD} = ${q.cop2VS} & ${q.cop2VT}[${q.cop2VecSelect}]`,J[41]=(q)=>`VNAND ${q.cop2VD} = ~(${q.cop2VS} & ${q.cop2VT}[${q.cop2VecSelect}])`,J[42]=(q)=>`VOR ${q.cop2VD} = ${q.cop2VS} | ${q.cop2VT}[${q.cop2VecSelect}]`,J[43]=(q)=>`VNOR ${q.cop2VD} = ~(${q.cop2VS} | ${q.cop2VT}[${q.cop2VecSelect}])`,J[44]=(q)=>`VXOR ${q.cop2VD} = ${q.cop2VS} ^ ${q.cop2VT}[${q.cop2VecSelect}]`,J[45]=(q)=>`VNXOR ${q.cop2VD} = ~(${q.cop2VS} ^ ${q.cop2VT}[${q.cop2VecSelect}])`,J[46]=(q)=>`V46 ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[47]=(q)=>`V47 ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[48]=(q)=>`VRCP ${q.cop2VD}[${q.cop2DE}] = 1/${q.cop2VT}[${q.cop2VecSelect}]`,J[49]=(q)=>`VRCPL ${q.cop2VD}[${q.cop2DE}] = 1/${q.cop2VT}[${q.cop2VecSelect}]`,J[50]=(q)=>`VRCPH ${q.cop2VD}[${q.cop2DE}], DIVIN = DIVOUT, ${q.cop2VT}[${q.cop2VecSelect}]`,J[51]=(q)=>`VMOV ${q.cop2VD}[${q.cop2DE}] = ${q.cop2VT}[${q.cop2VecSelect}]`,J[52]=(q)=>`VRSQ ${q.cop2VD}[${q.cop2DE}] = 1/sqrt(${q.cop2VT}[${q.cop2VecSelect}])`,J[53]=(q)=>`VRSQL ${q.cop2VD}[${q.cop2DE}] = 1/sqrt(${q.cop2VT}[${q.cop2VecSelect}])`,J[54]=(q)=>`VRSQH ${q.cop2VD}[${q.cop2DE}], DIVIN = DIVOUT, ${q.cop2VT}[${q.cop2VecSelect}]`,J[55]=(q)=>"VNOP",J[56]=(q)=>`VEXTT ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[57]=(q)=>`VEXTQ ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[58]=(q)=>`VEXTN ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[59]=(q)=>`V59 ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[60]=(q)=>`VINST ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[61]=(q)=>`VINSQ ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[62]=(q)=>`VINSN ${q.cop2VD} = 0, ACC = ${q.cop2VS} + ${q.cop2VT}[${q.cop2VecSelect}]`,J[63]=(q)=>"VNULL",J})(),qH=(()=>{let J=[];for(let q=0;q<32;q++)J.push(B6);return J[0]=(q)=>`LBV ${q.vmemVT}${q.vmemEls(1)} <- ${q.vmemload(1)}`,J[1]=(q)=>`LSV ${q.vmemVT}${q.vmemEls(2)} <- ${q.vmemload(2)}`,J[2]=(q)=>`LLV ${q.vmemVT}${q.vmemEls(3)} <- ${q.vmemload(4)}`,J[3]=(q)=>`LDV ${q.vmemVT}${q.vmemEls(4)} <- ${q.vmemload(8)}`,J[4]=(q)=>`LQV ${q.vmemVT} <- ${q.vmemload(16)}`,J[5]=(q)=>`LRV ${q.vmemVT} <- ${q.vmemload(16)}`,J[6]=(q)=>`LPV ${q.vmemVT} <- ${q.vmemload(8)}`,J[7]=(q)=>`LUV ${q.vmemVT} <- ${q.vmemload(8)}`,J[8]=(q)=>`LHV ${q.vmemVT} <- ${q.vmemload(16)}`,J[9]=(q)=>`LFV ${q.vmemVT} <- ${q.vmemload(16)}`,J[10]=(q)=>`LWV ${q.vmemVT} <- ${q.vmemload(16)}`,J[11]=(q)=>`LTV ${q.vmemVT} <- ${q.vmemload(16)}`,J})(),QH=(()=>{let J=[];for(let q=0;q<32;q++)J.push(B6);return J[0]=(q)=>`SBV ${q.vmemVT}${q.vmemEls(1)} -> ${q.vmemstore(1)}`,J[1]=(q)=>`SSV ${q.vmemVT}${q.vmemEls(2)} -> ${q.vmemstore(2)}`,J[2]=(q)=>`SLV ${q.vmemVT}${q.vmemEls(4)} -> ${q.vmemstore(4)}`,J[3]=(q)=>`SDV ${q.vmemVT}${q.vmemEls(8)} -> ${q.vmemstore(8)}`,J[4]=(q)=>`SQV ${q.vmemVT} -> ${q.vmemstore(16)}`,J[5]=(q)=>`SRV ${q.vmemVT} -> ${q.vmemstore(16)}`,J[6]=(q)=>`SPV ${q.vmemVT} -> ${q.vmemstore(8)}`,J[7]=(q)=>`SUV ${q.vmemVT} -> ${q.vmemstore(8)}`,J[8]=(q)=>`SHV ${q.vmemVT} -> ${q.vmemstore(16)}`,J[9]=(q)=>`SFV ${q.vmemVT} -> ${q.vmemstore(16)}`,J[10]=(q)=>`SWV ${q.vmemVT} -> ${q.vmemstore(16)}`,J[11]=(q)=>`STV ${q.vmemVT} -> ${q.vmemstore(16)}`,J})(),YH=(()=>{let J=[];for(let q=0;q<64;q++)J.push(B6);return J[0]=(q)=>rz[sK(q.opcode)](q),J[1]=(q)=>sz[gJ(q.opcode)](q),J[2]=(q)=>`J --> ${q.jumpAddress}`,J[3]=(q)=>`JAL --> ${q.jumpAddress}${q.writesRA()}`,J[4]=(q)=>{if(uJ(q.opcode)==gJ(q.opcode))return`B --> ${q.branchAddress}`;return`BEQ ${q.rs} == ${q.rt} --> ${q.branchAddress}`},J[5]=(q)=>`BNE ${q.rs} != ${q.rt} --> ${q.branchAddress}`,J[6]=(q)=>`BLEZ ${q.rs} <= 0 --> ${q.branchAddress}`,J[7]=(q)=>`BGTZ ${q.rs} > 0 --> ${q.branchAddress}`,J[8]=(q)=>`ADDI ${q.rt_d} = ${q.rs} + ${q.imm}`,J[9]=(q)=>`ADDIU ${q.rt_d} = ${q.rs} + ${q.imm}`,J[10]=(q)=>`SLTI ${q.rt_d} = (${q.rs} < ${q.imm})`,J[11]=(q)=>`SLTIU ${q.rt_d} = (${q.rs} < ${q.imm})`,J[12]=(q)=>`ANDI ${q.rt_d} = ${q.rs} & ${q.imm}`,J[13]=(q)=>`ORI ${q.rt_d} = ${q.rs} | ${q.imm}`,J[14]=(q)=>`XORI ${q.rt_d} = ${q.rs} ^ ${q.imm}`,J[15]=(q)=>`LUI ${q.rt_d} = ${q.imm} << 16`,J[16]=(q)=>iz[uJ(q.opcode)](q),J[18]=(q)=>tz[uJ(q.opcode)](q),J[32]=(q)=>`LB ${q.rt_d} <- ${q.memload()}`,J[33]=(q)=>`LH ${q.rt_d} <- ${q.memload()}`,J[35]=(q)=>`LW ${q.rt_d} <- ${q.memload()}`,J[36]=(q)=>`LBU ${q.rt_d} <- ${q.memload()}`,J[37]=(q)=>`LHU ${q.rt_d} <- ${q.memload()}`,J[39]=(q)=>`LWU ${q.rt_d} <- ${q.memload()}`,J[40]=(q)=>`SB ${q.rt} -> ${q.memstore()}`,J[41]=(q)=>`SH ${q.rt} -> ${q.memstore()}`,J[43]=(q)=>`SW ${q.rt} -> ${q.memstore()}`,J[50]=(q)=>qH[o6(q.opcode)](q),J[58]=(q)=>QH[o6(q.opcode)](q),J})();var KQ=function(J){let q,Q;if(q=J.match(/(#|0x)?([a-f0-9]{6})/i))Q=q[2];else if(q=J.match(/rgb\(\s*(\d*)\s*,\s*(\d*)\s*,\s*(\d*)\s*\)/))Q=parseInt(q[1]).toString(16).padStart(2,0)+parseInt(q[2]).toString(16).padStart(2,0)+parseInt(q[3]).toString(16).padStart(2,0);else if(q=J.match(/^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i))Q=q[1]+q[1]+q[2]+q[2]+q[3]+q[3];if(Q)return"#"+Q;return!1},$H=function(J){return WH.find((q)=>q.match(J))},HH=function(J){const q=document.createElement("style");q.innerHTML=J;const Q=document.querySelector("head link[rel=stylesheet], head style");if(Q)document.head.insertBefore(q,Q);else document.head.appendChild(q)};class X6{constructor(J,q,Q,Y,Z="div"){this.parent=J,this.object=q,this.property=Q,this._disabled=!1,this._hidden=!1,this.initialValue=this.getValue(),this.domElement=document.createElement("div"),this.domElement.classList.add("controller"),this.domElement.classList.add(Y),this.$name=document.createElement("div"),this.$name.classList.add("name"),X6.nextNameID=X6.nextNameID||0,this.$name.id=`lil-gui-name-${++X6.nextNameID}`,this.$widget=document.createElement(Z),this.$widget.classList.add("widget"),this.$disable=this.$widget,this.domElement.appendChild(this.$name),this.domElement.appendChild(this.$widget),this.domElement.addEventListener("keydown",(K)=>K.stopPropagation()),this.domElement.addEventListener("keyup",(K)=>K.stopPropagation()),this.parent.children.push(this),this.parent.controllers.push(this),this.parent.$children.appendChild(this.domElement),this._listenCallback=this._listenCallback.bind(this),this.name(Q)}name(J){return this._name=J,this.$name.innerHTML=J,this}onChange(J){return this._onChange=J,this}_callOnChange(){if(this.parent._callOnChange(this),this._onChange!==void 0)this._onChange.call(this,this.getValue());this._changed=!0}onFinishChange(J){return this._onFinishChange=J,this}_callOnFinishChange(){if(this._changed){if(this.parent._callOnFinishChange(this),this._onFinishChange!==void 0)this._onFinishChange.call(this,this.getValue())}this._changed=!1}reset(){return this.setValue(this.initialValue),this._callOnFinishChange(),this}enable(J=!0){return this.disable(!J)}disable(J=!0){if(J===this._disabled)return this;return this._disabled=J,this.domElement.classList.toggle("disabled",J),this.$disable.toggleAttribute("disabled",J),this}show(J=!0){return this._hidden=!J,this.domElement.style.display=this._hidden?"none":"",this}hide(){return this.show(!1)}options(J){const q=this.parent.add(this.object,this.property,J);return q.name(this._name),this.destroy(),q}min(J){return this}max(J){return this}step(J){return this}decimals(J){return this}listen(J=!0){if(this._listening=J,this._listenCallbackID!==void 0)cancelAnimationFrame(this._listenCallbackID),this._listenCallbackID=void 0;if(this._listening)this._listenCallback();return this}_listenCallback(){this._listenCallbackID=requestAnimationFrame(this._listenCallback);const J=this.save();if(J!==this._listenPrevValue)this.updateDisplay();this._listenPrevValue=J}getValue(){return this.object[this.property]}setValue(J){return this.object[this.property]=J,this._callOnChange(),this.updateDisplay(),this}updateDisplay(){return this}load(J){return this.setValue(J),this._callOnFinishChange(),this}save(){return this.getValue()}destroy(){this.listen(!1),this.parent.children.splice(this.parent.children.indexOf(this),1),this.parent.controllers.splice(this.parent.controllers.indexOf(this),1),this.parent.$children.removeChild(this.domElement)}}class qX extends X6{constructor(J,q,Q){super(J,q,Q,"boolean","label");this.$input=document.createElement("input"),this.$input.setAttribute("type","checkbox"),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$widget.appendChild(this.$input),this.$input.addEventListener("change",()=>{this.setValue(this.$input.checked),this._callOnFinishChange()}),this.$disable=this.$input,this.updateDisplay()}updateDisplay(){return this.$input.checked=this.getValue(),this}}var ZH={isPrimitive:!0,match:(J)=>typeof J==="string",fromHexString:KQ,toHexString:KQ},WJ={isPrimitive:!0,match:(J)=>typeof J==="number",fromHexString:(J)=>parseInt(J.substring(1),16),toHexString:(J)=>"#"+J.toString(16).padStart(6,0)},KH={isPrimitive:!1,match:(J)=>Array.isArray(J),fromHexString(J,q,Q=1){const Y=WJ.fromHexString(J);q[0]=(Y>>16&255)/255*Q,q[1]=(Y>>8&255)/255*Q,q[2]=(Y&255)/255*Q},toHexString([J,q,Q],Y=1){Y=255/Y;const Z=J*Y<<16^q*Y<<8^Q*Y<<0;return WJ.toHexString(Z)}},XH={isPrimitive:!1,match:(J)=>Object(J)===J,fromHexString(J,q,Q=1){const Y=WJ.fromHexString(J);q.r=(Y>>16&255)/255*Q,q.g=(Y>>8&255)/255*Q,q.b=(Y&255)/255*Q},toHexString({r:J,g:q,b:Q},Y=1){Y=255/Y;const Z=J*Y<<16^q*Y<<8^Q*Y<<0;return WJ.toHexString(Z)}},WH=[ZH,WJ,KH,XH];class QX extends X6{constructor(J,q,Q,Y){super(J,q,Q,"color");this.$input=document.createElement("input"),this.$input.setAttribute("type","color"),this.$input.setAttribute("tabindex",-1),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$text=document.createElement("input"),this.$text.setAttribute("type","text"),this.$text.setAttribute("spellcheck","false"),this.$text.setAttribute("aria-labelledby",this.$name.id),this.$display=document.createElement("div"),this.$display.classList.add("display"),this.$display.appendChild(this.$input),this.$widget.appendChild(this.$display),this.$widget.appendChild(this.$text),this._format=$H(this.initialValue),this._rgbScale=Y,this._initialValueHexString=this.save(),this._textFocused=!1,this.$input.addEventListener("input",()=>{this._setValueFromHexString(this.$input.value)}),this.$input.addEventListener("blur",()=>{this._callOnFinishChange()}),this.$text.addEventListener("input",()=>{const Z=KQ(this.$text.value);if(Z)this._setValueFromHexString(Z)}),this.$text.addEventListener("focus",()=>{this._textFocused=!0,this.$text.select()}),this.$text.addEventListener("blur",()=>{this._textFocused=!1,this.updateDisplay(),this._callOnFinishChange()}),this.$disable=this.$text,this.updateDisplay()}reset(){return this._setValueFromHexString(this._initialValueHexString),this}_setValueFromHexString(J){if(this._format.isPrimitive){const q=this._format.fromHexString(J);this.setValue(q)}else this._format.fromHexString(J,this.getValue(),this._rgbScale),this._callOnChange(),this.updateDisplay()}save(){return this._format.toHexString(this.getValue(),this._rgbScale)}load(J){return this._setValueFromHexString(J),this._callOnFinishChange(),this}updateDisplay(){if(this.$input.value=this._format.toHexString(this.getValue(),this._rgbScale),!this._textFocused)this.$text.value=this.$input.value.substring(1);return this.$display.style.backgroundColor=this.$input.value,this}}class pJ extends X6{constructor(J,q,Q){super(J,q,Q,"function");this.$button=document.createElement("button"),this.$button.appendChild(this.$name),this.$widget.appendChild(this.$button),this.$button.addEventListener("click",(Y)=>{Y.preventDefault(),this.getValue().call(this.object),this._callOnChange()}),this.$button.addEventListener("touchstart",()=>{},{passive:!0}),this.$disable=this.$button}}class YX extends X6{constructor(J,q,Q,Y,Z,K){super(J,q,Q,"number");this._initInput(),this.min(Y),this.max(Z);const X=K!==void 0;this.step(X?K:this._getImplicitStep(),X),this.updateDisplay()}decimals(J){return this._decimals=J,this.updateDisplay(),this}min(J){return this._min=J,this._onUpdateMinMax(),this}max(J){return this._max=J,this._onUpdateMinMax(),this}step(J,q=!0){return this._step=J,this._stepExplicit=q,this}updateDisplay(){const J=this.getValue();if(this._hasSlider){let q=(J-this._min)/(this._max-this._min);q=Math.max(0,Math.min(q,1)),this.$fill.style.width=q*100+"%"}if(!this._inputFocused)this.$input.value=this._decimals===void 0?J:J.toFixed(this._decimals);return this}_initInput(){if(this.$input=document.createElement("input"),this.$input.setAttribute("type","text"),this.$input.setAttribute("aria-labelledby",this.$name.id),window.matchMedia("(pointer: coarse)").matches)this.$input.setAttribute("type","number"),this.$input.setAttribute("step","any");this.$widget.appendChild(this.$input),this.$disable=this.$input;const q=()=>{let w=parseFloat(this.$input.value);if(isNaN(w))return;if(this._stepExplicit)w=this._snap(w);this.setValue(this._clamp(w))},Q=(w)=>{const y=parseFloat(this.$input.value);if(isNaN(y))return;this._snapClampSetValue(y+w),this.$input.value=this.getValue()},Y=(w)=>{if(w.key==="Enter")this.$input.blur();if(w.code==="ArrowUp")w.preventDefault(),Q(this._step*this._arrowKeyMultiplier(w));if(w.code==="ArrowDown")w.preventDefault(),Q(this._step*this._arrowKeyMultiplier(w)*-1)},Z=(w)=>{if(this._inputFocused)w.preventDefault(),Q(this._step*this._normalizeMouseWheel(w))};let K=!1,X,W,z,F,j;const G=5,P=(w)=>{X=w.clientX,W=z=w.clientY,K=!0,F=this.getValue(),j=0,window.addEventListener("mousemove",L),window.addEventListener("mouseup",U)},L=(w)=>{if(K){const y=w.clientX-X,S=w.clientY-W;if(Math.abs(S)>G)w.preventDefault(),this.$input.blur(),K=!1,this._setDraggingStyle(!0,"vertical");else if(Math.abs(y)>G)U()}if(!K){const y=w.clientY-z;if(j-=y*this._step*this._arrowKeyMultiplier(w),F+j>this._max)j=this._max-F;else if(F+j<this._min)j=this._min-F;this._snapClampSetValue(F+j)}z=w.clientY},U=()=>{this._setDraggingStyle(!1,"vertical"),this._callOnFinishChange(),window.removeEventListener("mousemove",L),window.removeEventListener("mouseup",U)},O=()=>{this._inputFocused=!0},E=()=>{this._inputFocused=!1,this.updateDisplay(),this._callOnFinishChange()};this.$input.addEventListener("input",q),this.$input.addEventListener("keydown",Y),this.$input.addEventListener("wheel",Z,{passive:!1}),this.$input.addEventListener("mousedown",P),this.$input.addEventListener("focus",O),this.$input.addEventListener("blur",E)}_initSlider(){this._hasSlider=!0,this.$slider=document.createElement("div"),this.$slider.classList.add("slider"),this.$fill=document.createElement("div"),this.$fill.classList.add("fill"),this.$slider.appendChild(this.$fill),this.$widget.insertBefore(this.$slider,this.$input),this.domElement.classList.add("hasSlider");const J=(E,w,y,S,g)=>{return(E-w)/(y-w)*(g-S)+S},q=(E)=>{const w=this.$slider.getBoundingClientRect();let y=J(E,w.left,w.right,this._min,this._max);this._snapClampSetValue(y)},Q=(E)=>{this._setDraggingStyle(!0),q(E.clientX),window.addEventListener("mousemove",Y),window.addEventListener("mouseup",Z)},Y=(E)=>{q(E.clientX)},Z=()=>{this._callOnFinishChange(),this._setDraggingStyle(!1),window.removeEventListener("mousemove",Y),window.removeEventListener("mouseup",Z)};let K=!1,X,W;const z=(E)=>{E.preventDefault(),this._setDraggingStyle(!0),q(E.touches[0].clientX),K=!1},F=(E)=>{if(E.touches.length>1)return;if(this._hasScrollBar)X=E.touches[0].clientX,W=E.touches[0].clientY,K=!0;else z(E);window.addEventListener("touchmove",j,{passive:!1}),window.addEventListener("touchend",G)},j=(E)=>{if(K){const w=E.touches[0].clientX-X,y=E.touches[0].clientY-W;if(Math.abs(w)>Math.abs(y))z(E);else window.removeEventListener("touchmove",j),window.removeEventListener("touchend",G)}else E.preventDefault(),q(E.touches[0].clientX)},G=()=>{this._callOnFinishChange(),this._setDraggingStyle(!1),window.removeEventListener("touchmove",j),window.removeEventListener("touchend",G)},P=this._callOnFinishChange.bind(this),L=400;let U;const O=(E)=>{if(Math.abs(E.deltaX)<Math.abs(E.deltaY)&&this._hasScrollBar)return;E.preventDefault();const y=this._normalizeMouseWheel(E)*this._step;this._snapClampSetValue(this.getValue()+y),this.$input.value=this.getValue(),clearTimeout(U),U=setTimeout(P,L)};this.$slider.addEventListener("mousedown",Q),this.$slider.addEventListener("touchstart",F,{passive:!1}),this.$slider.addEventListener("wheel",O,{passive:!1})}_setDraggingStyle(J,q="horizontal"){if(this.$slider)this.$slider.classList.toggle("active",J);document.body.classList.toggle("lil-gui-dragging",J),document.body.classList.toggle(`lil-gui-${q}`,J)}_getImplicitStep(){if(this._hasMin&&this._hasMax)return(this._max-this._min)/1000;return 0.1}_onUpdateMinMax(){if(!this._hasSlider&&this._hasMin&&this._hasMax){if(!this._stepExplicit)this.step(this._getImplicitStep(),!1);this._initSlider(),this.updateDisplay()}}_normalizeMouseWheel(J){let{deltaX:q,deltaY:Q}=J;if(Math.floor(J.deltaY)!==J.deltaY&&J.wheelDelta)q=0,Q=-J.wheelDelta/120,Q*=this._stepExplicit?1:10;return q+-Q}_arrowKeyMultiplier(J){let q=this._stepExplicit?1:10;if(J.shiftKey)q*=10;else if(J.altKey)q/=10;return q}_snap(J){const q=Math.round(J/this._step)*this._step;return parseFloat(q.toPrecision(15))}_clamp(J){if(J<this._min)J=this._min;if(J>this._max)J=this._max;return J}_snapClampSetValue(J){this.setValue(this._clamp(this._snap(J)))}get _hasScrollBar(){const J=this.parent.root.$children;return J.scrollHeight>J.clientHeight}get _hasMin(){return this._min!==void 0}get _hasMax(){return this._max!==void 0}}class ZX extends X6{constructor(J,q,Q,Y){super(J,q,Q,"option");this.$select=document.createElement("select"),this.$select.setAttribute("aria-labelledby",this.$name.id),this.$display=document.createElement("div"),this.$display.classList.add("display"),this._values=Array.isArray(Y)?Y:Object.values(Y),this._names=Array.isArray(Y)?Y:Object.keys(Y),this._names.forEach((Z)=>{const K=document.createElement("option");K.innerHTML=Z,this.$select.appendChild(K)}),this.$select.addEventListener("change",()=>{this.setValue(this._values[this.$select.selectedIndex]),this._callOnFinishChange()}),this.$select.addEventListener("focus",()=>{this.$display.classList.add("focus")}),this.$select.addEventListener("blur",()=>{this.$display.classList.remove("focus")}),this.$widget.appendChild(this.$select),this.$widget.appendChild(this.$display),this.$disable=this.$select,this.updateDisplay()}updateDisplay(){const J=this.getValue(),q=this._values.indexOf(J);return this.$select.selectedIndex=q,this.$display.innerHTML=q===-1?J:this._names[q],this}}class KX extends X6{constructor(J,q,Q){super(J,q,Q,"string");this.$input=document.createElement("input"),this.$input.setAttribute("type","text"),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$input.addEventListener("input",()=>{this.setValue(this.$input.value)}),this.$input.addEventListener("keydown",(Y)=>{if(Y.code==="Enter")this.$input.blur()}),this.$input.addEventListener("blur",()=>{this._callOnFinishChange()}),this.$widget.appendChild(this.$input),this.$disable=this.$input,this.updateDisplay()}updateDisplay(){return this.$input.value=this.getValue(),this}}var zH=`.lil-gui {
|
|
font-family: var(--font-family);
|
|
font-size: var(--font-size);
|
|
line-height: 1;
|
|
font-weight: normal;
|
|
font-style: normal;
|
|
text-align: left;
|
|
background-color: var(--background-color);
|
|
color: var(--text-color);
|
|
user-select: none;
|
|
-webkit-user-select: none;
|
|
touch-action: manipulation;
|
|
--background-color: #1f1f1f;
|
|
--text-color: #ebebeb;
|
|
--title-background-color: #111111;
|
|
--title-text-color: #ebebeb;
|
|
--widget-color: #424242;
|
|
--hover-color: #4f4f4f;
|
|
--focus-color: #595959;
|
|
--number-color: #2cc9ff;
|
|
--string-color: #a2db3c;
|
|
--font-size: 11px;
|
|
--input-font-size: 11px;
|
|
--font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
|
|
--font-family-mono: Menlo, Monaco, Consolas, "Droid Sans Mono", monospace;
|
|
--padding: 4px;
|
|
--spacing: 4px;
|
|
--widget-height: 20px;
|
|
--title-height: calc(var(--widget-height) + var(--spacing) * 1.25);
|
|
--name-width: 45%;
|
|
--slider-knob-width: 2px;
|
|
--slider-input-width: 27%;
|
|
--color-input-width: 27%;
|
|
--slider-input-min-width: 45px;
|
|
--color-input-min-width: 45px;
|
|
--folder-indent: 7px;
|
|
--widget-padding: 0 0 0 3px;
|
|
--widget-border-radius: 2px;
|
|
--checkbox-size: calc(0.75 * var(--widget-height));
|
|
--scrollbar-width: 5px;
|
|
}
|
|
.lil-gui, .lil-gui * {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
.lil-gui.root {
|
|
width: var(--width, 245px);
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.lil-gui.root > .title {
|
|
background: var(--title-background-color);
|
|
color: var(--title-text-color);
|
|
}
|
|
.lil-gui.root > .children {
|
|
overflow-x: hidden;
|
|
overflow-y: auto;
|
|
}
|
|
.lil-gui.root > .children::-webkit-scrollbar {
|
|
width: var(--scrollbar-width);
|
|
height: var(--scrollbar-width);
|
|
background: var(--background-color);
|
|
}
|
|
.lil-gui.root > .children::-webkit-scrollbar-thumb {
|
|
border-radius: var(--scrollbar-width);
|
|
background: var(--focus-color);
|
|
}
|
|
@media (pointer: coarse) {
|
|
.lil-gui.allow-touch-styles, .lil-gui.allow-touch-styles .lil-gui {
|
|
--widget-height: 28px;
|
|
--padding: 6px;
|
|
--spacing: 6px;
|
|
--font-size: 13px;
|
|
--input-font-size: 16px;
|
|
--folder-indent: 10px;
|
|
--scrollbar-width: 7px;
|
|
--slider-input-min-width: 50px;
|
|
--color-input-min-width: 65px;
|
|
}
|
|
}
|
|
.lil-gui.force-touch-styles, .lil-gui.force-touch-styles .lil-gui {
|
|
--widget-height: 28px;
|
|
--padding: 6px;
|
|
--spacing: 6px;
|
|
--font-size: 13px;
|
|
--input-font-size: 16px;
|
|
--folder-indent: 10px;
|
|
--scrollbar-width: 7px;
|
|
--slider-input-min-width: 50px;
|
|
--color-input-min-width: 65px;
|
|
}
|
|
.lil-gui.autoPlace {
|
|
max-height: 100%;
|
|
position: fixed;
|
|
top: 0;
|
|
right: 15px;
|
|
z-index: 1001;
|
|
}
|
|
|
|
.lil-gui .controller {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 0 var(--padding);
|
|
margin: var(--spacing) 0;
|
|
}
|
|
.lil-gui .controller.disabled {
|
|
opacity: 0.5;
|
|
}
|
|
.lil-gui .controller.disabled, .lil-gui .controller.disabled * {
|
|
pointer-events: none !important;
|
|
}
|
|
.lil-gui .controller > .name {
|
|
min-width: var(--name-width);
|
|
flex-shrink: 0;
|
|
white-space: pre;
|
|
padding-right: var(--spacing);
|
|
line-height: var(--widget-height);
|
|
}
|
|
.lil-gui .controller .widget {
|
|
position: relative;
|
|
display: flex;
|
|
align-items: center;
|
|
width: 100%;
|
|
min-height: var(--widget-height);
|
|
}
|
|
.lil-gui .controller.string input {
|
|
color: var(--string-color);
|
|
}
|
|
.lil-gui .controller.boolean .widget {
|
|
cursor: pointer;
|
|
}
|
|
.lil-gui .controller.color .display {
|
|
width: 100%;
|
|
height: var(--widget-height);
|
|
border-radius: var(--widget-border-radius);
|
|
position: relative;
|
|
}
|
|
@media (hover: hover) {
|
|
.lil-gui .controller.color .display:hover:before {
|
|
content: " ";
|
|
display: block;
|
|
position: absolute;
|
|
border-radius: var(--widget-border-radius);
|
|
border: 1px solid #fff9;
|
|
top: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
left: 0;
|
|
}
|
|
}
|
|
.lil-gui .controller.color input[type=color] {
|
|
opacity: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
cursor: pointer;
|
|
}
|
|
.lil-gui .controller.color input[type=text] {
|
|
margin-left: var(--spacing);
|
|
font-family: var(--font-family-mono);
|
|
min-width: var(--color-input-min-width);
|
|
width: var(--color-input-width);
|
|
flex-shrink: 0;
|
|
}
|
|
.lil-gui .controller.option select {
|
|
opacity: 0;
|
|
position: absolute;
|
|
width: 100%;
|
|
max-width: 100%;
|
|
}
|
|
.lil-gui .controller.option .display {
|
|
position: relative;
|
|
pointer-events: none;
|
|
border-radius: var(--widget-border-radius);
|
|
height: var(--widget-height);
|
|
line-height: var(--widget-height);
|
|
max-width: 100%;
|
|
overflow: hidden;
|
|
word-break: break-all;
|
|
padding-left: 0.55em;
|
|
padding-right: 1.75em;
|
|
background: var(--widget-color);
|
|
}
|
|
@media (hover: hover) {
|
|
.lil-gui .controller.option .display.focus {
|
|
background: var(--focus-color);
|
|
}
|
|
}
|
|
.lil-gui .controller.option .display.active {
|
|
background: var(--focus-color);
|
|
}
|
|
.lil-gui .controller.option .display:after {
|
|
font-family: "lil-gui";
|
|
content: "\u2195";
|
|
position: absolute;
|
|
top: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
padding-right: 0.375em;
|
|
}
|
|
.lil-gui .controller.option .widget,
|
|
.lil-gui .controller.option select {
|
|
cursor: pointer;
|
|
}
|
|
@media (hover: hover) {
|
|
.lil-gui .controller.option .widget:hover .display {
|
|
background: var(--hover-color);
|
|
}
|
|
}
|
|
.lil-gui .controller.number input {
|
|
color: var(--number-color);
|
|
}
|
|
.lil-gui .controller.number.hasSlider input {
|
|
margin-left: var(--spacing);
|
|
width: var(--slider-input-width);
|
|
min-width: var(--slider-input-min-width);
|
|
flex-shrink: 0;
|
|
}
|
|
.lil-gui .controller.number .slider {
|
|
width: 100%;
|
|
height: var(--widget-height);
|
|
background-color: var(--widget-color);
|
|
border-radius: var(--widget-border-radius);
|
|
padding-right: var(--slider-knob-width);
|
|
overflow: hidden;
|
|
cursor: ew-resize;
|
|
touch-action: pan-y;
|
|
}
|
|
@media (hover: hover) {
|
|
.lil-gui .controller.number .slider:hover {
|
|
background-color: var(--hover-color);
|
|
}
|
|
}
|
|
.lil-gui .controller.number .slider.active {
|
|
background-color: var(--focus-color);
|
|
}
|
|
.lil-gui .controller.number .slider.active .fill {
|
|
opacity: 0.95;
|
|
}
|
|
.lil-gui .controller.number .fill {
|
|
height: 100%;
|
|
border-right: var(--slider-knob-width) solid var(--number-color);
|
|
box-sizing: content-box;
|
|
}
|
|
|
|
.lil-gui-dragging .lil-gui {
|
|
--hover-color: var(--widget-color);
|
|
}
|
|
.lil-gui-dragging * {
|
|
cursor: ew-resize !important;
|
|
}
|
|
|
|
.lil-gui-dragging.lil-gui-vertical * {
|
|
cursor: ns-resize !important;
|
|
}
|
|
|
|
.lil-gui .title {
|
|
height: var(--title-height);
|
|
line-height: calc(var(--title-height) - 4px);
|
|
font-weight: 600;
|
|
padding: 0 var(--padding);
|
|
-webkit-tap-highlight-color: transparent;
|
|
cursor: pointer;
|
|
outline: none;
|
|
text-decoration-skip: objects;
|
|
}
|
|
.lil-gui .title:before {
|
|
font-family: "lil-gui";
|
|
content: "\u25BE";
|
|
padding-right: 2px;
|
|
display: inline-block;
|
|
}
|
|
.lil-gui .title:active {
|
|
background: var(--title-background-color);
|
|
opacity: 0.75;
|
|
}
|
|
@media (hover: hover) {
|
|
body:not(.lil-gui-dragging) .lil-gui .title:hover {
|
|
background: var(--title-background-color);
|
|
opacity: 0.85;
|
|
}
|
|
.lil-gui .title:focus {
|
|
text-decoration: underline var(--focus-color);
|
|
}
|
|
}
|
|
.lil-gui.root > .title:focus {
|
|
text-decoration: none !important;
|
|
}
|
|
.lil-gui.closed > .title:before {
|
|
content: "\u25B8";
|
|
}
|
|
.lil-gui.closed > .children {
|
|
transform: translateY(-7px);
|
|
opacity: 0;
|
|
}
|
|
.lil-gui.closed:not(.transition) > .children {
|
|
display: none;
|
|
}
|
|
.lil-gui.transition > .children {
|
|
transition-duration: 300ms;
|
|
transition-property: height, opacity, transform;
|
|
transition-timing-function: cubic-bezier(0.2, 0.6, 0.35, 1);
|
|
overflow: hidden;
|
|
pointer-events: none;
|
|
}
|
|
.lil-gui .children:empty:before {
|
|
content: "Empty";
|
|
padding: 0 var(--padding);
|
|
margin: var(--spacing) 0;
|
|
display: block;
|
|
height: var(--widget-height);
|
|
font-style: italic;
|
|
line-height: var(--widget-height);
|
|
opacity: 0.5;
|
|
}
|
|
.lil-gui.root > .children > .lil-gui > .title {
|
|
border: 0 solid var(--widget-color);
|
|
border-width: 1px 0;
|
|
transition: border-color 300ms;
|
|
}
|
|
.lil-gui.root > .children > .lil-gui.closed > .title {
|
|
border-bottom-color: transparent;
|
|
}
|
|
.lil-gui + .controller {
|
|
border-top: 1px solid var(--widget-color);
|
|
margin-top: 0;
|
|
padding-top: var(--spacing);
|
|
}
|
|
.lil-gui .lil-gui .lil-gui > .title {
|
|
border: none;
|
|
}
|
|
.lil-gui .lil-gui .lil-gui > .children {
|
|
border: none;
|
|
margin-left: var(--folder-indent);
|
|
border-left: 2px solid var(--widget-color);
|
|
}
|
|
.lil-gui .lil-gui .controller {
|
|
border: none;
|
|
}
|
|
|
|
.lil-gui input {
|
|
-webkit-tap-highlight-color: transparent;
|
|
border: 0;
|
|
outline: none;
|
|
font-family: var(--font-family);
|
|
font-size: var(--input-font-size);
|
|
border-radius: var(--widget-border-radius);
|
|
height: var(--widget-height);
|
|
background: var(--widget-color);
|
|
color: var(--text-color);
|
|
width: 100%;
|
|
}
|
|
@media (hover: hover) {
|
|
.lil-gui input:hover {
|
|
background: var(--hover-color);
|
|
}
|
|
.lil-gui input:active {
|
|
background: var(--focus-color);
|
|
}
|
|
}
|
|
.lil-gui input:disabled {
|
|
opacity: 1;
|
|
}
|
|
.lil-gui input[type=text],
|
|
.lil-gui input[type=number] {
|
|
padding: var(--widget-padding);
|
|
}
|
|
.lil-gui input[type=text]:focus,
|
|
.lil-gui input[type=number]:focus {
|
|
background: var(--focus-color);
|
|
}
|
|
.lil-gui input::-webkit-outer-spin-button,
|
|
.lil-gui input::-webkit-inner-spin-button {
|
|
-webkit-appearance: none;
|
|
margin: 0;
|
|
}
|
|
.lil-gui input[type=number] {
|
|
-moz-appearance: textfield;
|
|
}
|
|
.lil-gui input[type=checkbox] {
|
|
appearance: none;
|
|
-webkit-appearance: none;
|
|
height: var(--checkbox-size);
|
|
width: var(--checkbox-size);
|
|
border-radius: var(--widget-border-radius);
|
|
text-align: center;
|
|
cursor: pointer;
|
|
}
|
|
.lil-gui input[type=checkbox]:checked:before {
|
|
font-family: "lil-gui";
|
|
content: "\u2713";
|
|
font-size: var(--checkbox-size);
|
|
line-height: var(--checkbox-size);
|
|
}
|
|
@media (hover: hover) {
|
|
.lil-gui input[type=checkbox]:focus {
|
|
box-shadow: inset 0 0 0 1px var(--focus-color);
|
|
}
|
|
}
|
|
.lil-gui button {
|
|
-webkit-tap-highlight-color: transparent;
|
|
outline: none;
|
|
cursor: pointer;
|
|
font-family: var(--font-family);
|
|
font-size: var(--font-size);
|
|
color: var(--text-color);
|
|
width: 100%;
|
|
height: var(--widget-height);
|
|
text-transform: none;
|
|
background: var(--widget-color);
|
|
border-radius: var(--widget-border-radius);
|
|
border: 1px solid var(--widget-color);
|
|
text-align: center;
|
|
line-height: calc(var(--widget-height) - 4px);
|
|
}
|
|
@media (hover: hover) {
|
|
.lil-gui button:hover {
|
|
background: var(--hover-color);
|
|
border-color: var(--hover-color);
|
|
}
|
|
.lil-gui button:focus {
|
|
border-color: var(--focus-color);
|
|
}
|
|
}
|
|
.lil-gui button:active {
|
|
background: var(--focus-color);
|
|
}
|
|
|
|
@font-face {
|
|
font-family: "lil-gui";
|
|
src: url("data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAUsAAsAAAAACJwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAAH4AAADAImwmYE9TLzIAAAGIAAAAPwAAAGBKqH5SY21hcAAAAcgAAAD0AAACrukyyJBnbHlmAAACvAAAAF8AAACEIZpWH2hlYWQAAAMcAAAAJwAAADZfcj2zaGhlYQAAA0QAAAAYAAAAJAC5AHhobXR4AAADXAAAABAAAABMAZAAAGxvY2EAAANsAAAAFAAAACgCEgIybWF4cAAAA4AAAAAeAAAAIAEfABJuYW1lAAADoAAAASIAAAIK9SUU/XBvc3QAAATEAAAAZgAAAJCTcMc2eJxVjbEOgjAURU+hFRBK1dGRL+ALnAiToyMLEzFpnPz/eAshwSa97517c/MwwJmeB9kwPl+0cf5+uGPZXsqPu4nvZabcSZldZ6kfyWnomFY/eScKqZNWupKJO6kXN3K9uCVoL7iInPr1X5baXs3tjuMqCtzEuagm/AAlzQgPAAB4nGNgYRBlnMDAysDAYM/gBiT5oLQBAwuDJAMDEwMrMwNWEJDmmsJwgCFeXZghBcjlZMgFCzOiKOIFAB71Bb8AeJy1kjFuwkAQRZ+DwRAwBtNQRUGKQ8OdKCAWUhAgKLhIuAsVSpWz5Bbkj3dEgYiUIszqWdpZe+Z7/wB1oCYmIoboiwiLT2WjKl/jscrHfGg/pKdMkyklC5Zs2LEfHYpjcRoPzme9MWWmk3dWbK9ObkWkikOetJ554fWyoEsmdSlt+uR0pCJR34b6t/TVg1SY3sYvdf8vuiKrpyaDXDISiegp17p7579Gp3p++y7HPAiY9pmTibljrr85qSidtlg4+l25GLCaS8e6rRxNBmsnERunKbaOObRz7N72ju5vdAjYpBXHgJylOAVsMseDAPEP8LYoUHicY2BiAAEfhiAGJgZWBgZ7RnFRdnVJELCQlBSRlATJMoLV2DK4glSYs6ubq5vbKrJLSbGrgEmovDuDJVhe3VzcXFwNLCOILB/C4IuQ1xTn5FPilBTj5FPmBAB4WwoqAHicY2BkYGAA4sk1sR/j+W2+MnAzpDBgAyEMQUCSg4EJxAEAwUgFHgB4nGNgZGBgSGFggJMhDIwMqEAYAByHATJ4nGNgAIIUNEwmAABl3AGReJxjYAACIQYlBiMGJ3wQAEcQBEV4nGNgZGBgEGZgY2BiAAEQyQWEDAz/wXwGAAsPATIAAHicXdBNSsNAHAXwl35iA0UQXYnMShfS9GPZA7T7LgIu03SSpkwzYTIt1BN4Ak/gKTyAeCxfw39jZkjymzcvAwmAW/wgwHUEGDb36+jQQ3GXGot79L24jxCP4gHzF/EIr4jEIe7wxhOC3g2TMYy4Q7+Lu/SHuEd/ivt4wJd4wPxbPEKMX3GI5+DJFGaSn4qNzk8mcbKSR6xdXdhSzaOZJGtdapd4vVPbi6rP+cL7TGXOHtXKll4bY1Xl7EGnPtp7Xy2n00zyKLVHfkHBa4IcJ2oD3cgggWvt/V/FbDrUlEUJhTn/0azVWbNTNr0Ens8de1tceK9xZmfB1CPjOmPH4kitmvOubcNpmVTN3oFJyjzCvnmrwhJTzqzVj9jiSX911FjeAAB4nG3HMRKCMBBA0f0giiKi4DU8k0V2GWbIZDOh4PoWWvq6J5V8If9NVNQcaDhyouXMhY4rPTcG7jwYmXhKq8Wz+p762aNaeYXom2n3m2dLTVgsrCgFJ7OTmIkYbwIbC6vIB7WmFfAAAA==") format("woff");
|
|
}`,JX=!1;class XQ{constructor({parent:J,autoPlace:q=J===void 0,container:Q,width:Y,title:Z="Controls",closeFolders:K=!1,injectStyles:X=!0,touchStyles:W=!0}={}){if(this.parent=J,this.root=J?J.root:this,this.children=[],this.controllers=[],this.folders=[],this._closed=!1,this._hidden=!1,this.domElement=document.createElement("div"),this.domElement.classList.add("lil-gui"),this.$title=document.createElement("div"),this.$title.classList.add("title"),this.$title.setAttribute("role","button"),this.$title.setAttribute("aria-expanded",!0),this.$title.setAttribute("tabindex",0),this.$title.addEventListener("click",()=>this.openAnimated(this._closed)),this.$title.addEventListener("keydown",(z)=>{if(z.code==="Enter"||z.code==="Space")z.preventDefault(),this.$title.click()}),this.$title.addEventListener("touchstart",()=>{},{passive:!0}),this.$children=document.createElement("div"),this.$children.classList.add("children"),this.domElement.appendChild(this.$title),this.domElement.appendChild(this.$children),this.title(Z),this.parent){this.parent.children.push(this),this.parent.folders.push(this),this.parent.$children.appendChild(this.domElement);return}if(this.domElement.classList.add("root"),W)this.domElement.classList.add("allow-touch-styles");if(!JX&&X)HH(zH),JX=!0;if(Q)Q.appendChild(this.domElement);else if(q)this.domElement.classList.add("autoPlace"),document.body.appendChild(this.domElement);if(Y)this.domElement.style.setProperty("--width",Y+"px");this._closeFolders=K}add(J,q,Q,Y,Z){if(Object(Q)===Q)return new ZX(this,J,q,Q);const K=J[q];switch(typeof K){case"number":return new YX(this,J,q,Q,Y,Z);case"boolean":return new qX(this,J,q);case"string":return new KX(this,J,q);case"function":return new pJ(this,J,q)}console.error(`gui.add failed
|
|
property:`,q,`
|
|
object:`,J,`
|
|
value:`,K)}addColor(J,q,Q=1){return new QX(this,J,q,Q)}addFolder(J){const q=new XQ({parent:this,title:J});if(this.root._closeFolders)q.close();return q}load(J,q=!0){if(J.controllers)this.controllers.forEach((Q)=>{if(Q instanceof pJ)return;if(Q._name in J.controllers)Q.load(J.controllers[Q._name])});if(q&&J.folders)this.folders.forEach((Q)=>{if(Q._title in J.folders)Q.load(J.folders[Q._title])});return this}save(J=!0){const q={controllers:{},folders:{}};if(this.controllers.forEach((Q)=>{if(Q instanceof pJ)return;if(Q._name in q.controllers)throw new Error(`Cannot save GUI with duplicate property "${Q._name}"`);q.controllers[Q._name]=Q.save()}),J)this.folders.forEach((Q)=>{if(Q._title in q.folders)throw new Error(`Cannot save GUI with duplicate folder "${Q._title}"`);q.folders[Q._title]=Q.save()});return q}open(J=!0){return this._setClosed(!J),this.$title.setAttribute("aria-expanded",!this._closed),this.domElement.classList.toggle("closed",this._closed),this}close(){return this.open(!1)}_setClosed(J){if(this._closed===J)return;this._closed=J,this._callOnOpenClose(this)}show(J=!0){return this._hidden=!J,this.domElement.style.display=this._hidden?"none":"",this}hide(){return this.show(!1)}openAnimated(J=!0){return this._setClosed(!J),this.$title.setAttribute("aria-expanded",!this._closed),requestAnimationFrame(()=>{const q=this.$children.clientHeight;this.$children.style.height=q+"px",this.domElement.classList.add("transition");const Q=(Z)=>{if(Z.target!==this.$children)return;this.$children.style.height="",this.domElement.classList.remove("transition"),this.$children.removeEventListener("transitionend",Q)};this.$children.addEventListener("transitionend",Q);const Y=!J?0:this.$children.scrollHeight;this.domElement.classList.toggle("closed",!J),requestAnimationFrame(()=>{this.$children.style.height=Y+"px"})}),this}title(J){return this._title=J,this.$title.innerHTML=J,this}reset(J=!0){return(J?this.controllersRecursive():this.controllers).forEach((Q)=>Q.reset()),this}onChange(J){return this._onChange=J,this}_callOnChange(J){if(this.parent)this.parent._callOnChange(J);if(this._onChange!==void 0)this._onChange.call(this,{object:J.object,property:J.property,value:J.getValue(),controller:J})}onFinishChange(J){return this._onFinishChange=J,this}_callOnFinishChange(J){if(this.parent)this.parent._callOnFinishChange(J);if(this._onFinishChange!==void 0)this._onFinishChange.call(this,{object:J.object,property:J.property,value:J.getValue(),controller:J})}onOpenClose(J){return this._onOpenClose=J,this}_callOnOpenClose(J){if(this.parent)this.parent._callOnOpenClose(J);if(this._onOpenClose!==void 0)this._onOpenClose.call(this,J)}destroy(){if(this.parent)this.parent.children.splice(this.parent.children.indexOf(this),1),this.parent.folders.splice(this.parent.folders.indexOf(this),1);if(this.domElement.parentElement)this.domElement.parentElement.removeChild(this.domElement);Array.from(this.children).forEach((J)=>J.destroy())}controllersRecursive(){let J=Array.from(this.controllers);return this.folders.forEach((q)=>{J=J.concat(q.controllersRecursive())}),J}foldersRecursive(){let J=Array.from(this.folders);return this.folders.forEach((q)=>{J=J.concat(q.foldersRecursive())}),J}}var XX=XQ;function FH(){g0.show()}function jH(){g0.hide()}function WX(J){if(J)FH();else jH()}var g0=new XX;g0.title("Options");g0.hide();function HX(){WQ=new Map,mJ=new Map,$Q=[]}function zQ(){return mJ}function G8(J){let q=mJ.get(J);if(!q){if(!$X.enableDynarec)return null;let Q=WQ.get(J)||0;if(Q++,WQ.set(J,Q),Q<PH)return null;q=new zX(J),mJ.set(J,q)}if(!q.func)q.invalidate();return q}function FX(){let J=$Q;return $Q=[],J}var $X={enableDynarec:!0},GH=g0.addFolder("Performance");GH.add($X,"enableDynarec").name("Dynamic Recompilation");var PH=500,mJ=new Map,WQ=new Map,$Q=[];class zX{constructor(J){this.entryPC=J,this.minPC=J,this.maxPC=J+4,this.func=void 0,this.opsCompiled=0,this.executionCount=0,this.bailedOut=!1,this.nextFragments=[],this.bodyCode="",this.needsDelayCheck=!0,this.cop1statusKnown=!1,this.usesCop1=!1}invalidate(){this.minPC=this.entryPC,this.maxPC=this.entryPC+4,this.func=void 0,this.opsCompiled=0,this.executionCount=0,this.bailedOut=!1,this.nextFragments=[],this.bodyCode="",this.needsDelayCheck=!0,this.cop1statusKnown=!1,this.usesCop1=!1}updateMinMax(J){this.minPC=Math.min(this.minPC,J),this.maxPC=Math.max(this.maxPC,J+4)}getNextFragment(J,q){let Q=this.nextFragments[q];if(!Q||Q.entryPC!==J)Q=J===this.entryPC?this:G8(J),this.nextFragments[q]=Q;if(Q&&Q.opsCompiled>0&&!Q.func)Q.invalidate();return Q}}function aJ(J){var q="";if(J&$0.AA_EN)q+="|AA_EN";if(J&$0.Z_CMP)q+="|Z_CMP";if(J&$0.Z_UPD)q+="|Z_UPD";if(J&$0.IM_RD)q+="|IM_RD";if(J&$0.CLR_ON_CVG)q+="|CLR_ON_CVG";var Q=J&768;if(Q===$0.CVG_DST_CLAMP)q+="|CVG_DST_CLAMP";else if(Q===$0.CVG_DST_WRAP)q+="|CVG_DST_WRAP";else if(Q===$0.CVG_DST_FULL)q+="|CVG_DST_FULL";else if(Q===$0.CVG_DST_SAVE)q+="|CVG_DST_SAVE";var Y=J&3072;if(Y===$0.ZMODE_OPA)q+="|ZMODE_OPA";else if(Y===$0.ZMODE_INTER)q+="|ZMODE_INTER";else if(Y===$0.ZMODE_XLU)q+="|ZMODE_XLU";else if(Y===$0.ZMODE_DEC)q+="|ZMODE_DEC";if(J&$0.CVG_X_ALPHA)q+="|CVG_X_ALPHA";if(J&$0.ALPHA_CVG_SEL)q+="|ALPHA_CVG_SEL";if(J&$0.FORCE_BL)q+="|FORCE_BL";var Z=q.length>0?q.substr(1):"0",K=J>>>PQ,X="GBL_c1("+dJ(K>>>2)+") | GBL_c2("+dJ(K)+") /*"+r(K)+"*/";return Z+", "+X}function h0(J){var q=J;if(J===UQ)q="G_TX_LOADTILE";if(J===LH)q="G_TX_RENDERTILE";return q}function A8(J){switch(J){case VH:return"G_TX_WRAP";case FJ:return"G_TX_MIRROR";case R6:return"G_TX_CLAMP";case FJ|R6:return"G_TX_MIRROR|G_TX_CLAMP"}return J}function h8(J,q){var Q="";if(q&J.G_ZBUFFER)Q+="|G_ZBUFFER";if(q&J.G_TEXTURE_ENABLE)Q+="|G_TEXTURE_ENABLE";if(q&J.G_SHADE)Q+="|G_SHADE";if(q&J.G_SHADING_SMOOTH)Q+="|G_SHADING_SMOOTH";var Y=q&J.G_CULL_BOTH;if(Y===J.G_CULL_FRONT)Q+="|G_CULL_FRONT";else if(Y===J.G_CULL_BACK)Q+="|G_CULL_BACK";else if(Y===J.G_CULL_BOTH)Q+="|G_CULL_BOTH";if(q&J.G_FOG)Q+="|G_FOG";if(q&J.G_LIGHTING)Q+="|G_LIGHTING";if(q&J.G_TEXTURE_GEN)Q+="|G_TEXTURE_GEN";if(q&J.G_TEXTURE_GEN_LINEAR)Q+="|G_TEXTURE_GEN_LINEAR";if(q&J.G_LOD)Q+="|G_LOD";return Q.length>0?Q.substr(1):"0"}var Y0=function(J){return J.nameOf=(q)=>{for(var Q in J)if(Object.prototype.hasOwnProperty.call(J,Q)&&J[Q]===q)return Q;return N(q)},Object.freeze(J)};function dJ(J){var q=J>>>12&3,Q=J>>>8&3,Y=J>>>4&3,Z=J>>>0&3;return NX[q]+","+UH[Q]+","+NX[Y]+","+MH[Z]}var $0={AA_EN:8,Z_CMP:16,Z_UPD:32,IM_RD:64,CLR_ON_CVG:128,CVG_DST_CLAMP:0,CVG_DST_WRAP:256,CVG_DST_FULL:512,CVG_DST_SAVE:768,ZMODE_OPA:0,ZMODE_INTER:1024,ZMODE_XLU:2048,ZMODE_DEC:3072,CVG_X_ALPHA:4096,ALPHA_CVG_SEL:8192,FORCE_BL:16384,TEX_EDGE:0},HQ=0,jX=2;var PQ=16,P8=3,rJ=4,GX=4294967288,PX=0,$J=4,zJ=6,FQ=8,nJ=9,oJ=12,cJ=14,jQ=16,lJ=17,NQ=19,HJ=20;var GQ=23,x0=Y0({G_GBI2_MV_VIEWPORT:8,G_GBI2_MV_LIGHT:10,G_GBI2_MV_POINT:12,G_GBI2_MV_MATRIX:14,G_GBI2_MVO_LOOKATX:0,G_GBI2_MVO_LOOKATY:24,G_GBI2_MVO_L0:48,G_GBI2_MVO_L1:72,G_GBI2_MVO_L2:96,G_GBI2_MVO_L3:120,G_GBI2_MVO_L4:144,G_GBI2_MVO_L5:168,G_GBI2_MVO_L6:192,G_GBI2_MVO_L7:216}),sJ=1<<GQ,L8=3<<HJ,iJ=1<<NQ,tJ=3<<lJ,eJ=1<<jQ,V8=3<<cJ,U8=3<<oJ,J9=7<<nJ,q9=1<<FQ,Q9=3<<zJ,Y9=3<<$J;var Z9=1;var LQ=2;var VQ=4,M8=0;var j0=Y0({G_MW_MATRIX:0,G_MW_NUMLIGHT:2,G_MW_CLIP:4,G_MW_SEGMENT:6,G_MW_FOG:8,G_MW_LIGHTCOL:10,G_MW_POINTS:12,G_MW_PERSPNORM:14}),z0=Y0({G_MV_VIEWPORT:128,G_MV_LOOKATY:130,G_MV_LOOKATX:132,G_MV_L0:134,G_MV_L1:136,G_MV_L2:138,G_MV_L3:140,G_MV_L4:142,G_MV_L5:144,G_MV_L6:146,G_MV_L7:148,G_MV_TXTATT:150,G_MV_MATRIX_1:158,G_MV_MATRIX_2:152,G_MV_MATRIX_3:154,G_MV_MATRIX_4:156}),LX=0,K9=Y0({G_MWO_CLIP_RNX:4,G_MWO_CLIP_RNY:12,G_MWO_CLIP_RPX:20,G_MWO_CLIP_RPY:28}),X9=1,W9=2,$9=4,z9=8,H9=16,F9=32,j9=Y0({FR_NEG_FRUSTRATIO_1:1,FR_POS_FRUSTRATIO_1:65535,FR_NEG_FRUSTRATIO_2:2,FR_POS_FRUSTRATIO_2:65534,FR_NEG_FRUSTRATIO_3:3,FR_POS_FRUSTRATIO_3:65533,FR_NEG_FRUSTRATIO_4:4,FR_POS_FRUSTRATIO_4:65532,FR_NEG_FRUSTRATIO_5:5,FR_POS_FRUSTRATIO_5:65531,FR_NEG_FRUSTRATIO_6:6,FR_POS_FRUSTRATIO_6:65530}),N9=Y0({G_MWO_SEGMENT_0:0,G_MWO_SEGMENT_1:1,G_MWO_SEGMENT_2:2,G_MWO_SEGMENT_3:3,G_MWO_SEGMENT_4:4,G_MWO_SEGMENT_5:5,G_MWO_SEGMENT_6:6,G_MWO_SEGMENT_7:7,G_MWO_SEGMENT_8:8,G_MWO_SEGMENT_9:9,G_MWO_SEGMENT_A:10,G_MWO_SEGMENT_B:11,G_MWO_SEGMENT_C:12,G_MWO_SEGMENT_D:13,G_MWO_SEGMENT_E:14,G_MWO_SEGMENT_F:15});var O8=Y0({G_MWO_POINT_RGBA:16,G_MWO_POINT_ST:20,G_MWO_POINT_XYSCREEN:24,G_MWO_POINT_ZSCREEN:28}),G9=Y0({NUMLIGHTS_1:1,NUMLIGHTS_2:2,NUMLIGHTS_3:3,NUMLIGHTS_4:4,NUMLIGHTS_5:5,NUMLIGHTS_6:6,NUMLIGHTS_7:7}),UQ=7,LH=0,VH=0,FJ=1,R6=2,VX=Y0({G_SC_NON_INTERLACE:0,G_SC_ODD_INTERLACE:3,G_SC_EVEN_INTERLACE:2}),a0={G_ZBUFFER:1,G_TEXTURE_ENABLE:2,G_SHADE:4,G_SHADING_SMOOTH:512,G_CULL_FRONT:4096,G_CULL_BACK:8192,G_CULL_BOTH:12288,G_FOG:65536,G_LIGHTING:131072,G_TEXTURE_GEN:262144,G_TEXTURE_GEN_LINEAR:524288,G_LOD:1048576},V6={G_TEXTURE_ENABLE:2,G_SHADE:0,G_ZBUFFER:1,G_CULL_BACK:512,G_CULL_FRONT:1024,G_CULL_BOTH:1536,G_FOG:65536,G_LIGHTING:131072,G_TEXTURE_GEN:262144,G_TEXTURE_GEN_LINEAR:524288,G_LOD:1048576,G_SHADING_SMOOTH:2097152},Z0=Y0({G_IM_FMT_RGBA:0,G_IM_FMT_YUV:1,G_IM_FMT_CI:2,G_IM_FMT_IA:3,G_IM_FMT_I:4}),p=Y0({G_IM_SIZ_4b:0,G_IM_SIZ_8b:1,G_IM_SIZ_16b:2,G_IM_SIZ_32b:3}),P9=Y0({G_PM_1PRIMITIVE:1<<GQ,G_PM_NPRIMITIVE:0<<GQ}),K0=Y0({G_CYC_1CYCLE:0<<HJ,G_CYC_2CYCLE:1<<HJ,G_CYC_COPY:2<<HJ,G_CYC_FILL:3<<HJ}),L9=Y0({G_TP_NONE:0<<NQ,G_TP_PERSP:1<<NQ}),V9=Y0({G_TD_CLAMP:0<<lJ,G_TD_SHARPEN:1<<lJ,G_TD_DETAIL:2<<lJ}),U9=Y0({G_TL_TILE:0<<jQ,G_TL_LOD:1<<jQ}),E8=Y0({G_TT_NONE:0<<cJ,G_TT_RGBA16:2<<cJ,G_TT_IA16:3<<cJ}),w8=Y0({G_TF_POINT:0<<oJ,G_TF_AVERAGE:3<<oJ,G_TF_BILERP:2<<oJ}),M9=Y0({G_TC_CONV:0<<nJ,G_TC_FILTCONV:5<<nJ,G_TC_FILT:6<<nJ}),O9=Y0({G_CK_NONE:0<<FQ,G_CK_KEY:1<<FQ}),A9=Y0({G_CD_MAGICSQ:0<<zJ,G_CD_BAYER:1<<zJ,G_CD_NOISE:2<<zJ,G_CD_DISABLE:3<<zJ}),h9=Y0({G_AD_PATTERN:0<<$J,G_AD_NOTPATTERN:1<<$J,G_AD_NOISE:2<<$J,G_AD_DISABLE:3<<$J}),c6=Y0({G_AC_NONE:0<<HQ,G_AC_THRESHOLD:1<<HQ,G_AC_DITHER:3<<HQ}),l6=Y0({G_ZS_PIXEL:0<<jX,G_ZS_PRIM:1<<jX}),NX=["G_BL_CLR_IN","G_BL_CLR_MEM","G_BL_CLR_BL","G_BL_CLR_FOG"],UH=["G_BL_A_IN","G_BL_A_FOG","G_BL_A_SHADE","G_BL_0"],MH=["G_BL_1MA","G_BL_A_MEM","G_BL_1","G_BL_0"];function OH(J){var q=J>>>8&255;let Q=J&255;return q<<24|q<<16|q<<8|Q}function AQ(J){let q=C8[J>>>11&31],Q=C8[J>>>6&31],Y=C8[J>>>1&31],Z=J&1?255:0;return q<<24|Q<<16|Y<<8|Z}var AH=function(J,q,Q){const Y=J.data,Z=J.width*4;let K=0;const X=Q.line<<4;let W=Q.tmem<<3,z=0;for(let F=0;F<Q.height;++F){let j=W,G=K;for(let P=0;P<Q.width;++P){const L=j^z;Y[G+0]=q[L+0],Y[G+1]=q[L+1],Y[G+2]=q[L+2],Y[G+3]=q[L+3],j+=4,G+=4}W+=X,K+=Z,z^=8}},hH=function(J,q,Q){let Y=J.data,Z=J.width*4,K=0,X=Q.line<<3,W=Q.tmem<<3,z=0;for(let F=0;F<Q.height;++F){let j=W,G=K;for(let P=0;P<Q.width;++P){let L=j^z,U=q[L]<<8|q[L+1];Y[G+0]=C8[U>>>11&31],Y[G+1]=C8[U>>>6&31],Y[G+2]=C8[U>>>1&31],Y[G+3]=U&1?255:0,j+=2,G+=4}W+=X,K+=Z,z^=4}},EH=function(J,q,Q){let Y=J.data,Z=J.width*4,K=0,X=Q.line<<3,W=Q.tmem<<3,z=0;for(let F=0;F<Q.height;++F){let j=W,G=K;for(let P=0;P<Q.width;++P){let L=j^z,U=q[L],O=q[L+1];Y[G+0]=U,Y[G+1]=U,Y[G+2]=U,Y[G+3]=O,j+=2,G+=4}W+=X,K+=Z,z^=4}},wH=function(J,q,Q){let Y=J.data,Z=J.width*4,K=0,X=Q.line<<3,W=Q.tmem<<3,z=0;for(let F=0;F<Q.height;++F){let j=W,G=K;for(let P=0;P<Q.width;++P){let L=j^z,U=q[L],O=jJ[U>>>4&15],E=jJ[U&15];Y[G+0]=O,Y[G+1]=O,Y[G+2]=O,Y[G+3]=E,j+=1,G+=4}W+=X,K+=Z,z^=4}},kH=function(J,q,Q){let Y=J.data,Z=J.width*4,K=0,X=Q.line<<3,W=Q.tmem<<3,z=0;for(let F=0;F<Q.height;++F){let j=W,G=K;for(let P=0;P+1<Q.width;P+=2){let L=j^z,U=q[L],O=OQ[(U&224)>>>5],E=MQ[(U&16)>>>4],w=OQ[(U&14)>>>1],y=MQ[(U&1)>>>0];Y[G+0]=O,Y[G+1]=O,Y[G+2]=O,Y[G+3]=E,Y[G+4]=w,Y[G+5]=w,Y[G+6]=w,Y[G+7]=y,j+=1,G+=8}if(Q.width&1){let P=j^z,L=q[P],U=OQ[(L&224)>>>5],O=MQ[(L&16)>>>4];Y[G+0]=U,Y[G+1]=U,Y[G+2]=U,Y[G+3]=O,j+=1,G+=4}W+=X,K+=Z,z^=4}},CH=function(J,q,Q){let Y=J.data,Z=J.width*4,K=0,X=Q.line<<3,W=Q.tmem<<3,z=0;for(let F=0;F<Q.height;++F){let j=W,G=K;for(let P=0;P<Q.width;++P){let L=q[j^z];Y[G+0]=L,Y[G+1]=L,Y[G+2]=L,Y[G+3]=L,j+=1,G+=4}W+=X,K+=Z,z^=4}},DH=function(J,q,Q){let Y=J.data,Z=J.width*4,K=0,X=Q.line<<3,W=Q.tmem<<3,z=0;for(let F=0;F<Q.height;++F){let j=W,G=K;for(let P=0;P+1<Q.width;P+=2){let L=q[j^z],U=jJ[(L&240)>>>4],O=jJ[(L&15)>>>0];Y[G+0]=U,Y[G+1]=U,Y[G+2]=U,Y[G+3]=U,Y[G+4]=O,Y[G+5]=O,Y[G+6]=O,Y[G+7]=O,j+=1,G+=8}if(Q.width&1){let P=q[j^z],L=jJ[(P&240)>>>4];Y[G+0]=L,Y[G+1]=L,Y[G+2]=L,Y[G+3]=L,j+=1,G+=4}W+=X,K+=Z,z^=4}},UX=function(J,q,Q,Y){const Z=J.data,K=J.width*4;let X=0;const W=Q.line<<3;let z=Q.tmem<<3;const F=0;for(let G=0;G<256;++G){const U=2048+(G*4+F)*2,O=q[U+0]<<8|q[U+1];k8[G]=Y(O)}let j=0;for(let G=0;G<Q.height;++G){let P=z,L=X;for(let U=0;U<Q.width;++U){const O=k8[q[P^j]];Z[L+0]=O>>24&255,Z[L+1]=O>>16&255,Z[L+2]=O>>8&255,Z[L+3]=O&255,P+=1,L+=4}z+=W,X+=K,j^=4}},MX=function(J,q,Q,Y,Z){const K=J.data,X=J.width*4;let W=0;const z=Q.line<<3;let F=Q.tmem<<3;const j=0;for(let P=0;P<16;++P){const O=2048+((Y*16|P)*4+j)*2,E=q[O+0]<<8|q[O+1];k8[P]=Z(E)}let G=0;for(let P=0;P<Q.height;++P){let L=F,U=W;for(let O=0;O+1<Q.width;O+=2){let E=q[L^G],w=k8[(E&240)>>>4],y=k8[(E&15)>>>0];K[U+0]=w>>24&255,K[U+1]=w>>16&255,K[U+2]=w>>8&255,K[U+3]=w&255,K[U+4]=y>>24&255,K[U+5]=y>>16&255,K[U+6]=y>>8&255,K[U+7]=y&255,L+=1,U+=8}if(Q.width&1){let O=q[L^G],E=k8[(O&240)>>>4];K[U+0]=E>>24&255,K[U+1]=E>>16&255,K[U+2]=E>>8&255,K[U+3]=E&255,L+=1,U+=4}F+=z,W+=X,G^=4}};function OX(J,q,Q,Y){var Z=Y===E8.G_TT_IA16?OH:AQ;switch(Q.format){case Z0.G_IM_FMT_RGBA:switch(Q.size){case p.G_IM_SIZ_32b:return AH(J,q,Q),!0;case p.G_IM_SIZ_16b:return hH(J,q,Q),!0;case p.G_IM_SIZ_8b:return UX(J,q,Q,Z),!0;case p.G_IM_SIZ_4b:return MX(J,q,Q,Q.palette,Z),!0}break;case Z0.G_IM_FMT_IA:switch(Q.size){case p.G_IM_SIZ_16b:return EH(J,q,Q),!0;case p.G_IM_SIZ_8b:return wH(J,q,Q),!0;case p.G_IM_SIZ_4b:return kH(J,q,Q),!0}break;case Z0.G_IM_FMT_I:switch(Q.size){case p.G_IM_SIZ_8b:return CH(J,q,Q),!0;case p.G_IM_SIZ_4b:return DH(J,q,Q),!0}break;case Z0.G_IM_FMT_CI:switch(Q.size){case p.G_IM_SIZ_8b:return UX(J,q,Q,Z),!0;case p.G_IM_SIZ_4b:return MX(J,q,Q,Q.palette,Z),!0}break}return!1}var MQ=[0,255],OQ=[0,36,73,109,146,182,219,255],jJ=[0,17,34,51,68,85,102,119,136,153,170,187,204,221,238,255],C8=[0,8,16,24,33,41,49,57,66,74,82,90,99,107,115,123,132,140,148,156,165,173,181,189,198,206,214,222,231,239,247,255],k8=new Uint32Array(256);function E9(J,q,Q){let Y;switch(q){case P8:Y=`gsDPSetAlphaCompare(${c6.nameOf(Q)});`;break;case rJ:Y=`gsDPSetDepthSource(${l6.nameOf(Q)});`;break;case GX:Y=`gsDPSetRenderMode(${aJ(Q)});`;break;default:Y=`gsSPSetOtherMode(G_SETOTHERMODE_L, ${N(q)}, ${N(Q)}`;break}J.text(Y)}function w9(J,q,Q,Y,Z){let K;switch(q){case PX:break;case Y9:K=`gsDPSetAlphaDither(${h9.nameOf(Z)});`;break;case Q9:K=`gsDPSetColorDither(${A9.nameOf(Z)});`;break;case q9:K=`gsDPSetCombineKey(${O9.nameOf(Z)});`;break;case J9:K=`gsDPSetTextureConvert(${M9.nameOf(Z)});`;break;case U8:K=`gsDPSetTextureFilter(${w8.nameOf(Z)});`;break;case eJ:K=`gsDPSetTextureLOD(${U9.nameOf(Z)});`;break;case V8:K=`gsDPSetTextureLUT(${E8.nameOf(Z)});`;break;case tJ:K=`gsDPSetTextureDetail(${V9.nameOf(Z)});`;break;case iJ:K=`gsDPSetTexturePersp(${L9.nameOf(Z)});`;break;case L8:K=`gsDPSetCycleType(${K0.nameOf(Z)});`;break;case sJ:K=`gsDPPipelineMode(${P9.nameOf(Z)});`;break;default:K=`gsSPSetOtherMode(G_SETOTHERMODE_H, ${N(q)}, ${N(Z)});`;break}J.text(K)}var AX=function(J,q,Q,Y){const Z=`${J}, ${q}, ${Q}`,K=`${Z}, ${Y}`;if(J<128&&q<128||q<128&&Q<128||Q<128&&J<128)return`<span style="color: white; background-color: rgb(${Z})">${K}</span>`;return`<span style="background-color: rgb(${Z})">${K}</span>`};function b6(J){const q=J>>>24&255,Q=J>>>16&255,Y=J>>>8&255,Z=J&255;return AX(q,Q,Y,Z)}function k9(J){const q=J&255,Q=J>>>8&255,Y=J>>>16&255,Z=J>>>24&255;return AX(q,Q,Y,Z)}function hX(J){return b6(AQ(J))}function kQ(J,q,Q){let Y=wQ(J,q),Z=wQ(J,Q),K=J.createProgram();if(J.attachShader(K,Y),J.attachShader(K,Z),J.linkProgram(K),!J.getProgramParameter(K,J.LINK_STATUS))a(!1,"Unable to initialize the shader program.");return K}var wQ=function(J,q){let Q=document.getElementById(q);if(!Q)return null;let Y=yX(Q),Z;if(Q.type==="x-shader/x-fragment")Z=J.FRAGMENT_SHADER;else if(Q.type==="x-shader/x-vertex")Z=J.VERTEX_SHADER;else return null;return IX(J,Y,Z)},yX=function(J){let q="",Q=J.firstChild;while(Q){if(Q.nodeType==Node.TEXT_NODE)q+=Q.textContent;Q=Q.nextSibling}return q},IX=function(J,q,Q){let Y=J.createShader(Q);if(J.shaderSource(Y,q),J.compileShader(Y),!J.getShaderParameter(Y,J.COMPILE_STATUS))return a(!1,"An error occurred compiling the shaders: "+J.getShaderInfoLog(Y)),null;return Y};function RX(J,q,Q,Y,Z){let K=Y<K0.G_CYC_COPY?`${q.toString(16)+Q.toString(16)}_${Y}`:Y.toString();if(Z)K+="_alphaThreshold";let X=wX.get(K);if(X)return X;if(!EQ)EQ=wQ(J,"n64-shader-vs");if(!hQ){let C6=document.getElementById("n64-shader-fs");if(C6)hQ=yX(C6)}let W=q>>>20&15,z=Q>>>28&15,F=q>>>15&31,j=Q>>>15&7,G=q>>>12&7,P=Q>>>12&7,L=q>>>9&7,U=Q>>>9&7,O=q>>>5&15,E=Q>>>24&15,w=q>>>0&31,y=Q>>>6&7,S=Q>>>21&7,g=Q>>>3&7,x=Q>>>18&7,H0=Q>>>0&7,w0;if(Y===K0.G_CYC_FILL)w0="col = shade;\n";else if(Y===K0.G_CYC_COPY)w0="col = tex0;\n";else if(Y===K0.G_CYC_1CYCLE)w0="",w0+="col.rgb = ("+C9[W]+" - "+C9[z]+") * "+kX[F]+" + "+DX[j]+";\n",w0+="col.a = ("+T6[G]+" - "+T6[P]+") * "+T6[L]+" + "+T6[U]+";\n";else w0="",w0+="col.rgb = ("+C9[W]+" - "+C9[z]+") * "+kX[F]+" + "+DX[j]+";\n",w0+="col.a = ("+T6[G]+" - "+T6[P]+") * "+T6[L]+" + "+T6[U]+";\n",w0+="combined = vec4(col.rgb, col.a);\n",w0+="col.rgb = ("+CX[O]+" - "+CX[E]+") * "+IH[w]+" + "+BH[y]+";\n",w0+="col.a = ("+D9[S]+" - "+D9[g]+") * "+D9[x]+" + "+D9[H0]+";\n";if(Z)w0+="if(col.a <= uAlphaThreshold) discard;\n";let o8=hQ.replace("{{body}}",w0);if(yH){let C6="\n";C6+="\tRGB0 = ("+I9[W]+" - "+B9[z]+") * "+y9[F]+" + "+R9[j]+"\n",C6+="\t A0 = ("+_6[G]+" - "+_6[P]+") * "+b9[L]+" + "+T9[U]+"\n",C6+="\tRGB1 = ("+I9[O]+" - "+B9[E]+") * "+y9[w]+" + "+R9[y]+"\n",C6+="\t A1 = ("+_6[S]+" - "+_6[g]+") * "+b9[x]+" + "+T9[H0]+"\n";let Jz=o8.split("\n").join("<br>");M("Compiled "+C6+"\nto\n"+Jz)}let mZ=IX(J,o8,J.FRAGMENT_SHADER);if(!mZ)return null;let c8=J.createProgram();if(J.attachShader(c8,EQ),J.attachShader(c8,mZ),J.linkProgram(c8),!J.getProgramParameter(c8,J.LINK_STATUS))a(!1,"Unable to initialize the shader program.");return X=new BX(J,c8,o8),wX.set(K,X),X}function _9(J,q){let Q=J>>>20&15,Y=q>>>28&15,Z=J>>>15&31,K=q>>>15&7,X=J>>>12&7,W=q>>>12&7,z=J>>>9&7,F=q>>>9&7,j=J>>>5&15,G=q>>>24&15,P=J>>>0&31,L=q>>>6&7,U=q>>>21&7,O=q>>>3&7,E=q>>>18&7,w=q>>>0&7,y="";return y+="RGB0 = ("+I9[Q]+" - "+B9[Y]+") * "+y9[Z]+" + "+R9[K]+"\n",y+=" A0 = ("+_6[X]+" - "+_6[W]+") * "+b9[z]+" + "+T9[F]+"\n",y+="RGB1 = ("+I9[j]+" - "+B9[G]+") * "+y9[P]+" + "+R9[L]+"\n",y+=" A1 = ("+_6[U]+" - "+_6[O]+") * "+b9[E]+" + "+T9[w]+"\n",y}var yH=!1,wX=new Map,hQ=null,EQ=null,kX=["combined.rgb","tex0.rgb","tex1.rgb","prim.rgb","shade.rgb","env.rgb","one.rgb","combined.a","tex0.a","tex1.a","prim.a","shade.a","env.a","lod_frac","prim_lod_frac","k5","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","zero.rgb"],IH=["combined.rgb","tex1.rgb","tex0.rgb","prim.rgb","shade.rgb","env.rgb","one.rgb","combined.a","tex1.a","tex0.a","prim.a","shade.a","env.a","lod_frac","prim_lod_frac","k5","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","? ","zero.rgb"],C9=["combined.rgb","tex0.rgb","tex1.rgb","prim.rgb","shade.rgb","env.rgb","one.rgb","combined.a","tex0.a","tex1.a","prim.a","shade.a","env.a","lod_frac","prim_lod_frac","zero.rgb"],CX=["combined.rgb","tex1.rgb","tex0.rgb","prim.rgb","shade.rgb","env.rgb","one.rgb","combined.a","tex1.a","tex0.a","prim.a","shade.a","env.a","lod_frac","prim_lod_frac","zero.rgb"],DX=["combined.rgb","tex0.rgb","tex1.rgb","prim.rgb","shade.rgb","env.rgb","one.rgb","zero.rgb"],BH=["combined.rgb","tex1.rgb","tex0.rgb","prim.rgb","shade.rgb","env.rgb","one.rgb","zero.rgb"],T6=["combined.a","tex0.a","tex1.a","prim.a","shade.a","env.a","one.a","zero.a"],D9=["combined.a","tex1.a","tex0.a","prim.a","shade.a","env.a","one.a","zero.a"],y9=["Combined ","Texel0 ","Texel1 ","Primitive ","Shade ","Env ","KeyScale ","CombinedAlph","Texel0_Alpha","Texel1_Alpha","Prim_Alpha ","Shade_Alpha ","Env_Alpha ","LOD_Frac ","PrimLODFrac ","K5 ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 "],I9=["Combined ","Texel0 ","Texel1 ","Primitive ","Shade ","Env ","1 ","Noise ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 "],B9=["Combined ","Texel0 ","Texel1 ","Primitive ","Shade ","Env ","KeyCenter ","K4 ","0 ","0 ","0 ","0 ","0 ","0 ","0 ","0 "],R9=["Combined ","Texel0 ","Texel1 ","Primitive ","Shade ","Env ","1 ","0 "],_6=["Combined ","Texel0 ","Texel1 ","Primitive ","Shade ","Env ","PrimLODFrac ","0 "],b9=["Combined ","Texel0 ","Texel1 ","Primitive ","Shade ","Env ","1 ","0 "],T9=["Combined ","Texel0 ","Texel1 ","Primitive ","Shade ","Env ","1 ","0 "];class BX{constructor(J,q,Q){this.program=q,this.shaderSource=Q,this.vertexPositionAttribute=J.getAttribLocation(q,"aVertexPosition"),this.vertexColorAttribute=J.getAttribLocation(q,"aVertexColor"),this.texCoordAttribute=J.getAttribLocation(q,"aTextureCoord"),this.uSamplerUniform0=J.getUniformLocation(q,"uSampler0"),this.uSamplerUniform1=J.getUniformLocation(q,"uSampler1"),this.uTexScaleUniform0=J.getUniformLocation(q,"uTexScale0"),this.uTexScaleUniform1=J.getUniformLocation(q,"uTexScale1"),this.uTexOffsetUniform0=J.getUniformLocation(q,"uTexOffset0"),this.uTexOffsetUniform1=J.getUniformLocation(q,"uTexOffset1"),this.uPrimColorUniform=J.getUniformLocation(q,"uPrimColor"),this.uEnvColorUniform=J.getUniformLocation(q,"uEnvColor"),this.uAlphaThresholdUniform=J.getUniformLocation(q,"uAlphaThresholdUniform")}}var bH=function(J){const q=DQ("x",J,z9,X9),Q=DQ("y",J,H9,W9),Y=DQ("z",J,F9,$9);return`${q} ${Q} ${Y}`},DQ=function(J,q,Q,Y){const Z=q&Q,K=q&Y;let X="",W="";if(Z&&K)X="clip-err",W="!";else if(Z)X="clip-pos",W=">";else if(K)X="clip-neg",W="<";else X="clip-none",W="0";return`<span class="${X}">${J}${W}</span>`},S9,D8,S6,bX=$("#dlist-content"),RH=0,TX="";class yQ{constructor(J,q){this.state=J,this.processDList=q,this.currentOp=0,this.numOps=0,this.bailAfter=-1,this.lastTask,this.stateTimeShown=-1,this.running=!1,this.requested=!1,this.dlFocusCounter=0}onNewTask(J){if(this.lastTask=J,this.requested){if(TX==""||J.detectVersionString().includes(TX)){if(this.dlFocusCounter==RH)this.requested=!1,n64js.breakEmulationForDisplayListDebug(),this.stateTimeShown=-1,this.running=!0;this.dlFocusCounter++}}else this.dlFocusCounter=0}toggle(){if(this.running)this.hideUI(),this.bailAfter=-1,this.running=!1,n64js.toggleRun();else this.showUI(),this.requested=!0}halt(){this.showUI(),this.requested=!1,this.running=!0,this.bailAfter=this.currentOp,this.stateTimeShown=-1}debugDisplayList(){if(this.stateTimeShown==-1){const J=new _X(this);this.processDList(this.lastTask,J,-1),J.finalise(),this.numOps=J.numOps>0?J.numOps-1:0,this.setScrubRange(this.numOps);const q=this.bailAfter==-1?this.numOps:this.bailAfter;this.setScrubTime(q)}if(this.processDList(this.lastTask,null,this.bailAfter),this.stateTimeShown!==this.bailAfter)this.updateStateUI(),this.stateTimeShown=this.bailAfter}postOp(J){if(J>-1&&this.currentOp>=J)return!0;return this.currentOp++,!1}updateStateUI(){D8.find("#dl-geometrymode-content").html(this.buildStateTab()),D8.find("#dl-vertices-content").html(this.buildVerticesTab()),D8.find("#dl-tiles-content").html(this.buildTilesTab()),D8.find("#dl-combiner-content").html(this.buildCombinerTab()),D8.find("#dl-rdp-content").html(this.buildRDPTab())}setScrubText(J,q){S9.find(".scrub-text").html(`uCode op ${J}/${q}.`)}setScrubRange(J){S9.find("input").attr({min:0,max:J,value:J}),this.setScrubText(J,J)}setScrubTime(J){this.bailAfter=J,this.setScrubText(this.bailAfter,this.numOps);const q=S6.find(`#I${this.bailAfter}`);S6.scrollTop(S6.scrollTop()+q.position().top-S6.height()/2+q.height()/2);const Q="hle-cur-instr";S6.find(".hle-instr").removeClass(Q),q.addClass(Q)}initUI(){const J=bX.find("#controls");this.bailAfter=-1,this.numOps=0;const q=this;J.find("#rwd").click(()=>{if(q.running&&q.bailAfter>0)q.setScrubTime(q.bailAfter-1)}),J.find("#fwd").click(()=>{if(q.running&&q.bailAfter<q.numOps)q.setScrubTime(q.bailAfter+1)}),J.find("#stop").click(()=>{this.toggle()}),S9=J.find(".scrub"),S9.find("input").change(function(){q.setScrubTime($(this).val()|0)}),this.setScrubRange(0),D8=bX.find(".hle-state"),S6=$('<div class="hle-disasm"></div>'),$("#adjacent-debug").empty().append(S6)}showUI(){n64js.debugger().show(),$("#dlist-tab").tab("show")}hideUI(){n64js.debugger().hide()}setDisplayListOutput(J){S6.html(J),J.find(".dl-tip").parent().click(function(){$(this).find(".dl-tip").toggle()})}buildStateTab(){const J=$('<table class="table table-condensed dl-debug-table" style="width: auto;"></table>'),q=$("<tr />");for(let Q in this.state.geometryMode)if(Object.prototype.hasOwnProperty.call(this.state.geometryMode,Q)){const Y=$(`<td>${Q}</td>`);Y.addClass(this.state.geometryMode[Q]?"dl-debug-geommode-enabled":"dl-debug-geommode-disabled"),q.append(Y)}return J.append(q),J}buildRDPTab(){const J=this.state.rdpOtherModeL,q=this.state.rdpOtherModeH,Q=this.state.textureImage,Y=new Map([["alphaCompare",c6.nameOf(J&P8)],["depthSource",l6.nameOf(J&rJ)],["renderMode",aJ(J)],["alphaDither",h9.nameOf(q&Y9)],["colorDither",A9.nameOf(q&Q9)],["combineKey",O9.nameOf(q&q9)],["textureConvert",M9.nameOf(q&J9)],["textureFilter",w8.nameOf(q&U8)],["textureLUT",E8.nameOf(q&V8)],["textureLOD",U9.nameOf(q&eJ)],["texturePersp",L9.nameOf(q&iJ)],["textureDetail",V9.nameOf(q&tJ)],["cycleType",K0.nameOf(q&L8)],["pipelineMode",P9.nameOf(q&sJ)],[""," "],["TI.format",Z0.nameOf(Q.format)],["TI.size",p.nameOf(Q.size)],["TI.width",Q.width],["TI.address",N(Q.address)]]),Z=$('<table class="table table-condensed dl-debug-table" style="width: auto;"></table>');for(let[K,X]of Y){let W=$(`<tr><td>${K}</td><td>${X}</td></tr>`);Z.append(W)}return Z}buildColorsTable(){const J=["fillColor","envColor","primColor","blendColor","fogColor"],q=$('<table class="table table-condensed dl-debug-table" style="width: auto;"></table>');for(let Q of J){let Y=$(`<tr><td>${Q}</td><td>${b6(this.state[Q])}</td></tr>`);q.append(Y)}return q}buildCombinerTab(){const J=$('<pre class="combine"></pre>');J.append(K0.nameOf(this.state.getCycleType())+"\n"),J.append(this.buildColorsTable()),J.append(_9(this.state.combine.hi,this.state.combine.lo));const q=this.renderer.getCurrentN64Shader();if(q)J.append(q.shaderSource);return J}buildTexture(J){const q=this.renderer.lookupTexture(J);if(q)return q.createScaledCanvas(8)}buildTilesTab(){const J=$("<div />");J.append(this.buildTilesTable());const q=[],Q=$("<tr />");for(let Z=0;Z<8;++Z){let K=this.buildTexture(Z);q.push(h0(Z));let X=$("<td />");X.append(K?K:""),Q.append(X)}const Y=$('<table class="table table-condensed dl-debug-table" style="width: auto"></table>');return Y.append($(`<tr><th>${q.join("</th><th>")}</th></tr>`)),Y.append(Q),J.append(Y),J}buildTilesTable(){const J=["tile #","format","size","line","tmem","palette","cmS","maskS","shiftS","cmT","maskT","shiftT","left","top","right","bottom","width","height","unmasked w","unmasked h"],q=$('<table class="table table-condensed dl-debug-table" style="width: auto"></table>'),Q=$(`<tr><th>${J.join("</th><th>")}</th></tr>`);q.append(Q);for(let Y=0;Y<this.state.tiles.length;++Y){const Z=this.state.tiles[Y];if(Z.format===-1)continue;const K=[];K.push(h0(Y)),K.push(Z0.nameOf(Z.format)),K.push(p.nameOf(Z.size)),K.push(Z.line),K.push(Z.tmem),K.push(Z.palette),K.push(A8(Z.cmS)),K.push(Z.maskS),K.push(Z.shiftS),K.push(A8(Z.cmT)),K.push(Z.maskT),K.push(Z.shiftT),K.push(Z.left),K.push(Z.top),K.push(Z.right),K.push(Z.bottom),K.push(Z.width),K.push(Z.height),K.push(Z.unmaskedWidth),K.push(Z.unmaskedHeight);const X=$(`<tr><td>${K.join("</td><td>")}</td></tr>`);q.append(X)}return q}buildVerticesTab(){const J=["vtx #","x","y","z","px","py","pz","pw","color","u","v","clip"],q=$('<table class="table table-condensed dl-debug-table" style="width: auto"></table>'),Q=$(`<tr><th>${J.join("</th><th>")}</th></tr>`);q.append(Q);for(let Y=0;Y<this.state.projectedVertices.length;++Y){const Z=this.state.projectedVertices[Y];if(!Z.set)continue;const K=Z.pos.x/Z.pos.w,X=Z.pos.y/Z.pos.w,W=Z.pos.z/Z.pos.w,z=[];z.push(Y),z.push(K.toFixed(3)),z.push(X.toFixed(3)),z.push(W.toFixed(3)),z.push(Z.pos.x.toFixed(3)),z.push(Z.pos.y.toFixed(3)),z.push(Z.pos.z.toFixed(3)),z.push(Z.pos.w.toFixed(3)),z.push(k9(Z.color)),z.push(Z.u.toFixed(3)),z.push(Z.v.toFixed(3)),z.push(bH(Z.clipFlags));const F=$(`<tr><td>${z.join("</td><td>")}</td></tr>`);q.append(F)}return q}}class _X{constructor(J){this.debugController=J,this.$currentDis=$("<pre></pre>"),this.$span=void 0,this.numOps=0}begin(J,q,Q){const Y=new Array(Q+1).join(" ");this.$span=$(`<span class="hle-instr" id="I${this.numOps}" />`),this.$span.append(`${NK(this.numOps,5)} ${B(J,32)}${B(q,32)} ${Y}`),this.$currentDis.append(this.$span)}text(J){this.$span.append(J)}tip(J){const q=$(`<div class="dl-tip">${J}</div>`);q.hide(),this.$span.append(q)}end(){this.$span.append("<br>"),this.numOps++}finalise=function(){this.debugController.setDisplayListOutput(this.$currentDis)};rgba8888(J){return b6(J)}rgba5551(J){return hX(J)}}class X0{constructor(J,q,Q){if(Q!==void 0)this.elems=new Float32Array(3),this.elems[0]=J,this.elems[1]=q,this.elems[2]=Q;else this.elems=J||new Float32Array(3)}get x(){return this.elems[0]}get y(){return this.elems[1]}get z(){return this.elems[2]}set x(J){this.elems[0]=J}set y(J){this.elems[1]=J}set z(J){this.elems[2]=J}set(J,q,Q){return this.x=J,this.y=q,this.z=Q,this}dot(J){let q=0;for(let Q=0;Q<this.elems.length;++Q)q+=this.elems[Q]*J.elems[Q];return q}lengthSqr(){return this.dot(this)}length(){return Math.sqrt(this.lengthSqr())}addInPlace(J){for(var q=0;q<this.elems.length;++q)this.elems[q]+=J.elems[q];return this}subInPlace(J){for(var q=0;q<this.elems.length;++q)this.elems[q]-=J.elems[q];return this}scaleInPlace(J){for(var q=0;q<this.elems.length;++q)this.elems[q]*=J;return this}vecScaleInPlace(J){for(var q=0;q<this.elems.length;++q)this.elems[q]*=J.elems[q];return this}invVecScaleInPlace(J){for(var q=0;q<this.elems.length;++q)this.elems[q]/=J.elems[q];return this}normaliseInPlace(){var J=this.length();if(J>0)return this.scaleInPlace(1/J);return this}static create(J){let q=new X0;return q.elems[0]=J[0],q.elems[1]=J[1],q.elems[2]=J[2],q}}class y0{constructor(J){this.elems=J||new Float32Array(16)}multiply(J){let q=this.elems,Q=J.elems,Y=new Float32Array(16);for(let Z=0;Z<4;++Z)for(let K=0;K<4;++K)Y[Z*4+K]+=q[Z*4+0]*Q[0+K],Y[Z*4+K]+=q[Z*4+1]*Q[4+K],Y[Z*4+K]+=q[Z*4+2]*Q[8+K],Y[Z*4+K]+=q[Z*4+3]*Q[12+K];return new y0(Y)}transformNormal(J,q){let Q=this.elems,Y=J.elems,Z=Y[0],K=Y[1],X=Y[2];q.elems[0]=Q[0]*Z+Q[1]*K+Q[2]*X,q.elems[1]=Q[4]*Z+Q[5]*K+Q[6]*X,q.elems[2]=Q[8]*Z+Q[9]*K+Q[10]*X}transformPoint(J,q){let Q=this.elems,Y=J.elems,Z=Y[0],K=Y[1],X=Y[2];q.elems[0]=Q[0]*Z+Q[1]*K+Q[2]*X+Q[3],q.elems[1]=Q[4]*Z+Q[5]*K+Q[6]*X+Q[7],q.elems[2]=Q[8]*Z+Q[9]*K+Q[10]*X+Q[11],q.elems[3]=Q[12]*Z+Q[13]*K+Q[14]*X+Q[15]}static identity(){let J=new Float32Array(16);return J[0]=1,J[5]=1,J[10]=1,J[15]=1,new y0(J)}copy(){let J=new Float32Array(16);for(let q=0;q<16;q++)J[q]=this.elems[q];return new y0(J)}static makeOrtho(J,q,Q,Y,Z,K){let X=-(q+J)/(q-J),W=-(Y+Q)/(Y-Q),z=-(K+Z)/(K-Z),F=new Float32Array(16);return F[0]=2/(q-J),F[1]=0,F[2]=0,F[3]=0,F[4]=0,F[5]=2/(Y-Q),F[6]=0,F[7]=0,F[8]=0,F[9]=0,F[10]=-2/(K-Z),F[11]=0,F[12]=X,F[13]=W,F[14]=z,F[15]=1,new y0(F)}}var W6={canvasScale:1,haltOnWarning:!1,dumpMicrocodeSubstring:""},IQ=g0.addFolder("Graphics");IQ.add(W6,"canvasScale").name("Canvas Scale").min(1).max(4).step(0.25);IQ.add(W6,"haltOnWarning").name("Halt on Warning");IQ.add(W6,"dumpMicrocodeSubstring").name("Dump Microcode");function y8(J,q){return(J>>>2)-(q>>>2)+1&1023}var SX=function(J,q){return q?Math.min(1<<q,J):J};class BQ{constructor(){this.format=-1,this.size=0,this.line=0,this.tmem=0,this.palette=0,this.cmT=0,this.maskT=0,this.shiftT=0,this.cmS=0,this.maskS=0,this.shiftS=0,this.uls=0,this.ult=0,this.lrs=0,this.lrt=0,this.hash=0}get left(){return this.uls/4}get top(){return this.ult/4}get right(){return this.lrs/4}get bottom(){return this.lrt/4}get unmaskedWidth(){return y8(this.lrs,this.uls)}get unmaskedHeight(){return y8(this.lrt,this.ult)}get width(){return SX(this.unmaskedWidth,this.maskS)}get height(){return SX(this.unmaskedHeight,this.maskT)}set(J,q,Q,Y,Z,K,X,W,z,F,j){this.format=J,this.size=q,this.line=Q,this.tmem=Y,this.palette=Z,this.cmS=K,this.maskS=X,this.shiftS=W,this.cmT=z,this.maskT=F,this.shiftT=j,this.hash=0}setSize(J,q,Q,Y){this.uls=J,this.ult=q,this.lrs=Q,this.lrt=Y,this.hash=0}}class RQ{constructor(J){this.numTris=0,this.maxTris=J,this.positions=new Float32Array(J*3*4),this.colours=new Uint32Array(J*3*1),this.coords=new Float32Array(J*3*2)}reset(){this.numTris=0}empty(){return this.numTris==0}hasCapacity(J){return this.numTris+J<this.maxTris}pushTri(J,q,Q){if(this.numTris>=this.maxTris)return!1;var Y=this.numTris*3*4,Z=this.numTris*3*1,K=this.numTris*3*2,X=J.pos,W=q.pos,z=Q.pos;return this.positions[Y+0]=X.x,this.positions[Y+1]=X.y,this.positions[Y+2]=X.z,this.positions[Y+3]=X.w,this.positions[Y+4]=W.x,this.positions[Y+5]=W.y,this.positions[Y+6]=W.z,this.positions[Y+7]=W.w,this.positions[Y+8]=z.x,this.positions[Y+9]=z.y,this.positions[Y+10]=z.z,this.positions[Y+11]=z.w,this.colours[Z+0]=J.color,this.colours[Z+1]=q.color,this.colours[Z+2]=Q.color,this.coords[K+0]=J.u,this.coords[K+1]=J.v,this.coords[K+2]=q.u,this.coords[K+3]=q.v,this.coords[K+4]=Q.u,this.coords[K+5]=Q.v,this.numTris++,!0}pushTriWithUV(J,q,Q,Y,Z,K,X,W,z){if(this.numTris>=this.maxTris)return!1;var F=this.numTris*3*4,j=this.numTris*3*1,G=this.numTris*3*2,P=J.pos,L=q.pos,U=Q.pos;return this.positions[F+0]=P.x,this.positions[F+1]=P.y,this.positions[F+2]=P.z,this.positions[F+3]=P.w,this.positions[F+4]=L.x,this.positions[F+5]=L.y,this.positions[F+6]=L.z,this.positions[F+7]=L.w,this.positions[F+8]=U.x,this.positions[F+9]=U.y,this.positions[F+10]=U.z,this.positions[F+11]=U.w,this.colours[j+0]=J.color,this.colours[j+1]=q.color,this.colours[j+2]=Q.color,this.coords[G+0]=Y,this.coords[G+1]=Z,this.coords[G+2]=K,this.coords[G+3]=X,this.coords[G+4]=W,this.coords[G+5]=z,this.numTris++,!0}}var _H=function(J){return{r:(J>>>11&31)/31,g:(J>>>6&31)/31,b:(J>>>1&31)/31,a:(J>>>0&1)/1}},uX=function(J){return{r:(J>>>24&255)/255,g:(J>>>16&255)/255,b:(J>>>8&255)/255,a:(J>>>0&255)/255}},TH=!0,vX=new Map,fX=new Map;class NJ{constructor(J,q){this.state=J,this.ramDV=q,this.vertexStride=2,this.version="",this.triangleBuffer=new RQ(64),this.onLoadUcodeHandler=null,this.gbiCommonCommands=new Map([[228,this.executeTexRect.bind(this)],[229,this.executeTexRectFlip.bind(this)],[230,this.executeRDPLoadSync.bind(this)],[231,this.executeRDPPipeSync.bind(this)],[232,this.executeRDPTileSync.bind(this)],[233,this.executeRDPFullSync.bind(this)],[234,this.executeSetKeyGB.bind(this)],[235,this.executeSetKeyR.bind(this)],[236,this.executeSetConvert.bind(this)],[237,this.executeSetScissor.bind(this)],[238,this.executeSetPrimDepth.bind(this)],[239,this.executeSetRDPOtherMode.bind(this)],[240,this.executeLoadTLut.bind(this)],[242,this.executeSetTileSize.bind(this)],[243,this.executeLoadBlock.bind(this)],[244,this.executeLoadTile.bind(this)],[245,this.executeSetTile.bind(this)],[246,this.executeFillRect.bind(this)],[247,this.executeSetFillColor.bind(this)],[248,this.executeSetFogColor.bind(this)],[249,this.executeSetBlendColor.bind(this)],[250,this.executeSetPrimColor.bind(this)],[251,this.executeSetEnvColor.bind(this)],[252,this.executeSetCombine.bind(this)],[253,this.executeSetTImg.bind(this)],[254,this.executeSetZImg.bind(this)],[255,this.executeSetCImg.bind(this)]])}buildCommandTable(){const J=[];for(let q=0;q<256;++q){let Q=this.getHandler(q);if(!Q)Q=this.executeUnknown.bind(this);J.push(Q)}return J}getHandler(J){const q=this.gbiCommonCommands.get(J);if(q)return q;return null}onLoadUcode(J){this.onLoadUcodeHandler=J}executeUnknown(J,q){this.warn(`Unknown display list op ${M0(J>>>24)}`,`cmd0 ${N(J)}, cmd1 ${N(q)}`)}warnUnimplemented(J){this.warn(J,"unimplemented")}warn(J,q){if(fX.get(J))return;fX.set(J,!0);const Q=q!==void 0?`${J}: ${q}`:J;if(W6.haltOnWarning)this.hleHalt(Q);else n64js.warn(Q)}loadMatrix(J,q){const Y=new DataView(this.ramDV.buffer,J);if(q!=64)this.warn("Unusual matrix length",`${q}`);const Z=new Float32Array(16);for(let K=0;K<4;++K)Z[0+K]=(Y.getInt16(K*8+0)<<16|Y.getUint16(K*8+0+32))*0.0000152587890625,Z[4+K]=(Y.getInt16(K*8+2)<<16|Y.getUint16(K*8+2+32))*0.0000152587890625,Z[8+K]=(Y.getInt16(K*8+4)<<16|Y.getUint16(K*8+4+32))*0.0000152587890625,Z[12+K]=(Y.getInt16(K*8+6)<<16|Y.getUint16(K*8+6+32))*0.0000152587890625;return new y0(Z)}previewMatrix(J){const q=J.elems,Q=[q[0],q[1],q[2],q[3]],Y=[q[4],q[5],q[6],q[7]],Z=[q[8],q[9],q[10],q[11]],K=[q[12],q[13],q[14],q[15]];return`<div><table class="matrix-table">
|
|
<tr><td>${Q.join("</td><td>")}</td></tr>
|
|
<tr><td>${Y.join("</td><td>")}</td></tr>
|
|
<tr><td>${Z.join("</td><td>")}</td></tr>
|
|
<tr><td>${K.join("</td><td>")}</td></tr>
|
|
</table></div>`}loadViewport(J){const q=new X0(+this.ramDV.getInt16(J+0)/4,-this.ramDV.getInt16(J+2)/4,+this.ramDV.getInt16(J+4)),Q=new X0(this.ramDV.getInt16(J+8)/4,this.ramDV.getInt16(J+10)/4,this.ramDV.getInt16(J+12));this.state.viewport.set(q,Q)}previewViewport(J){const q=new X0(this.ramDV.getInt16(J+0)/4,this.ramDV.getInt16(J+2)/4,this.ramDV.getInt16(J+4)),Q=new X0(this.ramDV.getInt16(J+8)/4,this.ramDV.getInt16(J+10)/4,this.ramDV.getInt16(J+12));let Y="";return Y+=`scale = (${q.x}, ${q.y}, ${q.z}) `,Y+=`trans = (${Q.x}, ${Q.y}, ${Q.z}) `,Y}loadLight(J,q){if(J>=this.state.lights.length){M(`light index ${J} out of range`);return}this.state.lights[J].color=uX(this.ramDV.getUint32(q+0)),this.state.lights[J].dir=X0.create([this.ramDV.getInt8(q+8),this.ramDV.getInt8(q+9),this.ramDV.getInt8(q+10)]).normaliseInPlace()}previewLight(J){let q="";q+=`color = ${b6(this.ramDV.getUint32(J+0))} `,q+=`colorCopy = ${b6(this.ramDV.getUint32(J+4))} `;const Q=X0.create([this.ramDV.getInt8(J+8),this.ramDV.getInt8(J+9),this.ramDV.getInt8(J+10)]).normaliseInPlace();return q+=`norm = (${Q.x}, ${Q.y}, ${Q.z})`,q}loadVertices(J,q,Q,Y){const Z=this.state.geometryMode.lighting,K=this.state.geometryMode.textureGen,X=this.state.geometryMode.textureGenLinear,W=new DataView(this.ramDV.buffer,Q);if(Y)this.previewVertex(J,q,W,Y,Z);if(J+q>=this.state.projectedVertices.length){this.warn("Too many verts");return}const z=this.state.modelview[this.state.modelview.length-1],j=this.state.projection[this.state.projection.length-1].multiply(z),G=this.state.texture.scaleS/32,P=this.state.texture.scaleT/32,L=new X0,U=new X0,O=new X0,E=this.renderer.nativeTransform.viTransform,w=this.state.viewport.transform,y=16;for(let S=0;S<q;++S){const g=S*y,x=this.state.projectedVertices[J+S];if(x.set=!0,L.x=W.getInt16(g+0),L.y=W.getInt16(g+2),L.z=W.getInt16(g+4),x.u=W.getInt16(g+8)*G,x.v=W.getInt16(g+10)*P,x.color=W.getUint32(g+12,!0),this.projectInPlace(x,L,j,w,E),Z){if(this.unpackNormal(U,x.color),z.transformNormal(U,O),O.normaliseInPlace(),x.color=this.calculateLighting(O,255),K)if(X)x.calculateLinearUV(O);else x.calculateSphericalUV(O)}}}projectInPlace(J,q,Q,Y,Z){const K=J.pos;Q.transformPoint(q,K),J.clipFlags=this.calculateClipFlags(K);const X=K.w;K.scaleInPlace(1/X),Y.transformInPlace(K),Z.invTransformInPlace(K),K.scaleInPlace(X)}calculateClipFlags(J){let q=0;if(J.x<-J.w)q|=z9;else if(J.x>J.w)q|=X9;if(J.y<-J.w)q|=H9;else if(J.y>J.w)q|=W9;if(J.z<-J.w)q|=F9;else if(J.z>J.w)q|=$9;return q}unpackNormal(J,q){J.x=q<<24>>24,J.y=q<<16>>24,J.z=q<<8>>24}calculateLighting(J,q){const Q=this.state.numLights;let Y=this.state.lights[Q].color.r,Z=this.state.lights[Q].color.g,K=this.state.lights[Q].color.b;for(let X=0;X<Q;++X){const W=this.state.lights[X],z=J.dot(W.dir);if(z>0)Y+=W.color.r*z,Z+=W.color.g*z,K+=W.color.b*z}return Y=Math.min(Y,1)*255,Z=Math.min(Z,1)*255,K=Math.min(K,1)*255,q<<24|K<<16|Z<<8|Y}previewVertex(J,q,Q,Y,Z){const K=["#","x","y","z","?","u","v",Z?"norm":"rgba"];let X="";X+='<table class="vertex-table">',X+=`<tr><th>${K.join("</th><th>")}</th></tr>\n`;for(let W=0;W<q;++W){const z=W*16,F=Z?`${Q.getInt8(z+12)},${Q.getInt8(z+13)},${Q.getInt8(z+14)}`:b6(Q.getUint32(z+12)),j=[J+W,Q.getInt16(z+0),Q.getInt16(z+2),Q.getInt16(z+4),Q.getInt16(z+6),Q.getInt16(z+8),Q.getInt16(z+10),F];X+=`<tr><td>${j.join("</td><td>")}</td></tr>\n`}X+="</table>",Y.tip(X)}executeNoop(J,q,Q){if(Q)Q.text("gsDPNoOp();")}executeSpNoop(J,q,Q){if(Q)Q.text("gsSPNoOp();")}executeLoadUcode(J,q,Q){const Y=q&268435455,K=this.state.rdpHalf1Cmd1,X=(J&65535)+1;let W="?";if(this.onLoadUcodeHandler){const z=this.onLoadUcodeHandler(Y,4096,K,X);z.onLoadUcode(this.onLoadUcodeHandler),W=z.version}else this.warn("No loadUcodeHandler set!");if(Q)Q.text(`gsSPLoadUCode(${N(Y)}, 4096, ${N(K)} ${X}); // ${W}`)}executeRDPHalf1(J,q,Q){if(Q)Q.text(`gsImmp1(G_RDPHALF_1, ${N(q)});`);this.state.rdpHalf1Cmd1=q}executeRDPHalf2(J,q,Q){if(Q)Q.text(`gsImmp1(G_RDPHALF_2, ${N(q)});`);this.state.rdpHalf2Cmd1=q}executeRDPLoadSync(J,q,Q){if(Q)Q.text("gsDPLoadSync();")}executeRDPPipeSync(J,q,Q){if(Q)Q.text("gsDPPipeSync();")}executeRDPTileSync(J,q,Q){if(Q)Q.text("gsDPTileSync();")}executeRDPFullSync(J,q,Q){if(Q)Q.text("gsDPFullSync();")}executeSetKeyGB(J,q,Q){if(Q)Q.text("gsDPSetKeyGB(???);")}executeSetKeyR(J,q,Q){if(Q)Q.text("gsDPSetKeyR(???);")}executeSetConvert(J,q,Q){if(Q)Q.text("gsDPSetConvert(???);")}executeSetScissor(J,q,Q){const Y=(J>>>12&4095)/4,Z=(J>>>0&4095)/4,K=(q>>>12&4095)/4,X=(q>>>0&4095)/4,W=q>>>24&2;if(Q)Q.text(`gsDPSetScissor(${VX.nameOf(W)}, ${Y}, ${Z}, ${K}, ${X});`);this.state.scissor.x0=Y,this.state.scissor.y0=Z,this.state.scissor.x1=K,this.state.scissor.y1=X,this.state.scissor.mode=W}executeSetRDPOtherMode(J,q,Q){if(Q)Q.text(`gsDPSetOtherMode(${N(J)}, ${N(q)}); // TODO: fix formatting`);this.state.rdpOtherModeH=J,this.state.rdpOtherModeL=q}executeSetTile(J,q,Q){const Y=J>>>21&7,Z=J>>>19&3,K=J>>>9&511,X=J>>>0&511,W=q>>>24&7,z=q>>>20&15,F=q>>>18&3,j=q>>>14&15,G=q>>>10&15,P=q>>>8&3,L=q>>>4&15,U=q>>>0&15;if(this.state.tiles[W].set(Y,Z,K,X,z,P,L,U,F,j,G),Q){const E=Z0.nameOf(Y),w=p.nameOf(Z),y=h0(W),S=A8(P),g=A8(F);Q.text(`gsDPSetTile(${E}, ${w}, ${K}, ${X}, ${y}, ${z}, ${g}, ${j}, ${G}, ${S}, ${L}, ${U});`)}}executeSetTileSize(J,q,Q){const Y=J>>>12&4095,Z=J>>>0&4095,K=q>>>24&7,X=q>>>12&4095,W=q>>>0&4095,z=this.state.tiles[K];if(z.setSize(Y,Z,X,W),Q){const F=h0(K);Q.text(`gsDPSetTileSize(${F}, ${z.left}, ${z.top}, ${z.right}, ${z.bottom});`),Q.tip(`size (${z.width} x ${z.height}), unmasked (${z.unmaskedWidth} x ${z.unmaskedHeight})`)}}executeSetFillColor(J,q,Q){if(Q)Q.text(`gsDPSetFillColor(${Q.rgba8888(q)}); // hi as 5551 = ${Q.rgba5551(q>>>16)}, lo as 5551 = ${Q.rgba5551(q&65535)} `);this.state.fillColor=q}executeSetFogColor(J,q,Q){if(Q)Q.text(`gsDPSetFogColor(${Q.rgba8888(q)});`);this.state.fogColor=q}executeSetBlendColor(J,q,Q){if(Q)Q.text(`gsDPSetBlendColor(${Q.rgba8888(q)});`);this.state.blendColor=q}executeSetPrimColor(J,q,Q){if(Q){const Y=J>>>8&255,Z=J>>>0&255;Q.text(`gsDPSetPrimColor(${Y}, ${Z}, ${Q.rgba8888(q)});`)}this.state.primColor=q}executeSetPrimDepth(J,q,Q){const Y=q>>>16&65535,Z=q&65535;if(Q)Q.text(`gsDPSetPrimDepth(${Y},${Z});`)}executeSetEnvColor(J,q,Q){if(Q)Q.text(`gsDPSetEnvColor(${Q.rgba8888(q)});`);this.state.envColor=q}executeSetCombine(J,q,Q){if(Q){const Y=J&16777215,Z=q,K=_9(Y,Z);Q.text(`gsDPSetCombine(${N(Y)}, ${N(Z)});\n${K}`)}this.state.combine.hi=J&16777215,this.state.combine.lo=q}executeSetTImg(J,q,Q){const Y=J>>>21&7,Z=J>>>19&3,K=(J>>>0&4095)+1,X=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gsDPSetTextureImage(${Z0.nameOf(Y)}, ${p.nameOf(Z)}, ${K}, ${N(X)});`);this.state.textureImage.set(Y,Z,K,X)}executeSetZImg(J,q,Q){const Y=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gsDPSetDepthImage(${N(Y)});`);this.state.depthImage.address=Y}executeSetCImg(J,q,Q){const Y=J>>>21&7,Z=J>>>19&3,K=(J>>>0&4095)+1,X=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gsDPSetColorImage(${Z0.nameOf(Y)}, ${p.nameOf(Z)}, ${K}, ${N(X)});`);if(this.state.colorImage={format:Y,size:Z,width:K,address:X},n64js.hardware().timeline.addEvent(`SetColorImage ${N(X)}`),TH&&!vX.get(X))M(`Setting colorImage to ${N(X)}, ${K}, size ${p.nameOf(Z)}, format ${Z0.nameOf(Y)}`),vX.set(X,!0)}executeLoadBlock(J,q,Q){const Y=q>>>24&7,Z=J>>>12&4095,K=J>>>0&4095,X=q>>>12&4095,W=q>>>0&4095;if(Z!==0)this.warn("Unexpected non-zero uls in load block");if(K!==0)this.warn("Unexpected non-zero ult in load block");if(Q){const j=h0(Y);Q.text(`gsDPLoadBlock(${j}, ${Z}, ${K}, ${X}, ${W});`)}const z=this.state.textureImage,F=this.state.tiles[Y];this.state.tmem.loadBlock(z,F,Z,K,X,W,Q),this.state.invalidateTileHashes()}executeLoadTile(J,q,Q){const Y=q>>>24&7,Z=J>>>12&4095,K=J>>>0&4095,X=q>>>12&4095,W=q>>>0&4095;if(Q){const j=h0(Y);Q.text(`gsDPLoadTile(${j}, ${Z/4}, ${K/4}, ${X/4}, ${W/4});`)}const z=this.state.textureImage,F=this.state.tiles[Y];this.state.tmem.loadTile(z,F,Z,K,X,W,Q),this.state.invalidateTileHashes()}executeLoadTLut(J,q,Q){const Y=q>>>24&7,Z=J>>>12&4095,K=J>>>0&4095,X=q>>>12&4095,W=q>>>0&4095;if(Q){const j=h0(Y);Q.text(`gsDPLoadTLUTCmd(${j}, ${y8(X,Z)}); //${Z}, ${K}, ${X}, ${W}`)}const z=this.state.textureImage,F=this.state.tiles[Y];this.state.tmem.loadTLUT(z,F,Z,K,X,W,Q),this.state.invalidateTileHashes()}executeFillRect(J,q,Q){const Y=(q>>>12&4095)>>>2,Z=(q>>>0&4095)>>>2;let K=(J>>>12&4095)>>>2,X=(J>>>0&4095)>>>2;const W=this.gl;if(Q)Q.text(`gsDPFillRectangle(${Y}, ${Z}, ${K}, ${X});`);if(this.state.depthImage.address==this.state.colorImage.address){W.clearDepth(1),W.depthMask(!0),W.clear(W.DEPTH_BUFFER_BIT);return}const z=this.state.getCycleType();let F={r:0,g:0,b:0,a:0};if(z===K0.G_CYC_FILL){if(K+=1,X+=1,this.state.colorImage.size===p.G_IM_SIZ_16b)F=_H(this.state.fillColor&65535);else F=uX(this.state.fillColor);const j=K-Y,G=X-Z;if(j===this.renderer.nativeTransform.viWidth&&G===this.renderer.nativeTransform.viHeight){W.clearColor(F.r,F.g,F.b,F.a),W.clear(W.COLOR_BUFFER_BIT);return}}else if(z===K0.G_CYC_COPY)K+=1,X+=1;this.renderer.fillRect(Y,Z,K,X,F)}executeTexRect(J,q,Q){this.state.nextCommand();const Y=this.state.cmd1;this.state.nextCommand();const Z=this.state.cmd1;this.rdpTexRect(J,q,Y,Z,Q)}rdpTexRect(J,q,Q,Y,Z){let K=(J>>>12&4095)/4,X=(J>>>0&4095)/4;const W=q>>>24&7,z=(q>>>12&4095)/4,F=(q>>>0&4095)/4;let j=(Q>>>16&65535)/32,G=(Q>>>0&65535)/32,P=((Y|0)>>16)/1024;const L=(Y<<16>>16)/1024,U=this.state.getCycleType();if(U===K0.G_CYC_COPY)P*=0.25;if(U===K0.G_CYC_COPY||U===K0.G_CYC_FILL)K+=1,X+=1;if(P<0)j++;if(L<0)G++;const O=j+P*(K-z),E=G+L*(X-F);if(Z){const w=h0(W);Z.text(`gsSPTextureRectangle(${z},${F},${K},${X},${w},${j},${G},${P},${L});`),Z.tip(`cmd2 = ${N(Q)}, cmd3 = ${N(Y)}`),Z.tip(`st0 = (${j}, ${G}) st1 = (${O}, ${E})`)}this.renderer.texRect(W,z,F,K,X,j,G,O,E,!1)}executeTexRectFlip(J,q,Q){this.state.nextCommand();const Y=this.state.cmd1;this.state.nextCommand();const Z=this.state.cmd1;this.rdpTexRectFlip(J,q,Y,Z,Q)}rdpTexRectFlip(J,q,Q,Y,Z){let K=(J>>>12&4095)/4,X=(J>>>0&4095)/4;const W=q>>>24&7,z=(q>>>12&4095)/4,F=(q>>>0&4095)/4;let j=(Q>>>16&65535)/32,G=(Q>>>0&65535)/32,P=((Y|0)>>16)/1024;const L=(Y<<16>>16)/1024,U=this.state.getCycleType();if(U===K0.G_CYC_COPY)P*=0.25;if(U===K0.G_CYC_COPY||U===K0.G_CYC_FILL)K+=1,X+=1;if(P<0)j++;if(L<0)G++;const O=j+P*(X-F),E=G+L*(K-z);if(Z){const w=h0(W);Z.text(`gsSPTextureRectangleFlip(${z},${F},${K},${X},${w},${j},${G},${P},${L});`),Z.tip(`cmd2 = ${N(Q)}, cmd3 = ${N(Y)}`),Z.tip(`st0 = (${j}, ${G}) st1 = (${O}, ${E})`)}this.renderer.texRect(W,z,F,K,X,j,G,O,E,!0)}executeCullDL(J,q,Q){const Y=(J&65535)>>>1,Z=(q&65535)>>>1,K=this.testClipFlags(Y,Z);if(Q)Q.text(`gSPCullDisplayList(${Y}, ${Z}); // ${K?"continue":"end"}`);if(!K)this.state.endDisplayList()}testClipFlags(J,q){if(q<=J)return this.warn("begin and end vertices for testClipFlags are inverted or empty"),!0;if(q>=this.state.projectedVertices.length)return this.warn("end vertex for testClipFlags is out of bounds"),!0;let Q=~0;for(let Y=J;Y<=q;Y++)Q&=this.state.projectedVertices[Y].clipFlags;return Q==0}calcTextureScale(J){if(J===0||J===65535)return 1;return J/65536}}var v9=!1;class v6 extends NJ{constructor(J,q){super(J,q);this.vertexStride=2,this.gbi1Commands=new Map([[0,this.executeSpNoop.bind(this)],[1,this.executeMatrix.bind(this)],[3,this.executeMoveMem.bind(this)],[4,this.executeVertex.bind(this)],[6,this.executeDL.bind(this)],[9,this.executeSprite2DBase.bind(this)],[175,this.executeLoadUcode.bind(this)],[176,this.executeBranchZ.bind(this)],[177,this.executeTri2.bind(this)],[178,this.executeModifyVertex.bind(this)],[179,this.executeRDPHalf2.bind(this)],[180,this.executeRDPHalf1.bind(this)],[181,this.executeLine3D.bind(this)],[182,this.executeClearGeometryMode.bind(this)],[183,this.executeSetGeometryMode.bind(this)],[184,this.executeEndDL.bind(this)],[185,this.executeSetOtherModeL.bind(this)],[186,this.executeSetOtherModeH.bind(this)],[187,this.executeTexture.bind(this)],[188,this.executeMoveWord.bind(this)],[189,this.executePopMatrix.bind(this)],[190,this.executeCullDL.bind(this)],[191,this.executeTri1.bind(this)],[192,this.executeNoop.bind(this)]])}getHandler(J){const q=this.gbi1Commands.get(J);if(q)return q;return super.getHandler(J)}executeDL(J,q,Q){const Y=J>>>16&255,Z=this.state.rdpSegmentAddress(q);if(Q){const K=Y===M8?"gsSPDisplayList":"gsSPBranchList";Q.text(`${K}(<span class="dl-branch">${N(Z)}</span>);`)}if(Y===M8)this.state.pushDisplayList(Z);else this.state.branchDisplayList(Z)}executeEndDL(J,q,Q){if(Q)Q.text("gsSPEndDisplayList();");this.state.endDisplayList()}executeBranchZ(J,q,Q){const Y=this.state.rdpSegmentAddress(this.state.rdpHalf1Cmd1);if(this.warnUnimplemented("BranchLessZ"),Q)Q.text("gsSPBranchLessZ(/* TODO */);");this.state.branchDisplayList(Y)}executeClearGeometryMode(J,q,Q){if(Q)Q.text(`gsSPClearGeometryMode(${h8(a0,q)});`);this.state.geometryModeBits&=~q,this.state.updateGeometryModeFromBits(a0)}executeSetGeometryMode(J,q,Q){if(Q)Q.text(`gsSPSetGeometryMode(${h8(a0,q)});`);this.state.geometryModeBits|=q,this.state.updateGeometryModeFromBits(a0)}executeSetOtherModeL(J,q,Q){const Y=J>>>8&255,Z=J>>>0&255,K=q,X=(1<<Z)-1<<Y>>>0;if(Q)E9(Q,X,K);this.state.rdpOtherModeL=this.state.rdpOtherModeL&~X|K}executeSetOtherModeH(J,q,Q){const Y=J>>>8&255,Z=J>>>0&255,K=q,X=(1<<Z)-1<<Y>>>0;if(Q)w9(Q,X,Z,Y,K);this.state.rdpOtherModeH=this.state.rdpOtherModeH&~X|K}executeTexture(J,q,Q){const Y=J>>>16&255,Z=J>>>11&3,K=J>>>8&7,X=J>>>0&255,W=this.calcTextureScale(q>>>16&65535),z=this.calcTextureScale(q>>>0&65535);if(Q){const F=W.toString(),j=z.toString(),G=h0(K),P=X?"G_ON":"G_OFF";if(Y!==0)Q.text(`gsSPTextureL(${F}, ${j}, ${Z}, ${Y}, ${G}, ${P});`);else Q.text(`gsSPTexture(${F}, ${j}, ${Z}, ${G}, ${P});`)}if(this.state.setTexture(W,z,Z,K),X)this.state.geometryModeBits|=a0.G_TEXTURE_ENABLE;else this.state.geometryModeBits&=~a0.G_TEXTURE_ENABLE;this.state.updateGeometryModeFromBits(a0)}executeMatrix(J,q,Q){const Y=J>>>16&255,Z=J>>>0&65535,K=this.state.rdpSegmentAddress(q);let X=this.loadMatrix(K,Z);if(Q){let z="";z+=Y&Z9?"G_MTX_PROJECTION":"G_MTX_MODELVIEW",z+=Y&LQ?"|G_MTX_LOAD":"|G_MTX_MUL",z+=Y&VQ?"|G_MTX_PUSH":"",Q.text(`gsSPMatrix(${N(K)}, ${z});`),Q.tip(this.previewMatrix(X))}const W=Y&Z9?this.state.projection:this.state.modelview;if((Y&LQ)==0)X=W[W.length-1].multiply(X);if(Y&VQ)W.push(X);else W[W.length-1]=X}executePopMatrix(J,q,Q){const Y=q>>>0&255;if(Q){let Z="";Z+=Y&Z9?"G_MTX_PROJECTION":"G_MTX_MODELVIEW",Q.text(`gsSPPopMatrix(${Z});`)}if(this.state.modelview.length>0)this.state.modelview.pop()}executeVertex(J,q,Q){const Y=(J>>>16&255)/this.vertexStride,Z=J>>>10&63,K=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gsSPVertex(${N(K)}, ${Y}, ${Z});`);this.loadVertices(Y,Z,K,Q)}executeModifyVertex(J,q,Q){if(this.warnUnimplemented("ModifyVertex"),Q)Q.text("gsSPModifyVertex(???);")}executeSprite2DBase(J,q,Q){if(this.warnUnimplemented("Sprite2DBase"),Q)Q.text("gsSPSprite2DBase(/* TODO */);")}executeMoveMem(J,q,Q){const Y=J>>>16&255,Z=J>>>0&65535,K=this.state.rdpSegmentAddress(q);if(Q){const X=N(K),W=z0.nameOf(Y);let z=`gsDma1p(G_MOVEMEM, ${X}, ${Z}, ${W});`;switch(Y){case z0.G_MV_VIEWPORT:if(Z===16)z=`gsSPViewport(${X});`;break}Q.text(z),this.previewMoveMem(Y,Z,K,Q)}switch(Y){case z0.G_MV_VIEWPORT:this.loadViewport(K);break;case z0.G_MV_L0:case z0.G_MV_L1:case z0.G_MV_L2:case z0.G_MV_L3:case z0.G_MV_L4:case z0.G_MV_L5:case z0.G_MV_L6:case z0.G_MV_L7:{const X=(Y-z0.G_MV_L0)/2;this.loadLight(X,K)}break}}previewMoveMem(J,q,Q,Y){let Z="";for(let K=0;K<q;++K)Z+=B(this.ramDV.getUint8(Q+K),8)+" ";switch(Z+="<br>",J){case z0.G_MV_VIEWPORT:Z+=this.previewViewport(Q);break;case z0.G_MV_L0:case z0.G_MV_L1:case z0.G_MV_L2:case z0.G_MV_L3:case z0.G_MV_L4:case z0.G_MV_L5:case z0.G_MV_L6:case z0.G_MV_L7:Z+=this.previewLight(Q);break}Y.tip(Z)}executeMoveWord(J,q,Q){const Y=J&255,Z=J>>>8&65535,K=q;let X="";switch(Y){case j0.G_MW_MATRIX:this.warnUnimplemented("MoveWord Matrix");break;case j0.G_MW_NUMLIGHT:{let W=(K-2147483648>>>5)-1;if(Q){if(Z===LX)X=`gsSPNumLights(${G9.nameOf(W)});`}this.state.numLights=W}break;case j0.G_MW_CLIP:if(Q)X=`gSPClipRatio(${K9.nameOf(Z)}, ${j9.nameOf(K)});`;break;case j0.G_MW_SEGMENT:{const W=Z>>>2&15;if(Q)X=`gsSPSegment(${N9.nameOf(W)}, ${N(K)});`;this.state.segments[W]=K}break;case j0.G_MW_FOG:{const W=q>>16,z=q&65535;if(Q)X=`gSPFogPosition(${W}, ${z});`;this.state.fogParameters.set(W,z)}break;case j0.G_MW_LIGHTCOL:this.warnUnimplemented("MoveWord LightCol");break;case j0.G_MW_POINTS:this.warnUnimplemented("MoveWord Points");break;case j0.G_MW_PERSPNORM:if(Q)X=`gSPPerspNormalize(${K});`;break;default:this.warnUnimplemented("MoveWord Unknown");break}if(Q){if(!X)X=`gMoveWd(${j0.nameOf(Y)}, ${r(Z)}, ${N(K)});`;Q.text(X)}}executeTri1(J,q,Q){const Y=this.vertexStride,Z=this.state.projectedVertices,K=this.triangleBuffer;K.reset();let X=Q?1:0,W=this.state.executeBatch(X,(z,F)=>{const j=F>>>24&255,G=(F>>>16&255)/Y,P=(F>>>8&255)/Y,L=(F>>>0&255)/Y;if(Q)Q.text(`gsSP1Triangle(${G}, ${P}, ${L}, ${j});`);return K.pushTri(Z[G],Z[P],Z[L]),K.hasCapacity(1)});this.debugController.currentOp+=W-1,this.renderer.flushTris(K)}executeTri2(J,q,Q){const Y=this.vertexStride,Z=this.state.projectedVertices,K=this.triangleBuffer;K.reset();let X=Q?1:0,W=this.state.executeBatch(X,(z,F)=>{const j=(z>>>16&255)/Y,G=(z>>>8&255)/Y,P=(z>>>0&255)/Y,L=(F>>>16&255)/Y,U=(F>>>8&255)/Y,O=(F>>>0&255)/Y;if(Q)Q.text(`gsSP1Triangle2(${j},${G},${P}, ${L},${U},${O});`);return K.pushTri(Z[j],Z[G],Z[P]),K.pushTri(Z[L],Z[U],Z[O]),K.hasCapacity(2)});this.debugController.currentOp+=W-1,this.renderer.flushTris(K)}executeLine3D(J,q,Q){const Y=this.vertexStride,Z=this.state.projectedVertices,K=this.triangleBuffer;K.reset();let X=Q?1:0,W=this.state.executeBatch(X,(z,F)=>{const j=(F>>>24&255)/Y,G=(F>>>16&255)/Y,P=(F>>>8&255)/Y,L=(F>>>0&255)/Y;if(Q)Q.text(`gsSPLine3D(${G}, ${P}, ${L}, ${j});`);if(G<Z.length&&P<Z.length&&L<Z.length)K.pushTri(Z[G],Z[P],Z[L]);else if(!v9)console.log(`verts out of bounds, ignoring: ${G}, ${P}, ${L} vs ${Z.length}, stride ${Y}`),v9=!0;if(L<Z.length&&j<Z.length&&G<Z.length)K.pushTri(Z[L],Z[j],Z[G]);else if(!v9)console.log(`verts out of bounds, ignoring: ${L}, ${j}, ${G} vs ${Z.length}, stride ${Y}`),v9=!0;return K.hasCapacity(2)});this.debugController.currentOp+=W-1,this.renderer.flushTris(K)}}class bQ extends v6{constructor(J,q){super(J,q);this.vertexStride=2}}class $6 extends v6{constructor(J,q){super(J,q);this.vertexStride=10,this.gbi0Commands=new Map([[176,this.executeUnknown.bind(this)],[177,this.executeTri4.bind(this)],[178,this.executeRDPHalf_Cont.bind(this)]])}getHandler(J){const q=this.gbi0Commands.get(J);if(q)return q;return super.getHandler(J)}executeCullDL(J,q,Q){const Y=(J&16777215)/40&15,Z=q/40&15,K=this.testClipFlags(Y,Z);if(Q)Q.text(`gSPCullDisplayList(${Y}, ${Z}); // ${K?"continue":"end"}`);if(!K)this.state.endDisplayList()}executeVertex(J,q,Q){const Y=(J>>>20&15)+1,Z=J>>>16&15,K=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gsSPVertex(${N(K)}, ${Z}, ${Y});`);this.loadVertices(Z,Y,K,Q)}executeRDPHalf_Cont(J,q,Q){if(this.warnUnimplemented("RDPHalf_Cont"),Q)Q.text("gsDPHalf_Cont(/* TODO */);")}executeRDPHalf1Goldeneye(J,q,Q){if(this.warnUnimplemented("executeRDPHalf1"),Q)Q.text("gsSPRDPHalf();")}executeTri4(J,q,Q){const Y=this.state.projectedVertices,Z=this.triangleBuffer;Z.reset();let K=Q?1:0,X=this.state.executeBatch(K,(W,z)=>{const F=W>>>12&15,j=W>>>8&15,G=W>>>4&15,P=W>>>0&15,L=z>>>28&15,U=z>>>24&15,O=z>>>20&15,E=z>>>16&15,w=z>>>12&15,y=z>>>8&15,S=z>>>4&15,g=z>>>0&15;if(Q)Q.text(`gsSP1Triangle4(${P},${g},${S}, ${G},${y},${w}, ${j},${E},${O}, ${F},${U},${L});`);if(P!==g)Z.pushTri(Y[P],Y[g],Y[S]);if(G!==y)Z.pushTri(Y[G],Y[y],Y[w]);if(j!==E)Z.pushTri(Y[j],Y[E],Y[O]);if(F!==U)Z.pushTri(Y[F],Y[U],Y[L]);return Z.hasCapacity(4)});this.debugController.currentOp+=X-1,this.renderer.flushTris(Z)}}class TQ extends $6{constructor(J,q){super(J,q);this.vertexStride=10,this.geCommands=new Map([[180,this.executeRDPHalf1Goldeneye.bind(this)]])}getHandler(J){const q=this.geCommands.get(J);if(q)return q;return super.getHandler(J)}}class _Q extends $6{constructor(J,q){super(J,q);this.vertexStride=10,this.auxAddress=0,this.pdCommands=new Map([[7,this.executeSetVertexColorIndex.bind(this)],[180,this.executeRDPHalf1Goldeneye.bind(this)]])}getHandler(J){const q=this.pdCommands.get(J);if(q)return q;return super.getHandler(J)}executeSetVertexColorIndex(J,q,Q){const Y=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gsSPSetVertexColorIndex(${N(Y)});`);this.auxAddress=Y}loadVertices(J,q,Q,Y){const Z=this.state.geometryMode.lighting,K=this.state.geometryMode.textureGen,X=this.state.geometryMode.textureGenLinear,W=new DataView(this.ramDV.buffer,Q),z=new DataView(this.ramDV.buffer,this.auxAddress);if(Y)this.previewVertex(J,q,W,Y,Z);if(J+q>=this.state.projectedVertices.length){this.warn("Too many verts");return}const F=12,j=this.state.modelview[this.state.modelview.length-1],P=this.state.projection[this.state.projection.length-1].multiply(j),L=this.state.texture.scaleS/32,U=this.state.texture.scaleT/32,O=new X0,E=new X0,w=new X0,y=this.renderer.nativeTransform.viTransform,S=this.state.viewport.transform;for(let g=0;g<q;++g){const x=g*F,H0=this.state.projectedVertices[J+g];H0.set=!0,O.x=W.getInt16(x+0),O.y=W.getInt16(x+2),O.z=W.getInt16(x+4);const w0=W.getUint8(x+7);if(H0.u=W.getInt16(x+8)*L,H0.v=W.getInt16(x+10)*U,H0.color=z.getUint32(w0+0,!0),this.projectInPlace(H0,O,P,S,y),Z){const o8=H0.color&255;if(this.unpackNormal(E,H0.color),j.transformNormal(E,w),w.normaliseInPlace(),H0.color=this.calculateLighting(w,o8),X)H0.calculateLinearUV(w);else if(K)H0.calculateSphericalUV(w)}}}}class SQ extends $6{constructor(J,q){super(J,q);this.vertexStride=5}executeVertex(J,q,Q){const Y=J>>>9&127,Z=(J>>>16&255)/5,K=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gsSPVertex(${N(K)}, ${Z}, ${Y});`);this.loadVertices(Z,Y,K,Q)}}class vQ extends $6{constructor(J,q){super(J,q);this.vertexStride=5}executeVertex(J,q,Q){const Y=(J>>>4&4095)/33+1,K=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gsSPVertex(${N(K)}, 0, ${Y});`);this.loadVertices(0,Y,K,Q)}}class fQ extends $6{constructor(J,q){super(J,q);this.vertexStride=10,this.matrixAddress=0,this.matrixIndex=0,this.matrixArray=[y0.identity(),y0.identity(),y0.identity(),y0.identity()],this.vertexAddress=0,this.vertexOffset=0,this.billboardMode=!1,this.dkrCommands=new Map([[5,this.executeTriDMA.bind(this)],[7,this.executeDisplayListLen.bind(this)],[191,this.executeSetAddresses.bind(this)]])}getHandler(J){const q=this.dkrCommands.get(J);if(q)return q;return super.getHandler(J)}executeDisplayListLen(J,q,Q){const Y=J>>>16&255,Z=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gsSPDisplayListLen(<span class="dl-branch">${N(Z)}</span>, ${Y});`);this.state.pushDisplayList(Z,Y)}executeSetAddresses(J,q,Q){if(this.matrixAddress=this.state.rdpSegmentAddress(J),this.vertexAddress=this.state.rdpSegmentAddress(q),this.vertexOffset=0,Q)Q.text(`gsSPSetAddress(${N(this.matrixAddress)}, ${N(this.vertexAddress)};`)}executeMoveWord(J,q,Q){const Y=J&255;if(Y==2){if(this.billboardMode=(q&1)!=0,Q)Q.text(`gSetBillboardMode(${this.billboardMode});`)}else if(Y==10){if(this.matrixIndex=q>>6&3,Q)Q.text(`gSetMatrixIndex(${this.matrixIndex});`)}else super.executeMoveWord(J,q,Q)}executeTexture(J,q,Q){const Y=J>>>16&255,Z=J>>>11&3,K=J>>>8&7,W=this.calcTextureScale(q>>>16&65535),z=this.calcTextureScale(q>>>0&65535);if(Q){const F=W.toString(),j=z.toString(),G=h0(K);if(Y!==0)Q.text(`gsSPTextureL(${F}, ${j}, ${Z}, ${Y}, ${G}, G_ON);`);else Q.text(`gsSPTexture(${F}, ${j}, ${Z}, ${G}, G_ON);`)}this.state.setTexture(W,z,Z,K),this.state.geometryModeBits|=a0.G_TEXTURE_ENABLE,this.state.updateGeometryModeFromBits(a0)}executeMatrix(J,q,Q){const Y=this.matrixAddress+q,Z=J>>22&3,K=J&65535,X=this.loadMatrix(Y,K);if(Q)Q.text(`gsSPMatrix(${N(Y)}, ${Z});`),Q.tip(this.previewMatrix(X));this.matrixArray[Z]=X,this.matrixIndex=Z}executeVertex(J,q,Q){const Y=this.vertexAddress+q,Z=(J>>>19&31)+1,K=J&65536,X=J>>>9&31;if(this.billboardMode)this.vertexOffset=K?1:0;else if(!K)this.vertexOffset=0;const W=this.vertexOffset+X;if(Q)Q.text(`gsSPVertex(${N(Y)}, ${W}, ${Z});`);this.loadVertices(W,Z,Y,Q),this.vertexOffset+=Z}loadVertices(J,q,Q,Y){if(J+q>=this.state.projectedVertices.length){this.warn("Too many verts");return}const Z=10,K=new DataView(this.ramDV.buffer,Q);let X=this.matrixArray[this.matrixIndex];const W=this.renderer.nativeTransform.viTransform,z=this.state.viewport.transform,F=new X0;if(this.billboardMode){X=X.copy();const G=this.state.projectedVertices[0].pos;X.elems[3]+=G.x,X.elems[7]+=G.y,X.elems[11]+=G.z,X.elems[15]+=G.w}let j="";if(Y){const G=["#","x","y","z","rgba"];j+='<table class="vertex-table">',j+=`<tr><th>${G.join("</th><th>")}</th></tr>\n`}for(let G=0,P=0;G<q;G++,P+=Z){const L=this.state.projectedVertices[J+G];if(L.set=!0,F.x=K.getInt16(P+0),F.y=K.getInt16(P+2),F.z=K.getInt16(P+4),L.color=K.getUint32(P+6,!0),this.projectInPlace(L,F,X,z,W),Y){const U=[J+G,F.x,F.y,F.z,k9(K.getUint32(P+6,!0))];j+=`<tr><td>${U.join("</td><td>")}</td></tr>\n`}}if(Y)j+="</table>",Y.tip(j)}executeTriDMA(J,q,Q){const Y=J>>>4&31,Z=this.state.rdpSegmentAddress(q),K=new DataView(this.ramDV.buffer,Z),X=this.state.projectedVertices,W=this.triangleBuffer;if(W.reset(),Q)Q.text(`gsSPTriDMA(${N(Z)}, ${Y});`);let z="";if(Y>W.maxTris)this.warn(`Too many triangles for buffer: ${Y} > ${W.maxTris}`);const F=16;for(let j=0;j<Y&&W.hasCapacity(1);++j){const G=j*F,P=K.getUint8(G+0),L=K.getUint8(G+1),U=K.getUint8(G+2),O=K.getUint8(G+3),E=K.getInt16(G+4)/32,w=K.getInt16(G+6)/32,y=K.getInt16(G+8)/32,S=K.getInt16(G+10)/32,g=K.getInt16(G+12)/32,x=K.getInt16(G+14)/32;if(W.pushTriWithUV(X[L],X[U],X[O],E,w,y,S,g,x),Q)z+=`${j}: ${P}, v${L} (${E}, ${w}), v${U} (${y}, ${S}), v${O} (${g}, ${x})\n`}if(this.renderer.flushTris(W),this.vertexOffset=0,Q)Q.tip(z)}}class I8 extends NJ{constructor(J,q){super(J,q);this.vertexStride=2,this.gbi2Commands=new Map([[0,this.executeNoop.bind(this)],[1,this.executeVertex.bind(this)],[2,this.executeModifyVtx.bind(this)],[3,this.executeCullDL.bind(this)],[4,this.executeBranchZ.bind(this)],[5,this.executeTri1.bind(this)],[6,this.executeTri2.bind(this)],[7,this.executeQuad.bind(this)],[8,this.executeLine3D.bind(this)],[9,this.executeBgRect1Cyc.bind(this)],[10,this.executeBgRectCopy.bind(this)],[11,this.executeObjRenderMode.bind(this)],[214,this.executeDmaIo.bind(this)],[215,this.executeTexture.bind(this)],[216,this.executePopMatrix.bind(this)],[217,this.executeGeometryMode.bind(this)],[218,this.executeMatrix.bind(this)],[219,this.executeMoveWord.bind(this)],[220,this.executeMoveMem.bind(this)],[221,this.executeLoadUcode.bind(this)],[222,this.executeDL.bind(this)],[223,this.executeEndDL.bind(this)],[224,this.executeSpNoop.bind(this)],[225,this.executeRDPHalf1.bind(this)],[226,this.executeSetOtherModeL.bind(this)],[227,this.executeSetOtherModeH.bind(this)],[241,this.executeRDPHalf2.bind(this)]])}getHandler(J){const q=this.gbi2Commands.get(J);if(q)return q;return super.getHandler(J)}executeDL(J,q,Q){const Y=J>>>16&255,Z=this.state.rdpSegmentAddress(q);if(Q){const K=Y===M8?"gsSPDisplayList":"gsSPBranchList";Q.text(`${K}(<span class="dl-branch">${N(Z)}</span>);`)}if(Y===M8)this.state.pushDisplayList(Z);else this.state.branchDisplayList(Z)}executeEndDL(J,q,Q){if(Q)Q.text("gsSPEndDisplayList();");this.state.endDisplayList()}executeSetOtherModeL(J,q,Q){const Y=J>>>8&255,Z=J>>>0&255,K=q,X=2147483648>>Z>>>Y;if(Q)E9(Q,X,K);this.state.rdpOtherModeL=this.state.rdpOtherModeL&~X|K}executeSetOtherModeH(J,q,Q){const Y=J>>>8&255,Z=J>>>0&255,K=q,X=2147483648>>Z>>>Y;if(Q)w9(Q,X,Z,Y,K);this.state.rdpOtherModeH=this.state.rdpOtherModeH&~X|K}executeMatrix(J,q,Q){const Y=this.state.rdpSegmentAddress(q),Z=(J&1)===0,K=J>>>1&1,X=J>>>2&1;let W=this.loadMatrix(Y,64);if(Q){let F="";F+=X?"G_MTX_PROJECTION":"G_MTX_MODELVIEW",F+=K?"|G_MTX_LOAD":"|G_MTX_MUL",F+=Z?"|G_MTX_PUSH":"",Q.text(`gsSPMatrix(${N(Y)}, ${F});`),Q.tip(this.previewMatrix(W))}const z=X?this.state.projection:this.state.modelview;if(!K)W=z[z.length-1].multiply(W);if(Z)z.push(W);else z[z.length-1]=W}executeVertex(J,q,Q){const Y=(J&255)>>1,Z=J>>>12&255,K=Y-Z,X=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gsSPVertex(${N(X)}, ${K}, ${Z});`);this.loadVertices(K,Z,X,Q)}executeBranchZ(J,q,Q){if(this.warnUnimplemented("BranchZ"),Q)Q.text("gsSPBranchZ(/* TODO */);")}executeLine3D(J,q,Q){if(this.warnUnimplemented("Line3D"),Q)Q.text("gsSPLine3D(/* TODO */);")}executeBgRect1Cyc(J,q,Q){if(this.warnUnimplemented("BgRect1Cyc"),Q)Q.text("gsSPBgRect1Cyc(/* TODO */);")}executeBgRectCopy(J,q,Q){if(this.warnUnimplemented("BgRectCopy"),Q)Q.text("gsSPBgRectCopy(/* TODO */);")}executeObjRenderMode(J,q,Q){if(this.warnUnimplemented("ObjRenderMode"),Q)Q.text("gsSPObjRenderMode(/* TODO */);")}executeDmaIo(J,q,Q){if(Q)Q.text("DmaIo(/* TODO */);")}executeTri1(J,q,Q){const Y=this.state.projectedVertices,Z=this.triangleBuffer;Z.reset();let K=Q?1:0,X=this.state.executeBatch(K,(W,z)=>{const F=W>>>1&127,j=W>>>9&127,G=W>>>17&127,P=z>>>24&255;if(Q)Q.text(`gsSP1Triangle(${F},${j},${G}, ${P});`);return Z.pushTri(Y[F],Y[j],Y[G]),Z.hasCapacity(1)});this.debugController.currentOp+=X-1,this.renderer.flushTris(Z)}executeTri2(J,q,Q){const Y=this.state.projectedVertices,Z=this.triangleBuffer;Z.reset();let K=Q?1:0,X=this.state.executeBatch(K,(W,z)=>{const F=z>>>1&127,j=z>>>9&127,G=z>>>17&127,P=W>>>1&127,L=W>>>9&127,U=W>>>17&127;if(Q)Q.text(`gsSP2Triangles(${F},${j},${G}, ${P},${L},${U});`);return Z.pushTri(Y[F],Y[j],Y[G]),Z.pushTri(Y[P],Y[L],Y[U]),Z.hasCapacity(2)});this.debugController.currentOp+=X-1,this.renderer.flushTris(Z)}executeQuad(J,q,Q){const Y=this.state.projectedVertices,Z=this.triangleBuffer;Z.reset();let K=Q?1:0,X=this.state.executeBatch(K,(W,z)=>{const F=z>>>1&127,j=z>>>9&127,G=z>>>17&127,P=W>>>1&127,L=W>>>9&127,U=W>>>17&127;if(Q)Q.text(`gSP1Quadrangle(${F},${j},${G}, ${P},${L},${U});`);return Z.pushTri(Y[F],Y[j],Y[G]),Z.pushTri(Y[P],Y[L],Y[U]),Z.hasCapacity(2)});this.debugController.currentOp+=X-1,this.renderer.flushTris(Z)}executeModifyVtx(J,q,Q){const Y=J>>>1&32767,Z=J>>>16&255,K=q;if(Q)Q.text(`gsSPModifyVertex(${Y},${O8.nameOf(Z)},${N(K)});`);if(Y>=this.state.projectedVertices.length){this.warn("crazy vertex index",Y);return}const X=this.state.projectedVertices[Y];switch(Z){case O8.G_MWO_POINT_RGBA:this.warnUnimplemented("modifyVtx RGBA");break;case O8.G_MWO_POINT_ST:{const W=K>>16,z=(K&65535)<<16>>16;X.set=!0,X.u=W*this.state.texture.scaleS/32,X.v=z*this.state.texture.scaleT/32}break;case O8.G_MWO_POINT_XYSCREEN:this.warnUnimplemented("modifyVtx XYSCREEN");break;case O8.G_MWO_POINT_ZSCREEN:this.warnUnimplemented("modifyVtx ZSCREEN");break;default:this.warnUnimplemented("modifyVtx");break}}executeTexture(J,q,Q){const Y=J>>>16&255,Z=J>>>11&3,K=J>>>8&7,X=J>>>1&1,W=this.calcTextureScale(q>>>16&65535),z=this.calcTextureScale(q>>>0&65535);if(Q){const F=W.toString(),j=z.toString(),G=h0(K);if(Y!==0)Q.text(`gsSPTextureL(${F}, ${j}, ${Z}, ${Y}, ${G}, ${X});`);else Q.text(`gsSPTexture(${F}, ${j}, ${Z}, ${G}, ${X});`)}if(this.state.setTexture(W,z,Z,K),X)this.state.geometryModeBits|=V6.G_TEXTURE_ENABLE;else this.state.geometryModeBits&=~V6.G_TEXTURE_ENABLE;this.state.updateGeometryModeFromBits(V6)}executeGeometryMode(J,q,Q){const Y=J&16777215,Z=q;if(Q){const K=h8(V6,~Y),X=h8(V6,Z);Q.text(`gsSPGeometryMode(~(${K}),${X});`)}this.state.geometryModeBits&=Y|V6.G_TEXTURE_ENABLE,this.state.geometryModeBits|=Z&~V6.G_TEXTURE_ENABLE,this.state.updateGeometryModeFromBits(V6)}executePopMatrix(J,q,Q){if(Q)Q.text("gsSPPopMatrix(G_MTX_MODELVIEW);");const Z=this.state.modelview;if(Z.length>0)Z.pop()}executeMoveWord(J,q,Q){const Y=J>>>16&255,Z=J&65535,K=q;let X="";switch(Y){case j0.G_MW_MATRIX:this.warnUnimplemented("MoveWord Matrix");break;case j0.G_MW_NUMLIGHT:{let W=Math.floor(K/24);if(Q)X=`gsSPNumLights(${G9.nameOf(W)});`;this.state.numLights=W}break;case j0.G_MW_CLIP:if(Q)X=`gSPClipRatio(${K9.nameOf(Z)}, ${j9.nameOf(K)});`;break;case j0.G_MW_SEGMENT:{const W=Z>>>2&15;if(Q)X=`gsSPSegment(${N9.nameOf(W)}, ${N(K)});`;this.state.segments[W]=K}break;case j0.G_MW_FOG:{const W=q>>16,z=q&65535;if(Q)X=`gSPFogPosition(${W}, ${z});`;this.state.fogParameters.set(W,z)}break;case j0.G_MW_LIGHTCOL:this.warnUnimplemented("MoveWord LightCol");break;case j0.G_MW_POINTS:this.warnUnimplemented("MoveWord Points");break;case j0.G_MW_PERSPNORM:if(Q)X=`gSPPerspNormalize(${K});`;break;default:this.warnUnimplemented("MoveWord Unknown");break}if(Q){if(!X)X=`gMoveWd(${j0.nameOf(Y)}, ${r(Z)}, ${N(K)});`;Q.text(X)}}executeMoveMem(J,q,Q){const Y=this.state.rdpSegmentAddress(q),Z=(J>>>16&255)<<1,K=(J>>>8&255)<<3,X=J&254;let W;if(Q)W=`gsDma1p(G_MOVEMEM, ${N(Y)}, ${Z}, ${K}, ${x0.nameOf(X)});`;switch(X){case x0.G_GBI2_MV_VIEWPORT:if(Q)W=`gsSPViewport(${N(Y)});`;this.loadViewport(Y);break;case x0.G_GBI2_MV_LIGHT:if(K==x0.G_GBI2_MVO_LOOKATX){if(Q)W=`gSPLookAtX(${N(Y)});`}else if(K==x0.G_GBI2_MVO_LOOKATY){if(Q)W=`gSPLookAtY(${N(Y)});`}else if(K>=x0.G_GBI2_MVO_L0&&K<=x0.G_GBI2_MVO_L7){let z=(K-x0.G_GBI2_MVO_L0)/24>>>0;if(Q)W=`gsSPLight(${N(Y)}, ${z})`;if(this.loadLight(z,Y),Z!=16)console.log(`unexpected gsSPLight length ${Z}. Is this setting multiple lights?`)}else if(Q)W+=` // (unknown offset ${r(K)})`;break;case x0.G_GBI2_MV_POINT:this.warnUnimplemented("MoveMem G_GBI2_MV_POINT");break;case x0.G_GBI2_MV_MATRIX:this.warnUnimplemented("MoveMem G_GBI2_MV_MATRIX");break;default:this.warnUnimplemented(`MoveMem ${X.toString(16)}`)}if(Q)Q.text(W),this.previewMoveMem(X,Z,Y,Q)}previewMoveMem(J,q,Q,Y){let Z="";for(let K=0;K<q;K+=4)Z+=B(this.ramDV.getUint32(Q+K),32)+" ";switch(Z+="<br>",J){case x0.G_GBI2_MV_VIEWPORT:Z+=this.previewViewport(Q);break;case x0.G_GBI2_MV_LIGHT:Z+=this.previewLight(Q);break}Y.tip(Z)}}class uQ extends I8{constructor(J,q){super(J,q);this.vertexStride=2}}var gQ=0,xQ=1,pQ=2,mQ=3;class gX{constructor(){this.imageX=0,this.imageW=0,this.frameX=0,this.frameW=0,this.imageY=0,this.imageH=0,this.frameY=0,this.frameH=0,this.imagePtr=0,this.imageLoad=0,this.imageFmt=0,this.imageSiz=0,this.imagePal=0,this.imageFlip=0,this.scaleW=0,this.scaleH=0,this.imageYorig=0}load(J,q){this.imageX=J.getUint16(q+0,!1)/32,this.imageW=J.getUint16(q+2,!1)/4,this.frameX=J.getInt16(q+4,!1)/4,this.frameW=J.getUint16(q+6,!1)/4,this.imageY=J.getUint16(q+8,!1)/32,this.imageH=J.getUint16(q+10,!1)/4,this.frameY=J.getInt16(q+12,!1)/4,this.frameH=J.getUint16(q+14,!1)/4,this.imagePtr=J.getUint32(q+16,!1),this.imageLoad=J.getUint16(q+20,!1),this.imageFmt=J.getUint8(q+22,!1),this.imageSiz=J.getUint8(q+23,!1),this.imagePal=J.getUint16(q+24,!1),this.imageFlip=J.getUint16(q+26,!1),this.scaleW=J.getUint16(q+28,!1)/1024,this.scaleH=J.getUint16(q+30,!1)/1024,this.imageYorig=J.getInt32(q+32,!1)/32}toString(){return`imageX/Y = (${this.imageX}, ${this.imageY}), imageW/H = (${this.imageW}, ${this.imageH})
|
|
frameX/Y = (${this.frameX}, ${this.frameY}), frameW/H = (${this.frameW}, ${this.frameH})
|
|
imagePtr = ${N(this.imagePtr)}, imageLoad = ${this.imageLoad}
|
|
imageFmt = ${Z0.nameOf(this.imageFmt)}, imageSiz = ${p.nameOf(this.imageSiz)}
|
|
imagePal = ${this.imagePal}, imageFlip = ${this.imageFlip}
|
|
scaleW/H = (${this.scaleW}, ${this.scaleH})`}}class xX{constructor(){this.a=1,this.b=0,this.c=0,this.d=1,this.x=0,this.y=0,this.sx=1,this.sy=1}loadFullMatrix(J,q){this.a=J.getInt32(q+0,!1)/65536,this.b=J.getInt32(q+4,!1)/65536,this.c=J.getInt32(q+8,!1)/65536,this.d=J.getInt32(q+12,!1)/65536,this.loadSubMatrix(J,q+16)}loadSubMatrix(J,q){this.x=J.getInt16(q+0,!1)/4,this.y=J.getInt16(q+2,!1)/4,this.sx=J.getUint16(q+4,!1)/1024,this.sy=J.getUint16(q+6,!1)/1024}toString(){return`rot = (${this.a}, ${this.b}, ${this.c}, ${this.d}), trans = (${this.x}, ${this.y}), scale = (${this.sx}, ${this.sy})`}}class pX{constructor(){this.objX=0,this.scaleW=0,this.imageW=0,this.objY=0,this.scaleH=0,this.imageH=0,this.imageStride=0,this.imageAdrs=0,this.imageFmt=0,this.imageSiz=0,this.imagePal=0,this.imageFlags=0}load(J,q){this.objX=J.getInt16(q+0,!1)/4,this.scaleW=J.getUint16(q+2,!1)/1024,this.imageW=J.getUint16(q+4,!1)/32,this.objY=J.getInt16(q+8,!1)/4,this.scaleH=J.getUint16(q+10,!1)/1024,this.imageH=J.getUint16(q+12,!1)/32,this.imageStride=J.getUint16(q+16,!1),this.imageAdrs=J.getUint16(q+18,!1),this.imageFmt=J.getUint8(q+20,!1),this.imageSiz=J.getUint8(q+21,!1),this.imagePal=J.getUint8(q+22,!1),this.imageFlags=J.getUint8(q+23,!1)}get objW(){return this.imageW/this.scaleW}get objH(){return this.imageH/this.scaleH}toString(){return`pos = (${this.objX}, ${this.objY}), scale = (${this.scaleW}, ${this.scaleH}), image = (${this.imageW}, ${this.imageH})
|
|
stride = ${this.imageStride}, address = ${r(this.imageAdrs)}, format = ${Z0.nameOf(this.imageFmt)}, size = ${p.nameOf(this.imageSiz)}
|
|
paletteIdx = ${this.imagePal}, flags = ${this.imageFlags}`}}var SH=48;var vH=51,fH=52;class mX{constructor(){this.type=0,this.image=0,this.tileTMEM=0,this.texLoadSize=0,this.texLoadRows=0,this.sid=0,this.flag=0,this.mask=0}load(J,q){this.type=J.getUint32(q+0,!1),this.image=J.getUint32(q+4,!1),this.tileTMEM=J.getUint16(q+8,!1),this.texLoadSize=J.getUint16(q+10,!1),this.texLoadRows=J.getUint16(q+12,!1),this.sid=J.getUint16(q+14,!1),this.flag=J.getUint32(q+16,!1),this.mask=J.getUint32(q+20,!1)}toString(){let J=`type = ${N(this.type)}, image = ${N(this.image)}\n`;return J+=`tmem = ${r(this.tileTMEM)}, size (qwords) = ${r(this.texLoadSize)}, rows (texels) = ${this.texLoadRows}`,J}}class nQ{constructor(J,q,Q){this.state=J,this.ramDV=q,this.gbi=Q,this.scaleBg=new gX,this.matrix=new xX,this.sprite=new pX,this.texture=new mX}executeBg1cyc(J,q,Q){const Y=this.state.rdpSegmentAddress(q);if(this.scaleBg.load(this.ramDV,Y),this.gbi.warnUnimplemented("gSPBgRect1Cyc"),Q)Q.text(`gSPBgRect1Cyc(${N(Y)});`),Q.tip(this.scaleBg.toString())}executeBgCopy(J,q,Q){if(this.gbi.warnUnimplemented("gSPBgRectCopy"),Q)Q.text("gSPBgRectCopy(/* TODO */);")}executeObjRectangle(J,q,Q){this.execLoadTxRenderObj("gSPObjRectangle",!1,mQ,q,Q)}executeObjRectangleR(J,q,Q){this.execLoadTxRenderObj("gSPObjRectangleR",!1,pQ,q,Q)}executeObjSprite(J,q,Q){this.execLoadTxRenderObj("gSPObjSprite",!1,xQ,q,Q)}executeObjLoadTxRect(J,q,Q){this.execLoadTxRenderObj("gSPObjLoadTxRect",!0,mQ,q,Q)}executeObjLoadTxRectR(J,q,Q){this.execLoadTxRenderObj("gSPObjLoadTxRectR",!0,pQ,q,Q)}executeObjLoadTxSprite(J,q,Q){this.execLoadTxRenderObj("gSPObjLoadTxSprite",!0,xQ,q,Q)}executeObjLoadTxtr(J,q,Q){this.execLoadTxRenderObj("gSPObjLoadTxtr",!0,gQ,q,Q)}execLoadTxRenderObj(J,q,Q,Y,Z){const K=this.state.rdpSegmentAddress(Y);let X=K;if(q)this.texture.load(this.ramDV,X),this.loadTexture(),X+=24;if(Q!=gQ)this.sprite.load(this.ramDV,X),this.renderSprite(Q),X+=24;let W="";if(Z){if(Z.text(`${J}(${N(K)});`),q)W+=this.texture.toString()+"\n";if(Q!=gQ)W+=this.sprite.toString()+"\n";Z.tip(W)}}executeObjMoveMem(J,q,Q){const Y=this.state.rdpSegmentAddress(q),Z=J&65535;switch(Z){case 0:if(Q)Q.text(`gSPObjMatrix(${N(Y)});`);this.setObjMatrix(Y,Q);break;case 2:if(Q)Q.text(`gSPObjSubMatrix(${N(Y)});`);this.setObjSubMatrix(Y,Q);break;default:if(Q)Q.text(`gSPObjMoveMem(${Z}, ${N(Y)});`)}}setObjMatrix(J,q){if(this.matrix.loadFullMatrix(this.ramDV,J),q)q.tip(this.matrix.toString())}setObjSubMatrix(J,q){if(this.matrix.loadSubMatrix(this.ramDV,J),q)q.tip(this.matrix.toString())}executeSelectDL(J,q,Q){if(this.gbi.warnUnimplemented("gSPSelectDL"),Q)Q.text("gSPSelectDL(/* TODO */);")}executeObjRendermode(J,q,Q){if(Q)Q.text("gSPObjRenderMode(/* ignored */);")}executeTriRSP(J,q,Q){if(this.gbi.warnUnimplemented("executeTriRSP"),Q)Q.text("executeTriRSP(); // ignored")}loadTexture(){const J=this.texture,q=this.state.tiles[UQ],Q=this.state.rdpSegmentAddress(J.image),Y=this.state.textureImage;Y.set(Z0.G_IM_FMT_RGBA,p.G_IM_SIZ_16b,J.texLoadSize+1,Q);const Z=J.type>>>8&255,K=Z>>>5&7,X=Z>>>3&3,W=J.type<<8>>24,z=(J.texLoadSize+1&W)>>>2,F=0;q.set(K,X,z,J.tileTMEM,F,0,0,0,0,0,0);const j=2,G=J.texLoadSize<<j;switch(J.type>>>0&255){case vH:this.state.tmem.loadBlock(Y,q,0,0,G,J.texLoadRows);break;case fH:this.state.tmem.loadTile(Y,q,0,0,G,J.texLoadRows);break;case SH:this.state.tmem.loadTLUT(Y,q,0,0,G,J.texLoadRows);break;default:this.gbi.warnUnimplemented(`load texture type ${J.type}`);break}this.state.invalidateTileHashes()}renderSprite(J){const q=this.sprite,Q=this.matrix,Z=q.objX,K=q.objY,X=q.objW+Z,W=q.objH+K,z=this.state.tiles[0];z.set(q.imageFmt,q.imageSiz,q.imageStride,q.imageAdrs,q.imagePal,R6,0,0,R6,0,0),z.setSize(0,0,q.imageW-1<<2,q.imageH-1<<2);const F=q.imageFlags&1,j=q.imageFlags&16;if(F||j)this.gbi.warnUnimplemented("swapX/Y");const G=0,P=0,L=q.imageW,U=q.imageH;if(J==xQ){const O=Q.x+Q.a*Z+Q.b*K,E=Q.y+Q.c*Z+Q.d*K,w=Q.x+Q.a*X+Q.b*K,y=Q.y+Q.c*X+Q.d*K,S=Q.x+Q.a*Z+Q.b*W,g=Q.y+Q.c*Z+Q.d*W,x=Q.x+Q.a*X+Q.b*W,H0=Q.y+Q.c*X+Q.d*W;this.gbi.renderer.texRectRot(0,O,E,w,y,S,g,x,H0,G,P,L,U)}else if(J==pQ){const O=Q.x+Z/Q.sx,E=Q.y+K/Q.sy,w=Q.x+X/Q.sx,y=Q.y+W/Q.sy;this.gbi.renderer.texRect(0,O,E,w,y,G,P,L,U,!1)}else if(J==mQ){const O=Z,E=X,w=K,y=W;this.gbi.renderer.texRect(0,O,w,E,y,G,P,L,U,!1)}}}class oQ extends v6{constructor(J,q){super(J,q);this.vertexStride=2,this.s2dex=new nQ(J,q,this),this.sdexCommands=new Map([[1,this.s2dex.executeBg1cyc.bind(this.s2dex)],[2,this.s2dex.executeBgCopy.bind(this.s2dex)],[3,this.s2dex.executeObjRectangle.bind(this.s2dex)],[4,this.s2dex.executeObjSprite.bind(this.s2dex)],[5,this.s2dex.executeObjMoveMem.bind(this.s2dex)],[176,this.s2dex.executeSelectDL.bind(this.s2dex)],[177,this.s2dex.executeObjRendermode.bind(this.s2dex)],[178,this.s2dex.executeObjRectangleR.bind(this.s2dex)],[193,this.s2dex.executeObjLoadTxtr.bind(this.s2dex)],[194,this.s2dex.executeObjLoadTxSprite.bind(this.s2dex)],[195,this.s2dex.executeObjLoadTxRect.bind(this.s2dex)],[196,this.s2dex.executeObjLoadTxRectR.bind(this.s2dex)],[200,this.s2dex.executeTriRSP.bind(this.s2dex)],[201,this.s2dex.executeTriRSP.bind(this.s2dex)],[202,this.s2dex.executeTriRSP.bind(this.s2dex)],[203,this.s2dex.executeTriRSP.bind(this.s2dex)],[204,this.s2dex.executeTriRSP.bind(this.s2dex)],[205,this.s2dex.executeTriRSP.bind(this.s2dex)],[206,this.s2dex.executeTriRSP.bind(this.s2dex)],[207,this.s2dex.executeTriRSP.bind(this.s2dex)],[228,this.executeRDPHalf0.bind(this.s2dex)]])}getHandler(J){const q=this.sdexCommands.get(J);if(q)return q;return super.getHandler(J)}executeRDPHalf0(J,q,Q){if(Q)Q.text(`gsImmp1(G_RDPHALF_0, ${N(J)}, ${N(q)});`);this.state.rdpHalf0Cmd0=J,this.state.rdpHalf0Cmd1=q}executeRDPHalf2(J,q,Q){if(Q)Q.text(`gsImmp1(G_RDPHALF_2, ${N(q)});`);this.rdpTexRect(this.state.rdpHalf0Cmd0,this.state.rdpHalf0Cmd1,this.state.rdpHalf1Cmd1,q,Q)}}class cQ extends I8{constructor(J,q){super(J,q);this.vertexStride=2,this.s2dex=new nQ(J,q,this),this.sdexCommands=new Map([[1,this.s2dex.executeObjRectangle.bind(this.s2dex)],[2,this.s2dex.executeObjSprite.bind(this.s2dex)],[4,this.s2dex.executeSelectDL.bind(this.s2dex)],[5,this.s2dex.executeObjLoadTxtr.bind(this.s2dex)],[6,this.s2dex.executeObjLoadTxSprite.bind(this.s2dex)],[7,this.s2dex.executeObjLoadTxRect.bind(this.s2dex)],[8,this.s2dex.executeObjLoadTxRectR.bind(this.s2dex)],[9,this.s2dex.executeBg1cyc.bind(this.s2dex)],[10,this.s2dex.executeBgCopy.bind(this.s2dex)],[11,this.s2dex.executeObjRendermode.bind(this.s2dex)],[200,this.s2dex.executeTriRSP.bind(this.s2dex)],[201,this.s2dex.executeTriRSP.bind(this.s2dex)],[202,this.s2dex.executeTriRSP.bind(this.s2dex)],[203,this.s2dex.executeTriRSP.bind(this.s2dex)],[204,this.s2dex.executeTriRSP.bind(this.s2dex)],[205,this.s2dex.executeTriRSP.bind(this.s2dex)],[206,this.s2dex.executeTriRSP.bind(this.s2dex)],[207,this.s2dex.executeTriRSP.bind(this.s2dex)],[213,this.executeDLCount.bind(this)],[218,this.s2dex.executeObjRectangleR.bind(this.s2dex)]])}getHandler(J){const q=this.sdexCommands.get(J);if(q)return q;return super.getHandler(J)}executeDLCount(J,q,Q){if(this.warnUnimplemented("executeDL_Count"),Q)Q.text("executeDL_Count(/* TODO */);")}executeMoveMem(J,q,Q){const Y=J&254;if(Y==0){const Z=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gSPObjMatrix(${N(Z)});`);this.s2dex.setObjMatrix(Z,Q);return}else if(Y==2){const Z=this.state.rdpSegmentAddress(q);if(Q)Q.text(`gSPObjSubMatrix(${N(Z)});`);this.s2dex.setObjSubMatrix(Z,Q);return}super.executeMoveMem(J,q,Q)}}function JW(J,q,Q){const Y=J.detectVersionString(),Z=W6.dumpMicrocodeSubstring;if(Z!=""&&!nX&&Y.includes(Z))J.dumpCode(),nX=!0;const K=J.computeMicrocodeHash(),X=xH(Y,K),W=gH(X,q,Q);return W.version=Y,W}var gH=function(J,q,Q){switch(J){case g9:return new $6(q,Q);case f9:return new fQ(q,Q);case sX:return new vQ(q,Q);case eX:return new _Q(q,Q);case iX:return new TQ(q,Q);case rX:return new SQ(q,Q);case cX:return new v6(q,Q);case u9:return new bQ(q,Q);case dX:return new oQ(q,Q);case lX:return new I8(q,Q);case tX:return new uQ(q,Q);case aX:return new cQ(q,Q)}return M(`unhandled ucode during table init: ${J}`),new $6(q,Q)},xH=function(J,q){let Q=uH.get(q);if(Q===void 0)Q=mH(J);return pH(J,Q),Q},pH=function(J,q){if(oX.get(J))return;oX.set(J,!0),M(`New RSP graphics ucode seen: ${J} = ucode ${q}`)},mH=function(J){const q=["F3","L3","S2DEX"];let Q=-1;for(let Y of q)if(Q=J.indexOf(Y),Q>=0)break;if(Q>=0){if(J.indexOf("fifo",Q)>=0||J.indexOf("xbux",Q)>=0)return J.indexOf("S2DEX")>=0?aX:lX;return J.indexOf("S2DEX")>=0?dX:cX}return g9},g9=0,cX=1,lX=2,dX=3,aX=4,rX=5,f9=6,u9=7,sX=8,iX=9,tX=10,eX=11,uH=new Map([[1613065980,tX],[1837886526,u9],[202381338,f9],[1899172316,f9],[603530562,iX],[379440285,f9],[651856460,u9],[3401874884,eX],[1824215581,sX],[3713401635,u9],[1691120285,rX],[3610907332,g9],[826213259,g9]]),nX=!1,oX=new Map;class c0{constructor(J,q,Q,Y){if(Y!==void 0)this.elems=new Float32Array(4),this.elems[0]=J,this.elems[1]=q,this.elems[2]=Q,this.elems[3]=Y;else this.elems=J||new Float32Array(4)}get x(){return this.elems[0]}get y(){return this.elems[1]}get z(){return this.elems[2]}get w(){return this.elems[3]}set x(J){this.elems[0]=J}set y(J){this.elems[1]=J}set z(J){this.elems[2]=J}set w(J){this.elems[3]=J}set(J,q,Q,Y){return this.x=J,this.y=q,this.z=Q,this.w=Y,this}setV3(J,q){return this.x=J.x,this.y=J.y,this.z=J.z,this.w=q,this}dot(J){var q=0;for(var Q=0;Q<this.elems.length;++Q)q+=this.elems[Q]*J.elems[Q];return q}lengthSqr(){return this.dot(this)}length(){return Math.sqrt(this.lengthSqr())}addInPlace(J){for(var q=0;q<this.elems.length;++q)this.elems[q]+=J.elems[q];return this}subInPlace(J){for(var q=0;q<this.elems.length;++q)this.elems[q]-=J.elems[q];return this}scaleInPlace(J){for(var q=0;q<this.elems.length;++q)this.elems[q]*=J;return this}vecScaleInPlace(J){for(var q=0;q<this.elems.length;++q)this.elems[q]*=J.elems[q];return this}invVecScaleInPlace(J){for(var q=0;q<this.elems.length;++q)this.elems[q]/=J.elems[q];return this}normaliseInPlace(){var J=this.length();if(J>0)return this.scaleInPlace(1/J);return this}static create(J){var q=new X0;return q.elems[0]=J[0],q.elems[1]=J[1],q.elems[2]=J[2],q.elems[3]=J[3],q}}class lQ{constructor(){this.pos=new c0,this.color=0,this.u=0,this.v=0,this.clipFlags=0,this.set=!1}calculateLinearUV(J){this.u=0.5*(1+J.x),this.v=0.5*(1+J.y)}calculateSphericalUV(J){this.u=Math.acos(J.x)/Math.PI,this.v=Math.acos(J.y)/Math.PI}}class GJ{constructor(J,q){this.scale=J||new c0(1,1,1,1),this.trans=q||new c0(0,0,0,0)}transformInPlace(J){J.vecScaleInPlace(this.scale),J.addInPlace(this.trans)}invTransformInPlace(J){J.subInPlace(this.trans),J.invVecScaleInPlace(this.scale)}}var oH=function(){return n64js.hardware().cachedMemDevice.s32},qW=function(){return n64js.hardware().cachedMemDevice.u8},dQ=function(J,q,Q,Y){let Z=q>>2,K=q+Q>>2;while(Z<K)Y=Y*17+J[Z]>>>0,++Z;return Y},QW=function(J,q,Q,Y,Z){for(let K=0;K<Z;++K)J[q+0]=Q[Y+0],J[q+1]=Q[Y+1],q+=2,Y+=2},cH=function(J,q,Q,Y,Z,K){a((q&1)==0,"tmem isn't qword aligned");for(let X=0;X<Z;++X)J[q+0^K]=Q[Y+0],J[q+1^K]=Q[Y+1],q+=2,Y+=2},lH=function(J,q,Q,Y,Z,K){for(let X=0;X<Z;++X)J[q+X]=Q[Y+X];for(let X=Z;X<K;++X)J[q+X]=0},dH=function(J,q,Q,Y,Z,K,X){for(let W=0;W<Z;++W)J[q+W^X]=Q[Y+W];for(let W=Z;W<K;++W)J[q+W^X]=0},aH=function(J,q,Q,Y,Z){for(let K=0;K<Z;K++){const X=Q[Y+K*2+0],W=Q[Y+K*2+1];J[q+K*8+0]=X,J[q+K*8+1]=W,J[q+K*8+2]=X,J[q+K*8+3]=W,J[q+K*8+4]=X,J[q+K*8+5]=W,J[q+K*8+6]=X,J[q+K*8+7]=W}};class aQ{constructor(){const J=new ArrayBuffer(4096);this.tmemData32=new Int32Array(J),this.tmemData=new Uint8Array(J)}loadBlock(J,q,Q,Y,Z,K,X){const W=Q>>>2,z=Y>>>2,F=J.calcAddress(W,z),j=Z-Q+1&4095,G=J.texelsToBytes(j),P=G+7>>>3,L=this.tmemData32;let U=F>>>2,O=q.tmem<<3>>>2;const E=oH(),w=q.size==p.G_IM_SIZ_32b?2:1;if(X)X.tip(`bytes ${G}, qwords ${P}`);if(K===0)QW(L,O,E,U,P);else{const y=Math.ceil(2048/K);let S=0;for(let g=0;g<P;){const x=Math.min(P-g,y);if(S)cH(L,O,E,U,x,w);else QW(L,O,E,U,x);g+=x,O+=x*2,U+=x*2,S^=1}}}loadTile(J,q,Q,Y,Z,K,X){const W=Q>>>2,z=Y>>>2,F=Z>>>2,j=K>>>2,G=F+1-W,P=j+1-z,L=J.calcAddress(W,z),U=J.texelsToBytes(G),O=J.stride(),E=this.tmemData;let w=q.tmem<<3,y=L;const S=J.size==p.G_IM_SIZ_32b?q.line<<4:q.line<<3,g=q.size==p.G_IM_SIZ_32b?8:4;if(X)X.tip(`size (${G} x ${P}), rowBytes ${U}, ramStride ${O}, tmemStride ${S}, ramOffset ${N(y)}, tmemOffset ${r(w)}`);const x=qW();for(let H0=0;H0<P;++H0){if(H0&1)dH(E,w,x,y,U,S,g);else lH(E,w,x,y,U,S);w+=S,y+=O}}loadTLUT(J,q,Q,Y,Z,K,X){const W=Q>>>2,z=Y>>>2,F=J.calcAddress(W,z,p.G_IM_SIZ_16b),j=y8(Z,Q),G=qW();var P=q.tmem<<3;if(X)X.tip(`count ${j}, tmemOffset ${r(P)}`);aH(this.tmemData,P,G,F,j)}convertTexels(J,q,Q){return OX(Q,this.tmemData,J,q)}calculateCRC(J){if(J.hash)return J.hash;var q=J.height,Q=this.tmemData32,Y=J.tmem<<3,Z=J.line<<3;if(J.format==Z0.G_IM_FMT_RGBA&&J.size==p.G_IM_SIZ_32b)Z*=2;var K=q*Z,X=dQ(Q,Y,K,0);if(J.format===Z0.G_IM_FMT_CI||J.format===Z0.G_IM_FMT_RGBA){if(J.size===p.G_IM_SIZ_8b)X=dQ(Q,2048,2048,X);else if(J.size===p.G_IM_SIZ_4b)X=dQ(Q,2048+J.palette*16*2,128,X)}return J.hash=X,X}}var rQ=function(J,q){return J<<q>>>1};class sQ{constructor(){this.ramDV=null,this.pc=0,this.pcEnd=0,this.dlistStack=[],this.cmd0=0,this.cmd1=0,this.segments=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.tiles=new Array(8),this.lights=new Array(8),this.numLights=0,this.geometryModeBits=0,this.geometryMode={zbuffer:0,texture:0,shade:0,shadeSmooth:0,cullFront:0,cullBack:0,fog:0,lighting:0,textureGen:0,textureGenLinear:0,lod:0},this.rdpOtherModeL=0,this.rdpOtherModeH=0,this.rdpHalf0Cmd0=0,this.rdpHalf0Cmd1=0,this.rdpHalf1Cmd1=0,this.rdpHalf2Cmd1=0,this.viewport=new YW,this.projection=[],this.modelview=[],this.projectedVertices=new Array(64),this.scissor={mode:0,x0:0,y0:0,x1:320,y1:240},this.texture={tile:0,level:0,scaleS:1,scaleT:1},this.combine={lo:0,hi:0},this.fillColor=0,this.envColor=0,this.primColor=0,this.blendColor=0,this.fogColor=0,this.primDepth=0,this.fogParameters=new ZW,this.colorImage={format:0,size:0,width:0,address:0},this.textureImage=new KW,this.depthImage={address:0},this.tmem=new aQ,this.screenContext2d=null}reset(J,q){this.ramDV=J,this.pc=q,this.pcEnd=0,this.dlistStack=[],this.cmd0=0,this.cmd1=0;for(let Q=0;Q<this.segments.length;++Q)this.segments[Q]=0;this.rdpOtherModeL=5242881,this.rdpOtherModeH=0,this.projection=[y0.identity()],this.modelview=[y0.identity()],this.geometryModeBits=0,this.geometryMode.zbuffer=0,this.geometryMode.texture=0,this.geometryMode.shade=0,this.geometryMode.shadeSmooth=0,this.geometryMode.cullFront=0,this.geometryMode.cullBack=0,this.geometryMode.fog=0,this.geometryMode.lighting=0,this.geometryMode.textureGen=0,this.geometryMode.textureGenLinear=0,this.geometryMode.lod=0;for(let Q=0;Q<this.tiles.length;++Q)this.tiles[Q]=new BQ;this.numLights=0;for(let Q=0;Q<this.lights.length;++Q)this.lights[Q]={color:{r:0,g:0,b:0,a:0},dir:X0.create([1,0,0])};for(let Q=0;Q<this.projectedVertices.length;++Q)this.projectedVertices[Q]=new lQ;this.viewport.reset(),this.fogParameters.reset()}nextCommand(){if(this.pcEnd&&this.pc>=this.pcEnd)this.endDisplayList();if(this.pc==0)return!1;return this.cmd0=this.ramDV.getUint32(this.pc+0),this.cmd1=this.ramDV.getUint32(this.pc+4),this.pc+=8,!0}advanceIfCommand(J){if(this.pc==0||this.pcEnd&&this.pc>this.pcEnd)return!1;const q=this.ramDV.getUint32(this.pc+0);if(q>>>24!==J)return!1;return this.cmd0=q,this.cmd1=this.ramDV.getUint32(this.pc+4),this.pc+=8,!0}executeBatch(J,q){const Q=this.cmd0>>>24,Y=J<=0;let Z=0;do if(Z++,!q(this.cmd0,this.cmd1))break;while((Y||Z<J)&&this.advanceIfCommand(Q));return Z}pushDisplayList(J,q){const Q=q==void 0?0:J+q*8;this.dlistStack.push({pc:this.pc,pcEnd:this.pcEnd}),this.pc=J,this.pcEnd=Q}branchDisplayList(J){this.pc=J}endDisplayList(){if(this.dlistStack.length<=0){this.pc=0,this.pcEnd=0;return}const J=this.dlistStack.pop();this.pc=J.pc,this.pcEnd=J.pcEnd}invalidateTileHashes(){for(let J=0;J<8;++J)this.tiles[J].hash=0}rdpSegmentAddress(J){const q=J>>>24&15;return(this.segments[q]&8388607)+(J&8388607)}setTexture(J,q,Q,Y){this.texture.scaleS=J,this.texture.scaleT=q,this.texture.level=Q,this.texture.tile=Y}updateGeometryModeFromBits(J){var q=this.geometryMode,Q=this.geometryModeBits;q.zbuffer=Q&J.G_ZBUFFER?1:0,q.texture=Q&J.G_TEXTURE_ENABLE?1:0,q.shade=Q&J.G_SHADE?1:0,q.shadeSmooth=Q&J.G_SHADING_SMOOTH?1:0,q.cullFront=Q&J.G_CULL_FRONT?1:0,q.cullBack=Q&J.G_CULL_BACK?1:0,q.fog=Q&J.G_FOG?1:0,q.lighting=Q&J.G_LIGHTING?1:0,q.textureGen=Q&J.G_TEXTURE_GEN?1:0,q.textureGenLinear=Q&J.G_TEXTURE_GEN_LINEAR?1:0,q.lod=Q&J.G_LOD?1:0}getCycleType(){return this.rdpOtherModeH&L8}getTextureFilterType(){return this.rdpOtherModeH&U8}getTextureLUTType(){return this.rdpOtherModeH&V8}getAlphaCompareType(){return this.rdpOtherModeL&P8}getAntiAliasEnabled(){return(this.rdpOtherModeL&$0.AA_EN)!==0}getCoverageTimesAlpha(){return(this.rdpOtherModeL&$0.CVG_X_ALPHA)!==0}getAlphaCoverageSelect(){return(this.rdpOtherModeL&$0.ALPHA_CVG_SEL)!==0}}class YW{constructor(){this.reset()}reset(){const J=new X0(160,-120,1),q=new X0(160,120,0);this.set(J,q)}set(J,q){this.scale=J,this.trans=q;const Q=new c0().setV3(J,1),Y=new c0().setV3(q,0);this.transform=new GJ(Q,Y)}}class ZW{constructor(){this.reset()}reset(){this.multiplier=0,this.offset=0}set(J,q){this.multiplier=J,this.offset=q}}class KW{constructor(){this.format=0,this.size=0,this.width=0,this.address=0}set(J,q,Q,Y){this.format=J,this.size=q,this.width=Q,this.address=Y}calcAddress(J,q,Q){const Y=Q===void 0?this.size:Q;return this.address+q*rQ(this.width,Y)+rQ(J,Y)}texelsToBytes(J){return rQ(J,this.size)}stride(){return this.texelsToBytes(this.width)}}class N0{constructor(J,q){this.x=J,this.y=q}dot(J){return this.x*J.x+this.y*J.y}lengthSqr(){return this.dot(this)}length(){return Math.sqrt(this.lengthSqr())}add(J){return new N0(this.x+J.x,this.y+J.y)}sub(J){return new N0(this.x-J.x,this.y-J.y)}scale(J){return new N0(this.x*J,this.y*J)}normaliseInPlace(){const J=this.length();if(J>0)this.x/=J,this.y/=J;return this}}class iQ{constructor(J,q){this.scale=J||new N0(1,1),this.trans=q||new N0(0,0)}transform(J){const q=this.scale.x*J.x+this.trans.x,Q=this.scale.y*J.y+this.trans.y;return new N0(q,Q)}}function WW(J,q,Q){let Y=J.data,Z=J.width*4,K=0;if(q<J.width){let X=0;for(;K<Q;++K){let W=X+(q-1)*4,z=Y[W+0],F=Y[W+1],j=Y[W+2],G=Y[W+3];W+=4;for(let P=q;P<J.width;++P)Y[W+0]=z,Y[W+1]=F,Y[W+2]=j,Y[W+3]=G,W+=4;X+=Z}}if(Q<J.height){let X=Z*Q,W=X-Z;for(;K<J.height;++K){for(let z=0;z<Z;++z)Y[X+z]=Y[W+z];X+=Z}}}var XW=function(J){var q=1;while(q<J)q*=2;return q};class tQ{constructor(J,q,Q){this.width=q,this.height=Q;var Y=XW(q),Z=XW(Q);this.nativeWidth=Y,this.nativeHeight=Z,this.$canvas=$('<canvas width="'+Y+'" height="'+Z+'" />',{width:Y,height:Z}),this.texture=J.createTexture()}createScaledCanvas(J){var q=this.width*J,Q=this.height*J,Y=$('<canvas width="'+q+'" height="'+Q+'" style="background-color: black" />',{width:q,height:Q}),Z=this.$canvas[0].getContext("2d"),K=Y[0].getContext("2d"),X=Z.getImageData(0,0,this.width,this.height),W=K.createImageData(q,Q),z=X.data,F=W.data,j=X.width*4,G=W.width*4;for(let O=0;O<Q;++O){var P=j*Math.floor(O/J),L=G*O;for(let E=0;E<q;++E){var U=P+Math.floor(E/J)*4;F[L+0]=z[U+0],F[L+1]=z[U+1],F[L+2]=z[U+2],F[L+3]=z[U+3],L+=4}}return K.putImageData(W,0,0),Y}}var NW=function(J){if(J<=10)return 1/(1<<J);return 1<<16-J},$W=0,eQ=1,zW=2,HW=3,FW=4,jW=new Map;class JY{constructor(J,q,Q,Y){this.gl=J,this.state=q,this.nativeTransform=new GW,this.textureCache=new Map,this.frameBuffer=J.createFramebuffer(),J.bindFramebuffer(J.FRAMEBUFFER,this.frameBuffer),this.frameBuffer.width=Q,this.frameBuffer.height=Y,this.frameBufferTexture2D=J.createTexture(),J.bindTexture(J.TEXTURE_2D,this.frameBufferTexture2D),J.texParameteri(J.TEXTURE_2D,J.TEXTURE_MAG_FILTER,J.NEAREST),J.texParameteri(J.TEXTURE_2D,J.TEXTURE_MIN_FILTER,J.NEAREST),J.texParameteri(J.TEXTURE_2D,J.TEXTURE_WRAP_S,J.CLAMP_TO_EDGE),J.texParameteri(J.TEXTURE_2D,J.TEXTURE_WRAP_T,J.CLAMP_TO_EDGE),this.frameBufferTexture3D=J.createTexture(),J.bindTexture(J.TEXTURE_2D,this.frameBufferTexture3D),J.texParameteri(J.TEXTURE_2D,J.TEXTURE_MAG_FILTER,J.NEAREST),J.texParameteri(J.TEXTURE_2D,J.TEXTURE_MIN_FILTER,J.NEAREST),J.texParameteri(J.TEXTURE_2D,J.TEXTURE_WRAP_S,J.CLAMP_TO_EDGE),J.texParameteri(J.TEXTURE_2D,J.TEXTURE_WRAP_T,J.CLAMP_TO_EDGE),J.texImage2D(J.TEXTURE_2D,0,J.RGBA,Q,Y,0,J.RGBA,J.UNSIGNED_BYTE,null),J.framebufferTexture2D(J.FRAMEBUFFER,J.COLOR_ATTACHMENT0,J.TEXTURE_2D,this.frameBufferTexture3D,0),J.bindTexture(J.TEXTURE_2D,null);const Z=J.createRenderbuffer();J.bindRenderbuffer(J.RENDERBUFFER,Z),J.renderbufferStorage(J.RENDERBUFFER,J.DEPTH_COMPONENT16,Q,Y),J.framebufferRenderbuffer(J.FRAMEBUFFER,J.DEPTH_ATTACHMENT,J.RENDERBUFFER,Z),J.bindRenderbuffer(J.RENDERBUFFER,null),J.bindFramebuffer(J.FRAMEBUFFER,null),this.blitShaderProgram=kQ(J,"blit-shader-vs","blit-shader-fs"),this.blitVertexPositionAttribute=J.getAttribLocation(this.blitShaderProgram,"aVertexPosition"),this.blitTexCoordAttribute=J.getAttribLocation(this.blitShaderProgram,"aTextureCoord"),this.blitSamplerUniform=J.getUniformLocation(this.blitShaderProgram,"uSampler"),this.fillShaderProgram=kQ(J,"fill-shader-vs","fill-shader-fs"),this.fillVertexPositionAttribute=J.getAttribLocation(this.fillShaderProgram,"aVertexPosition"),this.fillFillColorUniform=J.getUniformLocation(this.fillShaderProgram,"uFillColor"),this.fillVerticesBuffer=J.createBuffer(),this.n64PositionsBuffer=J.createBuffer(),this.n64ColorsBuffer=J.createBuffer(),this.n64UVBuffer=J.createBuffer(),this.$textureOutput=$("#texture-content")}reset(){this.textureCache.clear(),this.$textureOutput.html("")}newFrame(){const J=this.gl;J.bindFramebuffer(J.FRAMEBUFFER,this.frameBuffer),J.viewport(0,0,this.frameBuffer.width,this.frameBuffer.height)}copyTextureToFrontBuffer(J){const q=this.gl;q.bindFramebuffer(q.FRAMEBUFFER,null);const Q=[-1,-1,0,1,1,-1,0,1,-1,1,0,1,1,1,0,1],Y=[0,0,1,0,0,1,1,1];q.useProgram(this.blitShaderProgram);const Z=document.getElementById("display");q.viewport(0,0,Z.width,Z.height),q.enableVertexAttribArray(this.blitVertexPositionAttribute),q.bindBuffer(q.ARRAY_BUFFER,this.n64PositionsBuffer),q.bufferData(q.ARRAY_BUFFER,new Float32Array(Q),q.STATIC_DRAW),q.vertexAttribPointer(this.blitVertexPositionAttribute,4,q.FLOAT,!1,0,0),q.enableVertexAttribArray(this.blitTexCoordAttribute),q.bindBuffer(q.ARRAY_BUFFER,this.n64UVBuffer),q.bufferData(q.ARRAY_BUFFER,new Float32Array(Y),q.STATIC_DRAW),q.vertexAttribPointer(this.blitTexCoordAttribute,2,q.FLOAT,!1,0,0),q.activeTexture(q.TEXTURE0),q.bindTexture(q.TEXTURE_2D,J),q.uniform1i(this.blitSamplerUniform,0),q.disable(q.CULL_FACE),q.disable(q.BLEND),q.disable(q.DEPTH_TEST),q.depthMask(!1),q.drawArrays(q.TRIANGLE_STRIP,0,4)}copyBackBufferToFrontBuffer(){this.copyTextureToFrontBuffer(this.frameBufferTexture3D)}copyPixelsToFrontBuffer(J,q,Q,Y){const Z=this.gl;if(Z.activeTexture(Z.TEXTURE0),Z.bindTexture(Z.TEXTURE_2D,this.frameBufferTexture2D),Y==32)Z.texImage2D(Z.TEXTURE_2D,0,Z.RGBA,q,Q,0,Z.RGBA,Z.UNSIGNED_BYTE,J);else if(Y==16)Z.texImage2D(Z.TEXTURE_2D,0,Z.RGBA,q,Q,0,Z.RGBA,Z.UNSIGNED_SHORT_5_5_5_1,J);this.copyTextureToFrontBuffer(this.frameBufferTexture2D)}flushTris(J){const q=this.gl;if(J.empty())return;const Q=this.state.geometryMode.texture,Y=this.state.geometryMode.lighting&&this.state.geometryMode.textureGen;if(this.setProgramState(J.positions,J.colours,J.coords,Q,Y,this.state.texture.tile),this.initDepth(),this.state.geometryMode.cullFront||this.state.geometryMode.cullBack){q.enable(q.CULL_FACE);const Z=this.state.geometryMode.cullFront?q.FRONT:q.BACK;q.cullFace(Z)}else q.disable(q.CULL_FACE);q.drawArrays(q.TRIANGLES,0,J.numTris*3),J.reset()}debugClear(){const J=this.gl,q=[1,1,0,1,-1,1,0,1,1,-1,0,1,-1,-1,0,1];J.useProgram(this.fillShaderProgram),J.enableVertexAttribArray(this.fillVertexPositionAttribute),J.bindBuffer(J.ARRAY_BUFFER,this.fillVerticesBuffer),J.bufferData(J.ARRAY_BUFFER,new Float32Array(q),J.STATIC_DRAW),J.vertexAttribPointer(this.fillVertexPositionAttribute,4,J.FLOAT,!1,0,0),J.uniform4f(this.fillFillColorUniform,1,0,1,1),J.disable(J.BLEND),J.disable(J.CULL_FACE),J.disable(J.DEPTH_TEST),J.depthMask(!1),J.drawArrays(J.TRIANGLE_STRIP,0,4)}fillRect(J,q,Q,Y,Z){const K=this.gl;this.setGLBlendMode();const X=this.nativeTransform.convertN64ToDisplay(new N0(J,q)),W=this.nativeTransform.convertN64ToDisplay(new N0(Q,Y)),z=[W.x,W.y,0,1,X.x,W.y,0,1,W.x,X.y,0,1,X.x,X.y,0,1];K.useProgram(this.fillShaderProgram),K.enableVertexAttribArray(this.fillVertexPositionAttribute),K.bindBuffer(K.ARRAY_BUFFER,this.fillVerticesBuffer),K.bufferData(K.ARRAY_BUFFER,new Float32Array(z),K.STATIC_DRAW),K.vertexAttribPointer(this.fillVertexPositionAttribute,4,K.FLOAT,!1,0,0),K.uniform4f(this.fillFillColorUniform,Z.r,Z.g,Z.b,Z.a),K.disable(K.CULL_FACE),K.disable(K.DEPTH_TEST),K.depthMask(!1),K.drawArrays(K.TRIANGLE_STRIP,0,4)}texRect(J,q,Q,Y,Z,K,X,W,z,F){const j=this.gl,G=this.nativeTransform.convertN64ToDisplay(new N0(q,Q)),P=this.nativeTransform.convertN64ToDisplay(new N0(Y,Z)),L=(this.state.rdpOtherModeL&l6.G_ZS_PRIM)!==0,U=L?this.state.primDepth:0,O=[G.x,G.y,U,1,P.x,G.y,U,1,G.x,P.y,U,1,P.x,P.y,U,1];let E;if(F)E=[K,X,K,z,W,X,W,z];else E=[K,X,W,X,K,z,W,z];const w=[4294967295,4294967295,4294967295,4294967295];if(this.setProgramState(new Float32Array(O),new Uint32Array(w),new Float32Array(E),!0,!1,J),j.disable(j.CULL_FACE),L?!0:!1)this.initDepth();else j.disable(j.DEPTH_TEST),j.depthMask(!1);j.drawArrays(j.TRIANGLE_STRIP,0,4)}texRectRot(J,q,Q,Y,Z,K,X,W,z,F,j,G,P){const L=this.gl,U=this.nativeTransform.convertN64ToDisplay(new N0(q,Q)),O=this.nativeTransform.convertN64ToDisplay(new N0(Y,Z)),E=this.nativeTransform.convertN64ToDisplay(new N0(K,X)),w=this.nativeTransform.convertN64ToDisplay(new N0(W,z)),y=(this.state.rdpOtherModeL&l6.G_ZS_PRIM)!==0,S=y?this.state.primDepth:0,g=[U.x,U.y,S,1,O.x,O.y,S,1,E.x,E.y,S,1,w.x,w.y,S,1];let x=[F,j,G,j,F,P,G,P];const H0=[4294967295,4294967295,4294967295,4294967295];if(this.setProgramState(new Float32Array(g),new Uint32Array(H0),new Float32Array(x),!0,!1,J),L.disable(L.CULL_FACE),y?!0:!1)this.initDepth();else L.disable(L.DEPTH_TEST),L.depthMask(!1);L.drawArrays(L.TRIANGLE_STRIP,0,4)}initDepth(){const J=this.gl,q=this.state.geometryMode.zbuffer!==0,Q=(this.state.rdpOtherModeL&$0.Z_CMP)!==0,Y=(this.state.rdpOtherModeL&$0.Z_UPD)!==0;if(q&&Q||Y)J.enable(J.DEPTH_TEST),J.depthFunc(J.LEQUAL);else J.disable(J.DEPTH_TEST);J.depthMask(Y)}setProgramState(J,q,Q,Y,Z,K){const X=this.gl;this.setGLBlendMode();const W=this.state.getCycleType();let z,F,j,G;if(Y){const E=K+0&7,w=K+1&7;z=this.state.tiles[E],F=this.state.tiles[w],j=this.lookupTexture(E),G=W==K0.G_CYC_2CYCLE?this.lookupTexture(w):null}const P=(this.state.getAlphaCompareType()&c6.G_AC_THRESHOLD)!=0,L=this.state.getAntiAliasEnabled()&&this.state.getCoverageTimesAlpha();let U=0;if(P)U=(this.state.blendColor>>>0&255)/255;else if(L)U=0;const O=this.getCurrentN64Shader();X.useProgram(O.program),X.enableVertexAttribArray(O.vertexPositionAttribute),X.bindBuffer(X.ARRAY_BUFFER,this.n64PositionsBuffer),X.bufferData(X.ARRAY_BUFFER,J,X.STATIC_DRAW),X.vertexAttribPointer(O.vertexPositionAttribute,4,X.FLOAT,!1,0,0),X.enableVertexAttribArray(O.vertexColorAttribute),X.bindBuffer(X.ARRAY_BUFFER,this.n64ColorsBuffer),X.bufferData(X.ARRAY_BUFFER,q,X.STATIC_DRAW),X.vertexAttribPointer(O.vertexColorAttribute,4,X.UNSIGNED_BYTE,!0,0,0),X.enableVertexAttribArray(O.texCoordAttribute),X.bindBuffer(X.ARRAY_BUFFER,this.n64UVBuffer),X.bufferData(X.ARRAY_BUFFER,Q,X.STATIC_DRAW),X.vertexAttribPointer(O.texCoordAttribute,2,X.FLOAT,!1,0,0),this.bindTexture(0,X.TEXTURE0,z,j,Z,O.uSamplerUniform0,O.uTexScaleUniform0,O.uTexOffsetUniform0),this.bindTexture(1,X.TEXTURE1,F,G,Z,O.uSamplerUniform1,O.uTexScaleUniform1,O.uTexOffsetUniform1),X.uniform1f(O.uAlphaThresholdUniform,U),X.uniform4f(O.uPrimColorUniform,(this.state.primColor>>>24&255)/255,(this.state.primColor>>>16&255)/255,(this.state.primColor>>>8&255)/255,(this.state.primColor>>>0&255)/255),X.uniform4f(O.uEnvColorUniform,(this.state.envColor>>>24&255)/255,(this.state.envColor>>>16&255)/255,(this.state.envColor>>>8&255)/255,(this.state.envColor>>>0&255)/255)}getCurrentN64Shader(){const J=this.state.combine.hi,q=this.state.combine.lo,Q=this.state.getCycleType(),Y=(this.state.getAlphaCompareType()&c6.G_AC_THRESHOLD)!=0,Z=this.state.getAntiAliasEnabled()&&this.state.getCoverageTimesAlpha();return RX(this.gl,J,q,Q,Y||Z)}lookupTexture(J){const q=this.state.tiles[J];if(q.line===0)return null;const Q=this.state.tmem.calculateCRC(q),Y=`${N(Q)}_${q.format}_${q.size}_${q.width}_${q.height}_${q.palette}`;if(this.textureCache.has(Y))return this.textureCache.get(Y);const Z=this.decodeTexture(q,this.state.getTextureLUTType(),Y);return this.textureCache.set(Y,Z),Z}decodeTexture(J,q,Q){const Y=this.gl,Z=new tQ(Y,J.width,J.height);if(!Z.$canvas[0].getContext)return null;this.$textureOutput.append(`${Q}: ${Z0.nameOf(J.format)}, ${p.nameOf(J.size)},${J.width}x${J.height}, <br>`);const K=Z.$canvas[0].getContext("2d"),X=K.createImageData(Z.nativeWidth,Z.nativeHeight);if(this.state.tmem.convertTexels(J,q,X))WW(X,J.width,J.height),K.putImageData(X,0,0),this.$textureOutput.append(Z.$canvas),this.$textureOutput.append("<br>");else{const z=`${Z0.nameOf(J.format)}/${p.nameOf(J.size)} is unhandled`;this.$textureOutput.append(z),this.hleHalt(z)}return Y.activeTexture(Y.TEXTURE0),Y.bindTexture(Y.TEXTURE_2D,Z.texture),Y.texImage2D(Y.TEXTURE_2D,0,Y.RGBA,Y.RGBA,Y.UNSIGNED_BYTE,Z.$canvas[0]),Y.generateMipmap(Y.TEXTURE_2D),Y.bindTexture(Y.TEXTURE_2D,null),Z}bindTexture(J,q,Q,Y,Z,K,X,W){const z=this.gl;if(z.activeTexture(q),!Y){z.bindTexture(z.TEXTURE_2D,null);return}let{left:F,top:j}=Q,G=1/Y.nativeWidth,P=1/Y.nativeHeight;if(Y.width===56&&Y.height===29)G*=0.5,P*=0.5;if(Z)G=1,P=1,F=0,j=0;if(G*=NW(Q.shiftS),P*=NW(Q.shiftT),z.bindTexture(z.TEXTURE_2D,Y.texture),z.uniform1i(K,J),z.uniform2f(X,G,P),z.uniform2f(W,F,j),this.state.getTextureFilterType()==w8.G_TF_POINT)z.texParameteri(z.TEXTURE_2D,z.TEXTURE_MAG_FILTER,z.NEAREST),z.texParameteri(z.TEXTURE_2D,z.TEXTURE_MIN_FILTER,z.NEAREST_MIPMAP_NEAREST);else z.texParameteri(z.TEXTURE_2D,z.TEXTURE_MAG_FILTER,z.LINEAR),z.texParameteri(z.TEXTURE_2D,z.TEXTURE_MIN_FILTER,z.LINEAR_MIPMAP_NEAREST);const L=Q.cmS===R6||Q.maskS===0,U=Q.cmT===R6||Q.maskT===0,O=Q.cmS===FJ,E=Q.cmT===FJ,w=L?z.CLAMP_TO_EDGE:O?z.MIRRORED_REPEAT:z.REPEAT,y=U?z.CLAMP_TO_EDGE:E?z.MIRRORED_REPEAT:z.REPEAT;z.texParameteri(z.TEXTURE_2D,z.TEXTURE_WRAP_S,w),z.texParameteri(z.TEXTURE_2D,z.TEXTURE_WRAP_T,y)}setGLBlendMode(){const J=this.gl,q=this.state.getCoverageTimesAlpha(),Q=this.state.getAlphaCoverageSelect(),Y=this.state.getCycleType();if(Y==K0.G_CYC_FILL||Y==K0.G_CYC_COPY){J.disable(J.BLEND);return}const Z=this.state.rdpOtherModeL>>PQ,K=(Y===K0.G_CYC_2CYCLE?Z:Z>>>2)&13107;let X=$W;switch(K){case 0:case 770:X=eQ;break;case 16:case 17:if(!Q||q)X=zW;break;case 272:X=eQ;break;case 784:case 4880:X=HW;break;case 12560:X=FW;break}let W=!1;switch(X){case eQ:J.disable(J.BLEND);break;case zW:J.blendFunc(J.SRC_ALPHA,J.ONE_MINUS_SRC_ALPHA),J.blendEquation(J.FUNC_ADD),J.enable(J.BLEND);break;case HW:J.blendFunc(J.ZERO,J.ONE_MINUS_SRC_ALPHA),J.blendEquation(J.FUNC_ADD),J.enable(J.BLEND);break;case FW:W=!0,J.disable(J.BLEND);break;case $W:W=!0,J.disable(J.BLEND);break}if(W)this.logUnhandledBlendMode(K,Q,q)}logUnhandledBlendMode(J,q,Q){if(jW.get(J))return;jW.set(J,!0),n64js.warn(`Unhandled blend mode: ${r(J)} = ${dJ(J)}, alphaCvgSel ${q}, cvgXAlpha ${Q}`)}}class GW{constructor(){this.initDimensions(320,240)}initDimensions(J,q){this.viWidth=J,this.viHeight=q,this.n64FramebufferToDevice=new iQ(new N0(2/J,-2/q),new N0(-1,1));const Q=J/2,Y=q/2,Z=512,K=511,X=new c0(Q,-Y,Z,1),W=new c0(Q,+Y,K,0);this.viTransform=new GJ(X,W)}convertN64ToDisplay(J){return this.n64FramebufferToDevice.transform(J)}}function VW(J){B0.initUI();const q=J[0];if(rH(q),!U6)return;r0=new JY(U6,I0,640,480),r0.hleHalt=CW,B0.renderer=r0}function UW(){if(r0)r0.reset()}var rH=function(J){if(U6)return;try{U6=J.getContext("webgl")||J.getContext("experimental-webgl")}catch(q){}if(!U6)alert("Unable to initialize WebGL. Your browser may not support it.")};function MW(){return B0.running}function OW(){return B0.requested}function AW(){B0.toggle()}function hW(){B0.debugDisplayList()}function EW(J){B0.onNewTask(J),wW(J,null,-1)}function x9(){n64js.onPresent();const J=n64js.hardware(),q=J.viRegDevice;if(J.timeline.addEvent(`Present ${N(q.dramAddrReg)}`),LW!==0){r0.copyBackBufferToFrontBuffer();return}kW(q);const Q=q.renderBackBuffer();if(!Q)return;r0.copyPixelsToFrontBuffer(Q,q.screenWidth,q.screenHeight,q.bitDepth)}var wW=function(J,q,Q){if(LW++,!U6)return;const Y=n64js.hardware(),Z=Y.cachedMemDevice.mem.dataView;I0.reset(Z,J.dataPtr);let K=PW(J,Z),X=K.buildCommandTable();if(K.onLoadUcode((W,z,F,j)=>{return J.loadUcode(W,z,F,j),K=PW(J,Z),X=K.buildCommandTable(),K}),kW(Y.viRegDevice),r0.newFrame(),B0.running)r0.debugClear();if(q){B0.currentOp=0;while(I0.nextCommand())q.begin(I0.cmd0,I0.cmd1,I0.dlistStack.length),X[I0.cmd0>>>24](I0.cmd0,I0.cmd1,q),q.end(),B0.currentOp++}else{B0.currentOp=0;while(I0.nextCommand())if(X[I0.cmd0>>>24](I0.cmd0,I0.cmd1),B0.postOp(Q))break}U6.bindFramebuffer(U6.FRAMEBUFFER,null)},kW=function(J){const q=J.computeDimensions();if(!q)return;r0.nativeTransform.initDimensions(q.srcWidth,q.srcHeight);const Q=document.getElementById("display");Q.width=q.screenWidth*W6.canvasScale,Q.height=q.screenHeight*W6.canvasScale},PW=function(J,q){const Q=JW(J,I0,q);return Q.debugController=B0,Q.hleHalt=CW,Q.gl=U6,Q.renderer=r0,Q},CW=function(J){if(B0.running)return;n64js.ui().displayWarning(J),n64js.breakEmulationForDisplayListDebug(),B0.halt()};window.n64js=window.n64js||{};var LW=0,U6=null,r0,I0=new sQ,B0=new yQ(I0,wW);var XF=function(J){return J<<YF},WF=function(J){return J<<Y$},$F=function(J){return J<<Z$},s0=function(J){const q=J&Zq,Q=J&zF;if(q==Zq){if(Q==0)return J&s6?O6:M6;return J&HF?m0:A6}if(q==0){if(Q!=0)return i0;return J&s6?WY:XY}return W$},H6=function(J){const q=J&Kq,Q=J&jF;if(q==Kq){if(Q==0)return J&i6?O6:M6;return J&NF?m0:A6}if(q==0){if(Q!=0)return i0;return J&i6?WY:XY}return W$},Yq=function(J){return J==m0||J==A6},d6=function(J){return J==XY||J==WY},F6=function(J){return J==M6||J==O6},KY=function(J,q,Q){return J[q*2+(Q?1:0)]},$$=function(J){if(J.length!=8)throw"Case table is unexpected size.";return J},aW=function(J,q){return J[q]},$Y=function(J){if(J.length!=Xq)throw"Case table is unexpected size.";return J},tW=function(J,q,Q){return J[q*Xq+Q]},Wq=function(J){if(J.length!=Xq*Xq)throw"Case table is unexpected size.";return J},DW=0,yW=1,IW=2,BW=3,RW=4,bW=5,TW=6,_W=7,p9=8,m9=9,n9=10,o9=11,c9=12,l9=13,d9=14,a9=15,r9=32,s9=33,i9=36,t9=37,sH=0,iH=1,tH=2,eH=3;var JF=128,qF=256;var SW=131072,vW=8388608,QF=16777216,e9=3,G0=1,Jq=2,PJ=4,fW=8,z6=16,YF=2,Y$=7,Z$=12;var ZF=3968,uW=258048,KF=25427967,s6=2147483648,Zq=2139095040,zF=8388607,HF=1<<22,qq=2143289343,qY=0,QY=s6,K$=8388608,FF=s6|K$,gW=Zq,xW=s6|Zq,i6=0x8000_0000_0000_0000n,Kq=0x7ff0_0000_0000_0000n,jF=0x000f_ffff_ffff_ffffn,NF=1n<<51n,Qq=0x7ff7_ffff_ffff_ffffn,YY=0n,ZY=i6,X$=0x0010_0000_0000_0000n,GF=i6|X$,pW=Kq,mW=i6|Kq,nW=Number.MAX_SAFE_INTEGER,oW=Number.MIN_SAFE_INTEGER,cW=2147483647,lW=-2147483648,W$=0,XY=1,WY=2,M6=3,O6=4,m0=5,A6=6,i0=7,Xq=8,dW=$$([QY,qY,QY,qY,QY,K$,FF,qY]),PF=$$([ZY,YY,ZY,YY,ZY,X$,GF,YY]),I=0,h=1,j6=2,e=3,i=4,P0=5,p0=6,B8=7,a6=8,r6=9,rW=$Y([B8,B8,B8,B8,I,I,h,h]),sW=$Y([a6,a6,a6,a6,a6,I,h,h]),iW=$Y([r6,r6,r6,r6,r6,I,h,h]),eW=Wq([e,e,e,e,e,I,h,h,e,e,e,e,e,I,h,h,e,e,e,e,e,I,h,h,e,e,e,e,I,I,h,h,e,e,e,I,e,I,h,h,I,I,I,I,I,I,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h]),J$=Wq([i,i,i,i,i,I,h,h,i,i,i,i,i,I,h,h,i,i,i,i,i,I,h,h,i,i,i,i,i,I,h,h,i,i,i,i,i,I,h,h,I,I,I,I,I,I,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h]),q$=Wq([P0,P0,P0,P0,P0,I,h,h,P0,P0,P0,I,I,I,h,h,P0,P0,P0,I,I,I,h,h,P0,I,I,P0,P0,I,h,h,P0,I,I,P0,P0,I,h,h,I,I,I,I,I,I,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h]),Q$=Wq([p0,j6,j6,p0,p0,I,h,h,p0,I,j6,p0,p0,I,h,h,p0,I,j6,p0,p0,I,h,h,p0,j6,j6,I,I,I,h,h,p0,j6,j6,I,I,I,h,h,I,I,I,I,I,I,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h,h]),l0=0,t0=1,e0=2,J6=3;class $q{constructor(J){this.hardware=J,this.control=new Uint32Array(32),this.mem=new ArrayBuffer(256),this.regF32=new Float32Array(this.mem),this.regF64=new Float64Array(this.mem),this.regS32=new Int32Array(this.mem),this.regU32=new Uint32Array(this.mem),this.regS64=new BigInt64Array(this.mem),this.regU64=new BigUint64Array(this.mem),this.regIdx32_cop=new Uint32Array(new ArrayBuffer(128)),this.regIdx32_d=new Uint32Array(new ArrayBuffer(128)),this.regIdx32_s=new Uint32Array(new ArrayBuffer(128)),this.regIdx32_t=new Uint32Array(new ArrayBuffer(128)),this.regIdx64_cop=new Uint32Array(new ArrayBuffer(128)),this.regIdx64_d=new Uint32Array(new ArrayBuffer(128)),this.regIdx64_s=new Uint32Array(new ArrayBuffer(128)),this.regIdx64_t=new Uint32Array(new ArrayBuffer(128)),this.tempBuf=new ArrayBuffer(8),this.tempF32=new Float32Array(this.tempBuf),this.tempF64=new Float64Array(this.tempBuf),this.tempU32=new Uint32Array(this.tempBuf),this.tempS32=new Int32Array(this.tempBuf),this.tempU64=new BigUint64Array(this.tempBuf),this.tempS64=new BigInt64Array(this.tempBuf),this._fullMode=!0,this.fullMode=!0,this.reset()}reset(){for(var J=0;J<32;++J)this.control[J]=0,this.regS64[J]=0n;this.control[0]=2560,this.fullMode=!0}set fullMode(J){if(this._fullMode=J,this._fullMode)for(let q=0;q<32;q++)this.regIdx32_cop[q]=q*2,this.regIdx32_d[q]=q*2,this.regIdx32_s[q]=q*2,this.regIdx32_t[q]=q*2,this.regIdx64_cop[q]=q,this.regIdx64_d[q]=q,this.regIdx64_s[q]=q,this.regIdx64_t[q]=q;else for(let q=0;q<32;q++){const Q=q&~1;this.regIdx32_cop[q]=Q*2+(q&1),this.regIdx32_d[q]=q*2,this.regIdx32_s[q]=Q*2,this.regIdx32_t[q]=q*2,this.regIdx64_cop[q]=Q,this.regIdx64_d[q]=q,this.regIdx64_s[q]=Q,this.regIdx64_t[q]=q}}execSInstr(J,q,Q,Y){if(J<48){switch(J){case DW:this.ADD_S(q,Q,Y);return;case yW:this.SUB_S(q,Q,Y);return;case IW:this.MUL_S(q,Q,Y);return;case BW:this.DIV_S(q,Q,Y);return;case RW:this.SQRT_S(q,Q);return;case bW:this.ABS_S(q,Q);return;case TW:this.MOV_S(q,Q);return;case _W:this.NEG_S(q,Q);return;case p9:this.ConvertSToL(q,Q,l0);return;case m9:this.ConvertSToL(q,Q,t0);return;case n9:this.ConvertSToL(q,Q,e0);return;case o9:this.ConvertSToL(q,Q,J6);return;case c9:this.ConvertSToW(q,Q,l0);return;case l9:this.ConvertSToW(q,Q,t0);return;case d9:this.ConvertSToW(q,Q,e0);return;case a9:this.ConvertSToW(q,Q,J6);return;case r9:this.raiseUnimplemented();return;case s9:this.CVT_D_S(q,Q);return;case i9:this.ConvertSToW(q,Q,this.roundingMode);return;case t9:this.ConvertSToL(q,Q,this.roundingMode);return}a(!1,"unhandled S instruction"),this.raiseUnimplemented()}else this.handleFloatCompareSingle(J,Q,Y)}execDInstr(J,q,Q,Y){if(J<48){switch(J){case DW:this.ADD_D(q,Q,Y);return;case yW:this.SUB_D(q,Q,Y);return;case IW:this.MUL_D(q,Q,Y);return;case BW:this.DIV_D(q,Q,Y);return;case RW:this.SQRT_D(q,Q);return;case bW:this.ABS_D(q,Q);return;case TW:this.MOV_D(q,Q);return;case _W:this.NEG_D(q,Q);return;case p9:this.ConvertDToL(q,Q,l0);return;case m9:this.ConvertDToL(q,Q,t0);return;case n9:this.ConvertDToL(q,Q,e0);return;case o9:this.ConvertDToL(q,Q,J6);return;case c9:this.ConvertDToW(q,Q,l0);return;case l9:this.ConvertDToW(q,Q,t0);return;case d9:this.ConvertDToW(q,Q,e0);return;case a9:this.ConvertDToW(q,Q,J6);return;case r9:this.CVT_S_D(q,Q);return;case s9:this.raiseUnimplemented();return;case i9:this.ConvertDToW(q,Q,this.roundingMode);return;case t9:this.ConvertDToL(q,Q,this.roundingMode);return}a(!1,"unhandled D instruction"),this.raiseUnimplemented()}else this.handleFloatCompareDouble(J,Q,Y)}execWInstr(J,q,Q,Y){switch(J){case p9:this.raiseUnimplemented();return;case m9:this.raiseUnimplemented();return;case n9:this.raiseUnimplemented();return;case o9:this.raiseUnimplemented();return;case c9:this.raiseUnimplemented();return;case l9:this.raiseUnimplemented();return;case d9:this.raiseUnimplemented();return;case a9:this.raiseUnimplemented();return;case r9:this.CVT_S_W(q,Q);return;case s9:this.CVT_D_W(q,Q);return;case i9:this.raiseUnimplemented();return;case t9:this.raiseUnimplemented();return}a(!1,"unhandled W instruction"),this.raiseUnimplemented()}execLInstr(J,q,Q,Y){switch(J){case p9:this.raiseUnimplemented();return;case m9:this.raiseUnimplemented();return;case n9:this.raiseUnimplemented();return;case o9:this.raiseUnimplemented();return;case c9:this.raiseUnimplemented();return;case l9:this.raiseUnimplemented();return;case d9:this.raiseUnimplemented();return;case a9:this.raiseUnimplemented();return;case r9:this.CVT_S_L(q,Q);return;case s9:this.CVT_D_L(q,Q);return;case i9:this.raiseUnimplemented();return;case t9:this.raiseUnimplemented();return}a(!1,"unhandled L instruction"),this.raiseUnimplemented()}handleFloatCompareSingle(J,q,Q){const Y=s0(this.loadU32(this.fsRegIdx32(q))),Z=s0(this.loadU32(this.ftRegIdx32(Q)));let K=!1;if(Yq(Y)||Yq(Z)){if(J&8||Y==m0||Z==m0){if(this.raiseException(z6))return}if(J&1)K=!0}else{const X=this.loadF32(this.fsRegIdx32(q)),W=this.loadF32(this.ftRegIdx32(Q));if(J&4)K|=X<W;if(J&2)K|=X==W}this.setCondition(K)}handleFloatCompareDouble(J,q,Q){const Y=H6(this.loadU64(this.fsRegIdx64(q))),Z=H6(this.loadU64(this.ftRegIdx64(Q)));let K=!1;if(Yq(Y)||Yq(Z)){if(J&8||Y==m0||Z==m0){if(this.raiseException(z6))return}if(J&1)K=!0}else{const X=this.loadF64(this.fsRegIdx64(q)),W=this.loadF64(this.ftRegIdx64(Q));if(J&4)K|=X<W;if(J&2)K|=X==W}this.setCondition(K)}DCFC1(J,q){this.clearCause(),this.raiseUnimplemented()}DCTC1(J,q){this.clearCause(),this.raiseUnimplemented()}MOV_S(J,q){this.store64(this.fdRegIdx64(J),this.loadU64(this.fsRegIdx64(q)))}SQRT_S(J,q){this.f32UnaryOp(J,q,rW)}ABS_S(J,q){this.f32UnaryOp(J,q,sW)}NEG_S(J,q){this.f32UnaryOp(J,q,iW)}ADD_S(J,q,Q){this.f32BinaryOp(J,q,Q,eW)}SUB_S(J,q,Q){this.f32BinaryOp(J,q,Q,J$)}MUL_S(J,q,Q){this.f32BinaryOp(J,q,Q,q$)}DIV_S(J,q,Q){this.f32BinaryOp(J,q,Q,Q$)}MOV_D(J,q){this.store64(this.fdRegIdx64(J),this.loadU64(this.fsRegIdx64(q)))}SQRT_D(J,q){this.f64UnaryOp(J,q,rW)}ABS_D(J,q){this.f64UnaryOp(J,q,sW)}NEG_D(J,q){this.f64UnaryOp(J,q,iW)}ADD_D(J,q,Q){this.f64BinaryOp(J,q,Q,eW)}SUB_D(J,q,Q){this.f64BinaryOp(J,q,Q,J$)}MUL_D(J,q,Q){this.f64BinaryOp(J,q,Q,q$)}DIV_D(J,q,Q){this.f64BinaryOp(J,q,Q,Q$)}CVT_S_D(J,q){this.clearCause();const Q=H6(this.loadU64(this.fsRegIdx64(q)));let Y=0;switch(Q){case A6:case i0:this.raiseUnimplemented();return;case m0:Y|=z6,this.tempU32[0]=qq;break;case M6:this.tempU32[0]=gW;break;case O6:this.tempU32[0]=xW;break;default:const Z=this.loadF64(this.fsRegIdx64(q));this.tempF32[0]=Z;const K=s0(this.tempU32[0]);if(Z!=this.tempF32[0])Y|=G0;if((K==i0||d6(K))&&Z!=0)Y|=G0|Jq,this.tempU32[0]=KY(dW,this.control[31]&e9,Z>0);if(!isFinite(this.tempF32[0]))Y|=PJ;break}if(this.raiseException(Y))return;this.store32ZeroExtend(this.fdRegIdx32(J),this.tempU32[0])}CVT_S_W(J,q){this.clearCause();const Q=this.loadS32(this.fsRegIdx32(q));this.tempF32[0]=Q;let Y=0;if(Q!=this.tempF32[0])Y|=G0;if(this.raiseException(Y))return;this.store32ZeroExtend(this.fdRegIdx32(J),this.tempU32[0])}CVT_S_L(J,q){this.clearCause();const Q=this.loadS64(this.fsRegIdx64(q));if(Q>=1n<<55n||Q<-(1n<<55n)){this.raiseUnimplemented();return}this.tempF32[0]=Number(Q);let Y=0;if(Q!=this.tempF32[0])Y|=G0;if(this.raiseException(Y))return;this.store32ZeroExtend(this.fdRegIdx32(J),this.tempU32[0])}f32UnaryOp(J,q,Q){this.clearCause();const Y=this.loadF32(this.fsRegIdx32(q)),Z=s0(this.loadU32(this.fsRegIdx32(q))),K=aW(Q,Z);let X;switch(K){case h:this.raiseUnimplemented();return;case I:if(!this.raiseException(z6))this.store32ZeroExtend(this.fdRegIdx32(J),qq);return;case B8:if(Y<0){if(!this.raiseException(z6))this.store32ZeroExtend(this.fdRegIdx32(J),qq);return}X=Math.sqrt(Y);break;case a6:X=Math.abs(Y);break;case r6:X=-Y;break;default:throw`unhandled op case: ${K}`}this.tempF32[0]=X;const W=s0(this.tempU32[0]);let z=0;if(X!=this.tempF32[0])z|=G0;if(F6(W)&&!F6(Z))z|=G0|PJ;if(!this.raiseException(z))this.store32ZeroExtend(this.fdRegIdx32(J),this.tempU32[0])}f32BinaryOp(J,q,Q,Y){this.clearCause();const Z=this.loadF32(this.fsRegIdx32(q)),K=this.loadF32(this.ftRegIdx32(Q)),X=this.loadU32(this.fsRegIdx32(q)),W=this.loadU32(this.ftRegIdx32(Q)),z=s0(X),F=s0(W),j=tW(Y,z,F);let G;switch(j){case h:this.raiseUnimplemented();return;case I:if(!this.raiseException(z6))this.store32ZeroExtend(this.fdRegIdx32(J),qq);return;case j6:if(!this.raiseException(fW)){const U=(X&s6)==(W&s6);this.store32ZeroExtend(this.fdRegIdx32(J),U?gW:xW)}return;case e:G=Z+K;break;case i:G=Z-K;break;case P0:G=Z*K;break;case p0:G=Z/K;break;default:throw`unhandled op case: ${j}`}this.tempF32[0]=G;const P=s0(this.tempU32[0]);let L=0;if(G!=this.tempF32[0])L|=G0;if(j==e||j==i){if(!d6(F)&&G==Z||!d6(z)&&G==K)L|=G0}if(F6(P)&&!F6(z)&&!F6(F))L|=G0|PJ;if((P==i0||d6(P))&&G!=0)L|=G0|Jq,this.tempU32[0]=KY(dW,this.control[31]&e9,G>0);if(!this.raiseException(L))this.store32ZeroExtend(this.fdRegIdx32(J),this.tempU32[0])}CVT_D_S(J,q){this.clearCause();let Q=0;switch(s0(this.loadU32(this.fsRegIdx32(q)))){case A6:case i0:this.raiseUnimplemented();return;case m0:Q|=z6,this.tempU64[0]=Qq;break;case M6:this.tempU64[0]=pW;break;case O6:this.tempU64[0]=mW;break;default:const Z=this.loadF32(this.fsRegIdx32(q));this.tempF64[0]=Z;break}if(this.raiseException(Q))return;this.store64(this.fdRegIdx64(J),this.tempU64[0])}CVT_D_W(J,q){this.clearCause(),this.tempF64[0]=this.loadS32(this.fsRegIdx32(q)),this.store64(this.fdRegIdx64(J),this.tempU64[0])}CVT_D_L(J,q){this.clearCause();const Q=this.loadS64(this.fsRegIdx64(q));if(Q>=1n<<55n||Q<-(1n<<55n)){this.raiseUnimplemented();return}let Y=0;if(this.tempF64[0]=Number(Q),this.raiseException(Y))return;this.store64(this.fdRegIdx64(J),this.tempU64[0])}f64UnaryOp(J,q,Q){this.clearCause();const Y=this.loadF64(this.fsRegIdx64(q)),Z=H6(this.loadU64(this.fsRegIdx64(q))),K=aW(Q,Z);let X;switch(K){case h:this.raiseUnimplemented();return;case I:if(!this.raiseException(z6))this.store64(this.fdRegIdx64(J),Qq);return;case B8:if(Y<0){if(!this.raiseException(z6))this.store64(this.fdRegIdx64(J),Qq);return}X=Math.sqrt(Y);break;case a6:X=Math.abs(Y);break;case r6:X=-Y;break;default:throw`unhandled op case: ${K}`}this.tempF64[0]=X;const W=H6(this.tempU64[0]);let z=0;if(X!=this.tempF64[0])z|=G0;if(F6(W)&&!F6(Z))z|=G0|PJ;if(!this.raiseException(z))this.store64(this.fdRegIdx64(J),this.tempU64[0])}f64BinaryOp(J,q,Q,Y){this.clearCause();const Z=this.loadF64(this.fsRegIdx64(q)),K=this.loadF64(this.ftRegIdx64(Q)),X=this.loadU64(this.fsRegIdx64(q)),W=this.loadU64(this.ftRegIdx64(Q)),z=H6(X),F=H6(W),j=tW(Y,z,F);let G;switch(j){case h:this.raiseUnimplemented();return;case I:if(!this.raiseException(z6))this.store64(this.fdRegIdx64(J),Qq);return;case j6:if(!this.raiseException(fW)){const U=(X&i6)==(W&i6);this.store64(this.fdRegIdx64(J),U?pW:mW)}return;case e:G=Z+K;break;case i:G=Z-K;break;case P0:G=Z*K;break;case p0:G=Z/K;break;default:throw`unhandled op case: ${j}`}this.tempF64[0]=G;const P=H6(this.tempU64[0]);let L=0;if(j==e||j==i){if(!d6(F)&&G==Z||!d6(z)&&G==K)L|=G0}if(F6(P)&&!F6(z)&&!F6(F))L|=G0|PJ;if((P==i0||d6(P))&&G!=0)L|=G0|Jq,this.tempU64[0]=KY(PF,this.control[31]&e9,G>0);if(!this.raiseException(L))this.store64(this.fdRegIdx64(J),this.tempU64[0])}ConvertSToL(J,q,Q){this.clearCause();let Y=0;switch(s0(this.loadU32(this.fsRegIdx32(q)))){case A6:case m0:case i0:case M6:case O6:this.raiseUnimplemented();return;default:const K=this.loadF32(this.fsRegIdx32(q)),X=this.convertUsingMode(K,Q);if(X>nW||X<oW){this.raiseUnimplemented();return}if(this.tempS64[0]=BigInt(X),K!=this.tempS64[0])Y|=G0;break}if(this.raiseException(Y))return;this.store64(this.fdRegIdx64(J),this.tempS64[0])}ConvertDToL(J,q,Q){this.clearCause();const Y=H6(this.loadU64(this.fsRegIdx64(q)));let Z=0;switch(Y){case A6:case m0:case i0:case M6:case O6:this.raiseUnimplemented();return;default:const K=this.loadF64(this.fsRegIdx64(q)),X=this.convertUsingMode(K,Q);if(X>nW||X<oW){this.raiseUnimplemented();return}if(this.tempS64[0]=BigInt(X),K!=this.tempS64[0])Z|=G0;break}if(this.raiseException(Z))return;this.store64(this.fdRegIdx64(J),this.tempS64[0])}ConvertSToW(J,q,Q){this.clearCause();const Y=s0(this.loadU32(this.fsRegIdx32(q)));let Z=0;switch(Y){case A6:case m0:case i0:case M6:case O6:this.raiseUnimplemented();return;default:const K=this.loadF32(this.fsRegIdx32(q)),X=this.convertUsingMode(K,Q);if(X>cW||X<lW){this.raiseUnimplemented();return}if(this.tempS32[0]=X,K!=this.tempS32[0])Z|=G0;break}if(this.raiseException(Z))return;this.store32ZeroExtend(this.fdRegIdx32(J),this.tempU32[0])}ConvertDToW(J,q,Q){this.clearCause();const Y=H6(this.loadU64(this.fsRegIdx64(q)));let Z=0;switch(Y){case A6:case m0:case i0:case M6:case O6:this.raiseUnimplemented();return;default:const K=this.loadF64(this.fsRegIdx64(q)),X=this.convertUsingMode(K,Q);if(X>cW||X<lW){this.raiseUnimplemented();return}if(this.tempS32[0]=X,K!=this.tempS32[0])Z|=G0;break}if(this.raiseException(Z))return;this.store32ZeroExtend(this.fdRegIdx32(J),this.tempU32[0])}get roundingMode(){switch(this.control[31]&e9){case sH:return l0;case iH:return t0;case tH:return e0;case eH:return J6}return a(!1,"unknown rounding mode"),l0}convertUsingMode(J,q){switch(q){case l0:return this.round(J);case t0:return this.trunc(J);case e0:return Math.ceil(J);case J6:return Math.floor(J)}a(!1,"unknown rounding mode")}round(J){const q=Math.floor(J);if(J-q==0.5){const Y=Math.ceil(J);if(J<0)return Y%2!=0?q:Y;return q%2!=0?Y:q}return Math.round(J)}trunc(J){if(J<0)return Math.ceil(J);return Math.floor(J)}setCondition(J){if(J)this.control[31]|=vW;else this.control[31]&=~vW}get flushSubnormals(){return(this.control[31]&QF)!=0}clearCause(){this.control[31]&=~uW}raiseException(J){if(!J)return!1;if(J&Jq){if((this.control[31]&(qF|JF))!=0||!this.flushSubnormals)return this.raiseUnimplemented()}const q=WF(J),Q=$F(J),Y=XF(J);return this.setStatusBits(q,Q,Y)}raiseUnimplemented(J){return this.control[31]|=SW,this.hardware.cpu0.raiseFPE(),!0}setStatusBits(J,q,Q){if(this.control[31]&J)return this.control[31]|=q,this.hardware.cpu0.raiseFPE(),!0;return this.control[31]|=Q|q,!1}setStatus(J){this.control[31]=J&KF;const q=(J&ZF)>>Y$,Q=(J&uW)>>Z$;if(q&Q||J&SW)return this.hardware.cpu0.raiseFPE(),!0;return!1}copRegIdx32(J){return this.regIdx32_cop[J]}fdRegIdx32(J){return this.regIdx32_d[J]}fsRegIdx32(J){return this.regIdx32_s[J]}ftRegIdx32(J){return this.regIdx32_t[J]}copRegIdx64(J){return this.regIdx64_cop[J]}fdRegIdx64(J){return this.regIdx64_d[J]}fsRegIdx64(J){return this.regIdx64_s[J]}ftRegIdx64(J){return this.regIdx64_t[J]}store64(J,q){this.regU64[J]=q}store32ZeroExtend(J,q){this.regU32[J]=q|0,this.regU32[J+1]=0}store32(J,q){this.regU32[J]=q|0}loadS32(J){return this.regS32[J]}loadU32(J){return this.regU32[J]}loadF32(J){return this.regF32[J]}loadU64(J){return this.regU64[J]}loadF64(J){return this.regF64[J]}loadS64(J){return this.regS64[J]}dump(){let J="Regs: ";for(let q=0;q<6;+q++)J+=N(this.regS32[q])+", ";M(J),M(`float32: [${this.regF32[0]}, ${this.regF32[1]}, ${this.regF32[2]}, ${this.regF32[3]}, ${this.regF32[4]}, ${this.regF32[5]}, ...]`),M(`float64: [${this.regF64[0]}, ${this.regF64[1]}, ...]`),console.log("")}}function z$(J,q){b0=J.memMap.getMemoryHandler.bind(J.memMap),d0=J.cachedMemDevice.mem.dataView,h6=q}function LF(J){if(J&7)h6.unalignedLoad(J);return b0(J).readU64(J)}function VF(J){if(J&1)h6.unalignedLoad(J);return b0(J).readU16(J)}function UF(J){if(J&3)h6.unalignedLoad(J);return b0(J).readU32(J)}function MF(J){return b0(J).readU8(J)}function zY(J){if(J&3)h6.unalignedLoad(J);return b0(J).readS32(J)}function OF(J){if(J&1)h6.unalignedLoad(J);return b0(J).readS16(J)}function AF(J){return b0(J).readS8(J)}function hF(J,q){if(J&7)h6.unalignedStore(J);b0(J).write64(J,q)}function EF(J,q){if(J&3)h6.unalignedStore(J);b0(J).write32(J,q)}function wF(J,q){if(J&1)h6.unalignedStore(J);b0(J).write16(J,q)}function kF(J,q){b0(J).write8(J,q)}function zq(J,q,Q){b0(J).write32masked(J,q,Q)}function Hq(J,q,Q){b0(J).write64masked(J,q,Q)}function HY(J){if(J<-2139095040){const q=J+2147483648|0;return d0.getUint8(q,!1)}return MF(J>>>0)}function FY(J){if(J<-2139095040){const q=J+2147483648|0;return d0.getInt8(q,!1)}return AF(J>>>0)}function jY(J){if((J&1)==0&&J<-2139095040){const q=J+2147483648|0;return d0.getUint16(q,!1)}return VF(J>>>0)}function NY(J){if((J&1)==0&&J<-2139095040){const q=J+2147483648|0;return d0.getInt16(q,!1)}return OF(J>>>0)}function LJ(J){if((J&3)==0&&J<-2139095040){const q=J+2147483648|0;return d0.getUint32(q,!1)}return UF(J>>>0)}function VJ(J){if((J&3)==0&&J<-2139095040){const q=J+2147483648|0;return d0.getInt32(q,!1)}return zY(J>>>0)}function t6(J){if((J&7)==0&&J<-2139095040){const q=J+2147483648|0;return d0.getBigUint64(q,!1)}return LF(J>>>0)}function GY(J,q){if(J<-2139095040){const Q=J+2147483648|0;d0.setUint8(Q,q,!1);return}kF(J>>>0,q)}function PY(J,q){if((J&1)==0&&J<-2139095040){const Q=J+2147483648|0;d0.setUint16(Q,q,!1);return}wF(J>>>0,q)}function UJ(J,q){if((J&3)==0&&J<-2139095040){const Q=J+2147483648|0;d0.setUint32(Q,q,!1);return}EF(J>>>0,q)}function MJ(J,q){if((J&7)==0&&J<-2139095040){const Q=J+2147483648|0;d0.setBigUint64(Q,q,!1);return}hF(J>>>0,q)}var b0,d0,h6;class LY{constructor(){this.cyclesToFirstEvent=0,this.firstEvent=null}reset(){this.cyclesToFirstEvent=0,this.firstEvent=null}nextEventCountdown(){return this.cyclesToFirstEvent}incrementCount(J){this.cyclesToFirstEvent-=J;while(this.cyclesToFirstEvent<=0){const q=this.firstEvent;if(!q)break;this.unlink(q),q.handler()}}unlink(J){if(J.prev)J.prev.cyclesToNextEvent=J.next?J.prev.cyclesToNextEvent+J.cyclesToNextEvent:0,J.prev.next=J.next;else this.cyclesToFirstEvent=J.next?this.cyclesToFirstEvent+J.cyclesToNextEvent:0,this.firstEvent=J.next;if(J.next)J.next.prev=J.prev;J.prev=null,J.next=null}insertAfter(J,q,Q,Y){const Z=J?J.next:this.firstEvent;if(Q.cyclesToNextEvent=Z?q-Y:0,a(Q.cyclesToNextEvent>=0,"cyclesToNextEvent must be positive or zero"),Q.next=Z,Q.prev=J,Z)Z.prev=Q;if(J)J.cyclesToNextEvent=Y,J.next=Q;else this.cyclesToFirstEvent=Y,this.firstEvent=Q}skipToNextEvent(J){if(!this.firstEvent||this.cyclesToFirstEvent<J)return 0;const q=this.cyclesToFirstEvent-J;return this.cyclesToFirstEvent=J,q}addEvent(J,q,Q){a(!this.hasEvent(J),`Already has event of type ${J}`),a(q>0,"cycles must be positive");const Y=new H$(J,Q);let Z=null,K=this.cyclesToFirstEvent;for(let X=this.firstEvent;X;X=X.next){if(q<=K){this.insertAfter(Z,K,Y,q);return}q-=K,K=X.cyclesToNextEvent,Z=X}this.insertAfter(Z,K,Y,q)}removeEvent(J){let q=this.cyclesToFirstEvent;for(let Q=this.firstEvent;Q;Q=Q.next){if(Q.type==J)return this.unlink(Q),q;q+=Q.cyclesToNextEvent}return-1}getEvent(J){for(let q=this.firstEvent;q;q=q.next)if(q.type==J)return q;return null}getCyclesUntilEvent(J){let q=this.cyclesToFirstEvent;for(let Q=this.firstEvent;Q;Q=Q.next){if(Q.type==J)return q;q+=Q.cyclesToNextEvent}return-1}hasEvent(J){return Boolean(this.getEvent(J))}}class H${constructor(J,q){this.type=J,this.cyclesToNextEvent=0,this.handler=q,this.prev=null,this.next=null}getName(){return this.type}}var R8=!0,e6=!1;function O$(J){J.needsDelayCheck=J.fragment.needsDelayCheck,J.isTrivial=!1;let q="";if(F$)q=T0(`
|
|
if (c.pc != ${N(J.pc)}) {
|
|
throw 'expected pc ${N(J.pc)}, got ' + c.pc.toString(16);
|
|
}
|
|
`);let Q=q+CN(J);if(J.dump)console.log(Q);if(!J.isTrivial&&J.delayedPCUpdate!==0)J.fragment.bodyCode+=`// Applying delayed pc\nc.pc = ${N(J.delayedPCUpdate)};\n`,J.delayedPCUpdate=0;if(J.fragment.needsDelayCheck=J.needsDelayCheck,J.fragment.bailedOut|=J.bailOut,n64js.getSyncFlow())Q=`if (!n64js.checkSyncState(sync, ${N(J.pc)})) { return ${J.fragment.opsCompiled}; }\n${Q}`;const Z=fJ(J.pc,J.instruction,!1),K=IF(Q," ");J.fragment.bodyCode+=`// ${Z.disassembly}
|
|
{
|
|
${K}
|
|
}
|
|
|
|
`}var IF=function(J,q){return T0(J).split("\n").filter((X)=>X!="").map((X)=>q+X).join("\n")},T0=function(J){J=J.replace(/^\n/,"");const q=J.match(/^\s+/);if(!q)return J;const Q=q[0];return q?J.replace(new RegExp("^"+Q,"gm"),""):J},J8=function(J){if(!J.startsWith("\n"))J="\n"+J;if(!J.endsWith("\n"))J+="\n";return J},A$=function(J,q,Q){let Y="";if(Y+=q.genAssert(`c.pc === ${N(q.pc)}`,"pc mismatch"),q.needsDelayCheck)Y+=`if (c.delayPC) { c.nextPC = c.delayPC; c.delayPC = 0; } else { c.nextPC = ${N(q.pc+4)}; }\n`,Y+=J8(J),Y+="c.pc = c.nextPC;\n";else if(Q)Y+=q.genAssert("c.delayPC === 0","delay pc should be zero"),Y+=`c.nextPC = ${N(q.pc+4)};\n`,Y+=J8(J),Y+="c.pc = c.nextPC;\n";else Y+=q.genAssert("c.delayPC === 0","delay pc should be zero"),Y+=J8(J),Y+=`c.pc = ${N(q.pc+4)};\n`;return Y},T=function(J,q){let Q="";if(Q+=q.genAssert(`c.pc === ${N(q.pc)}`,"pc mismatch"),q.needsDelayCheck)Q+=`c.nextPC = c.delayPC || ${N(q.pc+4)};\n`;else Q+=q.genAssert("c.delayPC === 0","delay pc should be zero"),Q+=`c.nextPC = ${N(q.pc+4)};\n`;if(Q+="c.branchTarget = 0;\n",Q+=J8(J),Q+="c.pc = c.nextPC;\n",Q+="c.delayPC = c.branchTarget;\n",q.needsDelayCheck=!0,e6)Q+="c.incrementCount(1);\n";if(q.bailOut)Q+=`return ${q.fragment.opsCompiled};\n`;else Q+=`if (c.stuffToDo) { return ${q.fragment.opsCompiled}; }\n`,Q+=`if (c.pc !== ${N(q.postPC)}) { return ${q.fragment.opsCompiled}; }\n`;return Q},t=function(J,q){let Q="";if(Q+=A$(J,q,!0),Q+=q.genAssert("c.delayPC === 0","delay pc should be zero"),q.needsDelayCheck=!1,e6)Q+="c.incrementCount(1);\n";return a(!q.bailOut,"Not expecting bailOut to be set for memory access"),Q+=`if (c.stuffToDo) { return ${q.fragment.opsCompiled}; }\n`,Q+=`if (c.pc !== ${N(q.postPC)}) { return ${q.fragment.opsCompiled}; }\n`,Q},D0=function(J,q,Q){let Y="";const Z=q.needsDelayCheck||Q||q.postPC!==q.pc+4;if(Y+=A$(J,q,Q),q.needsDelayCheck=!0,e6)Y+="c.incrementCount(1);\n";if(Y+=q.genAssert("c.stuffToDo === 0","stuffToDo should be zero"),q.bailOut)Y+=`return ${q.fragment.opsCompiled};\n`;else if(Z)Y+=`if (c.pc !== ${N(q.postPC)}) { return ${q.fragment.opsCompiled}; }\n`;else Y+="// Skipping pc test\n";return Y},_=function(J,q){let Q="";if(Q+=J8(J),q.isTrivial=!0,e6)Q+="c.incrementCount(1);\n";if(q.needsDelayCheck)Q+=`if (c.delayPC) { c.pc = c.delayPC; c.delayPC = 0; } else { c.pc = ${N(q.pc+4)}; }\n`,Q+=`if (c.pc !== ${N(q.postPC)}) { return ${q.fragment.opsCompiled}; }\n`;else{Q+=q.genAssert("c.delayPC === 0","delay pc should be zero");const Y=q.pc+4;if(q.postPC!==Y)a("postPC should always be pc+4 for trival ops?"),Q+=`c.pc = ${N(Y)};\n`,Q+=`if (c.pc !== ${N(q.postPC)}) { return ${q.fragment.opsCompiled}; }\n`;else if(Q+="// Delaying pc update\n",q.delayedPCUpdate=Y,F$)Q+=`c.pc = ${N(Y)};\n`}return Q+=q.genAssert("c.delayPC === 0","delay pc should be zero"),q.needsDelayCheck=!1,Q+=q.genAssert("c.stuffToDo === 0","stuffToDo should be zero"),Q},h$=function(J,q){return _(`// ${J}\n`,q)},E$=function(J){if(J===0)return"0";return`c.getRegU32Lo(${J})`},u6=function(J){if(J===0)return"0n";return`c.getRegS64(${J})`},f6=function(J){if(J===0)return"0n";return`c.getRegU64(${J})`},C=function(J){const q=`throw 'unknown op, pc ${N(J.pc)}, instruction: ${N(J.instruction)}'`;return T(q,J)},BF=function(J){if(J.instruction===0)return h$("NOP",J);const q=`c.execSLL(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_sa()});`;return _(q,J)},RF=function(J){const q=`c.execSRL(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_sa()});`;return _(q,J)},bF=function(J){const q=`c.execSRA(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_sa()});`;return _(q,J)},TF=function(J){const q=`c.execSLLV(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},_F=function(J){const q=`c.execSRLV(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},SF=function(J){const q=`c.execSRAV(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},vF=function(J){const q=`c.execDSLLV(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},fF=function(J){const q=`c.execDSRLV(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},uF=function(J){const q=`c.execDSRAV(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},gF=function(J){const q=`c.execDSLL(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_sa()});`;return _(q,J)},xF=function(J){const q=`c.execDSLL32(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_sa()});`;return _(q,J)},pF=function(J){const q=`c.execDSRL(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_sa()});`;return _(q,J)},mF=function(J){const q=`c.execDSRL32(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_sa()});`;return _(q,J)},nF=function(J){const q=`c.execDSRA(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_sa()});`;return _(q,J)},oF=function(J){const q=`c.execDSRA32(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_sa()});`;return _(q,J)},cF=function(J){return T("c.execRESERVED(0);",J)},lF=function(J){return T("c.execSYSCALL();",J)},dF=function(J){return T("c.execBREAK();",J)},aF=function(J){return T("c.execSYNC();",J)},rF=function(J){const q=`c.execTGE(${J.instr_rt()}, ${J.instr_rs()});`;return T(q,J)},sF=function(J){const q=`c.execTGEU(${J.instr_rt()}, ${J.instr_rs()});`;return T(q,J)},iF=function(J){const q=`c.execTLT(${J.instr_rt()}, ${J.instr_rs()});`;return T(q,J)},tF=function(J){const q=`c.execTLTU(${J.instr_rt()}, ${J.instr_rs()});`;return T(q,J)},eF=function(J){const q=`c.execTEQ(${J.instr_rt()}, ${J.instr_rs()});`;return T(q,J)},Jj=function(J){const q=`c.execTNE(${J.instr_rt()}, ${J.instr_rs()});`;return T(q,J)},qj=function(J){const q=`c.execMFHI(${J.instr_rd()});`;return _(q,J)},Qj=function(J){const q=`c.execMFLO(${J.instr_rd()});`;return _(q,J)},Yj=function(J){const q=`c.execMTHI(${J.instr_rs()});`;return _(q,J)},Zj=function(J){const q=`c.execMTLO(${J.instr_rs()});`;return _(q,J)},Kj=function(J){const q=`c.execMULT(${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Xj=function(J){const q=`c.execMULTU(${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Wj=function(J){const q=`c.execDMULT(${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},$j=function(J){const q=`c.execDMULTU(${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},zj=function(J){const q=`c.execDIV(${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Hj=function(J){const q=`c.execDIVU(${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Fj=function(J){const q=`c.execDDIV(${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},jj=function(J){const q=`c.execDDIVU(${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Nj=function(J){const q=`c.execADD(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return T(q,J)},Gj=function(J){const q=`c.execDADD(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return T(q,J)},Pj=function(J){const q=`c.execADDU(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Lj=function(J){const q=`c.execDADDU(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Vj=function(J){const q=`c.execSUB(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return T(q,J)},Uj=function(J){const q=`c.execDSUB(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return T(q,J)},Mj=function(J){const q=`c.execSUBU(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Oj=function(J){const q=`c.execDSUBU(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Aj=function(J){const q=`c.execAND(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},hj=function(J){let q;if(J.instr_rt()===0)if(J.instr_rs()===0)q=`c.execCLEAR(${J.instr_rd()});`;else q=`c.execMOV(${J.instr_rd()}, ${J.instr_rs()});`;else q=`c.execOR(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Ej=function(J){const q=`c.execXOR(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},wj=function(J){const q=`c.execNOR(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},kj=function(J){const q=`c.execSLT(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Cj=function(J){const q=`c.execSLTU(${J.instr_rd()}, ${J.instr_rt()}, ${J.instr_rs()});`;return _(q,J)},Dj=function(J){const q=`c.execADDI(${J.instr_rt()}, ${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},yj=function(J){const q=`c.execDADDI(${J.instr_rt()}, ${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},Ij=function(J){const q=`c.execADDI(${J.instr_rt()}, ${J.instr_rs()}, ${J.instr_imms()});`;return _(q,J)},Bj=function(J){const q=`c.execDADDIU(${J.instr_rt()}, ${J.instr_rs()}, ${J.instr_imms()});`;return _(q,J)},Rj=function(J){const q=`c.execMFC0(${J.instr_rt()}, ${J.instr_fs()});`;return T(q,J)},bj=function(J){const q=`c.execDMFC0(${J.instr_rt()}, ${J.instr_fs()});`;return T(q,J)},Tj=function(J){if(J.instr_fs()===U0)J.fragment.cop1statusKnown=!1;const q=`c.execMTC0(${J.instr_rt()}, ${J.instr_fs()});`;return T(q,J)},_j=function(J){if(J.instr_fs()===U0)J.fragment.cop1statusKnown=!1;const q=`c.execDMTC0(${J.instr_rt()}, ${J.instr_fs()});`;return T(q,J)},Sj=function(J){const q=`c.execTLB(${J.instr_tlbop()});`;return T(q,J)},vj=function(J){const q=`c.execMFC2(${J.instr_rt()});`;return T(q,J)},fj=function(J){const q=`c.execDMFC2(${J.instr_rt()});`;return T(q,J)},uj=function(J){const q=`c.execCFC2(${J.instr_rt()});`;return T(q,J)},gj=function(J){const q=`c.execDCFC2(${J.instr_rt()});`;return T(q,J)},xj=function(J){const q=`c.execMTC2(${J.instr_rt()});`;return T(q,J)},pj=function(J){const q=`c.execDMTC2(${J.instr_rt()});`;return T(q,J)},mj=function(J){const q=`c.execCTC2(${J.instr_rt()});`;return T(q,J)},nj=function(J){const q=`c.execDCTC2(${J.instr_rt()});`;return T(q,J)},oj=function(J){const q=I6(J.pc,J.instruction),Q="c.delayPC = "+N(q)+";";return D0(Q,J,!1)},cj=function(J){const q=I6(J.pc,J.instruction),Q=J.nextPC+4,Y=Q&2147483648?-1:0,Z=T0(`
|
|
c.delayPC = ${N(q)};
|
|
c.setRegS64LoHi(${Y6}, ${N(Q)}, ${Y});
|
|
`);return D0(Z,J,!1)},lj=function(J){const q=J.instr_rs(),Q=J.instr_rd(),Y=J.nextPC+4,Z=Y&2147483648?-1:0,K=T0(`
|
|
c.delayPC = ${E$(q)};
|
|
c.setRegS64LoHi(${Q}, ${N(Y)}, ${Z});
|
|
`);return D0(K,J,!1)},dj=function(J){const q=`c.delayPC = ${E$(J.instr_rs())};`;return D0(q,J,!1)},aj=function(J){const q=J.instr_rs(),Q=J.instr_rt(),Y=J.instr_offset(),Z=C0(J.pc,J.instruction);let K="";if(q===Q){if(R8&&Y===-1)K+="c.speedHack();\n",J.bailOut=!0;K+=`c.delayPC = ${N(Z)};\n`}else{if(K+=`if (${f6(q)} === ${f6(Q)}) {\n`,R8&&Y===-1)K+=" c.speedHack();\n",J.bailOut=!0;K+=` c.delayPC = ${N(Z)};\n`,K+="} else {\n",K+=` c.delayPC = ${N(J.pc+8)};\n`,K+="}\n"}return D0(K,J,!1)},rj=function(J){const q=J.instr_rs(),Q=J.instr_rt(),Y=C0(J.pc,J.instruction),Z=T0(`
|
|
if (${f6(q)} === ${f6(Q)}) {
|
|
c.delayPC = ${N(Y)};
|
|
} else {
|
|
c.nextPC += 4;
|
|
}`);return D0(Z,J,!0)},sj=function(J){const q=J.instr_rs(),Q=J.instr_rt(),Y=J.instr_offset(),Z=C0(J.pc,J.instruction);let K="";if(K+=`if (${f6(q)} !== ${f6(Q)}) {\n`,R8&&Y===-1)K+=" c.speedHack();\n",J.bailOut=!0;return K+=` c.delayPC = ${N(Z)};\n`,K+="} else {\n",K+=` c.delayPC = ${N(J.pc+8)};\n`,K+="}\n",D0(K,J,!1)},ij=function(J){const q=J.instr_rs(),Q=J.instr_rt(),Y=C0(J.pc,J.instruction),Z=T0(`
|
|
if (${f6(q)} !== ${f6(Q)}) {
|
|
c.delayPC = ${N(Y)};
|
|
} else {
|
|
c.nextPC += 4;
|
|
}
|
|
`);return D0(Z,J,!0)},tj=function(J){const q=J.instr_rs(),Q=C0(J.pc,J.instruction),Y=T0(`
|
|
if ( ${u6(q)} <= 0n) {
|
|
c.delayPC = ${N(Q)};
|
|
} else {
|
|
c.delayPC = ${N(J.pc+8)};
|
|
}`);return D0(Y,J,!1)},ej=function(J){const q=J.instr_rs(),Q=C0(J.pc,J.instruction),Y=T0(`
|
|
if ( ${u6(q)} <= 0n) {
|
|
c.delayPC = ${N(Q)};
|
|
} else {
|
|
c.nextPC += 4;
|
|
}`);return D0(Y,J,!1)},J4=function(J){const q=J.instr_rs(),Q=C0(J.pc,J.instruction),Y=T0(`
|
|
if (${u6(q)} > 0) {
|
|
c.delayPC = ${N(Q)};
|
|
} else {
|
|
c.delayPC = ${N(J.pc+8)};
|
|
}`);return D0(Y,J,!1)},q4=function(J){const q=J.instr_rs(),Q=C0(J.pc,J.instruction),Y=T0(`
|
|
if (${u6(q)} > 0) {
|
|
c.delayPC = ${N(Q)};
|
|
} else {
|
|
c.nextPC += 4;
|
|
}`);return D0(Y,J,!1)},Q4=function(J){const q=J.instr_rs(),Q=C0(J.pc,J.instruction),Y=T0(`
|
|
if (${u6(q)} < 0n) {
|
|
c.delayPC = ${N(Q)};
|
|
} else {
|
|
c.delayPC = ${N(J.pc+8)};
|
|
}`);return D0(Y,J,!1)},Y4=function(J){const q=J.instr_rs(),Q=C0(J.pc,J.instruction),Y=T0(`
|
|
if (${u6(q)} < 0n) {
|
|
c.delayPC = ${N(Q)};
|
|
} else {
|
|
c.nextPC += 4;
|
|
}`);return D0(Y,J,!0)},Z4=function(J){const q=J.instr_rs(),Q=C0(J.pc,J.instruction),Y=T0(`
|
|
if (${u6(q)} >= 0n) {
|
|
c.delayPC = ${N(Q)};
|
|
} else {
|
|
c.delayPC = ${N(J.pc+8)};
|
|
}`);return D0(Y,J,!1)},K4=function(J){const q=J.instr_rs(),Q=C0(J.pc,J.instruction),Y=T0(`
|
|
if (${u6(q)} >= 0n) {
|
|
c.delayPC = ${N(Q)};
|
|
} else {
|
|
c.nextPC += 4;
|
|
}`);return D0(Y,J,!0)},X4=function(J){const q=`c.execBLTZAL(${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},W4=function(J){const q=`c.execBGEZAL(${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},$4=function(J){const q=`c.execBLTZALL(${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},z4=function(J){const q=`c.execBGEZALL(${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},H4=function(J){const q=`c.execTGEI(${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},F4=function(J){const q=`c.execTGEIU(${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},j4=function(J){const q=`c.execTLTI(${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},N4=function(J){const q=`c.execTLTIU(${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},G4=function(J){const q=`c.execTEQI(${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},P4=function(J){const q=`c.execTNEI(${J.instr_rs()}, ${J.instr_imms()});`;return T(q,J)},L4=function(J){const q=`c.execSLTI(${J.instr_rt()}, ${J.instr_rs()}, ${J.instr_imms()});`;return _(q,J)},V4=function(J){const q=`c.execSLTIU(${J.instr_rt()}, ${J.instr_rs()}, ${J.instr_imms()});`;return _(q,J)},U4=function(J){const q=`c.execANDI(${J.instr_rt()}, ${J.instr_rs()}, ${J.instr_imm()});`;return _(q,J)},M4=function(J){const q=`c.execORI(${J.instr_rt()}, ${J.instr_rs()}, ${J.instr_imm()});`;return _(q,J)},O4=function(J){const q=`c.execXORI(${J.instr_rt()}, ${J.instr_rs()}, ${J.instr_imm()});`;return _(q,J)},A4=function(J){const q=`c.execLUI(${J.instr_rt()}, ${J.instr_imm()});`;return _(q,J)},h4=function(J){const q=`c.execLB(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},E4=function(J){const q=`c.execLBU(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},w4=function(J){const q=`c.execLH(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},k4=function(J){const q=`c.execLHU(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},C4=function(J){const q=`c.execLW(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},D4=function(J){const q=`c.execLWU(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},y4=function(J){const q=`c.execLD(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},I4=function(J){const q=`c.execLWL(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},B4=function(J){const q=`c.execLWR(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},R4=function(J){const q=`c.execLDL(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},b4=function(J){const q=`c.execLDR(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},T4=function(J){J.fragment.usesCop1=!0;const q=`c.execLWC1(${J.instr_ft()}, ${J.instr_base()}, ${J.instr_imms()});`;return T(q,J)},_4=function(J){J.fragment.usesCop1=!0;const q=`c.execLDC1(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return T(q,J)},S4=function(J){const q=`c.execLWC2(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},v4=function(J){const q=`c.execLWC3(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},f4=function(J){const q=`c.execLDC2(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},u4=function(J){const q=`c.execSB(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},g4=function(J){const q=`c.execSH(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},x4=function(J){const q=`c.execSW(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},p4=function(J){const q=`c.execSD(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},m4=function(J){const q=`c.execSWL(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},n4=function(J){const q=`c.execSWR(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},o4=function(J){const q=`c.execSDL(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},c4=function(J){const q=`c.execSDR(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},l4=function(J){J.fragment.usesCop1=!0;const q=`c.execSWC1(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return T(q,J)},d4=function(J){J.fragment.usesCop1=!0;const q=`c.execSDC1(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return T(q,J)},a4=function(J){const q=`c.execSWC2(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},r4=function(J){const q=`c.execSWC3(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},s4=function(J){const q=`c.execSDC2(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},i4=function(J){const q=`c.execLL(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},t4=function(J){const q=`c.execLLD(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},e4=function(J){const q=`c.execSC(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},JN=function(J){const q=`c.execSCD(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return t(q,J)},qN=function(J){if(!n64js.cpu0.ignoreCacheOp(J.instr_rt())){const q=`c.execCACHE(${J.instr_rt()}, ${J.instr_base()}, ${J.instr_imms()});`;return _(q,J)}else return h$("CACHE (ignored)",J)},QN=function(J){return J.fragment.usesCop1=!0,J.isTrivial=!0,`c.execMFC1(${J.instr_rt()}, ${J.instr_fs()});`},YN=function(J){return J.fragment.usesCop1=!0,J.isTrivial=!0,`c.execDMFC1(${J.instr_rt()}, ${J.instr_fs()});`},ZN=function(J){return J.fragment.usesCop1=!0,J.isTrivial=!0,`c.execMTC1(${J.instr_rt()}, ${J.instr_fs()});`},KN=function(J){return J.fragment.usesCop1=!0,J.isTrivial=!0,`c.execDMTC1(${J.instr_rt()}, ${J.instr_fs()});`},XN=function(J){return J.fragment.usesCop1=!0,J.isTrivial=!0,`c.execCFC1(${J.instr_rt()}, ${J.instr_fs()});`},WN=function(J){return J.fragment.usesCop1=!0,J.isTrivial=!0,`c.execCTC1(${J.instr_rt()}, ${J.instr_fs()});`},$N=function(J){return J.fragment.usesCop1=!0,J.isTrivial=!1,`c.execDCFC1(${J.instr_rt()}, ${J.instr_fs()});`},zN=function(J){return J.fragment.usesCop1=!0,J.isTrivial=!1,`c.execDCTC1(${J.instr_rt()}, ${J.instr_fs()});`},HN=function(J){const q=J.instruction;a((q>>>18&7)===0,"cc bit is not 0");const Q=(q&65536)!==0,Y=(q&131072)!==0,Z=C0(J.pc,q);J.fragment.usesCop1=!0,J.isTrivial=!1;let X=`const cond = (cpu1.control[31] & FPCSR_C) ${Q?"!==":"==="} 0;\n`;if(Y)X+="if (cond) {\n",X+=` c.branchTarget = ${N(Z)};\n`,X+="} else {\n",X+=" c.nextPC += 4;\n",X+="}\n";else X+="if (cond) {\n",X+=` c.branchTarget = ${N(Z)};\n`,X+="} else {\n",X+=` c.branchTarget = ${N(J.pc+8)};\n`,X+="}\n";return X},FN=function(J){const q=J.instr_fs(),Q=J.instr_ft(),Y=J.instr_fd();J.fragment.usesCop1=!0,J.isTrivial=!1;const Z=u0(J.instruction);if(Z<48){switch(Z){case j$:return`cpu1.ADD_S(${Y}, ${q}, ${Q});`;case N$:return`cpu1.SUB_S(${Y}, ${q}, ${Q});`;case G$:return`cpu1.MUL_S(${Y}, ${q}, ${Q});`;case P$:return`cpu1.DIV_S(${Y}, ${q}, ${Q});`;case L$:return`cpu1.SQRT_S(${Y}, ${q});`;case V$:return`cpu1.ABS_S(${Y}, ${q});`;case U$:return`cpu1.MOV_S(${Y}, ${q});`;case M$:return`cpu1.NEG_S(${Y}, ${q});`;case Fq:return`cpu1.ConvertSToL(${Y}, ${q}, ${l0});`;case jq:return`cpu1.ConvertSToL(${Y}, ${q}, ${t0});`;case Nq:return`cpu1.ConvertSToL(${Y}, ${q}, ${e0});`;case Gq:return`cpu1.ConvertSToL(${Y}, ${q}, ${J6});`;case Pq:return`cpu1.ConvertSToW(${Y}, ${q}, ${l0});`;case Lq:return`cpu1.ConvertSToW(${Y}, ${q}, ${t0});`;case Vq:return`cpu1.ConvertSToW(${Y}, ${q}, ${e0});`;case Uq:return`cpu1.ConvertSToW(${Y}, ${q}, ${J6});`;case Mq:return"cpu1.raiseUnimplemented();";case Oq:return`cpu1.CVT_D_S(${Y}, ${q});`;case Aq:return`cpu1.ConvertSToW(${Y}, ${q}, cpu1.roundingMode);`;case hq:return`cpu1.ConvertSToL(${Y}, ${q}, cpu1.roundingMode);`}return`unimplemented(${N(J.pc)},${N(J.instruction)});`}return`cpu1.handleFloatCompareSingle(${Z}, ${q}, ${Q});`},jN=function(J){const q=J.instr_fs(),Q=J.instr_ft(),Y=J.instr_fd();J.fragment.usesCop1=!0,J.isTrivial=!1;const Z=u0(J.instruction);if(Z<48){switch(Z){case j$:return`cpu1.ADD_D(${Y}, ${q}, ${Q});`;case N$:return`cpu1.SUB_D(${Y}, ${q}, ${Q});`;case G$:return`cpu1.MUL_D(${Y}, ${q}, ${Q});`;case P$:return`cpu1.DIV_D(${Y}, ${q}, ${Q});`;case L$:return`cpu1.SQRT_D(${Y}, ${q});`;case V$:return`cpu1.ABS_D(${Y}, ${q});`;case U$:return`cpu1.MOV_D(${Y}, ${q});`;case M$:return`cpu1.NEG_D(${Y}, ${q});`;case Fq:return`cpu1.ConvertDToL(${Y}, ${q}, ${l0});`;case jq:return`cpu1.ConvertDToL(${Y}, ${q}, ${t0});`;case Nq:return`cpu1.ConvertDToL(${Y}, ${q}, ${e0});`;case Gq:return`cpu1.ConvertDToL(${Y}, ${q}, ${J6});`;case Pq:return`cpu1.ConvertDToW(${Y}, ${q}, ${l0});`;case Lq:return`cpu1.ConvertDToW(${Y}, ${q}, ${t0});`;case Vq:return`cpu1.ConvertDToW(${Y}, ${q}, ${e0});`;case Uq:return`cpu1.ConvertDToW(${Y}, ${q}, ${J6});`;case Mq:return`cpu1.CVT_S_D(${Y}, ${q});`;case Oq:return"cpu1.raiseUnimplemented();";case Aq:return`cpu1.ConvertDToW(${Y}, ${q}, cpu1.roundingMode);`;case hq:return`cpu1.ConvertDToL(${Y}, ${q}, cpu1.roundingMode);`}return`unimplemented(${N(J.pc)},${N(J.instruction)});`}return`cpu1.handleFloatCompareDouble(${Z}, ${q}, ${Q});`},NN=function(J){const q=J.instr_fs(),Q=J.instr_fd();switch(J.fragment.usesCop1=!0,J.isTrivial=!1,u0(J.instruction)){case Fq:return"cpu1.raiseUnimplemented();";case jq:return"cpu1.raiseUnimplemented();";case Nq:return"cpu1.raiseUnimplemented();";case Gq:return"cpu1.raiseUnimplemented();";case Pq:return"cpu1.raiseUnimplemented();";case Lq:return"cpu1.raiseUnimplemented();";case Vq:return"cpu1.raiseUnimplemented();";case Uq:return"cpu1.raiseUnimplemented();";case Mq:return`cpu1.CVT_S_W(${Q}, ${q});`;case Oq:return`cpu1.CVT_D_W(${Q}, ${q});`;case Aq:return"cpu1.raiseUnimplemented();";case hq:return"cpu1.raiseUnimplemented();"}return`unimplemented(${N(J.pc)},${N(J.instruction)});`},GN=function(J){const q=J.instr_fs(),Q=J.instr_fd();switch(J.fragment.usesCop1=!0,J.isTrivial=!1,u0(J.instruction)){case Fq:return"cpu1.raiseUnimplemented();";case jq:return"cpu1.raiseUnimplemented();";case Nq:return"cpu1.raiseUnimplemented();";case Gq:return"cpu1.raiseUnimplemented();";case Pq:return"cpu1.raiseUnimplemented();";case Lq:return"cpu1.raiseUnimplemented();";case Vq:return"cpu1.raiseUnimplemented();";case Uq:return"cpu1.raiseUnimplemented();";case Mq:return`cpu1.CVT_S_L(${Q}, ${q});`;case Oq:return`cpu1.CVT_D_L(${Q}, ${q});`;case Aq:return"cpu1.raiseUnimplemented();";case hq:return"cpu1.raiseUnimplemented();"}return`unimplemented(${N(J.pc)},${N(J.instruction)});`},PN=function(J){const q=hN[f0(J.instruction)],Q=q(J);let Y="";if(J.fragment.usesCop1=!0,J.fragment.cop1statusKnown)Y+=J.genAssert("(c.getControlU32(12) & SR_CU1) !== 0","cop1 should be enabled"),Y+=J8(Q);else return Y+="if( (c.getControlU32(12) & SR_CU1) === 0 ) {\n",Y+=` n64js.executeCop1_disabled(${N(J.instruction)});\n`,Y+="} else {\n",Y+=" "+J8(Q),Y+="}\n",J.isTrivial=!1,J.fragment.cop1statusKnown=!0,T(Y,J);if(J.isTrivial)return _(Y,J);return T(Y,J)},LN=function(J){return T("c.execBreakpoint();",J)},VN=function(J){if(J.length!=64)throw"Special table is unexpected size.";return J},UY=function(J){if(J.length!=32)throw"Cop table is unexpected size.";return J},UN=function(J){if(J.length!=32)throw"RegImm table is unexpected size.";return J},MN=function(J){if(J.length!=64)throw"Simple table is unexpected size.";return J},CN=function(J){if(yF)return kN[$8(J.instruction)](J);const q=`n64js.executeOp(${J.instruction});`;return T(q,J)},DN=function(J){return ON[H8(J.instruction)](J)},yN=function(J){return wN[z8(J.instruction)](J)},IN=function(J){return AN[f0(J.instruction)](J)},BN=function(J){return EN[f0(J.instruction)](J)},RN=function(J){return T("c.execRESERVED(0);",J)},DF=!1,F$=!1,yF=!0,j$=0,N$=1,G$=2,P$=3,L$=4,V$=5,U$=6,M$=7,Fq=8,jq=9,Nq=10,Gq=11,Pq=12,Lq=13,Vq=14,Uq=15,Mq=32,Oq=33,Aq=36,hq=37;class VY{constructor(){this.fragment=void 0,this.pc=0,this.instruction=0,this.postPC=0,this.bailOut=!1,this.nextPC=0,this.needsDelayCheck=!0,this.isTrivial=!1,this.delayedPCUpdate=0,this.dump=!1}genAssert(J,q){if(DF)return"window.n64jsAssert("+J+', "'+q+'");\n';return""}newFragment(){this.delayedPCUpdate=0}set(J,q,Q,Y,Z){this.fragment=J,this.pc=q,this.instruction=Q,this.postPC=Y,this.nextPC=Z,this.bailOut=!1,this.needsDelayCheck=!0,this.isTrivial=!1,this.dump=!1}instr_rs(){return D(this.instruction)}instr_rt(){return A(this.instruction)}instr_rd(){return R(this.instruction)}instr_sa(){return R0(this.instruction)}instr_fs(){return J0(this.instruction)}instr_ft(){return K6(this.instruction)}instr_fd(){return P6(this.instruction)}instr_base(){return u(this.instruction)}instr_offset(){return q0(this.instruction)}instr_imms(){return b(this.instruction)}instr_imm(){return L6(this.instruction)}instr_tlbop(){return F8(this.instruction)}}var ON=VN([BF,C,RF,bF,TF,C,_F,SF,dj,lj,C,C,lF,dF,C,aF,qj,Yj,Qj,Zj,vF,C,fF,uF,Kj,Xj,zj,Hj,Wj,$j,Fj,jj,Nj,Pj,Vj,Mj,Aj,hj,Ej,wj,C,C,kj,Cj,Gj,Lj,Uj,Oj,rF,sF,iF,tF,eF,C,Jj,C,gF,C,pF,nF,xF,C,mF,oF]),AN=UY([Rj,bj,C,C,Tj,_j,C,C,C,C,C,C,C,C,C,C,Sj,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C]),hN=UY([QN,YN,XN,$N,ZN,KN,WN,zN,HN,C,C,C,C,C,C,C,FN,jN,C,C,NN,GN,C,C,C,C,C,C,C,C,C,C]),EN=UY([vj,fj,uj,gj,xj,pj,mj,nj,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C]),wN=UN([Q4,Z4,Y4,K4,C,C,C,C,H4,F4,j4,N4,G4,C,P4,C,X4,W4,$4,z4,C,C,C,C,C,C,C,C,C,C,C,C]),kN=MN([DN,yN,oj,cj,aj,sj,tj,J4,Dj,Ij,L4,V4,U4,M4,O4,A4,IN,PN,BN,RN,rj,ij,ej,q4,yj,Bj,R4,b4,LN,C,C,cF,h4,w4,I4,C4,E4,k4,B4,D4,u4,g4,m4,x4,o4,c4,n4,qN,i4,T4,S4,v4,t4,_4,f4,y4,e4,l4,a4,r4,JN,d4,s4,p4]);window.n64jsAssert=(J,q)=>{a(J,q)};var TN=function(J){const q=J<256?BigInt(J)+256n:(BigInt(J)-256n<<1n)+512n;let Q=1n<<17n,Y=512n;while(Y!=0){while(q*(Q+Y)*(Q+Y)<1n<<44n)Q+=Y;Y>>=1n}return Number(Q>>1n&0xffffn)};function MY(J){if(J==-32768)return 4294901760;else if(J==0)return 2147483647;const q=J>>>0>4294934528?J-1:J,Q=q>>31,Y=q^Q,Z=Math.clz32(Y)+1,X=Y<<Z>>>23;return(65536|bN[X])<<14>>>32-Z^Q}function OY(J){if(J==-32768)return 4294901760;else if(J==0)return 2147483647;const q=J>>>0>4294934528?J-1:J,Q=q>>31,Y=q^Q,Z=Math.clz32(Y)+1,X=Y<<Z>>>24|(Z&1)<<8;return(65536|_N[X])<<14>>>(32-Z>>1)^Q}var bN=function(){const J=[];J.push(65535);for(let q=1;q<512;q++){const Q=(1n<<34n)/(BigInt(q)+512n);J.push(Number(Q+1n>>8n&0xffffn))}return J}(),_N=function(){const J=[];for(let q=0;q<512;q++)J.push(TN(q));return J}();function p$(J){H=new o$(J)}var m$=function(J){return J&63},g6=function(J){return(J&65535)<<16>>16},hY=function(J){return J>>>6&31},Q0=function(J){return J>>>11&31},v=function(J){return J>>>16&31},d=function(J){return J>>>21&31},SN=function(J){return J>>>26&63},vN=function(J){return J>>>21&31},E0=function(J){return J>>>16&31},L0=function(J){return J>>>7&15},fN=function(J){return(J&127)<<25>>25},o=function(J){return J>>>21&15},EY=function(J){return J>>>11&31},c=function(J){return J>>>16&31},s=function(J){return J>>>11&31},m=function(J){return J>>>6&31},uN=function(J){return J&67108863},Eq=function(J){return J&65535},b8=function(J){return Eq(J)<<16>>16},gN=function(J){return J>>>21&31};var n$=function(J,q){return J&4026531840|uN(q)*4},g$=function(J){return J*4},x$=function(J){return(J-AY)*4},dN=function(J){return lN[m$(J)](J)},x6=function(J){H.disassembleAll(),n64js.halt(`RSP: unknown op, pc: ${r(H.pc)}, instruction: ${N(J)}`)},iN=function(J){H.setRegS32(Q0(J),H.getRegS32(v(J))<<hY(J))},tN=function(J){H.setRegS32(Q0(J),H.getRegS32(v(J))>>>hY(J))},eN=function(J){H.setRegS32(Q0(J),H.getRegS32(v(J))>>hY(J))},JG=function(J){H.setRegS32(Q0(J),H.getRegS32(v(J))<<(H.getRegS32(d(J))&31))},qG=function(J){H.setRegS32(Q0(J),H.getRegS32(v(J))>>>(H.getRegS32(d(J))&31))},QG=function(J){H.setRegS32(Q0(J),H.getRegS32(v(J))>>(H.getRegS32(d(J))&31))},YG=function(J){H.jump(H.getRegS32(d(J)))},ZG=function(J){const q=H.getRegS32(d(J));H.setRegS32(Q0(J),H.nextPC+4),H.jump(q)},KG=function(J){H.halt(pN)},XG=function(J){H.setRegS32(Q0(J),H.getRegS32(d(J))+H.getRegS32(v(J)))},WG=function(J){H.setRegU32(Q0(J),H.getRegU32(d(J))+H.getRegU32(v(J)))},$G=function(J){H.setRegS32(Q0(J),H.getRegS32(d(J))-H.getRegS32(v(J)))},zG=function(J){H.setRegU32(Q0(J),H.getRegU32(d(J))-H.getRegU32(v(J)))},HG=function(J){H.setRegU32(Q0(J),H.getRegU32(d(J))&H.getRegU32(v(J)))},FG=function(J){H.setRegU32(Q0(J),H.getRegU32(d(J))|H.getRegU32(v(J)))},jG=function(J){H.setRegU32(Q0(J),H.getRegU32(d(J))^H.getRegU32(v(J)))},NG=function(J){H.setRegU32(Q0(J),~(H.getRegU32(d(J))|H.getRegU32(v(J))))},GG=function(J){H.setRegS32(Q0(J),H.getRegS32(d(J))<H.getRegS32(v(J))?1:0)},PG=function(J){H.setRegU32(Q0(J),H.getRegU32(d(J))<H.getRegU32(v(J))?1:0)},LG=function(J){H.conditionalBranch(H.getRegS32(d(J))<0,g6(J))},VG=function(J){H.conditionalBranch(H.getRegS32(d(J))>=0,g6(J))},UG=function(J){const q=H.getRegS32(d(J))<0;H.setRegS32(wY,H.nextPC+4),H.conditionalBranch(q,g6(J))},MG=function(J){const q=H.getRegS32(d(J))>=0;H.setRegS32(wY,H.nextPC+4),H.conditionalBranch(q,g6(J))},OG=function(J){H.setRegU32(v(J),H.moveFromControl(Q0(J)))},AG=function(J){H.moveToControl(Q0(J),H.getRegU32(v(J)))},hG=function(J){H.setRegS16SignExtend(v(J),H.getVecU16UnalignedWrap(Q0(J),L0(J)))},EG=function(J){H.setVecU16UnalignedNoWrap(Q0(J),L0(J),H.getRegU32(v(J)))},wG=function(J){let q;switch(Q0(J)&3){case 0:q=H.VCO<<16>>16;break;case 1:q=H.VCC<<16>>16;break;case 2:q=H.VCE;break;case 3:q=H.VCE;break}H.setRegU32(v(J),q)},kG=function(J){const q=H.getRegS32(v(J));switch(Q0(J)&3){case 0:H.VCO=q;break;case 1:H.VCC=q;break;case 2:H.VCE=q;break;case 3:H.VCE=q;break}},CG=function(J,q,Q,Y){if(J>=0)return(J&~0x7fff_ffffn)!=0?Y:Number(J>>q);return(~J&~0x7fff_ffffn)!=0?Q:Number(J>>q)},DG=function(J,q,Q,Y){if(J>=0)return(J&~0x7fff_ffffn)!=0?Y:Number(J>>q);return Q},c$=function(J){if(J<-32768)return-32768;if(J>32767)return 32767;return J},V0=function(J){const q=s(J),Q=c(J);for(let Y=0,Z=H.vecSelectU32[o(J)];Y<8;Y++,Z>>=4){const K=H.getVecS16(q,Y),X=H.getVecS16(Q,Z&7);H.setAccLow(Y,K+X)}H.setVecZero(m(J))},yG=function(J){V0(J)},IG=function(J){V0(J)},BG=function(J){V0(J)},RG=function(J){V0(J)},bG=function(J){V0(J)},TG=function(J){V0(J)},_G=function(J){V0(J)},SG=function(J){V0(J)},vG=function(J){V0(J)},fG=function(J){V0(J)},uG=function(J){V0(J)},gG=function(J){V0(J)},xG=function(J){V0(J)},pG=function(J){V0(J)},mG=function(J){V0(J)},nG=function(J){V0(J)},oG=function(J){V0(J)},cG=function(J){V0(J)},lG=function(J){V0(J)},wq=function(J,q,Q,Y,Z){for(let K=0,X=H.vecSelectU32[Q];K<8;K++,X>>=4){const W=H.getVecS16(J,K),z=H.getVecS16(q,X&7),F=W*z*2+Z;H.updateAcc32Signed(K,F,Y)}},l$=function(J,q,Q,Y){for(let Z=0,K=H.vecSelectU32[Q];Z<8;Z++,K>>=4){const X=H.getVecU16(J,Z),W=H.getVecU16(q,K&7),z=X*W>>>16;H.updateAccU32(Z,z,Y)}},d$=function(J,q,Q,Y){for(let Z=0,K=H.vecSelectU32[Q];Z<8;Z++,K>>=4){const X=H.getVecS16(J,Z),W=H.getVecU16(q,K&7);H.updateAcc32Signed(Z,X*W,Y)}},a$=function(J,q,Q,Y){for(let Z=0,K=H.vecSelectU32[Q];Z<8;Z++,K>>=4){const X=H.getVecU16(J,Z),W=H.getVecS16(q,K&7);H.updateAcc32Signed(Z,X*W,Y)}},r$=function(J,q,Q,Y){for(let Z=0,K=H.vecSelectU32[Q];Z<8;Z++,K>>=4){const X=H.getVecS16(J,Z),W=H.getVecS16(q,K&7);H.updateAcc32SignedShift16(Z,X*W,Y)}},s$=function(J,q,Q,Y){const Z=J&1?16:0;for(let K=0,X=H.vecSelectU32[Q];K<8;K++,X>>=4){const W=H.getAccS48(K),z=H.getVecS16(q,X&7)<<Z,F=Y?W>=0:W<0;H.setAccS48(K,W+(F?BigInt(z):0n))}},dG=function(J){wq(s(J),c(J),o(J),!1,32768),H.setVecFromAccSignedMid(m(J))},aG=function(J){wq(s(J),c(J),o(J),!1,32768),H.setVecFromAccUnsignedMid(m(J))},rG=function(J){wq(s(J),c(J),o(J),!0,0),H.setVecFromAccSignedMid(m(J))},sG=function(J){wq(s(J),c(J),o(J),!0,0),H.setVecFromAccUnsignedMid(m(J))},iG=function(J){s$(s(J),c(J),o(J),!1),H.setVecFromAccSignedMid(m(J))},tG=function(J){s$(s(J),c(J),o(J),!0),H.setVecFromAccSignedMid(m(J))},eG=function(J){l$(s(J),c(J),o(J),!1),H.setVecFromAccLow(m(J))},JP=function(J){l$(s(J),c(J),o(J),!0),H.setVecFromAccSignedLow(m(J))},qP=function(J){d$(s(J),c(J),o(J),!1),H.setVecFromAccMid(m(J))},QP=function(J){d$(s(J),c(J),o(J),!0),H.setVecFromAccSignedMid(m(J))},YP=function(J){a$(s(J),c(J),o(J),!1),H.setVecFromAccLow(m(J))},ZP=function(J){a$(s(J),c(J),o(J),!0),H.setVecFromAccSignedLow(m(J))},KP=function(J){r$(s(J),c(J),o(J),!1),H.setVecFromAccSignedMid(m(J))},XP=function(J){r$(s(J),c(J),o(J),!0),H.setVecFromAccSignedMid(m(J))},WP=function(J){const q=s(J),Q=c(J);for(let Y=0,Z=H.vecSelectU32[o(J)];Y<8;Y++,Z>>=4){const K=H.getVecS16(q,Y),X=H.getVecS16(Q,Z&7),W=BigInt(K*X)<<16n;H.setAccS48(Y,W+(W<0?0x1f0000n:0n))}H.setVecFromAccOddified(m(J))},$P=function(J){for(let q=0;q<8;q++){const Q=H.getAccS48(q);let Y=0n;if((Q&0x20_0000n)==0){const Z=Q>>22n;if(Z<0)Y=0x20_0000n;else if(Z>0)Y=-0x20_0000n}H.setAccS48(q,Q+Y)}H.setVecFromAccOddified(m(J))},zP=function(J){const q=s(J),Q=c(J),Y=H.VCO,Z=H.vecTemp;for(let K=0,X=H.vecSelectU32[o(J)];K<8;K++,X>>=4){const W=H.getVecS16(q,K),z=H.getVecS16(Q,X&7),F=Y>>K&1,j=W+z+F;H.setAccLow(K,j),Z.setInt16(K*2,c$(j))}H.setVecFromTemp(m(J)),H.VCO=0},HP=function(J){const q=s(J),Q=c(J),Y=H.VCO,Z=H.vecTemp;for(let K=0,X=H.vecSelectU32[o(J)];K<8;K++,X>>=4){const W=H.getVecS16(q,K),z=H.getVecS16(Q,X&7),F=Y>>K&1,j=W-(z+F);H.setAccLow(K,j),Z.setInt16(K*2,c$(j))}H.setVecFromTemp(m(J)),H.VCO=0},FP=function(J,q){if(J<0)return-q;if(J>0)return q;return 0},jP=function(J){const q=s(J),Q=c(J),Y=H.vecTemp;for(let Z=0,K=H.vecSelectU32[o(J)];Z<8;Z++,K>>=4){const X=H.getVecS16(q,Z),W=H.getVecU16(Q,K&7),z=X<0&&W==32768,F=FP(X,W);H.setAccLow(Z,z?32768:F),Y.setInt16(Z*2,z?32767:F)}H.setVecFromTemp(m(J))},NP=function(J){const q=s(J),Q=c(J);let Y=0;for(let Z=0,K=H.vecSelectU32[o(J)];Z<8;Z++,K>>=4){const X=H.getVecU16(q,Z),W=H.getVecU16(Q,K&7),z=X+W;H.setAccLow(Z,z),Y|=z&~65535?1<<Z:0}H.setVecFromAccLow(m(J)),H.VCO=Y},GP=function(J){const q=s(J),Q=c(J);let Y=0;for(let Z=0,K=H.vecSelectU32[o(J)];Z<8;Z++,K>>=4){const X=H.getVecU16(q,Z),W=H.getVecU16(Q,K&7),z=X-W;H.setAccLow(Z,z),Y|=z!=0?1<<Z+8:0,Y|=z<0?1<<Z+0:0}H.setVecFromAccLow(m(J)),H.VCO=Y},UP=function(J){let q=64n;switch(o(J)){case PP:q=32n;break;case LP:q=16n;break;case VP:q=0n;break}const Q=m(J);for(let Y=0;Y<8;Y++)H.setVecS16(Q,Y,Number(H.vAcc[Y]>>q))},MP=function(J){const q=s(J),Q=c(J),Y=H.VCO;let Z=0,K=0;for(let X=0,W=H.vecSelectU32[o(J)];X<8;X++,W>>=4){const z=H.getVecS16(q,X),F=H.getVecS16(Q,W&7),j=1<<X,G=(Y&j)!=0,P=(Y&j<<8)!=0,L=G&&P,U=z<F||z==F&&L,O=U?z:F;Z|=U?j:0,H.setAccLow(X,O)}H.setVecFromAccLow(m(J)),H.setVCCHiLo(K,Z),H.VCO=0},OP=function(J){const q=s(J),Q=c(J),Y=H.VCO;let Z=0,K=0;for(let X=0,W=H.vecSelectU32[o(J)];X<8;X++,W>>=4){const z=H.getVecS16(q,X),F=H.getVecS16(Q,W&7),j=1<<X,G=(Y&j<<8)!=0,P=z==F&&!G,L=F;Z|=P?j:0,H.setAccLow(X,L)}H.setVecFromAccLow(m(J)),H.setVCCHiLo(K,Z),H.VCO=0},AP=function(J){const q=s(J),Q=c(J),Y=H.VCO;let Z=0,K=0;for(let X=0,W=H.vecSelectU32[o(J)];X<8;X++,W>>=4){const z=H.getVecS16(q,X),F=H.getVecS16(Q,W&7),j=1<<X,G=(Y&j<<8)!=0,P=z!=F||G,L=z;Z|=P?j:0,H.setAccLow(X,L)}H.setVecFromAccLow(m(J)),H.VCC=K<<8|Z,H.setVCCHiLo(K,Z),H.VCO=0},hP=function(J){const q=s(J),Q=c(J),Y=H.VCO;let Z=0,K=0;for(let X=0,W=H.vecSelectU32[o(J)];X<8;X++,W>>=4){const z=H.getVecS16(q,X),F=H.getVecS16(Q,W&7),j=1<<X,G=(Y&j)!=0,P=(Y&j<<8)!=0,L=G&&P,U=z>F||z==F&&!L,O=U?z:F;Z|=U?j:0,H.setAccLow(X,O)}H.setVecFromAccLow(m(J)),H.setVCCHiLo(K,Z),H.VCO=0},EP=function(J){const q=s(J),Q=c(J),Y=H.VCCHi,Z=H.VCCLo,K=H.VCE,X=H.VCOHi,W=H.VCOLo;let z=0,F=0;for(let j=0,G=H.vecSelectU32[o(J)];j<8;j++,G>>=4){const P=H.getVecU16(q,j),L=H.getVecU16(Q,G&7);let U=Z>>j&1,O=Y>>j&1;const E=K>>j&1,w=~(X>>j)&1,y=W>>j&1;let S;if(y){if(w){const g=P+L&65535,x=P+L>65535;U=!E&&(!g&&!x)||E&&(!g||!x)}S=U?-L:P}else{if(w)O=P-L>=0;S=O?L:P}H.setAccLow(j,S),z|=O<<j,F|=U<<j}H.setVecFromAccLow(m(J)),H.setVCCHiLo(z,F),H.VCO=0,H.VCE=0},wP=function(J){const q=s(J),Q=c(J);let Y=0,Z=0,K=0,X=0,W=0;for(let z=0,F=H.vecSelectU32[o(J)];z<8;z++,F>>=4){const j=H.getVecS16(q,z),G=H.getVecS16(Q,F&7);let P,L,U,O,E;const w=(j^G)<0;if(w){const y=j+G<<16>>16;L=G<0,P=y<=0,U=y==-1,O=y!=0&&j!=~G,E=P?-G:j}else{const y=j-G<<16>>16;P=G<0,L=y>=0,U=0,O=y!=0,E=L?G:j}H.setAccLow(z,E),Y|=L<<z,Z|=P<<z,K|=O<<z,X|=w<<z,W|=U<<z}H.setVecFromAccLow(m(J)),H.setVCCHiLo(Y,Z),H.setVCOHiLo(K,X),H.VCE=W},kP=function(J){const q=s(J),Q=c(J);let Y=0,Z=0;for(let K=0,X=H.vecSelectU32[o(J)];K<8;K++,X>>=4){const W=H.getVecS16(q,K),z=H.getVecS16(Q,X&7);let F,j,G;if((W^z)<0)j=z<0,F=W+z+1<=0,G=F?~z:W;else F=z<0,j=W-z>=0,G=j?z:W;Z|=F<<K,Y|=j<<K,H.setAccLow(K,G)}H.setVecFromAccLow(m(J)),H.setVCCHiLo(Y,Z),H.VCO=0,H.VCE=0},CP=function(J){const q=s(J),Q=c(J);let Y=H.VCC;for(let Z=0,K=H.vecSelectU32[o(J)];Z<8;Z++,Y>>=1,K>>=4){const X=H.getVecU16(q,Z),W=H.getVecU16(Q,K&7),z=Y&1?X:W;H.setAccLow(Z,z)}H.setVecFromAccLow(m(J)),H.VCO=0},DP=function(J){T8(J,(q,Q)=>q&Q)},yP=function(J){T8(J,(q,Q)=>~(q&Q))},IP=function(J){T8(J,(q,Q)=>q|Q)},BP=function(J){T8(J,(q,Q)=>~(q|Q))},RP=function(J){T8(J,(q,Q)=>q^Q)},bP=function(J){T8(J,(q,Q)=>~(q^Q))},T8=function(J,q){const Q=s(J),Y=c(J);for(let Z=0,K=H.vecSelectU32[o(J)];Z<8;Z++,K>>=4){const X=H.getVecU16(Q,Z),W=H.getVecU16(Y,K&7);H.setAccLow(Z,q(X,W))}H.setVecFromAccLow(m(J))},TP=function(J){const q=c(J),Q=m(J),Y=EY(J)&7,Z=H.vecSelectU32[o(J)];for(let K=0,X=Z;K<8;K++,X>>=4){const W=H.getVecS16(q,X&7);H.setAccLow(K,W)}H.setVecS16(Q,Y&7,H.getVecS16(q,Z>>4*Y&7))},i$=function(J,q){for(let Q=0,Y=H.vecSelectU32[q];Q<8;Q++,Y>>=4){const Z=H.getVecS16(J,Y&7);H.setAccLow(Q,Z)}},t$=function(J){const q=c(J),Q=o(J);i$(q,Q),H.divDP=!0,H.divIn=H.getVecS16(q,Q&7),H.setVecS16(m(J),EY(J)&7,H.divOut)},kq=function(J,q,Q){const Y=c(J),Z=o(J),K=H.getVecS16(Y,Z&7),X=Q&&H.divDP?H.divIn<<16|K&65535:K;i$(Y,Z);const W=q(X);H.divDP=!1,H.divOut=W>>16,H.setVecS16(m(J),EY(J)&7,W&65535)},_P=function(J){kq(J,MY,!1)},SP=function(J){kq(J,MY,!0)},vP=function(J){t$(J)},fP=function(J){kq(J,OY,!1)},uP=function(J){kq(J,OY,!0)},gP=function(J){t$(J)},xP=function(J){},pP=function(J){},mP=function(J){H.jump(n$(H.pc,J))},nP=function(J){H.setRegS32(wY,H.nextPC+4),H.jump(n$(H.pc,J))},oP=function(J){H.conditionalBranch(H.getRegS32(d(J))===H.getRegS32(v(J)),g6(J))},cP=function(J){H.conditionalBranch(H.getRegS32(d(J))!==H.getRegS32(v(J)),g6(J))},lP=function(J){H.conditionalBranch(H.getRegS32(d(J))<=0,g6(J))},dP=function(J){H.conditionalBranch(H.getRegS32(d(J))>0,g6(J))},aP=function(J){H.setRegS32(v(J),H.getRegS32(d(J))+b8(J))},rP=function(J){H.setRegS32(v(J),H.getRegS32(d(J))+b8(J))},sP=function(J){H.setRegS32(v(J),H.getRegS32(d(J))<b8(J)?1:0)},iP=function(J){H.setRegS32(v(J),H.getRegU32(d(J))<b8(J)>>>0?1:0)},tP=function(J){H.setRegS32(v(J),H.getRegS32(d(J))&Eq(J))},eP=function(J){H.setRegS32(v(J),H.getRegS32(d(J))|Eq(J))},JL=function(J){H.setRegS32(v(J),H.getRegS32(d(J))^Eq(J))},qL=function(J){H.setRegS32(v(J),b8(J)<<16)},QL=function(J){H.setRegS32(v(J),H.loadS8(H.calcAddress(J)))},YL=function(J){H.setRegU32(v(J),H.loadU8(H.calcAddress(J)))},ZL=function(J){H.setRegS32(v(J),H.loadS16(H.calcAddress(J)))},KL=function(J){H.setRegU32(v(J),H.loadU16(H.calcAddress(J)))},XL=function(J){H.setRegS32(v(J),H.loadS32(H.calcAddress(J)))},WL=function(J){H.setRegU32(v(J),H.loadU32(H.calcAddress(J)))},$L=function(J){H.store8(H.calcAddress(J),H.getRegS32(v(J)))},zL=function(J){H.store16(H.calcAddress(J),H.getRegS32(v(J)))},HL=function(J){H.store32(H.calcAddress(J),H.getRegS32(v(J)))},Cq=function(J,q){const Q=H.calcVecAddress(J,q),Y=E0(J),Z=L0(J),K=16-Z<q?16-Z:q;for(let X=0;X<K;X++)H.setVecS8(Y,Z+X,H.loadS8(Q+X))},Dq=function(J,q){const Q=H.calcVecAddress(J,q),Y=E0(J),Z=L0(J);for(let K=0;K<q;K++)H.store8(Q+K,H.getVecS8(Y,Z+K&15))},FL=function(J){Cq(J,1)},jL=function(J){Cq(J,2)},NL=function(J){Cq(J,4)},GL=function(J){Cq(J,8)},PL=function(J){const q=H.calcVecAddress(J,16),Q=(q&4080)+16,Y=E0(J),Z=L0(J),K=Math.min(Q-q,16-Z);for(let X=0;X<K;X++)H.setVecS8(Y,Z+X,H.loadU8(q+X))},LL=function(J){const q=H.calcVecAddress(J,16),Q=q&4080,Y=E0(J),Z=L0(J),K=q&15,X=16-K+Z,W=Math.min(K,16-X);for(let z=0;z<W;z++)H.setVecS8(Y,X+z,H.loadU8(Q+z))},kY=function(J,q,Q,Y,Z){const K=J&7,X=J&4088;for(let W=0;W<8;W++){const z=16-Q+W*Z+K&15;H.setVecS16(q,W,H.loadU8(X+z)<<Y)}},VL=function(J){kY(H.calcVecAddress(J,8),E0(J),L0(J),8,1)},UL=function(J){kY(H.calcVecAddress(J,8),E0(J),L0(J),7,1)},ML=function(J){kY(H.calcVecAddress(J,16),E0(J),L0(J),7,2)},OL=function(J){const q=H.calcVecAddress(J,16),Q=E0(J),Y=L0(J),Z=q&7,K=q&4088,X=H.vecTemp;X.setInt16(0,H.loadU8(K+(Z+0-Y&15))<<7,!1),X.setInt16(2,H.loadU8(K+(Z+4-Y&15))<<7,!1),X.setInt16(4,H.loadU8(K+(Z+8-Y&15))<<7,!1),X.setInt16(6,H.loadU8(K+(Z+12-Y&15))<<7,!1),X.setInt16(8,H.loadU8(K+(Z+8-Y&15))<<7,!1),X.setInt16(10,H.loadU8(K+(Z+12-Y&15))<<7,!1),X.setInt16(12,H.loadU8(K+(Z+0-Y&15))<<7,!1),X.setInt16(14,H.loadU8(K+(Z+4-Y&15))<<7,!1);const W=Math.min(8,16-Y);for(let z=Y,F=Y+W;z<F;z++)H.setVecS8(Q,z,X.getInt8(z,!1))},AL=function(J){},hL=function(J){const q=H.calcVecAddress(J,16),Q=E0(J),Y=L0(J),Z=Q&~7,K=Y>>1,X=q&~7,W=(q&8)+Y;for(let z=0;z<8;z++){const F=K+z&7;H.setVecS8(Z+F,z*2+0,H.loadU8(X+(W+z*2+0&15))),H.setVecS8(Z+F,z*2+1,H.loadU8(X+(W+z*2+1&15)))}},EL=function(J){Dq(J,1)},wL=function(J){Dq(J,2)},kL=function(J){Dq(J,4)},CL=function(J){Dq(J,8)},DL=function(J){const q=H.calcVecAddress(J,16),Q=(q&4080)+16,Y=E0(J),Z=L0(J);let K=Q-q;for(let X=0;X<K;X++)H.store8(q+X,H.getVecS8(Y,Z+X&15))},yL=function(J){const q=H.calcVecAddress(J,16),Q=q&4080,Y=E0(J),Z=L0(J),K=q&15,X=16-K+Z,W=K;for(let z=0;z<W;z++)H.store8(Q+z,H.getVecS8(Y,X+z&15))},IL=function(J){const q=H.calcVecAddress(J,8),Q=E0(J),Y=L0(J);for(let Z=0;Z<8;Z++){const K=Y+Z,X=K&8?7:8,W=H.getVecS16(Q,K&7)>>>X;H.store8(q+Z,W)}},BL=function(J){const q=H.calcVecAddress(J,8),Q=E0(J),Y=L0(J);for(let Z=0;Z<8;Z++){const K=Y+Z,X=K&8?8:7,W=H.getVecS16(Q,K&7)>>>X;H.store8(q+Z,W)}},RL=function(J){const q=H.calcVecAddress(J,16),Q=E0(J),Y=L0(J),Z=q&7,K=q-Z;for(let X=0;X<8;X++){const W=Y+X*2,z=Z+X*2&15,F=H.getVecU16UnalignedWrap(Q,W)>>>7;H.store8(K+z,F)}},TL=function(J){const q=H.calcVecAddress(J,16),Q=E0(J),Y=L0(J),Z=q&7,K=q-Z,X=bL.get(Y);if(X)for(let W=0;W<4;W++){const z=Z+W*4&15;H.store8(K+z,H.getVecU16(Q,X[W])>>>7)}else for(let W=0;W<4;W++){const z=Z+W*4&15;H.store8(K+z,0)}},_L=function(J){const q=H.calcVecAddress(J,16),Q=E0(J),Y=L0(J),Z=q&7,K=q-Z;for(let X=0;X<16;X++){const W=Y+X&15,z=Z+X&15;H.store8(K+z,H.getVecS8(Q,W))}},SL=function(J){const q=H.calcVecAddress(J,16),Q=E0(J),Y=L0(J),Z=q&4088,K=q&15,X=q&8,W=Q&~7,z=Y-(q&8)>>1;for(let F=0;F<16;F++){const j=Z+(K+F&15),G=W+(z+(F>>1)&7),P=X+F&15;H.store8(j,H.getVecS8(G,P))}};window.n64js=window.n64js||{};var H,wY=31,w$=0,k$=1,C$=2,D$=3,y$=4,I$=5,B$=6,R$=7,AY=8,b$=9,T$=10,_$=11,S$=12,v$=13,f$=14,u$=15;var xN=1,pN=2;class o${constructor(J){this.hardware=J,this.dmem=J.sp_mem.subRegion(0,4096),this.imem=J.sp_mem.subRegion(4096,4096),this.halted=!0,this.runEvent=null,this.pcDataView=J.sp_ibist_mem.dataView,this.pc=0,this.delayPC=0,this.nextPC=0,this.branchTarget=0;const q=new ArrayBuffer(128);this.gprU32=new Uint32Array(q),this.gprS32=new Int32Array(q);const Q=new ArrayBuffer(512);this.vpr=new DataView(Q),this.vprS16=new Int16Array(Q),this.vprS8=new Int8Array(Q),this.vprU64=new BigUint64Array(Q);const Y=new ArrayBuffer(64);this.vAcc=new BigInt64Array(Y),this.vAccS32=new Int32Array(Y),this.vAccU32=new Uint32Array(Y),this.vAccS16=new Int16Array(Y),this.vAccU16=new Uint16Array(Y),this.vuVCOReg=new Uint16Array(new ArrayBuffer(2)),this.vuVCCReg=new Uint16Array(new ArrayBuffer(2)),this.vuVCEReg=new Uint8Array(new ArrayBuffer(1)),this.divDP=!1,this.divIn=0,this.divOut=0,this.vecSelectU32=new Uint32Array(new ArrayBuffer(64)),this.vecSelectU32[0]=1985229328,this.vecSelectU32[1]=1985229328,this.vecSelectU32[2]=1715741184,this.vecSelectU32[3]=2002072337,this.vecSelectU32[4]=1145307136,this.vecSelectU32[5]=1431638289,this.vecSelectU32[6]=1717969442,this.vecSelectU32[7]=2004300595,this.vecSelectU32[8]=0,this.vecSelectU32[9]=286331153,this.vecSelectU32[10]=572662306,this.vecSelectU32[11]=858993459,this.vecSelectU32[12]=1145324612,this.vecSelectU32[13]=1431655765,this.vecSelectU32[14]=1717986918,this.vecSelectU32[15]=2004318071;const Z=new ArrayBuffer(128);this.vecTemp=new DataView(Z),this.vecTempU64=new BigUint64Array(Z),this.reset()}reset(){this.halted=!0,this.runEvent=null,this.pc=0,this.delayPC=0,this.nextPC=0,this.branchTarget=0;for(let J=0;J<32;++J){this.gprS32[J]=0;for(let q=0;q<8;q++)this.vprS16[J*8+q]=0}this.vAcc[0]=0n,this.vuVCOReg[0]=0,this.vuVCCReg[0]=0,this.vuVCEReg[0]=0,this.divDP=!1,this.divIn=0,this.divOut=0}getRegS32(J){return this.gprS32[J]}getRegU32(J){return this.gprU32[J]}setRegS32(J,q){if(J!=0)this.gprS32[J]=q}setRegU32(J,q){if(J!=0)this.gprU32[J]=q}setRegS16SignExtend(J,q){if(J!=0)this.gprS32[J]=q<<16>>16}getAccS48(J){return this.vAcc[J]}setAccS48(J,q){this.vAcc[J]=BigInt.asIntN(48,q)}updateAcc32Signed(J,q,Q){if(Q)this.setAccS48(J,this.vAcc[J]+BigInt(q));else this.vAccS32[J*2+1]=q>=0?0:4294967295,this.vAccS32[J*2+0]=q}updateAccU32(J,q,Q){if(Q)this.setAccS48(J,this.vAcc[J]+BigInt(q));else this.vAccU32[J*2+1]=0,this.vAccU32[J*2+0]=q}updateAcc32SignedShift16(J,q,Q){if(Q)this.setAccS48(J,this.vAcc[J]+(BigInt(q)<<16n));else this.vAccS32[J*2+1]=q>>16,this.vAccS32[J*2+0]=q<<16}setAccLow(J,q){this.vAccS16[J*4+0]=q}getAccLow(J){return this.vAccS16[J*4+0]}setAccMid(J,q){this.vAccS16[J*4+1]=q}getAccMid(J){return this.vAccS16[J*4+1]}setAccHigh(J,q){this.vAccS16[J*4+2]=q}getAccHigh(J){return this.vAccS16[J*4+2]}getAccHighMid(J){return this.vAccS16[J*4+2]<<16|this.vAccU16[J*4+1]}setVecFromAccSignedMid(J){for(let q=0;q<8;q++){const Q=this.getAccHighMid(q);let Y;if(Q>=0)Y=Q&4294934528?32767:Q;else Y=~Q&4294934528?32768:Q;this.setVecS16(J,q,Y)}}setVecFromAccSignedLow(J){for(let q=0;q<8;q++){const Q=this.getAccHighMid(q),Y=this.getAccLow(q);let Z;if(Q>=0)Z=Q&4294934528?65535:Y;else Z=~Q&4294934528?0:Y;this.setVecS16(J,q,Z)}}setVecFromAccOddified(J){for(let q=0;q<8;q++)this.setVecS16(J,q,CG(this.vAcc[q]>>1n,16n,32768,32767)&65520)}setVecFromAccUnsignedMid(J){for(let q=0;q<8;q++)this.setVecS16(J,q,DG(this.vAcc[q],16n,0,65535))}setVecFromAccMid(J){for(let q=0;q<8;q++)this.setVecS16(J,q,this.getAccMid(q))}setVecFromAccLow(J){for(let q=0;q<8;q++)this.setVecS16(J,q,this.getAccLow(q))}get VCO(){return this.vuVCOReg[0]}get VCOHi(){return this.vuVCOReg[0]>>>8&255}get VCOLo(){return this.vuVCOReg[0]>>>0&255}get VCC(){return this.vuVCCReg[0]}get VCCHi(){return this.vuVCCReg[0]>>>8&255}get VCCLo(){return this.vuVCCReg[0]>>>0&255}get VCE(){return this.vuVCEReg[0]}set VCO(J){this.vuVCOReg[0]=J}set VCC(J){this.vuVCCReg[0]=J}set VCE(J){this.vuVCEReg[0]=J}setVCOHiLo(J,q){this.vuVCOReg[0]=J<<8|q}setVCCHiLo(J,q){this.vuVCCReg[0]=J<<8|q}getVecS16(J,q){return this.vpr.getInt16(16*J+q*2,!1)}getVecU16(J,q){return this.vpr.getUint16(16*J+q*2,!1)}getVecS8(J,q){return this.vpr.getInt8(16*J+q,!1)}getVecU8(J,q){return this.vpr.getUint8(16*J+q,!1)}setVecZero(J){this.vprU64[J*2+0]=0n,this.vprU64[J*2+1]=0n}setVecFromTemp(J){this.vprU64[J*2+0]=this.vecTempU64[0],this.vprU64[J*2+1]=this.vecTempU64[1]}setVecS16(J,q,Q){this.vpr.setInt16(16*J+q*2,Q,!1)}setVecS8(J,q,Q){this.vpr.setInt8(16*J+q,Q,!1)}getVecU16UnalignedWrap(J,q){const Q=this.getVecU8(J,q&15),Y=this.getVecU8(J,q+1&15);return Q<<8|Y}setVecU16UnalignedNoWrap(J,q,Q){if(this.setVecS8(J,q+0,Q>>8),q<15)this.setVecS8(J,q+1,Q)}sprintVecReg(J){let q=[];for(let Q=0;Q<8;Q++)q.push(r(this.getVecS16(J,Q)));return`V${J}: [${q.join(", ")}]`}loadU8(J){return this.dmem.getU8(J&4095)}loadU16(J){return J<=4094?this.dmem.getU16(J):this.loadU16Wrapped(J)}loadU32(J){return J<=4092?this.dmem.getU32(J):this.loadU32Wrapped(J)}loadS8(J){return this.dmem.getS8(J&4095)}loadS16(J){return J<=4094?this.dmem.getS16(J):this.loadS16Wrapped(J)}loadS32(J){return J<=4092?this.dmem.getS32(J):this.loadS32Wrapped(J)}store8(J,q){return this.dmem.set8(J&4095,q)}store16(J,q){return J<=4094?this.dmem.set16(J,q):this.store16Wrapped(J,q)}store32(J,q){return J<=4092?this.dmem.set32(J,q):this.store32Wrapped(J,q)}store32masked(J,q,Q){const Z=this.loadU32(J,!1)&~Q|q&Q;this.store32(J,Z)}loadU16Wrapped(J){return(this.loadU8(J+0)<<8|this.loadU8(J+1)<<0)>>>0}loadS16Wrapped(J){return this.loadU16Wrapped(J)<<16>>16}loadU32Wrapped(J){return(this.loadU8(J+0)<<24|this.loadU8(J+1)<<16|this.loadU8(J+2)<<8|this.loadU8(J+3)<<0)>>>0}loadS32Wrapped(J){return this.loadU32Wrapped(J)>>0}store16Wrapped(J,q){this.store8(J+0,q>>>8),this.store8(J+1,q>>>0)}store32Wrapped(J,q){this.store8(J+0,q>>>24),this.store8(J+1,q>>>16),this.store8(J+2,q>>>8),this.store8(J+3,q>>>0)}calcDebuggerAddress(J){return this.calcAddress(J)+2751463424}calcAddress(J){return this.getRegS32(gN(J))+b8(J)&4095}calcVecAddress(J,q){return this.getRegS32(vN(J))+fN(J)*q&4095}conditionalBranch(J,q){const Q=J?q*4:4;this.branchTarget=this.pc+4+Q&4092}jump(J){this.branchTarget=J>>>0&4092}get pc(){return this.pcDataView.getInt32(0,!1)}set pc(J){this.pcDataView.setUint32(0,J,!1)}unhalt(){if(this.halted=!1,this.runEvent)this.runEvent.stop();this.runEvent=this.hardware.timeline.startEvent("RSP")}step(){if(this.halted)return;this.nextPC=this.delayPC||this.pc+4&4092;const J=this.imem.getU32(this.pc);this.branchTarget=0,this.executeOp(J),this.pc=this.nextPC,this.delayPC=this.branchTarget}halt(J){if(this.hardware.spRegDevice.setStatusBits(J|xN),this.halted=!0,this.runEvent)this.runEvent.stop(),this.runEvent=null}disassembleAll(){const J=xJ(this.imem,0,4096);for(let q of J)console.log(`${B(q.address,16)} ${q.disassembly}`)}disassembleOp(J,q){const Q=XJ(J,q);console.log(`${B(Q.address,16)} ${Q.disassembly}`)}executeOp(J){sN[SN(J)](J)}moveFromControl(J){switch(J){case w$:case k$:case C$:case D$:case y$:case I$:case B$:case R$:return this.hardware.spRegDevice.readRegU32(g$(J));case AY:case b$:case T$:case _$:case S$:case v$:case f$:case u$:return this.hardware.dpcDevice.readRegU32(x$(J))}return console.log(`MFC0: ${J} unhandled - returning 0`),0}moveToControl(J,q){switch(J){case w$:case k$:case C$:case D$:case y$:case I$:case B$:case R$:this.hardware.spRegDevice.writeReg32(g$(J),q);break;case AY:case b$:case T$:case _$:case S$:case v$:case f$:case u$:this.hardware.dpcDevice.writeReg32(x$(J),q);break;default:console.log(`Unhandled RSP MTC0 register: ${J} = ${N(q)}`);break}}}var mN=(()=>{let J=[];for(let q=0;q<64;q++)J[q]=x6;return J[0]=iN,J[2]=tN,J[3]=eN,J[4]=JG,J[6]=qG,J[7]=QG,J[8]=YG,J[9]=ZG,J[13]=KG,J[32]=XG,J[33]=WG,J[34]=$G,J[35]=zG,J[36]=HG,J[37]=FG,J[38]=jG,J[39]=NG,J[42]=GG,J[43]=PG,J})(),nN=(()=>{let J=[];for(let q=0;q<32;q++)J.push(x6);return J[0]=LG,J[1]=VG,J[16]=UG,J[17]=MG,J})(),oN=(()=>{let J=[];for(let q=0;q<32;q++)J.push(x6);return J[0]=OG,J[4]=AG,J})(),cN=(()=>{let J=[];for(let q=0;q<32;q++)J.push(x6);J[0]=hG,J[2]=wG,J[4]=EG,J[6]=kG;for(let q=16;q<32;q++)J[q]=dN;return J})(),lN=(()=>{let J=[];for(let q=0;q<64;q++)J.push(x6);return J[0]=dG,J[1]=aG,J[2]=tG,J[3]=WP,J[4]=eG,J[5]=qP,J[6]=YP,J[7]=KP,J[8]=rG,J[9]=sG,J[10]=iG,J[11]=$P,J[12]=JP,J[13]=QP,J[14]=ZP,J[15]=XP,J[16]=zP,J[17]=HP,J[18]=yG,J[19]=jP,J[20]=NP,J[21]=GP,J[22]=IG,J[23]=BG,J[24]=RG,J[25]=bG,J[26]=TG,J[27]=_G,J[28]=SG,J[29]=UP,J[30]=vG,J[31]=fG,J[32]=MP,J[33]=OP,J[34]=AP,J[35]=hP,J[36]=EP,J[37]=wP,J[38]=kP,J[39]=CP,J[40]=DP,J[41]=yP,J[42]=IP,J[43]=BP,J[44]=RP,J[45]=bP,J[46]=uG,J[47]=gG,J[48]=_P,J[49]=SP,J[50]=vP,J[51]=TP,J[52]=fP,J[53]=uP,J[54]=gP,J[55]=xP,J[56]=xG,J[57]=pG,J[58]=mG,J[59]=nG,J[60]=oG,J[61]=cG,J[62]=lG,J[63]=pP,J})(),aN=(()=>{let J=[];for(let q=0;q<32;q++)J.push(x6);return J[0]=FL,J[1]=jL,J[2]=NL,J[3]=GL,J[4]=PL,J[5]=LL,J[6]=VL,J[7]=UL,J[8]=ML,J[9]=OL,J[10]=AL,J[11]=hL,J})(),rN=(()=>{let J=[];for(let q=0;q<32;q++)J.push(x6);return J[0]=EL,J[1]=wL,J[2]=kL,J[3]=CL,J[4]=DL,J[5]=yL,J[6]=IL,J[7]=BL,J[8]=RL,J[9]=TL,J[10]=_L,J[11]=SL,J})(),sN=(()=>{let J=[];for(let q=0;q<64;q++)J.push(x6);return J[0]=(q)=>mN[m$(q)](q),J[1]=(q)=>nN[v(q)](q),J[2]=mP,J[3]=nP,J[4]=oP,J[5]=cP,J[6]=lP,J[7]=dP,J[8]=aP,J[9]=rP,J[10]=sP,J[11]=iP,J[12]=tP,J[13]=eP,J[14]=JL,J[15]=qL,J[16]=(q)=>oN[d(q)](q),J[18]=(q)=>cN[d(q)](q),J[32]=QL,J[33]=ZL,J[35]=XL,J[36]=YL,J[37]=KL,J[39]=WL,J[40]=$L,J[41]=zL,J[43]=HL,J[50]=(q)=>aN[Q0(q)](q),J[58]=(q)=>rN[Q0(q)](q),J})(),PP=8,LP=9,VP=10,bL=new Map([[0,[0,1,2,3]],[1,[6,7,4,5]],[4,[1,2,3,0]],[5,[7,4,5,6]],[8,[4,5,6,7]],[11,[3,0,1,2]],[12,[5,6,7,4]],[15,[0,1,2,3]]]);function $7(J){V=J.cpu0,l=J.cpu1,q8=J.cpu2,z$(J,V),n64js.cpu0=V}var OV=function(J){return J>>>13},AV=function(J){return(J&wJ)>>dL},hV=function(J){return(J&BY)>>lL},RY=function(J,q,Q){return(~(J^q)&(Q^J)&H7)!=0},j7=function(J,q,Q){return((J^q)&(Q^J)&H7)!=0},bY=function(J,q,Q){return(~(J^q)&(Q^J)&F7)!=0n},N7=function(J,q,Q){return((J^q)&(Q^J)&F7)!=0n},_Y=function(J){return J>>13&4095},wV=function(J){const Q=_Y(J)&2730;return(Q|Q>>1)<<13},kV=function(J){const q=_Y(J);if(q&2048)return 1<<24;if(q&512)return 1<<22;if(q&128)return 1<<20;if(q&32)return 1<<18;if(q&8)return 1<<16;if(q&2)return 1<<14;return 1<<12},CV=function(J){const q=EV.get(J);if(q)return q;return`Unknown(${_Y(J).toString(2)})`};var k=function(J){throw`CPU: unknown op, pc: ${N(V.pc)}, instruction: ${N(J)}`},X7=function(){},DV=function(J){return J&~3758096384},W7=function(J){return DV(J>>>0)>>>4},yV=function(J){a((J>>>18&7)===0,"cc bit is not 0");const q=(J&65536)!==0,Q=(J&131072)!==0,Z=(l.control[31]&z7)!==0===q;if(Q)V.conditionalBranchLikely(Z,q0(J));else V.conditionalBranch(Z,q0(J))},IV=function(J){if(J.length!=64)throw"Special table is unexpected size.";return J},RV=function(J){BV[H8(J)](J)},fY=function(J){if(J.length!=32)throw"Cop table is unexpected size.";return J},TV=function(J){bV[f0(J)](J)},SV=function(J){_V[f0(J)](J)},fV=function(J){vV[f0(J)](J)},uV=function(J){V.raiseRESERVEDException(0)},uY=function(J){a((V.getControlU32(U0)&TY)===0,"SR_CU1 in inconsistent state"),V.raiseCopXUnusable(1)},gV=function(J){if(J.length!=32)throw"RegImm table is unexpected size.";return J},pV=function(J){return xV[z8(J)](J)},mV=function(J){if(J.length!=64)throw"Simple table is unexpected size.";return J},P7=function(J){return L7[$8(J)](J)},nV=function(J,q,Q){return J-=q,J-=Q,J^=Q>>>13,q-=Q,q-=J,q^=J<<8,Q-=J,Q-=q,Q^=q>>>13,J-=q,J-=Q,J^=Q>>>12,q-=Q,q-=J,q^=J<<16,Q-=J,Q-=q,Q^=q>>>5,J-=q,J-=Q,J^=Q>>>3,q-=Q,q-=J,q^=J<<10,Q-=J,Q-=q,Q^=q>>>15,J},oV=function(J,q){if(!J.sync32(q,"pc"))return!1;{let Q=0;for(let Y=0;Y<32;++Y)Q=nV(Q,V.getRegU32Lo(Y),0);if(Q=Q>>>0,!J.sync32(Q,"regs"))return!1}return!0},cV=function(J,q,Q){if(Q.nextEventCountdown()<J.opsCompiled*_8)return null;J.executionCount++;const Y=J.func(),Z=Y*_8;if(!e6)q.incrementCount(Z);return Q.incrementCount(Z),J.getNextFragment(q.pc,Y)},lV=function(J,q,Q,Y){if(a(!J.func,`attempting to append op to already-compiled fragment ${N(J.entryPC)}`),J.opsCompiled===0)S8.newFragment();J.opsCompiled++,U7.addInstructionToFragment(J,q),J.bodyCode+="rsp.step();\n",J.bodyCode+=`if (c.stuffToDo) { return ${J.opsCompiled-1}; }\n`,J.bodyCode+="\n";const Z=q,K=Y.pc;if(S8.set(J,Z,Q,K,Y.nextPC),O$(S8),J.opsCompiled>8&&Y.pc!==q+4||J.opsCompiled>=vL||Y.stuffToDo)dV(J),J=G8(Y.pc);else J.bodyCode+=`// Keep going: ops ${J.opsCompiled}, pc: ${N(Y.pc)}, entry+4: ${N(q+4)}, stuff: ${Y.stuffToDo}\n`;return J},dV=function(J){let q="";if(n64js.getSyncFlow())q+="const sync = n64js.getSyncFlow();\n";if(J.usesCop1)q+=`const SR_CU1 = ${N(TY)};\n`,q+=`const FPCSR_C = ${N(z7)};\n`;if(S8.delayedPCUpdate!==0)J.bodyCode+=`c.pc = ${N(S8.delayedPCUpdate)};\n`,S8.delayedPCUpdate=0;J.bodyCode+=`return ${J.opsCompiled};\n`;const Y=`
|
|
return function fragment_${N(J.entryPC)}_${J.opsCompiled}() {
|
|
${q}
|
|
${J.bodyCode}
|
|
}`;J.bodyCode="",J.func=new Function("c","cpu1","rsp",Y)(V,l,H),J.nextFragments=[];for(let Z=0;Z<J.opsCompiled;Z++)J.nextFragments.push(void 0)};window.n64js=window.n64js||{};var V,l,q8,Bq=!1,vL=250,_8=1,e$=2147483648;var _0=2147484032,Rq=1,hJ=2,EJ=4;var fL=67108864;var TY=536870912;var uL=28,gL=0xfff7_ffffn,J7=2147483648,xL=805306368,pL=28,mL=256,nL=512,CY=1024;var q7=32768,oL=65280;var Q7=124,cL=BigInt(mL|nL);var z7=8388608;var BY=0xc000000000000000n,lL=62n,wJ=0x000000ffffffe000n,dL=13n,OJ=0xffn,aL=0xc00000ffffffe0ffn;var rL=4,DY=2,yY=1,sL=0x3fffffffn,iL=2147483648;var tL=0x8000003fn;var eL=0x3fn;var JV=8388592,qV=4,QV=~0x7fffffn,YV=0x7fff_fff0n,ZV=4n,KV=0x1_8000_0000n,XV=31n,WV=0xfffffffe_00000000n,$V=0,zV=24576,HV=122880,FV=516096,jV=2088960,NV=8380416,GV=33546240,PV=8191,LV=0x01ffe000n,VV=0x0f00800fn,UV=0xffffffffn,MV=0xffn,IY=1<<0,yq=1<<1,Y7=1<<2,Z7="Compare",AJ="Run For Cycles";n64js.getSyncFlow=()=>n6;var H7=2147483648,F7=0x8000_0000_0000_0000n,Iq=4294967295,q6=0xffff_ffff_ffff_ffffn,K7=0xffff_ffffn;n64js.s32CheckAddOverflow=RY;n64js.s32CheckSubOverflow=j7;n64js.s64CheckAddOverflow=bY;n64js.s64CheckSubOverflow=N7;class G7{constructor(){this.pagemask=0,this.hi=0n,this.pfne=0,this.pfno=0,this.global=0,this.offsetMask=0,this.vpnmask64=wJ,this.vpn2bits=0n,this.physEven=0,this.physOdd=0,this.checkbit=0}update(J,q,Q,Y,Z){if(Bq)M(`TLB update: index=${J}, pagemask=${N(q)}, entryhi=${y6(Q)}, entrylo0=${N(Y)}, entrylo1=${N(Z)}`),M(` ${CV(q)} Pagesize`);const K=Y&Z&yY;this.pagemask=wV(q),this.hi=Q,this.pfne=Y&~yY|K,this.pfno=Z&~yY|K,this.global=K,this.offsetMask=(this.pagemask|PV)>>>1,this.vpnmask64=wJ&BigInt(~this.pagemask),this.vpn2bits=Q&this.vpnmask64,this.physEven=this.pfne<<6&~this.offsetMask,this.physOdd=this.pfno<<6&~this.offsetMask,this.checkbit=kV(this.pagemask)}}var EV=new Map([[$V,"4k"],[zV,"16k"],[HV,"64k"],[FV,"256k"],[jV,"1M"],[NV,"4M"],[GV,"16M"]]);class SY{constructor(J){this.hardware=J,this.opsExecuted=0,this.ramDV=J.cachedMemDevice.mem.dataView;const q=new ArrayBuffer(256);this.gprU32=new Uint32Array(q),this.gprS32=new Int32Array(q),this.gprU64=new BigUint64Array(q),this.gprS64=new BigInt64Array(q);const Q=new ArrayBuffer(256);this.controlRegU32=new Uint32Array(Q),this.controlRegS32=new Int32Array(Q),this.controlRegU64=new BigUint64Array(Q),this.controlRegS64=new BigInt64Array(Q),this.controlCountValue=0,this.lastControlRegWrite=0n,this.pc=0,this.delayPC=0,this.nextPC=0,this.branchTarget=0,this.llBit=0,this.stuffToDo=0,this.eventQueue=new LY;const Y=new ArrayBuffer(8);this.multHiU32=new Uint32Array(Y),this.multHiS32=new Int32Array(Y),this.multHiU64=new BigUint64Array(Y),this.multHiS64=new BigInt64Array(Y);const Z=new ArrayBuffer(8);this.multLoU32=new Uint32Array(Z),this.multLoS32=new Int32Array(Z),this.multLoU64=new BigUint64Array(Z),this.multLoS64=new BigInt64Array(Z),this.tlbEntries=[];for(let K=0;K<32;++K)this.tlbEntries.push(new G7);this.loadU8fast=HY,this.loadU16fast=jY,this.loadU32fast=LJ,this.loadU64fast=t6,this.loadS8fast=FY,this.loadS16fast=NY,this.loadS32fast=VJ,this.store8fast=GY,this.store16fast=PY,this.store32fast=UJ,this.store64fast=MJ,this.store32masked=zq,this.store64masked=Hq,this.reset()}conditionalBranch(J,q){const Q=J?q*4:4;this.branchTarget=this.pc+4+Q}conditionalBranchLikely(J,q){if(J)this.branchTarget=this.pc+4+q*4;else this.nextPC+=4}jump(J){this.branchTarget=J}getOpsExecuted(){return this.controlCountValue}incrementCount(J){this.controlCountValue+=J}getRegS32Lo(J){return this.gprS32[J*2+0]}getRegU32Lo(J){return this.gprU32[J*2+0]}getRegS64(J){return this.gprS64[J]}getRegU64(J){return this.gprU64[J]}setRegU64(J,q){if(J==0)return;const Q=q&q6;this.gprU64[J]=Q}setRegU64Masked(J,q,Q){if(J==0)return;this.gprU64[J]=this.gprU64[J]&~Q|q&Q}setRegS64LoHi(J,q,Q){if(J==0)return;this.gprS32[J*2+0]=q,this.gprS32[J*2+1]=Q}setRegS32ExtendMasked(J,q,Q){if(J==0)return;const Y=this.gprS32[J*2+0]&~Q|q&Q;this.gprS32[J*2+0]=Y,this.gprS32[J*2+1]=Y>>31}setRegS32Extend(J,q){if(J==0)return;this.gprS32[J*2+0]=q,this.gprS32[J*2+1]=q>>31}setRegU32Extend(J,q){if(J==0)return;this.gprU32[J*2+0]=q,this.gprU32[J*2+1]=0}getMultLoS64(){return this.multLoS64[0]}getMultLoU64(){return this.multLoU64[0]}setMultLoS32Extend(J){this.multLoS64[0]=BigInt.asIntN(32,J)}setMultLoS64(J){this.multLoS64[0]=J}setMultLoU64(J){this.multLoU64[0]=J}getMultHiS64(){return this.multHiS64[0]}getMultHiU64(){return this.multHiU64[0]}setMultHiS32Extend(J){this.multHiS64[0]=BigInt.asIntN(32,J)}setMultHiS64(J){this.multHiS64[0]=J}setMultHiU64(J){this.multHiU64[0]=J}setControlU32(J,q){this.controlRegU32[J*2+0]=q}setControlS32(J,q){this.controlRegS32[J*2+0]=q}getControlU32(J){return this.controlRegU32[J*2+0]}getControlS32(J){return this.controlRegS32[J*2+0]}setControlS32Extend(J,q){this.controlRegS32[J*2+0]=q,this.controlRegS32[J*2+1]=q>>31}setControlU64(J,q){this.controlRegU64[J]=q}setControlS64(J,q){this.controlRegS64[J]=q}getControlU64(J){return this.controlRegU64[J]}getControlS64(J){return this.controlRegS64[J]}maskControlBits32(J,q,Q){const Y=J*2+0;this.controlRegU32[Y]=this.controlRegU32[Y]&~q|Q&q}setControlBits32(J,q){this.controlRegU32[J*2+0]|=q}clearControlBits32(J,q){this.controlRegU32[J*2+0]&=~q}maskControlBits64(J,q,Q){this.controlRegU64[J]=this.controlRegU64[J]&~q|Q&q}setControlBits64(J,q){this.controlRegU64[J]|=q}clearControlBits64(J,q){this.controlRegU64[J]&=~q}reset(){HX();for(let J=0;J<32;++J)this.gprU64[J]=0n,this.controlRegU64[J]=0n;for(let J=0;J<32;++J)this.tlbEntries[J].update(J,0,0x80000000n,0,0);this.pc=0,this.delayPC=0,this.nextPC=0,this.branchTarget=0,this.stuffToDo=0,this.eventQueue.reset(),this.multLoU32[0]=this.multLoU32[1]=0,this.multHiU32[0]=this.multHiU32[1]=0,this.setControlU32(l8,31),this.setControlU32(U0,1883242500),this.setControlU32(t8,1879499875),this.cop1ControlChanged()}cop1ControlChanged(){const J=this.getControlU32(U0),q=(J&TY)!==0;if(L7[17]=q?SV:uY,this.hardware.cpu1)this.hardware.cpu1.fullMode=(J&fL)!==0}moveToControl(J,q){switch(this.lastControlRegWrite=q,J){case Z8:this.setControlU64(J,q&tL);break;case d8:case a8:this.setControlU64(J,q&sL);break;case r8:this.setControlU64(J,q&QV);break;case s8:this.setControlU64(J,q&LV);break;case uq:this.setControlU64(J,q&eL),this.setControlU64(l8,31n);break;case D6:this.setControlU64(J,q&aL);break;case l8:case i8:case _J:case oZ:break;case t8:this.maskControlBits64(J,VV,q);break;case k0:M(`Setting cause register to ${N(q)}`),n64js.check(q===0,"Should only write 0 to Cause register."),this.maskControlBits64(J,cL,q);break;case U0:this.setControlU64(J,q&gL),this.statusRegisterChanged();break;case m6:this.controlCountValue=Number(q)*2;break;case K8:this.setCompare(Number(q&0xffff_ffffn));break;case xq:this.maskControlBits64(J,WV,q);break;case G6:case cZ:case lZ:this.setControlU64(J,q);break;case SJ:this.maskControlBits64(J,UV,q);break;case gq:case pq:case mq:case nq:case oq:case cq:case lq:break;case nZ:this.setControlU64(J,q&MV);break;case e8:this.setControlU64(J,q);break;default:this.setControlU64(J,q),M(`Write to cpu0 control register. ${y6(q)} --> ${j8[J]}`);break}}moveFromControl(J){if(J===k0)this.checkCauseIP3Consistent();switch(J){case l8:return BigInt(this.getRandom());case gq:case pq:case mq:case nq:case oq:case cq:case lq:return this.lastControlRegWrite;case m6:return BigInt(this.controlCountValue)>>1n;default:return this.getControlU64(J)}}breakExecution(){this.stuffToDo|=IY}run(J){this.stuffToDo&=~IY,this.checkCauseIP3Consistent(),n64js.hardware().checkSIStatusConsistent(),this.addRunForCyclesEvent(J);while(this.hasEvent(AJ))try{this.runImpl();break}catch(Q){if(Q instanceof E6)this.handleEmulatedException();else if(Q instanceof X7)n64js.stopForBreakpoint();else{n64js.halt("Exception :"+Q);break}}let q=this.removeEvent(AJ);if(q<0)q=0;if(q<J)this.opsExecuted+=J-q}runImpl(){const J=this.eventQueue,q=this.ramDV;while(this.hasEvent(AJ)){let Q=G8(this.pc);while(!this.stuffToDo)if(Q&&Q.func)Q=cV(Q,this,J);else{if(H.step(),this.stuffToDo)break;const Y=this.pc|0;this.nextPC=this.delayPC||this.pc+4;let Z;if((Y&3)!=0){this.raiseAdELException(Y),this.pc=this.nextPC,Q=G8(this.pc);continue}else if(Y<-2139095040){const K=Y+2147483648|0;Z=q.getInt32(K,!1)}else Z=zY(Y>>>0);if(this.branchTarget=0,P7(Z),this.pc=this.nextPC,this.delayPC=this.branchTarget,this.incrementCount(_8),J.incrementCount(_8),Q)Q=lV(Q,Y>>>0,Z,this);else if(this.pc<Y)Q=G8(this.pc)}if(this.stuffToDo&=~Y7,this.stuffToDo&yq)this.stuffToDo&=~yq,this.handleInterrupt();else if(this.stuffToDo&IY)break;else if(this.stuffToDo){n64js.warn("Don't know how to handle this event!");break}}}handleEmulatedException(){this.pc=this.nextPC,this.delayPC=0,this.branchTarget=0,this.incrementCount(_8),this.eventQueue.incrementCount(_8)}speedHack(){if(!H.halted)return;if(n64js.hardware().memMap.readMemoryInternal32(this.pc+4)!==0)return;const q=this.removeEvent(AJ),Q=this.eventQueue.skipToNextEvent(1);if(this.controlCountValue+=Q,q>=0)this.addRunForCyclesEvent(q)}updateCause3(){if(n64js.hardware().miRegDevice.interruptsUnmasked())this.setControlBits32(k0,CY),this.updateStuffToDoForInterrupts();else this.clearControlBits32(k0,CY);this.checkCauseIP3Consistent()}checkCauseIP3Consistent(){const q=n64js.hardware().miRegDevice.interruptsUnmasked(),Q=(this.getControlU32(k0)&CY)!==0;a(q===Q,`CAUSE_IP3 ${Q} inconsistent with MI_INTR_REG ${q}`)}statusRegisterChanged(){this.cop1ControlChanged(),this.updateStuffToDoForInterrupts()}checkForUnmaskedInterrupts(){const J=this.getControlU32(U0);if((J&(hJ|EJ|Rq))===Rq){const q=this.getControlU32(k0);if((J&q&oL)!==0)return!0}return!1}updateStuffToDoForInterrupts(){if(this.checkForUnmaskedInterrupts())this.stuffToDo|=yq;else this.stuffToDo&=~yq}setBadVAddr(J){this.setControlU64(i8,J)}setContext(J){const q=Number(J&0xffffffffn),Q=OV(q)<<qV;this.maskControlBits32(r8,JV,Q)}setXContext(J){const q=AV(J)<<ZV|hV(J)<<XV,Q=YV|KV;this.maskControlBits64(xq,Q,q)}checkCopXUsable(J){const q=1<<uL+J;if((this.getControlU32(U0)&q)==0)return this.raiseCopXUnusable(J),!1;return!0}maybeRaiseTRAPException(J){if(J)this.raiseTRAPException()}raiseCopXUnusable(J){this.raiseExceptionCopCode(_0,J,JK)}raiseSYSCALLException(){this.raiseExceptionCopCode(_0,0,iZ)}raiseBREAKException(){this.raiseExceptionCopCode(_0,0,tZ)}raiseRESERVEDException(J){this.raiseExceptionCopCode(_0,J,eZ)}raiseTRAPException(){this.raiseExceptionCopCode(_0,0,QK)}raiseOverflowException(){this.raiseExceptionCopCode(_0,0,qK)}raiseFPE(){this.raiseExceptionCopCode(_0,0,YK)}raiseAdELException(J){this.raiseAddressException(_0,rZ,J)}raiseAdESException(J){this.raiseAddressException(_0,sZ,J)}raiseTLBException(J,q,Q){const Y=BigInt(Q>>0);this.setBadVAddr(Y),this.setContext(Y),this.setXContext(Y),this.maskControlBits64(D6,wJ,Y),this.raiseExceptionCopCode(J,0,q)}raiseAddressException(J,q,Q){const Y=BigInt(Q>>0);this.setBadVAddr(Y),this.setContext(Y),this.setXContext(Y),this.raiseExceptionCopCode(J,0,q)}raiseExceptionCopCode(J,q,Q){const Y=Q7|xL,Z=Q<<dq,K=q<<pL;this.raiseException(Y,Z|K,J)}raiseException(J,q,Q){if(this.maskControlBits32(k0,J,q),this.setControlBits32(U0,hJ),this.delayPC)this.setControlBits32(k0,J7),this.setControlS32Extend(G6,this.pc-4);else this.clearControlBits32(k0,J7),this.setControlS32Extend(G6,this.pc);this.nextPC=Q}handleInterrupt(){if(this.checkForUnmaskedInterrupts())this.raiseException(Q7,dZ<<dq,_0),this.pc=_0,this.delayPC=0;else a(!1,"Was expecting an unmasked interrupt - something wrong with kStuffToDoCheckInterrupts?")}setCompare(J){if(this.clearControlBits32(k0,q7),J===this.getControlU32(K8));else{const q=this.controlCountValue/2>>0,Q=J-q>>>0;this.removeEvent(Z7),this.addCompareEvent(Q),this.setControlU32(K8,J)}}addEvent(J,q,Q){return this.eventQueue.addEvent(J,q,Q)}removeEvent(J){return this.eventQueue.removeEvent(J)}getCyclesUntilEvent(J){this.eventQueue.getCyclesUntilEvent(J)}hasEvent(J){return this.eventQueue.hasEvent(J)}addCompareEvent(J){const q=this;this.addEvent(Z7,J,()=>{q.setControlBits32(k0,q7),q.updateStuffToDoForInterrupts()})}addRunForCyclesEvent(J){const q=this;this.addEvent(AJ,J,()=>{q.stuffToDo|=Y7})}getRandom(){const J=this.getControlU32(uq),q=J>=32?0:J&31,Q=J>=32?64:32;let Y=Math.floor(Math.random()*(Q-q))+q;if(a(Y>=q&&Y<Q,`Ooops - random should be in range [${q},${Q}), but got ${Y}`),n6)Y=n6.reflect32(Y);return Y}setTLB(J){const q=J&31,Q=this.getControlU32(s8),Y=this.getControlU64(D6),Z=this.getControlU32(a8),K=this.getControlU32(d8);this.tlbEntries[q].update(q,Q,Y,K,Z)}tlbWriteIndex(){this.setTLB(this.getControlU32(Z8))}tlbWriteRandom(){this.setTLB(this.getRandom())}tlbRead(){const J=this.getControlU32(Z8)&31,q=this.tlbEntries[J],Q=(BY|wJ|OJ)&BigInt(~q.pagemask);if(this.setControlU32(s8,q.pagemask),this.setControlU64(D6,q.hi&Q),this.setControlU32(d8,q.pfne&67108863),this.setControlU32(a8,q.pfno&67108863),Bq)M("TLB Read Index "+M0(J)+"."),M(" PageMask: "+N(this.getControlU32(s8))),M(" EntryHi: "+y6(this.getControlU64(D6))),M(" EntryLo0: "+N(this.getControlU32(d8))),M(" EntryLo1: "+N(this.getControlU32(a8)))}tlbProbe(){const J=this.getControlU64(D6),q=J&OJ;for(let Q=0;Q<32;++Q){const Y=this.tlbEntries[Q],Z=Y.vpnmask64|BY;if((Y.hi&Z)!==(J&Z))continue;if(!Y.global&&(Y.hi&OJ)!==q)continue;if(Bq)M("TLB Probe. EntryHi:"+N(J)+". Found matching TLB entry - "+M0(Q));this.setControlU32(Z8,Q);return}if(Bq)M("TLB Probe. EntryHi:"+N(J)+". Didn't find matching entry");this.setControlU32(Z8,iL)}tlbFindEntry(J){const Q=this.getControlU64(D6)&OJ,Y=BigInt(J>>>0);for(let Z=0;Z<32;++Z){const K=this.tlbEntries[Z];if((Y&K.vpnmask64)!==K.vpn2bits)continue;if(!K.global&&(K.hi&OJ)!==Q)continue;return K}return null}translateReadInternal(J){const q=this.tlbFindEntry(J);if(!q)return 0;const Q=J&q.checkbit;if(((Q?q.pfno:q.pfne)&DY)===0)return 0;const Z=Q?q.physOdd:q.physEven,K=J&q.offsetMask;return Z|K}translateRead(J){const q=this.tlbFindEntry(J);if(!q)throw this.raiseTLBException(e$,aq,J),new E6;const Q=J&q.checkbit;if(((Q?q.pfno:q.pfne)&DY)===0)throw this.raiseTLBException(_0,aq,J),new E6;const Z=Q?q.physOdd:q.physEven,K=J&q.offsetMask;return Z|K}translateWrite(J){const q=this.tlbFindEntry(J);if(!q)throw this.raiseTLBException(e$,rq,J),new E6;const Q=J&q.checkbit,Y=Q?q.pfno:q.pfne;if((Y&DY)===0)throw this.raiseTLBException(_0,rq,J),new E6;if((Y&rL)===0)throw this.raiseTLBException(_0,aZ,J),new E6;const Z=Q?q.physOdd:q.physEven,K=J&q.offsetMask;return Z|K}unalignedLoad(J){throw this.raiseAdELException(J),new E6}unalignedStore(J){throw this.raiseAdESException(J),new E6}execBreakpoint(){throw new X7}execSLL(J,q,Q){this.setRegS32Extend(J,this.getRegS32Lo(q)<<Q)}execSRL(J,q,Q){this.setRegS32Extend(J,this.getRegU32Lo(q)>>>Q)}execSRA(J,q,Q){this.setRegS32Extend(J,Number(this.getRegS64(q)>>BigInt(Q)&0xffff_ffffn))}execSLLV(J,q,Q){this.setRegS32Extend(J,this.getRegS32Lo(q)<<(this.getRegS32Lo(Q)&31))}execSRLV(J,q,Q){this.setRegS32Extend(J,this.getRegS32Lo(q)>>>(this.getRegS32Lo(Q)&31))}execSRAV(J,q,Q){this.setRegS32Extend(J,Number(this.getRegS64(q)>>BigInt(this.getRegS32Lo(Q)&31)&0xffff_ffffn))}execDSLLV(J,q,Q){this.setRegU64(J,this.getRegU64(q)<<BigInt(this.getRegU32Lo(Q)&63))}execDSRLV(J,q,Q){this.setRegU64(J,this.getRegU64(q)>>BigInt(this.getRegU32Lo(Q)&63))}execDSRAV(J,q,Q){this.setRegU64(J,this.getRegS64(q)>>BigInt(this.getRegU32Lo(Q)&63))}execDSLL(J,q,Q){this.setRegU64(J,this.getRegU64(q)<<BigInt(Q))}execDSRL(J,q,Q){this.setRegU64(J,this.getRegU64(q)>>BigInt(Q))}execDSRA(J,q,Q){this.setRegU64(J,this.getRegS64(q)>>BigInt(Q))}execDSLL32(J,q,Q){this.setRegU64(J,this.getRegU64(q)<<BigInt(Q+32))}execDSRL32(J,q,Q){this.setRegU64(J,this.getRegU64(q)>>BigInt(Q+32))}execDSRA32(J,q,Q){this.setRegU64(J,this.getRegS64(q)>>BigInt(Q+32))}execRESERVED(J){this.raiseRESERVEDException(J)}execSYSCALL(){this.raiseSYSCALLException()}execBREAK(){this.raiseBREAKException()}execSYNC(){}execMFHI(J){this.setRegU64(J,this.getMultHiU64())}execMFLO(J){this.setRegU64(J,this.getMultLoU64())}execMTHI(J){this.setMultHiU64(this.getRegU64(J))}execMTLO(J){this.setMultLoU64(this.getRegU64(J))}execMULT(J,q){const Q=BigInt(this.getRegS32Lo(q))*BigInt(this.getRegS32Lo(J));this.setMultLoS32Extend(Q&K7),this.setMultHiS32Extend(Q>>32n)}execDMULT(J,q){const Q=this.getRegS64(q)*this.getRegS64(J);this.setMultLoS64(Q&q6),this.setMultHiS64(Q>>64n)}execMULTU(J,q){const Q=BigInt(this.getRegU32Lo(q))*BigInt(this.getRegU32Lo(J));this.setMultLoS32Extend(Q&K7),this.setMultHiS32Extend(Q>>32n)}execDMULTU(J,q){const Q=this.getRegU64(q)*this.getRegU64(J);this.setMultLoU64(Q&q6),this.setMultHiU64(Q>>64n)}execDIV(J,q){const Q=this.getRegS32Lo(q),Y=this.getRegS32Lo(J);let Z,K;if(Y)Z=Q/Y>>0,K=Q%Y;else Z=Q<0?1:-1,K=Q;this.setMultLoS32Extend(BigInt(Z)),this.setMultHiS32Extend(BigInt(K))}execDDIV(J,q){const Q=this.getRegS64(J),Y=this.getRegS64(q);let Z,K;if(Q)Z=Y/Q,K=Y%Q;else Z=Y<0?1n:-1n,K=Y;this.setMultLoS64(Z),this.setMultHiS64(K)}execDIVU(J,q){const Q=this.getRegU32Lo(q),Y=this.getRegU32Lo(J);let Z,K;if(Y)Z=Q/Y>>0,K=Q%Y;else Z=-1,K=Q;this.setMultLoS32Extend(BigInt(Z)),this.setMultHiS32Extend(BigInt(K))}execDDIVU(J,q){const Q=this.getRegU64(J),Y=this.getRegU64(q);let Z,K;if(Q)Z=Y/Q,K=Y%Q;else Z=-1n,K=Y;this.setMultLoU64(Z),this.setMultHiU64(K)}execADD(J,q,Q){const Y=this.getRegS32Lo(Q),Z=this.getRegS32Lo(q),K=Y+Z;if(RY(Y,Z,K)){this.raiseOverflowException();return}this.setRegS32Extend(J,K)}execDADD(J,q,Q){const Y=this.getRegS64(Q),Z=this.getRegS64(q),K=Y+Z;if(bY(Y,Z,K)){this.raiseOverflowException();return}this.setRegU64(J,K)}execADDU(J,q,Q){const Y=this.getRegS32Lo(Q),Z=this.getRegS32Lo(q),K=Y+Z;this.setRegS32Extend(J,K)}execDADDU(J,q,Q){const Y=this.getRegS64(Q),Z=this.getRegS64(q),K=Y+Z;this.setRegU64(J,K)}execSUB(J,q,Q){const Y=this.getRegS32Lo(Q),Z=this.getRegS32Lo(q),K=Y-Z;if(j7(Y,Z,K)){this.raiseOverflowException();return}this.setRegS32Extend(J,K)}execDSUB(J,q,Q){const Y=this.getRegS64(Q),Z=this.getRegS64(q),K=Y-Z;if(N7(Y,Z,K)){this.raiseOverflowException();return}this.setRegU64(J,K)}execSUBU(J,q,Q){const Y=this.getRegS32Lo(Q),Z=this.getRegS32Lo(q),K=Y-Z;this.setRegS32Extend(J,K)}execDSUBU(J,q,Q){const Y=this.getRegS64(Q),Z=this.getRegS64(q),K=Y-Z;this.setRegU64(J,K)}execAND(J,q,Q){this.setRegU64(J,this.getRegU64(Q)&this.getRegU64(q))}execOR(J,q,Q){this.setRegU64(J,this.getRegU64(Q)|this.getRegU64(q))}execXOR(J,q,Q){this.setRegU64(J,this.getRegU64(Q)^this.getRegU64(q))}execNOR(J,q,Q){this.setRegU64(J,~(this.getRegU64(Q)|this.getRegU64(q)))}execCLEAR(J){this.setRegU64(J,0n)}execMOV(J,q){this.setRegU64(J,this.getRegU64(q))}execSLT(J,q,Q){const Y=this.getRegS64(Q)<this.getRegS64(q)?1:0;this.setRegU32Extend(J,Y)}execSLTU(J,q,Q){const Y=this.getRegU64(Q)<this.getRegU64(q)?1:0;this.setRegU32Extend(J,Y)}execADDI(J,q,Q){const Y=this.getRegS32Lo(q),Z=Y+Q;if(RY(Y,Q,Z)){this.raiseOverflowException();return}this.setRegS32Extend(J,Z)}execDADDI(J,q,Q){const Y=this.getRegS64(q),Z=BigInt(Q),K=Y+Z;if(bY(Y,Z,K)){this.raiseOverflowException();return}this.setRegU64(J,K)}execADDIU(J,q,Q){this.setRegS32Extend(J,this.getRegS32Lo(q)+Q)}execDADDIU(J,q,Q){this.setRegU64(J,this.getRegS64(q)+BigInt(Q))}execSLTI(J,q,Q){this.setRegU32Extend(J,this.getRegS64(q)<BigInt(Q)?1:0)}execSLTIU(J,q,Q){const Y=BigInt.asUintN(64,BigInt(Q));this.setRegU32Extend(J,this.getRegU64(q)<Y?1:0)}execANDI(J,q,Q){this.setRegU64(J,this.getRegU64(q)&BigInt(Q))}execORI(J,q,Q){this.setRegU64(J,this.getRegU64(q)|BigInt(Q))}execXORI(J,q,Q){this.setRegU64(J,this.getRegU64(q)^BigInt(Q))}execLUI(J,q){this.setRegS32Extend(J,q<<16)}addrS32(J,q){return this.getRegS32Lo(J)+q>>0}addrU32(J,q){return this.getRegS32Lo(J)+q>>>0}calcDebuggerAddress(J){return this.addrS32(u(J),b(J))}execLB(J,q,Q){const Y=FY(this.addrS32(q,Q));this.setRegS32Extend(J,Y)}execLBU(J,q,Q){const Y=HY(this.addrS32(q,Q));this.setRegU32Extend(J,Y)}execLH(J,q,Q){const Y=NY(this.addrS32(q,Q));this.setRegS32Extend(J,Y)}execLHU(J,q,Q){const Y=jY(this.addrS32(q,Q));this.setRegU32Extend(J,Y)}execLW(J,q,Q){const Y=VJ(this.addrS32(q,Q));if(J==0){console.log("LW to register 0");return}this.setRegS32Extend(J,Y)}execLWU(J,q,Q){const Y=LJ(this.addrS32(q,Q));this.setRegU32Extend(J,Y)}execLD(J,q,Q){const Y=t6(this.addrS32(q,Q));this.setRegU64(J,Y)}execLWL(J,q,Q){const Y=this.addrU32(q,Q),Z=LJ((Y&~3)>>>0),K=8*(Y&3);this.setRegS32ExtendMasked(J,Z<<K,Iq<<K)}execLWR(J,q,Q){const Y=this.addrU32(q,Q),Z=LJ((Y&~3)>>>0),K=8*(3-(Y&3));this.setRegS32ExtendMasked(J,Z>>>K,Iq>>>K)}execLDL(J,q,Q){const Y=this.addrU32(q,Q),Z=BigInt(8*(Y&7)),K=t6((Y&~7)>>>0);this.setRegU64Masked(J,K<<Z&q6,q6<<Z&q6)}execLDR(J,q,Q){const Y=this.addrU32(q,Q),Z=BigInt(8*(7-(Y&7))),K=t6((Y&~7)>>>0);this.setRegU64Masked(J,K>>Z,q6>>Z)}execLWC1(J,q,Q){if(!this.checkCopXUsable(1))return;l.store32(l.copRegIdx32(J),VJ(this.addrS32(q,Q)))}execLWC2(J,q,Q){if(!this.checkCopXUsable(2))return;this.unimplemented(this.pc,"LWC2")}execLWC3(J,q,Q){if(!this.checkCopXUsable(3))return;this.unimplemented(this.pc,"LWC3")}execLDC1(J,q,Q){if(!this.checkCopXUsable(1))return;const Y=t6(this.addrS32(q,Q));l.store64(l.copRegIdx64(J),Y)}execLDC2(J,q,Q){if(!this.checkCopXUsable(2))return;this.unimplemented(this.pc,"LDC2")}execSB(J,q,Q){GY(this.addrS32(q,Q),this.getRegS32Lo(J))}execSH(J,q,Q){PY(this.addrS32(q,Q),this.getRegS32Lo(J))}execSW(J,q,Q){UJ(this.addrS32(q,Q),this.getRegS32Lo(J))}execSD(J,q,Q){MJ(this.addrS32(q,Q),this.getRegU64(J))}execSWL(J,q,Q){const Y=this.addrU32(q,Q),Z=8*(Y&3),K=this.getRegU32Lo(J);zq(Y,K>>>Z,Iq>>>Z)}execSWR(J,q,Q){const Y=this.addrU32(q,Q),Z=8*(3-(Y&3)),K=this.getRegU32Lo(J);zq(Y,K<<Z,Iq<<Z)}execSDL(J,q,Q){const Y=this.addrU32(q,Q),Z=BigInt(8*(Y&7)),K=this.getRegU64(J);Hq(Y,K>>Z,q6>>Z)}execSDR(J,q,Q){const Y=this.addrU32(q,Q),Z=this.getRegU64(J),K=BigInt(8*(7-(Y&7)));Hq(Y,Z<<K&q6,q6<<K&q6)}execSWC1(J,q,Q){if(!this.checkCopXUsable(1))return;UJ(this.addrS32(q,Q),l.loadU32(l.copRegIdx32(J)))}execSWC2(J,q,Q){if(!this.checkCopXUsable(2))return;this.unimplemented(this.pc,"SWC2")}execSWC3(J,q,Q){if(!this.checkCopXUsable(3))return;this.unimplemented(this.pc,"SWC3")}execSDC1(J,q,Q){if(!this.checkCopXUsable(1))return;MJ(this.addrS32(q,Q),l.loadU64(l.copRegIdx64(J)))}execSDC2(J,q,Q){if(!this.checkCopXUsable(2))return;this.unimplemented(this.pc,"SDC2")}execLL(J,q,Q){const Y=this.addrS32(q,Q);this.setControlU32(SJ,W7(Y)),this.setRegS32Extend(J,VJ(Y)),this.llBit=1}execLLD(J,q,Q){const Y=this.addrS32(q,Q);this.setControlU32(SJ,W7(Y)),this.setRegU64(J,t6(Y)),this.llBit=1}execSC(J,q,Q){let Y=0;if(this.llBit)UJ(this.addrS32(q,Q),this.getRegS32Lo(J)),this.llBit=0,Y=1;this.setRegU32Extend(J,Y)}execSCD(J,q,Q){let Y=0;if(this.llBit)MJ(this.addrS32(q,Q),this.getRegU64(J)),this.llBit=0,Y=1;this.setRegU32Extend(J,Y)}execCACHE(J,q,Q){if(!this.ignoreCacheOp(J))U7.invalidateEntry(this.addrU32(q,Q))}ignoreCacheOp(J){const q=J&3,Q=J>>>2&7;return q!==0||Q!==0&&Q!==4}execTGE(J,q){this.maybeRaiseTRAPException(this.getRegS64(q)>=this.getRegS64(J))}execTGEU(J,q){this.maybeRaiseTRAPException(this.getRegU64(q)>=this.getRegU64(J))}execTLT(J,q){this.maybeRaiseTRAPException(this.getRegS64(q)<this.getRegS64(J))}execTLTU(J,q){this.maybeRaiseTRAPException(this.getRegU64(q)<this.getRegU64(J))}execTEQ(J,q){this.maybeRaiseTRAPException(this.getRegS64(q)==this.getRegS64(J))}execTNE(J,q){this.maybeRaiseTRAPException(this.getRegS64(q)!=this.getRegS64(J))}execTGEI(J,q){this.maybeRaiseTRAPException(this.getRegS64(J)>=BigInt(q))}execTGEIU(J,q){this.maybeRaiseTRAPException(this.getRegU64(J)>=BigInt.asUintN(64,BigInt(q)))}execTLTI(J,q){this.maybeRaiseTRAPException(this.getRegS64(J)<BigInt(q))}execTLTIU(J,q){this.maybeRaiseTRAPException(this.getRegU64(J)<BigInt.asUintN(64,BigInt(q)))}execTEQI(J,q){this.maybeRaiseTRAPException(this.getRegS64(J)==BigInt(q))}execTNEI(J,q){this.maybeRaiseTRAPException(this.getRegS64(J)!=BigInt(q))}execJ(J){this.jump(J)}execJR(J){this.jump(this.getRegU32Lo(J))}execJAL(J){this.setRegS32Extend(Y6,this.nextPC+4),this.jump(J)}execJALR(J,q){const Q=this.getRegU32Lo(q);this.setRegS32Extend(J,this.nextPC+4),this.jump(Q)}execBEQ(J,q,Q){const Y=this.getRegU64(q)===this.getRegU64(J);if(this.conditionalBranch(Y,Q),R8&&Y&&Q===-1)this.speedHack()}execBNE(J,q,Q){this.conditionalBranch(this.getRegU64(q)!==this.getRegU64(J),Q)}execBEQL(J,q,Q){this.conditionalBranchLikely(this.getRegU64(q)===this.getRegU64(J),Q)}execBNEL(J,q,Q){this.conditionalBranchLikely(this.getRegU64(q)!==this.getRegU64(J),Q)}execBGEZ(J,q){this.conditionalBranch(this.getRegS64(J)>=0n,q)}execBGTZ(J,q){this.conditionalBranch(this.getRegS64(J)>0n,q)}execBLEZ(J,q){this.conditionalBranch(this.getRegS64(J)<=0n,q)}execBLTZ(J,q){this.conditionalBranch(this.getRegS64(J)<0n,q)}execBGEZL(J,q){this.conditionalBranchLikely(this.getRegS64(J)>=0n,q)}execBGTZL(J,q){this.conditionalBranchLikely(this.getRegS64(J)>0n,q)}execBLEZL(J,q){this.conditionalBranchLikely(this.getRegS64(J)<=0n,q)}execBLTZL(J,q){this.conditionalBranchLikely(this.getRegS64(J)<0n,q)}execBLTZAL(J,q){const Q=this.getRegS64(J)<0n;this.setRegS32Extend(Y6,this.nextPC+4),this.conditionalBranch(Q,q)}execBGEZAL(J,q){const Q=this.getRegS64(J)>=0n;this.setRegS32Extend(Y6,this.nextPC+4),this.conditionalBranch(Q,q)}execBLTZALL(J,q){const Q=this.getRegS64(J)<0n;this.setRegS32Extend(Y6,this.nextPC+4),this.conditionalBranchLikely(Q,q)}execBGEZALL(J,q){const Q=this.getRegS64(J)>=0n;this.setRegS32Extend(Y6,this.nextPC+4),this.conditionalBranchLikely(Q,q)}execMFC0(J,q){this.setRegS32Extend(J,Number(this.moveFromControl(q)&0xffff_ffffn))}execDMFC0(J,q){this.setRegU64(J,this.moveFromControl(q))}execMTC0(J,q){this.moveToControl(q,BigInt(this.getRegS32Lo(J)))}execDMTC0(J,q){this.moveToControl(q,this.getRegU64(J))}execTLB(J){switch(J){case 1:this.tlbRead();return;case 2:this.tlbWriteIndex();return;case 6:this.tlbWriteRandom();return;case 8:this.tlbProbe();return;case 24:this.execERET();return}n64js.warn(`CPU: unknown TLB op, pc: ${N(this.pc)}, op: ${N(J)}`)}execERET(){if(this.getControlU32(U0)&EJ)this.nextPC=this.getControlU32(e8),this.clearControlBits32(U0,EJ),M(`ERET from error trap - ${N(this.nextPC)}`);else this.nextPC=this.getControlU32(G6),this.clearControlBits32(U0,hJ);this.llBit=0}execMFC1(J,q){this.setRegS32Extend(J,l.loadS32(l.copRegIdx32(q)))}execDMFC1(J,q){this.setRegU64(J,l.loadU64(l.copRegIdx64(q)))}execMTC1(J,q){l.store32(l.copRegIdx32(q),this.getRegS32Lo(J))}execDMTC1(J,q){l.store64(l.copRegIdx64(q),this.getRegS64(J))}execCFC1(J,q){switch(q){case 0:case 31:this.setRegS32Extend(J,l.control[q]);break}}execCTC1(J,q){if(q===31)l.setStatus(this.getRegU32Lo(J))}execDCFC1(J,q){l.DCFC1(J,q)}execDCTC1(J,q){l.DCTC1(q,J)}execMFC2(J){if(!this.checkCopXUsable(2))return;this.setRegS32Extend(J,q8.getReg32())}execDMFC2(J){if(!this.checkCopXUsable(2))return;this.setRegU64(J,q8.getReg64())}execCFC2(J){if(!this.checkCopXUsable(2))return;this.setRegS32Extend(J,q8.getReg32())}execDCFC2(J){if(!this.checkCopXUsable(2))return;this.raiseRESERVEDException(2)}execMTC2(J){if(!this.checkCopXUsable(2))return;q8.setReg64(this.getRegU64(J))}execDMTC2(J){if(!this.checkCopXUsable(2))return;q8.setReg64(this.getRegU64(J))}execCTC2(J){if(!this.checkCopXUsable(2))return;q8.setReg64(this.getRegU64(J))}execDCTC2(J){if(!this.checkCopXUsable(2))return;this.raiseRESERVEDException(2)}unimplemented(J,q){n64js.warn(`${J}: ${q} is unimplemented`)}}class vY{constructor(J){this.hardware=J;const q=new ArrayBuffer(8);this.regU32=new Uint32Array(q),this.regU64=new BigUint64Array(q)}reset(){this.regU64[0]=0n}setReg32(J){this.regU32[0]=J,this.regU32[1]=J>>31}setReg64(J){this.regU64[0]=J}getReg32(){return this.regU32[0]}getReg64(){return this.regU64[0]}}class E6{}var BV=IV([(J)=>V.execSLL(R(J),A(J),R0(J)),k,(J)=>V.execSRL(R(J),A(J),R0(J)),(J)=>V.execSRA(R(J),A(J),R0(J)),(J)=>V.execSLLV(R(J),A(J),D(J)),k,(J)=>V.execSRLV(R(J),A(J),D(J)),(J)=>V.execSRAV(R(J),A(J),D(J)),(J)=>V.execJR(D(J)),(J)=>V.execJALR(R(J),D(J)),k,k,(J)=>V.execSYSCALL(),(J)=>V.execBREAK(),k,(J)=>V.execSYNC(),(J)=>V.execMFHI(R(J)),(J)=>V.execMTHI(D(J)),(J)=>V.execMFLO(R(J)),(J)=>V.execMTLO(D(J)),(J)=>V.execDSLLV(R(J),A(J),D(J)),k,(J)=>V.execDSRLV(R(J),A(J),D(J)),(J)=>V.execDSRAV(R(J),A(J),D(J)),(J)=>V.execMULT(A(J),D(J)),(J)=>V.execMULTU(A(J),D(J)),(J)=>V.execDIV(A(J),D(J)),(J)=>V.execDIVU(A(J),D(J)),(J)=>V.execDMULT(A(J),D(J)),(J)=>V.execDMULTU(A(J),D(J)),(J)=>V.execDDIV(A(J),D(J)),(J)=>V.execDDIVU(A(J),D(J)),(J)=>V.execADD(R(J),A(J),D(J)),(J)=>V.execADDU(R(J),A(J),D(J)),(J)=>V.execSUB(R(J),A(J),D(J)),(J)=>V.execSUBU(R(J),A(J),D(J)),(J)=>V.execAND(R(J),A(J),D(J)),(J)=>V.execOR(R(J),A(J),D(J)),(J)=>V.execXOR(R(J),A(J),D(J)),(J)=>V.execNOR(R(J),A(J),D(J)),k,k,(J)=>V.execSLT(R(J),A(J),D(J)),(J)=>V.execSLTU(R(J),A(J),D(J)),(J)=>V.execDADD(R(J),A(J),D(J)),(J)=>V.execDADDU(R(J),A(J),D(J)),(J)=>V.execDSUB(R(J),A(J),D(J)),(J)=>V.execDSUBU(R(J),A(J),D(J)),(J)=>V.execTGE(A(J),D(J)),(J)=>V.execTGEU(A(J),D(J)),(J)=>V.execTLT(A(J),D(J)),(J)=>V.execTLTU(A(J),D(J)),(J)=>V.execTEQ(A(J),D(J)),k,(J)=>V.execTNE(A(J),D(J)),k,(J)=>V.execDSLL(R(J),A(J),R0(J)),k,(J)=>V.execDSRL(R(J),A(J),R0(J)),(J)=>V.execDSRA(R(J),A(J),R0(J)),(J)=>V.execDSLL32(R(J),A(J),R0(J)),k,(J)=>V.execDSRL32(R(J),A(J),R0(J)),(J)=>V.execDSRA32(R(J),A(J),R0(J))]);n64js.executeUnknown=k;var bV=fY([(J)=>V.execMFC0(A(J),J0(J)),(J)=>V.execDMFC0(A(J),J0(J)),k,k,(J)=>V.execMTC0(A(J),J0(J)),(J)=>V.execDMTC0(A(J),J0(J)),k,k,k,k,k,k,k,k,k,k,(J)=>V.execTLB(F8(J)),k,k,k,k,k,k,k,k,k,k,k,k,k,k,k]),_V=fY([(J)=>V.execMFC1(A(J),J0(J)),(J)=>V.execDMFC1(A(J),J0(J)),(J)=>V.execCFC1(A(J),J0(J)),(J)=>V.execDCFC1(A(J),J0(J)),(J)=>V.execMTC1(A(J),J0(J)),(J)=>V.execDMTC1(A(J),J0(J)),(J)=>V.execCTC1(A(J),J0(J)),(J)=>V.execDCTC1(A(J),J0(J)),yV,k,k,k,k,k,k,k,(J)=>l.execSInstr(u0(J),P6(J),J0(J),K6(J)),(J)=>l.execDInstr(u0(J),P6(J),J0(J),K6(J)),k,k,(J)=>l.execWInstr(u0(J),P6(J),J0(J),K6(J)),(J)=>l.execLInstr(u0(J),P6(J),J0(J),K6(J)),k,k,k,k,k,k,k,k,k,k]),vV=fY([(J)=>V.execMFC2(A(J)),(J)=>V.execDMFC2(A(J)),(J)=>V.execCFC2(A(J)),(J)=>V.execDCFC2(A(J)),(J)=>V.execMTC2(A(J)),(J)=>V.execDMTC2(A(J)),(J)=>V.execCTC2(A(J)),(J)=>V.execDCTC2(A(J)),k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k]);n64js.executeCop1_disabled=uY;var xV=gV([(J)=>V.execBLTZ(D(J),q0(J)),(J)=>V.execBGEZ(D(J),q0(J)),(J)=>V.execBLTZL(D(J),q0(J)),(J)=>V.execBGEZL(D(J),q0(J)),k,k,k,k,(J)=>V.execTGEI(D(J),b(J)),(J)=>V.execTGEIU(D(J),b(J)),(J)=>V.execTLTI(D(J),b(J)),(J)=>V.execTLTIU(D(J),b(J)),(J)=>V.execTEQI(D(J),b(J)),k,(J)=>V.execTNEI(D(J),b(J)),k,(J)=>V.execBLTZAL(D(J),q0(J)),(J)=>V.execBGEZAL(D(J),q0(J)),(J)=>V.execBLTZALL(D(J),q0(J)),(J)=>V.execBGEZALL(D(J),q0(J)),k,k,k,k,k,k,k,k,k,k,k,k]),L7=mV([RV,pV,(J)=>V.execJ(I6(V.pc,J)),(J)=>V.execJAL(I6(V.pc,J)),(J)=>V.execBEQ(A(J),D(J),q0(J)),(J)=>V.execBNE(A(J),D(J),q0(J)),(J)=>V.execBLEZ(D(J),q0(J)),(J)=>V.execBGTZ(D(J),q0(J)),(J)=>V.execADDI(A(J),D(J),b(J)),(J)=>V.execADDIU(A(J),D(J),b(J)),(J)=>V.execSLTI(A(J),D(J),b(J)),(J)=>V.execSLTIU(A(J),D(J),b(J)),(J)=>V.execANDI(A(J),D(J),L6(J)),(J)=>V.execORI(A(J),D(J),L6(J)),(J)=>V.execXORI(A(J),D(J),L6(J)),(J)=>V.execLUI(A(J),L6(J)),TV,uY,fV,uV,(J)=>V.execBEQL(A(J),D(J),q0(J)),(J)=>V.execBNEL(A(J),D(J),q0(J)),(J)=>V.execBLEZL(D(J),q0(J)),(J)=>V.execBGTZL(D(J),q0(J)),(J)=>V.execDADDI(A(J),D(J),b(J)),(J)=>V.execDADDIU(A(J),D(J),b(J)),(J)=>V.execLDL(A(J),u(J),b(J)),(J)=>V.execLDR(A(J),u(J),b(J)),(J)=>V.execBreakpoint(),k,k,(J)=>V.execRESERVED(0),(J)=>V.execLB(A(J),u(J),b(J)),(J)=>V.execLH(A(J),u(J),b(J)),(J)=>V.execLWL(A(J),u(J),b(J)),(J)=>V.execLW(A(J),u(J),b(J)),(J)=>V.execLBU(A(J),u(J),b(J)),(J)=>V.execLHU(A(J),u(J),b(J)),(J)=>V.execLWR(A(J),u(J),b(J)),(J)=>V.execLWU(A(J),u(J),b(J)),(J)=>V.execSB(A(J),u(J),b(J)),(J)=>V.execSH(A(J),u(J),b(J)),(J)=>V.execSWL(A(J),u(J),b(J)),(J)=>V.execSW(A(J),u(J),b(J)),(J)=>V.execSDL(A(J),u(J),b(J)),(J)=>V.execSDR(A(J),u(J),b(J)),(J)=>V.execSWR(A(J),u(J),b(J)),(J)=>V.execCACHE(A(J),u(J),b(J)),(J)=>V.execLL(A(J),u(J),b(J)),(J)=>V.execLWC1(A(J),u(J),b(J)),(J)=>V.execLWC2(A(J),u(J),b(J)),(J)=>V.execLWC3(A(J),u(J),b(J)),(J)=>V.execLLD(A(J),u(J),b(J)),(J)=>V.execLDC1(A(J),u(J),b(J)),(J)=>V.execLDC2(A(J),u(J),b(J)),(J)=>V.execLD(A(J),u(J),b(J)),(J)=>V.execSC(A(J),u(J),b(J)),(J)=>V.execSWC1(A(J),u(J),b(J)),(J)=>V.execSWC2(A(J),u(J),b(J)),(J)=>V.execSWC3(A(J),u(J),b(J)),(J)=>V.execSCD(A(J),u(J),b(J)),(J)=>V.execSDC1(A(J),u(J),b(J)),(J)=>V.execSDC2(A(J),u(J),b(J)),(J)=>V.execSD(A(J),u(J),b(J))]);n64js.singleStep=function(){let J=0;if(n64js.isBreakpoint(V.pc))J=V.pc,n64js.toggleBreakpoint(J);if(V.run(1),J)n64js.toggleBreakpoint(J)};class V7{constructor(){this.kNumEntries=16384,this.entries=[];for(let J=0;J<this.kNumEntries;++J)this.entries.push(new Set)}addressToCacheLine(J){return Math.floor(J>>>5)}addressToCacheLineRoundUp(J){return Math.floor(J+31>>>5)}lookupEntry(J){const Q=this.addressToCacheLine(J)%this.entries.length;return this.entries[Q]}addInstructionToFragment(J,q){J.updateMinMax(q),this.lookupEntry(q).add(J)}invalidateEntry(J){const q=this.lookupEntry(J);let Q=0;const Y=this.addressToCacheLine(J);for(let[Z,K]of q.entries())if(this.addressToCacheLine(Z.minPC)<=Y&&this.addressToCacheLineRoundUp(Z.maxPC)>=Y)Z.invalidate(),q.delete(Z),Q++}}var U7=new V7,S8=new VY;n64js.checkSyncState=oV;n64js.executeOp=P7;class n{constructor(J,q,Q,Y,Z){this.name=J,this.hardware=q,this.mem=Q,this.u8=Q?Q.u8:null,this.rangeStart=Y,this.rangeEnd=Z,this.quiet=!0}setMem(J){this.mem=J,this.u8=J.u8}reset(){}calcEA(J){return J-this.rangeStart}calcInternalEA(J){return this.calcEA(J)}calcReadEA(J){return this.calcEA(J)}calcWriteEA(J){return this.calcEA(J)}readInternal32(J){const q=this.calcInternalEA(J);if(q+4<=this.u8.length)return this.mem.getU32(q);return 3722304989}writeInternal32(J,q){const Q=this.calcInternalEA(J);if(Q+4<=this.u8.length)this.mem.set32(Q,q)}logRead(J){}logWrite(J,q,Q){}readU64(J){const q=this.calcReadEA(J);if(q+8>this.u8.length)return 0;return this.mem.getU64(q)}readU32(J){const q=this.calcReadEA(J);if(q+4>this.u8.length)return 0;return this.mem.getU32(q)}readU16(J){const q=this.calcReadEA(J);if(q+2>this.u8.length)return 0;return this.mem.getU16(q)}readU8(J){const q=this.calcReadEA(J);if(q+1>this.u8.length)return 0;return this.mem.getU8(q)}readS32(J){const q=this.calcReadEA(J);if(q+4>this.u8.length)return 0;return this.mem.getS32(q)}readS16(J){const q=this.calcReadEA(J);if(q+2>this.u8.length)return 0;return this.mem.getS16(q)}readS8(J){const q=this.calcReadEA(J);if(q+1>this.u8.length)return 0;return this.mem.getS8(q)}write64masked(J,q,Q){const Y=this.calcWriteEA(J)&~7;if(Y+8>this.u8.length)return;this.mem.set64masked(Y,q,Q)}write32masked(J,q,Q){const Y=this.calcWriteEA(J)&~3;if(Y+4>this.u8.length)return;this.mem.set32masked(Y,q,Q)}write64(J,q){const Q=this.calcWriteEA(J);if(Q+8>this.u8.length)return;this.mem.set64(Q,q)}write32(J,q){const Q=this.calcWriteEA(J);if(Q+4>this.u8.length)return;this.mem.set32(Q,q)}write16(J,q){const Q=this.calcWriteEA(J);if(Q+2>this.u8.length)return;this.mem.set16(Q,q)}write8(J,q){const Q=this.calcWriteEA(J);if(Q+1>this.u8.length)return;this.mem.set8(Q,q)}}var gY=0,M7=4,W0=8,kJ=12,rV=128,sV=256,iV=512,tV=1024,eV=2048,JU=4096,qU=8192,O7=128,A7=256,h7=512,QU=1,YU=2,ZU=4,KU=8,XU=16,WU=32,$U=64,zU=128,HU=256,FU=512,jU=1024,NU=2048;var v8=1,w6=2,CJ=4,DJ=8,yJ=16,bq=32;class xY extends n{constructor(J,q,Q){super("MIReg",J,J.mi_reg,q,Q)}reset(){this.mem.set32(M7,33685762)}interruptsUnmasked(){return(this.mem.getU32(kJ)&this.mem.getU32(W0))!==0}intrReg(){return this.mem.getU32(W0)}intrMaskReg(){return this.mem.getU32(kJ)}setInterruptBit(J){this.mem.setBits32(W0,J),n64js.cpu0.updateCause3()}interruptSP(){this.setInterruptBit(v8)}interruptDP(){this.setInterruptBit(bq)}write32(J,q){const Q=this.calcWriteEA(J);if(Q+4>this.u8.length)throw"Write is out of range";switch(Q){case gY:if(!this.quiet)M(`Wrote to MI mode register: ${N(q)}`);this.writeModeReg(q);break;case kJ:if(!this.quiet)M(`Wrote to MI interrupt mask register: ${N(q)}`);this.writeIntrMaskReg(q);break;case M7:case W0:break;default:M(`Unhandled write to MIReg: ${N(q)} -> [${N(J)}]`),this.mem.set32(Q,q);break}}writeModeReg(J){let q=this.mem.getU32(gY);if(J&qU)q|=h7;if(J&JU)q&=~h7;if(J&sV)q|=O7;if(J&rV)q&=~O7;if(J&tV)q|=A7;if(J&iV)q&=~A7;if(this.mem.set32(gY,q),J&eV)this.mem.clearBits32(W0,bq),n64js.cpu0.updateCause3()}writeIntrMaskReg(J){let q=0,Q=0;q|=(J&QU)>>>0,q|=(J&ZU)>>>1,q|=(J&XU)>>>2,q|=(J&$U)>>>3,q|=(J&HU)>>>4,q|=(J&jU)>>>5,Q|=(J&YU)>>>1,Q|=(J&KU)>>>2,Q|=(J&WU)>>>3,Q|=(J&zU)>>>4,Q|=(J&FU)>>>5,Q|=(J&NU)>>>6;let Y=this.mem.getU32(kJ);Y&=~q,Y|=Q,this.mem.set32(kJ,Y),n64js.cpu0.updateCause3()}}var E7=function(J,q){return J&~(q-1)},O0=function(J,q){const Q=document.querySelector(J);if(Q)Q.textContent=q};window.n64js=window.n64js||{};class pY{constructor(){this.disasmAddress=0,this.lastPC=-1}setPC(J){if(J!==this.lastPC)this.disasmAddress=J,this.lastPC=J}scroll(J){this.disasmAddress+=J*4}}class w7 extends pY{disassembleRange(){return mK(this.disasmAddress-64,this.disasmAddress+64,!0)}updateStatusTable(){O0("#cpu0-status-opsexecuted",V.opsExecuted),O0("#cpu0-status-pc",N(V.pc)),O0("#cpu0-status-delaypc",N(V.delayPC)),O0("#cpu0-status-epc",N(V.getControlU32(G6))),O0("#cpu0-status-cause",N(Number(V.moveFromControl(k0)&0xffff_ffffn))),O0("#cpu0-status-count",N(Number(V.moveFromControl(m6)&0xffff_ffffn))),O0("#cpu0-status-compare",N(V.getControlU32(K8))),O0("#cpu0-status-multhi",y6(V.getMultHiU64())),O0("#cpu0-status-multlo",y6(V.getMultLoU64())),this.updateStatusRegisterRow(),this.updateMipsInterruptsRow();let J=$("#cpu0-status-events").find("tbody");J.empty(),J.append("<tr><td> </td></tr>"),J.append("<tr><td>Events</td></tr>");const q=V.eventQueue;let Q=q.cyclesToFirstEvent;for(let Y=q.firstEvent;Y;Y=Y.next)J.append(`<tr><td>${Y.getName()}</td><td class="fixed">${Q}</td></tr>`),Q+=Y.cyclesToNextEvent}updateStatusRegisterRow(){const J=V.getControlU32(U0);O0("#cpu0-status-sr",N(J));const q={"#cpu0-status-sr-ie":Rq,"#cpu0-status-sr-exl":hJ,"#cpu0-status-sr-erl":EJ};for(let[Q,Y]of Object.entries(q)){const Z=document.querySelector(Q);if(!Z)continue;const K=(J&Y)!==0;Z.classList.toggle("cpu0-status-bit-set",K)}}updateMipsInterruptsRow(){const J=n64js.hardware().miRegDevice,q=J.intrReg(),Q=J.intrMaskReg(),Y={"#cpu0-status-mi-sp":v8,"#cpu0-status-mi-si":w6,"#cpu0-status-mi-ai":CJ,"#cpu0-status-mi-vi":DJ,"#cpu0-status-mi-pi":yJ,"#cpu0-status-mi-dp":bq};for(let[Z,K]of Object.entries(Y)){const X=document.querySelector(Z);if(!X)continue;const W=(q&K)!==0,z=(Q&K)!==0;X.classList.toggle("cpu0-status-bit-enabled",z),X.classList.toggle("cpu0-status-bit-set",W)}}makeCop0RegistersTable(J){let q=$('<table class="register-table"><tbody></tbody></table>'),Q=q.find("tbody");const Y=2;for(let Z=0;Z<32;Z+=Y){let K=$("<tr />");for(let X=0;X<Y;++X){let W=JQ[Z+X],z=$(`<td>${W}</td><td class="fixed">${y6(V.getRegU64(Z+X))}</td>`);if(J.has(W))z.attr("bgcolor",J.get(W));K.append(z)}Q.append(K)}return q}makeCop1RegistersTable(J){let q=$('<table class="register-table"><tbody></tbody></table>'),Q=q.find("tbody");for(let Y=0;Y<32;++Y){let Z=qQ[Y],K;if((Y&1)===0)K=$(`<td>${Z}</td>
|
|
<td class="fixed fp-w">${N(l.regU32[Y])}</td>
|
|
<td class="fixed fp-s">${l.regF32[Y]}</td>
|
|
<td class="fixed fp-d">${l.regF64[Y/2]}</td>`);else K=$(`<td>${Z}</td>
|
|
<td class="fixed fp-w">${N(l.regU32[Y])}</td>
|
|
<td class="fixed fp-s">${l.regF32[Y]}</td>
|
|
<td></td>`);let X=$("<tr />");if(X.append(K),J.has(Z))X.attr("bgcolor",J.get(Z));else if(J.has(Z+"-w"))X.find(".fp-w").attr("bgcolor",J.get(Z+"-w"));else if(J.has(Z+"-s"))X.find(".fp-s").attr("bgcolor",J.get(Z+"-s"));else if(J.has(Z+"-d"))X.find(".fp-d").attr("bgcolor",J.get(Z+"-d"));Q.append(X)}return q}}class k7 extends pY{disassembleRange(){return xJ(H.imem,this.disasmAddress-64,this.disasmAddress+64,!0)}updateStatusTable(){O0("#rsp-status-halted",H.halted),O0("#rsp-status-pc",N(H.pc)),O0("#rsp-status-delaypc",N(H.delayPC)),O0("#rsp-status-nextpc",N(H.nextPC)),O0("#rsp-status-branchtarget",N(H.branchTarget)),O0("#rsp-status-vco",r(H.VCO)),O0("#rsp-status-vcc",r(H.VCC)),O0("#rsp-status-vce",M0(H.VCE))}makeScalarRegistersTable(J){let q=$('<table class="register-table"><tbody></tbody></table>'),Q=q.find("tbody");const Y=2;for(let Z=0;Z<32;Z+=Y){let K=$("<tr />");for(let X=0;X<Y;++X){let W=YQ[Z+X],z=$(`<td>${W}</td><td class="fixed">${N(H.getRegU32(Z+X))}</td>`);if(J.has(W))z.attr("bgcolor",J.get(W));K.append(z)}Q.append(K)}return q}makeVectorRegistersTable(J){let q=$('<table class="register-table"><tbody></tbody></table>'),Q=q.find("tbody");for(let Y=0;Y<32;Y++){let Z=$("<tr />");const K=`V${Y}`;Z.append($(`<td>${K}</td>`));for(let X=0;X<8;++X){let W=$(`<td class="fixed">${B(H.getVecU16(Y,X),16)}</td>`);if(J.has(K))W.attr("bgcolor",J.get(K));Z.append(W)}Q.append(Z)}return q}makeTaskTable(){const Q=n64js.hardware().sp_mem.subRegion(4032,64);let Y=$('<table class="register-table"><tbody></tbody></table>'),Z=Y.find("tbody");const K=["type","flags","ucode_boot","ucode_boot_size","ucode","ucode_size","ucode_data","ucode_data_size","dram_stack","dram_stack_size","output_buff","output_buff_size","data_ptr","data_size","yield_data_ptr","yield_data_size"];for(let X=0;X<16;X++){const W=$(`<tr><td>${K[X]}</td><td class="fixed">${B(Q.getU32(X*4),32)}</td></tr>`);Z.append(W)}return Y}}class mY{constructor(){this.active=!1,this.$cpuContent=$("#cpu-content"),this.cpuTabs=[$("#cpu0-content"),$("#cpu1-content")],this.$cpu0Disassembly=$("#cpu-disasm"),this.$rspContent=$("#rsp-content"),this.rspTabs=[$("#rsp-scalar-content"),$("#rsp-vector-content"),$("#rsp-task-content")],this.$rspDisassembly=$("#rsp-disasm"),this.$dynarecContent=$("#dynarec-content"),this.$memoryContent=$("#memory-content"),this.$timelineContent=$("#timeline-content"),this.cpu0State=new w7,this.rspState=new k7,this.lastOpExecuted=0,this.recentMemoryAccesses=[],this.lastMemoryAccessAddress=0,this.lastStore=null,this.labelMap=new Map,this.debugCycles=Math.pow(10,0),zK($(".output"),()=>{return N(V.pc)}),n64js.addResetCallback(this.onReset.bind(this)),$("#output").find("#clear").click(function(){HK()});const J=this;$("#cpu-speed").change(function(){J.debugCycles=Math.pow(10,$(this).val()|0),M("Speed is now "+J.debugCycles)}),$("#cpu").find("#address").change(function(){J.disasmAddress=parseInt($(this).val(),16),J.updateCPU()}),this.refreshLabelSelect(),this.$memoryContent.find("input").change(function(){J.lastMemoryAccessAddress=parseInt($(this).val(),16),J.updateMemoryView()}),this.updateMemoryView(),$("body").keydown(function(q){let Q=!1;switch(q.key){case"ArrowDown":Q=!0,J.disassemblerDown();break;case"ArrowUp":Q=!0,J.disassemblerUp();break;case"PageDown":Q=!0,J.disassemblerPageDown();break;case"PageUp":Q=!0,J.disassemblerPageUp();break;case"F8":Q=!0,n64js.toggleRun();break;case"F9":Q=!0,AW();break;case"F10":Q=!0,n64js.step();break}if(Q)q.preventDefault()}),document.querySelector("#cpu-tab").addEventListener("click",()=>{this.updateCPU()}),document.querySelector("#rsp-tab").addEventListener("click",()=>{this.updateRSP()}),document.querySelector("#memory-tab").addEventListener("click",()=>{this.updateMemoryView()}),document.querySelector("#dynarec-tab").addEventListener("click",()=>{this.updateDynarec()}),document.querySelector("#timeline-tab").addEventListener("click",()=>{this.updateTimeline()})}visible(){return this.active}show(){this.setVisible(!0)}hide(){this.setVisible(!1)}toggle(){this.setVisible(!this.active)}setVisible(J){this.active=J,document.querySelectorAll(".debug").forEach((q)=>{q.classList.toggle("hidden",!J)}),WX(J)}showTimeline(){this.updateTimeline(),this.show(),$("#timeline-tab").tab("show")}updateMemoryView(){const J=this.lastMemoryAccessAddress||2147483648;this.$memoryContent.find("pre").empty().append(this.makeMemoryAccessRow(J,1024))}refreshLabelSelect(){const J=$("#cpu").find("#labels"),q=Array.from(this.labelMap.keys()),Q=this;q.sort((Y,Z)=>{const K=Q.labelMap.get(Y),X=Q.labelMap.get(Z);return K.localeCompare(X)}),J.html("");for(let Y of q){const Z=this.labelMap.get(Y),K=$(`<option value="${Z}">${Z}</option>`);K.data("address",Y),J.append(K)}J.change(()=>{let Y=J.find("option:selected").data("address");Q.cpu0State.disasmAddress=Y>>>0,Q.updateCPU()})}onReset(){this.restoreLabelMap(),this.updateCPU(),this.updateRSP()}restoreLabelMap(){this.labelMap=n64js.getLocalStorageItem("debugLabelMap")||new Map,this.refreshLabelSelect()}storeLabelMap(){n64js.setLocalStorageItem("debugLabelMap",this.labelMap)}makeMemoryAccessRow(J,q,Q=64,Y=null){let Z=E7(J,Q)-E7(q/2,Q),K=Z+q,X="";for(let W=Z;W<K;W+=Q){let z=B(W,32)+":";for(let F=0;F<Q;F+=4){let j=W+F>>>0,G=n64js.hardware().memMap.readMemoryInternal32(j),P="";if(Y&&Y.has(j))P=` style="background-color: ${Y.get(j)}"`;z+=` <span id="mem-${B(j,32)}"${P}>${B(G,32)}</span>`}z+="\n",X+=z}return $(`<span>${X}</span>`)}makeRecentMemoryAccessRow(J,q){let Q=q==="store"?"#faa":"#ffa";if(q==="update")Q="#afa";let Y=new Map,Z=(J&~3)>>>0;return Y.set(Z,Q),this.makeMemoryAccessRow(J,32,32,Y)}makeLabelColor(J){let q=J>>>2,Q=q>>>16^(q&65535)*2803,Y=Q&31,Z=Q>>>5&31,K=Q>>>10&31,X=Q>>>15&3;switch(Y*=4,Z*=4,K*=4,X){case 0:Y*=2,Z*=2;break;case 1:Z*=2,K*=2;break;case 2:K*=2,Y*=2;break;default:Y*=2,Z*=2,K*=2;break}return"#"+B(Y,8)+B(Z,8)+B(K,8)}setLabelText(J,q){if(this.labelMap.has(q))J.append(` (${this.labelMap.get(q)})`)}setLabelColor(J,q){J.css("color",this.makeLabelColor(q))}makeLabelText(J){let q=this.labelMap.get(J)||"";while(q.length<20)q+=" ";return q}onLabelClicked(J){let q=$(J.delegateTarget),Q=q.data("address")>>>0,Y=this.labelMap.get(Q)||"",Z=$(`<input class="input-mini" value="${Y}" />`);const K=this;Z.keypress((X)=>{if(X.which==13){const W=Z.val();if(W)K.labelMap.set(Q,W.toString());else K.labelMap.delete(Q);K.storeLabelMap(),K.refreshLabelSelect(),this.updateCPU()}}),Z.blur(()=>{q.html(K.makeLabelText(Q))}),q.empty().append(Z),Z.focus()}onFragmentClicked(J){let Q=$(J.delegateTarget).data("fragment");M(`<pre>${Q.func.toString()}</pre>`)}onClickBreakpoint(J){let Q=$(J.delegateTarget).data("address")>>>0;n64js.toggleBreakpoint(Q),this.updateCPU()}updateCPU(){this.cpu0State.setPC(V.pc);let J=V.getOpsExecuted(),q=this.lastOpExecuted===J-1;this.lastOpExecuted=J;let Q=zQ(),Y=this.cpu0State.disassembleRange(),Z=$("<pre/>"),K=$("<pre/>"),X;for(let z=0;z<Y.length;++z){let F=Y[z],j=F.instruction.address,G=F.isJumpTarget||this.labelMap.has(j),P=(G?'<span class="dis-address-target">':'<span class="dis-address">')+B(j,32)+":</span>",L=`<span class="dis-label">${this.makeLabelText(j)}</span>`,U=`${P} ${B(F.instruction.opcode,32)} ${L}${F.disassembly}`,O=Q.get(j);if(O){const S=`<span class="dis-fragment-link"> frag - ops=${O.opsCompiled} hit=${O.executionCount}</span>`;U+=S}let E=$(`<span class="dis-line">${U}</span>`);if(E.find(".dis-label").data("address",j).css("color",this.makeLabelColor(j)).click(this.onLabelClicked.bind(this)),O)E.find(".dis-fragment-link").data("fragment",O).click(this.onFragmentClicked.bind(this));if(j===V.pc)X=F.instruction,E.addClass("dis-line-cur");if(G)E.addClass("dis-line-target"),this.setLabelColor(E.find(".dis-address-target"),j);K.append(E),K.append("<br>");let w=" ";if(n64js.isBreakpoint(j))w="•";let y=$(`<span>${w}</span>`).data("address",j).click(this.onClickBreakpoint.bind(this));Z.append(y),Z.append("<br>")}K.find(".dis-address-jump").each(function(){let z=parseInt($(this).text(),16);this.setLabelText($(this),z),this.setLabelColor($(this),z),$(this).click(function(){this.cpu0state.disasmAddress=z,this.redraw()})}.bind(this));let W=this.makeRegisterColours(X);for(let[z,F]of W)K.find(".dis-reg-"+z).css("background-color",F);this.$cpu0Disassembly.find(".dis-recent-memory").html(this.makeRecentMemoryAccesses(q,X,V.calcDebuggerAddress.bind(V))),this.$cpu0Disassembly.find(".dis-gutter").empty().append(Z),this.$cpu0Disassembly.find(".dis-view").empty().append(K),this.cpu0State.updateStatusTable(),this.cpuTabs[0].empty().append(this.cpu0State.makeCop0RegistersTable(W)),this.cpuTabs[1].empty().append(this.cpu0State.makeCop1RegistersTable(W))}updateRSP(){this.rspState.setPC(H.pc);const J=!0;let q=this.rspState.disassembleRange(),Q=$("<pre/>"),Y=$("<pre/>");for(let W=0;W<q.length;++W){let z=q[W],F=z.instruction.address,j=z.isJumpTarget||this.labelMap.has(F),G=(j?'<span class="dis-address-target">':'<span class="dis-address">')+B(F,32)+":</span>",P=`<span class="dis-label">${this.makeLabelText(F)}</span>`,L=`${G} ${B(z.instruction.opcode,32)} ${P}${z.disassembly}`,U=$(`<span class="dis-line">${L}</span>`);if(U.find(".dis-label").data("address",F).css("color",this.makeLabelColor(F)).click(this.onLabelClicked.bind(this)),F===H.pc)U.addClass("dis-line-cur");if(j)U.addClass("dis-line-target"),this.setLabelColor(U.find(".dis-address-target"),F);Y.append(U),Y.append("<br>");let O=" ";if(n64js.isBreakpoint(F))O="•";let E=$(`<span>${O}</span>`).data("address",F).click(this.onClickBreakpoint.bind(this));Q.append(E),Q.append("<br>")}Y.find(".dis-address-jump").each(function(){let W=parseInt($(this).text(),16);this.setLabelText($(this),W),this.setLabelColor($(this),W),$(this).click(function(){this.rspstate.disasmAddress=W,this.redraw()})}.bind(this));const K=XJ(H.pc,H.imem.getU32(H.pc)).instruction;let X=this.makeRegisterColours(K);for(let[W,z]of X)Y.find(".dis-reg-"+W).css("background-color",z);this.$rspDisassembly.find(".dis-recent-memory").html(this.makeRecentMemoryAccesses(J,K,H.calcDebuggerAddress.bind(H))),this.$rspDisassembly.find(".dis-gutter").empty().append(Q),this.$rspDisassembly.find(".dis-view").empty().append(Y),this.rspState.updateStatusTable(),this.rspTabs[0].empty().append(this.rspState.makeScalarRegistersTable(X)),this.rspTabs[1].empty().append(this.rspState.makeVectorRegistersTable(X)),this.rspTabs[2].empty().append(this.rspState.makeTaskTable())}makeRegisterColours(J){const q=["#fd7e14","#198754","#0d6efd"];let Q=new Map;if(J){let Y=0;for(let Z in J.srcRegs)if(!Object.prototype.hasOwnProperty.call(Q,Z))Q.set(Z,q[Y++]);for(let Z in J.dstRegs)if(!Object.prototype.hasOwnProperty.call(Q,Z))Q.set(Z,q[Y++])}return Q}makeRecentMemoryAccesses(J,q,Q){const Y=V.opsExecuted;if(J){if(this.lastStore){if(this.lastStore.cycle+1===Y){let X=this.makeRecentMemoryAccessRow(this.lastStore.address,"update");this.lastStore.element.append(X)}this.lastStore=null}const K=q.memory;if(K){const X=Q(q.opcode);let W=this.makeRecentMemoryAccessRow(X,K.mode);if(K.mode==="store")this.lastStore={address:X,cycle:Y,element:W};if(this.recentMemoryAccesses.push({element:W}),this.recentMemoryAccesses.length>4)this.recentMemoryAccesses.splice(0,1);this.lastMemoryAccessAddress=X}}else this.recentMemoryAccesses=[],this.lastStore=null;let Z=$("<pre />");if(this.recentMemoryAccesses.length>0){const K=["#bbb","#999","#666","#333"];for(let X=0;X<this.recentMemoryAccesses.length;++X){let W=this.recentMemoryAccesses[X].element;W.css("color",K[X]),Z.append(W)}}return Z}updateDynarec(){let J=FX(),q=new Map,Q=0,Y=[];for(let[W,z]of zQ()){let F=z.executionCount>0?Math.floor(Math.log10(z.executionCount)):0;q.set(F,(q.get(F)||0)+1),Y.push(z),Q=Math.max(Q,F)}Y.sort((W,z)=>{return z.opsCompiled*z.executionCount-W.opsCompiled*W.executionCount});let Z=$('<div class="container-fluid" />'),K="";K+='<div class="row">',K+='<table class="table table-condensed table-nonfluid"><tr><th>Execution Count</th><th>Frequency</th></tr>';for(let W=0;W<=Q;W++){let z=q.get(W)||0,F=`< ${Math.pow(10,W+1)}`;K+=`<tr><td>${F}</td><td>${z}</td></tr>`}K+="</table>",K+="</div>",Z.append(K),K="",K+='<div class="row">',K+=' <div class="col-lg-6" id="fragments" />',K+=' <div class="col-lg-6" id="fragment-code" />',K+="</div>";let X=$(K);if(this.createHotFragmentsTable(X,Y),Z.append(X),J.length>0){K="",K+='<div class="row">',K+='<div class="col-lg-6">',K+='<table class="table table-condensed">',K+="<tr><th>Address</th><th>Length</th><th>System</th><th>Fragments Removed</th></tr>";for(let W=0;W<J.length;++W){let z=[N(J[W].address),J[W].length,J[W].system,J[W].fragmentsRemoved];K+=`<tr><td>${z.join("</td><td>")}</td></tr>`}K+="</table>",K+="</div>",K+="</div>",Z.append(K)}this.$dynarecContent.empty().append(Z)}createHotFragmentsTable(J,q){let Q=J.find("#fragment-code"),Y=$('<table class="table table-condensed" />'),Z=["Address","Execution Count","Length","ExecCount * Length"];Y.append(`<tr><th>${Z.join("</th><th>")}</th></tr>`);for(let K=0;K<q.length&&K<20;++K){let X=q[K],W=[N(X.entryPC),X.executionCount,X.opsCompiled,X.executionCount*X.opsCompiled],z=$(`<tr><td>${W.join("</td><td>")}</td></tr>`);this.initFragmentRow(z,X,Q),Y.append(z)}if(J.find("#fragments").append(Y),q.length>0)Q.append(`<pre>${q[0].func.toString()}</pre>`)}initFragmentRow(J,q,Q){J.click(()=>{Q.html(`<pre>${q.func.toString()}</pre>`)})}updateTimeline(){const J=n64js.hardware().timeline,q=this.$timelineContent.find(".timeline-panel");q.empty();let Q=Number.MAX_VALUE,Y=0;J.tracks.forEach((z)=>{z.events.forEach((F)=>{if(F.start<Q)Q=F.start;if(F.end>Y)Y=F.end})});const Z=Y-Q;if(Z<=0)return;const K=4000,X=30;let W=0;J.tracks.forEach((z)=>{let F=0;z.events.forEach((j)=>{const G=K*(j.start-Q)/Z,P=K*(j.end-j.start)/Z,L=P<1?1:P,U=(W+j.depth)*X,O=X,E=j.name;let w="";if(w+=`<div class="timeline-block" style="left: ${G.toFixed(0)}px; top: ${U.toFixed(0)}px; width: ${L.toFixed(0)}px; height: ${O.toFixed(0)}px">`,w+=`<div class="timeline-name">${E}</div>`,w+="</div>",q.append(w),j.depth>F)F=j.depth}),W+=F+1})}disassemblerDown(){this.scrollActiveDisassemblyWindow(1),this.redraw()}disassemblerUp(){this.scrollActiveDisassemblyWindow(-1),this.redraw()}disassemblerPageDown(){this.scrollActiveDisassemblyWindow(16),this.redraw()}disassemblerPageUp(){this.scrollActiveDisassemblyWindow(-16),this.redraw()}scrollActiveDisassemblyWindow(J){const q=this.activeDisassemblyWindow();if(q)q.scroll(J)}activeDisassemblyWindow(){if(this.$cpuContent.hasClass("active"))return this.cpu0State;if(this.$rspContent.hasClass("active"))return this.rspState;return null}redraw(){if(!this.active)return;if(this.$cpuContent.hasClass("active"))this.updateCPU();if(this.$rspContent.hasClass("active"))this.updateRSP();if(this.$memoryContent.hasClass("active"))this.updateMemoryView();if(this.$dynarecContent.hasClass("active"))this.updateDynarec()}}function C7(J){var q=new DataView(J);switch(q.getUint32(0)){case 2151092800:break;case 1074935680:nY(J,3,2,1,0);break;case 306217015:nY(J,2,3,0,1);break;case 931151890:nY(J,1,0,3,2);break;default:throw"Unhandled byteswapping: "+q.getUint32(0).toString(16)}}var nY=function(J,q,Q,Y,Z){var K=new Uint8Array(J),X;for(X=0;X<K.length;X+=4){var W=K[X+q],z=K[X+Q],F=K[X+Y],j=K[X+Z];K[X]=W,K[X+1]=z,K[X+2]=F,K[X+3]=j}};function D7(J){var q="";for(let F=0;F<J.length;F+=3){var Q=J[F+0],Y=J[F+1],Z=J[F+2],K=Q>>>2,X=(Q&3)<<4|Y>>>4,W=(Y&15)<<2|Z>>>6,z=Z&63;if(F+1>=J.length)W=64;if(F+2>=J.length)z=64;q+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(K)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(X)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(W)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(z)}return q}function oY(J,q){var Q=0;for(let j=0;j<J.length;j+=4){var Y="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(j+0)),Z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(j+1)),K="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(j+2)),X="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(j+3)),W=Y<<2|Z>>>4,z=(Z&15)<<4|K>>>2,F=(K&3)<<6|X;if(q[Q++]=W,K!==64)q[Q++]=z;if(X!==64)q[Q++]=F}}var y7=0;class lY{constructor(J){this.getOpsExecuted=J,this.recording=!1,this.tracks=[new cY(this,"Default"),new cY(this,"Audio")],this.eventCount=0,this.curFrameEvent=0,this.frameCount=0}startRecording(){this.recording=!0;for(let J=0;J<this.tracks.length;J++)this.tracks[J].reset();this.eventCount=0,this.frameCount=0}newFrame(){if(!this.recording)return null;if(this.curFrameEvent)this.curFrameEvent.stop();if(this.tracks[1].curEvent=null,this.curFrameEvent=this.startEventInternal(`Frame ${this.frameCount}`,1),this.frameCount++,this.eventCount>=1e4||this.frameCount>=10)this.recording=!1,this.curFrameEvent=null,n64js.debugger().showTimeline()}addEvent(J,q){if(!this.curFrameEvent)return null;const Q=this.startEventInternal(J,q);if(Q)Q.stop()}startEvent(J,q){if(!this.curFrameEvent)return null;return this.startEventInternal(J,q)}startEventInternal(J,q){const Q=q==void 0?1:q,Y=this.tracks[Q];return this.eventCount++,Y.startEvent(J)}}class cY{constructor(J,q){this.timeline=J,this.name=q,this.events=[],this.curEvent=null}reset(){this.events=[],this.curEvent=null}startEvent(J){const q=this.timeline.getOpsExecuted(),Q=new I7(this,this.curEvent,J,q);return this.events.push(Q),this.curEvent=Q,Q}stopEvent(J){if(J.end=this.timeline.getOpsExecuted(),this.curEvent==J)this.curEvent=J.parent}}class I7{constructor(J,q,Q,Y){this.track=J,this.parent=q,this.depth=q?q.depth+1:0,this.name=Q,this.start=Y,this.end=Y}stop(){this.track.stopEvent(this)}}var yU=function(J){if(J<T7)return T7;if(J>_7)return _7;return J},PU=0,LU=4,VU=8,B7=12,UU=16,MU=20,OU=1,AU=17825792,hU=33554432,EU=1073741824,wU=2147483648,kU=16777208,CU=262136,R7="AI DMA",b7=0.005,T7=3000,_7=96000,DU=0.1,S7=5;class dY extends n{constructor(J,q,Q){super("AIReg",J,J.ai_reg,q,Q);this.audioContext=new window.AudioContext,this.pendingAddress=0,this.dmaAddresses=new Uint32Array(2),this.dmaLengths=new Uint32Array(2),this.dmaDurations=new Uint32Array(2),this.dmaCount=0,this.dmaEnable=!1,this.dacRate=0,this.bitRate=15,this.precision=16,this.frequency=32000,this.time=0,this.dynamicRate=1,this.lastLogTime=0}readU32(J){return this.readS32(J)>>>0}readS32(J){const q=this.calcWriteEA(J);if(q+4>this.u8.length)throw"Write is out of range";if(!this.quiet)M(`Read from ${N(q)}`);if(q==B7){let Q=AU;return Q|=this.dmaEnable?hU:0,Q|=this.dmaCount>0?EU:0,Q|=this.dmaCount>1?wU:0,Q|=this.dmaCount>1?OU:0,Q}return this.dmaLengthRemaining()}write32(J,q){const Q=this.calcWriteEA(J);if(Q+4>this.u8.length)throw"Write is out of range";switch(Q){case PU:if(!this.quiet)M(`Wrote to AI_DRAM_ADDR_REG: ${N(q)}`);this.pendingAddress=q&kU;break;case LU:if(!this.quiet)M(`Wrote to AI_LEN_REG: ${N(q)}`);this.pushDMA(q&CU);break;case VU:if(!this.quiet)M(`Wrote to AI_CONTROL_REG: ${N(q)}`);this.dmaEnable=(q&1)!=0;break;case B7:this.clearAI();break;case UU:if(this.dacRate=q&16383,this.frequency=Math.max(1,this.viClock/(this.dacRate+1))>>0,!this.quiet)M(`AI dacrate changed to ${this.dacRate}, vi clock is ${this.viClock}, freq ${this.frequency}`);break;case MU:if(!this.quiet)M(`Wrote to AI_BITRATE_REG: ${N(q)}`);this.bitRate=q&15,this.precision=this.bitRate+1;break;default:M(`Unhandled write to AIReg: ${N(q)} -> [${N(J)}]`);break}}get viClock(){return this.hardware.viRegDevice.videoClock}pushDMA(J){if(!J){n64js.warn("AI received zero length write");return}if(this.dmaCount>=2){n64js.warn("AI DMA FIFO is full");return}if(this.dmaAddresses[this.dmaCount]=this.pendingAddress,this.dmaLengths[this.dmaCount]=J,this.dmaDurations[this.dmaCount]=this.estimateDMACyclesFromLength(J),this.dmaCount++,this.dmaCount==1)this.startPlayback()}popDMA(){if(this.dmaCount<=0){n64js.warn("AI DMA underflow");return}if(this.dmaCount==2)this.dmaAddresses[0]=this.dmaAddresses[1],this.dmaLengths[0]=this.dmaLengths[1],this.dmaDurations[0]=this.dmaDurations[1];if(this.dmaCount--,this.dmaCount==1)this.startPlayback()}estimateDMACyclesFromLength(J){const Q=(this.bitRate+1<<1)/8*this.frequency;return J*this.viClock/Q>>>0}startPlayback(){const J=this.dmaAddresses[0],q=this.dmaLengths[0],Q=this.dmaDurations[0],Y=q/4,Z=new Float32Array(Y),K=new Float32Array(Y),X=this.hardware.cachedMemDevice.u8,W=new DataView(X.buffer,J,q);for(let L=0;L<Y;L++)Z[L]=W.getInt16(L*4+0)/32768,K[L]=W.getInt16(L*4+2)/32768;const z=this.audioContext.currentTime,F=this.time-z;this.dynamicRate=F>0?+b7:-b7;const j=yU(this.frequency*(1+this.dynamicRate));if(S7>0&&z-this.lastLogTime>S7){const L=F>0?"leading":"lagging";console.log(`AI sync: timeDelta ${F}, ${L}, dynamic ${this.dynamicRate}, ${this.frequency} -> ${j}`),this.lastLogTime=z}const G=new AudioBuffer({length:Y,sampleRate:j,numberOfChannels:2});G.copyToChannel(Z,0),G.copyToChannel(K,1);const P=new AudioBufferSourceNode(this.audioContext,{buffer:G});if(P.connect(this.audioContext.destination),P.start(this.time),F<0)this.time=z;this.time+=G.duration,this.raiseAI(),this.addAIDMAEvent(Q)}shouldSkipFrame(){return this.time-this.audioContext.currentTime>DU}dmaLengthRemaining(){if(this.dmaCount==0||this.dmaDurations[0]==0)return 0;const J=n64js.cpu0.getCyclesUntilEvent(R7);if(J<=0)return 0;return J*this.dmaLengths[0]/this.dmaDurations[0]&~7}addAIDMAEvent(J){const q=n64js.hardware().timeline.startEvent("AI DMA",y7),Q=this;n64js.cpu0.addEvent(R7,J,()=>{if(Q.dmaComplete(),q)q.stop()})}dmaComplete(){this.popDMA()}raiseAI(){this.hardware.mi_reg.setBits32(W0,CJ),n64js.cpu0.updateCause3()}clearAI(){this.hardware.mi_reg.clearBits32(W0,CJ),n64js.cpu0.updateCause3()}}var IU=0,BU=4,v7=8,aY=12,RU=16,bU=20,TU=24,_U=28,SU=1,vU=2,fU=4;var uU=16,gU=32;var f7=1,xU=2,u7=4;class rY extends n{constructor(J,q,Q){super("DPC",J,J.dpc_mem,q,Q)}write32(J,q){this.writeReg32(this.calcWriteEA(J),q)}writeReg32(J,q){if(J+4>this.u8.length)throw"Write is out of range";switch(J){case IU:if(!this.quiet)M(`DPC start set to: ${N(q)}`);this.mem.set32(J,q),this.mem.set32(v7,q);break;case BU:if(!this.quiet)M(`DPC end set to: ${N(q)}`);this.mem.set32(J,q);break;case aY:this.updateStatus(q);break;case v7:case RU:case bU:case TU:case _U:M("Wrote to read only DPC reg");break;default:this.mem.set32(J,q);break}}readU32(J){return this.logRead(J),this.readRegU32(this.calcReadEA(J))}readS32(J){return this.logRead(J),this.readRegU32(this.calcReadEA(J))>>0}readRegU32(J){if(J+4>this.u8.length)throw"Read is out of range";return this.mem.getU32(J)}updateStatus(J){let q=this.mem.getU32(aY);if(J&SU)q&=~f7;if(J&vU)q|=f7;if(J&fU)q&=~xU;if(J&uU)q&=~u7;if(J&gU)q|=u7;this.mem.set32(aY,q)}}class sY extends n{constructor(J,q,Q){super("DPS",J,J.dps_mem,q,Q)}write32(J,q){if(this.calcWriteEA(J)+4>this.u8.length)throw"Write is out of range";throw"DPS writes are unhandled"}readS32(J){if(this.logRead(J),this.calcReadEA(J)+4>this.u8.length)throw"Read is out of range";throw"DPS reads are unhandled"}readU32(J){return this.readS32(J)>>>0}}function Q3(J){return J>=tU&&J<eY}function Y3(J){return J>=eY&&J<IJ}function x7(J){return J>=IJ&&J<JZ}function Z3(J){return J>=JZ&&J<=J3}function K3(J){return J>=n7&&J<=q3}var p7=function(J){return J>=IJ&&J<=eU},f8=0,u8=4,iY=8,tY=12,N6=16,pU=20,mU=24,nU=28,oU=32,cU=36,lU=40,dU=44,aU=48,Tq=1;var rU=4,g7=8,sU=1,iU=2,tU=83886080,eY=100663296,IJ=134217728,eU=134348799,JZ=268435456,J3=532676607,n7=533725184,q3=2147483647,m7="PI Interrupt";class qZ extends n{constructor(J,q,Q){super("PIReg",J,J.pi_reg,q,Q);this.haveSetMemorySize=!1}reset(){this.haveSetMemorySize=!1}setMemorySize(){if(!this.haveSetMemorySize){const J=this.hardware.rominfo.cic==="6105"?2147484656:2147484440;this.hardware.ram.set32(J-2147483648,8388608),M("Setting memory size"),this.haveSetMemorySize=!0}}readS32(J){const q=this.calcReadEA(J);if(q+4>this.u8.length)throw"Read is out of range";let Q=this.mem.getS32(q);switch(q){case f8:Q&=16777214;break;case u8:Q&=4294967294;break;case iY:case tY:Q=127;break}if(!this.quiet)M(`Reading from PIReg: [${N(J)}] -> ${N(Q)}`);return Q}readU32(J){return this.readS32(J)>>>0}write32(J,q){const Q=this.calcWriteEA(J);if(Q+4>this.u8.length)throw"Write is out of range";if(!this.quiet)M(`Writing to PIReg: ${N(q)} -> [${N(J)}]`);if(this.busy()&&Q!=N6){n64js.warn("Write to PI registers while DMA or IO busy"),this.mem.setBits32(N6,rU);return}switch(Q){case f8:case u8:this.mem.set32(Q,q);break;case iY:this.mem.set32(Q,q),this.copyFromRDRAM();break;case tY:this.mem.set32(Q,q),this.copyToRDRAM();break;case N6:if(q&sU){if(!this.quiet)M("PI_STATUS_REG reset");this.mem.set32(N6,0),this.removePIInterrupt()}if(q&iU){if(!this.quiet)M("PI interrupt cleared");this.mem.clearBits32(N6,g7),this.hardware.mi_reg.clearBits32(W0,yJ),n64js.cpu0.updateCause3()}break;case pU:case mU:case nU:case oU:case cU:case lU:case dU:case aU:this.mem.set32(Q,q);break;default:M(`Unhandled write to PIReg: ${N(q)} -> [${N(J)}]`),this.mem.set32(Q,q);break}}busy(){return this.mem.getBits32(N6,Tq)!=0}copyFromRDRAM(){const J=this.mem.getU32(f8)&16777214,q=this.mem.getU32(u8)&4294967294;let Q=(this.mem.getU32(iY)&16777215)+1,Y,Z=0,K=4096;if(Q>=127&&Q&1)Q++;if(x7(q))if(p7(q))switch(this.hardware.saveType){case"SRAM":Y=this.hardware.saveMem,Z=q-IJ,this.hardware.saveDirty=!0;break;case"FlashRam":if(Y=this.hardware.romD2A2Device.flashBuffer,Z=0,Q>Y.length)n64js.warn(`PI DMA to FlashRam exceeds buffer length (${Q} > ${Y.length})`),Q=Y.length;break}else n64js.halt(`PI: unknown dom2addr2 address for ram->cart DMA: ${N(q)}`);else n64js.halt(`PI: unknown cart address for ram->cart DMA: ${N(q)}`);if(Y)Y.copy(Z,this.hardware.ram,J,Q);this.mem.setBits32(N6,Tq),this.addPIInterrupt(K)}copyToRDRAM(){const J=this.mem.getU32(f8)&16777214,q=this.mem.getU32(u8)&4294967294;let Q=(this.mem.getU32(tY)&16777215)+1;if(!this.quiet)M(`PI: copying ${Q} bytes of data from ${N(q)} to ${N(J)}`);if(Q>=127&&Q&1)Q++;if(Q<=128)Q-=J&7;let Y,Z=0,K=this.estimateDMACyclesFromLength(Q);if(Y3(q))Y=this.hardware.rom,Z=q-eY;else if(Z3(q))Y=this.hardware.rom,Z=q-JZ;else if(K3(q))Y=this.hardware.rom,Z=q-n7;else if(Q3(q))n64js.halt("PI: dom2addr1 transfer is unhandled (save)");else if(x7(q))if(p7(q)){switch(Z=q-IJ,this.hardware.saveType){case"SRAM":Y=this.hardware.saveMem;break;case"FlashRam":Y=this.hardware.romD2A2Device.flashDMASource();break}K=4096}else n64js.halt(`PI: unknown dom2addr2 address for cart->ram DMA: ${N(q)}`);else n64js.halt(`PI: unknown cart address for cart->ram DMA: ${N(q)}`);if(Y)this.hardware.ram.copy(J,Y,Z,Q);this.setMemorySize(),this.mem.setBits32(N6,Tq),this.mem.set32(f8,this.mem.getU32(f8)+Q+7&~7),this.mem.set32(u8,this.mem.getU32(u8)+Q+1&~1),this.addPIInterrupt(K)}estimateDMACyclesFromLength(J){const q=J>>>3;if(q)return q;return 16}removePIInterrupt(){n64js.cpu0.removeEvent(m7)}addPIInterrupt(J){const q=n64js.hardware().timeline.startEvent("PI DMA"),Q=this;n64js.cpu0.addEvent(m7,J,()=>{if(Q.dmaComplete(),q)q.stop()})}dmaComplete(){this.mem.clearBits32(N6,Tq),this.mem.setBits32(N6,g7),this.hardware.mi_reg.setBits32(W0,yJ),n64js.cpu0.updateCause3()}}var QZ=0,X3=4,W3=16,p6=24;var g8=4096;class YZ extends n{constructor(J,q,Q){super("SIReg",J,J.si_reg,q,Q)}readS32(J){this.logRead(J);const q=this.calcReadEA(J);if(q+4>this.u8.length)throw"Read is out of range";if(q===p6)this.checkStatusConsistent();return this.mem.getS32(q)}readU32(J){return this.readS32(J)>>>0}write32(J,q){const Q=this.calcWriteEA(J);if(Q+4>this.u8.length)throw"Write is out of range";switch(Q){case QZ:if(!this.quiet)M(`Writing to SI dram address reigster: ${N(q)}`);this.mem.set32(Q,q);break;case X3:this.mem.set32(Q,q),this.copyToRDRAM();break;case W3:this.mem.set32(Q,q),this.copyFromRDRAM();break;case p6:if(!this.quiet)M("SI interrupt cleared");this.mem.clearBits32(p6,g8),this.hardware.mi_reg.clearBits32(W0,w6),n64js.cpu0.updateCause3();break;default:M(`Unhandled write to SIReg: ${N(q)} -> [${N(J)}]`),this.mem.set32(Q,q);break}}checkStatusConsistent(){const J=this.hardware.mi_reg.getBits32(W0,w6)!==0,q=this.mem.getBits32(p6,g8)!==0;if(J!==q)n64js.halt("SI_STATUS register is in an inconsistent state")}copyFromRDRAM(){const J=this.mem.getU32(QZ)&536870911;if(!this.quiet)M(`SI: copying from ${N(J)} to PIF RAM`);n64js.joybus().dmaWrite(this.hardware.ram,J),this.mem.setBits32(p6,g8),this.hardware.mi_reg.setBits32(W0,w6),n64js.cpu0.updateCause3()}copyToRDRAM(){const J=this.mem.getU32(QZ)&536870911;if(!this.quiet)M(`SI: copying from PIF RAM to ${N(J)}`);n64js.joybus().dmaRead(this.hardware.ram,J),this.mem.setBits32(p6,g8),this.hardware.mi_reg.setBits32(W0,w6),n64js.cpu0.updateCause3()}}class ZZ extends n{constructor(J,q,Q){super("PIFMEM",J,J.pif_mem,q,Q)}readS32(J){const q=this.calcReadEA(J);if(q+4>this.u8.length)throw"Read is out of range";const Q=this.mem.getS32(q);if(q<1984)M(`Reading from PIF rom (${N(J)}). Got ${N(Q)}`);else{const Y=q-1984;switch(Y){case 36:M(`Reading PIF CIC values: ${N(Q)}`);break;case 60:M(`Reading PIF Control byte: ${N(Q)}`);break;default:M(`Reading from PIF ram [${N(J)}]. Got ${N(Q)}`);break}n64js.joybus().cpuRead(Y)}return Q}readU32(J){return this.readS32(J)>>>0}readS8(J){const q=this.calcReadEA(J),Q=this.mem.getU8(q);if(q<1984)M(`Reading from PIF rom (${N(J)}). Got ${M0(Q)}`);else{const Y=q-1984;switch(Y){case 36:M(`Reading PIF CIC values: ${M0(Q)}`);break;case 60:M(`Reading PIF Control byte: ${M0(Q)}`);break;default:M(`Reading from PIF ram [${N(J)}]. Got ${M0(Q)}`);break}n64js.joybus().cpuRead(Y)}return Q}readU8(J){return this.readS8(J)>>>0}write32(J,q){const Q=this.calcWriteEA(J);if(Q<1984){M("Attempting to write to PIF ROM");return}this.mem.set32(Q,q);const Y=Q-1984;switch(Y){case 36:M(`Writing PIF CIC values: ${N(q)}`);break;case 60:M(`Writing PIF Control byte: ${N(q)}`),this.updateControl();break;default:M(`Writing directly to PIF ram [${N(J)}] <-- ${N(q)}`);break}n64js.joybus().cpuWrite(Y)}write16(J,q){const Q=this.calcWriteEA(J);if(Q<1984){M("Attempting to write to PIF ROM");return}const Y=Q&~3,Z=8*(2-(Q&2));this.mem.set32(Y,q<<Z)}write8(J,q){const Q=this.calcWriteEA(J);if(Q<1984){M("Attempting to write to PIF ROM");return}const Y=Q&~3,Z=8*(3-(Q&3));this.mem.set32(Y,q<<Z)}updateControl(){const J=this.mem.subRegion(0,1984),q=this.mem.subRegion(1984,64),Q=q.getU8(63);switch(Q){case 1:M("PIF: execute block");break;case 8:M("PIF: interrupt control"),q.set8(63,0),this.hardware.si_reg.setBits32(p6,g8),this.hardware.mi_reg.setBits32(W0,w6),n64js.cpu0.updateCause3();break;case 16:M("PIF: clear rom"),J.clear();break;case 48:M("PIF: set 0x80 control "),q.set8(63,128);break;case 192:M("PIF: clear ram"),q.clear();break;default:n64js.halt(`Unknown PIF control value: ${M0(Q)}`);break}}}class BJ extends n{constructor(J,q,Q){super("VMEM",J,J.ram,q,Q)}calcInternalEA(J){return n64js.cpu0.translateReadInternal(J)&8388607}calcReadEA(J){return n64js.cpu0.translateRead(J)&8388607}calcWriteEA(J){return n64js.cpu0.translateWrite(J)&8388607}}class KZ extends n{constructor(J,q,Q){super("RAM",J,J.ram,q,Q);this.dataView=this.mem.dataView,this.s32=this.mem.s32Array()}readU32(J){const q=J-2147483648;return this.dataView.getUint32(q,!1)}readS32(J){const q=J-2147483648;return this.dataView.getInt32(q,!1)}write32(J,q){const Q=J-2147483648;this.dataView.setUint32(Q,q,!1)}}class XZ extends n{constructor(J,q,Q){super("RAM",J,J.ram,q,Q)}}class _q extends n{constructor(J,q,Q){super("Invalid",J,null,q,Q)}read(J){return M(`Reading from invalid address ${N(J)}`),0}write(J){M(`Writing to invalid address ${N(J)}`)}readU32(J){return this.read(J)>>>0}readU16(J){return this.read(J)&65535}readU8(J){return this.read(J)&255}readS32(J){return this.read(J)>>0}readS16(J){return this.read(J)&65535}readS8(J){return this.read(J)&255}write32(J,q){this.write(J,q)}write16(J,q){this.write(J,q)}write8(J,q){this.write(J,q)}}class WZ extends n{constructor(J,q,Q){super("RDRAMReg",J,J.rdram_reg,q,Q)}calcEA(J){return J&255}}var z3=12;class $Z extends n{constructor(J,q,Q){super("RIReg",J,J.ri_reg,q,Q)}reset(){this.mem.set32(z3,1)}}class k6{constructor(J,q,Q){if(q===void 0)q=0;if(Q===void 0)Q=J.byteLength-q;this.arrayBuffer=J,this.offset=q,this.length=Q,this.u8=new Uint8Array(J,q,Q),this.dataView=new DataView(J,q,Q)}clear(){for(let J=0;J<this.u8.length;++J)this.u8[J]=0}set(J,q,Q){for(let Y=0;Y<q;++Y)this.u8[J+Y]=Q}subRegion(J,q){if(J+q>this.length)throw"end is out of bounds";return new k6(this.arrayBuffer,this.offset+J,q)}s32Array(){return new Int32Array(this.arrayBuffer,this.offset,this.length/4)}copy(J,q,Q,Y){if(J+Y>this.u8.length)throw"overflow dst";if(Q+Y>q.u8.length)throw"overflow src";for(let Z=0;Z<Y;++Z)this.u8[J+Z]=q.u8[Q+Z]}getU64(J){return this.dataView.getBigUint64(J,!1)}getU32(J){return this.dataView.getUint32(J,!1)}getU16(J){return this.dataView.getUint16(J,!1)}getU8(J){return this.dataView.getUint8(J,!1)}getS64(J){return this.dataView.getBigInt64(J,!1)}getS32(J){return this.dataView.getInt32(J,!1)}getS16(J){return this.dataView.getInt16(J,!1)}getS8(J){return this.dataView.getInt8(J,!1)}set64masked(J,q,Q){const Z=this.getU64(J,!1)&~Q|q&Q;this.set64(J,Z,!1)}set32masked(J,q,Q){const Z=this.getU32(J,!1)&~Q|q&Q;this.set32(J,Z)}set64(J,q){this.dataView.setBigUint64(J,q,!1)}set32(J,q){this.dataView.setUint32(J,q,!1)}set16(J,q){this.dataView.setUint16(J,q,!1)}set8(J,q){this.dataView.setUint8(J,q,!1)}clearBits32(J,q){const Q=this.getU32(J)&~q;return this.set32(J,Q),Q}setBits32(J,q){const Q=this.getU32(J)|q;return this.set32(J,Q),Q}getBits32(J,q){return this.getU32(J)&q}}var M3=function(J){return(J<<16|J&65535)>>>0},H3=3019833364,zZ=3019833376,Sq=512,F3=zZ+Sq,j3=75,N3=120,G3=165,P3=180,L3=210,V3=225,U3=240,o7=0,c7=1,l7=2,d7=3,a7=4;class HZ extends n{constructor(J,q,Q){super("ROMd1a1",J,J.rom,q,Q)}write32(J,q){throw`Writing to rom d1a1 ${N(q)} -> [${N(J)}]`}write16(J,q){throw`Writing to rom d1a1 ${r(q)} -> [${N(J)}]`}write8(J,q){throw`Writing to rom d1a1 ${M0(q)} -> [${N(J)}]`}}class FZ extends n{constructor(J,q,Q){super("ROMd1a2",J,J.rom,q,Q);this.lastWrite=0,this.hasLastWrite=!1,this.debugBuffer=new ArrayBuffer(Sq),this.debugBufferU32=new Uint32Array(this.debugBuffer),this.debugBufferU8=new Uint8Array(this.debugBuffer),this.output=""}calcEA(J){return J-this.rangeStart+2&~2}write64(J,q){this.cacheLastWrite(Number(q>>32n))}write32(J,q){if(J==H3)return this.writeDebugBufferLen(q);if(J>=zZ&&J<F3)return this.writeDebugBuffer32(J-zZ,q);this.cacheLastWrite(q>>>0)}write16(J,q){const Q=8*(2-(J&2));this.cacheLastWrite(q<<Q&4294967295)}write8(J,q){const Q=8*(3-(J&3));this.cacheLastWrite(q<<Q&4294967295)}readU32(J){if(this.hasLastWrite)return this.consumeLastWrite()>>>0;return super.readU32(J)}readS32(J){if(this.hasLastWrite)return this.consumeLastWrite()>>0;return super.readS32(J)}readU16(J){if(this.hasLastWrite)return this.consumeLastWrite()>>>16;return super.readU16(J)}readS16(J){if(this.hasLastWrite)return this.consumeLastWrite()>>16;return super.readS16(J)}readU8(J){if(this.hasLastWrite)return this.consumeLastWrite()>>>24;return super.readU8(J)}readS8(J){if(this.hasLastWrite)return this.consumeLastWrite()>>24;return super.readS8(J)}cacheLastWrite(J){if(!this.hasLastWrite)this.lastWrite=J,this.hasLastWrite=!0}consumeLastWrite(){return this.hasLastWrite=!1,this.lastWrite}writeDebugBufferLen(J){if(J>Sq)console.log(`debug buffer value too long (${J}), truncating`),J=Sq;for(let q=0;q<J;q++)this.output+=String.fromCharCode(this.debugBufferU8[q^3]);this.flushDebugOutput()}writeDebugBuffer32(J,q){const Q=J>>>2;this.debugBufferU32[Q]=q}flushDebugOutput(){const J=this.output.lastIndexOf("\n");if(J>=0)console.log(this.output.substring(0,J+1)),this.output=this.output.substring(J+1)}}class jZ extends n{constructor(J,q,Q){super("ROMd1a3",J,J.rom,q,Q)}write32(J,q){throw`Writing to rom d1a3 ${N(q)} -> [${N(J)}]`}write16(J,q){throw`Writing to rom d1a3 ${r(q)} -> [${N(J)}]`}write8(J,q){throw`Writing to rom d1a3 ${M0(q)} -> [${N(J)}]`}}class NZ extends n{constructor(J,q,Q){super("ROMd2a1",J,null,q,Q)}read(J){if(J==2768241928)return M("Reading from ROMd2a1 0xa5000508 - spoofing ~0 value"),~0;return M(`Reading from invalid ROMd2a1 address ${N(J)}`),0}readU32(J){return this.read(J)>>>0}readU16(J){return this.read(J)&65535}readU8(J){return this.read(J)&255}readS32(J){return this.read(J)>>0}readS16(J){return this.read(J)&65535}readS8(J){return this.read(J)&255}write32(J,q){throw`Writing to rom ${N(q)} -> [${N(J)}]`}write16(J,q){throw`Writing to rom ${r(q)} -> [${N(J)}]`}write8(J,q){throw`Writing to rom ${M0(q)} -> [${N(J)}]`}}class GZ extends n{constructor(J,q,Q){super("ROMd2a2",J,null,q,Q);this.flashMode=o7,this.flashStatus=new k6(new ArrayBuffer(8)),this.flashBuffer=new k6(new ArrayBuffer(128)),this.flashOffset=0}hasFlashRam(){return this.hardware.saveType=="FlashRam"}readU32(J){return this.readS32(J)>>>0}readU16(J){return this.readS16(J)>>>0}readU8(J){return this.readS8(J)>>>0}readS32(J){const q=this.calcWriteEA(J);if(q>=557056)return M3(J);if(this.hasFlashRam()){const Q=q&4;return this.flashStatus.getS32(Q)}throw`Reading s32 from rom d2a2 [${N(J)}]`}readS16(J){throw`Reading s16 from rom d2a2 [${N(J)}]`}readS8(J){throw`Reading s8 from rom d2a2 [${N(J)}]`}write32(J,q){const Q=this.calcWriteEA(J);if(this.hasFlashRam()){if(Q!=0)this.flashCommand(q);return}throw`Writing s32 to rom ${N(q)} -> [${N(J)}]`}write16(J,q){throw`Writing s16 to rom ${r(q)} -> [${N(J)}]`}write8(J,q){throw`Writing s8 to rom ${M0(q)} -> [${N(J)}]`}flashDMASource(){switch(this.flashMode){case d7:return this.hardware.saveMem;case a7:return this.flashStatus}return n64js.warn(`Unexpected mode for flash DMA: ${this.flashMode}`),null}flashCommand(J){const q=J>>>24&255;switch(q){case j3:if(this.flashOffset=(J&65535)*128,!this.quiet)M(`set erase offset: ${N(this.flashOffset)}`);break;case N3:if(!this.quiet)M("set mode ERASE");this.flashMode=c7,this.flashStatus.set64(0,0x1111_8008_00c2_001dn);break;case G3:if(this.flashOffset=(J&65535)*128,!this.quiet)M(`set write offset: ${N(this.flashOffset)}`);this.flashStatus.set64(0,0x1111_8004_00c2_001dn);break;case P3:if(!this.quiet)M("setting mode WRITE");this.flashMode=l7;break;case L3:switch(this.flashMode){case o7:if(!this.quiet)M("execute IDLE (ignored)");break;case c7:if(!this.quiet)M(`execute ERASE flash @ ${N(this.flashOffset)} (set saveMem to 0xff)`);this.hardware.saveMem.set(this.flashOffset,128,255),this.hardware.saveDirty=!0;break;case l7:if(!this.quiet)M(`execute WRITE flash @ ${N(this.flashOffset)} (copy flashBuffer to saveMem)`);this.hardware.saveMem.copy(this.flashOffset,this.flashBuffer,0,128),this.hardware.saveDirty=!0;break;default:M(`execute (${N(J)}) with unhandled mode: ${this.flashMode}`);break}break;case V3:if(!this.quiet)M("setting mode STATUS");this.flashMode=a7,this.flashStatus.set64(0,0x1111_8001_00c2_001dn);break;case U3:if(!this.quiet)M("setting mode READ");this.flashMode=d7,this.flashStatus.set64(0,0x1111_8004_f000_001dn);break;default:if(!this.quiet)M(`execute with unknown command ${N(q)}`)}}}function i7(){const J=n64js.hardware(),q=J.cachedMemDevice.u8,Q=J.sp_mem.subRegion(A3,h3),Y=new s7(q,Q);let Z=!1;switch(Y.type){case I3:{const K=J.timeline.startEvent(`HLE Task ${Y.detectVersionString()}`);if(EW(Y),J.miRegDevice.interruptDP(),K)K.stop();Z=!0}break;case B3:Z=!r7.enableAudioLLE;break;case R3:break;case b3:break}return Z}var r7={enableAudioLLE:!0},O3=g0.addFolder("Audio");O3.add(r7,"enableAudioLLE").name("Audio LLE");var A3=4032,h3=64,E3=0;var w3=16,k3=20,C3=24,D3=28;var y3=48;var I3=1,B3=2,R3=3,b3=4;class s7{constructor(J,q){this.ram_u8=J,this.type=q.getU32(E3),this.codeAddr=q.getU32(w3)&536870911,this.codeSize=this.clampCodeSize(q.getU32(k3)),this.codeDataAddr=q.getU32(C3)&536870911,this.codeDataSize=q.getU32(D3),this.dataPtr=q.getU32(y3)}dumpCode(){const J=n64js.hardware().cachedMemDevice.mem,Q=ZQ(J,4224,this.codeAddr,this.codeSize);let Y=`${this.detectVersionString()}\n`;for(let Z of Q)Y+=`${B(Z.address,16)} ${Z.disassembly}\n`;Y+="\nDMEM\n",Y+=tK(J,0,this.codeDataAddr,this.codeDataSize),console.log(Y)}loadUcode(J,q,Q,Y){this.codeAddr=J&536870911,this.codeSize=this.clampCodeSize(q),this.codeDataAddr=Q&536870911,this.codeDataSize=Y}clampCodeSize(J){if(J==0||J>4096)return 4096;return J}dataByte(J){return this.ram_u8[this.codeDataAddr+J]}codeByte(J){return this.ram_u8[this.codeAddr+J]}detectVersionString(){const J="R".charCodeAt(0),q="S".charCodeAt(0),Q="P".charCodeAt(0);for(let Y=0;Y+2<this.codeDataSize;++Y)if(this.dataByte(Y+0)===J&&this.dataByte(Y+1)===q&&this.dataByte(Y+2)===Q){let Z="";for(let K=Y;K<this.codeDataSize;++K){const X=this.dataByte(K);if(X===0)break;if(X>=32)Z+=String.fromCharCode(X)}return Z}return""}computeMicrocodeHash(){let J=0;for(let q=0;q<this.codeSize;++q)J=J*17+this.codeByte(q)>>>0;return J}}var T3=!0,PZ=0,LZ=4,VZ=8,UZ=12,RJ=16,t7=20,e7=24,J5=28,_3=4294967288,S3=4294967288,q5=4287627256,Q5=4287627256,Y5=4096,Z5=4293918720,K5=20,x8=1044480,X5=12,p8=4095,m8=0,MZ=1,OZ=2,W5=4,AZ=8,hZ=16,$5=32,z5=64,H5=128,F5=256,j5=512,N5=1024,G5=2048,P5=4096,L5=8192,V5=16384,U5=32768,M5=65536,O5=131072,A5=262144,h5=524288,E5=1048576,w5=2097152,k5=4194304,C5=8388608,D5=16777216,EZ=1,y5=2,I5=4,B5=8;var v3=32,R5=64,f3=128,u3=256,T5=512,g3=1024,x3=2048,p3=4096,m3=8192,n3=16384;var o3=T5,c3=0,l3=4092,d3="SP DMA",b5=1,a3=2;class _5{constructor(J,q,Q,Y){this.isRead=J,this.spMemAddr=q,this.rdRamAddr=Q,this.len=Y}}class wZ extends n{constructor(J,q,Q){super("SPMem",J,J.sp_mem,q,Q);this.pendingSPMemAddr=0,this.pendingDRAMAddr=0}calcEA(J){return(J-this.rangeStart)%8192}write64(J,q){const Q=this.calcWriteEA(J);this.mem.set32(Q,Number(q>>32n))}write16(J,q){const Q=this.calcWriteEA(J),Y=Q&~3,Z=8*(2-(Q&2));this.mem.set32(Y,q<<Z)}write8(J,q){const Q=this.calcWriteEA(J),Y=Q&~3,Z=8*(3-(Q&3));this.mem.set32(Y,q<<Z)}}class kZ extends n{constructor(J,q,Q){super("SPIBIST",J,J.sp_ibist_mem,q,Q)}write32(J,q){const Q=this.calcWriteEA(J);switch(Q){case c3:this.mem.set32(Q,q&l3);break;default:M(`Unhandled write to SPIBISTReg: ${N(q)} -> [${N(J)}]`)}}}class CZ extends n{constructor(J,q,Q){super("SPReg",J,J.sp_reg,q,Q);this.dmaQueue=[]}write32(J,q){this.writeReg32(this.calcWriteEA(J),q)}writeReg32(J,q){if(J+4>this.u8.length)throw"Write is out of range";switch(J){case PZ:this.pendingSPMemAddr=q&_3;break;case LZ:this.pendingDRAMAddr=q&S3;break;case VZ:this.mem.set32(J,q&q5),this.pushDMA(b5,q&q5);break;case UZ:this.mem.set32(J,q&Q5),this.pushDMA(a3,q&Q5);break;case RJ:this.spUpdateStatus(q);break;case t7:case e7:break;case J5:this.mem.set32(J,0);break;default:M(`Unhandled write to SPReg: ${N(q)} -> [${N(J)}]`),this.mem.set32(J,q)}}readU32(J){return this.logRead(J),this.readRegU32(this.calcReadEA(J))}readS32(J){return this.logRead(J),this.readRegU32(this.calcReadEA(J))>>0}readRegU32(J){if(J+4>this.u8.length)throw"Read is out of range";const q=this.mem.getU32(J);if(J==J5)this.mem.set32(J,1);return q}setStatusBits(J){if(this.mem.setBits32(RJ,J)&R5)this.hardware.miRegDevice.interruptSP()}spUpdateStatus(J){if(!this.quiet){if(J&MZ)M("SP: Clearing Halt");if(J&OZ)M("SP: Setting Halt");if(J&W5)M("SP: Clearing Broke");if(J&AZ)M("SP: Clearing Interrupt");if(J&hZ)M("SP: Setting Interrupt");if(J&$5)M("SP: Clearing Single Step");if(J&z5)M("SP: Setting Single Step");if(J&H5)M("SP: Clearing Interrupt on break");if(J&F5)M("SP: Setting Interrupt on break");if(J&j5)M("SP: Clearing Sig0 (Yield)");if(J&N5)M("SP: Setting Sig0 (Yield)");if(J&G5)M("SP: Clearing Sig1 (Yielded)");if(J&P5)M("SP: Setting Sig1 (Yielded)");if(J&L5)M("SP: Clearing Sig2 (TaskDone)");if(J&V5)M("SP: Setting Sig2 (TaskDone)");if(J&U5)M("SP: Clearing Sig3");if(J&M5)M("SP: Setting Sig3");if(J&O5)M("SP: Clearing Sig4");if(J&A5)M("SP: Setting Sig4");if(J&h5)M("SP: Clearing Sig5");if(J&E5)M("SP: Setting Sig5");if(J&w5)M("SP: Clearing Sig6");if(J&k5)M("SP: Setting Sig6");if(J&C5)M("SP: Clearing Sig7");if(J&D5)M("SP: Setting Sig7")}function q(K,X,W,z,F){const j=X&z,G=X&W;if(j&&!G)return K|F;else if(G&&!j)return K&~F;return K}let Q=this.mem.getU32(RJ),Y=!1,Z=!1;if(J&OZ&&J&MZ);else if(J&OZ)Q|=EZ,Z=!0;else if(J&MZ)Q&=~EZ,Y=!0;if(J&hZ&&J&AZ);else if(J&hZ)this.hardware.mi_reg.setBits32(W0,v8),n64js.cpu0.updateCause3();else if(J&AZ)this.hardware.mi_reg.clearBits32(W0,v8),n64js.cpu0.updateCause3();if(Q=q(Q,J,W5,0,y5),Q=q(Q,J,$5,z5,v3),Q=q(Q,J,H5,F5,R5),Q=q(Q,J,j5,N5,f3),Q=q(Q,J,G5,P5,u3),Q=q(Q,J,L5,V5,T5),Q=q(Q,J,U5,M5,g3),Q=q(Q,J,O5,A5,x3),Q=q(Q,J,h5,E5,p3),Q=q(Q,J,w5,k5,m3),Q=q(Q,J,C5,D5,n3),this.mem.set32(RJ,Q),Y)if(i7()||!T3)this.hardware.spRegDevice.setStatusBits(o3|y5|EZ);else H.unhalt();else if(Z)H.halt(0)}pushDMA(J,q){if(this.dmaQueue.length>=2){n64js.warn("RSP DMA FIFO is full");return}const Q=J==b5,Y=new _5(Q,this.pendingSPMemAddr,this.pendingDRAMAddr,q);if(this.dmaQueue.push(Y),this.setDMAStatus(),this.dmaQueue.length==1)this.startDMA(Y)}startDMA(J){if(J.isRead)this.spCopyFromRDRAM(J.spMemAddr,J.rdRamAddr,J.len);else this.spCopyToRDRAM(J.spMemAddr,J.rdRamAddr,J.len)}dmaComplete(){if(this.dmaQueue.shift(),this.dmaQueue.length>0)this.startDMA(this.dmaQueue[0]);this.setDMAStatus()}setDMAStatus(){const J=this.dmaQueue.length>=2?B5:0,q=this.dmaQueue.length>=1?I5:0;this.mem.set32(t7,J?1:0),this.mem.set32(e7,q?1:0),this.mem.set32masked(RJ,J|q,B5|I5)}spCopyFromRDRAM(J,q,Q){const Y=J&8191,Z=q&16777215,K=((Q&p8)>>>m8|7)+1,X=((Q&x8)>>>X5)+1,W=(Q&Z5)>>>K5,z=Y&Y5;if(!this.quiet)M(`SP: copying ${K} bytes from ram ${N(Z)} to sp ${r(Y)}, count ${X}, skip ${W}`);let F=Y,j=Z;for(let P=0;P<X;P++){for(let L=0;L<K;++L)this.hardware.sp_mem.u8[z|F&4095]=this.hardware.ram.u8[j],F++,j++;j+=W}this.mem.set32(PZ,z|F&4095),this.mem.set32(LZ,j),this.mem.set32masked(VZ,4088<<m8,x8|p8),this.mem.set32masked(UZ,4088<<m8,x8|p8);const G=this.estimateDMACyclesFromLength(X,K);this.addSPDMAEvent(G)}spCopyToRDRAM(J,q,Q){const Y=J&8191,Z=q&16777215,K=((Q&p8)>>>m8|7)+1,X=((Q&x8)>>>X5)+1,W=(Q&Z5)>>>K5,z=Y&Y5;if(!this.quiet)M(`SP: copying ${K} bytes from sp ${r(Y)} to ram ${N(Z)}, count ${X}, skip ${W}`);let F=Z,j=Y;for(let P=0;P<X;P++){for(let L=0;L<K;++L)this.hardware.ram.u8[F]=this.hardware.sp_mem.u8[z|j&4095],F++,j++;F+=W}this.mem.set32(PZ,z|j&4095),this.mem.set32(LZ,F),this.mem.set32masked(VZ,4088<<m8,x8|p8),this.mem.set32masked(UZ,4088<<m8,x8|p8);const G=this.estimateDMACyclesFromLength(X,K);this.addSPDMAEvent(G)}estimateDMACyclesFromLength(J,q){const Y=J*q>>>3;if(Y)return Y;return 16}addSPDMAEvent(J){const q=this;n64js.cpu0.addEvent(d3,J,()=>{q.dmaComplete()})}}var WM=function(J){switch(J){case X8:return KM;case qJ:return x5;case ZK:return XM}return x5},$M=function(J){return J==X8?50:60},S5=0,v5=4,f5=8,DZ=12,yZ=16,r3=20,vq=24,s3=28,i3=32,t3=36,e3=40,JM=44,qM=48,QM=52,u5=2,g5=3;var YM=64;var ZM=3,KM=49656530,x5=48681812,XM=48628316,IZ="VI Interrupt";class BZ extends n{constructor(J,q,Q){super("VIReg",J,J.vi_reg,q,Q);this.field=0,this.videoClock=0,this.refreshRate=0,this.countPerScanline=0,this.countPerVbl=0,this.reset()}reset(){const J=this.hardware.rominfo.tvType==qJ;this.videoClock=WM(J),this.refreshRate=$M(J),this.countPerScanline=0,this.countPerVbl=0,this.screenWidth=640,this.screenHeight=J?480:576,this.hScanMin=J?108:128,this.hScanMax=this.hScanMin+this.screenWidth,this.vScanMin=J?34:44,this.vScanMax=this.vScanMin+this.screenHeight,this.dims=new p5(this.screenWidth,this.screenHeight)}get controlReg(){return this.mem.getU32(S5)}get dramAddrReg(){return this.mem.getU32(v5)}get hWidthReg(){return this.mem.getU32(f5)}get vIntrReg(){return this.mem.getU32(DZ)}get vCurrentLineReg(){return this.mem.getU32(yZ)}get timingReg(){return this.mem.getU32(r3)}get vSyncReg(){return this.mem.getU32(vq)}get hSyncReg(){return this.mem.getU32(s3)}get hSyncLeapReg(){return this.mem.getU32(i3)}get hVideoReg(){return this.mem.getU32(t3)}get vVideoReg(){return this.mem.getU32(e3)}get vBurstReg(){return this.mem.getU32(JM)}get xScaleReg(){return this.mem.getU32(qM)}get yScaleReg(){return this.mem.getU32(QM)}get interlaced(){return(this.controlReg&YM)!=0}get modeType(){return this.controlReg&ZM}get is32BitMode(){return this.modeType==g5}get is16BitMode(){return this.modeType==u5}get xScale(){return(this.xScaleReg&4095)/1024}get yScale(){return(this.yScaleReg&4095)/1024}get bitDepth(){switch(this.modeType){case g5:return 32;case u5:return 16}return 0}dump(){console.log(`VI_CONTROL = ${N(this.controlReg)}`),console.log(`VI_DRAM_ADDR = ${N(this.dramAddrReg)}`),console.log(`VI_H_WIDTH = ${N(this.hWidthReg)}`),console.log(`VI_V_INTR = ${N(this.vIntrReg)}`),console.log(`VI_V_CURRENT_LINE = ${N(this.vCurrentLineReg)}`),console.log(`VI_TIMING = ${N(this.timingReg)}`),console.log(`VI_V_SYNC = ${N(this.vSyncReg)}`),console.log(`VI_H_SYNC = ${N(this.hSyncReg)}`),console.log(`VI_H_SYNC_LEAP = ${N(this.hSyncLeapReg)}`),console.log(`VI_H_VIDEO = ${N(this.hVideoReg)}`),console.log(`VI_V_VIDEO = ${N(this.vVideoReg)}`),console.log(`VI_V_BURST = ${N(this.vBurstReg)}`),console.log(`VI_X_SCALE = ${N(this.xScaleReg)} = ${this.xScale}`),console.log(`VI_Y_SCALE = ${N(this.yScaleReg)} = ${this.yScale}`)}verticalBlank(){this.hardware.verticalBlank(),this.field^=this.interlaced?1:0,this.addInterruptEvent(),this.hardware.mi_reg.setBits32(W0,DJ),n64js.cpu0.updateCause3(),x9(),n64js.returnControlToSystem()}initInterrupt(){if(n64js.cpu0.hasEvent(IZ))return;const J=this.mem.getU32(DZ),q=this.mem.getU32(vq);if(J>=q){M(`not setting VI interrupt - intr ${J} >= sync ${q}`);return}this.addInterruptEvent()}addInterruptEvent(){n64js.cpu0.addEvent(IZ,this.countPerVbl,()=>{this.verticalBlank()})}getVblCount(){const J=n64js.cpu0.getCyclesUntilEvent(IZ);return J>=0?J:0}write32(J,q){const Q=this.calcWriteEA(J);if(Q+4>this.u8.length)throw"Write is out of range";switch(Q){case v5:this.mem.set32(Q,q);break;case S5:if(!this.quiet)M(`VI control set to: ${N(q)}`);this.mem.set32(Q,q);break;case f5:if(!this.quiet)M(`VI width set to: ${q}`);this.mem.set32(Q,q);break;case DZ:if(!this.quiet)M(`VI intr set to: ${q}`);this.mem.set32(Q,q),this.initInterrupt();break;case yZ:if(!this.quiet)M(`VI current set to: ${N(q)}`);if(!this.quiet)M("VI interrupt cleared");this.hardware.mi_reg.clearBits32(W0,DJ),n64js.cpu0.updateCause3();break;case vq:if(this.mem.getU32(Q)!=q){const Z=q+1;this.countPerScanline=this.hardware.systemFrequency/this.refreshRate/Z>>0,this.countPerVbl=Z*this.countPerScanline,M(`VI_V_SYNC_REG set to ${q}, cycles per scanline = ${this.countPerScanline}, cycles per vbl = ${this.countPerVbl}`),this.mem.set32(Q,q),this.initInterrupt()}break;default:this.mem.set32(Q,q);break}}readS32(J){this.logRead(J);const q=this.calcReadEA(J);if(q+4>this.u8.length)throw"Read is out of range";if(q===yZ){const Q=this.getVblCount(),Z=(this.countPerVbl-Q)/this.countPerScanline>>0,K=this.mem.getU32(vq);let X=Z;if(X>=K)X-=K;X=X&~1|this.field,this.mem.set32(q,X)}return this.mem.getS32(q)}readU32(J){return this.readS32(J)>>>0}computeDimensions(){if(this.modeType==0)return M("mode type is 0 - not rendering"),null;const J=this.hVideoReg,q=J>>16&1023,Q=J&1023;let Y=Math.max(q,this.hScanMin),Z=Math.min(Q,this.hScanMax);const K=this.vVideoReg,X=K>>16&1023,W=K&1023;let z=Math.max(X,this.vScanMin),F=W<X?this.vScanMax:Math.min(W,this.vScanMax);if(Y>=this.hScanMin)Y+=8;if(Z<this.hScanMax)Z-=7;const j=this.dims;j.interlaced=this.interlaced,j.field=this.field,j.xSubpixel=this.xScaleReg>>16&4095,j.ySubpixel=this.yScaleReg>>16&4095,j.xScale=this.xScaleReg&4095,j.yScale=this.yScaleReg&4095,j.sx0=Y-q,j.sy0=z-X,j.dx0=Y-this.hScanMin,j.dy0=z-this.vScanMin,j.dstWidth=Z-Y,j.dstHeight=F-z,j.srcPitch=this.hWidthReg;const G=(j.sx0+j.dstWidth)*j.xScale>>10,P=(j.sy0+j.dstHeight)*j.yScale>>11,L=j.srcPitch>768||j.srcPitch>=G*2?2:1;return j.srcWidth=G,j.srcHeight=P*L,j}renderBackBuffer(){const J=this.computeDimensions();if(!J)return null;const q=this.dramAddrReg&16777214;if(!q)return null;const Q=this.hardware.cachedMemDevice.mem.dataView;if(this.is32BitMode)return J.renderBackBuffer32(Q,q);if(this.is16BitMode)return J.renderBackBuffer16(Q,q);return null}}class p5{constructor(J,q){this.screenWidth=640,this.screenHeight=480,this.pixels32bpp=new Uint8Array(J*q*4),this.pixels16bpp=new Uint16Array(J*q),this.interlaced=!1,this.field=0,this.dstWidth=640,this.dstHeight=480,this.srcPitch=320,this.srcWidth=320,this.srcHeight=240,this.xSubpixel=0,this.ySubpixel=0,this.xScale=512,this.yScale=1024,this.sx0=0,this.sy0=0,this.dx0=0,this.dy0=0}renderBackBuffer32(J,q){const Q=this.pixels32bpp,Y=-this.screenWidth;let Z=(this.screenHeight-1-this.dy0)*this.screenWidth;const K=255;let X=this.sy0*this.yScale+this.ySubpixel;for(let W=0;W<this.dstHeight;W++){if(!this.interlaced||(this.dy0+W&1)!=this.field){const z=q+(X>>>11)*this.srcPitch*4;let F=Z+this.dx0,j=this.sx0*this.xScale+this.xSubpixel;for(let G=0;G<this.dstWidth;G++){const P=J.getInt32(z+(j>>>10)*4,!1);Q[F*4+0]=P>>>24,Q[F*4+1]=P>>>16,Q[F*4+2]=P>>>8,Q[F*4+3]=K,F++,j+=this.xScale}}X+=this.yScale,Z+=Y}return Q}renderBackBuffer16(J,q){const Q=this.pixels16bpp,Y=-this.screenWidth;let Z=(this.screenHeight-1-this.dy0)*this.screenWidth;const K=1;let X=this.sy0*this.yScale+this.ySubpixel;for(let W=0;W<this.dstHeight;W++){if(!this.interlaced||(this.dy0+W&1)!=this.field){const z=q+(X>>>11)*this.srcPitch*2;let F=Z+this.dx0,j=this.sx0*this.xScale+this.xSubpixel;for(let G=0;G<this.dstWidth;G++)Q[F++]=J.getInt16(z+(j>>>10)*2,!1)|K,j+=this.xScale}X+=this.yScale,Z+=Y}return Q}}class RZ{constructor(J){this.map=this.createMemMap(J)}createMemMap(J){const q=[];for(let Q=0;Q<16384;++Q)q.push(void 0);if(J.map((Q)=>{const Y=Q.rangeStart>>>18,Z=Q.rangeEnd-1>>>18;for(let K=Y;K<=Z;++K)q[K]=Q}),q.length!==16384)throw"initialisation error";return q}getMemoryHandler(J){var q=this.map[J>>>18];if(q)return q;throw M(`accessing unhandled location ${N(J)}`),`unhandled access ${N(J)}`}readMemoryInternal32(J){const q=this.map[J>>>18];if(q)return q.readInternal32(J);return 3722304989}writeMemoryInternal32(J,q){const Q=this.map[J>>>18];if(Q)Q.writeInternal32(J,q)}}var S0=function(J){return new k6(new ArrayBuffer(J))},bZ=64,zM=4096,HM=93750000;class bJ{constructor(){this.data=new Uint8Array(32768),this.dirty=!1}init(J){this.dirty=!1;for(let q=0;q<this.data.length;q++)this.data[q]=0;if(J&&J.data)oY(J.data,this.data)}}class TZ{constructor(J){this.rominfo=J,this.timeline=new lY(this.getOpsExecuted.bind(this)),this.systemFrequency=HM,this.rom=null,this.pif_mem=S0(2048),this.ram=S0(8388608),this.sp_mem=S0(8192),this.sp_reg=S0(32),this.sp_ibist_mem=S0(8),this.dpc_mem=S0(32),this.dps_mem=S0(16),this.rdram_reg=S0(48),this.mi_reg=S0(16),this.vi_reg=S0(56),this.ai_reg=S0(24),this.pi_reg=S0(52),this.ri_reg=S0(32),this.si_reg=S0(28),this.saveMem=null,this.saveDirty=!1,this.mempacks=[new bJ,new bJ,new bJ,new bJ],this.mappedMemDevice=new BJ(this,0,2147483648),this.invalidCachedMemDevice=new _q(this,2147483648,2684354560),this.cachedMemDevice=new KZ(this,2147483648,2155872256),this.invalidUnachedMemDevice=new _q(this,2684354560,3221225472),this.uncachedMemDevice=new XZ(this,2684354560,2692743168),this.rdRamRegDevice=new WZ(this,2750414848,2751463424),this.spMemDevice=new wZ(this,2751463424,2751725568),this.spRegDevice=new CZ(this,2751725568,2751725600),this.spIbistDevice=new kZ(this,2751987712,2751987720),this.dpcDevice=new rY(this,2752512000,2752512032),this.dpsDevice=new sY(this,2753560576,2753560592),this.miRegDevice=new xY(this,2754609152,2754609168),this.viRegDevice=new BZ(this,2755657728,2755657784),this.aiRegDevice=new dY(this,2756706304,2756706328),this.piRegDevice=new qZ(this,2757754880,2757754932),this.riRegDevice=new $Z(this,2758803456,2758803488),this.siRegDevice=new YZ(this,2759852032,2759852060),this.romD2A1Device=new NZ(this,2768240640,2785017856),this.romD1A1Device=new HZ(this,2785017856,2818572288),this.romD2A2Device=new GZ(this,2818572288,2952790016),this.romD1A2Device=new FZ(this,2952790016,3217031168),this.pifMemDevice=new ZZ(this,3217031168,3217033216),this.romD1A3Device=new jZ(this,3218079744,3221225472),this.mappedMem2Device=new BJ(this,3221225472,3758096384),this.mappedMem3Device=new BJ(this,3758096384,4294967296),this.devices=[this.mappedMemDevice,this.invalidCachedMemDevice,this.cachedMemDevice,this.invalidUnachedMemDevice,this.uncachedMemDevice,this.rdRamRegDevice,this.spMemDevice,this.spRegDevice,this.spIbistDevice,this.dpcDevice,this.dpsDevice,this.miRegDevice,this.viRegDevice,this.aiRegDevice,this.piRegDevice,this.riRegDevice,this.siRegDevice,this.romD2A1Device,this.romD1A1Device,this.romD2A2Device,this.romD1A2Device,this.pifMemDevice,this.romD1A3Device,this.mappedMem2Device,this.mappedMem3Device],this.memMap=new RZ(this.devices),this.cpu0=new SY(this),this.cpu1=new $q(this),this.cpu2=new vY(this)}reset(){this.cpu0.reset(),this.cpu1.reset(),this.cpu2.reset(),this.pif_mem.clear(),this.ram.clear(),this.sp_mem.clear(),this.sp_reg.clear(),this.sp_ibist_mem.clear(),this.rdram_reg.clear(),this.dpc_mem.clear(),this.dps_mem.clear(),this.mi_reg.clear(),this.vi_reg.clear(),this.ai_reg.clear(),this.pi_reg.clear(),this.ri_reg.clear(),this.si_reg.clear(),this.initSaveGame();for(let J of this.devices)J.reset()}getOpsExecuted(){return this.cpu0.getOpsExecuted()}createROM(J){if(Math.max(J.byteLength<8388608))J=J.transfer(8388608);const Q=new k6(J);return this.rom=Q,this.romD1A1Device.setMem(Q),this.romD1A2Device.setMem(Q),this.romD1A3Device.setMem(Q),Q}loadROM(){if(this.rom)this.sp_mem.copy(bZ,this.rom,bZ,zM-bZ)}verticalBlank(){this.flushSaveData(),this.timeline.newFrame()}initSaveGame(){for(let[q,Q]of this.mempacks.entries()){const Y=n64js.getLocalStorageItem(`mempack${q}`);Q.init(Y)}const J=this.saveSizeBytes();if(J){const q=new k6(new ArrayBuffer(J)),Q=n64js.getLocalStorageItem("save");if(Q&&Q.data)oY(Q.data,q.u8);this.saveMem=q}else this.saveMem=null;this.saveDirty=!1}saveSizeBytes(){switch(this.saveType){case"Eeprom4k":return 512;case"Eeprom16k":return 2048;case"SRAM":return 32768;case"FlashRam":return 131072}if(this.saveType)n64js.ui().displayWarning(`Unhandled savegame type: ${this.saveType}.`);return 0}get saveType(){return this.rominfo.save}flushSaveData(){if(this.saveMem&&this.saveDirty)this.saveU8Array("save",this.saveMem.u8),this.saveDirty=!1;for(let[J,q]of this.mempacks.entries())if(q.dirty)this.saveU8Array(`mempack${J}`,q.data),q.dirty=!1}saveU8Array(J,q){var Q={name:this.rominfo.name,id:this.rominfo.id,data:D7(q)};n64js.setLocalStorageItem(J,Q)}checkSIStatusConsistent(){this.siRegDevice.checkStatusConsistent()}}var FM=function(J,q){if(typeof q==="object"&&q!==null){if(q instanceof Map)return{_meta:{type:"map"},value:Array.from(q.entries())};else if(q instanceof Set)return{_meta:{type:"set"},value:Array.from(q.values())};else if("_meta"in q)return{...q,_meta:{type:"escaped-meta",value:q._meta}}}return q},jM=function(J,q){if(typeof q==="object"&&q!==null){if("_meta"in q)if(q._meta.type==="map")return new Map(q.value);else if(q._meta.type==="set")return new Set(q.value);else if(q._meta.type==="escaped-meta")return{...q,_meta:q._meta.value};else console.warn("Unexpected meta",q._meta)}return q},_Z=(J)=>JSON.stringify(J,FM),m5=(J)=>JSON.parse(J,jM);var n5=function(J){return J>>24&255|J>>8&65280|J<<8&16711680|J<<24&4278190080};function o5(J,q){return B(n5(J),32)+B(n5(q),32)}function c5(J){let q=0;for(let Q=0;Q<4032;Q++)q=q+J[64+Q];switch(q){case 211495:return"6101";case 213534:return"6101";case 213060:return"6102";case 219088:return"6103";case 293505:return"6105";case 225740:return"6106";case 213961:return"6106";default:return M("Unknown CIC Code "+N(q)),"6102"}}function l5(J,q,Q){let Y="";for(let Z=0;Z<Q;++Z){const K=J[q+Z];if(K===0)break;Y+=String.fromCharCode(K)}return Y}var d5={"134c3f03a7e79e31":{name:"007 - The World is Not Enough",save:"Eeprom4k"},"9516943beb5e0af9":{name:"007 - The World is Not Enough",save:"Eeprom4k"},"61f1ba1ff1541c2c":{name:"1080 Snowboarding",save:"SRAM"},"253ffd588daa2ed9":{name:"1080 Snowboarding",save:"SRAM"},"091da5abd9ba68c6":{name:"40 Winks",save:"Eeprom4k"},d927f2df69814d0d:{name:"A Bug's Life"},fd04dc82f4822dcf:{name:"A Bug's Life"},c0ae382b10b85063:{name:"A Bug's Life"},"96c0128fe117dc45":{name:"A Bug's Life"},f18b591b459ba2ec:{name:"Aero Fighters Assault",save:"Eeprom4k"},"95bef662d6d602f1":{name:"Aero Fighters Assault",save:"Eeprom4k"},"3e46beae4b4671cc":{name:"AeroGauge",save:"Eeprom4k"},"3111f480f6454638":{name:"AeroGauge",save:"Eeprom4k"},c84530d8363a9df2:{name:"AeroGauge",save:"Eeprom4k"},a682c18cb0cad0c2:{name:"AI Shogi 3"},ccffc42d215affc8:{name:"Aidyn Chronicles - The First Mage",save:"SRAM"},"4f5aa9e623ead2ba":{name:"Aidyn Chronicles - The First Mage",save:"SRAM"},"0cb6456c300ee5dc":{name:"Airboarder 64",save:"Eeprom4k"},d025c427c1992d8c:{name:"Airboarder 64",save:"Eeprom4k"},"941a95b6af49c863":{name:"Akumajou Dracula Mokushiroku"},"063153a55b5ef2b9":{name:"Akumajou Dracula Mokushiroku Gaiden"},fc81607a787a8fff:{name:"Alice no Wakuwaku Trump World",save:"Eeprom4k"},ad84d7df036642ae:{name:"All Star Tennis '99",save:"Eeprom4k"},"91e285e16d76504e":{name:"All Star Tennis '99",save:"Eeprom4k"},"2907d2674c7796f6":{name:"All Star! Dairantou Smash Brothers"},"4d7a545e9507e690":{name:"All-Star Baseball 2000"},efc64654bb478ee1:{name:"All-Star Baseball 2001"},a7233ec41a68b140:{name:"All-Star Baseball 99"},"4dd5edd974e2b86b":{name:"All-Star Baseball 99"},"0290aeb967a3b6c1":{name:"Animal Forest",save:"Eeprom4k"},"17dbf6c032d5e080":{name:"Armorines - Project S.W.A.R.M."},"32d9b51f1b48a93b":{name:"Armorines - Project S.W.A.R.M."},"5071c73c87b9cd21":{name:"Armorines - Project S.W.A.R.M."},b2bb524c6b0fabce:{name:"Army Men - Air Combat"},"57062c866d89fd8d":{name:"Army Men - Sarge's Heroes"},"19df10b21a8db598":{name:"Army Men - Sarge's Heroes"},b6730fb234fc7529:{name:"Army Men - Sarge's Heroes 2"},abd8f7d146043b29:{name:"Asteroids Hyper 64"},c45db2418667721b:{name:"Automobili Lamborghini",save:"Eeprom4k"},bf9777fc3ce8954a:{name:"Automobili Lamborghini",save:"Eeprom4k"},"9ca440e3418d3174":{name:"Baku Bomberman",save:"Eeprom4k"},"4f7c3ce738b893af":{name:"Baku Bomberman 2",save:"Eeprom4k"},"5db998df78098458":{name:"Bakuretsu Muteki Bangaioh",save:"Eeprom4k"},"0a98cf88b52ed58e":{name:"Bakushou Jinsei 64 - Mezase! Resort Ou"},"20d568510dcd5fca":{name:"Banjo to Kazooie no Dai Bouken",save:"Eeprom4k"},"00694b518198b1b4":{name:"Banjo to Kazooie no Dai Bouken 2",save:"Eeprom16k"},ac5975cdaef56cb2:{name:"Banjo-Kazooie",save:"Eeprom4k"},"0693bfa4d1df0cbf":{name:"Banjo-Kazooie",save:"Eeprom4k"},b1cc3f73f9924844:{name:"Banjo-Kazooie",save:"Eeprom4k"},"9aaae9c2aa705d47":{name:"Banjo-Tooie",save:"Eeprom16k"},"396d17c9d17947ea":{name:"Banjo-Tooie",save:"Eeprom16k"},df7c5b152573daf0:{name:"Banjo-Tooie",save:"Eeprom16k"},b4fb88b01d4b1e44:{name:"Bass Hunter 64",save:"Eeprom4k"},caa237d15350b662:{name:"Bass Tsuri No. 1 (Shigesato Itoi's Bass Fishing)"},aaccfabcefd814b8:{name:"Bassmasters 2000"},c18944202bcf8612:{name:"Batman Beyond - Return of the Joker"},"847f9f2526ed9e7c":{name:"Batman Beyond - Return of the Joker"},e7dda46ae7f4e2e3:{name:"BattleTanx"},"47e2a4753d960860":{name:"BattleTanx - Global Assault"},e617ad0c97b7a571:{name:"BattleTanx - Global Assault"},cec4d4558ac75377:{name:"Battlezone - Rise of the Black Dogs"},"3d1c69914d5bacf4":{name:"Beast Wars Metals"},"16d3794d331b50e8":{name:"Beast Wars Transmetal"},a819f4edcc0419bf:{name:"Beetle Adventure Racing!"},d218739cc10dae24:{name:"Beetle Adventure Racing!"},"614ab6a10b9414d0":{name:"Beetle Adventure Racing!"},b7a4ff08b653f401:{name:"Big Mountain 2000",save:"Eeprom4k"},"95351208def11005":{name:"Bio F.R.E.A.K.S."},"1d107cabb0c858ec":{name:"Bio F.R.E.A.K.S."},"8824ae7e5aa3409d":{name:"Bio Hazard 2",save:"SRAM"},dbe6647cdb24b955:{name:"Blast Corps",save:"Eeprom4k"},"257c647ce601d9d9":{name:"Blast Corps (v1.0)",save:"Eeprom4k"},"657e647c05d34819":{name:"Blast Corps (v1.1)",save:"Eeprom4k"},"514423656f34d3eb":{name:"Blast Dozer",save:"Eeprom16k"},"128bd07c89ff5311":{name:"Blues Brothers 2000",save:"SRAM"},"83c871d5cf3f2d82":{name:"Blues Brothers 2000",save:"SRAM"},"6f692653c3999afe":{name:"Body Harvest",save:"Eeprom4k"},cdb8580bd291b2b7:{name:"Body Harvest",save:"Eeprom4k"},c651d4b3e258cbe1:{name:"Bokujo Monogatari 2"},f4f06fdf3842d129:{name:"Bomberman 64",save:"Eeprom4k"},"1ed568f51eba497e":{name:"Bomberman 64",save:"Eeprom4k"},"3603165ab0377bbc":{name:"Bomberman 64",save:"Eeprom4k"},b4737e23376b3bd6:{name:"Bomberman 64 - The Second Attack!",save:"Eeprom4k"},d6fd4644088278e3:{name:"Bomberman Hero",save:"Eeprom4k"},cc12ff671202bf76:{name:"Bomberman Hero",save:"Eeprom4k"},"294e5cd8af76e288":{name:"Bomberman Hero",save:"Eeprom4k"},"4dd12fd7c432ed1f":{name:"Bottom of the 9th"},"2ecf221e13c8aa42":{name:"Brunswick Circuit Pro Bowling"},"1a78ae855df056c7":{name:"Buck Bumble"},b662c7d742963df8:{name:"Buck Bumble"},"9c33b2d5edcabcca":{name:"Buck Bumble"},"73f0868a4be545cd":{name:"Bust-A-Move 2 - Arcade Edition"},"1ededcce02053a51":{name:"Bust-A-Move 2 - Arcade Edition"},fab428e3e1284a00:{name:"Bust-A-Move 3 DX"},"9fd8224237b6e0af":{name:"Bust-A-Move '99"},"0e4016ac1a075dcf":{name:"California Speed"},"4e2d0ff0f4aa0f34":{name:"Carmageddon 64"},ec620158f18b10e3:{name:"Carmageddon 64 (censored)"},f5018ee49b1fe5e6:{name:"Carmageddon 64 (uncensored)"},"47ffcd4b8fafa3aa":{name:"Castlevania v1.2"},"955f5df3693dfe8a":{name:"Castlevania"},cab7f1645537a271:{name:"Castlevania"},"3863c01c26893887":{name:"Castlevania - Legacy of Darkness"},e74bc5a2b2cb1967:{name:"Castlevania - Legacy of Darkness"},"3421cfdc7835d69d":{name:"Centre Court Tennis"},"5a53206462800250":{name:"Chameleon Twist",save:"Eeprom4k"},"21f5f2a48e16ebf0":{name:"Chameleon Twist",save:"Eeprom4k"},c68cafb99ff1c9de:{name:"Chameleon Twist",save:"Eeprom4k"},e48c53cdf9fc8a61:{name:"Chameleon Twist 2"},"5a76490542d0b993":{name:"Chameleon Twist 2"},"019da607a1417d9a":{name:"Chameleon Twist 2"},e8960e1e6b82284e:{name:"Charlie Blast's Territory"},d0483cfb9ff6288d:{name:"Charlie Blast's Territory"},"94ad4c21243b1abe":{name:"Chopper Attack",save:"Eeprom4k"},"3993352ea6eda53f":{name:"Chopper Attack",save:"Eeprom4k"},c4f9cc2b6f9f3d40:{name:"Choro Q 64",save:"Eeprom4k"},"540fcd26e0efeb53":{name:"Choro Q 64 II",save:"Eeprom4k"},"281594a79d19f161":{name:"Chou Snobow Kids"},f40f183af78a8e5c:{name:"Chou Kuukan Night Pro Yakyuu King 2",save:"Eeprom4k"},b09d00f82318296b:{name:"City-Tour GP - All Japan Grand Touring Car Champion"},ff3d5afab9cdc9b4:{name:"Clay Fighter - Sculptor's Cut"},ca243cf0cc7b23c5:{name:"Clay Fighter 63 1/3"},b392968e2abb6442:{name:"Clay Fighter 63 1/3"},c0a76f2b2512a709:{name:"Clay Fighter 63 1/3 (beta)"},ad5b02b5fd7526d3:{name:"Command & Conquer",save:"FlashRam"},b46e28958fd56ab7:{name:"Command & Conquer",save:"FlashRam"},"65945bae76654dc5":{name:"Command & Conquer",save:"FlashRam"},"50acc7302d070477":{name:"Conker's Bad Fur Day",save:"Eeprom16k"},"89583f370aa86c9a":{name:"Conker's Bad Fur Day",save:"Eeprom16k"},aff7a346d091750f:{name:"Cruis'n Exotica",save:"Eeprom4k"},"542540b304c04073":{name:"Cruis'n USA",save:"Eeprom4k"},"60a73e50960e30e1":{name:"Cruis'n USA",save:"Eeprom4k"},b42f2fff9a1461d1:{name:"Cruis'n USA (v1.0)",save:"Eeprom4k"},"45cf06535092c4cb":{name:"Cruis'n USA (v1.1)",save:"Eeprom4k"},"5311e6dfe61861d7":{name:"Cruis'n World",save:"Eeprom16k"},"1e93f3833d2272cb":{name:"Cruis'n World",save:"Eeprom16k"},"870bcb835754327e":{name:"Custom Robo",save:"Eeprom4k"},b9019507ab3202ab:{name:"Custom Robo V2",save:"Eeprom16k"},a18efce89183739f:{name:"CyberTiger"},"078aa7d13edda352":{name:"CyberTiger"},"45f48871680a4184":{name:"Dance Dance Revolution - Disney Dancing Museum"},"582ba5a441987523":{name:"Dark Rift"},d47cd67e6d5e41b4:{name:"Dark Rift"},"493336f51bd2f9db":{name:"Deadly Arts"},d9a9663f005bcb9b:{name:"Defi au Tetris Magique"},e167f6a51fbd1fda:{name:"Derby Stallion 64",save:"FlashRam"},"614ac517e7f2834a":{name:"Densha de GO! 64",save:"SRAM"},a284e5de8711160f:{name:"Destruction Derby 64"},"7da30a63dbd76b89":{name:"Destruction Derby 64"},"9c167989a0f689f1":{name:"Dezaemon 3D",save:"SRAM"},"725629d51570b59c":{name:"Diddy Kong CRACKED",save:"Eeprom4k"},"5aa389f362557817":{name:"Diddy Kong Racing",save:"Eeprom4k"},e740d45311b01975:{name:"Diddy Kong Racing (v1.0)",save:"Eeprom4k"},"75f773fd5a752497":{name:"Diddy Kong Racing (v1.0)",save:"Eeprom4k"},"0d4302e49dfcfcd2":{name:"Diddy Kong Racing (v1.1)",save:"Eeprom4k"},"5b146e599f87d9f7":{name:"Diddy Kong Racing (v1.1)",save:"Eeprom4k"},"1b426cc1f78015a2":{name:"Disney's Donald Duck - Goin' Quackers",save:"Eeprom4k"},"2313264c1a5e294f":{name:"Disney's Tarzan"},c769fecb2aabc0f2:{name:"Disney's Tarzan",save:"Eeprom4k"},d03b1a001adeb3af:{name:"Disney's Tarzan"},bfe514d6c1bc6da7:{name:"Disney's Tarzan",save:"Eeprom4k"},"6d208ebd1c5ec398":{name:"Doubutsu No Mori",save:"Eeprom4k"},"8074f13d5aed3d19":{name:"Donald Duck - Quack Attack"},bfea58ec69717cad:{name:"Donkey Kong 64",save:"Eeprom16k"},a7893c05024306a5:{name:"Donkey Kong 64",save:"Eeprom16k"},"8c6d9311434b2c6f":{name:"Donkey Kong 64",save:"Eeprom16k"},ababd40d1ea9a2b5:{name:"Donkey Kong 64 - Kiosk",save:"Eeprom16k"},"1a103ea89db637e9":{name:"Doom 64"},f4963e425bf088ce:{name:"Doom 64"},"365ba67aade5cefd":{name:"Doom 64"},ac9e732c2677f79e:{name:"Doom 64"},c2b1f7bf8e14bfae:{name:"Doraemon - Mittsu no Seireiseki",save:"Eeprom4k"},"996e30b6b2d23eb6":{name:"Doraemon 2 - Hikari no Shinden",save:"Eeprom16k"},"405127a8e856b0b9":{name:"Doraemon 3 - Nobi Dai No Machi SOS!",save:"Eeprom16k"},"134d9d76fe3f23da":{name:"Dr. Mario 64",save:"Eeprom4k"},a0ecde3fb29b9f39:{name:"Dragon Sword 64"},c33022a6884483f0:{name:"Dual Heroes"},"63ab6e05d5fc15c2":{name:"Dual Heroes"},"614452b6b1046ded":{name:"Dual Heroes"},faf1b9fb8986f86b:{name:"Duck Dodgers Starring Daffy Duck",save:"Eeprom4k"},"7ff0da0488e6180d":{name:"Duke Nukem - ZER0 H0UR"},"4b97ca32509cc2b2":{name:"Duke Nukem - ZER0 H0UR"},"6a6236dccb70373f":{name:"Duke Nukem - ZER0 H0UR"},"56ab73a29adb33da":{name:"Duke Nukem 64"},"3d88121e1827b9d3":{name:"Duke Nukem 64"},"4df7bf57437774de":{name:"Duke Nukem 64"},cfb6db349d7806ea:{name:"Earthworm Jim 3D Ru",save:"Eeprom4k"},"914157df3d12b59e":{name:"Earthworm Jim 3D",save:"Eeprom4k"},e89d2b491cc8ccc6:{name:"Earthworm Jim 3D",save:"Eeprom4k"},"6d76f9bd708d06bd":{name:"ECW Hardcore Revolution"},dbe5388cd7277cb3:{name:"ECW Hardcore Revolution"},cb53a6f23b3b6360:{name:"Elmo's Letter Adventure"},"8f53b102d0884bc9":{name:"Elmo's Number Journey"},dce23ae1e85cb64f:{name:"Eltale Monsters"},"421886079fbc2ea1":{name:"Excitebike 64",save:"Eeprom16k"},"19351c86e51c09f6":{name:"Excitebike 64",save:"Eeprom16k"},e48e2a20898bf883:{name:"Excitebike 64",save:"Eeprom16k"},"7b4f75af8173d11d":{name:"Excitebike 64 - Kiosk",save:"Eeprom16k"},d245a2fd473d4aa7:{name:"Extreme-G"},c42d80ee7dd50b69:{name:"Extreme-G"},"4e839d8ea9298b1e":{name:"Extreme-G"},"0b15d45cf1c20c47":{name:"Extreme-G XG2"},"819b9b3911ad33d5":{name:"Extreme-G XG2"},"85ec851131775a4b":{name:"Extreme-G XG2"},"7a6882ae8d383f9a":{name:"F-1 Pole Position 64"},b248d2fd0e029a56:{name:"F-1 Pole Position 64"},b8bcec3c07bf2661:{name:"F1 Racing Championship"},"3426443860f0b366":{name:"F-1 World Grand Prix",save:"Eeprom4k"},b3c83ccca405c40e:{name:"F-1 World Grand Prix",save:"Eeprom4k"},e5ae0bb7a805503a:{name:"F-1 World Grand Prix",save:"Eeprom4k"},c447bf64ba22bdf4:{name:"F-1 World Grand Prix",save:"Eeprom4k"},"6e86c107decc7557":{name:"F-1 World Grand Prix II",save:"Eeprom16k"},"374cff6dfd63b7b1":{name:"Famista 64"},"4f47294f7a70cb30":{name:"F-Cup Maniax"},decd1acbf21d29cf:{name:"FIFA - Road to World Cup 98"},"673c73f53a97a317":{name:"FIFA - Road to World Cup 98"},f0ed310ed54972c3:{name:"FIFA - Road to World Cup 98"},"30a61376f396d63e":{name:"FIFA 99"},"51a69801849d21fc":{name:"FIFA 99"},"5991f1c35abcd265":{name:"FIFA Soccer 64"},"70e594fe9c3a87e4":{name:"Fighter's Destiny",save:"Eeprom4k"},"0588f752b7ca8f8b":{name:"Fighter's Destiny",save:"Eeprom4k"},c2f9410c0d7a7101:{name:"Fighter's Destiny",save:"Eeprom4k"},"4bc7f136399902f2":{name:"Fighter's Destiny",save:"Eeprom4k"},"452fefaef1307ef9":{name:"Fighter's Destiny 2",save:"Eeprom4k"},"2d6ce4490c111a7b":{name:"Fighting Cup"},cbc7ef32203feac3:{name:"Fighting Force 64"},fe0fcf669c7f69ad:{name:"Fighting Force 64"},"2d56d52850aed5e4":{name:"Fire Electric Pen",save:"Eeprom4k"},e5522da955b6261d:{name:"Flying Dragon"},"3f62e922ad520eb6":{name:"Flying Dragon"},"1a8fff35bee3796e":{name:"Flying Dragon Fighters (Hiro no Ken Twin)"},"79b1e5e8e830aa44":{name:"Frogger 2 (Alpha)"},ff76cdc3decb9d9b:{name:"Forsaken"},"010c339eba14038c":{name:"Forsaken"},aa172a14968d0213:{name:"Forsaken"},"79d4613225bc0ded":{name:"Fox Sports College Hoops '99"},eeea74f73eb1d8f0:{name:"Fushigi no Dungeon - Furai no Shiren 2",save:"FlashRam"},a9d183398c150420:{name:"F-Zero DXP",save:"SRAM"},"78d90eb3f9c90330":{name:"F-Zero X",save:"SRAM"},"2e623e4d4e8b829b":{name:"F-Zero X",save:"SRAM"},f64666772bacb906:{name:"F-Zero X",save:"SRAM"},b67986afbf11105e:{name:"G.A.S.P! Fighter's NEXTream",save:"Eeprom16k"},"26f7fc68bc8c6549":{name:"G.A.S.P! Fighter's NEXTream",save:"Eeprom16k"},"8b162c83aecda256":{name:"Ganbare Goemon"},d99c7b455253c509:{name:"Ganbare Goemon 2 - Deoru Dero Douchuu Obake Tenko"},"0afdff21981d0dfa":{name:"Ganbare Nippon Olympics 2000"},"325e9b7280d928b7":{name:"Gauntlet Legends"},"0e26b0704cd01667":{name:"Gauntlet Legends"},d6bc43d556e2a52b:{name:"Gauntlet Legends"},e6849c48f9496e4c:{name:"Getter Love!! Cho Renai Party Game"},"127edc3ec91c6ce2":{name:"Gex 3 - Deep Cover Gecko"},"59931799c3ebe72f":{name:"Gex 3 - Deep Cover Gecko"},a43347875a7423a8:{name:"Gex 3 - Deep Cover Gecko"},"74d7fe891be2afca":{name:"Gex 64 - Enter the Gecko"},"0e008ae6dd669163":{name:"Gex 64 - Enter the Gecko"},ff016e8e48f9b4cc:{name:"Glover",save:"Eeprom4k"},"017323f593eee399":{name:"Glover",save:"Eeprom4k"},"7fd2c6b2fd8ca42d":{name:"Goemon Mononoke Sugoroku"},ada552424ebf6fae:{name:"Goemon's Great Adventure"},"1cfb9046446dd54c":{name:"Golden Nugget 64"},d150bcdca31afd09:{name:"GoldenEye 007",save:"Eeprom4k"},f14c4fa2ba2723a8:{name:"GoldenEye 007",save:"Eeprom4k"},"61ca1404aab8572e":{name:"GoldenEye 007",save:"Eeprom4k"},a2dc9ac4621b50f1:{name:"GT 64 Championship Edition",save:"Eeprom4k"},"330e4aeec988d58f":{name:"GT 64 Championship Edition",save:"Eeprom4k"},"1401a8957f2ab7e0":{name:"Hamster Monogatari 64",save:"Eeprom4k"},bf2ff236f2128931:{name:"Hanafuda 64 - Tenshi no Yakusoku"},b157ae0937562a18:{name:"Harukanaru Augusta Masters 98",save:"Eeprom4k"},fc9ddf9889c10666:{name:"Harvest Moon 64",save:"SRAM"},"66e8703ee8ba3844":{name:"Heiwa Pachinko World",save:"Eeprom4k"},"77eb3c7f0a038189":{name:"Hercules - The Legendary Journeys"},ebdb90ae2391b879:{name:"Hercules - The Legendary Journeys"},"0ab5b39a056166bc":{name:"Hexen"},bd5f1b5c3416967e:{name:"Hexen"},ea6aab9c001cc687:{name:"Hexen"},"571a75666e9da254":{name:"Hexen"},"0bb3b295c115642b":{name:"Hexen"},"5d0ef1d379a52e05":{name:"Hey You, Pikachu!",save:"Eeprom4k"},"140efa7505d1b3c9":{name:"Holy Magic Century"},b0eb5fb304b22774:{name:"Holy Magic Century"},"9d127b27ff7938dd":{name:"Holy Magic Century"},bd02d7c14765416d:{name:"Hoshi no Kirby 64",save:"Eeprom4k"},"8e8fc9c7de5d1442":{name:"Hot Wheels Turbo Racing"},"9301d2e7938e15c1":{name:"Hot Wheels Turbo Racing"},"7d1d6172d2bd1999":{name:"HSV Adventure Racing"},"2e97355595328ebd":{name:"Human Grand Prix"},"6ac9dbe8eee2c9da":{name:"Hybrid Heaven"},bf882810ca884843:{name:"Hybrid Heaven"},"36cee20de6291dd4":{name:"Hybrid Heaven"},"7f3a1d6466048286":{name:"Hybrid Heaven"},eb65dcc804898c3d:{name:"Hydro Thunder"},e98889b5e84bfcb1:{name:"Hydro Thunder"},"9e8b456936f995fc":{name:"Iggy-kun no Bura Bura Poyon"},bcb516e6888b65c9:{name:"Iggy's Reckin' Balls"},"5ecc92d672d058ec":{name:"Iggy's Reckin' Balls"},"15cc9daf883d721a":{name:"Indiana Jones and the Infernal Machine",save:"Eeprom4k"},"7a4636e49b8fde82":{name:"Indy Racing 2000",save:"Eeprom4k"},e08b138c460e7095:{name:"In-Fisherman Bass Hunter 64",save:"Eeprom4k"},"3754838eb44857cd":{name:"International Superstar Soccer 2000"},a0646333bfd5c806:{name:"International Superstar Soccer 2000"},"71e8e8ba4e94ff35":{name:"International Superstar Soccer 2000"},c463275fe52a4162:{name:"International Superstar Soccer 64"},f07cd3e2ae4e7ef5:{name:"International Superstar Soccer 64"},"43631bf4e66106c1":{name:"International Superstar Soccer 98"},"09da0f7f0bce6160":{name:"International Superstar Soccer '98"},c73b072011013b5e:{name:"International Track and Field 2000"},"79c712671d78723b":{name:"International Track and Field Summer Games"},"476776876571c291":{name:"J. League Dynamite Soccer"},aa0acec619f017d1:{name:"J. League Tactics Soccer (1.1)"},"29a4bf4f15bb2069":{name:"J. League Eleven Beat 1997"},"424a5554fb5f98e4":{name:"J. League Live 64"},a09dd2e8941de615:{name:"J. League Tactics Soccer"},"16d03ac77d53c548":{name:"Jangou Simulation Mahjong Do 64"},"6064256986f5a3b9":{name:"Jeopardy!"},a5b130bbce12f7fc:{name:"Jeremy McGrath Supercross 2000"},fbabf721e8a78a6a:{name:"Jeremy McGrath Supercross 2000"},b609608a50e1ac94:{name:"Jet Force Gemini",save:"FlashRam"},dea1d7684a837900:{name:"Jet Force Gemini",save:"FlashRam"},"47abd8df89ebdb3c":{name:"Jet Force Gemini - Kiosk",save:"FlashRam"},f5d919afcc2302b7:{name:"Jikkyou G1 Stable"},"532a11638fa89fa2":{name:"Jikkyou J. League 1999 - Perfect Striker 2"},"66436c14b3dea672":{name:"Jikkyou J. League Perfect Striker"},"1c1f89d78837e4c3":{name:"Jikkyou Pawafuru Puroyakyu 4 (1.1)"},d144c20a05c60e1f:{name:"Jikkyou Pawapuro Puroyakyu 2000"},"23df6442f7bd28be":{name:"Jikkyou Pawapuro Puroyakyu 2000"},"2056ea3f40db5674":{name:"Jikkyou World Cup France '98"},"8cb354c9b3be626f":{name:"Jikkyou World Cup France '98"},d6abc7e1287f704e:{name:"Jikkyou World Cup France '98"},"8c9fa7e0fa97cc32":{name:"Jikkyou World Soccer 3"},edf6aa4aad286437:{name:"Jinsei Game 64"},b01a15d04ba15cfe:{name:"John Romero's Daikatana"},"4b3c7e9d6c4a0fe6":{name:"John Romero's Daikatana"},"9531740f95dba6d8":{name:"John Romero's Daikatana"},"231f2836cf569700":{name:"Ken Griffey Jr.'s Slugfest",save:"FlashRam"},"3e269b97040047f8":{name:"Killer Instinct Gold",save:"Eeprom4k"},bae28f9e7007278b:{name:"Killer Instinct Gold (v1.0)",save:"Eeprom4k"},facd8f9e2b65f549:{name:"Killer Instinct Gold (v1.0)",save:"Eeprom4k"},"4cca08f927434636":{name:"Killer Instinct Gold (v1.2)",save:"Eeprom4k"},e1a49e51e88475eb:{name:"King Hill 64 - Extreme Snowboarding"},d66abc75c92b5578:{name:"Kiratto Kaiketsu! 64 Tanteidan"},b49f03462c823703:{name:"Kirby 64 - The Crystal Shards",save:"Eeprom4k"},"11ba930da6683868":{name:"Kirby 64 - The Crystal Shards",save:"Eeprom4k"},"6fb81bcac5a5cc41":{name:"Kirby 64 - The Crystal Shards (1.1)",save:"Eeprom4k"},"7a1c580ce4206e3d":{name:"Kirby 64 - The Crystal Shards (1.2)",save:"Eeprom4k"},"9ff8b1bca2520706":{name:"Kirby 64 - The Crystal Shards (1.3)",save:"Eeprom4k"},"99d7e0fc546c3165":{name:"Knife Edge - Nose Gunner"},"3fef1a93906b19ef":{name:"Knife Edge - Nose Gunner"},"747c994a997f08e2":{name:"Knife Edge - Nose Gunner"},"9c9094082dd8d4da":{name:"Knockout Kings 2000"},"95a7d6e33c5d1c2a":{name:"Knockout Kings 2000"},"94846b611092508a":{name:"Kobe Bryant's NBA Courtside",save:"Eeprom16k"},baef3917683ab4d0:{name:"Kobe Bryant's NBA Courtside",save:"Eeprom16k"},e8603e5e95d4b54a:{name:"Kuiki Uhabi Suigo"},"9940307f7652cf52":{name:"Last Legion UX",save:"Eeprom4k"},ea406a09100abe8a:{name:"LEGO Racers"},b3d878f46ddd1697:{name:"LEGO Racers"},"2bc6673d5031d031":{name:"Let's Smash Tennis"},df1850253aaed657:{name:"Lode Runner 3-D",save:"Eeprom4k"},"0bdd4a96db1392b2":{name:"Lode Runner 3-D",save:"Eeprom4k"},"80064660720e5f30":{name:"Lode Runner 3-D",save:"Eeprom4k"},"5b05a00a65df3776":{name:"Looney Tunes - Duck Dodgers",save:"Eeprom4k"},"2ce9cbf412ed92b3":{name:"Lylat Wars",save:"Eeprom4k"},"2bf283245e026e13":{name:"Lylat Wars",save:"Eeprom4k"},"5007706bfe21d629":{name:"Mace - The Dark Age"},"3d444511db0e6111":{name:"Mace - The Dark Age"},"8616b80c815ad85f":{name:"Madden 2000"},"89638313763c5b26":{name:"Madden Football 64"},"52cb97a10ede2075":{name:"Madden Football 64"},"8d4f13d7b5001ac1":{name:"Madden NFL 2002",save:"Eeprom16k"},"92f738eb46a20e19":{name:"Madden NFL 2001"},ba8bb7de9dbdf652:{name:"Madden NFL 99"},"25d625395ec7838c":{name:"Madden NFL 99"},f793efe10b8b9014:{name:"Magical Tetris Challenge"},"4716b67578bfda7a":{name:"Magical Tetris Challenge"},"4a56c880ab659c92":{name:"Magical Tetris Challenge"},"796690e4053f249f":{name:"Magical Tetris Challenge"},"41dc3ec55993e1ec":{name:"Mahjong 64"},"1e82cccc838ae896":{name:"Mahjong Hourouki Classic"},"702cc40fcdf15487":{name:"Mahjong Master"},"5cc0c180f45e06ea":{name:"Major League Baseball Featuring Ken Griffey Jr.",save:"SRAM"},be98b9cdc8a52410:{name:"Major League Baseball Featuring Ken Griffey Jr.",save:"SRAM"},d4a34b66b7808a67:{name:"Mario Golf 64",save:"SRAM"},d14489d40e3ad9b0:{name:"Mario Golf 64",save:"SRAM"},d057e9625d5ac17f:{name:"Mario Golf 64",save:"SRAM"},b655503e52da922e:{name:"Mario Kart 64",save:"Eeprom4k"},"5847ff6b5e5dffe5":{name:"Mario Kart 64 (v1.0)",save:"Eeprom4k"},"9ddeb6c376ded265":{name:"Mario Kart 64 (v1.0)",save:"Eeprom4k"},"87a9c3c94c341058":{name:"Mario Kart 64 (v1.1)",save:"Eeprom4k"},d4c77725aeaa8fd1:{name:"Mario Kart 64 (v1.1)",save:"Eeprom4k"},ac90989adf13c3f0:{name:"Mario No Photopie"},"7e652928771862a0":{name:"Mario Party",save:"Eeprom4k"},be15a8ad2f622860:{name:"Mario Party",save:"Eeprom4k"},"6930669c804af280":{name:"Mario Party",save:"Eeprom4k"},"5858a99e18b672af":{name:"Mario Party 2",save:"Eeprom4k"},"0f7d56ed1589b038":{name:"Mario Party 2",save:"Eeprom4k"},"87033882d944c7df":{name:"Mario Party 2",save:"Eeprom4k"},d929387cce47826e:{name:"Mario Party 3",save:"Eeprom16k"},cdb40a0b3789157b:{name:"Mario Party 3",save:"Eeprom16k"},"604167c53c455f0f":{name:"Mario Party 3",save:"Eeprom16k"},dccda73ba0524e46:{name:"Mario Story",save:"FlashRam"},"4fcf0150bdb30cf3":{name:"Mario Tennis",save:"Eeprom16k"},b5426c3a1bdaca1a:{name:"Mario Tennis",save:"Eeprom16k"},d53a9f83fa156d40:{name:"Mario Tennis",save:"Eeprom16k"},f558c10e96683efb:{name:"Mega Man 64",save:"FlashRam"},"0cf10110c1d8513d":{name:"Mia Hamm Soccer 64"},c26661e3e5a21386:{name:"Michael Owens WLS 2000"},"71458cfac0f9e7bb":{name:"Mickey's Speedway USA",save:"Eeprom4k"},"9addd0dea72582e7":{name:"Mickey's Speedway USA",save:"Eeprom4k"},afe66a73c7e91741:{name:"Mickey no Racing Challenge USA",save:"Eeprom4k"},"350c85f11279e0ac":{name:"Micro Machines 64 Turbo"},"8d01492a024a03d0":{name:"Micro Machines 64 Turbo"},"4c5eb3e4c95cc41a":{name:"Midway's Greatest Arcade Hits Volume 1"},"163ed509b968b23a":{name:"Mike Piazza's Strike Zone"},cd5e952e840800f3:{name:"Milo's Astro Lanes"},"9d0d499adc3a018f":{name:"Milo's Astro Lanes"},"1b05930bf9813d60":{name:"Mischief Makers",save:"Eeprom4k"},"98da8b41580f8a24":{name:"Mischief Makers",save:"Eeprom4k"},"7e3feb93445e6781":{name:"Mission Impossible",save:"Eeprom4k"},f85c032635912b80:{name:"Mission Impossible",save:"Eeprom4k"},"345b0920879e3d34":{name:"Mission Impossible",save:"Eeprom4k"},dc49a9ebbdecba39:{name:"Mission Impossible",save:"Eeprom4k"},daec56229c1bab71:{name:"Mission Impossible",save:"Eeprom4k"},e2046a5f0d07fad4:{name:"Mission Impossible",save:"Eeprom4k"},"6d8d76286c9779b3":{name:"Monaco Grand Prix",save:"Eeprom4k"},e183c35a87e312d7:{name:"Monopoly",save:"Eeprom4k"},"99d99ab11851587e":{name:"Monster Truck Madness 64"},fc06d8d3a8a23ab4:{name:"Monster Truck Madness 64"},"70dde8e898d15d41":{name:"Morita Shogi 64",save:"Eeprom4k"},f4d47d41e22f481b:{name:"Mortal Kombat 4",save:"Eeprom4k"},"3b6f0373e9690dce":{name:"Mortal Kombat 4",save:"Eeprom4k"},ac0443c321c0792d:{name:"Mortal Kombat Mythologies - Sub-Zero"},c4ed44ff1392ae1a:{name:"Mortal Kombat Mythologies - Sub-Zero"},"125cf7d9599b85a8":{name:"Mortal Kombat Trilogy"},"92113d8ce172f1be":{name:"Mortal Kombat Trilogy"},a93af3830dd401a9:{name:"Mortal Kombat Trilogy (v1.2)"},"5cb6f92ad7a2e285":{name:"MRC - Multi Racing Championship",save:"Eeprom4k"},"13b4b6a6cc13d115":{name:"MRC - Multi Racing Championship",save:"Eeprom4k"},"03bdf0b89e187944":{name:"MRC - Multi Racing Championship",save:"Eeprom4k"},"5c52381956966e58":{name:"Ms. Pac-Man Maze Madness"},"21cbbcfc6b3c9072":{name:"Mystical Ninja - Starring Goemon"},be0f36f51d69f12b:{name:"Mystical Ninja - Starring Goemon"},d345937fdeca1e84:{name:"Mystical Ninja 2 - Starring Goemon"},"8725c27e23e31aef":{name:"Nagano Olympic Hockey '98"},"3730f490f570535c":{name:"Nagano Olympic Hockey '98"},"353a2dae1ad4f024":{name:"Nagano Olympic Hockey '98"},"98ae2b8dbf2537d7":{name:"Nagano Winter Olympics '98"},"4cc3c52f9dcc057a":{name:"Nagano Winter Olympics '98"},"1620456dee093c71":{name:"Nagano Winter Olympics '98"},dab629518c3cef9d:{name:"Namco Museum 64"},"181a33df44e0d45f":{name:"NASCAR 2000"},"78957423fd58dc80":{name:"NASCAR 99"},"49140000c99249ae":{name:"NASCAR 99"},c99249ae53b25392:{name:"NASCAR 99"},"57ebf724f4f9b374":{name:"NBA Courtside 2 - Featuring Kobe Bryant",save:"FlashRam"},d8526891efeadb73:{name:"NBA Courtside 2 - Featuring Kobe Bryant",save:"FlashRam"},"87b4694e90e218fe":{name:"NBA Hangtime"},aedc88c70a0003bd:{name:"NBA Hangtime"},"011fe1aa45a02526":{name:"NBA In the Zone 2000"},"185bf98d7b49daec":{name:"NBA In the Zone 2000"},"9f4f05b3b59eb696":{name:"NBA In the Zone 2000"},"3019126a74c25c66":{name:"NBA In the Zone '98"},"9bbaac36944d8df2":{name:"NBA In the Zone '98"},"4f5292a2492a6c3d":{name:"NBA In the Zone '99"},dba8eeeb3cb2ecf2:{name:"NBA Jam 2000"},a0cad0b6c893f4e3:{name:"NBA Jam 2000"},f6290781c1cf3fe0:{name:"NBA Jam 99"},"1e8300e6a822f459":{name:"NBA Jam 99"},eeb0255fdbc12762:{name:"NBA Live 2000"},"8f9c49ebb66745cd":{name:"NBA Live 2000"},"9b1cf85735fa3311":{name:"NBA Live 99"},"5ff484cfebf6e400":{name:"NBA Live 99"},"2f96deac7ff8cbb2":{name:"NBA Pro 98"},b680178d76b9b357:{name:"NBA Pro 99"},f480fe3f7e5fc1a7:{name:"NBA Showtime - NBA on NBC"},db0e7e142cb1c536:{name:"Neon Genesis Evangelion",save:"Eeprom16k"},"4fd5ea30f60b6231":{name:"NFL Blitz - Special Edition"},"70b194d0ccb5c4d7":{name:"NFL Blitz"},"6909a01585a2e534":{name:"NFL Blitz 2000"},eb35fa36362e5ee8:{name:"NFL Blitz 2001"},d04eabe3d20d0483:{name:"NFL Quarterback Club 2000"},"9e5abd88bfdf1fe8":{name:"NFL Quarterback Club 2000"},"224678288529b2ff":{name:"NFL Quarterback Club 2001"},f8e29bd8df7ac999:{name:"NFL Quarterback Club 98"},f49e624b9b1db299:{name:"NFL Quarterback Club 98"},ffed76be092d4520:{name:"NFL Quarterback Club 99"},"47cfa352fc3bc14e":{name:"NFL Quarterback Club 99"},"6e801a591d92e6a5":{name:"NHL 99"},"1e607d28aef8f4ab":{name:"NHL 99"},"30dcef8261246a80":{name:"NHL Blades of Steel '99"},c3cdfd6dc801e74d:{name:"NHL Breakaway 98"},"9276ce297985c571":{name:"NHL Breakaway 98"},d06817444ff2737d:{name:"NHL Breakaway 99"},cb21468727c13100:{name:"NHL Breakaway 99"},d95c89a96c012070:{name:"NHL Pro 99"},"4d675728da3743cc":{name:"Nightmare Creatures"},df3c3ccdfa937731:{name:"Nintama Rantarou 64"},"45b8508f2fd229d7":{name:"Nuclear Strike 64"},bbdd9849bcaeb7f7:{name:"Nuclear Strike 64"},"97a1978ac1f62d27":{name:"Nuclear Strike 64"},"20b93bd8166440cc":{name:"Nushi Zuri 64"},"18169b5b49c6431b":{name:"Nushi Tsuri 64 - Shiokaze ni Notte"},ec939031ef09c20f:{name:"Off Road Challenge"},d08922819632e5c2:{name:"Off Road Challenge"},c59b41e6e31d0169:{name:"Ogre Battle 64 - Person of Lordly Caliber",save:"SRAM"},"67cf7503aa3fa956":{name:"Ogre Battle 64 - Person of Lordly Caliber (v1.1)",save:"SRAM"},"6910969c8d48eaf5":{name:"Ohzumou 64",save:"Eeprom4k"},"168bc185af2296df":{name:"Ohzumou 64 2",save:"Eeprom4k"},"669464dcd9f02f57":{name:"Onegai Monsters"},"3b4b5574b5bcaef4":{name:"Pachinko 365 Nichi"},"3ae5ee653c737ded":{name:"Paper Mario",save:"FlashRam"},af29ab1928cd1bc7:{name:"Paper Mario",save:"FlashRam"},"129b52893bed5308":{name:"Paperboy"},"9e8d193e7e26e1f2":{name:"Paperboy"},"386b97ac7ac9a9c3":{name:"Paperboy"},"31cbe2cf1d1e6b4d":{name:"Parlor! Pro 64 Pachinko Jikki Simulation Game"},"6647dd6ea89b3ea9":{name:"Pawapuro Puroyakyu 2001"},ad5b4934269d2e50:{name:"Pawapuro Puroyakyu 4"},da4329d2c0772bac:{name:"Pawapuro Puroyakyu 5"},b7205eb7fdfdfeb3:{name:"Pawapuro Puroyakyu 6"},"8c1168f44ee42ee3":{name:"PD Ultraman Battle Collection 64",save:"Eeprom16k"},fbb1ab739360ca9c:{name:"Penny Racers",save:"Eeprom4k"},"83eb3cc81962c5fd":{name:"Penny Racers",save:"Eeprom4k"},b47e749643b24b10:{name:"Perfect Dark",save:"Eeprom16k"},"0780b0e433ff02a6":{name:"Perfect Dark",save:"Eeprom16k"},cc60f4ddc034a63c:{name:"Perfect Dark (v1.0)",save:"Eeprom16k"},"8fb9f24166b458b4":{name:"Perfect Dark (v1.1)",save:"Eeprom16k"},"81e84cb52661cbbc":{name:"PGA European Tour",save:"Eeprom4k"},"02c608eea6d5c26b":{name:"PGA European Tour",save:"Eeprom4k"},"0553243faa740bfc":{name:"Pikachu Genki Dechu"},"1c9651c8faaafc78":{name:"Pilot Wings 64",save:"Eeprom4k"},"0148cc0991e42ee4":{name:"Pilot Wings 64",save:"Eeprom4k"},d55aa01a802df546:{name:"Pilot Wings 64",save:"Eeprom4k"},"0d690fec8c43a732":{name:"Pocket Monsters Snap",save:"FlashRam"},"59825e661dbd98d0":{name:"Pocket Monsters Stadium",save:"FlashRam"},"865877637b0eb85f":{name:"Pocket Monsters Stadium 2",save:"FlashRam"},ac47477a23ecee44:{name:"Pokemon Puzzle League",save:"FlashRam"},a753c519524b0fa7:{name:"Pokemon Puzzle League",save:"FlashRam"},f3e6b23efe9e2f06:{name:"Pokemon Puzzle League",save:"FlashRam"},"53d11c4af8ae30d8":{name:"Pokemon Puzzle League",save:"FlashRam"},"6f97f54fd859f5ac":{name:"Pokemon Snap",save:"FlashRam"},"6a287d81167441ef":{name:"Pokemon Snap",save:"FlashRam"},"0d7253574d888a2a":{name:"Pokemon Snap",save:"FlashRam"},"47b512cae44efa71":{name:"Pokemon Snap",save:"FlashRam"},"3a296cba38a3af9f":{name:"Pokemon Snap",save:"FlashRam"},"4650c8c0051b0561":{name:"Pokemon Snap",save:"FlashRam"},"408db17b59851383":{name:"Pokemon Snap",save:"FlashRam"},"729811399f2e7207":{name:"Pokemon Snap Station",save:"FlashRam"},"432d121a0faf7dc1":{name:"Pokemon Stadium - Kiosk",save:"FlashRam"},"2da83fa55dc1e2da":{name:"Pokemon Stadium",save:"FlashRam"},"5de0c991b9af3aad":{name:"Pokemon Stadium",save:"FlashRam"},"1b1e0142b52d55e3":{name:"Pokemon Stadium",save:"FlashRam"},b3d9f590f0dc0e9d:{name:"Pokemon Stadium",save:"FlashRam"},a35335a2392dbf42:{name:"Pokemon Stadium",save:"FlashRam"},"757207849c5b3157":{name:"Pokemon Stadium",save:"FlashRam"},ce49e5b6c03481dc:{name:"Pokemon Stadium",save:"FlashRam"},"821157036dd02f89":{name:"Pokemon Stadium 2",save:"FlashRam"},c7a55aacc3cdb0a9:{name:"Pokemon Stadium 2",save:"FlashRam"},"727e9b435d49a1c1":{name:"Pokemon Stadium 2",save:"FlashRam"},"0bfca1d04b07b82f":{name:"Pokemon Stadium 2",save:"FlashRam"},"00afceef48480922":{name:"Pokemon Stadium 2",save:"FlashRam"},"5bfca1d04b07b82f":{name:"Pokemon Stadium 2",save:"FlashRam"},"9c365229a8c3e4b6":{name:"Pokemon Stadium 2",save:"FlashRam"},c2d74fee38d9f19c:{name:"Pokemon Stadium GS",save:"FlashRam"},"9207384145e067a1":{name:"Polaris Sno Cross"},fadca6d7b7b6fecc:{name:"Power League Baseball 64"},ad5789cfa97ed596:{name:"Power Rangers - Lightspeed Rescue"},"110cf6397dba2eab":{name:"Power Rangers - Lightspeed Rescue"},"75d474fcab78029a":{name:"Powerpuff Girls - Chemical X-Traction",save:"Eeprom4k"},"547fd2f3f9ac11c1":{name:"Premier Manager 64"},"4e0ca19bd3ab0804":{name:"Pro Mahjong Kiwame 64"},"0fb3dc1b76d832a1":{name:"Pro Mahjong Tsuwamono 64"},"8366ce8a6e42ba3f":{name:"Pro Yak Yu King Baseball"},b972464be75dbe2d:{name:"Puyo Puyo 4 - Puyo Puyo Party",save:"Eeprom4k"},"6b7e8094e462cc60":{name:"Puyo Puyo Sun 64",save:"Eeprom4k"},"4707dec0d372dfa2":{name:"Puzzle Bobble 64"},"9cf75b9fa008fed2":{name:"Quake 64"},"741d9316346ddc65":{name:"Quake 64"},"43f1a8bd622dafb1":{name:"Quake II"},d7d93374d022432c:{name:"Quake II"},d94dbbc80b435fcc:{name:"Quest 64"},a55f70280e6909b5:{name:"Racing Simulation - Monaco Grand Prix",save:"Eeprom4k"},"2dac77289a13dcc3":{name:"Racing Simulation 2"},f0ca1e9f0e8ac4ee:{name:"Rakuga Kids"},"6818d267614042c5":{name:"Rakuga Kids"},"0cbad935865548df":{name:"Rally '99"},"3d8ea87371c5c53a":{name:"Rally Challenge 2000",save:"Eeprom4k"},e4f99fc27dfe4b26:{name:"Rampage - World Tour"},"4844d484b019ca67":{name:"Rampage - World Tour"},"9b093d67de08c8a4":{name:"Rampage 2 - Universal Tour"},"4942fc5d079c5299":{name:"Rampage 2 - Universal Tour"},"8ec40403b80140ac":{name:"Rat Attack"},f10bfd20871dcff5:{name:"Rat Attack"},"9bbfc5f3e2330f16":{name:"Rayman 2 - The Great Escape"},"0be1d56046eded8b":{name:"Rayman 2 - The Great Escape"},"4a831839290cb515":{name:"Razor Freestyle Scooter"},"29b4b7ea572cc9ba":{name:"Ready 2 Rumble Boxing"},"34a3d48b058b131e":{name:"Ready 2 Rumble Boxing"},"339521e9bdaffb13":{name:"Ready 2 Rumble Boxing Round 2"},a5b118aaeb6adb07:{name:"Resident Evil 2",save:"SRAM"},"8e0e509bb35005e9":{name:"Resident Evil 2",save:"SRAM"},"87a91f0fa6afc1bf":{name:"Re-Volt"},"9ee2e7c3cc51725d":{name:"Re-Volt"},"6c7450f00b827b24":{name:"Road Rash 64"},"6a36d8029cefab6c":{name:"Road Rash 64"},db4d6b0b82e67196:{name:"Roadsters"},"707ae874d4ae9362":{name:"Roadsters"},d3a5bc747e5f944a:{name:"Roadsters Trophy"},"0f692b27777a0aad":{name:"Robot Ponkottsu 64 - Caramel of the 7 Seas",save:"Eeprom4k"},"93b8a075b521a34c":{name:"Robotech - Crystal Dreams"},"324b8eac2673b4e7":{name:"Robotron 64"},"4f9df69f59005f19":{name:"Robotron 64"},f875d39fc82df345:{name:"Rocket - Robot on Wheels",save:"Eeprom4k"},"85e05e0c3edd67a1":{name:"Rocket - Robot on Wheels",save:"Eeprom4k"},"3b5966d6075ca2d7":{name:"Rockman Dash",save:"FlashRam"},"7e260025cec37e2a":{name:"RR64 - Ridge Racer 64",save:"Eeprom16k"},"1070e9fea0a9944e":{name:"RR64 - Ridge Racer 64",save:"Eeprom16k"},"378f8f658dd21318":{name:"RTL World League Soccer 2000"},c5b3020cb811259e:{name:"Rugrats - Scavenger Hunt"},dadf3a4daefc9875:{name:"Rugrats - Treasure Hunt"},"0fca1a458abc6378":{name:"Rugrats - Treasure Hunt"},b46c692bd8dc937b:{name:"Rugrats - Treasure Hunt"},"3215c21fd466640b":{name:"Rugrats in Paris - The Movie"},"391dc60aa603faab":{name:"Rugrats in Paris - The Movie"},"31e0d6ed13601368":{name:"Rush 2 - Extreme Racing USA"},"3621cfb715a70afa":{name:"Rush 2 - Extreme Racing USA"},f34791760ec13320:{name:"S.C.A.R.S."},"602d8e913e6865f8":{name:"S.C.A.R.S."},"20186b2a66f4bc6a":{name:"San Francisco Rush - Extreme Racing"},b016d1610cd624fa:{name:"San Francisco Rush - Extreme Racing"},a2eca9b98ee4aa17:{name:"San Francisco Rush 2049"},"1894d251e36ab4d5":{name:"San Francisco Rush 2049"},c44e810ca85cfe58:{name:"Scooby-Doo - Classic Creep Capers"},"1d22bde3d334083c":{name:"Scooby-Doo - Classic Creep Capers"},b7f6f5eb39d756c9:{name:"SD Hiryuu no Ken Densetsu"},"75fdd584df3cfdbb":{name:"Shadow Man"},b560473a10d4742d:{name:"Shadow Man"},c3f806eaeddec207:{name:"Shadow Man"},e537c460e31e25a2:{name:"Shadow Man"},ce97680354fad4e0:{name:"Shadowgate 64 - Trials of the Four Towers"},"556fb4020b8d7761":{name:"Shadowgate 64 - Trials of the Four Towers"},"84ea4ed8b4f1b245":{name:"Shadowgate 64 - Trials of the Four Towers"},f2fcc12bf40d9a7b:{name:"Shadowgate 64 - Trials of the Four Towers"},"0c28d5b12abca74b":{name:"Sim City 2000"},b00fbcb6982181e3:{name:"Sin and Punishment - Tsumi To Batsu",save:"Eeprom4k"},"19d5f42e5e0c4ac6":{name:"Snow Speeder"},"9deaf4dbc0823e33":{name:"Snowboard Kids"},ff04fc84e93c25b1:{name:"Snowboard Kids"},a0cdd75fad51bbd9:{name:"Snowboard Kids"},ea290c93bf459293:{name:"Snowboard Kids 2",save:"Eeprom4k"},"1a1d75c2ff9bc1f8":{name:"Snowboard Kids 2",save:"Eeprom4k"},"512321224b594640":{name:"Sonic Wings Assault",save:"Eeprom4k"},"39e9cb7e9517333c":{name:"South Park"},"6236b5209f89617b":{name:"South Park"},"48a90cc04bd3608e":{name:"South Park - Chef's Luv Shack"},"76b2f307393d8fec":{name:"South Park Rally"},"3afc8a4ff22d91f7":{name:"South Park Rally"},"123446378d38c5ea":{name:"Space Dynamites",save:"Eeprom4k"},"9723feeb34da74ff":{name:"Space Invaders"},"8438e2bfafea48ef":{name:"Spacestation Silicon Valley",save:"Eeprom4k"},"72e270fcaae7ff08":{name:"Spacestation Silicon Valley",save:"Eeprom4k"},"71d10ea66ed0853d":{name:"Spider-Man"},"6805ed0d5e510215":{name:"St. Andrews Old Course"},f815d0a743aa8922:{name:"Star Fox 64",save:"Eeprom4k"},c1a7caff37858568:{name:"Star Fox 64",save:"Eeprom4k"},a00b78ba34db210f:{name:"Star Fox 64",save:"Eeprom4k"},"853cd9dde881e3da":{name:"Star Soldier Vanishing Earth",save:"Eeprom4k"},"23eb03b73ae5aa28":{name:"Star Soldier Vanishing Earth",save:"Eeprom4k"},"42a263f13b9b44f2":{name:"Star Twins"},"124aa266c26aaf22":{name:"Star Wars - Rogue Squadron",save:"Eeprom4k"},a2bd5c164622a605:{name:"Star Wars - Rogue Squadron",save:"Eeprom4k"},c1919121613c1833:{name:"Star Wars - Rogue Squadron",save:"Eeprom4k"},ec4ba2664fd9ad2e:{name:"Star Wars - Rogue Squadron",save:"Eeprom4k"},bbe8e07eaa11e449:{name:"Star Wars - Rogue Squadron",save:"Eeprom4k"},"63ac24fe17aa411b":{name:"Star Wars - Shadows of the Empire",save:"Eeprom4k"},"8166484d45927dab":{name:"Star Wars - Shadows of the Empire",save:"Eeprom4k"},"5c7e4d2622468718":{name:"Star Wars - Shadows of the Empire (v1.0)",save:"Eeprom4k"},"91b0474160102563":{name:"Star Wars - Shadows of the Empire (v1.1)",save:"Eeprom4k"},"54edd74d7d28f974":{name:"Star Wars - Shadows of the Empire (v1.2)",save:"Eeprom4k"},"90487e82dc688495":{name:"Star Wars - Shuggeki Rogue Chitai",save:"Eeprom4k"},"9b98023de281a3d4":{name:"Star Wars Episode I - Battle for Naboo",save:"Eeprom4k"},e2ace6ea84430b02:{name:"Star Wars Episode I - Battle for Naboo",save:"Eeprom4k"},"9803f7728ba95665":{name:"Star Wars Episode I - Racer",save:"Eeprom16k"},"52b1f561ab226104":{name:"Star Wars Episode I - Racer",save:"Eeprom16k"},c42ded5302802506:{name:"Star Wars Episode I - Racer",save:"Eeprom16k"},fbfb8406a5a83e5d:{name:"StarCraft 64",save:"FlashRam"},a35ecf42df34139a:{name:"StarCraft 64",save:"FlashRam"},c32c9bbca54dd04e:{name:"StarCraft 64 (beta)",save:"FlashRam"},b8a5ed9403e97386:{name:"Starshot - Space Circus Fever",save:"Eeprom4k"},"550e9ed89aa97ab1":{name:"Starshot - Space Circus Fever",save:"Eeprom4k"},d7d81095d20d1035:{name:"Stunt Racer 64"},"696b64f4951075c5":{name:"Super B-Daman - Battle Phoenix 64"},"5a211daa9abecb91":{name:"Super Bowling 64"},"85f3f2f37f0c496e":{name:"Super Bowling 64"},f08cbca5f651bad8:{name:"Super Mario 64 - Star Road",save:"Eeprom4k"},"76d1fe61f9bb05ea":{name:"Super Mario 64 - The Missing Stars v2",save:"Eeprom4k"},"88aefe21241410a4":{name:"Super Mario 64 - The Missing Stars",save:"Eeprom4k"},d5ba7f26dcfa9375:{name:"Super Mario 64 Ru",save:"Eeprom4k"},c5425a63dc8ec5bd:{name:"Super Mario 64 Extended",save:"Eeprom4k"},ff2b5a632623028b:{name:"Super Mario 64",save:"Eeprom4k"},"0e3daa4e247c7574":{name:"Super Mario 64",save:"Eeprom4k"},"36f03ca0d2c5c1bc":{name:"Super Mario 64",save:"Eeprom4k"},a8a4fbd62caa2663:{name:"Super Mario 64 Shindou Edition",save:"Eeprom4k"},"80205766e148e328":{name:"Super Robot Spirits"},"10d84916d2d63af7":{name:"Super Robot Taisen 64"},"5b8b6b91a4850b78":{name:"Super Smash Brothers",save:"SRAM"},"485f9493302e0f5c":{name:"Super Smash Brothers",save:"SRAM"},a1fd26dde36b4acb:{name:"Super Smash Brothers",save:"SRAM"},"222ee09cb0f16e20":{name:"Super Speed Race 64"},"532545c1d9247b5d":{name:"Supercross 2000"},"7f12bb2cd8bfc209":{name:"Supercross 2000"},"5bf3e8a2d987dcc9":{name:"Superman - The Animated Series"},"74ab4cb4299a0207":{name:"Superman - The Animated Series"},f311e83524277999:{name:"Susume! Taisen Puzzle Dama Toukon! Marumata Chou"},"56a48bb9af762b5b":{name:"Tamagotchi World 64",save:"Eeprom4k"},"54ddbcae4a83ff15":{name:"Taz Express",save:"Eeprom4k"},bb2f04d97c99fffc:{name:"Telefoot Soccer 2000"},a6db3a969bc8d5f7:{name:"Tetris 64"},beda1f3cbae0a402:{name:"Tetrisphere",save:"Eeprom4k"},a984e60fc47ab78b:{name:"Tetrisphere",save:"Eeprom4k"},"161b7d91e19b1f83":{name:"The Legend of Zelda - OoT Nightmare Mod",save:"SRAM"},c7c7b1f831a4fc1e:{name:"The Legend of Zelda - Ocarina of Time Ru",save:"SRAM"},"4fecec6a144892f0":{name:"The Legend of Zelda - Majora's Mask ",save:"FlashRam"},E585C39FC705CC3E:{name:"The Legend of Zelda - Majora's Mask Debug",save:"FlashRam"},b71170ec2bd71676:{name:"The Legend of Zelda - Ocarina of Time (v1.0)",save:"SRAM"},"1a0034f006ed47ae":{name:"The Legend of Zelda - Ocarina of Time Master Quest (GC)",save:"SRAM"},"69b544b085193c37":{name:"The Legend of Zelda - Ocarina of Time (v1.0)",save:"SRAM"},"1fa83dd4191e1e02":{name:"The Legend of Zelda - Ocarina of Time (v1.1)",save:"SRAM"},bd5f05b20c4eab0b:{name:"The Legend of Zelda - Ocarina of Time (v1.1)",save:"SRAM"},aea23b699f4ef1b7:{name:"The Legend of Zelda - Ocarina of Time (v1.2)",save:"SRAM"},c35a46091b50cbf8:{name:"The Legend of Zelda - Ocarina of Time (GC)",save:"SRAM"},f6187d915354bc69:{name:"The Legend of Zelda - Zelda's Birthday",save:"SRAM"},"08eb43b49311b34d":{name:"The Legend of Zelda - Majora's Mask (GC)",save:"FlashRam"},"459379bf027aff39":{name:"The Legend of Zelda - Majora's Mask (Demo)",save:"FlashRam"},"1c635453f0dea203":{name:"The Legend of Zelda - Majora's Mask",save:"FlashRam"},c65579e9388d33bc:{name:"The Legend of Zelda - Majora's Mask",save:"FlashRam"},ba35ddf375e05241:{name:"The Legend of Zelda - Ocarina of Time (GC)",save:"SRAM"},f336411da9ee63af:{name:"The Legend of Zelda - OOT (Master Quest)",save:"SRAM"},"3f14532151632d99":{name:"The New Tetris",save:"SRAM"},"0aff1ce6710d1cce":{name:"The New Tetris",save:"SRAM"},"33ddbf4e849d4c66":{name:"Tigger's Honey Hunt",save:"FlashRam"},"2ff7c4e006159e76":{name:"Tigger's Honey Hunt",save:"FlashRam"},"1c39e76333eacce6":{name:"Tom and Jerry in Fists of Furry",save:"Eeprom4k"},fb4e4f2bfe11c543:{name:"Tom and Jerry in Fists of Furry",save:"Eeprom4k"},"3329418ddb648f58":{name:"Tom Clancy's Rainbow Six"},"35f36b4881cc4d03":{name:"Tom Clancy's Rainbow Six"},"420c2a397de790b7":{name:"Tom Clancy's Rainbow Six"},"3daf7548a2d3669a":{name:"Tom Clancy's Rainbow Six"},"14979eef7d2c3bc0":{name:"Tonic Trouble"},"6e913f0998b60844":{name:"Tonic Trouble"},"22c04e2085d119b1":{name:"Tony Hawk's Pro Skater (v1.0)"},"804114e0c9780b65":{name:"Tony Hawk's Pro Skater (v1.1)"},a526899f09b48705:{name:"Tony Hawk's Pro Skater"},"57b5ea840f198ac8":{name:"Tony Hawk's Pro Skater 2"},"180e1599a5e66612":{name:"Tony Hawk's Pro Skater 2"},"99150E181266E6A5":{name:"Tony Hawk's Pro Skater 2"},b5707f1afdb9b700:{name:"Tony Hawk's Pro Skater 3"},bf6e749a99ea0228:{name:"Toon Panic (Proto)"},f002cc8e81de8b7f:{name:"Top Gear Hyper-Bike",save:"Eeprom4k"},c6493f5fb014c70d:{name:"Top Gear Hyper-Bike",save:"Eeprom4k"},"80cd41d712b9a9ac":{name:"Top Gear Overdrive",save:"Eeprom4k"},"4ff2780517bf7591":{name:"Top Gear Overdrive",save:"Eeprom4k"},"38a59bd089541a1c":{name:"Top Gear Overdrive",save:"Eeprom4k"},"3d9b2662e8b111fe":{name:"Top Gear Rally",save:"Eeprom4k"},"4762590e8b4b3d75":{name:"Top Gear Rally",save:"Eeprom4k"},"01e7437fd1286353":{name:"Top Gear Rally",save:"Eeprom4k"},e07359beb8edb089:{name:"Top Gear Rally 2"},d62cefcfe673e9c9:{name:"Top Gear Rally 2"},"77b6babee4b5b051":{name:"Top Gear Rally 2"},"77d32df847b33f8c":{name:"Top Gear Rally 2"},a43c70efc99a4a4d:{name:"Toukon Road - Brave Spirits"},"437f1c551c834991":{name:"Toukon Road 2 - The Next Generation"},"75902a781d6352e5":{name:"Toy Story 2"},"3e7450a1cd2225cf":{name:"Toy Story 2"},"97db93cbd5635c7f":{name:"Toy Story 2"},"5838ebcc972d9526":{name:"Toy Story 2"},"436b4bfea7291d08":{name:"Triple Play 2000"},"0ffae466d0c788de":{name:"Turok - Legenden des Verlorenen Landes"},"8b49b9ad558ff2da":{name:"Turok - Rage Wars"},"1462a21e0f9090e7":{name:"Turok - Rage Wars"},dd09702f53ac3bfc:{name:"Turok - The Dinosaur Hunter"},"63d95f661266ccb5":{name:"Turok - The Dinosaur Hunter"},b8e66a9122ab1788:{name:"Turok - The Dinosaur Hunter"},"0df1702fff87415c":{name:"Turok - The Dinosaur Hunter (v1.0)"},dd095f6653ac3bfc:{name:"Turok - The Dinosaur Hunter (v1.0)"},cd0d702fc9c56c17:{name:"Turok - The Dinosaur Hunter (v1.1/v1.2)"},"49770e2e599db4b8":{name:"Turok 2 - Seeds of Evil"},"942bb9e025e0a7b9":{name:"Turok 2 - Seeds of Evil"},"0b8405fe0c329393":{name:"Turok 2 - Seeds of Evil"},"118a08497e959464":{name:"Turok 2 - Seeds of Evil"},"942bb9e0bd7ce880":{name:"Turok 2 - Seeds of Evil"},fc5ac9e8da21d135:{name:"Turok 2 - Seeds of Evil - Kiosk"},f179a589ef977e66:{name:"Turok 3 - Shadow of Oblivion"},f22f166a4c709320:{name:"Turok 3 - Shadow of Oblivion"},"329dc9bb80aa7d11":{name:"Twisted Edge Extreme Snowboarding"},b8a588e6183f4bb1:{name:"Twisted Edge Extreme Snowboarding"},"7851da6ec1fe96d3":{name:"Vigilante 8"},"6a0571ea474821e4":{name:"Vigilante 8"},a282bce294d61c59:{name:"Vigilante 8"},f4791f15e5c8ed8e:{name:"Vigilante 8"},"6d86c5f5d9132705":{name:"Vigilante 8 - 2nd Offense"},"7ebc10dd51b300f9":{name:"Vigilante 8 - 2nd Offense"},"986c006081a30526":{name:"Violence Killer - Turok New Generation"},"8b24b3824d243ee7":{name:"Virtual Chess 64"},"21a2da2fcea788a5":{name:"Virtual Chess 64"},"43764a4ed73974a3":{name:"Virtual Pool 64"},d0f2f9989cf0d903:{name:"Virtual Pool 64"},c4085c048b79fd4a:{name:"Virtual Pro Wrestling",save:"Eeprom4k"},"354209cd624b0788":{name:"Virtual Pro Wrestling 2",save:"SRAM"},"3890053c8221bfc8":{name:"V-Rally Edition 99",save:"Eeprom4k"},a524024d9457eb1b:{name:"V-Rally Edition 99",save:"Eeprom4k"},"196b6e635fdc7de5":{name:"V-Rally Edition 99",save:"Eeprom4k"},"8ad56680c1cadec3":{name:"Waialae Country Club - True Golf Classics",save:"Eeprom4k"},"75300593430f1e26":{name:"Waialae Country Club - True Golf Classics",save:"Eeprom4k"},ad57500c6e126e04:{name:"Waialae Country Club - True Golf Classics (1.1)",save:"Eeprom4k"},e28c31ddba9837b7:{name:"Waialae Country Club - True Golf Classics (1.1)",save:"Eeprom4k"},f628fef7c3acf2c3:{name:"War Gods"},"70cc15d7d6f51c27":{name:"War Gods"},d691915c06c30ab3:{name:"Wave Race 64",save:"Eeprom4k"},"96fa0e65a7f9dd30":{name:"Wave Race 64",save:"Eeprom4k"},"531fe17d9d2f8774":{name:"Wave Race 64 (v1.0)",save:"Eeprom4k"},"614b2f496a14e504":{name:"Wave Race 64 (v1.1)",save:"Eeprom4k"},e2f35d53f1899760:{name:"Wave Race 64 Shindou Edition",save:"Eeprom4k"},"59aa3bdc6a45bb0a":{name:"Wayne Gretzky's 3D Hockey v1.1"},"3f22456b565c0ef0":{name:"Wayne Gretzky's 3D Hockey"},"431030f11a5480fd":{name:"Wayne Gretzky's 3D Hockey"},"4b090922af59952c":{name:"Wayne Gretzky's 3D Hockey"},"59389d5a10e7aa97":{name:"Wayne Gretzky's 3D Hockey '98"},f3451b666d26d69e:{name:"Wayne Gretzky's 3D Hockey '98"},dd5a6f39a7ec9366:{name:"WCW Backstage Assault"},d68cbe33126918ec:{name:"WCW Mayhem"},"58067baa7b93969c":{name:"WCW Mayhem"},"1a5ac4d45eb225f4":{name:"WCW Nitro"},"68afdb8b364b5b34":{name:"WCW vs. NWO - World Tour"},bd193e2c5eee1351:{name:"WCW vs. NWO - World Tour (v1.0)"},b960be713cfbdb1d:{name:"WCW vs. NWO - World Tour (v1.2)"},ab96e5dee77a3baf:{name:"WCW-NWO Revenge",save:"SRAM"},"75a8e86886a4e70c":{name:"WCW-NWO Revenge",save:"SRAM"},"4fb5a8ce03d5217f":{name:"Wetrix"},faeab6dca3cfbbc6:{name:"Wetrix"},"2b0996e84e4d24dc":{name:"Wheel of Fortune"},c7c4eb0c32e99c0c:{name:"Wild Choppers",save:"Eeprom4k"},"7e9598edacdc4282":{name:"WinBack - Covert Operations"},e056a01f6a94b9a4:{name:"WinBack - Covert Operations"},af8c89d55bb60760:{name:"WinBack - Covert Operations"},"32272d1318910ec7":{name:"Wipeout 64"},"7d0e3154d830546b":{name:"Wipeout 64"},"65973ce4bec1b105":{name:"Wonder Project J2"},"38594b3a9d986fa2":{name:"Wonder Project J2 (English)"},f7881e4f963f5a4a:{name:"Wonder Project J2 (English)"},"6a6d63bdba541f5d":{name:"World Cup 98"},"9030fcf9c24e01ff":{name:"World Cup 98"},c8fe8d30f6b52ece:{name:"World Driver Championship"},"782706acb8fcaddf":{name:"World Driver Championship"},a059e913b0ca930e:{name:"Worms - Armageddon",save:"Eeprom4k"},"7bc5212d8cc5e48f":{name:"Worms - Armageddon",save:"Eeprom4k"},"0fec5bcd0810fd86":{name:"WWF - War Zone"},a475a233594450b8:{name:"WWF - War Zone"},c851318f45f53a4f:{name:"WWF Attitude"},"142fbed288374538":{name:"WWF Attitude"},"7b5bf45be8ee6b59":{name:"WWF Attitude"},"40064b4efbbc491b":{name:"WWF No Mercy",save:"FlashRam"},"8ef08d6dcfc308d0":{name:"WWF No Mercy (v1.0)",save:"FlashRam"},c294db8cf0c646cb:{name:"WWF No Mercy (v1.1)",save:"FlashRam"},"0390a59064980831":{name:"WWF WrestleMania 2000",save:"SRAM"},a57d731259919623:{name:"WWF Wrestlemania 2000",save:"SRAM"},be5313c7eea609aa:{name:"WWF WrestleMania 2000",save:"SRAM"},"9dae5305c1e0d8ea":{name:"Xena Warrior Princess - Talisman of Fate"},c767160aa6463329:{name:"Xena Warrior Princess - Talisman of Fate"},c3968b9fdc9411a0:{name:"Yakouchuu II - Satsujun Kouru"},e8d83723ec7c8e6b:{name:"Yoshi's Story",save:"Eeprom16k"},"60cacf2d47b15483":{name:"Yoshi's Story",save:"Eeprom16k"},"497df9d35b132469":{name:"Yoshi's Story",save:"Eeprom16k"},"8d3bda777c0d2b16":{name:"Yosuke no Mahjong Juku",save:"Eeprom4k"},"2d16e69f37407ee9":{name:"Yuke Yuke!! Trouble Makers"},c1d0738466061223:{name:"Zelda no Densetsu 2 - Mujura no Kamen",save:"FlashRam"},b82df5f736e69521:{name:"Zelda no Densetsu - Toki no Ocarina Collectors Ed.",save:"SRAM"},baf411f65c1384c5:{name:"Zelda no Densetsu - Toki no Ocarina (GC)",save:"SRAM"},ba453bf46f9b0e2f:{name:"Zelda no Densetsu - Toki no Ocarina (GC)",save:"SRAM"},"127341ec5fde31eb":{name:"Zelda no Densetsu 2 - Mujura no Kamen",save:"FlashRam"},"3804ae69f3f3632c":{name:"Zelda no Densetsu 2 - Mujura no Kamen (1.1)",save:"FlashRam"},cd0c011cfab7d322:{name:"Zool - Majou Tsukai Densetsu"},"54a43977662af5a2":{name:"A HORiZON64 RELEASE"},"91d8ab5ccef62962":{name:"Fishy by NaN v0.3141"},bc069a1355006b41:{name:"Mind Present-Readme"},b1cb11c87c61b78f:{name:"Mind Present / DNX"},"54f53fcb0bcd7387":{name:"Tron Demo"},"4549049c0c0b1ed3":{name:"POM99 - README"},"7a7d3b994df0542e":{name:"POM99 - MADEIRAGAMES"},"575aa9a37dc2e69f":{name:"POM99 - WET DREAMS"},"95c03bca0a864996":{name:"POM99 - CAN-BETA"},d44a7da4f981fa8b:{name:"Manic Miner 64"},"2d369c9d086be65b":{name:"Shag-a-delic/CAMELOT"},c479518fdc263580:{name:"Space Rotator"},"70bb552625997d66":{name:"O.D.T.",save:"Controller"},a61564e8535b3998:{name:"O.D.T.",save:"Controller"}};class SZ{domLoaded(){const J=n64js.debugger();$(".tabbable a").on("shown.bs.tab",(q)=>{J.redraw()}),J.redraw()}triggerLoad(){const J=document.getElementById("fileInput");J.value="",J.click()}loadFile(){const J=document.getElementById("fileInput");if(J&&J.files.length>0){const q=J.files[0],Q=new FileReader;Q.onerror=(Y)=>{this.displayError("loading file")},Q.onload=(Y)=>{n64js.loadRomAndStartRunning(Y.target.result)},Q.readAsArrayBuffer(q)}}displayWarning(J){this.displayAlert("Warning",J)}displayError(J){this.displayAlert("Error",J)}displayAlert(J,q){const Y=document.getElementById("alert").content.cloneNode(!0),Z=Y.querySelector(".alert-type"),K=Y.querySelector(".alert-message");Z.textContent=J+"!",K.textContent=q,$("#alerts").append(Y)}setRunning(J){const q=J?'<i class="bi-pause"></i> Pause':'<i class="bi-play"></i> Run';$("#runbutton").html(q)}}var gZ=function(J){n8=J,uZ.setRunning(J)},LM=function(J){const q=md5(J);M(`hash is ${q}`)},VM=function(J){C7(J),LM(J);const q=n0.createROM(J),Q={header:q.getU32(0),clock:q.getU32(4),bootAddress:q.getU32(8),release:q.getU32(12),crclo:q.getU32(16),crchi:q.getU32(20),unk0:q.getU32(24),unk1:q.getU32(28),name:l5(q.u8,32,20),unk2:q.getU32(52),unk3:q.getU16(56),unk4:q.getU8(58),categoryCode:WK(q.getU8(59)),cartId:q.getU16(60),countryId:q.getU8(62),romVersion:q.getU8(63)};console.log(Q);const Y=$('<table class="register-table"><tbody></tbody></table>'),Z=Y.find("tbody");for(let X in Q){const W=typeof Q[X]==="string"?Q[X]:N(Q[X]);Z.append(`<tr><td>${X}</td><td>${W}</td></tr>`)}jK(Y),A0.cic=c5(q.u8),A0.id=o5(Q.crclo,Q.crchi),A0.country=Q.countryId,A0.tvType=XK(Q.countryId);const K=d5[A0.id];if(K)M(`Loaded info for ${A0.id} from db`),A0.name=K.name,A0.save=K.save;else M(`No info for ${A0.id} in db`),A0.name=Q.name,A0.save="Eeprom4k";M(`rominfo is ${_Z(A0)}`),$("#title").text(`n64js - ${A0.name}`)},UM=function(){const J=[],q=new XMLHttpRequest;if(q.open("GET","roms/n64-systemtest-all.z64",!0),q.responseType="arraybuffer",q.onload=(Q)=>{const Y=q.response;if(Y)n64js.loadRomAndStartRunning(Y)},q.send(null),q.status!=200)return;for(let Q=0;Q<q.responseText.length;++Q)J.push(q.responseText.charCodeAt(Q)&255)},MM=function(){n0.timeline.startRecording()},fZ=function(){if(Q6)Q6.begin();if(n8){if(requestAnimationFrame(fZ),n64js.hardware().aiRegDevice.shouldSkipFrame())return;let J=GM;if(Y8.active&&!OW())J=Y8.debugCycles;if(PK())J=LK(J);if(J>0)n64js.cpu0.run(J),Y8.redraw()}else if(MW())requestAnimationFrame(fZ),hW(),x9();if(Q6)Q6.end()},xZ=function(J){return(J>>26&63)===a5},i5=function(J){return J+"-"+A0.id},OM=function(J){const q=A0.name?`n64js - ${A0.name} - ${J}mspf`:`n64js - ${J}mspf`;$("#title").text(q)},e5=function(J,q){if(gZ(!1),pZ(),M('<span style="color:red">'+J+"</span>"),q)n64js.ui().displayError(J)},pZ=function(){n64js.cpu0.breakExecution()};window.n64js=window.n64js||{};var a5=28,GM=1e8,Q6=null,n8=!1,TJ=new Map,r5=[],s5={runTest:UM,recordTimeline:MM};g0.add(s5,"runTest").name("Run n64-systemtest");g0.add(s5,"recordTimeline").name("Record Timeline");var A0={id:"",name:"",cic:"6101",country:KK,tvType:qJ,save:"Eeprom4k"},n0=new TZ(A0),vZ=new sq,PM=new tq(n0,vZ.inputs),uZ=new SZ,Y8=null;n64js.hardware=()=>n0;n64js.joybus=()=>PM;n64js.ui=()=>uZ;n64js.debugger=()=>Y8;n64js.loadRomAndStartRunning=(J)=>{VM(J),n64js.reset(),Y8.redraw(),gZ(!1),n64js.toggleRun()};n64js.toggleRun=()=>{if(gZ(!n8),n8)fZ()};n64js.toggleFullscreen=()=>{document.getElementById("display").requestFullscreen().catch((q)=>{console.log(`Error attempting to enable fullscreen mode: ${q.message} (${q.name})`)})};n64js.breakEmulationForDisplayListDebug=()=>{if(n8)n64js.toggleRun(),pZ()};n64js.step=()=>{if(!n8)n64js.singleStep(),Y8.redraw()};n64js.getInstruction=(J)=>{const q=n0.memMap.readMemoryInternal32(J);if(xZ(q))return TJ[J]||0;return q};n64js.isBreakpoint=(J)=>{const q=n0.memMap.readMemoryInternal32(J);return xZ(q)};n64js.toggleBreakpoint=(J)=>{const q=n0.memMap.readMemoryInternal32(J);let Q;if(xZ(q))Q=TJ[J]||0,delete TJ[J];else Q=a5<<26,TJ[J]=q;n0.memMap.writeMemoryInternal32(J,Q)};n64js.getLocalStorageItem=(J)=>{const q=i5(J),Q=localStorage.getItem(q);return Q?m5(Q):void 0};n64js.setLocalStorageItem=(J,q)=>{const Q=i5(J),Y=_Z(q);localStorage.setItem(Q,Y)};var t5,fq;n64js.emitRunningTime=(J)=>{const Y=((new Date()).getTime()-t5.getTime()).toString();n64js.ui().displayWarning(`Time to ${J} ${Y}`)};n64js.onPresent=()=>{const J=new Date;if(fq){const q=J.getTime()-fq.getTime();OM(q)}fq=J};n64js.addResetCallback=(J)=>{r5.push(J)};n64js.reset=()=>{TJ.clear(),GK(),n0.reset(),$7(n0),p$(n0),UW(),n0.loadROM(),$K(n64js.cpu0,n0,A0),t5=new Date,fq=void 0;for(let J of r5)J()};n64js.check=(J,q)=>{if(!J)M(q)};n64js.warn=(J)=>{FK(J)};n64js.stopForBreakpoint=()=>{e5("Breakpoint",!1)};n64js.halt=(J)=>{e5(J,!0)};n64js.returnControlToSystem=()=>{pZ()};n64js.init=()=>{n64js.reset(),Y8=new mY,VW($("#display"));const J=document.querySelector("body");J.addEventListener("keyup",(q)=>{vZ.handleKey(0,q.key,!1)}),J.addEventListener("keydown",(q)=>{vZ.handleKey(0,q.key,!0)}),uZ.domLoaded()};n64js.togglePerformance=()=>{const J=document.getElementById("performance");if(Q6)J.removeChild(Q6.dom),Q6=null;else Q6=new Stats,Q6.showPanel(1),Q6.dom.style.position="relative",J.appendChild(Q6.dom)};
|