Changeset 52c4264 in mainline for uspace/lib/c/generic/io/chargrid.c


Ignore:
Timestamp:
2012-08-17T12:23:52Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
267f235
Parents:
ae2c925 (diff), ad78054 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/chargrid.c

    rae2c925 r52c4264  
    2727 */
    2828
    29 /** @addtogroup console
     29/** @addtogroup libc
    3030 * @{
    3131 */
     
    3939#include <bool.h>
    4040#include <as.h>
    41 #include "screenbuffer.h"
    42 
    43 /** Structure for buffering state of one virtual console.
    44  *
    45  */
    46 struct screenbuffer {
    47         size_t size;                /**< Structure size */
    48         screenbuffer_flag_t flags;  /**< Screenbuffer flags */
    49        
    50         sysarg_t cols;              /**< Number of columns */
    51         sysarg_t rows;              /**< Number of rows */
    52        
    53         sysarg_t col;               /**< Current column */
    54         sysarg_t row;               /**< Current row */
    55         bool cursor_visible;        /**< Cursor visibility */
    56        
    57         char_attrs_t attrs;         /**< Current attributes */
    58        
    59         sysarg_t top_row;           /**< The first row in the cyclic buffer */
    60         charfield_t data[];         /**< Screen contents (cyclic buffer) */
    61 };
    62 
    63 /** Create a screenbuffer.
     41#include <io/chargrid.h>
     42
     43/** Create a chargrid.
    6444 *
    6545 * @param[in] cols  Number of columns.
    6646 * @param[in] rows  Number of rows.
    67  * @param[in] flags Screenbuffer flags.
    68  *
    69  * @return New screenbuffer.
     47 * @param[in] flags Chargrid flags.
     48 *
     49 * @return New chargrid.
    7050 * @return NULL on failure.
    7151 *
    7252 */
    73 screenbuffer_t *screenbuffer_create(sysarg_t cols, sysarg_t rows,
    74     screenbuffer_flag_t flags)
     53chargrid_t *chargrid_create(sysarg_t cols, sysarg_t rows,
     54    chargrid_flag_t flags)
    7555{
    7656        size_t size =
    77             sizeof(screenbuffer_t) + cols * rows * sizeof(charfield_t);
    78         screenbuffer_t *scrbuf;
    79        
    80         if ((flags & SCREENBUFFER_FLAG_SHARED) == SCREENBUFFER_FLAG_SHARED) {
    81                 scrbuf = (screenbuffer_t *) as_area_create(AS_AREA_ANY, size,
     57            sizeof(chargrid_t) + cols * rows * sizeof(charfield_t);
     58        chargrid_t *scrbuf;
     59       
     60        if ((flags & CHARGRID_FLAG_SHARED) == CHARGRID_FLAG_SHARED) {
     61                scrbuf = (chargrid_t *) as_area_create(AS_AREA_ANY, size,
    8262                    AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    8363                if (scrbuf == AS_MAP_FAILED)
    8464                        return NULL;
    8565        } else {
    86                 scrbuf = (screenbuffer_t *) malloc(size);
     66                scrbuf = (chargrid_t *) malloc(size);
    8767                if (scrbuf == NULL)
    8868                        return NULL;
     
    9979       
    10080        scrbuf->top_row = 0;
    101         screenbuffer_clear(scrbuf);
     81        chargrid_clear(scrbuf);
    10282       
    10383        return scrbuf;
    10484}
    10585
    106 /** Return keyfield by coordinates
    107  *
    108  * The back buffer is organized as a cyclic buffer.
    109  * Therefore we must take into account the topmost column.
    110  *
    111  * @param scrbuf Screenbuffer
    112  * @param col    Column position on screen
    113  * @param row    Row position on screen
    114  *
    115  * @return Keyfield structure on (row, col)
    116  *
    117  */
    118 charfield_t *screenbuffer_field_at(screenbuffer_t *scrbuf, sysarg_t col,
    119     sysarg_t row)
    120 {
    121         return scrbuf->data +
    122             ((row + scrbuf->top_row) % scrbuf->rows) * scrbuf->cols +
    123             col;
    124 }
    125 
    126 bool screenbuffer_cursor_at(screenbuffer_t *scrbuf, sysarg_t col, sysarg_t row)
     86void chargrid_destroy(chargrid_t *srcbuf)
     87{
     88        // TODO
     89}
     90
     91bool chargrid_cursor_at(chargrid_t *scrbuf, sysarg_t col, sysarg_t row)
    12792{
    12893        return ((scrbuf->cursor_visible) && (scrbuf->col == col) &&
     
    13095}
    13196
    132 sysarg_t screenbuffer_get_top_row(screenbuffer_t *scrbuf)
     97sysarg_t chargrid_get_top_row(chargrid_t *scrbuf)
    13398{
    13499        return scrbuf->top_row;
    135100}
    136101
    137 static sysarg_t screenbuffer_update_rows(screenbuffer_t *scrbuf)
     102static sysarg_t chargrid_update_rows(chargrid_t *scrbuf)
    138103{
    139104        if (scrbuf->row == scrbuf->rows) {
    140105                scrbuf->row = scrbuf->rows - 1;
    141106                scrbuf->top_row = (scrbuf->top_row + 1) % scrbuf->rows;
    142                 screenbuffer_clear_row(scrbuf, scrbuf->row);
     107                chargrid_clear_row(scrbuf, scrbuf->row);
    143108               
    144109                return scrbuf->rows;
     
    148113}
    149114
    150 static sysarg_t screenbuffer_update_cols(screenbuffer_t *scrbuf)
     115static sysarg_t chargrid_update_cols(chargrid_t *scrbuf)
    151116{
    152117        /* Column overflow */
     
    154119                scrbuf->col = 0;
    155120                scrbuf->row++;
    156                 return screenbuffer_update_rows(scrbuf);
     121                return chargrid_update_rows(scrbuf);
    157122        }
    158123       
     
    160125}
    161126
    162 /** Store one character to screenbuffer.
     127/** Store one character to chargrid.
    163128 *
    164129 * Its position is determined by scrbuf->col
    165130 * and scrbuf->row.
    166131 *
    167  * @param scrbuf Screenbuffer.
     132 * @param scrbuf Chargrid.
    168133 * @param ch     Character to store.
    169134 * @param update Update coordinates.
     
    174139 *
    175140 */
    176 sysarg_t screenbuffer_putchar(screenbuffer_t *scrbuf, wchar_t ch, bool update)
     141sysarg_t chargrid_putchar(chargrid_t *scrbuf, wchar_t ch, bool update)
    177142{
    178143        assert(scrbuf->col < scrbuf->cols);
     
    180145       
    181146        charfield_t *field =
    182             screenbuffer_field_at(scrbuf, scrbuf->col, scrbuf->row);
     147            chargrid_charfield_at(scrbuf, scrbuf->col, scrbuf->row);
    183148       
    184149        field->ch = ch;
     
    188153        if (update) {
    189154                scrbuf->col++;
    190                 return screenbuffer_update_cols(scrbuf);
     155                return chargrid_update_cols(scrbuf);
    191156        }
    192157       
     
    194159}
    195160
    196 /** Jump to a new row in screenbuffer.
    197  *
    198  * @param scrbuf Screenbuffer.
     161/** Jump to a new row in chargrid.
     162 *
     163 * @param scrbuf Chargrid.
    199164 *
    200165 * @return Number of rows which have been affected. In usual
     
    203168 *
    204169 */
    205 sysarg_t screenbuffer_newline(screenbuffer_t *scrbuf)
     170sysarg_t chargrid_newline(chargrid_t *scrbuf)
    206171{
    207172        assert(scrbuf->col < scrbuf->cols);
     
    211176        scrbuf->row++;
    212177       
    213         return screenbuffer_update_rows(scrbuf);
    214 }
    215 
    216 /** Jump to a new row in screenbuffer.
    217  *
    218  * @param scrbuf   Screenbuffer.
     178        return chargrid_update_rows(scrbuf);
     179}
     180
     181/** Jump to a new row in chargrid.
     182 *
     183 * @param scrbuf   Chargrid.
    219184 * @param tab_size Tab size.
    220185 *
     
    224189 *
    225190 */
    226 sysarg_t screenbuffer_tabstop(screenbuffer_t *scrbuf, sysarg_t tab_size)
     191sysarg_t chargrid_tabstop(chargrid_t *scrbuf, sysarg_t tab_size)
    227192{
    228193        assert(scrbuf->col < scrbuf->cols);
     
    233198       
    234199        for (sysarg_t i = 0; i < spaces; i++)
    235                 flush += screenbuffer_putchar(scrbuf, ' ', true) - 1;
     200                flush += chargrid_putchar(scrbuf, ' ', true) - 1;
    236201       
    237202        return flush;
    238203}
    239204
    240 /** Jump to the previous character in screenbuffer.
     205/** Jump to the previous character in chargrid.
    241206 *
    242207 * Currently no scrollback is supported.
    243208 *
    244  * @param scrbuf Screenbuffer.
     209 * @param scrbuf Chargrid.
    245210 *
    246211 * @return Number of rows which have been affected. In usual
     
    250215 *
    251216 */
    252 sysarg_t screenbuffer_backspace(screenbuffer_t *scrbuf)
     217sysarg_t chargrid_backspace(chargrid_t *scrbuf)
    253218{
    254219        assert(scrbuf->col < scrbuf->cols);
     
    262227                scrbuf->row--;
    263228               
    264                 screenbuffer_putchar(scrbuf, ' ', false);
     229                chargrid_putchar(scrbuf, ' ', false);
    265230                return 2;
    266231        }
    267232       
    268233        scrbuf->col--;
    269         screenbuffer_putchar(scrbuf, ' ', false);
     234        chargrid_putchar(scrbuf, ' ', false);
    270235        return 1;
    271236}
    272237
    273 /** Clear the screenbuffer.
    274  *
    275  * @param scrbuf Screenbuffer.
    276  *
    277  */
    278 void screenbuffer_clear(screenbuffer_t *scrbuf)
     238/** Clear the chargrid.
     239 *
     240 * @param scrbuf Chargrid.
     241 *
     242 */
     243void chargrid_clear(chargrid_t *scrbuf)
    279244{
    280245        for (size_t pos = 0; pos < (scrbuf->cols * scrbuf->rows); pos++) {
     
    288253}
    289254
    290 /** Update current screenbuffer coordinates
    291  *
    292  * @param scrbuf Screenbuffer.
     255/** Update current chargrid coordinates
     256 *
     257 * @param scrbuf Chargrid.
    293258 * @param col    New column.
    294259 * @param row    New row.
    295260 *
    296261 */
    297 void screenbuffer_set_cursor(screenbuffer_t *scrbuf, sysarg_t col, sysarg_t row)
     262void chargrid_set_cursor(chargrid_t *scrbuf, sysarg_t col, sysarg_t row)
    298263{
    299264        scrbuf->col = col;
     
    301266}
    302267
    303 void screenbuffer_set_cursor_visibility(screenbuffer_t *scrbuf, bool visible)
     268void chargrid_set_cursor_visibility(chargrid_t *scrbuf, bool visible)
    304269{
    305270        scrbuf->cursor_visible = visible;
    306271}
    307272
    308 /** Get current screenbuffer coordinates
    309  *
    310  * @param scrbuf Screenbuffer.
     273/** Get current chargrid coordinates
     274 *
     275 * @param scrbuf Chargrid.
    311276 * @param col    Column.
    312277 * @param row    Row.
    313278 *
    314279 */
    315 void screenbuffer_get_cursor(screenbuffer_t *scrbuf, sysarg_t *col,
     280void chargrid_get_cursor(chargrid_t *scrbuf, sysarg_t *col,
    316281    sysarg_t *row)
    317282{
     
    323288}
    324289
    325 bool screenbuffer_get_cursor_visibility(screenbuffer_t *scrbuf)
     290bool chargrid_get_cursor_visibility(chargrid_t *scrbuf)
    326291{
    327292        return scrbuf->cursor_visible;
     
    330295/** Clear one buffer row.
    331296 *
    332  * @param scrbuf Screenbuffer.
     297 * @param scrbuf Chargrid.
    333298 * @param row    Row to clear.
    334299 *
    335300 */
    336 void screenbuffer_clear_row(screenbuffer_t *scrbuf, sysarg_t row)
     301void chargrid_clear_row(chargrid_t *scrbuf, sysarg_t row)
    337302{
    338303        for (sysarg_t col = 0; col < scrbuf->cols; col++) {
    339304                charfield_t *field =
    340                     screenbuffer_field_at(scrbuf, col, row);
     305                    chargrid_charfield_at(scrbuf, col, row);
    341306               
    342307                field->ch = 0;
     
    346311}
    347312
    348 /** Set screenbuffer style.
    349  *
    350  * @param scrbuf Screenbuffer.
     313/** Set chargrid style.
     314 *
     315 * @param scrbuf Chargrid.
    351316 * @param style  Style.
    352317 *
    353318 */
    354 void screenbuffer_set_style(screenbuffer_t *scrbuf, console_style_t style)
     319void chargrid_set_style(chargrid_t *scrbuf, console_style_t style)
    355320{
    356321        scrbuf->attrs.type = CHAR_ATTR_STYLE;
     
    358323}
    359324
    360 /** Set screenbuffer color.
    361  *
    362  * @param scrbuf  Screenbuffer.
     325/** Set chargrid color.
     326 *
     327 * @param scrbuf  Chargrid.
    363328 * @param bgcolor Background color.
    364329 * @param fgcolor Foreground color.
     
    366331 *
    367332 */
    368 void screenbuffer_set_color(screenbuffer_t *scrbuf, console_color_t bgcolor,
     333void chargrid_set_color(chargrid_t *scrbuf, console_color_t bgcolor,
    369334    console_color_t fgcolor, console_color_attr_t attr)
    370335{
     
    375340}
    376341
    377 /** Set screenbuffer RGB color.
    378  *
    379  * @param scrbuf  Screenbuffer.
     342/** Set chargrid RGB color.
     343 *
     344 * @param scrbuf  Chargrid.
    380345 * @param bgcolor Background color.
    381346 * @param fgcolor Foreground color.
    382347 *
    383348 */
    384 void screenbuffer_set_rgb_color(screenbuffer_t *scrbuf, pixel_t bgcolor,
     349void chargrid_set_rgb_color(chargrid_t *scrbuf, pixel_t bgcolor,
    385350    pixel_t fgcolor)
    386351{
Note: See TracChangeset for help on using the changeset viewer.