fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
1/*****************************************************************************
2 * pce *
3 *****************************************************************************/
4
5/*****************************************************************************
6 * File name: src/cpu/e8080/opcodes.c *
7 * Created: 2012-11-28 by Hampa Hug <hampa@hampa.ch> *
8 * Copyright: (C) 2012-2024 Hampa Hug <hampa@hampa.ch> *
9 *****************************************************************************/
10
11/*****************************************************************************
12 * This program is free software. You can redistribute it and / or modify it *
13 * under the terms of the GNU General Public License version 2 as published *
14 * by the Free Software Foundation. *
15 * *
16 * This program is distributed in the hope that it will be useful, but *
17 * WITHOUT ANY WARRANTY, without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
19 * Public License for more details. *
20 *****************************************************************************/
21
22
23#include "e8080.h"
24#include "internal.h"
25
26#include <stdlib.h>
27#include <stdio.h>
28
29
30static void op_ud (e8080_t *c)
31{
32 if (e8080_hook_undefined (c)) {
33 return;
34 }
35
36 e8080_set_clk (c, 1, 4);
37}
38
39/* OP 00: NOP */
40static void op_00 (e8080_t *c)
41{
42 e8080_set_clk (c, 1, 4);
43}
44
45/* OP 01: LXI BC */
46static void op_01 (e8080_t *c)
47{
48 e8080_get_inst12 (c);
49 e8080_set_b (c, c->inst[2]);
50 e8080_set_c (c, c->inst[1]);
51 e8080_set_clk (c, 3, 10);
52}
53
54/* OP 02: STAX BC */
55static void op_02 (e8080_t *c)
56{
57 e8080_set_mem8 (c, e8080_get_bc (c), e8080_get_a (c));
58 e8080_set_clk (c, 1, 7);
59}
60
61/* OP 03: INX BC */
62static void op_03 (e8080_t *c)
63{
64 e8080_set_bc (c, e8080_get_bc (c) + 1);
65 e8080_set_clk (c, 1, 5);
66}
67
68/* OP 04: INR B */
69static void op_04 (e8080_t *c)
70{
71 e8080_set_psw_inc (c, e8080_get_b (c));
72 e8080_set_b (c, e8080_get_b (c) + 1);
73 e8080_set_clk (c, 1, 5);
74}
75
76/* OP 05: DCR B */
77static void op_05 (e8080_t *c)
78{
79 e8080_set_psw_dec (c, e8080_get_b (c));
80 e8080_set_b (c, e8080_get_b (c) - 1);
81 e8080_set_clk (c, 1, 5);
82}
83
84/* OP 06: MVI B, IM8 */
85static void op_06 (e8080_t *c)
86{
87 e8080_get_inst1 (c);
88 e8080_set_b (c, c->inst[1]);
89 e8080_set_clk (c, 2, 7);
90}
91
92/* OP 07: RLC */
93static void op_07 (e8080_t *c)
94{
95 unsigned char val;
96
97 val = e8080_get_a (c);
98 e8080_set_cf (c, val & 0x80);
99 e8080_set_a (c, (val << 1) | (val >> 7));
100 e8080_set_clk (c, 1, 4);
101}
102
103/* OP 09: DAD BC */
104static void op_09 (e8080_t *c)
105{
106 unsigned short s1, s2, d;
107
108 s1 = e8080_get_hl (c);
109 s2 = e8080_get_bc (c);
110 d = (s1 + s2) & 0xffff;
111 e8080_set_hl (c, d);
112 e8080_set_cf (c, d < s1);
113 e8080_set_clk (c, 1, 10);
114}
115
116/* OP 0A: LDAX BC */
117static void op_0a (e8080_t *c)
118{
119 e8080_set_a (c, e8080_get_mem8 (c, e8080_get_bc (c)));
120 e8080_set_clk (c, 1, 7);
121}
122
123/* OP 0B: DCX BC */
124static void op_0b (e8080_t *c)
125{
126 e8080_set_bc (c, e8080_get_bc (c) - 1);
127 e8080_set_clk (c, 1, 5);
128}
129
130/* OP 0C: INR C */
131static void op_0c (e8080_t *c)
132{
133 e8080_set_psw_inc (c, e8080_get_c (c));
134 e8080_set_c (c, e8080_get_c (c) + 1);
135 e8080_set_clk (c, 1, 5);
136}
137
138/* OP 0D: DCR C */
139static void op_0d (e8080_t *c)
140{
141 e8080_set_psw_dec (c, e8080_get_c (c));
142 e8080_set_c (c, e8080_get_c (c) - 1);
143 e8080_set_clk (c, 1, 5);
144}
145
146/* OP 0E: MVI C, IM8 */
147static void op_0e (e8080_t *c)
148{
149 e8080_get_inst1 (c);
150 e8080_set_c (c, c->inst[1]);
151 e8080_set_clk (c, 2, 7);
152}
153
154/* OP 0F: RRC */
155static void op_0f (e8080_t *c)
156{
157 unsigned char val;
158
159 val = e8080_get_a (c);
160 e8080_set_cf (c, val & 0x01);
161 e8080_set_a (c, (val >> 1) | (val << 7));
162 e8080_set_clk (c, 1, 4);
163}
164
165/* OP 11: LXI DE */
166static void op_11 (e8080_t *c)
167{
168 e8080_get_inst12 (c);
169 e8080_set_d (c, c->inst[2]);
170 e8080_set_e (c, c->inst[1]);
171 e8080_set_clk (c, 3, 10);
172}
173
174/* OP 12: STAX DE */
175static void op_12 (e8080_t *c)
176{
177 e8080_set_mem8 (c, e8080_get_de (c), e8080_get_a (c));
178 e8080_set_clk (c, 1, 7);
179}
180
181/* OP 13: INX DE */
182static void op_13 (e8080_t *c)
183{
184 e8080_set_de (c, e8080_get_de (c) + 1);
185 e8080_set_clk (c, 1, 5);
186}
187
188/* OP 14: INR D */
189static void op_14 (e8080_t *c)
190{
191 e8080_set_psw_inc (c, e8080_get_d (c));
192 e8080_set_d (c, e8080_get_d (c) + 1);
193 e8080_set_clk (c, 1, 5);
194}
195
196/* OP 15: DCR D */
197static void op_15 (e8080_t *c)
198{
199 e8080_set_psw_dec (c, e8080_get_d (c));
200 e8080_set_d (c, e8080_get_d (c) - 1);
201 e8080_set_clk (c, 1, 5);
202}
203
204/* OP 16: MVI D, IM8 */
205static void op_16 (e8080_t *c)
206{
207 e8080_get_inst1 (c);
208 e8080_set_d (c, c->inst[1]);
209 e8080_set_clk (c, 2, 7);
210}
211
212/* OP 17: RAL */
213static void op_17 (e8080_t *c)
214{
215 unsigned char val;
216
217 val = e8080_get_a (c);
218 e8080_set_a (c, (val << 1) | e8080_get_cf (c));
219 e8080_set_cf (c, val & 0x80);
220 e8080_set_clk (c, 1, 4);
221}
222
223/* OP 19: DAD DE */
224static void op_19 (e8080_t *c)
225{
226 unsigned short s1, s2, d;
227
228 s1 = e8080_get_hl (c);
229 s2 = e8080_get_de (c);
230 d = (s1 + s2) & 0xffff;
231 e8080_set_hl (c, d);
232 e8080_set_cf (c, d < s1);
233 e8080_set_clk (c, 1, 10);
234}
235
236/* OP 1A: LDAX DE */
237static void op_1a (e8080_t *c)
238{
239 e8080_set_a (c, e8080_get_mem8 (c, e8080_get_de (c)));
240 e8080_set_clk (c, 1, 7);
241}
242
243/* OP 1B: DCX DE */
244static void op_1b (e8080_t *c)
245{
246 e8080_set_de (c, e8080_get_de (c) - 1);
247 e8080_set_clk (c, 1, 5);
248}
249
250/* OP 1C: INR E */
251static void op_1c (e8080_t *c)
252{
253 e8080_set_psw_inc (c, e8080_get_e (c));
254 e8080_set_e (c, e8080_get_e (c) + 1);
255 e8080_set_clk (c, 1, 5);
256}
257
258/* OP 1D: DCR E */
259static void op_1d (e8080_t *c)
260{
261 e8080_set_psw_dec (c, e8080_get_e (c));
262 e8080_set_e (c, e8080_get_e (c) - 1);
263 e8080_set_clk (c, 1, 5);
264}
265
266/* OP 1E: MVI E, IM8 */
267static void op_1e (e8080_t *c)
268{
269 e8080_get_inst1 (c);
270 e8080_set_e (c, c->inst[1]);
271 e8080_set_clk (c, 2, 7);
272}
273
274/* OP 1F: RAR */
275static void op_1f (e8080_t *c)
276{
277 unsigned char val;
278
279 val = e8080_get_a (c);
280 e8080_set_a (c, (val >> 1) | (e8080_get_cf (c) << 7));
281 e8080_set_cf (c, val & 0x01);
282 e8080_set_clk (c, 1, 4);
283}
284
285/* OP 21: LXI HL */
286static void op_21 (e8080_t *c)
287{
288 e8080_get_inst12 (c);
289 e8080_set_h (c, c->inst[2]);
290 e8080_set_l (c, c->inst[1]);
291 e8080_set_clk (c, 3, 10);
292}
293
294/* OP 22: SHLD IM16 */
295static void op_22 (e8080_t *c)
296{
297 unsigned adr;
298
299 e8080_get_inst12 (c);
300 adr = e8080_uint16 (c->inst[1], c->inst[2]);
301 e8080_set_mem8 (c, adr + 0, e8080_get_l (c));
302 e8080_set_mem8 (c, adr + 1, e8080_get_h (c));
303 e8080_set_clk (c, 3, 16);
304}
305
306/* OP 23: INX HL */
307static void op_23 (e8080_t *c)
308{
309 e8080_set_hl (c, e8080_get_hl (c) + 1);
310 e8080_set_clk (c, 1, 5);
311}
312
313/* OP 24: INR H */
314static void op_24 (e8080_t *c)
315{
316 e8080_set_psw_inc (c, e8080_get_h (c));
317 e8080_set_h (c, e8080_get_h (c) + 1);
318 e8080_set_clk (c, 1, 5);
319}
320
321/* OP 25: DCR H */
322static void op_25 (e8080_t *c)
323{
324 e8080_set_psw_dec (c, e8080_get_h (c));
325 e8080_set_h (c, e8080_get_h (c) - 1);
326 e8080_set_clk (c, 1, 5);
327}
328
329/* OP 26: MVI H, IM8 */
330static void op_26 (e8080_t *c)
331{
332 e8080_get_inst1 (c);
333 e8080_set_h (c, c->inst[1]);
334 e8080_set_clk (c, 2, 7);
335}
336
337/* OP 27: DAA */
338static void op_27 (e8080_t *c)
339{
340 unsigned s, d;
341
342 s = e8080_get_a (c);
343 d = s;
344
345 if (((s & 0x0f) >= 0x0a) || e8080_get_af (c)) {
346 d += 0x06;
347 }
348
349 if ((d >= 0xa0) || e8080_get_cf (c)) {
350 d += 0x60;
351 }
352
353 e8080_set_psw_szp (c, d, 0, 0);
354 e8080_set_a (c, d);
355 e8080_set_af (c, (s ^ d) & 0x10);
356
357 if (d > 255) {
358 e8080_set_cf (c, 1);
359 }
360
361 e8080_set_clk (c, 1, 4);
362}
363
364/* OP 29: DAD HL */
365static void op_29 (e8080_t *c)
366{
367 unsigned short s, d;
368
369 s = e8080_get_hl (c);
370 d = (s + s) & 0xffff;
371 e8080_set_hl (c, d);
372 e8080_set_cf (c, d < s);
373 e8080_set_clk (c, 1, 10);
374}
375
376/* OP 2A: LHLD IM16 */
377static void op_2a (e8080_t *c)
378{
379 unsigned adr;
380
381 e8080_get_inst12 (c);
382 adr = e8080_uint16 (c->inst[1], c->inst[2]);
383 e8080_set_l (c, e8080_get_mem8 (c, adr + 0));
384 e8080_set_h (c, e8080_get_mem8 (c, adr + 1));
385 e8080_set_clk (c, 3, 16);
386}
387
388/* OP 2B: DCX HL */
389static void op_2b (e8080_t *c)
390{
391 e8080_set_hl (c, e8080_get_hl (c) - 1);
392 e8080_set_clk (c, 1, 5);
393}
394
395/* OP 2C: INR L */
396static void op_2c (e8080_t *c)
397{
398 e8080_set_psw_inc (c, e8080_get_l (c));
399 e8080_set_l (c, e8080_get_l (c) + 1);
400 e8080_set_clk (c, 1, 5);
401}
402
403/* OP 2D: DCR L */
404static void op_2d (e8080_t *c)
405{
406 e8080_set_psw_dec (c, e8080_get_l (c));
407 e8080_set_l (c, e8080_get_l (c) - 1);
408 e8080_set_clk (c, 1, 5);
409}
410
411/* OP 2E: MVI L, IM8 */
412static void op_2e (e8080_t *c)
413{
414 e8080_get_inst1 (c);
415 e8080_set_l (c, c->inst[1]);
416 e8080_set_clk (c, 2, 7);
417}
418
419/* OP 2F: CMA */
420static void op_2f (e8080_t *c)
421{
422 e8080_set_a (c, ~e8080_get_a (c));
423 e8080_set_clk (c, 1, 4);
424}
425
426/* OP 31: LXI SP */
427static void op_31 (e8080_t *c)
428{
429 e8080_get_inst12 (c);
430 e8080_set_sp (c, e8080_uint16 (c->inst[1], c->inst[2]));
431 e8080_set_clk (c, 3, 10);
432}
433
434/* OP 32: STA IM16 */
435static void op_32 (e8080_t *c)
436{
437 e8080_get_inst12 (c);
438 e8080_set_mem8 (c, e8080_uint16 (c->inst[1], c->inst[2]), e8080_get_a (c));
439 e8080_set_clk (c, 3, 13);
440}
441
442/* OP 33: INX SP */
443static void op_33 (e8080_t *c)
444{
445 e8080_set_sp (c, e8080_get_sp (c) + 1);
446 e8080_set_clk (c, 1, 5);
447}
448
449/* OP 34: INR M */
450static void op_34 (e8080_t *c)
451{
452 unsigned char val;
453 unsigned short adr;
454
455 adr = e8080_get_hl (c);
456 val = e8080_get_mem8 (c, adr);
457 e8080_set_psw_inc (c, val);
458 e8080_set_mem8 (c, adr, val + 1);
459 e8080_set_clk (c, 1, 10);
460}
461
462/* OP 35: DCR M */
463static void op_35 (e8080_t *c)
464{
465 unsigned char val;
466 unsigned short adr;
467
468 adr = e8080_get_hl (c);
469 val = e8080_get_mem8 (c, adr);
470 e8080_set_psw_dec (c, val);
471 e8080_set_mem8 (c, adr, val - 1);
472 e8080_set_clk (c, 1, 10);
473}
474
475/* OP 36: MVI M, IM8 */
476static void op_36 (e8080_t *c)
477{
478 e8080_get_inst1 (c);
479 e8080_set_mem8 (c, e8080_get_hl (c), c->inst[1]);
480 e8080_set_clk (c, 2, 10);
481}
482
483/* OP 37: STC */
484static void op_37 (e8080_t *c)
485{
486 e8080_set_cf (c, 1);
487 e8080_set_clk (c, 1, 4);
488}
489
490/* OP 39: DAD SP */
491static void op_39 (e8080_t *c)
492{
493 unsigned short s1, s2, d;
494
495 s1 = e8080_get_hl (c);
496 s2 = e8080_get_sp (c);
497 d = (s1 + s2) & 0xffff;
498 e8080_set_hl (c, d);
499 e8080_set_cf (c, d < s1);
500 e8080_set_clk (c, 1, 10);
501}
502
503/* OP 3A: LDA IM16 */
504static void op_3a (e8080_t *c)
505{
506 e8080_get_inst12 (c);
507 e8080_set_a (c, e8080_get_mem8 (c, e8080_uint16 (c->inst[1], c->inst[2])));
508 e8080_set_clk (c, 3, 13);
509}
510
511/* OP 3B: DCX SP */
512static void op_3b (e8080_t *c)
513{
514 e8080_set_sp (c, e8080_get_sp (c) - 1);
515 e8080_set_clk (c, 1, 5);
516}
517
518/* OP 3C: INR A */
519static void op_3c (e8080_t *c)
520{
521 e8080_set_psw_inc (c, e8080_get_a (c));
522 e8080_set_a (c, e8080_get_a (c) + 1);
523 e8080_set_clk (c, 1, 5);
524}
525
526/* OP 3D: DCR A */
527static void op_3d (e8080_t *c)
528{
529 e8080_set_psw_dec (c, e8080_get_a (c));
530 e8080_set_a (c, e8080_get_a (c) - 1);
531 e8080_set_clk (c, 1, 5);
532}
533
534/* OP 3E: MVI A, IM8 */
535static void op_3e (e8080_t *c)
536{
537 e8080_get_inst1 (c);
538 e8080_set_a (c, c->inst[1]);
539 e8080_set_clk (c, 2, 7);
540}
541
542/* OP 3F: CMC */
543static void op_3f (e8080_t *c)
544{
545 e8080_set_cf (c, e8080_get_cf (c) == 0);
546 e8080_set_clk (c, 1, 4);
547}
548
549/* OP 40: MOV R, R */
550static void op_40 (e8080_t *c)
551{
552 e8080_set_reg8 (c, c->inst[0] >> 3, e8080_get_reg8 (c, c->inst[0]));
553 e8080_set_clk (c, 1, 5);
554}
555
556/* OP 46: MOV R, M */
557static void op_46 (e8080_t *c)
558{
559 e8080_set_reg8 (c, c->inst[0] >> 3, e8080_get_mem8 (c, e8080_get_hl (c)));
560 e8080_set_clk (c, 1, 7);
561}
562
563/* OP 70: MOV M, R */
564static void op_70 (e8080_t *c)
565{
566 e8080_set_mem8 (c, e8080_get_hl (c), e8080_get_reg8 (c, c->inst[0]));
567 e8080_set_clk (c, 1, 7);
568}
569
570/* OP 76: HLT */
571static void op_76 (e8080_t *c)
572{
573 c->halt = 1;
574 e8080_set_clk (c, 0, 7);
575}
576
577/* OP 80: ADD R */
578static void op_80 (e8080_t *c)
579{
580 unsigned char s1, s2;
581
582 s1 = e8080_get_a (c);
583 s2 = e8080_get_reg8 (c, c->inst[0]);
584 e8080_set_a (c, s1 + s2);
585 e8080_set_psw_add (c, s1, s2);
586 e8080_set_clk (c, 1, 4);
587}
588
589/* OP 86: ADD M */
590static void op_86 (e8080_t *c)
591{
592 unsigned char s1, s2;
593
594 s1 = e8080_get_a (c);
595 s2 = e8080_get_mem8 (c, e8080_get_hl (c));
596 e8080_set_a (c, s1 + s2);
597 e8080_set_psw_add (c, s1, s2);
598 e8080_set_clk (c, 1, 7);
599}
600
601/* OP 88: ADC R */
602static void op_88 (e8080_t *c)
603{
604 unsigned char s1, s2, s3;
605
606 s1 = e8080_get_a (c);
607 s2 = e8080_get_reg8 (c, c->inst[0]);
608 s3 = e8080_get_cf (c);
609 e8080_set_a (c, s1 + s2 + s3);
610 e8080_set_psw_adc (c, s1, s2, s3);
611 e8080_set_clk (c, 1, 4);
612}
613
614/* OP 8E: ADC M */
615static void op_8e (e8080_t *c)
616{
617 unsigned char s1, s2, s3;
618
619 s1 = e8080_get_a (c);
620 s2 = e8080_get_mem8 (c, e8080_get_hl (c));
621 s3 = e8080_get_cf (c);
622 e8080_set_a (c, s1 + s2 + s3);
623 e8080_set_psw_adc (c, s1, s2, s3);
624 e8080_set_clk (c, 1, 7);
625}
626
627/* OP 90: SUB R */
628static void op_90 (e8080_t *c)
629{
630 unsigned char s1, s2;
631
632 s1 = e8080_get_a (c);
633 s2 = e8080_get_reg8 (c, c->inst[0]);
634 e8080_set_a (c, s1 - s2);
635 e8080_set_psw_sub (c, s1, s2);
636 e8080_set_clk (c, 1, 4);
637}
638
639/* OP 96: SUB M */
640static void op_96 (e8080_t *c)
641{
642 unsigned char s1, s2;
643
644 s1 = e8080_get_a (c);
645 s2 = e8080_get_mem8 (c, e8080_get_hl (c));
646 e8080_set_a (c, s1 - s2);
647 e8080_set_psw_sub (c, s1, s2);
648 e8080_set_clk (c, 1, 7);
649}
650
651/* OP 98: SBB R */
652static void op_98 (e8080_t *c)
653{
654 unsigned char s1, s2, s3;
655
656 s1 = e8080_get_a (c);
657 s2 = e8080_get_reg8 (c, c->inst[0]);
658 s3 = e8080_get_cf (c);
659 e8080_set_a (c, s1 - s2 - s3);
660 e8080_set_psw_sbb (c, s1, s2, s3);
661 e8080_set_clk (c, 1, 4);
662}
663
664/* OP 9E: SBB M */
665static void op_9e (e8080_t *c)
666{
667 unsigned char s1, s2, s3;
668
669 s1 = e8080_get_a (c);
670 s2 = e8080_get_mem8 (c, e8080_get_hl (c));
671 s3 = e8080_get_cf (c);
672 e8080_set_a (c, s1 - s2 - s3);
673 e8080_set_psw_sbb (c, s1, s2, s3);
674 e8080_set_clk (c, 1, 7);
675}
676
677/* OP A0: ANA R */
678static void op_a0 (e8080_t *c)
679{
680 unsigned char s1, s2;
681
682 s1 = e8080_get_a (c);
683 s2 = e8080_get_reg8 (c, c->inst[0]);
684 e8080_set_a (c, s1 & s2);
685 e8080_set_psw_log (c, s1 & s2);
686 e8080_set_af (c, 1);
687 e8080_set_clk (c, 1, 4);
688}
689
690/* OP A6: ANA M */
691static void op_a6 (e8080_t *c)
692{
693 unsigned char s1, s2;
694
695 s1 = e8080_get_a (c);
696 s2 = e8080_get_mem8 (c, e8080_get_hl (c));
697 e8080_set_a (c, s1 & s2);
698 e8080_set_psw_log (c, s1 & s2);
699 e8080_set_af (c, 1);
700 e8080_set_clk (c, 1, 7);
701}
702
703/* OP A8: XRA R */
704static void op_a8 (e8080_t *c)
705{
706 unsigned char s1, s2;
707
708 s1 = e8080_get_a (c);
709 s2 = e8080_get_reg8 (c, c->inst[0]);
710 e8080_set_a (c, s1 ^ s2);
711 e8080_set_psw_log (c, s1 ^ s2);
712 e8080_set_clk (c, 1, 4);
713}
714
715/* OP AE: XRA M */
716static void op_ae (e8080_t *c)
717{
718 unsigned char s1, s2;
719
720 s1 = e8080_get_a (c);
721 s2 = e8080_get_mem8 (c, e8080_get_hl (c));
722 e8080_set_a (c, s1 ^ s2);
723 e8080_set_psw_log (c, s1 ^ s2);
724 e8080_set_clk (c, 1, 7);
725}
726
727/* OP B0: ORA R */
728static void op_b0 (e8080_t *c)
729{
730 unsigned char s1, s2;
731
732 s1 = e8080_get_a (c);
733 s2 = e8080_get_reg8 (c, c->inst[0]);
734 e8080_set_a (c, s1 | s2);
735 e8080_set_psw_log (c, s1 | s2);
736 e8080_set_clk (c, 1, 4);
737}
738
739/* OP B6: ORA M */
740static void op_b6 (e8080_t *c)
741{
742 unsigned char s1, s2;
743
744 s1 = e8080_get_a (c);
745 s2 = e8080_get_mem8 (c, e8080_get_hl (c));
746 e8080_set_a (c, s1 | s2);
747 e8080_set_psw_log (c, s1 | s2);
748 e8080_set_clk (c, 1, 7);
749}
750
751/* OP B8: CMP R */
752static void op_b8 (e8080_t *c)
753{
754 unsigned char s1, s2;
755
756 s1 = e8080_get_a (c);
757 s2 = e8080_get_reg8 (c, c->inst[0]);
758 e8080_set_psw_sub (c, s1, s2);
759 e8080_set_clk (c, 1, 4);
760}
761
762/* OP BE: CMP M */
763static void op_be (e8080_t *c)
764{
765 unsigned char s1, s2;
766
767 s1 = e8080_get_a (c);
768 s2 = e8080_get_mem8 (c, e8080_get_hl (c));
769 e8080_set_psw_sub (c, s1, s2);
770 e8080_set_clk (c, 1, 7);
771}
772
773/* OP C0: RNZ */
774static void op_c0 (e8080_t *c)
775{
776 if (e8080_get_zf (c) == 0) {
777 e8080_set_pc (c, e8080_get_mem16 (c, e8080_get_sp (c)));
778 e8080_set_sp (c, e8080_get_sp (c) + 2);
779 e8080_set_clk (c, 0, 11);
780 }
781 else {
782 e8080_set_clk (c, 1, 5);
783 }
784}
785
786/* OP C1: POP BC */
787static void op_c1 (e8080_t *c)
788{
789 e8080_set_c (c, e8080_get_mem8 (c, e8080_get_sp (c) + 0));
790 e8080_set_b (c, e8080_get_mem8 (c, e8080_get_sp (c) + 1));
791 e8080_set_sp (c, e8080_get_sp (c) + 2);
792 e8080_set_clk (c, 1, 10);
793}
794
795/* OP C2: JNZ IM16 */
796static void op_c2 (e8080_t *c)
797{
798 e8080_get_inst12 (c);
799
800 if (e8080_get_zf (c) == 0) {
801 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
802 e8080_set_clk (c, 0, 10);
803 }
804 else {
805 e8080_set_clk (c, 3, 10);
806 }
807}
808
809/* OP C3: JMP IM16 */
810static void op_c3 (e8080_t *c)
811{
812 e8080_get_inst12 (c);
813 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
814 e8080_set_clk (c, 0, 10);
815}
816
817/* OP C4: CNZ IM16 */
818static void op_c4 (e8080_t *c)
819{
820 e8080_get_inst12 (c);
821
822 if (e8080_get_zf (c) == 0) {
823 e8080_set_sp (c, e8080_get_sp (c) - 2);
824 e8080_set_mem16 (c, e8080_get_sp (c), e8080_get_pc (c) + 3);
825 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
826 e8080_set_clk (c, 0, 17);
827 }
828 else {
829 e8080_set_clk (c, 3, 11);
830 }
831}
832
833/* OP C5: PUSH BC */
834static void op_c5 (e8080_t *c)
835{
836 e8080_set_sp (c, e8080_get_sp (c) - 2);
837 e8080_set_mem8 (c, e8080_get_sp (c) + 1, e8080_get_b (c));
838 e8080_set_mem8 (c, e8080_get_sp (c) + 0, e8080_get_c (c));
839 e8080_set_clk (c, 1, 11);
840}
841
842/* OP C6: ADI IM8 */
843static void op_c6 (e8080_t *c)
844{
845 unsigned char s1, s2;
846
847 e8080_get_inst1 (c);
848 s1 = e8080_get_a (c);
849 s2 = c->inst[1];
850 e8080_set_a (c, s1 + s2);
851 e8080_set_psw_add (c, s1, s2);
852 e8080_set_clk (c, 2, 7);
853}
854
855/* OP C7: RST IM3 */
856static void op_c7 (e8080_t *c)
857{
858 e8080_set_clk (c, 1, 11);
859
860 if (e8080_hook_rst (c)) {
861 return;
862 }
863
864 e8080_set_sp (c, e8080_get_sp (c) - 2);
865 e8080_set_mem16 (c, e8080_get_sp (c), e8080_get_pc (c));
866 e8080_set_pc (c, c->inst[0] & 0x38);
867}
868
869/* OP C8: RZ */
870static void op_c8 (e8080_t *c)
871{
872 if (e8080_get_zf (c)) {
873 e8080_set_pc (c, e8080_get_mem16 (c, e8080_get_sp (c)));
874 e8080_set_sp (c, e8080_get_sp (c) + 2);
875 e8080_set_clk (c, 0, 11);
876 }
877 else {
878 e8080_set_clk (c, 1, 5);
879 }
880}
881
882/* OP C9: RET */
883static void op_c9 (e8080_t *c)
884{
885 e8080_set_pc (c, e8080_get_mem16 (c, e8080_get_sp (c)));
886 e8080_set_sp (c, e8080_get_sp (c) + 2);
887 e8080_set_clk (c, 0, 10);
888}
889
890/* OP CA: JZ IM16 */
891static void op_ca (e8080_t *c)
892{
893 e8080_get_inst12 (c);
894
895 if (e8080_get_zf (c)) {
896 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
897 e8080_set_clk (c, 0, 10);
898 }
899 else {
900 e8080_set_clk (c, 3, 10);
901 }
902}
903
904/* OP CC: CZ IM16 */
905static void op_cc (e8080_t *c)
906{
907 e8080_get_inst12 (c);
908
909 if (e8080_get_zf (c)) {
910 e8080_set_sp (c, e8080_get_sp (c) - 2);
911 e8080_set_mem16 (c, e8080_get_sp (c), e8080_get_pc (c) + 3);
912 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
913 e8080_set_clk (c, 0, 17);
914 }
915 else {
916 e8080_set_clk (c, 3, 11);
917 }
918}
919
920/* OP CD: CALL IM16 */
921static void op_cd (e8080_t *c)
922{
923 e8080_get_inst12 (c);
924 e8080_set_sp (c, e8080_get_sp (c) - 2);
925 e8080_set_mem16 (c, e8080_get_sp (c), e8080_get_pc (c) + 3);
926 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
927 e8080_set_clk (c, 0, 17);
928}
929
930/* OP CE: ACI IM8 */
931static void op_ce (e8080_t *c)
932{
933 unsigned char s1, s2, s3;
934
935 e8080_get_inst1 (c);
936 s1 = e8080_get_a (c);
937 s2 = c->inst[1];
938 s3 = e8080_get_cf (c);
939 e8080_set_a (c, s1 + s2 + s3);
940 e8080_set_psw_adc (c, s1, s2, s3);
941 e8080_set_clk (c, 2, 7);
942}
943
944/* OP D0: RNC */
945static void op_d0 (e8080_t *c)
946{
947 if (e8080_get_cf (c) == 0) {
948 e8080_set_pc (c, e8080_get_mem16 (c, e8080_get_sp (c)));
949 e8080_set_sp (c, e8080_get_sp (c) + 2);
950 e8080_set_clk (c, 0, 11);
951 }
952 else {
953 e8080_set_clk (c, 1, 5);
954 }
955}
956
957/* OP D1: POP DE */
958static void op_d1 (e8080_t *c)
959{
960 e8080_set_e (c, e8080_get_mem8 (c, e8080_get_sp (c) + 0));
961 e8080_set_d (c, e8080_get_mem8 (c, e8080_get_sp (c) + 1));
962 e8080_set_sp (c, e8080_get_sp (c) + 2);
963 e8080_set_clk (c, 1, 10);
964}
965
966/* OP D2: JNC IM16 */
967static void op_d2 (e8080_t *c)
968{
969 e8080_get_inst12 (c);
970
971 if (e8080_get_cf (c) == 0) {
972 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
973 e8080_set_clk (c, 0, 10);
974 }
975 else {
976 e8080_set_clk (c, 3, 10);
977 }
978}
979
980/* OP D3: OUT nn */
981static void op_d3 (e8080_t *c)
982{
983 e8080_get_inst1 (c);
984 e8080_set_port8 (c, c->inst[1], e8080_get_a (c));
985 e8080_set_clk (c, 2, 11);
986}
987
988/* OP D4: CNC IM16 */
989static void op_d4 (e8080_t *c)
990{
991 e8080_get_inst12 (c);
992
993 if (e8080_get_cf (c) == 0) {
994 e8080_set_sp (c, e8080_get_sp (c) - 2);
995 e8080_set_mem16 (c, e8080_get_sp (c), e8080_get_pc (c) + 3);
996 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
997 e8080_set_clk (c, 0, 17);
998 }
999 else {
1000 e8080_set_clk (c, 3, 11);
1001 }
1002}
1003
1004/* OP D5: PUSH DE */
1005static void op_d5 (e8080_t *c)
1006{
1007 e8080_set_sp (c, e8080_get_sp (c) - 2);
1008 e8080_set_mem8 (c, e8080_get_sp (c) + 1, e8080_get_d (c));
1009 e8080_set_mem8 (c, e8080_get_sp (c) + 0, e8080_get_e (c));
1010 e8080_set_clk (c, 1, 11);
1011}
1012
1013/* OP D6: SUI IM8 */
1014static void op_d6 (e8080_t *c)
1015{
1016 unsigned char s1, s2;
1017
1018 e8080_get_inst1 (c);
1019 s1 = e8080_get_a (c);
1020 s2 = c->inst[1];
1021 e8080_set_a (c, s1 - s2);
1022 e8080_set_psw_sub (c, s1, s2);
1023 e8080_set_clk (c, 2, 7);
1024}
1025
1026/* OP D8: RC */
1027static void op_d8 (e8080_t *c)
1028{
1029 if (e8080_get_cf (c)) {
1030 e8080_set_pc (c, e8080_get_mem16 (c, e8080_get_sp (c)));
1031 e8080_set_sp (c, e8080_get_sp (c) + 2);
1032 e8080_set_clk (c, 0, 11);
1033 }
1034 else {
1035 e8080_set_clk (c, 1, 5);
1036 }
1037}
1038
1039/* OP DA: JC IM16 */
1040static void op_da (e8080_t *c)
1041{
1042 e8080_get_inst12 (c);
1043
1044 if (e8080_get_cf (c)) {
1045 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
1046 e8080_set_clk (c, 0, 10);
1047 }
1048 else {
1049 e8080_set_clk (c, 3, 10);
1050 }
1051}
1052
1053/* OP DB: IN nn */
1054static void op_db (e8080_t *c)
1055{
1056 unsigned a;
1057
1058 e8080_get_inst1 (c);
1059 a = (e8080_get_a (c) << 8) | c->inst[1];
1060 e8080_set_a (c, e8080_get_port8 (c, a));
1061 e8080_set_clk (c, 2, 10);
1062}
1063
1064/* OP DC: CC IM16 */
1065static void op_dc (e8080_t *c)
1066{
1067 e8080_get_inst12 (c);
1068
1069 if (e8080_get_cf (c)) {
1070 e8080_set_sp (c, e8080_get_sp (c) - 2);
1071 e8080_set_mem16 (c, e8080_get_sp (c), e8080_get_pc (c) + 3);
1072 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
1073 e8080_set_clk (c, 0, 17);
1074 }
1075 else {
1076 e8080_set_clk (c, 3, 11);
1077 }
1078}
1079
1080/* OP DE: SBI IM8 */
1081static void op_de (e8080_t *c)
1082{
1083 unsigned char s1, s2, s3;
1084
1085 e8080_get_inst1 (c);
1086 s1 = e8080_get_a (c);
1087 s2 = c->inst[1];
1088 s3 = e8080_get_cf (c);
1089 e8080_set_a (c, s1 - s2 - s3);
1090 e8080_set_psw_sbb (c, s1, s2, s3);
1091 e8080_set_clk (c, 2, 7);
1092}
1093
1094/* OP E0: RPO */
1095static void op_e0 (e8080_t *c)
1096{
1097 if (e8080_get_pf (c) == 0) {
1098 e8080_set_pc (c, e8080_get_mem16 (c, e8080_get_sp (c)));
1099 e8080_set_sp (c, e8080_get_sp (c) + 2);
1100 e8080_set_clk (c, 0, 11);
1101 }
1102 else {
1103 e8080_set_clk (c, 1, 5);
1104 }
1105}
1106
1107/* OP E1: POP HL */
1108static void op_e1 (e8080_t *c)
1109{
1110 e8080_set_l (c, e8080_get_mem8 (c, e8080_get_sp (c) + 0));
1111 e8080_set_h (c, e8080_get_mem8 (c, e8080_get_sp (c) + 1));
1112 e8080_set_sp (c, e8080_get_sp (c) + 2);
1113 e8080_set_clk (c, 1, 10);
1114}
1115
1116/* OP E2: JPO IM16 */
1117static void op_e2 (e8080_t *c)
1118{
1119 e8080_get_inst12 (c);
1120
1121 if (e8080_get_pf (c) == 0) {
1122 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
1123 e8080_set_clk (c, 0, 10);
1124 }
1125 else {
1126 e8080_set_clk (c, 3, 10);
1127 }
1128}
1129
1130/* OP E3: XTHL */
1131static void op_e3 (e8080_t *c)
1132{
1133 unsigned sp;
1134 unsigned char v;
1135
1136 sp = e8080_get_sp (c);
1137
1138 v = e8080_get_mem8 (c, sp);
1139 e8080_set_mem8 (c, sp, e8080_get_l (c));
1140 e8080_set_l (c, v);
1141
1142 v = e8080_get_mem8 (c, sp + 1);
1143 e8080_set_mem8 (c, sp + 1, e8080_get_h (c));
1144 e8080_set_h (c, v);
1145
1146 e8080_set_clk (c, 1, 18);
1147}
1148
1149/* OP E4: CPO IM16 */
1150static void op_e4 (e8080_t *c)
1151{
1152 e8080_get_inst12 (c);
1153
1154 if (e8080_get_pf (c) == 0) {
1155 e8080_set_sp (c, e8080_get_sp (c) - 2);
1156 e8080_set_mem16 (c, e8080_get_sp (c), e8080_get_pc (c) + 3);
1157 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
1158 e8080_set_clk (c, 0, 17);
1159 }
1160 else {
1161 e8080_set_clk (c, 3, 11);
1162 }
1163}
1164
1165/* OP E5: PUSH HL */
1166static void op_e5 (e8080_t *c)
1167{
1168 e8080_set_sp (c, e8080_get_sp (c) - 2);
1169 e8080_set_mem8 (c, e8080_get_sp (c) + 1, e8080_get_h (c));
1170 e8080_set_mem8 (c, e8080_get_sp (c) + 0, e8080_get_l (c));
1171 e8080_set_clk (c, 1, 11);
1172}
1173
1174/* OP E6: ANI IM8 */
1175static void op_e6 (e8080_t *c)
1176{
1177 unsigned char s1, s2;
1178
1179 e8080_get_inst1 (c);
1180 s1 = e8080_get_a (c);
1181 s2 = c->inst[1];
1182 e8080_set_a (c, s1 & s2);
1183 e8080_set_psw_log (c, s1 & s2);
1184 e8080_set_af (c, 1);
1185 e8080_set_clk (c, 2, 7);
1186}
1187
1188/* OP E8: RPE */
1189static void op_e8 (e8080_t *c)
1190{
1191 if (e8080_get_pf (c)) {
1192 e8080_set_pc (c, e8080_get_mem16 (c, e8080_get_sp (c)));
1193 e8080_set_sp (c, e8080_get_sp (c) + 2);
1194 e8080_set_clk (c, 0, 11);
1195 }
1196 else {
1197 e8080_set_clk (c, 1, 5);
1198 }
1199}
1200
1201/* OP E9: PCHL */
1202static void op_e9 (e8080_t *c)
1203{
1204 e8080_set_pc (c, e8080_get_hl (c));
1205 e8080_set_clk (c, 0, 5);
1206}
1207
1208/* OP EA: JPE IM16 */
1209static void op_ea (e8080_t *c)
1210{
1211 e8080_get_inst12 (c);
1212
1213 if (e8080_get_pf (c)) {
1214 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
1215 e8080_set_clk (c, 0, 10);
1216 }
1217 else {
1218 e8080_set_clk (c, 3, 10);
1219 }
1220}
1221
1222/* OP EB: XCHG */
1223static void op_eb (e8080_t *c)
1224{
1225 unsigned short v;
1226
1227 v = e8080_get_hl (c);
1228 e8080_set_hl (c, e8080_get_de (c));
1229 e8080_set_de (c, v);
1230
1231 e8080_set_clk (c, 1, 4);
1232}
1233
1234/* OP EC: CPE IM16 */
1235static void op_ec (e8080_t *c)
1236{
1237 e8080_get_inst12 (c);
1238
1239 if (e8080_get_pf (c)) {
1240 e8080_set_sp (c, e8080_get_sp (c) - 2);
1241 e8080_set_mem16 (c, e8080_get_sp (c), e8080_get_pc (c) + 3);
1242 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
1243 e8080_set_clk (c, 0, 17);
1244 }
1245 else {
1246 e8080_set_clk (c, 3, 11);
1247 }
1248}
1249
1250/* OP EE: XRI IM8 */
1251static void op_ee (e8080_t *c)
1252{
1253 unsigned char s1, s2;
1254
1255 e8080_get_inst1 (c);
1256 s1 = e8080_get_a (c);
1257 s2 = c->inst[1];
1258 e8080_set_a (c, s1 ^ s2);
1259 e8080_set_psw_log (c, s1 ^ s2);
1260 e8080_set_clk (c, 2, 7);
1261}
1262
1263/* OP F0: RP */
1264static void op_f0 (e8080_t *c)
1265{
1266 if (e8080_get_sf (c) == 0) {
1267 e8080_set_pc (c, e8080_get_mem16 (c, e8080_get_sp (c)));
1268 e8080_set_sp (c, e8080_get_sp (c) + 2);
1269 e8080_set_clk (c, 0, 11);
1270 }
1271 else {
1272 e8080_set_clk (c, 1, 5);
1273 }
1274}
1275
1276/* OP F1: POP AF */
1277static void op_f1 (e8080_t *c)
1278{
1279 e8080_set_psw (c, (e8080_get_mem8 (c, e8080_get_sp (c) + 0) & 0xd7) | 0x02);
1280 e8080_set_a (c, e8080_get_mem8 (c, e8080_get_sp (c) + 1));
1281 e8080_set_sp (c, e8080_get_sp (c) + 2);
1282 e8080_set_clk (c, 1, 10);
1283}
1284
1285/* OP F2: JP IM16 */
1286static void op_f2 (e8080_t *c)
1287{
1288 e8080_get_inst12 (c);
1289
1290 if (e8080_get_sf (c) == 0) {
1291 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
1292 e8080_set_clk (c, 0, 10);
1293 }
1294 else {
1295 e8080_set_clk (c, 3, 10);
1296 }
1297}
1298
1299/* OP F3: DI */
1300static void op_f3 (e8080_t *c)
1301{
1302 e8080_set_iff1 (c, 0);
1303 e8080_set_iff2 (c, 0);
1304 e8080_set_clk (c, 1, 4);
1305}
1306
1307/* OP F4: CP IM16 */
1308static void op_f4 (e8080_t *c)
1309{
1310 e8080_get_inst12 (c);
1311
1312 if (e8080_get_sf (c) == 0) {
1313 e8080_set_sp (c, e8080_get_sp (c) - 2);
1314 e8080_set_mem16 (c, e8080_get_sp (c), e8080_get_pc (c) + 3);
1315 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
1316 e8080_set_clk (c, 0, 17);
1317 }
1318 else {
1319 e8080_set_clk (c, 3, 11);
1320 }
1321}
1322
1323/* OP F5: PUSH AF */
1324static void op_f5 (e8080_t *c)
1325{
1326 e8080_set_sp (c, e8080_get_sp (c) - 2);
1327 e8080_set_mem8 (c, e8080_get_sp (c) + 1, e8080_get_a (c));
1328 e8080_set_mem8 (c, e8080_get_sp (c) + 0, (e8080_get_psw (c) & 0xd7) | 0x02);
1329 e8080_set_clk (c, 1, 11);
1330}
1331
1332/* OP F6: ORI IM8 */
1333static void op_f6 (e8080_t *c)
1334{
1335 unsigned char s1, s2;
1336
1337 e8080_get_inst1 (c);
1338 s1 = e8080_get_a (c);
1339 s2 = c->inst[1];
1340 e8080_set_a (c, s1 | s2);
1341 e8080_set_psw_log (c, s1 | s2);
1342 e8080_set_clk (c, 2, 7);
1343}
1344
1345/* OP F8: RM */
1346static void op_f8 (e8080_t *c)
1347{
1348 if (e8080_get_sf (c)) {
1349 e8080_set_pc (c, e8080_get_mem16 (c, e8080_get_sp (c)));
1350 e8080_set_sp (c, e8080_get_sp (c) + 2);
1351 e8080_set_clk (c, 0, 11);
1352 }
1353 else {
1354 e8080_set_clk (c, 1, 5);
1355 }
1356}
1357
1358/* OP F9: SPHL */
1359static void op_f9 (e8080_t *c)
1360{
1361 e8080_set_sp (c, e8080_get_hl (c));
1362 e8080_set_clk (c, 1, 5);
1363}
1364
1365/* OP FA: JM IM16 */
1366static void op_fa (e8080_t *c)
1367{
1368 e8080_get_inst12 (c);
1369
1370 if (e8080_get_sf (c)) {
1371 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
1372 e8080_set_clk (c, 0, 10);
1373 }
1374 else {
1375 e8080_set_clk (c, 3, 10);
1376 }
1377}
1378
1379/* OP FB: EI */
1380static void op_fb (e8080_t *c)
1381{
1382 e8080_set_iff1 (c, 1);
1383 e8080_set_iff2 (c, 1);
1384 e8080_set_clk (c, 1, 4);
1385}
1386
1387/* OP FC: CM IM16 */
1388static void op_fc (e8080_t *c)
1389{
1390 e8080_get_inst12 (c);
1391
1392 if (e8080_get_sf (c)) {
1393 e8080_set_sp (c, e8080_get_sp (c) - 2);
1394 e8080_set_mem16 (c, e8080_get_sp (c), e8080_get_pc (c) + 3);
1395 e8080_set_pc (c, e8080_uint16 (c->inst[1], c->inst[2]));
1396 e8080_set_clk (c, 0, 17);
1397 }
1398 else {
1399 e8080_set_clk (c, 3, 11);
1400 }
1401}
1402
1403/* OP FE: CPI IM8 */
1404static void op_fe (e8080_t *c)
1405{
1406 unsigned char s1, s2;
1407
1408 e8080_get_inst1 (c);
1409 s1 = e8080_get_a (c);
1410 s2 = c->inst[1];
1411 e8080_set_psw_sub (c, s1, s2);
1412 e8080_set_clk (c, 2, 7);
1413}
1414
1415
1416e8080_opcode_f e8080_opcodes[256] = {
1417 op_00, op_01, op_02, op_03, op_04, op_05, op_06, op_07, /* 00 */
1418 NULL, op_09, op_0a, op_0b, op_0c, op_0d, op_0e, op_0f,
1419 NULL, op_11, op_12, op_13, op_14, op_15, op_16, op_17, /* 10 */
1420 NULL, op_19, op_1a, op_1b, op_1c, op_1d, op_1e, op_1f,
1421 NULL, op_21, op_22, op_23, op_24, op_25, op_26, op_27, /* 20 */
1422 NULL, op_29, op_2a, op_2b, op_2c, op_2d, op_2e, op_2f,
1423 NULL, op_31, op_32, op_33, op_34, op_35, op_36, op_37, /* 30 */
1424 NULL, op_39, op_3a, op_3b, op_3c, op_3d, op_3e, op_3f,
1425 op_40, op_40, op_40, op_40, op_40, op_40, op_46, op_40, /* 40 */
1426 op_40, op_40, op_40, op_40, op_40, op_40, op_46, op_40,
1427 op_40, op_40, op_40, op_40, op_40, op_40, op_46, op_40, /* 50 */
1428 op_40, op_40, op_40, op_40, op_40, op_40, op_46, op_40,
1429 op_40, op_40, op_40, op_40, op_40, op_40, op_46, op_40, /* 60 */
1430 op_40, op_40, op_40, op_40, op_40, op_40, op_46, op_40,
1431 op_70, op_70, op_70, op_70, op_70, op_70, op_76, op_70, /* 70 */
1432 op_40, op_40, op_40, op_40, op_40, op_40, op_46, op_40,
1433 op_80, op_80, op_80, op_80, op_80, op_80, op_86, op_80, /* 80 */
1434 op_88, op_88, op_88, op_88, op_88, op_88, op_8e, op_88,
1435 op_90, op_90, op_90, op_90, op_90, op_90, op_96, op_90, /* 90 */
1436 op_98, op_98, op_98, op_98, op_98, op_98, op_9e, op_98,
1437 op_a0, op_a0, op_a0, op_a0, op_a0, op_a0, op_a6, op_a0, /* 90 */
1438 op_a8, op_a8, op_a8, op_a8, op_a8, op_a8, op_ae, op_a8,
1439 op_b0, op_b0, op_b0, op_b0, op_b0, op_b0, op_b6, op_b0, /* 90 */
1440 op_b8, op_b8, op_b8, op_b8, op_b8, op_b8, op_be, op_b8,
1441 op_c0, op_c1, op_c2, op_c3, op_c4, op_c5, op_c6, op_c7, /* C0 */
1442 op_c8, op_c9, op_ca, NULL, op_cc, op_cd, op_ce, op_c7,
1443 op_d0, op_d1, op_d2, op_d3, op_d4, op_d5, op_d6, op_c7, /* D0 */
1444 op_d8, NULL, op_da, op_db, op_dc, NULL, op_de, op_c7,
1445 op_e0, op_e1, op_e2, op_e3, op_e4, op_e5, op_e6, op_c7, /* E0 */
1446 op_e8, op_e9, op_ea, op_eb, op_ec, NULL, op_ee, op_c7,
1447 op_f0, op_f1, op_f2, op_f3, op_f4, op_f5, op_f6, op_c7, /* F0 */
1448 op_f8, op_f9, op_fa, op_fb, op_fc, NULL, op_fe, op_c7
1449};
1450
1451void e8080_set_opcodes (e8080_t *c)
1452{
1453 unsigned i;
1454
1455 for (i = 0; i < 256; i++) {
1456 if (e8080_opcodes[i] == NULL) {
1457 c->op[i] = op_ud;
1458 }
1459 else {
1460 c->op[i] = e8080_opcodes[i];
1461 }
1462 }
1463}