src/gba/cheats.h (view raw)
1/* Copyright (c) 2013-2015 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#ifndef GBA_CHEATS_H
7#define GBA_CHEATS_H
8
9#include "util/common.h"
10
11#include "arm/arm.h"
12#include "core/cheats.h"
13
14#define MAX_ROM_PATCHES 4
15#define COMPLETE ((size_t) -1)
16
17enum GBACheatType {
18 GBA_CHEAT_AUTODETECT,
19 GBA_CHEAT_CODEBREAKER,
20 GBA_CHEAT_GAMESHARK,
21 GBA_CHEAT_PRO_ACTION_REPLAY,
22 GBA_CHEAT_VBA
23};
24
25enum GBACodeBreakerType {
26 CB_GAME_ID = 0x0,
27 CB_HOOK = 0x1,
28 CB_OR_2 = 0x2,
29 CB_ASSIGN_1 = 0x3,
30 CB_FILL = 0x4,
31 CB_FILL_8 = 0x5,
32 CB_AND_2 = 0x6,
33 CB_IF_EQ = 0x7,
34 CB_ASSIGN_2 = 0x8,
35 CB_ENCRYPT = 0x9,
36 CB_IF_NE = 0xA,
37 CB_IF_GT = 0xB,
38 CB_IF_LT = 0xC,
39 CB_IF_SPECIAL = 0xD,
40 CB_ADD_2 = 0xE,
41 CB_IF_AND = 0xF,
42};
43
44enum GBAGameSharkType {
45 GSA_ASSIGN_1 = 0x0,
46 GSA_ASSIGN_2 = 0x1,
47 GSA_ASSIGN_4 = 0x2,
48 GSA_ASSIGN_LIST = 0x3,
49 GSA_PATCH = 0x6,
50 GSA_BUTTON = 0x8,
51 GSA_IF_EQ = 0xD,
52 GSA_IF_EQ_RANGE = 0xE,
53 GSA_HOOK = 0xF
54};
55
56enum GBAActionReplay3Condition {
57 PAR3_COND_OTHER = 0x00000000,
58 PAR3_COND_EQ = 0x08000000,
59 PAR3_COND_NE = 0x10000000,
60 PAR3_COND_LT = 0x18000000,
61 PAR3_COND_GT = 0x20000000,
62 PAR3_COND_ULT = 0x28000000,
63 PAR3_COND_UGT = 0x30000000,
64 PAR3_COND_LAND = 0x38000000,
65};
66
67enum GBAActionReplay3Width {
68 PAR3_WIDTH_1 = 0x00000000,
69 PAR3_WIDTH_2 = 0x02000000,
70 PAR3_WIDTH_4 = 0x04000000,
71 PAR3_WIDTH_FALSE = 0x06000000,
72};
73
74enum GBAActionReplay3Action {
75 PAR3_ACTION_NEXT = 0x00000000,
76 PAR3_ACTION_NEXT_TWO = 0x40000000,
77 PAR3_ACTION_BLOCK = 0x80000000,
78 PAR3_ACTION_DISABLE = 0xC0000000,
79};
80
81enum GBAActionReplay3Base {
82 PAR3_BASE_ASSIGN = 0x00000000,
83 PAR3_BASE_INDIRECT = 0x40000000,
84 PAR3_BASE_ADD = 0x80000000,
85 PAR3_BASE_OTHER = 0xC0000000,
86
87 PAR3_BASE_ASSIGN_1 = 0x00000000,
88 PAR3_BASE_ASSIGN_2 = 0x02000000,
89 PAR3_BASE_ASSIGN_4 = 0x04000000,
90 PAR3_BASE_INDIRECT_1 = 0x40000000,
91 PAR3_BASE_INDIRECT_2 = 0x42000000,
92 PAR3_BASE_INDIRECT_4 = 0x44000000,
93 PAR3_BASE_ADD_1 = 0x80000000,
94 PAR3_BASE_ADD_2 = 0x82000000,
95 PAR3_BASE_ADD_4 = 0x84000000,
96 PAR3_BASE_HOOK = 0xC4000000,
97 PAR3_BASE_IO_2 = 0xC6000000,
98 PAR3_BASE_IO_3 = 0xC7000000,
99};
100
101enum GBAActionReplay3Other {
102 PAR3_OTHER_END = 0x00000000,
103 PAR3_OTHER_SLOWDOWN = 0x08000000,
104 PAR3_OTHER_BUTTON_1 = 0x10000000,
105 PAR3_OTHER_BUTTON_2 = 0x12000000,
106 PAR3_OTHER_BUTTON_4 = 0x14000000,
107 PAR3_OTHER_PATCH_1 = 0x18000000,
108 PAR3_OTHER_PATCH_2 = 0x1A000000,
109 PAR3_OTHER_PATCH_3 = 0x1C000000,
110 PAR3_OTHER_PATCH_4 = 0x1E000000,
111 PAR3_OTHER_ENDIF = 0x40000000,
112 PAR3_OTHER_ELSE = 0x60000000,
113 PAR3_OTHER_FILL_1 = 0x80000000,
114 PAR3_OTHER_FILL_2 = 0x82000000,
115 PAR3_OTHER_FILL_4 = 0x84000000,
116};
117
118enum {
119 PAR3_COND = 0x38000000,
120 PAR3_WIDTH = 0x06000000,
121 PAR3_ACTION = 0xC0000000,
122 PAR3_BASE = 0xC0000000,
123
124 PAR3_WIDTH_BASE = 25
125};
126
127struct GBACheatHook {
128 uint32_t address;
129 enum ExecutionMode mode;
130 uint32_t patchedOpcode;
131 size_t refs;
132 size_t reentries;
133};
134
135struct GBACheatSet {
136 struct mCheatSet d;
137 struct GBACheatHook* hook;
138
139 struct GBACheatPatch {
140 uint32_t address;
141 int16_t newValue;
142 int16_t oldValue;
143 bool applied;
144 bool exists;
145 } romPatches[MAX_ROM_PATCHES];
146
147 size_t incompleteCheat;
148 struct GBACheatPatch* incompletePatch;
149 size_t currentBlock;
150
151 int gsaVersion;
152 uint32_t gsaSeeds[4];
153 uint32_t cbRngState;
154 uint32_t cbMaster;
155 uint8_t cbTable[0x30];
156 uint32_t cbSeeds[4];
157 int remainingAddresses;
158};
159
160struct VFile;
161
162struct mCheatDevice* GBACheatDeviceCreate(void);
163
164bool GBACheatAddCodeBreaker(struct GBACheatSet*, uint32_t op1, uint16_t op2);
165bool GBACheatAddCodeBreakerLine(struct GBACheatSet*, const char* line);
166
167bool GBACheatAddGameShark(struct GBACheatSet*, uint32_t op1, uint32_t op2);
168bool GBACheatAddGameSharkLine(struct GBACheatSet*, const char* line);
169
170bool GBACheatAddProActionReplay(struct GBACheatSet*, uint32_t op1, uint32_t op2);
171bool GBACheatAddProActionReplayLine(struct GBACheatSet*, const char* line);
172
173bool GBACheatAddVBALine(struct GBACheatSet*, const char* line);
174
175#endif