src/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 "util/common.h"
10
11#include "core/cpu.h"
12#include "core/log.h"
13#include "util/vector.h"
14
15#define MAX_ROM_PATCHES 4
16
17enum mCheatType {
18 CHEAT_ASSIGN,
19 CHEAT_ASSIGN_INDIRECT,
20 CHEAT_AND,
21 CHEAT_ADD,
22 CHEAT_OR,
23 CHEAT_IF_EQ,
24 CHEAT_IF_NE,
25 CHEAT_IF_LT,
26 CHEAT_IF_GT,
27 CHEAT_IF_ULT,
28 CHEAT_IF_UGT,
29 CHEAT_IF_AND,
30 CHEAT_IF_LAND
31};
32
33struct mCheat {
34 enum mCheatType type;
35 int width;
36 uint32_t address;
37 uint32_t operand;
38 uint32_t repeat;
39 uint32_t negativeRepeat;
40
41 int32_t addressOffset;
42 int32_t operandOffset;
43};
44
45mLOG_DECLARE_CATEGORY(CHEATS);
46
47DECLARE_VECTOR(mCheatList, struct mCheat);
48DECLARE_VECTOR(StringList, char*);
49
50struct mCheatDevice;
51struct mCheatSet {
52 struct mCheatList list;
53
54 void (*deinit)(struct mCheatSet* set);
55 void (*add)(struct mCheatSet* set, struct mCheatDevice* device);
56 void (*remove)(struct mCheatSet* set, struct mCheatDevice* device);
57
58 bool (*addLine)(struct mCheatSet* set, const char* cheat, int type);
59 void (*copyProperties)(struct mCheatSet* set, struct mCheatSet* oldSet);
60
61 void (*refresh)(struct mCheatSet* set, struct mCheatDevice* device);
62
63 char* name;
64 bool enabled;
65 struct StringList lines;
66};
67
68DECLARE_VECTOR(mCheatSets, struct mCheatSet*);
69
70struct mCheatDevice {
71 struct mCPUComponent d;
72 struct mCore* p;
73
74 struct mCheatSet* (*createSet)(struct mCheatDevice*, const char* name);
75
76 struct mCheatSets cheats;
77};
78
79struct VFile;
80
81void mCheatDeviceCreate(struct mCheatDevice*);
82void mCheatDeviceDestroy(struct mCheatDevice*);
83void mCheatDeviceClear(struct mCheatDevice*);
84
85void mCheatSetInit(struct mCheatSet*, const char* name);
86void mCheatSetDeinit(struct mCheatSet*);
87void mCheatSetRename(struct mCheatSet*, const char* name);
88
89bool mCheatAddLine(struct mCheatSet*, const char* line, int type);
90
91void mCheatAddSet(struct mCheatDevice*, struct mCheatSet*);
92void mCheatRemoveSet(struct mCheatDevice*, struct mCheatSet*);
93
94bool mCheatParseFile(struct mCheatDevice*, struct VFile*);
95bool mCheatSaveFile(struct mCheatDevice*, struct VFile*);
96
97void mCheatRefresh(struct mCheatDevice*, struct mCheatSet*);
98
99#endif