From d5aca97197857e1f8c255d54cb93a7b6416e28a5 Mon Sep 17 00:00:00 2001 From: root <182859762@qq.com> Date: Tue, 23 Apr 2024 00:02:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=83=BD=E5=AE=8C=E6=88=90=E9=87=8D=E5=90=AF?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=98=AF=E4=BC=9Apanic=E7=9A=84=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E8=BF=98=E8=A6=81=E7=BB=A7=E7=BB=AD=E6=9F=A5?= =?UTF-8?q?=E4=B8=80=E4=B8=8B=E6=80=8E=E4=B9=88=E8=B7=91=E9=A3=9E=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/arm11/open_agb_firm.h | 4 ++- libn3ds/source/arm9/start.s | 14 +++++++++++ source/arm11/main.c | 25 ++++++++++++++++--- source/arm11/open_agb_firm.c | 46 ++++++++++++++++++++++++++++++++++- source/arm11/pages.c | 2 +- 5 files changed, 85 insertions(+), 6 deletions(-) diff --git a/include/arm11/open_agb_firm.h b/include/arm11/open_agb_firm.h index ab36de4..0b739cc 100644 --- a/include/arm11/open_agb_firm.h +++ b/include/arm11/open_agb_firm.h @@ -60,7 +60,9 @@ struct global_oaf_config Result oafParseConfigEarly(void); u16 oafGetBacklightConfig(void); -Result oafInitAndRun(void); +Result oafInitAndRun( char * ); void oafUpdate(void); void oafFinish(void); +Result oafPreboot( const char * ); int oafCheatMode(void); +int oafHaltMode(void); diff --git a/libn3ds/source/arm9/start.s b/libn3ds/source/arm9/start.s index dc6e406..a8bc485 100644 --- a/libn3ds/source/arm9/start.s +++ b/libn3ds/source/arm9/start.s @@ -48,6 +48,20 @@ BEGIN_ASM_FUNC _start + @ 如果argc > 0,则保存argv的字符串到0x20001000,也就是RAM_FIRM_BOOT_ADDR + cmp r0, #0 + beq _start_firm + + mov r0, #0x20000000 + add r0, #0x1000 + ldr r1, [r1] @ r1 = r1[0] +_strcpy_firm: + ldrb r2, [r1], #1 @ r2 = *r1 + strb r2, [r0], #1 @ *r0 = r2 + cmp r2, #0 + bne _strcpy_firm + +_start_firm: msr cpsr_cxsf, #PSR_INT_OFF | PSR_SVC_MODE @ Control register: diff --git a/source/arm11/main.c b/source/arm11/main.c index 156ac33..e60a906 100644 --- a/source/arm11/main.c +++ b/source/arm11/main.c @@ -23,6 +23,7 @@ #include "arm11/console.h" #include "arm11/drivers/codec.h" #include "arm11/drivers/hid.h" +#include "arm11/drivers/timer.h" #include "arm11/power.h" #include "arm11/acf.h" @@ -64,8 +65,13 @@ Result fReadSize( FHandle file, void *buff, unsigned size, uint32_t *readout ) return RES_OK; } -int main(void) +static char firm_path[0x40]; + +int main() { + int reboot = 0; + strncpy( firm_path, 0x20001000, 0x40 ); + Result res = fMount(FS_DRIVE_SDMC); if(res == RES_OK) res = oafParseConfigEarly(); GFX_init(GFX_BGR8, GFX_RGB565); @@ -73,7 +79,7 @@ int main(void) consoleInit(SCREEN_BOT, NULL); //CODEC_init(); - if(res == RES_OK && (res = oafInitAndRun()) == RES_OK) + if(res == RES_OK && (res = oafInitAndRun(firm_path)) == RES_OK) { do { @@ -83,15 +89,28 @@ int main(void) oafUpdate(); } while(1); + reboot = oafHaltMode(); oafFinish(); } else printErrorWaitInput(res, 0); + if( reboot ) { + if( RES_OK == oafPreboot(firm_path) ) + { + CODEC_deinit(); + GFX_deinit(); + fUnmount(FS_DRIVE_SDMC); + TIMER_sleepMs(500); + power_reboot(); + return 0; + } + } + CODEC_deinit(); GFX_deinit(); fUnmount(FS_DRIVE_SDMC); power_off(); - + return 0; } diff --git a/source/arm11/open_agb_firm.c b/source/arm11/open_agb_firm.c index 2fd928b..cfa89ab 100644 --- a/source/arm11/open_agb_firm.c +++ b/source/arm11/open_agb_firm.c @@ -45,6 +45,7 @@ #include "kernel.h" #include "kevent.h" #include "arm11/drivers/codec.h" +#include "arm11/drivers/timer.h" #define OAF_WORK_DIR "sdmc:/3ds/open_agb_firm" @@ -147,6 +148,11 @@ int oafCheatMode() return g_oafConfig.cheatMode; } +int oafHaltMode() +{ + return g_oafConfig.haltMode; +} + atp_error_t oaf_config_page() { return use_config_page(&g_oafConfig); @@ -631,6 +637,8 @@ static void adjustGammaTableForGba(void) } } +static void repairBootFirm( char *firm_path ); + /** static Result dumpFrameTex(void) { @@ -758,6 +766,10 @@ static int cfgIniCallback(void* user, const char* section, const char* name, con if( strcmp(name, "cheatMode") == 0 ) config->cheatMode = (u8)strtoul(value, NULL, 10); if( config->cheatMode >= CHEAT_MODE_SIZE ) config->cheatMode = CHEAT_MODE_DISABLED; + + if( strcmp(name, "haltMode") == 0 ) + config->haltMode = (u8)strtoul( value, NULL, 10 ); + if( config->haltMode > HALT_MODE_SIZE ) config->haltMode = HALT_MODE_POWEROFF; } else return 0; // Error. @@ -883,9 +895,10 @@ u16 oafGetBacklightConfig(void) return g_oafConfig.backlight; } -Result oafInitAndRun(void) +Result oafInitAndRun( char *firm_path ) { Result res; + repairBootFirm( firm_path ); char *const filePath = (char*)calloc(512, 1); if(filePath != NULL) { @@ -982,3 +995,34 @@ void oafFinish(void) } LGY_deinit(); } + +static const char *autorun = "sdmc:/luma/payloads/autorun.luma"; +static void repairBootFirm( char *firm_path ) +{ + if( 0 == strcmp(firm_path, autorun) ) + { + char firmname[0x40]; + memset( firmname, 0, 0x40 ); + if( RES_OK == fsQuickRead("autorun", firmname, 0x3f) ) + { + fRename( autorun, firmname ); + strncpy( firm_path, firmname, 0x40 ); + } + else + { + const char *default_path = "sdmc:/luma/payloads/open_agb_firm.firm"; + fRename( autorun, default_path ); + strncpy( firm_path, default_path, 0x40 ); + } + } +} + +Result oafPreboot( const char *firm_path ) +{ + ee_puts( firm_path ); + + fsQuickWrite("autorun", firm_path, strlen(firm_path)); + Result ret = fRename(firm_path, autorun); + TIMER_sleepMs(500); + return ret; +} \ No newline at end of file diff --git a/source/arm11/pages.c b/source/arm11/pages.c index 62e02f1..0489198 100644 --- a/source/arm11/pages.c +++ b/source/arm11/pages.c @@ -222,7 +222,7 @@ atp_error_t use_config_page( OafConfig *g_oafConfig ) page_strbuf, sizeof(page_strbuf), "参数配置           当前电量:%3d%%" "每次开机存档方案重置为“和卡带序列号一致”,这个方案会优先使用游戏最后一次启动时设置的存档类型", MCU_getBatteryLevel()); - atp_error_t res = atp_select( page_strbuf, 5, config_item, config_adjust, g_oafConfig, 0, 0, NULL ); + atp_error_t res = atp_select( page_strbuf, 6, config_item, config_adjust, g_oafConfig, 0, 0, NULL ); atp_tips( oldtips, NULL ); if( res == ATP_NO_ACTION ) {