修正显示的文字

调整cheat.c的一些可读性问题
This commit is contained in:
anod 2023-03-08 18:09:36 +08:00
parent ec67ae7364
commit b2562d2e4c
3 changed files with 30 additions and 23 deletions

View File

@ -7,16 +7,13 @@
typedef u32 instruction_t;
typedef instruction_t* CodeLocation;
#define INSTR_SIZE sizeof(instruction_t)
#define INSTR_LEN(memsize) ((memsize)/INSTR_SIZE)
#define CodeAtLocation(p) (*(p))
#define MAKE_ENT(hole,key) (((key)<<16) | (hole))
#define ENT_KEY(id) ((id)>>16)
#define ENT_HOLE(id) ((id)&0xffff)
#define ROM_LOC ((CodeLocation)0x20000000u)
#define GBA_KEYCODE(k) (0x3ff & (~(k)))
#define SIZE_32M (32*1024*1024)
#define MAX_HOOKPOINT 10
typedef struct {
u32 chtId; // acl_chtid_t
@ -106,8 +103,17 @@ cheat_error_t fini_current_cheat()
// code for patch rom with cheat instruction
// *******************************************
#define FIT_SPACE_RESERVED 80
#define ROM_LOC ((CodeLocation)0x20000000u)
#define GBACPU_PREFETCH 2
#define GBACPU_PREFETCH_BYTE (sizeof(instruction_t)*GBACPU_PREFETCH)
#define GBACPU_PREFETCH_BYTE (INSTR_SIZE*GBACPU_PREFETCH)
#define GBA_KEYCODE(k) (0x3ff & (~(k)))
#define GBA_CART_ADDR (0x8000000u)
#define SIZE_32M (32*1024*1024)
#define MAX_HOOKPOINT 10
const instruction_t HOOKPOINT_INSTR[] = {
0xe92d8000, // STMDB sp!, {pc}
@ -116,7 +122,7 @@ const instruction_t HOOKPOINT_INSTR[] = {
};
#define HP_INSTR_SIZE sizeof(HOOKPOINT_INSTR)
#define HP_INSTR_LEN (HP_INSTR_SIZE/sizeof(instruction_t))
#define HP_INSTR_LEN INSTR_LEN(HP_INSTR_SIZE)
#define HP_WRAPPER_ADDR 2
const instruction_t IRQ_WRAPPER_INSTR[] = {
@ -138,7 +144,7 @@ const instruction_t IRQ_WRAPPER_INSTR[] = {
};
#define IW_INSTR_SIZE sizeof(IRQ_WRAPPER_INSTR)
#define IW_INSTR_LEN (IW_INSTR_SIZE/sizeof(instruction_t))
#define IW_INSTR_LEN INSTR_LEN(IW_INSTR_SIZE)
#define IW_CALL_HANDLER 5
#define IW_ORIGNAL_IRQ 11
@ -167,7 +173,7 @@ const instruction_t KEY_ONOFF_INSTR[] = {
};
#define KOO_INSTR_SIZE sizeof(KEY_ONOFF_INSTR)
#define KOO_INSTR_LEN (KOO_INSTR_SIZE/sizeof(instruction_t))
#define KOO_INSTR_LEN INSTR_LEN(KOO_INSTR_SIZE)
#define KOO_INSTR_KEYDATA 19
#define KOO_INSTR_MEMADDR 20
@ -184,7 +190,7 @@ const instruction_t KEY_ENABLE_INSTR[] = {
};
#define KEN_INSTR_SIZE sizeof(KEY_ENABLE_INSTR)
#define KEN_INSTR_LEN (KEN_INSTR_SIZE/sizeof(instruction_t))
#define KEN_INSTR_LEN INSTR_LEN(KEN_INSTR_SIZE)
#define KEN_INSTR_KEYDATA 8
const instruction_t MEM_OVERWRITE_INSTR[] = {
@ -203,16 +209,16 @@ const instruction_t MEM_OVERWRITE_INSTR[] = {
};
#define MO_INSTR_SIZE sizeof(MEM_OVERWRITE_INSTR)
#define MO_INSTR_LEN (MO_INSTR_SIZE/sizeof(instruction_t))
#define MO_INSTR_LEN INSTR_LEN(MO_INSTR_SIZE)
static int end_of_rom( CodeLocation addr, u32 size )
{
CodeLocation prom = addr + size/sizeof(instruction_t) - 1;
CodeLocation prom = addr + INSTR_LEN( size ) - 1;
while( addr < prom && (CodeAtLocation(prom) == 0x00000000 || CodeAtLocation(prom) == 0xffffffff) )
{
prom--;
}
return sizeof(instruction_t) * (prom + 2 - addr); // consider the first 0x00000000/0xffffffff as in-using
return INSTR_SIZE * (prom + 2 - addr); // consider the first 0x00000000/0xffffffff as in-using
}
#define MASK_PC0( m ) (pc[0]&m)
@ -301,11 +307,11 @@ static int cht_calc_needsize( int mode, int numirq )
{
acl_elemlen_t len;
acl_select_entry( MAKE_ENT(i, val), &len );
total += len*sizeof(instruction_t);
total += len*INSTR_SIZE;
}
}
return total + sizeof(instruction_t);
return total + 1*INSTR_SIZE; // the zero-end marks for cheat data
}
static CodeLocation rom_fit_newsize( CodeLocation rom, int realend, int totalsize, u32 *newsize )
@ -316,13 +322,13 @@ static CodeLocation rom_fit_newsize( CodeLocation rom, int realend, int totalsiz
// get the biggest space that all bytes is 0
CodeLocation found=NULL, current=NULL;
int szfound=0, szcurrent=0;
int reallen = realend / sizeof(instruction_t);
int reallen = INSTR_LEN( realend );
for( int i=0; i < reallen; ++i )
{
if( rom[i] == 0 )
{
if( szcurrent == 0 ) current = rom+i;
szcurrent += sizeof(instruction_t);
szcurrent += INSTR_SIZE;
}
else if( szcurrent > 0 )
{
@ -338,7 +344,7 @@ static CodeLocation rom_fit_newsize( CodeLocation rom, int realend, int totalsiz
// the zero-filled space is big enough, 3 is a guess value
if( szfound > totalsize * 3 )
{
return found + 80;
return found + FIT_SPACE_RESERVED;
}
else return NULL;
}
@ -346,15 +352,15 @@ static CodeLocation rom_fit_newsize( CodeLocation rom, int realend, int totalsiz
{
// 似乎没什么要动的
*newsize = size + 1; // reserve a word for padding
return rom + realend / sizeof(instruction_t);
return rom + INSTR_LEN( realend );
}
return rom + realend / sizeof(instruction_t);
return rom + INSTR_LEN( realend );
}
static void rom_patch_hookpoint( CodeLocation start, CodeLocation hookpoint[MAX_HOOKPOINT], int hookcnt )
{
u32 addr = 0x8000000 + (start-ROM_LOC)*sizeof(instruction_t);
u32 addr = GBA_CART_ADDR + (start-ROM_LOC)*INSTR_SIZE;
for( int i=0; i < hookcnt; ++i )
{
CodeLocation hook_point = hookpoint[i];
@ -425,7 +431,7 @@ cheat_error_t apply_cheat( int mode, u32 szrom, u16 bindkey, u32 storagemem, u32
// find hook point
CodeLocation hookpoint[MAX_HOOKPOINT];
memset( hookpoint, 0, sizeof(hookpoint) );
int n_hookpoint = rom_search_hookpoint( romdata, realend/sizeof(u32) - 3, hookpoint ); // hook point need at least 3 instructions
int n_hookpoint = rom_search_hookpoint( romdata, INSTR_LEN(realend) - 3, hookpoint ); // hook point need at least 3 instructions
if( n_hookpoint == 0 ) return CCHT_NO_IRQ;
// find free space to put new code

View File

@ -416,6 +416,7 @@ static atp_pageopt_t serve_on_key( atp_callerdata_t data, atp_counter_t index, a
uint8_t status = DISP_REGION;
atp_counter_t defi = 0;
acl_entryid_t eid = 0;
atp_tips(NULL, "确定A/取消B");
while( status != DISP_DONE )
{
@ -481,6 +482,7 @@ static atp_pageopt_t serve_on_key( atp_callerdata_t data, atp_counter_t index, a
}
acl_close_lib();
atp_tips( NULL, "指引按START" );
return WAIT_ON_ACT( res );
}
return ATP_PAGE_NOOPTION;

View File

@ -143,7 +143,6 @@ atp_text_t config_help[] =
"~ ~ ~ ~ ~ ~ ~",
"-修改后的全局参数保存在config.ini ",
"保存修改时,存档方案的修改不会保存",
"~ ~ ~ ~ ~ ~ ~",
"-金手指组合键为下方向+L+R+SELECT",
" 也可以使用HOME键直接代替组合键 ",
"~ ~ ~ ~ ~ ~ ~",