Subversion Repositories HelenOS-historic

Rev

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

Rev 1534 Rev 1547
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 <align.h>
29
#include <align.h>
30
#include <async.h>
30
#include <async.h>
31
#include <ipc/ipc.h>
31
#include <ipc/ipc.h>
32
#include <errno.h>
32
#include <errno.h>
33
#include <stdio.h>
33
#include <stdio.h>
34
#include <ddi.h>
34
#include <ddi.h>
35
#include <sysinfo.h>
35
#include <sysinfo.h>
36
#include <as.h>
36
#include <as.h>
37
#include <ipc/fb.h>
37
#include <ipc/fb.h>
38
#include <ipc/ipc.h>
38
#include <ipc/ipc.h>
39
#include <ipc/ns.h>
39
#include <ipc/ns.h>
40
#include <ipc/services.h>
40
#include <ipc/services.h>
41
 
41
 
42
#include "ega.h"
42
#include "ega.h"
43
#include "../console/screenbuffer.h"
43
#include "../console/screenbuffer.h"
44
#include "main.h"
44
#include "main.h"
45
 
45
 
46
/* Allow only 1 connection */
46
/* Allow only 1 connection */
47
static int client_connected = 0;
47
static int client_connected = 0;
48
 
48
 
49
static unsigned int scr_width;
49
static unsigned int scr_width;
50
static unsigned int scr_height;
50
static unsigned int scr_height;
51
static char *scr_addr;
51
static char *scr_addr;
52
 
52
 
53
static unsigned int style = 0x0f;
53
static unsigned int style = 0x0f;
54
 
54
 
55
static void clrscr(void)
55
static void clrscr(void)
56
{
56
{
57
    int i;
57
    int i;
58
   
58
   
59
    for (i=0; i < scr_width*scr_height; i++) {
59
    for (i=0; i < scr_width*scr_height; i++) {
60
        scr_addr[i*2] = ' ';
60
        scr_addr[i*2] = ' ';
61
        scr_addr[i*2+1] = style;
61
        scr_addr[i*2+1] = style;
62
    }
62
    }
63
}
63
}
64
 
64
 
65
static void printchar(char c, unsigned int row, unsigned int col)
65
static void printchar(char c, unsigned int row, unsigned int col)
66
{
66
{
67
    scr_addr[(row*scr_width + col)*2] = c;
67
    scr_addr[(row*scr_width + col)*2] = c;
68
    scr_addr[(row*scr_width + col)*2+1] = style;
68
    scr_addr[(row*scr_width + col)*2+1] = style;
69
}
69
}
70
 
70
 
71
static void draw_text_data(keyfield_t *data)
71
static void draw_text_data(keyfield_t *data)
72
{
72
{
73
    int i;
73
    int i;
74
 
74
 
75
    for (i=0; i < scr_width*scr_height; i++) {
75
    for (i=0; i < scr_width*scr_height; i++) {
76
        scr_addr[i*2] = data[i].character;
76
        scr_addr[i*2] = data[i].character;
77
        if (data[i].style.fg_color > data[i].style.bg_color)
77
        if (data[i].style.fg_color > data[i].style.bg_color)
78
            scr_addr[i*2+1] = 0x0f;
78
            scr_addr[i*2+1] = 0x0f;
79
        else
79
        else
80
            scr_addr[i*2+1] = 0xf0;
80
            scr_addr[i*2+1] = 0xf0;
81
    }
81
    }
82
}
82
}
83
 
83
 
84
static void ega_client_connection(ipc_callid_t iid, ipc_call_t *icall)
84
static void ega_client_connection(ipc_callid_t iid, ipc_call_t *icall)
85
{
85
{
86
    int retval;
86
    int retval;
87
    ipc_callid_t callid;
87
    ipc_callid_t callid;
88
    ipc_call_t call;
88
    ipc_call_t call;
89
    char c;
89
    char c;
90
    unsigned int row, col;
90
    unsigned int row, col;
91
    int bgcolor,fgcolor;
91
    int bgcolor,fgcolor;
92
    keyfield_t *interbuf = NULL;
92
    keyfield_t *interbuf = NULL;
93
    size_t intersize = 0;
93
    size_t intersize = 0;
94
 
94
 
95
    if (client_connected) {
95
    if (client_connected) {
96
        ipc_answer_fast(iid, ELIMIT, 0,0);
96
        ipc_answer_fast(iid, ELIMIT, 0,0);
97
        return;
97
        return;
98
    }
98
    }
99
    client_connected = 1;
99
    client_connected = 1;
100
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
100
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
101
 
101
 
102
    while (1) {
102
    while (1) {
103
        callid = async_get_call(&call);
103
        callid = async_get_call(&call);
104
        switch (IPC_GET_METHOD(call)) {
104
        switch (IPC_GET_METHOD(call)) {
105
        case IPC_M_PHONE_HUNGUP:
105
        case IPC_M_PHONE_HUNGUP:
106
            client_connected = 0;
106
            client_connected = 0;
107
            ipc_answer_fast(callid,0,0,0);
107
            ipc_answer_fast(callid,0,0,0);
108
            return; /* Exit thread */
108
            return; /* Exit thread */
109
        case IPC_M_AS_AREA_SEND:
109
        case IPC_M_AS_AREA_SEND:
110
            /* We accept one area for data interchange */
110
            /* We accept one area for data interchange */
111
            intersize = IPC_GET_ARG2(call);
111
            intersize = IPC_GET_ARG2(call);
112
            if (intersize >= scr_width*scr_height*sizeof(*interbuf)) {
112
            if (intersize >= scr_width*scr_height*sizeof(*interbuf)) {
113
                receive_comm_area(callid,&call,(void **)&interbuf, scr_width*scr_height*sizeof(*interbuf));
113
                receive_comm_area(callid,&call,(void **)&interbuf);
114
                continue;
114
                continue;
115
            }
115
            }
116
            retval = EINVAL;
116
            retval = EINVAL;
117
            break;
117
            break;
118
        case FB_DRAW_TEXT_DATA:
118
        case FB_DRAW_TEXT_DATA:
119
            if (!interbuf) {
119
            if (!interbuf) {
120
                retval = EINVAL;
120
                retval = EINVAL;
121
                break;
121
                break;
122
            }
122
            }
123
            draw_text_data(interbuf);
123
            draw_text_data(interbuf);
124
            retval = 0;
124
            retval = 0;
125
            break;
125
            break;
126
        case FB_GET_CSIZE:
126
        case FB_GET_CSIZE:
127
            ipc_answer_fast(callid, 0, scr_height, scr_width);
127
            ipc_answer_fast(callid, 0, scr_height, scr_width);
128
            continue;
128
            continue;
129
        case FB_CLEAR:
129
        case FB_CLEAR:
130
            clrscr();
130
            clrscr();
131
            retval = 0;
131
            retval = 0;
132
            break;
132
            break;
133
        case FB_PUTCHAR:
133
        case FB_PUTCHAR:
134
            c = IPC_GET_ARG1(call);
134
            c = IPC_GET_ARG1(call);
135
            row = IPC_GET_ARG2(call);
135
            row = IPC_GET_ARG2(call);
136
            col = IPC_GET_ARG3(call);
136
            col = IPC_GET_ARG3(call);
137
            if (col >= scr_width || row >= scr_height) {
137
            if (col >= scr_width || row >= scr_height) {
138
                retval = EINVAL;
138
                retval = EINVAL;
139
                break;
139
                break;
140
            }
140
            }
141
            printchar(c,row,col);
141
            printchar(c,row,col);
142
            retval = 0;
142
            retval = 0;
143
            break;
143
            break;
144
        case FB_SET_STYLE:
144
        case FB_SET_STYLE:
145
            fgcolor = IPC_GET_ARG1(call);
145
            fgcolor = IPC_GET_ARG1(call);
146
            bgcolor = IPC_GET_ARG2(call);
146
            bgcolor = IPC_GET_ARG2(call);
147
            if (fgcolor > bgcolor)
147
            if (fgcolor > bgcolor)
148
                style = 0x0f;
148
                style = 0x0f;
149
            else
149
            else
150
                style = 0xf0;
150
                style = 0xf0;
151
        default:
151
        default:
152
            retval = ENOENT;
152
            retval = ENOENT;
153
        }
153
        }
154
        ipc_answer_fast(callid,retval,0,0);
154
        ipc_answer_fast(callid,retval,0,0);
155
    }
155
    }
156
}
156
}
157
 
157
 
158
int ega_init(void)
158
int ega_init(void)
159
{
159
{
160
    void *ega_ph_addr;
160
    void *ega_ph_addr;
161
    size_t sz;
161
    size_t sz;
162
 
162
 
163
 
163
 
164
    ega_ph_addr=(void *)sysinfo_value("fb.address.physical");
164
    ega_ph_addr=(void *)sysinfo_value("fb.address.physical");
165
    scr_width=sysinfo_value("fb.width");
165
    scr_width=sysinfo_value("fb.width");
166
    scr_height=sysinfo_value("fb.height");
166
    scr_height=sysinfo_value("fb.height");
167
 
167
 
168
    sz = scr_width*scr_height*2;
168
    sz = scr_width*scr_height*2;
169
    scr_addr = as_get_mappable_page(sz);
169
    scr_addr = as_get_mappable_page(sz);
170
 
170
 
171
    map_physmem(ega_ph_addr, scr_addr, ALIGN_UP(sz,PAGE_SIZE)>>PAGE_WIDTH,
171
    map_physmem(ega_ph_addr, scr_addr, ALIGN_UP(sz,PAGE_SIZE)>>PAGE_WIDTH,
172
            AS_AREA_READ | AS_AREA_WRITE);
172
            AS_AREA_READ | AS_AREA_WRITE);
173
 
173
 
174
    async_set_client_connection(ega_client_connection);
174
    async_set_client_connection(ega_client_connection);
175
 
175
 
176
    clrscr();
176
    clrscr();
177
 
177
 
178
    return 0;
178
    return 0;
179
}
179
}
180
 
180