Fix small buf and add cheat error messages
Some minor formating too
This commit is contained in:
parent
4fd456e158
commit
883f07f487
|
@ -31,8 +31,8 @@ u32 prepare_store_reg(u32 scratch_reg, u32 reg_index);
|
||||||
void generate_load_reg(u32 ireg, 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(u32 scratch_reg, u32 reg_index);
|
||||||
void complete_store_reg_pc_no_flags(u32 scratch_reg, u32 reg_index);
|
void complete_store_reg_pc_no_flags(u32 scratch_reg, u32 reg_index);
|
||||||
void thumb_cheat_hook();
|
void thumb_cheat_hook(void);
|
||||||
void arm_cheat_hook();
|
void arm_cheat_hook(void);
|
||||||
|
|
||||||
u32 arm_update_gba_arm(u32 pc);
|
u32 arm_update_gba_arm(u32 pc);
|
||||||
u32 arm_update_gba_thumb(u32 pc);
|
u32 arm_update_gba_thumb(u32 pc);
|
||||||
|
|
27
cheats.c
27
cheats.c
|
@ -33,6 +33,19 @@ cheat_type cheats[MAX_CHEATS];
|
||||||
u32 max_cheat = 0;
|
u32 max_cheat = 0;
|
||||||
u32 cheat_master_hook = 0xffffffff;
|
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)
|
static void update_hook_codebreaker(cheat_type *cheat)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -103,7 +116,7 @@ static void process_cheat_codebreaker(cheat_type *cheat, u16 pad)
|
||||||
bvalue = cheat->codes[i].address >> (24 - off*8);
|
bvalue = cheat->codes[i].address >> (24 - off*8);
|
||||||
break;
|
break;
|
||||||
case 4 ... 5:
|
case 4 ... 5:
|
||||||
bvalue = cheat->codes[i].address >> (40 - off*8);
|
bvalue = cheat->codes[i].value >> (40 - off*8);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
write_memory8(address, bvalue);
|
write_memory8(address, bvalue);
|
||||||
|
@ -192,7 +205,7 @@ void cheat_clear()
|
||||||
cheat_master_hook = 0xffffffff;
|
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 pos = 0;
|
||||||
int codelen = strlen(code);
|
int codelen = strlen(code);
|
||||||
|
@ -200,9 +213,9 @@ void cheat_parse(unsigned index, const char *code)
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
if (index >= MAX_CHEATS)
|
if (index >= MAX_CHEATS)
|
||||||
return;
|
return CheatErrorTooMany;
|
||||||
if (codelen >= sizeof(buf))
|
if (codelen >= sizeof(buf))
|
||||||
return;
|
return CheatErrorTooBig;
|
||||||
|
|
||||||
memcpy(buf, code, codelen+1);
|
memcpy(buf, code, codelen+1);
|
||||||
|
|
||||||
|
@ -236,13 +249,17 @@ void cheat_parse(unsigned index, const char *code)
|
||||||
|
|
||||||
if (pos >= codelen)
|
if (pos >= codelen)
|
||||||
{
|
{
|
||||||
|
/* Check whether these cheats are readable */
|
||||||
|
if (has_encrypted_codebreaker(ch))
|
||||||
|
return CheatErrorEncrypted;
|
||||||
/* All codes were parsed! Process hook here */
|
/* All codes were parsed! Process hook here */
|
||||||
ch->cheat_active = true;
|
ch->cheat_active = true;
|
||||||
update_hook_codebreaker(ch);
|
update_hook_codebreaker(ch);
|
||||||
return;
|
return CheatNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO parse other types here */
|
/* TODO parse other types here */
|
||||||
|
return CheatErrorNotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
12
cheats.h
12
cheats.h
|
@ -23,9 +23,17 @@
|
||||||
#define MAX_CHEATS 20
|
#define MAX_CHEATS 20
|
||||||
#define MAX_CHEAT_CODES 64
|
#define MAX_CHEAT_CODES 64
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CheatNoError = 0,
|
||||||
|
CheatErrorTooMany,
|
||||||
|
CheatErrorTooBig,
|
||||||
|
CheatErrorEncrypted,
|
||||||
|
CheatErrorNotSupported
|
||||||
|
} cheat_error;
|
||||||
|
|
||||||
void process_cheats(void);
|
void process_cheats(void);
|
||||||
void cheat_parse(unsigned index, const char *code);
|
cheat_error cheat_parse(unsigned index, const char *code);
|
||||||
void cheat_clear();
|
void cheat_clear(void);
|
||||||
|
|
||||||
extern u32 cheat_master_hook;
|
extern u32 cheat_master_hook;
|
||||||
|
|
||||||
|
|
18
libretro.c
18
libretro.c
|
@ -647,7 +647,23 @@ void retro_cheat_set(unsigned index, bool enabled, const char* code)
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
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)
|
static void extract_directory(char* buf, const char* path, size_t size)
|
||||||
|
|
|
@ -44,7 +44,7 @@ void mips_indirect_branch_dual(u32 address);
|
||||||
u32 execute_read_cpsr();
|
u32 execute_read_cpsr();
|
||||||
u32 execute_read_spsr();
|
u32 execute_read_spsr();
|
||||||
void execute_swi(u32 pc);
|
void execute_swi(u32 pc);
|
||||||
void mips_cheat_hook();
|
void mips_cheat_hook(void);
|
||||||
|
|
||||||
u32 execute_spsr_restore(u32 address);
|
u32 execute_spsr_restore(u32 address);
|
||||||
void execute_store_cpsr(u32 new_cpsr, u32 store_mask);
|
void execute_store_cpsr(u32 new_cpsr, u32 store_mask);
|
||||||
|
|
Loading…
Reference in New Issue