Changeset a2ae4f4 in mainline
- Timestamp:
- 2006-06-01T14:22:33Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 88c3151
- Parents:
- cf28036
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile
rcf28036 ra2ae4f4 77 77 clean: $(CLEANS) 78 78 find $(SOURCES) -name '*.o' -follow -exec rm \{\} \; 79 find libc -name "_link.ld" -exec rm \{\} \; 79 80 80 81 distclean: clean -
fb/fb.c
rcf28036 ra2ae4f4 47 47 #include "fb.h" 48 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); 49 #define DEFAULT_BGCOLOR 0x000080 50 #define DEFAULT_FGCOLOR 0xffff00 51 52 /***************************************************************/ 53 /* Pixel specific fuctions */ 54 55 typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color); 56 typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y); 57 58 struct { 59 __u8 *fbaddress ; 60 61 unsigned int xres ; 62 unsigned int yres ; 63 unsigned int scanline ; 64 unsigned int pixelbytes ; 65 66 putpixel_fn_t putpixel; 67 getpixel_fn_t getpixel; 68 } screen; 69 70 typedef struct { 71 int initialized; 72 unsigned int x, y; 73 unsigned int width, height; 74 75 /* Text support in window */ 76 unsigned int rows, cols; 77 /* Style for text printing */ 78 int bgcolor, fgcolor; 79 /* Auto-cursor position */ 80 int cursor_active, cur_x, cur_y; 81 } viewport_t; 82 83 #define MAX_VIEWPORTS 128 84 static viewport_t viewports[128]; 85 86 /* Allow only 1 connection */ 87 static int client_connected = 0; 88 89 #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) 90 #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) 91 #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) 92 93 #define COL_WIDTH 8 94 #define ROW_BYTES (screen.scanline * FONT_SCANLINES) 95 96 #define POINTPOS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) 97 98 /** Put pixel - 24-bit depth, 1 free byte */ 99 static void putpixel_4byte(unsigned int x, unsigned int y, int color) 100 { 101 *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color; 102 } 103 104 /** Return pixel color - 24-bit depth, 1 free byte */ 105 static int getpixel_4byte(unsigned int x, unsigned int y) 106 { 107 return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff; 108 } 109 110 /** Put pixel - 24-bit depth */ 111 static void putpixel_3byte(unsigned int x, unsigned int y, int color) 112 { 113 unsigned int startbyte = POINTPOS(x, y); 114 115 #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) 116 screen.fbaddress[startbyte] = RED(color, 8); 117 screen.fbaddress[startbyte + 1] = GREEN(color, 8); 118 screen.fbaddress[startbyte + 2] = BLUE(color, 8); 119 #else 120 screen.fbaddress[startbyte + 2] = RED(color, 8); 121 screen.fbaddress[startbyte + 1] = GREEN(color, 8); 122 screen.fbaddress[startbyte + 0] = BLUE(color, 8); 123 #endif 124 125 } 126 127 /** Return pixel color - 24-bit depth */ 128 static int getpixel_3byte(unsigned int x, unsigned int y) 129 { 130 unsigned int startbyte = POINTPOS(x, y); 131 132 133 134 #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) 135 return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2]; 136 #else 137 return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0]; 138 #endif 139 140 141 } 142 143 /** Put pixel - 16-bit depth (5:6:5) */ 144 static void putpixel_2byte(unsigned int x, unsigned int y, int color) 145 { 146 /* 5-bit, 6-bits, 5-bits */ 147 *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5); 148 } 149 150 /** Return pixel color - 16-bit depth (5:6:5) */ 151 static int getpixel_2byte(unsigned int x, unsigned int y) 152 { 153 int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y))); 154 return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); 155 } 156 157 /** Put pixel - 8-bit depth (3:2:3) */ 158 static void putpixel_1byte(unsigned int x, unsigned int y, int color) 159 { 160 screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3); 161 } 162 163 /** Return pixel color - 8-bit depth (3:2:3) */ 164 static int getpixel_1byte(unsigned int x, unsigned int y) 165 { 166 int color = screen.fbaddress[POINTPOS(x, y)]; 167 return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); 168 } 169 170 static void putpixel(int vp, unsigned int x, unsigned int y, int color) 171 { 172 screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color); 173 } 174 static int getpixel(int vp, unsigned int x, unsigned int y) 175 { 176 return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y); 177 } 178 179 /** Fill line with color BGCOLOR */ 180 static void clear_line(int vp, unsigned int y) 181 { 182 unsigned int x; 183 for (x = 0; x < viewports[vp].width; x++) 184 putpixel(vp, x, y, viewports[vp].bgcolor); 185 } 186 187 /** Fill viewport with background color */ 188 static void clear_port(int vp) 189 { 190 unsigned int y; 191 192 clear_line(vp, 0); 193 for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) { 194 memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], 195 &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)], 196 screen.pixelbytes * viewports[vp].width); 197 } 198 } 199 200 /** Optimized scroll for windows that cover whole lines */ 201 //static void scroll_optim(int vp, int rows) 202 //{ 203 /* TODO */ 204 //} 205 206 /** Scroll port up/down 207 * 208 * @param vp Viewport to scroll 209 * @param rows Positive number - scroll up, negative - scroll down 210 */ 211 static void scroll_port(int vp, int rows) 212 { 213 int y; 214 int startline; 215 int endline; 216 217 if (rows > 0) { 218 for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++) 219 memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], 220 &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)], 221 screen.pixelbytes * viewports[vp].width); 222 /* Clear last row */ 223 startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1); 224 endline = viewports[vp].y + viewports[vp].height; 225 clear_line(vp, startline); 226 for (y=startline+1;y < endline; y++) 227 memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], 228 &screen.fbaddress[POINTPOS(viewports[vp].x,startline)], 229 screen.pixelbytes * viewports[vp].width); 230 231 } else if (rows < 0) { 232 rows = -rows; 233 for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--) 234 memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], 235 &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)], 236 screen.pixelbytes * viewports[vp].width); 237 /* Clear first row */ 238 clear_line(0, viewports[vp].bgcolor); 239 for (y=1;y < rows*FONT_SCANLINES; y++) 240 memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)], 241 &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)], 242 screen.pixelbytes * viewports[vp].width); 243 } 244 } 245 246 static void invert_pixel(int vp,unsigned int x, unsigned int y) 247 { 248 putpixel(vp, x, y, ~getpixel(vp, x, y)); 249 } 250 251 252 /** Draw one line of glyph at a given position */ 253 static void draw_glyph_line(int vp,unsigned int glline, unsigned int x, unsigned int y) 254 { 255 unsigned int i; 256 257 for (i = 0; i < 8; i++) 258 if (glline & (1 << (7 - i))) { 259 putpixel(vp, x + i, y, viewports[vp].fgcolor); 260 } else 261 putpixel(vp, x + i, y, viewports[vp].bgcolor); 262 } 263 264 /***************************************************************/ 265 /* Character-console functions */ 266 267 /** Draw character at given position */ 268 static void draw_glyph(int vp,__u8 glyph, unsigned int row, unsigned int col) 269 { 270 unsigned int y; 271 272 for (y = 0; y < FONT_SCANLINES; y++) 273 draw_glyph_line(vp ,fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y); 274 } 275 276 /** Invert character at given position */ 277 static void invert_char(int vp,unsigned int col, unsigned int row) 278 { 279 unsigned int x; 280 unsigned int y; 281 282 for (x = 0; x < COL_WIDTH; x++) 283 for (y = 0; y < FONT_SCANLINES; y++) 284 invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y); 285 } 286 287 static void draw_logo(int vp,unsigned int startx, unsigned int starty) 288 { 289 unsigned int x; 290 unsigned int y; 291 unsigned int byte; 292 unsigned int rowbytes; 293 294 rowbytes = (helenos_width - 1) / 8 + 1; 295 296 for (y = 0; y < helenos_height; y++) 297 for (x = 0; x < helenos_width; x++) { 298 byte = helenos_bits[rowbytes * y + x / 8]; 299 byte >>= x % 8; 300 if (byte & 1) 301 putpixel(vp ,startx + x, starty + y, viewports[vp].fgcolor); 302 } 303 } 304 305 /***************************************************************/ 306 /* Stdout specific functions */ 307 308 309 /** Create new viewport 310 * 311 * @return New viewport number 312 */ 313 static int viewport_create(unsigned int x, unsigned int y,unsigned int width, 314 unsigned int height) 315 { 316 int i; 317 318 for (i=0; i < MAX_VIEWPORTS; i++) { 319 if (!viewports[i].initialized) 320 break; 321 } 322 if (i == MAX_VIEWPORTS) 323 return ELIMIT; 324 325 viewports[i].initialized = 1; 326 viewports[i].x = x; 327 viewports[i].y = y; 328 viewports[i].width = width; 329 viewports[i].height = height; 330 331 viewports[i].rows = height / FONT_SCANLINES; 332 viewports[i].cols = width / COL_WIDTH; 333 334 viewports[i].bgcolor = DEFAULT_BGCOLOR; 335 viewports[i].fgcolor = DEFAULT_FGCOLOR; 336 337 return i; 338 } 339 340 341 /** Initialize framebuffer as a chardev output device 342 * 343 * @param addr Address of theframebuffer 344 * @param x Screen width in pixels 345 * @param y Screen height in pixels 346 * @param bpp Bits per pixel (8, 16, 24, 32) 347 * @param scan Bytes per one scanline 348 * 349 */ 350 static void screen_init(__address addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan) 351 { 352 switch (bpp) { 353 case 8: 354 screen.putpixel = putpixel_1byte; 355 screen.getpixel = getpixel_1byte; 356 screen.pixelbytes = 1; 357 break; 358 case 16: 359 screen.putpixel = putpixel_2byte; 360 screen.getpixel = getpixel_2byte; 361 screen.pixelbytes = 2; 362 break; 363 case 24: 364 screen.putpixel = putpixel_3byte; 365 screen.getpixel = getpixel_3byte; 366 screen.pixelbytes = 3; 367 break; 368 case 32: 369 screen.putpixel = putpixel_4byte; 370 screen.getpixel = getpixel_4byte; 371 screen.pixelbytes = 4; 372 break; 373 } 374 375 376 screen.fbaddress = (unsigned char *) addr; 377 screen.xres = xres; 378 screen.yres = yres; 379 screen.scanline = scan; 380 381 /* Create first viewport */ 382 viewport_create(0,0,xres,yres); 383 384 clear_port(0); 385 } 71 386 72 387 static int init_fb(void) … … 95 410 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); 96 411 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 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 } 412 screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline); 413 119 414 return 0; 120 415 } 121 416 122 int vfb_no = 1;123 417 void client_connection(ipc_callid_t iid, ipc_call_t *icall) 124 418 { 125 419 ipc_callid_t callid; 126 420 ipc_call_t call; 127 int vfb = vfb_no++; 128 129 if (vfb > VFB_CONNECTIONS) { 421 int retval; 422 int i; 423 unsigned int row,col; 424 char c; 425 int vp = 0; 426 427 if (client_connected) { 130 428 ipc_answer_fast(iid, ELIMIT, 0,0); 131 429 return; 132 430 } 133 ipc_answer_fast(iid, 0, 0, 0); 431 ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ 134 432 135 433 while (1) { 136 434 callid = async_get_call(&call); 137 switch (IPC_GET_METHOD(call)) {435 switch (IPC_GET_METHOD(call)) { 138 436 case IPC_M_PHONE_HUNGUP: 437 client_connected = 0; 438 /* cleanup other viewports */ 439 for (i=1; i < MAX_VIEWPORTS; i++) 440 viewports[i].initialized = 0; 139 441 ipc_answer_fast(callid,0,0,0); 140 442 return; /* Exit thread */ 141 142 443 case FB_PUTCHAR: 143 fb_putchar(vfb,IPC_GET_ARG2(call)); 444 c = IPC_GET_ARG1(call); 445 row = IPC_GET_ARG2(call); 446 col = IPC_GET_ARG3(call); 447 if (row >= viewports[vp].rows || col >= viewports[vp].cols) { 448 retval = EINVAL; 449 break; 450 } 144 451 ipc_answer_fast(callid,0,0,0); 145 break; 146 /* 147 * case FB_CLEAR: 148 ipc_answer_fast(callid,0,0,0); 149 fb_putchar(vfb,IPC_GET_ARG2(call)); 150 break; 151 * case FB_GOTO: 152 ipc_answer_fast(callid,0,0,0); 153 fb_putchar(vfb,IPC_GET_ARG2(call)); 154 break; 155 */ 452 draw_glyph(vp,c, row, col); 453 continue; /* msg already answered */ 454 case FB_CLEAR: 455 clear_port(vp); 456 retval = 0; 457 break; 458 /* case FB_CURSOR_GOTO: */ 459 /* retval = 0; */ 460 /* break; */ 461 /* case FB_CURSOR_VISIBILITY: */ 462 /* retval = 0; */ 463 /* break; */ 464 case FB_GET_CSIZE: 465 ipc_answer_fast(callid, 0, viewports[vp].rows, viewports[vp].cols); 466 continue; 156 467 default: 157 ipc_answer_fast(callid,ENOENT,0,0);468 retval = ENOENT; 158 469 } 470 retval = ENOENT; 471 ipc_answer_fast(callid,retval,0,0); 159 472 } 160 473 } … … 162 475 int main(int argc, char *argv[]) 163 476 { 164 ipc_call_t call;165 ipc_callid_t callid;166 477 char connected = 0; 167 478 int res; 168 int c;169 479 ipcarg_t phonead; 170 171 ipcarg_t retval, arg1, arg2;172 480 173 481 if(!sysinfo_value("fb")) … … 184 492 return 0; 185 493 } 186 187 188 #define GRAPHICS_ITEMS 1024189 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_descriptor198 {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 8224 #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 #else256 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 #endif260 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 #else273 return FB(item,fbaddress)[startbyte + 2] << 16 | FB(item,fbaddress)[startbyte + 1] << 8 | FB(item,fbaddress)[startbyte + 0];274 #endif275 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 {321 clear_line(item,y);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 } else359 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 screen418 *419 * Emulate basic terminal commands420 */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 device462 *463 * @param addr Address of theframebuffer464 * @param x Screen width in pixels465 * @param y Screen height in pixels466 * @param bpp Bits per pixel (8, 16, 24, 32)467 * @param scan Bytes per one scanline468 *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 503 FB(item,fbaddress) = (unsigned char *) addr;504 FB(item,xres) = x;505 FB(item,yres) = y;506 FB(item,scanline) = scan;507 508 509 FB(item,rows) = y / FONT_SCANLINES;510 FB(item,columns) = x / COL_WIDTH;511 512 FB(item,BGCOLOR)=BGCOLOR;513 FB(item,FGCOLOR)=FGCOLOR;514 FB(item,LOGOCOLOR)=LOGOCOLOR;515 516 517 clear_screen(item);518 draw_logo(item,FB(item,xres) - helenos_width, 0);519 invert_cursor(item);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 548 if( (graphics_items[item_new]=malloc(sizeof(framebuffer_descriptor_t))) == NULL)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 -
fb/fb.h
rcf28036 ra2ae4f4 33 33 #include <arch/types.h> 34 34 35 #define VFB_CONNECTIONS 936 37 //void fb_init(int item,__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan);38 39 35 #endif -
libc/generic/string.c
rcf28036 ra2ae4f4 43 43 } 44 44 45 void * memcpy(void *dest, void *src, size_t n) 46 { 47 char *os = src; 48 char *odst = dest; 49 while (n--) 50 *(odst++) = *(os++); 51 return dest; 52 } 45 void * memcpy(void *dst, const void *src, size_t n) 46 { 47 int i, j; 48 49 for (i = 0; i < n/sizeof(unsigned long); i++) 50 ((unsigned long *) dst)[i] = ((unsigned long *) src)[i]; 51 52 for (j = 0; j < n%sizeof(unsigned long); j++) 53 ((unsigned char *)(((unsigned long *) dst) + i))[j] = ((unsigned char *)(((unsigned long *) src) + i))[j]; 54 55 return (char *)src; 56 } 57 58 void * memmove(void *dst, const void *src, size_t n) 59 { 60 int i, j; 61 62 if (src > dst) 63 return memcpy(dst, src, n); 64 65 for (j = (n%sizeof(unsigned long))-1; j >= 0; j--) 66 ((unsigned char *)(((unsigned long *) dst) + i))[j] = ((unsigned char *)(((unsigned long *) src) + i))[j]; 67 68 for (i = n/sizeof(unsigned long)-1; i >=0 ; i--) 69 ((unsigned long *) dst)[i] = ((unsigned long *) src)[i]; 70 71 return (char *)src; 72 } 73 53 74 54 75 /** Count the number of characters in the string, not including terminating 0. -
libc/include/ipc/fb.h
rcf28036 ra2ae4f4 7 7 #define __libc__FB_H__ 8 8 9 #define FB_GET_VFB 1024 10 #define FB_PUTCHAR 1025 11 12 #define METHOD_WIDTH 16 13 #define ITEM_WIDTH 16 14 #define COUNT_WIDTH 16 /* Should be 8 times integer */ 9 #define FB_PUTCHAR 1025 10 #define FB_CLEAR 1026 11 #define FB_GET_CSIZE 1027 15 12 16 13 17 struct _fb_method {18 unsigned m : METHOD_WIDTH;19 unsigned item : ITEM_WIDTH;20 } __attribute__((packed));21 22 union fb_method {23 struct _fb_method m;24 __native fill;25 } __attribute__((packed));26 27 struct fb_call_args {28 union fb_method method;29 union {30 struct {31 unsigned count : COUNT_WIDTH;32 char chars[3 * sizeof(__native) - (COUNT_WIDTH >> 3)];33 } putchar __attribute__((packed));34 } data ; // __attribute__((packed));35 } __attribute__((packed));36 37 struct fb_ipc_args {38 __native method;39 __native arg1;40 __native arg2;41 __native arg3;42 } __attribute__((packed));43 44 union fb_args {45 struct fb_call_args fb_args;46 struct fb_ipc_args ipc_args;47 } __attribute__((packed));48 49 typedef union fb_args fb_args_t;50 51 14 #endif -
libc/include/string.h
rcf28036 ra2ae4f4 36 36 37 37 void * memset(void *s, int c, size_t n); 38 void * memcpy(void *dest, void *src, size_t n); 38 void * memcpy(void *dest, const void *src, size_t n); 39 void * memmove(void *dest, const void *src, size_t n); 39 40 40 41 int strcmp(const char *, const char *);
Note:
See TracChangeset
for help on using the changeset viewer.