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_AND
26};
27
28enum GBACodeBreakerType {
29 CB_GAME_ID = 0x0,
30 CB_HOOK = 0x1,
31 CB_OR_2 = 0x2,
32 CB_ASSIGN_1 = 0x3,
33 CB_FILL = 0x4,
34 CB_FILL_8 = 0x5,
35 CB_AND_2 = 0x6,
36 CB_IF_EQ = 0x7,
37 CB_ASSIGN_2 = 0x8,
38 CB_ENCRYPT = 0x9,
39 CB_IF_NE = 0xA,
40 CB_IF_GT = 0xB,
41 CB_IF_LT = 0xC,
42 CB_IF_SPECIAL = 0xD,
43 CB_ADD_2 = 0xE,
44 CB_IF_AND = 0xF,
45};
46
47enum GBAGameSharkType {
48 GSA_ASSIGN_1 = 0x0,
49 GSA_ASSIGN_2 = 0x1,
50 GSA_ASSIGN_4 = 0x2,
51 GSA_ASSIGN_LIST = 0x3,
52 GSA_PATCH = 0x6,
53 GSA_BUTTON = 0x8,
54 GSA_IF_EQ = 0xD,
55 GSA_IF_EQ_RANGE = 0xE,
56 GSA_HOOK = 0xF
57};
58
59struct GBACheat {
60 enum GBACheatType type;
61 int width;
62 uint32_t address;
63 uint32_t operand;
64 uint32_t repeat;
65
66 int32_t addressOffset;
67 int32_t operandOffset;
68};
69
70DECLARE_VECTOR(GBACheatList, struct GBACheat);
71
72struct GBACheatSet {
73 uint32_t hookAddress;
74 enum ExecutionMode hookMode;
75 struct GBACheatList list;
76
77 struct GBACheat* incompleteCheat;
78 uint32_t patchedOpcode;
79
80 struct GBACheatPatch {
81 uint32_t address;
82 int16_t newValue;
83 int16_t oldValue;
84 bool applied;
85 } romPatches[MAX_ROM_PATCHES];
86 int nRomPatches;
87
88 int gsaVersion;
89 uint32_t gsaSeeds[4];
90 int remainingAddresses;
91};
92
93struct GBACheatDevice {
94 struct ARMComponent d;
95 struct GBA* p;
96
97 struct GBACheatSet* cheats;
98};
99
100void GBACheatDeviceCreate(struct GBACheatDevice*);
101
102void GBACheatSetInit(struct GBACheatSet*);
103void GBACheatSetDeinit(struct GBACheatSet*);
104
105void GBACheatAttachDevice(struct GBA* gba, struct GBACheatDevice*);
106void GBACheatInstallSet(struct GBACheatDevice*, struct GBACheatSet*);
107
108bool GBACheatAddCodeBreaker(struct GBACheatSet*, uint32_t op1, uint16_t op2);
109bool GBACheatAddCodeBreakerLine(struct GBACheatSet*, const char* line);
110
111bool GBACheatAddGameShark(struct GBACheatSet*, uint32_t op1, uint32_t op2);
112bool GBACheatAddGameSharkLine(struct GBACheatSet*, const char* line);
113
114bool GBACheatAddLine(struct GBACheatSet*, const char* line);
115
116void GBACheatRefresh(struct GBACheatDevice*);
117
118#endif