Subversion Repositories HelenOS-historic

Rev

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

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