Home | History | Annotate | Download | only in arch_msm7k
      1 /*
      2  * Copyright (c) 2008, Google Inc.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *  * Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  *  * Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in
     12  *    the documentation and/or other materials provided with the
     13  *    distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
     22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <boot/boot.h>
     30 #include <boot/font5x12.h>
     31 
     32 static unsigned short BGCOLOR = 0x001F;
     33 static unsigned short FGCOLOR = 0xFFFF;
     34 
     35 static void drawglyph(unsigned short *pixels, unsigned short paint,
     36                       unsigned stride, unsigned *glyph)
     37 {
     38     unsigned x, y, data;
     39     stride -= 5;
     40 
     41     data = glyph[0];
     42     for(y = 0; y < 6; y++) {
     43         for(x = 0; x < 5; x++) {
     44             if(data & 1) *pixels = paint;
     45             data >>= 1;
     46             pixels++;
     47         }
     48         pixels += stride;
     49     }
     50     data = glyph[1];
     51     for(y = 0; y < 6; y++) {
     52         for(x = 0; x < 5; x++) {
     53             if(data & 1) *pixels = paint;
     54             data >>= 1;
     55             pixels++;
     56         }
     57         pixels += stride;
     58     }
     59 }
     60 
     61 #if 0
     62 static void drawtext(unsigned x, unsigned y, unsigned paint, const char *text)
     63 {
     64     unsigned short *pixels = mddi_framebuffer();
     65     unsigned stride = fb_width;
     66     char c;
     67 
     68     while((c = *text++)) {
     69         if((c < ' ') || (c > 127)) continue;
     70         c = (c - 32) * 2;
     71         drawglyph(pixels + y*stride + x, paint, stride, font5x12 + c);
     72         x += 6;
     73     }
     74 }
     75 #endif
     76 
     77 static int cx, cy, cmaxx, cmaxy;
     78 
     79 void console_clear(void)
     80 {
     81     unsigned short *dst = mddi_framebuffer();
     82     unsigned count = fb_width * fb_height;
     83     cx = 0;
     84     cy = 0;
     85     while(count--) *dst++ = BGCOLOR;
     86 }
     87 
     88 static void scroll_up(void)
     89 {
     90     unsigned short *dst = mddi_framebuffer();
     91     unsigned short *src = dst + (fb_width * 12);
     92     unsigned count = fb_height * (fb_width - 12);
     93 
     94     while(count--) {
     95         *dst++ = *src++;
     96     }
     97     count = fb_width * 12;
     98     while(count--) {
     99         *dst++ = BGCOLOR;
    100     }
    101 }
    102 
    103 void console_putc(unsigned c)
    104 {
    105     unsigned short *pixels;
    106 
    107     if(c > 127) return;
    108     if(c < 32) {
    109         if(c == '\n') goto newline;
    110         return;
    111     }
    112 
    113     pixels = mddi_framebuffer();
    114     drawglyph(pixels + cy * 12 * fb_width + cx * 6, FGCOLOR,
    115               fb_width, font5x12 + (c - 32) * 2);
    116 
    117     cx++;
    118     if(cx < cmaxx) return;
    119 
    120 newline:
    121     cy++;
    122     cx = 0;
    123     if(cy >= cmaxy) {
    124         cy = cmaxy - 1;
    125         scroll_up();
    126     }
    127 }
    128 
    129 void console_flush(void)
    130 {
    131 	mddi_start_update();
    132 	while(!mddi_update_done()) ;
    133 }
    134 
    135 void console_set_colors(unsigned bg, unsigned fg)
    136 {
    137     BGCOLOR = bg;
    138     FGCOLOR = fg;
    139 }
    140 
    141 void console_init(void)
    142 {
    143     mddi_init();
    144 
    145     cmaxx = fb_width / 6;
    146     cmaxy = (fb_height-1) / 12;
    147     cx = 0;
    148     cy = 0;
    149 
    150     console_clear();
    151     console_flush();
    152 }
    153 
    154