Subversion Repositories HelenOS-historic

Rev

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

Rev 1476 Rev 1485
Line 44... Line 44...
44
#include <async.h>
44
#include <async.h>
45
#include "font-8x16.h"
45
#include "font-8x16.h"
46
#include "helenos.xbm"
46
#include "helenos.xbm"
47
#include "fb.h"
47
#include "fb.h"
48
 
48
 
49
#define EFB (-1)
-
 
50
 
-
 
51
#define DEFAULT_BGCOLOR     0x000080
49
#define DEFAULT_BGCOLOR                0x000080
52
#define DEFAULT_FGCOLOR     0xffff00
50
#define DEFAULT_FGCOLOR                0xffff00
53
#define DEFAULT_LOGOCOLOR   0x0000ff
-
 
54
 
-
 
55
#define MAIN_BGCOLOR        0x404000
-
 
56
#define MAIN_FGCOLOR        0x000000
-
 
57
#define MAIN_LOGOCOLOR  0x404000
-
 
58
 
-
 
59
#define SPACING (2)
-
 
60
 
-
 
61
#define H_NO_VFBS 3
-
 
62
#define V_NO_VFBS 3
-
 
63
 
-
 
64
static void fb_putchar(int item,char ch);
-
 
65
int create_window(int item,unsigned int x, unsigned int y,unsigned int x_size, unsigned int y_size,
-
 
66
    unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR);
-
 
67
void fb_init(int item,__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan,
-
 
68
    unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR);
-
 
69
 
-
 
70
unsigned int mod_col(unsigned int col,int mod);
-
 
71
 
-
 
72
static int init_fb(void)
-
 
73
{
-
 
74
    __address fb_ph_addr;
-
 
75
    unsigned int fb_width;
-
 
76
    unsigned int fb_height;
-
 
77
    unsigned int fb_bpp;
-
 
78
    unsigned int fb_scanline;
-
 
79
    __address fb_addr;
-
 
80
    int a=0;
-
 
81
    int i,j,k;
-
 
82
    int w;
-
 
83
    char text[]="HelenOS Framebuffer driver\non Virtual Framebuffer\nVFB ";
-
 
84
 
-
 
85
    fb_ph_addr=sysinfo_value("fb.address.physical");
-
 
86
    fb_width=sysinfo_value("fb.width");
-
 
87
    fb_height=sysinfo_value("fb.height");
-
 
88
    fb_bpp=sysinfo_value("fb.bpp");
-
 
89
    fb_scanline=sysinfo_value("fb.scanline");
-
 
90
 
-
 
91
    fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE);
-
 
92
   
-
 
93
    map_physmem(task_get_id(),(void *)((__address)fb_ph_addr),(void *)fb_addr,
-
 
94
            (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,
-
 
95
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
-
 
96
   
-
 
97
    fb_init(0,fb_addr, fb_width, fb_height, fb_bpp, fb_scanline,
-
 
98
        MAIN_BGCOLOR,MAIN_FGCOLOR,MAIN_LOGOCOLOR);
-
 
99
 
-
 
100
    fb_putchar(0,'\n');
-
 
101
    fb_putchar(0,' ');
-
 
102
 
-
 
103
    for(i=0;i<H_NO_VFBS;i++)
-
 
104
        for(j=0;j<V_NO_VFBS;j++) {
-
 
105
            w = create_window(0,(fb_width/H_NO_VFBS)*i+SPACING,
-
 
106
                      (fb_height/V_NO_VFBS)*j+SPACING,(fb_width/H_NO_VFBS)-2*SPACING ,
-
 
107
                      (fb_height/V_NO_VFBS)-2*SPACING,mod_col(DEFAULT_BGCOLOR,/*i+j*H_NO_VFBS*/0),
-
 
108
                      mod_col(DEFAULT_FGCOLOR,/*i+j*H_NO_VFBS*/0),
-
 
109
                      mod_col(DEFAULT_LOGOCOLOR,/*i+j*H_NO_VFBS)*/0));
-
 
110
           
-
 
111
            if( w== EFB)
-
 
112
                return -1;
-
 
113
           
-
 
114
            for(k=0;text[k];k++)
-
 
115
                fb_putchar(w,text[k]);
-
 
116
            fb_putchar(w,w+'0');
-
 
117
            fb_putchar(w,'\n');
-
 
118
        }
-
 
119
    return 0;
-
 
120
}
-
 
121
 
-
 
122
int vfb_no = 1;
-
 
123
void client_connection(ipc_callid_t iid, ipc_call_t *icall)
-
 
124
{
-
 
125
    ipc_callid_t callid;
-
 
126
    ipc_call_t call;
-
 
127
    int vfb = vfb_no++;
-
 
128
 
-
 
129
    if (vfb > VFB_CONNECTIONS) {
-
 
130
        ipc_answer_fast(iid, ELIMIT, 0,0);
-
 
131
        return;
-
 
132
    }
-
 
133
    ipc_answer_fast(iid, 0, 0, 0);
-
 
134
 
-
 
135
    while (1) {
-
 
136
        callid = async_get_call(&call);
-
 
137
        switch (IPC_GET_METHOD(call)) {
-
 
138
        case IPC_M_PHONE_HUNGUP:
-
 
139
            ipc_answer_fast(callid,0,0,0);
-
 
140
            return; /* Exit thread */
-
 
141
 
-
 
142
        case FB_PUTCHAR:
-
 
143
            fb_putchar(vfb,IPC_GET_ARG2(call));
-
 
144
            ipc_answer_fast(callid,0,0,0);
-
 
145
            break;
-
 
146
/*     
-
 
147
 *      case FB_CLEAR:
-
 
148
            ipc_answer_fast(callid,0,0,0);
-
 
149
            fb_putchar(vfb,IPC_GET_ARG2(call));
-
 
150
            break;
-
 
151
 *      case FB_GOTO:
-
 
152
            ipc_answer_fast(callid,0,0,0);
-
 
153
            fb_putchar(vfb,IPC_GET_ARG2(call));
-
 
154
            break;
-
 
155
*/
-
 
156
        default:
-
 
157
            ipc_answer_fast(callid,ENOENT,0,0);
-
 
158
        }
-
 
159
    }
-
 
160
}
-
 
161
 
-
 
162
int main(int argc, char *argv[])
-
 
163
{
-
 
164
    ipc_call_t call;
-
 
165
    ipc_callid_t callid;
-
 
166
    char connected = 0;
-
 
167
    int res;
-
 
168
    int c;
-
 
169
    ipcarg_t phonead;
-
 
170
   
-
 
171
    ipcarg_t retval, arg1, arg2;
-
 
172
 
-
 
173
    if(!sysinfo_value("fb"))
-
 
174
        return -1;
-
 
175
 
-
 
176
    if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, &phonead)) != 0)
-
 
177
        return -1;
-
 
178
   
-
 
179
    if (init_fb() != 0)
-
 
180
        return -1;
-
 
181
 
-
 
182
    async_manager();
-
 
183
    /* Never reached */
-
 
184
    return 0;
-
 
185
}
-
 
186
 
-
 
187
 
-
 
188
#define GRAPHICS_ITEMS 1024
-
 
189
 
-
 
190
 
51
 
191
/***************************************************************/
52
/***************************************************************/
192
/* Pixel specific fuctions */
53
/* Pixel specific fuctions */
193
 
54
 
194
typedef void (*putpixel_fn_t)(int item,unsigned int x, unsigned int y, int color);
55
typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color);
195
typedef int (*getpixel_fn_t)(int item,unsigned int x, unsigned int y);
56
typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y);
196
 
57
 
197
typedef struct framebuffer_descriptor
-
 
198
{
58
struct {
199
    __u8 *fbaddress ;
59
    __u8 *fbaddress ;
200
 
60
 
201
    unsigned int xres ;
61
    unsigned int xres ;
202
    unsigned int yres ;
62
    unsigned int yres ;
203
    unsigned int scanline ;
63
    unsigned int scanline ;
204
    unsigned int pixelbytes ;
64
    unsigned int pixelbytes ;
205
 
65
 
206
    unsigned int position ;
-
 
207
    unsigned int columns ;
-
 
208
    unsigned int rows ;
-
 
209
   
-
 
210
    unsigned int BGCOLOR;
-
 
211
    unsigned int FGCOLOR;
-
 
212
    unsigned int LOGOCOLOR;
-
 
213
   
-
 
214
    putpixel_fn_t putpixel;
66
    putpixel_fn_t putpixel;
215
    getpixel_fn_t getpixel;
67
    getpixel_fn_t getpixel;
216
   
-
 
217
}framebuffer_descriptor_t;
68
} screen;
218
 
69
 
-
 
70
typedef struct {
-
 
71
    int initialized;
-
 
72
    unsigned int x, y;
-
 
73
    unsigned int width, height;
-
 
74
 
-
 
75
    /* Text support in window */
-
 
76
    unsigned int rows, cols;
-
 
77
    /* Style for text printing */
-
 
78
    int bgcolor, fgcolor;
-
 
79
    /* Auto-cursor position */
219
void * graphics_items[GRAPHICS_ITEMS+1]={NULL};
80
    int cursor_active, cur_x, cur_y;
-
 
81
} viewport_t;
220
 
82
 
-
 
83
#define MAX_VIEWPORTS 128
221
#define FB(__a__,__b__) (((framebuffer_descriptor_t*)(graphics_items[__a__]))->__b__)
84
static viewport_t viewports[128];
-
 
85
 
-
 
86
/* Allow only 1 connection */
-
 
87
static int client_connected = 0;
222
 
88
 
223
#define COL_WIDTH   8
-
 
224
#define ROW_BYTES   (FB(item,scanline) * FONT_SCANLINES)
-
 
225
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
89
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
226
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
90
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
227
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
91
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
228
 
92
 
-
 
93
#define COL_WIDTH   8
229
#define POINTPOS(x, y)  (y * FB(item,scanline) + x * FB(item,pixelbytes))
94
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
230
 
-
 
231
 
-
 
232
 
95
 
-
 
96
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
233
 
97
 
234
/** Put pixel - 24-bit depth, 1 free byte */
98
/** Put pixel - 24-bit depth, 1 free byte */
235
static void putpixel_4byte(int item,unsigned int x, unsigned int y, int color)
99
static void putpixel_4byte(unsigned int x, unsigned int y, int color)
236
{
100
{
237
    *((__u32 *)(FB(item,fbaddress) + POINTPOS(x, y))) = color;
101
    *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color;
238
}
102
}
239
 
103
 
240
/** Return pixel color - 24-bit depth, 1 free byte */
104
/** Return pixel color - 24-bit depth, 1 free byte */
241
static int getpixel_4byte(int item,unsigned int x, unsigned int y)
105
static int getpixel_4byte(unsigned int x, unsigned int y)
242
{
106
{
243
    return *((__u32 *)(FB(item,fbaddress) + POINTPOS(x, y))) & 0xffffff;
107
    return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff;
244
}
108
}
245
 
109
 
246
/** Put pixel - 24-bit depth */
110
/** Put pixel - 24-bit depth */
247
static void putpixel_3byte(int item,unsigned int x, unsigned int y, int color)
111
static void putpixel_3byte(unsigned int x, unsigned int y, int color)
248
{
112
{
249
    unsigned int startbyte = POINTPOS(x, y);
113
    unsigned int startbyte = POINTPOS(x, y);
250
 
114
 
251
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
115
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
252
    FB(item,fbaddress)[startbyte] = RED(color, 8);
116
    screen.fbaddress[startbyte] = RED(color, 8);
253
    FB(item,fbaddress)[startbyte + 1] = GREEN(color, 8);
117
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
254
    FB(item,fbaddress)[startbyte + 2] = BLUE(color, 8);
118
    screen.fbaddress[startbyte + 2] = BLUE(color, 8);
255
#else
119
#else
256
    FB(item,fbaddress)[startbyte + 2] = RED(color, 8);
120
    screen.fbaddress[startbyte + 2] = RED(color, 8);
257
    FB(item,fbaddress)[startbyte + 1] = GREEN(color, 8);
121
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
258
    FB(item,fbaddress)[startbyte + 0] = BLUE(color, 8);
122
    screen.fbaddress[startbyte + 0] = BLUE(color, 8);
259
#endif
123
#endif
260
 
124
 
261
}
125
}
262
 
126
 
263
/** Return pixel color - 24-bit depth */
127
/** Return pixel color - 24-bit depth */
264
static int getpixel_3byte(int item,unsigned int x, unsigned int y)
128
static int getpixel_3byte(unsigned int x, unsigned int y)
265
{
129
{
266
    unsigned int startbyte = POINTPOS(x, y);
130
    unsigned int startbyte = POINTPOS(x, y);
267
 
131
 
268
 
132
 
269
 
133
 
270
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
134
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
271
    return FB(item,fbaddress)[startbyte] << 16 | FB(item,fbaddress)[startbyte + 1] << 8 | FB(item,fbaddress)[startbyte + 2];
135
    return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2];
272
#else
136
#else
273
    return FB(item,fbaddress)[startbyte + 2] << 16 | FB(item,fbaddress)[startbyte + 1] << 8 | FB(item,fbaddress)[startbyte + 0];
137
    return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0];
274
#endif
138
#endif
275
                               
139
                               
276
 
140
 
277
}
141
}
278
 
142
 
279
/** Put pixel - 16-bit depth (5:6:5) */
143
/** Put pixel - 16-bit depth (5:6:5) */
280
static void putpixel_2byte(int item,unsigned int x, unsigned int y, int color)
144
static void putpixel_2byte(unsigned int x, unsigned int y, int color)
281
{
145
{
282
    /* 5-bit, 6-bits, 5-bits */
146
    /* 5-bit, 6-bits, 5-bits */
283
    *((__u16 *)(FB(item,fbaddress) + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
147
    *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
284
}
148
}
285
 
149
 
286
/** Return pixel color - 16-bit depth (5:6:5) */
150
/** Return pixel color - 16-bit depth (5:6:5) */
287
static int getpixel_2byte(int item,unsigned int x, unsigned int y)
151
static int getpixel_2byte(unsigned int x, unsigned int y)
288
{
152
{
289
    int color = *((__u16 *)(FB(item,fbaddress) + POINTPOS(x, y)));
153
    int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y)));
290
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
154
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
291
}
155
}
292
 
156
 
293
/** Put pixel - 8-bit depth (3:2:3) */
157
/** Put pixel - 8-bit depth (3:2:3) */
294
static void putpixel_1byte(int item,unsigned int x, unsigned int y, int color)
158
static void putpixel_1byte(unsigned int x, unsigned int y, int color)
295
{
159
{
296
    FB(item,fbaddress)[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
160
    screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
297
}
161
}
298
 
162
 
299
/** Return pixel color - 8-bit depth (3:2:3) */
163
/** Return pixel color - 8-bit depth (3:2:3) */
300
static int getpixel_1byte(int item,unsigned int x, unsigned int y)
164
static int getpixel_1byte(unsigned int x, unsigned int y)
301
{
165
{
302
    int color = FB(item,fbaddress)[POINTPOS(x, y)];
166
    int color = screen.fbaddress[POINTPOS(x, y)];
303
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
167
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
304
}
168
}
305
 
169
 
-
 
170
static void putpixel(int vp, unsigned int x, unsigned int y, int color)
-
 
171
{
-
 
172
    screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color);
-
 
173
}
-
 
174
static int getpixel(int vp, unsigned int x, unsigned int y)
-
 
175
{
-
 
176
    return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y);
-
 
177
}
-
 
178
 
306
/** Fill line with color BGCOLOR */
179
/** Fill line with color BGCOLOR */
307
static void clear_line(int item,unsigned int y)
180
static void clear_line(int vp, unsigned int y)
308
{
181
{
309
    unsigned int x;
182
    unsigned int x;
310
    for (x = 0; x < FB(item,xres); x++)
183
    for (x = 0; x < viewports[vp].width; x++)
311
        FB(item,putpixel)(item,x, y, FB(item,BGCOLOR));
184
        putpixel(vp, x, y, viewports[vp].bgcolor);
312
}
185
}
313
 
186
 
314
 
-
 
315
/** Fill screen with background color */
187
/** Fill viewport with background color */
316
static void clear_screen(int item)
188
static void clear_port(int vp)
317
{
189
{
318
    unsigned int y;
190
    unsigned int y;
319
    for (y = 0; y < FB(item,yres); y++)
-
 
320
    {
191
 
321
        clear_line(item,y);
192
    clear_line(vp, 0);
-
 
193
    for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) {
-
 
194
        memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
-
 
195
               &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
-
 
196
               screen.pixelbytes * viewports[vp].width);
322
    }  
197
    }  
323
}
198
}
324
 
199
 
-
 
200
/** Optimized scroll for windows that cover whole lines */
-
 
201
//static void scroll_optim(int vp, int rows)
-
 
202
//{
-
 
203
    /* TODO */
-
 
204
//}
325
 
205
 
326
/** Scroll screen one row up */
206
/** Scroll port up/down
-
 
207
 *
-
 
208
 * @param vp Viewport to scroll
-
 
209
 * @param rows Positive number - scroll up, negative - scroll down
-
 
210
 */
327
static void scroll_screen(int item)
211
static void scroll_port(int vp, int rows)
328
{
212
{
-
 
213
    int y;
329
    unsigned int i;
214
    int startline;
330
    unsigned int j;
215
    int endline;
331
 
216
   
-
 
217
    if (rows > 0) {
-
 
218
        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
                   &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)],
-
 
221
                   screen.pixelbytes * viewports[vp].width);
-
 
222
        /* Clear last row */
-
 
223
        startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1);
-
 
224
        endline = viewports[vp].y + viewports[vp].height;
-
 
225
        clear_line(vp, startline);
332
    for(j=0;j<FB(item,yres)-FONT_SCANLINES;j++)
226
        for (y=startline+1;y < endline; y++)
333
        memcpy((void *) FB(item,fbaddress)+j*FB(item,scanline),
227
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
334
            (void *) &FB(item,fbaddress)[ROW_BYTES+j*FB(item,scanline)], FB(item,pixelbytes)*FB(item,xres));
228
                   &screen.fbaddress[POINTPOS(viewports[vp].x,startline)],
-
 
229
                   screen.pixelbytes * viewports[vp].width);
335
 
230
                 
-
 
231
    } else if (rows < 0) {
-
 
232
        rows = -rows;
336
    //memcpy((void *) FB(item,fbaddress), (void *) &FB(item,fbaddress)[ROW_BYTES], FB(item,scanline) * FB(item,yres) - ROW_BYTES);
233
        for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--)
337
 
-
 
-
 
234
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
-
 
235
                &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)],
-
 
236
                screen.pixelbytes * viewports[vp].width);
338
    /* Clear last row */
237
        /* Clear first row */
-
 
238
        clear_line(0, viewports[vp].bgcolor);
339
    for (i = 0; i < FONT_SCANLINES; i++)
239
        for (y=1;y < rows*FONT_SCANLINES; y++)
-
 
240
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)],
-
 
241
                   &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
340
        clear_line(item,(FB(item,rows) - 1) * FONT_SCANLINES + i);
242
                   screen.pixelbytes * viewports[vp].width);
-
 
243
    }
341
}
244
}
342
 
245
 
343
 
-
 
344
static void invert_pixel(int item,unsigned int x, unsigned int y)
246
static void invert_pixel(int vp,unsigned int x, unsigned int y)
345
{
247
{
346
    FB(item,putpixel)(item, x, y, ~FB(item,getpixel)(item, x, y));
248
    putpixel(vp, x, y, ~getpixel(vp, x, y));
347
}
249
}
348
 
250
 
349
 
251
 
350
/** Draw one line of glyph at a given position */
252
/** Draw one line of glyph at a given position */
351
static void draw_glyph_line(int item,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)
352
{
254
{
353
    unsigned int i;
255
    unsigned int i;
354
 
256
 
355
    for (i = 0; i < 8; i++)
257
    for (i = 0; i < 8; i++)
356
        if (glline & (1 << (7 - i))) {
258
        if (glline & (1 << (7 - i))) {
357
            FB(item,putpixel)(item,x + i, y, FB(item,FGCOLOR));
259
            putpixel(vp, x + i, y, viewports[vp].fgcolor);
358
        } else
260
        } else
359
            FB(item,putpixel)(item,x + i, y, FB(item,BGCOLOR));
261
            putpixel(vp, x + i, y, viewports[vp].bgcolor);
360
}
262
}
361
 
263
 
362
/***************************************************************/
264
/***************************************************************/
363
/* Character-console functions */
265
/* Character-console functions */
364
 
266
 
365
/** Draw character at given position */
267
/** Draw character at given position */
366
static void draw_glyph(int item,__u8 glyph, unsigned int col, unsigned int row)
268
static void draw_glyph(int vp,__u8 glyph, unsigned int row, unsigned int col)
367
{
269
{
368
    unsigned int y;
270
    unsigned int y;
369
 
271
 
370
    for (y = 0; y < FONT_SCANLINES; y++)
272
    for (y = 0; y < FONT_SCANLINES; y++)
371
        draw_glyph_line(item ,fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y);
273
        draw_glyph_line(vp ,fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y);
372
}
274
}
373
 
275
 
374
/** Invert character at given position */
276
/** Invert character at given position */
375
static void invert_char(int item,unsigned int col, unsigned int row)
277
static void invert_char(int vp,unsigned int col, unsigned int row)
376
{
278
{
377
    unsigned int x;
279
    unsigned int x;
378
    unsigned int y;
280
    unsigned int y;
379
 
281
 
380
    for (x = 0; x < COL_WIDTH; x++)
282
    for (x = 0; x < COL_WIDTH; x++)
381
        for (y = 0; y < FONT_SCANLINES; y++)
283
        for (y = 0; y < FONT_SCANLINES; y++)
382
            invert_pixel(item,col * COL_WIDTH + x, row * FONT_SCANLINES + y);
284
            invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
383
}
-
 
384
 
-
 
385
/** Draw character at default position */
-
 
386
static void draw_char(int item,char chr)
-
 
387
{
-
 
388
    draw_glyph(item ,chr, FB(item,position) % FB(item,columns), FB(item,position) / FB(item,columns));
-
 
389
}
285
}
390
 
286
 
391
static void draw_logo(int item,unsigned int startx, unsigned int starty)
287
static void draw_logo(int vp,unsigned int startx, unsigned int starty)
392
{
288
{
393
    unsigned int x;
289
    unsigned int x;
394
    unsigned int y;
290
    unsigned int y;
395
    unsigned int byte;
291
    unsigned int byte;
396
    unsigned int rowbytes;
292
    unsigned int rowbytes;
Line 400... Line 296...
400
    for (y = 0; y < helenos_height; y++)
296
    for (y = 0; y < helenos_height; y++)
401
        for (x = 0; x < helenos_width; x++) {
297
        for (x = 0; x < helenos_width; x++) {
402
            byte = helenos_bits[rowbytes * y + x / 8];
298
            byte = helenos_bits[rowbytes * y + x / 8];
403
            byte >>= x % 8;
299
            byte >>= x % 8;
404
            if (byte & 1)
300
            if (byte & 1)
405
                FB(item,putpixel)(item,startx + x, starty + y, FB(item,LOGOCOLOR));
301
                putpixel(vp ,startx + x, starty + y, viewports[vp].fgcolor);
406
        }
302
        }
407
}
303
}
408
 
304
 
409
/***************************************************************/
305
/***************************************************************/
410
/* Stdout specific functions */
306
/* Stdout specific functions */
411
 
307
 
412
static void invert_cursor(int item)
-
 
413
{
-
 
414
    invert_char(item,FB(item,position) % FB(item,columns), FB(item,position) / FB(item,columns));
-
 
415
}
-
 
416
 
308
 
417
/** Print character to screen
309
/** Create new viewport
418
 *
310
 *
419
 *  Emulate basic terminal commands
311
 * @return New viewport number
420
 */
312
 */
-
 
313
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
421
static void fb_putchar(int item,char ch)
314
               unsigned int height)
422
{
315
{
-
 
316
    int i;
423
   
317
 
424
    switch (ch) {
-
 
425
        case '\n':
-
 
426
            invert_cursor(item);
-
 
427
            FB(item,position) += FB(item,columns);
318
    for (i=0; i < MAX_VIEWPORTS; i++) {
428
            FB(item,position) -= FB(item,position) % FB(item,columns);
-
 
429
            break;
-
 
430
        case '\r':
-
 
431
            invert_cursor(item);
-
 
432
            FB(item,position) -= FB(item,position) % FB(item,columns);
-
 
433
            break;
-
 
434
        case '\b':
-
 
435
            invert_cursor(item);
-
 
436
            if (FB(item,position) % FB(item,columns))
319
        if (!viewports[i].initialized)
437
                FB(item,position)--;
-
 
438
            break;
-
 
439
        case '\t':
-
 
440
            invert_cursor(item);
-
 
441
            do {
-
 
442
                draw_char(item,' ');
-
 
443
                FB(item,position)++;
-
 
444
            } while (FB(item,position) % 8);
-
 
445
            break;
320
            break;
446
        default:
-
 
447
            draw_char(item,ch);
-
 
448
            FB(item,position)++;
-
 
449
    }
-
 
450
   
-
 
451
    if (FB(item,position) >= FB(item,columns) * FB(item,rows)) {
-
 
452
        FB(item,position) -= FB(item,columns);
-
 
453
        scroll_screen(item);
-
 
454
    }
321
    }
-
 
322
    if (i == MAX_VIEWPORTS)
-
 
323
        return ELIMIT;
-
 
324
 
-
 
325
    viewports[i].initialized = 1;
-
 
326
    viewports[i].x = x;
-
 
327
    viewports[i].y = y;
-
 
328
    viewports[i].width = width;
-
 
329
    viewports[i].height = height;
455
   
330
   
-
 
331
    viewports[i].rows = height / FONT_SCANLINES;
456
    invert_cursor(item);
332
    viewports[i].cols = width / COL_WIDTH;
-
 
333
 
-
 
334
    viewports[i].bgcolor = DEFAULT_BGCOLOR;
-
 
335
    viewports[i].fgcolor = DEFAULT_FGCOLOR;
457
   
336
   
-
 
337
    return i;
458
}
338
}
459
 
339
 
460
 
340
 
461
/** Initialize framebuffer as a chardev output device
341
/** Initialize framebuffer as a chardev output device
462
 *
342
 *
Line 465... Line 345...
465
 * @param y    Screen height in pixels
345
 * @param y    Screen height in pixels
466
 * @param bpp  Bits per pixel (8, 16, 24, 32)
346
 * @param bpp  Bits per pixel (8, 16, 24, 32)
467
 * @param scan Bytes per one scanline
347
 * @param scan Bytes per one scanline
468
 *
348
 *
469
 */
349
 */
470
void fb_init(int item,__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan,
350
static void screen_init(__address addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
471
    unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR)
-
 
472
{
351
{
473
   
-
 
474
    if( (graphics_items[item]=malloc(sizeof(framebuffer_descriptor_t))) ==NULL)
-
 
475
    {
-
 
476
        return;
-
 
477
    }
-
 
478
 
-
 
479
    switch (bpp) {
352
    switch (bpp) {
480
        case 8:
353
        case 8:
481
            FB(item,putpixel) = putpixel_1byte;
354
            screen.putpixel = putpixel_1byte;
482
            FB(item,getpixel) = getpixel_1byte;
355
            screen.getpixel = getpixel_1byte;
483
            FB(item,pixelbytes) = 1;
356
            screen.pixelbytes = 1;
484
            break;
357
            break;
485
        case 16:
358
        case 16:
486
            FB(item,putpixel) = putpixel_2byte;
359
            screen.putpixel = putpixel_2byte;
487
            FB(item,getpixel) = getpixel_2byte;
360
            screen.getpixel = getpixel_2byte;
488
            FB(item,pixelbytes) = 2;
361
            screen.pixelbytes = 2;
489
            break;
362
            break;
490
        case 24:
363
        case 24:
491
            FB(item,putpixel) = putpixel_3byte;
364
            screen.putpixel = putpixel_3byte;
492
            FB(item,getpixel) = getpixel_3byte;
365
            screen.getpixel = getpixel_3byte;
493
            FB(item,pixelbytes) = 3;
366
            screen.pixelbytes = 3;
494
            break;
367
            break;
495
        case 32:
368
        case 32:
496
            FB(item,putpixel) = putpixel_4byte;
369
            screen.putpixel = putpixel_4byte;
497
            FB(item,getpixel) = getpixel_4byte;
370
            screen.getpixel = getpixel_4byte;
498
            FB(item,pixelbytes) = 4;
371
            screen.pixelbytes = 4;
499
            break;
372
            break;
500
    }
373
    }
501
 
374
 
502
       
375
       
503
    FB(item,fbaddress) = (unsigned char *) addr;
376
    screen.fbaddress = (unsigned char *) addr;
504
    FB(item,xres) = x;
377
    screen.xres = xres;
505
    FB(item,yres) = y;
378
    screen.yres = yres;
506
    FB(item,scanline) = scan;
379
    screen.scanline = scan;
507
   
380
   
508
   
-
 
509
    FB(item,rows) = y / FONT_SCANLINES;
-
 
510
    FB(item,columns) = x / COL_WIDTH;
-
 
511
 
-
 
512
    FB(item,BGCOLOR)=BGCOLOR;
381
    /* Create first viewport */
513
    FB(item,FGCOLOR)=FGCOLOR;
382
    viewport_create(0,0,xres,yres);
514
    FB(item,LOGOCOLOR)=LOGOCOLOR;
-
 
515
 
-
 
516
 
383
 
517
    clear_screen(item);
384
    clear_port(0);
518
    draw_logo(item,FB(item,xres) - helenos_width, 0);
-
 
519
    invert_cursor(item);
-
 
520
 
-
 
521
}
-
 
522
 
-
 
523
 
-
 
524
static int get_free_item()
-
 
525
{
-
 
526
    int item;
-
 
527
    for(item=0;graphics_items[item]!=NULL;item++);
-
 
528
    return (item==GRAPHICS_ITEMS)?EFB:item;
-
 
529
}
385
}
530
 
386
 
531
unsigned int mod_col(unsigned int col,int mod)
387
static int init_fb(void)
532
{
388
{
-
 
389
    __address fb_ph_addr;
533
    if(mod & 1) col^=0xff;
390
    unsigned int fb_width;
534
    if(mod & 2) col^=0xff00;
391
    unsigned int fb_height;
-
 
392
    unsigned int fb_bpp;
535
    if(mod & 4) col^=0xff0000;
393
    unsigned int fb_scanline;
-
 
394
    __address fb_addr;
536
    return col;
395
    int a=0;
-
 
396
    int i,j,k;
537
}
397
    int w;
-
 
398
    char text[]="HelenOS Framebuffer driver\non Virtual Framebuffer\nVFB ";
538
 
399
 
-
 
400
    fb_ph_addr=sysinfo_value("fb.address.physical");
-
 
401
    fb_width=sysinfo_value("fb.width");
-
 
402
    fb_height=sysinfo_value("fb.height");
-
 
403
    fb_bpp=sysinfo_value("fb.bpp");
-
 
404
    fb_scanline=sysinfo_value("fb.scanline");
539
 
405
 
540
int create_window(int item,unsigned int x, unsigned int y,unsigned int x_size, unsigned int y_size,
-
 
541
    unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR)
-
 
542
{
-
 
543
    int item_new;
-
 
544
   
-
 
545
    if(EFB==(item_new=get_free_item()))return EFB;
-
 
546
   
-
 
547
   
-
 
548
    if( (graphics_items[item_new]=malloc(sizeof(framebuffer_descriptor_t))) == NULL)
406
    fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE);
549
    {
-
 
550
        return EFB;
-
 
551
    }
-
 
552
   
-
 
553
   
-
 
554
   
407
   
555
    FB(item_new,putpixel) = FB(item,putpixel);
-
 
556
    FB(item_new,getpixel) = FB(item,getpixel);
-
 
557
    FB(item_new,pixelbytes) = FB(item,pixelbytes);
-
 
558
 
-
 
559
    FB(item_new,fbaddress) = FB(item,fbaddress) + POINTPOS(x, y) ;
408
    map_physmem(task_get_id(),(void *)((__address)fb_ph_addr),(void *)fb_addr,
560
    FB(item_new,xres) = x_size;
-
 
561
    FB(item_new,yres) = y_size;
409
            (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,
562
    FB(item_new,scanline) =  FB(item,scanline);
410
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
563
   
411
   
-
 
412
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
564
 
413
 
565
    FB(item_new,rows) = y_size / FONT_SCANLINES;
-
 
566
    FB(item_new,columns) = x_size / COL_WIDTH;
414
    return 0;
567
 
415
}
568
    FB(item_new,BGCOLOR)=BGCOLOR;
-
 
569
    FB(item_new,FGCOLOR)=FGCOLOR;
-
 
570
    FB(item_new,LOGOCOLOR)=LOGOCOLOR;
-
 
571
 
416
 
-
 
417
void client_connection(ipc_callid_t iid, ipc_call_t *icall)
-
 
418
{
-
 
419
    ipc_callid_t callid;
-
 
420
    ipc_call_t call;
-
 
421
    int retval;
-
 
422
    int i;
-
 
423
    unsigned int row,col;
-
 
424
    char c;
-
 
425
    int vp = 0;
572
 
426
 
573
    clear_screen(item_new);
427
    if (client_connected) {
574
    draw_logo(item_new,FB(item_new,xres) - helenos_width, 0);
428
        ipc_answer_fast(iid, ELIMIT, 0,0);
575
    invert_cursor(item_new);
429
        return;
-
 
430
    }
-
 
431
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
576
 
432
 
-
 
433
    while (1) {
-
 
434
        callid = async_get_call(&call);
-
 
435
        switch (IPC_GET_METHOD(call)) {
-
 
436
        case IPC_M_PHONE_HUNGUP:
-
 
437
            client_connected = 0;
-
 
438
            /* cleanup other viewports */
-
 
439
            for (i=1; i < MAX_VIEWPORTS; i++)
-
 
440
                viewports[i].initialized = 0;
-
 
441
            ipc_answer_fast(callid,0,0,0);
-
 
442
            return; /* Exit thread */
-
 
443
        case FB_PUTCHAR:
-
 
444
            c = IPC_GET_ARG1(call);
-
 
445
            row = IPC_GET_ARG2(call);
-
 
446
            col = IPC_GET_ARG3(call);
-
 
447
            if (row >= viewports[vp].rows || col >= viewports[vp].cols) {
-
 
448
                retval = EINVAL;
-
 
449
                break;
-
 
450
            }
-
 
451
            ipc_answer_fast(callid,0,0,0);
-
 
452
            draw_glyph(vp,c, row, col);
-
 
453
            continue; /* msg already answered */
-
 
454
        case FB_CLEAR:
-
 
455
            clear_port(vp);
-
 
456
            retval = 0;
-
 
457
            break;
-
 
458
/*      case FB_CURSOR_GOTO: */
-
 
459
/*          retval = 0; */
-
 
460
/*          break; */
-
 
461
/*      case FB_CURSOR_VISIBILITY: */
-
 
462
/*          retval = 0; */
-
 
463
/*          break; */
-
 
464
        case FB_GET_CSIZE:
-
 
465
            ipc_answer_fast(callid, 0, viewports[vp].rows, viewports[vp].cols);
-
 
466
            continue;
-
 
467
        default:
-
 
468
            retval = ENOENT;
-
 
469
        }
577
    return item_new;
470
        retval = ENOENT;
-
 
471
        ipc_answer_fast(callid,retval,0,0);
-
 
472
    }
578
}
473
}
579
 
474
 
-
 
475
int main(int argc, char *argv[])
-
 
476
{
-
 
477
    char connected = 0;
-
 
478
    int res;
-
 
479
    ipcarg_t phonead;
580
 
480
 
-
 
481
    if(!sysinfo_value("fb"))
-
 
482
        return -1;
-
 
483
 
-
 
484
    if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, &phonead)) != 0)
-
 
485
        return -1;
-
 
486
   
-
 
487
    if (init_fb() != 0)
-
 
488
        return -1;
581
 
489
 
-
 
490
    async_manager();
-
 
491
    /* Never reached */
-
 
492
    return 0;
-
 
493
}