Changeset 9f1362d4 in mainline for uspace/srv


Ignore:
Timestamp:
2010-04-19T19:58:18Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
369a5f8
Parents:
caad59a
Message:

console output improvements

  • define new generic styles (STYLE_INVERTED for inverted print and STYLE_SELECTION for selections), use them primarily instead of specifying colors or RGBs
  • use console_set_style(fphone(stdout), STYLE_NORMAL) as the correct mean for reseting console settings (instead of specifying conrete hardcoded colors)
  • rename console_goto() to console_set_pos() (consistency with console_get_pos())
  • use semantically correct unsigned types for console sizes and cursor positions (instead of signed types)
  • use unsigned types for sizes and positions in libclui
  • top: nicer screen redrawing (do not use console_clear() which causes flickering, but repaint the screen properly — not entirely finished yet)
  • initialize mouse pointer coordinates (so the mouse cursor does not behave erratic after boot, unfortunatelly this does not solve ticket #223)
Location:
uspace/srv/hid
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/console.c

    rcaad59a r9f1362d4  
    7171/** Information about framebuffer */
    7272struct {
    73         int phone;      /**< Framebuffer phone */
    74         ipcarg_t cols;  /**< Framebuffer columns */
    75         ipcarg_t rows;  /**< Framebuffer rows */
    76         int color_cap;  /**< Color capabilities (FB_CCAP_xxx) */
     73        int phone;           /**< Framebuffer phone */
     74        ipcarg_t cols;       /**< Framebuffer columns */
     75        ipcarg_t rows;       /**< Framebuffer rows */
     76        ipcarg_t color_cap;  /**< Color capabilities (FB_CCAP_xxx) */
    7777} fb_info;
    7878
     
    9999/** Information on row-span yet unsent to FB driver. */
    100100struct {
    101         size_t col;  /**< Leftmost column of the span. */
    102         size_t row;  /**< Row where the span lies. */
    103         size_t cnt;  /**< Width of the span. */
     101        ipcarg_t col;  /**< Leftmost column of the span. */
     102        ipcarg_t row;  /**< Row where the span lies. */
     103        ipcarg_t cnt;  /**< Width of the span. */
    104104} fb_pending;
    105105
     
    117117}
    118118
    119 static void curs_goto(size_t x, size_t y)
     119static void curs_goto(ipcarg_t x, ipcarg_t y)
    120120{
    121121        async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
     
    147147}
    148148
    149 static void set_style(int style)
     149static void set_style(uint8_t style)
    150150{
    151151        async_msg_1(fb_info.phone, FB_SET_STYLE, style);
    152152}
    153153
    154 static void set_color(int fgcolor, int bgcolor, int flags)
     154static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags)
    155155{
    156156        async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
    157157}
    158158
    159 static void set_rgb_color(int fgcolor, int bgcolor)
     159static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
    160160{
    161161        async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
     
    178178}
    179179
    180 static int ccap_fb_to_con(int ccap_fb, int *ccap_con)
     180static int ccap_fb_to_con(ipcarg_t ccap_fb, ipcarg_t *ccap_con)
    181181{
    182182        switch (ccap_fb) {
    183         case FB_CCAP_NONE: *ccap_con = CONSOLE_CCAP_NONE; break;
    184         case FB_CCAP_STYLE: *ccap_con = CONSOLE_CCAP_STYLE; break;
    185         case FB_CCAP_INDEXED: *ccap_con = CONSOLE_CCAP_INDEXED; break;
    186         case FB_CCAP_RGB: *ccap_con = CONSOLE_CCAP_RGB; break;
    187         default: return EINVAL;
    188         }
    189 
     183        case FB_CCAP_NONE:
     184                *ccap_con = CONSOLE_CCAP_NONE;
     185                break;
     186        case FB_CCAP_STYLE:
     187                *ccap_con = CONSOLE_CCAP_STYLE;
     188                break;
     189        case FB_CCAP_INDEXED:
     190                *ccap_con = CONSOLE_CCAP_INDEXED;
     191                break;
     192        case FB_CCAP_RGB:
     193                *ccap_con = CONSOLE_CCAP_RGB;
     194                break;
     195        default:
     196                return EINVAL;
     197        }
     198       
    190199        return EOK;
    191200}
     
    226235 *
    227236 */
    228 static void cell_mark_changed(size_t col, size_t row)
     237static void cell_mark_changed(ipcarg_t col, ipcarg_t row)
    229238{
    230239        if (fb_pending.cnt != 0) {
     
    253262{
    254263        bool flush_cursor = false;
    255 
     264       
    256265        switch (ch) {
    257266        case '\n':
     
    297306                        async_msg_1(fb_info.phone, FB_SCROLL, 1);
    298307        }
    299 
     308       
    300309        if (cons == active_console && flush_cursor)
    301310                curs_goto(cons->scr.position_x, cons->scr.position_y);
     
    327336       
    328337        if (cons != kernel_console) {
    329                 size_t x;
    330                 size_t y;
    331                 int rc = 0;
    332                
    333338                async_serialize_start();
    334339               
     
    344349                set_attrs(&cons->scr.attrs);
    345350                curs_visibility(false);
     351               
     352                ipcarg_t x;
     353                ipcarg_t y;
     354                int rc = 0;
     355               
    346356                if (interbuffer) {
    347357                        for (y = 0; y < cons->scr.size_y; y++) {
     
    390400        /* Ignore parameters, the connection is already opened */
    391401        while (true) {
    392                
    393402                ipc_call_t call;
    394403                ipc_callid_t callid = async_get_call(&call);
     
    433442static void mouse_events(ipc_callid_t iid, ipc_call_t *icall)
    434443{
    435         int button, press;
    436         int dx, dy;
    437         int newcon;
    438 
    439444        /* Ignore parameters, the connection is already opened */
    440445        while (true) {
    441 
    442446                ipc_call_t call;
    443447                ipc_callid_t callid = async_get_call(&call);
    444 
     448               
    445449                int retval;
    446 
     450               
    447451                switch (IPC_GET_METHOD(call)) {
    448452                case IPC_M_PHONE_HUNGUP:
     
    450454                        return;
    451455                case MEVENT_BUTTON:
    452                         button = IPC_GET_ARG1(call);
    453                         press = IPC_GET_ARG2(call);
    454                         if (button == 1) {
    455                                 newcon = gcons_mouse_btn(press);
     456                        if (IPC_GET_ARG1(call) == 1) {
     457                                int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call));
    456458                                if (newcon != -1)
    457459                                        change_console(&consoles[newcon]);
     
    460462                        break;
    461463                case MEVENT_MOVE:
    462                         dx = IPC_GET_ARG1(call);
    463                         dy = IPC_GET_ARG2(call);
    464                         gcons_mouse_move(dx, dy);
     464                        gcons_mouse_move((int) IPC_GET_ARG1(call),
     465                            (int) IPC_GET_ARG2(call));
    465466                        retval = 0;
    466467                        break;
     
    520521        console_event_t ev;
    521522        fibril_mutex_lock(&input_mutex);
     523       
    522524recheck:
    523525        while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) {
     
    536538                goto recheck;
    537539        }
     540       
    538541        fibril_mutex_unlock(&input_mutex);
    539542}
     
    542545{
    543546        console_event_t ev;
    544 
     547       
    545548        fibril_mutex_lock(&input_mutex);
     549       
    546550recheck:
    547551        if (keybuffer_pop(&cons->keybuffer, &ev)) {
     
    551555                goto recheck;
    552556        }
     557       
    553558        fibril_mutex_unlock(&input_mutex);
    554559}
     
    580585        ipcarg_t arg2;
    581586        ipcarg_t arg3;
    582 
    583         int cons_ccap;
     587       
    584588        int rc;
    585589       
     
    622626                        if (cons == active_console) {
    623627                                async_req_0_0(fb_info.phone, FB_FLUSH);
    624                                
    625628                                curs_goto(cons->scr.position_x, cons->scr.position_y);
    626629                        }
     
    650653                        break;
    651654                case CONSOLE_GET_COLOR_CAP:
    652                         rc = ccap_fb_to_con(fb_info.color_cap, &cons_ccap);
     655                        rc = ccap_fb_to_con(fb_info.color_cap, &arg1);
    653656                        if (rc != EOK) {
    654657                                ipc_answer_0(callid, rc);
    655658                                continue;
    656659                        }
    657                         arg1 = cons_ccap;
    658660                        break;
    659661                case CONSOLE_SET_STYLE:
     
    714716                return false;
    715717        }
    716 
     718       
    717719        kbd_phone = fd_phone(input_fd);
    718720        if (kbd_phone < 0) {
     
    720722                return false;
    721723        }
    722 
     724       
    723725        /* NB: The callback connection is slotted for removal */
    724726        ipcarg_t phonehash;
     
    727729                return false;
    728730        }
    729 
     731       
    730732        async_new_connection(phonehash, 0, NULL, keyboard_events);
    731 
     733       
    732734        /* Connect to mouse device */
    733735        mouse_phone = -1;
    734736        int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY);
    735 
     737       
    736738        if (mouse_fd < 0) {
    737739                printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse");
    738740                goto skip_mouse;
    739741        }
    740 
     742       
    741743        mouse_phone = fd_phone(mouse_fd);
    742744        if (mouse_phone < 0) {
     
    744746                goto skip_mouse;
    745747        }
    746 
     748       
    747749        if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
    748750                printf(NAME ": Failed to create callback from mouse device\n");
     
    750752                goto skip_mouse;
    751753        }
    752 
     754       
    753755        async_new_connection(phonehash, 0, NULL, mouse_events);
    754756skip_mouse:
    755 
     757       
    756758        /* Connect to framebuffer driver */
    757759        fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
     
    760762                return -1;
    761763        }
    762 
     764       
    763765        /* Register driver */
    764766        int rc = devmap_driver_register(NAME, client_connection);
     
    772774       
    773775        /* Synchronize, the gcons could put something in queue */
    774         ipcarg_t color_cap;
    775776        async_req_0_0(fb_info.phone, FB_FLUSH);
    776777        async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
    777         async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &color_cap);
    778         fb_info.color_cap = color_cap;
     778        async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap);
    779779       
    780780        /* Set up shared memory buffer. */
  • uspace/srv/hid/console/gcons.c

    rcaad59a r9f1362d4  
    5454#define STATUS_HEIGHT  48
    5555
    56 #define MAIN_COLOR  0xffffff
     56#define COLOR_MAIN        0xffffff
     57#define COLOR_FOREGROUND  0x202020
     58#define COLOR_BACKGROUND  0xffffff
     59
     60extern char _binary_gfx_helenos_ppm_start[0];
     61extern int _binary_gfx_helenos_ppm_size;
     62extern char _binary_gfx_nameic_ppm_start[0];
     63extern int _binary_gfx_nameic_ppm_size;
     64
     65extern char _binary_gfx_anim_1_ppm_start[0];
     66extern int _binary_gfx_anim_1_ppm_size;
     67extern char _binary_gfx_anim_2_ppm_start[0];
     68extern int _binary_gfx_anim_2_ppm_size;
     69extern char _binary_gfx_anim_3_ppm_start[0];
     70extern int _binary_gfx_anim_3_ppm_size;
     71extern char _binary_gfx_anim_4_ppm_start[0];
     72extern int _binary_gfx_anim_4_ppm_size;
     73
     74extern char _binary_gfx_cons_selected_ppm_start[0];
     75extern int _binary_gfx_cons_selected_ppm_size;
     76extern char _binary_gfx_cons_idle_ppm_start[0];
     77extern int _binary_gfx_cons_idle_ppm_size;
     78extern char _binary_gfx_cons_has_data_ppm_start[0];
     79extern int _binary_gfx_cons_has_data_ppm_size;
     80extern char _binary_gfx_cons_kernel_ppm_start[0];
     81extern int _binary_gfx_cons_kernel_ppm_size;
    5782
    5883static bool use_gcons = false;
     
    82107static size_t active_console = 0;
    83108
    84 size_t mouse_x;
    85 size_t mouse_y;
    86 
    87 bool btn_pressed;
    88 size_t btn_x;
    89 size_t btn_y;
     109static ipcarg_t mouse_x = 0;
     110static ipcarg_t mouse_y= 0;
     111
     112static bool btn_pressed = false;
     113static ipcarg_t btn_x = 0;
     114static ipcarg_t btn_y = 0;
    90115
    91116static void vp_switch(int vp)
     
    95120
    96121/** Create view port */
    97 static int vp_create(size_t x, size_t y, size_t width, size_t height)
     122static int vp_create(ipcarg_t x, ipcarg_t y, ipcarg_t width, ipcarg_t height)
    98123{
    99124        return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
     
    112137
    113138/** Transparent putchar */
    114 static void tran_putch(wchar_t ch, size_t col, size_t row)
     139static void tran_putch(wchar_t ch, ipcarg_t col, ipcarg_t row)
    115140{
    116141        async_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
     
    259284void gcons_mouse_move(ssize_t dx, ssize_t dy)
    260285{
    261         mouse_x = limit(mouse_x + dx, 0, xres);
    262         mouse_y = limit(mouse_y + dy, 0, yres);
    263 
     286        ssize_t nx = (ssize_t) mouse_x + dx;
     287        ssize_t ny = (ssize_t) mouse_y + dy;
     288       
     289        mouse_x = (size_t) limit(nx, 0, xres);
     290        mouse_y = (size_t) limit(ny, 0, yres);
     291       
    264292        if (active_console != KERNEL_CONSOLE)
    265293                async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
    266294}
    267295
    268 static int gcons_find_conbut(int x, int y)
    269 {
    270         int status_start = STATUS_START + (xres - 800) / 2;
     296static int gcons_find_conbut(ipcarg_t x, ipcarg_t y)
     297{
     298        ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
    271299       
    272300        if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
     
    278306        if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
    279307                return -1;
     308       
    280309        if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
    281310                return -1;
    282311       
    283         return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
     312        ipcarg_t btn = (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
     313       
     314        if (btn < CONSOLE_COUNT)
     315                return btn;
     316       
     317        return -1;
    284318}
    285319
     
    287321 *
    288322 * @param state New state (true - pressed, false - depressed)
     323 *
    289324 */
    290325int gcons_mouse_btn(bool state)
    291326{
    292         int conbut;
     327        /* Ignore mouse clicks if no buttons
     328           are drawn at all */
     329        if (xres < 800)
     330                return -1;
    293331       
    294332        if (state) {
    295                 conbut = gcons_find_conbut(mouse_x, mouse_y);
     333                int conbut = gcons_find_conbut(mouse_x, mouse_y);
    296334                if (conbut != -1) {
    297335                        btn_pressed = true;
     
    307345        btn_pressed = false;
    308346       
    309         conbut = gcons_find_conbut(mouse_x, mouse_y);
     347        int conbut = gcons_find_conbut(mouse_x, mouse_y);
    310348        if (conbut == gcons_find_conbut(btn_x, btn_y))
    311349                return conbut;
     
    313351        return -1;
    314352}
    315 
    316353
    317354/** Draw a PPM pixmap to framebuffer
     
    321358 * @param x Coordinate of upper left corner
    322359 * @param y Coordinate of upper left corner
    323  */
    324 static void draw_pixmap(char *logo, size_t size, int x, int y)
    325 {
    326         char *shm;
    327         int rc;
    328        
     360 *
     361 */
     362static void draw_pixmap(char *logo, size_t size, ipcarg_t x, ipcarg_t y)
     363{
    329364        /* Create area */
    330         shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
     365        char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
    331366            MAP_ANONYMOUS, 0, 0);
    332367        if (shm == MAP_FAILED)
     
    336371       
    337372        /* Send area */
    338         rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
     373        int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
    339374        if (rc)
    340375                goto exit;
     
    356391}
    357392
    358 extern char _binary_gfx_helenos_ppm_start[0];
    359 extern int _binary_gfx_helenos_ppm_size;
    360 extern char _binary_gfx_nameic_ppm_start[0];
    361 extern int _binary_gfx_nameic_ppm_size;
    362 
    363393/** Redraws console graphics */
    364394void gcons_redraw_console(void)
    365395{
    366         int i;
    367        
    368396        if (!use_gcons)
    369397                return;
    370398       
    371399        vp_switch(0);
    372         set_rgb_color(MAIN_COLOR, MAIN_COLOR);
     400        set_rgb_color(COLOR_MAIN, COLOR_MAIN);
    373401        clear();
    374402        draw_pixmap(_binary_gfx_helenos_ppm_start,
     
    377405            (size_t) &_binary_gfx_nameic_ppm_size, 5, 17);
    378406       
     407        unsigned int i;
    379408        for (i = 0; i < CONSOLE_COUNT; i++)
    380409                redraw_state(i);
     
    393422static int make_pixmap(char *data, size_t size)
    394423{
    395         char *shm;
    396         int rc;
    397         int pxid = -1;
    398        
    399424        /* Create area */
    400         shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
     425        char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
    401426            MAP_ANONYMOUS, 0, 0);
    402427        if (shm == MAP_FAILED)
     
    405430        memcpy(shm, data, size);
    406431       
     432        int pxid = -1;
     433       
    407434        /* Send area */
    408         rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
     435        int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
    409436        if (rc)
    410437                goto exit;
     
    432459}
    433460
    434 extern char _binary_gfx_anim_1_ppm_start[0];
    435 extern int _binary_gfx_anim_1_ppm_size;
    436 extern char _binary_gfx_anim_2_ppm_start[0];
    437 extern int _binary_gfx_anim_2_ppm_size;
    438 extern char _binary_gfx_anim_3_ppm_start[0];
    439 extern int _binary_gfx_anim_3_ppm_size;
    440 extern char _binary_gfx_anim_4_ppm_start[0];
    441 extern int _binary_gfx_anim_4_ppm_size;
    442 
    443461static void make_anim(void)
    444462{
    445         int an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
     463        int an = async_req_1_0(fbphone, FB_ANIM_CREATE,
     464            cstatus_vp[KERNEL_CONSOLE]);
    446465        if (an < 0)
    447466                return;
     
    467486        animation = an;
    468487}
    469 
    470 extern char _binary_gfx_cons_selected_ppm_start[0];
    471 extern int _binary_gfx_cons_selected_ppm_size;
    472 extern char _binary_gfx_cons_idle_ppm_start[0];
    473 extern int _binary_gfx_cons_idle_ppm_size;
    474 extern char _binary_gfx_cons_has_data_ppm_start[0];
    475 extern int _binary_gfx_cons_has_data_ppm_size;
    476 extern char _binary_gfx_cons_kernel_ppm_start[0];
    477 extern int _binary_gfx_cons_kernel_ppm_size;
    478488
    479489/** Initialize nice graphical console environment */
     
    500510       
    501511        /* Create status buttons */
    502         size_t status_start = STATUS_START + (xres - 800) / 2;
     512        ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
    503513        size_t i;
    504514        for (i = 0; i < CONSOLE_COUNT; i++) {
     
    511521               
    512522                vp_switch(cstatus_vp[i]);
    513                 set_rgb_color(0x202020, 0xffffff);
     523                set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND);
    514524        }
    515525       
  • uspace/srv/hid/console/gcons.h

    rcaad59a r9f1362d4  
    3838#include <sys/types.h>
    3939
    40 void gcons_init(int phone);
     40void gcons_init(int);
    4141
    4242void gcons_redraw_console(void);
    43 void gcons_change_console(size_t index);
    44 void gcons_notify_char(size_t index);
     43void gcons_change_console(size_t);
     44void gcons_notify_char(size_t);
    4545void gcons_in_kernel(void);
    4646
    47 void gcons_notify_connect(size_t index);
    48 void gcons_notify_disconnect(size_t index);
     47void gcons_notify_connect(size_t);
     48void gcons_notify_disconnect(size_t);
    4949
    50 void gcons_mouse_move(ssize_t dx, ssize_t dy);
     50void gcons_mouse_move(ssize_t, ssize_t);
    5151int gcons_mouse_btn(bool state);
    5252
  • uspace/srv/hid/console/keybuffer.h

    rcaad59a r9f1362d4  
    4747typedef struct {
    4848        console_event_t fifo[KEYBUFFER_SIZE];
    49         unsigned long head;
    50         unsigned long tail;
    51         unsigned long items;
     49        size_t head;
     50        size_t tail;
     51        size_t items;
    5252} keybuffer_t;
    5353
  • uspace/srv/hid/console/screenbuffer.c

    rcaad59a r9f1362d4  
    6767 *
    6868 */
    69 screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y)
     69screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, ipcarg_t size_x,
     70    ipcarg_t size_y)
    7071{
    7172        scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
     
    109110 *
    110111 */
    111 void screenbuffer_clear_line(screenbuffer_t *scr, size_t line)
     112void screenbuffer_clear_line(screenbuffer_t *scr, ipcarg_t line)
    112113{
    113         size_t x;
     114        ipcarg_t x;
    114115       
    115116        for (x = 0; x < scr->size_x; x++) {
     
    140141 *
    141142 */
    142 void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y)
     143void screenbuffer_goto(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
    143144{
    144145        scr->position_x = x % scr->size_x;
     
    166167 *
    167168 */
    168 void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color, uint8_t bg_color, uint8_t flags)
     169void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color,
     170    uint8_t bg_color, uint8_t flags)
    169171{
    170172        scr->attrs.t = at_idx;
     
    181183 *
    182184 */
    183 void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color, uint32_t bg_color)
     185void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color,
     186    uint32_t bg_color)
    184187{
    185188        scr->attrs.t = at_rgb;
  • uspace/srv/hid/console/screenbuffer.h

    rcaad59a r9f1362d4  
    3838#include <stdint.h>
    3939#include <sys/types.h>
     40#include <ipc/ipc.h>
    4041#include <bool.h>
    4142
    42 #define DEFAULT_FOREGROUND  0x0       /**< default console foreground color */
     43#define DEFAULT_FOREGROUND  0x000000  /**< default console foreground color */
    4344#define DEFAULT_BACKGROUND  0xf0f0f0  /**< default console background color */
    4445
     
    8283        keyfield_t *buffer;      /**< Screen content - characters and
    8384                                      their attributes (used as a circular buffer) */
    84         size_t size_x;           /**< Number of columns  */
    85         size_t size_y;           /**< Number of rows */
     85        ipcarg_t size_x;         /**< Number of columns  */
     86        ipcarg_t size_y;         /**< Number of rows */
    8687       
    8788        /** Coordinates of last printed character for determining cursor position */
    88         size_t position_x;
    89         size_t position_y;
     89        ipcarg_t position_x;
     90        ipcarg_t position_y;
    9091       
    9192        attrs_t attrs;           /**< Current attributes. */
     
    107108 *
    108109 */
    109 static inline keyfield_t *get_field_at(screenbuffer_t *scr, size_t x, size_t y)
     110static inline keyfield_t *get_field_at(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
    110111{
    111112        return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x;
     
    140141}
    141142
     143extern void screenbuffer_putchar(screenbuffer_t *, wchar_t);
     144extern screenbuffer_t *screenbuffer_init(screenbuffer_t *, ipcarg_t, ipcarg_t);
    142145
    143 void screenbuffer_putchar(screenbuffer_t *scr, wchar_t c);
    144 screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y);
    145 
    146 void screenbuffer_clear(screenbuffer_t *scr);
    147 void screenbuffer_clear_line(screenbuffer_t *scr, size_t line);
    148 void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest);
    149 void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y);
    150 void screenbuffer_set_style(screenbuffer_t *scr, uint8_t style);
    151 void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color,
    152     uint8_t bg_color, uint8_t attr);
    153 void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color,
    154     uint32_t bg_color);
     146extern void screenbuffer_clear(screenbuffer_t *);
     147extern void screenbuffer_clear_line(screenbuffer_t *, ipcarg_t);
     148extern void screenbuffer_copy_buffer(screenbuffer_t *, keyfield_t *);
     149extern void screenbuffer_goto(screenbuffer_t *, ipcarg_t, ipcarg_t);
     150extern void screenbuffer_set_style(screenbuffer_t *, uint8_t);
     151extern void screenbuffer_set_color(screenbuffer_t *, uint8_t, uint8_t, uint8_t);
     152extern void screenbuffer_set_rgb_color(screenbuffer_t *, uint32_t, uint32_t);
    155153
    156154#endif
  • uspace/srv/hid/fb/ega.c

    rcaad59a r9f1362d4  
    2828
    2929/** @defgroup egafb EGA framebuffer
    30  * @brief       HelenOS EGA framebuffer.
     30 * @brief HelenOS EGA framebuffer.
    3131 * @ingroup fbs
    3232 * @{
    33  */ 
     33 */
    3434/** @file
    3535 */
     
    5858#include "main.h"
    5959
    60 #define MAX_SAVED_SCREENS 256
     60#define MAX_SAVED_SCREENS  256
     61
    6162typedef struct saved_screen {
    6263        short *data;
     
    6566saved_screen saved_screens[MAX_SAVED_SCREENS];
    6667
    67 #define EGA_IO_BASE ((ioport8_t *) 0x3d4)
    68 #define EGA_IO_SIZE 2
    69 
    70 int ega_normal_color = 0x0f;
    71 int ega_inverted_color = 0xf0;
    72 
    73 #define NORMAL_COLOR            ega_normal_color
    74 #define INVERTED_COLOR          ega_inverted_color
     68#define EGA_IO_BASE  ((ioport8_t *) 0x3d4)
     69#define EGA_IO_SIZE  2
    7570
    7671/* Allow only 1 connection */
    7772static int client_connected = 0;
    7873
    79 static unsigned int scr_width;
    80 static unsigned int scr_height;
     74static sysarg_t scr_width;
     75static sysarg_t scr_height;
    8176static uint8_t *scr_addr;
    8277
    83 static unsigned int style;
    84 
    85 static unsigned attr_to_ega_style(const attrs_t *a);
    86 static uint8_t ega_glyph(wchar_t ch);
     78static uint8_t style_normal = 0xf0;
     79static uint8_t style_inverted = 0x0f;
     80static uint8_t style;
     81
     82static uint8_t style_to_ega_style(uint8_t style)
     83{
     84        switch (style) {
     85        case STYLE_EMPHASIS:
     86                return (style_normal | 0x04);
     87        case STYLE_SELECTED:
     88                return (style_inverted | 0x40);
     89        case STYLE_INVERTED:
     90                return style_inverted;
     91        }
     92       
     93        return style_normal;
     94}
     95
     96static uint8_t color_to_ega_style(uint8_t fg_color, uint8_t bg_color,
     97    uint8_t attr)
     98{
     99        uint8_t style = (fg_color & 7) | ((bg_color & 7) << 4);
     100       
     101        if (attr & CATTR_BRIGHT)
     102                style |= 0x08;
     103       
     104        return style;
     105}
     106
     107static uint8_t rgb_to_ega_style(uint32_t fg, uint32_t bg)
     108{
     109        return (fg > bg) ? style_inverted : style_normal;
     110}
     111
     112static uint8_t attr_to_ega_style(const attrs_t *attr)
     113{
     114        switch (attr->t) {
     115        case at_style:
     116                return style_to_ega_style(attr->a.s.style);
     117        case at_idx:
     118                return color_to_ega_style(attr->a.i.fg_color,
     119                    attr->a.i.bg_color, attr->a.i.flags);
     120        case at_rgb:
     121                return rgb_to_ega_style(attr->a.r.fg_color, attr->a.r.bg_color);
     122        default:
     123                return style_normal;
     124        }
     125}
     126
     127static uint8_t ega_glyph(wchar_t ch)
     128{
     129        if (ch >= 0 && ch < 128)
     130                return ch;
     131       
     132        return '?';
     133}
    87134
    88135static void clrscr(void)
     
    96143}
    97144
    98 static void cursor_goto(unsigned int col, unsigned int row)
    99 {
    100         int ega_cursor;
    101 
    102         ega_cursor = col + scr_width * row;
     145static void cursor_goto(sysarg_t col, sysarg_t row)
     146{
     147        sysarg_t cursor = col + scr_width * row;
    103148       
    104149        pio_write_8(EGA_IO_BASE, 0xe);
    105         pio_write_8(EGA_IO_BASE + 1, (ega_cursor >> 8) & 0xff);
     150        pio_write_8(EGA_IO_BASE + 1, (cursor >> 8) & 0xff);
    106151        pio_write_8(EGA_IO_BASE, 0xf);
    107         pio_write_8(EGA_IO_BASE + 1, ega_cursor & 0xff);
     152        pio_write_8(EGA_IO_BASE + 1, cursor & 0xff);
    108153}
    109154
    110155static void cursor_disable(void)
    111156{
    112         uint8_t stat;
    113 
    114157        pio_write_8(EGA_IO_BASE, 0xa);
    115         stat = pio_read_8(EGA_IO_BASE + 1);
     158       
     159        uint8_t stat = pio_read_8(EGA_IO_BASE + 1);
     160       
    116161        pio_write_8(EGA_IO_BASE, 0xa);
    117162        pio_write_8(EGA_IO_BASE + 1, stat | (1 << 5));
     
    120165static void cursor_enable(void)
    121166{
    122         uint8_t stat;
    123 
    124167        pio_write_8(EGA_IO_BASE, 0xa);
    125         stat = pio_read_8(EGA_IO_BASE + 1);
     168       
     169        uint8_t stat = pio_read_8(EGA_IO_BASE + 1);
     170       
    126171        pio_write_8(EGA_IO_BASE, 0xa);
    127172        pio_write_8(EGA_IO_BASE + 1, stat & (~(1 << 5)));
    128173}
    129174
    130 static void scroll(int rows)
    131 {
    132         unsigned i;
    133 
     175static void scroll(ssize_t rows)
     176{
     177        size_t i;
     178       
    134179        if (rows > 0) {
    135180                memmove(scr_addr, ((char *) scr_addr) + rows * scr_width * 2,
     
    142187                    scr_width * scr_height * 2 + rows * scr_width * 2);
    143188                for (i = 0; i < -rows * scr_width; i++)
    144                         ((short *)scr_addr)[i] = ((style << 8 ) + ' ');
    145         }
    146 }
    147 
    148 static void printchar(wchar_t c, unsigned int col, unsigned int row)
     189                        ((short *) scr_addr)[i] = ((style << 8 ) + ' ');
     190        }
     191}
     192
     193static void printchar(wchar_t c, sysarg_t col, sysarg_t row)
    149194{
    150195        scr_addr[(row * scr_width + col) * 2] = ega_glyph(c);
     
    158203 * @param vport Viewport id
    159204 * @param data  Text data.
    160  * @param x     Leftmost column of the area.
    161  * @param y     Topmost row of the area.
    162  * @param w     Number of rows.
    163  * @param h     Number of columns.
     205 * @param x     Leftmost column of the area.
     206 * @param y     Topmost row of the area.
     207 * @param w     Number of rows.
     208 * @param h     Number of columns.
     209 *
    164210 */
    165 static void draw_text_data(keyfield_t *data, unsigned int x,
    166     unsigned int y, unsigned int w, unsigned int h)
    167 {
    168         unsigned int i, j;
     211static void draw_text_data(keyfield_t *data, sysarg_t x, sysarg_t y,
     212    sysarg_t w, sysarg_t h)
     213{
     214        sysarg_t i;
     215        sysarg_t j;
    169216        keyfield_t *field;
    170217        uint8_t *dp;
    171 
     218       
    172219        for (j = 0; j < h; j++) {
    173220                for (i = 0; i < w; i++) {
    174221                        field = &data[j * w + i];
    175222                        dp = &scr_addr[2 * ((y + j) * scr_width + (x + i))];
    176 
     223                       
    177224                        dp[0] = ega_glyph(field->character);
    178225                        dp[1] = attr_to_ega_style(&field->attrs);
     
    183230static int save_screen(void)
    184231{
    185         int i;
    186 
    187         for (i = 0; (i < MAX_SAVED_SCREENS) && (saved_screens[i].data); i++)
    188                 ;
    189         if (i == MAX_SAVED_SCREENS)
     232        ipcarg_t i;
     233       
     234        /* Find empty screen */
     235        for (i = 0; (i < MAX_SAVED_SCREENS) && (saved_screens[i].data); i++);
     236       
     237        if (i == MAX_SAVED_SCREENS)
    190238                return EINVAL;
    191         if (!(saved_screens[i].data = malloc(2 * scr_width * scr_height)))
     239       
     240        if (!(saved_screens[i].data = malloc(2 * scr_width * scr_height)))
    192241                return ENOMEM;
     242       
    193243        memcpy(saved_screens[i].data, scr_addr, 2 * scr_width * scr_height);
    194 
    195         return i;
    196 }
    197 
    198 static int print_screen(int i)
    199 {
    200         if (saved_screens[i].data)
     244        return (int) i;
     245}
     246
     247static int print_screen(ipcarg_t i)
     248{
     249        if ((i >= MAX_SAVED_SCREENS) || (saved_screens[i].data))
    201250                memcpy(scr_addr, saved_screens[i].data, 2 * scr_width *
    202251                    scr_height);
    203252        else
    204253                return EINVAL;
    205         return i;
    206 }
    207 
    208 static int style_to_ega_style(int style)
    209 {
    210         unsigned int ega_style;
    211 
    212         switch (style) {
    213         case STYLE_NORMAL:
    214                 ega_style = INVERTED_COLOR;
    215                 break;
    216         case STYLE_EMPHASIS:
    217                 ega_style = INVERTED_COLOR | 4;
    218                 break;
    219         default:
    220                 return INVERTED_COLOR;
    221         }
    222 
    223         return ega_style;
    224 }
    225 
    226 static unsigned int color_to_ega_style(int fg_color, int bg_color, int attr)
    227 {
    228         unsigned int style;
    229 
    230         style = (fg_color & 7) | ((bg_color & 7) << 4);
    231         if (attr & CATTR_BRIGHT)
    232                 style = style | 0x08;
    233 
    234         return style;
    235 }
    236 
    237 static unsigned int rgb_to_ega_style(uint32_t fg, uint32_t bg)
    238 {
    239         return (fg > bg) ? NORMAL_COLOR : INVERTED_COLOR;
    240 }
    241 
    242 static unsigned attr_to_ega_style(const attrs_t *a)
    243 {
    244         switch (a->t) {
    245         case at_style:
    246                 return style_to_ega_style(a->a.s.style);
    247         case at_rgb:
    248                 return rgb_to_ega_style(a->a.r.fg_color, a->a.r.bg_color);
    249         case at_idx:
    250                 return color_to_ega_style(a->a.i.fg_color,
    251                     a->a.i.bg_color, a->a.i.flags);
    252         default:
    253                 return INVERTED_COLOR;
    254         }
    255 }
    256 
    257 static uint8_t ega_glyph(wchar_t ch)
    258 {
    259         if (ch >= 0 && ch < 128)
    260                 return ch;
    261 
    262         return '?';
     254       
     255        return (int) i;
    263256}
    264257
    265258static void ega_client_connection(ipc_callid_t iid, ipc_call_t *icall)
    266259{
    267         int retval;
    268         ipc_callid_t callid;
    269         ipc_call_t call;
    270         wchar_t c;
    271         unsigned int row, col, w, h;
    272         int bg_color, fg_color, attr;
    273         uint32_t bg_rgb, fg_rgb;
     260        size_t intersize = 0;
    274261        keyfield_t *interbuf = NULL;
    275         size_t intersize = 0;
    276         int i;
    277262
    278263        if (client_connected) {
     
    280265                return;
    281266        }
     267       
     268        /* Accept connection */
    282269        client_connected = 1;
    283         ipc_answer_0(iid, EOK); /* Accept connection */
    284 
    285         while (1) {
    286                 callid = async_get_call(&call);
    287                 switch (IPC_GET_METHOD(call)) {
     270        ipc_answer_0(iid, EOK);
     271       
     272        while (true) {
     273                ipc_call_t call;
     274                ipc_callid_t callid = async_get_call(&call);
     275               
     276                wchar_t c;
     277               
     278                ipcarg_t col;
     279                ipcarg_t row;
     280                ipcarg_t w;
     281                ipcarg_t h;
     282               
     283                ssize_t rows;
     284               
     285                uint8_t bg_color;
     286                uint8_t fg_color;
     287                uint8_t attr;
     288               
     289                uint32_t fg_rgb;
     290                uint32_t bg_rgb;
     291               
     292                ipcarg_t scr;
     293                int retval;
     294               
     295                switch (IPC_GET_METHOD(call)) {
    288296                case IPC_M_PHONE_HUNGUP:
    289297                        client_connected = 0;
    290298                        ipc_answer_0(callid, EOK);
    291                         return; /* Exit thread */
     299                       
     300                        /* Exit thread */
     301                        return;
    292302                case IPC_M_SHARE_OUT:
    293303                        /* We accept one area for data interchange */
     
    299309                                continue;
    300310                        }
     311                       
    301312                        retval = EINVAL;
    302313                        break;
    303314                case FB_DRAW_TEXT_DATA:
     315                        if (!interbuf) {
     316                                retval = EINVAL;
     317                                break;
     318                        }
     319                       
    304320                        col = IPC_GET_ARG1(call);
    305321                        row = IPC_GET_ARG2(call);
    306322                        w = IPC_GET_ARG3(call);
    307323                        h = IPC_GET_ARG4(call);
    308                         if (!interbuf) {
     324                       
     325                        if ((col + w > scr_width) || (row + h > scr_height)) {
    309326                                retval = EINVAL;
    310327                                break;
    311328                        }
    312                         if (col + w > scr_width || row + h > scr_height) {
    313                                 retval = EINVAL;
    314                                 break;
    315                         }
     329                       
    316330                        draw_text_data(interbuf, col, row, w, h);
    317331                        retval = 0;
     
    331345                        col = IPC_GET_ARG2(call);
    332346                        row = IPC_GET_ARG3(call);
    333                         if (col >= scr_width || row >= scr_height) {
     347                       
     348                        if ((col >= scr_width) || (row >= scr_height)) {
    334349                                retval = EINVAL;
    335350                                break;
    336351                        }
     352                       
    337353                        printchar(c, col, row);
    338354                        retval = 0;
    339355                        break;
    340                 case FB_CURSOR_GOTO:
    341                         col = IPC_GET_ARG1(call);
     356                case FB_CURSOR_GOTO:
     357                        col = IPC_GET_ARG1(call);
    342358                        row = IPC_GET_ARG2(call);
    343                         if (row >= scr_height || col >= scr_width) {
     359                       
     360                        if ((row >= scr_height) || (col >= scr_width)) {
    344361                                retval = EINVAL;
    345362                                break;
    346363                        }
     364                       
    347365                        cursor_goto(col, row);
    348                         retval = 0;
    349                         break;
     366                        retval = 0;
     367                        break;
    350368                case FB_SCROLL:
    351                         i = IPC_GET_ARG1(call);
    352                         if (i > (int) scr_height || i < -((int) scr_height)) {
    353                                 retval = EINVAL;
    354                                 break;
    355                         }
    356                         scroll(i);
     369                        rows = IPC_GET_ARG1(call);
     370                       
     371                        if (rows >= 0) {
     372                                if ((ipcarg_t) rows > scr_height) {
     373                                        retval = EINVAL;
     374                                        break;
     375                                }
     376                        } else {
     377                                if ((ipcarg_t) (-rows) > scr_height) {
     378                                        retval = EINVAL;
     379                                        break;
     380                                }
     381                        }
     382                       
     383                        scroll(rows);
    357384                        retval = 0;
    358385                        break;
     
    362389                        else
    363390                                cursor_disable();
     391                       
    364392                        retval = 0;
    365393                        break;
     
    372400                        bg_color = IPC_GET_ARG2(call);
    373401                        attr = IPC_GET_ARG3(call);
     402                       
    374403                        style = color_to_ega_style(fg_color, bg_color, attr);
    375404                        retval = 0;
     
    378407                        fg_rgb = IPC_GET_ARG1(call);
    379408                        bg_rgb = IPC_GET_ARG2(call);
     409                       
    380410                        style = rgb_to_ega_style(fg_rgb, bg_rgb);
    381411                        retval = 0;
    382412                        break;
    383413                case FB_VP_DRAW_PIXMAP:
    384                         i = IPC_GET_ARG2(call);
    385                         retval = print_screen(i);
     414                        scr = IPC_GET_ARG2(call);
     415                        retval = print_screen(scr);
    386416                        break;
    387417                case FB_VP2PIXMAP:
     
    389419                        break;
    390420                case FB_DROP_PIXMAP:
    391                         i = IPC_GET_ARG1(call);
    392                         if (i >= MAX_SAVED_SCREENS) {
     421                        scr = IPC_GET_ARG1(call);
     422                       
     423                        if (scr >= MAX_SAVED_SCREENS) {
    393424                                retval = EINVAL;
    394425                                break;
    395426                        }
    396                         if (saved_screens[i].data) {
    397                                 free(saved_screens[i].data);
    398                                 saved_screens[i].data = NULL;
    399                         }
     427                       
     428                        if (saved_screens[scr].data) {
     429                                free(saved_screens[scr].data);
     430                                saved_screens[scr].data = NULL;
     431                        }
     432                       
    400433                        retval = 0;
    401434                        break;
     
    413446int ega_init(void)
    414447{
    415         void *ega_ph_addr;
    416         size_t sz;
    417        
    418448        sysarg_t paddr;
    419449        if (sysinfo_get_value("fb.address.physical", &paddr) != EOK)
    420450                return -1;
    421451       
    422         sysarg_t width;
    423         if (sysinfo_get_value("fb.width", &width) != EOK)
     452        if (sysinfo_get_value("fb.width", &scr_width) != EOK)
    424453                return -1;
    425454       
    426         sysarg_t height;
    427         if (sysinfo_get_value("fb.width", &height) != EOK)
     455        if (sysinfo_get_value("fb.height", &scr_height) != EOK)
    428456                return -1;
    429457       
     
    432460                blinking = false;
    433461       
    434         ega_ph_addr = (void *) paddr;
    435         scr_width = width;
    436         scr_height = height;
     462        void *ega_ph_addr = (void *) paddr;
    437463        if (blinking) {
    438                 ega_normal_color &= 0x77;
    439                 ega_inverted_color &= 0x77;
    440         }
    441        
    442         style = NORMAL_COLOR;
     464                style_normal &= 0x77;
     465                style_inverted &= 0x77;
     466        }
     467       
     468        style = style_normal;
    443469       
    444470        iospace_enable(task_get_id(), (void *) EGA_IO_BASE, 2);
    445471       
    446         sz = scr_width * scr_height * 2;
     472        size_t sz = scr_width * scr_height * 2;
    447473        scr_addr = as_get_mappable_page(sz);
    448474       
     
    450476            PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
    451477                return -1;
    452 
     478       
    453479        async_set_client_connection(ega_client_connection);
    454 
     480       
    455481        return 0;
    456482}
    457 
    458483
    459484/**
  • uspace/srv/hid/fb/fb.c

    rcaad59a r9f1362d4  
    7272#define DEFAULT_FGCOLOR  0x000000
    7373
    74 #define GLYPH_UNAVAIL    '?'
    75 
    76 #define MAX_ANIM_LEN     8
    77 #define MAX_ANIMATIONS   4
    78 #define MAX_PIXMAPS      256  /**< Maximum number of saved pixmaps */
    79 #define MAX_VIEWPORTS    128  /**< Viewport is a rectangular area on the screen */
     74#define GLYPH_UNAVAIL  '?'
     75
     76#define MAX_ANIM_LEN    8
     77#define MAX_ANIMATIONS  4
     78#define MAX_PIXMAPS     256  /**< Maximum number of saved pixmaps */
     79#define MAX_VIEWPORTS   128  /**< Viewport is a rectangular area on the screen */
    8080
    8181/** Function to render a pixel from a RGB value. */
     
    956956        bb_cell_t *bbp;
    957957        attrs_t *a;
    958         attr_rgb_t rgb;
    959958       
    960959        for (j = 0; j < h; j++) {
     
    966965                       
    967966                        a = &data[j * w + i].attrs;
     967                       
     968                        attr_rgb_t rgb;
     969                        rgb.fg_color = 0;
     970                        rgb.bg_color = 0;
    968971                        rgb_from_attr(&rgb, a);
    969972                       
     
    15111514                rgb->bg_color = color_table[COLOR_WHITE];
    15121515                break;
     1516        case STYLE_INVERTED:
     1517                rgb->fg_color = color_table[COLOR_WHITE];
     1518                rgb->bg_color = color_table[COLOR_BLACK];
     1519                break;
     1520        case STYLE_SELECTED:
     1521                rgb->fg_color = color_table[COLOR_WHITE];
     1522                rgb->bg_color = color_table[COLOR_RED];
     1523                break;
    15131524        default:
    15141525                return EINVAL;
    15151526        }
    1516 
     1527       
    15171528        return EOK;
    15181529}
Note: See TracChangeset for help on using the changeset viewer.