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
14enum GBACheatType {
15 CHEAT_ASSIGN,
16 CHEAT_AND,
17 CHEAT_ADD,
18 CHEAT_OR,
19 CHEAT_IF_EQ,
20 CHEAT_IF_NE,
21 CHEAT_IF_LT,
22 CHEAT_IF_GT,
23 CHEAT_IF_AND
24};
25
26enum GBACodeBreakerType {
27 CB_GAME_ID = 0x0,
28 CB_HOOK = 0x1,
29 CB_OR_2 = 0x2,
30 CB_ASSIGN_1 = 0x3,
31 CB_FILL = 0x4,
32 CB_FILL_8 = 0x5,
33 CB_AND_2 = 0x6,
34 CB_IF_EQ = 0x7,
35 CB_ASSIGN_2 = 0x8,
36 CB_ENCRYPT = 0x9,
37 CB_IF_NE = 0xA,
38 CB_IF_GT = 0xB,
39 CB_IF_LT = 0xC,
40 CB_IF_SPECIAL = 0xD,
41 CB_ADD_2 = 0xE,
42 CB_IF_AND = 0xF,
43};
44
45struct GBACheat {
46 enum GBACheatType type;
47 int width;
48 uint32_t address;
49 uint32_t operand;
50 uint32_t repeat;
51
52 int32_t addressOffset;
53 int32_t operandOffset;
54};
55
56DECLARE_VECTOR(GBACheatList, struct GBACheat);
57
58struct GBACheatSet {
59 uint32_t hookAddress;
60 enum ExecutionMode hookMode;
61 struct GBACheatList list;
62
63 struct GBACheat* incompleteCheat;
64 uint32_t patchedOpcode;
65};
66
67struct GBACheatDevice {
68 struct ARMComponent d;
69 struct GBA* p;
70
71 struct GBACheatSet* cheats;
72};
73
74void GBACheatDeviceCreate(struct GBACheatDevice*);
75
76void GBACheatSetInit(struct GBACheatSet*);
77void GBACheatSetDeinit(struct GBACheatSet*);
78
79void GBACheatAttachDevice(struct GBA* gba, struct GBACheatDevice*);
80void GBACheatInstallSet(struct GBACheatDevice*, struct GBACheatSet*);
81
82bool GBACheatAddCodeBreaker(struct GBACheatSet*, uint32_t op1, uint16_t op2);
83bool GBACheatAddCodeBreakerLine(struct GBACheatSet*, const char* line);
84
85void GBACheatRefresh(struct GBACheatDevice*);
86
87#endif