From 32c763d8b7e789eda24586800be95453db643909 Mon Sep 17 00:00:00 2001 From: root <182859762@qq.com> Date: Mon, 16 Oct 2023 17:56:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A3=B0=E9=9F=B3=E5=A4=B1=E7=9C=9F=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arm11/Makefile | 2 +- arm9/Makefile | 2 +- source/arm11/open_agb_firm.c | 52 ++++++++++++++++++++---------------- source/oaf_error_codes.c | 4 ++- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/arm11/Makefile b/arm11/Makefile index da84f68..f7536a6 100644 --- a/arm11/Makefile +++ b/arm11/Makefile @@ -25,7 +25,7 @@ SOURCES := ../libn3ds/kernel/source ../libn3ds/source ../libn3ds/source/drivers DATA := INCLUDES := ../libn3ds/include ../libn3ds/include/arm11 ../libn3ds/kernel/include ../libn3ds/thirdparty ../include \ ../thirdparty -DEFINES := -DARM11 -D_3DS -DVERS_STRING=\"$(VERS_STRING)\" \ +DEFINES := -DARM11 -D_3DS -DLIBN3DS_LEGACY=1 -DVERS_STRING=\"$(VERS_STRING)\" \ -DVERS_MAJOR=$(VERS_MAJOR) -DVERS_MINOR=$(VERS_MINOR) ASSETS := diff --git a/arm9/Makefile b/arm9/Makefile index bfab345..220d1d0 100644 --- a/arm9/Makefile +++ b/arm9/Makefile @@ -22,7 +22,7 @@ SOURCES := ../libn3ds/source ../libn3ds/source/drivers/mmc ../libn3ds/source/dr ../libn3ds/source/arm9/drivers ../libn3ds/thirdparty/fatfs ../source/arm9 DATA := INCLUDES := ../libn3ds/include ../libn3ds/include/arm9 ../libn3ds/thirdparty ../include ../thirdparty -DEFINES := -DARM9 -D_3DS -DVERS_STRING=\"$(VERS_STRING)\" \ +DEFINES := -DARM9 -D_3DS -DLIBN3DS_LEGACY=1 -DVERS_STRING=\"$(VERS_STRING)\" \ -DVERS_MAJOR=$(VERS_MAJOR) -DVERS_MINOR=$(VERS_MINOR) ifneq ($(strip $(NO_DEBUG)),) diff --git a/source/arm11/open_agb_firm.c b/source/arm11/open_agb_firm.c index ce9c9f5..ce0dd56 100644 --- a/source/arm11/open_agb_firm.c +++ b/source/arm11/open_agb_firm.c @@ -217,31 +217,35 @@ static u32 fixRomPadding(u32 romFileSize) // Pad unused ROM area with 0xFFs (trimmed ROMs). // Smallest retail ROM chip is 8 Mbit (1 MiB). u32 romSize = nextPow2(romFileSize); - if(romSize < 0x100000u) romSize = 0x100000u; - memset((void*)(LGY_ROM_LOC + romFileSize), 0xFFFFFFFFu, romSize - romFileSize); + if(romSize < 0x100000) romSize = 0x100000; + const uintptr_t romLoc = LGY_ROM_LOC; + memset((void*)(romLoc + romFileSize), 0xFFFFFFFF, romSize - romFileSize); - if(romSize > 0x100000u) // >1 MiB. + u32 mirroredSize = romSize; + if(romSize == 0x100000) // 1 MiB. { - // Fake "open bus" padding. - u32 padding = (LGY_ROM_LOC + romSize) / 2; - padding = __pkhbt(padding, padding + 1, 16); // Copy lower half + 1 to upper half. - for(uintptr_t i = LGY_ROM_LOC + romSize; i < LGY_ROM_LOC + LGY_MAX_ROM_SIZE; i += 4) + // ROM mirroring for Classic NES Series/others with 8 Mbit ROM. + // The ROM is mirrored exactly 4 times. + // Thanks to endrift for discovering this. + mirroredSize = 0x400000; // 4 MiB. + uintptr_t mirrorLoc = romLoc + romSize; + do { - *(u32*)i = padding; - padding = __uadd16(padding, 0x00020002u); // Unsigned parallel halfword-wise addition. - } - } - else - { - // ROM mirroring (Classic NES Series/possibly others with 8 Mbit ROM). - // Mirror ROM across the entire 32 MiB area. - for(uintptr_t i = LGY_ROM_LOC + romSize; i < LGY_ROM_LOC + LGY_MAX_ROM_SIZE; i += romSize) - { - //memcpy((void*)i, (void*)(i - romSize), romSize); // 0x23A15DD - memcpy((void*)i, (void*)LGY_ROM_LOC, romSize); // 0x237109B - } + memcpy((void*)mirrorLoc, (void*)romLoc, romSize); + mirrorLoc += romSize; + } while(mirrorLoc < romLoc + mirroredSize); } + // Fake "open bus" padding. + u32 padding = (romLoc + mirroredSize) / 2; + padding = __pkhbt(padding, padding + 1, 16); // Copy lower half + 1 to upper half. + for(uintptr_t i = romLoc + mirroredSize; i < romLoc + LGY_MAX_ROM_SIZE; i += 4) + { + *(u32*)i = padding; + padding = __uadd16(padding, 0x20002); // Unsigned parallel halfword-wise addition. + } + + // We don't return the mirrored size because the db hashes are over unmirrored dumps. return romSize; } @@ -284,12 +288,14 @@ static Result loadGbaRom(char * path, u32 *const romSizeOut) } { - // @MERGE 231006 END u8 *ptr = (u8*)LGY_ROM_LOC; u32 read; - while((res = fRead(f, ptr, 0x100000u, &read)) == RES_OK && read == 0x100000u) - ptr += 0x100000u; + // 貌似fatfs更新后,fread支持一次调用读取较大size的文件了 + // 然而经过测试,fRead并不能解决acl.c的问题。所以目前继续用fReadSize + res = fRead(f, (void*)ptr, fileSize, &read); + if( res != RES_OK ) return res; fClose(f); + // @MERGE 231006 END // use the gbaatm cheat if( g_oafConfig.cheatMode != CHEAT_MODE_DISABLED diff --git a/source/oaf_error_codes.c b/source/oaf_error_codes.c index e62cb3e..66b3988 100644 --- a/source/oaf_error_codes.c +++ b/source/oaf_error_codes.c @@ -39,7 +39,9 @@ const char* oafResult2String(Result res) #ifdef ARM11 void printError(Result res) { - ee_printf("Error: %s.\n", oafResult2String(res)); + // @MERGE 231006 START + ee_printf("Error<%ld>: %s.\n", res, oafResult2String(res)); + // @MERGE 231006 END } void printErrorWaitInput(Result res, u32 waitKeys)