From 988d7d5307d80098682187d61c7812aab4f3a488 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Sat, 25 Jun 2016 17:30:40 -0400 Subject: [PATCH] Background support. These should be 90 degree rotated RGB8 pixel data. They go at the locations: /corbenik/bits/top.bin /corbenik/bits/bottom.bin --- source/main.c | 4 ++++ source/screeninit.c | 3 --- source/std/draw.c | 58 ++++++++++++++++++++++++++++++++++++++------- source/std/draw.h | 4 ++++ 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/source/main.c b/source/main.c index 9788ded..34de34b 100644 --- a/source/main.c +++ b/source/main.c @@ -20,6 +20,10 @@ main(int argc, char** argv) int c = fmount(); screen_init(); + 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(); set_font(PATH_BITS "/termfont.bin"); diff --git a/source/screeninit.c b/source/screeninit.c index 2dfc0d1..81cc4c8 100644 --- a/source/screeninit.c +++ b/source/screeninit.c @@ -26,7 +26,4 @@ screen_init() // Turn on backlight i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A); } - - // Flush garbage off the FB. - clear_screens(); } diff --git a/source/std/draw.c b/source/std/draw.c index fb4c930..49327a0 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -27,6 +27,32 @@ 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]; + +void clear_bg() { + memset(top_bg, 0, TOP_SIZE); + memset(bottom_bg, 0, BOTTOM_SIZE); +} + +void load_bg_top(char* fname_top) { + FILE* f = fopen(fname_top, "r"); + if (!f) return; + + fread(top_bg, 1, TOP_SIZE, f); + + fclose(f); +} + +void load_bg_bottom(char* fname_bottom) { + FILE* f = fopen(fname_bottom, "r"); + if (!f) + return; + + fread(bottom_bg, 1, BOTTOM_SIZE, f); + fclose(f); +} + void set_font(const char* filename) { // TODO - Unicode support. Right now, we only load 32 @@ -107,15 +133,16 @@ clear_disp(uint8_t *screen) screen = framebuffers->bottom; if (screen == framebuffers->top_left || screen == framebuffers->top_right) { - memset(screen, 0, TOP_SIZE); + memcpy(screen, top_bg, TOP_SIZE); } else if (screen == framebuffers->bottom) { - memset(screen, 0, BOTTOM_SIZE); + memcpy(screen, bottom_bg, BOTTOM_SIZE); } } void clear_screen(uint8_t *screen) { + // TODO - remove. This is a stub now. clear_disp(screen); } @@ -146,12 +173,15 @@ draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, co _UNUSED int width = 0; int height = 0; + uint8_t* buffer_bg; if (screen == framebuffers->top_left || screen == framebuffers->top_right) { width = TOP_WIDTH; height = TOP_HEIGHT; + buffer_bg = top_bg; } else if (screen == framebuffers->bottom) { width = BOTTOM_WIDTH; height = BOTTOM_HEIGHT; + buffer_bg = bottom_bg; } else { return; // Invalid buffer. } @@ -170,14 +200,26 @@ draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, co unsigned int pos = xDisplacement + yDisplacement; 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++) { - screen[pos] = color_bg >> 16; - screen[pos + 1] = color_bg >> 8; - screen[pos + 2] = color_bg; + if (color_bg == 0) { + screen[pos] = buffer_bg[pos]; + screen[pos + 1] = buffer_bg[pos + 1]; + screen[pos + 2] = buffer_bg[pos + 2]; + } else { + screen[pos] = color_bg >> 16; + screen[pos + 1] = color_bg >> 8; + screen[pos + 2] = color_bg; + } if (char_dat & 0x80) { - screen[pos] = color_fg >> 16; - screen[pos + 1] = color_fg >> 8; - screen[pos + 2] = color_fg; + if (color_fg == 0) { + screen[pos] = buffer_bg[pos]; + screen[pos + 1] = buffer_bg[pos + 1]; + screen[pos + 2] = buffer_bg[pos + 2]; + } else { + screen[pos] = color_fg >> 16; + screen[pos + 1] = color_fg >> 8; + screen[pos + 2] = color_fg; + } } char_dat <<= 1; diff --git a/source/std/draw.h b/source/std/draw.h index a066ff9..40d9ea7 100644 --- a/source/std/draw.h +++ b/source/std/draw.h @@ -37,6 +37,10 @@ _UNUSED static struct framebuffers #define TOP_FB framebuffers->top_left #define BOTTOM_FB framebuffers->bottom +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); -- 2.39.5