Rev 1535 | Rev 1630 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1535 | Rev 1542 | ||
---|---|---|---|
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 | /* Allow only 1 connection */ |
40 | /* Allow only 1 connection */ |
41 | static int client_connected = 0; |
41 | static int client_connected = 0; |
42 | 42 | ||
43 | static void sysput(char c) |
43 | static void sysput(char c) |
44 | { |
44 | { |
45 | __SYSCALL3(SYS_IO, 1, (sysarg_t)&c, (sysarg_t) 1); |
45 | __SYSCALL3(SYS_IO, 1, (sysarg_t)&c, (sysarg_t) 1); |
46 | } |
46 | } |
47 | 47 | ||
48 | static void sysputs(char *s) |
48 | static void sysputs(char *s) |
49 | { |
49 | { |
- | 50 | while (*s) { |
|
- | 51 | sysput(*(s++)); |
|
- | 52 | } |
|
50 | __SYSCALL3(SYS_IO, 1, (sysarg_t)s, strlen(s)); |
53 | // __SYSCALL3(SYS_IO, 1, (sysarg_t)s, strlen(s)); |
51 | } |
54 | } |
52 | 55 | ||
53 | /** Send clearscreen sequence to console */ |
56 | /** Send clearscreen sequence to console */ |
54 | static void clrscr(void) |
57 | static void clrscr(void) |
55 | { |
58 | { |
56 | sysputs("\033[2J"); |
59 | sysputs("\033[2J"); |
57 | } |
60 | } |
58 | 61 | ||
59 | /** Send ansi sequence to console to change cursor position */ |
62 | /** Send ansi sequence to console to change cursor position */ |
60 | static void curs_goto(unsigned int row, unsigned int col) |
63 | static void curs_goto(unsigned int row, unsigned int col) |
61 | { |
64 | { |
62 | char control[20]; |
65 | char control[20]; |
63 | 66 | ||
64 | if (row > 200 || col > 200) |
67 | if (row > 200 || col > 200) |
65 | return; |
68 | return; |
66 | 69 | ||
67 | snprintf(control, 20, "\033[%d;%df",row+1, col+1); |
70 | snprintf(control, 20, "\033[%d;%df",row+1, col+1); |
68 | sysputs(control); |
71 | sysputs(control); |
69 | } |
72 | } |
70 | 73 | ||
71 | static void set_style(int mode) |
74 | static void set_style(int mode) |
72 | { |
75 | { |
73 | char control[20]; |
76 | char control[20]; |
74 | 77 | ||
75 | snprintf(control, 20, "\033[%dm", mode); |
78 | snprintf(control, 20, "\033[%dm", mode); |
76 | sysputs(control); |
79 | sysputs(control); |
77 | } |
80 | } |
78 | 81 | ||
79 | /** ANSI terminal emulation main thread */ |
82 | /** ANSI terminal emulation main thread */ |
80 | static void sysio_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
83 | static void sysio_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
81 | { |
84 | { |
82 | int retval; |
85 | int retval; |
83 | ipc_callid_t callid; |
86 | ipc_callid_t callid; |
84 | ipc_call_t call; |
87 | ipc_call_t call; |
85 | char c; |
88 | char c; |
86 | int lastcol=0; |
89 | int lastcol=0; |
87 | int lastrow=0; |
90 | int lastrow=0; |
88 | int newcol,newrow; |
91 | int newcol,newrow; |
89 | int fgcolor,bgcolor; |
92 | int fgcolor,bgcolor; |
90 | 93 | ||
91 | if (client_connected) { |
94 | if (client_connected) { |
92 | ipc_answer_fast(iid, ELIMIT, 0,0); |
95 | ipc_answer_fast(iid, ELIMIT, 0,0); |
93 | return; |
96 | return; |
94 | } |
97 | } |
95 | client_connected = 1; |
98 | client_connected = 1; |
96 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
99 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
97 | while (1) { |
100 | while (1) { |
98 | callid = async_get_call(&call); |
101 | callid = async_get_call(&call); |
99 | switch (IPC_GET_METHOD(call)) { |
102 | switch (IPC_GET_METHOD(call)) { |
100 | case IPC_M_PHONE_HUNGUP: |
103 | case IPC_M_PHONE_HUNGUP: |
101 | client_connected = 0; |
104 | client_connected = 0; |
102 | ipc_answer_fast(callid,0,0,0); |
105 | ipc_answer_fast(callid,0,0,0); |
103 | return; /* Exit thread */ |
106 | return; /* Exit thread */ |
104 | case FB_PUTCHAR: |
107 | case FB_PUTCHAR: |
105 | c = IPC_GET_ARG1(call); |
108 | c = IPC_GET_ARG1(call); |
106 | newrow = IPC_GET_ARG2(call); |
109 | newrow = IPC_GET_ARG2(call); |
107 | newcol = IPC_GET_ARG3(call); |
110 | newcol = IPC_GET_ARG3(call); |
108 | if (lastcol != newcol || lastrow!=newrow) |
111 | if (lastcol != newcol || lastrow!=newrow) |
109 | curs_goto(newrow, newcol); |
112 | curs_goto(newrow, newcol); |
110 | lastcol = newcol + 1; |
113 | lastcol = newcol + 1; |
111 | lastrow = newrow; |
114 | lastrow = newrow; |
112 | sysput(c); |
115 | sysput(c); |
113 | retval = 0; |
116 | retval = 0; |
114 | break; |
117 | break; |
115 | case FB_CURSOR_GOTO: |
118 | case FB_CURSOR_GOTO: |
116 | newrow = IPC_GET_ARG1(call); |
119 | newrow = IPC_GET_ARG1(call); |
117 | newcol = IPC_GET_ARG2(call); |
120 | newcol = IPC_GET_ARG2(call); |
118 | curs_goto(newrow, newcol); |
121 | curs_goto(newrow, newcol); |
119 | break; |
122 | break; |
120 | case FB_GET_CSIZE: |
123 | case FB_GET_CSIZE: |
121 | ipc_answer_fast(callid, 0, 25, 80); |
124 | ipc_answer_fast(callid, 0, 25, 80); |
122 | continue; |
125 | continue; |
123 | case FB_CLEAR: |
126 | case FB_CLEAR: |
124 | clrscr(); |
127 | clrscr(); |
125 | retval = 0; |
128 | retval = 0; |
126 | break; |
129 | break; |
127 | case FB_SET_STYLE: |
130 | case FB_SET_STYLE: |
128 | fgcolor = IPC_GET_ARG1(call); |
131 | fgcolor = IPC_GET_ARG1(call); |
129 | bgcolor = IPC_GET_ARG2(call); |
132 | bgcolor = IPC_GET_ARG2(call); |
130 | if (fgcolor > bgcolor) |
133 | if (fgcolor > bgcolor) |
131 | set_style(0); |
134 | set_style(0); |
132 | else |
135 | else |
133 | set_style(7); |
136 | set_style(7); |
134 | retval = 0; |
137 | retval = 0; |
135 | break; |
138 | break; |
136 | default: |
139 | default: |
137 | retval = ENOENT; |
140 | retval = ENOENT; |
138 | } |
141 | } |
139 | ipc_answer_fast(callid,retval,0,0); |
142 | ipc_answer_fast(callid,retval,0,0); |
140 | } |
143 | } |
141 | } |
144 | } |
142 | 145 | ||
143 | /** ANSI terminal emulation initialization */ |
146 | /** ANSI terminal emulation initialization */ |
144 | void sysio_init(void) |
147 | void sysio_init(void) |
145 | { |
148 | { |
146 | async_set_client_connection(sysio_client_connection); |
149 | async_set_client_connection(sysio_client_connection); |
147 | clrscr(); |
150 | clrscr(); |
148 | curs_goto(0,0); |
151 | curs_goto(0,0); |
149 | } |
152 | } |
150 | 153 |