Advertisement
Guest User

Untitled

a guest
Apr 18th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. diff --git a/include/dev/fbcon.h b/include/dev/fbcon.h
  2. index 5466ee9..99904ca 100755
  3. --- a/include/dev/fbcon.h
  4. +++ b/include/dev/fbcon.h
  5. @@ -54,6 +54,15 @@ enum fbcon_rotation {
  6. ROTATE_180,
  7. };
  8.  
  9. +struct fbcon_font {
  10. + uint8_t font_width;
  11. + uint8_t font_height;
  12. + uint8_t font_fshift;
  13. + uint8_t font_padding;
  14. + const unsigned char *font_data;
  15. +};
  16. +
  17. struct fbcon_config {
  18. void *base;
  19. unsigned width;
  20.  
  21. diff --git a/dev/fbcon/fbcon.c b/dev/fbcon/fbcon.c
  22. index 1dc97b6..a3dcc87 100755
  23. --- a/dev/fbcon/fbcon.c
  24. +++ b/dev/fbcon/fbcon.c
  25. @@ -36,6 +36,7 @@
  26. #include <kernel/thread.h>
  27.  
  28. #include "font_8x8.h"
  29. +#include "font_8x16.h"
  30.  
  31. struct pos {
  32. int x;
  33. @@ -45,9 +46,9 @@ struct pos {
  34. static void fbcon_draw_glyph_0(unsigned char c);
  35. static void fbcon_scroll_up_0(void);
  36.  
  37. static struct fbcon_private {
  38. struct fbcon_config *config;
  39. + struct fbcon_font *font_ptr;
  40. void (*draw_glyph)(unsigned char c);
  41. void (*scroll_up)(void);
  42. uint16_t bg_color;
  43. @@ -56,10 +57,21 @@ static struct fbcon_private {
  44. struct pos max_position;
  45. } fbcon = {
  46. .config = NULL,
  47. + .font_ptr = NULL,
  48. .draw_glyph = fbcon_draw_glyph_0,
  49. .scroll_up = fbcon_scroll_up_0,
  50. };
  51.  
  52. static void fbcon_flush(void)
  53. {
  54. if (fbcon.config->update_start)
  55. @@ -70,19 +82,21 @@ static void fbcon_flush(void)
  56.  
  57. static void fbcon_draw_glyph_180(unsigned char c)
  58. {
  59. + if (!fbcon.font_ptr)
  60. + return;
  61. uint16_t *pixels =
  62. fbcon.config->base +
  63. fbcon.config->width * fbcon.config->height * (fbcon.config->bpp >> 3);
  64. - pixels -= fbcon.position.y * FONT_HEIGHT * fbcon.config->width;
  65. - pixels -= (fbcon.position.x * (FONT_WIDTH + 1) + 1);
  66. + pixels -= fbcon.position.y * fbcon.font_ptr->font_height * fbcon.config->width;
  67. + pixels -= (fbcon.position.x * (fbcon.font_ptr->font_width + 1) + 1);
  68. unsigned stride = fbcon.config->stride;
  69. - stride -= FONT_WIDTH;
  70. + stride -= fbcon.font_ptr->font_width;
  71.  
  72. int x, y;
  73.  
  74. - for (y = 0; y < FONT_HEIGHT; y++) {
  75. - for (x = FONT_WIDTH - 1; x >= 0; x--) {
  76. - if (fontdata_8x8[(c << 3) + y] & (1 << x))
  77. + for (y = 0; y < fbcon.font_ptr->font_height; y++) {
  78. + for (x = fbcon.font_ptr->font_width - 1; x >= 0; x--) {
  79. + if (fbcon.font_ptr->font_data[(c << fbcon.font_ptr->font_fshift) + y] & (1 << x))
  80. *pixels = fbcon.fg_color;
  81. pixels--;
  82. }
  83. @@ -92,16 +106,16 @@ static void fbcon_draw_glyph_180(unsigned char c)
  84.  
  85. static void fbcon_draw_glyph_0(unsigned char c) {
  86. uint16_t *pixels = fbcon.config->base;
  87. - pixels += fbcon.position.y * FONT_HEIGHT * fbcon.config->width;
  88. - pixels += (fbcon.position.x * (FONT_WIDTH + 1) + 1);
  89. + pixels += fbcon.position.y * fbcon.font_ptr->font_height * fbcon.config->width;
  90. + pixels += (fbcon.position.x * (fbcon.font_ptr->font_width + 1) + 1);
  91. unsigned stride = fbcon.config->stride;
  92. - stride -= FONT_WIDTH;
  93. + stride -= fbcon.font_ptr->font_width;
  94.  
  95. int x, y;
  96.  
  97. - for (y = 0; y < FONT_HEIGHT; y++) {
  98. - for (x = FONT_WIDTH - 1; x >= 0; x--) {
  99. - if (fontdata_8x8[(c << 3) + y] & (1 << x))
  100. + for (y = 0; y < fbcon.font_ptr->font_height; y++) {
  101. + for (x = fbcon.font_ptr->font_width - 1; x >= 0; x--) {
  102. + if (fbcon.font_ptr->font_data[(c << fbcon.font_ptr->font_fshift) + y] & (1 << x))
  103. *pixels = fbcon.fg_color;
  104. pixels++;
  105. }
  106. @@ -115,8 +129,8 @@ static void fbcon_scroll_up_180(void)
  107. unsigned short *dst =
  108. fbcon.config->base +
  109. fbcon.config->width * fbcon.config->height * (fbcon.config->bpp >> 3);
  110. - unsigned short *src = dst - (fbcon.config->width * FONT_HEIGHT);
  111. - unsigned count = fbcon.config->width * (fbcon.config->height - FONT_HEIGHT);
  112. + unsigned short *src = dst - (fbcon.config->width * fbcon.font_ptr->font_height);
  113. + unsigned count = fbcon.config->width * (fbcon.config->height - fbcon.font_ptr->font_height);
  114. while (count--) {
  115. *dst-- = *src--;
  116. }
  117.  
  118. @@ -216,6 +231,8 @@ void fbcon_setup(struct fbcon_config *_config)
  119. ASSERT(0);
  120. break;
  121. }
  122. +
  123. + fbcon.font_ptr = (struct fbcon_font *) &font_8x16;
  124.  
  125. if (fbcon.config->rotation == ROTATE_180) {
  126. fbcon.scroll_up = fbcon_scroll_up_180;
  127. @@ -224,8 +241,8 @@ void fbcon_setup(struct fbcon_config *_config)
  128.  
  129. fbcon.position.x = 0;
  130. fbcon.position.y = 0;
  131. - fbcon.max_position.x = fbcon.config->width / (FONT_WIDTH + 1);
  132. - fbcon.max_position.y = (fbcon.config->height - 1) / FONT_HEIGHT;
  133. + fbcon.max_position.x = fbcon.config->width / (fbcon.font_ptr->font_width + 1);
  134. + fbcon.max_position.y = (fbcon.config->height - 1) / fbcon.font_ptr->font_height;
  135. fbcon_clear();
  136. }
  137.  
  138. diff --git a/dev/fbcon/font_8x8.h b/dev/fbcon/font_8x8.h
  139. index 4ef36cf..124820f 100755
  140. --- a/dev/fbcon/font_8x8.h
  141. +++ b/dev/fbcon/font_8x8.h
  142. @@ -1,13 +1,6 @@
  143. -/**********************************************/
  144. -/* */
  145. -/* Font file generated by cpi2fnt */
  146. -/* */
  147. -/**********************************************/
  148. +#include <dev/fbcon.h>
  149.  
  150. -#define FONT_WIDTH 8
  151. -#define FONT_HEIGHT 8
  152. -
  153. -static const unsigned char fontdata_8x8[] = {
  154. +const unsigned char fontdata_8x8[] = {
  155.  
  156. /* 32 0x20 ' ' */
  157. 0x00, /* 00000000 */
  158. @@ -970,3 +963,10 @@ static const unsigned char fontdata_8x8[] = {
  159. 0x00, /* 00000000 */
  160. };
  161.  
  162. +struct fbcon_font font_8x8 = {
  163. + .font_width = 8,
  164. + .font_height = 8,
  165. + .font_fshift = 3,
  166. + .font_padding = 0,
  167. + .font_data = (const unsigned char *) &fontdata_8x8,
  168. +};
  169. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement