Subversion Repositories HelenOS

Rev

Rev 1487 | Rev 1490 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1487 Rev 1489
Line 38... Line 38...
38
#include <unistd.h>
38
#include <unistd.h>
39
#include <async.h>
39
#include <async.h>
40
#include <libadt/fifo.h>
40
#include <libadt/fifo.h>
41
#include <screenbuffer.h>
41
#include <screenbuffer.h>
42
 
42
 
43
static void sysput(char c)
-
 
44
{
-
 
45
    __SYSCALL3(SYS_IO, 1, &c, 1);
-
 
46
}
-
 
47
 
-
 
48
//#define CONSOLE_COUNT VFB_CONNECTIONS
-
 
49
#define CONSOLE_COUNT 8
43
#define CONSOLE_COUNT 8
50
#define MAX_KEYREQUESTS_BUFFERED 32
44
#define MAX_KEYREQUESTS_BUFFERED 32
51
 
45
 
52
#define NAME "CONSOLE"
46
#define NAME "CONSOLE"
53
 
47
 
Line 100... Line 94...
100
{
94
{
101
    ipc_callid_t callid;
95
    ipc_callid_t callid;
102
    ipc_call_t call;
96
    ipc_call_t call;
103
    int retval;
97
    int retval;
104
    int i, j;
98
    int i, j;
105
    char c;
99
    char c,d;
-
 
100
    connection_t *conn;
106
 
101
 
107
    /* Ignore parameters, the connection is alread opened */
102
    /* Ignore parameters, the connection is alread opened */
108
    while (1) {
103
    while (1) {
109
        callid = async_get_call(&call);
104
        callid = async_get_call(&call);
110
        switch (IPC_GET_METHOD(call)) {
105
        switch (IPC_GET_METHOD(call)) {
Line 115... Line 110...
115
        case KBD_PUSHCHAR:
110
        case KBD_PUSHCHAR:
116
            /* got key from keyboard driver */
111
            /* got key from keyboard driver */
117
           
112
           
118
            retval = 0;
113
            retval = 0;
119
            c = IPC_GET_ARG1(call);
114
            c = IPC_GET_ARG1(call);
120
//          ipc_call_sync_2(connections[3].vfb_phone, FB_PUTCHAR, 0, c,NULL,NULL);
-
 
121
       
-
 
122
            /* switch to another virtual console */
115
            /* switch to another virtual console */
123
           
116
           
-
 
117
            conn = &connections[active_console];
124
            if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) {
118
            if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) {
125
                /*FIXME: draw another console content from buffer */
119
                /*FIXME: draw another console content from buffer */
126
 
120
 
127
                active_console = c - KBD_KEY_F1;
121
                active_console = c - KBD_KEY_F1;
-
 
122
                conn = &connections[active_console];
-
 
123
 
-
 
124
                ipc_call_async(fb_info.phone, FB_CURSOR_VISIBILITY, 0, NULL, NULL);
128
                ipc_call_async_2(fb_info.phone, FB_CLEAR, 0, 0, NULL, NULL);
125
                ipc_call_async_2(fb_info.phone, FB_CLEAR, 0, 0, NULL, NULL);
129
                ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, 'a', 0, 0,NULL,NULL, NULL);
126
                for (i = 0; i < conn->screenbuffer.size_x; i++)
130
               
-
 
131
                for (i = 0; i < connections[active_console].screenbuffer.size_x; i++)
127
                    for (j = 0; j < conn->screenbuffer.size_y; j++) {
132
                    for (j = 0; j < connections[active_console].screenbuffer.size_y; j++) {
128
                        d = get_field_at(&(conn->screenbuffer),i, j)->character;
-
 
129
                        if (d && d != ' ')
-
 
130
                            ipc_call_async_3(fb_info.phone, FB_PUTCHAR, d, j, i, NULL, NULL);
133
                   
131
                    }
134
                    ipc_call_async_3(fb_info.phone, FB_PUTCHAR, get_field_at(&(connections[active_console].screenbuffer),\
132
                ipc_call_async_2(fb_info.phone, FB_CURSOR_GOTO, conn->screenbuffer.position_y, conn->screenbuffer.position_x, NULL, NULL);
135
                                i, j)->character, j, i, NULL, NULL, NULL);
133
                ipc_call_async(fb_info.phone, FB_CURSOR_VISIBILITY, 1, NULL, NULL);
136
                }
-
 
137
 
134
 
138
                break;
135
                break;
139
            }
136
            }
140
           
137
           
141
            /* if client is awaiting key, send it */
138
            /* if client is awaiting key, send it */
142
            if (connections[active_console].keyrequest_counter > 0) {      
139
            if (conn->keyrequest_counter > 0) {    
143
                connections[active_console].keyrequest_counter--;
140
                conn->keyrequest_counter--;
144
                ipc_answer_fast(fifo_pop(connections[active_console].keyrequests), 0, c, 0);
141
                ipc_answer_fast(fifo_pop(conn->keyrequests), 0, c, 0);
145
                break;
142
                break;
146
            }
143
            }
147
           
144
           
148
            /*FIXME: else store key to its buffer */
145
            /*FIXME: else store key to its buffer */
149
            keybuffer_push(&(connections[active_console].keybuffer), c);
146
            keybuffer_push(&conn->keybuffer, c);
150
           
147
           
151
            /* Send it to first FB, DEBUG */
-
 
152
//          ipc_call_async_2(connections[0].vfb_phone, FB_PUTCHAR, 0, IPC_GET_ARG1(call),NULL,NULL);
-
 
153
//          ipc_call_sync_2(connections[4].vfb_phone, FB_PUTCHAR, 0, c,NULL,NULL);
-
 
154
 
-
 
155
            break;
148
            break;
156
        default:
149
        default:
157
            retval = ENOENT;
150
            retval = ENOENT;
158
        }      
151
        }      
159
        ipc_answer_fast(callid, retval, 0, 0);
152
        ipc_answer_fast(callid, retval, 0, 0);
Line 189... Line 182...
189
            return;
182
            return;
190
        case CONSOLE_PUTCHAR:
183
        case CONSOLE_PUTCHAR:
191
           
184
           
192
            /* Send message to fb */
185
            /* Send message to fb */
193
            if (consnum == active_console) {
186
            if (consnum == active_console) {
194
                ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, IPC_GET_ARG2(call), connections[consnum].screenbuffer.position_y, \
187
                ipc_call_async_3(fb_info.phone, FB_PUTCHAR, IPC_GET_ARG2(call), connections[consnum].screenbuffer.position_y, \
195
                        connections[consnum].screenbuffer.position_x, NULL, NULL, NULL);
188
                        connections[consnum].screenbuffer.position_x, NULL, NULL);
196
            }
189
            }
197
           
190
           
198
            screenbuffer_putchar(&(connections[consnum].screenbuffer), IPC_GET_ARG2(call));
191
            screenbuffer_putchar(&(connections[consnum].screenbuffer), IPC_GET_ARG2(call));
199
            break;
192
            break;
200
        case CONSOLE_CLEAR:
193
        case CONSOLE_CLEAR:
Line 223... Line 216...
223
                    ipc_answer_fast(callid, ELIMIT, 0, 0);
216
                    ipc_answer_fast(callid, ELIMIT, 0, 0);
224
                }
217
                }
225
                continue;
218
                continue;
226
            };
219
            };
227
            keybuffer_pop(&(connections[consnum].keybuffer), (char *)&arg1);
220
            keybuffer_pop(&(connections[consnum].keybuffer), (char *)&arg1);
228
//          ipc_call_sync_2(connections[6].vfb_phone, FB_PUTCHAR, 0, arg1,NULL,NULL);
-
 
229
           
221
           
230
            break;
222
            break;
231
        }
223
        }
232
        ipc_answer_fast(callid, 0, arg1, 0);
224
        ipc_answer_fast(callid, 0, arg1, 0);
233
    }
225
    }
Line 255... Line 247...
255
   
247
   
256
    while ((fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
248
    while ((fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
257
        usleep(10000);
249
        usleep(10000);
258
    }
250
    }
259
   
251
   
260
    ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, '1', 0, 0,NULL,NULL, NULL);
-
 
261
    ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols));
252
    ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols));
-
 
253
    ipc_call_sync(fb_info.phone, FB_CURSOR_VISIBILITY, 1, NULL);
262
   
254
   
263
    /* Init virtual consoles */
255
    /* Init virtual consoles */
264
    for (i = 0; i < CONSOLE_COUNT; i++) {
256
    for (i = 0; i < CONSOLE_COUNT; i++) {
265
        ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, '$', 2*i, 1,NULL,NULL, NULL);
-
 
266
        connections[i].used = 0;
257
        connections[i].used = 0;
267
        keybuffer_init(&(connections[i].keybuffer));
258
        keybuffer_init(&(connections[i].keybuffer));
268
        ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, '>', 2*i+1, 1,NULL,NULL, NULL);
-
 
269
       
259
       
270
        connections[i].keyrequests.head = connections[i].keyrequests.tail = 0;
260
        connections[i].keyrequests.head = connections[i].keyrequests.tail = 0;
271
        connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED;
261
        connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED;
272
        connections[i].keyrequest_counter = 0;
262
        connections[i].keyrequest_counter = 0;
273
       
263
       
274
        ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, '?', 2*i+1, 1,NULL,NULL, NULL);
-
 
275
        if (screenbuffer_init(&(connections[i].screenbuffer), fb_info.cols, fb_info.rows ) == NULL) {
264
        if (screenbuffer_init(&(connections[i].screenbuffer), fb_info.cols, fb_info.rows ) == NULL) {
276
            /*FIXME: handle error */
265
            /*FIXME: handle error */
277
            return -1;
266
            return -1;
278
        }
267
        }
279
    }
268
    }
280
   
269
   
281
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) {
270
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) {
282
        return -1;
271
        return -1;
283
    };
272
    };
284
   
273
   
285
    ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, 'M', 3, 3,NULL,NULL, NULL);
-
 
286
    async_manager();
274
    async_manager();
287
 
275
 
288
    return 0;  
276
    return 0;  
289
}
277
}