暂时提交用于后续对比修改

This commit is contained in:
anod 2023-03-06 18:06:55 +08:00
parent da04e14d52
commit 30cb8eec81
2 changed files with 66 additions and 10 deletions

View File

@ -2,6 +2,7 @@
#define _CHEAT_H_
#include "types.h"
#include "arm11/acl.h"
typedef int cheat_error_t;
@ -9,6 +10,9 @@ typedef int cheat_error_t;
#define CCHT_NO_SPACE 1
#define CCHT_NO_IRQ 2
#define CCHT_NO_CHEAT 3
#define CCHT_NO_MEM 4
#define CCHT_NOT_INIT 5
#define CCHT_INVALID 6
#define CHEAT_MODE_DISABLED 0
#define CHEAT_MODE_FULLTIME 1
@ -16,9 +20,11 @@ typedef int cheat_error_t;
#define CHEAT_MODE_KEYONOFF 3
#define CHEAT_MODE_SIZE 3
cheat_error_t init_current_cheat( u32 id, u32 len );
cheat_error_t put_current_cheat( u32 index, u32 entry_id );
cheat_error_t get_current_cheat( u32 *id, u32 *len, u32 *entry_array );
#define MAKE_ENTID(hole, key) ((key+1)<<16|(hole+1))
cheat_error_t init_current_cheat( u32 id, u16 len );
cheat_error_t put_current_cheat( acl_entryid_t entry_id );
cheat_error_t get_current_cheat( u32 *id, u32 *len, void **entry_array );
cheat_error_t fini_current_cheat();
cheat_error_t push_current_cheat( const char *filename, int is_using );

View File

@ -9,13 +9,63 @@
typedef u32 instruction_t;
typedef struct {
u32 chtId;
u16 entLen;
acl_index_t *entArr;
u32 chtId; // acl_chtid_t
u16 entLen; // entArr.length
acl_index_t *entArr; // 下标表示hole值表示key
} CurrentCheat;
static CurrentCheat setting = {0, 0, NULL};
cheat_error_t init_current_cheat( u32 id, u16 len )
{
if( setting.entArr ) fini_current_cheat();
if( id == 0 ) return CCHT_OK;
setting.chtId = id;
setting.entLen = len;
if( len )
{
acl_index_t *p = (acl_index_t*)malloc( len * sizeof(acl_index_t) );
if( p == NULL ) return CCHT_NO_MEM;
memset(p, 0, len*sizeof(acl_index_t));
setting.entArr = p;
}
return CCHT_OK;
}
cheat_error_t put_current_cheat( acl_entryid_t entid )
{
if( setting.chtId == 0 ) return CCHT_NOT_INIT;
u16 index = entid & 0xffff;
u16 option = entid >> 16;
if( index == 0 ) return CCHT_INVALID;
if( index <= setting.entLen )
{
setting.entArr[index-1] = option;
return CCHT_OK;
}
else return CCHT_INVALID;
}
cheat_error_t get_current_cheat( u32 *id, u32 *len, void **entry_array )
{
if( setting.chtId == 0 ) return CCHT_NOT_INIT;
*id = setting.chtId;
*len = setting.entLen;
*entry_array = setting.entArr;
return CCHT_OK;
}
cheat_error_t fini_current_cheat()
{
if( setting.entArr ) free( setting.entArr );
setting.entArr = NULL;
setting.entLen = 0;
setting.chtId = 0;
return CCHT_OK;
}
typedef instruction_t* CodeLocation;
#define CodeAtLocation(p) (*p)
@ -25,7 +75,7 @@ typedef instruction_t* CodeLocation;
#define GBACPU_PREFETCH 2
#define GBACPU_PREFETCH_BYTE (sizeof(instruction_t)*GBACPU_PREFETCH)
#define MAKE_ENT(lock, key) ((key+1)<<16|(lock+1))
#define MAKE_ENT(hole,key) ((key<<16) | hole)
const instruction_t HOOKPOINT_INSTR[] = {
0xe92d8000, // STMDB sp!, {pc}
@ -321,7 +371,7 @@ static void rom_append_cheatproc( int mode, CodeLocation start, u16 bindkey, u32
*start++ = 0;
}
cheat_error_t apply_cheat( int mode, u32 szrom )
cheat_error_t apply_cheat( int mode, u32 szrom, u16 bindkey, u32 storagemem )
{
// try ignore patch
if( mode == CHEAT_MODE_DISABLED ) return CCHT_OK;
@ -345,7 +395,7 @@ cheat_error_t apply_cheat( int mode, u32 szrom )
// patching the rom
rom_append_newirq( page, hookpoint, n_hookpoint );
rom_patch_hookpoint( page, hookpoint, n_hookpoint ); // FIXME: romdata+realend
rom_append_cheatproc( mode, page + n_hookpoint * IW_INSTR_LEN );
rom_patch_hookpoint( page, hookpoint, n_hookpoint );
rom_append_cheatproc( mode, page + n_hookpoint * IW_INSTR_LEN, bindkey, storagemem );
return CCHT_OK;
}