From: chaoskagami Date: Wed, 29 Jun 2016 22:47:03 +0000 (-0400) Subject: Clean up static buffers in favor of a static allocation function using high fcram X-Git-Tag: v0.2.0~53 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=b4169d2b4bd22dea3b34e15719be12c18369ad10;p=corbenik%2Fcorbenik.git Clean up static buffers in favor of a static allocation function using high fcram --- diff --git a/source/firm/fcram.c b/source/firm/fcram.c index 6ab1f67..1949451 100644 --- a/source/firm/fcram.c +++ b/source/firm/fcram.c @@ -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; +} diff --git a/source/firm/fcram.h b/source/firm/fcram.h index 3ca5fb1..7413a87 100644 --- a/source/firm/fcram.h +++ b/source/firm/fcram.h @@ -5,6 +5,7 @@ // It provides an easy overview of all that is used. #include +#include #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 diff --git a/source/main.c b/source/main.c index 34de34b..c6dd2d8 100644 --- a/source/main.c +++ b/source/main.c @@ -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(); diff --git a/source/std/draw.c b/source/std/draw.c index 04470b3..422698a 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -14,8 +14,10 @@ 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) diff --git a/source/std/draw.h b/source/std/draw.h index de24ff7..d26d26c 100644 --- a/source/std/draw.h +++ b/source/std/draw.h @@ -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); diff --git a/source/std/fs.c b/source/std/fs.c index 22d2666..c7a1f3f 100644 --- a/source/std/fs.c +++ b/source/std/fs.c @@ -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.