Rev 1631 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1631 | Rev 1649 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
- | 29 | /** @defgroup sysio SysIO |
|
- | 30 | * @brief HelenOS framebuffer emulation via kernel. |
|
- | 31 | * @ingroup fbs |
|
- | 32 | * @{ |
|
- | 33 | */ |
|
- | 34 | /** @file |
|
- | 35 | */ |
|
- | 36 | ||
29 | #include <async.h> |
37 | #include <async.h> |
30 | #include <ipc/fb.h> |
38 | #include <ipc/fb.h> |
31 | #include <ipc/ipc.h> |
39 | #include <ipc/ipc.h> |
32 | #include <libc.h> |
40 | #include <libc.h> |
33 | #include <errno.h> |
41 | #include <errno.h> |
34 | #include <string.h> |
42 | #include <string.h> |
35 | #include <libc.h> |
43 | #include <libc.h> |
36 | #include <stdio.h> |
44 | #include <stdio.h> |
37 | 45 | ||
38 | #include "sysio.h" |
46 | #include "sysio.h" |
39 | 47 | ||
40 | #define WIDTH 80 |
48 | #define WIDTH 80 |
41 | #define HEIGHT 25 |
49 | #define HEIGHT 25 |
42 | 50 | ||
43 | /* Allow only 1 connection */ |
51 | /* Allow only 1 connection */ |
44 | static int client_connected = 0; |
52 | static int client_connected = 0; |
45 | 53 | ||
46 | static void sysput(char c) |
54 | static void sysput(char c) |
47 | { |
55 | { |
48 | __SYSCALL3(SYS_IO, 1, (sysarg_t)&c, (sysarg_t) 1); |
56 | __SYSCALL3(SYS_IO, 1, (sysarg_t)&c, (sysarg_t) 1); |
49 | } |
57 | } |
50 | 58 | ||
51 | static void sysputs(char *s) |
59 | static void sysputs(char *s) |
52 | { |
60 | { |
53 | while (*s) { |
61 | while (*s) { |
54 | sysput(*(s++)); |
62 | sysput(*(s++)); |
55 | } |
63 | } |
56 | // __SYSCALL3(SYS_IO, 1, (sysarg_t)s, strlen(s)); |
64 | // __SYSCALL3(SYS_IO, 1, (sysarg_t)s, strlen(s)); |
57 | } |
65 | } |
58 | 66 | ||
59 | /** Send clearscreen sequence to console */ |
67 | /** Send clearscreen sequence to console */ |
60 | static void clrscr(void) |
68 | static void clrscr(void) |
61 | { |
69 | { |
62 | sysputs("\033[2J"); |
70 | sysputs("\033[2J"); |
63 | } |
71 | } |
64 | 72 | ||
65 | /** Send ansi sequence to console to change cursor position */ |
73 | /** Send ansi sequence to console to change cursor position */ |
66 | static void curs_goto(unsigned int row, unsigned int col) |
74 | static void curs_goto(unsigned int row, unsigned int col) |
67 | { |
75 | { |
68 | char control[20]; |
76 | char control[20]; |
69 | 77 | ||
70 | if (row > 200 || col > 200) |
78 | if (row > 200 || col > 200) |
71 | return; |
79 | return; |
72 | 80 | ||
73 | snprintf(control, 20, "\033[%d;%df",row+1, col+1); |
81 | snprintf(control, 20, "\033[%d;%df",row+1, col+1); |
74 | sysputs(control); |
82 | sysputs(control); |
75 | } |
83 | } |
76 | 84 | ||
77 | static void set_style(int mode) |
85 | static void set_style(int mode) |
78 | { |
86 | { |
79 | char control[20]; |
87 | char control[20]; |
80 | 88 | ||
81 | snprintf(control, 20, "\033[%dm", mode); |
89 | snprintf(control, 20, "\033[%dm", mode); |
82 | sysputs(control); |
90 | sysputs(control); |
83 | } |
91 | } |
84 | 92 | ||
85 | static void scroll(int i) |
93 | static void scroll(int i) |
86 | { |
94 | { |
87 | if (i > 0) { |
95 | if (i > 0) { |
88 | curs_goto(HEIGHT-1, 0); |
96 | curs_goto(HEIGHT-1, 0); |
89 | while (i--) |
97 | while (i--) |
90 | sysputs("\033D"); |
98 | sysputs("\033D"); |
91 | } else if (i < 0) { |
99 | } else if (i < 0) { |
92 | curs_goto(0,0); |
100 | curs_goto(0,0); |
93 | while (i++) |
101 | while (i++) |
94 | sysputs("\033M"); |
102 | sysputs("\033M"); |
95 | } |
103 | } |
96 | } |
104 | } |
97 | 105 | ||
98 | /** ANSI terminal emulation main thread */ |
106 | /** ANSI terminal emulation main thread */ |
99 | static void sysio_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
107 | static void sysio_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
100 | { |
108 | { |
101 | int retval; |
109 | int retval; |
102 | ipc_callid_t callid; |
110 | ipc_callid_t callid; |
103 | ipc_call_t call; |
111 | ipc_call_t call; |
104 | char c; |
112 | char c; |
105 | int lastcol=0; |
113 | int lastcol=0; |
106 | int lastrow=0; |
114 | int lastrow=0; |
107 | int newcol,newrow; |
115 | int newcol,newrow; |
108 | int fgcolor,bgcolor; |
116 | int fgcolor,bgcolor; |
109 | int i; |
117 | int i; |
110 | 118 | ||
111 | if (client_connected) { |
119 | if (client_connected) { |
112 | ipc_answer_fast(iid, ELIMIT, 0,0); |
120 | ipc_answer_fast(iid, ELIMIT, 0,0); |
113 | return; |
121 | return; |
114 | } |
122 | } |
115 | client_connected = 1; |
123 | client_connected = 1; |
116 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
124 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
117 | while (1) { |
125 | while (1) { |
118 | callid = async_get_call(&call); |
126 | callid = async_get_call(&call); |
119 | switch (IPC_GET_METHOD(call)) { |
127 | switch (IPC_GET_METHOD(call)) { |
120 | case IPC_M_PHONE_HUNGUP: |
128 | case IPC_M_PHONE_HUNGUP: |
121 | client_connected = 0; |
129 | client_connected = 0; |
122 | ipc_answer_fast(callid,0,0,0); |
130 | ipc_answer_fast(callid,0,0,0); |
123 | return; /* Exit thread */ |
131 | return; /* Exit thread */ |
124 | case FB_PUTCHAR: |
132 | case FB_PUTCHAR: |
125 | c = IPC_GET_ARG1(call); |
133 | c = IPC_GET_ARG1(call); |
126 | newrow = IPC_GET_ARG2(call); |
134 | newrow = IPC_GET_ARG2(call); |
127 | newcol = IPC_GET_ARG3(call); |
135 | newcol = IPC_GET_ARG3(call); |
128 | if (lastcol != newcol || lastrow!=newrow) |
136 | if (lastcol != newcol || lastrow!=newrow) |
129 | curs_goto(newrow, newcol); |
137 | curs_goto(newrow, newcol); |
130 | lastcol = newcol + 1; |
138 | lastcol = newcol + 1; |
131 | lastrow = newrow; |
139 | lastrow = newrow; |
132 | sysput(c); |
140 | sysput(c); |
133 | retval = 0; |
141 | retval = 0; |
134 | break; |
142 | break; |
135 | case FB_CURSOR_GOTO: |
143 | case FB_CURSOR_GOTO: |
136 | newrow = IPC_GET_ARG1(call); |
144 | newrow = IPC_GET_ARG1(call); |
137 | newcol = IPC_GET_ARG2(call); |
145 | newcol = IPC_GET_ARG2(call); |
138 | curs_goto(newrow, newcol); |
146 | curs_goto(newrow, newcol); |
139 | lastrow = newrow; |
147 | lastrow = newrow; |
140 | lastcol = newcol; |
148 | lastcol = newcol; |
141 | break; |
149 | break; |
142 | case FB_GET_CSIZE: |
150 | case FB_GET_CSIZE: |
143 | ipc_answer_fast(callid, 0, HEIGHT, WIDTH); |
151 | ipc_answer_fast(callid, 0, HEIGHT, WIDTH); |
144 | continue; |
152 | continue; |
145 | case FB_CLEAR: |
153 | case FB_CLEAR: |
146 | clrscr(); |
154 | clrscr(); |
147 | retval = 0; |
155 | retval = 0; |
148 | break; |
156 | break; |
149 | case FB_SET_STYLE: |
157 | case FB_SET_STYLE: |
150 | fgcolor = IPC_GET_ARG1(call); |
158 | fgcolor = IPC_GET_ARG1(call); |
151 | bgcolor = IPC_GET_ARG2(call); |
159 | bgcolor = IPC_GET_ARG2(call); |
152 | if (fgcolor < bgcolor) |
160 | if (fgcolor < bgcolor) |
153 | set_style(0); |
161 | set_style(0); |
154 | else |
162 | else |
155 | set_style(7); |
163 | set_style(7); |
156 | retval = 0; |
164 | retval = 0; |
157 | break; |
165 | break; |
158 | case FB_SCROLL: |
166 | case FB_SCROLL: |
159 | i = IPC_GET_ARG1(call); |
167 | i = IPC_GET_ARG1(call); |
160 | if (i > HEIGHT || i < -HEIGHT) { |
168 | if (i > HEIGHT || i < -HEIGHT) { |
161 | retval = EINVAL; |
169 | retval = EINVAL; |
162 | break; |
170 | break; |
163 | } |
171 | } |
164 | scroll(i); |
172 | scroll(i); |
165 | curs_goto(lastrow, lastcol); |
173 | curs_goto(lastrow, lastcol); |
166 | retval = 0; |
174 | retval = 0; |
167 | break; |
175 | break; |
168 | 176 | ||
169 | default: |
177 | default: |
170 | retval = ENOENT; |
178 | retval = ENOENT; |
171 | } |
179 | } |
172 | ipc_answer_fast(callid,retval,0,0); |
180 | ipc_answer_fast(callid,retval,0,0); |
173 | } |
181 | } |
174 | } |
182 | } |
175 | 183 | ||
176 | /** ANSI terminal emulation initialization */ |
184 | /** ANSI terminal emulation initialization */ |
177 | void sysio_init(void) |
185 | void sysio_init(void) |
178 | { |
186 | { |
179 | async_set_client_connection(sysio_client_connection); |
187 | async_set_client_connection(sysio_client_connection); |
180 | clrscr(); |
188 | clrscr(); |
181 | curs_goto(0,0); |
189 | curs_goto(0,0); |
182 | /* Set scrolling region to 0-25 lines */ |
190 | /* Set scrolling region to 0-25 lines */ |
183 | sysputs("\033[0;25r"); |
191 | sysputs("\033[0;25r"); |
184 | } |
192 | } |
- | 193 | ||
- | 194 | /** |
|
- | 195 | * @} |
|
- | 196 | */ |
|
- | 197 | ||
185 | 198 |