logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0003-GBA-Cheats-Use-defines-for-action-replay-constants.patch (5335B)


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