all repos — mgba @ 1cb054ec67ea7b1e7e9162c1e74bd4ab254efb74

mGBA Game Boy Advance Emulator

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