eighty-eighty-js
Version:
A nice little Intel 8080 emulator for Node.js and Browser!
3 lines (2 loc) • 22.4 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("typed-numbers")):"function"==typeof define&&define.amd?define(["exports","typed-numbers"],t):t((e||self).eightyEightyJs={},e.typedNumbers)}(this,function(e,t){function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,a(e,t)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function a(e,t){return a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},a(e,t)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function h(e,t,s){return h=i()?Reflect.construct:function(e,t,s){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return s&&a(i,s.prototype),i},h.apply(null,arguments)}function g(e){var t="function"==typeof Map?new Map:void 0;return g=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,s)}function s(){return h(e,arguments,r(this).constructor)}return s.prototype=Object.create(e.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),a(s,e)},g(e)}var c=function(){function e(){}return e.get=function(e,t){return 0!=(e&1<<t)},e.set=function(e,s,r){return t.u8(r?e|1<<s:e&~(1<<s))},e.countOnes=function(e){for(var t=0;e;)t+=1&e,e>>=1;return t},e}(),n=function(){function e(){}return e.getCycles=function(t){return e.OP_CYCLES_TABLE[t]},e.toString=function(t){return e.ASM_TABLE[t]},e}();n.OP_CYCLES_TABLE=[4,10,7,5,5,5,7,4,4,10,7,5,5,5,7,4,4,10,7,5,5,5,7,4,4,10,7,5,5,5,7,4,4,10,16,5,5,5,7,4,4,10,16,5,5,5,7,4,4,10,13,5,10,10,10,4,4,10,13,5,5,5,7,4,5,5,5,5,5,5,7,5,5,5,5,5,5,5,7,5,5,5,5,5,5,5,7,5,5,5,5,5,5,5,7,5,5,5,5,5,5,5,7,5,5,5,5,5,5,5,7,5,7,7,7,7,7,7,7,7,5,5,5,5,5,5,7,5,4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,5,10,10,10,11,11,7,11,5,10,10,10,11,17,7,11,5,10,10,10,11,11,7,11,5,10,10,10,11,17,7,11,5,10,10,18,11,11,7,11,5,5,10,5,11,17,7,11,5,10,10,4,11,11,7,11,5,5,10,4,11,17,7,11],n.ASM_TABLE={0:"NOP",1:"LXI BC",2:"STAX BC",3:"INX BC",4:"INR B",5:"DCR B",6:"MVI B",7:"RLC",8:"NOP",9:"DAD BC",10:"LDAX BC",11:"DCX BC",12:"INR C",13:"DCR C",14:"MVI C",15:"RRC",16:"NOP",17:"LXI DE",18:"STAX DE",19:"INX DE",20:"INR D",21:"DCR D",22:"MVI D",23:"RAL",24:"NOP",25:"DAD DE",26:"LDAX DE",27:"DCX DE",28:"INR E",29:"DCR E",30:"MVI E",31:"RAR",32:"NOP",33:"LXI HL",34:"SHLD",35:"INX HL",36:"INR H",37:"DCR H",38:"MVI H",39:"DAA",40:"NOP",41:"DAD HL",42:"LHLD",43:"DCX HL",44:"INR L",45:"DCR L",46:"MVI L",47:"CMA",48:"NOP",49:"LXI SP",50:"STA",51:"INX SP",52:"INR M",53:"DCR M",54:"MVI M",55:"STC",56:"NOP",57:"DAD SP",58:"LDA",59:"DCX SP",60:"INR A",61:"DCR A",62:"MVI A",63:"CMC",64:"MOV (B, B)",65:"MOV (B, C)",66:"MOV (B, D)",67:"MOV (B, E)",68:"MOV (B, H)",69:"MOV (B, L)",70:"MOV (B, M)",71:"MOV (B, A)",72:"MOV (C, B)",73:"MOV (C, C)",74:"MOV (C, D)",75:"MOV (C, E)",76:"MOV (C, H)",77:"MOV (C, L)",78:"MOV (C, M)",79:"MOV (C, A)",80:"MOV (D, B)",81:"MOV (D, C)",82:"MOV (D, D)",83:"MOV (D, E)",84:"MOV (D, H)",85:"MOV (D, L)",86:"MOV (D, M)",87:"MOV (D, A)",88:"MOV (E, B)",89:"MOV (E, C)",90:"MOV (E, D)",91:"MOV (E, E)",92:"MOV (E, H)",93:"MOV (E, L)",94:"MOV (E, M)",95:"MOV (E, A)",96:"MOV (H, B)",97:"MOV (H, C)",98:"MOV (H, D)",99:"MOV (H, E)",100:"MOV (H, H)",101:"MOV (H, L)",102:"MOV (H, M)",103:"MOV (H, A)",104:"MOV (L, B)",105:"MOV (L, C)",106:"MOV (L, D)",107:"MOV (L, E)",108:"MOV (L, H)",109:"MOV (L, L)",110:"MOV (L, M)",111:"MOV (L, A)",112:"MOV (M, B)",113:"MOV (M, C)",114:"MOV (M, D)",115:"MOV (M, E)",116:"MOV (M, H)",117:"MOV (M, L)",118:"HLT",119:"MOV (M, A)",120:"MOV (A, B)",121:"MOV (A, C)",122:"MOV (A, D)",123:"MOV (A, E)",124:"MOV (A, H)",125:"MOV (A, L)",126:"MOV (A, M)",127:"MOV (A, A)",128:"ADD B",129:"ADD C",130:"ADD D",131:"ADD E",132:"ADD H",133:"ADD L",134:"ADD M",135:"ADD A",136:"ADC B",137:"ADC C",138:"ADC D",139:"ADC E",140:"ADC H",141:"ADC L",142:"ADC M",143:"ADC A",144:"SUB B",145:"SUB C",146:"SUB D",147:"SUB E",148:"SUB H",149:"SUB L",150:"SUB M",151:"SUB A",152:"SBB B",153:"SBB C",154:"SBB D",155:"SBB E",156:"SBB H",157:"SBB L",158:"SBB M",159:"SBB A",160:"ANA B",161:"ANA C",162:"ANA D",163:"ANA E",164:"ANA H",165:"ANA L",166:"ANA M",167:"ANA A",168:"XRA B",169:"XRA C",170:"XRA D",171:"XRA E",172:"XRA H",173:"XRA L",174:"XRA M",175:"XRA A",176:"ORA B",177:"ORA C",178:"ORA D",179:"ORA E",180:"ORA H",181:"ORA L",182:"ORA M",183:"ORA A",184:"CMP B",185:"CMP C",186:"CMP D",187:"CMP E",188:"CMP H",189:"CMP L",190:"CMP M",191:"CMP A",192:"RNZ",193:"POP BC",194:"JNZ",195:"JMP",196:"CNZ",197:"PUSH B",198:"ADI",199:"RST 0",200:"RZ",201:"RET",202:"JZ",203:"JMP",204:"CZ",205:"CALL",206:"ACI",207:"RST 1",208:"RNC",209:"POP DE",210:"JNC",211:"OUT",212:"CNC",213:"PUSH D",214:"SUI",215:"RST 2",216:"RC",217:"RET",218:"JC",219:"IN",220:"CC",221:"CALL",222:"SBI",223:"RST 3",224:"RPO",225:"POP HL",226:"JPO",227:"XTHL",228:"CPO",229:"PUSH H",230:"ANI",231:"RST 4",232:"RPE",233:"PCHL",234:"JPE",235:"XCHG",236:"CPE",237:"CALL",238:"XRI",239:"RST 5",240:"RP",241:"POP PSW",242:"JP",243:"DI",244:"CP",245:"PUSH PSW",246:"ORI",247:"RST 6",248:"RM",249:"SPHL",250:"JM",251:"EI",252:"CM",253:"CALL",254:"CPI",255:"RST 7"};var b,o=function(){function e(){}return e.toHexStr=function(e,t){void 0===t&&(t=2);var s=e.toString(16).toUpperCase();return s.startsWith("-")?"-"+s.substr(1).padStart(t,"0"):s.padStart(t,"0")},e.printOperation=function(t,s){console.log("["+e.toHexStr(s.reg.pc-1,4)+"] "+n.toString(t).padEnd(15," ")+"(SP="+e.toHexStr(s.reg.sp,4)+" A="+e.toHexStr(s.reg.a)+" F="+e.toHexStr(s.reg.f)+" B="+e.toHexStr(s.reg.b)+" C="+e.toHexStr(s.reg.c)+" D="+e.toHexStr(s.reg.d)+" E="+e.toHexStr(s.reg.e)+" H="+e.toHexStr(s.reg.h)+" L="+e.toHexStr(s.reg.l)+" FLAGS="+(s.reg.getFlagS()?"S":".")+(s.reg.getFlagZ()?"Z":".")+(s.reg.getFlagA()?"A":".")+(s.reg.getFlagP()?"P":".")+(s.reg.getFlagC()?"C":".")+")")},e}();e.Flag=void 0,(b=e.Flag||(e.Flag={}))[b.S=7]="S",b[b.Z=6]="Z",b[b.A=4]="A",b[b.P=2]="P",b[b.C=0]="C";var u,k,l,d,C=function(){function s(){this.a=0,this.f=2,this.b=0,this.c=0,this.d=0,this.e=0,this.h=0,this.l=0,this.sp=0,this.pc=0}var r=s.prototype;return r.getAF=function(){return t.u16(this.a<<8|this.f)},r.getBC=function(){return t.u16(this.b<<8|this.c)},r.getDE=function(){return t.u16(this.d<<8|this.e)},r.getHL=function(){return t.u16(this.h<<8|this.l)},r.setAF=function(e){this.a=t.u8(e>>8),this.f=t.u8(213&e|2)},r.setBC=function(e){this.b=t.u8(e>>8),this.c=t.u8(255&e)},r.setDE=function(e){this.d=t.u8(e>>8),this.e=t.u8(255&e)},r.setHL=function(e){this.h=t.u8(e>>8),this.l=t.u8(255&e)},r.setFlag=function(e,t){this.f=c.set(this.f,e,t)},r.getFlag=function(e){return c.get(this.f,e)},r.setFlagS=function(t){this.setFlag(e.Flag.S,c.get(t,7))},r.setFlagZ=function(t){this.setFlag(e.Flag.Z,0==t)},r.setFlagA=function(t){this.setFlag(e.Flag.A,t)},r.setFlagP=function(t){this.setFlag(e.Flag.P,0==(1&c.countOnes(t)))},r.setFlagC=function(t){this.setFlag(e.Flag.C,t)},r.getFlagS=function(){return this.getFlag(e.Flag.S)},r.getFlagZ=function(){return this.getFlag(e.Flag.Z)},r.getFlagA=function(){return this.getFlag(e.Flag.A)},r.getFlagP=function(){return this.getFlag(e.Flag.P)},r.getFlagC=function(){return this.getFlag(e.Flag.C)},s}();e.Cpu=function(){function e(e,t,s){void 0===s&&(s=!1),this.reg=new C,this.mem=void 0,this.halted=!1,this.interruptEnabled=!1,this.debugEnabled=!1,this.device=void 0,this.stepCycles=0,this.stepZero=Date.now(),this.mem=e,this.device=t,this.debugEnabled=s}var s=e.prototype;return s.next=function(){if(this.halted)return 0;var s=this.getNextByte();this.debugEnabled&&o.printOperation(s,this);var r=0;switch(s){case 0:case 8:case 16:case 24:case 32:case 40:case 48:case 56:case 64:case 73:case 82:case 91:case 100:case 109:case 127:break;case 63:this.reg.setFlagC(!this.reg.getFlagC());break;case 55:this.reg.setFlagC(!0);break;case 4:this.reg.b=this.inr(this.reg.b);break;case 12:this.reg.c=this.inr(this.reg.c);break;case 20:this.reg.d=this.inr(this.reg.d);break;case 28:this.reg.e=this.inr(this.reg.e);break;case 36:this.reg.h=this.inr(this.reg.h);break;case 44:this.reg.l=this.inr(this.reg.l);break;case 52:var a=this.getM(),i=this.inr(a);this.setM(i);break;case 60:this.reg.a=this.inr(this.reg.a);break;case 5:this.reg.b=this.dcr(this.reg.b);break;case 13:this.reg.c=this.dcr(this.reg.c);break;case 21:this.reg.d=this.dcr(this.reg.d);break;case 29:this.reg.e=this.dcr(this.reg.e);break;case 37:this.reg.h=this.dcr(this.reg.h);break;case 45:this.reg.l=this.dcr(this.reg.l);break;case 53:var h=this.getM(),g=this.dcr(h);this.setM(g);break;case 61:this.reg.a=this.dcr(this.reg.a);break;case 47:this.reg.a=t.u8(~this.reg.a);break;case 39:this.daa();break;case 65:this.reg.b=this.reg.c;break;case 66:this.reg.b=this.reg.d;break;case 67:this.reg.b=this.reg.e;break;case 68:this.reg.b=this.reg.h;break;case 69:this.reg.b=this.reg.l;break;case 70:this.reg.b=this.getM();break;case 71:this.reg.b=this.reg.a;break;case 72:this.reg.c=this.reg.b;break;case 74:this.reg.c=this.reg.d;break;case 75:this.reg.c=this.reg.e;break;case 76:this.reg.c=this.reg.h;break;case 77:this.reg.c=this.reg.l;break;case 78:this.reg.c=this.getM();break;case 79:this.reg.c=this.reg.a;break;case 80:this.reg.d=this.reg.b;break;case 81:this.reg.d=this.reg.c;break;case 83:this.reg.d=this.reg.e;break;case 84:this.reg.d=this.reg.h;break;case 85:this.reg.d=this.reg.l;break;case 86:this.reg.d=this.getM();break;case 87:this.reg.d=this.reg.a;break;case 88:this.reg.e=this.reg.b;break;case 89:this.reg.e=this.reg.c;break;case 90:this.reg.e=this.reg.d;break;case 92:this.reg.e=this.reg.h;break;case 93:this.reg.e=this.reg.l;break;case 94:this.reg.e=this.getM();break;case 95:this.reg.e=this.reg.a;break;case 96:this.reg.h=this.reg.b;break;case 97:this.reg.h=this.reg.c;break;case 98:this.reg.h=this.reg.d;break;case 99:this.reg.h=this.reg.e;break;case 101:this.reg.h=this.reg.l;break;case 102:this.reg.h=this.getM();break;case 103:this.reg.h=this.reg.a;break;case 104:this.reg.l=this.reg.b;break;case 105:this.reg.l=this.reg.c;break;case 106:this.reg.l=this.reg.d;break;case 107:this.reg.l=this.reg.e;break;case 108:this.reg.l=this.reg.h;break;case 110:this.reg.l=this.getM();break;case 111:this.reg.l=this.reg.a;break;case 112:this.setM(this.reg.b);break;case 113:this.setM(this.reg.c);break;case 114:this.setM(this.reg.d);break;case 115:this.setM(this.reg.e);break;case 116:this.setM(this.reg.h);break;case 117:this.setM(this.reg.l);break;case 119:this.setM(this.reg.a);break;case 120:this.reg.a=this.reg.b;break;case 121:this.reg.a=this.reg.c;break;case 122:this.reg.a=this.reg.d;break;case 123:this.reg.a=this.reg.e;break;case 124:this.reg.a=this.reg.h;break;case 125:this.reg.a=this.reg.l;break;case 126:this.reg.a=this.getM();break;case 2:this.mem.set(this.reg.getBC(),this.reg.a);break;case 18:this.mem.set(this.reg.getDE(),this.reg.a);break;case 10:this.reg.a=this.mem.get(this.reg.getBC());break;case 26:this.reg.a=this.mem.get(this.reg.getDE());break;case 128:this.add(this.reg.b);break;case 129:this.add(this.reg.c);break;case 130:this.add(this.reg.d);break;case 131:this.add(this.reg.e);break;case 132:this.add(this.reg.h);break;case 133:this.add(this.reg.l);break;case 134:this.add(this.getM());break;case 135:this.add(this.reg.a);break;case 136:this.adc(this.reg.b);break;case 137:this.adc(this.reg.c);break;case 138:this.adc(this.reg.d);break;case 139:this.adc(this.reg.e);break;case 140:this.adc(this.reg.h);break;case 141:this.adc(this.reg.l);break;case 142:this.adc(this.getM());break;case 143:this.adc(this.reg.a);break;case 144:this.sub(this.reg.b);break;case 145:this.sub(this.reg.c);break;case 146:this.sub(this.reg.d);break;case 147:this.sub(this.reg.e);break;case 148:this.sub(this.reg.h);break;case 149:this.sub(this.reg.l);break;case 150:this.sub(this.getM());break;case 151:this.sub(this.reg.a);break;case 152:this.sbb(this.reg.b);break;case 153:this.sbb(this.reg.c);break;case 154:this.sbb(this.reg.d);break;case 155:this.sbb(this.reg.e);break;case 156:this.sbb(this.reg.h);break;case 157:this.sbb(this.reg.l);break;case 158:this.sbb(this.getM());break;case 159:this.sbb(this.reg.a);break;case 160:this.ana(this.reg.b);break;case 161:this.ana(this.reg.c);break;case 162:this.ana(this.reg.d);break;case 163:this.ana(this.reg.e);break;case 164:this.ana(this.reg.h);break;case 165:this.ana(this.reg.l);break;case 166:this.ana(this.getM());break;case 167:this.ana(this.reg.a);break;case 168:this.xra(this.reg.b);break;case 169:this.xra(this.reg.c);break;case 170:this.xra(this.reg.d);break;case 171:this.xra(this.reg.e);break;case 172:this.xra(this.reg.h);break;case 173:this.xra(this.reg.l);break;case 174:this.xra(this.getM());break;case 175:this.xra(this.reg.a);break;case 176:this.ora(this.reg.b);break;case 177:this.ora(this.reg.c);break;case 178:this.ora(this.reg.d);break;case 179:this.ora(this.reg.e);break;case 180:this.ora(this.reg.h);break;case 181:this.ora(this.reg.l);break;case 182:this.ora(this.getM());break;case 183:this.ora(this.reg.a);break;case 184:this.cmp(this.reg.b);break;case 185:this.cmp(this.reg.c);break;case 186:this.cmp(this.reg.d);break;case 187:this.cmp(this.reg.e);break;case 188:this.cmp(this.reg.h);break;case 189:this.cmp(this.reg.l);break;case 190:this.cmp(this.getM());break;case 191:this.cmp(this.reg.a);break;case 7:this.rlc();break;case 15:this.rrc();break;case 23:this.ral();break;case 31:this.rar();break;case 197:this.stackAdd(this.reg.getBC());break;case 213:this.stackAdd(this.reg.getDE());break;case 229:this.stackAdd(this.reg.getHL());break;case 245:this.stackAdd(this.reg.getAF());break;case 193:this.reg.setBC(this.stackPop());break;case 209:this.reg.setDE(this.stackPop());break;case 225:this.reg.setHL(this.stackPop());break;case 241:this.reg.setAF(this.stackPop());break;case 9:this.dad(this.reg.getBC());break;case 25:this.dad(this.reg.getDE());break;case 41:this.dad(this.reg.getHL());break;case 57:this.dad(this.reg.sp);break;case 3:this.reg.setBC(t.u16(this.reg.getBC()+1));break;case 19:this.reg.setDE(t.u16(this.reg.getDE()+1));break;case 35:this.reg.setHL(t.u16(this.reg.getHL()+1));break;case 51:this.reg.sp=t.u16(this.reg.sp+1);break;case 11:this.reg.setBC(t.u16(this.reg.getBC()-1));break;case 27:this.reg.setDE(t.u16(this.reg.getDE()-1));break;case 43:this.reg.setHL(t.u16(this.reg.getHL()-1));break;case 59:this.reg.sp=t.u16(this.reg.sp-1);break;case 235:var c=this.reg.h;this.reg.h=this.reg.d,this.reg.d=c;var b=this.reg.l;this.reg.l=this.reg.e,this.reg.e=b;break;case 227:var u=this.mem.getWord(this.reg.sp),k=this.reg.getHL();this.reg.setHL(u),this.mem.setWord(this.reg.sp,k);break;case 249:this.reg.sp=this.reg.getHL();break;case 1:this.reg.setBC(this.getNextWord());break;case 17:this.reg.setDE(this.getNextWord());break;case 33:this.reg.setHL(this.getNextWord());break;case 49:this.reg.sp=this.getNextWord();break;case 6:this.reg.b=this.getNextByte();break;case 14:this.reg.c=this.getNextByte();break;case 22:this.reg.d=this.getNextByte();break;case 30:this.reg.e=this.getNextByte();break;case 38:this.reg.h=this.getNextByte();break;case 46:this.reg.l=this.getNextByte();break;case 54:this.setM(this.getNextByte());break;case 62:this.reg.a=this.getNextByte();break;case 198:this.add(this.getNextByte());break;case 206:this.adc(this.getNextByte());break;case 214:this.sub(this.getNextByte());break;case 222:this.sbb(this.getNextByte());break;case 230:this.ana(this.getNextByte());break;case 238:this.xra(this.getNextByte());break;case 246:this.ora(this.getNextByte());break;case 254:this.cmp(this.getNextByte());break;case 50:this.mem.set(this.getNextWord(),this.reg.a);break;case 58:this.reg.a=this.mem.get(this.getNextWord());break;case 34:this.mem.setWord(this.getNextWord(),this.reg.getHL());break;case 42:this.reg.setHL(this.mem.getWord(this.getNextWord()));break;case 233:this.reg.pc=this.reg.getHL();break;case 195:case 218:case 210:case 202:case 194:case 250:case 242:case 234:case 226:var l=this.getNextWord();this.checkBranchCondition(s)&&(this.reg.pc=l);break;case 205:case 220:case 212:case 204:case 196:case 236:case 228:case 252:case 244:var d=this.getNextWord();this.checkBranchCondition(s)&&(r=6,this.stackAdd(this.reg.pc),this.reg.pc=d);break;case 201:case 216:case 208:case 200:case 192:case 248:case 240:case 232:case 224:this.checkBranchCondition(s)&&(r=6,this.reg.pc=this.stackPop());break;case 199:case 207:case 215:case 223:case 231:case 239:case 247:case 255:this.stackAdd(this.reg.pc),this.reg.pc=t.u16(56&s);break;case 251:this.interruptEnabled=!0;break;case 243:this.interruptEnabled=!1;break;case 219:this.reg.a=this.device.input(this.getNextByte());break;case 211:this.device.output(this.getNextByte(),this.reg.a);break;case 118:this.halted=!0;break;default:throw new e.UnimplementedInstructionError(s)}return n.getCycles(s)+r},s.step=function(){try{var t=this,s=function(){var e=t.next();return t.stepCycles+=e,e},r=function(){if(t.stepCycles>e.STEP_CYCLES){t.stepCycles-=e.STEP_CYCLES;var s=Date.now()-t.stepZero,r=e.STEP_TIME-s;return Promise.resolve(new Promise(function(e){return setTimeout(e,r)})).then(function(){t.stepZero=t.stepZero+e.STEP_TIME})}}();return Promise.resolve(r&&r.then?r.then(s):s())}catch(e){return Promise.reject(e)}},s.handleInterrupt=function(e){this.interruptEnabled&&(this.interruptEnabled=!1,this.stackAdd(this.reg.pc),this.reg.pc=e,this.stepCycles+=n.getCycles(205))},s.getNextByte=function(){var e=this.mem.get(this.reg.pc);return this.reg.pc=t.u16(this.reg.pc+1),e},s.getNextWord=function(){var e=this.mem.getWord(this.reg.pc);return this.reg.pc=t.u16(this.reg.pc+2),e},s.getM=function(){var e=this.reg.getHL();return this.mem.get(e)},s.setM=function(e){var t=this.reg.getHL();this.mem.set(t,e)},s.stackAdd=function(e){this.reg.sp=t.u16(this.reg.sp-2),this.mem.setWord(this.reg.sp,e)},s.stackPop=function(){var e=this.mem.getWord(this.reg.sp);return this.reg.sp=t.u16(this.reg.sp+2),e},s.checkBranchCondition=function(t){switch(t){case 195:case 205:case 201:return!0;case 218:case 220:case 216:return this.reg.getFlagC();case 210:case 212:case 208:return!this.reg.getFlagC();case 202:case 204:case 200:return this.reg.getFlagZ();case 194:case 196:case 192:return!this.reg.getFlagZ();case 250:case 252:case 248:return this.reg.getFlagS();case 242:case 244:case 240:return!this.reg.getFlagS();case 234:case 236:case 232:return this.reg.getFlagP();case 226:case 228:case 224:return!this.reg.getFlagP();default:throw new e.UnimplementedInstructionError(t)}},s.inr=function(e){var s=t.u8(e+1);return this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(1+(15&e)>15),s},s.dcr=function(e){var s=t.u8(e-1);return this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(15!=(15&s)),s},s.daa=function(){var e=0,s=this.reg.getFlagC(),r=15&this.reg.a,a=this.reg.a>>4&15;(r>9||this.reg.getFlagA())&&(e=t.u8(e+6)),(a>9||this.reg.getFlagC()||a>=9&&r>9)&&(e=t.u8(e+96),s=!0),this.add(e),this.reg.setFlagC(s)},s.add=function(e){var s=this.reg.a,r=t.u8(s+e);this.reg.setFlagS(r),this.reg.setFlagZ(r),this.reg.setFlagP(r),this.reg.setFlagA((15&s)+(15&e)>15),this.reg.setFlagC(s+e>255),this.reg.a=r},s.adc=function(e){var s=+this.reg.getFlagC(),r=this.reg.a,a=t.u8(r+e+s);this.reg.setFlagS(a),this.reg.setFlagZ(a),this.reg.setFlagP(a),this.reg.setFlagA((15&r)+(15&e)+s>15),this.reg.setFlagC(r+e+s>255),this.reg.a=a},s.sub=function(e){var s=this.reg.a,r=t.u8(s-e);this.reg.setFlagS(r),this.reg.setFlagZ(r),this.reg.setFlagP(r),this.reg.setFlagA((15&s)-(15&e)>=0),this.reg.setFlagC(s<e),this.reg.a=r},s.sbb=function(e){var s=+this.reg.getFlagC(),r=this.reg.a,a=t.u8(r-e-s);this.reg.setFlagS(a),this.reg.setFlagZ(a),this.reg.setFlagP(a),this.reg.setFlagA((15&r)-(15&e)-s>=0),this.reg.setFlagC(r<e+s),this.reg.a=a},s.ana=function(e){var s=t.u8(this.reg.a&e);this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(0!=(8&(this.reg.a|e))),this.reg.setFlagC(!1),this.reg.a=s},s.xra=function(e){var s=t.u8(this.reg.a^e);this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(!1),this.reg.setFlagC(!1),this.reg.a=s},s.ora=function(e){var s=t.u8(this.reg.a|e);this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(!1),this.reg.setFlagC(!1),this.reg.a=s},s.cmp=function(e){var t=this.reg.a;this.sub(e),this.reg.a=t},s.rlc=function(){var e=c.get(this.reg.a,7),s=t.u8(this.reg.a<<1|+e);this.reg.setFlagC(e),this.reg.a=s},s.rrc=function(){var e=c.get(this.reg.a,0),s=t.u8(e?128|this.reg.a>>1:this.reg.a>>1);this.reg.setFlagC(e),this.reg.a=s},s.ral=function(){var e=c.get(this.reg.a,7),s=t.u8(this.reg.a<<1|+this.reg.getFlagC());this.reg.setFlagC(e),this.reg.a=s},s.rar=function(){var e=c.get(this.reg.a,0),s=this.reg.getFlagC()?t.u8(128|this.reg.a>>1):t.u8(this.reg.a>>1);this.reg.setFlagC(e),this.reg.a=s},s.dad=function(e){var s=this.reg.getHL(),r=t.u16(s+e);this.reg.setFlagC(s>65535-e),this.reg.setHL(r)},e}(),e.Cpu.CLOCK_FREQUENCY=2e6,e.Cpu.STEP_TIME=16,e.Cpu.STEP_CYCLES=e.Cpu.STEP_TIME/(1e3/e.Cpu.CLOCK_FREQUENCY),u=e.Cpu||(e.Cpu={}),k=function(e){function t(t){var s;return(s=e.call(this,"Unimplemented instruction: "+n.toString(t)+" (0x"+o.toHexStr(t)+")")||this).opcode=void 0,s.opcode=t,s}return s(t,e),t}(g(Error)),u.UnimplementedInstructionError=k,e.Memory=function(){function e(){this.data=new ArrayBuffer(e.MEMORY_SIZE),this.view=new DataView(this.data)}var s=e.prototype;return s.load=function(s,r){void 0===r&&(r=0);for(var a=0;a<s.length;a++){if(r+a>=e.MEMORY_SIZE)throw new e.NotEnoughMemoryError;this.set(t.u16(r+a),t.u8(s[a]))}},s.get=function(e){return this.view.getUint8(e)},s.set=function(e,t){this.view.setUint8(e,t)},s.getWord=function(e){return this.view.getUint16(e,!0)},s.setWord=function(e,t){this.view.setUint16(e,t,!0)},e}(),e.Memory.MEMORY_SIZE=65536,l=e.Memory||(e.Memory={}),d=function(e){function t(){return e.call(this,"Not enough memory for this operation!")||this}return s(t,e),t}(g(Error)),l.NotEnoughMemoryError=d,e.Bit=c,e.Debug=o,e.Opcode=n,e.Register=C});
//# sourceMappingURL=eighty-eighty.umd.js.map