Changeset 95c7526 in mainline


Ignore:
Timestamp:
2006-02-14T10:48:52Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fcbca14f
Parents:
fe050b7
Message:

Added untested support for 2 & 4-byte (15-bit & 24-bit depth) framebuffer.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • arch/mips32/src/console.c

    rfe050b7 r95c7526  
    4343                msim_console();
    4444#ifdef CONFIG_FB
    45         fb_init(0xb2000000, 640, 480);
     45        fb_init(0xb2000000, 640, 480, 3); // gxemul framebuffer
    4646#endif
    4747}
  • genarch/include/fb/fb.h

    rfe050b7 r95c7526  
    3333#include <arch/types.h>
    3434
    35 void fb_init(__address addr, int x, int y);
     35void fb_init(__address addr, int x, int y, int bytes);
    3636
    3737#endif
  • genarch/src/fb/fb.c

    rfe050b7 r95c7526  
    3535SPINLOCK_INITIALIZE(fb_lock);
    3636
    37 static unsigned char *fbaddress=NULL;
     37static __u8 *fbaddress=NULL;
    3838static int xres,yres;
    3939static int position=0;
    4040static int columns=0;
    4141static int rows=0;
     42static int pixelbytes=0;
    4243
    4344#define COL_WIDTH   8
    4445#define ROW_HEIGHT  (FONT_SCANLINES)
    45 #define ROW_PIX     (xres*ROW_HEIGHT*3)
     46#define ROW_PIX     (xres*ROW_HEIGHT*pixelbytes)
    4647
    4748#define BGCOLOR   0x000080
    4849#define FGCOLOR   0xffff00
    4950
    50 #define RED(x)    ((x >> 16) & 0xff)
    51 #define GREEN(x)  ((x >> 8) & 0xff)
    52 #define BLUE(x)   (x & 0xff)
    53 
    54 #define POINTPOS(x,y,colidx)   ((y*xres+x)*3+colidx)
     51#define RED(x,bits)    ((x >> (16+8-bits)) & ((1<<bits)-1))
     52#define GREEN(x,bits)  ((x >> (8+8-bits)) & ((1<<bits)-1))
     53#define BLUE(x,bits)   ((x >> (8-bits)) & ((1<<bits)-1))
     54
     55#define POINTPOS(x,y)   ((y*xres+x)*pixelbytes)
     56
     57/***************************************************************/
     58/* Pixel specific fuctions */
    5559
    5660/** Draw pixel of given color on screen */
    5761static inline void putpixel(int x,int y,int color)
    5862{
    59         fbaddress[POINTPOS(x,y,0)] = RED(color);
    60         fbaddress[POINTPOS(x,y,1)] = GREEN(color);
    61         fbaddress[POINTPOS(x,y,2)] = BLUE(color);
    62 }
    63 
    64 /** Fill line with color BGCOLOR */
    65 static void clear_line(int y)
    66 {
    67         int x;
    68         for (x=0; x<xres;x++)
    69                 putpixel(x,y,BGCOLOR);
    70 }
    71 
    72 /** Fill screen with background color */
    73 static void clear_screen(void)
    74 {
    75         int y;
    76 
    77         for (y=0; y<yres;y++)
    78                 clear_line(y);
    79 }
    80 
    81 static void invert_pixel(int x, int y)
    82 {
    83         fbaddress[POINTPOS(x,y,0)] = ~fbaddress[POINTPOS(x,y,0)];
    84         fbaddress[POINTPOS(x,y,1)] = ~fbaddress[POINTPOS(x,y,1)];
    85         fbaddress[POINTPOS(x,y,2)] = ~fbaddress[POINTPOS(x,y,2)];
    86 }
    87 
     63        int startbyte = POINTPOS(x,y);
     64
     65        if (pixelbytes == 3) {
     66                fbaddress[startbyte] = RED(color,8);
     67                fbaddress[startbyte+1] = GREEN(color,8);
     68                fbaddress[startbyte+2] = BLUE(color,8);
     69        } else if (pixelbytes == 4) {
     70                *((__u32 *)(fbaddress+startbyte)) = color;
     71        } else {
     72                int compcolor;
     73                /* 5-bit, 5-bits, 5-bits */
     74                compcolor = RED(color,5) << 10 \
     75                        | GREEN(color,5) << 5 \
     76                        | BLUE(color,5);
     77                *((__u16 *)(fbaddress+startbyte)) = compcolor;
     78        }
     79}
     80
     81/** Return pixel color */
     82static inline int getpixel(int x,int y)
     83{
     84        int startbyte = POINTPOS(x,y);
     85        int color;
     86        int result;
     87
     88        if (pixelbytes == 3) {
     89                result = fbaddress[startbyte] << 16 \
     90                        | fbaddress[startbyte+1] << 8 \
     91                        | fbaddress[startbyte+2];
     92        } else if (pixelbytes == 4) {
     93                result = *((__u32 *)(fbaddress+startbyte)) & 0xffffff;
     94        } else {
     95                int red,green,blue;
     96                color = *((__u16 *)(fbaddress+startbyte));
     97                red = (color >> 10) & 0x1f;
     98                green = (color >> 5) & 0x1f;
     99                blue = color & 0x1f;
     100                result = (red << 16) | (green << 8) | blue;
     101        }
     102        return result;
     103}
     104
     105static void clear_line(int y);
    88106/** Scroll screen one row up */
    89107static void scroll_screen(void)
     
    91109        int i;
    92110
    93         for (i=0;i < (xres*yres*3)-ROW_PIX; i++)
     111        for (i=0;i < (xres*yres*pixelbytes)-ROW_PIX; i++)
    94112                fbaddress[i] = fbaddress[i+ROW_PIX];
    95113
     
    99117       
    100118}
     119
     120
     121/***************************************************************/
     122/* Screen specific function */
     123
     124/** Fill line with color BGCOLOR */
     125static void clear_line(int y)
     126{
     127        int x;
     128        for (x=0; x<xres;x++)
     129                putpixel(x,y,BGCOLOR);
     130}
     131
     132/** Fill screen with background color */
     133static void clear_screen(void)
     134{
     135        int y;
     136
     137        for (y=0; y<yres;y++)
     138                clear_line(y);
     139}
     140
     141static void invert_pixel(int x, int y)
     142{
     143        putpixel(x,y, ~getpixel(x,y));
     144}
     145
    101146
    102147/** Draw one line of glyph at a given position */
     
    112157}
    113158
     159/***************************************************************/
     160/* Character-console functions */
     161
    114162/** Draw character at given position */
    115 static void draw_glyph(unsigned char glyph, int col, int row)
     163static void draw_glyph(__u8 glyph, int col, int row)
    116164{
    117165        int y;
     
    138186}
    139187
     188/***************************************************************/
     189/* Stdout specific functions */
     190
    140191static void invert_cursor(void)
    141192{
     
    162213                if (position % columns)
    163214                        position--;
     215        } else if (ch == '\t') {
     216                invert_cursor();
     217                do {
     218                        draw_char(' ');
     219                        position++;
     220                } while (position % 8);
    164221        } else {
    165222                draw_char(ch);
     
    185242 * @param x X resolution
    186243 * @param y Y resolution
     244 * @param bytes Bytes per pixel (2,3,4)
    187245 */
    188 void fb_init(__address addr, int x, int y)
     246void fb_init(__address addr, int x, int y, int bytes)
    189247{
    190248        fbaddress = (unsigned char *)addr;
     
    192250        xres = x;
    193251        yres = y;
     252        pixelbytes = bytes;
    194253       
    195254        rows = y/ROW_HEIGHT;
Note: See TracChangeset for help on using the changeset viewer.