Skip to content

Commit

Permalink
cheats: handle 1F and D4
Browse files Browse the repository at this point in the history
  • Loading branch information
notaz committed Dec 13, 2023
1 parent 8412166 commit 5162c3f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
27 changes: 24 additions & 3 deletions libpcsxcore/cheat.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "r3000a.h"
#include "psxmem.h"
#include "misc.h"
#include "../frontend/plugin_lib.h" // in_keystate for D4

#include "cheat.h"

Expand Down Expand Up @@ -228,6 +229,10 @@ void ApplyCheats() {
psxMu16ref(addr) = SWAPu16(val);
break;

case CHEAT_SCRATCHPAD16: // 1F
psxHs16ref(addr) = SWAPu16(val);
break;

case CHEAT_INC16:
psxMu16ref(addr) = SWAPu16(psxMu16(addr) + val);
break;
Expand Down Expand Up @@ -319,6 +324,20 @@ void ApplyCheats() {
if (PSXMu16(addr) <= val)
j++; // skip the next code
break;

case CHEAT_BUTTONS1_16: { // D4
u16 keys = in_keystate[0];
keys = (keys << 8) | (keys >> 8);
if (keys != val)
j++; // skip the next code
break;
}

default:
SysPrintf("unhandled cheat %d,%d code %08X\n",
i, j, CheatCodes[j].Addr);
Cheats[i].WasEnabled = Cheats[i].Enabled = 0;
break;
}
}
}
Expand Down Expand Up @@ -350,7 +369,7 @@ int AddCheat(const char *descr, char *code) {
p2 = code;

while (c) {
unsigned int t1, t2;
unsigned int t1, t2, r;

while (*p2 != '\n' && *p2 != '\0')
p2++;
Expand All @@ -363,9 +382,11 @@ int AddCheat(const char *descr, char *code) {

t1 = 0;
t2 = 0;
sscanf(p1, "%x %x", &t1, &t2);
r = sscanf(p1, "%x %x", &t1, &t2);

if (t1 > 0x10000000) {
if (r != 2)
SysPrintf("cheat %d: couldn't parse '%s'\n", NumCodes, p1);
else if (t1 >= 0x10000000) {
if (NumCodes >= NumCodesAllocated) {
NumCodesAllocated += ALLOC_INCREMENT;

Expand Down
36 changes: 20 additions & 16 deletions libpcsxcore/cheat.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,27 @@ extern int NumCodesAllocated;
#define PrevMu32(mem) (SWAP32(*(u32 *)PREVM(mem)))

// cheat types
#define CHEAT_CONST8 0x30 /* 8-bit Constant Write */
#define CHEAT_CONST16 0x80 /* 16-bit Constant Write */
#define CHEAT_INC16 0x10 /* 16-bit Increment */
#define CHEAT_DEC16 0x11 /* 16-bit Decrement */
#define CHEAT_INC8 0x20 /* 8-bit Increment */
#define CHEAT_DEC8 0x21 /* 8-bit Decrement */
#define CHEAT_SLIDE 0x50 /* Slide Codes */
#define CHEAT_MEMCPY 0xC2 /* Memory Copy */

#define CHEAT_EQU8 0xE0 /* 8-bit Equal To */
#define CHEAT_NOTEQU8 0xE1 /* 8-bit Not Equal To */
#define CHEAT_LESSTHAN8 0xE2 /* 8-bit Less Than */
#define CHEAT_GREATERTHAN8 0xE3 /* 8-bit Greater Than */
#define CHEAT_EQU16 0xD0 /* 16-bit Equal To */
#define CHEAT_NOTEQU16 0xD1 /* 16-bit Not Equal To */
#define CHEAT_LESSTHAN16 0xD2 /* 16-bit Less Than */
#define CHEAT_CONST8 0x30 /* 8-bit Constant Write */
#define CHEAT_CONST16 0x80 /* 16-bit Constant Write */

#define CHEAT_INC16 0x10 /* 16-bit Increment */
#define CHEAT_DEC16 0x11 /* 16-bit Decrement */
#define CHEAT_SCRATCHPAD16 0x1F /* 16-bit Scratchpad Write */
#define CHEAT_INC8 0x20 /* 8-bit Increment */
#define CHEAT_DEC8 0x21 /* 8-bit Decrement */
#define CHEAT_SLIDE 0x50 /* Slide Codes */
#define CHEAT_MEMCPY 0xC2 /* Memory Copy */

// conditionals
#define CHEAT_EQU16 0xD0 /* 16-bit Equal To */
#define CHEAT_NOTEQU16 0xD1 /* 16-bit Not Equal To */
#define CHEAT_LESSTHAN16 0xD2 /* 16-bit Less Than */
#define CHEAT_GREATERTHAN16 0xD3 /* 16-bit Greater Than */
#define CHEAT_BUTTONS1_16 0xD4 /* button presses equate to YYYY */
#define CHEAT_EQU8 0xE0 /* 8-bit Equal To */
#define CHEAT_NOTEQU8 0xE1 /* 8-bit Not Equal To */
#define CHEAT_LESSTHAN8 0xE2 /* 8-bit Less Than */
#define CHEAT_GREATERTHAN8 0xE3 /* 8-bit Greater Than */

#ifdef __cplusplus
}
Expand Down

0 comments on commit 5162c3f

Please sign in to comment.