Subversion Repositories HelenOS-historic

Rev

Rev 1430 | Rev 1447 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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