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