From f830537f9e19485ccd104a509917d792114aebc5 Mon Sep 17 00:00:00 2001 From: anod <182859762@qq.com> Date: Fri, 17 Mar 2023 17:43:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8Afit=5Fsize=E7=9A=84=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E5=86=8D=E6=94=B9=E5=9B=9E=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/arm11/cheat.c | 74 +++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/source/arm11/cheat.c b/source/arm11/cheat.c index 0c12bea..9638fa5 100644 --- a/source/arm11/cheat.c +++ b/source/arm11/cheat.c @@ -337,11 +337,13 @@ static CodeLocation rom_fit_newsize( CodeLocation rom, int realend, int totalsiz { u32 size = realend + totalsize; + if( size > SIZE_32M ) + { // get the biggest space that all bytes is 0 - CodeLocation found=NULL, current=NULL; - int szfound=0, szcurrent=0; - int reallen = INSTR_LEN( realend ); - instruction_t freeinstr = 0; // 0/0xffffffff will be free + CodeLocation found=NULL, current=NULL; + int szfound=0, szcurrent=0; + int reallen = INSTR_LEN( realend ); + instruction_t freeinstr = 0; // 0/0xffffffff will be free #define START_FREE_BLOCK(n) {\ current = rom+i;\ @@ -357,45 +359,45 @@ static CodeLocation rom_fit_newsize( CodeLocation rom, int realend, int totalsiz szcurrent = 0;\ } - for( int i=0; i < reallen; ++i ) - { - if( rom[i] == 0 ) + for( int i=0; i < reallen; ++i ) { - if( szcurrent == 0 ) + if( rom[i] == 0 ) { - START_FREE_BLOCK(0); + if( szcurrent == 0 ) + { + START_FREE_BLOCK(0); + } + else + { + if( freeinstr == 0 )// same block + szcurrent += INSTR_SIZE; + else END_FREE_BLOCK; + } } - else + else if( rom[i] == 0xffffffff ) { - if( freeinstr == 0 )// same block - szcurrent += INSTR_SIZE; - else END_FREE_BLOCK; - } + if( szcurrent == 0xffffffff ) + { + START_FREE_BLOCK(0xffffffff); + } + else + { + if( freeinstr == 0xffffffff ) + szcurrent += INSTR_SIZE; + else END_FREE_BLOCK; + } + } + else if( szcurrent > 0 ) END_FREE_BLOCK; } - else if( rom[i] == 0xffffffff ) - { - if( szcurrent == 0xffffffff ) - { - START_FREE_BLOCK(0xffffffff); - } - else - { - if( freeinstr == 0xffffffff ) - szcurrent += INSTR_SIZE; - else END_FREE_BLOCK; - } - } - else if( szcurrent > 0 ) END_FREE_BLOCK; - } - // the zero-filled space is big enough, 3 is a guess value - if( szfound > totalsize * 3 ) - { - return found + FIT_SPACE_RESERVED; + // the zero-filled space is big enough, 3 is a guess value + if( szfound > totalsize * 3 ) + { + return found + FIT_SPACE_RESERVED; + } + // cannot find a good block + else return NULL; } - - // cannot find a good block - if( size > SIZE_32M ) return NULL; // grow cart volumn else if( szrom < size || nextPow2(size) != nextPow2(szrom) )