Mercurial > repos > blastem
annotate ztestgen.c @ 491:193ca779988e opengl
Close OpenGL feature branch
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 27 Oct 2013 22:07:43 -0700 |
parents | 140af5509ce7 |
children | b7b7a1cab44a |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
400
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
400
diff
changeset
|
2 Copyright 2013 Michael Pavone |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
400
diff
changeset
|
3 This file is part of BlastEm. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
400
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
400
diff
changeset
|
5 */ |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "z80inst.h" |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include <stdlib.h> |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include <string.h> |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include <stdint.h> |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include <stdio.h> |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include <sys/stat.h> |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 #include <sys/types.h> |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #include <errno.h> |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 extern z80inst z80_tbl_a[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 extern z80inst z80_tbl_extd[0xC0-0x40]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 extern z80inst z80_tbl_bit[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 extern z80inst z80_tbl_ix[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 extern z80inst z80_tbl_iy[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 extern z80inst z80_tbl_ix_bit[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 extern z80inst z80_tbl_iy_bit[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 extern char *z80_mnemonics[Z80_OTDR+1]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 extern char * z80_regs[Z80_USE_IMMED]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 #define PRE_IX 0xDD |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 #define PRE_IY 0xFD |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 #define LD_IR16 0x01 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 #define LD_IR8 0x06 |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
28 #define LD_RR8 0x40 |
400
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
29 #define AND_R 0xA0 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 #define PUSH 0xC5 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 #define POP 0xC1 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 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
|
34 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 if (reg == Z80_IX) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 *(dst++) = PRE_IX; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 return ld_ir16(dst, Z80_HL, val); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 } else if(reg == Z80_IY) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 *(dst++) = PRE_IY; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 return ld_ir16(dst, Z80_HL, val); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 *(dst++) = LD_IR16 | ((reg - Z80_BC) << 4); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 *(dst++) = val & 0xFF; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 *(dst++) = val >> 8; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 return dst; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 } |
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 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
|
50 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 if (reg <= Z80_H) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 reg = (reg - Z80_C) ^ 1; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 reg = 0x7; |
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++) = LD_IR8 | (reg << 3); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 *(dst++) = val; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 return dst; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
61 uint8_t * ld_rr8(uint8_t * dst, uint8_t src, uint8_t dstr) |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
62 { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
63 if (src <= Z80_H) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
64 src = (src - Z80_C) ^ 1; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
65 } else { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
66 src = 0x7; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
67 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
68 if (dstr <= Z80_H) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
69 dstr = (dstr - Z80_C) ^ 1; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
70 } else { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
71 dstr = 0x7; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
72 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
73 *(dst++) = LD_RR8 | (dstr << 3) | src; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
74 return dst; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
75 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
76 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 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
|
78 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 *(dst++) = 0x32; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 *(dst++) = address & 0xFF; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 *(dst++) = address >> 8; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 return dst; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
85 uint8_t * ld_mema(uint8_t * dst, uint16_t address) |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
86 { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
87 *(dst++) = 0x3A; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
88 *(dst++) = address & 0xFF; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
89 *(dst++) = address >> 8; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
90 return dst; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
91 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
92 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 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
|
94 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 if (reg == Z80_IX) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 *(dst++) = PRE_IX; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 return push(dst, Z80_HL); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 } else if(reg == Z80_IY) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 *(dst++) = PRE_IY; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 return push(dst, Z80_HL); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 if (reg == Z80_AF) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 reg--; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 *(dst++) = PUSH | ((reg - Z80_BC) << 4); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 return dst; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 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
|
111 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 if (reg == Z80_IX) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 *(dst++) = PRE_IX; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 return pop(dst, Z80_HL); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 } else if(reg == Z80_IY) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 *(dst++) = PRE_IY; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 return pop(dst, Z80_HL); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 if (reg == Z80_AF) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 reg--; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 *(dst++) = POP | ((reg - Z80_BC) << 4); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 return dst; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 } |
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 |
400
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
127 uint8_t * and_r(uint8_t * dst, uint8_t reg) |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
128 { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
129 if (reg == Z80_IXH || reg == Z80_IXL) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
130 *(dst++) = PRE_IX; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
131 return and_r(dst, reg - (Z80_IXL - Z80_L)); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
132 } else if(reg == Z80_IYH || reg == Z80_IYL) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
133 *(dst++) = PRE_IY; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
134 return and_r(dst, reg - (Z80_IYL - Z80_L)); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
135 } else { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
136 if (reg == Z80_A) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
137 reg = 7; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
138 } else { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
139 reg = (reg - Z80_C) ^ 1; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
140 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
141 *(dst++) = AND_R | reg; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
142 return dst; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
143 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
144 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
145 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 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
|
147 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 z80inst copy; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 uint16_t reg_values[Z80_UNUSED]; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
150 uint8_t reg_usage[Z80_UNUSED]; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 memset(reg_values, 0, sizeof(reg_values)); |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
152 memset(reg_usage, 0, sizeof(reg_usage)); |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 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
|
154 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
|
155 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 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
|
157 || 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
|
158 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 memcpy(©, inst, sizeof(copy)); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 inst = © |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 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
|
162 || (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
|
163 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 copy.immed = rand() % (word_sized ? 65536 : 256); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 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
|
167 copy.ea_reg = rand() % 256; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 if (addr_mode == Z80_IMMED_INDIRECT) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 copy.immed = 0x1000 + (rand() % 256 - 128); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 } |
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 uint8_t is_mem = 0; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 uint16_t address; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 int16_t offset; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 switch(addr_mode) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 case Z80_REG: |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
179 reg_usage[inst->ea_reg] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 if (word_sized) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 reg_values[inst->ea_reg] = rand() % 65536; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 reg_values[z80_high_reg(inst->ea_reg)] = reg_values[inst->ea_reg] >> 8; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
183 reg_usage[z80_high_reg(inst->ea_reg)] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 reg_values[z80_low_reg(inst->ea_reg)] = reg_values[inst->ea_reg] & 0xFF; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
185 reg_usage[z80_low_reg(inst->ea_reg)] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 reg_values[inst->ea_reg] = rand() % 256; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 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
|
189 if (word_reg != Z80_UNUSED) { |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
190 reg_usage[word_reg] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 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
|
192 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 break; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 case Z80_REG_INDIRECT: |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 is_mem = 1; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 reg_values[inst->ea_reg] = 0x1000 + (rand() % 256 - 128); |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
198 reg_usage[inst->ea_reg] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 address = reg_values[inst->ea_reg]; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
200 reg_usage[z80_high_reg(inst->ea_reg)] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 reg_values[z80_high_reg(inst->ea_reg)] = reg_values[inst->ea_reg] >> 8; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
202 reg_usage[z80_low_reg(inst->ea_reg)] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 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
|
204 break; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 case Z80_IMMED_INDIRECT: |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 is_mem = 1; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 address = inst->immed; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 break; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 case Z80_IX_DISPLACE: |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 reg_values[Z80_IX] = 0x1000; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
211 reg_usage[Z80_IX] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 reg_values[Z80_IXH] = 0x10; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
213 reg_usage[Z80_IXH] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 reg_values[Z80_IXL] = 0; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
215 reg_usage[Z80_IXL] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 is_mem = 1; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 offset = inst->ea_reg; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 if (offset > 0x7F) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 offset -= 256; |
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 address = 0x1000 + offset; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 break; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 case Z80_IY_DISPLACE: |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 reg_values[Z80_IY] = 0x1000; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
225 reg_usage[Z80_IY] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 reg_values[Z80_IYH] = 0x10; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
227 reg_usage[Z80_IYH] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 reg_values[Z80_IYL] = 0; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
229 reg_usage[Z80_IYL] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 is_mem = 1; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 offset = inst->ea_reg; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 if (offset > 0x7F) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 offset -= 256; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 address = 0x1000 + offset; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 break; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 if (inst->reg != Z80_UNUSED && inst->reg != Z80_USE_IMMED) { |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
239 reg_usage[inst->reg] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 if (word_sized) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 reg_values[inst->reg] = rand() % 65536; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
242 reg_usage[z80_high_reg(inst->reg)] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 reg_values[z80_high_reg(inst->reg)] = reg_values[inst->reg] >> 8; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
244 reg_usage[z80_low_reg(inst->reg)] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 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
|
246 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 reg_values[inst->reg] = rand() % 255; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 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
|
249 if (word_reg != Z80_UNUSED) { |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
250 reg_usage[word_reg] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 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
|
252 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 puts("--------------"); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 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
|
257 if (reg_values[reg]) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 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
|
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 char disbuf[80]; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
262 z80_disasm(inst, disbuf, 0); |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 puts(disbuf); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 char pathbuf[128]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 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
|
266 if (mkdir(pathbuf, 0777) != 0) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 if (errno != EEXIST) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 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
|
269 exit(1); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 } |
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 uint8_t prog[200]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 uint8_t *cur = prog; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 uint8_t mem_val; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 //disable interrupts |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 *(cur++) = 0xF3; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 //setup SP |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 cur = ld_ir16(cur, Z80_SP, 0x2000); |
400
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
279 for (int i = 0; i < 2; i ++) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
280 //setup memory |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
281 if (is_mem) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
282 mem_val = rand() % 256; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
283 cur = ld_ir8(cur, Z80_A, mem_val); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
284 cur = ld_amem(cur, address); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
285 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
286 //setup AF |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
287 cur = ld_ir16(cur, Z80_BC, reg_values[Z80_A] << 8 | (i ? 0xFF : 0)); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
288 cur = push(cur, Z80_BC); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
289 cur = pop(cur, Z80_AF); |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 |
400
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
291 //setup other regs |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
292 for (uint8_t reg = Z80_BC; reg <= Z80_IY; reg++) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
293 if (reg != Z80_AF && reg != Z80_SP) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
294 cur = ld_ir16(cur, reg, reg_values[reg]); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
295 } |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 } |
400
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
297 |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
298 //copy instruction |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
299 if (instlen == 3) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
300 memcpy(cur, instbuf, 2); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
301 cur += 2; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
302 } else { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
303 memcpy(cur, instbuf, instlen); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
304 cur += instlen; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
305 } |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 |
400
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
307 //immed/displacement byte(s) |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
308 if (addr_mode == Z80_IX_DISPLACE || addr_mode == Z80_IY_DISPLACE) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
309 *(cur++) = inst->ea_reg; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
310 } else if (addr_mode == Z80_IMMED & inst->op != Z80_IM) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
311 *(cur++) = inst->immed & 0xFF; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
312 if (word_sized) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
313 *(cur++) = inst->immed >> 8; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
314 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
315 } else if (addr_mode == Z80_IMMED_INDIRECT) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
316 *(cur++) = inst->immed & 0xFF; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 *(cur++) = inst->immed >> 8; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 } |
400
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
319 if (inst->reg == Z80_USE_IMMED && inst->op != Z80_BIT && inst->op != Z80_RES && inst->op != Z80_SET) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
320 *(cur++) = inst->immed & 0xFF; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
321 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
322 if (instlen == 3) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
323 *(cur++) = instbuf[2]; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
324 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
325 if (!i) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
326 //Save AF from first run |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
327 cur = push(cur, Z80_AF); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
328 } else { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
329 //Pop AF from first run for final result |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
330 for (int reg = Z80_BC; reg <= Z80_IY; reg++) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
331 if (reg != Z80_AF && !reg_usage[reg]) { |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
332 cur = pop(cur, reg); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
333 cur = push(cur, Z80_AF); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
334 cur = ld_ir8(cur, Z80_A, 0xC7); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
335 cur = and_r(cur, z80_low_reg(reg)); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
336 cur = ld_rr8(cur, Z80_A, z80_low_reg(reg)); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
337 cur = pop(cur, Z80_AF); |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
338 reg_usage[reg] = 1; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
339 reg_usage[z80_low_reg(reg)] = 1; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
340 break; |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
341 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
342 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
343 } |
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
|
344 } |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
346 for (char * cur = disbuf; *cur != 0; cur++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 if (*cur == ',' || *cur == ' ') { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 *cur = '_'; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 } |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
351 //save memory result |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
352 if (is_mem) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
353 if (reg_usage[Z80_A]) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
354 cur = push(cur, Z80_AF); |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
355 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
356 cur = ld_mema(cur, address); |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
357 if (reg_usage[Z80_A]) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
358 for (int reg = 0; reg < Z80_I; reg++) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
359 if (!reg_usage[reg]) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
360 cur = ld_rr8(cur, Z80_A, reg); |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
361 break; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
362 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
363 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
364 cur = pop(cur, Z80_AF); |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
365 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
366 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
367 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 //halt |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 *(cur++) = 0x76; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 sprintf(pathbuf + strlen(pathbuf), "/%s.bin", disbuf); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 FILE * progfile = fopen(pathbuf, "wb"); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 fwrite(prog, 1, cur - prog, progfile); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 fclose(progfile); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 uint8_t should_skip(z80inst * inst) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 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
|
380 || 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
|
381 || 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
|
382 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
384 void z80_gen_all() |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 uint8_t inst[3]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 for (int op = 0; op < 256; op++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 inst[0] = op; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 if (op == 0xCB) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 for (int subop = 0; subop < 256; subop++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 if (!should_skip(z80_tbl_bit + subop)) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 inst[1] = subop; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 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
|
394 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 } else if(op == 0xDD) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 for (int ixop = 0; ixop < 256; ixop++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 inst[1] = ixop; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 if (ixop == 0xCB) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 for (int subop = 0; subop < 256; subop++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 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
|
402 inst[2] = subop; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 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
|
404 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 if (!should_skip(z80_tbl_ix + ixop)) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 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
|
409 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 } else if(op == 0xED) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 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
|
414 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
|
415 inst[1] = subop + 0x40; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 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
|
417 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
419 } else if(op == 0xFD) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 for (int iyop = 0; iyop < 256; iyop++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 inst[1] = iyop; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 if (iyop == 0xCB) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 for (int subop = 0; subop < 256; subop++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 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
|
425 inst[2] = subop; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 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
|
427 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 if (!should_skip(z80_tbl_iy + iyop)) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
431 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
|
432 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 if (!should_skip(z80_tbl_a + op)) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 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
|
438 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
439 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
440 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
441 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 int main(int argc, char ** argv) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
444 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
445 z80_gen_all(); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
446 return 0; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
447 } |