From ef73faf65218fe47cffc51a188fda129abc6ad63 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Wed, 17 Aug 2016 10:44:02 -0400 Subject: [PATCH] Minor tweaks --- external/loader/source/loader.c | 2 +- external/loader/source/lzss.h | 6 ---- include/arm11.h | 5 +++ {external/loader/source => include}/lzss.c | 11 +++--- include/option.h | 3 ++ source/arm11.c | 10 ++++-- source/firm/firm.c | 5 ++- source/main.c | 41 ++++++++++++---------- 8 files changed, 46 insertions(+), 37 deletions(-) delete mode 100644 external/loader/source/lzss.h rename {external/loader/source => include}/lzss.c (88%) diff --git a/external/loader/source/loader.c b/external/loader/source/loader.c index 5353073..609aa9f 100644 --- a/external/loader/source/loader.c +++ b/external/loader/source/loader.c @@ -5,7 +5,7 @@ #include "fsreg.h" #include "pxipm.h" #include "srvsys.h" -#include "lzss.h" +#include #include "internal.h" #include "logger.h" diff --git a/external/loader/source/lzss.h b/external/loader/source/lzss.h deleted file mode 100644 index 5ab8b82..0000000 --- a/external/loader/source/lzss.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __LZSS_H -#define __LZSS_H - -int lzss_decompress(u8 *buffer); - -#endif diff --git a/include/arm11.h b/include/arm11.h index 4dfeac4..f7c2a21 100644 --- a/include/arm11.h +++ b/include/arm11.h @@ -45,5 +45,10 @@ // Inits the screen if needed. void screen_mode(uint32_t mode); +void invokeArm11Function(void (*func)()); +void deinitScreens(void); +void updateBrightness(uint32_t brightnessIndex); +void clearScreens(void); +void installArm11Stub(void); #endif diff --git a/external/loader/source/lzss.c b/include/lzss.c similarity index 88% rename from external/loader/source/lzss.c rename to include/lzss.c index 7ca6e0b..c2f02de 100644 --- a/external/loader/source/lzss.c +++ b/include/lzss.c @@ -1,14 +1,11 @@ -#include <3ds.h> +#ifndef __LZSS_H +#define __LZSS_H -// TODO - In the future, why not ADD code compression modes? Like, zlib, for example. Or lzss+zlib. - -int +static int lzss_decompress(u8 *buffer) { // This WAS originally a decompilation in @yifan_lu's repo; it was rewritten // for readability following ctrtool's namings. - // You can thank me for making it more readable if you'd like; I don't - // really care. Did it for myself. unsigned int decompSize, v15; u8 *compressEndOff, *index, *stopIndex; char control; @@ -55,3 +52,5 @@ lzss_decompress(u8 *buffer) return ret; } + +#endif diff --git a/include/option.h b/include/option.h index fb864d7..30d86bb 100644 --- a/include/option.h +++ b/include/option.h @@ -121,6 +121,9 @@ struct options_s // (e.g. SaltySD) #define OPTION_LOADER_LOADCODE 21 +// Silenced autoboot will not init the screen. +#define OPTION_SILENT_NOSCREEN 22 + // Calculate EmuNAND at the back of the disk, rather than the front. // There's many good reasons for this to be supported: // - Resizable FAT partition diff --git a/source/arm11.c b/source/arm11.c index 2115a2c..f8566aa 100644 --- a/source/arm11.c +++ b/source/arm11.c @@ -53,8 +53,7 @@ void __attribute__((naked)) arm11Stub(void) ((void (*)())*arm11Entry)(); } -static void invokeArm11Function(void (*func)()) -{ +void installArm11Stub(void) { static int hasCopiedStub = false; if(!hasCopiedStub) { @@ -62,6 +61,11 @@ static void invokeArm11Function(void (*func)()) ctr_cache_clean_and_flush_all(); hasCopiedStub = true; } +} + +void invokeArm11Function(void (*func)()) +{ + installArm11Stub(); *arm11Entry = (uint32_t)func; while(*arm11Entry); @@ -78,11 +82,13 @@ void deinitScreens(void) //Shutdown LCDs *(volatile uint32_t *)0x10202A44 = 0; *(volatile uint32_t *)0x10202244 = 0; + *(volatile uint32_t *)0x1020200C = 0; *(volatile uint32_t *)0x10202014 = 0; WAIT_FOR_ARM9(); } + // If screen is initialized, invoke. if(PDN_GPU_CNT != 1) invokeArm11Function(ARM11); } diff --git a/source/firm/firm.c b/source/firm/firm.c index 1be1a4d..171dc36 100644 --- a/source/firm/firm.c +++ b/source/firm/firm.c @@ -473,9 +473,8 @@ boot_firm() // No fprintf will work from here on out. - *a11_entry = (uint32_t)arm11_preboot_halt; - while (*a11_entry) - ; // Make sure it jumped there correctly before changing it. + deinitScreens(); + *a11_entry = (uint32_t)firm_loc->a11Entry; ((void (*)())firm_loc->a9Entry)(); diff --git a/source/main.c b/source/main.c index c0fd59e..d33d131 100644 --- a/source/main.c +++ b/source/main.c @@ -22,38 +22,41 @@ main(int argc, char** argv) if (fmount()) poweroff(); // Failed to mount SD. Bomb out. - set_font(PATH_TERMFONT); // Read the font before all else. - load_config(); // Load configuration. + install_interrupts(); // Get some free debug info. + + installArm11Stub(); + + if (CFG_BOOTENV == 7) + config->options[OPTION_EMUNAND] = 0; // Disable EmuNAND on AGB reboot. + + if (config->options[OPTION_AUTOBOOT] && !(ctr_hid_get_buttons() & CTR_HID_RT)) { + doing_autoboot = 1; + + if (config->options[OPTION_SILENCE] || config->options[OPTION_SILENT_NOSCREEN]) + shut_up(); // This does exactly what it sounds like. + + if (config->options[OPTION_SILENT_NOSCREEN]) + boot_cfw(); // Skip all other checks and just boot. + } + + set_font(PATH_TERMFONT); // Read the font before all else. + + // Check key down for autoboot screen_mode(RGBA8); // Use RGBA8 mode. clear_bg(); load_bg_top (PATH_TOP_BG); - load_bg_bottom(PATH_BOTTOM_BG); // This is basically a menuhax splash (90deg rotated BGR8 pixel data) + load_bg_bottom(PATH_BOTTOM_BG); // This is a menuhax splash (90deg rotated BGR8 pixel data) clear_disp(TOP_SCREEN); clear_disp(BOTTOM_SCREEN); -// ctr_screen_enable_backlight(CTR_SCREEN_BOTH); - -// install_interrupts(); // Get some free debug info. - - if (CFG_BOOTENV == 7) { - fprintf(stderr, "Rebooted from AGB, disabling EmuNAND.\n"); - config->options[OPTION_EMUNAND] = 0; - } - // Autoboot. Non-standard code path. - if (config->options[OPTION_AUTOBOOT] && !(ctr_hid_get_buttons() & CTR_HID_RT)) { - if (config->options[OPTION_SILENCE]) - shut_up(); // This does exactly what it sounds like. - doing_autoboot = 1; - } else { + if (!doing_autoboot) menu_handler(); - } boot_cfw(); - // Under ideal conditions, we never get here. } -- 2.39.5