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