Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 6d5e378 in mainline for uspace/srv/hid/output/port/ega.c


Ignore:
Timestamp:
2012-08-16T19:27:44Z (9 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
4f351432, 7d27f422
Parents:
c9d011e4
Message:

cherrypick GUI implementation (originally by Petr Koupy), with several major changes

  • for character-oriented devices a new output server and output protocol was created based on the original fb server
  • DDF visualizer drivers are pixel-oriented only
  • console and compositor can coexist in the same build
  • terminal widget is self-sufficient, no strange console nesting is needed
File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/output/port/ega.c

    rc9d011e4 r6d5e378  
    3333#include <errno.h>
    3434#include <sysinfo.h>
    35 #include <task.h>
     35#include <align.h>
     36#include <as.h>
    3637#include <ddi.h>
    3738#include <libarch/ddi.h>
    38 #include <as.h>
    39 #include <malloc.h>
    40 #include <align.h>
    41 #include <screenbuffer.h>
    42 #include "../fb.h"
     39#include <io/chargrid.h>
     40#include "../output.h"
    4341#include "ega.h"
    4442
     
    4644#define EGA_IO_SIZE  2
    4745
    48 #define FB_POS(x, y)  (((y) * ega.width + (x)) << 1)
     46#define FB_POS(x, y)  (((y) * ega.cols + (x)) << 1)
    4947
    5048typedef struct {
    51         sysarg_t width;
    52         sysarg_t height;
     49        sysarg_t cols;
     50        sysarg_t rows;
     51       
     52        uint8_t style_normal;
     53        uint8_t style_inverted;
    5354       
    5455        size_t size;
    5556        uint8_t *addr;
    56        
    57         uint8_t style_normal;
    58         uint8_t style_inverted;
    59        
    60         uint8_t *backbuf;
    6157} ega_t;
    6258
     
    10197}
    10298
    103 /** Draw the character at the specified position in viewport.
    104  *
    105  * @param vp     Viewport.
    106  * @param col    Screen position relative to viewport.
    107  * @param row    Screen position relative to viewport.
    108  *
    109  */
    110 static void draw_vp_char(fbvp_t *vp, sysarg_t col, sysarg_t row)
    111 {
    112         sysarg_t x = vp->x + col;
    113         sysarg_t y = vp->y + row;
    114        
    115         charfield_t *field = screenbuffer_field_at(vp->backbuf, col, row);
    116        
     99/** Draw the character at the specified position.
     100 *
     101 * @param field Character field.
     102 * @param col   Horizontal screen position.
     103 * @param row   Vertical screen position.
     104 *
     105 */
     106static void draw_char(charfield_t *field, sysarg_t col, sysarg_t row)
     107{
    117108        uint8_t glyph;
    118109       
     
    124115        uint8_t attr = attrs_attr(field->attrs);
    125116       
    126         ega.addr[FB_POS(x, y)] = glyph;
    127         ega.addr[FB_POS(x, y) + 1] = attr;
    128 }
    129 
    130 static int ega_yield(fbdev_t *dev)
    131 {
    132         if (ega.backbuf == NULL) {
    133                 ega.backbuf = malloc(ega.size);
    134                 if (ega.backbuf == NULL)
    135                         return ENOMEM;
    136         }
    137        
    138         memcpy(ega.backbuf, ega.addr, ega.size);
     117        ega.addr[FB_POS(col, row)] = glyph;
     118        ega.addr[FB_POS(col, row) + 1] = attr;
     119}
     120
     121static int ega_yield(outdev_t *dev)
     122{
    139123        return EOK;
    140124}
    141125
    142 static int ega_claim(fbdev_t *dev)
    143 {
    144         if (ega.backbuf == NULL)
    145                 return ENOENT;
    146        
    147         memcpy(ega.addr, ega.backbuf, ega.size);
     126static int ega_claim(outdev_t *dev)
     127{
    148128        return EOK;
    149129}
    150130
    151 static int ega_get_resolution(fbdev_t *dev, sysarg_t *width, sysarg_t *height)
    152 {
    153         *width = ega.width;
    154         *height = ega.height;
    155         return EOK;
    156 }
    157 
    158 static void ega_font_metrics(fbdev_t *dev, sysarg_t width, sysarg_t height,
    159     sysarg_t *cols, sysarg_t *rows)
    160 {
    161         *cols = width;
    162         *rows = height;
    163 }
    164 
    165 static int ega_vp_create(fbdev_t *dev, fbvp_t *vp)
    166 {
    167         vp->attrs.type = CHAR_ATTR_STYLE;
    168         vp->attrs.val.style = STYLE_NORMAL;
    169         vp->data = NULL;
    170        
    171         return EOK;
    172 }
    173 
    174 static void ega_vp_destroy(fbdev_t *dev, fbvp_t *vp)
    175 {
    176         /* No-op */
    177 }
    178 
    179 static void ega_vp_clear(fbdev_t *dev, fbvp_t *vp)
    180 {
    181         for (sysarg_t row = 0; row < vp->rows; row++) {
    182                 for (sysarg_t col = 0; col < vp->cols; col++) {
    183                         charfield_t *field =
    184                             screenbuffer_field_at(vp->backbuf, col, row);
    185                        
    186                         field->ch = 0;
    187                         field->attrs = vp->attrs;
    188                        
    189                         draw_vp_char(vp, col, row);
    190                 }
    191         }
    192 }
    193 
    194 static console_caps_t ega_vp_get_caps(fbdev_t *dev, fbvp_t *vp)
     131static void ega_get_dimensions(outdev_t *dev, sysarg_t *cols, sysarg_t *rows)
     132{
     133        *cols = ega.cols;
     134        *rows = ega.rows;
     135}
     136
     137static console_caps_t ega_get_caps(outdev_t *dev)
    195138{
    196139        return (CONSOLE_CAP_STYLE | CONSOLE_CAP_INDEXED);
    197140}
    198141
    199 static void ega_vp_cursor_update(fbdev_t *dev, fbvp_t *vp, sysarg_t prev_col,
     142static void ega_cursor_update(outdev_t *dev, sysarg_t prev_col,
    200143    sysarg_t prev_row, sysarg_t col, sysarg_t row, bool visible)
    201144{
    202145        /* Cursor position */
    203         uint16_t cursor = row * ega.width + col;
     146        uint16_t cursor = row * ega.cols + col;
    204147       
    205148        pio_write_8(EGA_IO_BASE, 0x0e);
     
    220163}
    221164
    222 static void ega_vp_char_update(fbdev_t *dev, fbvp_t *vp, sysarg_t col,
    223     sysarg_t row)
    224 {
    225         draw_vp_char(vp, col, row);
    226 }
    227 
    228 static fbdev_ops_t ega_ops = {
     165static void ega_char_update(outdev_t *dev, sysarg_t col, sysarg_t row)
     166{
     167        charfield_t *field =
     168            chargrid_charfield_at(dev->backbuf, col, row);
     169       
     170        draw_char(field, col, row);
     171}
     172
     173static outdev_ops_t ega_ops = {
    229174        .yield = ega_yield,
    230175        .claim = ega_claim,
    231         .get_resolution = ega_get_resolution,
    232         .font_metrics = ega_font_metrics,
    233         .vp_create = ega_vp_create,
    234         .vp_destroy = ega_vp_destroy,
    235         .vp_clear = ega_vp_clear,
    236         .vp_get_caps = ega_vp_get_caps,
    237         .vp_cursor_update = ega_vp_cursor_update,
    238         .vp_char_update = ega_vp_char_update
     176        .get_dimensions = ega_get_dimensions,
     177        .get_caps = ega_get_caps,
     178        .cursor_update = ega_cursor_update,
     179        .char_update = ega_char_update
    239180};
    240181
     
    262203                return rc;
    263204       
    264         sysarg_t width;
    265         rc = sysinfo_get_value("fb.width", &width);
    266         if (rc != EOK)
    267                 return rc;
    268        
    269         sysarg_t height;
    270         rc = sysinfo_get_value("fb.height", &height);
    271         if (rc != EOK)
    272                 return rc;
    273        
    274         rc = iospace_enable(task_get_id(), (void *) EGA_IO_BASE, EGA_IO_SIZE);
    275         if (rc != EOK)
    276                 return rc;
    277        
    278         ega.width = width;
    279         ega.height = height;
    280        
    281         ega.size = (width * height) << 1;
     205        rc = sysinfo_get_value("fb.width", &ega.cols);
     206        if (rc != EOK)
     207                return rc;
     208       
     209        rc = sysinfo_get_value("fb.height", &ega.rows);
     210        if (rc != EOK)
     211                return rc;
     212       
     213        rc = iospace_enable(task_get_id(), (void *) EGA_IO_BASE,
     214            EGA_IO_SIZE);
     215        if (rc != EOK)
     216                return rc;
     217       
     218        ega.size = (ega.cols * ega.rows) << 1;
    282219       
    283220        rc = physmem_map((void *) paddr,
     
    300237        }
    301238       
    302         ega.backbuf = NULL;
    303        
    304         fbdev_t *dev = fbdev_register(&ega_ops, (void *) &ega);
     239        outdev_t *dev = outdev_register(&ega_ops, (void *) &ega);
    305240        if (dev == NULL) {
    306241                as_area_destroy(ega.addr);
     
    311246}
    312247
    313 /**
    314  * @}
    315  */
     248/** @}
     249 */
Note: See TracChangeset for help on using the changeset viewer.