fbcon-mfb.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:5k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/drivers/video/mfb.c -- Low level frame buffer operations for
  3.  *  monochrome
  4.  *
  5.  * Created 5 Apr 1997 by Geert Uytterhoeven
  6.  *
  7.  *  This file is subject to the terms and conditions of the GNU General Public
  8.  *  License.  See the file COPYING in the main directory of this archive for
  9.  *  more details.
  10.  */
  11. #include <linux/module.h>
  12. #include <linux/tty.h>
  13. #include <linux/console.h>
  14. #include <linux/string.h>
  15. #include <linux/fb.h>
  16. #include <video/fbcon.h>
  17. #include <video/fbcon-mfb.h>
  18.     /*
  19.      *  Monochrome
  20.      */
  21. void fbcon_mfb_setup(struct display *p)
  22. {
  23.     if (p->line_length)
  24. p->next_line = p->line_length;
  25.     else
  26. p->next_line = p->var.xres_virtual>>3;
  27.     p->next_plane = 0;
  28. }
  29. void fbcon_mfb_bmove(struct display *p, int sy, int sx, int dy, int dx,
  30.      int height, int width)
  31. {
  32.     u8 *src, *dest;
  33.     u_int rows;
  34.     if (sx == 0 && dx == 0 && width == p->next_line) {
  35. src = p->screen_base+sy*fontheight(p)*width;
  36. dest = p->screen_base+dy*fontheight(p)*width;
  37. fb_memmove(dest, src, height*fontheight(p)*width);
  38.     } else if (dy <= sy) {
  39. src = p->screen_base+sy*fontheight(p)*p->next_line+sx;
  40. dest = p->screen_base+dy*fontheight(p)*p->next_line+dx;
  41. for (rows = height*fontheight(p); rows--;) {
  42.     fb_memmove(dest, src, width);
  43.     src += p->next_line;
  44.     dest += p->next_line;
  45. }
  46.     } else {
  47. src = p->screen_base+((sy+height)*fontheight(p)-1)*p->next_line+sx;
  48. dest = p->screen_base+((dy+height)*fontheight(p)-1)*p->next_line+dx;
  49. for (rows = height*fontheight(p); rows--;) {
  50.     fb_memmove(dest, src, width);
  51.     src -= p->next_line;
  52.     dest -= p->next_line;
  53. }
  54.     }
  55. }
  56. void fbcon_mfb_clear(struct vc_data *conp, struct display *p, int sy, int sx,
  57.      int height, int width)
  58. {
  59.     u8 *dest;
  60.     u_int rows;
  61.     int inverse = conp ? attr_reverse(p,conp->vc_video_erase_char) : 0;
  62.     dest = p->screen_base+sy*fontheight(p)*p->next_line+sx;
  63.     if (sx == 0 && width == p->next_line) {
  64. if (inverse)
  65.     fb_memset255(dest, height*fontheight(p)*width);
  66. else
  67.     fb_memclear(dest, height*fontheight(p)*width);
  68.     } else
  69. for (rows = height*fontheight(p); rows--; dest += p->next_line)
  70.     if (inverse)
  71. fb_memset255(dest, width);
  72.     else
  73. fb_memclear_small(dest, width);
  74. }
  75. void fbcon_mfb_putc(struct vc_data *conp, struct display *p, int c, int yy,
  76.     int xx)
  77. {
  78.     u8 *dest, *cdat;
  79.     u_int rows, bold, revs, underl;
  80.     u8 d;
  81.     dest = p->screen_base+yy*fontheight(p)*p->next_line+xx;
  82.     cdat = p->fontdata+(c&p->charmask)*fontheight(p);
  83.     bold = attr_bold(p,c);
  84.     revs = attr_reverse(p,c);
  85.     underl = attr_underline(p,c);
  86.     for (rows = fontheight(p); rows--; dest += p->next_line) {
  87. d = *cdat++;
  88. if (underl && !rows)
  89.     d = 0xff;
  90. else if (bold)
  91.     d |= d>>1;
  92. if (revs)
  93.     d = ~d;
  94.      fb_writeb (d, dest);
  95.     }
  96. }
  97. void fbcon_mfb_putcs(struct vc_data *conp, struct display *p, 
  98.      const unsigned short *s, int count, int yy, int xx)
  99. {
  100.     u8 *dest, *dest0, *cdat;
  101.     u_int rows, bold, revs, underl;
  102.     u8 d;
  103.     u16 c;
  104.     dest0 = p->screen_base+yy*fontheight(p)*p->next_line+xx;
  105.     c = scr_readw(s);
  106.     bold = attr_bold(p, c);
  107.     revs = attr_reverse(p, c);
  108.     underl = attr_underline(p, c);
  109.     while (count--) {
  110. c = scr_readw(s++) & p->charmask;
  111. dest = dest0++;
  112. cdat = p->fontdata+c*fontheight(p);
  113. for (rows = fontheight(p); rows--; dest += p->next_line) {
  114.     d = *cdat++;
  115.     if (underl && !rows)
  116. d = 0xff;
  117.     else if (bold)
  118. d |= d>>1;
  119.     if (revs)
  120. d = ~d;
  121.          fb_writeb (d, dest);
  122. }
  123.     }
  124. }
  125. void fbcon_mfb_revc(struct display *p, int xx, int yy)
  126. {
  127.     u8 *dest, d;
  128.     u_int rows;
  129.     dest = p->screen_base+yy*fontheight(p)*p->next_line+xx;
  130.     for (rows = fontheight(p); rows--; dest += p->next_line) {
  131.      d = fb_readb(dest);
  132. fb_writeb (~d, dest);
  133.     }
  134. }
  135. void fbcon_mfb_clear_margins(struct vc_data *conp, struct display *p,
  136.      int bottom_only)
  137. {
  138.     u8 *dest;
  139.     int height, bottom;
  140.     int inverse = conp ? attr_reverse(p,conp->vc_video_erase_char) : 0;
  141.     /* XXX Need to handle right margin? */
  142.     height = p->var.yres - conp->vc_rows * fontheight(p);
  143.     if (!height)
  144. return;
  145.     bottom = conp->vc_rows + p->yscroll;
  146.     if (bottom >= p->vrows)
  147. bottom -= p->vrows;
  148.     dest = p->screen_base + bottom * fontheight(p) * p->next_line;
  149.     if (inverse)
  150. fb_memset255(dest, height * p->next_line);
  151.     else
  152. fb_memclear(dest, height * p->next_line);
  153. }
  154.     /*
  155.      *  `switch' for the low level operations
  156.      */
  157. struct display_switch fbcon_mfb = {
  158.     setup: fbcon_mfb_setup,
  159.     bmove: fbcon_mfb_bmove,
  160.     clear: fbcon_mfb_clear,
  161.     putc: fbcon_mfb_putc,
  162.     putcs: fbcon_mfb_putcs,
  163.     revc: fbcon_mfb_revc,
  164.     clear_margins: fbcon_mfb_clear_margins,
  165.     fontwidthmask: FONTWIDTH(8)
  166. };
  167. #ifdef MODULE
  168. MODULE_LICENSE("GPL");
  169. int init_module(void)
  170. {
  171.     return 0;
  172. }
  173. void cleanup_module(void)
  174. {}
  175. #endif /* MODULE */
  176.     /*
  177.      *  Visible symbols for modules
  178.      */
  179. EXPORT_SYMBOL(fbcon_mfb);
  180. EXPORT_SYMBOL(fbcon_mfb_setup);
  181. EXPORT_SYMBOL(fbcon_mfb_bmove);
  182. EXPORT_SYMBOL(fbcon_mfb_clear);
  183. EXPORT_SYMBOL(fbcon_mfb_putc);
  184. EXPORT_SYMBOL(fbcon_mfb_putcs);
  185. EXPORT_SYMBOL(fbcon_mfb_revc);
  186. EXPORT_SYMBOL(fbcon_mfb_clear_margins);