all repos — mgba @ 168cad7f9cb9df70fcad15b6d89769d8d96834d2

mGBA Game Boy Advance Emulator

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