Subversion Repositories HelenOS

Rev

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

Rev 1498 Rev 1500
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
    int cursor_shown;
79
} viewport_t;
80
} viewport_t;
80
 
81
 
81
#define MAX_VIEWPORTS 128
82
#define MAX_VIEWPORTS 128
82
static viewport_t viewports[128];
83
static viewport_t viewports[128];
83
 
84
 
84
/* Allow only 1 connection */
85
/* Allow only 1 connection */
85
static int client_connected = 0;
86
static int client_connected = 0;
86
 
87
 
87
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
88
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
88
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
89
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
89
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
90
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
90
 
91
 
91
#define COL_WIDTH   8
92
#define COL_WIDTH   8
92
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
93
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
93
 
94
 
94
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
95
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
95
 
96
 
96
/** Put pixel - 24-bit depth, 1 free byte */
97
/** Put pixel - 24-bit depth, 1 free byte */
97
static void putpixel_4byte(unsigned int x, unsigned int y, int color)
98
static void putpixel_4byte(unsigned int x, unsigned int y, int color)
98
{
99
{
99
    *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color;
100
    *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color;
100
}
101
}
101
 
102
 
102
/** Return pixel color - 24-bit depth, 1 free byte */
103
/** Return pixel color - 24-bit depth, 1 free byte */
103
static int getpixel_4byte(unsigned int x, unsigned int y)
104
static int getpixel_4byte(unsigned int x, unsigned int y)
104
{
105
{
105
    return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff;
106
    return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff;
106
}
107
}
107
 
108
 
108
/** Put pixel - 24-bit depth */
109
/** Put pixel - 24-bit depth */
109
static void putpixel_3byte(unsigned int x, unsigned int y, int color)
110
static void putpixel_3byte(unsigned int x, unsigned int y, int color)
110
{
111
{
111
    unsigned int startbyte = POINTPOS(x, y);
112
    unsigned int startbyte = POINTPOS(x, y);
112
 
113
 
113
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
114
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
114
    screen.fbaddress[startbyte] = RED(color, 8);
115
    screen.fbaddress[startbyte] = RED(color, 8);
115
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
116
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
116
    screen.fbaddress[startbyte + 2] = BLUE(color, 8);
117
    screen.fbaddress[startbyte + 2] = BLUE(color, 8);
117
#else
118
#else
118
    screen.fbaddress[startbyte + 2] = RED(color, 8);
119
    screen.fbaddress[startbyte + 2] = RED(color, 8);
119
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
120
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
120
    screen.fbaddress[startbyte + 0] = BLUE(color, 8);
121
    screen.fbaddress[startbyte + 0] = BLUE(color, 8);
121
#endif
122
#endif
122
 
123
 
123
}
124
}
124
 
125
 
125
/** Return pixel color - 24-bit depth */
126
/** Return pixel color - 24-bit depth */
126
static int getpixel_3byte(unsigned int x, unsigned int y)
127
static int getpixel_3byte(unsigned int x, unsigned int y)
127
{
128
{
128
    unsigned int startbyte = POINTPOS(x, y);
129
    unsigned int startbyte = POINTPOS(x, y);
129
 
130
 
130
 
131
 
131
 
132
 
132
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
133
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
133
    return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2];
134
    return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2];
134
#else
135
#else
135
    return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0];
136
    return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0];
136
#endif
137
#endif
137
                               
138
                               
138
 
139
 
139
}
140
}
140
 
141
 
141
/** Put pixel - 16-bit depth (5:6:5) */
142
/** Put pixel - 16-bit depth (5:6:5) */
142
static void putpixel_2byte(unsigned int x, unsigned int y, int color)
143
static void putpixel_2byte(unsigned int x, unsigned int y, int color)
143
{
144
{
144
    /* 5-bit, 6-bits, 5-bits */
145
    /* 5-bit, 6-bits, 5-bits */
145
    *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
146
    *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
146
}
147
}
147
 
148
 
148
/** Return pixel color - 16-bit depth (5:6:5) */
149
/** Return pixel color - 16-bit depth (5:6:5) */
149
static int getpixel_2byte(unsigned int x, unsigned int y)
150
static int getpixel_2byte(unsigned int x, unsigned int y)
150
{
151
{
151
    int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y)));
152
    int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y)));
152
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
153
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
153
}
154
}
154
 
155
 
155
/** Put pixel - 8-bit depth (3:2:3) */
156
/** Put pixel - 8-bit depth (3:2:3) */
156
static void putpixel_1byte(unsigned int x, unsigned int y, int color)
157
static void putpixel_1byte(unsigned int x, unsigned int y, int color)
157
{
158
{
158
    screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
159
    screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
159
}
160
}
160
 
161
 
161
/** Return pixel color - 8-bit depth (3:2:3) */
162
/** Return pixel color - 8-bit depth (3:2:3) */
162
static int getpixel_1byte(unsigned int x, unsigned int y)
163
static int getpixel_1byte(unsigned int x, unsigned int y)
163
{
164
{
164
    int color = screen.fbaddress[POINTPOS(x, y)];
165
    int color = screen.fbaddress[POINTPOS(x, y)];
165
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
166
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
166
}
167
}
167
 
168
 
168
/** Put pixel into viewport
169
/** Put pixel into viewport
169
 *
170
 *
170
 * @param vp Viewport identification
171
 * @param vp Viewport identification
171
 * @param x X coord relative to viewport
172
 * @param x X coord relative to viewport
172
 * @param y Y coord relative to viewport
173
 * @param y Y coord relative to viewport
173
 * @param color RGB color
174
 * @param color RGB color
174
 */
175
 */
175
static void putpixel(int vp, unsigned int x, unsigned int y, int color)
176
static void putpixel(int vp, unsigned int x, unsigned int y, int color)
176
{
177
{
177
    screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color);
178
    screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color);
178
}
179
}
179
/** Get pixel from viewport */
180
/** Get pixel from viewport */
180
static int getpixel(int vp, unsigned int x, unsigned int y)
181
static int getpixel(int vp, unsigned int x, unsigned int y)
181
{
182
{
182
    return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y);
183
    return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y);
183
}
184
}
184
 
185
 
185
/** Fill line with color BGCOLOR */
186
/** Fill line with color BGCOLOR */
186
static void clear_line(int vp, unsigned int y)
187
static void clear_line(int vp, unsigned int y)
187
{
188
{
188
    unsigned int x;
189
    unsigned int x;
189
    for (x = 0; x < viewports[vp].width; x++)
190
    for (x = 0; x < viewports[vp].width; x++)
190
        putpixel(vp, x, y, viewports[vp].bgcolor);
191
        putpixel(vp, x, y, viewports[vp].bgcolor);
191
}
192
}
192
 
193
 
193
/** Fill viewport with background color */
194
/** Fill viewport with background color */
194
static void clear_port(int vp)
195
static void clear_port(int vp)
195
{
196
{
196
    unsigned int y;
197
    unsigned int y;
197
 
198
 
198
    clear_line(vp, 0);
199
    clear_line(vp, 0);
199
    for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) {
200
    for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) {
200
        memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
201
        memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
201
               &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
202
               &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
202
               screen.pixelbytes * viewports[vp].width);
203
               screen.pixelbytes * viewports[vp].width);
203
    }  
204
    }  
204
}
205
}
205
 
206
 
206
/** Scroll port up/down
207
/** Scroll port up/down
207
 *
208
 *
208
 * @param vp Viewport to scroll
209
 * @param vp Viewport to scroll
209
 * @param rows Positive number - scroll up, negative - scroll down
210
 * @param rows Positive number - scroll up, negative - scroll down
210
 */
211
 */
211
static void scroll_port(int vp, int rows)
212
static void scroll_port(int vp, int rows)
212
{
213
{
213
    int y;
214
    int y;
214
    int startline;
215
    int startline;
215
    int endline;
216
    int endline;
216
   
217
   
217
    if (rows > 0) {
218
    if (rows > 0) {
218
        for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++)
219
        for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++)
219
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
220
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
220
                   &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)],
221
                   &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)],
221
                   screen.pixelbytes * viewports[vp].width);
222
                   screen.pixelbytes * viewports[vp].width);
222
        /* Clear last row */
223
        /* Clear last row */
223
        startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1);
224
        startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1);
224
        endline = viewports[vp].y + viewports[vp].height;
225
        endline = viewports[vp].y + viewports[vp].height;
225
        clear_line(vp, startline);
226
        clear_line(vp, startline);
226
        for (y=startline+1;y < endline; y++)
227
        for (y=startline+1;y < endline; y++)
227
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
228
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
228
                   &screen.fbaddress[POINTPOS(viewports[vp].x,startline)],
229
                   &screen.fbaddress[POINTPOS(viewports[vp].x,startline)],
229
                   screen.pixelbytes * viewports[vp].width);
230
                   screen.pixelbytes * viewports[vp].width);
230
                 
231
                 
231
    } else if (rows < 0) {
232
    } else if (rows < 0) {
232
        rows = -rows;
233
        rows = -rows;
233
        for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--)
234
        for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--)
234
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
235
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
235
                &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)],
236
                &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)],
236
                screen.pixelbytes * viewports[vp].width);
237
                screen.pixelbytes * viewports[vp].width);
237
        /* Clear first row */
238
        /* Clear first row */
238
        clear_line(0, viewports[vp].bgcolor);
239
        clear_line(0, viewports[vp].bgcolor);
239
        for (y=1;y < rows*FONT_SCANLINES; y++)
240
        for (y=1;y < rows*FONT_SCANLINES; y++)
240
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)],
241
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)],
241
                   &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
242
                   &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
242
                   screen.pixelbytes * viewports[vp].width);
243
                   screen.pixelbytes * viewports[vp].width);
243
    }
244
    }
244
}
245
}
245
 
246
 
246
static void invert_pixel(int vp,unsigned int x, unsigned int y)
247
static void invert_pixel(int vp,unsigned int x, unsigned int y)
247
{
248
{
248
    putpixel(vp, x, y, ~getpixel(vp, x, y));
249
    putpixel(vp, x, y, ~getpixel(vp, x, y));
249
}
250
}
250
 
251
 
251
 
252
 
252
/** Draw one line of glyph at a given position */
253
/** Draw one line of glyph at a given position */
253
static void draw_glyph_line(int vp,unsigned int glline, unsigned int x, unsigned int y)
254
static void draw_glyph_line(int vp,unsigned int glline, unsigned int x, unsigned int y)
254
{
255
{
255
    unsigned int i;
256
    unsigned int i;
256
 
257
 
257
    for (i = 0; i < 8; i++)
258
    for (i = 0; i < 8; i++)
258
        if (glline & (1 << (7 - i))) {
259
        if (glline & (1 << (7 - i))) {
259
            putpixel(vp, x + i, y, viewports[vp].fgcolor);
260
            putpixel(vp, x + i, y, viewports[vp].fgcolor);
260
        } else
261
        } else
261
            putpixel(vp, x + i, y, viewports[vp].bgcolor);
262
            putpixel(vp, x + i, y, viewports[vp].bgcolor);
262
}
263
}
263
 
264
 
264
/***************************************************************/
265
/***************************************************************/
265
/* Character-console functions */
266
/* Character-console functions */
266
 
267
 
267
/** Draw character at given position */
268
/** Draw character at given position */
268
static void draw_glyph(int vp,__u8 glyph, unsigned int sx, unsigned int sy)
269
static void draw_glyph(int vp,__u8 glyph, unsigned int sx, unsigned int sy)
269
{
270
{
270
    unsigned int y;
271
    unsigned int y;
271
 
272
 
272
    for (y = 0; y < FONT_SCANLINES; y++)
273
    for (y = 0; y < FONT_SCANLINES; y++)
273
        draw_glyph_line(vp ,fb_font[glyph * FONT_SCANLINES + y], sx, sy + y);
274
        draw_glyph_line(vp ,fb_font[glyph * FONT_SCANLINES + y], sx, sy + y);
274
}
275
}
275
 
276
 
276
/** Invert character at given position */
277
/** Invert character at given position */
277
static void invert_char(int vp,unsigned int row, unsigned int col)
278
static void invert_char(int vp,unsigned int row, unsigned int col)
278
{
279
{
279
    unsigned int x;
280
    unsigned int x;
280
    unsigned int y;
281
    unsigned int y;
281
 
282
 
282
    for (x = 0; x < COL_WIDTH; x++)
283
    for (x = 0; x < COL_WIDTH; x++)
283
        for (y = 0; y < FONT_SCANLINES; y++)
284
        for (y = 0; y < FONT_SCANLINES; y++)
284
            invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
285
            invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
285
}
286
}
286
 
287
 
287
static void draw_logo(int vp,unsigned int startx, unsigned int starty)
288
static void draw_logo(int vp,unsigned int startx, unsigned int starty)
288
{
289
{
289
    unsigned int x;
290
    unsigned int x;
290
    unsigned int y;
291
    unsigned int y;
291
    unsigned int byte;
292
    unsigned int byte;
292
    unsigned int rowbytes;
293
    unsigned int rowbytes;
293
 
294
 
294
    rowbytes = (helenos_width - 1) / 8 + 1;
295
    rowbytes = (helenos_width - 1) / 8 + 1;
295
 
296
 
296
    for (y = 0; y < helenos_height; y++)
297
    for (y = 0; y < helenos_height; y++)
297
        for (x = 0; x < helenos_width; x++) {
298
        for (x = 0; x < helenos_width; x++) {
298
            byte = helenos_bits[rowbytes * y + x / 8];
299
            byte = helenos_bits[rowbytes * y + x / 8];
299
            byte >>= x % 8;
300
            byte >>= x % 8;
300
            if (byte & 1)
301
            if (byte & 1)
301
                putpixel(vp ,startx + x, starty + y, viewports[vp].fgcolor);
302
                putpixel(vp ,startx + x, starty + y, viewports[vp].fgcolor);
302
        }
303
        }
303
}
304
}
304
 
305
 
305
/***************************************************************/
306
/***************************************************************/
306
/* Stdout specific functions */
307
/* Stdout specific functions */
307
 
308
 
308
 
309
 
309
/** Create new viewport
310
/** Create new viewport
310
 *
311
 *
311
 * @return New viewport number
312
 * @return New viewport number
312
 */
313
 */
313
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
314
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
314
               unsigned int height)
315
               unsigned int height)
315
{
316
{
316
    int i;
317
    int i;
317
 
318
 
318
for (i=0; i < MAX_VIEWPORTS; i++) {
319
for (i=0; i < MAX_VIEWPORTS; i++) {
319
        if (!viewports[i].initialized)
320
        if (!viewports[i].initialized)
320
            break;
321
            break;
321
    }
322
    }
322
    if (i == MAX_VIEWPORTS)
323
    if (i == MAX_VIEWPORTS)
323
        return ELIMIT;
324
        return ELIMIT;
324
 
325
 
325
    if (width ==0 || height == 0 ||
326
    if (width ==0 || height == 0 ||
326
        x+width > screen.xres || y+height > screen.yres)
327
        x+width > screen.xres || y+height > screen.yres)
327
        return EINVAL;
328
        return EINVAL;
328
    if (width < FONT_SCANLINES || height < COL_WIDTH)
329
    if (width < FONT_SCANLINES || height < COL_WIDTH)
329
        return EINVAL;
330
        return EINVAL;
330
 
331
 
331
    viewports[i].x = x;
332
    viewports[i].x = x;
332
    viewports[i].y = y;
333
    viewports[i].y = y;
333
    viewports[i].width = width;
334
    viewports[i].width = width;
334
    viewports[i].height = height;
335
    viewports[i].height = height;
335
   
336
   
336
    viewports[i].rows = height / FONT_SCANLINES;
337
    viewports[i].rows = height / FONT_SCANLINES;
337
    viewports[i].cols = width / COL_WIDTH;
338
    viewports[i].cols = width / COL_WIDTH;
338
 
339
 
339
    viewports[i].bgcolor = DEFAULT_BGCOLOR;
340
    viewports[i].bgcolor = DEFAULT_BGCOLOR;
340
    viewports[i].fgcolor = DEFAULT_FGCOLOR;
341
    viewports[i].fgcolor = DEFAULT_FGCOLOR;
341
   
342
   
342
    viewports[i].cur_col = 0;
343
    viewports[i].cur_col = 0;
343
    viewports[i].cur_row = 0;
344
    viewports[i].cur_row = 0;
344
    viewports[i].cursor_active = 0;
345
    viewports[i].cursor_active = 0;
345
 
346
 
346
    viewports[i].initialized = 1;
347
    viewports[i].initialized = 1;
347
 
348
 
348
    return i;
349
    return i;
349
}
350
}
350
 
351
 
351
 
352
 
352
/** Initialize framebuffer as a chardev output device
353
/** Initialize framebuffer as a chardev output device
353
 *
354
 *
354
 * @param addr Address of theframebuffer
355
 * @param addr Address of theframebuffer
355
 * @param x    Screen width in pixels
356
 * @param x    Screen width in pixels
356
 * @param y    Screen height in pixels
357
 * @param y    Screen height in pixels
357
 * @param bpp  Bits per pixel (8, 16, 24, 32)
358
 * @param bpp  Bits per pixel (8, 16, 24, 32)
358
 * @param scan Bytes per one scanline
359
 * @param scan Bytes per one scanline
359
 *
360
 *
360
 */
361
 */
361
static void screen_init(__address addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
362
static void screen_init(__address addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
362
{
363
{
363
    switch (bpp) {
364
    switch (bpp) {
364
        case 8:
365
        case 8:
365
            screen.putpixel = putpixel_1byte;
366
            screen.putpixel = putpixel_1byte;
366
            screen.getpixel = getpixel_1byte;
367
            screen.getpixel = getpixel_1byte;
367
            screen.pixelbytes = 1;
368
            screen.pixelbytes = 1;
368
            break;
369
            break;
369
        case 16:
370
        case 16:
370
            screen.putpixel = putpixel_2byte;
371
            screen.putpixel = putpixel_2byte;
371
            screen.getpixel = getpixel_2byte;
372
            screen.getpixel = getpixel_2byte;
372
            screen.pixelbytes = 2;
373
            screen.pixelbytes = 2;
373
            break;
374
            break;
374
        case 24:
375
        case 24:
375
            screen.putpixel = putpixel_3byte;
376
            screen.putpixel = putpixel_3byte;
376
            screen.getpixel = getpixel_3byte;
377
            screen.getpixel = getpixel_3byte;
377
            screen.pixelbytes = 3;
378
            screen.pixelbytes = 3;
378
            break;
379
            break;
379
        case 32:
380
        case 32:
380
            screen.putpixel = putpixel_4byte;
381
            screen.putpixel = putpixel_4byte;
381
            screen.getpixel = getpixel_4byte;
382
            screen.getpixel = getpixel_4byte;
382
            screen.pixelbytes = 4;
383
            screen.pixelbytes = 4;
383
            break;
384
            break;
384
    }
385
    }
385
 
386
 
386
       
387
       
387
    screen.fbaddress = (unsigned char *) addr;
388
    screen.fbaddress = (unsigned char *) addr;
388
    screen.xres = xres;
389
    screen.xres = xres;
389
    screen.yres = yres;
390
    screen.yres = yres;
390
    screen.scanline = scan;
391
    screen.scanline = scan;
391
   
392
   
392
    /* Create first viewport */
393
    /* Create first viewport */
393
    viewport_create(0,0,xres,yres);
394
    viewport_create(0,0,xres,yres);
394
 
395
 
395
    clear_port(0);
396
    clear_port(0);
396
}
397
}
397
 
398
 
-
 
399
static void cursor_hide(int vp)
-
 
400
{
-
 
401
    viewport_t *vport = &viewports[vp];
-
 
402
 
-
 
403
    if (vport->cursor_active && vport->cursor_shown) {
-
 
404
        invert_char(vp, vport->cur_row, vport->cur_col);
-
 
405
        vport->cursor_shown = 0;
-
 
406
    }
-
 
407
}
-
 
408
 
-
 
409
static void cursor_print(int vp)
-
 
410
{
-
 
411
    viewport_t *vport = &viewports[vp];
-
 
412
 
-
 
413
    /* Do not check for cursor_shown */
-
 
414
    if (vport->cursor_active) {
-
 
415
        invert_char(vp, vport->cur_row, vport->cur_col);
-
 
416
        vport->cursor_shown = 1;
-
 
417
    }
-
 
418
}
-
 
419
 
-
 
420
static void cursor_blink(int vp)
-
 
421
{
-
 
422
    viewport_t *vport = &viewports[vp];
-
 
423
 
-
 
424
    if (vport->cursor_shown)
-
 
425
        cursor_hide(vp);
-
 
426
    else
-
 
427
        cursor_print(vp);
-
 
428
}
-
 
429
 
398
/** Draw character at given position relative to viewport
430
/** Draw character at given position relative to viewport
399
 *
431
 *
400
 * @param vp Viewport identification
432
 * @param vp Viewport identification
401
 * @param c Character to print
433
 * @param c Character to print
402
 * @param row Screen position relative to viewport
434
 * @param row Screen position relative to viewport
403
 * @param col Screen position relative to viewport
435
 * @param col Screen position relative to viewport
404
 */
436
 */
405
static void draw_char(int vp, char c, unsigned int row, unsigned int col)
437
static void draw_char(int vp, char c, unsigned int row, unsigned int col)
406
{
438
{
407
    viewport_t *vport = &viewports[vp];
439
    viewport_t *vport = &viewports[vp];
408
 
440
 
-
 
441
    /* Optimize - do not hide cursor if we are going to overwrite it */
-
 
442
    if (vport->cursor_active && vport->cursor_shown &&
409
    if (vport->cursor_active && (vport->cur_col != col || vport->cur_row != row))
443
        (vport->cur_col != col || vport->cur_row != row))
410
        invert_char(vp, vport->cur_row, vport->cur_col);
444
        invert_char(vp, vport->cur_row, vport->cur_col);
411
   
445
   
412
    draw_glyph(vp, c, col * COL_WIDTH, row * FONT_SCANLINES);
446
    draw_glyph(vp, c, col * COL_WIDTH, row * FONT_SCANLINES);
413
 
447
 
414
    vport->cur_col = col;
448
    vport->cur_col = col;
415
    vport->cur_row = row;
449
    vport->cur_row = row;
416
 
450
 
417
    vport->cur_col++;
451
    vport->cur_col++;
418
    if (vport->cur_col>= vport->cols) {
452
    if (vport->cur_col>= vport->cols) {
419
        vport->cur_col = 0;
453
        vport->cur_col = 0;
420
        vport->cur_row++;
454
        vport->cur_row++;
421
        if (vport->cur_row >= vport->rows)
455
        if (vport->cur_row >= vport->rows)
422
            vport->cur_row--;
456
            vport->cur_row--;
423
    }
457
    }
424
    if (vport->cursor_active)
458
    cursor_print(vp);
425
        invert_char(vp, vport->cur_row, vport->cur_col);
-
 
426
}
459
}
427
 
460
 
428
/** Function for handling connections to FB
461
/** Function for handling connections to FB
429
 *
462
 *
430
 */
463
 */
431
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
464
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
432
{
465
{
433
    ipc_callid_t callid;
466
    ipc_callid_t callid;
434
    ipc_call_t call;
467
    ipc_call_t call;
435
    int retval;
468
    int retval;
436
    int i;
469
    int i;
437
    unsigned int row,col;
470
    unsigned int row,col;
438
    char c;
471
    char c;
439
 
472
 
440
    int vp = 0;
473
    int vp = 0;
441
    viewport_t *vport = &viewports[0];
474
    viewport_t *vport = &viewports[0];
442
 
475
 
443
    if (client_connected) {
476
    if (client_connected) {
444
        ipc_answer_fast(iid, ELIMIT, 0,0);
477
        ipc_answer_fast(iid, ELIMIT, 0,0);
445
        return;
478
        return;
446
    }
479
    }
447
    client_connected = 1;
480
    client_connected = 1;
448
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
481
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
449
 
482
 
450
    while (1) {
483
    while (1) {
451
        callid = async_get_call(&call);
484
        callid = async_get_call_timeout(&call,250000);
-
 
485
        if (!callid) {
-
 
486
            cursor_blink(vp);
-
 
487
            continue;
-
 
488
        }
452
        switch (IPC_GET_METHOD(call)) {
489
        switch (IPC_GET_METHOD(call)) {
453
        case IPC_M_PHONE_HUNGUP:
490
        case IPC_M_PHONE_HUNGUP:
454
            client_connected = 0;
491
            client_connected = 0;
455
            /* cleanup other viewports */
492
            /* cleanup other viewports */
456
            for (i=1; i < MAX_VIEWPORTS; i++)
493
            for (i=1; i < MAX_VIEWPORTS; i++)
457
                vport->initialized = 0;
494
                vport->initialized = 0;
458
            ipc_answer_fast(callid,0,0,0);
495
            ipc_answer_fast(callid,0,0,0);
459
            return; /* Exit thread */
496
            return; /* Exit thread */
460
        case FB_PUTCHAR:
497
        case FB_PUTCHAR:
461
            c = IPC_GET_ARG1(call);
498
            c = IPC_GET_ARG1(call);
462
            row = IPC_GET_ARG2(call);
499
            row = IPC_GET_ARG2(call);
463
            col = IPC_GET_ARG3(call);
500
            col = IPC_GET_ARG3(call);
464
            if (row >= vport->rows || col >= vport->cols) {
501
            if (row >= vport->rows || col >= vport->cols) {
465
                retval = EINVAL;
502
                retval = EINVAL;
466
                break;
503
                break;
467
            }
504
            }
468
            ipc_answer_fast(callid,0,0,0);
505
            ipc_answer_fast(callid,0,0,0);
469
 
506
 
470
            draw_char(vp, c, row, col);
507
            draw_char(vp, c, row, col);
471
            continue; /* msg already answered */
508
            continue; /* msg already answered */
472
        case FB_CLEAR:
509
        case FB_CLEAR:
473
            clear_port(vp);
510
            clear_port(vp);
474
            if (vport->cursor_active)
511
            cursor_print(vp);
475
                invert_char(vp, vport->cur_row, vport->cur_col);
-
 
476
            retval = 0;
512
            retval = 0;
477
            break;
513
            break;
478
        case FB_CURSOR_GOTO:
514
        case FB_CURSOR_GOTO:
479
            row = IPC_GET_ARG1(call);
515
            row = IPC_GET_ARG1(call);
480
            col = IPC_GET_ARG2(call);
516
            col = IPC_GET_ARG2(call);
481
            if (row >= vport->rows || col >= vport->cols) {
517
            if (row >= vport->rows || col >= vport->cols) {
482
                retval = EINVAL;
518
                retval = EINVAL;
483
                break;
519
                break;
484
            }
520
            }
485
            retval = 0;
521
            retval = 0;
486
            if (viewports[vp].cursor_active) {
-
 
487
                invert_char(vp, vport->cur_row, vport->cur_col);
-
 
488
                invert_char(vp, row, col);
522
            cursor_hide(vp);
489
            }
-
 
490
            vport->cur_col = col;
523
            vport->cur_col = col;
491
            vport->cur_row = row;
524
            vport->cur_row = row;
-
 
525
            cursor_print(vp);
492
            break;
526
            break;
493
        case FB_CURSOR_VISIBILITY:
527
        case FB_CURSOR_VISIBILITY:
-
 
528
            cursor_hide(vp);
494
            i = IPC_GET_ARG1(call);
529
            vport->cursor_active = IPC_GET_ARG1(call);
-
 
530
            cursor_print(vp);
495
            retval = 0;
531
            retval = 0;
496
            if ((i && vport->cursor_active) || (!i && !vport->cursor_active))
-
 
497
                break;
-
 
498
 
-
 
499
            vport->cursor_active = i;
-
 
500
            invert_char(vp, vport->cur_row, vport->cur_col);
-
 
501
            break;
532
            break;
502
        case FB_GET_CSIZE:
533
        case FB_GET_CSIZE:
503
            ipc_answer_fast(callid, 0, vport->rows, vport->cols);
534
            ipc_answer_fast(callid, 0, vport->rows, vport->cols);
504
            continue;
535
            continue;
505
        case FB_SCROLL:
536
        case FB_SCROLL:
506
            i = IPC_GET_ARG1(call);
537
            i = IPC_GET_ARG1(call);
507
            if (i > vport->rows || i < (- (int)vport->rows)) {
538
            if (i > vport->rows || i < (- (int)vport->rows)) {
508
                retval = EINVAL;
539
                retval = EINVAL;
509
                break;
540
                break;
510
            }
541
            }
511
            if (vport->cursor_active)
542
            cursor_hide(vp);
512
                invert_char(vp, vport->cur_row, vport->cur_col);
-
 
513
            scroll_port(vp, i);
543
            scroll_port(vp, i);
514
            if (vport->cursor_active)
544
            cursor_print(vp);
515
                invert_char(vp, vport->cur_row, vport->cur_col);
-
 
516
            retval = 0;
545
            retval = 0;
517
            break;
546
            break;
518
        case FB_VIEWPORT_SWITCH:
547
        case FB_VIEWPORT_SWITCH:
519
            i = IPC_GET_ARG1(call);
548
            i = IPC_GET_ARG1(call);
520
            if (i < 0 || i >= MAX_VIEWPORTS) {
549
            if (i < 0 || i >= MAX_VIEWPORTS) {
521
                retval = EINVAL;
550
                retval = EINVAL;
522
                break;
551
                break;
523
            }
552
            }
524
            if (! viewports[i].initialized ) {
553
            if (! viewports[i].initialized ) {
525
                retval = EADDRNOTAVAIL;
554
                retval = EADDRNOTAVAIL;
526
                break;
555
                break;
527
            }
556
            }
-
 
557
            cursor_hide(vp);
528
            vp = i;
558
            vp = i;
529
            vport = &viewports[vp];
559
            vport = &viewports[vp];
-
 
560
            cursor_print(vp);
530
            retval = 0;
561
            retval = 0;
531
            break;
562
            break;
532
        case FB_VIEWPORT_CREATE:
563
        case FB_VIEWPORT_CREATE:
533
            retval = viewport_create(IPC_GET_ARG1(call) >> 16,
564
            retval = viewport_create(IPC_GET_ARG1(call) >> 16,
534
                         IPC_GET_ARG1(call) & 0xffff,
565
                         IPC_GET_ARG1(call) & 0xffff,
535
                         IPC_GET_ARG2(call) >> 16,
566
                         IPC_GET_ARG2(call) >> 16,
536
                         IPC_GET_ARG2(call) & 0xffff);
567
                         IPC_GET_ARG2(call) & 0xffff);
537
            break;
568
            break;
538
        case FB_VIEWPORT_DELETE:
569
        case FB_VIEWPORT_DELETE:
539
            i = IPC_GET_ARG1(call);
570
            i = IPC_GET_ARG1(call);
540
            if (i < 0 || i >= MAX_VIEWPORTS) {
571
            if (i < 0 || i >= MAX_VIEWPORTS) {
541
                retval = EINVAL;
572
                retval = EINVAL;
542
                break;
573
                break;
543
            }
574
            }
544
            if (! viewports[i].initialized ) {
575
            if (! viewports[i].initialized ) {
545
                retval = EADDRNOTAVAIL;
576
                retval = EADDRNOTAVAIL;
546
                break;
577
                break;
547
            }
578
            }
548
            viewports[i].initialized = 0;
579
            viewports[i].initialized = 0;
549
            retval = 0;
580
            retval = 0;
550
            break;
581
            break;
551
        case FB_SET_STYLE:
582
        case FB_SET_STYLE:
552
            vport->fgcolor = IPC_GET_ARG1(call);
583
            vport->fgcolor = IPC_GET_ARG1(call);
553
            vport->bgcolor = IPC_GET_ARG2(call);
584
            vport->bgcolor = IPC_GET_ARG2(call);
554
            retval = 0;
585
            retval = 0;
555
            break;
586
            break;
556
        case FB_GET_RESOLUTION:
587
        case FB_GET_RESOLUTION:
557
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
588
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
558
            continue;
589
            continue;
559
        default:
590
        default:
560
            retval = ENOENT;
591
            retval = ENOENT;
561
        }
592
        }
562
        ipc_answer_fast(callid,retval,0,0);
593
        ipc_answer_fast(callid,retval,0,0);
563
    }
594
    }
564
}
595
}
565
 
596
 
566
/** Initialization of framebuffer */
597
/** Initialization of framebuffer */
567
int fb_init(void)
598
int fb_init(void)
568
{
599
{
569
    __address fb_ph_addr;
600
    __address fb_ph_addr;
570
    unsigned int fb_width;
601
    unsigned int fb_width;
571
    unsigned int fb_height;
602
    unsigned int fb_height;
572
    unsigned int fb_bpp;
603
    unsigned int fb_bpp;
573
    unsigned int fb_scanline;
604
    unsigned int fb_scanline;
574
    __address fb_addr;
605
    __address fb_addr;
575
 
606
 
576
    async_set_client_connection(fb_client_connection);
607
    async_set_client_connection(fb_client_connection);
577
 
608
 
578
    fb_ph_addr=sysinfo_value("fb.address.physical");
609
    fb_ph_addr=sysinfo_value("fb.address.physical");
579
    fb_width=sysinfo_value("fb.width");
610
    fb_width=sysinfo_value("fb.width");
580
    fb_height=sysinfo_value("fb.height");
611
    fb_height=sysinfo_value("fb.height");
581
    fb_bpp=sysinfo_value("fb.bpp");
612
    fb_bpp=sysinfo_value("fb.bpp");
582
    fb_scanline=sysinfo_value("fb.scanline");
613
    fb_scanline=sysinfo_value("fb.scanline");
583
 
614
 
584
    fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE);
615
    fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE);
585
   
616
   
586
    map_physmem((void *)((__address)fb_ph_addr),(void *)fb_addr,
617
    map_physmem((void *)((__address)fb_ph_addr),(void *)fb_addr,
587
            (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,
618
            (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,
588
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
619
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
589
   
620
   
590
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
621
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
591
 
622
 
592
    return 0;
623
    return 0;
593
}
624
}
594
 
625
 
595
 
626