Subversion Repositories HelenOS

Rev

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

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