Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/include/dev/fbcon.h b/include/dev/fbcon.h
- index 5466ee9..99904ca 100755
- --- a/include/dev/fbcon.h
- +++ b/include/dev/fbcon.h
- @@ -54,6 +54,15 @@ enum fbcon_rotation {
- ROTATE_180,
- };
- +struct fbcon_font {
- + uint8_t font_width;
- + uint8_t font_height;
- + uint8_t font_fshift;
- + uint8_t font_padding;
- + const unsigned char *font_data;
- +};
- +
- struct fbcon_config {
- void *base;
- unsigned width;
- diff --git a/dev/fbcon/fbcon.c b/dev/fbcon/fbcon.c
- index 1dc97b6..a3dcc87 100755
- --- a/dev/fbcon/fbcon.c
- +++ b/dev/fbcon/fbcon.c
- @@ -36,6 +36,7 @@
- #include <kernel/thread.h>
- #include "font_8x8.h"
- +#include "font_8x16.h"
- struct pos {
- int x;
- @@ -45,9 +46,9 @@ struct pos {
- static void fbcon_draw_glyph_0(unsigned char c);
- static void fbcon_scroll_up_0(void);
- static struct fbcon_private {
- struct fbcon_config *config;
- + struct fbcon_font *font_ptr;
- void (*draw_glyph)(unsigned char c);
- void (*scroll_up)(void);
- uint16_t bg_color;
- @@ -56,10 +57,21 @@ static struct fbcon_private {
- struct pos max_position;
- } fbcon = {
- .config = NULL,
- + .font_ptr = NULL,
- .draw_glyph = fbcon_draw_glyph_0,
- .scroll_up = fbcon_scroll_up_0,
- };
- static void fbcon_flush(void)
- {
- if (fbcon.config->update_start)
- @@ -70,19 +82,21 @@ static void fbcon_flush(void)
- static void fbcon_draw_glyph_180(unsigned char c)
- {
- + if (!fbcon.font_ptr)
- + return;
- uint16_t *pixels =
- fbcon.config->base +
- fbcon.config->width * fbcon.config->height * (fbcon.config->bpp >> 3);
- - pixels -= fbcon.position.y * FONT_HEIGHT * fbcon.config->width;
- - pixels -= (fbcon.position.x * (FONT_WIDTH + 1) + 1);
- + pixels -= fbcon.position.y * fbcon.font_ptr->font_height * fbcon.config->width;
- + pixels -= (fbcon.position.x * (fbcon.font_ptr->font_width + 1) + 1);
- unsigned stride = fbcon.config->stride;
- - stride -= FONT_WIDTH;
- + stride -= fbcon.font_ptr->font_width;
- int x, y;
- - for (y = 0; y < FONT_HEIGHT; y++) {
- - for (x = FONT_WIDTH - 1; x >= 0; x--) {
- - if (fontdata_8x8[(c << 3) + y] & (1 << x))
- + for (y = 0; y < fbcon.font_ptr->font_height; y++) {
- + for (x = fbcon.font_ptr->font_width - 1; x >= 0; x--) {
- + if (fbcon.font_ptr->font_data[(c << fbcon.font_ptr->font_fshift) + y] & (1 << x))
- *pixels = fbcon.fg_color;
- pixels--;
- }
- @@ -92,16 +106,16 @@ static void fbcon_draw_glyph_180(unsigned char c)
- static void fbcon_draw_glyph_0(unsigned char c) {
- uint16_t *pixels = fbcon.config->base;
- - pixels += fbcon.position.y * FONT_HEIGHT * fbcon.config->width;
- - pixels += (fbcon.position.x * (FONT_WIDTH + 1) + 1);
- + pixels += fbcon.position.y * fbcon.font_ptr->font_height * fbcon.config->width;
- + pixels += (fbcon.position.x * (fbcon.font_ptr->font_width + 1) + 1);
- unsigned stride = fbcon.config->stride;
- - stride -= FONT_WIDTH;
- + stride -= fbcon.font_ptr->font_width;
- int x, y;
- - for (y = 0; y < FONT_HEIGHT; y++) {
- - for (x = FONT_WIDTH - 1; x >= 0; x--) {
- - if (fontdata_8x8[(c << 3) + y] & (1 << x))
- + for (y = 0; y < fbcon.font_ptr->font_height; y++) {
- + for (x = fbcon.font_ptr->font_width - 1; x >= 0; x--) {
- + if (fbcon.font_ptr->font_data[(c << fbcon.font_ptr->font_fshift) + y] & (1 << x))
- *pixels = fbcon.fg_color;
- pixels++;
- }
- @@ -115,8 +129,8 @@ static void fbcon_scroll_up_180(void)
- unsigned short *dst =
- fbcon.config->base +
- fbcon.config->width * fbcon.config->height * (fbcon.config->bpp >> 3);
- - unsigned short *src = dst - (fbcon.config->width * FONT_HEIGHT);
- - unsigned count = fbcon.config->width * (fbcon.config->height - FONT_HEIGHT);
- + unsigned short *src = dst - (fbcon.config->width * fbcon.font_ptr->font_height);
- + unsigned count = fbcon.config->width * (fbcon.config->height - fbcon.font_ptr->font_height);
- while (count--) {
- *dst-- = *src--;
- }
- @@ -216,6 +231,8 @@ void fbcon_setup(struct fbcon_config *_config)
- ASSERT(0);
- break;
- }
- +
- + fbcon.font_ptr = (struct fbcon_font *) &font_8x16;
- if (fbcon.config->rotation == ROTATE_180) {
- fbcon.scroll_up = fbcon_scroll_up_180;
- @@ -224,8 +241,8 @@ void fbcon_setup(struct fbcon_config *_config)
- fbcon.position.x = 0;
- fbcon.position.y = 0;
- - fbcon.max_position.x = fbcon.config->width / (FONT_WIDTH + 1);
- - fbcon.max_position.y = (fbcon.config->height - 1) / FONT_HEIGHT;
- + fbcon.max_position.x = fbcon.config->width / (fbcon.font_ptr->font_width + 1);
- + fbcon.max_position.y = (fbcon.config->height - 1) / fbcon.font_ptr->font_height;
- fbcon_clear();
- }
- diff --git a/dev/fbcon/font_8x8.h b/dev/fbcon/font_8x8.h
- index 4ef36cf..124820f 100755
- --- a/dev/fbcon/font_8x8.h
- +++ b/dev/fbcon/font_8x8.h
- @@ -1,13 +1,6 @@
- -/**********************************************/
- -/* */
- -/* Font file generated by cpi2fnt */
- -/* */
- -/**********************************************/
- +#include <dev/fbcon.h>
- -#define FONT_WIDTH 8
- -#define FONT_HEIGHT 8
- -
- -static const unsigned char fontdata_8x8[] = {
- +const unsigned char fontdata_8x8[] = {
- /* 32 0x20 ' ' */
- 0x00, /* 00000000 */
- @@ -970,3 +963,10 @@ static const unsigned char fontdata_8x8[] = {
- 0x00, /* 00000000 */
- };
- +struct fbcon_font font_8x8 = {
- + .font_width = 8,
- + .font_height = 8,
- + .font_fshift = 3,
- + .font_padding = 0,
- + .font_data = (const unsigned char *) &fontdata_8x8,
- +};
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement