-
Notifications
You must be signed in to change notification settings - Fork 1
/
1802.min.js
30 lines (30 loc) · 9.22 KB
/
1802.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(function(a,b){if(typeof module!="undefined"){module.exports=b();}else{if(typeof define=="function"&&typeof define.amd=="object"){define(b);}else{this[a]=b();
}}}("CPU1802",function(){var e=0,i=0,b=0,n=0,a=0,u=0,m=0,w=0,g=0,E=0,C=0,z=0,x=0,M=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],l=false,f,o;var N,aa,K,t,O,R,S=function(r){return aa(r)*256+aa(65535&(r+1));
},G=function(D,r){N(D,(r>>8)&255);N((D+1)&65535,r&255);},U=[0,2,0,0,0,0,2,2,4,4,2,2,2,2,2,2,2,2,0,0,0,0,2,2,0,2,0,2,0,0,0,0,4,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,5,0,10,0,0,9,12,2,0,0,2,2,0,2,2,2,2,2,0,2,2,0,2,2,0,0,2,2,0,2,2,2,2,2,0,2,2,0,2,7,0,0,7,7,0,7,7,7,7,7,0,7,7,4,7,6,0,0,6,6,0,6,6,6,6,6,0,6,6,3,6,2,2,2,0,2,2,2,0,2,2,2,2,3,8,3,0,3,3,3,0,3,3,3,4,3,3,3,3,4,0,4,5,5,5,5,0,5,5,5,6,5,5,5,5,6,8,6,7,4,4,4,0,4,4,4,5,4,4,4,4,5,9,5,6,2,2,2,0,2,2,2,0,2,2,2,2,0,0,3,0,3,3,3,0,3,3,3,4,3,3,3,3,0,0,4,5,5,5,5,0,5,5,5,6,5,5,5,5,0,0,6,7,4,4,4,0,4,4,4,5,4,4,4,4,0,0,5,6],Z=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165],d=[0,1,2,3,4,5,6,7,8,9,16,17,18,19,20,21,22,23,24,25,32,33,34,35,36,37,38,39,40,41,48,49,50,51,52,53,54,55,56,57,64,65,66,67,68,69,70,71,72,73,80,81,82,83,84,85,86,87,88,89,96,97,98,99,100,101,102,103,104,105,112,113,114,115,116,117,118,119,120,121,128,129,130,131,132,133,134,135,136,137,144,145,146,147,148,149,150,151,152,153],v=function(){return M[i];
},c=function(r){M[i]=r;},s=function(){return M[b];},ab=function(r){M[b]=r;},p=function(){var D=v();var r=aa(D++);D&=65535;c(D);return r;},V=function(D){var r=false;
switch(D&7){case 0:r=true;break;case 1:r=(g==1);break;case 2:r=(n===0);break;case 3:r=(a==1);break;case 4:r=(E==1);break;case 5:r=(C===0);break;case 6:r=(z==1);
break;case 7:r=(x===0);break;}return(D>7)?!r:r;},j=function(r,D){n=n+r+D;if(n>255){a=1;n-=256;}else{a=0;}},I=function(r,D){n=n-r-D;if(n<0){a=1;n+=256;}else{a=0;
}},L=function(r,D){n=r-n-D;if(n<0){a=1;n+=256;}else{a=0;}},y=function(){a=n&1;n>>=1;},H=function(){a=(n&128)?1:0;n<<=1;n&=255;},Y=function(){n|=a<<8;a=n&1;
n>>=1;},W=function(){n<<=1;n|=a;a=(n&256)?1:0;n&=255;},B=function(){if(m==1){e+=2;return 2;}var Q=v();var ac=p();var T=false;var r,D;var P=(ac&240)>>4;
var X=(ac&15);switch(P){case 0:if(X===0){m=1;break;}n=aa(M[X]);break;case 1:M[X]++;M[X]&=65535;break;case 2:M[X]--;M[X]&=65535;break;case 4:n=aa(M[X]++);
M[X]&=65535;break;case 5:N(M[X],n);break;case 8:n=M[X]&255;break;case 9:n=(M[X]&65280)>>8;break;case 10:M[X]=(M[X]&65280)|(n&255);break;case 11:M[X]=(M[X]&255)|((n&255)<<8);
break;case 13:i=X;break;case 14:b=X;break;case 3:r=V(X);D=p();if(r){c(Q&65280|D);}break;case 12:T=true;if((X&7)<4){r=V(X);D=p()<<8|p();if(r){c(D);}}else{if(X==4){break;
}r=!V(X-4);if(X==12){r=(u==1);}if(r){p();p();}}break;case 6:if(X===0){ab((s()+1)&65535);}if(X<8){D=s();ab((D+1)&65535);t(X,aa(D));}if(X>8){D=O(X-8,n);N(s(),D);
}break;case 7:switch(X){case 0:case 1:D=aa(s());b=(D&240)>>4;i=(D&15);ab((s()+1)&65535);u=(X===0)?1:0;break;case 2:n=aa(s());ab((s()+1)&65535);break;case 3:N(s(),n);
ab((s()-1)&65535);break;case 8:N(s(),w);break;case 9:w=i|(b<<4);N(M[2],w);b=i;M[2]=(M[2]-1)&65535;break;case 10:g=0;if(R){R(0);}break;case 11:g=1;if(R){R(1);
}break;case 4:j(aa(s()),a);break;case 12:j(p(),a);break;case 5:L(aa(s()),a);break;case 13:L(p(),a);break;case 6:Y();break;case 14:W();break;case 7:I(aa(s()),a);
break;case 15:I(p(),a);break;}break;case 15:switch(X){case 0:n=aa(s());break;case 1:n=n|aa(s());break;case 2:n=n&aa(s());break;case 3:n=n^aa(s());break;
case 8:D=p();n=D;break;case 9:n=n|p();break;case 10:n=n&p();break;case 11:n=n^p();break;case 4:j(aa(s()),0);break;case 12:j(p(),0);break;case 5:L(aa(s()),0);
break;case 13:L(p(),0);break;case 6:y();break;case 14:H();break;case 7:I(aa(s()),0);break;case 15:I(p(),0);break;}break;}e+=2;if(T){e++;}time=T?3:2;if(K){K(time);
}return time;},J=function(){M[0]=0;i=0;b=0;g=0;u=1;m=0;e=0;};var q=function(P,D){var r=P.toString(16);while(r.length<D){r="0"+r;}return r.toUpperCase();
};var F=function(r){return q(r&255,2);};var A=function(r){return q(r,4);};var h=[["IDL",1],["LDN 1",1],["LDN 2",1],["LDN 3",1],["LDN 4",1],["LDN 5",1],["LDN 6",1],["LDN 7",1],["LDN 8",1],["LDN 9",1],["LDN A",1],["LDN B",1],["LDN C",1],["LDN D",1],["LDN E",1],["LDN F",1],["INC 0",1],["INC 1",1],["INC 2",1],["INC 3",1],["INC 4",1],["INC 5",1],["INC 6",1],["INC 7",1],["INC 8",1],["INC 9",1],["INC A",1],["INC B",1],["INC C",1],["INC D",1],["INC E",1],["INC F",1],["DEC 0",1],["DEC 1",1],["DEC 2",1],["DEC 3",1],["DEC 4",1],["DEC 5",1],["DEC 6",1],["DEC 7",1],["DEC 8",1],["DEC 9",1],["DEC A",1],["DEC B",1],["DEC C",1],["DEC D",1],["DEC E",1],["DEC F",1],["BR ~",2],["BQ ~",2],["BZ ~",2],["BDF ~",2],["B1 ~",2],["B2 ~",2],["B3 ~",2],["B4 ~",2],["SKP",1],["BNQ ~",2],["BNZ ~",2],["BNF ~",2],["BN1 ~",2],["BN2 ~",2],["BN3 ~",2],["BN4 ~",2],["LDA 0",1],["LDA 1",1],["LDA 2",1],["LDA 3",1],["LDA 4",1],["LDA 5",1],["LDA 6",1],["LDA 7",1],["LDA 8",1],["LDA 9",1],["LDA A",1],["LDA B",1],["LDA C",1],["LDA D",1],["LDA E",1],["LDA F",1],["STR 0",1],["STR 1",1],["STR 2",1],["STR 3",1],["STR 4",1],["STR 5",1],["STR 6",1],["STR 7",1],["STR 8",1],["STR 9",1],["STR A",1],["STR B",1],["STR C",1],["STR D",1],["STR E",1],["STR F",1],["IRX",1],["OUT 1",1],["OUT 2",1],["OUT 3",1],["OUT 4",1],["OUT 5",1],["OUT 6",1],["OUT 7",1],["---",1],["INP 1",1],["INP 2",1],["INP 3",1],["INP 4",1],["INP 5",1],["INP 6",1],["INP 7",1],["RET",1],["DIS",1],["LDXA",1],["STXD",1],["ADC",1],["SDB",1],["SHRC",1],["SMB",1],["SAV",1],["MARK",1],["REQ",1],["SEQ",1],["ADCI @",2],["SDBI @",2],["SHLC",1],["SMBI @",2],["GLO 0",1],["GLO 1",1],["GLO 2",1],["GLO 3",1],["GLO 4",1],["GLO 5",1],["GLO 6",1],["GLO 7",1],["GLO 8",1],["GLO 9",1],["GLO A",1],["GLO B",1],["GLO C",1],["GLO D",1],["GLO E",1],["GLO F",1],["GHI 0",1],["GHI 1",1],["GHI 2",1],["GHI 3",1],["GHI 4",1],["GHI 5",1],["GHI 6",1],["GHI 7",1],["GHI 8",1],["GHI 9",1],["GHI A",1],["GHI B",1],["GHI C",1],["GHI D",1],["GHI E",1],["GHI F",1],["PLO 0",1],["PLO 1",1],["PLO 2",1],["PLO 3",1],["PLO 4",1],["PLO 5",1],["PLO 6",1],["PLO 7",1],["PLO 8",1],["PLO 9",1],["PLO A",1],["PLO B",1],["PLO C",1],["PLO D",1],["PLO E",1],["PLO F",1],["PHI 0",1],["PHI 1",1],["PHI 2",1],["PHI 3",1],["PHI 4",1],["PHI 5",1],["PHI 6",1],["PHI 7",1],["PHI 8",1],["PHI 9",1],["PHI A",1],["PHI B",1],["PHI C",1],["PHI D",1],["PHI E",1],["PHI F",1],["LBR ^",3],["LBQ ^",3],["LBZ ^",3],["LBDF ^",3],["NOP",1],["LSNQ",1],["LSNZ",1],["LSNF",1],["LSKP",1],["LBNQ ^",3],["LBNZ ^",3],["LBNF ^",3],["LSIE",1],["LSQ",1],["LSZ",1],["LSDF",1],["SEP 0",1],["SEP 1",1],["SEP 2",1],["SEP 3",1],["SEP 4",1],["SEP 5",1],["SEP 6",1],["SEP 7",1],["SEP 8",1],["SEP 9",1],["SEP A",1],["SEP B",1],["SEP C",1],["SEP D",1],["SEP E",1],["SEP F",1],["SEX 0",1],["SEX 1",1],["SEX 2",1],["SEX 3",1],["SEX 4",1],["SEX 5",1],["SEX 6",1],["SEX 7",1],["SEX 8",1],["SEX 9",1],["SEX A",1],["SEX B",1],["SEX C",1],["SEX D",1],["SEX E",1],["SEX F",1],["LDX",1],["OR",1],["AND",1],["XOR",1],["ADD",1],["SD",1],["SHR",1],["SM",1],["LDI @",2],["ORI @",2],["ANI @",2],["XRI @",2],["ADI @",2],["SDI @",2],["SHL",1],["SMI @",2]];
var k=function(P,ac,T,Q){var X=h[P];var ae=X[0];var ad=F(ac);var r=A((Q&65280)|(ac&255));ae=ae.replace("~","$"+r);ae=ae.replace("@","$"+ad);var D=F(ac)+F(T);
ae=ae.replace("^","$"+D);return[ae,X[1]];};return{steps:function(r){while(r>0){r-=B();if(l){e+=r;return;}}},T:function(){return e;},memr:function(r){return aa(r);
},reset:J,init:function(D,X,r,P,T,Q){N=D;aa=X;t=P;O=T;R=Q;K=r;J();},status:function(){return{pc:M[i],sp:M[b],d:n,p:i,x:b,r0:M[0],r1:M[1],r2:M[2],r3:M[3],r4:M[4],r5:M[5],r6:M[6],r7:M[7],r8:M[8],r9:M[9],ra:M[10],rb:M[11],rc:M[12],rd:M[13],re:M[14],rf:M[15],df:a,q:g,ef1:E,ef2:C,ef3:z,ef4:x};
},interrupt:function(){if(u===0){return;}u=1;w=i|(b<<4);b=2;i=1;e++;m=0;},dmaOUT:function(){var r=aa(M[0]);M[0]++;m=0;e++;return r;},dmaIN:function(r){N(M[0],r&255);
M[0]++;e++;m=0;},set:function(r,D){switch(r.toLowerCase()){case"pc":M[i]=D&65535;return;case"d":n=D&255;return;case"x":b=D&15;return;case"p":i=D&15;return;
case"df":a=D&1;return;case"sp":M[b]=D&65535;return;case"r0":M[0]=D&65535;return;case"r1":M[1]=D&65535;return;case"r2":M[2]=D&65535;return;case"r3":M[3]=D&65535;
return;case"r4":M[4]=D&65535;return;case"r5":M[5]=D&65535;return;case"r6":M[6]=D&65535;return;case"r7":M[7]=D&65535;return;case"r8":M[8]=D&65535;return;
case"r9":M[9]=D&65535;return;case"ra":M[10]=D&65535;return;case"rb":M[11]=D&65535;return;case"rc":M[12]=D&65535;return;case"rd":M[13]=D&65535;return;case"re":M[14]=D&65535;
return;case"rf":M[15]=D&65535;return;case"q":g=D&1;return;case"ef1":E=D&1;return;case"ef2":C=D&1;return;case"ef3":z=D&1;return;case"ef4":x=D&1;return;}},flagsToString:function(){return(a==1)?"DF":"-";
},disasm:k};}));