Subversion Repositories HelenOS-historic

Rev

Rev 1493 | Rev 1500 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1493 Rev 1498
1
/*
1
/*
2
 * Copyright (C) 2006 Jakub Vana
2
 * Copyright (C) 2006 Jakub Vana
3
 * Copyright (C) 2006 Ondrej Palkovsky
3
 * Copyright (C) 2006 Ondrej Palkovsky
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
#include <stdlib.h>
30
#include <stdlib.h>
31
#include <unistd.h>
31
#include <unistd.h>
32
#include <string.h>
32
#include <string.h>
33
#include <ddi.h>
33
#include <ddi.h>
34
#include <sysinfo.h>
34
#include <sysinfo.h>
35
#include <align.h>
35
#include <align.h>
36
#include <as.h>
36
#include <as.h>
37
#include <ipc/fb.h>
37
#include <ipc/fb.h>
38
#include <ipc/ipc.h>
38
#include <ipc/ipc.h>
39
#include <ipc/ns.h>
39
#include <ipc/ns.h>
40
#include <ipc/services.h>
40
#include <ipc/services.h>
41
#include <kernel/errno.h>
41
#include <kernel/errno.h>
42
#include <async.h>
42
#include <async.h>
43
#include "font-8x16.h"
43
#include "font-8x16.h"
44
#include "helenos.xbm"
44
#include "helenos.xbm"
45
#include "fb.h"
45
#include "fb.h"
46
 
46
 
47
#define DEFAULT_BGCOLOR                0x000080
47
#define DEFAULT_BGCOLOR                0x000080
48
#define DEFAULT_FGCOLOR                0xffff00
48
#define DEFAULT_FGCOLOR                0xffff00
49
 
49
 
50
/***************************************************************/
50
/***************************************************************/
51
/* Pixel specific fuctions */
51
/* Pixel specific fuctions */
52
 
52
 
53
typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color);
53
typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color);
54
typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y);
54
typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y);
55
 
55
 
56
struct {
56
struct {
57
    __u8 *fbaddress ;
57
    __u8 *fbaddress ;
58
 
58
 
59
    unsigned int xres ;
59
    unsigned int xres ;
60
    unsigned int yres ;
60
    unsigned int yres ;
61
    unsigned int scanline ;
61
    unsigned int scanline ;
62
    unsigned int pixelbytes ;
62
    unsigned int pixelbytes ;
63
 
63
 
64
    putpixel_fn_t putpixel;
64
    putpixel_fn_t putpixel;
65
    getpixel_fn_t getpixel;
65
    getpixel_fn_t getpixel;
66
} screen;
66
} screen;
67
 
67
 
68
typedef struct {
68
typedef struct {
69
    int initialized;
69
    int initialized;
70
    unsigned int x, y;
70
    unsigned int x, y;
71
    unsigned int width, height;
71
    unsigned int width, height;
72
 
72
 
73
    /* Text support in window */
73
    /* Text support in window */
74
    unsigned int rows, cols;
74
    unsigned int rows, cols;
75
    /* Style for text printing */
75
    /* Style for text printing */
76
    int bgcolor, fgcolor;
76
    int bgcolor, fgcolor;
77
    /* Auto-cursor position */
77
    /* Auto-cursor position */
78
    int cursor_active, cur_col, cur_row;
78
    int cursor_active, cur_col, cur_row;
79
} viewport_t;
79
} viewport_t;
80
 
80
 
81
#define MAX_VIEWPORTS 128
81
#define MAX_VIEWPORTS 128
82
static viewport_t viewports[128];
82
static viewport_t viewports[128];
83
 
83
 
84
/* Allow only 1 connection */
84
/* Allow only 1 connection */
85
static int client_connected = 0;
85
static int client_connected = 0;
86
 
86
 
87
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
87
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
88
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
88
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
89
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
89
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
90
 
90
 
91
#define COL_WIDTH   8
91
#define COL_WIDTH   8
92
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
92
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
93
 
93
 
94
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
94
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
95
 
95
 
96
/** Put pixel - 24-bit depth, 1 free byte */
96
/** Put pixel - 24-bit depth, 1 free byte */
97
static void putpixel_4byte(unsigned int x, unsigned int y, int color)
97
static void putpixel_4byte(unsigned int x, unsigned int y, int color)
98
{
98
{
99
    *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color;
99
    *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color;
100
}
100
}
101
 
101
 
102
/** Return pixel color - 24-bit depth, 1 free byte */
102
/** Return pixel color - 24-bit depth, 1 free byte */
103
static int getpixel_4byte(unsigned int x, unsigned int y)
103
static int getpixel_4byte(unsigned int x, unsigned int y)
104
{
104
{
105
    return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff;
105
    return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff;
106
}
106
}
107
 
107
 
108
/** Put pixel - 24-bit depth */
108
/** Put pixel - 24-bit depth */
109
static void putpixel_3byte(unsigned int x, unsigned int y, int color)
109
static void putpixel_3byte(unsigned int x, unsigned int y, int color)
110
{
110
{
111
    unsigned int startbyte = POINTPOS(x, y);
111
    unsigned int startbyte = POINTPOS(x, y);
112
 
112
 
113
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
113
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
114
    screen.fbaddress[startbyte] = RED(color, 8);
114
    screen.fbaddress[startbyte] = RED(color, 8);
115
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
115
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
116
    screen.fbaddress[startbyte + 2] = BLUE(color, 8);
116
    screen.fbaddress[startbyte + 2] = BLUE(color, 8);
117
#else
117
#else
118
    screen.fbaddress[startbyte + 2] = RED(color, 8);
118
    screen.fbaddress[startbyte + 2] = RED(color, 8);
119
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
119
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
120
    screen.fbaddress[startbyte + 0] = BLUE(color, 8);
120
    screen.fbaddress[startbyte + 0] = BLUE(color, 8);
121
#endif
121
#endif
122
 
122
 
123
}
123
}
124
 
124
 
125
/** Return pixel color - 24-bit depth */
125
/** Return pixel color - 24-bit depth */
126
static int getpixel_3byte(unsigned int x, unsigned int y)
126
static int getpixel_3byte(unsigned int x, unsigned int y)
127
{
127
{
128
    unsigned int startbyte = POINTPOS(x, y);
128
    unsigned int startbyte = POINTPOS(x, y);
129
 
129
 
130
 
130
 
131
 
131
 
132
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
132
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
133
    return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2];
133
    return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2];
134
#else
134
#else
135
    return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0];
135
    return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0];
136
#endif
136
#endif
137
                               
137
                               
138
 
138
 
139
}
139
}
140
 
140
 
141
/** Put pixel - 16-bit depth (5:6:5) */
141
/** Put pixel - 16-bit depth (5:6:5) */
142
static void putpixel_2byte(unsigned int x, unsigned int y, int color)
142
static void putpixel_2byte(unsigned int x, unsigned int y, int color)
143
{
143
{
144
    /* 5-bit, 6-bits, 5-bits */
144
    /* 5-bit, 6-bits, 5-bits */
145
    *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
145
    *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
146
}
146
}
147
 
147
 
148
/** Return pixel color - 16-bit depth (5:6:5) */
148
/** Return pixel color - 16-bit depth (5:6:5) */
149
static int getpixel_2byte(unsigned int x, unsigned int y)
149
static int getpixel_2byte(unsigned int x, unsigned int y)
150
{
150
{
151
    int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y)));
151
    int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y)));
152
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
152
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
153
}
153
}
154
 
154
 
155
/** Put pixel - 8-bit depth (3:2:3) */
155
/** Put pixel - 8-bit depth (3:2:3) */
156
static void putpixel_1byte(unsigned int x, unsigned int y, int color)
156
static void putpixel_1byte(unsigned int x, unsigned int y, int color)
157
{
157
{
158
    screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
158
    screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
159
}
159
}
160
 
160
 
161
/** Return pixel color - 8-bit depth (3:2:3) */
161
/** Return pixel color - 8-bit depth (3:2:3) */
162
static int getpixel_1byte(unsigned int x, unsigned int y)
162
static int getpixel_1byte(unsigned int x, unsigned int y)
163
{
163
{
164
    int color = screen.fbaddress[POINTPOS(x, y)];
164
    int color = screen.fbaddress[POINTPOS(x, y)];
165
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
165
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
166
}
166
}
167
 
167
 
-
 
168
/** Put pixel into viewport
-
 
169
 *
-
 
170
 * @param vp Viewport identification
-
 
171
 * @param x X coord relative to viewport
-
 
172
 * @param y Y coord relative to viewport
-
 
173
 * @param color RGB color
-
 
174
 */
168
static void putpixel(int vp, unsigned int x, unsigned int y, int color)
175
static void putpixel(int vp, unsigned int x, unsigned int y, int color)
169
{
176
{
170
    screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color);
177
    screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color);
171
}
178
}
-
 
179
/** Get pixel from viewport */
172
static int getpixel(int vp, unsigned int x, unsigned int y)
180
static int getpixel(int vp, unsigned int x, unsigned int y)
173
{
181
{
174
    return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y);
182
    return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y);
175
}
183
}
176
 
184
 
177
/** Fill line with color BGCOLOR */
185
/** Fill line with color BGCOLOR */
178
static void clear_line(int vp, unsigned int y)
186
static void clear_line(int vp, unsigned int y)
179
{
187
{
180
    unsigned int x;
188
    unsigned int x;
181
    for (x = 0; x < viewports[vp].width; x++)
189
    for (x = 0; x < viewports[vp].width; x++)
182
        putpixel(vp, x, y, viewports[vp].bgcolor);
190
        putpixel(vp, x, y, viewports[vp].bgcolor);
183
}
191
}
184
 
192
 
185
/** Fill viewport with background color */
193
/** Fill viewport with background color */
186
static void clear_port(int vp)
194
static void clear_port(int vp)
187
{
195
{
188
    unsigned int y;
196
    unsigned int y;
189
 
197
 
190
    clear_line(vp, 0);
198
    clear_line(vp, 0);
191
    for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) {
199
    for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) {
192
        memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
200
        memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
193
               &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
201
               &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
194
               screen.pixelbytes * viewports[vp].width);
202
               screen.pixelbytes * viewports[vp].width);
195
    }  
203
    }  
196
}
204
}
197
 
205
 
198
/** Scroll port up/down
206
/** Scroll port up/down
199
 *
207
 *
200
 * @param vp Viewport to scroll
208
 * @param vp Viewport to scroll
201
 * @param rows Positive number - scroll up, negative - scroll down
209
 * @param rows Positive number - scroll up, negative - scroll down
202
 */
210
 */
203
static void scroll_port(int vp, int rows)
211
static void scroll_port(int vp, int rows)
204
{
212
{
205
    int y;
213
    int y;
206
    int startline;
214
    int startline;
207
    int endline;
215
    int endline;
208
   
216
   
209
    if (rows > 0) {
217
    if (rows > 0) {
210
        for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++)
218
        for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++)
211
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
219
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
212
                   &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)],
220
                   &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)],
213
                   screen.pixelbytes * viewports[vp].width);
221
                   screen.pixelbytes * viewports[vp].width);
214
        /* Clear last row */
222
        /* Clear last row */
215
        startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1);
223
        startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1);
216
        endline = viewports[vp].y + viewports[vp].height;
224
        endline = viewports[vp].y + viewports[vp].height;
217
        clear_line(vp, startline);
225
        clear_line(vp, startline);
218
        for (y=startline+1;y < endline; y++)
226
        for (y=startline+1;y < endline; y++)
219
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
227
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
220
                   &screen.fbaddress[POINTPOS(viewports[vp].x,startline)],
228
                   &screen.fbaddress[POINTPOS(viewports[vp].x,startline)],
221
                   screen.pixelbytes * viewports[vp].width);
229
                   screen.pixelbytes * viewports[vp].width);
222
                 
230
                 
223
    } else if (rows < 0) {
231
    } else if (rows < 0) {
224
        rows = -rows;
232
        rows = -rows;
225
        for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--)
233
        for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--)
226
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
234
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
227
                &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)],
235
                &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)],
228
                screen.pixelbytes * viewports[vp].width);
236
                screen.pixelbytes * viewports[vp].width);
229
        /* Clear first row */
237
        /* Clear first row */
230
        clear_line(0, viewports[vp].bgcolor);
238
        clear_line(0, viewports[vp].bgcolor);
231
        for (y=1;y < rows*FONT_SCANLINES; y++)
239
        for (y=1;y < rows*FONT_SCANLINES; y++)
232
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)],
240
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)],
233
                   &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
241
                   &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
234
                   screen.pixelbytes * viewports[vp].width);
242
                   screen.pixelbytes * viewports[vp].width);
235
    }
243
    }
236
}
244
}
237
 
245
 
238
static void invert_pixel(int vp,unsigned int x, unsigned int y)
246
static void invert_pixel(int vp,unsigned int x, unsigned int y)
239
{
247
{
240
    putpixel(vp, x, y, ~getpixel(vp, x, y));
248
    putpixel(vp, x, y, ~getpixel(vp, x, y));
241
}
249
}
242
 
250
 
243
 
251
 
244
/** Draw one line of glyph at a given position */
252
/** Draw one line of glyph at a given position */
245
static void draw_glyph_line(int vp,unsigned int glline, unsigned int x, unsigned int y)
253
static void draw_glyph_line(int vp,unsigned int glline, unsigned int x, unsigned int y)
246
{
254
{
247
    unsigned int i;
255
    unsigned int i;
248
 
256
 
249
    for (i = 0; i < 8; i++)
257
    for (i = 0; i < 8; i++)
250
        if (glline & (1 << (7 - i))) {
258
        if (glline & (1 << (7 - i))) {
251
            putpixel(vp, x + i, y, viewports[vp].fgcolor);
259
            putpixel(vp, x + i, y, viewports[vp].fgcolor);
252
        } else
260
        } else
253
            putpixel(vp, x + i, y, viewports[vp].bgcolor);
261
            putpixel(vp, x + i, y, viewports[vp].bgcolor);
254
}
262
}
255
 
263
 
256
/***************************************************************/
264
/***************************************************************/
257
/* Character-console functions */
265
/* Character-console functions */
258
 
266
 
259
/** Draw character at given position */
267
/** Draw character at given position */
260
static void draw_glyph(int vp,__u8 glyph, unsigned int row, unsigned int col)
268
static void draw_glyph(int vp,__u8 glyph, unsigned int sx, unsigned int sy)
261
{
269
{
262
    unsigned int y;
270
    unsigned int y;
263
 
271
 
264
    for (y = 0; y < FONT_SCANLINES; y++)
272
    for (y = 0; y < FONT_SCANLINES; y++)
265
        draw_glyph_line(vp ,fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y);
273
        draw_glyph_line(vp ,fb_font[glyph * FONT_SCANLINES + y], sx, sy + y);
266
}
274
}
267
 
275
 
268
/** Invert character at given position */
276
/** Invert character at given position */
269
static void invert_char(int vp,unsigned int row, unsigned int col)
277
static void invert_char(int vp,unsigned int row, unsigned int col)
270
{
278
{
271
    unsigned int x;
279
    unsigned int x;
272
    unsigned int y;
280
    unsigned int y;
273
 
281
 
274
    for (x = 0; x < COL_WIDTH; x++)
282
    for (x = 0; x < COL_WIDTH; x++)
275
        for (y = 0; y < FONT_SCANLINES; y++)
283
        for (y = 0; y < FONT_SCANLINES; y++)
276
            invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
284
            invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
277
}
285
}
278
 
286
 
279
static void draw_logo(int vp,unsigned int startx, unsigned int starty)
287
static void draw_logo(int vp,unsigned int startx, unsigned int starty)
280
{
288
{
281
    unsigned int x;
289
    unsigned int x;
282
    unsigned int y;
290
    unsigned int y;
283
    unsigned int byte;
291
    unsigned int byte;
284
    unsigned int rowbytes;
292
    unsigned int rowbytes;
285
 
293
 
286
    rowbytes = (helenos_width - 1) / 8 + 1;
294
    rowbytes = (helenos_width - 1) / 8 + 1;
287
 
295
 
288
    for (y = 0; y < helenos_height; y++)
296
    for (y = 0; y < helenos_height; y++)
289
        for (x = 0; x < helenos_width; x++) {
297
        for (x = 0; x < helenos_width; x++) {
290
            byte = helenos_bits[rowbytes * y + x / 8];
298
            byte = helenos_bits[rowbytes * y + x / 8];
291
            byte >>= x % 8;
299
            byte >>= x % 8;
292
            if (byte & 1)
300
            if (byte & 1)
293
                putpixel(vp ,startx + x, starty + y, viewports[vp].fgcolor);
301
                putpixel(vp ,startx + x, starty + y, viewports[vp].fgcolor);
294
        }
302
        }
295
}
303
}
296
 
304
 
297
/***************************************************************/
305
/***************************************************************/
298
/* Stdout specific functions */
306
/* Stdout specific functions */
299
 
307
 
300
 
308
 
301
/** Create new viewport
309
/** Create new viewport
302
 *
310
 *
303
 * @return New viewport number
311
 * @return New viewport number
304
 */
312
 */
305
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
313
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
306
               unsigned int height)
314
               unsigned int height)
307
{
315
{
308
    int i;
316
    int i;
309
 
317
 
310
    for (i=0; i < MAX_VIEWPORTS; i++) {
318
for (i=0; i < MAX_VIEWPORTS; i++) {
311
        if (!viewports[i].initialized)
319
        if (!viewports[i].initialized)
312
            break;
320
            break;
313
    }
321
    }
314
    if (i == MAX_VIEWPORTS)
322
    if (i == MAX_VIEWPORTS)
315
        return ELIMIT;
323
        return ELIMIT;
316
 
324
 
317
    if (width ==0 || height == 0 ||
325
    if (width ==0 || height == 0 ||
318
        x+width > screen.xres || y+height > screen.yres)
326
        x+width > screen.xres || y+height > screen.yres)
319
        return EINVAL;
327
        return EINVAL;
320
    if (width < FONT_SCANLINES || height < COL_WIDTH)
328
    if (width < FONT_SCANLINES || height < COL_WIDTH)
321
        return EINVAL;
329
        return EINVAL;
322
 
330
 
323
    viewports[i].x = x;
331
    viewports[i].x = x;
324
    viewports[i].y = y;
332
    viewports[i].y = y;
325
    viewports[i].width = width;
333
    viewports[i].width = width;
326
    viewports[i].height = height;
334
    viewports[i].height = height;
327
   
335
   
328
    viewports[i].rows = height / FONT_SCANLINES;
336
    viewports[i].rows = height / FONT_SCANLINES;
329
    viewports[i].cols = width / COL_WIDTH;
337
    viewports[i].cols = width / COL_WIDTH;
330
 
338
 
331
    viewports[i].bgcolor = DEFAULT_BGCOLOR;
339
    viewports[i].bgcolor = DEFAULT_BGCOLOR;
332
    viewports[i].fgcolor = DEFAULT_FGCOLOR;
340
    viewports[i].fgcolor = DEFAULT_FGCOLOR;
333
   
341
   
334
    viewports[i].cur_col = 0;
342
    viewports[i].cur_col = 0;
335
    viewports[i].cur_row = 0;
343
    viewports[i].cur_row = 0;
336
    viewports[i].cursor_active = 0;
344
    viewports[i].cursor_active = 0;
337
 
345
 
338
    viewports[i].initialized = 1;
346
    viewports[i].initialized = 1;
339
 
347
 
340
    return i;
348
    return i;
341
}
349
}
342
 
350
 
343
 
351
 
344
/** Initialize framebuffer as a chardev output device
352
/** Initialize framebuffer as a chardev output device
345
 *
353
 *
346
 * @param addr Address of theframebuffer
354
 * @param addr Address of theframebuffer
347
 * @param x    Screen width in pixels
355
 * @param x    Screen width in pixels
348
 * @param y    Screen height in pixels
356
 * @param y    Screen height in pixels
349
 * @param bpp  Bits per pixel (8, 16, 24, 32)
357
 * @param bpp  Bits per pixel (8, 16, 24, 32)
350
 * @param scan Bytes per one scanline
358
 * @param scan Bytes per one scanline
351
 *
359
 *
352
 */
360
 */
353
static void screen_init(__address addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
361
static void screen_init(__address addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
354
{
362
{
355
    switch (bpp) {
363
    switch (bpp) {
356
        case 8:
364
        case 8:
357
            screen.putpixel = putpixel_1byte;
365
            screen.putpixel = putpixel_1byte;
358
            screen.getpixel = getpixel_1byte;
366
            screen.getpixel = getpixel_1byte;
359
            screen.pixelbytes = 1;
367
            screen.pixelbytes = 1;
360
            break;
368
            break;
361
        case 16:
369
        case 16:
362
            screen.putpixel = putpixel_2byte;
370
            screen.putpixel = putpixel_2byte;
363
            screen.getpixel = getpixel_2byte;
371
            screen.getpixel = getpixel_2byte;
364
            screen.pixelbytes = 2;
372
            screen.pixelbytes = 2;
365
            break;
373
            break;
366
        case 24:
374
        case 24:
367
            screen.putpixel = putpixel_3byte;
375
            screen.putpixel = putpixel_3byte;
368
            screen.getpixel = getpixel_3byte;
376
            screen.getpixel = getpixel_3byte;
369
            screen.pixelbytes = 3;
377
            screen.pixelbytes = 3;
370
            break;
378
            break;
371
        case 32:
379
        case 32:
372
            screen.putpixel = putpixel_4byte;
380
            screen.putpixel = putpixel_4byte;
373
            screen.getpixel = getpixel_4byte;
381
            screen.getpixel = getpixel_4byte;
374
            screen.pixelbytes = 4;
382
            screen.pixelbytes = 4;
375
            break;
383
            break;
376
    }
384
    }
377
 
385
 
378
       
386
       
379
    screen.fbaddress = (unsigned char *) addr;
387
    screen.fbaddress = (unsigned char *) addr;
380
    screen.xres = xres;
388
    screen.xres = xres;
381
    screen.yres = yres;
389
    screen.yres = yres;
382
    screen.scanline = scan;
390
    screen.scanline = scan;
383
   
391
   
384
    /* Create first viewport */
392
    /* Create first viewport */
385
    viewport_create(0,0,xres,yres);
393
    viewport_create(0,0,xres,yres);
386
 
394
 
387
    clear_port(0);
395
    clear_port(0);
388
}
396
}
389
 
397
 
-
 
398
/** Draw character at given position relative to viewport
-
 
399
 *
-
 
400
 * @param vp Viewport identification
-
 
401
 * @param c Character to print
-
 
402
 * @param row Screen position relative to viewport
-
 
403
 * @param col Screen position relative to viewport
-
 
404
 */
390
static void draw_char(int vp, char c, unsigned int row, unsigned int col)
405
static void draw_char(int vp, char c, unsigned int row, unsigned int col)
391
{
406
{
392
    viewport_t *vport = &viewports[vp];
407
    viewport_t *vport = &viewports[vp];
393
 
408
 
394
    if (vport->cursor_active && (vport->cur_col != col || vport->cur_row != row))
409
    if (vport->cursor_active && (vport->cur_col != col || vport->cur_row != row))
395
        invert_char(vp, vport->cur_row, vport->cur_col);
410
        invert_char(vp, vport->cur_row, vport->cur_col);
396
   
411
   
397
    draw_glyph(vp, c, row, col);
412
    draw_glyph(vp, c, col * COL_WIDTH, row * FONT_SCANLINES);
398
 
413
 
399
    vport->cur_col = col;
414
    vport->cur_col = col;
400
    vport->cur_row = row;
415
    vport->cur_row = row;
401
 
416
 
402
    vport->cur_col++;
417
    vport->cur_col++;
403
    if (vport->cur_col>= vport->cols) {
418
    if (vport->cur_col>= vport->cols) {
404
        vport->cur_col = 0;
419
        vport->cur_col = 0;
405
        vport->cur_row++;
420
        vport->cur_row++;
406
        if (vport->cur_row >= vport->rows)
421
        if (vport->cur_row >= vport->rows)
407
            vport->cur_row--;
422
            vport->cur_row--;
408
    }
423
    }
409
    if (vport->cursor_active)
424
    if (vport->cursor_active)
410
        invert_char(vp, vport->cur_row, vport->cur_col);
425
        invert_char(vp, vport->cur_row, vport->cur_col);
411
}
426
}
412
 
427
 
-
 
428
/** Function for handling connections to FB
-
 
429
 *
-
 
430
 */
413
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
431
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
414
{
432
{
415
    ipc_callid_t callid;
433
    ipc_callid_t callid;
416
    ipc_call_t call;
434
    ipc_call_t call;
417
    int retval;
435
    int retval;
418
    int i;
436
    int i;
419
    unsigned int row,col;
437
    unsigned int row,col;
420
    char c;
438
    char c;
421
 
439
 
422
    int vp = 0;
440
    int vp = 0;
423
    viewport_t *vport = &viewports[0];
441
    viewport_t *vport = &viewports[0];
424
 
442
 
425
    if (client_connected) {
443
    if (client_connected) {
426
        ipc_answer_fast(iid, ELIMIT, 0,0);
444
        ipc_answer_fast(iid, ELIMIT, 0,0);
427
        return;
445
        return;
428
    }
446
    }
429
    client_connected = 1;
447
    client_connected = 1;
430
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
448
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
431
 
449
 
432
    while (1) {
450
    while (1) {
433
        callid = async_get_call(&call);
451
        callid = async_get_call(&call);
434
        switch (IPC_GET_METHOD(call)) {
452
        switch (IPC_GET_METHOD(call)) {
435
        case IPC_M_PHONE_HUNGUP:
453
        case IPC_M_PHONE_HUNGUP:
436
            client_connected = 0;
454
            client_connected = 0;
437
            /* cleanup other viewports */
455
            /* cleanup other viewports */
438
            for (i=1; i < MAX_VIEWPORTS; i++)
456
            for (i=1; i < MAX_VIEWPORTS; i++)
439
                vport->initialized = 0;
457
                vport->initialized = 0;
440
            ipc_answer_fast(callid,0,0,0);
458
            ipc_answer_fast(callid,0,0,0);
441
            return; /* Exit thread */
459
            return; /* Exit thread */
442
        case FB_PUTCHAR:
460
        case FB_PUTCHAR:
443
            c = IPC_GET_ARG1(call);
461
            c = IPC_GET_ARG1(call);
444
            row = IPC_GET_ARG2(call);
462
            row = IPC_GET_ARG2(call);
445
            col = IPC_GET_ARG3(call);
463
            col = IPC_GET_ARG3(call);
446
            if (row >= vport->rows || col >= vport->cols) {
464
            if (row >= vport->rows || col >= vport->cols) {
447
                retval = EINVAL;
465
                retval = EINVAL;
448
                break;
466
                break;
449
            }
467
            }
450
            ipc_answer_fast(callid,0,0,0);
468
            ipc_answer_fast(callid,0,0,0);
451
 
469
 
452
            draw_char(vp, c, row, col);
470
            draw_char(vp, c, row, col);
453
            continue; /* msg already answered */
471
            continue; /* msg already answered */
454
        case FB_CLEAR:
472
        case FB_CLEAR:
455
            clear_port(vp);
473
            clear_port(vp);
456
            if (vport->cursor_active)
474
            if (vport->cursor_active)
457
                invert_char(vp, vport->cur_row, vport->cur_col);
475
                invert_char(vp, vport->cur_row, vport->cur_col);
458
            retval = 0;
476
            retval = 0;
459
            break;
477
            break;
460
        case FB_CURSOR_GOTO:
478
        case FB_CURSOR_GOTO:
461
            row = IPC_GET_ARG1(call);
479
            row = IPC_GET_ARG1(call);
462
            col = IPC_GET_ARG2(call);
480
            col = IPC_GET_ARG2(call);
463
            if (row >= vport->rows || col >= vport->cols) {
481
            if (row >= vport->rows || col >= vport->cols) {
464
                retval = EINVAL;
482
                retval = EINVAL;
465
                break;
483
                break;
466
            }
484
            }
467
            retval = 0;
485
            retval = 0;
468
            if (viewports[vp].cursor_active) {
486
            if (viewports[vp].cursor_active) {
469
                invert_char(vp, vport->cur_row, vport->cur_col);
487
                invert_char(vp, vport->cur_row, vport->cur_col);
470
                invert_char(vp, row, col);
488
                invert_char(vp, row, col);
471
            }
489
            }
472
            vport->cur_col = col;
490
            vport->cur_col = col;
473
            vport->cur_row = row;
491
            vport->cur_row = row;
474
            break;
492
            break;
475
        case FB_CURSOR_VISIBILITY:
493
        case FB_CURSOR_VISIBILITY:
476
            i = IPC_GET_ARG1(call);
494
            i = IPC_GET_ARG1(call);
477
            retval = 0;
495
            retval = 0;
478
            if ((i && vport->cursor_active) || (!i && !vport->cursor_active))
496
            if ((i && vport->cursor_active) || (!i && !vport->cursor_active))
479
                break;
497
                break;
480
 
498
 
481
            vport->cursor_active = i;
499
            vport->cursor_active = i;
482
            invert_char(vp, vport->cur_row, vport->cur_col);
500
            invert_char(vp, vport->cur_row, vport->cur_col);
483
            break;
501
            break;
484
        case FB_GET_CSIZE:
502
        case FB_GET_CSIZE:
485
            ipc_answer_fast(callid, 0, vport->rows, vport->cols);
503
            ipc_answer_fast(callid, 0, vport->rows, vport->cols);
486
            continue;
504
            continue;
487
        case FB_SCROLL:
505
        case FB_SCROLL:
488
            i = IPC_GET_ARG1(call);
506
            i = IPC_GET_ARG1(call);
489
            if (i > vport->rows || i < (- (int)vport->rows)) {
507
            if (i > vport->rows || i < (- (int)vport->rows)) {
490
                retval = EINVAL;
508
                retval = EINVAL;
491
                break;
509
                break;
492
            }
510
            }
493
            if (vport->cursor_active)
511
            if (vport->cursor_active)
494
                invert_char(vp, vport->cur_row, vport->cur_col);
512
                invert_char(vp, vport->cur_row, vport->cur_col);
495
            scroll_port(vp, i);
513
            scroll_port(vp, i);
496
            if (vport->cursor_active)
514
            if (vport->cursor_active)
497
                invert_char(vp, vport->cur_row, vport->cur_col);
515
                invert_char(vp, vport->cur_row, vport->cur_col);
498
            retval = 0;
516
            retval = 0;
499
            break;
517
            break;
500
        case FB_VIEWPORT_SWITCH:
518
        case FB_VIEWPORT_SWITCH:
501
            i = IPC_GET_ARG1(call);
519
            i = IPC_GET_ARG1(call);
502
            if (i < 0 || i >= MAX_VIEWPORTS) {
520
            if (i < 0 || i >= MAX_VIEWPORTS) {
503
                retval = EINVAL;
521
                retval = EINVAL;
504
                break;
522
                break;
505
            }
523
            }
506
            if (! viewports[i].initialized ) {
524
            if (! viewports[i].initialized ) {
507
                retval = EADDRNOTAVAIL;
525
                retval = EADDRNOTAVAIL;
508
                break;
526
                break;
509
            }
527
            }
510
            vp = i;
528
            vp = i;
511
            vport = &viewports[vp];
529
            vport = &viewports[vp];
512
            retval = 0;
530
            retval = 0;
513
            break;
531
            break;
514
        case FB_VIEWPORT_CREATE:
532
        case FB_VIEWPORT_CREATE:
515
            retval = viewport_create(IPC_GET_ARG1(call) >> 16,
533
            retval = viewport_create(IPC_GET_ARG1(call) >> 16,
516
                         IPC_GET_ARG1(call) & 0xffff,
534
                         IPC_GET_ARG1(call) & 0xffff,
517
                         IPC_GET_ARG2(call) >> 16,
535
                         IPC_GET_ARG2(call) >> 16,
518
                         IPC_GET_ARG2(call) & 0xffff);
536
                         IPC_GET_ARG2(call) & 0xffff);
519
            break;
537
            break;
520
        case FB_VIEWPORT_DELETE:
538
        case FB_VIEWPORT_DELETE:
521
            i = IPC_GET_ARG1(call);
539
            i = IPC_GET_ARG1(call);
522
            if (i < 0 || i >= MAX_VIEWPORTS) {
540
            if (i < 0 || i >= MAX_VIEWPORTS) {
523
                retval = EINVAL;
541
                retval = EINVAL;
524
                break;
542
                break;
525
            }
543
            }
526
            if (! viewports[i].initialized ) {
544
            if (! viewports[i].initialized ) {
527
                retval = EADDRNOTAVAIL;
545
                retval = EADDRNOTAVAIL;
528
                break;
546
                break;
529
            }
547
            }
530
            viewports[i].initialized = 0;
548
            viewports[i].initialized = 0;
531
            retval = 0;
549
            retval = 0;
532
            break;
550
            break;
533
        case FB_SET_STYLE:
551
        case FB_SET_STYLE:
534
            vport->fgcolor = IPC_GET_ARG1(call);
552
            vport->fgcolor = IPC_GET_ARG1(call);
535
            vport->bgcolor = IPC_GET_ARG2(call);
553
            vport->bgcolor = IPC_GET_ARG2(call);
536
            retval = 0;
554
            retval = 0;
537
            break;
555
            break;
538
        case FB_GET_RESOLUTION:
556
        case FB_GET_RESOLUTION:
539
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
557
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
540
            continue;
558
            continue;
541
        default:
559
        default:
542
            retval = ENOENT;
560
            retval = ENOENT;
543
        }
561
        }
544
        ipc_answer_fast(callid,retval,0,0);
562
        ipc_answer_fast(callid,retval,0,0);
545
    }
563
    }
546
}
564
}
547
 
565
 
-
 
566
/** Initialization of framebuffer */
548
int fb_init(void)
567
int fb_init(void)
549
{
568
{
550
    __address fb_ph_addr;
569
    __address fb_ph_addr;
551
    unsigned int fb_width;
570
    unsigned int fb_width;
552
    unsigned int fb_height;
571
    unsigned int fb_height;
553
    unsigned int fb_bpp;
572
    unsigned int fb_bpp;
554
    unsigned int fb_scanline;
573
    unsigned int fb_scanline;
555
    __address fb_addr;
574
    __address fb_addr;
556
 
575
 
557
    async_set_client_connection(fb_client_connection);
576
    async_set_client_connection(fb_client_connection);
558
 
577
 
559
    fb_ph_addr=sysinfo_value("fb.address.physical");
578
    fb_ph_addr=sysinfo_value("fb.address.physical");
560
    fb_width=sysinfo_value("fb.width");
579
    fb_width=sysinfo_value("fb.width");
561
    fb_height=sysinfo_value("fb.height");
580
    fb_height=sysinfo_value("fb.height");
562
    fb_bpp=sysinfo_value("fb.bpp");
581
    fb_bpp=sysinfo_value("fb.bpp");
563
    fb_scanline=sysinfo_value("fb.scanline");
582
    fb_scanline=sysinfo_value("fb.scanline");
564
 
583
 
565
    fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE);
584
    fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE);
566
   
585
   
567
    map_physmem((void *)((__address)fb_ph_addr),(void *)fb_addr,
586
    map_physmem((void *)((__address)fb_ph_addr),(void *)fb_addr,
568
            (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,
587
            (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,
569
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
588
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
570
   
589
   
571
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
590
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
572
 
591
 
573
    return 0;
592
    return 0;
574
}
593
}
575
 
594
 
576
 
595