Rev 3234 | Rev 3386 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3234 | Rev 3235 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * Copyright (c) 2008 Martin Decky |
3 | * Copyright (c) 2008 Martin Decky |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @defgroup msimfb MSIM text console |
30 | /** @defgroup msimfb MSIM text console |
31 | * @brief HelenOS MSIM text console. |
31 | * @brief HelenOS MSIM text console. |
32 | * @ingroup fbs |
32 | * @ingroup fbs |
33 | * @{ |
33 | * @{ |
34 | */ |
34 | */ |
35 | /** @file |
35 | /** @file |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <async.h> |
38 | #include <async.h> |
39 | #include <ipc/fb.h> |
39 | #include <ipc/fb.h> |
40 | #include <ipc/ipc.h> |
40 | #include <ipc/ipc.h> |
41 | #include <libc.h> |
41 | #include <libc.h> |
42 | #include <errno.h> |
42 | #include <errno.h> |
43 | #include <string.h> |
43 | #include <string.h> |
44 | #include <libc.h> |
44 | #include <libc.h> |
45 | #include <stdio.h> |
45 | #include <stdio.h> |
46 | #include <ipc/fb.h> |
46 | #include <ipc/fb.h> |
47 | #include <sysinfo.h> |
47 | #include <sysinfo.h> |
48 | #include <as.h> |
48 | #include <as.h> |
49 | #include <align.h> |
49 | #include <align.h> |
50 | #include <ddi.h> |
50 | #include <ddi.h> |
51 | 51 | ||
52 | #include "msim.h" |
52 | #include "msim.h" |
53 | 53 | ||
54 | #define WIDTH 80 |
54 | #define WIDTH 80 |
55 | #define HEIGHT 25 |
55 | #define HEIGHT 25 |
56 | 56 | ||
57 | #define MAX_CONTROL 20 |
57 | #define MAX_CONTROL 20 |
58 | 58 | ||
59 | /* Allow only 1 connection */ |
59 | /* Allow only 1 connection */ |
60 | static int client_connected = 0; |
60 | static int client_connected = 0; |
61 | 61 | ||
62 | static char *virt_addr; |
62 | static char *virt_addr; |
63 | 63 | ||
64 | static void msim_putc(const char c) |
64 | static void msim_putc(const char c) |
65 | { |
65 | { |
66 | *virt_addr = c; |
66 | *virt_addr = c; |
67 | } |
67 | } |
68 | 68 | ||
69 | static void msim_puts(char *str) |
69 | static void msim_puts(char *str) |
70 | { |
70 | { |
71 | while (*str) |
71 | while (*str) |
72 | *virt_addr = *(str++); |
72 | *virt_addr = *(str++); |
73 | } |
73 | } |
74 | 74 | ||
75 | static void msim_clrscr(void) |
75 | static void msim_clrscr(void) |
76 | { |
76 | { |
77 | msim_puts("\033[2J"); |
77 | msim_puts("\033[2J"); |
78 | } |
78 | } |
79 | 79 | ||
80 | static void msim_goto(const unsigned int row, const unsigned int col) |
80 | static void msim_goto(const unsigned int row, const unsigned int col) |
81 | { |
81 | { |
82 | if ((row > HEIGHT) || (col > WIDTH)) |
82 | if ((row > HEIGHT) || (col > WIDTH)) |
83 | return; |
83 | return; |
84 | 84 | ||
85 | char control[MAX_CONTROL]; |
85 | char control[MAX_CONTROL]; |
86 | snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1); |
86 | snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1); |
87 | msim_puts(control); |
87 | msim_puts(control); |
88 | } |
88 | } |
89 | 89 | ||
90 | static void msim_set_style(const unsigned int mode) |
90 | static void msim_set_style(const unsigned int mode) |
91 | { |
91 | { |
92 | char control[MAX_CONTROL]; |
92 | char control[MAX_CONTROL]; |
93 | snprintf(control, MAX_CONTROL, "\033[%um", mode); |
93 | snprintf(control, MAX_CONTROL, "\033[%um", mode); |
94 | msim_puts(control); |
94 | msim_puts(control); |
95 | } |
95 | } |
96 | 96 | ||
97 | static void msim_cursor_disable(void) |
97 | static void msim_cursor_disable(void) |
98 | { |
98 | { |
99 | msim_puts("\033[?25l"); |
99 | msim_puts("\033[?25l"); |
100 | } |
100 | } |
101 | 101 | ||
102 | static void msim_cursor_enable(void) |
102 | static void msim_cursor_enable(void) |
103 | { |
103 | { |
104 | msim_puts("\033[?25h"); |
104 | msim_puts("\033[?25h"); |
105 | } |
105 | } |
106 | 106 | ||
107 | static void msim_scroll(int i) |
107 | static void msim_scroll(int i) |
108 | { |
108 | { |
109 | if (i > 0) { |
109 | if (i > 0) { |
110 | msim_goto(HEIGHT - 1, 0); |
110 | msim_goto(HEIGHT - 1, 0); |
111 | while (i--) |
111 | while (i--) |
112 | msim_puts("\033D"); |
112 | msim_puts("\033D"); |
113 | } else if (i < 0) { |
113 | } else if (i < 0) { |
114 | msim_goto(0, 0); |
114 | msim_goto(0, 0); |
115 | while (i++) |
115 | while (i++) |
116 | msim_puts("\033M"); |
116 | msim_puts("\033M"); |
117 | } |
117 | } |
118 | } |
118 | } |
119 | 119 | ||
120 | static void msim_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
120 | static void msim_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
121 | { |
121 | { |
122 | int retval; |
122 | int retval; |
123 | ipc_callid_t callid; |
123 | ipc_callid_t callid; |
124 | ipc_call_t call; |
124 | ipc_call_t call; |
125 | char c; |
125 | char c; |
126 | int lastcol = 0; |
126 | int lastcol = 0; |
127 | int lastrow = 0; |
127 | int lastrow = 0; |
128 | int newcol; |
128 | int newcol; |
129 | int newrow; |
129 | int newrow; |
130 | int fgcolor; |
130 | int fgcolor; |
131 | int bgcolor; |
131 | int bgcolor; |
132 | int i; |
132 | int i; |
133 | 133 | ||
134 | if (client_connected) { |
134 | if (client_connected) { |
135 | ipc_answer_0(iid, ELIMIT); |
135 | ipc_answer_0(iid, ELIMIT); |
136 | return; |
136 | return; |
137 | } |
137 | } |
138 | 138 | ||
139 | client_connected = 1; |
139 | client_connected = 1; |
140 | ipc_answer_0(iid, EOK); |
140 | ipc_answer_0(iid, EOK); |
- | 141 | ||
- | 142 | /* Clear the terminal, set scrolling region |
|
- | 143 | to 0 - 25 lines */ |
|
- | 144 | msim_clrscr(); |
|
- | 145 | msim_goto(0, 0); |
|
- | 146 | msim_puts("\033[0;25r"); |
|
141 | 147 | ||
142 | while (true) { |
148 | while (true) { |
143 | callid = async_get_call(&call); |
149 | callid = async_get_call(&call); |
144 | switch (IPC_GET_METHOD(call)) { |
150 | switch (IPC_GET_METHOD(call)) { |
145 | case IPC_M_PHONE_HUNGUP: |
151 | case IPC_M_PHONE_HUNGUP: |
146 | client_connected = 0; |
152 | client_connected = 0; |
147 | ipc_answer_0(callid, EOK); |
153 | ipc_answer_0(callid, EOK); |
148 | return; |
154 | return; |
149 | case FB_PUTCHAR: |
155 | case FB_PUTCHAR: |
150 | c = IPC_GET_ARG1(call); |
156 | c = IPC_GET_ARG1(call); |
151 | newrow = IPC_GET_ARG2(call); |
157 | newrow = IPC_GET_ARG2(call); |
152 | newcol = IPC_GET_ARG3(call); |
158 | newcol = IPC_GET_ARG3(call); |
153 | if ((lastcol != newcol) || (lastrow != newrow)) |
159 | if ((lastcol != newcol) || (lastrow != newrow)) |
154 | msim_goto(newrow, newcol); |
160 | msim_goto(newrow, newcol); |
155 | lastcol = newcol + 1; |
161 | lastcol = newcol + 1; |
156 | lastrow = newrow; |
162 | lastrow = newrow; |
157 | msim_putc(c); |
163 | msim_putc(c); |
158 | retval = 0; |
164 | retval = 0; |
159 | break; |
165 | break; |
160 | case FB_CURSOR_GOTO: |
166 | case FB_CURSOR_GOTO: |
161 | newrow = IPC_GET_ARG1(call); |
167 | newrow = IPC_GET_ARG1(call); |
162 | newcol = IPC_GET_ARG2(call); |
168 | newcol = IPC_GET_ARG2(call); |
163 | msim_goto(newrow, newcol); |
169 | msim_goto(newrow, newcol); |
164 | lastrow = newrow; |
170 | lastrow = newrow; |
165 | lastcol = newcol; |
171 | lastcol = newcol; |
166 | retval = 0; |
172 | retval = 0; |
167 | break; |
173 | break; |
168 | case FB_GET_CSIZE: |
174 | case FB_GET_CSIZE: |
169 | ipc_answer_2(callid, EOK, HEIGHT, WIDTH); |
175 | ipc_answer_2(callid, EOK, HEIGHT, WIDTH); |
170 | continue; |
176 | continue; |
171 | case FB_CLEAR: |
177 | case FB_CLEAR: |
172 | msim_clrscr(); |
178 | msim_clrscr(); |
173 | retval = 0; |
179 | retval = 0; |
174 | break; |
180 | break; |
175 | case FB_SET_STYLE: |
181 | case FB_SET_STYLE: |
176 | fgcolor = IPC_GET_ARG1(call); |
182 | fgcolor = IPC_GET_ARG1(call); |
177 | bgcolor = IPC_GET_ARG2(call); |
183 | bgcolor = IPC_GET_ARG2(call); |
178 | if (fgcolor < bgcolor) |
184 | if (fgcolor < bgcolor) |
179 | msim_set_style(0); |
185 | msim_set_style(0); |
180 | else |
186 | else |
181 | msim_set_style(7); |
187 | msim_set_style(7); |
182 | retval = 0; |
188 | retval = 0; |
183 | break; |
189 | break; |
184 | case FB_SCROLL: |
190 | case FB_SCROLL: |
185 | i = IPC_GET_ARG1(call); |
191 | i = IPC_GET_ARG1(call); |
186 | if ((i > HEIGHT) || (i < -HEIGHT)) { |
192 | if ((i > HEIGHT) || (i < -HEIGHT)) { |
187 | retval = EINVAL; |
193 | retval = EINVAL; |
188 | break; |
194 | break; |
189 | } |
195 | } |
190 | msim_scroll(i); |
196 | msim_scroll(i); |
191 | msim_goto(lastrow, lastcol); |
197 | msim_goto(lastrow, lastcol); |
192 | retval = 0; |
198 | retval = 0; |
193 | break; |
199 | break; |
194 | case FB_CURSOR_VISIBILITY: |
200 | case FB_CURSOR_VISIBILITY: |
195 | if(IPC_GET_ARG1(call)) |
201 | if(IPC_GET_ARG1(call)) |
196 | msim_cursor_enable(); |
202 | msim_cursor_enable(); |
197 | else |
203 | else |
198 | msim_cursor_disable(); |
204 | msim_cursor_disable(); |
199 | retval = 0; |
205 | retval = 0; |
200 | break; |
206 | break; |
201 | default: |
207 | default: |
202 | retval = ENOENT; |
208 | retval = ENOENT; |
203 | } |
209 | } |
204 | ipc_answer_0(callid, retval); |
210 | ipc_answer_0(callid, retval); |
205 | } |
211 | } |
206 | } |
212 | } |
207 | 213 | ||
208 | int msim_init(void) |
214 | int msim_init(void) |
209 | { |
215 | { |
210 | void *phys_addr = (void *) sysinfo_value("fb.address.physical"); |
216 | void *phys_addr = (void *) sysinfo_value("fb.address.physical"); |
211 | virt_addr = (char *) as_get_mappable_page(1); |
217 | virt_addr = (char *) as_get_mappable_page(1); |
212 | 218 | ||
213 | physmem_map(phys_addr, virt_addr, 1, AS_AREA_READ | AS_AREA_WRITE); |
219 | physmem_map(phys_addr, virt_addr, 1, AS_AREA_READ | AS_AREA_WRITE); |
214 | 220 | ||
215 | async_set_client_connection(msim_client_connection); |
221 | async_set_client_connection(msim_client_connection); |
216 | - | ||
217 | /* Clear the terminal, set scrolling region |
- | |
218 | to 0 - 25 lines */ |
- | |
219 | msim_clrscr(); |
- | |
220 | msim_goto(0, 0); |
- | |
221 | msim_puts("\033[0;25r"); |
- | |
222 | - | ||
223 | return 0; |
222 | return 0; |
224 | } |
223 | } |
225 | 224 | ||
226 | /** |
225 | /** |
227 | * @} |
226 | * @} |
228 | */ |
227 | */ |
229 | 228 |