Subversion Repositories HelenOS

Rev

Rev 1509 | Rev 1515 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2006 Jakub Vana
  3.  * Copyright (C) 2006 Ondrej Palkovsky
  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 <stdlib.h>
  31. #include <unistd.h>
  32. #include <string.h>
  33. #include <ddi.h>
  34. #include <sysinfo.h>
  35. #include <align.h>
  36. #include <as.h>
  37. #include <ipc/fb.h>
  38. #include <ipc/ipc.h>
  39. #include <ipc/ns.h>
  40. #include <ipc/services.h>
  41. #include <kernel/errno.h>
  42. #include <async.h>
  43.  
  44. #include "font-8x16.h"
  45. #include "helenos.xbm"
  46. #include "fb.h"
  47. #include "main.h"
  48. #include "../console/screenbuffer.h"
  49.  
  50. #define DEFAULT_BGCOLOR                0x000080
  51. #define DEFAULT_FGCOLOR                0xffff00
  52.  
  53. /***************************************************************/
  54. /* Pixel specific fuctions */
  55.  
  56. typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color);
  57. typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y);
  58.  
  59. struct {
  60.     __u8 *fbaddress ;
  61.  
  62.     unsigned int xres ;
  63.     unsigned int yres ;
  64.     unsigned int scanline ;
  65.     unsigned int pixelbytes ;
  66.  
  67.     putpixel_fn_t putpixel;
  68.     getpixel_fn_t getpixel;
  69. } screen;
  70.  
  71. typedef struct {
  72.     int initialized;
  73.     unsigned int x, y;
  74.     unsigned int width, height;
  75.  
  76.     /* Text support in window */
  77.     unsigned int rows, cols;
  78.     /* Style for text printing */
  79.     style_t style;
  80.     /* Auto-cursor position */
  81.     int cursor_active, cur_col, cur_row;
  82.     int cursor_shown;
  83. } viewport_t;
  84.  
  85. #define MAX_VIEWPORTS 128
  86. static viewport_t viewports[128];
  87.  
  88. /* Allow only 1 connection */
  89. static int client_connected = 0;
  90.  
  91. #define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
  92. #define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
  93. #define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
  94.  
  95. #define COL_WIDTH   8
  96. #define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
  97.  
  98. #define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
  99.  
  100. /** Put pixel - 24-bit depth, 1 free byte */
  101. static void putpixel_4byte(unsigned int x, unsigned int y, int color)
  102. {
  103.     *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color;
  104. }
  105.  
  106. /** Return pixel color - 24-bit depth, 1 free byte */
  107. static int getpixel_4byte(unsigned int x, unsigned int y)
  108. {
  109.     return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff;
  110. }
  111.  
  112. /** Put pixel - 24-bit depth */
  113. static void putpixel_3byte(unsigned int x, unsigned int y, int color)
  114. {
  115.     unsigned int startbyte = POINTPOS(x, y);
  116.  
  117. #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
  118.     screen.fbaddress[startbyte] = RED(color, 8);
  119.     screen.fbaddress[startbyte + 1] = GREEN(color, 8);
  120.     screen.fbaddress[startbyte + 2] = BLUE(color, 8);
  121. #else
  122.     screen.fbaddress[startbyte + 2] = RED(color, 8);
  123.     screen.fbaddress[startbyte + 1] = GREEN(color, 8);
  124.     screen.fbaddress[startbyte + 0] = BLUE(color, 8);
  125. #endif
  126.  
  127. }
  128.  
  129. /** Return pixel color - 24-bit depth */
  130. static int getpixel_3byte(unsigned int x, unsigned int y)
  131. {
  132.     unsigned int startbyte = POINTPOS(x, y);
  133.  
  134.  
  135.  
  136. #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
  137.     return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2];
  138. #else
  139.     return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0];
  140. #endif
  141.                                
  142.  
  143. }
  144.  
  145. /** Put pixel - 16-bit depth (5:6:5) */
  146. static void putpixel_2byte(unsigned int x, unsigned int y, int color)
  147. {
  148.     /* 5-bit, 6-bits, 5-bits */
  149.     *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
  150. }
  151.  
  152. /** Return pixel color - 16-bit depth (5:6:5) */
  153. static int getpixel_2byte(unsigned int x, unsigned int y)
  154. {
  155.     int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y)));
  156.     return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
  157. }
  158.  
  159. /** Put pixel - 8-bit depth (3:2:3) */
  160. static void putpixel_1byte(unsigned int x, unsigned int y, int color)
  161. {
  162.     screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
  163. }
  164.  
  165. /** Return pixel color - 8-bit depth (3:2:3) */
  166. static int getpixel_1byte(unsigned int x, unsigned int y)
  167. {
  168.     int color = screen.fbaddress[POINTPOS(x, y)];
  169.     return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
  170. }
  171.  
  172. /** Put pixel into viewport
  173.  *
  174.  * @param vp Viewport identification
  175.  * @param x X coord relative to viewport
  176.  * @param y Y coord relative to viewport
  177.  * @param color RGB color
  178.  */
  179. static void putpixel(int vp, unsigned int x, unsigned int y, int color)
  180. {
  181.     screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color);
  182. }
  183. /** Get pixel from viewport */
  184. static int getpixel(int vp, unsigned int x, unsigned int y)
  185. {
  186.     return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y);
  187. }
  188.  
  189. /** Fill line with color BGCOLOR */
  190. static void clear_line(int vp, unsigned int y)
  191. {
  192.     unsigned int x;
  193.     for (x = 0; x < viewports[vp].width; x++)
  194.         putpixel(vp, x, y, viewports[vp].style.bg_color);
  195. }
  196.  
  197. /** Fill viewport with background color */
  198. static void clear_port(int vp)
  199. {
  200.     unsigned int y;
  201.  
  202.     clear_line(vp, 0);
  203.     for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) {
  204.         memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
  205.                &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
  206.                screen.pixelbytes * viewports[vp].width);
  207.     }  
  208. }
  209.  
  210. /** Scroll port up/down
  211.  *
  212.  * @param vp Viewport to scroll
  213.  * @param rows Positive number - scroll up, negative - scroll down
  214.  */
  215. static void scroll_port(int vp, int rows)
  216. {
  217.     int y;
  218.     int startline;
  219.     int endline;
  220.    
  221.     if (rows > 0) {
  222.         for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++)
  223.             memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
  224.                    &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)],
  225.                    screen.pixelbytes * viewports[vp].width);
  226.         /* Clear last row */
  227.         startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1);
  228.         endline = viewports[vp].y + viewports[vp].height;
  229.         clear_line(vp, startline);
  230.         for (y=startline+1;y < endline; y++)
  231.             memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
  232.                    &screen.fbaddress[POINTPOS(viewports[vp].x,startline)],
  233.                    screen.pixelbytes * viewports[vp].width);
  234.                  
  235.     } else if (rows < 0) {
  236.         rows = -rows;
  237.         for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--)
  238.             memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
  239.                 &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)],
  240.                 screen.pixelbytes * viewports[vp].width);
  241.         /* Clear first row */
  242.         clear_line(0, viewports[vp].style.bg_color);
  243.         for (y=1;y < rows*FONT_SCANLINES; y++)
  244.             memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)],
  245.                    &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
  246.                    screen.pixelbytes * viewports[vp].width);
  247.     }
  248. }
  249.  
  250. static void invert_pixel(int vp,unsigned int x, unsigned int y)
  251. {
  252.     putpixel(vp, x, y, ~getpixel(vp, x, y));
  253. }
  254.  
  255.  
  256. /***************************************************************/
  257. /* Character-console functions */
  258.  
  259. /** Draw character at given position */
  260. static void draw_glyph(int vp,__u8 glyph, unsigned int sx, unsigned int sy, style_t style)
  261. {
  262.     int i;
  263.     unsigned int y;
  264.     unsigned int glline;
  265.  
  266.     for (y = 0; y < FONT_SCANLINES; y++) {
  267.         glline = fb_font[glyph * FONT_SCANLINES + y];
  268.         for (i = 0; i < 8; i++) {
  269.             if (glline & (1 << (7 - i)))
  270.                 putpixel(vp, sx + i, sy + y, style.fg_color);
  271.             else
  272.                 putpixel(vp, sx + i, sy + y, style.bg_color);
  273.         }
  274.     }
  275. }
  276.  
  277. /** Invert character at given position */
  278. static void invert_char(int vp,unsigned int row, unsigned int col)
  279. {
  280.     unsigned int x;
  281.     unsigned int y;
  282.  
  283.     for (x = 0; x < COL_WIDTH; x++)
  284.         for (y = 0; y < FONT_SCANLINES; y++)
  285.             invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
  286. }
  287.  
  288. static void draw_logo(int vp,unsigned int startx, unsigned int starty)
  289. {
  290.     unsigned int x;
  291.     unsigned int y;
  292.     unsigned int byte;
  293.     unsigned int rowbytes;
  294.  
  295.     rowbytes = (helenos_width - 1) / 8 + 1;
  296.  
  297.     for (y = 0; y < helenos_height; y++)
  298.         for (x = 0; x < helenos_width; x++) {
  299.             byte = helenos_bits[rowbytes * y + x / 8];
  300.             byte >>= x % 8;
  301.             if (byte & 1)
  302.                 putpixel(vp ,startx + x, starty + y, viewports[vp].style.fg_color);
  303.         }
  304. }
  305.  
  306. /***************************************************************/
  307. /* Stdout specific functions */
  308.  
  309.  
  310. /** Create new viewport
  311.  *
  312.  * @return New viewport number
  313.  */
  314. static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
  315.                unsigned int height)
  316. {
  317.     int i;
  318.  
  319. for (i=0; i < MAX_VIEWPORTS; i++) {
  320.         if (!viewports[i].initialized)
  321.             break;
  322.     }
  323.     if (i == MAX_VIEWPORTS)
  324.         return ELIMIT;
  325.  
  326.     if (width ==0 || height == 0 ||
  327.         x+width > screen.xres || y+height > screen.yres)
  328.         return EINVAL;
  329.     if (width < FONT_SCANLINES || height < COL_WIDTH)
  330.         return EINVAL;
  331.  
  332.     viewports[i].x = x;
  333.     viewports[i].y = y;
  334.     viewports[i].width = width;
  335.     viewports[i].height = height;
  336.    
  337.     viewports[i].rows = height / FONT_SCANLINES;
  338.     viewports[i].cols = width / COL_WIDTH;
  339.  
  340.     viewports[i].style.bg_color = DEFAULT_BGCOLOR;
  341.     viewports[i].style.fg_color = DEFAULT_FGCOLOR;
  342.    
  343.     viewports[i].cur_col = 0;
  344.     viewports[i].cur_row = 0;
  345.     viewports[i].cursor_active = 0;
  346.  
  347.     viewports[i].initialized = 1;
  348.  
  349.     return i;
  350. }
  351.  
  352.  
  353. /** Initialize framebuffer as a chardev output device
  354.  *
  355.  * @param addr Address of theframebuffer
  356.  * @param x    Screen width in pixels
  357.  * @param y    Screen height in pixels
  358.  * @param bpp  Bits per pixel (8, 16, 24, 32)
  359.  * @param scan Bytes per one scanline
  360.  *
  361.  */
  362. static void screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
  363. {
  364.     switch (bpp) {
  365.         case 8:
  366.             screen.putpixel = putpixel_1byte;
  367.             screen.getpixel = getpixel_1byte;
  368.             screen.pixelbytes = 1;
  369.             break;
  370.         case 16:
  371.             screen.putpixel = putpixel_2byte;
  372.             screen.getpixel = getpixel_2byte;
  373.             screen.pixelbytes = 2;
  374.             break;
  375.         case 24:
  376.             screen.putpixel = putpixel_3byte;
  377.             screen.getpixel = getpixel_3byte;
  378.             screen.pixelbytes = 3;
  379.             break;
  380.         case 32:
  381.             screen.putpixel = putpixel_4byte;
  382.             screen.getpixel = getpixel_4byte;
  383.             screen.pixelbytes = 4;
  384.             break;
  385.     }
  386.  
  387.        
  388.     screen.fbaddress = (unsigned char *) addr;
  389.     screen.xres = xres;
  390.     screen.yres = yres;
  391.     screen.scanline = scan;
  392.    
  393.     /* Create first viewport */
  394.     viewport_create(0,0,xres,yres);
  395. }
  396.  
  397. static void cursor_hide(int vp)
  398. {
  399.     viewport_t *vport = &viewports[vp];
  400.  
  401.     if (vport->cursor_active && vport->cursor_shown) {
  402.         invert_char(vp, vport->cur_row, vport->cur_col);
  403.         vport->cursor_shown = 0;
  404.     }
  405. }
  406.  
  407. static void cursor_print(int vp)
  408. {
  409.     viewport_t *vport = &viewports[vp];
  410.  
  411.     /* Do not check for cursor_shown */
  412.     if (vport->cursor_active) {
  413.         invert_char(vp, vport->cur_row, vport->cur_col);
  414.         vport->cursor_shown = 1;
  415.     }
  416. }
  417.  
  418. static void cursor_blink(int vp)
  419. {
  420.     viewport_t *vport = &viewports[vp];
  421.  
  422.     if (vport->cursor_shown)
  423.         cursor_hide(vp);
  424.     else
  425.         cursor_print(vp);
  426. }
  427.  
  428. /** Draw character at given position relative to viewport
  429.  *
  430.  * @param vp Viewport identification
  431.  * @param c Character to print
  432.  * @param row Screen position relative to viewport
  433.  * @param col Screen position relative to viewport
  434.  */
  435. static void draw_char(int vp, char c, unsigned int row, unsigned int col, style_t style)
  436. {
  437.     viewport_t *vport = &viewports[vp];
  438.  
  439.     /* Optimize - do not hide cursor if we are going to overwrite it */
  440.     if (vport->cursor_active && vport->cursor_shown &&
  441.         (vport->cur_col != col || vport->cur_row != row))
  442.         invert_char(vp, vport->cur_row, vport->cur_col);
  443.    
  444.     draw_glyph(vp, c, col * COL_WIDTH, row * FONT_SCANLINES, style);
  445.  
  446.     vport->cur_col = col;
  447.     vport->cur_row = row;
  448.  
  449.     vport->cur_col++;
  450.     if (vport->cur_col>= vport->cols) {
  451.         vport->cur_col = 0;
  452.         vport->cur_row++;
  453.         if (vport->cur_row >= vport->rows)
  454.             vport->cur_row--;
  455.     }
  456.     cursor_print(vp);
  457. }
  458.  
  459. static void draw_text_data(int vp, keyfield_t *data)
  460. {
  461.     viewport_t *vport = &viewports[vp];
  462.     int i;
  463.     char c;
  464.  
  465.     clear_port(vp);
  466.     for (i=0; i < vport->cols * vport->rows; i++) {
  467.         if (data[i].character == ' ' && style_same(data[i].style,vport->style))
  468.             continue;
  469.         draw_char(vp, data[i].character, i/vport->cols, i % vport->cols,
  470.               data[i].style);
  471.     }
  472.     cursor_print(vp);
  473. }
  474.  
  475.  
  476. /** Function for handling connections to FB
  477.  *
  478.  */
  479. static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
  480. {
  481.     ipc_callid_t callid;
  482.     ipc_call_t call;
  483.     int retval;
  484.     int i;
  485.     unsigned int row,col;
  486.     char c;
  487.     keyfield_t *interbuffer = NULL;
  488.     size_t intersize = 0;
  489.  
  490.     int vp = 0;
  491.     viewport_t *vport = &viewports[0];
  492.  
  493.     if (client_connected) {
  494.         ipc_answer_fast(iid, ELIMIT, 0,0);
  495.         return;
  496.     }
  497.     client_connected = 1;
  498.     ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
  499.  
  500.     while (1) {
  501.         callid = async_get_call_timeout(&call,250000);
  502.         if (!callid) {
  503.             cursor_blink(vp);
  504.             continue;
  505.         }
  506.         switch (IPC_GET_METHOD(call)) {
  507.         case IPC_M_PHONE_HUNGUP:
  508.             client_connected = 0;
  509.             /* cleanup other viewports */
  510.             for (i=1; i < MAX_VIEWPORTS; i++)
  511.                 vport->initialized = 0;
  512.             ipc_answer_fast(callid,0,0,0);
  513.             return; /* Exit thread */
  514.         case IPC_M_AS_AREA_SEND:
  515.             /* We accept one area for data interchange */
  516.             intersize = IPC_GET_ARG2(call);
  517.             receive_comm_area(callid,&call,(void **)&interbuffer,
  518.                       sizeof(*interbuffer)*viewports[0].cols*viewports[0].rows);
  519.             continue;
  520.  
  521.         case FB_DRAW_TEXT_DATA:
  522.             if (!interbuffer) {
  523.                 retval = EINVAL;
  524.                 break;
  525.             }
  526.             if (intersize < vport->cols*vport->rows*sizeof(*interbuffer)) {
  527.                 retval = EINVAL;
  528.                 break;
  529.             }
  530.             draw_text_data(vp, interbuffer);
  531.             retval = 0;
  532.             break;
  533.         case FB_PUTCHAR:
  534.             c = IPC_GET_ARG1(call);
  535.             row = IPC_GET_ARG2(call);
  536.             col = IPC_GET_ARG3(call);
  537.             if (row >= vport->rows || col >= vport->cols) {
  538.                 retval = EINVAL;
  539.                 break;
  540.             }
  541.             ipc_answer_fast(callid,0,0,0);
  542.  
  543.             draw_char(vp, c, row, col, vport->style);
  544.             continue; /* msg already answered */
  545.         case FB_CLEAR:
  546.             clear_port(vp);
  547.             cursor_print(vp);
  548.             retval = 0;
  549.             break;
  550.         case FB_CURSOR_GOTO:
  551.             row = IPC_GET_ARG1(call);
  552.             col = IPC_GET_ARG2(call);
  553.             if (row >= vport->rows || col >= vport->cols) {
  554.                 retval = EINVAL;
  555.                 break;
  556.             }
  557.             retval = 0;
  558.             cursor_hide(vp);
  559.             vport->cur_col = col;
  560.             vport->cur_row = row;
  561.             cursor_print(vp);
  562.             break;
  563.         case FB_CURSOR_VISIBILITY:
  564.             cursor_hide(vp);
  565.             vport->cursor_active = IPC_GET_ARG1(call);
  566.             cursor_print(vp);
  567.             retval = 0;
  568.             break;
  569.         case FB_GET_CSIZE:
  570.             ipc_answer_fast(callid, 0, vport->rows, vport->cols);
  571.             continue;
  572.         case FB_SCROLL:
  573.             i = IPC_GET_ARG1(call);
  574.             if (i > vport->rows || i < (- (int)vport->rows)) {
  575.                 retval = EINVAL;
  576.                 break;
  577.             }
  578.             cursor_hide(vp);
  579.             scroll_port(vp, i);
  580.             cursor_print(vp);
  581.             retval = 0;
  582.             break;
  583.         case FB_VIEWPORT_SWITCH:
  584.             i = IPC_GET_ARG1(call);
  585.             if (i < 0 || i >= MAX_VIEWPORTS) {
  586.                 retval = EINVAL;
  587.                 break;
  588.             }
  589.             if (! viewports[i].initialized ) {
  590.                 retval = EADDRNOTAVAIL;
  591.                 break;
  592.             }
  593.             cursor_hide(vp);
  594.             vp = i;
  595.             vport = &viewports[vp];
  596.             cursor_print(vp);
  597.             retval = 0;
  598.             break;
  599.         case FB_VIEWPORT_CREATE:
  600.             retval = viewport_create(IPC_GET_ARG1(call) >> 16,
  601.                          IPC_GET_ARG1(call) & 0xffff,
  602.                          IPC_GET_ARG2(call) >> 16,
  603.                          IPC_GET_ARG2(call) & 0xffff);
  604.             break;
  605.         case FB_VIEWPORT_DELETE:
  606.             i = IPC_GET_ARG1(call);
  607.             if (i < 0 || i >= MAX_VIEWPORTS) {
  608.                 retval = EINVAL;
  609.                 break;
  610.             }
  611.             if (! viewports[i].initialized ) {
  612.                 retval = EADDRNOTAVAIL;
  613.                 break;
  614.             }
  615.             viewports[i].initialized = 0;
  616.             retval = 0;
  617.             break;
  618.         case FB_SET_STYLE:
  619.             vport->style.fg_color = IPC_GET_ARG1(call);
  620.             vport->style.bg_color = IPC_GET_ARG2(call);
  621.             retval = 0;
  622.             break;
  623.         case FB_GET_RESOLUTION:
  624.             ipc_answer_fast(callid, 0, screen.xres,screen.yres);
  625.             continue;
  626.         default:
  627.             retval = ENOENT;
  628.         }
  629.         ipc_answer_fast(callid,retval,0,0);
  630.     }
  631. }
  632.  
  633. /** Initialization of framebuffer */
  634. int fb_init(void)
  635. {
  636.     void *fb_ph_addr;
  637.     unsigned int fb_width;
  638.     unsigned int fb_height;
  639.     unsigned int fb_bpp;
  640.     unsigned int fb_scanline;
  641.     void *fb_addr;
  642.     size_t asz;
  643.  
  644.     async_set_client_connection(fb_client_connection);
  645.  
  646.     fb_ph_addr=(void *)sysinfo_value("fb.address.physical");
  647.     fb_width=sysinfo_value("fb.width");
  648.     fb_height=sysinfo_value("fb.height");
  649.     fb_bpp=sysinfo_value("fb.bpp");
  650.     fb_scanline=sysinfo_value("fb.scanline");
  651.  
  652.     asz = fb_scanline*fb_height;
  653.     fb_addr = as_get_mappable_page(asz);
  654.    
  655.     map_physmem(fb_ph_addr, fb_addr, ALIGN_UP(asz,PAGE_SIZE) >>PAGE_WIDTH,
  656.             AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
  657.    
  658.     screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
  659.  
  660.     return 0;
  661. }
  662.  
  663.