From: chaoskagami Date: Fri, 1 Jul 2016 13:54:08 +0000 (-0400) Subject: Make dimmer optional (since it's buggy atm) X-Git-Tag: v0.2.0~45 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=89f412bfdaed87409b490b964826fa091a528965;p=corbenik%2Fcorbenik.git Make dimmer optional (since it's buggy atm) --- diff --git a/source/config.h b/source/config.h index 9de4341..54b6928 100644 --- a/source/config.h +++ b/source/config.h @@ -74,7 +74,10 @@ struct options_s #define OPTION_TRACE 7 // Freed up options due to code changes. -// 8, 9, 10 +// 9, 10 + +// Dim background for readability. +#define OPTION_DIM_MODE 8 // Enable L2 cache. #define OPTION_LOADER_CPU_L2 11 diff --git a/source/display.c b/source/display.c index ba9303f..ffcd83d 100644 --- a/source/display.c +++ b/source/display.c @@ -9,7 +9,7 @@ extern int is_n3ds; extern unsigned int font_h; void show_help(char* help) { - clear_screen(TOP_SCREEN); + clear_disp(TOP_SCREEN); set_cursor(TOP_SCREEN, 0, 0); header("Any:Back"); fprintf(stdout, "%s", help); @@ -27,7 +27,7 @@ show_menu(struct options_s *options, uint8_t *toggles) int window_top = 0, window_bottom = window_size; int less_mode = 0; - clear_screen(TOP_SCREEN); + clear_disp(TOP_SCREEN); if (options[0].index == -1) { set_cursor(TOP_SCREEN, 0, 0); @@ -157,7 +157,7 @@ show_menu(struct options_s *options, uint8_t *toggles) ((func_call_t)(options[cursor_y].a))(options[cursor_y].b); // Call 'a' as a function. } else if (options[cursor_y].allowed == break_menu) { exit = 1; - clear_screen(TOP_SCREEN); + clear_disp(TOP_SCREEN); cursor_y = cursor_min; } break; @@ -171,13 +171,13 @@ show_menu(struct options_s *options, uint8_t *toggles) break; case BUTTON_B: exit = 1; - clear_screen(TOP_SCREEN); + clear_disp(TOP_SCREEN); cursor_y = cursor_min; break; case BUTTON_SEL: if (options[cursor_y].desc[0] != 0) { show_help(options[cursor_y].desc); - clear_screen(TOP_SCREEN); + clear_disp(TOP_SCREEN); } break; } @@ -190,12 +190,12 @@ show_menu(struct options_s *options, uint8_t *toggles) if (cursor_y < window_top + cursor_min) { window_top = cursor_y - cursor_min; window_bottom = window_top + window_size; - clear_screen(TOP_SCREEN); + clear_disp(TOP_SCREEN); } else if (cursor_y > window_bottom - cursor_min) { window_bottom = cursor_y + cursor_min; window_top = window_bottom - window_size; - clear_screen(TOP_SCREEN); + clear_disp(TOP_SCREEN); } } diff --git a/source/main.c b/source/main.c index c6dd2d8..a32a418 100644 --- a/source/main.c +++ b/source/main.c @@ -25,7 +25,8 @@ main(int argc, char** argv) clear_bg(); load_bg_top(PATH_BITS "/top.bin"); load_bg_bottom(PATH_BITS "/bottom.bin"); // This is basically a menuhax splash (90deg rotated RGB8 pixel data) - clear_screens(); + clear_disp(TOP_SCREEN); + clear_disp(BOTTOM_SCREEN); set_font(PATH_BITS "/termfont.bin"); diff --git a/source/menu.c b/source/menu.c index caafcc9..6f47c32 100644 --- a/source/menu.c +++ b/source/menu.c @@ -21,6 +21,7 @@ static struct options_s options[] = { { OPTION_AUTOBOOT, "Autoboot", "Boot the system automatically, unless the R key is held while booting.", boolean_val, 0, 0 }, { OPTION_SILENCE, " Silent mode", "Suppress all debug output during autoboot. You'll see the screen turn on and then off once.", boolean_val, 0, 0 }, + { OPTION_DIM_MODE, "Dim Background", "Experimental! Dims colors on lighter backgrounds to improve readability with text. You won't notice the change until scrolling or exiting the current menu due to the way rendering works.", boolean_val, 0, 0 }, // space { 0, "", "", not_option, 0, 0 }, diff --git a/source/std/draw.c b/source/std/draw.c index 461a37b..f6bd45d 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -39,6 +39,8 @@ unsigned char color_top = 0xf0; unsigned char color_bottom = 0xf0; int kill_output = 0; +#define TRANSP_THRESH 178 + void std_init() { top_bg = static_allocate(TOP_SIZE); bottom_bg = static_allocate(BOTTOM_SIZE); @@ -170,8 +172,8 @@ void load_bg_top(char* fname_top) { // See load_bg_bottom for an explanation on the magic value. dim_factor_top = 0; - if (max > 178) - dim_factor_top = max - 178; + if (max > TRANSP_THRESH) + dim_factor_top = max - TRANSP_THRESH; } void load_bg_bottom(char* fname_bottom) { @@ -196,8 +198,8 @@ void load_bg_bottom(char* fname_bottom) { // 70% of 255 is approximately 178, and 255 - 178 is 77. That's therefore the maximum we want to subtract. // Thus this is the value for 70% transparency. dim_factor_bottom = 0; - if (max > 178) - dim_factor_bottom = max - 178; + if (max > TRANSP_THRESH) + dim_factor_bottom = max - TRANSP_THRESH; } void set_font(const char* filename) { @@ -261,19 +263,32 @@ clear_disp(uint8_t *screen) screen = framebuffers->bottom; if (screen == framebuffers->top_left || screen == framebuffers->top_right) { - memcpy(screen, top_bg, TOP_SIZE); + if (kill_output || !config.options[OPTION_DIM_MODE]) { + memcpy(screen, top_bg, TOP_SIZE); + } else { + for(int i=0; i < TOP_SIZE; i++) { + screen[i] = 0; + if (top_bg[i] > dim_factor_top) + screen[i] = top_bg[i] - dim_factor_top; + } + } + top_cursor_x = 0; + top_cursor_y = 0; } else if (screen == framebuffers->bottom) { - memcpy(screen, bottom_bg, BOTTOM_SIZE); + if (kill_output || !config.options[OPTION_DIM_MODE]) { + memcpy(screen, bottom_bg, BOTTOM_SIZE); + } else { + for(int i=0; i < BOTTOM_SIZE; i++) { + screen[i] = 0; + if (bottom_bg[i] >= dim_factor_bottom) + screen[i] = bottom_bg[i] - dim_factor_bottom; + } + } + bottom_cursor_x = 0; + bottom_cursor_y = 0; } } -void -clear_screen(uint8_t *screen) -{ - // TODO - remove. This is a stub now. - clear_disp(screen); -} - void set_cursor(void *channel, unsigned int x, unsigned int y) { @@ -286,13 +301,6 @@ set_cursor(void *channel, unsigned int x, unsigned int y) } } -void -clear_screens() -{ - clear_screen(framebuffers->top_left); - clear_screen(framebuffers->bottom); -} - void draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, const uint32_t color_fg, const uint32_t color_bg) { @@ -332,23 +340,11 @@ draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, co unsigned char char_dat = ((char*)FCRAM_FONT_LOC)[(character - ' ') * (c_font_w * font_h) + yy]; for(unsigned int i=0; i < font_w + font_kern; i++) { if (color_bg == 0) { - screen[pos] = 0; - screen[pos + 1] = 0; - screen[pos + 2] = 0; - if (buffer_bg[pos] >= dim_factor) - screen[pos] = buffer_bg[pos] - dim_factor; - if (buffer_bg[pos + 1] >= dim_factor) - screen[pos + 1] = buffer_bg[pos + 1] - dim_factor; - if (buffer_bg[pos + 2] >= dim_factor) - screen[pos + 2] = buffer_bg[pos + 2] - dim_factor; - } else { - screen[pos] = color_bg >> 16; - screen[pos + 1] = color_bg >> 8; - screen[pos + 2] = color_bg; - } - - if (char_dat & 0x80) { - if (color_fg == 0) { + if (!config.options[OPTION_DIM_MODE]) { + screen[pos] = buffer_bg[pos]; + screen[pos + 1] = buffer_bg[pos + 1]; + screen[pos + 2] = buffer_bg[pos + 2]; + } else { screen[pos] = 0; screen[pos + 1] = 0; screen[pos + 2] = 0; @@ -358,6 +354,30 @@ draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, co screen[pos + 1] = buffer_bg[pos + 1] - dim_factor; if (buffer_bg[pos + 2] >= dim_factor) screen[pos + 2] = buffer_bg[pos + 2] - dim_factor; + } + } else { + screen[pos] = color_bg >> 16; + screen[pos + 1] = color_bg >> 8; + screen[pos + 2] = color_bg; + } + + if (char_dat & 0x80) { + if (color_fg == 0) { + if (!config.options[OPTION_DIM_MODE]) { + screen[pos] = buffer_bg[pos]; + screen[pos + 1] = buffer_bg[pos + 1]; + screen[pos + 2] = buffer_bg[pos + 2]; + } else { + screen[pos] = 0; + screen[pos + 1] = 0; + screen[pos + 2] = 0; + if (buffer_bg[pos] >= dim_factor) + screen[pos] = buffer_bg[pos] - dim_factor; + if (buffer_bg[pos + 1] >= dim_factor) + screen[pos + 1] = buffer_bg[pos + 1] - dim_factor; + if (buffer_bg[pos + 2] >= dim_factor) + screen[pos + 2] = buffer_bg[pos + 2] - dim_factor; + } } else { screen[pos] = color_fg >> 16; screen[pos + 1] = color_fg >> 8; @@ -375,6 +395,8 @@ void shut_up() { kill_output = !kill_output; + clear_disp(TOP_SCREEN); + clear_disp(BOTTOM_SCREEN); } void diff --git a/source/std/draw.h b/source/std/draw.h index d26d26c..4a40242 100644 --- a/source/std/draw.h +++ b/source/std/draw.h @@ -47,7 +47,6 @@ void clear_bg(); void load_bg_top(char* fname_top); void load_bg_bottom(char* fname_bottom); -void clear_screen(uint8_t *screen); void clear_screens(); void draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, const uint32_t color_fg, const uint32_t color_bg);