New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eighty-eighty-js

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eighty-eighty-js - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

4

dist/core/Memory.d.ts

@@ -15,5 +15,5 @@ import { u16, u8 } from 'typed-numbers';

* @param buffer - The buffer to load into memory. Can be of any array-like type.
* @param offset - The offset from where to start writing the buffer into memory.
* @param [offset = 0] - The offset from where to start writing the buffer into memory.
*/
load(buffer: ArrayLike<number>, offset: number): void;
load(buffer: ArrayLike<number>, offset?: number): void;
/**

@@ -20,0 +20,0 @@ * Read memory at `address`.

@@ -1,2 +0,2 @@

var e=require("typed-numbers");function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,r(e,t)}function s(e){return s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},s(e)}function r(e,t){return r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},r(e,t)}function a(){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 i(e,t,s){return i=a()?Reflect.construct:function(e,t,s){var a=[null];a.push.apply(a,t);var i=new(Function.bind.apply(e,a));return s&&r(i,s.prototype),i},i.apply(null,arguments)}function h(e){var t="function"==typeof Map?new Map:void 0;return h=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,a)}function a(){return i(e,arguments,s(this).constructor)}return a.prototype=Object.create(e.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),r(a,e)},h(e)}var g=function(){function t(){}return t.get=function(e,t){return 0!=(e&1<<t)},t.set=function(t,s,r){return e.u8(r?t|1<<s:t&~(1<<s))},t.countOnes=function(e){for(var t=0;e;)t+=1&e,e>>=1;return t},t}(),c=function(){function e(){}return e.getCycles=function(t){return e.OP_CYCLES_TABLE[t]},e.toString=function(t){return e.ASM_TABLE[t]},e}();c.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],c.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 n,b=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)+"] "+c.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"}(n||(n={}));var o,u,k,l,d=function(){function t(){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 s=t.prototype;return s.getAF=function(){return e.u16(this.a<<8|this.f)},s.getBC=function(){return e.u16(this.b<<8|this.c)},s.getDE=function(){return e.u16(this.d<<8|this.e)},s.getHL=function(){return e.u16(this.h<<8|this.l)},s.setAF=function(t){this.a=e.u8(t>>8),this.f=e.u8(213&t|2)},s.setBC=function(t){this.b=e.u8(t>>8),this.c=e.u8(255&t)},s.setDE=function(t){this.d=e.u8(t>>8),this.e=e.u8(255&t)},s.setHL=function(t){this.h=e.u8(t>>8),this.l=e.u8(255&t)},s.setFlag=function(e,t){this.f=g.set(this.f,e,t)},s.getFlag=function(e){return g.get(this.f,e)},s.setFlagS=function(e){this.setFlag(n.S,g.get(e,7))},s.setFlagZ=function(e){this.setFlag(n.Z,0==e)},s.setFlagA=function(e){this.setFlag(n.A,e)},s.setFlagP=function(e){this.setFlag(n.P,0==(1&g.countOnes(e)))},s.setFlagC=function(e){this.setFlag(n.C,e)},s.getFlagS=function(){return this.getFlag(n.S)},s.getFlagZ=function(){return this.getFlag(n.Z)},s.getFlagA=function(){return this.getFlag(n.A)},s.getFlagP=function(){return this.getFlag(n.P)},s.getFlagC=function(){return this.getFlag(n.C)},t}();exports.Cpu=function(){function t(e,t,s){void 0===s&&(s=!1),this.reg=new d,this.mem=void 0,this.halted=!1,this.intEnabled=!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=t.prototype;return s.next=function(){if(this.halted)return 0;var s=this.getNextByte();this.debugEnabled&&b.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=e.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(e.u16(this.reg.getBC()+1));break;case 19:this.reg.setDE(e.u16(this.reg.getDE()+1));break;case 35:this.reg.setHL(e.u16(this.reg.getHL()+1));break;case 51:this.reg.sp=e.u16(this.reg.sp+1);break;case 11:this.reg.setBC(e.u16(this.reg.getBC()-1));break;case 27:this.reg.setDE(e.u16(this.reg.getDE()-1));break;case 43:this.reg.setHL(e.u16(this.reg.getHL()-1));break;case 59:this.reg.sp=e.u16(this.reg.sp-1);break;case 235:var n=this.reg.h;this.reg.h=this.reg.d,this.reg.d=n;var o=this.reg.l;this.reg.l=this.reg.e,this.reg.e=o;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=e.u16(56&s);break;case 251:this.intEnabled=!0;break;case 243:this.intEnabled=!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 t.UnimplementedInstructionError(s)}return c.getCycles(s)+r},s.step=function(){try{var e=this,s=function(){var t=e.next();return e.stepCycles+=t,t},r=function(){if(e.stepCycles>t.STEP_CYCLES){e.stepCycles-=t.STEP_CYCLES;var s=Date.now()-e.stepZero,r=t.STEP_TIME-s;return Promise.resolve(new Promise(function(e){return setTimeout(e,r)})).then(function(){e.stepZero=e.stepZero+t.STEP_TIME})}}();return Promise.resolve(r&&r.then?r.then(s):s())}catch(e){return Promise.reject(e)}},s.handleIntEnabled=function(e){this.intEnabled&&(this.intEnabled=!1,this.stackAdd(this.reg.pc),this.reg.pc=e,this.stepCycles+=c.getCycles(205))},s.getNextByte=function(){var t=this.mem.get(this.reg.pc);return this.reg.pc=e.u16(this.reg.pc+1),t},s.getNextWord=function(){var t=this.mem.getWord(this.reg.pc);return this.reg.pc=e.u16(this.reg.pc+2),t},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(t){this.reg.sp=e.u16(this.reg.sp-2),this.mem.setWord(this.reg.sp,t)},s.stackPop=function(){var t=this.mem.getWord(this.reg.sp);return this.reg.sp=e.u16(this.reg.sp+2),t},s.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 t.UnimplementedInstructionError(e)}},s.inr=function(t){var s=e.u8(t+1);return this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(1+(15&t)>15),s},s.dcr=function(t){var s=e.u8(t-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 t=0,s=this.reg.getFlagC(),r=15&this.reg.a,a=this.reg.a>>4&15;(r>9||this.reg.getFlagA())&&(t=e.u8(t+6)),(a>9||this.reg.getFlagC()||a>=9&&r>9)&&(t=e.u8(t+96),s=!0),this.add(t),this.reg.setFlagC(s)},s.add=function(t){var s=this.reg.a,r=e.u8(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},s.adc=function(t){var s=+this.reg.getFlagC(),r=this.reg.a,a=e.u8(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},s.sub=function(t){var s=this.reg.a,r=e.u8(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},s.sbb=function(t){var s=+this.reg.getFlagC(),r=this.reg.a,a=e.u8(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},s.ana=function(t){var s=e.u8(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},s.xra=function(t){var s=e.u8(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},s.ora=function(t){var s=e.u8(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},s.cmp=function(e){var t=this.reg.a;this.sub(e),this.reg.a=t},s.rlc=function(){var t=g.get(this.reg.a,7),s=e.u8(this.reg.a<<1|+t);this.reg.setFlagC(t),this.reg.a=s},s.rrc=function(){var t=g.get(this.reg.a,0),s=e.u8(t?128|this.reg.a>>1:this.reg.a>>1);this.reg.setFlagC(t),this.reg.a=s},s.ral=function(){var t=g.get(this.reg.a,7),s=e.u8(this.reg.a<<1|+this.reg.getFlagC());this.reg.setFlagC(t),this.reg.a=s},s.rar=function(){var t=g.get(this.reg.a,0),s=this.reg.getFlagC()?e.u8(128|this.reg.a>>1):e.u8(this.reg.a>>1);this.reg.setFlagC(t),this.reg.a=s},s.dad=function(t){var s=this.reg.getHL(),r=e.u16(s+t);this.reg.setFlagC(s>65535-t),this.reg.setHL(r)},t}(),exports.Cpu.CLOCK_FREQUENCY=2e6,exports.Cpu.STEP_TIME=16,exports.Cpu.STEP_CYCLES=exports.Cpu.STEP_TIME/(1e3/exports.Cpu.CLOCK_FREQUENCY),o=exports.Cpu||(exports.Cpu={}),u=function(e){function s(t){var s;return(s=e.call(this,"Unimplemented instruction: "+c.toString(t)+" (0x"+b.toHexStr(t)+")")||this).opcode=void 0,s.opcode=t,s}return t(s,e),s}(h(Error)),o.UnimplementedInstructionError=u,exports.Memory=function(){function t(){this.data=new ArrayBuffer(t.MEMORY_SIZE),this.view=new DataView(this.data)}var s=t.prototype;return s.load=function(s,r){for(var a=0;a<s.length;a++){if(r+a>=t.MEMORY_SIZE)throw new t.NotEnoughMemoryError;this.set(e.u16(r+a),e.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)},t}(),exports.Memory.MEMORY_SIZE=65536,k=exports.Memory||(exports.Memory={}),l=function(e){function s(){return e.call(this,"Not enough memory for this operation!")||this}return t(s,e),s}(h(Error)),k.NotEnoughMemoryError=l;
var e=require("typed-numbers");function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,r(e,t)}function s(e){return s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},s(e)}function r(e,t){return r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},r(e,t)}function a(){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 i(e,t,s){return i=a()?Reflect.construct:function(e,t,s){var a=[null];a.push.apply(a,t);var i=new(Function.bind.apply(e,a));return s&&r(i,s.prototype),i},i.apply(null,arguments)}function h(e){var t="function"==typeof Map?new Map:void 0;return h=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,a)}function a(){return i(e,arguments,s(this).constructor)}return a.prototype=Object.create(e.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),r(a,e)},h(e)}var g=function(){function t(){}return t.get=function(e,t){return 0!=(e&1<<t)},t.set=function(t,s,r){return e.u8(r?t|1<<s:t&~(1<<s))},t.countOnes=function(e){for(var t=0;e;)t+=1&e,e>>=1;return t},t}(),c=function(){function e(){}return e.getCycles=function(t){return e.OP_CYCLES_TABLE[t]},e.toString=function(t){return e.ASM_TABLE[t]},e}();c.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],c.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 n,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)+"] "+c.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}();exports.Flag=void 0,(n=exports.Flag||(exports.Flag={}))[n.S=7]="S",n[n.Z=6]="Z",n[n.A=4]="A",n[n.P=2]="P",n[n.C=0]="C";var b,u,k,l,d=function(){function t(){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 s=t.prototype;return s.getAF=function(){return e.u16(this.a<<8|this.f)},s.getBC=function(){return e.u16(this.b<<8|this.c)},s.getDE=function(){return e.u16(this.d<<8|this.e)},s.getHL=function(){return e.u16(this.h<<8|this.l)},s.setAF=function(t){this.a=e.u8(t>>8),this.f=e.u8(213&t|2)},s.setBC=function(t){this.b=e.u8(t>>8),this.c=e.u8(255&t)},s.setDE=function(t){this.d=e.u8(t>>8),this.e=e.u8(255&t)},s.setHL=function(t){this.h=e.u8(t>>8),this.l=e.u8(255&t)},s.setFlag=function(e,t){this.f=g.set(this.f,e,t)},s.getFlag=function(e){return g.get(this.f,e)},s.setFlagS=function(e){this.setFlag(exports.Flag.S,g.get(e,7))},s.setFlagZ=function(e){this.setFlag(exports.Flag.Z,0==e)},s.setFlagA=function(e){this.setFlag(exports.Flag.A,e)},s.setFlagP=function(e){this.setFlag(exports.Flag.P,0==(1&g.countOnes(e)))},s.setFlagC=function(e){this.setFlag(exports.Flag.C,e)},s.getFlagS=function(){return this.getFlag(exports.Flag.S)},s.getFlagZ=function(){return this.getFlag(exports.Flag.Z)},s.getFlagA=function(){return this.getFlag(exports.Flag.A)},s.getFlagP=function(){return this.getFlag(exports.Flag.P)},s.getFlagC=function(){return this.getFlag(exports.Flag.C)},t}();exports.Cpu=function(){function t(e,t,s){void 0===s&&(s=!1),this.reg=new d,this.mem=void 0,this.halted=!1,this.intEnabled=!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=t.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=e.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(e.u16(this.reg.getBC()+1));break;case 19:this.reg.setDE(e.u16(this.reg.getDE()+1));break;case 35:this.reg.setHL(e.u16(this.reg.getHL()+1));break;case 51:this.reg.sp=e.u16(this.reg.sp+1);break;case 11:this.reg.setBC(e.u16(this.reg.getBC()-1));break;case 27:this.reg.setDE(e.u16(this.reg.getDE()-1));break;case 43:this.reg.setHL(e.u16(this.reg.getHL()-1));break;case 59:this.reg.sp=e.u16(this.reg.sp-1);break;case 235:var n=this.reg.h;this.reg.h=this.reg.d,this.reg.d=n;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=e.u16(56&s);break;case 251:this.intEnabled=!0;break;case 243:this.intEnabled=!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 t.UnimplementedInstructionError(s)}return c.getCycles(s)+r},s.step=function(){try{var e=this,s=function(){var t=e.next();return e.stepCycles+=t,t},r=function(){if(e.stepCycles>t.STEP_CYCLES){e.stepCycles-=t.STEP_CYCLES;var s=Date.now()-e.stepZero,r=t.STEP_TIME-s;return Promise.resolve(new Promise(function(e){return setTimeout(e,r)})).then(function(){e.stepZero=e.stepZero+t.STEP_TIME})}}();return Promise.resolve(r&&r.then?r.then(s):s())}catch(e){return Promise.reject(e)}},s.handleIntEnabled=function(e){this.intEnabled&&(this.intEnabled=!1,this.stackAdd(this.reg.pc),this.reg.pc=e,this.stepCycles+=c.getCycles(205))},s.getNextByte=function(){var t=this.mem.get(this.reg.pc);return this.reg.pc=e.u16(this.reg.pc+1),t},s.getNextWord=function(){var t=this.mem.getWord(this.reg.pc);return this.reg.pc=e.u16(this.reg.pc+2),t},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(t){this.reg.sp=e.u16(this.reg.sp-2),this.mem.setWord(this.reg.sp,t)},s.stackPop=function(){var t=this.mem.getWord(this.reg.sp);return this.reg.sp=e.u16(this.reg.sp+2),t},s.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 t.UnimplementedInstructionError(e)}},s.inr=function(t){var s=e.u8(t+1);return this.reg.setFlagS(s),this.reg.setFlagZ(s),this.reg.setFlagP(s),this.reg.setFlagA(1+(15&t)>15),s},s.dcr=function(t){var s=e.u8(t-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 t=0,s=this.reg.getFlagC(),r=15&this.reg.a,a=this.reg.a>>4&15;(r>9||this.reg.getFlagA())&&(t=e.u8(t+6)),(a>9||this.reg.getFlagC()||a>=9&&r>9)&&(t=e.u8(t+96),s=!0),this.add(t),this.reg.setFlagC(s)},s.add=function(t){var s=this.reg.a,r=e.u8(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},s.adc=function(t){var s=+this.reg.getFlagC(),r=this.reg.a,a=e.u8(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},s.sub=function(t){var s=this.reg.a,r=e.u8(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},s.sbb=function(t){var s=+this.reg.getFlagC(),r=this.reg.a,a=e.u8(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},s.ana=function(t){var s=e.u8(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},s.xra=function(t){var s=e.u8(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},s.ora=function(t){var s=e.u8(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},s.cmp=function(e){var t=this.reg.a;this.sub(e),this.reg.a=t},s.rlc=function(){var t=g.get(this.reg.a,7),s=e.u8(this.reg.a<<1|+t);this.reg.setFlagC(t),this.reg.a=s},s.rrc=function(){var t=g.get(this.reg.a,0),s=e.u8(t?128|this.reg.a>>1:this.reg.a>>1);this.reg.setFlagC(t),this.reg.a=s},s.ral=function(){var t=g.get(this.reg.a,7),s=e.u8(this.reg.a<<1|+this.reg.getFlagC());this.reg.setFlagC(t),this.reg.a=s},s.rar=function(){var t=g.get(this.reg.a,0),s=this.reg.getFlagC()?e.u8(128|this.reg.a>>1):e.u8(this.reg.a>>1);this.reg.setFlagC(t),this.reg.a=s},s.dad=function(t){var s=this.reg.getHL(),r=e.u16(s+t);this.reg.setFlagC(s>65535-t),this.reg.setHL(r)},t}(),exports.Cpu.CLOCK_FREQUENCY=2e6,exports.Cpu.STEP_TIME=16,exports.Cpu.STEP_CYCLES=exports.Cpu.STEP_TIME/(1e3/exports.Cpu.CLOCK_FREQUENCY),b=exports.Cpu||(exports.Cpu={}),u=function(e){function s(t){var s;return(s=e.call(this,"Unimplemented instruction: "+c.toString(t)+" (0x"+o.toHexStr(t)+")")||this).opcode=void 0,s.opcode=t,s}return t(s,e),s}(h(Error)),b.UnimplementedInstructionError=u,exports.Memory=function(){function t(){this.data=new ArrayBuffer(t.MEMORY_SIZE),this.view=new DataView(this.data)}var s=t.prototype;return s.load=function(s,r){void 0===r&&(r=0);for(var a=0;a<s.length;a++){if(r+a>=t.MEMORY_SIZE)throw new t.NotEnoughMemoryError;this.set(e.u16(r+a),e.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)},t}(),exports.Memory.MEMORY_SIZE=65536,k=exports.Memory||(exports.Memory={}),l=function(e){function s(){return e.call(this,"Not enough memory for this operation!")||this}return t(s,e),s}(h(Error)),k.NotEnoughMemoryError=l,exports.Bit=g,exports.Debug=o,exports.Opcode=c,exports.Register=d;
//# sourceMappingURL=eighty-eighty.js.map

@@ -1,2 +0,2 @@

import{u8 as e,u16 as s}from"typed-numbers";class t{static get(e,s){return 0!=(e&1<<s)}static set(s,t,r){return e(r?s|1<<t:s&~(1<<t))}static countOnes(e){let s=0;for(;e;)s+=1&e,e>>=1;return s}}class r{static getCycles(e){return r.OP_CYCLES_TABLE[e]}static toString(e){return r.ASM_TABLE[e]}}r.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],r.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"};class a{static toHexStr(e,s=2){const t=e.toString(16).toUpperCase();return t.startsWith("-")?"-"+t.substr(1).padStart(s,"0"):t.padStart(s,"0")}static printOperation(e,s){console.log(`[${a.toHexStr(s.reg.pc-1,4)}] ${r.toString(e).padEnd(15," ")}(SP=${a.toHexStr(s.reg.sp,4)} A=${a.toHexStr(s.reg.a)} F=${a.toHexStr(s.reg.f)} B=${a.toHexStr(s.reg.b)} C=${a.toHexStr(s.reg.c)} D=${a.toHexStr(s.reg.d)} E=${a.toHexStr(s.reg.e)} H=${a.toHexStr(s.reg.h)} L=${a.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":".")+")")}}var i;!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"}(i||(i={}));class h{constructor(){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}getAF(){return s(this.a<<8|this.f)}getBC(){return s(this.b<<8|this.c)}getDE(){return s(this.d<<8|this.e)}getHL(){return s(this.h<<8|this.l)}setAF(s){this.a=e(s>>8),this.f=e(213&s|2)}setBC(s){this.b=e(s>>8),this.c=e(255&s)}setDE(s){this.d=e(s>>8),this.e=e(255&s)}setHL(s){this.h=e(s>>8),this.l=e(255&s)}setFlag(e,s){this.f=t.set(this.f,e,s)}getFlag(e){return t.get(this.f,e)}setFlagS(e){this.setFlag(i.S,t.get(e,7))}setFlagZ(e){this.setFlag(i.Z,0==e)}setFlagA(e){this.setFlag(i.A,e)}setFlagP(e){this.setFlag(i.P,0==(1&t.countOnes(e)))}setFlagC(e){this.setFlag(i.C,e)}getFlagS(){return this.getFlag(i.S)}getFlagZ(){return this.getFlag(i.Z)}getFlagA(){return this.getFlag(i.A)}getFlagP(){return this.getFlag(i.P)}getFlagC(){return this.getFlag(i.C)}}class g{constructor(e,s,t=!1){this.reg=new h,this.mem=void 0,this.halted=!1,this.intEnabled=!1,this.debugEnabled=!1,this.device=void 0,this.stepCycles=0,this.stepZero=Date.now(),this.mem=e,this.device=s,this.debugEnabled=t}next(){if(this.halted)return 0;const t=this.getNextByte();this.debugEnabled&&a.printOperation(t,this);let i=0;switch(t){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:{const e=this.getM(),s=this.inr(e);this.setM(s);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:{const e=this.getM(),s=this.dcr(e);this.setM(s);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(s(this.reg.getBC()+1));break;case 19:this.reg.setDE(s(this.reg.getDE()+1));break;case 35:this.reg.setHL(s(this.reg.getHL()+1));break;case 51:this.reg.sp=s(this.reg.sp+1);break;case 11:this.reg.setBC(s(this.reg.getBC()-1));break;case 27:this.reg.setDE(s(this.reg.getDE()-1));break;case 43:this.reg.setHL(s(this.reg.getHL()-1));break;case 59:this.reg.sp=s(this.reg.sp-1);break;case 235:{const e=this.reg.h;this.reg.h=this.reg.d,this.reg.d=e;const s=this.reg.l;this.reg.l=this.reg.e,this.reg.e=s;break}case 227:{const e=this.mem.getWord(this.reg.sp),s=this.reg.getHL();this.reg.setHL(e),this.mem.setWord(this.reg.sp,s);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:{const e=this.getNextWord();this.checkBranchCondition(t)&&(this.reg.pc=e);break}case 205:case 220:case 212:case 204:case 196:case 236:case 228:case 252:case 244:{const e=this.getNextWord();this.checkBranchCondition(t)&&(i=6,this.stackAdd(this.reg.pc),this.reg.pc=e);break}case 201:case 216:case 208:case 200:case 192:case 248:case 240:case 232:case 224:this.checkBranchCondition(t)&&(i=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=s(56&t);break;case 251:this.intEnabled=!0;break;case 243:this.intEnabled=!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 g.UnimplementedInstructionError(t)}return r.getCycles(t)+i}async step(){if(this.stepCycles>g.STEP_CYCLES){this.stepCycles-=g.STEP_CYCLES;const e=Date.now()-this.stepZero,s=g.STEP_TIME-e;await new Promise(e=>setTimeout(e,s)),this.stepZero=this.stepZero+g.STEP_TIME}const e=this.next();return this.stepCycles+=e,e}handleIntEnabled(e){this.intEnabled&&(this.intEnabled=!1,this.stackAdd(this.reg.pc),this.reg.pc=e,this.stepCycles+=r.getCycles(205))}getNextByte(){const e=this.mem.get(this.reg.pc);return this.reg.pc=s(this.reg.pc+1),e}getNextWord(){const e=this.mem.getWord(this.reg.pc);return this.reg.pc=s(this.reg.pc+2),e}getM(){const e=this.reg.getHL();return this.mem.get(e)}setM(e){const s=this.reg.getHL();this.mem.set(s,e)}stackAdd(e){this.reg.sp=s(this.reg.sp-2),this.mem.setWord(this.reg.sp,e)}stackPop(){const e=this.mem.getWord(this.reg.sp);return this.reg.sp=s(this.reg.sp+2),e}checkBranchCondition(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 g.UnimplementedInstructionError(e)}}inr(s){const t=e(s+1);return this.reg.setFlagS(t),this.reg.setFlagZ(t),this.reg.setFlagP(t),this.reg.setFlagA(1+(15&s)>15),t}dcr(s){const t=e(s-1);return this.reg.setFlagS(t),this.reg.setFlagZ(t),this.reg.setFlagP(t),this.reg.setFlagA(15!=(15&t)),t}daa(){let s=0,t=this.reg.getFlagC();const r=15&this.reg.a,a=this.reg.a>>4&15;(r>9||this.reg.getFlagA())&&(s=e(s+6)),(a>9||this.reg.getFlagC()||a>=9&&r>9)&&(s=e(s+96),t=!0),this.add(s),this.reg.setFlagC(t)}add(s){const t=this.reg.a,r=e(t+s);this.reg.setFlagS(r),this.reg.setFlagZ(r),this.reg.setFlagP(r),this.reg.setFlagA((15&t)+(15&s)>15),this.reg.setFlagC(t+s>255),this.reg.a=r}adc(s){const t=+this.reg.getFlagC(),r=this.reg.a,a=e(r+s+t);this.reg.setFlagS(a),this.reg.setFlagZ(a),this.reg.setFlagP(a),this.reg.setFlagA((15&r)+(15&s)+t>15),this.reg.setFlagC(r+s+t>255),this.reg.a=a}sub(s){const t=this.reg.a,r=e(t-s);this.reg.setFlagS(r),this.reg.setFlagZ(r),this.reg.setFlagP(r),this.reg.setFlagA((15&t)-(15&s)>=0),this.reg.setFlagC(t<s),this.reg.a=r}sbb(s){const t=+this.reg.getFlagC(),r=this.reg.a,a=e(r-s-t);this.reg.setFlagS(a),this.reg.setFlagZ(a),this.reg.setFlagP(a),this.reg.setFlagA((15&r)-(15&s)-t>=0),this.reg.setFlagC(r<s+t),this.reg.a=a}ana(s){const t=e(this.reg.a&s);this.reg.setFlagS(t),this.reg.setFlagZ(t),this.reg.setFlagP(t),this.reg.setFlagA(0!=(8&(this.reg.a|s))),this.reg.setFlagC(!1),this.reg.a=t}xra(s){const t=e(this.reg.a^s);this.reg.setFlagS(t),this.reg.setFlagZ(t),this.reg.setFlagP(t),this.reg.setFlagA(!1),this.reg.setFlagC(!1),this.reg.a=t}ora(s){const t=e(this.reg.a|s);this.reg.setFlagS(t),this.reg.setFlagZ(t),this.reg.setFlagP(t),this.reg.setFlagA(!1),this.reg.setFlagC(!1),this.reg.a=t}cmp(e){const s=this.reg.a;this.sub(e),this.reg.a=s}rlc(){const s=t.get(this.reg.a,7),r=e(this.reg.a<<1|+s);this.reg.setFlagC(s),this.reg.a=r}rrc(){const s=t.get(this.reg.a,0),r=e(s?128|this.reg.a>>1:this.reg.a>>1);this.reg.setFlagC(s),this.reg.a=r}ral(){const s=t.get(this.reg.a,7),r=e(this.reg.a<<1|+this.reg.getFlagC());this.reg.setFlagC(s),this.reg.a=r}rar(){const s=t.get(this.reg.a,0),r=this.reg.getFlagC()?e(128|this.reg.a>>1):e(this.reg.a>>1);this.reg.setFlagC(s),this.reg.a=r}dad(e){const t=this.reg.getHL(),r=s(t+e);this.reg.setFlagC(t>65535-e),this.reg.setHL(r)}}g.CLOCK_FREQUENCY=2e6,g.STEP_TIME=16,g.STEP_CYCLES=g.STEP_TIME/(1e3/g.CLOCK_FREQUENCY),function(e){class s extends Error{constructor(e){super(`Unimplemented instruction: ${r.toString(e)} (0x${a.toHexStr(e)})`),this.opcode=void 0,this.opcode=e}}e.UnimplementedInstructionError=s}(g||(g={}));class c{constructor(){this.data=new ArrayBuffer(c.MEMORY_SIZE),this.view=new DataView(this.data)}load(t,r){for(let a=0;a<t.length;a++){if(r+a>=c.MEMORY_SIZE)throw new c.NotEnoughMemoryError;this.set(s(r+a),e(t[a]))}}get(e){return this.view.getUint8(e)}set(e,s){this.view.setUint8(e,s)}getWord(e){return this.view.getUint16(e,!0)}setWord(e,s){this.view.setUint16(e,s,!0)}}c.MEMORY_SIZE=65536,function(e){class s extends Error{constructor(){super("Not enough memory for this operation!")}}e.NotEnoughMemoryError=s}(c||(c={}));export{g as Cpu,c as Memory};
import{u8 as e,u16 as s}from"typed-numbers";class t{static get(e,s){return 0!=(e&1<<s)}static set(s,t,r){return e(r?s|1<<t:s&~(1<<t))}static countOnes(e){let s=0;for(;e;)s+=1&e,e>>=1;return s}}class r{static getCycles(e){return r.OP_CYCLES_TABLE[e]}static toString(e){return r.ASM_TABLE[e]}}r.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],r.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"};class a{static toHexStr(e,s=2){const t=e.toString(16).toUpperCase();return t.startsWith("-")?"-"+t.substr(1).padStart(s,"0"):t.padStart(s,"0")}static printOperation(e,s){console.log(`[${a.toHexStr(s.reg.pc-1,4)}] ${r.toString(e).padEnd(15," ")}(SP=${a.toHexStr(s.reg.sp,4)} A=${a.toHexStr(s.reg.a)} F=${a.toHexStr(s.reg.f)} B=${a.toHexStr(s.reg.b)} C=${a.toHexStr(s.reg.c)} D=${a.toHexStr(s.reg.d)} E=${a.toHexStr(s.reg.e)} H=${a.toHexStr(s.reg.h)} L=${a.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":".")+")")}}var i;!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"}(i||(i={}));class h{constructor(){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}getAF(){return s(this.a<<8|this.f)}getBC(){return s(this.b<<8|this.c)}getDE(){return s(this.d<<8|this.e)}getHL(){return s(this.h<<8|this.l)}setAF(s){this.a=e(s>>8),this.f=e(213&s|2)}setBC(s){this.b=e(s>>8),this.c=e(255&s)}setDE(s){this.d=e(s>>8),this.e=e(255&s)}setHL(s){this.h=e(s>>8),this.l=e(255&s)}setFlag(e,s){this.f=t.set(this.f,e,s)}getFlag(e){return t.get(this.f,e)}setFlagS(e){this.setFlag(i.S,t.get(e,7))}setFlagZ(e){this.setFlag(i.Z,0==e)}setFlagA(e){this.setFlag(i.A,e)}setFlagP(e){this.setFlag(i.P,0==(1&t.countOnes(e)))}setFlagC(e){this.setFlag(i.C,e)}getFlagS(){return this.getFlag(i.S)}getFlagZ(){return this.getFlag(i.Z)}getFlagA(){return this.getFlag(i.A)}getFlagP(){return this.getFlag(i.P)}getFlagC(){return this.getFlag(i.C)}}class g{constructor(e,s,t=!1){this.reg=new h,this.mem=void 0,this.halted=!1,this.intEnabled=!1,this.debugEnabled=!1,this.device=void 0,this.stepCycles=0,this.stepZero=Date.now(),this.mem=e,this.device=s,this.debugEnabled=t}next(){if(this.halted)return 0;const t=this.getNextByte();this.debugEnabled&&a.printOperation(t,this);let i=0;switch(t){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:{const e=this.getM(),s=this.inr(e);this.setM(s);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:{const e=this.getM(),s=this.dcr(e);this.setM(s);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(s(this.reg.getBC()+1));break;case 19:this.reg.setDE(s(this.reg.getDE()+1));break;case 35:this.reg.setHL(s(this.reg.getHL()+1));break;case 51:this.reg.sp=s(this.reg.sp+1);break;case 11:this.reg.setBC(s(this.reg.getBC()-1));break;case 27:this.reg.setDE(s(this.reg.getDE()-1));break;case 43:this.reg.setHL(s(this.reg.getHL()-1));break;case 59:this.reg.sp=s(this.reg.sp-1);break;case 235:{const e=this.reg.h;this.reg.h=this.reg.d,this.reg.d=e;const s=this.reg.l;this.reg.l=this.reg.e,this.reg.e=s;break}case 227:{const e=this.mem.getWord(this.reg.sp),s=this.reg.getHL();this.reg.setHL(e),this.mem.setWord(this.reg.sp,s);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:{const e=this.getNextWord();this.checkBranchCondition(t)&&(this.reg.pc=e);break}case 205:case 220:case 212:case 204:case 196:case 236:case 228:case 252:case 244:{const e=this.getNextWord();this.checkBranchCondition(t)&&(i=6,this.stackAdd(this.reg.pc),this.reg.pc=e);break}case 201:case 216:case 208:case 200:case 192:case 248:case 240:case 232:case 224:this.checkBranchCondition(t)&&(i=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=s(56&t);break;case 251:this.intEnabled=!0;break;case 243:this.intEnabled=!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 g.UnimplementedInstructionError(t)}return r.getCycles(t)+i}async step(){if(this.stepCycles>g.STEP_CYCLES){this.stepCycles-=g.STEP_CYCLES;const e=Date.now()-this.stepZero,s=g.STEP_TIME-e;await new Promise(e=>setTimeout(e,s)),this.stepZero=this.stepZero+g.STEP_TIME}const e=this.next();return this.stepCycles+=e,e}handleIntEnabled(e){this.intEnabled&&(this.intEnabled=!1,this.stackAdd(this.reg.pc),this.reg.pc=e,this.stepCycles+=r.getCycles(205))}getNextByte(){const e=this.mem.get(this.reg.pc);return this.reg.pc=s(this.reg.pc+1),e}getNextWord(){const e=this.mem.getWord(this.reg.pc);return this.reg.pc=s(this.reg.pc+2),e}getM(){const e=this.reg.getHL();return this.mem.get(e)}setM(e){const s=this.reg.getHL();this.mem.set(s,e)}stackAdd(e){this.reg.sp=s(this.reg.sp-2),this.mem.setWord(this.reg.sp,e)}stackPop(){const e=this.mem.getWord(this.reg.sp);return this.reg.sp=s(this.reg.sp+2),e}checkBranchCondition(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 g.UnimplementedInstructionError(e)}}inr(s){const t=e(s+1);return this.reg.setFlagS(t),this.reg.setFlagZ(t),this.reg.setFlagP(t),this.reg.setFlagA(1+(15&s)>15),t}dcr(s){const t=e(s-1);return this.reg.setFlagS(t),this.reg.setFlagZ(t),this.reg.setFlagP(t),this.reg.setFlagA(15!=(15&t)),t}daa(){let s=0,t=this.reg.getFlagC();const r=15&this.reg.a,a=this.reg.a>>4&15;(r>9||this.reg.getFlagA())&&(s=e(s+6)),(a>9||this.reg.getFlagC()||a>=9&&r>9)&&(s=e(s+96),t=!0),this.add(s),this.reg.setFlagC(t)}add(s){const t=this.reg.a,r=e(t+s);this.reg.setFlagS(r),this.reg.setFlagZ(r),this.reg.setFlagP(r),this.reg.setFlagA((15&t)+(15&s)>15),this.reg.setFlagC(t+s>255),this.reg.a=r}adc(s){const t=+this.reg.getFlagC(),r=this.reg.a,a=e(r+s+t);this.reg.setFlagS(a),this.reg.setFlagZ(a),this.reg.setFlagP(a),this.reg.setFlagA((15&r)+(15&s)+t>15),this.reg.setFlagC(r+s+t>255),this.reg.a=a}sub(s){const t=this.reg.a,r=e(t-s);this.reg.setFlagS(r),this.reg.setFlagZ(r),this.reg.setFlagP(r),this.reg.setFlagA((15&t)-(15&s)>=0),this.reg.setFlagC(t<s),this.reg.a=r}sbb(s){const t=+this.reg.getFlagC(),r=this.reg.a,a=e(r-s-t);this.reg.setFlagS(a),this.reg.setFlagZ(a),this.reg.setFlagP(a),this.reg.setFlagA((15&r)-(15&s)-t>=0),this.reg.setFlagC(r<s+t),this.reg.a=a}ana(s){const t=e(this.reg.a&s);this.reg.setFlagS(t),this.reg.setFlagZ(t),this.reg.setFlagP(t),this.reg.setFlagA(0!=(8&(this.reg.a|s))),this.reg.setFlagC(!1),this.reg.a=t}xra(s){const t=e(this.reg.a^s);this.reg.setFlagS(t),this.reg.setFlagZ(t),this.reg.setFlagP(t),this.reg.setFlagA(!1),this.reg.setFlagC(!1),this.reg.a=t}ora(s){const t=e(this.reg.a|s);this.reg.setFlagS(t),this.reg.setFlagZ(t),this.reg.setFlagP(t),this.reg.setFlagA(!1),this.reg.setFlagC(!1),this.reg.a=t}cmp(e){const s=this.reg.a;this.sub(e),this.reg.a=s}rlc(){const s=t.get(this.reg.a,7),r=e(this.reg.a<<1|+s);this.reg.setFlagC(s),this.reg.a=r}rrc(){const s=t.get(this.reg.a,0),r=e(s?128|this.reg.a>>1:this.reg.a>>1);this.reg.setFlagC(s),this.reg.a=r}ral(){const s=t.get(this.reg.a,7),r=e(this.reg.a<<1|+this.reg.getFlagC());this.reg.setFlagC(s),this.reg.a=r}rar(){const s=t.get(this.reg.a,0),r=this.reg.getFlagC()?e(128|this.reg.a>>1):e(this.reg.a>>1);this.reg.setFlagC(s),this.reg.a=r}dad(e){const t=this.reg.getHL(),r=s(t+e);this.reg.setFlagC(t>65535-e),this.reg.setHL(r)}}g.CLOCK_FREQUENCY=2e6,g.STEP_TIME=16,g.STEP_CYCLES=g.STEP_TIME/(1e3/g.CLOCK_FREQUENCY),function(e){class s extends Error{constructor(e){super(`Unimplemented instruction: ${r.toString(e)} (0x${a.toHexStr(e)})`),this.opcode=void 0,this.opcode=e}}e.UnimplementedInstructionError=s}(g||(g={}));class c{constructor(){this.data=new ArrayBuffer(c.MEMORY_SIZE),this.view=new DataView(this.data)}load(t,r=0){for(let a=0;a<t.length;a++){if(r+a>=c.MEMORY_SIZE)throw new c.NotEnoughMemoryError;this.set(s(r+a),e(t[a]))}}get(e){return this.view.getUint8(e)}set(e,s){this.view.setUint8(e,s)}getWord(e){return this.view.getUint16(e,!0)}setWord(e,s){this.view.setUint16(e,s,!0)}}c.MEMORY_SIZE=65536,function(e){class s extends Error{constructor(){super("Not enough memory for this operation!")}}e.NotEnoughMemoryError=s}(c||(c={}));export{t as Bit,g as Cpu,a as Debug,i as Flag,c as Memory,r as Opcode,h as Register};
//# sourceMappingURL=eighty-eighty.modern.js.map

@@ -1,2 +0,2 @@

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.intEnabled=!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.intEnabled=!0;break;case 243:this.intEnabled=!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.handleIntEnabled=function(e){this.intEnabled&&(this.intEnabled=!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){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{u as Cpu,l as Memory};
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.intEnabled=!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.intEnabled=!0;break;case 243:this.intEnabled=!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.handleIntEnabled=function(e){this.intEnabled&&(this.intEnabled=!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

@@ -1,2 +0,2 @@

!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}();!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 u,k,l,d,C=function(){function e(){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 s=e.prototype;return s.getAF=function(){return t.u16(this.a<<8|this.f)},s.getBC=function(){return t.u16(this.b<<8|this.c)},s.getDE=function(){return t.u16(this.d<<8|this.e)},s.getHL=function(){return t.u16(this.h<<8|this.l)},s.setAF=function(e){this.a=t.u8(e>>8),this.f=t.u8(213&e|2)},s.setBC=function(e){this.b=t.u8(e>>8),this.c=t.u8(255&e)},s.setDE=function(e){this.d=t.u8(e>>8),this.e=t.u8(255&e)},s.setHL=function(e){this.h=t.u8(e>>8),this.l=t.u8(255&e)},s.setFlag=function(e,t){this.f=c.set(this.f,e,t)},s.getFlag=function(e){return c.get(this.f,e)},s.setFlagS=function(e){this.setFlag(b.S,c.get(e,7))},s.setFlagZ=function(e){this.setFlag(b.Z,0==e)},s.setFlagA=function(e){this.setFlag(b.A,e)},s.setFlagP=function(e){this.setFlag(b.P,0==(1&c.countOnes(e)))},s.setFlagC=function(e){this.setFlag(b.C,e)},s.getFlagS=function(){return this.getFlag(b.S)},s.getFlagZ=function(){return this.getFlag(b.Z)},s.getFlagA=function(){return this.getFlag(b.A)},s.getFlagP=function(){return this.getFlag(b.P)},s.getFlagC=function(){return this.getFlag(b.C)},e}();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.intEnabled=!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.intEnabled=!0;break;case 243:this.intEnabled=!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.handleIntEnabled=function(e){this.intEnabled&&(this.intEnabled=!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){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});
!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.intEnabled=!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.intEnabled=!0;break;case 243:this.intEnabled=!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.handleIntEnabled=function(e){this.intEnabled&&(this.intEnabled=!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

@@ -1,2 +0,3 @@

export { Cpu, Memory } from './core';
export { Cpu, Memory, Flag, Register } from './core';
export { Bit, Debug, Opcode } from './helpers';
export { Device } from './types';
{
"name": "eighty-eighty-js",
"description": "A nice little Intel 8080 emulator for Node.js and Browser!",
"version": "1.0.6",
"version": "1.0.7",
"author": "Skayo (https://skayo.dev)",

@@ -35,3 +35,3 @@ "license": "MIT",

"dependencies": {
"typed-numbers": "^1.0.0"
"typed-numbers": "^1.0.2"
},

@@ -38,0 +38,0 @@ "devDependencies": {

@@ -46,3 +46,3 @@ <h1 align="center">EightyEighty.js</h1>

You'll probably need to install `typed-numbers` too!
You'll probably need to install [`typed-numbers`](https://github.com/Skayo/TypedNumbers) too!

@@ -49,0 +49,0 @@ ```typescript

@@ -22,5 +22,5 @@ import { u16, u8 } from 'typed-numbers';

* @param buffer - The buffer to load into memory. Can be of any array-like type.
* @param offset - The offset from where to start writing the buffer into memory.
* @param [offset = 0] - The offset from where to start writing the buffer into memory.
*/
public load(buffer: ArrayLike<number>, offset: number) {
public load(buffer: ArrayLike<number>, offset: number = 0) {
for (let address = 0; address < buffer.length; address++) {

@@ -27,0 +27,0 @@ if (offset + address >= Memory.MEMORY_SIZE) throw new Memory.NotEnoughMemoryError();

@@ -1,2 +0,3 @@

export { Cpu, Memory } from './core';
export { Cpu, Memory, Flag, Register } from './core';
export { Bit, Debug, Opcode } from './helpers';
export { Device } from './types';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc