aboutsummaryrefslogtreecommitdiff
path: root/source/cheats.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/cheats.c')
-rw-r--r--source/cheats.c271
1 files changed, 1 insertions, 270 deletions
diff --git a/source/cheats.c b/source/cheats.c
index 1a5e833..572fd55 100644
--- a/source/cheats.c
+++ b/source/cheats.c
@@ -22,8 +22,7 @@ static bool S9xAllHex(const char* code, int32_t len)
const char* S9xProActionReplayToRaw(const char* code, uint32_t* address, uint8_t* byte)
{
uint32_t data = 0;
- if (strlen(code) != 8 || !S9xAllHex(code, 8) ||
- sscanf(code, "%x", &data) != 1)
+ if (strlen(code) != 8 || !S9xAllHex(code, 8) || sscanf(code, "%x", &data) != 1)
return "Invalid Pro Action Replay code - should be 8 hex digits in length.";
*address = data >> 8;
@@ -100,271 +99,3 @@ const char* S9xGameGenieToRaw(const char* code, uint32_t* address, uint8_t* byte
return NULL;
}
-
-void S9xStartCheatSearch(SCheatData* d)
-{
- // memmove may be required: Source is usually a different malloc, but could be pointed to d->CWRAM [Neb]
- memmove(d->CWRAM, d->RAM, 0x20000);
- // memmove may be required: Source is usually a different malloc, but could be pointed to d->CSRAM [Neb]
- memmove(d->CSRAM, d->SRAM, 0x10000);
- // memmove may be required: Source is usually a different malloc, but could be pointed to d->CIRAM [Neb]
- memmove(d->CIRAM, &d->FillRAM [0x3000], 0x2000);
- memset(d->WRAM_BITS, 0xff, 0x20000 >> 3);
- memset(d->SRAM_BITS, 0xff, 0x10000 >> 3);
- memset(d->IRAM_BITS, 0xff, 0x2000 >> 3);
-}
-
-#define BIT_CLEAR(a,v) \
-(a)[(v) >> 5] &= ~(1 << ((v) & 31))
-
-#define BIT_SET(a,v) \
-(a)[(v) >> 5] |= 1 << ((v) & 31)
-
-#define TEST_BIT(a,v) \
-((a)[(v) >> 5] & (1 << ((v) & 31)))
-
-#define CHEATS_C(c,a,b) \
-((c) == S9X_LESS_THAN ? (a) < (b) : \
- (c) == S9X_GREATER_THAN ? (a) > (b) : \
- (c) == S9X_LESS_THAN_OR_EQUAL ? (a) <= (b) : \
- (c) == S9X_GREATER_THAN_OR_EQUAL ? (a) >= (b) : \
- (c) == S9X_EQUAL ? (a) == (b) : \
- (a) != (b))
-
-#define _D(s,m,o) \
-((s) == S9X_8_BITS ? (uint8_t) (*((m) + (o))) : \
- (s) == S9X_16_BITS ? ((uint16_t) (*((m) + (o)) + (*((m) + (o) + 1) << 8))) : \
- (s) == S9X_24_BITS ? ((uint32_t) (*((m) + (o)) + (*((m) + (o) + 1) << 8) + (*((m) + (o) + 2) << 16))) : \
-((uint32_t) (*((m) + (o)) + (*((m) + (o) + 1) << 8) + (*((m) + (o) + 2) << 16) + (*((m) + (o) + 3) << 24))))
-
-#define _DS(s,m,o) \
-((s) == S9X_8_BITS ? ((int8_t) *((m) + (o))) : \
- (s) == S9X_16_BITS ? ((int16_t) (*((m) + (o)) + (*((m) + (o) + 1) << 8))) : \
- (s) == S9X_24_BITS ? (((int32_t) ((*((m) + (o)) + (*((m) + (o) + 1) << 8) + (*((m) + (o) + 2) << 16)) << 8)) >> 8): \
- ((int32_t) (*((m) + (o)) + (*((m) + (o) + 1) << 8) + (*((m) + (o) + 2) << 16) + (*((m) + (o) + 3) << 24))))
-
-void S9xSearchForChange(SCheatData* d, S9xCheatComparisonType cmp,
- S9xCheatDataSize size, bool is_signed, bool update)
-{
- int32_t l;
- int32_t i;
-
- switch (size)
- {
- case S9X_8_BITS:
- l = 0;
- break;
- case S9X_16_BITS:
- l = 1;
- break;
- case S9X_24_BITS:
- l = 2;
- break;
- default:
- case S9X_32_BITS:
- l = 3;
- break;
- }
-
- if (is_signed)
- {
- for (i = 0; i < 0x20000 - l; i++)
- {
- if (TEST_BIT(d->WRAM_BITS, i) &&
- CHEATS_C(cmp, _DS(size, d->RAM, i), _DS(size, d->CWRAM, i)))
- {
- if (update)
- d->CWRAM [i] = d->RAM [i];
- }
- else
- BIT_CLEAR(d->WRAM_BITS, i);
- }
-
- for (i = 0; i < 0x10000 - l; i++)
- {
- if (TEST_BIT(d->SRAM_BITS, i) &&
- CHEATS_C(cmp, _DS(size, d->SRAM, i), _DS(size, d->CSRAM, i)))
- {
- if (update)
- d->CSRAM [i] = d->SRAM [i];
- }
- else
- BIT_CLEAR(d->SRAM_BITS, i);
- }
-
- for (i = 0; i < 0x2000 - l; i++)
- {
- if (TEST_BIT(d->IRAM_BITS, i) &&
- CHEATS_C(cmp, _DS(size, d->FillRAM + 0x3000, i), _DS(size, d->CIRAM, i)))
- {
- if (update)
- d->CIRAM [i] = d->FillRAM [i + 0x3000];
- }
- else
- BIT_CLEAR(d->IRAM_BITS, i);
- }
- }
- else
- {
- for (i = 0; i < 0x20000 - l; i++)
- {
- if (TEST_BIT(d->WRAM_BITS, i) &&
- CHEATS_C(cmp, _D(size, d->RAM, i), _D(size, d->CWRAM, i)))
- {
- if (update)
- d->CWRAM [i] = d->RAM [i];
- }
- else
- BIT_CLEAR(d->WRAM_BITS, i);
- }
-
- for (i = 0; i < 0x10000 - l; i++)
- {
- if (TEST_BIT(d->SRAM_BITS, i) &&
- CHEATS_C(cmp, _D(size, d->SRAM, i), _D(size, d->CSRAM, i)))
- {
- if (update)
- d->CSRAM [i] = d->SRAM [i];
- }
- else
- BIT_CLEAR(d->SRAM_BITS, i);
- }
-
- for (i = 0; i < 0x2000 - l; i++)
- {
- if (TEST_BIT(d->IRAM_BITS, i) &&
- CHEATS_C(cmp, _D(size, d->FillRAM + 0x3000, i), _D(size, d->CIRAM, i)))
- {
- if (update)
- d->CIRAM [i] = d->FillRAM [i + 0x3000];
- }
- else
- BIT_CLEAR(d->IRAM_BITS, i);
- }
- }
-}
-
-void S9xSearchForValue(SCheatData* d, S9xCheatComparisonType cmp,
- S9xCheatDataSize size, uint32_t value,
- bool is_signed, bool update)
-{
- int32_t l;
- int32_t i;
-
- switch (size)
- {
- case S9X_8_BITS:
- l = 0;
- break;
- case S9X_16_BITS:
- l = 1;
- break;
- case S9X_24_BITS:
- l = 2;
- break;
- default:
- case S9X_32_BITS:
- l = 3;
- break;
- }
-
-
- if (is_signed)
- {
- for (i = 0; i < 0x20000 - l; i++)
- {
- if (TEST_BIT(d->WRAM_BITS, i) &&
- CHEATS_C(cmp, _DS(size, d->RAM, i), (int32_t) value))
- {
- if (update)
- d->CWRAM [i] = d->RAM [i];
- }
- else
- BIT_CLEAR(d->WRAM_BITS, i);
- }
-
- for (i = 0; i < 0x10000 - l; i++)
- {
- if (TEST_BIT(d->SRAM_BITS, i) &&
- CHEATS_C(cmp, _DS(size, d->SRAM, i), (int32_t) value))
- {
- if (update)
- d->CSRAM [i] = d->SRAM [i];
- }
- else
- BIT_CLEAR(d->SRAM_BITS, i);
- }
-
- for (i = 0; i < 0x2000 - l; i++)
- {
- if (TEST_BIT(d->IRAM_BITS, i) &&
- CHEATS_C(cmp, _DS(size, d->FillRAM + 0x3000, i), (int32_t) value))
- {
- if (update)
- d->CIRAM [i] = d->FillRAM [i + 0x3000];
- }
- else
- BIT_CLEAR(d->IRAM_BITS, i);
- }
- }
- else
- {
- for (i = 0; i < 0x20000 - l; i++)
- {
- if (TEST_BIT(d->WRAM_BITS, i) &&
- CHEATS_C(cmp, _D(size, d->RAM, i), value))
- {
- if (update)
- d->CWRAM [i] = d->RAM [i];
- }
- else
- BIT_CLEAR(d->WRAM_BITS, i);
- }
-
- for (i = 0; i < 0x10000 - l; i++)
- {
- if (TEST_BIT(d->SRAM_BITS, i) &&
- CHEATS_C(cmp, _D(size, d->SRAM, i), value))
- {
- if (update)
- d->CSRAM [i] = d->SRAM [i];
- }
- else
- BIT_CLEAR(d->SRAM_BITS, i);
- }
-
- for (i = 0; i < 0x2000 - l; i++)
- {
- if (TEST_BIT(d->IRAM_BITS, i) &&
- CHEATS_C(cmp, _D(size, d->FillRAM + 0x3000, i), value))
- {
- if (update)
- d->CIRAM [i] = d->FillRAM [i + 0x3000];
- }
- else
- BIT_CLEAR(d->IRAM_BITS, i);
- }
- }
-}
-
-void S9xOutputCheatSearchResults(SCheatData* d)
-{
- int32_t i;
- for (i = 0; i < 0x20000; i++)
- {
- if (TEST_BIT(d->WRAM_BITS, i))
- printf("WRAM: %05x: %02x\n", i, d->RAM [i]);
- }
-
- for (i = 0; i < 0x10000; i++)
- {
- if (TEST_BIT(d->SRAM_BITS, i))
- printf("SRAM: %04x: %02x\n", i, d->SRAM [i]);
- }
-
- for (i = 0; i < 0x2000; i++)
- {
- if (TEST_BIT(d->IRAM_BITS, i))
- printf("IRAM: %05x: %02x\n", i, d->FillRAM [i + 0x3000]);
- }
-}