]> Chaos Git - corbenik/corbenik.git/commitdiff
Clean up static buffers in favor of a static allocation function using high fcram
authorchaoskagami <chaos.kagami@gmail.com>
Wed, 29 Jun 2016 22:47:03 +0000 (18:47 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Wed, 29 Jun 2016 22:47:03 +0000 (18:47 -0400)
source/firm/fcram.c
source/firm/fcram.h
source/main.c
source/std/draw.c
source/std/draw.h
source/std/fs.c

index 6ab1f67220c411f9cc4d82283959e280b1593d58..1949451d9a68119eb8d77c4c7556a68117cfa9ef 100644 (file)
@@ -1,3 +1,11 @@
 #include "fcram.h"
 
 void *fcram_temp = (void *)0x23000000;
+
+void *fcram_static_mem = (void*)FCRAM_STATIC_ALLOC_LOC;
+void *static_allocate(size_t bytes) {
+    size_t aligned_bytes = bytes + (4 - (bytes % 4)); // Align to integer size (for ARM processor)
+    void *ret = fcram_static_mem;
+    fcram_static_mem += aligned_bytes;
+    return ret;
+}
index 3ca5fb12e1ddec1e94c622b938fc12c9541a3820..7413a87bcc299a2d729e30d87e1326db8d8df2f2 100644 (file)
@@ -5,6 +5,7 @@
 // It provides an easy overview of all that is used.
 
 #include <stdint.h>
+#include <stddef.h>
 
 #include "../std/unused.h"
 
@@ -39,4 +40,10 @@ extern void *fcram_temp;
 // Path that the menu for chains will be at
 #define FCRAM_CHAIN_LOC (FCRAM_FONT_LOC + FCRAM_SPACING)
 
+// Location to perform static allocations at.
+#define FCRAM_STATIC_ALLOC_LOC (0x25000000)
+
+// Allocate static memory.
+void *static_allocate(size_t bytes);
+
 #endif
index 34de34be14183000c4959b2cf96785f3b4a9c1b2..c6dd2d8cae7caf9835f0a3d34d6508400b67fc24 100644 (file)
@@ -18,6 +18,8 @@ main(int argc, char** argv)
     if (PDN_MPCORE_CFG == 7)
         is_n3ds = 1; // Enable n3ds specific options.
 
+    std_init();
+
     int c = fmount();
     screen_init();
     clear_bg();
index 04470b3ed4397369f0fa8cd8e9a668166a2a2d30..422698a2ead690fd1029e1550d351b82e60b8a68 100644 (file)
 static unsigned int top_cursor_x = 0, top_cursor_y = 0;
 static unsigned int bottom_cursor_x = 0, bottom_cursor_y = 0;
 
+#define LOG_BUFFER_SIZE 4096
+
 static size_t  log_size = 0;
-static char    log_buffer[4096]; // Log buffer.
+static char*   log_buffer; // Log buffer.
 
 unsigned int font_w = 8;
 unsigned int font_h = 8;
@@ -27,8 +29,14 @@ static unsigned int text_top_height = 10;
 static unsigned int text_bottom_width = 20;
 static unsigned int text_bottom_height = 10;
 
-uint8_t top_bg[TOP_SIZE];
-uint8_t bottom_bg[BOTTOM_SIZE];
+uint8_t *top_bg;
+uint8_t *bottom_bg;
+
+void std_init() {
+    top_bg     = static_allocate(TOP_SIZE);
+    bottom_bg  = static_allocate(BOTTOM_SIZE);
+    log_buffer = static_allocate(LOG_BUFFER_SIZE);
+}
 
 static uint32_t colors[16] = {
     0x000000, // Black
@@ -193,7 +201,7 @@ void dump_log(unsigned int force) {
     if(!config.options[OPTION_SAVE_LOGS])
         return;
 
-    if (force == 0 && log_size < sizeof(log_buffer)-1)
+    if (force == 0 && log_size < LOG_BUFFER_SIZE-1)
         return;
 
     if (log_size == 0)
index de24ff7c10752dc5e0b1d37791ebe6b726671409..d26d26c5465f4d2dec30f3060aac0dfe8e8f8370 100644 (file)
@@ -41,6 +41,8 @@ void screenshot();
 void rect(void* channel, int x, int y, int x2, int y2, uint8_t color);
 void fill_line(void* channel, int y, uint8_t color);
 
+void std_init();
+
 void clear_bg();
 void load_bg_top(char* fname_top);
 void load_bg_bottom(char* fname_bottom);
index 22d26667e65e57700fe3c288229f87bcdd8ce69e..c7a1f3f483d73103eee4ed5bccbf366359278234 100644 (file)
@@ -8,7 +8,7 @@
 
 static FATFS fs;
 
-static FILE files[MAX_FILES_OPEN];
+FILE files[MAX_FILES_OPEN];
 
 // This function is based on PathDeleteWorker from GodMode9.
 // It was easier to just import it.