UNPKG

eighty-eighty-js

Version:

A nice little Intel 8080 emulator for Node.js and Browser!

3 lines (2 loc) 22 kB
import{u8 as e,u16 as t}from"typed-numbers";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 t(){}return t.get=function(e,t){return 0!=(e&1<<t)},t.set=function(t,s,r){return e(r?t|1<<s:t&~(1<<s))},t.countOnes=function(e){for(var t=0;e;)t+=1&e,e>>=1;return t},t}(),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}();!function(e){e[e.S=7]="S",e[e.Z=6]="Z",e[e.A=4]="A",e[e.P=2]="P",e[e.C=0]="C"}(b||(b={}));var k=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(this.a<<8|this.f)},r.getBC=function(){return t(this.b<<8|this.c)},r.getDE=function(){return t(this.d<<8|this.e)},r.getHL=function(){return t(this.h<<8|this.l)},r.setAF=function(t){this.a=e(t>>8),this.f=e(213&t|2)},r.setBC=function(t){this.b=e(t>>8),this.c=e(255&t)},r.setDE=function(t){this.d=e(t>>8),this.e=e(255&t)},r.setHL=function(t){this.h=e(t>>8),this.l=e(255&t)},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(e){this.setFlag(b.S,c.get(e,7))},r.setFlagZ=function(e){this.setFlag(b.Z,0==e)},r.setFlagA=function(e){this.setFlag(b.A,e)},r.setFlagP=function(e){this.setFlag(b.P,0==(1&c.countOnes(e)))},r.setFlagC=function(e){this.setFlag(b.C,e)},r.getFlagS=function(){return this.getFlag(b.S)},r.getFlagZ=function(){return this.getFlag(b.Z)},r.getFlagA=function(){return this.getFlag(b.A)},r.getFlagP=function(){return this.getFlag(b.P)},r.getFlagC=function(){return this.getFlag(b.C)},s}(),u=function(){function s(e,t,s){void 0===s&&(s=!1),this.reg=new k,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 r=s.prototype;return r.next=function(){if(this.halted)return 0;var r=this.getNextByte();this.debugEnabled&&o.printOperation(r,this);var a=0;switch(r){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 i=this.getM(),h=this.inr(i);this.setM(h);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 g=this.getM(),c=this.dcr(g);this.setM(c);break;case 61:this.reg.a=this.dcr(this.reg.a);break;case 47:this.reg.a=e(~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(this.reg.getBC()+1));break;case 19:this.reg.setDE(t(this.reg.getDE()+1));break;case 35:this.reg.setHL(t(this.reg.getHL()+1));break;case 51:this.reg.sp=t(this.reg.sp+1);break;case 11:this.reg.setBC(t(this.reg.getBC()-1));break;case 27:this.reg.setDE(t(this.reg.getDE()-1));break;case 43:this.reg.setHL(t(this.reg.getHL()-1));break;case 59:this.reg.sp=t(this.reg.sp-1);break;case 235:var b=this.reg.h;this.reg.h=this.reg.d,this.reg.d=b;var k=this.reg.l;this.reg.l=this.reg.e,this.reg.e=k;break;case 227:var u=this.mem.getWord(this.reg.sp),l=this.reg.getHL();this.reg.setHL(u),this.mem.setWord(this.reg.sp,l);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 d=this.getNextWord();this.checkBranchCondition(r)&&(this.reg.pc=d);break;case 205:case 220:case 212:case 204:case 196:case 236:case 228:case 252:case 244:var C=this.getNextWord();this.checkBranchCondition(r)&&(a=6,this.stackAdd(this.reg.pc),this.reg.pc=C);break;case 201:case 216:case 208:case 200:case 192:case 248:case 240:case 232:case 224:this.checkBranchCondition(r)&&(a=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(56&r);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 s.UnimplementedInstructionError(r)}return n.getCycles(r)+a},r.step=function(){try{var e=this,t=function(){var t=e.next();return e.stepCycles+=t,t},r=function(){if(e.stepCycles>s.STEP_CYCLES){e.stepCycles-=s.STEP_CYCLES;var t=Date.now()-e.stepZero,r=s.STEP_TIME-t;return Promise.resolve(new Promise(function(e){return setTimeout(e,r)})).then(function(){e.stepZero=e.stepZero+s.STEP_TIME})}}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},r.handleInterrupt=function(e){this.interruptEnabled&&(this.interruptEnabled=!1,this.stackAdd(this.reg.pc),this.reg.pc=e,this.stepCycles+=n.getCycles(205))},r.getNextByte=function(){var e=this.mem.get(this.reg.pc);return this.reg.pc=t(this.reg.pc+1),e},r.getNextWord=function(){var e=this.mem.getWord(this.reg.pc);return this.reg.pc=t(this.reg.pc+2),e},r.getM=function(){var e=this.reg.getHL();return this.mem.get(e)},r.setM=function(e){var t=this.reg.getHL();this.mem.set(t,e)},r.stackAdd=function(e){this.reg.sp=t(this.reg.sp-2),this.mem.setWord(this.reg.sp,e)},r.stackPop=function(){var e=this.mem.getWord(this.reg.sp);return this.reg.sp=t(this.reg.sp+2),e},r.checkBranchCondition=function(e){switch(e){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 s.UnimplementedInstructionError(e)}},r.inr=function(t){var s=e(t+1);return this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(1+(15&t)>15),s},r.dcr=function(t){var s=e(t-1);return this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(15!=(15&s)),s},r.daa=function(){var t=0,s=this.reg.getFlagC(),r=15&this.reg.a,a=this.reg.a>>4&15;(r>9||this.reg.getFlagA())&&(t=e(t+6)),(a>9||this.reg.getFlagC()||a>=9&&r>9)&&(t=e(t+96),s=!0),this.add(t),this.reg.setFlagC(s)},r.add=function(t){var s=this.reg.a,r=e(s+t);this.reg.setFlagS(r),this.reg.setFlagZ(r),this.reg.setFlagP(r),this.reg.setFlagA((15&s)+(15&t)>15),this.reg.setFlagC(s+t>255),this.reg.a=r},r.adc=function(t){var s=+this.reg.getFlagC(),r=this.reg.a,a=e(r+t+s);this.reg.setFlagS(a),this.reg.setFlagZ(a),this.reg.setFlagP(a),this.reg.setFlagA((15&r)+(15&t)+s>15),this.reg.setFlagC(r+t+s>255),this.reg.a=a},r.sub=function(t){var s=this.reg.a,r=e(s-t);this.reg.setFlagS(r),this.reg.setFlagZ(r),this.reg.setFlagP(r),this.reg.setFlagA((15&s)-(15&t)>=0),this.reg.setFlagC(s<t),this.reg.a=r},r.sbb=function(t){var s=+this.reg.getFlagC(),r=this.reg.a,a=e(r-t-s);this.reg.setFlagS(a),this.reg.setFlagZ(a),this.reg.setFlagP(a),this.reg.setFlagA((15&r)-(15&t)-s>=0),this.reg.setFlagC(r<t+s),this.reg.a=a},r.ana=function(t){var s=e(this.reg.a&t);this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(0!=(8&(this.reg.a|t))),this.reg.setFlagC(!1),this.reg.a=s},r.xra=function(t){var s=e(this.reg.a^t);this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(!1),this.reg.setFlagC(!1),this.reg.a=s},r.ora=function(t){var s=e(this.reg.a|t);this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(!1),this.reg.setFlagC(!1),this.reg.a=s},r.cmp=function(e){var t=this.reg.a;this.sub(e),this.reg.a=t},r.rlc=function(){var t=c.get(this.reg.a,7),s=e(this.reg.a<<1|+t);this.reg.setFlagC(t),this.reg.a=s},r.rrc=function(){var t=c.get(this.reg.a,0),s=e(t?128|this.reg.a>>1:this.reg.a>>1);this.reg.setFlagC(t),this.reg.a=s},r.ral=function(){var t=c.get(this.reg.a,7),s=e(this.reg.a<<1|+this.reg.getFlagC());this.reg.setFlagC(t),this.reg.a=s},r.rar=function(){var t=c.get(this.reg.a,0),s=this.reg.getFlagC()?e(128|this.reg.a>>1):e(this.reg.a>>1);this.reg.setFlagC(t),this.reg.a=s},r.dad=function(e){var s=this.reg.getHL(),r=t(s+e);this.reg.setFlagC(s>65535-e),this.reg.setHL(r)},s}();u.CLOCK_FREQUENCY=2e6,u.STEP_TIME=16,u.STEP_CYCLES=u.STEP_TIME/(1e3/u.CLOCK_FREQUENCY),function(e){var t=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));e.UnimplementedInstructionError=t}(u||(u={}));var l=function(){function s(){this.data=new ArrayBuffer(s.MEMORY_SIZE),this.view=new DataView(this.data)}var r=s.prototype;return r.load=function(r,a){void 0===a&&(a=0);for(var i=0;i<r.length;i++){if(a+i>=s.MEMORY_SIZE)throw new s.NotEnoughMemoryError;this.set(t(a+i),e(r[i]))}},r.get=function(e){return this.view.getUint8(e)},r.set=function(e,t){this.view.setUint8(e,t)},r.getWord=function(e){return this.view.getUint16(e,!0)},r.setWord=function(e,t){this.view.setUint16(e,t,!0)},s}();l.MEMORY_SIZE=65536,function(e){var t=function(e){function t(){return e.call(this,"Not enough memory for this operation!")||this}return s(t,e),t}(g(Error));e.NotEnoughMemoryError=t}(l||(l={}));export{c as Bit,u as Cpu,o as Debug,b as Flag,l as Memory,n as Opcode,k as Register}; //# sourceMappingURL=eighty-eighty.module.js.map