annotate ztestgen.c @ 312:cf7ecda060c7

Properly handle instructions that use boty IYH and IYL
author Mike Pavone <pavone@retrodev.com>
date Thu, 09 May 2013 18:36:21 -0700
parents 170722e80fc0
children 3f4f2b7318a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include "z80inst.h"
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <stdlib.h>
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include <string.h>
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include <stdint.h>
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include <stdio.h>
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include <sys/stat.h>
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 #include <sys/types.h>
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include <errno.h>
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 extern z80inst z80_tbl_a[256];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 extern z80inst z80_tbl_extd[0xC0-0x40];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 extern z80inst z80_tbl_bit[256];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13 extern z80inst z80_tbl_ix[256];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 extern z80inst z80_tbl_iy[256];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15 extern z80inst z80_tbl_ix_bit[256];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 extern z80inst z80_tbl_iy_bit[256];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 extern char *z80_mnemonics[Z80_OTDR+1];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 extern char * z80_regs[Z80_USE_IMMED];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 #define PRE_IX 0xDD
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 #define PRE_IY 0xFD
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
21 #define LD_IR16 0x01
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
22 #define LD_IR8 0x06
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 #define PUSH 0xC5
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24 #define POP 0xC1
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
25
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26 uint8_t * ld_ir16(uint8_t * dst, uint8_t reg, uint16_t val)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 if (reg == Z80_IX) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
29 *(dst++) = PRE_IX;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30 return ld_ir16(dst, Z80_HL, val);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31 } else if(reg == Z80_IY) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 *(dst++) = PRE_IY;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
33 return ld_ir16(dst, Z80_HL, val);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34 } else {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
35 *(dst++) = LD_IR16 | ((reg - Z80_BC) << 4);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 *(dst++) = val & 0xFF;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37 *(dst++) = val >> 8;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
38 return dst;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
42 uint8_t * ld_ir8(uint8_t * dst, uint8_t reg, uint8_t val)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 if (reg <= Z80_H) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45 reg = (reg - Z80_C) ^ 1;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
46 } else {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 reg = 0x7;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 *(dst++) = LD_IR8 | (reg << 3);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 *(dst++) = val;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51 return dst;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
54 uint8_t * ld_amem(uint8_t * dst, uint16_t address)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56 *(dst++) = 0x32;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57 *(dst++) = address & 0xFF;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 *(dst++) = address >> 8;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 return dst;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
62 uint8_t * push(uint8_t * dst, uint8_t reg)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
64 if (reg == Z80_IX) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 *(dst++) = PRE_IX;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 return push(dst, Z80_HL);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 } else if(reg == Z80_IY) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 *(dst++) = PRE_IY;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 return push(dst, Z80_HL);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 } else {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 if (reg == Z80_AF) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 reg--;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
74 *(dst++) = PUSH | ((reg - Z80_BC) << 4);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
75 return dst;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
76 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
77 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
78
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
79 uint8_t * pop(uint8_t * dst, uint8_t reg)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
80 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
81 if (reg == Z80_IX) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
82 *(dst++) = PRE_IX;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
83 return pop(dst, Z80_HL);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
84 } else if(reg == Z80_IY) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
85 *(dst++) = PRE_IY;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
86 return pop(dst, Z80_HL);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87 } else {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 if (reg == Z80_AF) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
89 reg--;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
91 *(dst++) = POP | ((reg - Z80_BC) << 4);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
92 return dst;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
93 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
94 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
96 void z80_gen_test(z80inst * inst, uint8_t *instbuf, uint8_t instlen)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
97 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
98 z80inst copy;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
99 uint16_t reg_values[Z80_UNUSED];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 memset(reg_values, 0, sizeof(reg_values));
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 uint8_t addr_mode = inst->addr_mode & 0x1F;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
102 uint8_t word_sized = ((inst->reg != Z80_USE_IMMED && inst->reg != Z80_UNUSED && inst->reg >= Z80_BC) || (addr_mode == Z80_REG && inst->ea_reg >= Z80_BC)) ? 1 : 0;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
103
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
104 if (inst->reg == Z80_USE_IMMED || addr_mode == Z80_IMMED || addr_mode == Z80_IMMED_INDIRECT
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105 || addr_mode == Z80_IX_DISPLACE || addr_mode == Z80_IY_DISPLACE)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
106 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107 memcpy(&copy, inst, sizeof(copy));
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108 inst = &copy;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 if ((inst->reg == Z80_USE_IMMED && inst->op != Z80_BIT && inst->op != Z80_RES && inst->op != Z80_SET)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
110 || (addr_mode == Z80_IMMED && inst->op != Z80_IM))
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
111 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
112 copy.immed = rand() % (word_sized ? 65536 : 256);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
113 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114 if (addr_mode == Z80_IX_DISPLACE || addr_mode == Z80_IY_DISPLACE) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
115 copy.ea_reg = rand() % 256;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
116 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
117 if (addr_mode == Z80_IMMED_INDIRECT) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
118 copy.immed = 0x1000 + (rand() % 256 - 128);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
119 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
121 uint8_t is_mem = 0;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
122 uint16_t address;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 int16_t offset;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
124 switch(addr_mode)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
125 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 case Z80_REG:
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
127 if (word_sized) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
128 reg_values[inst->ea_reg] = rand() % 65536;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
129 reg_values[z80_high_reg(inst->ea_reg)] = reg_values[inst->ea_reg] >> 8;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
130 reg_values[z80_low_reg(inst->ea_reg)] = reg_values[inst->ea_reg] & 0xFF;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
131 } else {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
132 reg_values[inst->ea_reg] = rand() % 256;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
133 uint8_t word_reg = z80_word_reg(inst->ea_reg);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
134 if (word_reg != Z80_UNUSED) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
135 reg_values[word_reg] = (reg_values[z80_high_reg(word_reg)] << 8) | (reg_values[z80_low_reg(word_reg)] & 0xFF);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
136 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
137 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
138 break;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
139 case Z80_REG_INDIRECT:
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
140 is_mem = 1;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
141 reg_values[inst->ea_reg] = 0x1000 + (rand() % 256 - 128);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
142 address = reg_values[inst->ea_reg];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
143 reg_values[z80_high_reg(inst->ea_reg)] = reg_values[inst->ea_reg] >> 8;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
144 reg_values[z80_low_reg(inst->ea_reg)] = reg_values[inst->ea_reg] & 0xFF;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
145 break;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
146 case Z80_IMMED_INDIRECT:
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
147 is_mem = 1;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
148 address = inst->immed;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
149 break;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
150 case Z80_IX_DISPLACE:
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
151 reg_values[Z80_IX] = 0x1000;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
152 reg_values[Z80_IXH] = 0x10;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
153 reg_values[Z80_IXL] = 0;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
154 is_mem = 1;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
155 offset = inst->ea_reg;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
156 if (offset > 0x7F) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
157 offset -= 256;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
158 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
159 address = 0x1000 + offset;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
160 break;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
161 case Z80_IY_DISPLACE:
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
162 reg_values[Z80_IY] = 0x1000;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
163 reg_values[Z80_IYH] = 0x10;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
164 reg_values[Z80_IYL] = 0;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
165 is_mem = 1;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
166 offset = inst->ea_reg;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
167 if (offset > 0x7F) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
168 offset -= 256;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
169 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
170 address = 0x1000 + offset;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
171 break;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
172 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
173 if (inst->reg != Z80_UNUSED && inst->reg != Z80_USE_IMMED) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
174 if (word_sized) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
175 reg_values[inst->reg] = rand() % 65536;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
176 reg_values[z80_high_reg(inst->reg)] = reg_values[inst->reg] >> 8;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
177 reg_values[z80_low_reg(inst->reg)] = reg_values[inst->reg] & 0xFF;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
178 } else {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
179 reg_values[inst->reg] = rand() % 255;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
180 uint8_t word_reg = z80_word_reg(inst->reg);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
181 if (word_reg != Z80_UNUSED) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
182 reg_values[word_reg] = (reg_values[z80_high_reg(word_reg)] << 8) | (reg_values[z80_low_reg(word_reg)] & 0xFF);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
183 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
184 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
185 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
186 puts("--------------");
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
187 for (uint8_t reg = 0; reg < Z80_UNUSED; reg++) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
188 if (reg_values[reg]) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 printf("%s: %X\n", z80_regs[reg], reg_values[reg]);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
190 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
191 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
192 char disbuf[80];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
193 z80_disasm(inst, disbuf);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
194 puts(disbuf);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
195 char pathbuf[128];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
196 sprintf(pathbuf, "ztests/%s", z80_mnemonics[inst->op]);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
197 if (mkdir(pathbuf, 0777) != 0) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
198 if (errno != EEXIST) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
199 fprintf(stderr, "Failed to create directory %s\n", disbuf);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
200 exit(1);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
201 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
202 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
203 uint8_t prog[200];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
204 uint8_t *cur = prog;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
205 uint8_t mem_val;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
206 //disable interrupts
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
207 *(cur++) = 0xF3;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
208 //setup SP
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
209 cur = ld_ir16(cur, Z80_SP, 0x2000);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
210 //setup memory
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
211 if (is_mem) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
212 mem_val = rand() % 256;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
213 cur = ld_ir8(cur, Z80_A, mem_val);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
214 cur = ld_amem(cur, address);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
215 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
216 //setup AF
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
217 cur = ld_ir16(cur, Z80_BC, reg_values[Z80_A] << 8);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
218 cur = push(cur, Z80_BC);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
219 cur = pop(cur, Z80_AF);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
220
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
221 //setup other regs
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
222 for (uint8_t reg = Z80_BC; reg <= Z80_IY; reg++) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
223 if (reg != Z80_AF && reg != Z80_SP) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
224 cur = ld_ir16(cur, reg, reg_values[reg]);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
225 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
226 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
227
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
228 //copy instruction
298
170722e80fc0 Fix handling of instructions that combine an IX/IY displacement with another prefix in test generator
Mike Pavone <pavone@retrodev.com>
parents: 296
diff changeset
229 if (instlen == 3) {
170722e80fc0 Fix handling of instructions that combine an IX/IY displacement with another prefix in test generator
Mike Pavone <pavone@retrodev.com>
parents: 296
diff changeset
230 memcpy(cur, instbuf, 2);
170722e80fc0 Fix handling of instructions that combine an IX/IY displacement with another prefix in test generator
Mike Pavone <pavone@retrodev.com>
parents: 296
diff changeset
231 cur += 2;
170722e80fc0 Fix handling of instructions that combine an IX/IY displacement with another prefix in test generator
Mike Pavone <pavone@retrodev.com>
parents: 296
diff changeset
232 } else {
170722e80fc0 Fix handling of instructions that combine an IX/IY displacement with another prefix in test generator
Mike Pavone <pavone@retrodev.com>
parents: 296
diff changeset
233 memcpy(cur, instbuf, instlen);
170722e80fc0 Fix handling of instructions that combine an IX/IY displacement with another prefix in test generator
Mike Pavone <pavone@retrodev.com>
parents: 296
diff changeset
234 cur += instlen;
170722e80fc0 Fix handling of instructions that combine an IX/IY displacement with another prefix in test generator
Mike Pavone <pavone@retrodev.com>
parents: 296
diff changeset
235 }
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
236
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
237 //immed/displacement byte(s)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
238 if (addr_mode == Z80_IX_DISPLACE || addr_mode == Z80_IY_DISPLACE) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
239 *(cur++) = inst->ea_reg;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
240 } else if (addr_mode == Z80_IMMED & inst->op != Z80_IM) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
241 *(cur++) = inst->immed & 0xFF;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
242 if (word_sized) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
243 *(cur++) = inst->immed >> 8;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
244 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
245 } else if (addr_mode == Z80_IMMED_INDIRECT) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
246 *(cur++) = inst->immed & 0xFF;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
247 *(cur++) = inst->immed >> 8;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
248 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
249 if (inst->reg == Z80_USE_IMMED && inst->op != Z80_BIT && inst->op != Z80_RES && inst->op != Z80_SET) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
250 *(cur++) = inst->immed & 0xFF;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
251 }
298
170722e80fc0 Fix handling of instructions that combine an IX/IY displacement with another prefix in test generator
Mike Pavone <pavone@retrodev.com>
parents: 296
diff changeset
252 if (instlen == 3) {
170722e80fc0 Fix handling of instructions that combine an IX/IY displacement with another prefix in test generator
Mike Pavone <pavone@retrodev.com>
parents: 296
diff changeset
253 *(cur++) = instbuf[2];
170722e80fc0 Fix handling of instructions that combine an IX/IY displacement with another prefix in test generator
Mike Pavone <pavone@retrodev.com>
parents: 296
diff changeset
254 }
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
255
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
256 for (char * cur = disbuf; *cur != 0; cur++) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
257 if (*cur == ',' || *cur == ' ') {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
258 *cur = '_';
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
259 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
260 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
261 //halt
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
262 *(cur++) = 0x76;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
263 sprintf(pathbuf + strlen(pathbuf), "/%s.bin", disbuf);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
264 FILE * progfile = fopen(pathbuf, "wb");
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
265 fwrite(prog, 1, cur - prog, progfile);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
266 fclose(progfile);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
267 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
268
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
269
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
270 uint8_t should_skip(z80inst * inst)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
271 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
272 return inst->op >= Z80_JP || (inst->op >= Z80_LDI && inst->op <= Z80_CPDR) || inst->op == Z80_HALT
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
273 || inst->op == Z80_DAA || inst->op == Z80_RLD || inst->op == Z80_RRD || inst->op == Z80_NOP
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
274 || inst->op == Z80_DI || inst->op == Z80_EI;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
275 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
276
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
277 void z80_gen_all()
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
278 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
279 uint8_t inst[3];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
280 for (int op = 0; op < 256; op++) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
281 inst[0] = op;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
282 if (op == 0xCB) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
283 for (int subop = 0; subop < 256; subop++) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
284 if (!should_skip(z80_tbl_bit + subop)) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
285 inst[1] = subop;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
286 z80_gen_test(z80_tbl_bit + subop, inst, 2);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
287 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
288 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
289 } else if(op == 0xDD) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
290 for (int ixop = 0; ixop < 256; ixop++) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
291 inst[1] = ixop;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
292 if (ixop == 0xCB) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
293 for (int subop = 0; subop < 256; subop++) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
294 if (!should_skip(z80_tbl_ix_bit + subop)) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
295 inst[2] = subop;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
296 z80_gen_test(z80_tbl_ix_bit + subop, inst, 3);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
297 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
298 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
299 } else {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
300 if (!should_skip(z80_tbl_ix + ixop)) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
301 z80_gen_test(z80_tbl_ix + ixop, inst, 2);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
302 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
303 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
304 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
305 } else if(op == 0xED) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
306 for (int subop = 0; subop < sizeof(z80_tbl_extd)/sizeof(z80inst); subop++) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
307 if (!should_skip(z80_tbl_extd + subop)) {
296
f90aeea98e53 Fix encoding of "extended" instructions in Z80 test generator
Mike Pavone <pavone@retrodev.com>
parents: 292
diff changeset
308 inst[1] = subop + 0x40;
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
309 z80_gen_test(z80_tbl_extd + subop, inst, 2);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
310 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
311 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
312 } else if(op == 0xFD) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
313 for (int iyop = 0; iyop < 256; iyop++) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
314 inst[1] = iyop;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
315 if (iyop == 0xCB) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
316 for (int subop = 0; subop < 256; subop++) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
317 if (!should_skip(z80_tbl_iy_bit + subop)) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
318 inst[2] = subop;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
319 z80_gen_test(z80_tbl_iy_bit + subop, inst, 3);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
320 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
321 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
322 } else {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
323 if (!should_skip(z80_tbl_iy + iyop)) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
324 z80_gen_test(z80_tbl_iy + iyop, inst, 2);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
325 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
326 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
327 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
328 } else {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
329 if (!should_skip(z80_tbl_a + op)) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
330 z80_gen_test(z80_tbl_a + op, inst, 1);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
331 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
332 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
333 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
334 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
335
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
336 int main(int argc, char ** argv)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
337 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
338 z80_gen_all();
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
339 return 0;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
340 }