Subversion Repositories HelenOS-historic

Rev

Rev 1490 | Rev 1498 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1490 Rev 1492
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>
-
 
35
#include <libc.h>
-
 
36
#include <stdio.h>
34
 
37
 
35
#include "sysio.h"
38
#include "sysio.h"
36
 
39
 
37
/* Allow only 1 connection */
40
/* Allow only 1 connection */
38
static int client_connected = 0;
41
static int client_connected = 0;
39
 
42
 
-
 
43
#define CLRSCR   "\033[2J"
-
 
44
 
40
static void sysput(char c)
45
static void sysput(char c)
41
{
46
{
42
    __SYSCALL3(SYS_IO, 1, (sysarg_t)&c, (sysarg_t) 1);
47
    __SYSCALL3(SYS_IO, 1, (sysarg_t)&c, (sysarg_t) 1);
43
}
48
}
44
 
49
 
-
 
50
static void sysputs(char *s)
-
 
51
{
-
 
52
    __SYSCALL3(SYS_IO, 1, (sysarg_t)s, strlen(s));
-
 
53
}
-
 
54
 
-
 
55
static void curs_goto(unsigned int row, unsigned int col)
-
 
56
{
-
 
57
    char control[20];
-
 
58
 
-
 
59
    if (row > 100 || col > 100)
-
 
60
        return;
-
 
61
 
-
 
62
    snprintf(control, 20, "\033[%d;%df",row, col);
-
 
63
    sysputs(control);
-
 
64
}
-
 
65
 
45
static void sysio_client_connection(ipc_callid_t iid, ipc_call_t *icall)
66
static void sysio_client_connection(ipc_callid_t iid, ipc_call_t *icall)
46
{
67
{
47
    int retval;
68
    int retval;
48
    ipc_callid_t callid;
69
    ipc_callid_t callid;
49
    ipc_call_t call;
70
    ipc_call_t call;
50
    char c;
71
    char c;
-
 
72
    int lastcol=0;
-
 
73
    int lastrow=0;
-
 
74
    int newcol,newrow;
51
 
75
 
52
    if (client_connected) {
76
    if (client_connected) {
53
        ipc_answer_fast(iid, ELIMIT, 0,0);
77
        ipc_answer_fast(iid, ELIMIT, 0,0);
54
        return;
78
        return;
55
    }
79
    }
56
    client_connected = 1;
80
    client_connected = 1;
57
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
81
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
58
    while (1) {
82
    while (1) {
59
        callid = async_get_call(&call);
83
        callid = async_get_call(&call);
60
        switch (IPC_GET_METHOD(call)) {
84
        switch (IPC_GET_METHOD(call)) {
61
        case IPC_M_PHONE_HUNGUP:
85
        case IPC_M_PHONE_HUNGUP:
62
            client_connected = 0;
86
            client_connected = 0;
63
            ipc_answer_fast(callid,0,0,0);
87
            ipc_answer_fast(callid,0,0,0);
64
            return; /* Exit thread */
88
            return; /* Exit thread */
65
        case FB_PUTCHAR:
89
        case FB_PUTCHAR:
66
            c = IPC_GET_ARG1(call);
90
            c = IPC_GET_ARG1(call);
-
 
91
            newrow = IPC_GET_ARG2(call);
-
 
92
            newcol = IPC_GET_ARG3(call);
-
 
93
            if (lastcol != newcol || lastrow!=newrow)
-
 
94
                curs_goto(newrow, newcol);
-
 
95
            lastcol = newcol + 1;
-
 
96
            lastrow = newrow;
67
            sysput(c);
97
            sysput(c);
68
            retval = 0;
98
            retval = 0;
69
            break;
99
            break;
-
 
100
        case FB_CURSOR_GOTO:
-
 
101
            newrow = IPC_GET_ARG1(call);
-
 
102
            newcol = IPC_GET_ARG2(call);
-
 
103
            curs_goto(newrow, newcol);
-
 
104
            break;
70
        case FB_GET_CSIZE:
105
        case FB_GET_CSIZE:
71
            ipc_answer_fast(callid, 0, 25, 80);
106
            ipc_answer_fast(callid, 0, 25, 80);
72
            continue;
107
            continue;
-
 
108
        case FB_CLEAR:
-
 
109
            sysputs(CLRSCR);
-
 
110
            retval = 0;
-
 
111
            break;
73
        default:
112
        default:
74
            retval = ENOENT;
113
            retval = ENOENT;
75
        }
114
        }
76
        ipc_answer_fast(callid,retval,0,0);
115
        ipc_answer_fast(callid,retval,0,0);
77
    }
116
    }
78
}
117
}
79
 
118
 
80
void sysio_init(void)
119
void sysio_init(void)
81
{
120
{
82
    async_set_client_connection(sysio_client_connection);
121
    async_set_client_connection(sysio_client_connection);
-
 
122
    sysputs(CLRSCR);
-
 
123
    curs_goto(0,0);
83
}
124
}
84
 
125