From b913ec4e0b373863645fc9b06e36995fe06507a6 Mon Sep 17 00:00:00 2001 From: Michael Forney 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