Subversion Repositories HelenOS-historic

Rev

Rev 1490 | Rev 1498 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1490 palkovsky 1
/*
2
 * Copyright (C) 2006 Ondrej Palkovsky
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
#include <async.h>
30
#include <ipc/fb.h>
31
#include <ipc/ipc.h>
32
#include <libc.h>
33
#include <errno.h>
1492 palkovsky 34
#include <string.h>
35
#include <libc.h>
36
#include <stdio.h>
1490 palkovsky 37
 
38
#include "sysio.h"
39
 
40
/* Allow only 1 connection */
41
static int client_connected = 0;
42
 
1492 palkovsky 43
#define CLRSCR   "\033[2J"
44
 
1490 palkovsky 45
static void sysput(char c)
46
{
47
    __SYSCALL3(SYS_IO, 1, (sysarg_t)&c, (sysarg_t) 1);
48
}
49
 
1492 palkovsky 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
 
1490 palkovsky 66
static void sysio_client_connection(ipc_callid_t iid, ipc_call_t *icall)
67
{
68
    int retval;
69
    ipc_callid_t callid;
70
    ipc_call_t call;
71
    char c;
1492 palkovsky 72
    int lastcol=0;
73
    int lastrow=0;
74
    int newcol,newrow;
1490 palkovsky 75
 
76
    if (client_connected) {
77
        ipc_answer_fast(iid, ELIMIT, 0,0);
78
        return;
79
    }
80
    client_connected = 1;
81
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
82
    while (1) {
83
        callid = async_get_call(&call);
84
        switch (IPC_GET_METHOD(call)) {
85
        case IPC_M_PHONE_HUNGUP:
86
            client_connected = 0;
87
            ipc_answer_fast(callid,0,0,0);
88
            return; /* Exit thread */
89
        case FB_PUTCHAR:
90
            c = IPC_GET_ARG1(call);
1492 palkovsky 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;
1490 palkovsky 97
            sysput(c);
98
            retval = 0;
99
            break;
1492 palkovsky 100
        case FB_CURSOR_GOTO:
101
            newrow = IPC_GET_ARG1(call);
102
            newcol = IPC_GET_ARG2(call);
103
            curs_goto(newrow, newcol);
104
            break;
1490 palkovsky 105
        case FB_GET_CSIZE:
106
            ipc_answer_fast(callid, 0, 25, 80);
107
            continue;
1492 palkovsky 108
        case FB_CLEAR:
109
            sysputs(CLRSCR);
110
            retval = 0;
111
            break;
1490 palkovsky 112
        default:
113
            retval = ENOENT;
114
        }
115
        ipc_answer_fast(callid,retval,0,0);
116
    }
117
}
118
 
119
void sysio_init(void)
120
{
121
    async_set_client_connection(sysio_client_connection);
1492 palkovsky 122
    sysputs(CLRSCR);
123
    curs_goto(0,0);
1490 palkovsky 124
}