Subversion Repositories HelenOS

Rev

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

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