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.h"
12#include "util/vector.h"
13
14#define MAX_ROM_PATCHES 4
15
16enum GBACheatType {
17 CHEAT_ASSIGN,
18 CHEAT_AND,
19 CHEAT_ADD,
20 CHEAT_OR,
21 CHEAT_IF_EQ,
22 CHEAT_IF_NE,
23 CHEAT_IF_LT,
24 CHEAT_IF_GT,
25 CHEAT_IF_ULT,
26 CHEAT_IF_UGT,
27 CHEAT_IF_AND,
28 CHEAT_IF_LAND
29};
30
31enum GBACodeBreakerType {
32 CB_GAME_ID = 0x0,
33 CB_HOOK = 0x1,
34 CB_OR_2 = 0x2,
35 CB_ASSIGN_1 = 0x3,
36 CB_FILL = 0x4,
37 CB_FILL_8 = 0x5,
38 CB_AND_2 = 0x6,
39 CB_IF_EQ = 0x7,
40 CB_ASSIGN_2 = 0x8,
41 CB_ENCRYPT = 0x9,
42 CB_IF_NE = 0xA,
43 CB_IF_GT = 0xB,
44 CB_IF_LT = 0xC,
45 CB_IF_SPECIAL = 0xD,
46 CB_ADD_2 = 0xE,
47 CB_IF_AND = 0xF,
48};
49
50enum GBAGameSharkType {
51 GSA_ASSIGN_1 = 0x0,
52 GSA_ASSIGN_2 = 0x1,
53 GSA_ASSIGN_4 = 0x2,
54 GSA_ASSIGN_LIST = 0x3,
55 GSA_PATCH = 0x6,
56 GSA_BUTTON = 0x8,
57 GSA_IF_EQ = 0xD,
58 GSA_IF_EQ_RANGE = 0xE,
59 GSA_HOOK = 0xF
60};
61
62enum GBAActionReplay3Condition {
63 PAR3_COND_OTHER = 0x00000000,
64 PAR3_COND_EQ = 0x08000000,
65 PAR3_COND_NE = 0x10000000,
66 PAR3_COND_LT = 0x18000000,
67 PAR3_COND_GT = 0x20000000,
68 PAR3_COND_ULT = 0x28000000,
69 PAR3_COND_UGT = 0x30000000,
70 PAR3_COND_LAND = 0x38000000,
71};
72
73enum GBAActionReplay3Width {
74 PAR3_WIDTH_1 = 0x00000000,
75 PAR3_WIDTH_2 = 0x02000000,
76 PAR3_WIDTH_4 = 0x04000000,
77 PAR3_WIDTH_FALSE = 0x06000000,
78};
79
80enum GBAActionReplay3Action {
81 PAR3_ACTION_NEXT = 0x00000000,
82 PAR3_ACTION_NEXT_TWO = 0x40000000,
83 PAR3_ACTION_BLOCK = 0x80000000,
84 PAR3_ACTION_DISABLE = 0xC0000000,
85};
86
87enum GBAActionReplay3Base {
88 PAR3_BASE_ASSIGN_1 = 0x00000000,
89 PAR3_BASE_ASSIGN_2 = 0x02000000,
90 PAR3_BASE_ASSIGN_4 = 0x04000000,
91 PAR3_BASE_INDIRECT_1 = 0x40000000,
92 PAR3_BASE_INDIRECT_2 = 0x42000000,
93 PAR3_BASE_INDIRECT_4 = 0x44000000,
94 PAR3_BASE_ADD_1 = 0x80000000,
95 PAR3_BASE_ADD_2 = 0x82000000,
96 PAR3_BASE_ADD_4 = 0x84000000,
97 PAR3_BASE_HOOK = 0xC4000000,
98 PAR3_BASE_IO_2 = 0xC6000000,
99 PAR3_BASE_IO_3 = 0xC7000000,
100};
101
102enum GBAActionReplay3Other {
103 PAR3_OTHER_END = 0x00000000,
104 PAR3_OTHER_SLOWDOWN = 0x08000000,
105 PAR3_OTHER_BUTTON_1 = 0x10000000,
106 PAR3_OTHER_BUTTON_2 = 0x12000000,
107 PAR3_OTHER_BUTTON_4 = 0x14000000,
108 PAR3_OTHER_PATCH_1 = 0x18000000,
109 PAR3_OTHER_PATCH_2 = 0x1A000000,
110 PAR3_OTHER_PATCH_3 = 0x1C000000,
111 PAR3_OTHER_PATCH_4 = 0x1E000000,
112 PAR3_OTHER_ENDIF = 0x40000000,
113 PAR3_OTHER_ELSE = 0x60000000,
114 PAR3_OTHER_FILL_1 = 0x80000000,
115 PAR3_OTHER_FILL_2 = 0x82000000,
116 PAR3_OTHER_FILL_4 = 0x84000000,
117};
118
119enum {
120 PAR3_COND = 0x38000000,
121 PAR3_WIDTH = 0x06000000,
122 PAR3_ACTION = 0xC0000000
123};
124
125struct GBACheat {
126 enum GBACheatType type;
127 int width;
128 uint32_t address;
129 uint32_t operand;
130 uint32_t repeat;
131
132 int32_t addressOffset;
133 int32_t operandOffset;
134};
135
136DECLARE_VECTOR(GBACheatList, struct GBACheat);
137
138struct GBACheatSet {
139 uint32_t hookAddress;
140 enum ExecutionMode hookMode;
141 struct GBACheatList list;
142
143 struct GBACheat* incompleteCheat;
144 uint32_t patchedOpcode;
145
146 struct GBACheatPatch {
147 uint32_t address;
148 int16_t newValue;
149 int16_t oldValue;
150 bool applied;
151 bool exists;
152 } romPatches[MAX_ROM_PATCHES];
153
154 int gsaVersion;
155 uint32_t gsaSeeds[4];
156 int remainingAddresses;
157};
158
159struct GBACheatDevice {
160 struct ARMComponent d;
161 struct GBA* p;
162
163 struct GBACheatSet* cheats;
164};
165
166void GBACheatDeviceCreate(struct GBACheatDevice*);
167
168void GBACheatSetInit(struct GBACheatSet*);
169void GBACheatSetDeinit(struct GBACheatSet*);
170
171void GBACheatAttachDevice(struct GBA* gba, struct GBACheatDevice*);
172void GBACheatInstallSet(struct GBACheatDevice*, struct GBACheatSet*);
173
174bool GBACheatAddCodeBreaker(struct GBACheatSet*, uint32_t op1, uint16_t op2);
175bool GBACheatAddCodeBreakerLine(struct GBACheatSet*, const char* line);
176
177bool GBACheatAddGameShark(struct GBACheatSet*, uint32_t op1, uint32_t op2);
178bool GBACheatAddGameSharkLine(struct GBACheatSet*, const char* line);
179
180bool GBACheatAddLine(struct GBACheatSet*, const char* line);
181
182void GBACheatRefresh(struct GBACheatDevice*);
183
184#endif