Subversion Repositories HelenOS-historic

Rev

Rev 838 | Rev 862 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 838 Rev 839
Line 28... Line 28...
28
 
28
 
29
#include <genarch/fb/font-8x16.h>
29
#include <genarch/fb/font-8x16.h>
30
#include <genarch/fb/fb.h>
30
#include <genarch/fb/fb.h>
31
#include <console/chardev.h>
31
#include <console/chardev.h>
32
#include <console/console.h>
32
#include <console/console.h>
33
#include <print.h>
33
#include <panic.h>
34
 
34
 
35
SPINLOCK_INITIALIZE(fb_lock);
35
SPINLOCK_INITIALIZE(fb_lock);
36
 
36
 
37
static __u8 *fbaddress=NULL;
37
static __u8 *fbaddress=NULL;
38
static int xres,yres;
38
static int xres,yres;
Line 55... Line 55...
55
#define POINTPOS(x,y)   ((y*xres+x)*pixelbytes)
55
#define POINTPOS(x,y)   ((y*xres+x)*pixelbytes)
56
 
56
 
57
/***************************************************************/
57
/***************************************************************/
58
/* Pixel specific fuctions */
58
/* Pixel specific fuctions */
59
 
59
 
-
 
60
static void (*putpixel)(int x,int y,int color);
-
 
61
static int (*getpixel)(int x,int y);
-
 
62
 
60
/** Draw pixel of given color on screen */
63
/** Put pixel - 24-bit depth, 1 free byte */
61
static inline void putpixel(int x,int y,int color)
64
static void putpixel_4byte(int x,int y,int color)
62
{
65
{
63
    int startbyte = POINTPOS(x,y);
66
    int startbyte = POINTPOS(x,y);
64
 
67
 
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;
68
    *((__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
}
69
}
80
 
70
 
81
/** Return pixel color */
71
/** Return pixel color */
82
static inline int getpixel(int x,int y)
72
static int getpixel_4byte(int x,int y)
-
 
73
{
-
 
74
    int startbyte = POINTPOS(x,y);
-
 
75
 
-
 
76
    return *((__u32 *)(fbaddress+startbyte)) & 0xffffff;
-
 
77
}
-
 
78
 
-
 
79
/** Draw pixel of given color on screen - 24-bit depth */
-
 
80
static void putpixel_3byte(int x,int y,int color)
-
 
81
{
-
 
82
    int startbyte = POINTPOS(x,y);
-
 
83
 
-
 
84
    fbaddress[startbyte] = RED(color,8);
-
 
85
    fbaddress[startbyte+1] = GREEN(color,8);
-
 
86
    fbaddress[startbyte+2] = BLUE(color,8);
-
 
87
}
-
 
88
 
-
 
89
static int getpixel_3byte(int x,int y)
83
{
90
{
84
    int startbyte = POINTPOS(x,y);
91
    int startbyte = POINTPOS(x,y);
85
    int color;
-
 
86
    int result;
92
    int result;
87
 
93
 
88
    if (pixelbytes == 3) {
-
 
89
        result = fbaddress[startbyte] << 16 \
94
    result = fbaddress[startbyte] << 16 \
90
            | fbaddress[startbyte+1] << 8 \
95
        | fbaddress[startbyte+1] << 8 \
91
            | fbaddress[startbyte+2];
96
        | 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;
97
    return result;
103
}
98
}
104
 
99
 
-
 
100
/** Put pixel - 16-bit depth (5:6:6) */
-
 
101
static void putpixel_2byte(int x,int y,int color)
-
 
102
{
-
 
103
    int startbyte = POINTPOS(x,y);
-
 
104
    int compcolor;
-
 
105
 
-
 
106
    /* 5-bit, 5-bits, 5-bits */
-
 
107
    compcolor = RED(color,5) << 11 \
-
 
108
        | GREEN(color,6) << 5 \
-
 
109
        | BLUE(color,5);
-
 
110
    *((__u16 *)(fbaddress+startbyte)) = compcolor;
-
 
111
}
-
 
112
 
-
 
113
static int getpixel_2byte(int x,int y)
-
 
114
{
-
 
115
    int startbyte = POINTPOS(x,y);
-
 
116
    int color;
-
 
117
    int red,green,blue;
-
 
118
 
-
 
119
    color = *((__u16 *)(fbaddress+startbyte));
-
 
120
    red = (color >> 11) & 0x1f;
-
 
121
    green = (color >> 5) & 0x3f;
-
 
122
    blue = color & 0x1f;
-
 
123
    return (red << (16+3)) | (green << (8+2)) | (blue << 3);
-
 
124
}
-
 
125
 
-
 
126
/** Put pixel - 8-bit depth (3:3:2) */
-
 
127
static void putpixel_1byte(int x,int y,int color)
-
 
128
{
-
 
129
    int compcolor;
-
 
130
 
-
 
131
    /* 3-bit, 3-bits, 2-bits */
-
 
132
    compcolor = RED(color,3) << 5 \
-
 
133
        | GREEN(color,3) << 2 \
-
 
134
        | BLUE(color,2);
-
 
135
    fbaddress[POINTPOS(x,y)] = compcolor;
-
 
136
}
-
 
137
 
-
 
138
 
-
 
139
static int getpixel_1byte(int x,int y)
-
 
140
{
-
 
141
    int color;
-
 
142
    int red,green,blue;
-
 
143
 
-
 
144
    color = fbaddress[POINTPOS(x,y)];
-
 
145
    red = (color >> 5) & 0x7;
-
 
146
    green = (color >> 5) & 0x7;
-
 
147
    blue = color & 0x3;
-
 
148
    return (red << (16+5)) | (green << (8+5)) | blue << 6;
-
 
149
}
-
 
150
 
105
static void clear_line(int y);
151
static void clear_line(int y);
106
/** Scroll screen one row up */
152
/** Scroll screen one row up */
107
static void scroll_screen(void)
153
static void scroll_screen(void)
108
{
154
{
109
    int i;
155
    int i;
Line 124... Line 170...
124
/** Fill line with color BGCOLOR */
170
/** Fill line with color BGCOLOR */
125
static void clear_line(int y)
171
static void clear_line(int y)
126
{
172
{
127
    int x;
173
    int x;
128
    for (x=0; x<xres;x++)
174
    for (x=0; x<xres;x++)
129
        putpixel(x,y,BGCOLOR);
175
        (*putpixel)(x,y,BGCOLOR);
130
}
176
}
131
 
177
 
132
/** Fill screen with background color */
178
/** Fill screen with background color */
133
static void clear_screen(void)
179
static void clear_screen(void)
134
{
180
{
Line 138... Line 184...
138
        clear_line(y);
184
        clear_line(y);
139
}
185
}
140
 
186
 
141
static void invert_pixel(int x, int y)
187
static void invert_pixel(int x, int y)
142
{
188
{
143
    putpixel(x,y, ~getpixel(x,y));
189
    (*putpixel)(x,y, ~(*getpixel)(x,y));
144
}
190
}
145
 
191
 
146
 
192
 
147
/** Draw one line of glyph at a given position */
193
/** Draw one line of glyph at a given position */
148
static void draw_glyph_line(int glline, int x, int y)
194
static void draw_glyph_line(int glline, int x, int y)
149
{
195
{
150
    int i;
196
    int i;
151
 
197
 
152
    for (i=0; i < 8; i++)
198
    for (i=0; i < 8; i++)
153
        if (glline & (1 << (7-i))) {
199
        if (glline & (1 << (7-i))) {
154
            putpixel(x+i,y,FGCOLOR);
200
            (*putpixel)(x+i,y,FGCOLOR);
155
        } else
201
        } else
156
            putpixel(x+i,y,BGCOLOR);
202
            (*putpixel)(x+i,y,BGCOLOR);
157
}
203
}
158
 
204
 
159
/***************************************************************/
205
/***************************************************************/
160
/* Character-console functions */
206
/* Character-console functions */
161
 
207
 
Line 244... Line 290...
244
 * @param bytes Bytes per pixel (2,3,4)
290
 * @param bytes Bytes per pixel (2,3,4)
245
 */
291
 */
246
void fb_init(__address addr, int x, int y, int bytes)
292
void fb_init(__address addr, int x, int y, int bytes)
247
{
293
{
248
    fbaddress = (unsigned char *)addr;
294
    fbaddress = (unsigned char *)addr;
-
 
295
 
-
 
296
    switch (bytes) {
-
 
297
    case 1:
-
 
298
        putpixel = putpixel_1byte;
-
 
299
        getpixel = getpixel_1byte;
-
 
300
        break;
-
 
301
    case 2:
-
 
302
        putpixel = putpixel_2byte;
-
 
303
        getpixel = getpixel_2byte;
-
 
304
        break;
-
 
305
    case 3:
-
 
306
        putpixel = putpixel_3byte;
-
 
307
        getpixel = getpixel_3byte;
-
 
308
        break;
-
 
309
    case 4:
-
 
310
        putpixel = putpixel_4byte;
-
 
311
        getpixel = getpixel_4byte;
-
 
312
        break;
-
 
313
    default:
-
 
314
        panic("Unsupported color depth");
-
 
315
    }
249
   
316
   
250
    xres = x;
317
    xres = x;
251
    yres = y;
318
    yres = y;
252
    pixelbytes = bytes;
319
    pixelbytes = bytes;
253
   
320