smolder_tests/gb/cpu_instrs/
test_10.rs

1use crate::{
2  crc::Crc,
3  gb::{mem::Mem, CpuReg8, CpuTestHarness},
4};
5
6pub fn bit_ops(cpu: &mut impl CpuTestHarness) {
7  let mut crc = Crc::default();
8  let mut mem = Mem::default();
9
10  for (expected, instr) in INSTRS {
11    for f in [0x00, 0xf0] {
12      for n in 0..VALUES.len() {
13        for m in 0..VALUES.len() {
14          cpu.set_reg_8(CpuReg8::A, VALUES[n]); // AF
15          cpu.set_reg_8(CpuReg8::F, f);
16          cpu.set_reg_8(CpuReg8::B, VALUES[(m + 0) % VALUES.len()]); // BC
17          cpu.set_reg_8(CpuReg8::C, VALUES[(m + 1) % VALUES.len()]);
18          cpu.set_reg_8(CpuReg8::D, VALUES[(m + 4) % VALUES.len()]); // DE
19          cpu.set_reg_8(CpuReg8::E, VALUES[(m + 5) % VALUES.len()]);
20          cpu.set_reg_8(CpuReg8::H, VALUES[(m + 2) % VALUES.len()]); // HL
21          cpu.set_reg_8(CpuReg8::L, VALUES[(m + 3) % VALUES.len()]);
22
23          cpu.execute(&mut mem, instr);
24
25          crc.add(cpu);
26        }
27      }
28    }
29
30    assert_eq!(expected, crc.take_val(), "instr={:?}", instr);
31  }
32}
33
34const VALUES: [u8; 10] = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xff];
35
36const INSTRS: [(u32, &'static [u8]); 168] = [
37  (0x164a5146, &[0xcb, 0x40]), // bit  0,b
38  (0x4eb218d4, &[0xcb, 0x41]), // bit  0,c
39  (0xea15b5ed, &[0xcb, 0x42]), // bit  0,d
40  (0x3e666674, &[0xcb, 0x43]), // bit  0,e
41  (0x6a7ff3c2, &[0xcb, 0x44]), // bit  0,h
42  (0x2162ca63, &[0xcb, 0x45]), // bit  0,l
43  (0x83e41e72, &[0xcb, 0x47]), // bit  0,a
44  (0x1d41566a, &[0xcb, 0x48]), // bit  1,b
45  (0x38db9091, &[0xcb, 0x49]), // bit  1,c
46  (0x246c0a54, &[0xcb, 0x4a]), // bit  1,d
47  (0x5bea9e02, &[0xcb, 0x4b]), // bit  1,e
48  (0x80cba76d, &[0xcb, 0x4c]), // bit  1,h
49  (0x0ff30bb4, &[0xcb, 0x4d]), // bit  1,l
50  (0xbb753840, &[0xcb, 0x4f]), // bit  1,a
51  (0xe52b30af, &[0xcb, 0x50]), // bit  2,b
52  (0x33d097bd, &[0xcb, 0x51]), // bit  2,c
53  (0x0afdcb83, &[0xcb, 0x52]), // bit  2,d
54  (0x959321bb, &[0xcb, 0x53]), // bit  2,e
55  (0xf6a22f28, &[0xcb, 0x54]), // bit  2,h
56  (0xe5475f1b, &[0xcb, 0x55]), // bit  2,l
57  (0x63392ea3, &[0xcb, 0x57]), // bit  2,a
58  (0xbb02e06c, &[0xcb, 0x58]), // bit  3,b
59  (0xcbbaf178, &[0xcb, 0x59]), // bit  3,c
60  (0xe0499f2c, &[0xcb, 0x5a]), // bit  3,d
61  (0xbb02e06c, &[0xcb, 0x5b]), // bit  3,e
62  (0xfda92804, &[0xcb, 0x5c]), // bit  3,h
63  (0x932ed75e, &[0xcb, 0x5d]), // bit  3,l
64  (0x0008781b, &[0xcb, 0x5f]), // bit  3,a
65  (0x0afdcb83, &[0xcb, 0x60]), // bit  4,b
66  (0x959321bb, &[0xcb, 0x61]), // bit  4,c
67  (0x96201769, &[0xcb, 0x62]), // bit  4,d
68  (0x51b6b4c3, &[0xcb, 0x63]), // bit  4,e
69  (0x05c34ec1, &[0xcb, 0x64]), // bit  4,h
70  (0x9825d072, &[0xcb, 0x65]), // bit  4,l
71  (0xb799f044, &[0xcb, 0x67]), // bit  4,a
72  (0x0ff30bb4, &[0xcb, 0x68]), // bit  5,b
73  (0x246c0a54, &[0xcb, 0x69]), // bit  5,c
74  (0x9d2b1045, &[0xcb, 0x6a]), // bit  5,d
75  (0x27df3c86, &[0xcb, 0x6b]), // bit  5,e
76  (0x5bea9e02, &[0xcb, 0x6c]), // bit  5,h
77  (0x604fb6b7, &[0xcb, 0x6d]), // bit  5,l
78  (0xaae1e070, &[0xcb, 0x6f]), // bit  5,a
79  (0x6a7ff3c2, &[0xcb, 0x70]), // bit  6,b
80  (0x2162ca63, &[0xcb, 0x71]), // bit  6,c
81  (0x65417680, &[0xcb, 0x72]), // bit  6,d
82  (0x2cd43baa, &[0xcb, 0x73]), // bit  6,e
83  (0xea15b5ed, &[0xcb, 0x74]), // bit  6,h
84  (0x3e666674, &[0xcb, 0x75]), // bit  6,l
85  (0x43a0ffad, &[0xcb, 0x77]), // bit  6,a
86  (0xa4064c7b, &[0xcb, 0x78]), // bit  7,b
87  (0x44ee3215, &[0xcb, 0x79]), // bit  7,c
88  (0x3b68a643, &[0xcb, 0x7a]), // bit  7,d
89  (0xd4be5d6f, &[0xcb, 0x7b]), // bit  7,e
90  (0xef1b75da, &[0xcb, 0x7c]), // bit  7,h
91  (0x8f994d9b, &[0xcb, 0x7d]), // bit  7,l
92  (0x1da9e849, &[0xcb, 0x7f]), // bit  7,a
93  (0x3a581bf5, &[0xcb, 0x80]), // res  0,b
94  (0x512d2592, &[0xcb, 0x81]), // res  0,c
95  (0x05625c38, &[0xcb, 0x82]), // res  0,d
96  (0xad63a9dd, &[0xcb, 0x83]), // res  0,e
97  (0x372f78e3, &[0xcb, 0x84]), // res  0,h
98  (0x62db1590, &[0xcb, 0x85]), // res  0,l
99  (0x35e8e258, &[0xcb, 0x87]), // res  0,a
100  (0xea5ac1bb, &[0xcb, 0x88]), // res  1,b
101  (0xaa28fe06, &[0xcb, 0x89]), // res  1,c
102  (0xbf645d4f, &[0xcb, 0x8a]), // res  1,d
103  (0xb27fcf83, &[0xcb, 0x8b]), // res  1,e
104  (0xbf90a9f9, &[0xcb, 0x8c]), // res  1,h
105  (0x64b606dd, &[0xcb, 0x8d]), // res  1,l
106  (0x24e08a25, &[0xcb, 0x8f]), // res  1,a
107  (0x139540fa, &[0xcb, 0x90]), // res  2,b
108  (0x0d936191, &[0xcb, 0x91]), // res  2,c
109  (0x0b0ea869, &[0xcb, 0x92]), // res  2,d
110  (0x1adffdae, &[0xcb, 0x93]), // res  2,e
111  (0x11d898d4, &[0xcb, 0x94]), // res  2,h
112  (0x6616e961, &[0xcb, 0x95]), // res  2,l
113  (0x2c1f82bd, &[0xcb, 0x97]), // res  2,a
114  (0x772674e2, &[0xcb, 0x98]), // res  3,b
115  (0x256ae413, &[0xcb, 0x99]), // res  3,c
116  (0x4f8aded7, &[0xcb, 0x9a]), // res  3,d
117  (0xbc477b1f, &[0xcb, 0x9b]), // res  3,e
118  (0xe731dbda, &[0xcb, 0x9c]), // res  3,h
119  (0x392c062b, &[0xcb, 0x9d]), // res  3,l
120  (0x0b1cfc15, &[0xcb, 0x9f]), // res  3,a
121  (0x0fa03b1a, &[0xcb, 0xa0]), // res  4,b
122  (0x1cd8e555, &[0xcb, 0xa1]), // res  4,c
123  (0xb87f6c6d, &[0xcb, 0xa2]), // res  4,d
124  (0xaf9cad14, &[0xcb, 0xa3]), // res  4,e
125  (0x4060b692, &[0xcb, 0xa4]), // res  4,h
126  (0x2f6de676, &[0xcb, 0xa5]), // res  4,l
127  (0x6d45ca9e, &[0xcb, 0xa7]), // res  4,a
128  (0x35479754, &[0xcb, 0xa8]), // res  5,b
129  (0x635039ee, &[0xcb, 0xa9]), // res  5,c
130  (0xab8a8c47, &[0xcb, 0xaa]), // res  5,d
131  (0x106df718, &[0xcb, 0xab]), // res  5,e
132  (0x0c74a6b7, &[0xcb, 0xac]), // res  5,h
133  (0xf59c2411, &[0xcb, 0xad]), // res  5,l
134  (0x16fb5d64, &[0xcb, 0xaf]), // res  5,a
135  (0xc6591c65, &[0xcb, 0xb0]), // res  6,b
136  (0x5230e3b9, &[0xcb, 0xb1]), // res  6,c
137  (0x9eb8e41d, &[0xcb, 0xb2]), // res  6,d
138  (0x6f7b2fa3, &[0xcb, 0xb3]), // res  6,e
139  (0x41242003, &[0xcb, 0xb4]), // res  6,h
140  (0xb822f74c, &[0xcb, 0xb5]), // res  6,l
141  (0xe375a792, &[0xcb, 0xb7]), // res  6,a
142  (0xfd5ef21d, &[0xcb, 0xb8]), // res  7,b
143  (0x34f3a4b7, &[0xcb, 0xb9]), // res  7,c
144  (0xca37f7bf, &[0xcb, 0xba]), // res  7,d
145  (0x4dd42267, &[0xcb, 0xbb]), // res  7,e
146  (0x58991ade, &[0xcb, 0xbc]), // res  7,h
147  (0x129165b2, &[0xcb, 0xbd]), // res  7,l
148  (0x08658cf2, &[0xcb, 0xbf]), // res  7,a
149  (0xd39be269, &[0xcb, 0xc0]), // set  0,b
150  (0xf1718c94, &[0xcb, 0xc1]), // set  0,c
151  (0x532922d8, &[0xcb, 0xc2]), // set  0,d
152  (0x55d96ae8, &[0xcb, 0xc3]), // set  0,e
153  (0xef42243e, &[0xcb, 0xc4]), // set  0,h
154  (0x02ac1238, &[0xcb, 0xc5]), // set  0,l
155  (0x2c7d8435, &[0xcb, 0xc7]), // set  0,a
156  (0xe2ac34c2, &[0xcb, 0xc8]), // set  1,b
157  (0x31e0aa4b, &[0xcb, 0xc9]), // set  1,c
158  (0x13f2a08f, &[0xcb, 0xca]), // set  1,d
159  (0x987b4fa8, &[0xcb, 0xcb]), // set  1,e
160  (0xd43b1602, &[0xcb, 0xcc]), // set  1,h
161  (0xa458098d, &[0xcb, 0xcd]), // set  1,l
162  (0x17ca46ff, &[0xcb, 0xcf]), // set  1,a
163  (0x0278aa08, &[0xcb, 0xd0]), // set  2,b
164  (0xe172cf4a, &[0xcb, 0xd1]), // set  2,c
165  (0x895255a8, &[0xcb, 0xd2]), // set  2,d
166  (0x4ed6fdf8, &[0xcb, 0xd3]), // set  2,e
167  (0xc68fe722, &[0xcb, 0xd4]), // set  2,h
168  (0x3cbbf180, &[0xcb, 0xd5]), // set  2,l
169  (0x4a4a1b09, &[0xcb, 0xd7]), // set  2,a
170  (0x54fda106, &[0xcb, 0xd8]), // set  3,b
171  (0x27d8bfe4, &[0xcb, 0xd9]), // set  3,c
172  (0x90422314, &[0xcb, 0xda]), // set  3,d
173  (0x14557bb3, &[0xcb, 0xdb]), // set  3,e
174  (0x92ee2277, &[0xcb, 0xdc]), // set  3,h
175  (0x8c7637e9, &[0xcb, 0xdd]), // set  3,l
176  (0xc7b7cf7d, &[0xcb, 0xdf]), // set  3,a
177  (0x481790d2, &[0xcb, 0xe0]), // set  4,b
178  (0x19bc52bb, &[0xcb, 0xe1]), // set  4,c
179  (0xdc9f91aa, &[0xcb, 0xe2]), // set  4,d
180  (0x24c9aa0d, &[0xcb, 0xe3]), // set  4,e
181  (0xabdf45c8, &[0xcb, 0xe4]), // set  4,h
182  (0x9ea883b3, &[0xcb, 0xe5]), // set  4,l
183  (0x2f62aa0f, &[0xcb, 0xe7]), // set  4,a
184  (0xba28c0c4, &[0xcb, 0xe8]), // set  5,b
185  (0x69995632, &[0xcb, 0xe9]), // set  5,c
186  (0x624b77c9, &[0xcb, 0xea]), // set  5,d
187  (0xddb6ff6b, &[0xcb, 0xeb]), // set  5,e
188  (0x007a4642, &[0xcb, 0xec]), // set  5,h
189  (0x4d67e9da, &[0xcb, 0xed]), // set  5,l
190  (0x92b59c46, &[0xcb, 0xef]), // set  5,a
191  (0x03f6b504, &[0xcb, 0xf0]), // set  6,b
192  (0x47a23c01, &[0xcb, 0xf1]), // set  6,c
193  (0xd64a1540, &[0xcb, 0xf2]), // set  6,d
194  (0x2fbc3904, &[0xcb, 0xf3]), // set  6,e
195  (0x5939e1e9, &[0xcb, 0xf4]), // set  6,h
196  (0x12a46a9b, &[0xcb, 0xf5]), // set  6,l
197  (0x30992397, &[0xcb, 0xf7]), // set  6,a
198  (0xad70a69e, &[0xcb, 0xf8]), // set  7,b
199  (0x1fd61bc7, &[0xcb, 0xf9]), // set  7,c
200  (0x5bd21505, &[0xcb, 0xfa]), // set  7,d
201  (0xcc5a0f29, &[0xcb, 0xfb]), // set  7,e
202  (0x68a2990a, &[0xcb, 0xfc]), // set  7,h
203  (0x9ced585d, &[0xcb, 0xfd]), // set  7,l
204  (0x74cd82b9, &[0xcb, 0xff]), // set  7,a
205];