src/gba/test/cheats.c (view raw)
1/* Copyright (c) 2013-2017 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "util/test/suite.h"
7
8#include <mgba/core/cheats.h>
9#include <mgba/core/core.h>
10#include <mgba/gba/core.h>
11#include <mgba/internal/gba/cheats.h>
12
13#include "gba/cheats/parv3.h"
14#include "gba/cheats/gameshark.h"
15
16static int cheatsSetup(void** state) {
17 struct mCore* core = GBACoreCreate();
18 core->init(core);
19 mCoreInitConfig(core, NULL);
20 core->cheatDevice(core);
21 *state = core;
22 return 0;
23}
24
25static int cheatsTeardown(void** state) {
26 if (!*state) {
27 return 0;
28 }
29 struct mCore* core = *state;
30 mCoreConfigDeinit(&core->config);
31 core->deinit(core);
32 return 0;
33}
34
35M_TEST_DEFINE(createSet) {
36 struct mCore* core = *state;
37 struct mCheatDevice* device = core->cheatDevice(core);
38 assert_non_null(device);
39 struct mCheatSet* set = device->createSet(device, NULL);
40 assert_non_null(set);
41 mCheatSetDeinit(set);
42}
43
44M_TEST_DEFINE(addRawPARv3) {
45 struct mCore* core = *state;
46 struct mCheatDevice* device = core->cheatDevice(core);
47 assert_non_null(device);
48 struct mCheatSet* set = device->createSet(device, NULL);
49 assert_non_null(set);
50 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
51 assert_true(set->addLine(set, "80000000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
52 assert_false(set->addLine(set, "43000000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
53 mCheatSetDeinit(set);
54}
55
56M_TEST_DEFINE(doPARv3Assign) {
57 struct mCore* core = *state;
58 struct mCheatDevice* device = core->cheatDevice(core);
59 assert_non_null(device);
60 struct mCheatSet* set = device->createSet(device, NULL);
61 assert_non_null(set);
62 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
63 assert_true(set->addLine(set, "00300000 00000078", GBA_CHEAT_PRO_ACTION_REPLAY));
64 assert_true(set->addLine(set, "02300002 00005678", GBA_CHEAT_PRO_ACTION_REPLAY));
65 assert_true(set->addLine(set, "04300004 12345678", GBA_CHEAT_PRO_ACTION_REPLAY));
66
67 core->reset(core);
68 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
69 assert_int_equal(core->rawRead16(core, 0x03000002, -1), 0);
70 assert_int_equal(core->rawRead32(core, 0x03000004, -1), 0);
71
72 mCheatRefresh(device, set);
73 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x78);
74 assert_int_equal(core->rawRead16(core, 0x03000002, -1), 0x5678);
75 assert_int_equal(core->rawRead32(core, 0x03000004, -1), 0x12345678);
76
77 mCheatSetDeinit(set);
78}
79
80M_TEST_DEFINE(doPARv3Slide1) {
81 struct mCore* core = *state;
82 struct mCheatDevice* device = core->cheatDevice(core);
83 assert_non_null(device);
84 struct mCheatSet* set = device->createSet(device, NULL);
85 assert_non_null(set);
86 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
87 assert_true(set->addLine(set, "00000000 80300000", GBA_CHEAT_PRO_ACTION_REPLAY));
88 assert_true(set->addLine(set, "00000001 01020002", GBA_CHEAT_PRO_ACTION_REPLAY));
89
90 core->reset(core);
91 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
92 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
93 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
94 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
95 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0);
96 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0);
97
98 mCheatRefresh(device, set);
99 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 1);
100 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
101 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 2);
102 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
103 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0);
104 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0);
105
106 mCheatSetDeinit(set);
107}
108
109M_TEST_DEFINE(doPARv3Slide2) {
110 struct mCore* core = *state;
111 struct mCheatDevice* device = core->cheatDevice(core);
112 assert_non_null(device);
113 struct mCheatSet* set = device->createSet(device, NULL);
114 assert_non_null(set);
115 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
116 assert_true(set->addLine(set, "00000000 82300000", GBA_CHEAT_PRO_ACTION_REPLAY));
117 assert_true(set->addLine(set, "00000001 01020002", GBA_CHEAT_PRO_ACTION_REPLAY));
118
119 core->reset(core);
120 assert_int_equal(core->rawRead16(core, 0x03000000, -1), 0);
121 assert_int_equal(core->rawRead16(core, 0x03000002, -1), 0);
122 assert_int_equal(core->rawRead16(core, 0x03000004, -1), 0);
123 assert_int_equal(core->rawRead16(core, 0x03000006, -1), 0);
124 assert_int_equal(core->rawRead16(core, 0x03000008, -1), 0);
125 assert_int_equal(core->rawRead16(core, 0x0300000A, -1), 0);
126
127 mCheatRefresh(device, set);
128 assert_int_equal(core->rawRead16(core, 0x03000000, -1), 1);
129 assert_int_equal(core->rawRead16(core, 0x03000002, -1), 0);
130 assert_int_equal(core->rawRead16(core, 0x03000004, -1), 2);
131 assert_int_equal(core->rawRead16(core, 0x03000006, -1), 0);
132 assert_int_equal(core->rawRead16(core, 0x03000008, -1), 0);
133 assert_int_equal(core->rawRead16(core, 0x0300000A, -1), 0);
134
135 mCheatSetDeinit(set);
136}
137
138M_TEST_DEFINE(doPARv3Slide4) {
139 struct mCore* core = *state;
140 struct mCheatDevice* device = core->cheatDevice(core);
141 assert_non_null(device);
142 struct mCheatSet* set = device->createSet(device, NULL);
143 assert_non_null(set);
144 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
145 assert_true(set->addLine(set, "00000000 84300000", GBA_CHEAT_PRO_ACTION_REPLAY));
146 assert_true(set->addLine(set, "00000001 01020002", GBA_CHEAT_PRO_ACTION_REPLAY));
147
148 core->reset(core);
149 assert_int_equal(core->rawRead32(core, 0x03000000, -1), 0);
150 assert_int_equal(core->rawRead32(core, 0x03000004, -1), 0);
151 assert_int_equal(core->rawRead32(core, 0x03000008, -1), 0);
152 assert_int_equal(core->rawRead32(core, 0x0300000C, -1), 0);
153 assert_int_equal(core->rawRead32(core, 0x03000010, -1), 0);
154 assert_int_equal(core->rawRead32(core, 0x03000014, -1), 0);
155
156 mCheatRefresh(device, set);
157 assert_int_equal(core->rawRead16(core, 0x03000000, -1), 1);
158 assert_int_equal(core->rawRead16(core, 0x03000004, -1), 0);
159 assert_int_equal(core->rawRead16(core, 0x03000008, -1), 2);
160 assert_int_equal(core->rawRead16(core, 0x0300000C, -1), 0);
161 assert_int_equal(core->rawRead16(core, 0x03000010, -1), 0);
162 assert_int_equal(core->rawRead16(core, 0x03000014, -1), 0);
163
164 mCheatSetDeinit(set);
165}
166
167M_TEST_DEFINE(doPARv3If1) {
168 struct mCore* core = *state;
169 struct mCheatDevice* device = core->cheatDevice(core);
170 assert_non_null(device);
171 struct mCheatSet* set = device->createSet(device, NULL);
172 assert_non_null(set);
173 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
174 assert_true(set->addLine(set, "00300001 00000011", GBA_CHEAT_PRO_ACTION_REPLAY));
175 assert_true(set->addLine(set, "08300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
176 assert_true(set->addLine(set, "00300001 00000012", GBA_CHEAT_PRO_ACTION_REPLAY));
177 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
178
179 core->reset(core);
180 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
181 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
182
183 mCheatRefresh(device, set);
184 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
185 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x12);
186
187 core->reset(core);
188 core->rawWrite8(core, 0x03000000, -1, 0x1);
189 mCheatRefresh(device, set);
190 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
191 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x11);
192
193 mCheatSetDeinit(set);
194}
195
196M_TEST_DEFINE(doPARv3If1x1) {
197 struct mCore* core = *state;
198 struct mCheatDevice* device = core->cheatDevice(core);
199 assert_non_null(device);
200 struct mCheatSet* set = device->createSet(device, NULL);
201 assert_non_null(set);
202 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
203 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
204 assert_true(set->addLine(set, "00300003 00000031", GBA_CHEAT_PRO_ACTION_REPLAY));
205 assert_true(set->addLine(set, "08300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
206 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
207 assert_true(set->addLine(set, "08300001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
208 assert_true(set->addLine(set, "00300003 00000032", GBA_CHEAT_PRO_ACTION_REPLAY));
209 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
210
211 core->reset(core);
212 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
213 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
214 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
215 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
216
217 mCheatRefresh(device, set);
218 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
219 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
220 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
221 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
222
223 core->reset(core);
224 core->rawWrite8(core, 0x03000000, -1, 0x1);
225 mCheatRefresh(device, set);
226 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
227 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
228 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
229 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
230
231 core->reset(core);
232 core->rawWrite8(core, 0x03000001, -1, 0x1);
233 mCheatRefresh(device, set);
234 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
235 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
236 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
237 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
238
239 core->reset(core);
240 core->rawWrite8(core, 0x03000000, -1, 0x1);
241 core->rawWrite8(core, 0x03000001, -1, 0x1);
242 mCheatRefresh(device, set);
243 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
244 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
245 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
246 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
247
248 mCheatSetDeinit(set);
249}
250
251M_TEST_DEFINE(doPARv3If2) {
252 struct mCore* core = *state;
253 struct mCheatDevice* device = core->cheatDevice(core);
254 assert_non_null(device);
255 struct mCheatSet* set = device->createSet(device, NULL);
256 assert_non_null(set);
257 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
258 assert_true(set->addLine(set, "00300001 00000011", GBA_CHEAT_PRO_ACTION_REPLAY));
259 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
260 assert_true(set->addLine(set, "48300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
261 assert_true(set->addLine(set, "00300001 00000012", GBA_CHEAT_PRO_ACTION_REPLAY));
262 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
263 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
264
265 core->reset(core);
266 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
267 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
268 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
269
270 mCheatRefresh(device, set);
271 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
272 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x12);
273 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
274
275 core->reset(core);
276 core->rawWrite8(core, 0x03000000, -1, 0x1);
277 mCheatRefresh(device, set);
278 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
279 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x11);
280 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
281
282 mCheatSetDeinit(set);
283}
284
285M_TEST_DEFINE(doPARv3If2x2) {
286 struct mCore* core = *state;
287 struct mCheatDevice* device = core->cheatDevice(core);
288 assert_non_null(device);
289 struct mCheatSet* set = device->createSet(device, NULL);
290 assert_non_null(set);
291 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
292 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
293 assert_true(set->addLine(set, "00300003 00000031", GBA_CHEAT_PRO_ACTION_REPLAY));
294 assert_true(set->addLine(set, "00300004 00000041", GBA_CHEAT_PRO_ACTION_REPLAY));
295 assert_true(set->addLine(set, "00300005 00000051", GBA_CHEAT_PRO_ACTION_REPLAY));
296 assert_true(set->addLine(set, "48300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
297 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
298 assert_true(set->addLine(set, "00300003 00000032", GBA_CHEAT_PRO_ACTION_REPLAY));
299 assert_true(set->addLine(set, "48300001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
300 assert_true(set->addLine(set, "00300004 00000042", GBA_CHEAT_PRO_ACTION_REPLAY));
301 assert_true(set->addLine(set, "00300005 00000052", GBA_CHEAT_PRO_ACTION_REPLAY));
302 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
303
304 core->reset(core);
305 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
306 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
307 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
308 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
309 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0);
310 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0);
311
312 mCheatRefresh(device, set);
313 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
314 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
315 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
316 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
317 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
318 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
319
320 core->reset(core);
321 core->rawWrite8(core, 0x03000000, -1, 0x1);
322 mCheatRefresh(device, set);
323 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
324 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
325 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
326 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
327 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
328 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
329
330 core->reset(core);
331 core->rawWrite8(core, 0x03000001, -1, 0x1);
332 mCheatRefresh(device, set);
333 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
334 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
335 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
336 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
337 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
338 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
339
340 core->reset(core);
341 core->rawWrite8(core, 0x03000000, -1, 0x1);
342 core->rawWrite8(core, 0x03000001, -1, 0x1);
343 mCheatRefresh(device, set);
344 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
345 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
346 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
347 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
348 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
349 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
350 mCheatSetDeinit(set);
351}
352
353M_TEST_DEFINE(doPARv3If2Contain1) {
354 struct mCore* core = *state;
355 struct mCheatDevice* device = core->cheatDevice(core);
356 assert_non_null(device);
357 struct mCheatSet* set = device->createSet(device, NULL);
358 assert_non_null(set);
359 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
360 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
361 assert_true(set->addLine(set, "48300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
362 assert_true(set->addLine(set, "08300001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
363 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
364 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
365
366 core->reset(core);
367 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
368 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
369 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
370
371 mCheatRefresh(device, set);
372 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
373 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
374 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
375
376 core->reset(core);
377 core->rawWrite8(core, 0x03000000, -1, 0x1);
378 mCheatRefresh(device, set);
379 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
380 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
381 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
382
383 core->reset(core);
384 core->rawWrite8(core, 0x03000001, -1, 0x1);
385 mCheatRefresh(device, set);
386 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
387 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
388 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
389
390 core->reset(core);
391 core->rawWrite8(core, 0x03000000, -1, 0x1);
392 core->rawWrite8(core, 0x03000001, -1, 0x1);
393 mCheatRefresh(device, set);
394 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
395 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
396 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
397 mCheatSetDeinit(set);
398}
399
400M_TEST_DEFINE(doPARv3IfX) {
401 struct mCore* core = *state;
402 struct mCheatDevice* device = core->cheatDevice(core);
403 assert_non_null(device);
404 struct mCheatSet* set = device->createSet(device, NULL);
405 assert_non_null(set);
406 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
407 assert_true(set->addLine(set, "00300001 00000011", GBA_CHEAT_PRO_ACTION_REPLAY));
408 assert_true(set->addLine(set, "88300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
409 assert_true(set->addLine(set, "00300001 00000012", GBA_CHEAT_PRO_ACTION_REPLAY));
410 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
411 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
412
413 core->reset(core);
414 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
415 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
416
417 mCheatRefresh(device, set);
418 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
419 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x12);
420
421 core->reset(core);
422 core->rawWrite8(core, 0x03000000, -1, 0x1);
423 mCheatRefresh(device, set);
424 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
425 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x11);
426 mCheatSetDeinit(set);
427}
428
429M_TEST_DEFINE(doPARv3IfXxX) {
430 struct mCore* core = *state;
431 struct mCheatDevice* device = core->cheatDevice(core);
432 assert_non_null(device);
433 struct mCheatSet* set = device->createSet(device, NULL);
434 assert_non_null(set);
435 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
436 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
437 assert_true(set->addLine(set, "00300003 00000031", GBA_CHEAT_PRO_ACTION_REPLAY));
438 assert_true(set->addLine(set, "00300004 00000041", GBA_CHEAT_PRO_ACTION_REPLAY));
439 assert_true(set->addLine(set, "88300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
440 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
441 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
442 assert_true(set->addLine(set, "00300003 00000032", GBA_CHEAT_PRO_ACTION_REPLAY));
443 assert_true(set->addLine(set, "88300001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
444 assert_true(set->addLine(set, "00300004 00000042", GBA_CHEAT_PRO_ACTION_REPLAY));
445 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
446 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
447
448 core->reset(core);
449 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
450 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
451 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
452 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
453 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0);
454
455 mCheatRefresh(device, set);
456 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
457 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
458 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
459 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
460 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
461
462 core->reset(core);
463 core->rawWrite8(core, 0x03000000, -1, 0x1);
464 mCheatRefresh(device, set);
465 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
466 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
467 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
468 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
469 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
470
471 core->reset(core);
472 core->rawWrite8(core, 0x03000001, -1, 0x1);
473 mCheatRefresh(device, set);
474 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
475 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
476 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
477 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
478 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
479
480 core->reset(core);
481 core->rawWrite8(core, 0x03000000, -1, 0x1);
482 core->rawWrite8(core, 0x03000001, -1, 0x1);
483 mCheatRefresh(device, set);
484 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
485 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
486 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
487 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
488 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
489 mCheatSetDeinit(set);
490}
491
492M_TEST_DEFINE(doPARv3IfXElse) {
493 struct mCore* core = *state;
494 struct mCheatDevice* device = core->cheatDevice(core);
495 assert_non_null(device);
496 struct mCheatSet* set = device->createSet(device, NULL);
497 assert_non_null(set);
498 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
499 assert_true(set->addLine(set, "00300001 00000011", GBA_CHEAT_PRO_ACTION_REPLAY));
500 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
501 assert_true(set->addLine(set, "88300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
502 assert_true(set->addLine(set, "00300001 00000012", GBA_CHEAT_PRO_ACTION_REPLAY));
503 assert_true(set->addLine(set, "00000000 60000000", GBA_CHEAT_PRO_ACTION_REPLAY));
504 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
505 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
506 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
507
508 core->reset(core);
509 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
510 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
511 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
512
513 mCheatRefresh(device, set);
514 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
515 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x12);
516 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
517
518 core->reset(core);
519 core->rawWrite8(core, 0x03000000, -1, 0x1);
520 mCheatRefresh(device, set);
521 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
522 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x11);
523 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
524 mCheatSetDeinit(set);
525}
526
527M_TEST_DEFINE(doPARv3IfXElsexX) {
528 struct mCore* core = *state;
529 struct mCheatDevice* device = core->cheatDevice(core);
530 assert_non_null(device);
531 struct mCheatSet* set = device->createSet(device, NULL);
532 assert_non_null(set);
533 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
534 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
535 assert_true(set->addLine(set, "00300003 00000031", GBA_CHEAT_PRO_ACTION_REPLAY));
536 assert_true(set->addLine(set, "00300004 00000041", GBA_CHEAT_PRO_ACTION_REPLAY));
537 assert_true(set->addLine(set, "00300005 00000051", GBA_CHEAT_PRO_ACTION_REPLAY));
538 assert_true(set->addLine(set, "88300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
539 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
540 assert_true(set->addLine(set, "00000000 60000000", GBA_CHEAT_PRO_ACTION_REPLAY));
541 assert_true(set->addLine(set, "00300003 00000032", GBA_CHEAT_PRO_ACTION_REPLAY));
542 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
543 assert_true(set->addLine(set, "00300004 00000042", GBA_CHEAT_PRO_ACTION_REPLAY));
544 assert_true(set->addLine(set, "88300001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
545 assert_true(set->addLine(set, "00300005 00000052", GBA_CHEAT_PRO_ACTION_REPLAY));
546 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
547 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
548
549 core->reset(core);
550 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
551 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
552 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
553 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
554 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0);
555 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0);
556
557 mCheatRefresh(device, set);
558 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
559 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
560 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
561 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
562 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
563 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
564
565 core->reset(core);
566 core->rawWrite8(core, 0x03000000, -1, 0x1);
567 mCheatRefresh(device, set);
568 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
569 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
570 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
571 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
572 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
573 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
574
575 core->reset(core);
576 core->rawWrite8(core, 0x03000001, -1, 0x1);
577 mCheatRefresh(device, set);
578 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
579 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
580 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
581 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
582 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
583 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
584
585 core->reset(core);
586 core->rawWrite8(core, 0x03000000, -1, 0x1);
587 core->rawWrite8(core, 0x03000001, -1, 0x1);
588 mCheatRefresh(device, set);
589 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
590 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
591 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
592 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
593 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
594 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
595 mCheatSetDeinit(set);
596}
597
598M_TEST_DEFINE(doPARv3IfXElsexXElse) {
599 struct mCore* core = *state;
600 struct mCheatDevice* device = core->cheatDevice(core);
601 assert_non_null(device);
602 struct mCheatSet* set = device->createSet(device, NULL);
603 assert_non_null(set);
604 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
605 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
606 assert_true(set->addLine(set, "00300003 00000031", GBA_CHEAT_PRO_ACTION_REPLAY));
607 assert_true(set->addLine(set, "00300004 00000041", GBA_CHEAT_PRO_ACTION_REPLAY));
608 assert_true(set->addLine(set, "00300005 00000051", GBA_CHEAT_PRO_ACTION_REPLAY));
609 assert_true(set->addLine(set, "00300006 00000061", GBA_CHEAT_PRO_ACTION_REPLAY));
610 assert_true(set->addLine(set, "88300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
611 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
612 assert_true(set->addLine(set, "00000000 60000000", GBA_CHEAT_PRO_ACTION_REPLAY));
613 assert_true(set->addLine(set, "00300003 00000032", GBA_CHEAT_PRO_ACTION_REPLAY));
614 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
615 assert_true(set->addLine(set, "00300004 00000042", GBA_CHEAT_PRO_ACTION_REPLAY));
616 assert_true(set->addLine(set, "88300001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
617 assert_true(set->addLine(set, "00300005 00000052", GBA_CHEAT_PRO_ACTION_REPLAY));
618 assert_true(set->addLine(set, "00000000 60000000", GBA_CHEAT_PRO_ACTION_REPLAY));
619 assert_true(set->addLine(set, "00300006 00000062", GBA_CHEAT_PRO_ACTION_REPLAY));
620 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
621 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
622
623 core->reset(core);
624 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
625 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
626 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
627 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
628 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0);
629 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0);
630 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0);
631
632 mCheatRefresh(device, set);
633 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
634 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
635 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
636 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
637 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
638 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
639
640 core->reset(core);
641 core->rawWrite8(core, 0x03000000, -1, 0x1);
642 mCheatRefresh(device, set);
643 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
644 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
645 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
646 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
647 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
648 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
649 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x61);
650
651 core->reset(core);
652 core->rawWrite8(core, 0x03000001, -1, 0x1);
653 mCheatRefresh(device, set);
654 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
655 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
656 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
657 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
658 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
659 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
660 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x62);
661
662 core->reset(core);
663 core->rawWrite8(core, 0x03000000, -1, 0x1);
664 core->rawWrite8(core, 0x03000001, -1, 0x1);
665 mCheatRefresh(device, set);
666 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
667 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
668 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
669 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
670 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
671 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
672 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x62);
673 mCheatSetDeinit(set);
674}
675
676M_TEST_DEFINE(doPARv3IfXContain1) {
677 struct mCore* core = *state;
678 struct mCheatDevice* device = core->cheatDevice(core);
679 assert_non_null(device);
680 struct mCheatSet* set = device->createSet(device, NULL);
681 assert_non_null(set);
682 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
683 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
684 assert_true(set->addLine(set, "00300003 00000031", GBA_CHEAT_PRO_ACTION_REPLAY));
685 assert_true(set->addLine(set, "00300004 00000041", GBA_CHEAT_PRO_ACTION_REPLAY));
686 assert_true(set->addLine(set, "88300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
687 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
688 assert_true(set->addLine(set, "08300001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
689 assert_true(set->addLine(set, "00300003 00000032", GBA_CHEAT_PRO_ACTION_REPLAY));
690 assert_true(set->addLine(set, "00300004 00000042", GBA_CHEAT_PRO_ACTION_REPLAY));
691 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
692 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
693
694 core->reset(core);
695 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
696 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
697 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
698 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
699 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0);
700
701 mCheatRefresh(device, set);
702 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
703 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
704 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
705 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
706 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
707
708 core->reset(core);
709 core->rawWrite8(core, 0x03000000, -1, 0x1);
710 mCheatRefresh(device, set);
711 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
712 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
713 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
714 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
715 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
716
717 core->reset(core);
718 core->rawWrite8(core, 0x03000001, -1, 0x1);
719 mCheatRefresh(device, set);
720 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
721 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
722 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
723 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
724 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
725
726 core->reset(core);
727 core->rawWrite8(core, 0x03000000, -1, 0x1);
728 core->rawWrite8(core, 0x03000001, -1, 0x1);
729 mCheatRefresh(device, set);
730 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
731 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
732 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
733 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
734 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
735 mCheatSetDeinit(set);
736}
737
738M_TEST_DEFINE(doPARv3IfXContain1Else) {
739 struct mCore* core = *state;
740 struct mCheatDevice* device = core->cheatDevice(core);
741 assert_non_null(device);
742 struct mCheatSet* set = device->createSet(device, NULL);
743 assert_non_null(set);
744 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
745 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
746 assert_true(set->addLine(set, "00300003 00000031", GBA_CHEAT_PRO_ACTION_REPLAY));
747 assert_true(set->addLine(set, "00300004 00000041", GBA_CHEAT_PRO_ACTION_REPLAY));
748 assert_true(set->addLine(set, "00300005 00000051", GBA_CHEAT_PRO_ACTION_REPLAY));
749 assert_true(set->addLine(set, "88300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
750 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
751 assert_true(set->addLine(set, "08300001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
752 assert_true(set->addLine(set, "00300003 00000032", GBA_CHEAT_PRO_ACTION_REPLAY));
753 assert_true(set->addLine(set, "00300004 00000042", GBA_CHEAT_PRO_ACTION_REPLAY));
754 assert_true(set->addLine(set, "00000000 60000000", GBA_CHEAT_PRO_ACTION_REPLAY));
755 assert_true(set->addLine(set, "00300005 00000052", GBA_CHEAT_PRO_ACTION_REPLAY));
756 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
757 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
758
759 core->reset(core);
760 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
761 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
762 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
763 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
764 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0);
765 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0);
766
767 mCheatRefresh(device, set);
768 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
769 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
770 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
771 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
772 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
773 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
774
775 core->reset(core);
776 core->rawWrite8(core, 0x03000000, -1, 0x1);
777 mCheatRefresh(device, set);
778 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
779 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
780 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
781 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
782 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
783 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
784
785 core->reset(core);
786 core->rawWrite8(core, 0x03000001, -1, 0x1);
787 mCheatRefresh(device, set);
788 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
789 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
790 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
791 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
792 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
793 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
794
795 core->reset(core);
796 core->rawWrite8(core, 0x03000000, -1, 0x1);
797 core->rawWrite8(core, 0x03000001, -1, 0x1);
798 mCheatRefresh(device, set);
799 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
800 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
801 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
802 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
803 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
804 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
805 mCheatSetDeinit(set);
806}
807
808M_TEST_DEFINE(doPARv3IfXElseContain1) {
809 struct mCore* core = *state;
810 struct mCheatDevice* device = core->cheatDevice(core);
811 assert_non_null(device);
812 struct mCheatSet* set = device->createSet(device, NULL);
813 assert_non_null(set);
814 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
815 assert_true(set->addLine(set, "00300002 00000021", GBA_CHEAT_PRO_ACTION_REPLAY));
816 assert_true(set->addLine(set, "00300003 00000031", GBA_CHEAT_PRO_ACTION_REPLAY));
817 assert_true(set->addLine(set, "00300004 00000041", GBA_CHEAT_PRO_ACTION_REPLAY));
818 assert_true(set->addLine(set, "00300005 00000051", GBA_CHEAT_PRO_ACTION_REPLAY));
819 assert_true(set->addLine(set, "88300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
820 assert_true(set->addLine(set, "00300002 00000022", GBA_CHEAT_PRO_ACTION_REPLAY));
821 assert_true(set->addLine(set, "00000000 60000000", GBA_CHEAT_PRO_ACTION_REPLAY));
822 assert_true(set->addLine(set, "00300003 00000032", GBA_CHEAT_PRO_ACTION_REPLAY));
823 assert_true(set->addLine(set, "08300001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
824 assert_true(set->addLine(set, "00300004 00000042", GBA_CHEAT_PRO_ACTION_REPLAY));
825 assert_true(set->addLine(set, "00300005 00000052", GBA_CHEAT_PRO_ACTION_REPLAY));
826 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
827 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
828
829 core->reset(core);
830 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
831 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
832 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
833 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
834 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0);
835 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0);
836
837 mCheatRefresh(device, set);
838 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
839 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
840 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
841 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
842 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
843 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
844
845 core->reset(core);
846 core->rawWrite8(core, 0x03000000, -1, 0x1);
847 mCheatRefresh(device, set);
848 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
849 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
850 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
851 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
852 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
853 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
854
855 core->reset(core);
856 core->rawWrite8(core, 0x03000001, -1, 0x1);
857 mCheatRefresh(device, set);
858 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
859 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
860 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22);
861 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
862 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
863 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
864
865 core->reset(core);
866 core->rawWrite8(core, 0x03000000, -1, 0x1);
867 core->rawWrite8(core, 0x03000001, -1, 0x1);
868 mCheatRefresh(device, set);
869 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
870 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
871 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21);
872 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
873 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
874 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
875 mCheatSetDeinit(set);
876}
877
878M_TEST_DEFINE(doPARv3IfXContain1ElseContain1) {
879 struct mCore* core = *state;
880 struct mCheatDevice* device = core->cheatDevice(core);
881 assert_non_null(device);
882 struct mCheatSet* set = device->createSet(device, NULL);
883 assert_non_null(set);
884 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
885 assert_true(set->addLine(set, "00300003 00000031", GBA_CHEAT_PRO_ACTION_REPLAY));
886 assert_true(set->addLine(set, "00300004 00000041", GBA_CHEAT_PRO_ACTION_REPLAY));
887 assert_true(set->addLine(set, "00300005 00000051", GBA_CHEAT_PRO_ACTION_REPLAY));
888 assert_true(set->addLine(set, "00300006 00000061", GBA_CHEAT_PRO_ACTION_REPLAY));
889 assert_true(set->addLine(set, "00300007 00000071", GBA_CHEAT_PRO_ACTION_REPLAY));
890 assert_true(set->addLine(set, "00300008 00000081", GBA_CHEAT_PRO_ACTION_REPLAY));
891 assert_true(set->addLine(set, "88300000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
892 assert_true(set->addLine(set, "00300003 00000032", GBA_CHEAT_PRO_ACTION_REPLAY));
893 assert_true(set->addLine(set, "08300001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
894 assert_true(set->addLine(set, "00300004 00000042", GBA_CHEAT_PRO_ACTION_REPLAY));
895 assert_true(set->addLine(set, "00300005 00000052", GBA_CHEAT_PRO_ACTION_REPLAY));
896 assert_true(set->addLine(set, "00000000 60000000", GBA_CHEAT_PRO_ACTION_REPLAY));
897 assert_true(set->addLine(set, "00300006 00000062", GBA_CHEAT_PRO_ACTION_REPLAY));
898 assert_true(set->addLine(set, "08300002 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
899 assert_true(set->addLine(set, "00300007 00000072", GBA_CHEAT_PRO_ACTION_REPLAY));
900 assert_true(set->addLine(set, "00300008 00000082", GBA_CHEAT_PRO_ACTION_REPLAY));
901 assert_true(set->addLine(set, "00000000 40000000", GBA_CHEAT_PRO_ACTION_REPLAY));
902 assert_true(set->addLine(set, "00300000 00000001", GBA_CHEAT_PRO_ACTION_REPLAY));
903
904 core->reset(core);
905 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
906 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
907 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
908 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);
909 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0);
910 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0);
911 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0);
912 assert_int_equal(core->rawRead8(core, 0x03000007, -1), 0);
913 assert_int_equal(core->rawRead8(core, 0x03000008, -1), 0);
914
915 mCheatRefresh(device, set);
916 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
917 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
918 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
919 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
920 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
921 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
922 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x61);
923 assert_int_equal(core->rawRead8(core, 0x03000007, -1), 0x71);
924 assert_int_equal(core->rawRead8(core, 0x03000008, -1), 0x81);
925
926 core->reset(core);
927 core->rawWrite8(core, 0x03000000, -1, 0x1);
928 mCheatRefresh(device, set);
929 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
930 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
931 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
932 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
933 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
934 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
935 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x62);
936 assert_int_equal(core->rawRead8(core, 0x03000007, -1), 0x72);
937 assert_int_equal(core->rawRead8(core, 0x03000008, -1), 0x82);
938
939 core->reset(core);
940 core->rawWrite8(core, 0x03000001, -1, 0x1);
941 mCheatRefresh(device, set);
942 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
943 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
944 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
945 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
946 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
947 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
948 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x61);
949 assert_int_equal(core->rawRead8(core, 0x03000007, -1), 0x71);
950 assert_int_equal(core->rawRead8(core, 0x03000008, -1), 0x81);
951
952 core->reset(core);
953 core->rawWrite8(core, 0x03000002, -1, 0x1);
954 mCheatRefresh(device, set);
955 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
956 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
957 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x1);
958 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
959 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42);
960 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
961 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x61);
962 assert_int_equal(core->rawRead8(core, 0x03000007, -1), 0x71);
963 assert_int_equal(core->rawRead8(core, 0x03000008, -1), 0x81);
964
965 core->reset(core);
966 core->rawWrite8(core, 0x03000000, -1, 0x1);
967 core->rawWrite8(core, 0x03000001, -1, 0x1);
968 mCheatRefresh(device, set);
969 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
970 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
971 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0);
972 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
973 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
974 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
975 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x62);
976 assert_int_equal(core->rawRead8(core, 0x03000007, -1), 0x72);
977 assert_int_equal(core->rawRead8(core, 0x03000008, -1), 0x82);
978
979 core->reset(core);
980 core->rawWrite8(core, 0x03000000, -1, 0x1);
981 core->rawWrite8(core, 0x03000002, -1, 0x1);
982 mCheatRefresh(device, set);
983 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
984 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0);
985 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x1);
986 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
987 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
988 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
989 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x62);
990 assert_int_equal(core->rawRead8(core, 0x03000007, -1), 0x71);
991 assert_int_equal(core->rawRead8(core, 0x03000008, -1), 0x82);
992
993 core->reset(core);
994 core->rawWrite8(core, 0x03000001, -1, 0x1);
995 core->rawWrite8(core, 0x03000002, -1, 0x1);
996 mCheatRefresh(device, set);
997 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
998 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
999 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x1);
1000 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32);
1001 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
1002 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52);
1003 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x61);
1004 assert_int_equal(core->rawRead8(core, 0x03000007, -1), 0x71);
1005 assert_int_equal(core->rawRead8(core, 0x03000008, -1), 0x81);
1006
1007 core->reset(core);
1008 core->rawWrite8(core, 0x03000000, -1, 0x1);
1009 core->rawWrite8(core, 0x03000001, -1, 0x1);
1010 core->rawWrite8(core, 0x03000002, -1, 0x1);
1011 mCheatRefresh(device, set);
1012 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
1013 assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);
1014 assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x1);
1015 assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31);
1016 assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41);
1017 assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);
1018 assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x62);
1019 assert_int_equal(core->rawRead8(core, 0x03000007, -1), 0x71);
1020 assert_int_equal(core->rawRead8(core, 0x03000008, -1), 0x82);
1021 mCheatSetDeinit(set);
1022}
1023
1024M_TEST_DEFINE(doPARv3IfButton) {
1025 struct mCore* core = *state;
1026 struct mCheatDevice* device = core->cheatDevice(core);
1027 assert_non_null(device);
1028 struct mCheatSet* set = device->createSet(device, NULL);
1029 assert_non_null(set);
1030 GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW);
1031 assert_true(set->addLine(set, "00000000 10300000", GBA_CHEAT_PRO_ACTION_REPLAY));
1032 assert_true(set->addLine(set, "00000001 00000000", GBA_CHEAT_PRO_ACTION_REPLAY));
1033
1034 core->reset(core);
1035 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
1036
1037 mCheatRefresh(device, set);
1038 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
1039
1040 mCheatPressButton(device, true);
1041 mCheatRefresh(device, set);
1042 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
1043
1044 mCheatPressButton(device, false);
1045 mCheatRefresh(device, set);
1046 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1);
1047
1048 core->rawWrite8(core, 0x03000000, -1, 0);
1049 mCheatRefresh(device, set);
1050 assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0);
1051 mCheatSetDeinit(set);
1052}
1053
1054M_TEST_SUITE_DEFINE(GBACheats,
1055 cmocka_unit_test_setup_teardown(createSet, cheatsSetup, cheatsTeardown),
1056 cmocka_unit_test_setup_teardown(addRawPARv3, cheatsSetup, cheatsTeardown),
1057 cmocka_unit_test_setup_teardown(doPARv3Assign, cheatsSetup, cheatsTeardown),
1058 cmocka_unit_test_setup_teardown(doPARv3Slide1, cheatsSetup, cheatsTeardown),
1059 cmocka_unit_test_setup_teardown(doPARv3Slide2, cheatsSetup, cheatsTeardown),
1060 cmocka_unit_test_setup_teardown(doPARv3Slide4, cheatsSetup, cheatsTeardown),
1061 cmocka_unit_test_setup_teardown(doPARv3If1, cheatsSetup, cheatsTeardown),
1062 cmocka_unit_test_setup_teardown(doPARv3If1x1, cheatsSetup, cheatsTeardown),
1063 cmocka_unit_test_setup_teardown(doPARv3If2, cheatsSetup, cheatsTeardown),
1064 cmocka_unit_test_setup_teardown(doPARv3If2x2, cheatsSetup, cheatsTeardown),
1065 cmocka_unit_test_setup_teardown(doPARv3If2Contain1, cheatsSetup, cheatsTeardown),
1066 cmocka_unit_test_setup_teardown(doPARv3IfX, cheatsSetup, cheatsTeardown),
1067 cmocka_unit_test_setup_teardown(doPARv3IfXxX, cheatsSetup, cheatsTeardown),
1068 cmocka_unit_test_setup_teardown(doPARv3IfXElse, cheatsSetup, cheatsTeardown),
1069 cmocka_unit_test_setup_teardown(doPARv3IfXElsexX, cheatsSetup, cheatsTeardown),
1070 cmocka_unit_test_setup_teardown(doPARv3IfXElsexXElse, cheatsSetup, cheatsTeardown),
1071 cmocka_unit_test_setup_teardown(doPARv3IfXContain1, cheatsSetup, cheatsTeardown),
1072 cmocka_unit_test_setup_teardown(doPARv3IfXContain1Else, cheatsSetup, cheatsTeardown),
1073 cmocka_unit_test_setup_teardown(doPARv3IfXElseContain1, cheatsSetup, cheatsTeardown),
1074 cmocka_unit_test_setup_teardown(doPARv3IfXContain1ElseContain1, cheatsSetup, cheatsTeardown),
1075 cmocka_unit_test_setup_teardown(doPARv3IfButton, cheatsSetup, cheatsTeardown))