1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
From b913ec4e0b373863645fc9b06e36995fe06507a6 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Sat, 7 Nov 2020 14:28:05 -0800
Subject: [PATCH] GBA Cheats: Use defines for action replay constants
ISO C requires that enum constants must be representable as int and
have type int (C99 6.7.2.2p2 and 6.4.4.3p2). Some of these are
larger than 0x7fffffff, so just use preprocessor defines instead.
This changes the type of the constants from int to unsigned int.
[0] https://port70.net/~nsz/c/c99/n1256.html#6.7.2.2p2
[1] https://port70.net/~nsz/c/c99/n1256.html#6.4.4.3p2
---
include/mgba/internal/gba/cheats.h | 128 +++++++++++++----------------
src/gba/cheats/parv3.c | 2 +-
2 files changed, 59 insertions(+), 71 deletions(-)
diff --git a/include/mgba/internal/gba/cheats.h b/include/mgba/internal/gba/cheats.h
index fe17af1a6..19de60319 100644
--- a/include/mgba/internal/gba/cheats.h
+++ b/include/mgba/internal/gba/cheats.h
@@ -55,76 +55,64 @@ enum GBAGameSharkType {
GSA_HOOK = 0xF
};
-enum GBAActionReplay3Condition {
- PAR3_COND_OTHER = 0x00000000,
- PAR3_COND_EQ = 0x08000000,
- PAR3_COND_NE = 0x10000000,
- PAR3_COND_LT = 0x18000000,
- PAR3_COND_GT = 0x20000000,
- PAR3_COND_ULT = 0x28000000,
- PAR3_COND_UGT = 0x30000000,
- PAR3_COND_AND = 0x38000000,
-};
-
-enum GBAActionReplay3Width {
- PAR3_WIDTH_1 = 0x00000000,
- PAR3_WIDTH_2 = 0x02000000,
- PAR3_WIDTH_4 = 0x04000000,
- PAR3_WIDTH_FALSE = 0x06000000,
-};
-
-enum GBAActionReplay3Action {
- PAR3_ACTION_NEXT = 0x00000000,
- PAR3_ACTION_NEXT_TWO = 0x40000000,
- PAR3_ACTION_BLOCK = 0x80000000,
- PAR3_ACTION_DISABLE = 0xC0000000,
-};
-
-enum GBAActionReplay3Base {
- PAR3_BASE_ASSIGN = 0x00000000,
- PAR3_BASE_INDIRECT = 0x40000000,
- PAR3_BASE_ADD = 0x80000000,
- PAR3_BASE_OTHER = 0xC0000000,
-
- PAR3_BASE_ASSIGN_1 = 0x00000000,
- PAR3_BASE_ASSIGN_2 = 0x02000000,
- PAR3_BASE_ASSIGN_4 = 0x04000000,
- PAR3_BASE_INDIRECT_1 = 0x40000000,
- PAR3_BASE_INDIRECT_2 = 0x42000000,
- PAR3_BASE_INDIRECT_4 = 0x44000000,
- PAR3_BASE_ADD_1 = 0x80000000,
- PAR3_BASE_ADD_2 = 0x82000000,
- PAR3_BASE_ADD_4 = 0x84000000,
- PAR3_BASE_HOOK = 0xC4000000,
- PAR3_BASE_IO_2 = 0xC6000000,
- PAR3_BASE_IO_3 = 0xC7000000,
-};
-
-enum GBAActionReplay3Other {
- PAR3_OTHER_END = 0x00000000,
- PAR3_OTHER_SLOWDOWN = 0x08000000,
- PAR3_OTHER_BUTTON_1 = 0x10000000,
- PAR3_OTHER_BUTTON_2 = 0x12000000,
- PAR3_OTHER_BUTTON_4 = 0x14000000,
- PAR3_OTHER_PATCH_1 = 0x18000000,
- PAR3_OTHER_PATCH_2 = 0x1A000000,
- PAR3_OTHER_PATCH_3 = 0x1C000000,
- PAR3_OTHER_PATCH_4 = 0x1E000000,
- PAR3_OTHER_ENDIF = 0x40000000,
- PAR3_OTHER_ELSE = 0x60000000,
- PAR3_OTHER_FILL_1 = 0x80000000,
- PAR3_OTHER_FILL_2 = 0x82000000,
- PAR3_OTHER_FILL_4 = 0x84000000,
-};
-
-enum {
- PAR3_COND = 0x38000000,
- PAR3_WIDTH = 0x06000000,
- PAR3_ACTION = 0xC0000000,
- PAR3_BASE = 0xC0000000,
-
- PAR3_WIDTH_BASE = 25
-};
+#define PAR3_COND_OTHER 0x00000000
+#define PAR3_COND_EQ 0x08000000
+#define PAR3_COND_NE 0x10000000
+#define PAR3_COND_LT 0x18000000
+#define PAR3_COND_GT 0x20000000
+#define PAR3_COND_ULT 0x28000000
+#define PAR3_COND_UGT 0x30000000
+#define PAR3_COND_AND 0x38000000
+
+#define PAR3_WIDTH_1 0x00000000
+#define PAR3_WIDTH_2 0x02000000
+#define PAR3_WIDTH_4 0x04000000
+#define PAR3_WIDTH_FALSE 0x06000000
+
+#define PAR3_ACTION_NEXT 0x00000000
+#define PAR3_ACTION_NEXT_TWO 0x40000000
+#define PAR3_ACTION_BLOCK 0x80000000
+#define PAR3_ACTION_DISABLE 0xC0000000
+
+#define PAR3_BASE_ASSIGN 0x00000000
+#define PAR3_BASE_INDIRECT 0x40000000
+#define PAR3_BASE_ADD 0x80000000
+#define PAR3_BASE_OTHER 0xC0000000
+
+#define PAR3_BASE_ASSIGN_1 0x00000000
+#define PAR3_BASE_ASSIGN_2 0x02000000
+#define PAR3_BASE_ASSIGN_4 0x04000000
+#define PAR3_BASE_INDIRECT_1 0x40000000
+#define PAR3_BASE_INDIRECT_2 0x42000000
+#define PAR3_BASE_INDIRECT_4 0x44000000
+#define PAR3_BASE_ADD_1 0x80000000
+#define PAR3_BASE_ADD_2 0x82000000
+#define PAR3_BASE_ADD_4 0x84000000
+#define PAR3_BASE_HOOK 0xC4000000
+#define PAR3_BASE_IO_2 0xC6000000
+#define PAR3_BASE_IO_3 0xC7000000
+
+#define PAR3_OTHER_END 0x00000000
+#define PAR3_OTHER_SLOWDOWN 0x08000000
+#define PAR3_OTHER_BUTTON_1 0x10000000
+#define PAR3_OTHER_BUTTON_2 0x12000000
+#define PAR3_OTHER_BUTTON_4 0x14000000
+#define PAR3_OTHER_PATCH_1 0x18000000
+#define PAR3_OTHER_PATCH_2 0x1A000000
+#define PAR3_OTHER_PATCH_3 0x1C000000
+#define PAR3_OTHER_PATCH_4 0x1E000000
+#define PAR3_OTHER_ENDIF 0x40000000
+#define PAR3_OTHER_ELSE 0x60000000
+#define PAR3_OTHER_FILL_1 0x80000000
+#define PAR3_OTHER_FILL_2 0x82000000
+#define PAR3_OTHER_FILL_4 0x84000000
+
+#define PAR3_COND 0x38000000
+#define PAR3_WIDTH 0x06000000
+#define PAR3_ACTION 0xC0000000
+#define PAR3_BASE 0xC0000000
+
+#define PAR3_WIDTH_BASE 25
struct GBACheatHook {
uint32_t address;
diff --git a/src/gba/cheats/parv3.c b/src/gba/cheats/parv3.c
index 4f3a89310..731de638e 100644
--- a/src/gba/cheats/parv3.c
+++ b/src/gba/cheats/parv3.c
@@ -70,7 +70,7 @@ static void _parElseBlock(struct GBACheatSet* cheats) {
}
static bool _addPAR3Cond(struct GBACheatSet* cheats, uint32_t op1, uint32_t op2) {
- enum GBAActionReplay3Condition condition = op1 & PAR3_COND;
+ uint32_t condition = op1 & PAR3_COND;
int width = 1 << ((op1 & PAR3_WIDTH) >> PAR3_WIDTH_BASE);
if (width > 4) {
// TODO: Always false conditions
--
2.29.2
|