Changeset 9f1362d4 in mainline
- Timestamp:
- 2010-04-19T19:58:18Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 369a5f8
- Parents:
- caad59a
- Location:
- uspace
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
rcaad59a r9f1362d4 40 40 #include <vfs/vfs.h> 41 41 #include <io/console.h> 42 #include <io/ color.h>42 #include <io/style.h> 43 43 #include <io/keycode.h> 44 44 #include <errno.h> … … 100 100 static bool cursor_visible; 101 101 102 static int scr_rows, scr_columns; 102 static ipcarg_t scr_rows; 103 static ipcarg_t scr_columns; 103 104 104 105 #define ROW_BUF_SIZE 4096 … … 505 506 asprintf(&str, "%s: %s", prompt, init_value); 506 507 status_display(str); 507 console_ goto(con, 1 + str_length(str), scr_rows - 1);508 console_set_pos(con, 1 + str_length(str), scr_rows - 1); 508 509 free(str); 509 510 510 console_set_ color(con, COLOR_WHITE, COLOR_BLACK, 0);511 console_set_style(con, STYLE_INVERTED); 511 512 512 513 max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt)); … … 552 553 str = wstr_to_astr(buffer); 553 554 554 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);555 console_set_style(con, STYLE_NORMAL); 555 556 556 557 return str; … … 671 672 { 672 673 int sh_rows, rows; 673 int i, j;674 674 675 675 sheet_get_num_rows(&doc.sh, &sh_rows); … … 678 678 /* Draw rows from the sheet. */ 679 679 680 console_ goto(con, 0, 0);680 console_set_pos(con, 0, 0); 681 681 pane_row_range_display(0, rows); 682 682 683 683 /* Clear the remaining rows if file is short. */ 684 684 685 int i; 686 ipcarg_t j; 685 687 for (i = rows; i < pane.rows; ++i) { 686 console_ goto(con, 0, i);688 console_set_pos(con, 0, i); 687 689 for (j = 0; j < scr_columns; ++j) 688 690 putchar(' '); … … 736 738 /* Draw rows from the sheet. */ 737 739 738 console_ goto(con, 0, 0);740 console_set_pos(con, 0, 0); 739 741 for (i = r0; i < r1; ++i) { 740 742 /* Starting point for row display */ … … 756 758 coord_cmp(&rbc, &csel_end) < 0) { 757 759 fflush(stdout); 758 console_set_ color(con, COLOR_BLACK, COLOR_RED, 0);760 console_set_style(con, STYLE_SELECTED); 759 761 fflush(stdout); 760 762 } 761 763 762 console_ goto(con, 0, i);764 console_set_pos(con, 0, i); 763 765 size = str_size(row_buf); 764 766 pos = 0; … … 767 769 if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) { 768 770 fflush(stdout); 769 console_set_ color(con, COLOR_BLACK, COLOR_RED, 0);771 console_set_style(con, STYLE_SELECTED); 770 772 fflush(stdout); 771 773 } … … 773 775 if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) { 774 776 fflush(stdout); 775 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);777 console_set_style(con, STYLE_NORMAL); 776 778 fflush(stdout); 777 779 } … … 793 795 if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) { 794 796 fflush(stdout); 795 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);797 console_set_style(con, STYLE_NORMAL); 796 798 fflush(stdout); 797 799 } … … 807 809 putchar(' '); 808 810 fflush(stdout); 809 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);811 console_set_style(con, STYLE_NORMAL); 810 812 } 811 813 … … 824 826 const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>"; 825 827 826 console_ goto(con, 0, scr_rows - 1);827 console_set_ color(con, COLOR_WHITE, COLOR_BLACK, 0);828 console_set_pos(con, 0, scr_rows - 1); 829 console_set_style(con, STYLE_INVERTED); 828 830 int n = printf(" %d, %d: File '%s'. Ctrl-Q Quit Ctrl-S Save " 829 831 "Ctrl-E Save As", coord.row, coord.column, fname); 830 832 printf("%*s", scr_columns - 1 - n, ""); 831 833 fflush(stdout); 832 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);834 console_set_style(con, STYLE_NORMAL); 833 835 834 836 pane.rflags |= REDRAW_CARET; … … 844 846 845 847 spt_get_coord(&caret_pt, &coord); 846 console_ goto(con, coord.column - pane.sh_column,848 console_set_pos(con, coord.column - pane.sh_column, 847 849 coord.row - pane.sh_row); 848 850 } … … 1149 1151 static void status_display(char const *str) 1150 1152 { 1151 console_ goto(con, 0, scr_rows - 1);1152 console_set_ color(con, COLOR_WHITE, COLOR_BLACK, 0);1153 console_set_pos(con, 0, scr_rows - 1); 1154 console_set_style(con, STYLE_INVERTED); 1153 1155 printf(" %*s ", -(scr_columns - 3), str); 1154 1156 fflush(stdout); 1155 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);1157 console_set_style(con, STYLE_NORMAL); 1156 1158 1157 1159 pane.rflags |= REDRAW_CARET; -
uspace/app/tester/console/console1.c
rcaad59a r9f1362d4 53 53 fflush(stdout); 54 54 console_set_style(fphone(stdout), STYLE_NORMAL); 55 printf(" normal ");55 printf(" normal "); 56 56 fflush(stdout); 57 57 console_set_style(fphone(stdout), STYLE_EMPHASIS); 58 printf("emphasized"); 58 printf(" emphasized "); 59 fflush(stdout); 60 console_set_style(fphone(stdout), STYLE_INVERTED); 61 printf(" inverted "); 62 fflush(stdout); 63 console_set_style(fphone(stdout), STYLE_SELECTED); 64 printf(" selected "); 59 65 fflush(stdout); 60 66 console_set_style(fphone(stdout), STYLE_NORMAL); 61 printf(" .\n");67 printf("\n"); 62 68 63 69 unsigned int i; … … 73 79 } 74 80 fflush(stdout); 75 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);81 console_set_style(fphone(stdout), STYLE_NORMAL); 76 82 putchar('\n'); 77 83 } … … 86 92 } 87 93 fflush(stdout); 88 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);94 console_set_style(fphone(stdout), STYLE_NORMAL); 89 95 putchar('\n'); 90 96 } … … 94 100 for (i = 0; i < 255; i += 16) { 95 101 fflush(stdout); 96 console_set_rgb_color(fphone(stdout), 0xffffff, i << 16);102 console_set_rgb_color(fphone(stdout), (255 - i) << 16, i << 16); 97 103 putchar('X'); 98 104 } … … 103 109 for (i = 0; i < 255; i += 16) { 104 110 fflush(stdout); 105 console_set_rgb_color(fphone(stdout), 0xffffff, i << 8);111 console_set_rgb_color(fphone(stdout), (255 - i) << 8, i << 8); 106 112 putchar('X'); 107 113 } … … 112 118 for (i = 0; i < 255; i += 16) { 113 119 fflush(stdout); 114 console_set_rgb_color(fphone(stdout), 0xffffff, i);120 console_set_rgb_color(fphone(stdout), 255 - i, i); 115 121 putchar('X'); 116 122 } 117 123 fflush(stdout); 118 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);124 console_set_style(fphone(stdout), STYLE_NORMAL); 119 125 putchar('\n'); 120 126 } -
uspace/app/tetris/screen.c
rcaad59a r9f1362d4 53 53 #include <vfs/vfs.h> 54 54 #include <async.h> 55 #include <bool.h> 56 #include <io/console.h> 57 #include <io/style.h> 55 58 #include "screen.h" 56 59 #include "tetris.h" 57 #include <io/console.h>58 60 59 61 #define STOP (B_COLS - 3) … … 63 65 static int isset; /* true => terminal is in game mode */ 64 66 65 static int use_color;/* true => use colors */67 static bool use_color; /* true => use colors */ 66 68 67 69 static const struct shape *lastshape; … … 81 83 { 82 84 fflush(stdout); 83 console_set_rgb_color(fphone(stdout), 0xf 0f0f0,85 console_set_rgb_color(fphone(stdout), 0xffffff, 84 86 use_color ? color : 0x000000); 85 87 } … … 88 90 { 89 91 fflush(stdout); 90 console_set_ rgb_color(fphone(stdout), 0, 0xf0f0f0);92 console_set_style(fphone(stdout), STYLE_NORMAL); 91 93 } 92 94 … … 118 120 } 119 121 120 void moveto(i nt r, int c)122 void moveto(ipcarg_t r, ipcarg_t c) 121 123 { 122 124 fflush(stdout); 123 console_ goto(fphone(stdout), c, r);125 console_set_pos(fphone(stdout), c, r); 124 126 } 125 127 … … 131 133 } 132 134 133 static int get_display_color_sup(void) 134 { 135 int rc; 136 int ccap; 137 138 rc = console_get_color_cap(fphone(stdout), &ccap); 135 static bool get_display_color_sup(void) 136 { 137 ipcarg_t ccap; 138 int rc = console_get_color_cap(fphone(stdout), &ccap); 139 139 140 if (rc != 0) 140 return 0;141 141 return false; 142 142 143 return (ccap >= CONSOLE_CCAP_RGB); 143 144 } … … 308 309 * (We need its length in case we have to overwrite with blanks.) 309 310 */ 310 void scr_msg(char *s, intset)311 void scr_msg(char *s, bool set) 311 312 { 312 313 int l = str_size(s); -
uspace/app/tetris/screen.h
rcaad59a r9f1362d4 48 48 49 49 #include <sys/types.h> 50 #include <ipc/ipc.h> 50 51 #include <async.h> 52 #include <bool.h> 51 53 52 54 typedef struct { 53 i nt ws_row;54 i nt ws_col;55 ipcarg_t ws_row; 56 ipcarg_t ws_col; 55 57 } winsize_t; 56 58 57 59 extern winsize_t winsize; 58 60 59 extern void moveto(i nt r, int c);61 extern void moveto(ipcarg_t r, ipcarg_t c); 60 62 extern void clear_screen(void); 61 63 … … 65 67 extern void scr_end(void); 66 68 extern void scr_init(void); 67 extern void scr_msg(char *, int);69 extern void scr_msg(char *, bool); 68 70 extern void scr_set(void); 69 71 extern void scr_update(void); -
uspace/app/top/screen.c
rcaad59a r9f1362d4 37 37 38 38 #include <stdio.h> 39 #include <ipc/ipc.h> 39 40 #include <io/console.h> 41 #include <io/style.h> 40 42 #include <vfs/vfs.h> 41 43 #include <stdarg.h> … … 45 47 #include "top.h" 46 48 47 #define WHITE 0xf0f0f0 48 #define BLACK 0x000000 49 50 static int rows; 51 static int colls; 52 static int up_rows; 49 static ipcarg_t warn_col = 0; 50 static ipcarg_t warn_row = 0; 51 52 static void screen_style_normal(void) 53 { 54 fflush(stdout); 55 console_set_style(fphone(stdout), STYLE_NORMAL); 56 } 57 58 static void screen_style_inverted(void) 59 { 60 fflush(stdout); 61 console_set_style(fphone(stdout), STYLE_INVERTED); 62 } 63 64 static void screen_moveto(ipcarg_t col, ipcarg_t row) 65 { 66 fflush(stdout); 67 console_set_pos(fphone(stdout), col, row); 68 } 69 70 static void screen_get_pos(ipcarg_t *col, ipcarg_t *row) 71 { 72 fflush(stdout); 73 console_get_pos(fphone(stdout), col, row); 74 } 75 76 static void screen_get_size(ipcarg_t *col, ipcarg_t *row) 77 { 78 fflush(stdout); 79 console_get_size(fphone(stdout), col, row); 80 } 81 82 static void screen_restart(bool clear) 83 { 84 screen_style_normal(); 85 86 if (clear) { 87 fflush(stdout); 88 console_clear(fphone(stdout)); 89 } 90 91 screen_moveto(0, 0); 92 } 93 94 static void screen_newline(void) 95 { 96 ipcarg_t cols; 97 ipcarg_t rows; 98 screen_get_size(&cols, &rows); 99 100 ipcarg_t c; 101 ipcarg_t r; 102 screen_get_pos(&c, &r); 103 104 ipcarg_t i; 105 for (i = c + 1; i < cols; i++) 106 puts(" "); 107 108 if (r + 1 < rows) 109 puts("\n"); 110 } 111 112 void screen_init(void) 113 { 114 fflush(stdout); 115 console_cursor_visibility(fphone(stdout), false); 116 117 screen_restart(true); 118 } 119 120 void screen_done(void) 121 { 122 screen_restart(true); 123 124 fflush(stdout); 125 console_cursor_visibility(fphone(stdout), true); 126 } 53 127 54 128 static void print_float(fixed_float ffloat, unsigned int precision) … … 64 138 } 65 139 66 static void screen_resume_normal(void) 67 { 68 fflush(stdout); 69 console_set_rgb_color(fphone(stdout), 0, WHITE); 70 } 71 72 static void screen_moveto(int r, int c) 73 { 74 fflush(stdout); 75 console_goto(fphone(stdout), c, r); 76 } 77 78 static void screen_clear(void) 79 { 80 console_clear(fphone(stdout)); 81 screen_moveto(0, 0); 82 up_rows = 0; 83 fflush(stdout); 84 } 85 86 void screen_init(void) 87 { 88 console_cursor_visibility(fphone(stdout), 0); 89 screen_resume_normal(); 90 screen_clear(); 91 92 console_get_size(fphone(stdout), &colls, &rows); 93 } 94 95 void screen_done(void) 96 { 97 screen_resume_normal(); 98 screen_clear(); 99 console_cursor_visibility(fphone(stdout), 1); 100 } 101 102 static inline void print_time(data_t *data) 103 { 104 printf("%02lu:%02lu:%02lu ", data->hours, data->minutes, data->seconds); 105 } 106 107 static inline void print_uptime(data_t *data) 108 { 109 printf("up %u days, %02u:%02u:%02u, ", data->udays, data->uhours, 110 data->uminutes, data->useconds); 111 } 112 113 static inline void print_load(data_t *data) 114 { 115 printf("load avarage: "); 140 static inline void print_global_head(data_t *data) 141 { 142 printf("top - %02lu:%02lu:%02lu up %u days, %02u:%02u:%02u, load avarage:", 143 data->hours, data->minutes, data->seconds, 144 data->udays, data->uhours, data->uminutes, data->useconds); 116 145 117 146 size_t i; 118 147 for (i = 0; i < data->load_count; i++) { 148 puts(" "); 119 149 stats_print_load_fragment(data->load[i], 2); 120 printf(" "); 121 } 150 } 151 152 screen_newline(); 122 153 } 123 154 … … 125 156 { 126 157 printf("tasks: %u total", data->tasks_count); 158 screen_newline(); 127 159 } 128 160 … … 137 169 size_t invalid = 0; 138 170 139 140 171 size_t i; 141 172 for (i = 0; i < data->threads_count; i++) { … … 167 198 "%u other, %u invalid", 168 199 total, running, ready, sleeping, lingering, other, invalid); 200 screen_newline(); 169 201 } 170 202 … … 178 210 data->cpus[i].id, data->cpus[i].frequency_mhz, 179 211 data->cpus[i].busy_ticks, data->cpus[i].idle_ticks); 180 p rintf(", idle: ");212 puts(", idle: "); 181 213 print_float(data->cpus_perc[i].idle, 2); 182 p rintf("%%, busy: ");214 puts("%, busy: "); 183 215 print_float(data->cpus_perc[i].busy, 2); 184 p rintf("%%\n");216 puts("%"); 185 217 } else 186 printf("cpu%u inactive \n", data->cpus[i].id);187 188 up_rows++;218 printf("cpu%u inactive", data->cpus[i].id); 219 220 screen_newline(); 189 221 } 190 222 } … … 209 241 PRIu64 "%c used, %" PRIu64 "%c free", total, total_suffix, 210 242 unavail, unavail_suffix, used, used_suffix, free, free_suffix); 211 } 212 213 static inline void print_tasks(data_t *data, int row) 214 { 215 size_t i; 216 for (i = 0; i < data->tasks_count; i++, row++) { 217 if (row > rows) 218 break; 219 243 screen_newline(); 244 } 245 246 static inline void print_task_head(void) 247 { 248 screen_style_inverted(); 249 printf(" ID Threads Mem %%Mem %%uCycles %%kCycles Name"); 250 screen_newline(); 251 screen_style_normal(); 252 } 253 254 static inline void print_tasks(data_t *data) 255 { 256 ipcarg_t cols; 257 ipcarg_t rows; 258 screen_get_size(&cols, &rows); 259 260 ipcarg_t col; 261 ipcarg_t row; 262 screen_get_pos(&col, &row); 263 264 size_t i; 265 for (i = 0; (i < data->tasks_count) && (row < rows); i++, row++) { 220 266 uint64_t virtmem; 221 267 char virtmem_suffix; … … 224 270 printf("%8" PRIu64 " %8u %8" PRIu64 "%c ", data->tasks[i].task_id, 225 271 data->tasks[i].threads, virtmem, virtmem_suffix); 226 p rintf(" ");272 puts(" "); 227 273 print_float(data->tasks_perc[i].virtmem, 2); 228 p rintf("%% ");274 puts("% "); 229 275 print_float(data->tasks_perc[i].ucycles, 2); 230 p rintf("%% ");276 puts("% "); 231 277 print_float(data->tasks_perc[i].kcycles, 2); 232 printf("%% %s\n", data->tasks[i].name); 233 } 234 } 235 236 static inline void print_task_head(void) 237 { 238 fflush(stdout); 239 console_set_rgb_color(fphone(stdout), WHITE, BLACK); 240 241 printf(" ID Threads Mem %%Mem %%uCycles %%kCycles Name"); 242 243 int i; 244 for (i = 61; i < colls; ++i) 245 printf(" "); 246 247 fflush(stdout); 248 console_set_rgb_color(fphone(stdout), BLACK, WHITE); 278 printf("%% %s", data->tasks[i].name); 279 280 screen_newline(); 281 } 249 282 } 250 283 251 284 static inline void print_ipc_head(void) 252 285 { 253 fflush(stdout); 254 console_set_rgb_color(fphone(stdout), WHITE, BLACK); 255 286 screen_style_inverted(); 256 287 printf(" ID Calls sent Calls recv Answs sent Answs recv IRQn recv Forw Name"); 257 258 int i;259 for (i = 80; i < colls; ++i) 260 printf(" "); 261 262 fflush(stdout); 263 console_set_rgb_color(fphone(stdout), BLACK, WHITE);264 } 265 266 static inline void print_ipc(data_t *data, int row) 267 { 268 size_t i;269 for (i = 0; i < data->tasks_count; i++, row++) {270 if (row > rows)271 break;272 288 screen_newline(); 289 screen_style_normal(); 290 } 291 292 static inline void print_ipc(data_t *data) 293 { 294 ipcarg_t cols; 295 ipcarg_t rows; 296 screen_get_size(&cols, &rows); 297 298 ipcarg_t col; 299 ipcarg_t row; 300 screen_get_pos(&col, &row); 301 302 size_t i; 303 for (i = 0; (i < data->tasks_count) && (row < rows); i++, row++) { 273 304 printf("%8" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 274 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %s \n",305 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %s", 275 306 data->tasks[i].task_id, data->tasks[i].ipc_info.call_sent, 276 307 data->tasks[i].ipc_info.call_recieved, … … 279 310 data->tasks[i].ipc_info.irq_notif_recieved, 280 311 data->tasks[i].ipc_info.forwarded, data->tasks[i].name); 312 313 screen_newline(); 281 314 } 282 315 } … … 284 317 void print_data(data_t *data) 285 318 { 286 screen_clear(); 287 fflush(stdout); 288 289 printf("top - "); 290 print_time(data); 291 print_uptime(data); 292 print_load(data); 293 294 printf("\n"); 295 up_rows++; 296 319 screen_restart(false); 320 print_global_head(data); 297 321 print_task_summary(data); 298 299 printf("\n");300 up_rows++;301 302 322 print_thread_summary(data); 303 304 printf("\n");305 up_rows++;306 307 323 print_cpu_info(data); 308 324 print_physmem_info(data); 309 325 310 printf("\n");311 up_rows++;312 313 326 /* Empty row for warnings */ 314 printf("\n"); 327 screen_get_pos(&warn_col, &warn_row); 328 screen_newline(); 315 329 316 330 if (operation_type == OP_IPC) { 317 331 print_ipc_head(); 318 printf("\n"); 319 print_ipc(data, up_rows); 332 print_ipc(data); 320 333 } else { 321 334 print_task_head(); 322 printf("\n"); 323 print_tasks(data, up_rows); 335 print_tasks(data); 324 336 } 325 337 … … 329 341 void print_warning(const char *fmt, ...) 330 342 { 331 screen_moveto( up_rows, 0);343 screen_moveto(warn_col, warn_row); 332 344 333 345 va_list args; … … 336 348 va_end(args); 337 349 350 screen_newline(); 338 351 fflush(stdout); 339 352 } -
uspace/lib/c/generic/io/console.c
rcaad59a r9f1362d4 45 45 } 46 46 47 int console_get_size(int phone, i nt *cols, int *rows)47 int console_get_size(int phone, ipcarg_t *cols, ipcarg_t *rows) 48 48 { 49 ipcarg_t cols_v; 50 ipcarg_t rows_v; 51 int rc; 52 53 rc = async_req_0_2(phone, CONSOLE_GET_SIZE, &cols_v, &rows_v); 54 55 *cols = (int) cols_v; 56 *rows = (int) rows_v; 57 return rc; 49 return async_req_0_2(phone, CONSOLE_GET_SIZE, cols, rows); 58 50 } 59 51 60 void console_set_style(int phone, int style)52 void console_set_style(int phone, uint8_t style) 61 53 { 62 54 async_msg_1(phone, CONSOLE_SET_STYLE, style); 63 55 } 64 56 65 void console_set_color(int phone, int fg_color, int bg_color, int flags) 57 void console_set_color(int phone, uint8_t fg_color, uint8_t bg_color, 58 uint8_t flags) 66 59 { 67 60 async_msg_3(phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags); 68 61 } 69 62 70 void console_set_rgb_color(int phone, int fg_color, int bg_color)63 void console_set_rgb_color(int phone, uint32_t fg_color, uint32_t bg_color) 71 64 { 72 65 async_msg_2(phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color); … … 75 68 void console_cursor_visibility(int phone, bool show) 76 69 { 77 async_msg_1(phone, CONSOLE_CURSOR_VISIBILITY, show != false);70 async_msg_1(phone, CONSOLE_CURSOR_VISIBILITY, (show != false)); 78 71 } 79 72 80 int console_get_color_cap(int phone, i nt *ccap)73 int console_get_color_cap(int phone, ipcarg_t *ccap) 81 74 { 82 ipcarg_t ccap_tmp; 83 int rc; 84 85 rc = async_req_0_1(phone, CONSOLE_GET_COLOR_CAP, &ccap_tmp); 86 *ccap = ccap_tmp; 87 88 return rc; 75 return async_req_0_1(phone, CONSOLE_GET_COLOR_CAP, ccap); 89 76 } 90 77 … … 94 81 } 95 82 96 int console_get_pos(int phone, i nt *col, int *row)83 int console_get_pos(int phone, ipcarg_t *col, ipcarg_t *row) 97 84 { 98 ipcarg_t col_v; 99 ipcarg_t row_v; 100 int rc; 101 102 rc = async_req_0_2(phone, CONSOLE_GET_POS, &col_v, &row_v); 103 104 *col = (int) col_v; 105 *row = (int) row_v; 106 return rc; 85 return async_req_0_2(phone, CONSOLE_GET_POS, col, row); 107 86 } 108 87 109 void console_ goto(int phone, int col, int row)88 void console_set_pos(int phone, ipcarg_t col, ipcarg_t row) 110 89 { 111 90 async_msg_2(phone, CONSOLE_GOTO, col, row); -
uspace/lib/c/include/io/console.h
rcaad59a r9f1362d4 68 68 extern void console_clear(int phone); 69 69 70 extern int console_get_size(int phone, i nt *cols, int *rows);71 extern int console_get_pos(int phone, i nt *col, int *row);72 extern void console_ goto(int phone, int col, int row);70 extern int console_get_size(int phone, ipcarg_t *cols, ipcarg_t *rows); 71 extern int console_get_pos(int phone, ipcarg_t *col, ipcarg_t *row); 72 extern void console_set_pos(int phone, ipcarg_t col, ipcarg_t row); 73 73 74 extern void console_set_style(int phone, int style); 75 extern void console_set_color(int phone, int fg_color, int bg_color, int flags); 76 extern void console_set_rgb_color(int phone, int fg_color, int bg_color); 74 extern void console_set_style(int phone, uint8_t style); 75 extern void console_set_color(int phone, uint8_t fg_color, uint8_t bg_color, 76 uint8_t flags); 77 extern void console_set_rgb_color(int phone, uint32_t fg_color, uint32_t bg_color); 77 78 78 79 extern void console_cursor_visibility(int phone, bool show); 79 extern int console_get_color_cap(int phone, i nt *ccap);80 extern int console_get_color_cap(int phone, ipcarg_t *ccap); 80 81 extern void console_kcon_enable(int phone); 81 82 -
uspace/lib/c/include/io/style.h
rcaad59a r9f1362d4 38 38 enum console_style { 39 39 STYLE_NORMAL = 0, 40 STYLE_EMPHASIS = 1 40 STYLE_EMPHASIS = 1, 41 STYLE_INVERTED = 2, 42 STYLE_SELECTED = 3 41 43 }; 42 44 -
uspace/lib/clui/Makefile
rcaad59a r9f1362d4 28 28 29 29 USPACE_PREFIX = ../.. 30 EXTRA_CFLAGS = -I. 30 31 LIBRARY = libclui 31 32 -
uspace/lib/clui/tinput.c
rcaad59a r9f1362d4 40 40 #include <assert.h> 41 41 #include <bool.h> 42 43 #include "tinput.h" 42 #include <tinput.h> 44 43 45 44 /** Seek direction */ … … 49 48 } seek_dir_t; 50 49 51 static void tinput_init(tinput_t * ti);52 static void tinput_insert_string(tinput_t * ti, const char *str);53 static void tinput_sel_get_bounds(tinput_t * ti, int *sa, int *sb);54 static bool tinput_sel_active(tinput_t * ti);55 static void tinput_sel_all(tinput_t * ti);56 static void tinput_sel_delete(tinput_t * ti);57 static void tinput_key_ctrl(tinput_t * ti, console_event_t *ev);58 static void tinput_key_shift(tinput_t * ti, console_event_t *ev);59 static void tinput_key_ctrl_shift(tinput_t * ti, console_event_t *ev);60 static void tinput_key_unmod(tinput_t * ti, console_event_t *ev);61 static void tinput_pre_seek(tinput_t * ti, bool shift_held);62 static void tinput_post_seek(tinput_t * ti, bool shift_held);50 static void tinput_init(tinput_t *); 51 static void tinput_insert_string(tinput_t *, const char *); 52 static void tinput_sel_get_bounds(tinput_t *, size_t *, size_t *); 53 static bool tinput_sel_active(tinput_t *); 54 static void tinput_sel_all(tinput_t *); 55 static void tinput_sel_delete(tinput_t *); 56 static void tinput_key_ctrl(tinput_t *, console_event_t *); 57 static void tinput_key_shift(tinput_t *, console_event_t *); 58 static void tinput_key_ctrl_shift(tinput_t *, console_event_t *); 59 static void tinput_key_unmod(tinput_t *, console_event_t *); 60 static void tinput_pre_seek(tinput_t *, bool); 61 static void tinput_post_seek(tinput_t *, bool); 63 62 64 63 /** Create a new text input field. */ … … 66 65 { 67 66 tinput_t *ti; 68 67 69 68 ti = malloc(sizeof(tinput_t)); 70 69 if (ti == NULL) 71 70 return NULL; 72 71 73 72 tinput_init(ti); 74 73 return ti; … … 81 80 } 82 81 83 static void tinput_display_tail(tinput_t *ti, int start, int pad)84 { 85 staticwchar_t dbuf[INPUT_MAX_SIZE + 1];86 int sa, sb;87 int i, p;88 82 static void tinput_display_tail(tinput_t *ti, size_t start, size_t pad) 83 { 84 wchar_t dbuf[INPUT_MAX_SIZE + 1]; 85 86 size_t sa; 87 size_t sb; 89 88 tinput_sel_get_bounds(ti, &sa, &sb); 90 91 console_ goto(fphone(stdout), (ti->col0 + start) % ti->con_cols,89 90 console_set_pos(fphone(stdout), (ti->col0 + start) % ti->con_cols, 92 91 ti->row0 + (ti->col0 + start) / ti->con_cols); 93 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);94 95 p = start;92 console_set_style(fphone(stdout), STYLE_NORMAL); 93 94 size_t p = start; 96 95 if (p < sa) { 97 96 memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(wchar_t)); … … 100 99 p = sa; 101 100 } 102 101 103 102 if (p < sb) { 104 103 fflush(stdout); 105 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_RED, 0);104 console_set_style(fphone(stdout), STYLE_SELECTED); 106 105 memcpy(dbuf, ti->buffer + p, 107 106 (sb - p) * sizeof(wchar_t)); … … 110 109 p = sb; 111 110 } 112 111 113 112 fflush(stdout); 114 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);115 113 console_set_style(fphone(stdout), STYLE_NORMAL); 114 116 115 if (p < ti->nc) { 117 116 memcpy(dbuf, ti->buffer + p, … … 120 119 printf("%ls", dbuf); 121 120 } 122 123 for ( i = 0; i < pad; ++i)121 122 for (p = 0; p < pad; p++) 124 123 putchar(' '); 124 125 125 fflush(stdout); 126 126 } … … 133 133 static void tinput_position_caret(tinput_t *ti) 134 134 { 135 console_ goto(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols,135 console_set_pos(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols, 136 136 ti->row0 + (ti->col0 + ti->pos) / ti->con_cols); 137 137 } … … 140 140 static void tinput_update_origin(tinput_t *ti) 141 141 { 142 int width, rows; 143 144 width = ti->col0 + ti->nc; 145 rows = (width / ti->con_cols) + 1; 146 142 ipcarg_t width = ti->col0 + ti->nc; 143 ipcarg_t rows = (width / ti->con_cols) + 1; 144 147 145 /* Update row0 if the screen scrolled. */ 148 146 if (ti->row0 + rows > ti->con_rows) 149 ti->row0 = ti->con_rows - rows; 147 ti->row0 = ti->con_rows - rows; 150 148 } 151 149 152 150 static void tinput_insert_char(tinput_t *ti, wchar_t c) 153 151 { 154 int i;155 int new_width, new_height;156 157 152 if (ti->nc == INPUT_MAX_SIZE) 158 153 return; 159 160 new_width = ti->col0 + ti->nc + 1;154 155 ipcarg_t new_width = ti->col0 + ti->nc + 1; 161 156 if (new_width % ti->con_cols == 0) { 162 157 /* Advancing to new line. */ 163 new_height = (new_width / ti->con_cols) + 1; 164 if (new_height >= ti->con_rows) 165 return; /* Disallow text longer than 1 page for now. */ 166 } 167 168 for (i = ti->nc; i > ti->pos; --i) 158 ipcarg_t new_height = (new_width / ti->con_cols) + 1; 159 if (new_height >= ti->con_rows) { 160 /* Disallow text longer than 1 page for now. */ 161 return; 162 } 163 } 164 165 size_t i; 166 for (i = ti->nc; i > ti->pos; i--) 169 167 ti->buffer[i] = ti->buffer[i - 1]; 170 168 171 169 ti->buffer[ti->pos] = c; 172 170 ti->pos += 1; … … 174 172 ti->buffer[ti->nc] = '\0'; 175 173 ti->sel_start = ti->pos; 176 174 177 175 tinput_display_tail(ti, ti->pos - 1, 0); 178 176 tinput_update_origin(ti); … … 182 180 static void tinput_insert_string(tinput_t *ti, const char *str) 183 181 { 184 int i; 185 int new_width, new_height; 186 int ilen; 187 wchar_t c; 188 size_t off; 189 190 ilen = min((ssize_t) str_length(str), INPUT_MAX_SIZE - ti->nc); 182 size_t ilen = min(str_length(str), INPUT_MAX_SIZE - ti->nc); 191 183 if (ilen == 0) 192 184 return; 193 194 new_width = ti->col0 + ti->nc + ilen; 195 new_height = (new_width / ti->con_cols) + 1; 196 if (new_height >= ti->con_rows) 197 return; /* Disallow text longer than 1 page for now. */ 198 199 for (i = ti->nc - 1; i >= ti->pos; --i) 200 ti->buffer[i + ilen] = ti->buffer[i]; 201 202 off = 0; i = 0; 185 186 ipcarg_t new_width = ti->col0 + ti->nc + ilen; 187 ipcarg_t new_height = (new_width / ti->con_cols) + 1; 188 if (new_height >= ti->con_rows) { 189 /* Disallow text longer than 1 page for now. */ 190 return; 191 } 192 193 if (ti->nc > 0) { 194 size_t i; 195 for (i = ti->nc; i > ti->pos; i--) 196 ti->buffer[i + ilen - 1] = ti->buffer[i - 1]; 197 } 198 199 size_t off = 0; 200 size_t i = 0; 203 201 while (i < ilen) { 204 c = str_decode(str, &off, STR_NO_LIMIT);202 wchar_t c = str_decode(str, &off, STR_NO_LIMIT); 205 203 if (c == '\0') 206 204 break; 207 205 208 206 /* Filter out non-printable chars. */ 209 207 if (c < 32) 210 208 c = 32; 211 209 212 210 ti->buffer[ti->pos + i] = c; 213 ++i;214 } 215 211 i++; 212 } 213 216 214 ti->pos += ilen; 217 215 ti->nc += ilen; 218 216 ti->buffer[ti->nc] = '\0'; 219 217 ti->sel_start = ti->pos; 220 218 221 219 tinput_display_tail(ti, ti->pos - ilen, 0); 222 220 tinput_update_origin(ti); … … 226 224 static void tinput_backspace(tinput_t *ti) 227 225 { 228 int i;229 230 226 if (tinput_sel_active(ti)) { 231 227 tinput_sel_delete(ti); 232 228 return; 233 229 } 234 230 235 231 if (ti->pos == 0) 236 232 return; 237 238 for (i = ti->pos; i < ti->nc; ++i) 233 234 size_t i; 235 for (i = ti->pos; i < ti->nc; i++) 239 236 ti->buffer[i - 1] = ti->buffer[i]; 237 240 238 ti->pos -= 1; 241 239 ti->nc -= 1; 242 240 ti->buffer[ti->nc] = '\0'; 243 241 ti->sel_start = ti->pos; 244 242 245 243 tinput_display_tail(ti, ti->pos, 1); 246 244 tinput_position_caret(ti); … … 253 251 return; 254 252 } 255 253 256 254 if (ti->pos == ti->nc) 257 255 return; 258 256 259 257 ti->pos += 1; 260 258 ti->sel_start = ti->pos; 261 259 262 260 tinput_backspace(ti); 263 261 } … … 266 264 { 267 265 tinput_pre_seek(ti, shift_held); 268 266 269 267 if (dir == seek_forward) { 270 268 if (ti->pos < ti->nc) … … 274 272 ti->pos -= 1; 275 273 } 276 274 277 275 tinput_post_seek(ti, shift_held); 278 276 } … … 281 279 { 282 280 tinput_pre_seek(ti, shift_held); 283 281 284 282 if (dir == seek_forward) { 285 283 if (ti->pos == ti->nc) 286 284 return; 287 288 while ( 1) {285 286 while (true) { 289 287 ti->pos += 1; 290 288 291 289 if (ti->pos == ti->nc) 292 290 break; 293 294 if ( ti->buffer[ti->pos - 1] == ' '&&295 ti->buffer[ti->pos] != ' ')291 292 if ((ti->buffer[ti->pos - 1] == ' ') && 293 (ti->buffer[ti->pos] != ' ')) 296 294 break; 297 295 } … … 299 297 if (ti->pos == 0) 300 298 return; 301 302 while ( 1) {299 300 while (true) { 303 301 ti->pos -= 1; 304 302 305 303 if (ti->pos == 0) 306 304 break; 307 305 308 306 if (ti->buffer[ti->pos - 1] == ' ' && 309 307 ti->buffer[ti->pos] != ' ') 310 308 break; 311 309 } 312 313 } 314 310 311 } 312 315 313 tinput_post_seek(ti, shift_held); 316 314 } … … 319 317 { 320 318 tinput_pre_seek(ti, shift_held); 321 319 322 320 if (dir == seek_forward) { 323 321 if (ti->pos + ti->con_cols <= ti->nc) 324 322 ti->pos = ti->pos + ti->con_cols; 325 323 } else { 326 if (ti->pos - ti->con_cols >= 0)324 if (ti->pos >= ti->con_cols) 327 325 ti->pos = ti->pos - ti->con_cols; 328 326 } 329 327 330 328 tinput_post_seek(ti, shift_held); 331 329 } … … 334 332 { 335 333 tinput_pre_seek(ti, shift_held); 336 334 337 335 if (dir == seek_backward) 338 336 ti->pos = 0; 339 337 else 340 338 ti->pos = ti->nc; 341 339 342 340 tinput_post_seek(ti, shift_held); 343 341 } … … 345 343 static void tinput_pre_seek(tinput_t *ti, bool shift_held) 346 344 { 347 if ( tinput_sel_active(ti) && !shift_held) {345 if ((tinput_sel_active(ti)) && (!shift_held)) { 348 346 /* Unselect and redraw. */ 349 347 ti->sel_start = ti->pos; … … 362 360 ti->sel_start = ti->pos; 363 361 } 362 364 363 tinput_position_caret(ti); 365 364 } … … 367 366 static void tinput_history_insert(tinput_t *ti, char *str) 368 367 { 369 int i;370 371 368 if (ti->hnum < HISTORY_LEN) { 372 369 ti->hnum += 1; … … 375 372 free(ti->history[HISTORY_LEN]); 376 373 } 377 378 for (i = ti->hnum; i > 1; --i) 374 375 size_t i; 376 for (i = ti->hnum; i > 1; i--) 379 377 ti->history[i] = ti->history[i - 1]; 380 378 381 379 ti->history[1] = str_dup(str); 382 380 383 381 if (ti->history[0] != NULL) { 384 382 free(ti->history[0]); … … 395 393 } 396 394 397 static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb)395 static void tinput_sel_get_bounds(tinput_t *ti, size_t *sa, size_t *sb) 398 396 { 399 397 if (ti->sel_start < ti->pos) { … … 408 406 static bool tinput_sel_active(tinput_t *ti) 409 407 { 410 return ti->sel_start != ti->pos;408 return (ti->sel_start != ti->pos); 411 409 } 412 410 … … 421 419 static void tinput_sel_delete(tinput_t *ti) 422 420 { 423 int sa, sb; 424 421 size_t sa; 422 size_t sb; 423 425 424 tinput_sel_get_bounds(ti, &sa, &sb); 426 425 if (sa == sb) 427 426 return; 428 427 429 428 memmove(ti->buffer + sa, ti->buffer + sb, 430 429 (ti->nc - sb) * sizeof(wchar_t)); 430 431 431 ti->pos = ti->sel_start = sa; 432 432 ti->nc -= (sb - sa); 433 433 ti->buffer[ti->nc] = '\0'; 434 434 435 435 tinput_display_tail(ti, sa, sb - sa); 436 436 tinput_position_caret(ti); … … 439 439 static void tinput_sel_copy_to_cb(tinput_t *ti) 440 440 { 441 int sa, sb; 441 size_t sa; 442 size_t sb; 443 444 tinput_sel_get_bounds(ti, &sa, &sb); 445 442 446 char *str; 443 444 tinput_sel_get_bounds(ti, &sa, &sb); 445 447 446 448 if (sb < ti->nc) { 447 449 wchar_t tmp_c = ti->buffer[sb]; … … 454 456 if (str == NULL) 455 457 goto error; 456 458 457 459 if (clipboard_put_str(str) != EOK) 458 460 goto error; 459 461 460 462 free(str); 461 463 return; 464 462 465 error: 466 /* TODO: Give the user some kind of warning. */ 463 467 return; 464 /* TODO: Give the user some warning. */465 468 } 466 469 … … 468 471 { 469 472 char *str; 470 int rc; 471 472 rc = clipboard_get_str(&str); 473 if (rc != EOK || str == NULL) 474 return; /* TODO: Give the user some warning. */ 475 473 int rc = clipboard_get_str(&str); 474 475 if ((rc != EOK) || (str == NULL)) { 476 /* TODO: Give the user some kind of warning. */ 477 return; 478 } 479 476 480 tinput_insert_string(ti, str); 477 481 free(str); … … 480 484 static void tinput_history_seek(tinput_t *ti, int offs) 481 485 { 482 int pad; 483 484 if (ti->hpos + offs < 0 || ti->hpos + offs > ti->hnum) 485 return; 486 486 if (offs >= 0) { 487 if (ti->hpos + offs > ti->hnum) 488 return; 489 } else { 490 if (ti->hpos < (size_t) -offs) 491 return; 492 } 493 487 494 if (ti->history[ti->hpos] != NULL) { 488 495 free(ti->history[ti->hpos]); 489 496 ti->history[ti->hpos] = NULL; 490 497 } 491 498 492 499 ti->history[ti->hpos] = tinput_get_str(ti); 493 500 ti->hpos += offs; 494 495 pad = ti->nc - str_length(ti->history[ti->hpos]); 496 if (pad < 0) pad = 0; 497 501 502 int pad = (int) ti->nc - str_length(ti->history[ti->hpos]); 503 if (pad < 0) 504 pad = 0; 505 498 506 tinput_set_str(ti, ti->history[ti->hpos]); 499 507 tinput_display_tail(ti, 0, pad); … … 515 523 /** Read in one line of input. 516 524 * 517 * @param ti Text input. 518 * @param dstr Place to save pointer to new string. 519 * @return EOK on success, ENOENT if user requested abort, EIO 520 * if communication with console failed. 525 * @param ti Text input. 526 * @param dstr Place to save pointer to new string. 527 * 528 * @return EOK on success 529 * @return ENOENT if user requested abort 530 * @return EIO if communication with console failed 531 * 521 532 */ 522 533 int tinput_read(tinput_t *ti, char **dstr) 523 534 { 524 console_event_t ev;525 char *str;526 527 535 fflush(stdout); 528 529 536 if (console_get_size(fphone(stdin), &ti->con_cols, &ti->con_rows) != EOK) 530 537 return EIO; 538 531 539 if (console_get_pos(fphone(stdin), &ti->col0, &ti->row0) != EOK) 532 540 return EIO; 533 534 ti->pos = ti->sel_start = 0; 541 542 ti->pos = 0; 543 ti->sel_start = 0; 535 544 ti->nc = 0; 536 545 ti->buffer[0] = '\0'; 537 546 ti->done = false; 538 547 ti->exit_clui = false; 539 548 540 549 while (!ti->done) { 541 550 fflush(stdout); 551 552 console_event_t ev; 542 553 if (!console_get_event(fphone(stdin), &ev)) 543 554 return EIO; 544 555 545 556 if (ev.type != KEY_PRESS) 546 557 continue; 547 548 if (( ev.mods & KM_CTRL) != 0&&549 ( ev.mods & (KM_ALT | KM_SHIFT)) == 0) {558 559 if (((ev.mods & KM_CTRL) != 0) && 560 ((ev.mods & (KM_ALT | KM_SHIFT)) == 0)) 550 561 tinput_key_ctrl(ti, &ev); 551 } 552 553 if ((ev.mods & KM_SHIFT) != 0 && 554 (ev.mods & (KM_CTRL | KM_ALT)) == 0) { 562 563 if (((ev.mods & KM_SHIFT) != 0) && 564 ((ev.mods & (KM_CTRL | KM_ALT)) == 0)) 555 565 tinput_key_shift(ti, &ev); 556 } 557 558 if ((ev.mods & KM_CTRL) != 0 && 559 (ev.mods & KM_SHIFT) != 0 && 560 (ev.mods & KM_ALT) == 0) { 566 567 if (((ev.mods & KM_CTRL) != 0) && 568 ((ev.mods & KM_SHIFT) != 0) && 569 ((ev.mods & KM_ALT) == 0)) 561 570 tinput_key_ctrl_shift(ti, &ev); 562 } 563 564 if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) { 571 572 if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) 565 573 tinput_key_unmod(ti, &ev); 566 } 567 574 568 575 if (ev.c >= ' ') { 569 576 tinput_sel_delete(ti); … … 571 578 } 572 579 } 573 580 574 581 if (ti->exit_clui) 575 582 return ENOENT; 576 583 577 584 ti->pos = ti->nc; 578 585 tinput_position_caret(ti); 579 586 putchar('\n'); 580 581 str = tinput_get_str(ti);587 588 char *str = tinput_get_str(ti); 582 589 if (str_cmp(str, "") != 0) 583 590 tinput_history_insert(ti, str); 584 591 585 592 ti->hpos = 0; 586 593 587 594 *dstr = str; 588 595 return EOK; … … 700 707 break; 701 708 case KC_UP: 702 tinput_history_seek(ti, +1);709 tinput_history_seek(ti, 1); 703 710 break; 704 711 case KC_DOWN: -
uspace/lib/clui/tinput.h
rcaad59a r9f1362d4 29 29 /** @addtogroup libclui 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file … … 37 37 #define LIBCLUI_TINPUT_H_ 38 38 39 #define HISTORY_LEN 10 40 #define INPUT_MAX_SIZE 1024 39 #include <ipc/ipc.h> 40 41 #define HISTORY_LEN 10 42 #define INPUT_MAX_SIZE 1024 41 43 42 44 /** Text input field (command line). … … 47 49 /** Buffer holding text currently being edited */ 48 50 wchar_t buffer[INPUT_MAX_SIZE + 1]; 51 49 52 /** Screen coordinates of the top-left corner of the text field */ 50 int col0, row0; 53 ipcarg_t col0; 54 ipcarg_t row0; 55 51 56 /** Screen dimensions */ 52 int con_cols, con_rows; 57 ipcarg_t con_cols; 58 ipcarg_t con_rows; 59 53 60 /** Number of characters in @c buffer */ 54 int nc; 61 size_t nc; 62 55 63 /** Caret position within buffer */ 56 int pos; 64 size_t pos; 65 57 66 /** Selection mark position within buffer */ 58 int sel_start;59 67 size_t sel_start; 68 60 69 /** History (dynamically allocated strings) */ 61 char *history[1 + HISTORY_LEN]; 70 char *history[HISTORY_LEN + 1]; 71 62 72 /** Number of entries in @c history, not counting [0] */ 63 int hnum; 73 size_t hnum; 74 64 75 /** Current position in history */ 65 int hpos; 76 size_t hpos; 77 66 78 /** @c true if finished with this line (return to caller) */ 67 79 bool done; 80 68 81 /** @c true if user requested to abort interactive loop */ 69 82 bool exit_clui; … … 71 84 72 85 extern tinput_t *tinput_new(void); 73 extern void tinput_destroy(tinput_t * ti);74 extern int tinput_read(tinput_t * ti, char **str);86 extern void tinput_destroy(tinput_t *); 87 extern int tinput_read(tinput_t *, char **); 75 88 76 89 #endif … … 78 91 /** @} 79 92 */ 80 -
uspace/srv/hid/console/console.c
rcaad59a r9f1362d4 71 71 /** Information about framebuffer */ 72 72 struct { 73 int phone; /**< Framebuffer phone */74 ipcarg_t cols; /**< Framebuffer columns */75 ipcarg_t rows; /**< Framebuffer rows */76 i nt 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) */ 77 77 } fb_info; 78 78 … … 99 99 /** Information on row-span yet unsent to FB driver. */ 100 100 struct { 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. */ 104 104 } fb_pending; 105 105 … … 117 117 } 118 118 119 static void curs_goto( size_t x, size_t y)119 static void curs_goto(ipcarg_t x, ipcarg_t y) 120 120 { 121 121 async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y); … … 147 147 } 148 148 149 static void set_style( int style)149 static void set_style(uint8_t style) 150 150 { 151 151 async_msg_1(fb_info.phone, FB_SET_STYLE, style); 152 152 } 153 153 154 static void set_color( int fgcolor, int bgcolor, int flags)154 static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags) 155 155 { 156 156 async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); 157 157 } 158 158 159 static void set_rgb_color( int fgcolor, int bgcolor)159 static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor) 160 160 { 161 161 async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); … … 178 178 } 179 179 180 static int ccap_fb_to_con(i nt ccap_fb, int *ccap_con)180 static int ccap_fb_to_con(ipcarg_t ccap_fb, ipcarg_t *ccap_con) 181 181 { 182 182 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 190 199 return EOK; 191 200 } … … 226 235 * 227 236 */ 228 static void cell_mark_changed( size_t col, size_t row)237 static void cell_mark_changed(ipcarg_t col, ipcarg_t row) 229 238 { 230 239 if (fb_pending.cnt != 0) { … … 253 262 { 254 263 bool flush_cursor = false; 255 264 256 265 switch (ch) { 257 266 case '\n': … … 297 306 async_msg_1(fb_info.phone, FB_SCROLL, 1); 298 307 } 299 308 300 309 if (cons == active_console && flush_cursor) 301 310 curs_goto(cons->scr.position_x, cons->scr.position_y); … … 327 336 328 337 if (cons != kernel_console) { 329 size_t x;330 size_t y;331 int rc = 0;332 333 338 async_serialize_start(); 334 339 … … 344 349 set_attrs(&cons->scr.attrs); 345 350 curs_visibility(false); 351 352 ipcarg_t x; 353 ipcarg_t y; 354 int rc = 0; 355 346 356 if (interbuffer) { 347 357 for (y = 0; y < cons->scr.size_y; y++) { … … 390 400 /* Ignore parameters, the connection is already opened */ 391 401 while (true) { 392 393 402 ipc_call_t call; 394 403 ipc_callid_t callid = async_get_call(&call); … … 433 442 static void mouse_events(ipc_callid_t iid, ipc_call_t *icall) 434 443 { 435 int button, press;436 int dx, dy;437 int newcon;438 439 444 /* Ignore parameters, the connection is already opened */ 440 445 while (true) { 441 442 446 ipc_call_t call; 443 447 ipc_callid_t callid = async_get_call(&call); 444 448 445 449 int retval; 446 450 447 451 switch (IPC_GET_METHOD(call)) { 448 452 case IPC_M_PHONE_HUNGUP: … … 450 454 return; 451 455 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)); 456 458 if (newcon != -1) 457 459 change_console(&consoles[newcon]); … … 460 462 break; 461 463 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)); 465 466 retval = 0; 466 467 break; … … 520 521 console_event_t ev; 521 522 fibril_mutex_lock(&input_mutex); 523 522 524 recheck: 523 525 while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) { … … 536 538 goto recheck; 537 539 } 540 538 541 fibril_mutex_unlock(&input_mutex); 539 542 } … … 542 545 { 543 546 console_event_t ev; 544 547 545 548 fibril_mutex_lock(&input_mutex); 549 546 550 recheck: 547 551 if (keybuffer_pop(&cons->keybuffer, &ev)) { … … 551 555 goto recheck; 552 556 } 557 553 558 fibril_mutex_unlock(&input_mutex); 554 559 } … … 580 585 ipcarg_t arg2; 581 586 ipcarg_t arg3; 582 583 int cons_ccap; 587 584 588 int rc; 585 589 … … 622 626 if (cons == active_console) { 623 627 async_req_0_0(fb_info.phone, FB_FLUSH); 624 625 628 curs_goto(cons->scr.position_x, cons->scr.position_y); 626 629 } … … 650 653 break; 651 654 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); 653 656 if (rc != EOK) { 654 657 ipc_answer_0(callid, rc); 655 658 continue; 656 659 } 657 arg1 = cons_ccap;658 660 break; 659 661 case CONSOLE_SET_STYLE: … … 714 716 return false; 715 717 } 716 718 717 719 kbd_phone = fd_phone(input_fd); 718 720 if (kbd_phone < 0) { … … 720 722 return false; 721 723 } 722 724 723 725 /* NB: The callback connection is slotted for removal */ 724 726 ipcarg_t phonehash; … … 727 729 return false; 728 730 } 729 731 730 732 async_new_connection(phonehash, 0, NULL, keyboard_events); 731 733 732 734 /* Connect to mouse device */ 733 735 mouse_phone = -1; 734 736 int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY); 735 737 736 738 if (mouse_fd < 0) { 737 739 printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse"); 738 740 goto skip_mouse; 739 741 } 740 742 741 743 mouse_phone = fd_phone(mouse_fd); 742 744 if (mouse_phone < 0) { … … 744 746 goto skip_mouse; 745 747 } 746 748 747 749 if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { 748 750 printf(NAME ": Failed to create callback from mouse device\n"); … … 750 752 goto skip_mouse; 751 753 } 752 754 753 755 async_new_connection(phonehash, 0, NULL, mouse_events); 754 756 skip_mouse: 755 757 756 758 /* Connect to framebuffer driver */ 757 759 fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0); … … 760 762 return -1; 761 763 } 762 764 763 765 /* Register driver */ 764 766 int rc = devmap_driver_register(NAME, client_connection); … … 772 774 773 775 /* Synchronize, the gcons could put something in queue */ 774 ipcarg_t color_cap;775 776 async_req_0_0(fb_info.phone, FB_FLUSH); 776 777 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); 779 779 780 780 /* Set up shared memory buffer. */ -
uspace/srv/hid/console/gcons.c
rcaad59a r9f1362d4 54 54 #define STATUS_HEIGHT 48 55 55 56 #define MAIN_COLOR 0xffffff 56 #define COLOR_MAIN 0xffffff 57 #define COLOR_FOREGROUND 0x202020 58 #define COLOR_BACKGROUND 0xffffff 59 60 extern char _binary_gfx_helenos_ppm_start[0]; 61 extern int _binary_gfx_helenos_ppm_size; 62 extern char _binary_gfx_nameic_ppm_start[0]; 63 extern int _binary_gfx_nameic_ppm_size; 64 65 extern char _binary_gfx_anim_1_ppm_start[0]; 66 extern int _binary_gfx_anim_1_ppm_size; 67 extern char _binary_gfx_anim_2_ppm_start[0]; 68 extern int _binary_gfx_anim_2_ppm_size; 69 extern char _binary_gfx_anim_3_ppm_start[0]; 70 extern int _binary_gfx_anim_3_ppm_size; 71 extern char _binary_gfx_anim_4_ppm_start[0]; 72 extern int _binary_gfx_anim_4_ppm_size; 73 74 extern char _binary_gfx_cons_selected_ppm_start[0]; 75 extern int _binary_gfx_cons_selected_ppm_size; 76 extern char _binary_gfx_cons_idle_ppm_start[0]; 77 extern int _binary_gfx_cons_idle_ppm_size; 78 extern char _binary_gfx_cons_has_data_ppm_start[0]; 79 extern int _binary_gfx_cons_has_data_ppm_size; 80 extern char _binary_gfx_cons_kernel_ppm_start[0]; 81 extern int _binary_gfx_cons_kernel_ppm_size; 57 82 58 83 static bool use_gcons = false; … … 82 107 static size_t active_console = 0; 83 108 84 s ize_t mouse_x;85 s ize_t mouse_y;86 87 bool btn_pressed;88 s ize_t btn_x;89 s ize_t btn_y;109 static ipcarg_t mouse_x = 0; 110 static ipcarg_t mouse_y= 0; 111 112 static bool btn_pressed = false; 113 static ipcarg_t btn_x = 0; 114 static ipcarg_t btn_y = 0; 90 115 91 116 static void vp_switch(int vp) … … 95 120 96 121 /** Create view port */ 97 static int vp_create( size_t x, size_t y, size_t width, size_t height)122 static int vp_create(ipcarg_t x, ipcarg_t y, ipcarg_t width, ipcarg_t height) 98 123 { 99 124 return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y, … … 112 137 113 138 /** Transparent putchar */ 114 static void tran_putch(wchar_t ch, size_t col, size_t row)139 static void tran_putch(wchar_t ch, ipcarg_t col, ipcarg_t row) 115 140 { 116 141 async_msg_3(fbphone, FB_PUTCHAR, ch, col, row); … … 259 284 void gcons_mouse_move(ssize_t dx, ssize_t dy) 260 285 { 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 264 292 if (active_console != KERNEL_CONSOLE) 265 293 async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y); 266 294 } 267 295 268 static int gcons_find_conbut(i nt x, int y)269 { 270 i nt status_start = STATUS_START + (xres - 800) / 2;296 static int gcons_find_conbut(ipcarg_t x, ipcarg_t y) 297 { 298 ipcarg_t status_start = STATUS_START + (xres - 800) / 2; 271 299 272 300 if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT)) … … 278 306 if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT) 279 307 return -1; 308 280 309 if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE) 281 310 return -1; 282 311 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; 284 318 } 285 319 … … 287 321 * 288 322 * @param state New state (true - pressed, false - depressed) 323 * 289 324 */ 290 325 int gcons_mouse_btn(bool state) 291 326 { 292 int conbut; 327 /* Ignore mouse clicks if no buttons 328 are drawn at all */ 329 if (xres < 800) 330 return -1; 293 331 294 332 if (state) { 295 conbut = gcons_find_conbut(mouse_x, mouse_y);333 int conbut = gcons_find_conbut(mouse_x, mouse_y); 296 334 if (conbut != -1) { 297 335 btn_pressed = true; … … 307 345 btn_pressed = false; 308 346 309 conbut = gcons_find_conbut(mouse_x, mouse_y);347 int conbut = gcons_find_conbut(mouse_x, mouse_y); 310 348 if (conbut == gcons_find_conbut(btn_x, btn_y)) 311 349 return conbut; … … 313 351 return -1; 314 352 } 315 316 353 317 354 /** Draw a PPM pixmap to framebuffer … … 321 358 * @param x Coordinate of upper left corner 322 359 * @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 */ 362 static void draw_pixmap(char *logo, size_t size, ipcarg_t x, ipcarg_t y) 363 { 329 364 /* 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 | 331 366 MAP_ANONYMOUS, 0, 0); 332 367 if (shm == MAP_FAILED) … … 336 371 337 372 /* 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); 339 374 if (rc) 340 375 goto exit; … … 356 391 } 357 392 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 363 393 /** Redraws console graphics */ 364 394 void gcons_redraw_console(void) 365 395 { 366 int i;367 368 396 if (!use_gcons) 369 397 return; 370 398 371 399 vp_switch(0); 372 set_rgb_color( MAIN_COLOR, MAIN_COLOR);400 set_rgb_color(COLOR_MAIN, COLOR_MAIN); 373 401 clear(); 374 402 draw_pixmap(_binary_gfx_helenos_ppm_start, … … 377 405 (size_t) &_binary_gfx_nameic_ppm_size, 5, 17); 378 406 407 unsigned int i; 379 408 for (i = 0; i < CONSOLE_COUNT; i++) 380 409 redraw_state(i); … … 393 422 static int make_pixmap(char *data, size_t size) 394 423 { 395 char *shm;396 int rc;397 int pxid = -1;398 399 424 /* 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 | 401 426 MAP_ANONYMOUS, 0, 0); 402 427 if (shm == MAP_FAILED) … … 405 430 memcpy(shm, data, size); 406 431 432 int pxid = -1; 433 407 434 /* 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); 409 436 if (rc) 410 437 goto exit; … … 432 459 } 433 460 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 443 461 static void make_anim(void) 444 462 { 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]); 446 465 if (an < 0) 447 466 return; … … 467 486 animation = an; 468 487 } 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;478 488 479 489 /** Initialize nice graphical console environment */ … … 500 510 501 511 /* Create status buttons */ 502 size_t status_start = STATUS_START + (xres - 800) / 2;512 ipcarg_t status_start = STATUS_START + (xres - 800) / 2; 503 513 size_t i; 504 514 for (i = 0; i < CONSOLE_COUNT; i++) { … … 511 521 512 522 vp_switch(cstatus_vp[i]); 513 set_rgb_color( 0x202020, 0xffffff);523 set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND); 514 524 } 515 525 -
uspace/srv/hid/console/gcons.h
rcaad59a r9f1362d4 38 38 #include <sys/types.h> 39 39 40 void gcons_init(int phone);40 void gcons_init(int); 41 41 42 42 void gcons_redraw_console(void); 43 void gcons_change_console(size_t index);44 void gcons_notify_char(size_t index);43 void gcons_change_console(size_t); 44 void gcons_notify_char(size_t); 45 45 void gcons_in_kernel(void); 46 46 47 void gcons_notify_connect(size_t index);48 void gcons_notify_disconnect(size_t index);47 void gcons_notify_connect(size_t); 48 void gcons_notify_disconnect(size_t); 49 49 50 void gcons_mouse_move(ssize_t dx, ssize_t dy);50 void gcons_mouse_move(ssize_t, ssize_t); 51 51 int gcons_mouse_btn(bool state); 52 52 -
uspace/srv/hid/console/keybuffer.h
rcaad59a r9f1362d4 47 47 typedef struct { 48 48 console_event_t fifo[KEYBUFFER_SIZE]; 49 unsigned longhead;50 unsigned longtail;51 unsigned longitems;49 size_t head; 50 size_t tail; 51 size_t items; 52 52 } keybuffer_t; 53 53 -
uspace/srv/hid/console/screenbuffer.c
rcaad59a r9f1362d4 67 67 * 68 68 */ 69 screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y) 69 screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, ipcarg_t size_x, 70 ipcarg_t size_y) 70 71 { 71 72 scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y); … … 109 110 * 110 111 */ 111 void screenbuffer_clear_line(screenbuffer_t *scr, size_t line)112 void screenbuffer_clear_line(screenbuffer_t *scr, ipcarg_t line) 112 113 { 113 size_t x;114 ipcarg_t x; 114 115 115 116 for (x = 0; x < scr->size_x; x++) { … … 140 141 * 141 142 */ 142 void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y)143 void screenbuffer_goto(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y) 143 144 { 144 145 scr->position_x = x % scr->size_x; … … 166 167 * 167 168 */ 168 void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color, uint8_t bg_color, uint8_t flags) 169 void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color, 170 uint8_t bg_color, uint8_t flags) 169 171 { 170 172 scr->attrs.t = at_idx; … … 181 183 * 182 184 */ 183 void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color, uint32_t bg_color) 185 void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color, 186 uint32_t bg_color) 184 187 { 185 188 scr->attrs.t = at_rgb; -
uspace/srv/hid/console/screenbuffer.h
rcaad59a r9f1362d4 38 38 #include <stdint.h> 39 39 #include <sys/types.h> 40 #include <ipc/ipc.h> 40 41 #include <bool.h> 41 42 42 #define DEFAULT_FOREGROUND 0x0 43 #define DEFAULT_FOREGROUND 0x000000 /**< default console foreground color */ 43 44 #define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */ 44 45 … … 82 83 keyfield_t *buffer; /**< Screen content - characters and 83 84 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 */ 86 87 87 88 /** 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; 90 91 91 92 attrs_t attrs; /**< Current attributes. */ … … 107 108 * 108 109 */ 109 static inline keyfield_t *get_field_at(screenbuffer_t *scr, size_t x, size_t y)110 static inline keyfield_t *get_field_at(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y) 110 111 { 111 112 return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; … … 140 141 } 141 142 143 extern void screenbuffer_putchar(screenbuffer_t *, wchar_t); 144 extern screenbuffer_t *screenbuffer_init(screenbuffer_t *, ipcarg_t, ipcarg_t); 142 145 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); 146 extern void screenbuffer_clear(screenbuffer_t *); 147 extern void screenbuffer_clear_line(screenbuffer_t *, ipcarg_t); 148 extern void screenbuffer_copy_buffer(screenbuffer_t *, keyfield_t *); 149 extern void screenbuffer_goto(screenbuffer_t *, ipcarg_t, ipcarg_t); 150 extern void screenbuffer_set_style(screenbuffer_t *, uint8_t); 151 extern void screenbuffer_set_color(screenbuffer_t *, uint8_t, uint8_t, uint8_t); 152 extern void screenbuffer_set_rgb_color(screenbuffer_t *, uint32_t, uint32_t); 155 153 156 154 #endif -
uspace/srv/hid/fb/ega.c
rcaad59a r9f1362d4 28 28 29 29 /** @defgroup egafb EGA framebuffer 30 * @brief 30 * @brief HelenOS EGA framebuffer. 31 31 * @ingroup fbs 32 32 * @{ 33 */ 33 */ 34 34 /** @file 35 35 */ … … 58 58 #include "main.h" 59 59 60 #define MAX_SAVED_SCREENS 256 60 #define MAX_SAVED_SCREENS 256 61 61 62 typedef struct saved_screen { 62 63 short *data; … … 65 66 saved_screen saved_screens[MAX_SAVED_SCREENS]; 66 67 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 75 70 76 71 /* Allow only 1 connection */ 77 72 static int client_connected = 0; 78 73 79 static unsigned int scr_width;80 static unsigned int scr_height;74 static sysarg_t scr_width; 75 static sysarg_t scr_height; 81 76 static uint8_t *scr_addr; 82 77 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); 78 static uint8_t style_normal = 0xf0; 79 static uint8_t style_inverted = 0x0f; 80 static uint8_t style; 81 82 static 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 96 static 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 107 static uint8_t rgb_to_ega_style(uint32_t fg, uint32_t bg) 108 { 109 return (fg > bg) ? style_inverted : style_normal; 110 } 111 112 static 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 127 static uint8_t ega_glyph(wchar_t ch) 128 { 129 if (ch >= 0 && ch < 128) 130 return ch; 131 132 return '?'; 133 } 87 134 88 135 static void clrscr(void) … … 96 143 } 97 144 98 static void cursor_goto(unsigned int col, unsigned int row) 99 { 100 int ega_cursor; 101 102 ega_cursor = col + scr_width * row; 145 static void cursor_goto(sysarg_t col, sysarg_t row) 146 { 147 sysarg_t cursor = col + scr_width * row; 103 148 104 149 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); 106 151 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); 108 153 } 109 154 110 155 static void cursor_disable(void) 111 156 { 112 uint8_t stat;113 114 157 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 116 161 pio_write_8(EGA_IO_BASE, 0xa); 117 162 pio_write_8(EGA_IO_BASE + 1, stat | (1 << 5)); … … 120 165 static void cursor_enable(void) 121 166 { 122 uint8_t stat;123 124 167 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 126 171 pio_write_8(EGA_IO_BASE, 0xa); 127 172 pio_write_8(EGA_IO_BASE + 1, stat & (~(1 << 5))); 128 173 } 129 174 130 static void scroll( int rows)131 { 132 unsignedi;133 175 static void scroll(ssize_t rows) 176 { 177 size_t i; 178 134 179 if (rows > 0) { 135 180 memmove(scr_addr, ((char *) scr_addr) + rows * scr_width * 2, … … 142 187 scr_width * scr_height * 2 + rows * scr_width * 2); 143 188 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 193 static void printchar(wchar_t c, sysarg_t col, sysarg_t row) 149 194 { 150 195 scr_addr[(row * scr_width + col) * 2] = ega_glyph(c); … … 158 203 * @param vport Viewport id 159 204 * @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 * 164 210 */ 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; 211 static 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; 169 216 keyfield_t *field; 170 217 uint8_t *dp; 171 218 172 219 for (j = 0; j < h; j++) { 173 220 for (i = 0; i < w; i++) { 174 221 field = &data[j * w + i]; 175 222 dp = &scr_addr[2 * ((y + j) * scr_width + (x + i))]; 176 223 177 224 dp[0] = ega_glyph(field->character); 178 225 dp[1] = attr_to_ega_style(&field->attrs); … … 183 230 static int save_screen(void) 184 231 { 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) 190 238 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))) 192 241 return ENOMEM; 242 193 243 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 247 static int print_screen(ipcarg_t i) 248 { 249 if ((i >= MAX_SAVED_SCREENS) || (saved_screens[i].data)) 201 250 memcpy(scr_addr, saved_screens[i].data, 2 * scr_width * 202 251 scr_height); 203 252 else 204 253 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; 263 256 } 264 257 265 258 static void ega_client_connection(ipc_callid_t iid, ipc_call_t *icall) 266 259 { 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; 274 261 keyfield_t *interbuf = NULL; 275 size_t intersize = 0;276 int i;277 262 278 263 if (client_connected) { … … 280 265 return; 281 266 } 267 268 /* Accept connection */ 282 269 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)) { 288 296 case IPC_M_PHONE_HUNGUP: 289 297 client_connected = 0; 290 298 ipc_answer_0(callid, EOK); 291 return; /* Exit thread */ 299 300 /* Exit thread */ 301 return; 292 302 case IPC_M_SHARE_OUT: 293 303 /* We accept one area for data interchange */ … … 299 309 continue; 300 310 } 311 301 312 retval = EINVAL; 302 313 break; 303 314 case FB_DRAW_TEXT_DATA: 315 if (!interbuf) { 316 retval = EINVAL; 317 break; 318 } 319 304 320 col = IPC_GET_ARG1(call); 305 321 row = IPC_GET_ARG2(call); 306 322 w = IPC_GET_ARG3(call); 307 323 h = IPC_GET_ARG4(call); 308 if (!interbuf) { 324 325 if ((col + w > scr_width) || (row + h > scr_height)) { 309 326 retval = EINVAL; 310 327 break; 311 328 } 312 if (col + w > scr_width || row + h > scr_height) { 313 retval = EINVAL; 314 break; 315 } 329 316 330 draw_text_data(interbuf, col, row, w, h); 317 331 retval = 0; … … 331 345 col = IPC_GET_ARG2(call); 332 346 row = IPC_GET_ARG3(call); 333 if (col >= scr_width || row >= scr_height) { 347 348 if ((col >= scr_width) || (row >= scr_height)) { 334 349 retval = EINVAL; 335 350 break; 336 351 } 352 337 353 printchar(c, col, row); 338 354 retval = 0; 339 355 break; 340 341 356 case FB_CURSOR_GOTO: 357 col = IPC_GET_ARG1(call); 342 358 row = IPC_GET_ARG2(call); 343 if (row >= scr_height || col >= scr_width) { 359 360 if ((row >= scr_height) || (col >= scr_width)) { 344 361 retval = EINVAL; 345 362 break; 346 363 } 364 347 365 cursor_goto(col, row); 348 349 366 retval = 0; 367 break; 350 368 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); 357 384 retval = 0; 358 385 break; … … 362 389 else 363 390 cursor_disable(); 391 364 392 retval = 0; 365 393 break; … … 372 400 bg_color = IPC_GET_ARG2(call); 373 401 attr = IPC_GET_ARG3(call); 402 374 403 style = color_to_ega_style(fg_color, bg_color, attr); 375 404 retval = 0; … … 378 407 fg_rgb = IPC_GET_ARG1(call); 379 408 bg_rgb = IPC_GET_ARG2(call); 409 380 410 style = rgb_to_ega_style(fg_rgb, bg_rgb); 381 411 retval = 0; 382 412 break; 383 413 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); 386 416 break; 387 417 case FB_VP2PIXMAP: … … 389 419 break; 390 420 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) { 393 424 retval = EINVAL; 394 425 break; 395 426 } 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 400 433 retval = 0; 401 434 break; … … 413 446 int ega_init(void) 414 447 { 415 void *ega_ph_addr;416 size_t sz;417 418 448 sysarg_t paddr; 419 449 if (sysinfo_get_value("fb.address.physical", &paddr) != EOK) 420 450 return -1; 421 451 422 sysarg_t width; 423 if (sysinfo_get_value("fb.width", &width) != EOK) 452 if (sysinfo_get_value("fb.width", &scr_width) != EOK) 424 453 return -1; 425 454 426 sysarg_t height; 427 if (sysinfo_get_value("fb.width", &height) != EOK) 455 if (sysinfo_get_value("fb.height", &scr_height) != EOK) 428 456 return -1; 429 457 … … 432 460 blinking = false; 433 461 434 ega_ph_addr = (void *) paddr; 435 scr_width = width; 436 scr_height = height; 462 void *ega_ph_addr = (void *) paddr; 437 463 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; 443 469 444 470 iospace_enable(task_get_id(), (void *) EGA_IO_BASE, 2); 445 471 446 s z = scr_width * scr_height * 2;472 size_t sz = scr_width * scr_height * 2; 447 473 scr_addr = as_get_mappable_page(sz); 448 474 … … 450 476 PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0) 451 477 return -1; 452 478 453 479 async_set_client_connection(ega_client_connection); 454 480 455 481 return 0; 456 482 } 457 458 483 459 484 /** -
uspace/srv/hid/fb/fb.c
rcaad59a r9f1362d4 72 72 #define DEFAULT_FGCOLOR 0x000000 73 73 74 #define GLYPH_UNAVAIL 75 76 #define MAX_ANIM_LEN 77 #define MAX_ANIMATIONS 78 #define MAX_PIXMAPS 79 #define MAX_VIEWPORTS 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 */ 80 80 81 81 /** Function to render a pixel from a RGB value. */ … … 956 956 bb_cell_t *bbp; 957 957 attrs_t *a; 958 attr_rgb_t rgb;959 958 960 959 for (j = 0; j < h; j++) { … … 966 965 967 966 a = &data[j * w + i].attrs; 967 968 attr_rgb_t rgb; 969 rgb.fg_color = 0; 970 rgb.bg_color = 0; 968 971 rgb_from_attr(&rgb, a); 969 972 … … 1511 1514 rgb->bg_color = color_table[COLOR_WHITE]; 1512 1515 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; 1513 1524 default: 1514 1525 return EINVAL; 1515 1526 } 1516 1527 1517 1528 return EOK; 1518 1529 }
Note:
See TracChangeset
for help on using the changeset viewer.