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