Subversion Repositories HelenOS-historic

Rev

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

Rev 1528 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 <ipc/fb.h>
29
#include <ipc/fb.h>
30
#include <ipc/ipc.h>
30
#include <ipc/ipc.h>
31
#include <async.h>
31
#include <async.h>
32
#include <stdio.h>
32
#include <stdio.h>
-
 
33
#include <sys/mman.h>
-
 
34
#include <string.h>
33
 
35
 
34
#include "console.h"
36
#include "console.h"
35
#include "gcons.h"
37
#include "gcons.h"
36
 
38
 
37
#define CONSOLE_TOP      50
39
#define CONSOLE_TOP      65
38
#define CONSOLE_MARGIN   10
40
#define CONSOLE_MARGIN   10
39
 
41
 
-
 
42
#define STATUS_START    120
40
#define STATUS_SPACE    20
43
#define STATUS_SPACE    5
41
#define STATUS_WIDTH    40
44
#define STATUS_WIDTH    40
42
#define STATUS_HEIGHT   30
45
#define STATUS_HEIGHT   30
43
 
46
 
44
#define MAIN_COLOR      0x118811
47
#define MAIN_COLOR      0xffffff
45
 
48
 
46
static int use_gcons = 0;
49
static int use_gcons = 0;
47
static ipcarg_t xres,yres;
50
static ipcarg_t xres,yres;
48
 
51
 
49
static int console_vp;
52
static int console_vp;
50
static int cstatus_vp[CONSOLE_COUNT];
53
static int cstatus_vp[CONSOLE_COUNT];
51
static int console_has_input[CONSOLE_COUNT];
54
static int console_has_input[CONSOLE_COUNT];
52
static int cstat_row, cstat_col; /* Size of cstatus buttons */
55
static int cstat_row, cstat_col; /* Size of cstatus buttons */
53
 
56
 
54
static int fbphone;
57
static int fbphone;
55
 
58
 
56
enum butstate {
59
enum butstate {
57
    CONS_ACTIVE = 0,
60
    CONS_ACTIVE = 0,
58
    CONS_IDLE,
61
    CONS_IDLE,
59
    CONS_HAS_INPUT,
62
    CONS_HAS_INPUT,
60
    CONS_DISCONNECTED
63
    CONS_DISCONNECTED
61
};
64
};
62
 
65
 
63
static struct {
66
static struct {
64
    int fgcolor;
67
    int fgcolor;
65
    int bgcolor;
68
    int bgcolor;
66
} stat_colors[] = {
69
} stat_colors[] = {
67
    {0xd0d0d0, 0x808080},
70
    {0xd0d0d0, 0x808080},
68
    {0xd0d0d0, 0x0},
71
    {0xd0d0d0, 0x0},
69
    {0xd0d0d0, 0xa04040},
72
    {0xd0d0d0, 0xa04040},
70
    {0xd0d0d0, 0x0}
73
    {0xd0d0d0, 0x0}
71
};
74
};
72
 
75
 
73
static int active_console = 0;
76
static int active_console = 0;
74
 
77
 
75
static void vp_switch(int vp)
78
static void vp_switch(int vp)
76
{
79
{
77
    nsend_call(fbphone,FB_VIEWPORT_SWITCH, vp);
80
    nsend_call(fbphone,FB_VIEWPORT_SWITCH, vp);
78
}
81
}
79
 
82
 
80
/** Create view port */
83
/** Create view port */
81
static int vp_create(unsigned int x, unsigned int y,
84
static int vp_create(unsigned int x, unsigned int y,
82
             unsigned int width, unsigned int height)
85
             unsigned int width, unsigned int height)
83
{
86
{
84
    /* Init function, use ipc_call_sync */
87
    /* Init function, use ipc_call_sync */
85
    return ipc_call_sync_2(fbphone, FB_VIEWPORT_CREATE,
88
    return ipc_call_sync_2(fbphone, FB_VIEWPORT_CREATE,
86
                   (x << 16) | y, (width << 16) | height,
89
                   (x << 16) | y, (width << 16) | height,
87
                   NULL, NULL);
90
                   NULL, NULL);
88
}
91
}
89
 
92
 
90
static void clear(void)
93
static void clear(void)
91
{
94
{
92
    nsend_call(fbphone, FB_CLEAR, 0);
95
    nsend_call(fbphone, FB_CLEAR, 0);
93
   
96
   
94
}
97
}
95
 
98
 
96
static void set_style(int fgcolor, int bgcolor)
99
static void set_style(int fgcolor, int bgcolor)
97
{
100
{
98
    nsend_call_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor);
101
    nsend_call_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor);
99
}
102
}
100
 
103
 
101
static void putch(char c, int row, int col)
104
static void putch(char c, int row, int col)
102
{
105
{
103
    nsend_call_3(fbphone, FB_PUTCHAR, c, row, col);
106
    nsend_call_3(fbphone, FB_PUTCHAR, c, row, col);
104
}
107
}
105
 
108
 
106
static void draw_stat(int consnum, enum butstate state)
109
static void draw_stat(int consnum, enum butstate state)
107
{
110
{
108
    char data[5];
111
    char data[5];
109
    int i;
112
    int i;
110
   
113
   
111
    vp_switch(cstatus_vp[consnum]);
114
    vp_switch(cstatus_vp[consnum]);
112
    set_style(stat_colors[state].fgcolor, stat_colors[state].bgcolor);
115
    set_style(stat_colors[state].fgcolor, stat_colors[state].bgcolor);
113
    clear();
116
    clear();
114
    if (state != CONS_DISCONNECTED) {
117
    if (state != CONS_DISCONNECTED) {
115
        snprintf(data, 5, "%d", consnum+1);
118
        snprintf(data, 5, "%d", consnum+1);
116
        for (i=0;data[i];i++)
119
        for (i=0;data[i];i++)
117
            putch(data[i], 0, i);
120
            putch(data[i], 0, i);
118
    }
121
    }
119
}
122
}
120
 
123
 
121
void gcons_change_console(int consnum)
124
void gcons_change_console(int consnum)
122
{
125
{
123
    if (!use_gcons)
126
    if (!use_gcons)
124
        return;
127
        return;
125
   
128
   
126
    draw_stat(active_console, CONS_IDLE);
129
    draw_stat(active_console, CONS_IDLE);
127
    active_console = consnum;
130
    active_console = consnum;
128
    draw_stat(consnum, CONS_ACTIVE);
131
    draw_stat(consnum, CONS_ACTIVE);
129
    console_has_input[consnum] = 0;
132
    console_has_input[consnum] = 0;
130
 
133
 
131
    vp_switch(console_vp);
134
    vp_switch(console_vp);
132
}
135
}
133
 
136
 
134
void gcons_notify_char(int consnum)
137
void gcons_notify_char(int consnum)
135
{
138
{
136
    if (!use_gcons)
139
    if (!use_gcons)
137
        return;
140
        return;
138
 
141
 
139
    if (consnum == active_console || console_has_input[consnum])
142
    if (consnum == active_console || console_has_input[consnum])
140
        return;
143
        return;
141
 
144
 
142
    console_has_input[consnum] = 1;
145
    console_has_input[consnum] = 1;
143
    draw_stat(consnum, CONS_HAS_INPUT);
146
    draw_stat(consnum, CONS_HAS_INPUT);
144
   
147
   
145
    vp_switch(console_vp);
148
    vp_switch(console_vp);
146
}
149
}
147
 
150
 
-
 
151
static void draw_pixmap(char *logo, size_t size, int x, int y)
-
 
152
{
-
 
153
    char *shm;
-
 
154
    int rc;
-
 
155
 
-
 
156
    /* Create area */
-
 
157
    shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
-
 
158
    if (shm == MAP_FAILED)
-
 
159
        return;
-
 
160
 
-
 
161
    memcpy(shm, logo, size);
-
 
162
    /* Send area */
-
 
163
    rc = sync_send_2(fbphone, FB_PREPARE_SHM, (ipcarg_t)shm, 0, NULL, NULL);
-
 
164
    if (rc)
-
 
165
        goto exit;
-
 
166
    rc = sync_send_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t)shm, 0, PROTO_READ, NULL, NULL, NULL);
-
 
167
    if (rc)
-
 
168
        goto drop;
-
 
169
    /* Draw logo */
-
 
170
    send_call_2(fbphone, FB_DRAW_PPM, x, y);
-
 
171
drop:
-
 
172
    /* Drop area */
-
 
173
    nsend_call(fbphone, FB_DROP_SHM, 0);
-
 
174
exit:      
-
 
175
    /* Remove area */
-
 
176
    munmap(shm, size);
-
 
177
}
-
 
178
 
-
 
179
extern char _binary_helenos_ppm_start[0];
-
 
180
extern int _binary_helenos_ppm_size;
-
 
181
extern char _binary_nameic_ppm_start[0];
-
 
182
extern int _binary_nameic_ppm_size;
148
void gcons_redraw_console(void)
183
void gcons_redraw_console(void)
149
{
184
{
150
    int i;
185
    int i;
-
 
186
    size_t hsize = (size_t)&_binary_helenos_ppm_size;
151
 
187
 
152
    if (!use_gcons)
188
    if (!use_gcons)
153
        return;
189
        return;
154
   
190
   
155
    vp_switch(0);
191
    vp_switch(0);
156
    set_style(MAIN_COLOR, MAIN_COLOR);
192
    set_style(MAIN_COLOR, MAIN_COLOR);
157
    clear();
193
    clear();
-
 
194
    draw_pixmap(_binary_helenos_ppm_start, (size_t)&_binary_helenos_ppm_size, xres-64, 0);
-
 
195
    draw_pixmap(_binary_nameic_ppm_start, (size_t)&_binary_nameic_ppm_size, 5, 10);
-
 
196
 
158
 
197
 
159
    for (i=0;i < CONSOLE_COUNT; i++)
198
    for (i=0;i < CONSOLE_COUNT; i++)
160
        draw_stat(i, i == active_console ? CONS_ACTIVE : CONS_DISCONNECTED);
199
        draw_stat(i, i == active_console ? CONS_ACTIVE : CONS_DISCONNECTED);
161
    vp_switch(console_vp);
200
    vp_switch(console_vp);
162
}
201
}
163
 
202
 
164
/** Initialize nice graphical console environment */
203
/** Initialize nice graphical console environment */
165
void gcons_init(int phone)
204
void gcons_init(int phone)
166
{
205
{
167
    int rc;
206
    int rc;
168
    int i;
207
    int i;
169
 
208
 
170
    fbphone = phone;
209
    fbphone = phone;
171
 
210
 
172
    rc = ipc_call_sync_2(phone, FB_GET_RESOLUTION, 0, 0, &xres, &yres);
211
    rc = ipc_call_sync_2(phone, FB_GET_RESOLUTION, 0, 0, &xres, &yres);
173
    if (rc)
212
    if (rc)
174
        return;
213
        return;
175
   
214
   
176
    if (xres < 800 || yres < 600)
215
    if (xres < 800 || yres < 600)
177
        return;
216
        return;
178
 
217
 
179
    /* create console viewport */
218
    /* create console viewport */
180
    console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, xres-2*CONSOLE_MARGIN,
219
    console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, xres-2*CONSOLE_MARGIN,
181
                   yres-(CONSOLE_TOP+CONSOLE_MARGIN));
220
                   yres-(CONSOLE_TOP+CONSOLE_MARGIN));
182
    if (console_vp < 0)
221
    if (console_vp < 0)
183
        return;
222
        return;
184
   
223
   
185
    /* Create status buttons */
224
    /* Create status buttons */
186
    for (i=0; i < CONSOLE_COUNT; i++) {
225
    for (i=0; i < CONSOLE_COUNT; i++) {
187
        cstatus_vp[i] = vp_create(CONSOLE_MARGIN+i*(STATUS_WIDTH+STATUS_SPACE),
226
        cstatus_vp[i] = vp_create(STATUS_START+CONSOLE_MARGIN+i*(STATUS_WIDTH+STATUS_SPACE),
188
                      CONSOLE_MARGIN, STATUS_WIDTH, STATUS_HEIGHT);
227
                      CONSOLE_MARGIN, STATUS_WIDTH, STATUS_HEIGHT);
189
        if (cstatus_vp[i] < 0)
228
        if (cstatus_vp[i] < 0)
190
            return;
229
            return;
191
    }
230
    }
192
   
231
   
193
    use_gcons = 1;
232
    use_gcons = 1;
194
    gcons_redraw_console();
233
    gcons_redraw_console();
195
}
234
}
196
 
235