]> Chaos Git - corbenik/corbenik.git/commitdiff
Make dimmer optional (since it's buggy atm)
authorchaoskagami <chaos.kagami@gmail.com>
Fri, 1 Jul 2016 13:54:08 +0000 (09:54 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Fri, 1 Jul 2016 13:54:20 +0000 (09:54 -0400)
source/config.h
source/display.c
source/main.c
source/menu.c
source/std/draw.c
source/std/draw.h

index 9de4341bcde0598c47d4067859b09ef2a8284a14..54b692827a3622ee7d04a40a8a880636940c7fca 100644 (file)
@@ -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
index ba9303fa298d7fae6eacaa571c34a7785fe32787..ffcd83d6931288f9b328d8010ab50ca501c4865a 100644 (file)
@@ -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);
         }
     }
 
index c6dd2d8cae7caf9835f0a3d34d6508400b67fc24..a32a418188dbe0276944b152d6c029fbaf057a04 100644 (file)
@@ -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");
 
index caafcc934ef7bdaa456b15d669c4e8bc87308bea..6f47c32b9154c50671247a07d221096743028706 100644 (file)
@@ -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 },
index 461a37b40fb53d27f14ef3b3ae385d02694a883f..f6bd45d6f2754e4e13dc5611d4d28deb726ab948 100644 (file)
@@ -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
index d26d26c5465f4d2dec30f3060aac0dfe8e8f8370..4a4024206247bdb7051dd52bceff083c61ddce33 100644 (file)
@@ -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);