-
Notifications
You must be signed in to change notification settings - Fork 22
/
i8080.c
1766 lines (1473 loc) · 43.2 KB
/
i8080.c
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
// Intel 8080 (KR580VM80A) microprocessor core model
//
// Copyright (C) 2012 Alexander Demin <[email protected]>
//
// Credits
//
// Viacheslav Slavinsky, Vector-06C FPGA Replica
// http://code.google.com/p/vector06cc/
//
// Dmitry Tselikov, Bashrikia-2M and Radio-86RK on Altera DE1
// http://bashkiria-2m.narod.ru/fpga.html
//
// Ian Bartholomew, 8080/8085 CPU Exerciser
// http://www.idb.me.uk/sunhillow/8080.html
//
// Frank Cringle, The original exerciser for the Z80.
//
// Thanks to zx.pk.ru and nedopc.org/forum communities.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "i8080.h"
#include "i8080_hal.h"
#define RD_BYTE(addr) i8080_hal_memory_read_byte(addr)
#define RD_WORD(addr) i8080_hal_memory_read_word(addr)
#define WR_BYTE(addr, value) i8080_hal_memory_write_byte(addr, value)
#define WR_WORD(addr, value) i8080_hal_memory_write_word(addr, value)
typedef unsigned char uns8;
typedef unsigned short uns16;
typedef unsigned long int uns32;
typedef signed char sgn8;
typedef signed short sgn16;
typedef signed long int sgn32;
typedef union {
struct {
uns8 l, h;
} b;
uns16 w;
} reg_pair;
typedef struct {
uns8 carry_flag;
uns8 unused1;
uns8 parity_flag;
uns8 unused3;
uns8 half_carry_flag;
uns8 unused5;
uns8 zero_flag;
uns8 sign_flag;
} flag_reg;
struct i8080 {
flag_reg f;
reg_pair af, bc, de, hl;
reg_pair sp, pc;
uns16 iff;
uns16 last_pc;
};
#define FLAGS cpu.f
#define AF cpu.af.w
#define BC cpu.bc.w
#define DE cpu.de.w
#define HL cpu.hl.w
#define SP cpu.sp.w
#define PC cpu.pc.w
#define A cpu.af.b.h
#define F cpu.af.b.l
#define B cpu.bc.b.h
#define C cpu.bc.b.l
#define D cpu.de.b.h
#define E cpu.de.b.l
#define H cpu.hl.b.h
#define L cpu.hl.b.l
#define HSP cpu.sp.b.h
#define LSP cpu.sp.b.l
#define HPC cpu.pc.b.h
#define LPC cpu.pc.b.l
#define IFF cpu.iff
#define F_CARRY 0x01
#define F_UN1 0x02
#define F_PARITY 0x04
#define F_UN3 0x08
#define F_HCARRY 0x10
#define F_UN5 0x20
#define F_ZERO 0x40
#define F_NEG 0x80
#define C_FLAG FLAGS.carry_flag
#define P_FLAG FLAGS.parity_flag
#define H_FLAG FLAGS.half_carry_flag
#define Z_FLAG FLAGS.zero_flag
#define S_FLAG FLAGS.sign_flag
#define UN1_FLAG FLAGS.unused1
#define UN3_FLAG FLAGS.unused3
#define UN5_FLAG FLAGS.unused5
#define SET(flag) (flag = 1)
#define CLR(flag) (flag = 0)
#define TST(flag) (flag)
#define CPL(flag) (flag = !flag)
#define POP(reg) { (reg) = RD_WORD(SP); SP += 2; }
#define PUSH(reg) { SP -= 2; WR_WORD(SP, (reg)); }
#define RET() { POP(PC); }
#define STC() { SET(C_FLAG); }
#define CMC() { CPL(C_FLAG); }
#define INR(reg) \
{ \
++(reg); \
S_FLAG = (((reg) & 0x80) != 0); \
Z_FLAG = ((reg) == 0); \
H_FLAG = (((reg) & 0x0f) == 0); \
P_FLAG = PARITY(reg); \
}
#define DCR(reg) \
{ \
--(reg); \
S_FLAG = (((reg) & 0x80) != 0); \
Z_FLAG = ((reg) == 0); \
H_FLAG = !(((reg) & 0x0f) == 0x0f); \
P_FLAG = PARITY(reg); \
}
#define ADD(val) \
{ \
work16 = (uns16)A + (val); \
index = ((A & 0x88) >> 1) | \
(((val) & 0x88) >> 2) | \
((work16 & 0x88) >> 3); \
A = work16 & 0xff; \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
H_FLAG = half_carry_table[index & 0x7]; \
P_FLAG = PARITY(A); \
C_FLAG = ((work16 & 0x0100) != 0); \
}
#define ADC(val) \
{ \
work16 = (uns16)A + (val) + C_FLAG; \
index = ((A & 0x88) >> 1) | \
(((val) & 0x88) >> 2) | \
((work16 & 0x88) >> 3); \
A = work16 & 0xff; \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
H_FLAG = half_carry_table[index & 0x7]; \
P_FLAG = PARITY(A); \
C_FLAG = ((work16 & 0x0100) != 0); \
}
#define SUB(val) \
{ \
work16 = (uns16)A - (val); \
index = ((A & 0x88) >> 1) | \
(((val) & 0x88) >> 2) | \
((work16 & 0x88) >> 3); \
A = work16 & 0xff; \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
H_FLAG = !sub_half_carry_table[index & 0x7]; \
P_FLAG = PARITY(A); \
C_FLAG = ((work16 & 0x0100) != 0); \
}
#define SBB(val) \
{ \
work16 = (uns16)A - (val) - C_FLAG; \
index = ((A & 0x88) >> 1) | \
(((val) & 0x88) >> 2) | \
((work16 & 0x88) >> 3); \
A = work16 & 0xff; \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
H_FLAG = !sub_half_carry_table[index & 0x7]; \
P_FLAG = PARITY(A); \
C_FLAG = ((work16 & 0x0100) != 0); \
}
#define CMP(val) \
{ \
work16 = (uns16)A - (val); \
index = ((A & 0x88) >> 1) | \
(((val) & 0x88) >> 2) | \
((work16 & 0x88) >> 3); \
S_FLAG = ((work16 & 0x80) != 0); \
Z_FLAG = ((work16 & 0xff) == 0); \
H_FLAG = !sub_half_carry_table[index & 0x7]; \
C_FLAG = ((work16 & 0x0100) != 0); \
P_FLAG = PARITY(work16 & 0xff); \
}
#define ANA(val) \
{ \
H_FLAG = ((A | val) & 0x08) != 0; \
A &= (val); \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
P_FLAG = PARITY(A); \
CLR(C_FLAG); \
}
#define XRA(val) \
{ \
A ^= (val); \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
CLR(H_FLAG); \
P_FLAG = PARITY(A); \
CLR(C_FLAG); \
}
#define ORA(val) \
{ \
A |= (val); \
S_FLAG = ((A & 0x80) != 0); \
Z_FLAG = (A == 0); \
CLR(H_FLAG); \
P_FLAG = PARITY(A); \
CLR(C_FLAG); \
}
#define DAD(reg) \
{ \
work32 = (uns32)HL + (reg); \
HL = work32 & 0xffff; \
C_FLAG = ((work32 & 0x10000L) != 0); \
}
#define CALL \
{ \
PUSH(PC + 2); \
PC = RD_WORD(PC); \
}
#define RST(addr) \
{ \
PUSH(PC); \
PC = (addr); \
}
#define PARITY(reg) parity_table[(reg)]
static struct i8080 cpu;
static uns32 work32;
static uns16 work16;
static uns8 work8;
static int index;
static uns8 carry, add;
int parity_table[] = {
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
};
int half_carry_table[] = { 0, 0, 1, 0, 1, 0, 1, 1 };
int sub_half_carry_table[] = { 0, 1, 1, 1, 0, 0, 0, 1 };
void i8080_init(void) {
C_FLAG = 0;
S_FLAG = 0;
Z_FLAG = 0;
H_FLAG = 0;
P_FLAG = 0;
UN1_FLAG = 1;
UN3_FLAG = 0;
UN5_FLAG = 0;
PC = 0xF800;
}
static void i8080_store_flags(void) {
if (S_FLAG) F |= F_NEG; else F &= ~F_NEG;
if (Z_FLAG) F |= F_ZERO; else F &= ~F_ZERO;
if (H_FLAG) F |= F_HCARRY; else F &= ~F_HCARRY;
if (P_FLAG) F |= F_PARITY; else F &= ~F_PARITY;
if (C_FLAG) F |= F_CARRY; else F &= ~F_CARRY;
F |= F_UN1; // UN1_FLAG is always 1.
F &= ~F_UN3; // UN3_FLAG is always 0.
F &= ~F_UN5; // UN5_FLAG is always 0.
}
static void i8080_retrieve_flags(void) {
S_FLAG = F & F_NEG ? 1 : 0;
Z_FLAG = F & F_ZERO ? 1 : 0;
H_FLAG = F & F_HCARRY ? 1 : 0;
P_FLAG = F & F_PARITY ? 1 : 0;
C_FLAG = F & F_CARRY ? 1 : 0;
}
static int i8080_execute(int opcode) {
int cpu_cycles;
switch (opcode) {
case 0x00: /* nop */
// Undocumented NOP.
case 0x08: /* nop */
case 0x10: /* nop */
case 0x18: /* nop */
case 0x20: /* nop */
case 0x28: /* nop */
case 0x30: /* nop */
case 0x38: /* nop */
cpu_cycles = 4;
break;
case 0x01: /* lxi b, data16 */
cpu_cycles = 10;
BC = RD_WORD(PC);
PC += 2;
break;
case 0x02: /* stax b */
cpu_cycles = 7;
WR_BYTE(BC, A);
break;
case 0x03: /* inx b */
cpu_cycles = 5;
BC++;
break;
case 0x04: /* inr b */
cpu_cycles = 5;
INR(B);
break;
case 0x05: /* dcr b */
cpu_cycles = 5;
DCR(B);
break;
case 0x06: /* mvi b, data8 */
cpu_cycles = 7;
B = RD_BYTE(PC++);
break;
case 0x07: /* rlc */
cpu_cycles = 4;
C_FLAG = ((A & 0x80) != 0);
A = (A << 1) | C_FLAG;
break;
case 0x09: /* dad b */
cpu_cycles = 10;
DAD(BC);
break;
case 0x0A: /* ldax b */
cpu_cycles = 7;
A = RD_BYTE(BC);
break;
case 0x0B: /* dcx b */
cpu_cycles = 5;
BC--;
break;
case 0x0C: /* inr c */
cpu_cycles = 5;
INR(C);
break;
case 0x0D: /* dcr c */
cpu_cycles = 5;
DCR(C);
break;
case 0x0E: /* mvi c, data8 */
cpu_cycles = 7;
C = RD_BYTE(PC++);
break;
case 0x0F: /* rrc */
cpu_cycles = 4;
C_FLAG = A & 0x01;
A = (A >> 1) | (C_FLAG << 7);
break;
case 0x11: /* lxi d, data16 */
cpu_cycles = 10;
DE = RD_WORD(PC);
PC += 2;
break;
case 0x12: /* stax d */
cpu_cycles = 7;
WR_BYTE(DE, A);
break;
case 0x13: /* inx d */
cpu_cycles = 5;
DE++;
break;
case 0x14: /* inr d */
cpu_cycles = 5;
INR(D);
break;
case 0x15: /* dcr d */
cpu_cycles = 5;
DCR(D);
break;
case 0x16: /* mvi d, data8 */
cpu_cycles = 7;
D = RD_BYTE(PC++);
break;
case 0x17: /* ral */
cpu_cycles = 4;
work8 = (uns8)C_FLAG;
C_FLAG = ((A & 0x80) != 0);
A = (A << 1) | work8;
break;
case 0x19: /* dad d */
cpu_cycles = 10;
DAD(DE);
break;
case 0x1A: /* ldax d */
cpu_cycles = 7;
A = RD_BYTE(DE);
break;
case 0x1B: /* dcx d */
cpu_cycles = 5;
DE--;
break;
case 0x1C: /* inr e */
cpu_cycles = 5;
INR(E);
break;
case 0x1D: /* dcr e */
cpu_cycles = 5;
DCR(E);
break;
case 0x1E: /* mvi e, data8 */
cpu_cycles = 7;
E = RD_BYTE(PC++);
break;
case 0x1F: /* rar */
cpu_cycles = 4;
work8 = (uns8)C_FLAG;
C_FLAG = A & 0x01;
A = (A >> 1) | (work8 << 7);
break;
case 0x21: /* lxi h, data16 */
cpu_cycles = 10;
HL = RD_WORD(PC);
PC += 2;
break;
case 0x22: /* shld addr */
cpu_cycles = 16;
WR_WORD(RD_WORD(PC), HL);
PC += 2;
break;
case 0x23: /* inx h */
cpu_cycles = 5;
HL++;
break;
case 0x24: /* inr h */
cpu_cycles = 5;
INR(H);
break;
case 0x25: /* dcr h */
cpu_cycles = 5;
DCR(H);
break;
case 0x26: /* mvi h, data8 */
cpu_cycles = 7;
H = RD_BYTE(PC++);
break;
case 0x27: /* daa */
cpu_cycles = 4;
carry = (uns8)C_FLAG;
add = 0;
if (H_FLAG || (A & 0x0f) > 9) {
add = 0x06;
}
if (C_FLAG || (A >> 4) > 9 || ((A >> 4) >= 9 && (A & 0x0f) > 9)) {
add |= 0x60;
carry = 1;
}
ADD(add);
P_FLAG = PARITY(A);
C_FLAG = carry;
break;
case 0x29: /* dad hl */
cpu_cycles = 10;
DAD(HL);
break;
case 0x2A: /* ldhl addr */
cpu_cycles = 16;
HL = RD_WORD(RD_WORD(PC));
PC += 2;
break;
case 0x2B: /* dcx h */
cpu_cycles = 5;
HL--;
break;
case 0x2C: /* inr l */
cpu_cycles = 5;
INR(L);
break;
case 0x2D: /* dcr l */
cpu_cycles = 5;
DCR(L);
break;
case 0x2E: /* mvi l, data8 */
cpu_cycles = 7;
L = RD_BYTE(PC++);
break;
case 0x2F: /* cma */
cpu_cycles = 4;
A ^= 0xff;
break;
case 0x31: /* lxi sp, data16 */
cpu_cycles = 10;
SP = RD_WORD(PC);
PC += 2;
break;
case 0x32: /* sta addr */
cpu_cycles = 13;
WR_BYTE(RD_WORD(PC), A);
PC += 2;
break;
case 0x33: /* inx sp */
cpu_cycles = 5;
SP++;
break;
case 0x34: /* inr m */
cpu_cycles = 10;
work8 = RD_BYTE(HL);
INR(work8);
WR_BYTE(HL, work8);
break;
case 0x35: /* dcr m */
cpu_cycles = 10;
work8 = RD_BYTE(HL);
DCR(work8);
WR_BYTE(HL, work8);
break;
case 0x36: /* mvi m, data8 */
cpu_cycles = 10;
WR_BYTE(HL, RD_BYTE(PC++));
break;
case 0x37: /* stc */
cpu_cycles = 4;
SET(C_FLAG);
break;
case 0x39: /* dad sp */
cpu_cycles = 10;
DAD(SP);
break;
case 0x3A: /* lda addr */
cpu_cycles = 13;
A = RD_BYTE(RD_WORD(PC));
PC += 2;
break;
case 0x3B: /* dcx sp */
cpu_cycles = 5;
SP--;
break;
case 0x3C: /* inr a */
cpu_cycles = 5;
INR(A);
break;
case 0x3D: /* dcr a */
cpu_cycles = 5;
DCR(A);
break;
case 0x3E: /* mvi a, data8 */
cpu_cycles = 7;
A = RD_BYTE(PC++);
break;
case 0x3F: /* cmc */
cpu_cycles = 4;
CPL(C_FLAG);
break;
case 0x40: /* mov b, b */
cpu_cycles = 4;
break;
case 0x41: /* mov b, c */
cpu_cycles = 5;
B = C;
break;
case 0x42: /* mov b, d */
cpu_cycles = 5;
B = D;
break;
case 0x43: /* mov b, e */
cpu_cycles = 5;
B = E;
break;
case 0x44: /* mov b, h */
cpu_cycles = 5;
B = H;
break;
case 0x45: /* mov b, l */
cpu_cycles = 5;
B = L;
break;
case 0x46: /* mov b, m */
cpu_cycles = 7;
B = RD_BYTE(HL);
break;
case 0x47: /* mov b, a */
cpu_cycles = 5;
B = A;
break;
case 0x48: /* mov c, b */
cpu_cycles = 5;
C = B;
break;
case 0x49: /* mov c, c */
cpu_cycles = 5;
break;
case 0x4A: /* mov c, d */
cpu_cycles = 5;
C = D;
break;
case 0x4B: /* mov c, e */
cpu_cycles = 5;
C = E;
break;
case 0x4C: /* mov c, h */
cpu_cycles = 5;
C = H;
break;
case 0x4D: /* mov c, l */
cpu_cycles = 5;
C = L;
break;
case 0x4E: /* mov c, m */
cpu_cycles = 7;
C = RD_BYTE(HL);
break;
case 0x4F: /* mov c, a */
cpu_cycles = 5;
C = A;
break;
case 0x50: /* mov d, b */
cpu_cycles = 5;
D = B;
break;
case 0x51: /* mov d, c */
cpu_cycles = 5;
D = C;
break;
case 0x52: /* mov d, d */
cpu_cycles = 5;
break;
case 0x53: /* mov d, e */
cpu_cycles = 5;
D = E;
break;
case 0x54: /* mov d, h */
cpu_cycles = 5;
D = H;
break;
case 0x55: /* mov d, l */
cpu_cycles = 5;
D = L;
break;
case 0x56: /* mov d, m */
cpu_cycles = 7;
D = RD_BYTE(HL);
break;
case 0x57: /* mov d, a */
cpu_cycles = 5;
D = A;
break;
case 0x58: /* mov e, b */
cpu_cycles = 5;
E = B;
break;
case 0x59: /* mov e, c */
cpu_cycles = 5;
E = C;
break;
case 0x5A: /* mov e, d */
cpu_cycles = 5;
E = D;
break;
case 0x5B: /* mov e, e */
cpu_cycles = 5;
break;
case 0x5C: /* mov c, h */
cpu_cycles = 5;
E = H;
break;
case 0x5D: /* mov c, l */
cpu_cycles = 5;
E = L;
break;
case 0x5E: /* mov c, m */
cpu_cycles = 7;
E = RD_BYTE(HL);
break;
case 0x5F: /* mov c, a */
cpu_cycles = 5;
E = A;
break;
case 0x60: /* mov h, b */
cpu_cycles = 5;
H = B;
break;
case 0x61: /* mov h, c */
cpu_cycles = 5;
H = C;
break;
case 0x62: /* mov h, d */
cpu_cycles = 5;
H = D;
break;
case 0x63: /* mov h, e */
cpu_cycles = 5;
H = E;
break;
case 0x64: /* mov h, h */
cpu_cycles = 5;
break;
case 0x65: /* mov h, l */
cpu_cycles = 5;
H = L;
break;
case 0x66: /* mov h, m */
cpu_cycles = 7;
H = RD_BYTE(HL);
break;
case 0x67: /* mov h, a */
cpu_cycles = 5;
H = A;
break;
case 0x68: /* mov l, b */
cpu_cycles = 5;
L = B;
break;
case 0x69: /* mov l, c */
cpu_cycles = 5;
L = C;
break;
case 0x6A: /* mov l, d */
cpu_cycles = 5;
L = D;
break;
case 0x6B: /* mov l, e */
cpu_cycles = 5;
L = E;
break;
case 0x6C: /* mov l, h */
cpu_cycles = 5;
L = H;
break;
case 0x6D: /* mov l, l */
cpu_cycles = 5;
break;
case 0x6E: /* mov l, m */
cpu_cycles = 7;
L = RD_BYTE(HL);
break;
case 0x6F: /* mov l, a */
cpu_cycles = 5;
L = A;
break;
case 0x70: /* mov m, b */
cpu_cycles = 7;
WR_BYTE(HL, B);
break;
case 0x71: /* mov m, c */
cpu_cycles = 7;
WR_BYTE(HL, C);
break;
case 0x72: /* mov m, d */
cpu_cycles = 7;
WR_BYTE(HL, D);
break;
case 0x73: /* mov m, e */
cpu_cycles = 7;
WR_BYTE(HL, E);
break;
case 0x74: /* mov m, h */
cpu_cycles = 7;
WR_BYTE(HL, H);
break;
case 0x75: /* mov m, l */
cpu_cycles = 7;
WR_BYTE(HL, L);
break;
case 0x76: /* hlt */
cpu_cycles = 4;
PC--;
break;
case 0x77: /* mov m, a */
cpu_cycles = 7;
WR_BYTE(HL, A);
break;
case 0x78: /* mov a, b */
cpu_cycles = 5;
A = B;
break;
case 0x79: /* mov a, c */
cpu_cycles = 5;
A = C;
break;
case 0x7A: /* mov a, d */
cpu_cycles = 5;
A = D;
break;
case 0x7B: /* mov a, e */
cpu_cycles = 5;
A = E;
break;
case 0x7C: /* mov a, h */
cpu_cycles = 5;
A = H;
break;
case 0x7D: /* mov a, l */
cpu_cycles = 5;
A = L;
break;
case 0x7E: /* mov a, m */
cpu_cycles = 7;
A = RD_BYTE(HL);
break;
case 0x7F: /* mov a, a */
cpu_cycles = 5;
break;
case 0x80: /* add b */
cpu_cycles = 4;
ADD(B);
break;
case 0x81: /* add c */
cpu_cycles = 4;
ADD(C);
break;
case 0x82: /* add d */
cpu_cycles = 4;
ADD(D);
break;
case 0x83: /* add e */
cpu_cycles = 4;
ADD(E);
break;
case 0x84: /* add h */
cpu_cycles = 4;
ADD(H);
break;
case 0x85: /* add l */
cpu_cycles = 4;
ADD(L);
break;
case 0x86: /* add m */
cpu_cycles = 7;
work8 = RD_BYTE(HL);
ADD(work8);
break;
case 0x87: /* add a */
cpu_cycles = 4;