From: chaoskagami Date: Tue, 27 Dec 2016 02:36:39 +0000 (-0500) Subject: Resolve #48 X-Git-Tag: v0.3.1~45 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=bb396533e4637f7f613c8a4d573317eb18216482;p=corbenik%2Fcorbenik.git Resolve #48 Allocate framebuffer before screeninit, and only initialize screen before entering menu (or showing splash) --- diff --git a/include/arm11.h b/include/arm11.h index 83981f2..983cbd9 100644 --- a/include/arm11.h +++ b/include/arm11.h @@ -73,4 +73,8 @@ void clearScreens(void); */ void installArm11Stub(void); +/* Sets up framebuffer offsets independent of screeninit. + */ +void set_fb_struct(); + #endif diff --git a/include/std/draw.h b/include/std/draw.h index 82fa6bc..7242380 100644 --- a/include/std/draw.h +++ b/include/std/draw.h @@ -71,14 +71,16 @@ void clear_bg(void); /* Loads top background image from a path. * * \param fname_top filename to load from. + * \return 1 if background loaded */ -void load_bg_top(const char* fname_top); +int load_bg_top(const char* fname_top); /* Loads bottom background image from a path. * * \param fname_bottom filename to load from. + * \return 1 if background loaded */ -void load_bg_bottom(const char* fname_bottom); +int load_bg_bottom(const char* fname_bottom); /* Clears the displays either to black or the background image. */ diff --git a/source/arm11.c b/source/arm11.c index bb7148d..d5e8593 100644 --- a/source/arm11.c +++ b/source/arm11.c @@ -143,6 +143,20 @@ void clearScreens(void) { invokeArm11Function(ARM11); } +void set_fb_struct() { + if (!framebuffers) { + // Look ma, dynamically allocating the CakeHax struct! (joking) + // We literally just discard the previous state - for sanity's sake. + // On chainload, it is needed to copy the framebuffer struct. + framebuffers = memalign(16, sizeof(struct framebuffers)); + + // Set not-actually cakebrah framebuffers. Meh. + framebuffers->top_left = (uint8_t *)0x18300000; + framebuffers->top_right = (uint8_t *)0x18300000; + framebuffers->bottom = (uint8_t *)0x1835dc00; + } +} + void screen_mode(uint32_t mode) { static uint32_t stride, init_top, init_bottom, bright; @@ -164,13 +178,6 @@ void screen_mode(uint32_t mode) { init_top = MAKE_FRAMEBUFFER_PIXFMT(mode, 0, 1); init_bottom = MAKE_FRAMEBUFFER_PIXFMT(mode, 0, 0); - if (!framebuffers) { - // Look ma, dynamically allocating the CakeHax struct! (joking) - // We literally just discard the previous state - for sanity's sake. - // On chainload, it is needed to copy the framebuffer struct. - framebuffers = memalign(16, sizeof(struct framebuffers)); - } - void __attribute__((naked)) ARM11(void) { //Disable interrupts __asm(".word 0xF10C01C0"); @@ -260,11 +267,6 @@ void screen_mode(uint32_t mode) { PDC1_FRAMEBUFFER_SETUP_FBA_ADDR_1 = 0x1835dc00; PDC1_FRAMEBUFFER_SETUP_FBA_ADDR_2 = 0x1835dc00; - // Set not-actually cakebrah framebuffers. Meh. - framebuffers->top_left = (uint8_t *)0x18300000; - framebuffers->top_right = (uint8_t *)0x18300000; - framebuffers->bottom = (uint8_t *)0x1835dc00; - WAIT_FOR_ARM9(); } diff --git a/source/main.c b/source/main.c index 9dfe557..42c552d 100644 --- a/source/main.c +++ b/source/main.c @@ -17,6 +17,9 @@ extern int changed_consoles; int main(int argc, char** argv) { + int have_bg = 0; + int si = 0; + int r_held = (ctr_hid_get_buttons() & CTR_HID_RT); if (PDN_MPCORE_CFG == 7) @@ -39,12 +42,13 @@ main(int argc, char** argv) set_font(PATH_TERMFONT); // Read the font before all else. // Check key down for autoboot - screen_mode(RGBA8); // Use RGBA8 mode. + set_fb_struct(); clear_bg(); - load_bg_top (PATH_TOP_BG); - load_bg_bottom(PATH_BOTTOM_BG); // This is a menuhax splash (90deg rotated BGR8 pixel data) + // This is a menuhax splash (90deg rotated BGR8 pixel data) + if (load_bg_top(PATH_TOP_BG) || load_bg_bottom(PATH_BOTTOM_BG)) + have_bg = 1; clear_disp(TOP_SCREEN); clear_disp(BOTTOM_SCREEN); @@ -55,7 +59,16 @@ main(int argc, char** argv) if (get_opt_u32(OPTION_SILENCE)) shut_up(); // This does exactly what it sounds like. + + if (have_bg && !si) { + screen_mode(RGBA8); // Use RGBA8 mode. + si = 1; + } } else { + if (!si) { + screen_mode(RGBA8); // Use RGBA8 mode. + si = 1; + } menu_handler(); } diff --git a/source/std/draw.c b/source/std/draw.c index 2294e0d..bd5c12c 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -156,27 +156,31 @@ void clear_bg(void) { memset(bottom_bg, 0, BOTTOM_SIZE); } -void load_bg_top(const char* fname_top) { +int load_bg_top(const char* fname_top) { FILE* f = cropen(fname_top, "r"); - if (!f) return; + if (!f) return 0; for (int i=1; i < TOP_SIZE; i += 4) { crread(&top_bg[i], 1, 3, f); } crclose(f); + + return 1; } -void load_bg_bottom(const char* fname_bottom) { +int load_bg_bottom(const char* fname_bottom) { FILE* f = cropen(fname_bottom, "r"); if (!f) - return; + return 0; for (int i=1; i < BOTTOM_SIZE; i += 4) { crread(&bottom_bg[i], 1, 3, f); } crclose(f); + + return 1; } void set_font(const char* filename) {