]> Chaos Git - corbenik/corbenik.git/commitdiff
Resolve #48
authorchaoskagami <chaos.kagami@gmail.com>
Tue, 27 Dec 2016 02:36:39 +0000 (21:36 -0500)
committerchaoskagami <chaos.kagami@gmail.com>
Tue, 27 Dec 2016 02:36:39 +0000 (21:36 -0500)
Allocate framebuffer before screeninit, and only initialize screen before entering menu (or showing splash)

include/arm11.h
include/std/draw.h
source/arm11.c
source/main.c
source/std/draw.c

index 83981f255d658b274eaeade2114efa344d780fc2..983cbd989bf168a65d9c69fca5ed4e0a281afc31 100644 (file)
@@ -73,4 +73,8 @@ void clearScreens(void);
  */
 void installArm11Stub(void);
 
+/* Sets up framebuffer offsets independent of screeninit.
+ */
+void set_fb_struct();
+
 #endif
index 82fa6bc3dae655b067c2037cccbaef9377553bda..7242380670fd2857d98a3824fca3e50520bd4f2c 100644 (file)
@@ -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.
  */
index bb7148de6827c2fae3e1ad0ce0fbc8de4f35cc9c..d5e859336f6d80bdd8ef7cfc4ac7be8184189fce 100644 (file)
@@ -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();
     }
 
index 9dfe5573944b71cd15694a27eb006aefb02e342e..42c552de4e40b53050fdd3c0b02efa9d8adc28b6 100644 (file)
@@ -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();
         }
 
index 2294e0d727be30c2562bed6d5e0c7e8049017123..bd5c12c61d87048d5afe951408bd7ae5e5806cd4 100644 (file)
@@ -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) {