Mercurial > repos > blastem
annotate ztestgen.c @ 2476:aaf7bb58ffca
Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 03 Mar 2024 13:47:59 -0800 |
parents | cd6f4cea97b6 |
children |
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 |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
3 This file is part of BlastEm. |
467
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> |
1746
cd6f4cea97b6
Call srand in Z80 test generator so different values are used when regenerating tests
Michael Pavone <pavone@retrodev.com>
parents:
1042
diff
changeset
|
14 #include <time.h> |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 extern z80inst z80_tbl_a[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 extern z80inst z80_tbl_extd[0xC0-0x40]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 extern z80inst z80_tbl_bit[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 extern z80inst z80_tbl_ix[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 extern z80inst z80_tbl_iy[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 extern z80inst z80_tbl_ix_bit[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 extern z80inst z80_tbl_iy_bit[256]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 extern char *z80_mnemonics[Z80_OTDR+1]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 extern char * z80_regs[Z80_USE_IMMED]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 #define PRE_IX 0xDD |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 #define PRE_IY 0xFD |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 #define LD_IR16 0x01 |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
28 #define INC_R8 0x04 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 #define LD_IR8 0x06 |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
30 #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
|
31 #define AND_R 0xA0 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 #define PUSH 0xC5 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 #define POP 0xC1 |
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 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
|
36 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 if (reg == Z80_IX) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 *(dst++) = PRE_IX; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 return ld_ir16(dst, Z80_HL, val); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 } else if(reg == Z80_IY) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 *(dst++) = PRE_IY; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 return ld_ir16(dst, Z80_HL, val); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 *(dst++) = LD_IR16 | ((reg - Z80_BC) << 4); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 *(dst++) = val & 0xFF; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 *(dst++) = val >> 8; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 return dst; |
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 } |
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 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
|
52 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 if (reg <= Z80_H) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 reg = (reg - Z80_C) ^ 1; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 reg = 0x7; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 *(dst++) = LD_IR8 | (reg << 3); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 *(dst++) = val; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 return dst; |
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 |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
63 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
|
64 { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
65 if (src <= Z80_H) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
66 src = (src - Z80_C) ^ 1; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
67 } else { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
68 src = 0x7; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
69 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
70 if (dstr <= Z80_H) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
71 dstr = (dstr - Z80_C) ^ 1; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
72 } else { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
73 dstr = 0x7; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
74 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
75 *(dst++) = LD_RR8 | (dstr << 3) | src; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
76 return dst; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
77 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
78 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 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
|
80 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 *(dst++) = 0x32; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 *(dst++) = address & 0xFF; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 *(dst++) = address >> 8; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 return dst; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
87 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
|
88 { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
89 *(dst++) = 0x3A; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
90 *(dst++) = address & 0xFF; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
91 *(dst++) = address >> 8; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
92 return dst; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
93 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
94 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 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
|
96 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 if (reg == Z80_IX) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 *(dst++) = PRE_IX; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 return push(dst, Z80_HL); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 } else if(reg == Z80_IY) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 *(dst++) = PRE_IY; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 return push(dst, Z80_HL); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 if (reg == Z80_AF) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 reg--; |
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 *(dst++) = PUSH | ((reg - Z80_BC) << 4); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 return dst; |
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 } |
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 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
|
113 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 if (reg == Z80_IX) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 *(dst++) = PRE_IX; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 return pop(dst, Z80_HL); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 } else if(reg == Z80_IY) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 *(dst++) = PRE_IY; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 return pop(dst, Z80_HL); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 if (reg == Z80_AF) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 reg--; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 *(dst++) = POP | ((reg - Z80_BC) << 4); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 return dst; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 |
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
|
129 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
|
130 { |
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 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
|
132 *(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
|
133 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
|
134 } 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
|
135 *(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
|
136 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
|
137 } 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
|
138 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
|
139 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
|
140 } 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
|
141 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
|
142 } |
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 *(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
|
144 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
|
145 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
146 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
147 |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
148 uint8_t * inc_r(uint8_t *dst, uint8_t reg) |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
149 { |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
150 if (reg == Z80_IXH || reg == Z80_IXL) { |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
151 *(dst++) = PRE_IX; |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
152 return inc_r(dst, reg - (Z80_IXL - Z80_L)); |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
153 } else if(reg == Z80_IYH || reg == Z80_IYL) { |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
154 *(dst++) = PRE_IY; |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
155 return inc_r(dst, reg - (Z80_IYL - Z80_L)); |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
156 } else { |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
157 *(dst++) = INC_R8 | reg << 3; |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
158 return dst; |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
159 } |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
160 } |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
161 |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
162 void mark_used8(uint8_t *reg_usage, uint16_t *reg_values, uint8_t reg, uint8_t init_value) |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
163 { |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
164 reg_usage[reg] = 1; |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
165 reg_values[reg] = init_value; |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
166 uint8_t word_reg = z80_word_reg(reg); |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
167 if (word_reg != Z80_UNUSED) { |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
168 reg_usage[word_reg] = 1; |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
169 reg_values[word_reg] = (reg_values[z80_high_reg(word_reg)] << 8) | (reg_values[z80_low_reg(word_reg)] & 0xFF); |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
170 } |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
171 } |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
172 |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
173 uint8_t alloc_reg8(uint8_t *reg_usage, uint16_t *reg_values, uint8_t init_value) |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
174 { |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
175 for (uint8_t reg = 0; reg < Z80_BC; reg++) |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
176 { |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
177 if (!reg_usage[reg]) { |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
178 mark_used8(reg_usage, reg_values, reg, init_value); |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
179 return reg; |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
180 } |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
181 } |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
182 return Z80_UNUSED; |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
183 } |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
184 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 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
|
186 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 z80inst copy; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 uint16_t reg_values[Z80_UNUSED]; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
189 uint8_t reg_usage[Z80_UNUSED]; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 memset(reg_values, 0, sizeof(reg_values)); |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 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
|
196 || 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
|
197 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 memcpy(©, inst, sizeof(copy)); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 inst = © |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
200 if ((inst->reg == Z80_USE_IMMED && inst->op != Z80_BIT && inst->op != Z80_RES && inst->op != Z80_SET) |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 || (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
|
202 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 copy.immed = rand() % (word_sized ? 65536 : 256); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 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
|
206 copy.ea_reg = rand() % 256; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 if (addr_mode == Z80_IMMED_INDIRECT) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 copy.immed = 0x1000 + (rand() % 256 - 128); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 uint8_t is_mem = 0; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 uint16_t address; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 int16_t offset; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 switch(addr_mode) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 case Z80_REG: |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
218 reg_usage[inst->ea_reg] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 if (word_sized) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 reg_values[inst->ea_reg] = rand() % 65536; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 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
|
222 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
|
223 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
|
224 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
|
225 } else { |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
226 mark_used8(reg_usage, reg_values, inst->ea_reg, rand() % 256); |
292
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 break; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 case Z80_REG_INDIRECT: |
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 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
|
232 reg_usage[inst->ea_reg] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 address = reg_values[inst->ea_reg]; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
234 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
|
235 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
|
236 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
|
237 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
|
238 break; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 case Z80_IMMED_INDIRECT: |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 is_mem = 1; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 address = inst->immed; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 break; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 case Z80_IX_DISPLACE: |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 reg_values[Z80_IX] = 0x1000; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
245 reg_usage[Z80_IX] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 reg_values[Z80_IXH] = 0x10; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
247 reg_usage[Z80_IXH] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 reg_values[Z80_IXL] = 0; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
249 reg_usage[Z80_IXL] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 is_mem = 1; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 offset = inst->ea_reg; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 if (offset > 0x7F) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 offset -= 256; |
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 address = 0x1000 + offset; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 break; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 case Z80_IY_DISPLACE: |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 reg_values[Z80_IY] = 0x1000; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
259 reg_usage[Z80_IY] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 reg_values[Z80_IYH] = 0x10; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
261 reg_usage[Z80_IYH] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 reg_values[Z80_IYL] = 0; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
263 reg_usage[Z80_IYL] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 is_mem = 1; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 offset = inst->ea_reg; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 if (offset > 0x7F) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 offset -= 256; |
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 address = 0x1000 + offset; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 break; |
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 if (inst->reg != Z80_UNUSED && inst->reg != Z80_USE_IMMED) { |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
273 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 if (word_sized) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 reg_values[inst->reg] = rand() % 65536; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
276 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
|
277 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
|
278 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
|
279 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
|
280 } else { |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
281 if (!reg_usage[inst->reg]) { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
282 reg_values[inst->reg] = rand() % 255; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
283 uint8_t word_reg = z80_word_reg(inst->reg); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
284 if (word_reg != Z80_UNUSED) { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
285 reg_usage[word_reg] = 1; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
286 reg_values[word_reg] = (reg_values[z80_high_reg(word_reg)] << 8) | (reg_values[z80_low_reg(word_reg)] & 0xFF); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
287 } |
292
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 } |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
290 reg_usage[inst->reg] = 1; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 } |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
292 uint8_t counter_reg = Z80_UNUSED; |
619
3072fb746601
Added support for JR and JRcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
618
diff
changeset
|
293 if (inst->op >= Z80_JP && inst->op <= Z80_JRCC) { |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
294 counter_reg = alloc_reg8(reg_usage, reg_values, 0); |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
295 } |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 puts("--------------"); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 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
|
298 if (reg_values[reg]) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 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
|
300 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 char disbuf[80]; |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
303 z80_disasm(inst, disbuf, 0); |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 puts(disbuf); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 char pathbuf[128]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 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
|
307 if (mkdir(pathbuf, 0777) != 0) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 if (errno != EEXIST) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 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
|
310 exit(1); |
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 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 uint8_t prog[200]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 uint8_t *cur = prog; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 uint8_t mem_val; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 //disable interrupts |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 *(cur++) = 0xF3; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 //setup SP |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 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
|
320 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
|
321 //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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 } |
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 //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
|
328 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
|
329 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
|
330 cur = pop(cur, Z80_AF); |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
331 |
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
|
332 //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
|
333 for (uint8_t reg = Z80_BC; reg <= Z80_IY; reg++) { |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
334 if (reg != Z80_AF && reg != Z80_SP && (inst->op != Z80_JP || addr_mode != Z80_REG_INDIRECT || inst->ea_reg != reg)) { |
618
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
335 if (i == 1 && (z80_high_reg(reg) == counter_reg || z80_low_reg(reg) == counter_reg)) { |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
336 if (z80_high_reg(reg) == counter_reg) { |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
337 if (reg_usage[z80_low_reg(reg)]) { |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
338 cur = ld_ir8(cur, z80_low_reg(reg), reg_values[z80_low_reg(reg)]); |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
339 } |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
340 } else if (reg_usage[z80_high_reg(reg)]) { |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
341 cur = ld_ir8(cur, z80_high_reg(reg), reg_values[z80_high_reg(reg)]); |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
342 } |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
343 } else { |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
344 cur = ld_ir16(cur, reg, reg_values[reg]); |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
345 } |
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
|
346 } |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 } |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
348 |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
349 if (inst->op == Z80_JP && addr_mode == Z80_REG_INDIRECT) { |
618
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
350 uint16_t address = cur - prog + (inst->ea_reg == Z80_HL ? 3 : 4) + instlen + 1 + i; |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
351 cur = ld_ir16(cur, inst->ea_reg, address); |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
352 } |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
353 |
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
|
354 //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
|
355 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
|
356 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
|
357 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
|
358 } 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
|
359 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
|
360 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
|
361 } |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
362 |
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
|
363 //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
|
364 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
|
365 *(cur++) = inst->ea_reg; |
618
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
366 } else if ((inst->op == Z80_JP || inst->op == Z80_JPCC) && addr_mode == Z80_IMMED) { |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
367 uint16_t address = cur - prog + 3 + i; //2 for immed address, 1/2 for instruction(s) to skip |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
368 *(cur++) = address; |
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
369 *(cur++) = address >> 8; |
619
3072fb746601
Added support for JR and JRcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
618
diff
changeset
|
370 } else if(inst->op == Z80_JR || inst->op == Z80_JRCC) { |
3072fb746601
Added support for JR and JRcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
618
diff
changeset
|
371 *(cur++) = 1 + i; //skip one or 2 instructions based on value of i |
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
|
372 } 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
|
373 *(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
|
374 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
|
375 *(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
|
376 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
377 } 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
|
378 *(cur++) = inst->immed & 0xFF; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 *(cur++) = inst->immed >> 8; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
380 } |
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
|
381 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
|
382 *(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
|
383 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
384 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
|
385 *(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
|
386 } |
619
3072fb746601
Added support for JR and JRcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
618
diff
changeset
|
387 if (inst->op >= Z80_JP && inst->op <= Z80_JRCC) { |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
388 cur = inc_r(cur, counter_reg); |
618
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
389 if (i) { |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
390 //inc twice on second iteration so we can differentiate the two |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
391 cur = inc_r(cur, counter_reg); |
abc834e4a520
Added support for JPcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
617
diff
changeset
|
392 } |
617
33ff0171301b
Added support for JP in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
393 } |
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
|
394 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
|
395 //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
|
396 cur = push(cur, Z80_AF); |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
397 if (is_mem) { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
398 //Save memory location from frist run |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
399 cur = ld_mema(cur, address); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
400 cur = push(cur, Z80_AF); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
401 } |
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
|
402 } 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
|
403 //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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 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
|
415 } |
a09aa6d067fd
Have test generator test both flag register 0 case and flag register FF case
Mike Pavone <pavone@retrodev.com>
parents:
391
diff
changeset
|
416 } |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
417 if (is_mem) { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
418 //Pop memory location from frist run |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
419 for (int reg = Z80_BC; reg <= Z80_IY; reg++) { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
420 if (reg != Z80_AF && !reg_usage[reg]) { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
421 cur = pop(cur, reg); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
422 cur = push(cur, Z80_AF); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
423 cur = ld_mema(cur, address); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
424 cur = ld_rr8(cur, Z80_A, z80_low_reg(reg)); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
425 cur = pop(cur, Z80_AF); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
426 reg_usage[reg] = 1; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
427 reg_usage[z80_low_reg(reg)] = 1; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
428 break; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
429 } |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
430 } |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
431 } |
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
|
432 } |
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
|
433 } |
292
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 for (char * cur = disbuf; *cur != 0; cur++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 if (*cur == ',' || *cur == ' ') { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 *cur = '_'; |
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 } |
391
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
440 //save memory result |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
441 if (is_mem) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
442 if (reg_usage[Z80_A]) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
443 cur = push(cur, Z80_AF); |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
444 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
445 cur = ld_mema(cur, address); |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
446 if (reg_usage[Z80_A]) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
447 for (int reg = 0; reg < Z80_I; reg++) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
448 if (!reg_usage[reg]) { |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
449 cur = ld_rr8(cur, Z80_A, reg); |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
450 break; |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
451 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
452 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
453 cur = pop(cur, Z80_AF); |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
454 } |
3f4f2b7318a1
Check memory results in ztestgen
Mike Pavone <pavone@retrodev.com>
parents:
298
diff
changeset
|
455 } |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
456 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 //halt |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 *(cur++) = 0x76; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
459 sprintf(pathbuf + strlen(pathbuf), "/%s.bin", disbuf); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
460 FILE * progfile = fopen(pathbuf, "wb"); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 fwrite(prog, 1, cur - prog, progfile); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 fclose(progfile); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
463 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
464 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
465 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 uint8_t should_skip(z80inst * inst) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 { |
619
3072fb746601
Added support for JR and JRcc in Z80 test generator
Michael Pavone <pavone@retrodev.com>
parents:
618
diff
changeset
|
468 return inst->op >= Z80_DJNZ || (inst->op >= Z80_LDI && inst->op <= Z80_CPDR) || inst->op == Z80_HALT |
1042
a6c6b621d0dc
Implement Z80 DAA. Implement half-carry flag for the rest of the "easy" cases. Implement flags for IN instruction. Fix implementation of IN for IN F, (C) case
Michael Pavone <pavone@retrodev.com>
parents:
619
diff
changeset
|
469 || inst->op == Z80_RLD || inst->op == Z80_RRD || inst->op == Z80_NOP |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
470 || 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
|
471 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 void z80_gen_all() |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 uint8_t inst[3]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 for (int op = 0; op < 256; op++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 inst[0] = op; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 if (op == 0xCB) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 for (int subop = 0; subop < 256; subop++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 if (!should_skip(z80_tbl_bit + subop)) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 inst[1] = subop; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 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
|
483 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 } else if(op == 0xDD) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 for (int ixop = 0; ixop < 256; ixop++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 inst[1] = ixop; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 if (ixop == 0xCB) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 for (int subop = 0; subop < 256; subop++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 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
|
491 inst[2] = subop; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
492 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
|
493 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 if (!should_skip(z80_tbl_ix + ixop)) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 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
|
498 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 } else if(op == 0xED) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 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
|
503 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
|
504 inst[1] = subop + 0x40; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 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
|
506 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
508 } else if(op == 0xFD) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
509 for (int iyop = 0; iyop < 256; iyop++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
510 inst[1] = iyop; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 if (iyop == 0xCB) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
512 for (int subop = 0; subop < 256; subop++) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
513 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
|
514 inst[2] = subop; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 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
|
516 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
517 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
518 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
519 if (!should_skip(z80_tbl_iy + iyop)) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
520 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
|
521 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
523 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 } else { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
525 if (!should_skip(z80_tbl_a + op)) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 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
|
527 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
528 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
529 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
530 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 int main(int argc, char ** argv) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
533 { |
1746
cd6f4cea97b6
Call srand in Z80 test generator so different values are used when regenerating tests
Michael Pavone <pavone@retrodev.com>
parents:
1042
diff
changeset
|
534 srand(time(NULL)); |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
535 z80_gen_all(); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
536 return 0; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
537 } |