Rev 1542 | Rev 1631 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1542 | Rev 1630 | ||
---|---|---|---|
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 | #include <async.h> |
29 | #include <async.h> |
30 | #include <ipc/fb.h> |
30 | #include <ipc/fb.h> |
31 | #include <ipc/ipc.h> |
31 | #include <ipc/ipc.h> |
32 | #include <libc.h> |
32 | #include <libc.h> |
33 | #include <errno.h> |
33 | #include <errno.h> |
34 | #include <string.h> |
34 | #include <string.h> |
35 | #include <libc.h> |
35 | #include <libc.h> |
36 | #include <stdio.h> |
36 | #include <stdio.h> |
37 | 37 | ||
38 | #include "sysio.h" |
38 | #include "sysio.h" |
39 | 39 | ||
- | 40 | #define WIDTH 80 |
|
- | 41 | #define HEIGHT 25 |
|
- | 42 | ||
40 | /* Allow only 1 connection */ |
43 | /* Allow only 1 connection */ |
41 | static int client_connected = 0; |
44 | static int client_connected = 0; |
42 | 45 | ||
43 | static void sysput(char c) |
46 | static void sysput(char c) |
44 | { |
47 | { |
45 | __SYSCALL3(SYS_IO, 1, (sysarg_t)&c, (sysarg_t) 1); |
48 | __SYSCALL3(SYS_IO, 1, (sysarg_t)&c, (sysarg_t) 1); |
46 | } |
49 | } |
47 | 50 | ||
48 | static void sysputs(char *s) |
51 | static void sysputs(char *s) |
49 | { |
52 | { |
50 | while (*s) { |
53 | while (*s) { |
51 | sysput(*(s++)); |
54 | sysput(*(s++)); |
52 | } |
55 | } |
53 | // __SYSCALL3(SYS_IO, 1, (sysarg_t)s, strlen(s)); |
56 | // __SYSCALL3(SYS_IO, 1, (sysarg_t)s, strlen(s)); |
54 | } |
57 | } |
55 | 58 | ||
56 | /** Send clearscreen sequence to console */ |
59 | /** Send clearscreen sequence to console */ |
57 | static void clrscr(void) |
60 | static void clrscr(void) |
58 | { |
61 | { |
59 | sysputs("\033[2J"); |
62 | sysputs("\033[2J"); |
60 | } |
63 | } |
61 | 64 | ||
62 | /** Send ansi sequence to console to change cursor position */ |
65 | /** Send ansi sequence to console to change cursor position */ |
63 | static void curs_goto(unsigned int row, unsigned int col) |
66 | static void curs_goto(unsigned int row, unsigned int col) |
64 | { |
67 | { |
65 | char control[20]; |
68 | char control[20]; |
66 | 69 | ||
67 | if (row > 200 || col > 200) |
70 | if (row > 200 || col > 200) |
68 | return; |
71 | return; |
69 | 72 | ||
70 | snprintf(control, 20, "\033[%d;%df",row+1, col+1); |
73 | snprintf(control, 20, "\033[%d;%df",row+1, col+1); |
71 | sysputs(control); |
74 | sysputs(control); |
72 | } |
75 | } |
73 | 76 | ||
74 | static void set_style(int mode) |
77 | static void set_style(int mode) |
75 | { |
78 | { |
76 | char control[20]; |
79 | char control[20]; |
77 | 80 | ||
78 | snprintf(control, 20, "\033[%dm", mode); |
81 | snprintf(control, 20, "\033[%dm", mode); |
79 | sysputs(control); |
82 | sysputs(control); |
80 | } |
83 | } |
81 | 84 | ||
- | 85 | static void scroll(int i) |
|
- | 86 | { |
|
- | 87 | if (i > 0) { |
|
- | 88 | curs_goto(HEIGHT-1, 0); |
|
- | 89 | while (i--) |
|
- | 90 | sysputs("\033D"); |
|
- | 91 | } else if (i < 0) { |
|
- | 92 | curs_goto(0,0); |
|
- | 93 | while (i++) |
|
- | 94 | sysputs("\033M"); |
|
- | 95 | } |
|
- | 96 | } |
|
- | 97 | ||
82 | /** ANSI terminal emulation main thread */ |
98 | /** ANSI terminal emulation main thread */ |
83 | static void sysio_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
99 | static void sysio_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
84 | { |
100 | { |
85 | int retval; |
101 | int retval; |
86 | ipc_callid_t callid; |
102 | ipc_callid_t callid; |
87 | ipc_call_t call; |
103 | ipc_call_t call; |
88 | char c; |
104 | char c; |
89 | int lastcol=0; |
105 | int lastcol=0; |
90 | int lastrow=0; |
106 | int lastrow=0; |
91 | int newcol,newrow; |
107 | int newcol,newrow; |
92 | int fgcolor,bgcolor; |
108 | int fgcolor,bgcolor; |
- | 109 | int i; |
|
93 | 110 | ||
94 | if (client_connected) { |
111 | if (client_connected) { |
95 | ipc_answer_fast(iid, ELIMIT, 0,0); |
112 | ipc_answer_fast(iid, ELIMIT, 0,0); |
96 | return; |
113 | return; |
97 | } |
114 | } |
98 | client_connected = 1; |
115 | client_connected = 1; |
99 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
116 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
100 | while (1) { |
117 | while (1) { |
101 | callid = async_get_call(&call); |
118 | callid = async_get_call(&call); |
102 | switch (IPC_GET_METHOD(call)) { |
119 | switch (IPC_GET_METHOD(call)) { |
103 | case IPC_M_PHONE_HUNGUP: |
120 | case IPC_M_PHONE_HUNGUP: |
104 | client_connected = 0; |
121 | client_connected = 0; |
105 | ipc_answer_fast(callid,0,0,0); |
122 | ipc_answer_fast(callid,0,0,0); |
106 | return; /* Exit thread */ |
123 | return; /* Exit thread */ |
107 | case FB_PUTCHAR: |
124 | case FB_PUTCHAR: |
108 | c = IPC_GET_ARG1(call); |
125 | c = IPC_GET_ARG1(call); |
109 | newrow = IPC_GET_ARG2(call); |
126 | newrow = IPC_GET_ARG2(call); |
110 | newcol = IPC_GET_ARG3(call); |
127 | newcol = IPC_GET_ARG3(call); |
111 | if (lastcol != newcol || lastrow!=newrow) |
128 | if (lastcol != newcol || lastrow!=newrow) |
112 | curs_goto(newrow, newcol); |
129 | curs_goto(newrow, newcol); |
113 | lastcol = newcol + 1; |
130 | lastcol = newcol + 1; |
114 | lastrow = newrow; |
131 | lastrow = newrow; |
115 | sysput(c); |
132 | sysput(c); |
116 | retval = 0; |
133 | retval = 0; |
117 | break; |
134 | break; |
118 | case FB_CURSOR_GOTO: |
135 | case FB_CURSOR_GOTO: |
119 | newrow = IPC_GET_ARG1(call); |
136 | newrow = IPC_GET_ARG1(call); |
120 | newcol = IPC_GET_ARG2(call); |
137 | newcol = IPC_GET_ARG2(call); |
121 | curs_goto(newrow, newcol); |
138 | curs_goto(newrow, newcol); |
- | 139 | lastrow = newrow; |
|
- | 140 | lastcol = newcol; |
|
122 | break; |
141 | break; |
123 | case FB_GET_CSIZE: |
142 | case FB_GET_CSIZE: |
124 | ipc_answer_fast(callid, 0, 25, 80); |
143 | ipc_answer_fast(callid, 0, HEIGHT, WIDTH); |
125 | continue; |
144 | continue; |
126 | case FB_CLEAR: |
145 | case FB_CLEAR: |
127 | clrscr(); |
146 | clrscr(); |
128 | retval = 0; |
147 | retval = 0; |
129 | break; |
148 | break; |
130 | case FB_SET_STYLE: |
149 | case FB_SET_STYLE: |
131 | fgcolor = IPC_GET_ARG1(call); |
150 | fgcolor = IPC_GET_ARG1(call); |
132 | bgcolor = IPC_GET_ARG2(call); |
151 | bgcolor = IPC_GET_ARG2(call); |
- | 152 | if (bgcolor == 0xf0f0f0) |
|
- | 153 | set_style(0); |
|
133 | if (fgcolor > bgcolor) |
154 | else if (fgcolor > bgcolor) |
134 | set_style(0); |
155 | set_style(0); |
135 | else |
156 | else |
136 | set_style(7); |
157 | set_style(7); |
137 | retval = 0; |
158 | retval = 0; |
138 | break; |
159 | break; |
- | 160 | case FB_SCROLL: |
|
- | 161 | i = IPC_GET_ARG1(call); |
|
- | 162 | if (i > HEIGHT || i < -HEIGHT) { |
|
- | 163 | retval = EINVAL; |
|
- | 164 | break; |
|
- | 165 | } |
|
- | 166 | scroll(i); |
|
- | 167 | curs_goto(lastrow, lastcol); |
|
- | 168 | retval = 0; |
|
- | 169 | break; |
|
- | 170 | ||
139 | default: |
171 | default: |
140 | retval = ENOENT; |
172 | retval = ENOENT; |
141 | } |
173 | } |
142 | ipc_answer_fast(callid,retval,0,0); |
174 | ipc_answer_fast(callid,retval,0,0); |
143 | } |
175 | } |
144 | } |
176 | } |
145 | 177 | ||
146 | /** ANSI terminal emulation initialization */ |
178 | /** ANSI terminal emulation initialization */ |
147 | void sysio_init(void) |
179 | void sysio_init(void) |
148 | { |
180 | { |
149 | async_set_client_connection(sysio_client_connection); |
181 | async_set_client_connection(sysio_client_connection); |
150 | clrscr(); |
182 | clrscr(); |
151 | curs_goto(0,0); |
183 | curs_goto(0,0); |
- | 184 | /* Set scrolling region to 0-25 lines */ |
|
- | 185 | sysputs("\033[0;25r"); |
|
152 | } |
186 | } |
153 | 187 |