Changeset 6d5e378 in mainline for uspace/srv/hid/output/proto/vt100.c
- Timestamp:
- 2012-08-16T19:27:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4f351432, 7d27f422
- Parents:
- c9d011e4
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/output/proto/vt100.c
rc9d011e4 r6d5e378 32 32 #include <sys/types.h> 33 33 #include <inttypes.h> 34 #include <errno.h> 34 35 #include <stdio.h> 36 #include <unistd.h> 37 #include <malloc.h> 35 38 #include <io/color.h> 36 #include <malloc.h>37 #include <errno.h>38 39 #include "vt100.h" 39 40 40 41 #define MAX_CONTROL 20 41 42 #define BACKBUF_POS(state, x, y) ((y) * ((state)->width) + (x))43 44 struct vt100_state {45 vt100_putchar_t putchar;46 vt100_control_puts_t control_puts;47 48 sysarg_t width;49 sysarg_t height;50 51 sysarg_t cur_col;52 sysarg_t cur_row;53 54 char_attrs_t cur_attrs;55 56 charfield_t backbuf[];57 };58 42 59 43 typedef enum { … … 154 138 } 155 139 156 vt100_state_t *vt100_state_create(sysarg_t width, sysarg_t height,140 vt100_state_t *vt100_state_create(sysarg_t cols, sysarg_t rows, 157 141 vt100_putchar_t putchar_fn, vt100_control_puts_t control_puts_fn) 158 142 { 159 size_t sz = width * height * sizeof(charfield_t);160 161 143 vt100_state_t *state = 162 malloc(sizeof(vt100_state_t) + sz);144 malloc(sizeof(vt100_state_t)); 163 145 if (state == NULL) 164 146 return NULL; … … 167 149 state->control_puts = control_puts_fn; 168 150 169 state-> width = width;170 state-> height = height;151 state->cols = cols; 152 state->rows = rows; 171 153 172 154 state->cur_col = (sysarg_t) -1; … … 175 157 state->cur_attrs.type = CHAR_ATTR_STYLE; 176 158 state->cur_attrs.val.style = STYLE_NORMAL; 177 178 memset(state->backbuf, 0, sz);179 159 180 160 /* Initialize graphic rendition attributes */ … … 183 163 vt100_sgr(state, SGR_BGCOLOR + CI_WHITE); 184 164 state->control_puts("\033[2J"); 165 state->control_puts("\033[?25l"); 185 166 186 167 return state; 187 168 } 188 169 189 void vt100_get_resolution(vt100_state_t *state, sysarg_t *width, 190 sysarg_t *height) 191 { 192 *width = state->width; 193 *height = state->height; 170 void vt100_state_destroy(vt100_state_t *state) 171 { 172 free(state); 173 } 174 175 void vt100_get_dimensions(vt100_state_t *state, sysarg_t *cols, 176 sysarg_t *rows) 177 { 178 *cols = state->cols; 179 *rows = state->rows; 194 180 } 195 181 … … 201 187 int vt100_claim(vt100_state_t *state) 202 188 { 203 for (sysarg_t row = 0; row < state->height; row++) {204 vt100_set_pos(state, 0, row);205 for (sysarg_t col = 0; col < state->width; col++) {206 charfield_t *field = state->backbuf +207 BACKBUF_POS(state, col, row);208 vt100_set_sgr(state, field->attrs);209 state->putchar(field->ch);210 }211 }212 213 vt100_set_pos(state, state->cur_col, state->cur_row);214 vt100_set_sgr(state, state->cur_attrs);215 216 189 return EOK; 217 190 } 218 191 219 void vt100_putchar(vt100_state_t *state, wchar_t ch)220 {221 charfield_t *field = state->backbuf +222 BACKBUF_POS(state, state->cur_col, state->cur_row);223 field->ch = ch;224 field->attrs = state->cur_attrs;225 226 state->putchar(ch);227 state->cur_col++;228 229 if (state->cur_col >= state->width) {230 state->cur_row += state->cur_col / state->width;231 state->cur_col %= state->width;232 }233 }234 235 void vt100_set_attr(vt100_state_t *state, char_attrs_t attrs)236 {237 if (!attrs_same(state->cur_attrs, attrs)) {238 vt100_set_sgr(state, attrs);239 state->cur_attrs = attrs;240 }241 }242 243 192 void vt100_goto(vt100_state_t *state, sysarg_t col, sysarg_t row) 244 193 { 245 if ((col >= state-> width) || (row >= state->height))194 if ((col >= state->cols) || (row >= state->rows)) 246 195 return; 247 196 … … 253 202 } 254 203 204 void vt100_set_attr(vt100_state_t *state, char_attrs_t attrs) 205 { 206 if (!attrs_same(state->cur_attrs, attrs)) { 207 vt100_set_sgr(state, attrs); 208 state->cur_attrs = attrs; 209 } 210 } 211 255 212 void vt100_cursor_visibility(vt100_state_t *state, bool visible) 256 213 { … … 261 218 } 262 219 220 void vt100_putchar(vt100_state_t *state, wchar_t ch) 221 { 222 state->putchar(ch == 0 ? ' ' : ch); 223 state->cur_col++; 224 225 if (state->cur_col >= state->cols) { 226 state->cur_row += state->cur_col / state->cols; 227 state->cur_col %= state->cols; 228 } 229 } 230 263 231 /** @} 264 232 */
Note:
See TracChangeset
for help on using the changeset viewer.