summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Guillen Fandos2021-05-05 18:07:55 +0200
committerDavid G. F2021-05-05 21:15:27 +0200
commit883f07f487ecd2e803cf2f924ab1e9a51e5f4fa9 (patch)
treea6ba3622f8d9ad72e8b6d9d084ac3e04b814a5b5
parent4fd456e1583a4c8686c8de87c2aeb1eb78125be1 (diff)
downloadpicogpsp-883f07f487ecd2e803cf2f924ab1e9a51e5f4fa9.tar.gz
picogpsp-883f07f487ecd2e803cf2f924ab1e9a51e5f4fa9.tar.bz2
picogpsp-883f07f487ecd2e803cf2f924ab1e9a51e5f4fa9.zip
Fix small buf and add cheat error messages
Some minor formating too
-rw-r--r--arm/arm_emit.h4
-rw-r--r--cheats.c27
-rw-r--r--cheats.h12
-rw-r--r--libretro.c18
-rw-r--r--psp/mips_emit.h2
5 files changed, 52 insertions, 11 deletions
diff --git a/arm/arm_emit.h b/arm/arm_emit.h
index 4368a80..1b6b251 100644
--- a/arm/arm_emit.h
+++ b/arm/arm_emit.h
@@ -31,8 +31,8 @@ u32 prepare_store_reg(u32 scratch_reg, u32 reg_index);
void generate_load_reg(u32 ireg, u32 reg_index);
void complete_store_reg(u32 scratch_reg, u32 reg_index);
void complete_store_reg_pc_no_flags(u32 scratch_reg, u32 reg_index);
-void thumb_cheat_hook();
-void arm_cheat_hook();
+void thumb_cheat_hook(void);
+void arm_cheat_hook(void);
u32 arm_update_gba_arm(u32 pc);
u32 arm_update_gba_thumb(u32 pc);
diff --git a/cheats.c b/cheats.c
index 1a37081..17556ca 100644
--- a/cheats.c
+++ b/cheats.c
@@ -33,6 +33,19 @@ cheat_type cheats[MAX_CHEATS];
u32 max_cheat = 0;
u32 cheat_master_hook = 0xffffffff;
+static bool has_encrypted_codebreaker(cheat_type *cheat)
+{
+ int i;
+ for(i = 0; i < cheat->cheat_count; i++)
+ {
+ u32 code = cheat->codes[i].address;
+ u32 opcode = code >> 28;
+ if (opcode == 9)
+ return true;
+ }
+ return false;
+}
+
static void update_hook_codebreaker(cheat_type *cheat)
{
int i;
@@ -103,7 +116,7 @@ static void process_cheat_codebreaker(cheat_type *cheat, u16 pad)
bvalue = cheat->codes[i].address >> (24 - off*8);
break;
case 4 ... 5:
- bvalue = cheat->codes[i].address >> (40 - off*8);
+ bvalue = cheat->codes[i].value >> (40 - off*8);
break;
};
write_memory8(address, bvalue);
@@ -192,7 +205,7 @@ void cheat_clear()
cheat_master_hook = 0xffffffff;
}
-void cheat_parse(unsigned index, const char *code)
+cheat_error cheat_parse(unsigned index, const char *code)
{
int pos = 0;
int codelen = strlen(code);
@@ -200,9 +213,9 @@ void cheat_parse(unsigned index, const char *code)
char buf[1024];
if (index >= MAX_CHEATS)
- return;
+ return CheatErrorTooMany;
if (codelen >= sizeof(buf))
- return;
+ return CheatErrorTooBig;
memcpy(buf, code, codelen+1);
@@ -236,13 +249,17 @@ void cheat_parse(unsigned index, const char *code)
if (pos >= codelen)
{
+ /* Check whether these cheats are readable */
+ if (has_encrypted_codebreaker(ch))
+ return CheatErrorEncrypted;
/* All codes were parsed! Process hook here */
ch->cheat_active = true;
update_hook_codebreaker(ch);
- return;
+ return CheatNoError;
}
/* TODO parse other types here */
+ return CheatErrorNotSupported;
}
diff --git a/cheats.h b/cheats.h
index 496df15..b6e0a5d 100644
--- a/cheats.h
+++ b/cheats.h
@@ -23,9 +23,17 @@
#define MAX_CHEATS 20
#define MAX_CHEAT_CODES 64
+typedef enum {
+ CheatNoError = 0,
+ CheatErrorTooMany,
+ CheatErrorTooBig,
+ CheatErrorEncrypted,
+ CheatErrorNotSupported
+} cheat_error;
+
void process_cheats(void);
-void cheat_parse(unsigned index, const char *code);
-void cheat_clear();
+cheat_error cheat_parse(unsigned index, const char *code);
+void cheat_clear(void);
extern u32 cheat_master_hook;
diff --git a/libretro.c b/libretro.c
index 40aec37..d8e9efc 100644
--- a/libretro.c
+++ b/libretro.c
@@ -647,7 +647,23 @@ void retro_cheat_set(unsigned index, bool enabled, const char* code)
if (!enabled)
return;
- cheat_parse(index, code);
+ switch (cheat_parse(index, code))
+ {
+ case CheatErrorTooMany:
+ show_warning_message("Too many active cheats!", 2500);
+ break;
+ case CheatErrorTooBig:
+ show_warning_message("Cheats are too big!", 2500);
+ break;
+ case CheatErrorEncrypted:
+ show_warning_message("Encrypted cheats are not supported!", 2500);
+ break;
+ case CheatErrorNotSupported:
+ show_warning_message("Cheat type is not supported!", 2500);
+ break;
+ case CheatNoError:
+ break;
+ };
}
static void extract_directory(char* buf, const char* path, size_t size)
diff --git a/psp/mips_emit.h b/psp/mips_emit.h
index 174fee5..aa00d86 100644
--- a/psp/mips_emit.h
+++ b/psp/mips_emit.h
@@ -44,7 +44,7 @@ void mips_indirect_branch_dual(u32 address);
u32 execute_read_cpsr();
u32 execute_read_spsr();
void execute_swi(u32 pc);
-void mips_cheat_hook();
+void mips_cheat_hook(void);
u32 execute_spsr_restore(u32 address);
void execute_store_cpsr(u32 new_cpsr, u32 store_mask);