JavaScriptによるPC-8001ビープ音エミュレーション

[昨日の記事](https://qiita.com/KoichiYasuoka/items/a68532e5e2c34f0bd103)と[一昨昨日の記事](https://qiita.com/KoichiYasuoka/items/2c7f947db259db3c5ffe)で、私(安岡孝一)はこう書いた。

> どうにもならなかったのがビープ音で、とりあえず2400Hzのoscillatorを、gainの上げ下げで実装しているが、なかなかうまい感じの音にならない。

そもそもPC-8001のビープ音を、JavaScriptでエミュレートしようというのがどうかしているのだが、要は44.1kHzもしくは48kHzのサンプリング信号を作り出せればいいはずなのだ。仮に3MHz相当のZ80ならば、68ステートないし62.5ステート毎に、2400Hzビープ音との掛け合わせで、サンプリング信号を作り出していけばいい。ただ、audioContext.createBufferのバッファサイズをどうするかがあって、色々試したあげく、1/60秒のバッファサイズに落ち着いた。この方法だと、音が最悪1/60秒ズレるし、60Hzのノイズが背後に乗ってしまうのだが、この60HzのノイズがPC-8001の実機に近くて、わりといい感じに聞こえる(でも関西だけかもしれない)。

5月24日時点でのビープ音改造版『[ΡΟΠΗ](http://kanji.zinbun.kyoto-u.ac.jp/~yasuoka/ropee/ropee.html)』のプログラムリストを、以下に公開しておくことにする。

```
<!DOCTYPE html><head><meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>&#x03A1;&#x039F;&#x03A0;&#x0397; by Koichi Yasuoka, May 24, 2025</title>
<script>
var pc8001=new Object();
pc8001.memory=new Array(65536);
pc8001.memory.fill(0x76);
["0000 31 FF FF C3 06 A0",
 "0018                         C3 A6 40",
 "093A                               2A 5A EA EB 21 00", // init display 80x25
 "0940 F3 06 50 73 23 10 FC AF 77 23 77 23 36 01 23 72",
 "0950 23 01 50 11 71 23 72 23 10 FA 71 23 77 23 11 00",
 "0960 F3 EB 01 40 0B ED B0 C9",
 "1602       C9",                                        // "date" unsupport
 "40A6                   FE 0C CA 3A 09 76",             // print one-char
 "A000 31 FF FF CD 0F B0 CD 26 A0 CD 62 A8 CD 62 AA CD",
 "A010 F4 AB CD 85 AF CD F0 B0 CD DF B1 CD DE B2 CD FB",
 "A020 BC CD 13 BE 18 E9 DB 01 07 30 FB 21 21 C0 01 00",
 "A030 0E 71 2C 10 FC 2E CB 06 08 71 7D 80 6F 30 FA 21",
 "A040 00 CD 06 04 71 7D 80 6F 20 FA 21 04 CE 06 12 71",
 "A050 7D 80 6F 30 FA CD 02 16 2A 76 EA 22 02 CE 21 00",
 "A060 B8 22 5A EA 26 FF 22 60 EA 3E 05 32 66 EA 01 19",
 "A070 50 C3 3A 09 6B 64 0B 10 11 00 C6 C8 06 21 22 01",
 "A080 8C 80 0C 52 55 02 08 00 08 B5 BA 05 B0 46 B6 00",
 "A090 11 01 60 8C 6C 10 22 12 C0 08 C8 20 55 25 80 00",
 "A0A0 80 50 AB 5B E1 E0 01 01 00 01 C2 C0 02 12 10 02",
 "A0B0 84 80 04 34 30 04 08 00 08 78 70 08 10 0E 1E 10",
 "A0C0 00 10 20 0C 2C 20 01 21 40 08 48 40 03 43 80 00",
 "A0D0 80 80 07 87 48 4F 08 10 10 00 80 8E 00 21 21 01",
 "A0E0 00 0C 00 52 53 02 00 08 00 A4 A7 04 80 F4 84 00",
 "A0F0 01 01 00 E8 08 10 12 12 00 C0 00 20 35 25 00 80",
 "A100 00 40 7A 4A 5A 59 0A 01 00 01 A4 A2 04 03 01 03",
 "A110 48 44 08 16 12 06 80 88 00 2D 24 0D A0 95 A5 10",
 "A120 00 10 40 2A 4A 30 10 30 80 44 84 60 21 61 00 88",
 "A130 08 D0 42 D2 43 4A 03 11 10 01 86 84 06 22 21 02",
 "A140 0C 08 0C 54 52 04 08 00 08 A9 A5 09 30 A4 34 10",
 "A150 01 11 60 48 68 20 12 22 C0 80 C0 40 25 45 80 00",
 "A160 80 90 5A 9A A4 A3 04 10 10 00 48 46 08 30 30 00",
 "A170 80 8C 00 61 60 01 00 08 00 D2 D1 02 40 3A 4A 00",
 "A180 01 01 80 64 84 00 03 03 00 C8 08 10 06 16 00 80",
 "A190 00 20 1D 2D 54 5B 04 10 11 00 A8 A6 08 20 23 00",
 "A1A0 40 4C 00 51 56 01 80 88 00 A2 AD 02 40 B5 45 00",
 "A1B0 11 01 80 6A 8A 00 32 02 00 C4 04 10 65 15 00 88",
 "A1C0 08 20 DA 2A A1 A4 01 01 00 01 42 48 02 12 10 02",
 "A1D0 84 80 04 24 21 04 08 00 08 58 52 08 10 4A 1A 10",
 "A1E0 00 10 20 84 24 20 01 21 40 08 48 40 12 42 80 00",
 "A1F0 80 80 25 85 B3 B6 03 11 10 01 66 6C 06 32 30 02",
 "A200 CC C8 0C 64 61 04 88 80 08 D9 D3 09 30 6B 3B 10",
 "A210 01 11 60 C6 66 20 03 23 C0 8C CC 40 16 46 80 08",
 "A220 88 90 3D 9D 8F 8E 0F 00 01 00 0E 0C 0E 11 13 01",
 "A230 0C 08 0C 23 27 03 08 00 08 47 4F 07 F0 E8 F8 00",
 "A240 10 00 E0 C0 E0 10 31 11 C0 80 C0 30 72 32 80 00",
 "A250 80 70 F4 74 A4 A5 04 01 00 01 48 4A 08 12 10 02",
 "A260 80 84 00 25 21 05 00 08 00 5A 52 0A 40 5A 4A 10",
 "A270 00 10 80 A4 84 20 01 21 00 48 08 50 12 52 00 80",
 "A280 00 A0 25 A5 53 5B 03 10 10 00 A6 A6 06 20 21 00",
 "A290 4C 4C 0C 50 52 00 88 88 08 A1 A5 01 30 B5 35 00",
 "A2A0 01 01 60 6A 6A 00 12 02 C0 C4 C4 00 25 05 80 88",
 "A2B0 88 10 5A 1A 97 91 07 11 10 01 2E 22 0E 32 30 02",
 "A2C0 4C 44 0C 65 60 05 88 88 08 CB C0 0B 70 19 79 10",
 "A2D0 01 11 E0 22 E2 20 03 23 C0 44 C4 50 06 56 80 88",
 "A2E0 88 B0 0C BC A4 A1 04 00 01 00 48 42 08 10 12 00",
 "A2F0 80 84 00 21 24 01 00 08 00 52 58 02 40 1A 4A 00",
 "A300 10 00 80 24 84 00 21 01 00 48 08 10 42 12 00 80",
 "A310 00 20 85 25 BB B0 0B 11 10 01 66 60 06 33 30 03",
 "A320 CC C0 0C 66 60 06 88 80 08 DD D0 0D B0 0B BB 10",
 "A330 01 11 60 06 66 30 03 33 C0 0C CC 60 06 66 80 08",
 "A340 88 D0 0D DD 91 97 01 00 01 00 22 2E 02 10 12 00",
 "A350 44 4C 04 20 25 00 88 88 08 40 4B 00 10 79 19 00",
 "A360 10 00 20 E2 22 00 21 01 40 C4 44 00 52 02 80 88",
 "A370 88 00 B4 04 B9 BC 09 01 00 01 62 68 02 13 11 03",
 "A380 C4 C0 04 26 23 06 88 80 08 5C 56 0C 90 CB 9B 10",
 "A390 00 10 20 86 26 30 11 31 40 0C 4C 60 32 62 80 08",
 "A3A0 88 C0 65 C5 B6 BA 06 00 01 00 6C 64 0C 10 13 00",
 "A3B0 C8 C8 08 21 26 01 80 80 00 53 5D 03 60 AB 6B 00",
 "A3C0 10 00 C0 46 C6 00 31 01 80 8C 8C 10 62 12 00 08",
 "A3D0 08 30 D5 35 0F 0E 0F 10 10 00 0E 0C 0E 21 21 01",
 "A3E0 0C 08 0C 43 43 03 08 00 08 87 87 07 F0 E0 F0 00",
 "A3F0 01 01 E0 C0 E0 10 12 12 C0 80 C0 30 34 34 80 00",
 "A400 80 70 78 78 D1 D7 01 01 00 01 A2 AE 02 12 10 02",
 "A410 44 4C 04 34 31 04 88 88 08 68 63 08 10 7D 1D 10",
 "A420 00 10 20 EA 2A 20 01 21 40 C4 44 40 13 43 80 88",
 "A430 88 80 36 86 1E 15 0E 10 11 00 2C 2A 0E 21 22 01",
 "A440 48 44 08 43 45 03 80 88 00 87 8A 07 E0 51 E1 00",
 "A450 11 01 C0 A2 C2 10 22 12 80 44 84 30 54 34 00 88",
 "A460 08 70 A8 78 F0 F0 00 10 10 00 E0 E0 00 30 30 00",
 "A470 C0 C0 00 70 70 00 80 80 00 F0 F0 00 00 0F 0F 00",
 "A480 01 01 00 0E 0E 00 03 03 00 0C 0C 00 07 07 00 08",
 "A490 08 00 0F 0F 00 00 00 03 04 05 14 05 0A 14 32 04",
 "A4A0 05 06 14 05 06 07 19 0A 0F 14 3C 07 09 0C 1E 08",
 "A4B0 09 0A 19 06 08 0A 1E 0F 14 19 46 09 0C 0F 28 14",
 "A4C0 19 1E 50 0B 0C 0D 2D 03 05 07 1E 07 0A 0F 3C 04",
 "A4D0 07 0A 23 06 07 08 19 0A 0C 0F 28 08 0A 0C 46 06",
 "A4E0 09 0C 50 0C 0F 12 4B 1E 23 28 5A 28 2D 32 64 00",
 "A4F0 00 00 9F 99 0F 1F 31 0F F1 F1 09 8F 88 0F 00 00",
 "A500 00 0C 0C C4 C4 04 4C 0C 00 C0 48 00 C0 C0 80 84",
 "A510 C0 44 C0 C0 C0 C4 C0 48 80 84 77 00 00 47 44 07",
 "A520 70 70 07 77 00 07 00 00 00 70 00 70 70 00 47 07",
 "A530 00 70 61 40 10 16 70 72 50 75 70 74 70 74 70 61",
 "A540 70 72 C0 44 C0 C4 C0 C0 C0 C4 C0 C4 C0 C4 C0 44",
 "A550 70 45 70 11 00 07 70 75 70 11 70 74 60 45 40 44",
 "A560 80 84 C0 C4 C0 C4 C0 C4 C0 44 40 45 70 72 70 70",
 "A570 70 75 70 74 60 45 C0 C0 80 84 C0 44 C4 C0 C4 C0",
 "A580 C4 C0 44 60 61 70 70 50 06 56 70 11 70 74 60 45",
 "A590 88 88 88 08 00 00 00 00 00 00 C0 C4 80 84 C0 C0",
 "A5A0 C0 44 00 C0 44 C0 C4 C0 C4 80 84 C0 C4 C0 44 00",
 "A5B0 10 33 13 00 00 00 00 00 00 00 70 70 70 72 00 07",
 "A5C0 60 45 00 50 75 70 74 70 74 70 70 70 74 70 00 04",
 "A5D0 4C 08 48 08 48 08 48 08 4C 44 0C 08 00 88 88 88",
 "A5E0 88 88 88 88 88 08 00 00 00 4C 0C 48 08 4C 44 0C",
 "A5F0 08 00 2E AA 2E 2E 2E 2E AA AE A2 0E 57 02 27 07",
 "A600 07 07 07 07 65 60 05 02 00 23 22 22 22 22 22 22",
 "A610 22 03 00 00 00 07 07 27 07 65 60 05 02 00 AF 8A",
 "A620 8F 8E 8F 8F FE FF F8 0F 11 11 11 70 52 72 10 11",
 "A630 11 01 00 00 00 00 00 00 00 00 00 00 00 00 11 07",
 "A640 11 11 11 10 1B 10 11 11 01 57 07 00 00 00 00 08",
 "A650 08 0D 04 08 10 0B 06 14 07 13 0D 06 08 0B 12 0E",
 "A660 0E 0A 09 0D 12 88 8C 08 4C 04 4C 4C 0C 23 27 03",
 "A670 57 04 07 07 07 44 0C 0C 0C 8C 04 48 08 56 04 17",
 "A680 07 17 06 07 07 48 08 0C 4C 04 C0 C0 C0 C4 C0 C0",
 "A690 40 4C 47 07 07 07 00 60 61 70 11 70 71 00 07 4C",
 "A6A0 04 0C 0C 07 00 70 00 4C 08 0C 48 08 4C 44 0C 57",
 "A6B0 02 07 47 07 65 60 05 08 0C 08 4C 0C 4C 4C 0C C4",
 "A6C0 C4 04 4C 44 0C 4C 04 23 27 03 47 07 07 07 07 70",
 "A6D0 70 00 65 60 05 57 04 48 08 0C 4C 08 48 08 4C 0C",
 "A6E0 48 08 47 07 07 57 02 27 07 07 07 47 07 C4 04 4C",
 "A6F0 04 0C 0C 70 00 57 04 16 06 4C 0C 4C 0C 0C 4C 04",
 "A700 8C 04 4C 04 C0 C4 C4 C0 C0 40 C4 80 84 57 07 17",
 "A710 01 07 07 00 17 06 57 04 70 70 70 70 71 60 45 70",
 "A720 72 0C 48 08 4C 0C 44 04 07 47 07 47 07 54 04 4C",
 "A730 0C 48 08 C0 C4 C4 C0 44 C0 C4 C0 C4 80 84 C0 C0",
 "A740 40 4C 57 07 27 07 70 70 70 70 45 70 75 70 11 70",
 "A750 72 60 61 00 07 4C 04 48 08 4C 04 4C 0C 0C 0C 4C",
 "A760 4C 0C 07 00 27 07 07 00 47 07 70 00 07 07 07 48",
 "A770 08 4C 04 4C 04 27 07 07 00 07 00 0C 08 0C 08 4C",
 "A780 04 4C 0C 07 23 27 03 57 04 07 07 C4 04 48 08 0C",
 "A790 0C 4C 4C 0C 48 08 70 00 27 07 70 00 07 07 07 27",
 "A7A0 07 C4 C4 04 48 08 4C 0C 0C C0 C4 C4 C0 44 C4 C0",
 "A7B0 C4 C0 C0 70 70 00 27 07 17 01 07 70 70 70 50 06",
 "A7C0 56 70 70 70 71 0C 0C 44 04 48 08 4C 0C 48 08 4C",
 "A7D0 0C 4C 04 70 00 54 04 27 07 07 07 47 07 47 07 56",
 "A7E0 04 4C 04 0C 48 08 40 4C 4C C0 C4 C0 C4 C0 48 56",
 "A7F0 04 07 27 07 00 07 07 70 74 70 11 70 61 88 8C 08",
 "A800 0C 4C 0C 48 08 48 08 23 27 03 07 07 07 47 07 07",
 "A810 07 4C 04 48 08 0C C4 04 0C 0C 57 04 07 07 07 70",
 "A820 00 17 07 4C 04 4C 04 0C 0C 4C 0C 4C 08 C0 C4 C0",
 "A830 56 04 57 04 16 06 47 07 57 02 70 75 70 0C 4C 0C",
 "A840 C0 C0 40 4C 4C C0 C4 00 4C 0C 4C 04 88 8C 08 07",
 "A850 47 07 00 07 00 07 07 70 74 00 57 07 57 04 23 27",
 "A860 03 00 DB 01 07 D0 3E 0C DF 21 98 10 22 53 F3 22",
 "A870 CB F3 3E F8 32 BB F4 32 33 F5 32 F3 F8 32 6B F9",
 "A880 3E 78 32 AB F5 32 23 F6 3E D8 32 9B F6 32 13 F7",
 "A890 7D 32 8B F7 32 03 F8 21 F2 A4 11 03 F3 01 28 00",
 "A8A0 ED B0 1E 7B 0E 28 ED B0 11 70 F5 0E 0E ED B0 1E",
 "A8B0 E8 0E 0E ED B0 11 62 F6 0E 0C ED B0 1E DA 0E 0C",
 "A8C0 ED B0 11 51 F7 0E 0D ED B0 1E C9 0E 0D ED B0 11",
 "A8D0 B4 F8 0E 20 ED B0 11 2C F9 0E 20 ED B0 11 1A FA",
 "A8E0 0E 2C ED B0 1E 92 0E 2C ED B0 11 F0 FC 0E 23 ED",
 "A8F0 B0 3E C0 32 7C FC 21 C0 C4 22 2B FB 21 70 75 22",
 "A900 A3 FB 3E 0F 32 1C FC 32 84 FD 3E 0B 32 94 FC 21",
 "A910 40 C5 22 FB FD 21 70 55 22 73 FE 21 0C 0C 22 8E",
 "A920 FC 21 4C 04 22 99 FC 3A 2D C0 47 04 AF 21 4E A6",
 "A930 86 2C 10 FC 4E 6F 29 11 65 5A 19 79 11 74 F4 ED",
 "A940 B0 1E EC 4F ED B0 3A 2D C0 47 80 80 87 87 6F 61",
 "A950 29 29 11 80 A0 19 F9 D1 C1 E1 78 32 E4 F5 32 D4",
 "A960 F6 32 C4 F7 22 E5 F5 22 D5 F6 22 C5 F7 79 EB 32",
 "A970 6E F5 32 5E F6 32 4E F7 22 6C F5 22 5C F6 22 4C",
 "A980 F7 21 8B F5 3A 2D C0 87 87 C6 97 5F 16 A4 01 04",
 "A990 03 1A F9 D9 21 0A FF 24 95 30 FC 85 87 87 C6 35",
 "A9A0 6F 7C 26 AA 01 C0 44 C5 06 C4 C5 01 80 84 C5 01",
 "A9B0 C0 C4 C5 4E 2C 46 2C 5E 2C 56 C5 87 20 02 3E 14",
 "A9C0 87 C6 35 6F 4E 2C 46 C5 D9 21 84 00 39 71 F9 D9",
 "A9D0 01 70 00 C5 06 74 C5 41 C5 06 74 C5 D5 2C 4E 2C",
 "A9E0 46 C5 D9 21 84 00 39 1C 10 A7 31 FD FF DB 08 E6",
 "A9F0 20 32 00 CE 28 1A 21 C4 00 22 76 FC 21 44 0C 22",
 "AA00 82 FC 21 74 04 22 EE FC 21 55 07 22 FA FC 18 16",
 "AA10 21 44 0C 22 76 FC 6C 22 82 FC 21 56 04 22 EE FC",
 "AA20 21 16 06 22 FA FC 47 DB 08 E6 20 A8 20 BF DB 01",
 "AA30 07 38 F4 C9 00 C0 C4 70 74 40 0C 40 47 40 C4 70",
 "AA40 55 40 C4 50 75 C0 C0 10 71 C0 44 50 75 C0 44 70",
 "AA50 75 40 C4 00 70 C0 C4 70 75 C0 C4 50 75 00 00 00",
 "AA60 00 00 21 2E C0 DB 09 07 30 05 CD E1 BD 18 03 CD",
 "AA70 EF BD 31 62 C0 11 06 06 D5 11 01 01 D5 11 20 20",
 "AA80 D5 11 FF 1A D5 2E C3 71 21 7F C1 11 B8 60 06 13",
 "AA90 73 2D 72 2D 10 FA 73 2D 71 20 FC 11 80 C1 01 80",
 "AAA0 0A ED B0 2E 88 16 F3 0E 78 ED B0 62 01 40 0B ED",
 "AAB0 B0 3E F8 32 51 F3 32 C9 F3 32 91 FE 31 10 F3 21",
 "AAC0 4C 04 E5 55 5C 26 0C E5 E5 D5 5C D5 26 04 E5 63",
 "AAD0 E5 21 48 08 E5 31 88 F3 11 56 04 D5 21 47 07 E5",
 "AAE0 6C E5 6A E5 53 5C D5 50 D5 2E 47 E5 6C E5 31 90",
 "AAF0 FE 21 11 11 06 28 E5 10 FD 21 C0 C4 22 1E F3 21",
 "AB00 70 74 22 96 F3 31 FD FF C9 00 00 00 39 25 2E 3F",
 "AB10 76 22 49 64 53 59 94 71 83 8B 69 2A 9C A6 BC C6",
 "AB20 D0 EA 0A 87 FF 09 87 2E 11 FF 0B 87 FF 00 01 87",
 "AB30 23 24 23 24 23 24 23 24 FF 01 87 FF 23 24 FF 11",
 "AB40 86 89 02 03 41 04 00 00 00 01 86 6A 02 03 24 41",
 "AB50 00 00 00 0A 87 20 8D 0B FF 35 83 26 25 23 4D 10",
 "AB60 01 42 24 FF 01 87 6D 0B FF 09 87 4A 13 10 13 09",
 "AB70 FF 02 87 31 4D FF 01 87 20 21 FF 6C 03 24 4D 6C",
 "AB80 03 24 4D 01 87 33 12 13 11 11 FF 31 83 6D 06 09",
 "AB90 2F 6D 01 FF 09 87 21 90 03 02 05 FF 01 87 67 0C",
 "ABA0 28 87 0B 28 0E 00 0B 87 63 0C 24 0E FF 00 00 00",
 "ABB0 63 0C 20 4D 05 07 10 FF 63 0C 24 FF 11 86 6A 02",
 "ABC0 07 4D 01 08 00 00 09 87 33 03 24 0F 33 03 24 0F",
 "ABD0 0B 87 31 4D 07 32 12 05 FF 00 31 03 4D 07 32 12",
 "ABE0 05 FF 31 0E 4D 07 32 12 05 FF 01 87 31 21 0F FF",
 "ABF0 00 00 00 00 3A 55 C0 B7 C2 66 AC 3A 54 C0 B7 CA",
 "AC00 D7 AC 3A 53 C0 B7 C2 56 AD 3A 52 C0 D6 08 D2 D7",
 "AC10 AD 3A 2C C0 3D F0 32 53 C0 2A 50 C0 7C 85 4F 21",
 "AC20 06 03 22 50 C0 3A 2D C0 C6 3A 6F 26 C0 7E 81 77",
 "AC30 2E 2E 7E 3C FE E1 20 02 3E C3 77 5F 16 BD 2D 1A",
 "AC40 77 C6 3A 6F 3A 52 C0 2F C6 0D 86 77 2E 32 2D 7E",
 "AC50 36 00 3C FE 0A 28 F7 77 2E 52 36 15 11 1F C0 01",
 "AC60 19 00 ED B8 C9 00 CD 59 BE 20 16 F1 3A 32 C0 B7",
 "AC70 CA 09 A0 21 33 C0 11 23 C0 01 07 00 ED B0 C3 09",
 "AC80 A0 31 38 C7 11 80 84 D5 21 84 C0 E5 43 4C C5 D5",
 "AC90 21 4C 4C E5 11 04 40 D5 2E 0C E5 2E 08 E5 16 48",
 "ACA0 D5 6B E5 21 00 C4 E5 31 B8 C7 21 70 72 E5 11 74",
 "ACB0 70 D5 5A D5 E5 21 07 07 E5 3B 11 56 04 D5 01 47",
 "ACC0 07 C5 E5 1C D5 21 70 00 E5 31 FD FF 21 02 37 22",
 "ACD0 00 C7 22 80 C7 C9 00 3A 5A C0 FE 40 C0 3A 2A C0",
 "ACE0 2A 2B C0 B4 B5 2A 58 C0 B4 B5 C0 3A 60 C0 3D 20",
 "ACF0 05 3D 32 55 C0 C9 32 60 C0 3E 54 32 54 C0 ED 5B",
 "AD00 60 C0 0E 2A 21 4F F3 1D 28 20 43 79 D6 03 38 37",
 "AD10 4F 36 00 2D 36 C0 2D 36 00 7D C6 7A 6F 36 72 2D",
 "AD20 36 52 2D 36 70 D6 7B 6F 10 E1 15 28 1A 42 79 D6",
 "AD30 02 38 14 4F 36 08 2D 36 00 7D C6 79 6F 36 13 2D",
 "AD40 36 10 D6 7A 6F 10 E7 0C 41 AF 11 9D F3 77 12 2D",
 "AD50 1C 10 FA C9 00 00 3D 32 53 C0 FE E0 D0 31 2F C7",
 "AD60 21 0C 0C E5 E5 11 48 08 D5 2E 4C E5 7D 32 26 C7",
 "AD70 31 AF C7 11 17 07 D5 01 16 06 C5 1E 27 D5 5A D5",
 "AD80 7A 32 A6 C7 3A 2F C0 87 20 08 3A 30 C0 87 20 15",
 "AD90 18 22 87 C6 35 6F 26 AA F9 E1 22 2F C7 E1 22 AF",
 "ADA0 C7 3A 30 C0 87 87 C6 35 6F 26 AA F9 E1 22 31 C7",
 "ADB0 E1 22 B1 C7 3A 31 C0 87 87 C6 35 6F 26 AA F9 E1",
 "ADC0 22 33 C7 E1 22 B3 C7 31 FD FF 21 02 34 22 00 C7",
 "ADD0 22 80 C7 C9 00 00 00 21 5C C0 35 C0 2C 86 2D 77",
 "ADE0 3A 2C C0 FE 0C D0 47 3A 52 C0 90 47 CD 72 AF 16",
 "ADF0 02 0F 30 02 16 A5 E6 1F B8 D0 D9 21 39 C0 2C 96",
 "AE00 30 FC 7D D6 3A FE 16 38 09 3A 2D C0 28 02 C6 40",
 "AE10 C6 40 D9 47 E6 1F C6 0C 6F 26 AB 6E CB 56 28 15",
 "AE20 3A 54 C0 92 38 02 ED 44 C6 57 30 09 C6 02 5F ED",
 "AE30 53 65 C0 18 0F 4A EB CD 72 AF E6 3F C6 08 6F 61",
 "AE40 22 65 C0 EB 7E 2C 4E 2C EB 21 00 00 CB 6F 28 01",
 "AE50 24 22 69 C0 CB 67 28 05 26 01 08 18 4A CB 5F 20",
 "AE60 0E 08 CD 72 AF 26 00 C6 80 6F 30 3B 24 18 38 08",
 "AE70 3A 65 C0 C6 15 6F 26 AF 6E 3A 66 C0 67 3A 54 C0",
 "AE80 94 30 02 ED 44 26 FF BD 38 05 24 95 BD 30 D3 D5",
 "AE90 54 1E FF 67 AF 24 1C 95 30 FC 25 20 F9 EB D1 24",
 "AEA0 20 05 7D FE 40 38 BB 3A 66 C0 07 30 06 AF 95 6F",
 "AEB0 9F 94 67 22 67 C0 D9 08 E6 03 47 11 65 C0 D9 C5",
 "AEC0 CD D2 AE C1 EB D9 35 C8 1A C6 06 12 10 F0 C9 00",
 "AED0 00 00 21 2C C0 34 21 F2 CE 7D C6 12 6F CB 7E 20",
 "AEE0 F9 71 2C 3A 56 C0 B7 28 0A CB 70 28 06 AF 32 56",
 "AEF0 C0 CB F8 70 2C ED 4B 67 C0 71 2C 36 80 2C 70 2C",
 "AF00 ED 4B 65 C0 70 2C 79 ED 4B 69 C0 71 2C 36 80 2C",
 "AF10 70 2C 77 2C EB 01 08 00 ED B0 C9 00 00 5B 5A 59",
 "AF20 59 58 58 57 57 56 55 55 54 54 53 52 52 51 50 50",
 "AF30 4F 4F 4E 4D 4D 4C 4B 4B 4A 49 48 48 47 46 46 45",
 "AF40 44 43 43 42 41 40 40 3F 3E 3D 3C 3B 3B 3A 39 38",
 "AF50 37 36 35 34 33 32 31 30 2F 2E 2D 2C 2A 29 28 27",
 "AF60 25 24 23 21 20 1E 1C 1A 18 16 14 11 0E 0A 00 00",
 "AF70 00 00 2A 02 CE 7C 07 0F CB 15 1F 8D 3D 67 22 02",
 "AF80 CE C9 00 00 00 3A 54 C0 B7 C8 3A 5A C0 E6 03 20",
 "AF90 18 DB 08 E6 40 CC E4 AF DB 09 E6 40 20 08 3A 01",
 "AFA0 CE B7 C4 1F B0 AF 32 01 CE 3A 57 C0 B7 C0 3A 00",
 "AFB0 CE B7 28 15 DB 00 E6 0A FE 08 28 17 FE 02 C0 21",
 "AFC0 54 C0 7E FE A1 C8 3C 18 12 DB 05 E6 05 FE 04 28",
 "AFD0 EE 3D C0 21 54 C0 7E FE 06 C8 3D 77 2E 58 BE C0",
 "AFE0 2D 36 01 C9 3A C3 C0 B7 C0 3A 61 C0 3D C8 32 61",
 "AFF0 C0 3E 20 D3 40 3A 54 C0 32 C3 C0 21 C5 80 22 C4",
 "B000 C0 21 FE 55 22 C6 C0 3A 5A C0 07 D2 FE AC C9 7C",
 "B010 FE A0 D0 21 69 BE CD ED 52 DB 01 07 38 FB C9 21",
 "B020 2A C0 7E FE 06 D0 34 21 02 CE 34 3E 20 D3 40 2A",
 "B030 53 C0 2E 55 22 65 C0 3A C3 C0 B7 28 06 21 54 C0",
 "B040 96 20 0F 21 00 00 22 67 C0 21 3E FE 22 69 C0 C3",
 "B050 C1 B0 21 00 01 30 04 ED 44 26 FF 22 67 C0 4F 3A",
 "B060 C7 C0 D6 05 47 C6 1E 6F 26 AF 7E B9 20 11 7D 87",
 "B070 C6 02 6F 26 B1 5E 2C 56 ED 53 69 C0 C3 C1 B0 11",
 "B080 6E AF 30 0E 2D 1D 1A 86 B9 30 E3 10 F7 21 2A C0",
 "B090 35 C9 2D 1D 1A 2F 86 B9 38 D4 10 F6 3C 41 4F 21",
 "B0A0 00 00 3E FF 2C 91 30 FC 10 FA 3A 68 C0 3C 20 03",
 "B0B0 95 6F 25 22 67 C0 21 3E FE 22 69 C0 C3 C1 B0 00",
 "B0C0 00 26 C0 3E C3 C6 08 6F 46 04 10 F9 D6 03 6F ED",
 "B0D0 5B 67 C0 73 2C 36 80 2C 72 2C ED 5B 65 C0 72 2C",
 "B0E0 ED 4B 69 C0 71 2C 36 80 2C 70 2C 73 C9 00 00 00",
 "B0F0 AF D3 40 2A C3 C0 B4 C0 B5 C8 DB 00 E6 50 FE 40",
 "B100 20 0B 21 C3 C0 7E FE 06 28 10 35 18 0D FE 10 20",
 "B110 09 21 C3 C0 7E FE A1 28 01 34 DB 01 0F DB 00 1F",
 "B120 E6 82 FE 02 20 09 21 C7 C0 7E FE 06 C8 35 C9 FE",
 "B130 80 C0 21 C7 C0 7E FE 54 C8 34 C9 00 00 00 3E FE",
 "B140 41 FE 44 FE 46 FE 49 FE 4C FE 4F FE 52 FE 55 FE",
 "B150 58 FE 5D FE 5E FE 61 FE 64 FE 67 FE 6A FE 6E FE",
 "B160 71 FE 74 FE 77 FE 7A FE 7E FE 81 FE 84 FE 88 FE",
 "B170 8B FE 8F FE 92 FE 95 FE 99 FE 9D FE A0 FE A4 FE",
 "B180 A7 FE AB FE AF FE B3 FE B7 FE BA FE BE FE C2 FE",
 "B190 C6 FE CA FE CF FE D3 FE D7 FE DB FE E0 FE E4 FE",
 "B1A0 E9 FE ED FE F2 FE F7 FE FC FE 00 FF 05 FF 0B FF",
 "B1B0 10 FF 15 FF 1B FF 20 FF 26 FF 2C FF 32 FF 38 FF",
 "B1C0 3F FF 45 FF 4C FF 53 FF 5B FF 62 FF 6B FF 73 FF",
 "B1D0 7D FF 87 FF 91 FF 9D FF AB FF BB FF D0 FF 00 21",
 "B1E0 5A C0 34 20 31 2C 35 C2 FE AC 36 19 2E 5D 7E FE",
 "B1F0 04 28 01 35 3A 58 C0 B7 20 1C 3A 54 C0 B7 28 16",
 "B200 CD 72 AF 11 01 01 0F 30 03 11 FF A6 21 58 C0 72",
 "B210 2E 64 73 C3 FE AC 7E FE 80 C0 21 02 CE 34 31 40",
 "B220 F3 21 4C 04 E5 55 5C 26 0C E5 E5 D5 5C D5 26 04",
 "B230 E5 63 E5 21 48 08 E5 11 00 00 D5 21 44 C4 E5 21",
 "B240 C4 C0 E5 2E 84 E5 57 D5 31 B8 F3 21 56 04 E5 01",
 "B250 47 07 C5 48 C5 4C C5 65 68 E5 63 E5 0E 47 C5 48",
 "B260 C5 21 10 01 E5 21 06 56 E5 21 70 50 E5 21 72 70",
 "B270 E5 6B E5 31 FD FF 3A 32 C0 B7 28 13 21 10 F3 43",
 "B280 4D 11 40 F3 ED B0 2E 88 1E B8 0E 10 ED B0 C9 21",
 "B290 C0 C4 22 4E F3 21 70 74 22 C6 F3 11 40 F3 01 23",
 "B2A0 C0 0A B7 20 16 12 1C 12 7B C6 77 5F AF 12 1C 12",
 "B2B0 7B D6 77 5F 0C FE 4E 20 E8 C9 0A 87 87 C6 35 6F",
 "B2C0 26 AA ED A0 0C 7E 12 7B C6 77 5F 2C ED A0 0C 7E",
 "B2D0 12 7B D6 77 5F 0C FE 4E 20 E0 C9 00 00 00 CD A8",
 "B2E0 B6 3A 2C C0 B7 28 1A 21 6B C0 74 DD 21 04 CE DD",
 "B2F0 CB 00 7E C4 20 B9 DD 7D C6 12 DD 6F 20 F1 CD 78",
 "B300 BC 2A C3 C0 2C 2D 28 1B DD 21 C0 C0 24 25 28 09",
 "B310 21 C3 C0 5E CD 7F B3 18 0A 3A C7 C0 67 3A C3 C0",
 "B320 CD 9C B3 3A 2A C0 B7 28 13 DD 21 C8 C0 DD 7E 03",
 "B330 B7 C4 64 B3 DD 7D C6 08 DD 6F 20 F1 3A 2B C0 B7",
 "B340 28 19 DD 21 00 CD 3E 20 D3 40 DD 7E 00 B7 C4 AA",
 "B350 B8 DD 7D C6 04 DD 6F 20 F1 D3 40 CD 14 B8 C3 32",
 "B360 B7 00 00 00 DD 7D 6F 26 C0 7E 2C 86 77 2C 7E 2C",
 "B370 8E 77 5F D6 03 FE A2 38 06 36 00 2E 2A 35 C9 2C",
 "B380 7E 4F 2C 86 77 2C 7E 2C 8E FE 5B D2 59 B4 77 57",
 "B390 79 C6 05 DD 77 04 30 02 2D 34 62 7B C6 06 6F 7C",
 "B3A0 CB 3C 37 CB 1C 24 CB 2C CB 1D 38 6C E6 03 20 2B",
 "B3B0 7E 4F F6 13 77 2D CB E6 11 81 FF 19 CB DE 1D 14",
 "B3C0 7D E6 80 45 6F 78 E6 7F 36 02 2C BE 38 01 77 19",
 "B3D0 BE DA 0F B5 77 2D 36 02 C3 0F B5 47 10 1C 7E 4F",
 "B3E0 F6 27 77 2D CB EE 2C 7D E6 80 45 6F 78 E6 7F 36",
 "B3F0 02 2C BE DA 0F B5 77 C3 0F B5 10 0A 7E 4F F6 4E",
 "B400 77 2D CB F6 18 E0 7E 4F F6 8C 77 2D CB FE 11 81",
 "B410 00 19 CB C6 1D 15 18 A8 E6 03 20 12 7E 4F F6 31",
 "B420 77 2C CB C6 11 7F FF 19 CB FE 2C 1C 18 91 47 10",
 "B430 0A 7E 4F F6 72 77 2C CB CE 18 AC 10 0A 7E 4F F6",
 "B440 E4 77 2C CB D6 18 A0 7E 4F F6 C8 77 2C CB DE 11",
 "B450 7F 00 19 CB E6 2C 1C 18 BC 7D D6 07 6F 5E 2C 2C",
 "B460 56 ED 53 67 C0 2C 56 AF 77 1E 5B ED 53 65 C0 2C",
 "B470 96 4F 2C 2C 3E 00 9E 1F CB 19 37 1F CB 19 47 ED",
 "B480 43 69 C0 3A 58 C0 D6 04 38 06 92 FE F9 D4 7F B6",
 "B490 21 2A C0 35 21 2B C0 7E FE 3A D0 C6 07 77 ED 73",
 "B4A0 C1 C0 31 F0 B4 FD 21 FC CD 06 07 FD 7D C6 04 FD",
 "B4B0 6F FD 7E 00 B7 20 F4 2A 67 C0 D1 19 22 67 C0 2A",
 "B4C0 69 C0 D1 19 22 69 C0 16 CC FD 5D EB 73 2C 36 80",
 "B4D0 2C 72 2C ED 5B 65 C0 73 24 7A ED 5B 67 C0 73 2D",
 "B4E0 36 80 2D 72 2D 77 10 C3 ED 7B C1 C0 C9 00 00 00",
 "B4F0 00 00 C0 FF CE FF 18 00 F3 FF 36 00 23 00 2B 00",
 "B500 38 00 00 00 22 00 D5 FF F4 FF CA FF 00 00 00 0C",
 "B510 0D C8 AF 32 C0 C0 DD 56 03 DD 5E 07 DD E5 DD 21",
 "B520 04 CE DD CB 00 7E 28 19 7A DD 96 05 C6 02 FE 05",
 "B530 30 0F 7B DD 96 09 C6 02 FE 05 30 05 D5 CD 87 B5",
 "B540 D1 DD 7D C6 12 DD 6F 20 D9 DD E1 3A C0 C0 B7 C8",
 "B550 DD 7D FE C0 20 0B 21 00 00 22 67 C0 21 C3 C0 18",
 "B560 0E 21 2A C0 35 6F 5E 2C 2C 56 ED 53 67 C0 2C 46",
 "B570 36 00 2C 5E 2C 2C 56 ED 53 69 C0 2C 4E ED 43 65",
 "B580 C0 C3 94 B4 00 00 00 DD 7D 6F 26 CE 32 C0 C0 CB",
 "B590 BE 4E CB 49 20 09 7D C6 05 6F 11 00 00 18 07 2C",
 "B5A0 2C 5E 2C 2C 56 2C ED 53 67 C0 46 CB 41 20 0B DD",
 "B5B0 4E 09 21 00 00 22 69 C0 18 0B 2C 5E 2C 2C 56 2C",
 "B5C0 ED 53 69 C0 4E ED 43 65 C0 21 2C C0 35 2E 52 35",
 "B5D0 DD 7E 01 07 30 18 07 38 06 2E 57 36 00 18 10 57",
 "B5E0 79 FE 05 7A 38 09 ED 43 62 C0 2E 59 35 0F 07 C6",
 "B5F0 97 6F 26 A4 46 CD FB B5 C3 94 B4 21 3A C0 0E 0A",
 "B600 2D 78 86 06 00 04 91 30 FC 81 77 10 F3 7D FE 38",
 "B610 30 10 D9 21 5E C0 35 20 08 2C 34 7E 2D 77 32 56",
 "B620 C0 D9 7D 87 D6 56 5F 16 F3 06 AA 7E 87 87 C6 35",
 "B630 4F 0A 12 0C 1C 0A 12 0C 7B C6 77 5F 0A 12 0C 1C",
 "B640 0A 12 7B D6 77 5F 2C FE 1E 20 E0 2E 32 7E B7 20",
 "B650 12 11 22 C0 06 07 2C 1C 1A BE 38 03 C0 10 F7 2E",
 "B660 32 36 01 3A 5A C0 07 D0 21 10 F3 11 40 F3 01 0E",
 "B670 00 ED B0 2E 88 1E B8 0E 0E ED B0 C9 00 00 00 3A",
 "B680 58 C0 21 40 FE FE 08 38 0A 2E 8D FE A0 30 04 1F",
 "B690 C6 BD 6F 3E 11 77 2C 77 2C 77 21 00 00 22 57 C0",
 "B6A0 06 32 C3 FB B5 00 00 00 2A 57 C0 7C 2D A5 C8 3A",
 "B6B0 5A C0 E6 03 C0 3A 64 C0 84 32 58 C0 21 54 C0 BE",
 "B6C0 20 04 2E 57 36 01 FE 07 30 1A 21 40 FE 3D 28 0E",
 "B6D0 3D 28 26 3D 28 31 3D 28 1D 3D 28 28 18 15 36 11",
 "B6E0 32 58 C0 C9 FE A1 30 25 1F 38 11 C6 BC 6F 26 FE",
 "B6F0 36 11 2C 36 73 2C 36 77 2C 36 13 C9 C6 BD 6F 26",
 "B700 FE 36 31 2C 36 77 2C 36 37 2C 36 11 C9 21 8F FE",
 "B710 D6 A6 28 CA 3C 28 0F 3C 28 12 3C 28 06 3C 28 09",
 "B720 36 37 2D 36 77 2D 36 31 C9 36 77 2D 36 73 2D 36",
 "B730 11 C9 3A 59 C0 B7 C8 3D 32 59 C0 2A 62 C0 3A C3",
 "B740 C0 B7 28 24 94 C6 03 28 12 FE 06 28 0E 30 19 3A",
 "B750 C7 C0 95 C6 03 D6 07 30 0F 18 0A 3A C7 C0 95 C6",
 "B760 02 D6 05 30 03 32 22 C0 7C C6 06 65 6F 7C CB 3C",
 "B770 37 CB 1C 24 CB 2C CB 1D 38 62 E6 03 20 13 7E F6",
 "B780 21 77 2D CB EE 11 80 FF 19 CB FE 2C CB FE 14 18",
 "B790 34 11 52 50 3D 28 06 3D 20 1A 11 A4 A0 2D 7E B2",
 "B7A0 77 2C 7E B3 77 7D E6 80 45 6F 78 E6 7F 36 02 2C",
 "B7B0 BE D8 77 C9 7E F6 48 77 2D CB F6 11 80 00 19 CB",
 "B7C0 E6 2C CB E6 15 7D E6 80 45 6F 78 E6 7F 36 02 2C",
 "B7D0 BE 38 01 77 19 BE D8 77 2D 36 02 C9 E6 03 20 14",
 "B7E0 7E F6 12 77 2C CB CE 11 7F FF 19 CB DE 2C CB DE",
 "B7F0 14 1C 18 D1 11 05 25 3D 28 A4 11 0A 4A 3D 28 9E",
 "B800 7E F6 84 77 2C CB D6 11 7F 00 19 CB C6 2C CB C6",
 "B810 15 1C 18 B1 3A 54 C0 B7 C8 26 CB 1F 38 1A C6 82",
 "B820 6F 7E 57 F6 4E 77 2C 7E 5F F6 4B 77 2C 7E F6 0E",
 "B830 77 2D CB BD CB DE 18 18 C6 82 6F 7E F6 E0 77 2C",
 "B840 7E 57 F6 B4 77 2C 7E 5F F6 E4 77 2D CB BD CB FE",
 "B850 7D 2E 01 BE 38 04 77 2D 36 02 2E 81 3C BE 38 04",
 "B860 77 2D 36 02 7A B3 C8 DD 21 04 CE DD CB 00 7E 28",
 "B870 14 DD 7E 09 FE 56 38 0D 3A 54 C0 DD 96 05 D6 05",
 "B880 FE F7 D4 87 B5 DD 7D C6 12 DD 6F 20 DE 2A 53 C0",
 "B890 2E 5A 22 65 C0 67 6F 22 67 C0 21 40 FF 22 69 C0",
 "B8A0 32 54 C0 32 57 C0 C3 94 B4 00 DD 7D 6F 26 CC 7E",
 "B8B0 2C 86 77 2C 7E 2C 8E 77 C6 40 FE 9C 38 09 DD 36",
 "B8C0 00 00 21 2B C0 35 C9 5F 24 7E 2D 86 77 2D 7E 2D",
 "B8D0 8E 77 D6 04 FE A0 38 07 36 00 21 2B C0 35 C9 C6",
 "B8E0 0A 01 01 01 1F 30 02 0E 10 57 25 7E C6 05 77 30",
 "B8F0 03 2C 2C 34 7B D6 44 F8 1F 30 02 CB 01 0F 30 04",
 "B900 CB 01 CB 01 6A 0F 30 04 CB FD 06 81 F6 C0 3C 67",
 "B910 7E B1 77 AF D3 40 68 7E BA D0 72 2D 36 02 C9 00",
 "B920 DD CB 00 5E 20 4D DD CB 00 4E 28 5A DD 7D C6 02",
 "B930 6F 26 CE 7E 2C 86 77 2C 7E 2C 8E 77 D6 02 FE A4",
 "B940 38 1F DD 7D 6F 36 00 2C 7E FE 40 38 0B E6 C0 E2",
 "B950 54 B9 3E 40 07 07 C6 15 C6 3A 21 2C C0 35 6F 34",
 "B960 C9 C6 02 21 54 C0 BE 20 1D DD 7E 0A E6 E0 EC CB",
 "B970 BA 18 13 3A 5A C0 E6 04 0F 3D DD 86 05 DD 77 05",
 "B980 D6 02 FE A4 30 BC DD CB 00 46 28 30 DD 7D C6 06",
 "B990 6F 26 CE 7E 2C 86 77 2C 7E 2C 8E 77 FE 02 FA 42",
 "B9A0 B9 FE 5A 38 17 36 59 2D 2D 2D AF 96 77 2C 2C 9F",
 "B9B0 96 77 2C 2C 7E E6 E0 FE 20 CC CB BA DD CB 00 56",
 "B9C0 28 19 DD 7E 06 C6 05 DD 77 06 30 0F DD 34 08 20",
 "B9D0 0A DD 7E 0A E6 E0 FE 40 CC CB BA 3A 5A C0 B7 20",
 "B9E0 0A DD 7E 0A E6 E0 FE 80 CC CB BA DD 7E 01 47 80",
 "B9F0 80 87 87 6F 26 00 29 29 3E 78 CB 00 30 02 C6 20",
 "BA00 CB 00 30 02 C6 60 32 67 C0 DD 7E 09 D6 06 30 38",
 "BA10 47 80 80 87 DD 5E 05 CB 3B 30 02 C6 18 C6 8F 4F",
 "BA20 06 A0 09 EB 26 00 22 65 C0 26 C1 2C 2C 1A B6 77",
 "BA30 2C 13 1A B6 77 2C 1C 1A B6 77 7D 2E 01 BE DA 3D",
 "BA40 BC 77 2D 36 02 C3 3D BC 01 74 A0 1F 30 03 0E 7A",
 "BA50 B7 1F 32 66 C0 30 06 57 79 C6 0C 4F 7A 1F 38 0F",
 "BA60 C6 C1 57 DD 7E 05 1F 32 65 C0 5F 38 11 18 13 C6",
 "BA70 C1 57 DD 7E 05 1F 32 65 C0 CB FF 5F 30 04 79 C6",
 "BA80 18 4F 09 F9 1C 1C C1 1A B1 12 1C 1A B0 12 1C C1",
 "BA90 1A B1 12 21 7E 00 19 7E B0 77 2C C1 7E B1 77 2C",
 "BAA0 7E B0 77 31 FB FF 7D E6 80 6F 7B E6 7F 36 02 2C",
 "BAB0 BE 38 01 77 11 80 FF 19 BE 38 04 77 2D 36 02 CD",
 "BAC0 3D BC 21 66 C0 34 C3 3D BC 00 00 DD 7E 0A E6 1F",
 "BAD0 87 C6 12 6F 26 BC F9 C9 00 DD 7D C6 0A 6F 26 CE",
 "BAE0 F9 C1 70 D1 E1 F1 3B F5 E5 D5 DD 71 11 78 E6 E0",
 "BAF0 28 D9 31 F9 FF C9 DD CB 00 86 18 DD DD CB 00 C6",
 "BB00 18 D7 DD CB 00 8E 18 D1 DD CB 00 CE 18 CB DD CB",
 "BB10 00 96 18 C5 DD CB 00 D6 18 BF DD CB 00 DE 18 B9",
 "BB20 DD CB 00 9E 18 B3 DD 36 06 00 DD 36 08 00 18 A9",
 "BB30 DD 36 06 00 DD 36 08 01 18 9F DD CB 08 7E 20 99",
 "BB40 DD 7D C6 06 6F 26 CE AF 96 77 2C 2C 9F 96 77 18",
 "BB50 88 DD CB 08 7E 28 82 18 E7 DD 7E 09 FE 52 D2 D9",
 "BB60 BA C6 04 6F 3A 2A C0 FE 07 CA D9 BA 3C 32 2A C0",
 "BB70 DD 66 05 22 65 C0 21 A0 00 22 69 C0 6C 22 67 C0",
 "BB80 31 F9 FF CD C1 B0 C3 D9 BA 3A 54 C0 DD 96 05 1F",
 "BB90 DD AE 04 F2 D9 BA DD 7D C6 02 18 A8 DD 36 06 00",
 "BBA0 DD 36 08 FF C3 D9 BA DD CB 08 2E DD CB 06 1E C3",
 "BBB0 D9 BA DD CB 06 26 DD CB 08 16 C3 D9 BA 3A 2C C0",
 "BBC0 FE 0E CA D9 BA DD 7D 6F 26 CE 4E 2C 46 78 FE 40",
 "BBD0 38 0E 07 07 E6 03 C6 4F FE 52 20 06 3E 16 CB B8",
 "BBE0 C6 3A 5F 16 C0 1A 3D FA D9 BA 12 2C 5E 2C 2C 56",
 "BBF0 ED 53 67 C0 2C 7E 2C 5E 2C 2C 56 ED 53 69 C0 2C",
 "BC00 6E 67 22 65 C0 11 3B AB 31 F9 FF CD D2 AE C3 D9",
 "BC10 BA 00 D9 BA F6 BA FC BA 02 BB 08 BB 0E BB 14 BB",
 "BC20 1A BB 20 BB 26 BB 30 BB 3A BB 51 BB 59 BB 96 BB",
 "BC30 89 BB 9C BB A7 BB B2 BB BD BB 00 00 00 21 6B C0",
 "BC40 7E BC 20 0D 11 BD C0 73 2E 65 ED A0 ED A0 ED A0",
 "BC50 C9 6F D6 03 32 6B C0 5F 54 2F C6 BE 4F 06 00 3A",
 "BC60 65 C0 BE 38 09 ED A0 ED A0 ED A0 EA 62 BC 2A 66",
 "BC70 C0 EB 77 2C 73 2C 72 C9 21 6B C0 6E 7C 95 C8 47",
 "BC80 F9 E1 4D CB FC 2E AE CB 2C CB 1D 24 36 02 2C 54",
 "BC90 5D 7E B7 28 3E 6F F6 81 FE FB 38 3C 0F 3C 28 2A",
 "BCA0 08 2C 2C 7E 91 28 23 FE 04 38 07 08 3C 28 1B 08",
 "BCB0 2C 2C 79 D6 03 77 7D 12 2C 3B F1 77 08 3C 28 02",
 "BCC0 2C 71 05 05 10 BB 31 FB FF C9 33 05 05 10 B2 31",
 "BCD0 FB FF C9 79 FE 04 38 13 2C 2C 7E 91 28 EC C6 03",
 "BCE0 F2 E5 BC 2C 2C 79 D6 03 77 7D 12 2C 3B F1 77 2C",
 "BCF0 71 05 05 10 8C 31 FB FF C9 00 00 DD 21 01 C1 FD",
 "BD00 21 F0 F3 DD CB FF 3E 28 76 DD F9 C1 78 B9 30 01",
 "BD10 79 41 0E 00 C5 C1 C1 D6 01 1F FE 2A 20 0A 3E 29",
 "BD20 DD 36 54 00 DD 36 55 00 47 4F 05 FD 54 FD 5D EB",
 "BD30 D1 73 2C 72 23 10 F9 11 00 00 41 D5 10 FD 1E 80",
 "BD40 DD 19 1E 78 FD 19 DD CB D6 3E 20 07 30 27 FD F9",
 "BD50 3B 18 1A DD 54 DD 5D 1D 1B 62 6B FD F9 3B 3E 13",
 "BD60 2D 46 2D 4E C5 3D 20 F8 DD 77 D7 EB F9 11 B8 60",
 "BD70 06 13 D5 10 FD DD 7C FE CC 20 88 31 FD FF C9 38",
 "BD80 0F 06 60 10 FE 11 80 00 DD 19 1E 78 FD 19 18 E5",
 "BD90 DD 7E 01 11 00 00 DD 72 01 D6 03 E6 FE FE 52 20",
 "BDA0 02 3E 50 6F 62 FD 44 FD 4D 09 F9 0F 47 D5 10 FD",
 "BDB0 1E 80 DD 19 1E 78 FD 19 DD CB D6 3E 30 B7 FD F9",
 "BDC0 3B 18 AA 00 01 02 02 03 04 05 05 06 07 08 08 09",
 "BDD0 0C 0B 0B 0D 0E 0F 0F 10 11 11 0A 12 12 13 14 14",
 "BDE0 15 AF 32 21 C0 36 C2 01 00 2B 2C 71 10 FC C9 3A",
 "BDF0 21 C0 C6 FD A6 28 EE AF 32 55 C0 2E 53 36 FF 2D",
 "BE00 EB 21 1F C0 01 19 00 ED B8 06 08 12 1D 10 FC 2E",
 "BE10 21 34 C9 3A 22 C0 B7 C8 AF 32 22 C0 32 59 C0 21",
 "BE20 60 C0 34 2C 34 3A 5A C0 07 D4 FE AC 0E 00 3E 20",
 "BE30 D3 40 41 10 FE AF D3 40 41 10 FE 3E 20 D3 40 41",
 "BE40 10 FE AF D3 40 41 10 FE 3E 20 D3 40 41 10 FE AF",
 "BE50 D3 40 41 10 FE 0C 20 D6 C9 DB 01 E6 80 C8 3A 5A",
 "BE60 C0 E6 03 C0 21 55 C0 35 C9 98 9D 20 91 91 0D 0A",
 "BE70 93 9F ED 96 96 93 92 0D 0A 43 6F 70 79 72 69 67",
 "BE80 68 74 20 4D 43 4D 4C 58 58 58 56 20 28 43 29 20",
 "BE90 62 79 20 4B 2E 59 61 73 75 6F 6B 61 0D 0A 0A 20",
 "BEA0 20 53 74 61 72 74 20 41 64 64 72 65 73 73 3A 20",
 "BEB0 41 30 30 30 0D 0A 20 20 41 75 74 6F 73 61 76 65",
 "BEC0 72 20 53 74 61 72 74 20 41 64 64 72 65 73 73 3A",
 "BED0 20 42 46 30 30 0D 0A 0A 20 20 50 72 6F 67 72 61",
 "BEE0 6D 20 41 72 65 61 3A 20 41 30 30 30 2D 42 46 46",
 "BEF0 46 20 28 38 31 39 32 20 62 79 74 65 73 29 0A 00",
 "BF00 31 FF FF 21 A8 BF CD ED 52 DB 01 07 30 FB 21 EC",
 "BF10 BF CD ED 52 DB 01 07 38 FB 21 F9 BF CD ED 52 3A",
 "BF20 66 EA E6 03 F6 08 D3 30 21 7A BF 01 21 04 ED B3",
 "BF30 DB 20 06 06 CD 6F BF 10 FB 06 2A 7E CD 2F 5F 2C",
 "BF40 10 F9 21 00 A0 45 7E CD 2F 5F 80 47 2C 20 F7 ED",
 "BF50 44 CD 2F 5F 24 7C FE C0 20 EB CD 6F BF CD 6F BF",
 "BF60 3A 66 EA E6 F7 F6 04 32 66 EA D3 30 C3 81 00 11",
 "BF70 FF FF 7A B3 1B 20 FB C9 00 00 0E 40 CE 11 3A E8",
 "BF80 AC 6C 3A 21 21 00 A0 45 CD 9E 5F 77 80 47 2C 20",
 "BF90 F7 CD 9E 5F 80 C2 98 5F 24 7C FE C0 20 E9 C3 00",
 "BFA0 A0 00 00 AC E8 2D 3A 00 4D 61 63 68 69 6E 65 20",
 "BFB0 4C 61 6E 67 75 61 67 65 20 41 75 74 6F 73 61 76",
 "BFC0 65 72 0D 0A 43 6F 70 79 72 69 67 68 74 20 4D 43",
 "BFD0 4D 4C 58 58 58 49 56 20 28 43 29 20 62 79 20 4B",
 "BFE0 2E 59 61 73 75 6F 6B 61 0D 0A 0A 00 54 61 70 65",
 "BFF0 20 52 65 61 64 79 3F 0D 00 53 41 56 45 09 09 00"
].forEach(function(v){
  var t=v.split(/ +/);
  var a=parseInt(t[0],16);
  var i;
  for(i=1;i<t.length;i++)
    pc8001.memory[a+i-1]=parseInt(t[i],16);
});
pc8001.initDisplay80x25=function(svg){
  var d=pc8001.display=new Object();
  var t=d.textArray=new Array(80);
  var x,y,e;
  d.svg=svg;
  d.colors=new Array(256);
  d.colors.fill("none");
  for(x=0;x<8;x++){
    d.colors[0x18+x]="#000000";
    d.colors[0x38+x]="#0000ff";
    d.colors[0x58+x]="#ff0000";
    d.colors[0x78+x]="#ff00ff";
    d.colors[0x98+x]="#00ff00";
    d.colors[0xb8+x]="#00ffff";
    d.colors[0xd8+x]="#ffff00";
    d.colors[0xf8+x]="#ffffff";
  }
  d.colors[0x00]="#ffffff";
  for(x=0;x<80;x++)
    t[x]=new Array(25);
  d.start=d.end=0xf300;
  for(y=0;y<25;y++){
    for(x=0;x<80;x++){
      pc8001.memory[d.end]=0;
      d.end++;
      t[x][y]=new Object();
      e=document.createElementNS("http://www.w3.org/2000/svg","text");
      e.setAttribute("y",x*2);
      e.setAttribute("x",y*4);
      e.setAttribute("font-family","monospace");
      e.setAttribute("font-size",2);
      e.setAttribute("transform","matrix(0 1 1 0 1.8 0)");
      e.setAttribute("fill","#ffffff");
      e.setAttribute("stroke","none");
      d.svg.appendChild(e);
      t[x][y].element=e;
      t[x][y].attribute="#ffffff";
    }
    pc8001.memory[d.end]=0;
    d.end++;
    for(x=1;x<39;x++){
      pc8001.memory[d.end]=(x%2==0)?80:0xf8;
      d.end++;
    }
    pc8001.memory[d.end]=0;
    d.end++;
  }
  d.end--;
  e=[[0x3000,0x2598,0x259d,0x2580],
     [0x2596,0x258c,0x259e,0x259b],
     [0x2597,0x259a,0x2590,0x259c],
     [0x2584,0x2599,0x259f,0x2588]];
  d.blocks=new Array(256);
  d.blocks[0]="";
  for(x=1;x<256;x++){
    if((x&0xcc)>0)
      d.blocks[x]=String.fromCodePoint(e[(x>>4)&3][x&3],e[(x>>6)&3][(x>>2)&3]);
    else
      d.blocks[x]=String.fromCodePoint(e[(x>>4)&3][x&3]);
  }
  pc8001.writeMemory(d.start,0xff);
  y=t[0][0].element.getBBox();
  pc8001.writeMemory(d.start,0);
  if(y.width<4){
    e[0][0]=0x2003;
    for(x=1;x<256;x++){
      if((x&0xcc)>0)
        d.blocks[x]=String.fromCodePoint(e[(x>>4)&3][x&3],e[(x>>6)&3][(x>>2)&3]);
      else
        d.blocks[x]=String.fromCodePoint(e[(x>>4)&3][x&3]);
    }
    e=4/y.width;
    for(y=0;y<25;y++){
      for(x=0;x<80;x++){
        t[x][y].element.setAttribute("x",y*4/e);
        t[x][y].element.setAttribute("transform","matrix(0 "+e+" 1 0 1.8 0)");
      }
    }
  }
}
pc8001.writeMemory=function(address,data){
  var t=pc8001.memory[address];
  var d=pc8001.display;
  var x,y,i,j;
  pc8001.memory[address]=data;
  if(address<d.start||d.end<address||t==data)
    return;
  x=(address-d.start)%120;
  y=Math.floor((address-d.start)/120);
  if(x<80){
    d.textArray[x][y].element.textContent=d.blocks[data];
    return;
  }
  i=d.start+80+y*120;
  j="#ffffff";
  for(x=0;x<80;x++){
    if(pc8001.memory[i]==x){
      i++;
      j=d.colors[pc8001.memory[i]];
      i++;
    }
    t=d.textArray[x][y];
    if(t.attribute!=j){
      t.element.setAttribute("fill",j);
      t.attribute=j;
    }
  }
}
pc8001.inports=new Array(256);
pc8001.inports.fill(0xff);
pc8001.keymap=new Array(256);
pc8001.keymap.fill([-1,0xff]);
pc8001.keymap[13]=[1,0x7f];                    // enter-key
pc8001.keymap[97]=pc8001.keymap[188]=[0,0xfd]; // ten-key 1 = key <
pc8001.keymap[98]=pc8001.keymap[40]=[0,0xfb];  // ten-key 2 = downarrow
pc8001.keymap[99]=pc8001.keymap[190]=[0,0xf7]; // ten-key 3 = key >
pc8001.keymap[100]=pc8001.keymap[37]=[0,0xef]; // ten-key 4 = leftarrow
pc8001.keymap[102]=pc8001.keymap[39]=[0,0xbf]; // ten-key 6 = rightarrow
pc8001.keymap[104]=pc8001.keymap[38]=[1,0xfe]; // ten-key 8 = uparrow
pc8001.keymap[16]=[8,0xbf];                    // shift-key
pc8001.keymap[32]=[9,0xbf];                    // space-key
pc8001.keydown=function(event){
  var k=pc8001.keymap[event.keyCode]
  if(k[0]<0)
    return;
  pc8001.inports[k[0]]&=k[1];
}
pc8001.keyup=function(event){
  var k=pc8001.keymap[event.keyCode]
  if(k[0]<0)
    return;
  pc8001.inports[k[0]]|=(k[1]^0xff);
  if(pc8001.beep.counter<0){
    pc8001.beep.counter=pc8001.beep.on=0;
    pc8001.beep.start=pc8001.z80.states;
    pc8001.beep.oscillator.start();
  }
}
pc8001.beep=new Object();
pc8001.beep.audio=new(window.AudioContext||window.webkitAudioContext)();
pc8001.beep.buffer=pc8001.beep.audio.createBuffer(1,Math.floor(pc8001.beep.audio.sampleRate/60),pc8001.beep.audio.sampleRate);
pc8001.beep.oscillator=pc8001.beep.audio.createBufferSource();
pc8001.beep.oscillator.buffer=pc8001.beep.buffer;
pc8001.beep.wave=pc8001.beep.buffer.getChannelData(0);
pc8001.beep.wave.fill(0);
pc8001.beep.counter=-1;
pc8001.beep.oscillator.loop=true;
pc8001.beep.oscillator.connect(pc8001.beep.audio.destination);
pc8001.beep.refWave=new Array(pc8001.beep.wave.length);
pc8001.beep.refWave.fill(0);
pc8001.beep.refWave.forEach(function(v,i,a){
  a[i]=Math.sin(i*Math.PI*2/pc8001.beep.audio.sampleRate*2400);
});
pc8001.z80=new Object();
pc8001.z80.frequency=3000000;                  // down to 3MHz
pc8001.z80.millistates=pc8001.z80.frequency/1000;
pc8001.z80.regs={"PC":0,"SP":0,"A":0,"B":0,"C":0,"D":0,"E":0,"H":0,"L":0,"J":0,"X":0,"K":0,"Y":0,"a":0,"b":0,"c":0,"d":0,"e":0,"h":0,"l":0};
pc8001.z80.flags={"Z":0,"C":0,"V":0,"M":0,"z":0,"c":0,"v":0,"m":0};
pc8001.z80.mnemonics={};
pc8001.z80.halt=pc8001.z80.states=0;
pc8001.z80.ops=new Array(256);
pc8001.z80.ops.fill(["UNDEF","",0]);
pc8001.z80.ops[0xcb]=new Array(257);
pc8001.z80.ops[0xcb].fill(["UNDEF","CB",0]);
pc8001.z80.ops[0xcb][256]=-1;
pc8001.z80.ops[0xdd]=new Array(257);
pc8001.z80.ops[0xdd].fill(["UNDEF","DD",0]);
pc8001.z80.ops[0xdd][256]=-1;
pc8001.z80.ops[0xed]=new Array(257);
pc8001.z80.ops[0xed].fill(["UNDEF","ED",0]);
pc8001.z80.ops[0xed][256]=-1;
pc8001.z80.ops[0xfd]=new Array(257);
pc8001.z80.ops[0xfd].fill(["UNDEF","FD",0]);
pc8001.z80.ops[0xfd][256]=-1;
pc8001.z80.mnemonics["UNDEF"]=function(x,m){
  pc8001.z80.regs["PC"]=(pc8001.z80.regs["PC"]+0xffff)&0xffff;
  pc8001.z80.halt=1;
  console.log(performance.now()-pc8001.z80.millitimer,"milliseconds");
  console.log(pc8001.z80.states,"states");
  console.log(m[0],m[1],x.toString(16).toUpperCase().padStart(2,"0"));
  Object.keys(pc8001.z80.regs).forEach(function(v){
    console.log(" reg",v,pc8001.z80.regs[v].toString(16).toUpperCase().padStart(v.length*2,"0"));
  });
  console.log(" flags",pc8001.z80.flags);
}
pc8001.z80.ops[0x00]=["NOP",4];
pc8001.z80.mnemonics["NOP"]=function(x,m){
}
pc8001.operators=["ADD","ADC","SUB","SBC","AND","XOR","OR","CP"];
pc8001.params=["B","C","D","E","H","L","(HL)","A"];
pc8001.params.forEach(function(v,i,a){
  var j;
  for(j=0;j<8;j++)
    pc8001.z80.ops[i*8+j+0x40]=["LD",v,a[j],(i==6||j==6)?7:4];
  pc8001.z80.ops[i*8+4]=["INC",v,(i==6)?11:4];
  pc8001.z80.ops[i*8+5]=["DEC",v,(i==6)?11:4];
  pc8001.z80.ops[i*8+6]=["LD",v,"n",(i==6)?10:7];
  pc8001.operators.forEach(function(w,j){
    pc8001.z80.ops[i+j*8+0x80]=[w,"A",v,(i==6)?7:4];
  });
  if(i!=6){
    pc8001.z80.ops[0xdd][i*8+0x46]=["LD",v,"(JX+d)",19];
    pc8001.z80.ops[0xdd][i+0x70]=["LD","(JX+d)",v,19];
    pc8001.z80.ops[0xdd][i*8+0x44]=["LD",v,"J",8];
    pc8001.z80.ops[0xdd][i*8+0x45]=["LD",v,"X",8];
    pc8001.z80.ops[0xdd][i+0x60]=["LD","J",v,8];
    pc8001.z80.ops[0xdd][i+0x68]=["LD","X",v,8];
    pc8001.z80.ops[0xfd][i*8+0x46]=["LD",v,"(KY+d)",19];
    pc8001.z80.ops[0xfd][i+0x70]=["LD","(KY+d)",v,19];
    pc8001.z80.ops[0xfd][i*8+0x44]=["LD",v,"K",8];
    pc8001.z80.ops[0xfd][i*8+0x45]=["LD",v,"Y",8];
    pc8001.z80.ops[0xfd][i+0x60]=["LD","K",v,8];
    pc8001.z80.ops[0xfd][i+0x68]=["LD","Y",v,8];
    pc8001.z80.ops[0xed][i*8+0x40]=["IN",v,"(C)",12];
    pc8001.z80.ops[0xed][i*8+0x41]=["OUT","(C)",v,12];
  }
  pc8001.z80.ops[0xcb][i+0x00]=["RLC",v,(i==6)?15:8];
  pc8001.z80.ops[0xcb][i+0x08]=["RRC",v,(i==6)?15:8];
  pc8001.z80.ops[0xcb][i+0x10]=["RL",v,(i==6)?15:8];
  pc8001.z80.ops[0xcb][i+0x18]=["RR",v,(i==6)?15:8];
  pc8001.z80.ops[0xcb][i+0x20]=["SLA",v,(i==6)?15:8];
  pc8001.z80.ops[0xcb][i+0x28]=["SRA",v,(i==6)?15:8];
  pc8001.z80.ops[0xcb][i+0x30]=["SLL",v,(i==6)?15:8];
  pc8001.z80.ops[0xcb][i+0x38]=["SRL",v,(i==6)?15:8];
  for(j=0;j<8;j++){
    pc8001.z80.ops[0xcb][i+j*8+0x40]=["BIT",j,v,(i==6)?12:8];
    pc8001.z80.ops[0xcb][i+j*8+0x80]=["RES",j,v,(i==6)?15:8];
    pc8001.z80.ops[0xcb][i+j*8+0xc0]=["SET",j,v,(i==6)?15:8];
  }
});
pc8001.operators.forEach(function(v,i){
  pc8001.z80.ops[i*8+0xc6]=[v,"A","n",7];
  pc8001.z80.ops[0xdd][i*8+0x86]=[v,"A","(JX+d)",19];
  pc8001.z80.ops[0xfd][i*8+0x86]=[v,"A","(KY+d)",19];
});
pc8001.z80.ops[0x76]=["HALT","",4];
pc8001.z80.mnemonics["HALT"]=pc8001.z80.mnemonics["UNDEF"];
pc8001.z80.ops[0x02]=["LD","(BC)","A",7];
pc8001.z80.ops[0x0a]=["LD","A","(BC)",7];
pc8001.z80.ops[0x12]=["LD","(DE)","A",7];
pc8001.z80.ops[0x1a]=["LD","A","(DE)",7];
pc8001.z80.ops[0x32]=["LD","(nn)","A",13];
pc8001.z80.ops[0x3a]=["LD","A","(nn)",13];
pc8001.z80.ops[0xdd][0x26]=["LD","J","n",11];
pc8001.z80.ops[0xdd][0x2e]=["LD","X","n",11];
pc8001.z80.ops[0xdd][0x36]=["LD","(JX+d)","n",19];
pc8001.z80.ops[0xdd][0x64]=["LD","J","J",8];
pc8001.z80.ops[0xdd][0x65]=["LD","J","X",8];
pc8001.z80.ops[0xdd][0x6c]=["LD","X","J",8];
pc8001.z80.ops[0xdd][0x6d]=["LD","X","X",8];
pc8001.z80.ops[0xfd][0x26]=["LD","K","n",11];
pc8001.z80.ops[0xfd][0x2e]=["LD","Y","n",11];
pc8001.z80.ops[0xfd][0x36]=["LD","(KY+d)","n",19];
pc8001.z80.ops[0xfd][0x64]=["LD","K","K",8];
pc8001.z80.ops[0xfd][0x65]=["LD","K","Y",8];
pc8001.z80.ops[0xfd][0x6c]=["LD","Y","K",8];
pc8001.z80.ops[0xfd][0x6d]=["LD","Y","Y",8];
pc8001.z80.mnemonics["LD"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a=-1;
  var b,c;
  switch(m[1].length){
    case 4:
      if(m[1]=="(nn)"){
        a=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
        pc8001.z80.regs["PC"]=pc=(pc+2)&0xffff;
      }
      else
        a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
  }
  switch(m[2].length){
    case 1:
      if(m[2]=="n"){
        c=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        c=pc8001.z80.regs[m[2]];
      break;
    case 4:
      if(m[2]=="(nn)"){
        b=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
        pc8001.z80.regs["PC"]=pc=(pc+2)&0xffff;
      }
      else
        b=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      c=pc8001.memory[b];
      break;
    case 6:
      b=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(b>0x7f)
        b+=0xff00;
      b+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      c=pc8001.memory[b&0xffff];
  }
  if(a<0)
    pc8001.z80.regs[m[1]]=c;
  else
    pc8001.writeMemory(a,c);
}
pc8001.z80.ops[0x01]=["LD16","BC","nn",10];
pc8001.z80.ops[0x11]=["LD16","DE","nn",10];
pc8001.z80.ops[0x21]=["LD16","HL","nn",10];
pc8001.z80.ops[0x22]=["LD16","(nn)","HL",16];
pc8001.z80.ops[0x2a]=["LD16","HL","(nn)",16];
pc8001.z80.ops[0x31]=["LD16","SP","nn",10];
pc8001.z80.ops[0xf9]=["LD16","SP","HL",6];
pc8001.z80.ops[0xed][0x43]=["LD16","(nn)","BC",20];
pc8001.z80.ops[0xed][0x4b]=["LD16","BC","(nn)",20];
pc8001.z80.ops[0xed][0x53]=["LD16","(nn)","DE",20];
pc8001.z80.ops[0xed][0x5b]=["LD16","DE","(nn)",20];
pc8001.z80.ops[0xed][0x63]=["LD16","(nn)","HL",20];
pc8001.z80.ops[0xed][0x6b]=["LD16","HL","(nn)",20];
pc8001.z80.ops[0xed][0x73]=["LD16","(nn)","SP",20];
pc8001.z80.ops[0xed][0x7b]=["LD16","SP","(nn)",20];
pc8001.z80.ops[0xdd][0x21]=["LD16","JX","nn",14];
pc8001.z80.ops[0xdd][0xf9]=["LD16","SP","JX",10];
pc8001.z80.ops[0xfd][0x21]=["LD16","KY","nn",14];
pc8001.z80.ops[0xfd][0xf9]=["LD16","SP","KY",10];
pc8001.z80.mnemonics["LD16"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var h,l,a;
  switch(m[2]){
    case "nn":
      l=pc8001.memory[pc];
      h=pc8001.memory[(pc+1)&0xffff];
      pc=pc8001.z80.regs["PC"]=(pc+2)&0xffff;
      break;
    case "(nn)":
      a=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
      pc=pc8001.z80.regs["PC"]=(pc+2)&0xffff;
      l=pc8001.memory[a];
      h=pc8001.memory[(a+1)&0xffff];
      break;
    case "SP":
      a=pc8001.z80.regs["SP"];
      h=a>>8;
      l=a&0xff;
      break;
    default:
      h=pc8001.z80.regs[m[2].substr(0,1)];
      l=pc8001.z80.regs[m[2].substr(1)];
  }
  switch(m[1]){
    case "(nn)":
      a=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
      pc=pc8001.z80.regs["PC"]=(pc+2)&0xffff;
      pc8001.writeMemory(a,l);
      pc8001.writeMemory((a+1)&0xffff,h);
      return;
    case "SP":
      pc8001.z80.regs["SP"]=h*256+l;
      return;
    default:
      pc8001.z80.regs[m[1].substr(0,1)]=h;
      pc8001.z80.regs[m[1].substr(1)]=l;
  }
}
pc8001.z80.ops[0x08]=["EX","AF","af",4];
pc8001.z80.ops[0xe3]=["EX","(SP)","HL",19];
pc8001.z80.ops[0xeb]=["EX","DE","HL",4];
pc8001.z80.mnemonics["EX"]=function(x,m){
  var a,t;
  if(m[1]=="(SP)"){
    a=pc8001.z80.regs["SP"]
    t=pc8001.memory[a];
    pc8001.writeMemory(a,pc8001.z80.regs[m[2].substr(1)]);
    pc8001.z80.regs[m[2].substr(1)]=t;
    a=(a+1)&0xffff;
    t=pc8001.memory[a];
    pc8001.writeMemory(a,pc8001.z80.regs[m[2].substr(0,1)]);
    pc8001.z80.regs[m[2].substr(0,1)]=t;
    return;
  }
  t=pc8001.z80.regs[m[1].substr(0,1)];
  pc8001.z80.regs[m[1].substr(0,1)]=pc8001.z80.regs[m[2].substr(0,1)];
  pc8001.z80.regs[m[2].substr(0,1)]=t;
  if(m[1].substr(1)=="F"){
    a=["Z","C","V","M"];
    a.forEach(function(v){
      var b=pc8001.z80.flags[v];
      pc8001.z80.flags[v]=pc8001.z80.flags[v.toLowerCase()];
      pc8001.z80.flags[v.toLowerCase()]=b;
    });
    return;
  }
  t=pc8001.z80.regs[m[1].substr(1)];
  pc8001.z80.regs[m[1].substr(1)]=pc8001.z80.regs[m[2].substr(1)];
  pc8001.z80.regs[m[2].substr(1)]=t;
}
pc8001.z80.ops[0xd9]=["EXX",4];
pc8001.z80.mnemonics["EXX"]=function(x,m){
  var r=["B","C","D","E","H","L"];
  r.forEach(function(v){
    var t=pc8001.z80.regs[v];
    pc8001.z80.regs[v]=pc8001.z80.regs[v.toLowerCase()];
    pc8001.z80.regs[v.toLowerCase()]=t;
  });
}
pc8001.z80.ops[0xdd][0x34]=["INC","(JX+d)",23];
pc8001.z80.ops[0xfd][0x34]=["INC","(KY+d)",23];
pc8001.z80.mnemonics["INC"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a,t;
  switch(m[1].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  t=(t+1)&0xff;
  if(a<0)
    pc8001.z80.regs[m[1]]=t;
  else
    pc8001.writeMemory(a,t);
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  pc8001.z80.flags["V"]=(t==0x80)?1:0;
}
pc8001.z80.ops[0x03]=["INC16","BC",6];
pc8001.z80.ops[0x13]=["INC16","DE",6];
pc8001.z80.ops[0x23]=["INC16","HL",6];
pc8001.z80.ops[0x33]=["INC16","SP",6];
pc8001.z80.ops[0xdd][0x23]=["INC16","JX",10];
pc8001.z80.ops[0xfd][0x23]=["INC16","KY",10];
pc8001.z80.mnemonics["INC16"]=function(x,m){
  var t;
  if(m[1]=="SP")
    pc8001.z80.regs["SP"]=(pc8001.z80.regs["SP"]+1)&0xffff;
  else{
    pc8001.z80.regs[m[1].substr(1)]=t=(pc8001.z80.regs[m[1].substr(1)]+1)&0xff;
    if(t==0)
      pc8001.z80.regs[m[1].substr(0,1)]=(pc8001.z80.regs[m[1].substr(0,1)]+1)&0xff;
  }
}
pc8001.z80.ops[0xdd][0x35]=["DEC","(JX+d)",23];
pc8001.z80.ops[0xfd][0x35]=["DEC","(KY+d)",23];
pc8001.z80.mnemonics["DEC"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a,t;
  switch(m[1].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  t=(t+0xff)&0xff;
  if(a<0)
    pc8001.z80.regs[m[1]]=t;
  else
    pc8001.writeMemory(a,t);
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  pc8001.z80.flags["V"]=(t==0x7f)?1:0;
}
pc8001.z80.ops[0x0b]=["DEC16","BC",6];
pc8001.z80.ops[0x1b]=["DEC16","DE",6];
pc8001.z80.ops[0x2b]=["DEC16","HL",6];
pc8001.z80.ops[0x3b]=["DEC16","SP",6];
pc8001.z80.ops[0xdd][0x2b]=["DEC16","JX",6];
pc8001.z80.ops[0xfd][0x2b]=["DEC16","KY",6];
pc8001.z80.mnemonics["DEC16"]=function(x,m){
  var t;
  if(m[1]=="SP")
    pc8001.z80.regs["SP"]=(pc8001.z80.regs["SP"]+0xffff)&0xffff;
  else{
    pc8001.z80.regs[m[1].substr(1)]=t=(pc8001.z80.regs[m[1].substr(1)]+0xff)&0xff;
    if(t==0xff)
      pc8001.z80.regs[m[1].substr(0,1)]=(pc8001.z80.regs[m[1].substr(0,1)]+0xff)&0xff;
  }
}
pc8001.z80.ops[0x09]=["ADD16","HL","BC",11];
pc8001.z80.ops[0x19]=["ADD16","HL","DE",11];
pc8001.z80.ops[0x29]=["ADD16","HL","HL",11];
pc8001.z80.ops[0x39]=["ADD16","HL","SP",11];
pc8001.z80.ops[0xdd][0x09]=["ADD16","JX","BC",15];
pc8001.z80.ops[0xdd][0x19]=["ADD16","JX","DE",15];
pc8001.z80.ops[0xdd][0x29]=["ADD16","JX","JX",15];
pc8001.z80.ops[0xdd][0x39]=["ADD16","JX","SP",15];
pc8001.z80.ops[0xfd][0x09]=["ADD16","KY","BC",15];
pc8001.z80.ops[0xfd][0x19]=["ADD16","KY","DE",15];
pc8001.z80.ops[0xfd][0x29]=["ADD16","KY","KY",15];
pc8001.z80.ops[0xfd][0x39]=["ADD16","KY","SP",15];
pc8001.z80.mnemonics["ADD16"]=function(x,m){
  var t;
  t=pc8001.z80.regs[m[1].substr(0,1)]*256+pc8001.z80.regs[m[1].substr(1)];
  if(m[2]=="SP")
    t+=pc8001.z80.regs["SP"];
  else
    t+=pc8001.z80.regs[m[2].substr(0,1)]*256+pc8001.z80.regs[m[2].substr(1)];
  if(t>0xffff){
    pc8001.z80.flags["C"]=1;
    t&=0xffff;
  }
  else
    pc8001.z80.flags["C"]=0;
  pc8001.z80.regs[m[1].substr(0,1)]=t>>8;
  pc8001.z80.regs[m[1].substr(1)]=t&0xff;
}
pc8001.z80.mnemonics["ADD"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a,t,u,v;
  switch(m[2].length){
    case 1:
      if(m[2]=="n"){
        t=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        t=pc8001.z80.regs[m[2]];
      break;
    case 4:
      t=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  u=pc8001.z80.regs[m[1]];
  v=t+u;
  pc8001.z80.flags["C"]=(v>0xff)?1:0;
  v&=0xff;
  pc8001.z80.regs[m[1]]=v;
  pc8001.z80.flags["Z"]=(v==0)?1:0;
  pc8001.z80.flags["M"]=(v>0x7f)?1:0;
  pc8001.z80.flags["V"]=((t>0x7f&&u>0x7f&&v<0x80)||(t<0x80&&u<0x80&&v>0x7f))?1:0;
}
pc8001.z80.ops[0xed][0x4a]=["ADC16","HL","BC",15]
pc8001.z80.ops[0xed][0x5a]=["ADC16","HL","DE",15]
pc8001.z80.ops[0xed][0x6a]=["ADC16","HL","HL",15]
pc8001.z80.ops[0xed][0x7a]=["ADC16","HL","SP",15]
pc8001.z80.mnemonics["ADC16"]=function(x,m){
  var t,u,v;
  t=pc8001.z80.regs[m[1].substr(0,1)]*256+pc8001.z80.regs[m[1].substr(1)];
  if(m[2]=="SP")
    u=pc8001.z80.regs["SP"];
  else
    u=pc8001.z80.regs[m[2].substr(0,1)]*256+pc8001.z80.regs[m[2].substr(1)];
  v=t+u+pc8001.z80.flags["C"]
  if(v>0xffff){
    pc8001.z80.flags["C"]=1;
    v&=0xffff;
  }
  else
    pc8001.z80.flags["C"]=0;
  pc8001.z80.regs[m[1].substr(0,1)]=v>>8;
  pc8001.z80.regs[m[1].substr(1)]=v&0xff;
  pc8001.z80.flags["Z"]=(v==0)?1:0;
  pc8001.z80.flags["M"]=(v>0x7fff)?1:0;
  pc8001.z80.flags["V"]=((u<0x8000&&t<0x8000&&v>0x7fff)||(u>0x7fff&&t>0x7fff&&v<0x8000))?1:0;
}
pc8001.z80.mnemonics["ADC"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a,t,u,v;
  switch(m[2].length){
    case 1:
      if(m[2]=="n"){
        t=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        t=pc8001.z80.regs[m[2]];
      break;
    case 4:
      t=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  u=pc8001.z80.regs[m[1]];
  v=t+u+pc8001.z80.flags["C"];
  pc8001.z80.flags["C"]=(v>0xff)?1:0;
  v&=0xff;
  pc8001.z80.regs[m[1]]=v;
  pc8001.z80.flags["Z"]=(v==0)?1:0;
  pc8001.z80.flags["M"]=(v>0x7f)?1:0;
  pc8001.z80.flags["V"]=((t>0x7f&&u>0x7f&&v<0x80)||(t<0x80&&u<0x80&&v>0x7f))?1:0;
}
pc8001.z80.ops[0xed][0x44]=["NEG","A",8];
pc8001.z80.mnemonics["NEG"]=function(x,m){
  var t=(256-pc8001.z80.regs[m[1]])&0xff;
  pc8001.z80.regs[m[1]]=t;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["C"]=(t==0)?0:1;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  pc8001.z80.flags["V"]=(t==0x80)?1:0;
}
pc8001.z80.mnemonics["SUB"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a,t,u,v;
  switch(m[2].length){
    case 1:
      if(m[2]=="n"){
        t=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        t=pc8001.z80.regs[m[2]];
      break;
    case 4:
      t=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  u=pc8001.z80.regs[m[1]];
  v=u-t;
  pc8001.z80.flags["C"]=(v<0)?1:0;
  v=(v+256)&0xff;
  pc8001.z80.regs[m[1]]=v;
  pc8001.z80.flags["Z"]=(v==0)?1:0;
  pc8001.z80.flags["M"]=(v>0x7f)?1:0;
  pc8001.z80.flags["V"]=((u<0x80&&t>0x7f&&v>0x7f)||(u>0x7f&&t<0x80&&v<0x80))?1:0;
}
pc8001.z80.ops[0xed][0x42]=["SBC16","HL","BC",15]
pc8001.z80.ops[0xed][0x52]=["SBC16","HL","DE",15]
pc8001.z80.ops[0xed][0x62]=["SBC16","HL","HL",15]
pc8001.z80.ops[0xed][0x72]=["SBC16","HL","SP",15]
pc8001.z80.mnemonics["SBC16"]=function(x,m){
  var t,u,v;
  t=pc8001.z80.regs[m[1].substr(0,1)]*256+pc8001.z80.regs[m[1].substr(1)];
  if(m[2]=="SP")
    u=pc8001.z80.regs["SP"];
  else
    u=pc8001.z80.regs[m[2].substr(0,1)]*256+pc8001.z80.regs[m[2].substr(1)];
  v=t-u-pc8001.z80.flags["C"]
  if(v<0){
    pc8001.z80.flags["C"]=1;
    v=(v+65536)&0xffff;
  }
  else
    pc8001.z80.flags["C"]=0;
  pc8001.z80.regs[m[1].substr(0,1)]=v>>8;
  pc8001.z80.regs[m[1].substr(1)]=v&0xff;
  pc8001.z80.flags["Z"]=(v==0)?1:0;
  pc8001.z80.flags["M"]=(v>0x7fff)?1:0;
  pc8001.z80.flags["V"]=((u<0x8000&&t>0x7fff&&v>0x7fff)||(u>0x7fff&&t<0x8000&&v<0x8000))?1:0;
}
pc8001.z80.mnemonics["SBC"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a,t,u,v;
  switch(m[2].length){
    case 1:
      if(m[2]=="n"){
        t=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        t=pc8001.z80.regs[m[2]];
      break;
    case 4:
      t=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  u=pc8001.z80.regs[m[1]];
  v=u-t-pc8001.z80.flags["C"];
  pc8001.z80.flags["C"]=(v<0)?1:0;
  v=(v+256)&0xff;
  pc8001.z80.regs[m[1]]=v;
  pc8001.z80.flags["Z"]=(v==0)?1:0;
  pc8001.z80.flags["M"]=(v>0x7f)?1:0;
  pc8001.z80.flags["V"]=((u<0x80&&t>0x7f&&v>0x7f)||(u>0x7f&&t<0x80&&v<0x80))?1:0;
}
pc8001.z80.mnemonics["AND"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a,t;
  switch(m[2].length){
    case 1:
      if(m[2]=="n"){
        t=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        t=pc8001.z80.regs[m[2]];
      break;
    case 4:
      t=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  t&=pc8001.z80.regs[m[1]];
  pc8001.z80.regs[m[1]]=t;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  pc8001.z80.flags["C"]=0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.ops[0x2f]=["CPL","A",4];
pc8001.z80.mnemonics["CPL"]=function(x,m){
  pc8001.z80.regs[m[1]]^=0xff;
}
pc8001.z80.mnemonics["XOR"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a,t;
  switch(m[2].length){
    case 1:
      if(m[2]=="n"){
        t=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        t=pc8001.z80.regs[m[2]];
      break;
    case 4:
      t=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  t^=pc8001.z80.regs[m[1]];
  pc8001.z80.regs[m[1]]=t;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  pc8001.z80.flags["C"]=0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.mnemonics["OR"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a,t;
  switch(m[2].length){
    case 1:
      if(m[2]=="n"){
        t=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        t=pc8001.z80.regs[m[2]];
      break;
    case 4:
      t=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  t|=pc8001.z80.regs[m[1]];
  pc8001.z80.regs[m[1]]=t;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  pc8001.z80.flags["C"]=0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.mnemonics["CP"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var a,t,u,v;
  switch(m[2].length){
    case 1:
      if(m[2]=="n"){
        t=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        t=pc8001.z80.regs[m[2]];
      break;
    case 4:
      t=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  u=pc8001.z80.regs[m[1]];
  v=u-t;
  pc8001.z80.flags["C"]=(v<0)?1:0;
  v=(v+256)&0xff;
  pc8001.z80.flags["Z"]=(v==0)?1:0;
  pc8001.z80.flags["M"]=(v>0x7f)?1:0;
  pc8001.z80.flags["V"]=((u<0x80&&t>0x7f&&v>0x7f)||(u>0x7f&&t<0x80&&v<0x80))?1:0;
}
pc8001.z80.ops[0x37]=["SCF",4];
pc8001.z80.mnemonics["SCF"]=function(x,m){
  pc8001.z80.flags["C"]=1;
}
pc8001.z80.ops[0x3f]=["CCF",4];
pc8001.z80.mnemonics["CCF"]=function(x,m){
  pc8001.z80.flags["C"]^=1;
}
pc8001.z80.ops[0xc2]=["JP","NZ","nn",10];
pc8001.z80.ops[0xc3]=["JP","","nn",10];
pc8001.z80.ops[0xca]=["JP","Z","nn",10];
pc8001.z80.ops[0xd2]=["JP","NC","nn",10];
pc8001.z80.ops[0xda]=["JP","C","nn",10];
pc8001.z80.ops[0xe2]=["JP","NV","nn",10];
pc8001.z80.ops[0xea]=["JP","V","nn",10];
pc8001.z80.ops[0xf2]=["JP","NM","nn",10];
pc8001.z80.ops[0xfa]=["JP","M","nn",10];
pc8001.z80.ops[0xe9]=["JP","","(HL)",4];
pc8001.z80.ops[0xdd][0xe9]=["JP","","(JX)",8];
pc8001.z80.ops[0xfd][0xe9]=["JP","","(KY)",8];
pc8001.z80.mnemonics["JP"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var c=1;
  switch(m[1].length){
    case 1:
      c=pc8001.z80.flags[m[1]];
      break;
    case 2:
      c=1-pc8001.z80.flags[m[1].substr(1)];
  }
  if(c==0){
    if(m[2]=="nn")
      pc8001.z80.regs["PC"]=(pc+2)&0xffff;
    return;
  }
  switch(m[2].length){
    case 2:
      pc8001.z80.regs["PC"]=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
      return;
    case 4:
      pc8001.z80.regs["PC"]=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      return;
  }
}
pc8001.z80.ops[0x10]=["JR","DJNZ","e",13];
pc8001.z80.ops[0x18]=["JR","","e",12];
pc8001.z80.ops[0x20]=["JR","NZ","e",12];
pc8001.z80.ops[0x28]=["JR","Z","e",12];
pc8001.z80.ops[0x30]=["JR","NC","e",12];
pc8001.z80.ops[0x38]=["JR","C","e",12];
pc8001.z80.mnemonics["JR"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var c=1;
  switch(m[1].length){
    case 1:
      c=pc8001.z80.flags[m[1]];
      break;
    case 2:
      c=1-pc8001.z80.flags[m[1].substr(1)];
      break;
    case 4:
      pc8001.z80.regs["B"]=c=(pc8001.z80.regs["B"]+0xff)&0xff;
  }
  if(c==0){
    if(m[2]=="e")
      pc8001.z80.regs["PC"]=(pc+1)&0xffff;
    return;
  }
  c=pc8001.memory[pc];
  pc8001.z80.regs["PC"]=((c>0x7f)?pc+0xff01+c:pc+1+c)&0xffff;
}
pc8001.z80.ops[0xc4]=["CALL","NZ","nn",17];
pc8001.z80.ops[0xc7]=["CALL","","0000",11];
pc8001.z80.ops[0xcc]=["CALL","Z","nn",17];
pc8001.z80.ops[0xcd]=["CALL","","nn",17];
pc8001.z80.ops[0xcf]=["CALL","","0008",11];
pc8001.z80.ops[0xd4]=["CALL","NC","nn",17];
pc8001.z80.ops[0xd7]=["CALL","","0010",11];
pc8001.z80.ops[0xdc]=["CALL","C","nn",17];
pc8001.z80.ops[0xdf]=["CALL","","0018",11];
pc8001.z80.ops[0xe4]=["CALL","NV","nn",17];
pc8001.z80.ops[0xe7]=["CALL","","0020",11];
pc8001.z80.ops[0xec]=["CALL","V","nn",17];
pc8001.z80.ops[0xef]=["CALL","","0028",11];
pc8001.z80.ops[0xf4]=["CALL","NM","nn",17];
pc8001.z80.ops[0xf7]=["CALL","","0030",11];
pc8001.z80.ops[0xfc]=["CALL","M","nn",17];
pc8001.z80.ops[0xff]=["CALL","","0038",11];
pc8001.z80.mnemonics["CALL"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var sp=pc8001.z80.regs["SP"];
  var c=1;
  switch(m[1].length){
    case 1:
      c=pc8001.z80.flags[m[1]];
      break;
    case 2:
      c=1-pc8001.z80.flags[m[1].substr(1)];
  }
  if(c==0){
    if(m[2]=="nn")
      pc8001.z80.regs["PC"]=(pc+2)&0xffff;
    return;
  }
  if(m[2]=="nn"){
    a=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
    pc=(pc+2)&0xffff;
  }
  else
    a=parseInt(m[2],16);
  pc8001.writeMemory((sp+0xffff)&0xffff,pc>>8);
  pc8001.z80.regs["SP"]=sp=(sp+0xfffe)&0xffff;
  pc8001.writeMemory(sp,pc&0xff);
  pc8001.z80.regs["PC"]=a;
}
pc8001.z80.ops[0xc0]=["RET","NZ",11];
pc8001.z80.ops[0xc8]=["RET","Z",11];
pc8001.z80.ops[0xc9]=["RET","",10];
pc8001.z80.ops[0xd0]=["RET","NC",11];
pc8001.z80.ops[0xd8]=["RET","C",11];
pc8001.z80.ops[0xe0]=["RET","NV",11];
pc8001.z80.ops[0xe8]=["RET","V",11];
pc8001.z80.ops[0xf0]=["RET","NM",11];
pc8001.z80.ops[0xf8]=["RET","M",11];
pc8001.z80.mnemonics["RET"]=function(x,m){
  var sp=pc8001.z80.regs["SP"];
  var c=1;
  switch(m[1].length){
    case 1:
      c=pc8001.z80.flags[m[1]];
      break;
    case 2:
      c=1-pc8001.z80.flags[m[1].substr(1)];
  }
  if(c==0)
    return;
  pc8001.z80.regs["PC"]=pc8001.memory[sp]+pc8001.memory[(sp+1)&0xffff]*256;
  pc8001.z80.regs["SP"]=(sp+2)&0xffff;
}
pc8001.z80.ops[0xc5]=["PUSH","BC",11];
pc8001.z80.ops[0xd5]=["PUSH","DE",11];
pc8001.z80.ops[0xe5]=["PUSH","HL",11];
pc8001.z80.ops[0xf5]=["PUSH","AF",11];
pc8001.z80.ops[0xdd][0xe5]=["PUSH","JX",15];
pc8001.z80.ops[0xfd][0xe5]=["PUSH","KY",15];
pc8001.z80.mnemonics["PUSH"]=function(x,m){
  var sp=pc8001.z80.regs["SP"];
  pc8001.writeMemory((sp+0xffff)&0xffff,pc8001.z80.regs[m[1].substr(0,1)]);
  pc8001.z80.regs["SP"]=sp=(sp+0xfffe)&0xffff;
  if(m[1]=="AF")
    pc8001.writeMemory(sp,pc8001.z80.flags["C"]+(pc8001.z80.flags["V"]<<2)+(pc8001.z80.flags["Z"]<<6)+(pc8001.z80.flags["M"]<<7));
  else
    pc8001.writeMemory(sp,pc8001.z80.regs[m[1].substr(1)]);
}
pc8001.z80.ops[0xc1]=["POP","BC",10];
pc8001.z80.ops[0xd1]=["POP","DE",10];
pc8001.z80.ops[0xe1]=["POP","HL",10];
pc8001.z80.ops[0xf1]=["POP","AF",10];
pc8001.z80.ops[0xdd][0xe1]=["POP","JX",14];
pc8001.z80.ops[0xfd][0xe1]=["POP","KY",14];
pc8001.z80.mnemonics["POP"]=function(x,m){
  var sp=pc8001.z80.regs["SP"];
  var t=pc8001.memory[sp];
  if(m[1]=="AF"){
    pc8001.z80.flags["C"]=((t&1)==0)?0:1;
    pc8001.z80.flags["V"]=((t&4)==0)?0:1;
    pc8001.z80.flags["Z"]=((t&0x40)==0)?0:1;
    pc8001.z80.flags["M"]=((t&0x80)==0)?0:1;
  }
  else
    pc8001.z80.regs[m[1].substr(1)]=t;
  pc8001.z80.regs[m[1].substr(0,1)]=pc8001.memory[(sp+1)&0xffff];
  pc8001.z80.regs["SP"]=(sp+2)&0xffff;
}
pc8001.z80.ops[0x07]=["RLCA",4];
pc8001.z80.mnemonics["RLCA"]=function(x,m){
  var t=pc8001.z80.regs["A"];
  var c=(t>0x7f)?1:0;
  pc8001.z80.regs["A"]=((t<<1)+c)&0xff;
  pc8001.z80.flags["C"]=c;
}
pc8001.z80.mnemonics["RLC"]=function(x,m){
  var a,t,c;
  switch(m[1].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  c=(t>0x7f)?1:0;
  t=((t<<1)+c)&0xff;
  if(a<0)
    pc8001.z80.regs[m[1]]=t;
  else
    pc8001.writeMemory(a,t);
  pc8001.z80.flags["C"]=c;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.ops[0x0f]=["RRCA",4];
pc8001.z80.mnemonics["RRCA"]=function(x,m){
  var t=pc8001.z80.regs["A"];
  var c=t&1;
  pc8001.z80.regs["A"]=(t>>1)+c*0x80;
  pc8001.z80.flags["C"]=c;
}
pc8001.z80.mnemonics["RRC"]=function(x,m){
  var a,t,c;
  switch(m[1].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  c=t&1;
  t=(t>>1)+c*0x80;
  if(a<0)
    pc8001.z80.regs[m[1]]=t;
  else
    pc8001.writeMemory(a,t);
  pc8001.z80.flags["C"]=c;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.ops[0x17]=["RLA",4];
pc8001.z80.mnemonics["RLA"]=function(x,m){
  var t=pc8001.z80.regs["A"];
  var c=(t>0x7f)?1:0;
  pc8001.z80.regs["A"]=((t<<1)+pc8001.z80.flags["C"])&0xff;
  pc8001.z80.flags["C"]=c;
}
pc8001.z80.mnemonics["RL"]=function(x,m){
  var a,t,c;
  switch(m[1].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  c=(t>0x7f)?1:0;
  t=((t<<1)+pc8001.z80.flags["C"])&0xff;
  if(a<0)
    pc8001.z80.regs[m[1]]=t;
  else
    pc8001.writeMemory(a,t);
  pc8001.z80.flags["C"]=c;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.ops[0x1f]=["RRA",4];
pc8001.z80.mnemonics["RRA"]=function(x,m){
  var t=pc8001.z80.regs["A"];
  pc8001.z80.regs["A"]=(t>>1)+pc8001.z80.flags["C"]*0x80;
  pc8001.z80.flags["C"]=t&1;
}
pc8001.z80.mnemonics["RR"]=function(x,m){
  var a,t,c;
  switch(m[1].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  c=t&1;
  t=(t>>1)+pc8001.z80.flags["C"]*0x80;
  if(a<0)
    pc8001.z80.regs[m[1]]=t;
  else
    pc8001.writeMemory(a,t);
  pc8001.z80.flags["C"]=c;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.mnemonics["SLA"]=function(x,m){
  var a,t;
  switch(m[1].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  t=t<<1;
  pc8001.z80.flags["C"]=(t>0xff)?1:0;
  t&=0xff;
  if(a<0)
    pc8001.z80.regs[m[1]]=t;
  else
    pc8001.writeMemory(a,t);
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.mnemonics["SRA"]=function(x,m){
  var a,t;
  switch(m[1].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  pc8001.z80.flags["C"]=t&1;
  t=((t>>1)|(t&0x80));
  if(a<0)
    pc8001.z80.regs[m[1]]=t;
  else
    pc8001.writeMemory(a,t);
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.mnemonics["SLL"]=function(x,m){
  var a,t;
  switch(m[1].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  t=(t<<1)|1;
  pc8001.z80.flags["C"]=(t>0xff)?1:0;
  t&=0xff;
  if(a<0)
    pc8001.z80.regs[m[1]]=t;
  else
    pc8001.writeMemory(a,t);
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=(t>0x7f)?1:0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.mnemonics["SRL"]=function(x,m){
  var a,t;
  switch(m[1].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  pc8001.z80.flags["C"]=t&1;
  t=t>>1;
  if(a<0)
    pc8001.z80.regs[m[1]]=t;
  else
    pc8001.writeMemory(a,t);
  pc8001.z80.flags["Z"]=(t==0)?1:0;
  pc8001.z80.flags["M"]=0;
  t=(((t>>6)|4)^(t>>3)^t)&3;
  pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
}
pc8001.z80.mnemonics["BIT"]=function(x,m){
  var a,t;
  switch(m[2].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[2]];
      break;
    case 4:
      a=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[2].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  pc8001.z80.flags["Z"]=((t&(1<<m[1]))==0)?1:0;
}
pc8001.z80.mnemonics["RES"]=function(x,m){
  var a,t
  switch(m[2].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[2]]
      break;
    case 4:
      a=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[2].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  t&=(1<<m[1])^0xff;
  if(a<0)
    pc8001.z80.regs[m[2]]=t;
  else
    pc8001.writeMemory(a,t);
}
pc8001.z80.mnemonics["SET"]=function(x,m){
  var a,t;
  switch(m[2].length){
    case 1:
      a=-1;
      t=pc8001.z80.regs[m[2]]
      break;
    case 4:
      a=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      t=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[2].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
  }
  t|=1<<m[1];
  if(a<0)
    pc8001.z80.regs[m[2]]=t;
  else
    pc8001.writeMemory(a,t);
}
pc8001.z80.ops[0xed][0xa0]=["LDI",16];
pc8001.z80.mnemonics["LDI"]=function(x,m){
  var hl=pc8001.z80.regs["H"]*256+pc8001.z80.regs["L"];
  var de=pc8001.z80.regs["D"]*256+pc8001.z80.regs["E"];
  var bc=pc8001.z80.regs["B"]*256+pc8001.z80.regs["C"];
  pc8001.writeMemory(de,pc8001.memory[hl]);
  hl=(hl+1)&0xffff;
  de=(de+1)&0xffff;
  bc=(bc+0xffff)&0xffff;
  pc8001.z80.regs["H"]=hl>>8;
  pc8001.z80.regs["L"]=hl&0xff;
  pc8001.z80.regs["D"]=de>>8;
  pc8001.z80.regs["E"]=de&0xff;
  pc8001.z80.regs["B"]=bc>>8;
  pc8001.z80.regs["C"]=bc&0xff;
  pc8001.z80.flags["V"]=(bc==0)?0:1;
}
pc8001.z80.ops[0xed][0xb0]=["LDIR",21];
pc8001.z80.mnemonics["LDIR"]=function(x,m){
  var hl=pc8001.z80.regs["H"]*256+pc8001.z80.regs["L"];
  var de=pc8001.z80.regs["D"]*256+pc8001.z80.regs["E"];
  var bc=pc8001.z80.regs["B"]*256+pc8001.z80.regs["C"];
  pc8001.writeMemory(de,pc8001.memory[hl]);
  hl=(hl+1)&0xffff;
  de=(de+1)&0xffff;
  bc=(bc+0xffff)&0xffff;
  pc8001.z80.regs["H"]=hl>>8;
  pc8001.z80.regs["L"]=hl&0xff;
  pc8001.z80.regs["D"]=de>>8;
  pc8001.z80.regs["E"]=de&0xff;
  pc8001.z80.regs["B"]=bc>>8;
  pc8001.z80.regs["C"]=bc&0xff;
  if(bc!=0){
    pc8001.z80.regs["PC"]=(pc8001.z80.regs["PC"]+0xfffe)&0xffff;
    pc8001.z80.flags["V"]=1;
  }
  else
    pc8001.z80.flags["V"]=0;
}
pc8001.z80.ops[0xed][0xa8]=["LDD",16];
pc8001.z80.mnemonics["LDD"]=function(x,m){
  var hl=pc8001.z80.regs["H"]*256+pc8001.z80.regs["L"];
  var de=pc8001.z80.regs["D"]*256+pc8001.z80.regs["E"];
  var bc=pc8001.z80.regs["B"]*256+pc8001.z80.regs["C"];
  pc8001.writeMemory(de,pc8001.memory[hl]);
  hl=(hl+0xffff)&0xffff;
  de=(de+0xffff)&0xffff;
  bc=(bc+0xffff)&0xffff;
  pc8001.z80.regs["H"]=hl>>8;
  pc8001.z80.regs["L"]=hl&0xff;
  pc8001.z80.regs["D"]=de>>8;
  pc8001.z80.regs["E"]=de&0xff;
  pc8001.z80.regs["B"]=bc>>8;
  pc8001.z80.regs["C"]=bc&0xff;
  pc8001.z80.flags["V"]=(bc==0)?0:1;
}
pc8001.z80.ops[0xed][0xb8]=["LDDR",21];
pc8001.z80.mnemonics["LDDR"]=function(x,m){
  var hl=pc8001.z80.regs["H"]*256+pc8001.z80.regs["L"];
  var de=pc8001.z80.regs["D"]*256+pc8001.z80.regs["E"];
  var bc=pc8001.z80.regs["B"]*256+pc8001.z80.regs["C"];
  pc8001.writeMemory(de,pc8001.memory[hl]);
  hl=(hl+0xffff)&0xffff;
  de=(de+0xffff)&0xffff;
  bc=(bc+0xffff)&0xffff;
  pc8001.z80.regs["H"]=hl>>8;
  pc8001.z80.regs["L"]=hl&0xff;
  pc8001.z80.regs["D"]=de>>8;
  pc8001.z80.regs["E"]=de&0xff;
  pc8001.z80.regs["B"]=bc>>8;
  pc8001.z80.regs["C"]=bc&0xff;
  if(bc!=0){
    pc8001.z80.regs["PC"]=(pc8001.z80.regs["PC"]+0xfffe)&0xffff;
    pc8001.z80.flags["V"]=1;
  }
  else
    pc8001.z80.flags["V"]=0;
}
pc8001.z80.ops[0xdb]=["IN","A","(n)",11];
pc8001.z80.mnemonics["IN"]=function(x,m){
  var c,t,pc;
  if(m[2]=="(n)"){
    pc=pc8001.z80.regs["PC"];
    c=pc8001.memory[pc];
    pc8001.z80.regs["PC"]=(pc+1)&0xffff;
  }
  else
    c=pc8001.z80.regs[m[2].substr(1,1)];
  pc8001.z80.regs[m[1]]=t=pc8001.inports[c];
  if(m[2]!="(n)"){
    pc8001.z80.flags["Z"]=(t==0)?1:0;
    pc8001.z80.flags["M"]=(t>0x7f)?1:0;
    t=(((t>>6)|4)^(t>>3)^t)&3;
    pc8001.z80.flags["V"]=((t>>2)^(t>>1)^t)&1;
  }
}
pc8001.z80.ops[0xd3]=["OUT","(n)","A",11];
pc8001.z80.mnemonics["OUT"]=function(x,m){
  var c,pc;
  if(m[1]=="(n)"){
    pc=pc8001.z80.regs["PC"];
    c=pc8001.memory[pc];
    pc8001.z80.regs["PC"]=(pc+1)&0xffff;
  }
  else
    c=pc8001.z80.regs[m[1].substr(1,1)];
  pc8001.outports(c,pc8001.z80.regs[m[2]]);
}
pc8001.outports=function(p,d){
  if(p!=0x40){
    pc8001.z80.mnemonics["UNDEF"](p,["UNDEF","OUT",0]);
    return;
  }
  pc8001.beep.on=((d&0x20)==0)?0:1;
}
pc8001.z80.ops[0xdd][0xcb]=["EXTCB","DD CB dd","JX",20];
pc8001.z80.ops[0xfd][0xcb]=["EXTCB","FD CB dd","KY",20];
pc8001.z80.mnemonics["EXTCB"]=function(x,m){
  var pc=pc8001.z80.regs["PC"];
  var d=pc8001.memory[pc];
  var e=pc8001.memory[(pc+1)&0xffff];
  var f=pc8001.z80.ops[0xcb][e].slice();
  pc8001.z80.regs["PC"]=(pc+2)&0xffff;
  if(f[f.length-2]=="(HL)"){
    f[f.length-2]="("+m[2]+"+"+d.toString(16).padStart(2,"0")+")";
    pc8001.z80.mnemonics[f[0]](e,f);
    return;
  }
  pc8001.z80.mnemonics["UNDEF"](e,["UNDEF",m[1],0]);
}
pc8001.z80.run=function(){
  var i,pc,v,m,s;
  for(i=0;i<4000;i++){
    pc=pc8001.z80.regs["PC"];
    v=pc8001.memory[pc];
    m=pc8001.z80.ops[v];
    pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
    s=m[m.length-1];
    if(s<0){
      v=pc8001.memory[pc];
      m=m[v];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      s=m[m.length-1];
    }
    pc8001.z80.states+=s;
    pc8001.z80.mnemonics[m[0]](v,m);
    if(pc8001.z80.halt==1)
      return;
    if(pc8001.beep.counter!=-1){
      v=Math.floor(pc8001.z80.states*pc8001.beep.audio.sampleRate/pc8001.z80.frequency)%pc8001.beep.refWave.length;
      if(v==pc8001.beep.counter){
        pc8001.beep.wave[v]=pc8001.beep.on*pc8001.beep.refWave[v];
        pc8001.beep.counter=(pc8001.beep.counter+1)%pc8001.beep.refWave.length;
      }
    }
    s=pc8001.z80.states-(performance.now()-pc8001.z80.millitimer)*pc8001.z80.millistates;
    if(s>1000)
      break;
  }
  pc8001.z80.timer=setTimeout("clearTimeout(pc8001.z80.timer);pc8001.z80.run()",(s>1000)?s/pc8001.z80.millistates:0);
}
pc8001.run=function(){
  document.addEventListener("keydown",pc8001.keydown);
  document.addEventListener("keyup",pc8001.keyup);
  pc8001.z80.millitimer=performance.now();
  pc8001.z80.run();
}
</script>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink"
 width=984 height=624 viewBox="-2 -2 164 104"
 style="background-color:black"
 onload="pc8001.initDisplay80x25(this);pc8001.run()">
</svg>
</body>
</html>
```

一方、JavaScript版『[FEDORA](http://kanji.zinbun.kyoto-u.ac.jp/~yasuoka/fedora/fedora.html)』は、4MHz相当のZ80をエミュレートしているので、90.7ステートないし83.3ステート毎にサンプリング信号を作り出すことになるが、その点以外はほぼ同じアイデアである。5月24日時点でのプログラムリストを、以下に公開しておくことにする。

```
<!DOCTYPE html><head><meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>FEDORA by Koichi Yasuoka, May 24, 2025</title>
<script>
var pc8001=new Object();
pc8001.memory=new Array(65536);
pc8001.memory.fill(0x76);
["0000 C3 00 E0",
 "0018                         FE 0C CA 3A 09 76",
 "093A                               2A 5A EA EB 21 00",
 "0940 F3 06 50 73 23 10 FC AF 77 23 77 23 36 01 23 72",
 "0950 23 01 50 11 71 23 72 23 10 FA 71 23 77 23 11 00",
 "0960 F3 EB 01 40 0B ED B0 C9",
 "1602       C9",
 "DC00 11 00 02 CD EA E4 21 55 DC DB 01 07 30 3D AF 32",
 "DC10 26 E2 3E 18 32 45 E8 CD ED 52 21 97 DC DB 03 E6",
 "DC20 40 28 13 DB 05 E6 02 20 F4 3E 3A 32 26 E2 3E 20",
 "DC30 32 45 E8 21 66 DC CD ED 52 60 69 23 11 FF FF CD",
 "DC40 EA E4 CD ED 52 11 FF FF CD EA E4 21 9F DC CD ED",
 "DC50 52 C3 81 00 00 46 45 44 4F 52 41 2D 32 20 52 65",
 "DC60 61 64 79 3F 20 00 59 65 73 0D 0A 0A 07 00 50 75",
 "DC70 73 68 97 1E 80 80 1D 1D 1F B6 C5 1D 1D 1F 94 94",
 "DC80 1E 88 77 68 65 6E 20 79 6F 75 20 75 73 65 20 69",
 "DC90 74 2E 0D 1F 1F 00 00 4E 6F 0D 0A 0A 07 00 00 BD",
 "DCA0 C0 B0 C4 CA 20 45 30 30 30 C3 DE BD A1 07 00 0C",
 "DCB0 0C 04 00 C0 44 C0 44 C0 C4 C0 84 C0 44 17 07 07",
 "DCC0 11 50 75 70 44 70 74 70 61 70 45 3A D6 E8 B7 C8",
 "DCD0 3A D8 E8 B7 20 05 3A D7 E8 B7 C0 D9 E5 79 D9 E3",
 "DCE0 4F CD 8D E3 CD 43 E4 54 26 78 CD 32 E4 7A 2B 2B",
 "DCF0 BE 38 FB 23 3E A8 BE E1 C9 00 00 00 3E 20 D3 40",
 "DD00 D9 21 D6 E8 34 7E CD 4C DD 11 31 FA CD 2F DD 23",
 "DD10 3A D1 E8 BE D9 D0 D9 7E 32 D1 E8 11 93 F4 CD 2F",
 "DD20 DD D9 C9 16 00 EB 29 29 29 29 EB C9 00 00 00 21",
 "DD30 D2 E8 0E 03 13 13 23 7E 0D 28 03 B7 28 F6 0E 01",
 "DD40 CD 97 DD 7D FE D5 20 EC C9 00 00 00 47 21 D3 E8",
 "DD50 16 00 72 23 72 23 36 FF 04 3E 0A 21 D6 E8 2B 34",
 "DD60 4E 72 B9 28 F9 71 10 F3 C9 00 00 00 C0 C4 70 74",
 "DD70 40 0C 40 47 40 C4 70 55 40 C4 50 75 C0 C0 10 71",
 "DD80 C0 44 50 75 C0 44 70 75 40 C4 00 70 C0 C4 70 75",
 "DD90 C0 C4 50 75 00 00 00 E5 D5 C5 07 07 C6 6C 6F 26",
 "DDA0 DD ED A0 ED A0 01 76 00 EB 09 EB ED A0 ED A0 C1",
 "DDB0 D1 E1 C9 00 00 00 3E D8 32 BB F4 32 33 F5 21 B3",
 "DDC0 DC 11 27 FA 01 0A 00 ED B0 21 C1 DC 11 9F FA 01",
 "DDD0 0A 00 ED B0 21 AF DC 11 85 F4 01 0E 00 ED B0 11",
 "DDE0 FD F4 01 0E 00 ED B0 AF 32 D6 E8 11 37 FA CD 97",
 "DDF0 DD 3A D1 E8 CD 4C DD 11 93 F4 C3 2F DD 00 00 00",
 "DE00 3A D4 E8 E6 07 C0 21 D6 E8 7E 35 28 18 E6 2F C0",
 "DE10 21 BA F8 0E 02 06 1B 1A AE 77 13 23 10 F9 21 32",
 "DE20 F9 0D 20 F1 C9 21 E0 DF E3 C9 00 DD 7D 0F 0F D6",
 "DE30 2E 6F 26 E0 7E DD 77 00 23 7E DD 77 01 C5 CD 59",
 "DE40 E4 C1 21 D5 E8 7E C6 10 77 D0 36 FF C9 00 00 00",
 "DE50 9F 91 0B F8 F9 08 9F F1 11 0F 9F 99 01 00 00 1F",
 "DE60 31 0F FF 00 0F 9F 99 01 9F F9 08 77 44 07 77 00",
 "DE70 07 77 70 00 07 77 44 04 00 00 47 44 07 70 64 03",
 "DE80 77 44 04 77 00 07 00 00 00 00 8F F0 00 0F 8F F0",
 "DE90 19 F1 F0 19 F1 F0 08 9F 11 0F 9F 91 0B 00 00 00",
 "DEA0 00 00 00 00 00 77 74 44 07 77 70 07 70 70 07 70",
 "DEB0 70 07 77 00 07 77 44 07 00 00 00 00 00 00 00 00",
 "DEC0 00 21 D3 E8 7E B7 28 0E 35 3E 20 D3 40 11 20 00",
 "DED0 CD EA E4 D3 40 C9 21 D8 E8 7E B7 20 24 2B 7E 11",
 "DEE0 50 DE B7 CA 00 DE 3A D4 E8 E6 07 20 14 2B 35 28",
 "DEF0 07 DB 01 07 38 0B 36 00 23 35 DD 21 D8 E8 CD 2B",
 "DF00 DE 3A D2 E8 FE 82 30 20 06 01 0F 38 08 0F 38 05",
 "DF10 0F E6 03 3C 47 DD 21 E0 E8 DD 7E 00 B7 CC 2B DE",
 "DF20 11 08 00 DD 19 10 F2 C9 21 D8 E8 11 86 DE 7E B7",
 "DF30 C8 7D C6 08 6F CA 00 DE 7E B7 18 F5 C9 00 21 D4",
 "DF40 E8 35 C0 23 34 C0 35 C9 00 00 00 FD 66 00 FD 6E",
 "DF50 01 CD 43 E4 CD 32 E4 79 AE 77 C9 00 00 00 FD 21",
 "DF60 00 E9 FD 7E 00 B7 28 1A FD 35 05 20 15 CD 4B DF",
 "DF70 FD 7E 01 FD 86 03 FD 77 01 CD B1 E2 FD 7E 07 FD",
 "DF80 77 05 FD 7D C6 08 FD 6F 20 D8 C9 00 00 00 DD 21",
 "DF90 D8 E8 DD 7E 00 B7 28 39 DD 35 05 20 34 DD 7E 06",
 "DFA0 D6 08 4F CD D0 E1 DD 72 03 DD 73 05 CD C5 E3 DD",
 "DFB0 7E 01 DD 86 03 FE 03 28 04 FE 5C 20 0E 3E 2F DD",
 "DFC0 96 06 DD 77 06 DD 7E 01 DD 96 03 DD 77 01 CD 59",
 "DFD0 E4 DD 7D C6 08 DD 6F 20 B9 C9 31 FF FF CD 7E E8",
 "DFE0 CD 9F E7 CD 24 E5 CD 10 E2 CD 22 E1 CD 40 E0 CD",
 "DFF0 8E DF CD 12 E0 CD 5E DF CD 3E DF CD C1 DE 18 E6",
 "E000 DB 01 07 30 FB 18 D3 00 02 04 99 5B 02 04 02 5B",
 "E010 99 04 FD 21 00 E9 FD 7E 00 B7 28 1A FD 35 04 20",
 "E020 15 CD 4B DF FD 7E 00 FD 86 02 FD 77 00 CD B1 E2",
 "E030 FD 7E 06 FD 77 04 FD 7D C6 08 FD 6F 20 D8 C9 00",
 "E040 DD 21 D8 E8 DD 7E 00 B7 28 36 DD 35 04 20 31 DD",
 "E050 4E 06 CD D0 E1 DD 72 02 DD 73 04 CD C5 E3 DD 7E",
 "E060 00 DD 86 02 FE 01 28 04 FE 9A 20 0E 3E 1F DD 96",
 "E070 06 DD 77 06 DD 7E 00 DD 96 02 DD 77 00 CD 59 E4",
 "E080 DD 7D C6 08 DD 6F 20 BC C9 00 00 00 03 06 0A 10",
 "E090 17 26 50 00 00 00 DD 35 07 C0 DD 36 07 40 3A D8",
 "E0A0 E8 DD 96 00 01 01 08 30 05 ED 44 01 FF 17 57 3A",
 "E0B0 D9 E8 DD 96 01 5F 30 0C ED 44 5F 3E 2F 90 E6 1F",
 "E0C0 47 AF 91 4F 21 8C E0 7E E5 D5 C5 21 00 00 5A 54",
 "E0D0 06 07 0F 30 01 19 EB 29 EB 10 F7 C1 D1 D5 CD 23",
 "E0E0 DD ED 52 D1 E1 30 09 78 81 47 23 7D FE 93 20 D7",
 "E0F0 DD 7E 06 E6 1F 4F 3A DE E8 E6 1F B9 28 0A 30 02",
 "E100 C6 20 D6 10 81 0F E6 1F 90 57 78 92 E6 1F B9 D5",
 "E110 CC 3C E1 D1 DD 34 06 CB 62 C0 DD 35 06 DD 35 06",
 "E120 C9 00 3A D8 E8 B7 C8 DD 21 E0 E8 DD 7E 00 B7 C4",
 "E130 96 E0 DD 7D C6 08 DD 6F 20 F1 C9 00 21 D3 E8 3E",
 "E140 18 BE 38 01 77 CD D0 E1 EB 79 D6 08 4F CD D0 E1",
 "E150 79 C6 08 4F CB 3B CB 3D C3 9B E1 02 FE 03 FE 04",
 "E160 FE 04 FF 05 FF 05 00 06 00 06 01 06 02 06 03 06",
 "E170 04 06 05 06 06 05 06 04 06 03 06 02 06 01 06 00",
 "E180 06 FF 06 FE 06 FE 05 FE 04 FE 03 FE 02 FE 01 FE",
 "E190 00 FF 00 FF FF 00 FF 00 FE 01 FE DD CB 07 D6 79",
 "E1A0 44 4A 55 E6 1F 87 C6 5B 6F 26 E1 7E 23 6E DD 66",
 "E1B0 00 84 C8 67 DD 7E 01 85 6F C3 E2 E2 00 55 1D 12",
 "E1C0 0D 0B 09 09 08 08 09 09 0B 0D 12 1D 55 00 00 00",
 "E1D0 16 01 CB 61 28 02 16 FF 79 E6 0F C6 BD E5 6F 26",
 "E1E0 E1 5E E1 C9 00 00 00 21 D3 E8 3E 30 BE 38 01 77",
 "E1F0 23 23 35 CD D0 E1 EB 79 D6 08 4F CD D0 E1 79 C6",
 "E200 08 4F CB 3B CB 3B CB 3D CB 3D C3 9B E1 00 00 00",
 "E210 3A D8 E8 B7 C8 DD 21 D8 E8 DD 35 07 C0 DD 36 07",
 "E220 20 3A D0 E8 B7 28 3A DB 00 CB 67 20 03 DD 35 06",
 "E230 E6 40 20 03 DD 34 06 3A D5 E8 FE 06 D8 DD 7E 06",
 "E240 D6 04 4F 06 05 DB 09 0F 0F C5 F5 D4 E7 E1 F1 C1",
 "E250 0C 0C 10 F4 0F D8 79 C6 0A 4F 21 D5 E8 35 C3 3C",
 "E260 E1 0E 00 DB 01 0F 30 14 0E 10 DB 00 CB 57 28 0C",
 "E270 0E 18 CB 67 28 06 0E 08 E6 40 20 11 DD 7E 06 91",
 "E280 DD 34 06 E6 10 20 06 DD 35 06 DD 35 06 3A D5 E8",
 "E290 FE 02 D8 DD 4E 06 DB 09 E6 40 CC E7 E1 DB 00 0F",
 "E2A0 D8 21 D5 E8 35 DD 7E 06 C6 10 4F C3 3C E1 00 00",
 "E2B0 00 FD 66 00 FD 6E 01 7C D6 02 FE 9C 30 1C 7D D6",
 "E2C0 04 FE 5C 30 15 CD 43 E4 CD 32 E4 79 AE 77 2F A1",
 "E2D0 C8 FD 66 00 FD 6E 01 C3 3D E3 FD 36 00 00 C9 00",
 "E2E0 00 00 FD E5 FD 21 00 E9 FD 7E 00 B7 28 0B FD 7D",
 "E2F0 C6 08 FD 6F 20 F2 FD E1 C9 FD 74 00 FD 75 01 FD",
 "E300 70 02 FD 71 03 FD 72 04 FD 73 05 FD 72 06 FD 73",
 "E310 07 D9 CD 4B DF D9 FD E1 C9 00 00 00 16 06 01 FF",
 "E320 16 06 FF 01 06 16 01 01 06 16 FF FF 07 0D 01 FF",
 "E330 07 0D FF 01 0D 07 01 01 0D 07 FF FF 00 E5 CD 43",
 "E340 E4 54 26 78 CD 32 E4 7A 2B 2B BE 38 FB 23 7E E6",
 "E350 07 28 37 87 87 87 C6 D0 DD E5 DD 6F DD 26 E8 FE",
 "E360 D8 28 04 21 D2 E8 34 CD C5 E3 DD 36 00 00 DD E1",
 "E370 21 1C E3 56 23 5E 23 46 23 4E 23 E3 CD E2 E2 E3",
 "E380 7D FE 3C 20 EE 3E FF 32 D3 E8 E1 C9 00 11 00 0D",
 "E390 19 06 FF 11 88 FF 04 19 38 FC 7D C6 78 67 3E 0F",
 "E3A0 B9 CB 14 14 CB 03 79 A3 28 F9 78 87 87 82 6F C9",
 "E3B0 00 00 00 E5 23 23 7E B7 28 06 2B 2B 77 23 18 F4",
 "E3C0 E1 C9 00 00 00 CD D2 E4 E5 CD 32 E4 0E 02 06 03",
 "E3D0 1A AE 77 23 13 10 F9 79 01 75 00 09 4F 0D 20 EE",
 "E3E0 E1 E5 CD E7 E3 E1 2C 26 78 CD 32 E4 CD 12 E4 2B",
 "E3F0 BE 28 06 2B 34 35 20 F7 C9 3E B8 77 23 23 BE 2B",
 "E400 CC B3 E3 2B 2B 2B 7E 23 FE B8 CA B3 E3 C9 00 00",
 "E410 00 00 DD 7D 0F 0F 0F C6 5E FE 79 C0 3E 99 C9 00",
 "E420 23 23 E5 7E B7 28 06 70 41 4F 23 18 F6 E1 C9 00",
 "E430 00 00 7D 6C 26 F3 B7 C8 D5 11 78 00 19 3D 20 FC",
 "E440 D1 C9 00 0E 01 CB 3C 30 02 0E 10 CB 3D 30 02 CB",
 "E450 01 CB 3D D0 CB 01 CB 01 C9 CD D2 E4 E5 CD 32 E4",
 "E460 D9 0E 00 D9 0E 02 06 03 1A AE 77 2F EB A6 EB 28",
 "E470 05 E5 D9 E1 4F D9 23 13 10 EE 79 01 75 00 09 4F",
 "E480 0D 20 E3 E1 D9 0C 0D D9 28 05 CD CB DC 30 2F E5",
 "E490 CD 95 E4 E1 2C 54 26 78 CD 32 E4 7A C6 03 2B 2B",
 "E4A0 BE 38 FB 28 0A 47 0E B8 23 7E 2B B9 CC 20 E4 CD",
 "E4B0 12 E4 4F 2B 2B 42 7E B8 DA 20 E4 23 71 C9 D9 CD",
 "E4C0 8D E3 E5 DD 7D C3 58 E3 00 00 00 00 00 00 00 00",
 "E4D0 00 00 DD 66 00 DD 6E 01 CD 43 E4 3E 94 C6 06 CB",
 "E4E0 09 30 FA 5F 16 E5 C9 00 00 00 7A B3 1B 20 FB C9",
 "E4F0 00 00 00 00 00 00 00 00 02 02 04 01 01 20 27 0B",
 "E500 20 00 00 FF FF 20 27 1B 40 00 00 01 01 20 27 0B",
 "E510 40 00 00 01 FF 27 20 03 40 00 00 FF 01 27 20 13",
 "E520 40 00 00 00 21 F3 E4 11 D2 E8 01 2E 00 ED B0 EB",
 "E530 11 08 00 06 20 72 19 10 FC 3E 0C DF 21 00 F3 36",
 "E540 80 06 4E 23 36 88 10 FB 23 36 08 11 78 00 06 17",
 "E550 19 36 0F 10 FB 19 36 01 06 4E 2B 36 11 10 FB 2B",
 "E560 36 10 11 88 FF 06 17 19 36 F0 10 FB DD 21 D8 E8",
 "E570 C3 59 E4 00 00 00 9F 99 01 9F 99 01 9F 11 0F 1F",
 "E580 31 0F 9F F9 08 F8 F9 08 77 00 00 77 44 04 77 44",
 "E590 07 47 44 07 77 00 07 77 00 07 A4 A9 04 01 01 01",
 "E5A0 48 42 08 12 13 02 80 84 00 25 26 05 00 08 00 5A",
 "E5B0 5C 0A 40 9A 4A 10 10 10 80 24 84 20 31 21 00 48",
 "E5C0 08 50 62 52 00 80 00 A0 C5 A5 00 00 00 00 00 00",
 "E5D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 47 0F",
 "E5E0 E4 45 44 88 00 00 00 00 00 00 00 80 48 44 E5 04",
 "E5F0 5F 0D 00 01 00 01 00 00 11 42 08 00 00 48 12 01",
 "E600 00 00 01 00 11 01 00 00 00 00 00 00 00 00 61 08",
 "E610 68 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
 "E620 00 00 00 0F 0F 00 00 00 00 00 00 00 00 00 00 00",
 "E630 00 00 00 00 00 00 00 83 03 00 00 00 00 00 00 00",
 "E640 00 00 00 00 00 00 00 00 00 00 A0 C5 A5 00 00 00",
 "E650 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
 "E660 00 00 00 00 00 00 00 00 00 00 AE 0A 8E 0E 2E 0E", //SHOT: FGHJK SPACE
 "E670 E2 02 04 00 00 AE 02 00 2E 0A 00 8E 0E 00 08 0E", // E66A-E6B3 37bytes*2
 "E680 00 CE 02 00 00 AE 0A AE 0E 2C 0C 2E 02 AE 02 22",
 "E690 03 03 03 23 03 30 00 01 00 00 03 00 00 23 03 00",
 "E6A0 03 03 00 23 03 00 03 03 00 00 22 03 03 00 13 03",
 "E6B0 23 02 23 02 00 00 00 00 00 00 00 00 00 5F 0F 00",
 "E6C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
 "E6D0 00 D1 01 00 00 00 00 00 00 00 00 00 00 00 00 00",
 "E6E0 00 00 00 00 00 F0 00 00 00 00 00 00 00 00 00 00",
 "E6F0 00 00 00 8E 0E 88 88 88 80 24 84 80 88 88 08 AE",
 "E700 0A 00 00 00 00 00 00 00 03 00 00 00 20 B1 21 00",
 "E710 00 00 00 23 03 00 00 00 00 00 00 00 00 00 00 00",
 "E720 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
 "E730 00 00 00 00 00 54 0C 00 00 00 00 00 00 00 00 00",
 "E740 00 00 00 00 00 00 00 00 00 57 05 00 00 00 00 00",
 "E750 00 00 00 00 AE 0A 8E 0E 2E 0E E2 02 04 00 AE 0A",
 "E760 AE 0E 2C 0C 2E 02 AE 02 00 00 2E 0E 1E 20 0E E0",
 "E770 E2 E0 2C E0 2A E0 E0 10 0E 22 03 03 03 23 03 30",
 "E780 00 01 00 22 03 03 00 13 03 23 02 23 02 06 00 23",
 "E790 03 43 20 23 30 32 30 30 30 22 00 03 40 03 00 3E",
 "E7A0 0C DF 21 98 18 22 53 F3 22 CB F3 21 AB F5 11 78",
 "E7B0 00 06 0C 36 78 19 10 FB 06 08 36 F8 19 10 FB 21",
 "E7C0 76 E5 11 02 F3 01 12 00 ED B0 11 7A F3 01 12 00",
 "E7D0 ED B0 21 C8 E8 7E FE 72 20 10 11 A5 F3 01 16 00",
 "E7E0 ED B8 11 2D F3 01 16 00 ED B8 CD B6 DD 3A D2 E8",
 "E7F0 B7 28 48 FE 83 38 02 3E 82 4F 21 59 F5 06 1A EB",
 "E800 21 A6 E5 79 C6 06 4F ED A0 ED A0 ED A0 7B C6 75",
 "E810 5F 30 01 14 ED A0 ED A0 ED A0 EB CD FC DC 11 00",
 "E820 20 CD EA E4 D3 40 11 00 10 CD EA E4 0D 28 0C 11",
 "E830 88 FF 19 10 CA 11 A2 00 19 18 C2 21 CA E5 DB 08",
 "E840 E6 20 32 D0 E8 20 03 21 B4 E6 3E 08 11 02 FB 01",
 "E850 14 00 ED B0 EB 01 64 00 09 EB 3D 20 F2 11 88 FC",
 "E860 01 25 00 ED B0 11 00 FD 01 25 00 ED B0 21 D0 E8",
 "E870 DB 08 E6 20 AE 20 C4 DB 01 07 38 F4 C9 00 21 00",
 "E880 00 22 D1 E8 21 5A EA 11 05 00 01 19 50 72 23 36",
 "E890 B8 19 72 23 36 FF 19 CB 8E C3 3A 09 00 4C 08 0C",
 "E8A0 0C 00 C0 48 00 C0 C0 80 84 C0 44 C0 C0 C0 C4 C0",
 "E8B0 48 80 84 57 02 61 01 00 70 61 40 10 16 70 72 50",
 "E8C0 75 70 74 70 74 70 61 70 72 00 00 DA DF 00 00 00"
].forEach(function(v){
  var t=v.split(/ +/);
  var a=parseInt(t[0],16);
  var i;
  for(i=1;i<t.length;i++)
    pc8001.memory[a+i-1]=parseInt(t[i],16);
});
pc8001.initDisplay80x25=function(svg){
  var d=pc8001.display=new Object();
  var t=d.textArray=new Array(80);
  var x,y,e;
  d.svg=svg;
  d.colors=new Array(256);
  d.colors.fill("none");
  for(x=0;x<8;x++){
    d.colors[0x18+x]="#000000";
    d.colors[0x38+x]="#0000ff";
    d.colors[0x58+x]="#ff0000";
    d.colors[0x78+x]="#ff00ff";
    d.colors[0x98+x]="#00ff00";
    d.colors[0xb8+x]="#00ffff";
    d.colors[0xd8+x]="#ffff00";
    d.colors[0xf8+x]="#ffffff";
  }
  d.colors[0x00]="#00ffff";
  for(x=0;x<80;x++)
    t[x]=new Array(25);
  d.start=d.end=0xf300;
  for(y=0;y<25;y++){
    for(x=0;x<80;x++){
      pc8001.memory[d.end]=0;
      d.end++;
      t[x][y]=new Object();
      e=document.createElementNS("http://www.w3.org/2000/svg","text");
      e.setAttribute("y",x*2);
      e.setAttribute("x",y*4);
      e.setAttribute("font-family","monospace");
      e.setAttribute("font-size",2.1);
      e.setAttribute("transform","matrix(0 1 1 0 1.8 0)");
      e.setAttribute("fill","#00ffff");
      e.setAttribute("stroke","none");
      d.svg.appendChild(e);
      t[x][y].element=e;
      t[x][y].attribute="#00ffff";
    }
    pc8001.memory[d.end]=0;
    d.end++;
    for(x=1;x<39;x++){
      pc8001.memory[d.end]=(x%2==0)?80:0xb8;
      d.end++;
    }
    pc8001.memory[d.end]=0;
    d.end++;
  }
  d.end--;
  e=[[0x3000,0x2598,0x259d,0x2580],
     [0x2596,0x258c,0x259e,0x259b],
     [0x2597,0x259a,0x2590,0x259c],
     [0x2584,0x2599,0x259f,0x2588]];
  d.blocks=new Array(256);
  d.blocks[0]="";
  for(x=1;x<256;x++){
    if((x&0xcc)>0)
      d.blocks[x]=String.fromCodePoint(e[(x>>4)&3][x&3],e[(x>>6)&3][(x>>2)&3]);
    else
      d.blocks[x]=String.fromCodePoint(e[(x>>4)&3][x&3]);
  }
  pc8001.writeMemory(d.start,0xff);
  y=t[0][0].element.getBBox();
  pc8001.writeMemory(d.start,0);
  if(y.width<4){
    e[0][0]=0x2003;
    for(x=1;x<256;x++){
      if((x&0xcc)>0)
        d.blocks[x]=String.fromCodePoint(e[(x>>4)&3][x&3],e[(x>>6)&3][(x>>2)&3]);
      else
        d.blocks[x]=String.fromCodePoint(e[(x>>4)&3][x&3]);
    }
    e=4/y.width;
    for(y=0;y<25;y++){
      for(x=0;x<80;x++){
        t[x][y].element.setAttribute("x",y*4/e);
        t[x][y].element.setAttribute("transform","matrix(0 "+e+" 1 0 1.8 0)");
      }
    }
  }
}
pc8001.writeMemory=function(address,data){
  var t=pc8001.memory[address];
  var d=pc8001.display;
  var x,y,i,j;
  pc8001.memory[address]=data;
  if(address<d.start||d.end<address||t==data)
    return;
  x=(address-d.start)%120;
  y=Math.floor((address-d.start)/120);
  if(x<80){
    d.textArray[x][y].element.textContent=d.blocks[data];
    return;
  }
  i=d.start+80+y*120;
  j="#00ffff";
  for(x=0;x<80;x++){
    if(pc8001.memory[i]==x){
      i++;
      j=d.colors[pc8001.memory[i]];
      i++;
    }
    t=d.textArray[x][y];
    if(t.attribute!=j){
      t.element.setAttribute("fill",j);
      t.attribute=j;
    }
  }
}
pc8001.inports=new Array(256);
pc8001.inports.fill(0xff);
pc8001.keymap=new Array(256);
pc8001.keymap.fill([-1,0xff]);
pc8001.keymap[13]=[1,0x7f];                    // enter-key
pc8001.keymap[100]=pc8001.keymap[37]=[0,0xef]; // ten-key 4 = leftarrow
pc8001.keymap[102]=pc8001.keymap[39]=[0,0xbf]; // ten-key 6 = rightarrow
pc8001.keymap[32]=[9,0xbf];                    // space-key
pc8001.keymap[112]=pc8001.keymap[70]=[9,0xfd]; // function-key F1 = key F
pc8001.keymap[113]=pc8001.keymap[71]=[9,0xfb]; // function-key F2 = key G
pc8001.keymap[114]=pc8001.keymap[72]=[9,0xf7]; // function-key F3 = key H
pc8001.keymap[115]=pc8001.keymap[74]=[9,0xef]; // function-key F4 = key J
pc8001.keymap[116]=pc8001.keymap[75]=[9,0xdf]; // function-key F5 = key K
pc8001.keydown=function(event){
  var k=pc8001.keymap[event.keyCode]
  if(k[0]<0)
    return;
  pc8001.inports[k[0]]&=k[1];
}
pc8001.keyup=function(event){
  var k=pc8001.keymap[event.keyCode]
  if(k[0]<0)
    return;
  pc8001.inports[k[0]]|=(k[1]^0xff);
  if(pc8001.beep.counter<0){
    pc8001.beep.counter=pc8001.beep.on=0;
    pc8001.beep.oscillator.start();
  }
}
pc8001.beep=new Object();
pc8001.beep.audio=new(window.AudioContext||window.webkitAudioContext)();
pc8001.beep.buffer=pc8001.beep.audio.createBuffer(1,Math.floor(pc8001.beep.audio.sampleRate/60),pc8001.beep.audio.sampleRate);
pc8001.beep.oscillator=pc8001.beep.audio.createBufferSource();
pc8001.beep.oscillator.buffer=pc8001.beep.buffer;
pc8001.beep.wave=pc8001.beep.buffer.getChannelData(0);
pc8001.beep.wave.fill(0);
pc8001.beep.counter=-1;
pc8001.beep.oscillator.loop=true;
pc8001.beep.oscillator.connect(pc8001.beep.audio.destination);
pc8001.beep.refWave=new Array(pc8001.beep.wave.length);
pc8001.beep.refWave.fill(0);
pc8001.beep.refWave.forEach(function(v,i,a){
  a[i]=Math.sin(i*Math.PI*2/pc8001.beep.audio.sampleRate*2400);
});
pc8001.z80=new Object();
pc8001.z80.frequency=4000000;                  // 4MHz
pc8001.z80.millistates=pc8001.z80.frequency/1000;
pc8001.z80.regs={"PC":0,"SP":0,"A":0,"B":0,"C":0,"D":0,"E":0,"H":0,"L":0,"J":0,"X":0,"K":0,"Y":0,"a":0,"b":0,"c":0,"d":0,"e":0,"h":0,"l":0};
pc8001.z80.flags={"Z":0,"C":0,"z":0,"c":0};
pc8001.z80.mnemonics={};
pc8001.z80.halt=pc8001.z80.states=0;
pc8001.z80.ops=new Array(256);
pc8001.z80.ops.fill(["UNDEF","",0]);
pc8001.z80.ops[0xcb]=new Array(257);
pc8001.z80.ops[0xcb].fill(["UNDEF","CB",0]);
pc8001.z80.ops[0xcb][256]=-1;
pc8001.z80.ops[0xdd]=new Array(257);
pc8001.z80.ops[0xdd].fill(["UNDEF","DD",0]);
pc8001.z80.ops[0xdd][256]=-1;
pc8001.z80.ops[0xed]=new Array(257);
pc8001.z80.ops[0xed].fill(["UNDEF","ED",0]);
pc8001.z80.ops[0xed][256]=-1;
pc8001.z80.ops[0xfd]=new Array(257);
pc8001.z80.ops[0xfd].fill(["UNDEF","FD",0]);
pc8001.z80.ops[0xfd][256]=-1;
pc8001.z80.mnemonics["UNDEF"]=function(v,m){
  pc8001.z80.regs["PC"]=(pc8001.z80.regs["PC"]+0xffff)&0xffff;
  pc8001.z80.halt=1;
  console.log(performance.now()-pc8001.z80.millitimer,"milliseconds");
  console.log(pc8001.z80.states,"states");
  console.log(m[0],m[1],v.toString(16).toUpperCase().padStart(2,"0"));
  Object.keys(pc8001.z80.regs).forEach(function(v){
    console.log(" reg",v,pc8001.z80.regs[v].toString(16).toUpperCase().padStart(v.length*2,"0"));
  });
  console.log(" flags",pc8001.z80.flags);
}
pc8001.params=["B","C","D","E","H","L","(HL)","A"];
pc8001.params.forEach(function(v,i,a){
  var j;
  for(j=0;j<8;j++)
    pc8001.z80.ops[i*8+j+0x40]=["LD",v,a[j],(i==6||j==6)?7:4];
  pc8001.z80.ops[i*8+4]=["INC",v,(i==6)?11:4];
  pc8001.z80.ops[i*8+5]=["DEC",v,(i==6)?11:4];
  pc8001.z80.ops[i*8+6]=["LD",v,"n",(i==6)?10:7];
  pc8001.z80.ops[i+0x80]=["ADD","A",v,(i==6)?7:4];
  pc8001.z80.ops[i+0x90]=["SUB","A",v,(i==6)?7:4];
  pc8001.z80.ops[i+0xa0]=["AND","A",v,(i==6)?7:4];
  pc8001.z80.ops[i+0xa8]=["XOR","A",v,(i==6)?7:4];
  pc8001.z80.ops[i+0xb0]=["OR","A",v,(i==6)?7:4];
  pc8001.z80.ops[i+0xb8]=["CP","A",v,(i==6)?7:4];
  if(i!=6){
    pc8001.z80.ops[0xdd][i*8+0x46]=["LD",v,"(JX+d)",19];
    pc8001.z80.ops[0xdd][i+0x70]=["LD","(JX+d)",v,19];
    pc8001.z80.ops[0xdd][i*8+0x44]=["LD",v,"J",8];
    pc8001.z80.ops[0xdd][i*8+0x45]=["LD",v,"X",8];
    pc8001.z80.ops[0xdd][i+0x60]=["LD","J",v,8];
    pc8001.z80.ops[0xdd][i+0x68]=["LD","X",v,8];
    pc8001.z80.ops[0xfd][i*8+0x46]=["LD",v,"(KY+d)",19];
    pc8001.z80.ops[0xfd][i+0x70]=["LD","(KY+d)",v,19];
    pc8001.z80.ops[0xfd][i*8+0x44]=["LD",v,"K",8];
    pc8001.z80.ops[0xfd][i*8+0x45]=["LD",v,"Y",8];
    pc8001.z80.ops[0xfd][i+0x60]=["LD","K",v,8];
    pc8001.z80.ops[0xfd][i+0x68]=["LD","Y",v,8];
    pc8001.z80.ops[0xed][i*8+0x40]=["IN",v,"(C)",12];
    pc8001.z80.ops[0xed][i*8+0x41]=["OUT","(C)",v,12];
  }
  pc8001.z80.ops[0xcb][i+0x00]=["RLC",v,(i==6)?15:8];
  pc8001.z80.ops[0xcb][i+0x08]=["RRC",v,(i==6)?15:8];
  pc8001.z80.ops[0xcb][i+0x10]=["RL",v,(i==6)?15:8];
  pc8001.z80.ops[0xcb][i+0x38]=["SRL",v,(i==6)?15:8];
  for(j=0;j<8;j++){
    pc8001.z80.ops[0xcb][i+j*8+0x40]=["BIT",j,v,(i==6)?12:8];
    pc8001.z80.ops[0xcb][i+j*8+0x80]=["RES",j,v,(i==6)?15:8];
    pc8001.z80.ops[0xcb][i+j*8+0xc0]=["SET",j,v,(i==6)?15:8];
  }
});
pc8001.z80.ops[0x76]=["HALT","",4];
pc8001.z80.mnemonics["HALT"]=pc8001.z80.mnemonics["UNDEF"];
pc8001.z80.ops[0x02]=["LD","(BC)","A",7];
pc8001.z80.ops[0x0a]=["LD","A","(BC)",7];
pc8001.z80.ops[0x12]=["LD","(DE)","A",7];
pc8001.z80.ops[0x1a]=["LD","A","(DE)",7];
pc8001.z80.ops[0x32]=["LD","(nn)","A",13];
pc8001.z80.ops[0x3a]=["LD","A","(nn)",13];
pc8001.z80.ops[0xdd][0x26]=["LD","J","n",11];
pc8001.z80.ops[0xdd][0x2e]=["LD","X","n",11];
pc8001.z80.ops[0xdd][0x36]=["LD","(JX+d)","n",19];
pc8001.z80.ops[0xdd][0x64]=["LD","J","J",8];
pc8001.z80.ops[0xdd][0x65]=["LD","J","X",8];
pc8001.z80.ops[0xdd][0x6c]=["LD","X","J",8];
pc8001.z80.ops[0xdd][0x6d]=["LD","X","X",8];
pc8001.z80.ops[0xfd][0x26]=["LD","K","n",11];
pc8001.z80.ops[0xfd][0x2e]=["LD","Y","n",11];
pc8001.z80.ops[0xfd][0x36]=["LD","(KY+d)","n",19];
pc8001.z80.ops[0xfd][0x64]=["LD","K","K",8];
pc8001.z80.ops[0xfd][0x65]=["LD","K","Y",8];
pc8001.z80.ops[0xfd][0x6c]=["LD","Y","K",8];
pc8001.z80.ops[0xfd][0x6d]=["LD","Y","Y",8];
pc8001.z80.mnemonics["LD"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var a=-1;
  var b,c;
  switch(m[1].length){
    case 4:
      if(m[1]=="(nn)"){
        a=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
        pc8001.z80.regs["PC"]=pc=(pc+2)&0xffff;
      }
      else
        a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
  }
  switch(m[2].length){
    case 1:
      if(m[2]=="n"){
        c=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        c=pc8001.z80.regs[m[2]];
      break;
    case 4:
      if(m[2]=="(nn)"){
        b=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
        pc8001.z80.regs["PC"]=pc=(pc+2)&0xffff;
      }
      else
        b=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      c=pc8001.memory[b];
      break;
    case 6:
      b=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(b>0x7f)
        b+=0xff00;
      b+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      c=pc8001.memory[b&0xffff];
  }
  if(a<0)
    pc8001.z80.regs[m[1]]=c;
  else
    pc8001.writeMemory(a,c);
}
pc8001.z80.ops[0x01]=["LD16","BC","nn",10];
pc8001.z80.ops[0x11]=["LD16","DE","nn",10];
pc8001.z80.ops[0x21]=["LD16","HL","nn",10];
pc8001.z80.ops[0x22]=["LD16","(nn)","HL",16];
pc8001.z80.ops[0x2a]=["LD16","HL","(nn)",16];
pc8001.z80.ops[0x31]=["LD16","SP","nn",10];
pc8001.z80.ops[0xf9]=["LD16","SP","HL",6];
pc8001.z80.ops[0xed][0x43]=["LD16","(nn)","BC",20];
pc8001.z80.ops[0xed][0x4b]=["LD16","BC","(nn)",20];
pc8001.z80.ops[0xed][0x53]=["LD16","(nn)","DE",20];
pc8001.z80.ops[0xed][0x5b]=["LD16","DE","(nn)",20];
pc8001.z80.ops[0xdd][0x21]=["LD16","JX","nn",14];
pc8001.z80.ops[0xdd][0xf9]=["LD16","SP","JX",10];
pc8001.z80.ops[0xfd][0x21]=["LD16","KY","nn",14];
pc8001.z80.ops[0xfd][0xf9]=["LD16","SP","KY",10];
pc8001.z80.mnemonics["LD16"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var h,l,a;
  switch(m[2]){
    case "nn":
      l=pc8001.memory[pc];
      h=pc8001.memory[(pc+1)&0xffff];
      pc=pc8001.z80.regs["PC"]=(pc+2)&0xffff;
      break;
    case "(nn)":
      a=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
      pc=pc8001.z80.regs["PC"]=(pc+2)&0xffff;
      l=pc8001.memory[a];
      h=pc8001.memory[(a+1)&0xffff];
      break;
    default:
      h=pc8001.z80.regs[m[2].substr(0,1)];
      l=pc8001.z80.regs[m[2].substr(1)];
  }
  switch(m[1]){
    case "(nn)":
      a=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
      pc=pc8001.z80.regs["PC"]=(pc+2)&0xffff;
      pc8001.writeMemory(a,l);
      pc8001.writeMemory((a+1)&0xffff,h);
      return;
    case "SP":
      pc8001.z80.regs["SP"]=h*256+l;
      return;
    default:
      pc8001.z80.regs[m[1].substr(0,1)]=h;
      pc8001.z80.regs[m[1].substr(1)]=l;
  }
}
pc8001.z80.ops[0x08]=["EX","AF","af",4];
pc8001.z80.ops[0xe3]=["EX","(SP)","HL",19];
pc8001.z80.ops[0xeb]=["EX","DE","HL",4];
pc8001.z80.mnemonics["EX"]=function(v,m){
  var a,t;
  if(m[1]=="(SP)"){
    a=pc8001.z80.regs["SP"]
    t=pc8001.memory[a];
    pc8001.writeMemory(a,pc8001.z80.regs[m[2].substr(1)]);
    pc8001.z80.regs[m[2].substr(1)]=t;
    a=(a+1)&0xffff;
    t=pc8001.memory[a];
    pc8001.writeMemory(a,pc8001.z80.regs[m[2].substr(0,1)]);
    pc8001.z80.regs[m[2].substr(0,1)]=t;
    return;
  }
  t=pc8001.z80.regs[m[1].substr(0,1)];
  pc8001.z80.regs[m[1].substr(0,1)]=pc8001.z80.regs[m[2].substr(0,1)];
  pc8001.z80.regs[m[2].substr(0,1)]=t;
  if(m[1].substr(1)=="F"){
    a=["Z","C"];
    a.forEach(function(v){
      var b=pc8001.z80.flags[v];
      pc8001.z80.flags[v]=pc8001.z80.flags[v.toLowerCase()];
      pc8001.z80.flags[v.toLowerCase()]=b;
    });
    return;
  }
  t=pc8001.z80.regs[m[1].substr(1)];
  pc8001.z80.regs[m[1].substr(1)]=pc8001.z80.regs[m[2].substr(1)];
  pc8001.z80.regs[m[2].substr(1)]=t;
}
pc8001.z80.ops[0xd9]=["EXX",4];
pc8001.z80.mnemonics["EXX"]=function(v,m){
  var r=["B","C","D","E","H","L"];
  r.forEach(function(v){
    var t=pc8001.z80.regs[v];
    pc8001.z80.regs[v]=pc8001.z80.regs[v.toLowerCase()];
    pc8001.z80.regs[v.toLowerCase()]=t;
  });
}
pc8001.z80.ops[0xdd][0x34]=["INC","(JX+d)",23];
pc8001.z80.ops[0xfd][0x34]=["INC","(KY+d)",23];
pc8001.z80.mnemonics["INC"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var a=-1;
  var c;
  switch(m[1].length){
    case 1:
      c=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      c=pc8001.memory[a];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      c=pc8001.memory[a];
  }
  c=(c+1)&0xff;
  pc8001.z80.flags["Z"]=(c==0)?1:0;
  if(a<0)
    pc8001.z80.regs[m[1]]=c;
  else
    pc8001.writeMemory(a,c);
}
pc8001.z80.ops[0x03]=["INC16","BC",6];
pc8001.z80.ops[0x13]=["INC16","DE",6];
pc8001.z80.ops[0x23]=["INC16","HL",6];
pc8001.z80.ops[0x33]=["INC16","SP",6];
pc8001.z80.mnemonics["INC16"]=function(v,m){
  var c;
  if(m[1]=="SP")
    pc8001.z80.regs["SP"]=(pc8001.z80.regs["SP"]+1)&0xffff;
  else{
    pc8001.z80.regs[m[1].substr(1)]=c=(pc8001.z80.regs[m[1].substr(1)]+1)&0xff;
    if(c==0)
      pc8001.z80.regs[m[1].substr(0,1)]=(pc8001.z80.regs[m[1].substr(0,1)]+1)&0xff;
  }
}
pc8001.z80.ops[0xdd][0x35]=["DEC","(JX+d)",23];
pc8001.z80.ops[0xfd][0x35]=["DEC","(KY+d)",23];
pc8001.z80.mnemonics["DEC"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var a=-1;
  var c;
  switch(m[1].length){
    case 1:
      c=pc8001.z80.regs[m[1]];
      break;
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      c=pc8001.memory[a];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      c=pc8001.memory[a];
  }
  c=(c+0xff)&0xff;
  pc8001.z80.flags["Z"]=(c==0)?1:0;
  if(a<0)
    pc8001.z80.regs[m[1]]=c;
  else
    pc8001.writeMemory(a,c);
}
pc8001.z80.ops[0x0b]=["DEC16","BC",6];
pc8001.z80.ops[0x1b]=["DEC16","DE",6];
pc8001.z80.ops[0x2b]=["DEC16","HL",6];
pc8001.z80.ops[0x3b]=["DEC16","SP",6];
pc8001.z80.mnemonics["DEC16"]=function(v,m){
  var c;
  if(m[1]=="SP")
    pc8001.z80.regs["SP"]=(pc8001.z80.regs["SP"]+0xffff)&0xffff;
  else{
    pc8001.z80.regs[m[1].substr(1)]=c=(pc8001.z80.regs[m[1].substr(1)]+0xff)&0xff;
    if(c==0xff)
      pc8001.z80.regs[m[1].substr(0,1)]=(pc8001.z80.regs[m[1].substr(0,1)]+0xff)&0xff;
  }
}
pc8001.z80.ops[0x09]=["ADD16","HL","BC",11];
pc8001.z80.ops[0x19]=["ADD16","HL","DE",11];
pc8001.z80.ops[0x29]=["ADD16","HL","HL",11];
pc8001.z80.ops[0x39]=["ADD16","HL","SP",11];
pc8001.z80.ops[0xdd][0x09]=["ADD16","JX","BC",15];
pc8001.z80.ops[0xdd][0x19]=["ADD16","JX","DE",15];
pc8001.z80.ops[0xdd][0x29]=["ADD16","JX","JX",15];
pc8001.z80.ops[0xdd][0x39]=["ADD16","JX","SP",15];
pc8001.z80.ops[0xfd][0x09]=["ADD16","KY","BC",15];
pc8001.z80.ops[0xfd][0x19]=["ADD16","KY","DE",15];
pc8001.z80.ops[0xfd][0x29]=["ADD16","KY","KY",15];
pc8001.z80.ops[0xfd][0x39]=["ADD16","KY","SP",15];
pc8001.z80.mnemonics["ADD16"]=function(v,m){
  var c;
  c=pc8001.z80.regs[m[1].substr(0,1)]*256+pc8001.z80.regs[m[1].substr(1)];
  if(m[2]=="SP")
    c+=pc8001.z80.regs["SP"];
  else
    c+=pc8001.z80.regs[m[2].substr(0,1)]*256+pc8001.z80.regs[m[2].substr(1)];
  if(c>0xffff){
    pc8001.z80.flags["C"]=1;
    c&=0xffff;
  }
  else
    pc8001.z80.flags["C"]=0;
  pc8001.z80.regs[m[1].substr(0,1)]=c>>8;
  pc8001.z80.regs[m[1].substr(1)]=c&0xff;
}
pc8001.z80.ops[0xc6]=["ADD","A","n",7];
pc8001.z80.ops[0xdd][0x86]=["ADD","A","(JX+d)",19];
pc8001.z80.ops[0xfd][0x86]=["ADD","A","(KY+d)",19];
pc8001.z80.mnemonics["ADD"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var c,a;
  switch(m[2].length){
    case 4:
      c=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      c=pc8001.memory[a];
      break;
    default:
      if(m[2]=="n"){
        c=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        c=pc8001.z80.regs[m[2]];
  }
  c+=pc8001.z80.regs[m[1]];
  pc8001.z80.flags["C"]=(c>0xff)?1:0;
  c&=0xff;
  pc8001.z80.regs[m[1]]=c;
  pc8001.z80.flags["Z"]=(c==0)?1:0;
}
pc8001.z80.ops[0xed][0x44]=["NEG","A",8];
pc8001.z80.mnemonics["NEG"]=function(v,m){
  var c=(256-pc8001.z80.regs[m[1]])&0xff;
  pc8001.z80.regs[m[1]]=c;
  pc8001.z80.flags["Z"]=(c==0)?1:0;
  pc8001.z80.flags["C"]=(c==0)?0:1;
}
pc8001.z80.ops[0xd6]=["SUB","A","n",7];
pc8001.z80.ops[0xdd][0x96]=["SUB","A","(JX+d)",19];
pc8001.z80.ops[0xfd][0x96]=["SUB","A","(KY+d)",19];
pc8001.z80.mnemonics["SUB"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var c,a;
  switch(m[2].length){
    case 4:
      c=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    case 6:
      a=pc8001.memory[pc];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      c=pc8001.memory[a];
      break;
    default:
      if(m[2]=="n"){
        c=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        c=pc8001.z80.regs[m[2]];
  }
  c=pc8001.z80.regs[m[1]]-c;
  pc8001.z80.flags["C"]=(c<0)?1:0;
  c=(c+256)&0xff;
  pc8001.z80.regs[m[1]]=c;
  pc8001.z80.flags["Z"]=(c==0)?1:0;
}
pc8001.z80.ops[0xed][0x42]=["SBC16","HL","BC",15]
pc8001.z80.ops[0xed][0x52]=["SBC16","HL","DE",15]
pc8001.z80.ops[0xed][0x62]=["SBC16","HL","HL",15]
pc8001.z80.ops[0xed][0x72]=["SBC16","HL","SP",15]
pc8001.z80.mnemonics["SBC16"]=function(v,m){
  var c;
  c=pc8001.z80.regs[m[1].substr(0,1)]*256+pc8001.z80.regs[m[1].substr(1)];
  if(m[2]=="SP")
    c-=pc8001.z80.regs["SP"];
  else
    c-=pc8001.z80.regs[m[2].substr(0,1)]*256+pc8001.z80.regs[m[2].substr(1)];
  c-=pc8001.z80.flags["C"]
  if(c<0){
    pc8001.z80.flags["C"]=1;
    c=(c+65536)&0xffff;
  }
  else
    pc8001.z80.flags["C"]=0;
  pc8001.z80.regs[m[1].substr(0,1)]=c>>8;
  pc8001.z80.regs[m[1].substr(1)]=c&0xff;
  pc8001.z80.flags["Z"]=(c==0)?1:0;
}
pc8001.z80.ops[0xe6]=["AND","A","n",7];
pc8001.z80.mnemonics["AND"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var c;
  switch(m[2].length){
    case 4:
      c=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    default:
      if(m[2]=="n"){
        c=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        c=pc8001.z80.regs[m[2]];
  }
  c&=pc8001.z80.regs[m[1]];
  pc8001.z80.regs[m[1]]=c;
  pc8001.z80.flags["Z"]=(c==0)?1:0;
  pc8001.z80.flags["C"]=0;
}
pc8001.z80.ops[0x2f]=["CPL","A",4];
pc8001.z80.mnemonics["CPL"]=function(v,m){
  pc8001.z80.regs[m[1]]^=0xff;
}
pc8001.z80.ops[0xee]=["XOR","A","n",7];
pc8001.z80.mnemonics["XOR"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var c;
  switch(m[2].length){
    case 4:
      c=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    default:
      if(m[2]=="n"){
        c=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        c=pc8001.z80.regs[m[2]];
  }
  c^=pc8001.z80.regs[m[1]];
  pc8001.z80.regs[m[1]]=c;
  pc8001.z80.flags["Z"]=(c==0)?1:0;
  pc8001.z80.flags["C"]=0;
}
pc8001.z80.ops[0xf6]=["OR","A","n",7];
pc8001.z80.mnemonics["OR"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var c;
  switch(m[2].length){
    case 4:
      c=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    default:
      if(m[2]=="n"){
        c=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        c=pc8001.z80.regs[m[2]];
  }
  c|=pc8001.z80.regs[m[1]];
  pc8001.z80.regs[m[1]]=c;
  pc8001.z80.flags["Z"]=(c==0)?1:0;
  pc8001.z80.flags["C"]=0;
}
pc8001.z80.ops[0xfe]=["CP","A","n",7];
pc8001.z80.mnemonics["CP"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var c;
  switch(m[2].length){
    case 4:
      c=pc8001.memory[pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)]];
      break;
    default:
      if(m[2]=="n"){
        c=pc8001.memory[pc];
        pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      }
      else
        c=pc8001.z80.regs[m[2]];
  }
  c=pc8001.z80.regs[m[1]]-c;
  pc8001.z80.flags["C"]=(c<0)?1:0;
  c=(c+256)&0xff;
  pc8001.z80.flags["Z"]=(c==0)?1:0;
}
pc8001.z80.ops[0xc2]=["JP","NZ","nn",10];
pc8001.z80.ops[0xc3]=["JP","","nn",10];
pc8001.z80.ops[0xca]=["JP","Z","nn",10];
pc8001.z80.ops[0xd2]=["JP","NC","nn",10];
pc8001.z80.ops[0xda]=["JP","C","nn",10];
pc8001.z80.ops[0xe9]=["JP","","(HL)",4];
pc8001.z80.mnemonics["JP"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var c=1;
  switch(m[1].length){
    case 1:
      c=pc8001.z80.flags[m[1]];
      break;
    case 2:
      c=1-pc8001.z80.flags[m[1].substr(1)];
  }
  if(c==0){
    if(m[2]=="nn")
      pc8001.z80.regs["PC"]=(pc+2)&0xffff;
    return;
  }
  switch(m[2].length){
    case 2:
      pc8001.z80.regs["PC"]=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
      return;
    case 4:
      pc8001.z80.regs["PC"]=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      return;
  }
}
pc8001.z80.ops[0x10]=["JR","DJNZ","e",13];
pc8001.z80.ops[0x18]=["JR","","e",12];
pc8001.z80.ops[0x20]=["JR","NZ","e",12];
pc8001.z80.ops[0x28]=["JR","Z","e",12];
pc8001.z80.ops[0x30]=["JR","NC","e",12];
pc8001.z80.ops[0x38]=["JR","C","e",12];
pc8001.z80.mnemonics["JR"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var c=1;
  switch(m[1].length){
    case 1:
      c=pc8001.z80.flags[m[1]];
      break;
    case 2:
      c=1-pc8001.z80.flags[m[1].substr(1)];
      break;
    case 4:
      pc8001.z80.regs["B"]=c=(pc8001.z80.regs["B"]+0xff)&0xff;
  }
  if(c==0){
    if(m[2]=="e")
      pc8001.z80.regs["PC"]=(pc+1)&0xffff;
    return;
  }
  c=pc8001.memory[pc];
  pc8001.z80.regs["PC"]=((c>0x7f)?pc+0xff01+c:pc+1+c)&0xffff;
}
pc8001.z80.ops[0xc4]=["CALL","NZ","nn",17];
pc8001.z80.ops[0xc7]=["CALL","","0000",11];
pc8001.z80.ops[0xcc]=["CALL","Z","nn",17];
pc8001.z80.ops[0xcd]=["CALL","","nn",17];
pc8001.z80.ops[0xcf]=["CALL","","0008",11];
pc8001.z80.ops[0xd4]=["CALL","NC","nn",17];
pc8001.z80.ops[0xd7]=["CALL","","0010",11];
pc8001.z80.ops[0xdc]=["CALL","C","nn",17];
pc8001.z80.ops[0xdf]=["CALL","","0018",11];
pc8001.z80.ops[0xe7]=["CALL","","0020",11];
pc8001.z80.ops[0xef]=["CALL","","0028",11];
pc8001.z80.ops[0xf7]=["CALL","","0030",11];
pc8001.z80.ops[0xff]=["CALL","","0038",11];
pc8001.z80.mnemonics["CALL"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var sp=pc8001.z80.regs["SP"];
  var c=1;
  switch(m[1].length){
    case 1:
      c=pc8001.z80.flags[m[1]];
      break;
    case 2:
      c=1-pc8001.z80.flags[m[1].substr(1)];
  }
  if(c==0){
    if(m[2]=="nn")
      pc8001.z80.regs["PC"]=(pc+2)&0xffff;
    return;
  }
  if(m[2]=="nn"){
    a=pc8001.memory[pc]+pc8001.memory[(pc+1)&0xffff]*256;
    pc=(pc+2)&0xffff;
  }
  else
    a=parseInt(m[2],16);
  pc8001.writeMemory((sp+0xffff)&0xffff,pc>>8);
  pc8001.z80.regs["SP"]=sp=(sp+0xfffe)&0xffff;
  pc8001.writeMemory(sp,pc&0xff);
  pc8001.z80.regs["PC"]=a;
}
pc8001.z80.ops[0xc0]=["RET","NZ",11];
pc8001.z80.ops[0xc8]=["RET","Z",11];
pc8001.z80.ops[0xc9]=["RET","",10];
pc8001.z80.ops[0xd0]=["RET","NC",11];
pc8001.z80.ops[0xd8]=["RET","C",11];
pc8001.z80.mnemonics["RET"]=function(v,m){
  var sp=pc8001.z80.regs["SP"];
  var c=1;
  switch(m[1].length){
    case 1:
      c=pc8001.z80.flags[m[1]];
      break;
    case 2:
      c=1-pc8001.z80.flags[m[1].substr(1)];
  }
  if(c==0)
    return;
  pc8001.z80.regs["PC"]=pc8001.memory[sp]+pc8001.memory[(sp+1)&0xffff]*256;
  pc8001.z80.regs["SP"]=(sp+2)&0xffff;
}
pc8001.z80.ops[0xc5]=["PUSH","BC",11];
pc8001.z80.ops[0xd5]=["PUSH","DE",11];
pc8001.z80.ops[0xe5]=["PUSH","HL",11];
pc8001.z80.ops[0xf5]=["PUSH","AF",11];
pc8001.z80.ops[0xdd][0xe5]=["PUSH","JX",15];
pc8001.z80.ops[0xfd][0xe5]=["PUSH","KY",15];
pc8001.z80.mnemonics["PUSH"]=function(v,m){
  var sp=pc8001.z80.regs["SP"];
  pc8001.writeMemory((sp+0xffff)&0xffff,pc8001.z80.regs[m[1].substr(0,1)]);
  pc8001.z80.regs["SP"]=sp=(sp+0xfffe)&0xffff;
  if(m[1]=="AF")
    pc8001.writeMemory(sp,pc8001.z80.flags["C"]+(pc8001.z80.flags["Z"]<<6));
  else
    pc8001.writeMemory(sp,pc8001.z80.regs[m[1].substr(1)]);
}
pc8001.z80.ops[0xc1]=["POP","BC",10];
pc8001.z80.ops[0xd1]=["POP","DE",10];
pc8001.z80.ops[0xe1]=["POP","HL",10];
pc8001.z80.ops[0xf1]=["POP","AF",10];
pc8001.z80.ops[0xdd][0xe1]=["POP","JX",14];
pc8001.z80.ops[0xfd][0xe1]=["POP","KY",14];
pc8001.z80.mnemonics["POP"]=function(v,m){
  var sp=pc8001.z80.regs["SP"];
  var c=pc8001.memory[sp];
  if(m[1]=="AF"){
    pc8001.z80.flags["Z"]=((c&0x40)==0)?0:1;
    pc8001.z80.flags["C"]=((c&1)==0)?0:1;
  }
  else
    pc8001.z80.regs[m[1].substr(1)]=c;
  pc8001.z80.regs[m[1].substr(0,1)]=pc8001.memory[(sp+1)&0xffff];
  pc8001.z80.regs["SP"]=(sp+2)&0xffff;
}
pc8001.z80.ops[0x07]=["RLCA",4];
pc8001.z80.mnemonics["RLCA"]=function(v,m){
  var t=pc8001.z80.regs["A"];
  var c=(t>0x7f)?1:0;
  pc8001.z80.regs["A"]=((t<<1)+c)&0xff;
  pc8001.z80.flags["C"]=c;
}
pc8001.z80.mnemonics["RLC"]=function(v,m){
  var a,t,c;
  switch(m[1].length){
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      c=(t>0x7f)?1:0;
      t=((t<<1)+c)&0xff;
      pc8001.writeMemory(a,t);
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
      c=(t>0x7f)?1:0;
      t=((t<<1)+c)&0xff;
      pc8001.writeMemory(a,t);
      break;
    default:
      t=pc8001.z80.regs[m[1]];
      c=(t>0x7f)?1:0;
      t=((t<<1)+c)&0xff;
      pc8001.z80.regs[m[1]]=t;
  }
  pc8001.z80.flags["C"]=c;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
}
pc8001.z80.ops[0x0f]=["RRCA",4];
pc8001.z80.mnemonics["RRCA"]=function(v,m){
  var t=pc8001.z80.regs["A"];
  var c=t&1;
  pc8001.z80.regs["A"]=(t>>1)+c*0x80;
  pc8001.z80.flags["C"]=c;
}
pc8001.z80.mnemonics["RRC"]=function(v,m){
  var a,t,c;
  switch(m[1].length){
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      c=t&1;
      t=(t>>1)+c*0x80;
      pc8001.writeMemory(a,t);
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
      c=t&1;
      t=(t>>1)+c*0x80;
      pc8001.writeMemory(a,t);
      break;
    default:
      t=pc8001.z80.regs[m[1]];
      c=t&1;
      t=(t>>1)+c*0x80;
      pc8001.z80.regs[m[1]]=t;
  }
  pc8001.z80.flags["C"]=c;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
}
pc8001.z80.ops[0x17]=["RLA",4];
pc8001.z80.mnemonics["RLA"]=function(v,m){
  var t=pc8001.z80.regs["A"];
  var c=(t>0x7f)?1:0;
  pc8001.z80.regs["A"]=((t<<1)+pc8001.z80.flags["C"])&0xff;
  pc8001.z80.flags["C"]=c;
}
pc8001.z80.mnemonics["RL"]=function(v,m){
  var a,t,c;
  switch(m[1].length){
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      c=(t>0x7f)?1:0;
      t=((t<<1)+pc8001.z80.flags["C"])&0xff;
      pc8001.writeMemory(a,t);
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
      c=(t>0x7f)?1:0;
      t=((t<<1)+pc8001.z80.flags["C"])&0xff;
      pc8001.writeMemory(a,t);
      break;
    default:
      t=pc8001.z80.regs[m[1]];
      c=(t>0x7f)?1:0;
      pc8001.z80.regs[m[1]]=t=((t<<1)+pc8001.z80.flags["C"])&0xff;
  }
  pc8001.z80.flags["C"]=c;
  pc8001.z80.flags["Z"]=(t==0)?1:0;
}
pc8001.z80.ops[0x1f]=["RRA",4];
pc8001.z80.mnemonics["RRA"]=function(v,m){
  var t=pc8001.z80.regs["A"];
  pc8001.z80.regs["A"]=(t>>1)+pc8001.z80.flags["C"]*0x80;
  pc8001.z80.flags["C"]=t&1;
}
pc8001.z80.mnemonics["SRL"]=function(v,m){
  var a,t;
  switch(m[1].length){
    case 4:
      a=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      t=pc8001.memory[a];
      pc8001.writeMemory(a,t>>1);
      break;
    case 7:
      a=parseInt(m[1].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[1].substr(1,1)]*256+pc8001.z80.regs[m[1].substr(2,1)];
      a&=0xffff;
      t=pc8001.memory[a];
      pc8001.writeMemory(a,t>>1);
      break;
    default:
      t=pc8001.z80.regs[m[1]];
      pc8001.z80.regs[m[1]]=(t>>1);
  }
  pc8001.z80.flags["C"]=t&1;
  pc8001.z80.flags["Z"]=(t<2)?1:0;
}
pc8001.z80.mnemonics["BIT"]=function(v,m){
  var a,c;
  switch(m[2].length){
    case 4:
      a=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      c=pc8001.memory[a];
      break;
    case 7:
      a=parseInt(m[2].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      c=pc8001.memory[a];
      break;
    default:
      c=pc8001.z80.regs[m[2]];
  }
  pc8001.z80.flags["Z"]=((c&(1<<m[1]))==0)?1:0;
}
pc8001.z80.mnemonics["RES"]=function(v,m){
  var a;
  switch(m[2].length){
    case 1:
      pc8001.z80.regs[m[2]]&=(1<<m[1])^0xff;
      break;
    case 4:
      a=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      pc8001.writeMemory(a,pc8001.memory[a]&((1<<m[1])^0xff));
      break;
    case 7:
      a=parseInt(m[2].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      pc8001.writeMemory(a,pc8001.memory[a]&((1<<m[1])^0xff));
      break;
  }
}
pc8001.z80.mnemonics["SET"]=function(v,m){
  var a;
  switch(m[2].length){
    case 4:
      a=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      pc8001.writeMemory(a,pc8001.memory[a]|(1<<m[1]));
      break;
    case 7:
      a=parseInt(m[2].substr(4,2),16);
      if(a>0x7f)
        a+=0xff00;
      a+=pc8001.z80.regs[m[2].substr(1,1)]*256+pc8001.z80.regs[m[2].substr(2,1)];
      a&=0xffff;
      pc8001.writeMemory(a,pc8001.memory[a]|(1<<m[1]));
      break;
    default:
      pc8001.z80.regs[m[2]]|=1<<m[1];
  }
}
pc8001.z80.ops[0xed][0xa0]=["LDI",16];
pc8001.z80.mnemonics["LDI"]=function(v,m){
  var hl=pc8001.z80.regs["H"]*256+pc8001.z80.regs["L"];
  var de=pc8001.z80.regs["D"]*256+pc8001.z80.regs["E"];
  var bc=pc8001.z80.regs["B"]*256+pc8001.z80.regs["C"];
  pc8001.writeMemory(de,pc8001.memory[hl]);
  hl=(hl+1)&0xffff;
  de=(de+1)&0xffff;
  bc=(bc+0xffff)&0xffff;
  pc8001.z80.regs["H"]=hl>>8;
  pc8001.z80.regs["L"]=hl&0xff;
  pc8001.z80.regs["D"]=de>>8;
  pc8001.z80.regs["E"]=de&0xff;
  pc8001.z80.regs["B"]=bc>>8;
  pc8001.z80.regs["C"]=bc&0xff;
}
pc8001.z80.ops[0xed][0xb0]=["LDIR",21];
pc8001.z80.mnemonics["LDIR"]=function(v,m){
  var hl=pc8001.z80.regs["H"]*256+pc8001.z80.regs["L"];
  var de=pc8001.z80.regs["D"]*256+pc8001.z80.regs["E"];
  var bc=pc8001.z80.regs["B"]*256+pc8001.z80.regs["C"];
  pc8001.writeMemory(de,pc8001.memory[hl]);
  hl=(hl+1)&0xffff;
  de=(de+1)&0xffff;
  bc=(bc+0xffff)&0xffff;
  pc8001.z80.regs["H"]=hl>>8;
  pc8001.z80.regs["L"]=hl&0xff;
  pc8001.z80.regs["D"]=de>>8;
  pc8001.z80.regs["E"]=de&0xff;
  pc8001.z80.regs["B"]=bc>>8;
  pc8001.z80.regs["C"]=bc&0xff;
  if(bc!=0)
    pc8001.z80.regs["PC"]=(pc8001.z80.regs["PC"]+0xfffe)&0xffff;
}
pc8001.z80.ops[0xed][0xa8]=["LDD",16];
pc8001.z80.mnemonics["LDD"]=function(v,m){
  var hl=pc8001.z80.regs["H"]*256+pc8001.z80.regs["L"];
  var de=pc8001.z80.regs["D"]*256+pc8001.z80.regs["E"];
  var bc=pc8001.z80.regs["B"]*256+pc8001.z80.regs["C"];
  pc8001.writeMemory(de,pc8001.memory[hl]);
  hl=(hl+0xffff)&0xffff;
  de=(de+0xffff)&0xffff;
  bc=(bc+0xffff)&0xffff;
  pc8001.z80.regs["H"]=hl>>8;
  pc8001.z80.regs["L"]=hl&0xff;
  pc8001.z80.regs["D"]=de>>8;
  pc8001.z80.regs["E"]=de&0xff;
  pc8001.z80.regs["B"]=bc>>8;
  pc8001.z80.regs["C"]=bc&0xff;
}
pc8001.z80.ops[0xed][0xb8]=["LDDR",21];
pc8001.z80.mnemonics["LDDR"]=function(v,m){
  var hl=pc8001.z80.regs["H"]*256+pc8001.z80.regs["L"];
  var de=pc8001.z80.regs["D"]*256+pc8001.z80.regs["E"];
  var bc=pc8001.z80.regs["B"]*256+pc8001.z80.regs["C"];
  pc8001.writeMemory(de,pc8001.memory[hl]);
  hl=(hl+0xffff)&0xffff;
  de=(de+0xffff)&0xffff;
  bc=(bc+0xffff)&0xffff;
  pc8001.z80.regs["H"]=hl>>8;
  pc8001.z80.regs["L"]=hl&0xff;
  pc8001.z80.regs["D"]=de>>8;
  pc8001.z80.regs["E"]=de&0xff;
  pc8001.z80.regs["B"]=bc>>8;
  pc8001.z80.regs["C"]=bc&0xff;
  if(bc!=0)
    pc8001.z80.regs["PC"]=(pc8001.z80.regs["PC"]+0xfffe)&0xffff;
}
pc8001.z80.ops[0xdb]=["IN","A","(n)",11];
pc8001.z80.mnemonics["IN"]=function(v,m){
  var c,pc;
  if(m[2]=="(n)"){
    pc=pc8001.z80.regs["PC"];
    c=pc8001.memory[pc];
    pc8001.z80.regs["PC"]=(pc+1)&0xffff;
  }
  else
    c=pc8001.z80.regs[m[2].substr(1,1)];
  pc8001.z80.regs[m[1]]=pc8001.inports[c];
}
pc8001.z80.ops[0xd3]=["OUT","(n)","A",11];
pc8001.z80.mnemonics["OUT"]=function(v,m){
  var c,pc;
  if(m[1]=="(n)"){
    pc=pc8001.z80.regs["PC"];
    c=pc8001.memory[pc];
    pc8001.z80.regs["PC"]=(pc+1)&0xffff;
  }
  else
    c=pc8001.z80.regs[m[1].substr(1,1)];
  pc8001.outports(c,pc8001.z80.regs[m[2]]);
}
pc8001.outports=function(p,d){
  if(p!=0x40){
    pc8001.z80.mnemonics["UNDEF"](p,["UNDEF","OUT",0]);
    return;
  }
  pc8001.beep.on=((d&0x20)==0)?0:1;
}
pc8001.z80.ops[0xdd][0xcb]=["EXTCB","DD CB dd","JX",20];
pc8001.z80.ops[0xfd][0xcb]=["EXTCB","FD CB dd","KY",20];
pc8001.z80.mnemonics["EXTCB"]=function(v,m){
  var pc=pc8001.z80.regs["PC"];
  var d=pc8001.memory[pc];
  var e=pc8001.memory[(pc+1)&0xffff];
  var f=pc8001.z80.ops[0xcb][e].slice();
  pc8001.z80.regs["PC"]=(pc+2)&0xffff;
  if(f[f.length-2]=="(HL)"){
    f[f.length-2]="("+m[2]+"+"+d.toString(16).padStart(2,"0")+")";
    pc8001.z80.mnemonics[f[0]](e,f);
    return;
  }
  pc8001.z80.mnemonics["UNDEF"](e,["UNDEF",m[1],0]);
}
pc8001.z80.run=function(){
  var i,pc,v,m,s;
  for(i=0;i<4000;i++){
    pc=pc8001.z80.regs["PC"];
    v=pc8001.memory[pc];
    m=pc8001.z80.ops[v];
    pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
    s=m[m.length-1];
    if(s<0){
      v=pc8001.memory[pc];
      m=m[v];
      pc8001.z80.regs["PC"]=pc=(pc+1)&0xffff;
      s=m[m.length-1];
    }
    pc8001.z80.states+=s;
    pc8001.z80.mnemonics[m[0]](v,m);
    if(pc8001.z80.halt==1)
      return;
    if(pc8001.beep.counter!=-1){
      v=Math.floor(pc8001.z80.states*pc8001.beep.audio.sampleRate/pc8001.z80.frequency)%pc8001.beep.refWave.length;
      if(v==pc8001.beep.counter){
        pc8001.beep.wave[v]=pc8001.beep.on*pc8001.beep.refWave[v];
        pc8001.beep.counter=(pc8001.beep.counter+1)%pc8001.beep.refWave.length;
      }
    }
    s=pc8001.z80.states-(performance.now()-pc8001.z80.millitimer)*pc8001.z80.millistates;
    if(s>1000)
      break;
  }
  pc8001.z80.timer=setTimeout("clearTimeout(pc8001.z80.timer);pc8001.z80.run()",(s>1000)?s/pc8001.z80.millistates:0);
}
pc8001.run=function(){
  document.addEventListener("keydown",pc8001.keydown);
  document.addEventListener("keyup",pc8001.keyup);
  pc8001.z80.millitimer=performance.now()
  pc8001.z80.run();
}
</script>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink"
 width=984 height=624 viewBox="-2 -2 164 104"
 style="background-color:black"
 onload="pc8001.initDisplay80x25(this);pc8001.run()">
</svg>
</body>
</html>
```

ただ、ビープ音がどんな風に聞こえるかは、当然ブラウザにも依存するはずである。まだまだバグが残っていると思うが、ぜひ遊んでみてほしい。