Rev 4160 | Rev 4168 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4160 | Rev 4164 | ||
---|---|---|---|
Line 36... | Line 36... | ||
36 | 36 | ||
37 | #include <async.h> |
37 | #include <async.h> |
38 | #include <io/stream.h> |
38 | #include <io/stream.h> |
39 | #include <ipc/console.h> |
39 | #include <ipc/console.h> |
40 | #include <ipc/services.h> |
40 | #include <ipc/services.h> |
- | 41 | #include <errno.h> |
|
- | 42 | #include <string.h> |
|
41 | #include <console.h> |
43 | #include <console.h> |
42 | 44 | ||
43 | static int console_phone = -1; |
45 | static int console_phone = -1; |
44 | 46 | ||
- | 47 | /** Size of cbuffer. */ |
|
- | 48 | #define CBUFFER_SIZE 256 |
|
- | 49 | ||
- | 50 | /** Buffer for writing characters to the console. */ |
|
- | 51 | static char cbuffer[CBUFFER_SIZE]; |
|
- | 52 | ||
- | 53 | /** Pointer to end of cbuffer. */ |
|
- | 54 | static char *cbuffer_end = cbuffer + CBUFFER_SIZE; |
|
- | 55 | ||
- | 56 | /** Pointer to first available field in cbuffer. */ |
|
- | 57 | static char *cbp = cbuffer; |
|
- | 58 | ||
- | 59 | static ssize_t cons_write(const char *buf, size_t nbyte); |
|
- | 60 | static void cons_putchar(int c); |
|
- | 61 | ||
- | 62 | static void cbuffer_flush(void); |
|
- | 63 | static void cbuffer_drain(void); |
|
- | 64 | static void cbuffer_putc(int c); |
|
- | 65 | ||
- | 66 | ||
45 | void console_open(bool blocking) |
67 | void console_open(bool blocking) |
46 | { |
68 | { |
47 | if (console_phone < 0) { |
69 | if (console_phone < 0) { |
48 | int phone; |
70 | int phone; |
49 | if (blocking) { |
71 | if (blocking) { |
Line 82... | Line 104... | ||
82 | } |
104 | } |
83 | 105 | ||
84 | void console_clear(void) |
106 | void console_clear(void) |
85 | { |
107 | { |
86 | int cons_phone = console_phone_get(true); |
108 | int cons_phone = console_phone_get(true); |
- | 109 | ||
- | 110 | cbuffer_drain(); |
|
87 | async_msg_0(cons_phone, CONSOLE_CLEAR); |
111 | async_msg_0(cons_phone, CONSOLE_CLEAR); |
88 | } |
112 | } |
89 | 113 | ||
90 | void console_goto(int row, int col) |
114 | void console_goto(int row, int col) |
91 | { |
115 | { |
92 | int cons_phone = console_phone_get(true); |
116 | int cons_phone = console_phone_get(true); |
- | 117 | ||
- | 118 | cbuffer_flush(); |
|
93 | async_msg_2(cons_phone, CONSOLE_GOTO, row, col); |
119 | async_msg_2(cons_phone, CONSOLE_GOTO, row, col); |
94 | } |
120 | } |
95 | 121 | ||
96 | void console_putchar(int c) |
122 | void console_putchar(int c) |
97 | { |
123 | { |
- | 124 | cbuffer_putc(c); |
|
- | 125 | } |
|
- | 126 | ||
- | 127 | /** Write all data from output buffer to the console. */ |
|
- | 128 | static void cbuffer_flush(void) |
|
- | 129 | { |
|
- | 130 | int rc; |
|
- | 131 | int len; |
|
- | 132 | ||
- | 133 | len = cbp - cbuffer; |
|
- | 134 | ||
- | 135 | while (len > 0) { |
|
- | 136 | rc = cons_write(cbuffer, cbp - cbuffer); |
|
- | 137 | if (rc < 0) |
|
- | 138 | return; |
|
- | 139 | ||
- | 140 | len -= rc; |
|
- | 141 | } |
|
- | 142 | ||
- | 143 | cbp = cbuffer; |
|
- | 144 | } |
|
- | 145 | ||
- | 146 | /** Drop all data in console output buffer. */ |
|
- | 147 | static void cbuffer_drain(void) |
|
- | 148 | { |
|
- | 149 | cbp = cbuffer; |
|
- | 150 | } |
|
- | 151 | ||
- | 152 | /** Write one character to the output buffer. */ |
|
- | 153 | static inline void cbuffer_putc(int c) |
|
- | 154 | { |
|
- | 155 | if (cbp == cbuffer_end) |
|
- | 156 | cbuffer_flush(); |
|
- | 157 | ||
- | 158 | *cbp++ = c; |
|
- | 159 | ||
- | 160 | if (c == '\n') |
|
- | 161 | cbuffer_flush(); |
|
- | 162 | } |
|
- | 163 | ||
- | 164 | /** Write one character to the console via IPC. */ |
|
- | 165 | static void cons_putchar(int c) |
|
- | 166 | { |
|
98 | int cons_phone = console_phone_get(true); |
167 | int cons_phone = console_phone_get(true); |
99 | async_msg_1(cons_phone, CONSOLE_PUTCHAR, c); |
168 | async_msg_1(cons_phone, CONSOLE_PUTCHAR, c); |
100 | } |
169 | } |
101 | 170 | ||
102 | void console_flush(void) |
171 | /** Write characters to the console via IPC. */ |
- | 172 | static ssize_t cons_write(const char *buf, size_t nbyte) |
|
103 | { |
173 | { |
104 | int cons_phone = console_phone_get(true); |
174 | int cons_phone = console_phone_get(true); |
- | 175 | ipcarg_t rc; |
|
- | 176 | ipc_call_t answer; |
|
- | 177 | aid_t req; |
|
- | 178 | ||
- | 179 | async_serialize_start(); |
|
- | 180 | ||
- | 181 | req = async_send_0(cons_phone, CONSOLE_WRITE, &answer); |
|
- | 182 | rc = ipc_data_write_start(cons_phone, (void *) buf, nbyte); |
|
- | 183 | ||
- | 184 | if (rc != EOK) { |
|
- | 185 | async_wait_for(req, NULL); |
|
- | 186 | async_serialize_end(); |
|
- | 187 | return (ssize_t) rc; |
|
- | 188 | } |
|
- | 189 | ||
- | 190 | async_wait_for(req, &rc); |
|
- | 191 | async_serialize_end(); |
|
- | 192 | ||
- | 193 | if (rc == EOK) |
|
- | 194 | return (ssize_t) IPC_GET_ARG1(answer); |
|
- | 195 | else |
|
- | 196 | return -1; |
|
- | 197 | } |
|
- | 198 | ||
- | 199 | /** Write characters to the console. */ |
|
- | 200 | ssize_t console_write(const char *buf, size_t nbyte) |
|
- | 201 | { |
|
- | 202 | size_t left; |
|
- | 203 | ||
- | 204 | left = nbyte; |
|
- | 205 | ||
- | 206 | while (left > 0) { |
|
- | 207 | cbuffer_putc(*buf++); |
|
- | 208 | --left; |
|
- | 209 | } |
|
- | 210 | ||
- | 211 | return nbyte; |
|
- | 212 | } |
|
- | 213 | ||
- | 214 | /** Write a NULL-terminated string to the console. */ |
|
- | 215 | void console_putstr(const char *s) |
|
- | 216 | { |
|
- | 217 | size_t len; |
|
- | 218 | ssize_t rc; |
|
- | 219 | ||
- | 220 | len = strlen(s); |
|
- | 221 | while (len > 0) { |
|
- | 222 | rc = console_write(s, len); |
|
- | 223 | if (rc < 0) |
|
- | 224 | return; /* Error */ |
|
- | 225 | s += rc; |
|
- | 226 | len -= rc; |
|
- | 227 | } |
|
- | 228 | } |
|
- | 229 | ||
- | 230 | /** Flush all output to the console. */ |
|
- | 231 | void console_flush(void) |
|
- | 232 | { |
|
- | 233 | int cons_phone = console_phone_get(false); |
|
- | 234 | ||
- | 235 | cbuffer_flush(); |
|
105 | async_msg_0(cons_phone, CONSOLE_FLUSH); |
236 | async_msg_0(cons_phone, CONSOLE_FLUSH); |
106 | } |
237 | } |
107 | 238 | ||
108 | int console_get_size(int *rows, int *cols) |
239 | int console_get_size(int *rows, int *cols) |
109 | { |
240 | { |
Line 120... | Line 251... | ||
120 | } |
251 | } |
121 | 252 | ||
122 | void console_set_style(int style) |
253 | void console_set_style(int style) |
123 | { |
254 | { |
124 | int cons_phone = console_phone_get(true); |
255 | int cons_phone = console_phone_get(true); |
- | 256 | ||
- | 257 | cbuffer_flush(); |
|
125 | async_msg_1(cons_phone, CONSOLE_SET_STYLE, style); |
258 | async_msg_1(cons_phone, CONSOLE_SET_STYLE, style); |
126 | } |
259 | } |
127 | 260 | ||
128 | void console_set_color(int fg_color, int bg_color, int flags) |
261 | void console_set_color(int fg_color, int bg_color, int flags) |
129 | { |
262 | { |
130 | int cons_phone = console_phone_get(true); |
263 | int cons_phone = console_phone_get(true); |
- | 264 | ||
- | 265 | cbuffer_flush(); |
|
131 | async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags); |
266 | async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags); |
132 | } |
267 | } |
133 | 268 | ||
134 | void console_set_rgb_color(int fg_color, int bg_color) |
269 | void console_set_rgb_color(int fg_color, int bg_color) |
135 | { |
270 | { |
136 | int cons_phone = console_phone_get(true); |
271 | int cons_phone = console_phone_get(true); |
- | 272 | ||
- | 273 | cbuffer_flush(); |
|
137 | async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color); |
274 | async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color); |
138 | } |
275 | } |
139 | 276 | ||
140 | void console_cursor_visibility(int show) |
277 | void console_cursor_visibility(int show) |
141 | { |
278 | { |
142 | int cons_phone = console_phone_get(true); |
279 | int cons_phone = console_phone_get(true); |
- | 280 | ||
- | 281 | cbuffer_flush(); |
|
143 | async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0); |
282 | async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0); |
144 | } |
283 | } |
145 | 284 | ||
146 | /** @} |
285 | /** @} |
147 | */ |
286 | */ |