-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu.js
2933 lines (2461 loc) · 133 KB
/
cpu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if (!cpuCore) {
var cpuCore = [];
}
cpuCore.push(function() {
var cpu = {
name: "Z80"
};
/*
Read this to keep some semblance of sanity.
Warning: This is my own intreptation and understanding of the instructions provided by the Z80 processor. A lot of this was discovered by trial and error.
I tried to keep this code a balance between not repeating myself and in the process creating 18 layers of functions. Pls forgive me and my protension.
I have modified the assembly OP codes to be easier to understand by those not familiar with the Z80 processor's instruction set for the disassembler.
In the mnemonics list below, I've added a reference to the original instruction mnemonic.
Disassembler Instructions:
Terms:
PC - Program Counter. This is a special register used by the CPU. This is the command that's currently being executed.
It always increases by at least 1, and no more than 3 after each instruction, some instructions can increase it by 2 or 3.
OREG - Output to registers. Usually used to determine a memory location, but not always.
IREG - Input from registers. Usually used to load a value from to write somewhere.
P1 - Parameter 1. This will be PC + 1 in memory.
P2 - Parameter 2. This will be PC + 2 in memory.
PTR - Pointer value. If this is set it will look up using the value stored in that memory location, and use it. Basically a pointer.
# - Output values are the location
& - Input values are the location
! - Unknown (Used for UKNOP)
Note: The special flag F will never be specified in IREG or OREG.
Mnemonics:
UKNOP: Unknown Operation
I don't know what this does, so I couldn't write any code to deal with it. An error should be thrown. If one isn't by some chance, crazy things gonna happen.
NOP: No Operation
This spins the CPU +4 cycles. Usually used to let hardware settle, or to wait.
LD2M: Load to memory location
Uses OREG (or P1 and P2) to get a memory location, and writes either P1 or IREG into it.
Note that if there is 2 parameters, and 1 OREG, the pointer flag maybe set.
LD2R: Load to register
Uses both registers in OREG to get a memory location; or, values in P1 and/or P2, and writes that value to one or 2 registers.
If a memory location is provided, only one register will be written to.
If 1 parameter is provided, only 1 register is written to. If 2 parameters are provided, 2 registers are written to.
Note that if there is 2 parameters, and 1 OREG, the pointer flag maybe set.
INCR: Increment register(s) by 1
Increments a register, or 2 registers (the pair register) by 1. Register(s) effected are described in OREG and IREG.
DCRR: Decrement register(s) by 1
Decrements a register, or 2 registers (the pair register) by 1. Register(s) effected are described in OREG and IREG.
INXR: Increment register(s) by X
This loads a value from either P1 and/or P2; or from IREG, then adds and stores it into OREG.
Technically any registers in OREG should also be added into IREG, since they need to be passed into the ALU with IREG, but were left out for brevity's sake.
If two parameters are used, there will be 2 OREGs
If 2 IREGs are used, there will be 2 OREGs
ICXR: Increment carry register(s) by X
This loads a value from either P1 and/or P2; or from IREG, then adds the carry flag from the F register and stores it into OREG.
Technically any registers in OREG should also be added into IREG, since they need to be passed into the ALU with IREG, but were left out for brevity's sake.
If two parameters are used, there will be 2 OREGs
If 2 IREGs are used, there will be 2 OREGs
DEXR: Decrement carry register(s) by X
The first parameter is added to the carry flag in the F register before this operation is performed.
This loads a value from either P1 and/or P2; or from IREG, then substracts and stores it into OREG.
Technically any registers in OREG should also be added into IREG, since they need to be passed into the ALU with IREG, but were left out for brevity's sake.
If two parameters are used, there will be 2 OREGs
If 2 IREGs are used, there will be 2 OREGs
DCXR: Increment register(s) by X
This loads a value from either P1 and/or P2; or from IREG, then subtracts and stores it into OREG.
Technically any registers in OREG should also be added into IREG, since they need to be passed into the ALU with IREG, but were left out for brevity's sake.
If two parameters are used, there will be 2 OREGs
If 2 IREGs are used, there will be 2 OREGs
SUBX: Decrement register(s) by X
This loads a value from either P1 and/or P2; or from IREG, then subtracts it. It does not store the result.
This does modify the F register.
INCM: Increment memory by 1
Increments the value in a memory location by 1.
If IREG has 2 registers present, then that is the memory location.
Otherwise it will be a pointer of P1 and P2
DCRM: Decrement memory by 1
Decrements the value in a memory location by 1.
If IREG has 2 registers present, then that is the memory location.
Otherwise it will be a pointer of P1 and P2
RLC: 8-bit Rotational Left Carry
Rotates the bits loaded from P1, or IREG, and stores them in OREG. The most left bit is moved into the carry flag and to bit 0.
RRC: 8-bit Rotational Right Carry
Rotates the bits loaded from P1, or IREG, and stores them in OREG. The most right bit is moved into the carry flag and to bit 7.
RRC9: 9-bit Rotational Right Carry
Performs a 9-bit right rotation to the bits loaded from P1, or IREG, and stores them in OREG. The carry is copied into bit 7, then the bit leaving on the right is copied into the carry.
RLC9: 9-bit Rotational Left Carry
Performs a 9-bit left rotation to the bits loaded from P1, or IREG, and stores them in OREG. The carry is copied into bit 7, then the bit leaving on the left is copied into the carry.
CPL: Invert All Bits
Inverts all bits from IREG and stores them in OREG
SCF: Set Carry Flag
Sets the carry flag bit (On).
CCF: Inverts the carry flag
Flips the carry flag in the F register
SIF: Sets the interrupt bit
Sets the interrupt flag bit (On).
DIF: Disable the interrupt bit
Turns off the interrupt flag bit (Off).
HALT: Halts
Omea wa mou shindeiru
ANDR: Bitwise AND
Performs a bitwise AND operation on IREG registers, and stores the result into OREG
ORR: Bitwise OR
Performs a bitwise OR operation on IREG registers, and stores the result into OREG
XORR: Bitwise XOR
Performs a bitwise XOR operation on IREG registers, and stores the result into OREG
RETNZ: Return Non-Zero
If the F register is set, and the zero flag is set, then do nothing (moves PC forward 2).
If the F register is set, and the zero flag is NOT set, then get the value from SP and put it into PC. This in effect pops the stack.
RETC: Return Carry
If the F register is set, and the carry flag is set, then get the value from SP and put it into PC. This in effect pops the stack.
If the F register is set, and the carry flag is NOT set, then do nothing (moves PC forward 2).
RETS: Return Sign
If the F register is set, and the sign flag is set, then get the value from SP and put it into PC. This in effect pops the stack.
If the F register is set, and the sign flag is NOT set, then do nothing (moves PC forward 2).
RETP: Return Parity
If the F register is set, and the parity flag is set, then get the value from SP and put it into PC. This in effect pops the stack.
If the F register is set, and the parity flag is NOT set, then do nothing (moves PC forward 2).
RETNP: Return Non-Parity
If the F register is set, and the parity flag is set, then do nothing (moves PC forward 2).
If the F register is set, and the parity flag is NOT set, then get the value from SP and put it into PC. This in effect pops the stack.
RETP: Return Parity
If the F register is set, and the parity flag is set, then get the value from SP and put it into PC. This in effect pops the stack.
If the F register is set, and the parity flag is NOT set, then do nothing (moves PC forward 2).
RET: Return
Gets the SP from memory and sets PC with it.
RETZ: Return Zero
If the F register is set, and the zero flag is set, get the value in memory pointed to by SP, and put it into PC.
If the F register is set, and the zero flag is NOT set, then do nothing (moves PC forward 2).
RETNS: Return Non-Sign
If the F register is set, and the sign flag is set, get the value in memory pointed to by SP, and put it into PC.
If the F register is set, and the sign flag is NOT set, then do nothing (moves PC forward 2).
POPR: Pop stack to register pair
This gets the value stored in SP and stores it into both the IREGs. It also moves SP forward 2.
CALL: Push onto the stack with a pointer
If the F register is set, and the zero flag is set, then do nothing (moves PC forward 2).
If the F register is set, and the zero flag is NOT set, then move SP back 2, temporarily store P1 and P2, write SP into P1 and P2 and jump to the original P1 and P2 values.
CALLZ: Push onto the stack with a pointer if zero
If the F register is set, and the zero flag is set, then move SP back 2 and store PC into it, then jump to P1 and P2 values.
If the F register is set, and the zero flag is NOT set, then do nothing (moves PC forward 2).
CALLP: Push onto the stack with a pointer if parity
If the F register is set, and the parity flag is set, then move SP back 2 and store PC into it, then jump to P1 and P2 values.
If the F register is set, and the parity flag is NOT set, then do nothing (moves PC forward 2).
CALLC: Push onto the stack with a pointer if carry
If the F register is set, and the carry flag is set, then move SP back 2, temporarily store P1 and P2, write SP into P1 and P2 and jump to the original P1 and P2 values.
If the F register is set, and the carry flag is NOT set, then do nothing (moves PC forward 2).
CALLNC: Push onto the stack with a pointer if non-carry
If the F register is set, and the carry flag is set, then do nothing (moves PC forward 2).
If the F register is set, and the carry flag is NOT set, then move SP back 2, temporarily store P1 and P2, write SP into P1 and P2 and jump to the original P1 and P2 values.
CALLNP: Push onto the stack with a pointer if non-parity
If the F register is set, and the parity flag is set, then do nothing (moves PC forward 2).
If the F register is set, and the parity flag is NOT set, then move SP back 2, temporarily store P1 and P2, write SP into P1 and P2 and jump to the original P1 and P2 values.
CALLS: Push onto the stack with a pointer if sign
If the F register is set, and the sign flag is set, then move SP back 2, temporarily store P1 and P2, write SP into P1 and P2 and jump to the original P1 and P2 values.
If the F register is set, and the sign flag is NOT set, then do nothing (moves PC forward 2).
CALLS: Push onto the stack with a pointer if not sign
If the F register is set, and the sign flag is set, then do nothing (moves PC forward 2).
If the F register is set, and the sign flag is NOT set, then move SP back 2, temporarily store P1 and P2, write SP into P1 and P2 and jump to the original P1 and P2 values.
PUSH: Push onto the stack
Move both IREGs, or P1 and P2 into SP and move SP back 2.
PUSHNZ: Push onto the stack if non-zero
If the F register is set, and the zero flag is set, then do nothing (moves PC forward 2).
If the F register is set, and the zero flag is NOT set, then move both IREGs into SP and move SP back 2.
JMPNZ: Jump if non-zero
If the F register is set, and the zero flag is set, then set PC to P1 and P2
If the F register is set, and the zero flag is NOT set, then move PC forward 2, and do a NOP.
JMPNC: Jump if non-carry
If the F register is set, and the carry flag is set, then move PC forward 2, and do a NOP.
If the F register is set, and the zero flag is NOT set, then set PC to P1 and P2.
JMP: Jump to an address
Sets PC to P1 and P2, or both IREGs
JMPC: Jump if carry
If the F register is set, and the carry flag is set, then set PC to P1 and P2
If the F register is set, and the carry flag is NOT set, then move PC forward 2, and do a NOP.
JMPP: Jump if parity
If the F register is set, and the parity flag is set, then set PC to P1 and P2
If the F register is set, and the parity flag is NOT set, then move PC forward 2, and do a NOP.
JMPZ: Jump if zero
If the F register is set, and the zero flag is set, then set PC to P1 and P2
If the F register is set, and the zero flag is NOT set, then move PC forward 2, and do a NOP.
JMPS: Jump if sign
If the F register is set, and the sign flag is set, then set PC to P1 and P2
If the F register is set, and the sign flag is NOT set, then move PC forward 2, and do a NOP.
JMPNS: Jump if Non-sign
If the F register is set, and the sign flag is set, then move PC forward 2, and do a NOP.
If the F register is set, and the sign flag is NOT set, then set PC to P1 and P2
XCHM: Swap register value with memory
This swaps the value in a register with the value in a memory location. This can work with bytes and words.
XCHR: Swap register values with each other
This swaps the values stored in 2 registers. This can work with register pairs.
HWIN: Hardware Input
Read data from the hardware. It can be accessed with cpu.hwIntPorts[0 - 255]
HWOUT: Hardware Input
Write data to the hardware. It can be accessed with cpu.hwIntPorts[0 - 255]
NEXTOP: Next OP Register
The next operation will be performed on either the IX or IY special register, instead of on the HL register.
RST [number]: Reset/Move
This looks like it resets the machine, or is used to jump to specific points in memory.
It stores PC into SP, and moves SP back 2, before setting PC to the predetermined locations listed below.
The [number] is where it's moving PC to after execution. These numbers are discrete.
RST 00 means PC = 0
RST 08 means PC = 64 (0x08 * 8)
RST 10 means PC = 128 (0x10 * 8)
RST 18 means PC = 192 (0x18 * 8)
RST 20 means PC = 256 (0x20 * 8)
RST 28 means PC = 320 (0x28 * 8)
RST 30 means PC = 384 (0x30 * 8)
RST 38 means PC = 448 (0x30 * 8)
// */
var cpuFlags = Object.freeze({
a: 0, // Results from the ALU usually end up here. 2 bytes, grouped with F.
b: 0, // General register, 2 bytes, grouped with C
c: 0, // General register, 2 bytes, grouped with B
d: 0, // General register, 2 bytes, grouped with E
e: 0, // General register, 2 bytes, grouped with D
f: 0, // F is a special flag. Mainly used for overflows and parity. 2 bytes, grouped with A
h: 0, // General register, 2 bytes, grouped with L. These are generally used as a buffer, or for calculations.
l: 0, // General register, 2 bytes, grouped with H. These are generally used as a buffer, or for calculations.
ix: 0, // Index Register
iy: 0, // Index Register
sp: 0, // Stack pointer, 4 bytes
pc: 0, // Program counter (Current executing address), 4 bytes
enabled: 1 // Chip enabled
});
const fFlags = Object.freeze({
carry: 0x01,
parity: 0x04,
halfcarry: 0x10,
interrupt: 0x20,
zero: 0x40,
sign: 0x80,
});
var debugFlags = Object.freeze({
executionCount: 0,
totalCPUCycles: 0,
cycleRollover: false,
nextOpIReg: "" // Let the emulator know the next instruction is for IX or IY and not HL.
});
cpu.hwIntPorts = [];
cpu.flags = JSON.parse(JSON.stringify(cpuFlags));
cpu.db = JSON.parse(JSON.stringify(debugFlags));
cpu.cycles = 0;
cpu.lastOpCycle = 0;
cpu.modeClock = 0;
cpu.pInterrupt = 0x10;
cpu.memory = [];
cpu.warningCb;
cpu.memoryUpdateCb;
cpu.isHalted = false;
cpu.disassemble8080OP = function(state, pc) {
var memory = state.memory;
// Not all OPCodes will have 3 bytes. The trailing bytes are ignored if unsed.
var opCode = [memory[pc], memory[pc + 1], memory[pc + 2]];
var output = {
execCount: 0,
programCounter: 0,
opCode: "",
z80OPCode: "", // I added this so the Z80 op codes could be referenced.
opCodeHex: 0,
ireg: "", // Input registers
oreg: "", // Output registers (usually determing a memory location)
para1: "",
para2: "",
ptr: "",
opBytes: 0,
cycles: 0,
cycleConditional: false,
error: true,
indexRegUsed: false
};
output.execCount = state.db.executionCount;
output.programCounter = pc.toString(16);
if (opCode[0] == null && pc < state.memory.length) {
if (typeof(state.warningCb) === 'function') { state.warningCb('disassemble8080OP', state, ["Warning: No instruction passed: ", opCode, 'State: ', state, "PC", pc ]); }
return output;
} else if (pc >= state.memory.length) {
output.opCode = "--";
return output;
}
if ((opCode[1] == null && pc + 1 < state.memory.length) || (opCode[2] == null && pc + 2 < state.memory.length) ) {
if (typeof(state.warningCb) === 'function') { state.warningCb('disassemble8080OP', state, ["Warning: OP Code undefined.", opCode, 'State: ', state, "PC", pc ]); }
return output;
}
output.opCodeHex = opCode[0].toString(16);
output.opBytes = 1;
switch (opCode[0]) {
case 0x00: output.opCode = "NOP"; output.z80OPCode = "NOP"; output.cycles = 4; break;
case 0x01: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 10; output.oreg = "BC"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0x02: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "#"; output.oreg = "BC"; output.ireg = "A"; break;
case 0x03: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 6; output.ireg = "BC"; output.oreg = "BC"; break;
case 0x04: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 5; output.ireg = "B"; output.oreg = "B"; break;
case 0x05: output.opCode = "DCRR"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "B"; output.ireg = "B"; break;
case 0x06: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.oreg = "B"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0x07: output.opCode = "RLCA"; output.z80OPCode = "RCLA"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0x08: output.opCode = "NOP"; output.z80OPCode = "NOP"; output.cycles = 4; break;
case 0x09: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 11; output.ireg = "BC"; output.oreg = "HL"; break;
case 0x0a: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "&"; output.oreg = "A"; output.ireg = "BC"; break;
case 0x0b: output.opCode = "DCRR"; output.z80OPCode = "DEC"; output.cycles = 6; output.ireg = "BC"; output.ireg = "BC"; break;
case 0x0c: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 5; output.ireg = "C"; output.oreg = "C"; break;
case 0x0d: output.opCode = "DCRR"; output.z80OPCode = "DEC"; output.cycles = 5; output.ireg = "C"; output.oreg = "C"; break;
case 0x0e: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.oreg = "C"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0x0f: output.opCode = "RRCA"; output.z80OPCode = "RRCA"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0x10: output.opCode = "NOP"; output.z80OPCode = "NOP"; output.cycles = 4; break;
case 0x11: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 10; output.oreg = "DE"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0x12: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "#"; output.oreg = "DE"; output.ireg = "A"; break;
case 0x13: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 6; output.oreg = "DE"; output.ireg = "DE"; break;
case 0x14: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 5; output.oreg = "D"; output.ireg = "D"; break;
case 0x15: output.opCode = "DCRR"; output.z80OPCode = "DEC"; output.cycles = 5; output.ireg = "D"; break;
case 0x16: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.oreg = "D"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0x17: output.opCode = "RLC9"; output.z80OPCode = "RLA"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0x18: output.opCode = "NOP"; output.z80OPCode = "NOP"; output.cycles = 4; break;
case 0x19: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 11; output.oreg = "HL"; output.ireg = "DE"; break;
case 0x1a: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "&"; output.ireg = "DE"; output.oreg = "A"; break;
case 0x1b: output.opCode = "DCRR"; output.z80OPCode = "DEC"; output.cycles = 6; output.oreg = "DE"; output.ireg = "DE"; break;
case 0x1c: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 5; output.ireg = "E"; output.oreg = "E"; break;
case 0x1d: output.opCode = "DCRR"; output.z80OPCode = "DEC"; output.cycles = 5; output.ireg = "E"; output.oreg = "E"; break;
case 0x1e: output.opCode = "UNKOP"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "!"; output.para1 = opCode[1].toString(16); output.para2 = opCode[1].toString(16); output.opBytes = 2; break;
case 0x1f: output.opCode = "RRC"; output.z80OPCode = "RRA"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0x20: output.opCode = "NOP"; output.z80OPCode = "NOP"; output.cycles = 4; break;
case 0x21: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 10; output.oreg = "HL"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0x22: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 16; output.ireg = "HL"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0x23: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 6; output.oreg = "HL"; output.ireg = "HL"; break;
case 0x24: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 5; output.ireg = "H"; output.oreg = "H"; break;
case 0x25: output.opCode = "DCRR"; output.z80OPCode = "DEC"; output.cycles = 5; output.ireg = "H"; output.oreg = "H"; break;
case 0x26: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.oreg = "H"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0x27: output.opCode = "NOP"; output.z80OPCode = "DAA"; output.cycles = 7; output.ptr = "!"; output.para1 = opCode[1].toString(16); output.para2 = opCode[1].toString(16); output.opBytes = 2; break;
case 0x28: output.opCode = "NOP"; output.z80OPCode = "NOP"; output.cycles = 4; break;
case 0x29: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 11; output.oreg = "HL"; output.ireg = "HL"; break;
case 0x2a: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 16; output.ptr = "&"; output.oreg = "HL"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0x2b: output.opCode = "DCRR"; output.z80OPCode = "DEC"; output.cycles = 6; output.ireg = "HL"; output.oreg = "HL"; break;
case 0x2c: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 5; output.ireg = "L"; output.oreg = "L"; break;
case 0x2d: output.opCode = "DCRR"; output.z80OPCode = "DEC"; output.cycles = 5; output.ireg = "L"; output.oreg = "L"; break;
case 0x2e: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.oreg = "L"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0x2f: output.opCode = "CPL"; output.z80OPCode = "CPL"; output.cycles = 4; output.oreg = "A"; break;
case 0x30: output.opCode = "NOP"; output.z80OPCode = "NOP"; output.cycles = 4; break;
case 0x31: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 10; output.oreg = "SP"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0x32: output.opCode = "LD2M"; output.z80OPCode = "INC"; output.cycles = 13; output.ptr = "#"; output.ireg = "A"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0x33: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 6; output.oreg = "SP"; output.ireg = "SP"; break;
case 0x34: output.opCode = "INCM"; output.z80OPCode = "INC"; output.cycles = 10; output.ptr = "#"; output.oreg = "HL"; output.ireg = "HL"; break;
case 0x35: output.opCode = "DCRM"; output.z80OPCode = "DEC"; output.cycles = 10; output.ptr = "#"; output.oreg = "HL"; output.ireg = "HL"; break;
case 0x36: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 10; output.ptr = "#"; output.oreg = "HL"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0x37: output.opCode = "SCF"; output.z80OPCode = "SCF"; output.cycles = 4; break;
case 0x38: output.opCode = "NOP"; output.z80OPCode = "NOP"; output.cycles = 4; break;
case 0x39: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.oreg = "HL"; output.ireg = "SP"; output.cycles = 11; break;
case 0x3a: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 13; output.ptr = "$"; output.oreg = "A"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0x3b: output.opCode = "DCRR"; output.z80OPCode = "DEC"; output.cycles = 6; output.ireg = "SP"; output.oreg = "SP"; break;
case 0x3c: output.opCode = "INCR"; output.z80OPCode = "INC"; output.cycles = 6; output.ireg = "A"; output.oreg = "A"; break;
case 0x3d: output.opCode = "DCRR"; output.z80OPCode = "DEC"; output.cycles = 5; output.ireg = "A"; output.oreg = "A"; break;
case 0x3e: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.oreg = "A"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0x3f: output.opCode = "CCF"; output.z80OPCode = "CCF"; output.cycles = 4; break;
case 0x40: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "B"; output.ireg = "B"; break;
case 0x41: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "B"; output.ireg = "C"; break;
case 0x42: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "B"; output.ireg = "D"; break;
case 0x43: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "B"; output.ireg = "E"; break;
case 0x44: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "B"; output.ireg = "H"; break;
case 0x45: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "B"; output.ireg = "L"; break;
case 0x46: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "$"; output.oreg = "B"; output.ireg = "HL"; break;
case 0x47: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "B"; output.ireg = "A"; break;
case 0x48: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "C"; output.ireg = "B"; break;
case 0x49: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "C"; output.ireg = "C"; break;
case 0x4a: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "C"; output.ireg = "D"; break;
case 0x4b: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "C"; output.ireg = "E"; break;
case 0x4c: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "C"; output.ireg = "H"; break;
case 0x4d: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "C"; output.ireg = "L"; break;
case 0x4e: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "$"; output.oreg = "C"; output.ireg = "HL"; break;
case 0x4f: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "C"; output.ireg = "A"; break;
case 0x50: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "D"; output.ireg = "B"; break;
case 0x51: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "D"; output.ireg = "C"; break;
case 0x52: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "D"; output.ireg = "D"; break;
case 0x53: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "D"; output.ireg = "E"; break;
case 0x54: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "D"; output.ireg = "H"; break;
case 0x55: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "D"; output.ireg = "L"; break;
case 0x56: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "$"; output.oreg = "D"; output.ireg = "HL"; break;
case 0x57: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "D"; output.ireg = "A"; break;
case 0x58: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "E"; output.ireg = "B"; break;
case 0x59: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "E"; output.ireg = "C"; break;
case 0x5a: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "E"; output.ireg = "D"; break;
case 0x5b: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "E"; output.ireg = "E"; break;
case 0x5c: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "E"; output.ireg = "H"; break;
case 0x5d: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "E"; output.ireg = "L"; break;
case 0x5e: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "$"; output.oreg = "E"; output.ireg = "HL"; break;
case 0x5f: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "E"; output.ireg = "A"; break;
case 0x60: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "H"; output.ireg = "B"; break;
case 0x61: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "H"; output.ireg = "C"; break;
case 0x62: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "H"; output.ireg = "D"; break;
case 0x63: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "H"; output.ireg = "E"; break;
case 0x64: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "H"; output.ireg = "H"; break;
case 0x65: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "H"; output.ireg = "L"; break;
case 0x66: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "$"; output.oreg = "H"; output.ireg = "HL"; break;
case 0x67: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "H"; output.ireg = "A"; break;
case 0x68: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "L"; output.ireg = "B"; break;
case 0x69: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "L"; output.ireg = "C"; break;
case 0x6a: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "L"; output.ireg = "D"; break;
case 0x6b: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "L"; output.ireg = "E"; break;
case 0x6c: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "L"; output.ireg = "H"; break;
case 0x6d: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "L"; output.ireg = "L"; break;
case 0x6e: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "$"; output.oreg = "L"; output.ireg = "HL"; break;
case 0x6f: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "L"; output.ireg = "A"; break;
case 0x70: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "#"; output.oreg = "HL"; output.ireg = "B"; break;
case 0x71: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "#"; output.oreg = "HL"; output.ireg = "C"; break;
case 0x72: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "#"; output.oreg = "HL"; output.ireg = "D"; break;
case 0x73: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "#"; output.oreg = "HL"; output.ireg = "E"; break;
case 0x74: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "#"; output.oreg = "HL"; output.ireg = "H"; break;
case 0x75: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "#"; output.oreg = "HL"; output.ireg = "L"; break;
case 0x76: output.opCode = "HLT"; output.z80OPCode = "LD"; output.cycles = 7; break;
case 0x77: output.opCode = "LD2M"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "#"; output.oreg = "HL"; output.ireg = "A"; break;
case 0x78: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "A"; output.ireg = "B"; break;
case 0x79: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "A"; output.ireg = "C"; break;
case 0x7a: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "A"; output.ireg = "D"; break;
case 0x7b: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "A"; output.ireg = "E"; break;
case 0x7c: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "A"; output.ireg = "H"; break;
case 0x7d: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "A"; output.ireg = "L"; break;
case 0x7e: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 7; output.ptr = "$"; output.oreg = "A"; output.ireg = "HL"; break;
case 0x7f: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.cycles = 5; output.oreg = "A"; output.ireg = "A"; break;
case 0x80: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "B"; break;
case 0x81: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "C"; break;
case 0x82: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "D"; break;
case 0x83: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "E"; break;
case 0x84: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "H"; break;
case 0x85: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "L"; break;
case 0x86: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 7; output.ptr = "$"; output.oreg = "A"; output.ireg = "HL"; break;
case 0x87: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0x88: output.opCode = "ICXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "B"; break;
case 0x89: output.opCode = "ICXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "C"; break;
case 0x8a: output.opCode = "ICXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "D"; break;
case 0x8b: output.opCode = "ICXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "E"; break;
case 0x8c: output.opCode = "ICXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "H"; break;
case 0x8d: output.opCode = "ICXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "L"; break;
case 0x8e: output.opCode = "ICXR"; output.z80OPCode = "ADD"; output.cycles = 7; output.ptr = "$"; output.oreg = "A"; output.ireg = "HL"; break;
case 0x8f: output.opCode = "ICXR"; output.z80OPCode = "ADD"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0x90: output.opCode = "DCXR"; output.z80OPCode = "SUB"; output.cycles = 4; output.oreg = "A"; output.ireg = "B"; break;
case 0x91: output.opCode = "DCXR"; output.z80OPCode = "SUB"; output.cycles = 4; output.oreg = "A"; output.ireg = "C"; break;
case 0x92: output.opCode = "DCXR"; output.z80OPCode = "SUB"; output.cycles = 4; output.oreg = "A"; output.ireg = "D"; break;
case 0x93: output.opCode = "DCXR"; output.z80OPCode = "SUB"; output.cycles = 4; output.oreg = "A"; output.ireg = "E"; break;
case 0x94: output.opCode = "DCXR"; output.z80OPCode = "SUB"; output.cycles = 4; output.oreg = "A"; output.ireg = "H"; break;
case 0x95: output.opCode = "DCXR"; output.z80OPCode = "SUB"; output.cycles = 4; output.oreg = "A"; output.ireg = "L"; break;
case 0x96: output.opCode = "DCXR"; output.z80OPCode = "SUB"; output.cycles = 7; output.ptr = "$"; output.oreg = "A"; output.ireg = "HL"; break;
case 0x97: output.opCode = "DCXR"; output.z80OPCode = "SUB"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0x98: output.opCode = "DEXR"; output.z80OPCode = "SBC"; output.cycles = 4; output.oreg = "A"; output.ireg = "B"; break;
case 0x99: output.opCode = "DEXR"; output.z80OPCode = "SBC"; output.cycles = 4; output.oreg = "A"; output.ireg = "C"; break;
case 0x9a: output.opCode = "DEXR"; output.z80OPCode = "SBC"; output.cycles = 4; output.oreg = "A"; output.ireg = "D"; break;
case 0x9b: output.opCode = "DEXR"; output.z80OPCode = "SBC"; output.cycles = 4; output.oreg = "A"; output.ireg = "E"; break;
case 0x9c: output.opCode = "DEXR"; output.z80OPCode = "SBC"; output.cycles = 4; output.oreg = "A"; output.ireg = "H"; break;
case 0x9d: output.opCode = "DEXR"; output.z80OPCode = "SBC"; output.cycles = 4; output.oreg = "A"; output.ireg = "L"; break;
case 0x9e: output.opCode = "DEXR"; output.z80OPCode = "SBC"; output.cycles = 7; output.ptr = "$"; output.oreg = "A"; output.ireg = "HL"; break;
case 0x9f: output.opCode = "DEXR"; output.z80OPCode = "SBC"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0xa0: output.opCode = "ANDR"; output.z80OPCode = "AND"; output.cycles = 4; output.oreg = "A"; output.ireg = "B"; break;
case 0xa1: output.opCode = "ANDR"; output.z80OPCode = "AND"; output.cycles = 4; output.oreg = "A"; output.ireg = "C"; break;
case 0xa2: output.opCode = "ANDR"; output.z80OPCode = "AND"; output.cycles = 4; output.oreg = "A"; output.ireg = "D"; break;
case 0xa3: output.opCode = "ANDR"; output.z80OPCode = "AND"; output.cycles = 4; output.oreg = "A"; output.ireg = "E"; break;
case 0xa4: output.opCode = "ANDR"; output.z80OPCode = "AND"; output.cycles = 4; output.oreg = "A"; output.ireg = "H"; break;
case 0xa5: output.opCode = "ANDR"; output.z80OPCode = "AND"; output.cycles = 4; output.oreg = "A"; output.ireg = "L"; break;
case 0xa6: output.opCode = "ANDR"; output.z80OPCode = "AND"; output.cycles = 7; output.ptr = "$"; output.oreg = "A"; output.ireg = "HL"; break;
case 0xa7: output.opCode = "ANDR"; output.z80OPCode = "AND"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0xa8: output.opCode = "XORR"; output.z80OPCode = "XOR"; output.cycles = 4; output.oreg = "A"; output.ireg = "B"; break;
case 0xa9: output.opCode = "XORR"; output.z80OPCode = "XOR"; output.cycles = 4; output.oreg = "A"; output.ireg = "C"; break;
case 0xaa: output.opCode = "XORR"; output.z80OPCode = "XOR"; output.cycles = 4; output.oreg = "A"; output.ireg = "D"; break;
case 0xab: output.opCode = "XORR"; output.z80OPCode = "XOR"; output.cycles = 4; output.oreg = "A"; output.ireg = "E"; break;
case 0xac: output.opCode = "XORR"; output.z80OPCode = "XOR"; output.cycles = 4; output.oreg = "A"; output.ireg = "H"; break;
case 0xad: output.opCode = "XORR"; output.z80OPCode = "XOR"; output.cycles = 4; output.oreg = "A"; output.ireg = "L"; break;
case 0xae: output.opCode = "XORR"; output.z80OPCode = "XOR"; output.cycles = 7; output.ptr = "$"; output.oreg = "A"; output.ireg = "HL"; break;
case 0xaf: output.opCode = "XORR"; output.z80OPCode = "XOR"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0xb0: output.opCode = "ORR"; output.z80OPCode = "OR"; output.cycles = 4; output.oreg = "A"; output.ireg = "B"; break;
case 0xb1: output.opCode = "ORR"; output.z80OPCode = "OR"; output.cycles = 4; output.oreg = "A"; output.ireg = "C"; break;
case 0xb2: output.opCode = "ORR"; output.z80OPCode = "OR"; output.cycles = 4; output.oreg = "A"; output.ireg = "D"; break;
case 0xb3: output.opCode = "ORR"; output.z80OPCode = "OR"; output.cycles = 4; output.oreg = "A"; output.ireg = "E"; break;
case 0xb4: output.opCode = "ORR"; output.z80OPCode = "OR"; output.cycles = 4; output.oreg = "A"; output.ireg = "H"; break;
case 0xb5: output.opCode = "ORR"; output.z80OPCode = "OR"; output.cycles = 4; output.oreg = "A"; output.ireg = "L"; break;
case 0xb6: output.opCode = "ORR"; output.z80OPCode = "OR"; output.cycles = 7; output.ptr = "$"; output.oreg = "A"; output.ireg = "HL"; break;
case 0xb7: output.opCode = "ORR"; output.z80OPCode = "OR"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0xb8: output.opCode = "SUBX"; output.z80OPCode = "CP"; output.cycles = 4; output.oreg = "A"; output.ireg = "B"; break;
case 0xb9: output.opCode = "SUBX"; output.z80OPCode = "CP"; output.cycles = 4; output.oreg = "A"; output.ireg = "C"; break;
case 0xba: output.opCode = "SUBX"; output.z80OPCode = "CP"; output.cycles = 4; output.oreg = "A"; output.ireg = "D"; break;
case 0xbb: output.opCode = "SUBX"; output.z80OPCode = "CP"; output.cycles = 4; output.oreg = "A"; output.ireg = "E"; break;
case 0xbc: output.opCode = "SUBX"; output.z80OPCode = "CP"; output.cycles = 4; output.oreg = "A"; output.ireg = "H"; break;
case 0xbd: output.opCode = "SUBX"; output.z80OPCode = "CP"; output.cycles = 4; output.oreg = "A"; output.ireg = "L"; break;
case 0xbe: output.opCode = "SUBX"; output.z80OPCode = "CP"; output.cycles = 7; output.ptr = "$"; output.oreg = "A"; output.ireg = "HL"; break;
case 0xbf: output.opCode = "SUBX"; output.z80OPCode = "CP"; output.cycles = 4; output.oreg = "A"; output.ireg = "A"; break;
case 0xc0: output.opCode = "RETNZ"; output.z80OPCode = "RET NZ"; (state.flags.f & fFlags.zero) ? output.cycles = 4 : output.cycles = 11; output.cycleConditional = true; break;
case 0xc1: output.opCode = "POPR"; output.z80OPCode = "POP"; output.cycles = 10; output.oreg = "BC"; output.ireg = "SP"; output.ptr = "$"; break;
case 0xc2: output.opCode = "JMPNZ"; output.z80OPCode = "JP NZ"; output.cycles = 15; (state.flags.f & fFlags.zero) ? output.cycles = 10 : output.cycles = 15; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xc3: output.opCode = "JMP"; output.z80OPCode = "JP"; output.cycles = 10; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xc4: output.opCode = "PUSHNZ"; output.z80OPCode = "CALL NZ"; (state.flags.f & fFlags.zero) ? output.cycles = 11 : output.cycles = 18; output.cycleConditional = true; output.ireg = "BC"; output.ptr = "$"; output.oreg = "SP"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xc5: output.opCode = "PUSH"; output.z80OPCode = "PUSH"; output.cycles = 11; output.ireg = "BC"; output.oreg = "SP"; output.ptr = "#"; break;
case 0xc6: output.opCode = "INXR"; output.z80OPCode = "ADD"; output.cycles = 7; output.oreg = "A"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0xc7: output.opCode = "RST0"; output.z80OPCode = "RST 00"; output.cycles = 11; output.oreg = "SP"; break;
case 0xc8: output.opCode = "RETZ"; output.z80OPCode = "RET Z"; (state.flags.f & fFlags.zero) ? output.cycles = 11 : output.cycles = 5; output.ptr = "$"; output.ireg = "SP"; output.cycleConditional = true; break;
case 0xc9: output.opCode = "RET"; output.z80OPCode = "RET"; output.cycles = 10; output.ireg = "SP"; output.ptr = "$"; break;
case 0xca: output.opCode = "JMPZ"; output.z80OPCode = "JP Z"; (state.flags.f & fFlags.zero) ? output.cycles = 15 : output.cycles = 10; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xcb: output.opCode = "NOP"; output.z80OPCode = "NOP"; output.cycles = 4; break;
case 0xcc: output.opCode = "CALLZ"; output.z80OPCode = "CALL Z"; (state.flags.f & fFlags.zero) ? output.cycles = 18 : output.cycles = 11; output.cycleConditional = true; output.ptr = "#"; output.oreg = "SP"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xcd: output.opCode = "CALL"; output.z80OPCode = "CALL"; output.cycles = 17; output.para1 = opCode[1].toString(16); output.ptr = "#"; output.oreg = "SP"; output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xce: output.opCode = "ICXR"; output.z80OPCode = "ADC"; output.cycles = 7; output.ireg = "A"; output.oreg = "A"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0xcf: output.opCode = "RST1"; output.z80OPCode = "RST08"; output.cycles = 11; output.oreg = "SP"; break;
case 0xd0: output.opCode = "RETNC"; output.z80OPCode = "RET NC"; (state.flags.f & fFlags.carry) ? output.cycles = 5 : output.cycles = 11; output.cycleConditional = true; break;
case 0xd1: output.opCode = "POPR"; output.z80OPCode = "POP"; output.cycles = 10; output.oreg = "DE"; output.ireg = "SP"; output.ptr = "$"; break;
case 0xd2: output.opCode = "JMPNP"; output.z80OPCode = "JP NC"; (state.flags.f & fFlags.carry) ? output.cycles = 10 : output.cycles = 15; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xd3: output.opCode = "HWOUT"; output.z80OPCode = "OUT"; output.cycles = 10; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0xd4: output.opCode = "CALLNC"; output.z80OPCode = "CALL NC"; (state.flags.f & fFlags.carry) ? output.cycles = 11 : output.cycles = 18; output.cycleConditional = true; output.oreg = "SP"; output.ptr = "$"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xd5: output.opCode = "PUSH"; output.z80OPCode = "PUSH"; output.ireg = "DE"; output.oreg = "SP"; output.ptr = "#"; break;
case 0xd6: output.opCode = "DCXR"; output.z80OPCode = "SUB"; output.oreg = "A"; output.ireg = "A"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0xd7: output.opCode = "RST10"; output.z80OPCode = "RST 10"; output.cycles = 11; output.oreg = "SP"; break;
case 0xd8: output.opCode = "RETC"; output.z80OPCode = "RET"; (state.flags.f & fFlags.carry) ? output.cycles = 11 : output.cycles = 5; output.cycleConditional = true; output.ireg = "SP"; break;
case 0xd9: output.opCode = "NOP"; output.z80OPCode = "NOP"; output.cycles = 4; break;
case 0xda: output.opCode = "JMPC"; output.z80OPCode = "JP"; (state.flags.f & fFlags.carry) ? output.cycles = 15 : output.cycles = 10; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xdb: output.opCode = "HWIN"; output.z80OPCode = "EXX"; output.cycles = 10; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0xdc: output.opCode = "CALLC"; output.z80OPCode = "CP"; (state.flags.f & fFlags.carry) ? output.cycles = 18 : output.cycles = 10; output.cycleConditional = true; output.oreg = "SP"; output.ptr = "#"; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break; // TODO: Update cycle count with F flag condition
case 0xdd: output = state.disassemble8080OP(state, pc + 1); output.opBytes += 1; output.indexRegUsed = "IX"; output.z80OPCode = "**"; output.cycles += 10; break;
case 0xde: output.opCode = "DEXR"; output.z80OPCode = "SBC"; output.cycles = 7; output.para1 = opCode[1].toString(16); output.oreg = "A"; output.ireg = "A"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0xdf: output.opCode = "RST18"; output.z80OPCode = "RST 18"; output.cycles = 11; output.oreg = "SP"; break;
case 0xe0: output.opCode = "RETNP"; output.z80OPCode = "RET"; (state.flags.f & fFlags.parity) ? output.cycles = 5 : output.cycles = 11; output.cycleConditional = true; break;
case 0xe1: output.opCode = "POPR"; output.z80OPCode = "POP"; output.cycles = 10; output.oreg = "HL"; output.ireg = "SP"; output.ptr = "$"; break;
case 0xe2: output.opCode = "JMPNP"; output.z80OPCode = "JP PO"; (state.flags.f & fFlags.parity) ? output.cycles = 10 : output.cycles = 15; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xe3: output.opCode = "XCHM"; output.z80OPCode = "EX"; output.ptr = "$"; output.ireg = "SP"; output.oreg = "HL"; output.cycles = 4; break;
case 0xe4: output.opCode = "UKNOP"; output.z80OPCode = "CALL"; output.ptr = "!"; output.cycles = 18; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break; // TODO: Update cycle count with F flag condition
case 0xe5: output.opCode = "PUSH"; output.z80OPCode = "PUSH"; output.cycles = 11; output.ireg = "HL"; output.oreg = "SP"; output.ptr = "#"; break;
case 0xe6: output.opCode = "ANDR"; output.z80OPCode = "AND"; output.cycles = 11; output.ireg = "A"; output.oreg = "A"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0xe7: output.opCode = "RST20"; output.z80OPCode = "RST 20"; output.cycles = 11; output.oreg = "SP"; break;
case 0xe8: output.opCode = "RETP"; output.z80OPCode = "RET"; (state.flags.f & fFlags.parity) ? output.cycles = 11 : output.cycles = 5; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); break;
case 0xe9: output.opCode = "JMP"; output.z80OPCode = "JP"; output.ireg = "HL"; output.cycles = 4; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); break;
case 0xea: output.opCode = "JMPP"; output.z80OPCode = "JP"; (state.flags.f & fFlags.parity) ? output.cycles = 15 : output.cycles = 10; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xeb: output.opCode = "XCHR"; output.z80OPCode = "EX"; output.cycles = 4; output.ireg = "DE"; output.oreg = "HL"; break;
case 0xec: output.opCode = "UKNOP"; output.z80OPCode = "CALL"; output.ptr = "!"; output.cycles = 18; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break; // TODO: Update cycle count with F flag condition
case 0xed: output.opCode = "NOP"; output.z80OPCode = "UKNOP"; output.ptr = "!"; output.cycles = 4; output.opBytes = 3; break; // Not sure if this is correct
case 0xee: output.opCode = "XORR"; output.z80OPCode = "XOR"; output.cycles = 7; output.para1 = opCode[1].toString(16); output.ireg = "A"; output.oreg = "A"; output.opBytes = 2; break;
case 0xef: output.opCode = "RST28"; output.z80OPCode = "RST 28"; output.cycles = 11; output.oreg = "SP"; break;
case 0xf0: output.opCode = "UKNOP"; output.z80OPCode = "RET"; output.ptr = "!"; output.cycles = 11; break; // TODO: Update cycle count with F flag condition
case 0xf1: output.opCode = "POPR"; output.z80OPCode = "POP"; output.cycles = 10; output.oreg = "AF"; output.ireg = "SP"; output.ptr = "$"; break;
case 0xf2: output.opCode = "JMPNS"; output.z80OPCode = "JP"; (state.flags.f & fFlags.sign) ? output.cycles = 10 : output.cycles = 15; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break; // TODO: Update cycle count with F flag condition
case 0xf3: output.opCode = "DIF"; output.z80OPCode = "DI"; output.cycles = 4; break;
case 0xf4: output.opCode = "CALLS"; output.z80OPCode = "CALL"; (state.flags.f & fFlags.sign) ? output.cycles = 18 : output.cycles = 11; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xf5: output.opCode = "PUSH"; output.z80OPCode = "PUSH"; output.cycles = 11; output.ireg = "AF"; output.oreg = "SP"; output.ptr = "#"; break;
case 0xf6: output.opCode = "ORR"; output.z80OPCode = "OR"; output.cycles = 7; output.oreg = "A"; output.ireg = "A"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0xf7: output.opCode = "RST30"; output.z80OPCode = "RST 30"; output.cycles = 11; output.oreg = "SP"; break;
case 0xf8: output.opCode = "RETS"; output.z80OPCode = "RET"; (state.flags.f & fFlags.sign) ? output.cycles = 11 : output.cycles = 5; output.cycleConditional = true; break;
case 0xf9: output.opCode = "LD2R"; output.z80OPCode = "LD"; output.oreg = "SP"; output.ireg = "HL"; output.cycles = 6; break;
case 0xfa: output.opCode = "JMPS"; output.z80OPCode = "JP"; (state.flags.f & fFlags.sign) ? output.cycles = 15 : output.cycles = 10; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xfb: output.opCode = "SIF"; output.z80OPCode = "EI"; output.cycles = 4; break;
case 0xfc: output.opCode = "CALLS"; output.z80OPCode = "CALL"; (state.flags.f & fFlags.sign) ? output.cycles = 18 : output.cycles = 11; output.cycleConditional = true; output.para1 = opCode[1].toString(16); output.para2 = opCode[2].toString(16); output.opBytes = 3; break;
case 0xfd: output = state.disassemble8080OP(state, pc + 1); output.opBytes += 1; output.indexRegUsed = "IY"; output.z80OPCode = "**"; output.cycles += 10; break;
case 0xfe: output.opCode = "DCXR"; output.z80OPCode = "CP"; output.cycles = 7; output.ireg = "A"; output.para1 = opCode[1].toString(16); output.opBytes = 2; break;
case 0xff: output.opCode = "RST38"; output.z80OPCode = "RST 38"; output.cycles = 7; output.oreg = "SP"; break;
}
if (output.indexRegUsed) {
output.ireg = output.ireg === "HL" ? output.indexRegUsed : output.ireg;
output.oreg = output.oreg === "HL" ? output.indexRegUsed : output.oreg;
}
output.error = false;
return output;
}
cpu.emulate8080OP = function(state) {
// Not all OPCodes will have 3 bytes. The trailing bytes are ignored if unsed.
var opCode = [state.memory[state.flags.pc], state.memory[state.flags.pc + 1], state.memory[state.flags.pc + 2]];
var currentPC = state.flags.pc;
var preCycleChange = state.cycles;
state.flags.pc = (state.flags.pc + 1) & 0xffff;
switch (opCode[0]) {
case 0x00: state.cycles += 4; break; // NOP
case 0x01: // LD2R BC, word
state.flags.c = opCode[1] & 0xff;
state.flags.b = opCode[2] & 0xff;
state.flags.pc += 2;
state.flags.pc &= 0xffff;
state.cycles += 10;
break;
case 0x02: // LD2M (BC),A
var bc = cpu.getFlags(state, "bc");
cpu.writeByte(state, bc, state.flags.a);
state.cycles += 7;
break;
case 0x03: // INCR BC
var bc = cpu.getFlags(state, "bc");
bc++ & 0xffff;
state.flags.b = (bc & 0xff00) >> 8;
state.flags.c = bc & 0xff;
state.cycles += 6;
break;
case 0x04: // INCR B
state.flags.b = cpu.indecrementByte(state, state.flags.b, 1);
state.cycles += 5;
break;
case 0x05: // DCRR B
state.flags.b = cpu.indecrementByte(state, state.flags.b, -1);
state.cycles += 5;
break;
case 0x06: // LD2R B,byte
state.flags.b = opCode[1] & 0xff;
state.flags.pc = (state.flags.pc + 1) & 0xffff;
state.cycles += 7;
break;
case 0x07: // RLC A
var res = state.flags.a >> 7;
if (res) {
state.flags.f |= fFlags.carry;
} else {
state.flags.f &= ~fFlags.carry & 0xff;
}
state.flags.a = (((state.flags.a << 1) & 0xff) | res);
state.cycles += 4;
break;
case 0x08: state.cycles += 4; break; // NOP
case 0x09: // INXR HL, BC
var reg;
if ((state.db.nextOpIReg === "IX") || (state.db.nextOpIReg === "IY")) {
reg = cpu.getFlags(state, state.db.nextOpIReg.toLowerCase());
} else {
reg = cpu.getFlags(state, "hl");
}
var bc = cpu.getFlags(state, "bc");
var res = reg + bc;
if (state.db.nextOpIReg === "IX" || state.db.nextOpIReg === "IY") {
state.flags[state.db.nextOpIReg.toLowerCase()] = res & 0xffff;
} else {
state.flags.h = (res & 0xff00) >> 8;
state.flags.l = res & 0xff;
}
state.cycles += 11;
break;
case 0x0a: // LD2R A,(BC)
state.flags.a = state.memory[cpu.getFlags(state, "bc")];
state.cycles += 7;
break;
case 0x0b: // DCRR BC
var bc = cpu.getFlags(state, "bc");
bc-- & 0xffff;
var ret = cpu.splitBytes(bc);
state.flags.b = ret[1];
state.flags.c = ret[0];
state.cycles += 6;
break;
case 0x0c: // INCR C
state.flags.c = cpu.indecrementByte(state, state.flags.c, 1);
state.cycles += 5;
break;
case 0x0d: // DCRR C
state.flags.c = cpu.indecrementByte(state, state.flags.c, -1);
state.cycles += 5;
break;
case 0x0e: // LD2R C,byte
state.flags.c = opCode[1] & 0xff;
state.flags.pc = (state.flags.pc + 1) & 0xffff;
state.cycles += 7;
break;
case 0x0f: // RRCA
var hi = (state.flags.a & 1) << 7;
if (hi) {
state.flags.f |= fFlags.carry;
} else {
state.flags.f &= ~fFlags.carry & 0xff;
}
state.flags.a = (state.flags.a & 0xfe) >> 1 | hi;
state.cycles += 4;
break;
case 0x10: state.cycles += 4; break;
case 0x11: // LD2R DE,word
state.flags.e = opCode[1] & 0xff;
state.flags.d = opCode[2] & 0xff;
state.flags.pc += 2;
state.flags.pc &= 0xffff;
state.cycles += 10;
break;
case 0x12: // LD2M (DE),A
var de = cpu.getFlags(state, "de");
cpu.writeByte(state, de, state.flags.a);
state.cycles += 7;
break;
case 0x13: // INCR DE
var de = cpu.getFlags(state, "de");
de++ & 0xffff;
state.flags.d = (de & 0xff00) >> 8;
state.flags.e = de & 0xff;
state.cycles += 6;
break;
case 0x14: // INCR D
state.flags.d = cpu.indecrementByte(state, state.flags.d, 1);
state.cycles += 5;
break;
case 0x15: // DCRR D
state.flags.d = cpu.indecrementByte(state, state.flags.d, -1);
state.cycles += 5;
break;
case 0x16: // LD2R D,byte
state.flags.d = opCode[1] & 0xff;
state.flags.pc = (state.flags.pc + 1) & 0xffff;
state.cycles += 7;
break;
case 0x17: // RLC9 A
var carry = (state.flags.f & fFlags.carry) ? 1 : 0;
if(state.flags.a & 0x80) {
state.flags.f |= fFlags.carry;
} else {
state.flags.f &= ~fFlags.carry & 0xff;
}
state.flags.a = ((state.flags.a & 0x7f) << 7) | carry;
state.cycles += 4;
break;
case 0x18: state.cycles += 4; break; // NOP
case 0x19: // INXR HL, DE
var reg;
if ((state.db.nextOpIReg === "IX") || (state.db.nextOpIReg === "IY")) {
reg = cpu.getFlags(state, state.db.nextOpIReg.toLowerCase());
} else {
reg = cpu.getFlags(state, "hl");
}
var de = cpu.getFlags(state, "de");
var res = reg + de;
if (state.db.nextOpIReg === "IX" || state.db.nextOpIReg === "IY") {
state.flags[state.db.nextOpIReg.toLowerCase()] = res & 0xffff;
} else {
state.flags.h = (res & 0xff00) >> 8;
state.flags.l = res & 0xff;
}
state.cycles += 11;
break;
case 0x1a: // LD2R A,(DE)
state.flags.a = state.memory[cpu.getFlags(state, "de")];
state.cycles += 7;
break;
case 0x1b: // DCRR DE
var de = cpu.getFlags(state, "de");
de-- & 0xFFFF;
var ret = cpu.splitBytes(de);
state.flags.e = ret[0];
state.flags.d = ret[1];
state.cycles += 6;
break;
case 0x1c: // INCR E
state.flags.e = cpu.indecrementByte(state, state.flags.e, 1);
state.cycles += 5;
break;
case 0x1d: // DCRR E
state.flags.e = cpu.indecrementByte(state, state.flags.e, -1);
state.cycles += 7;
break;
case 0x1e: // LD2R
state.flags.e = opCode[1] & 0xff;
state.flags.pc = (state.flags.pc + 1) & 0xffff;
state.cycles += 7;
break;
case 0x1f: // RRC A
var carry = (state.flags.f & fFlags.carry) ? 0x80 : 0;
if(state.flags.a & 1) {
state.flags.f |= fFlags.carry;
} else {
state.flags.f &= ~fFlags.carry & 0xff;
}
state.flags.a = ((state.flags.a & 0xfe) >> 1) | carry;
state.cycles += 4;
break;
case 0x20: state.cycles += 4; break; // NOP
case 0x21: // LD2R HL,word
if ((state.db.nextOpIReg === "IX") || (state.db.nextOpIReg === "IY")) {
state.flags[state.db.nextOpIReg.toLowerCase()] = (((opCode[2] << 8) | opCode[1]) & 0xffff);
} else {
state.flags.l = opCode[1] & 0xff;
state.flags.h = opCode[2] & 0xff;
}
state.flags.pc += 2;
state.flags.pc &= 0xffff;
state.cycles += 10;
break;
case 0x22: // LD2M (word),HL
var reg;
if ((state.db.nextOpIReg === "IX") || (state.db.nextOpIReg === "IY")) {
reg = cpu.getFlags(state, state.db.nextOpIReg.toLowerCase());
} else {
reg = cpu.getFlags(state, "hl");
}
cpu.writeWord(state, (((opCode[2] << 8) | opCode[1]) & 0xffff), reg);
state.flags.pc += 2;
state.flags.pc &= 0xffff;
state.cycles += 16;
break;
case 0x23: // INCR HL
if ((state.db.nextOpIReg === "IX") || (state.db.nextOpIReg === "IY")) {
state.flags[state.db.nextOpIReg.toLowerCase()] = cpu.getFlags(state, state.db.nextOpIReg.toLowerCase())++ & 0xffff;
} else {
var hl = cpu.getFlags(state, "hl");
hl++ & 0xffff;
var ret = cpu.splitBytes(hl);
state.flags.h = ret[1];
state.flags.l = ret[0];
}
state.cycles += 6;
break;
case 0x24: // INCR H
state.flags.h = cpu.indecrementByte(state, state.flags.h, 1);
state.cycles += 5;
break;
case 0x25: // DCRR H
state.flags.h = cpu.indecrementByte(state, state.flags.h, -1);
state.cycles += 5;
break;
case 0x26: // LD2R H,byte
state.flags.h = opCode[1] & 0xff;
state.flags.pc = (state.flags.pc + 1) & 0xffff;
state.cycles += 7;
break;
case 0x27: state.cycles += 4; break; // NOP // DAA
case 0x28: state.cycles += 4; break; // NOP
case 0x29: // INXR HL, HL
if ((state.db.nextOpIReg === "IX") || (state.db.nextOpIReg === "IY")) {
var ret = cpu.getFlags(state, state.db.nextOpIReg.toLowerCase());
ret += ret;
state.flags[state.db.nextOpIReg.toLowerCase()] = ret & 0xffff;
} else {
var hl = cpu.getFlags(state, "hl");
var res = hl + hl;
state.flags.h = (res & 0xff00) >> 8;
state.flags.l = res & 0xff;
}
state.cycles += 11;
break;
case 0x2a: // LD2R HL, (word)
var offset = (opCode[2] << 8) | (opCode[1]);
if ((state.db.nextOpIReg === "IX") || (state.db.nextOpIReg === "IY")) {
state.flags[state.db.nextOpIReg.toLowerCase()] = (((opCode[2] << 8) | opCode[1]) & 0xffff);
} else {
state.flags.l = state.memory[(offset) & 0xffff] & 0xff;
state.flags.h = state.memory[(offset + 1) & 0xffff] & 0xff;
}
state.flags.pc += 2;
state.flags.pc &= 0xffff;
state.cycles += 16;
break;
case 0x2b: // DCRR HL
if ((state.db.nextOpIReg === "IX") || (state.db.nextOpIReg === "IY")) {
state.flags[state.db.nextOpIReg.toLowerCase()] = cpu.getFlags(state, state.db.nextOpIReg.toLowerCase())-- & 0xffff;
} else {
var hl = cpu.getFlags(state, "hl");
hl-- & 0xffff;
var ret = cpu.splitBytes(hl);
state.flags.h = ret[1];
state.flags.l = ret[0];
}
state.cycles += 6;
break;
case 0x2c: // INCR L
state.flags.l = cpu.indecrementByte(state, state.flags.l, 1);
state.cycles += 5;
break;
case 0x2d: // DCRR L
state.flags.l = cpu.indecrementByte(state, state.flags.l, -1);
state.cycles += 7;
break;
case 0x2e: // LD2R L,byte
state.flags.l = opCode[1] & 0xff;