include/mgba/core/cheats.h (view raw)
1/* Copyright (c) 2013-2016 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 CHEATS_H
7#define CHEATS_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/cpu.h>
14#include <mgba/core/log.h>
15#include <mgba-util/table.h>
16#include <mgba-util/vector.h>
17
18enum mCheatType {
19 CHEAT_ASSIGN,
20 CHEAT_ASSIGN_INDIRECT,
21 CHEAT_AND,
22 CHEAT_ADD,
23 CHEAT_OR,
24 CHEAT_IF_EQ,
25 CHEAT_IF_NE,
26 CHEAT_IF_LT,
27 CHEAT_IF_GT,
28 CHEAT_IF_ULT,
29 CHEAT_IF_UGT,
30 CHEAT_IF_AND,
31 CHEAT_IF_LAND,
32 CHEAT_IF_NAND,
33 CHEAT_IF_BUTTON,
34};
35
36struct mCheat {
37 enum mCheatType type;
38 int width;
39 uint32_t address;
40 uint32_t operand;
41 uint32_t repeat;
42 uint32_t negativeRepeat;
43
44 int32_t addressOffset;
45 int32_t operandOffset;
46};
47
48struct mCheatPatch {
49 uint32_t address;
50 int segment;
51 uint32_t value;
52 int width;
53 bool applied;
54 uint32_t checkValue;
55 bool check;
56};
57
58mLOG_DECLARE_CATEGORY(CHEATS);
59
60DECLARE_VECTOR(mCheatList, struct mCheat);
61DECLARE_VECTOR(mCheatPatchList, struct mCheatPatch);
62
63struct mCheatDevice;
64struct mCheatSet {
65 struct mCheatList list;
66
67 void (*deinit)(struct mCheatSet* set);
68 void (*add)(struct mCheatSet* set, struct mCheatDevice* device);
69 void (*remove)(struct mCheatSet* set, struct mCheatDevice* device);
70
71 bool (*addLine)(struct mCheatSet* set, const char* cheat, int type);
72 void (*copyProperties)(struct mCheatSet* set, struct mCheatSet* oldSet);
73
74 void (*parseDirectives)(struct mCheatSet* set, const struct StringList* directives);
75 void (*dumpDirectives)(struct mCheatSet* set, struct StringList* directives);
76
77 void (*refresh)(struct mCheatSet* set, struct mCheatDevice* device);
78
79 char* name;
80 bool enabled;
81 struct mCheatPatchList romPatches;
82 struct StringList lines;
83};
84
85DECLARE_VECTOR(mCheatSets, struct mCheatSet*);
86
87struct mCheatDevice {
88 struct mCPUComponent d;
89 struct mCore* p;
90
91 struct mCheatSet* (*createSet)(struct mCheatDevice*, const char* name);
92
93 struct mCheatSets cheats;
94 struct Table unpatchedMemory;
95 bool autosave;
96 bool buttonDown;
97};
98
99struct VFile;
100
101void mCheatDeviceCreate(struct mCheatDevice*);
102void mCheatDeviceDestroy(struct mCheatDevice*);
103void mCheatDeviceClear(struct mCheatDevice*);
104
105void mCheatSetInit(struct mCheatSet*, const char* name);
106void mCheatSetDeinit(struct mCheatSet*);
107void mCheatSetRename(struct mCheatSet*, const char* name);
108
109bool mCheatAddLine(struct mCheatSet*, const char* line, int type);
110
111void mCheatAddSet(struct mCheatDevice*, struct mCheatSet*);
112void mCheatRemoveSet(struct mCheatDevice*, struct mCheatSet*);
113
114bool mCheatParseFile(struct mCheatDevice*, struct VFile*);
115bool mCheatSaveFile(struct mCheatDevice*, struct VFile*);
116
117bool mCheatParseLibretroFile(struct mCheatDevice*, struct VFile*);
118bool mCheatParseEZFChtFile(struct mCheatDevice*, struct VFile*);
119
120#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
121void mCheatAutosave(struct mCheatDevice*);
122#endif
123
124void mCheatRefresh(struct mCheatDevice*, struct mCheatSet*);
125void mCheatPressButton(struct mCheatDevice*, bool down);
126
127CXX_GUARD_END
128
129#endif