1 | /*
|
---|
2 | * Copyright (c) 2006 Josef Cejka
|
---|
3 | * Copyright (c) 2006 Jakub Vana
|
---|
4 | * Copyright (c) 2008 Jiri Svoboda
|
---|
5 | * All rights reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * - Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | * - Redistributions in binary form must reproduce the above copyright
|
---|
14 | * notice, this list of conditions and the following disclaimer in the
|
---|
15 | * documentation and/or other materials provided with the distribution.
|
---|
16 | * - The name of the author may not be used to endorse or promote products
|
---|
17 | * derived from this software without specific prior written permission.
|
---|
18 | *
|
---|
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /** @addtogroup libc
|
---|
32 | * @{
|
---|
33 | */
|
---|
34 | /** @file
|
---|
35 | */
|
---|
36 |
|
---|
37 | #include <async.h>
|
---|
38 | #include <io/stream.h>
|
---|
39 | #include <ipc/console.h>
|
---|
40 | #include <ipc/services.h>
|
---|
41 | #include <console.h>
|
---|
42 |
|
---|
43 | static int console_phone = -1;
|
---|
44 |
|
---|
45 | void console_open(void)
|
---|
46 | {
|
---|
47 | if (console_phone < 0) {
|
---|
48 | int phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0, 0);
|
---|
49 | if (phone >= 0)
|
---|
50 | console_phone = phone;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | void console_close(void)
|
---|
55 | {
|
---|
56 | if (console_phone >= 0) {
|
---|
57 | if (ipc_hangup(console_phone) == 0) {
|
---|
58 | console_phone = -1;
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | int console_phone_get(void)
|
---|
64 | {
|
---|
65 | if (console_phone < 0)
|
---|
66 | console_open();
|
---|
67 |
|
---|
68 | return console_phone;
|
---|
69 | }
|
---|
70 |
|
---|
71 | void console_wait(void)
|
---|
72 | {
|
---|
73 | while (console_phone < 0)
|
---|
74 | console_open();
|
---|
75 | }
|
---|
76 |
|
---|
77 | void console_clear(void)
|
---|
78 | {
|
---|
79 | int cons_phone = console_phone_get();
|
---|
80 | async_msg_0(cons_phone, CONSOLE_CLEAR);
|
---|
81 | }
|
---|
82 |
|
---|
83 | void console_goto(int row, int col)
|
---|
84 | {
|
---|
85 | int cons_phone = console_phone_get();
|
---|
86 | async_msg_2(cons_phone, CONSOLE_GOTO, row, col);
|
---|
87 | }
|
---|
88 |
|
---|
89 | void console_putchar(int c)
|
---|
90 | {
|
---|
91 | int cons_phone = console_phone_get();
|
---|
92 | async_msg_1(cons_phone, CONSOLE_PUTCHAR, c);
|
---|
93 | }
|
---|
94 |
|
---|
95 | void console_flush(void)
|
---|
96 | {
|
---|
97 | int cons_phone = console_phone_get();
|
---|
98 | async_msg_0(cons_phone, CONSOLE_FLUSH);
|
---|
99 | }
|
---|
100 |
|
---|
101 | int console_get_size(int *rows, int *cols)
|
---|
102 | {
|
---|
103 | int cons_phone = console_phone_get();
|
---|
104 | ipcarg_t r, c;
|
---|
105 | int rc;
|
---|
106 |
|
---|
107 | rc = async_req_0_2(cons_phone, CONSOLE_GETSIZE, &r, &c);
|
---|
108 |
|
---|
109 | *rows = (int) r;
|
---|
110 | *cols = (int) c;
|
---|
111 |
|
---|
112 | return rc;
|
---|
113 | }
|
---|
114 |
|
---|
115 | void console_set_style(int style)
|
---|
116 | {
|
---|
117 | int cons_phone = console_phone_get();
|
---|
118 | async_msg_1(cons_phone, CONSOLE_SET_STYLE, style);
|
---|
119 | }
|
---|
120 |
|
---|
121 | void console_set_color(int fg_color, int bg_color, int flags)
|
---|
122 | {
|
---|
123 | int cons_phone = console_phone_get();
|
---|
124 | async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
|
---|
125 | }
|
---|
126 |
|
---|
127 | void console_set_rgb_color(int fg_color, int bg_color)
|
---|
128 | {
|
---|
129 | int cons_phone = console_phone_get();
|
---|
130 | async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
|
---|
131 | }
|
---|
132 |
|
---|
133 | void console_cursor_visibility(int show)
|
---|
134 | {
|
---|
135 | int cons_phone = console_phone_get();
|
---|
136 | async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0);
|
---|
137 | }
|
---|
138 |
|
---|
139 | /** @}
|
---|
140 | */
|
---|