Subversion Repositories HelenOS

Rev

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

Rev 3767 Rev 3793
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
/** @addtogroup console
29
/** @addtogroup console
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <ipc/fb.h>
35
#include <ipc/fb.h>
36
#include <ipc/ipc.h>
36
#include <ipc/ipc.h>
37
#include <async.h>
37
#include <async.h>
38
#include <stdio.h>
38
#include <stdio.h>
39
#include <sys/mman.h>
39
#include <sys/mman.h>
40
#include <string.h>
40
#include <string.h>
41
#include <align.h>
41
#include <align.h>
42
 
42
 
43
#include "console.h"
43
#include "console.h"
44
#include "gcons.h"
44
#include "gcons.h"
45
 
45
 
46
#define CONSOLE_TOP      66
46
#define CONSOLE_TOP      66
47
#define CONSOLE_MARGIN   6
47
#define CONSOLE_MARGIN   6
48
 
48
 
49
#define STATUS_START    110
49
#define STATUS_START    110
50
#define STATUS_TOP      8
50
#define STATUS_TOP      8
51
#define STATUS_SPACE    4
51
#define STATUS_SPACE    4
52
#define STATUS_WIDTH    48
52
#define STATUS_WIDTH    48
53
#define STATUS_HEIGHT   48
53
#define STATUS_HEIGHT   48
54
 
54
 
55
#define MAIN_COLOR      0xffffff
55
#define MAIN_COLOR      0xffffff
56
 
56
 
57
static int use_gcons = 0;
57
static int use_gcons = 0;
58
static ipcarg_t xres,yres;
58
static ipcarg_t xres,yres;
59
 
59
 
60
enum butstate {
60
enum butstate {
61
    CONS_DISCONNECTED = 0,
61
    CONS_DISCONNECTED = 0,
62
    CONS_SELECTED,
62
    CONS_SELECTED,
63
    CONS_IDLE,
63
    CONS_IDLE,
64
    CONS_HAS_DATA,
64
    CONS_HAS_DATA,
65
    CONS_KERNEL,
65
    CONS_KERNEL,
66
    CONS_DISCONNECTED_SEL,
66
    CONS_DISCONNECTED_SEL,
67
    CONS_LAST
67
    CONS_LAST
68
};
68
};
69
 
69
 
70
static int console_vp;
70
static int console_vp;
71
static int cstatus_vp[CONSOLE_COUNT];
71
static int cstatus_vp[CONSOLE_COUNT];
72
static enum butstate console_state[CONSOLE_COUNT];
72
static enum butstate console_state[CONSOLE_COUNT];
73
 
73
 
74
static int fbphone;
74
static int fbphone;
75
 
75
 
76
/** List of pixmaps identifying these icons */
76
/** List of pixmaps identifying these icons */
77
static int ic_pixmaps[CONS_LAST] = {-1, -1, -1, -1, -1, -1};
77
static int ic_pixmaps[CONS_LAST] = {-1, -1, -1, -1, -1, -1};
78
static int animation = -1;
78
static int animation = -1;
79
 
79
 
80
static int active_console = 0;
80
static int active_console = 0;
81
 
81
 
82
static void vp_switch(int vp)
82
static void vp_switch(int vp)
83
{
83
{
84
    async_msg_1(fbphone, FB_VIEWPORT_SWITCH, vp);
84
    async_msg_1(fbphone, FB_VIEWPORT_SWITCH, vp);
85
}
85
}
86
 
86
 
-
 
87
static void vp_invalidate(int vp)
-
 
88
{
-
 
89
    async_msg_1(fbphone, FB_VIEWPORT_INVALIDATE, vp);
-
 
90
}
-
 
91
 
-
 
92
 
87
/** Create view port */
93
/** Create view port */
88
static int vp_create(unsigned int x, unsigned int y, unsigned int width,
94
static int vp_create(unsigned int x, unsigned int y, unsigned int width,
89
    unsigned int height)
95
    unsigned int height)
90
{
96
{
91
    return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
97
    return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
92
        (width << 16) | height);
98
        (width << 16) | height);
93
}
99
}
94
 
100
 
95
static void clear(void)
101
static void clear(void)
96
{
102
{
97
    async_msg_0(fbphone, FB_CLEAR);
103
    async_msg_0(fbphone, FB_CLEAR);
98
}
104
}
99
 
105
 
100
static void set_rgb_color(int fgcolor, int bgcolor)
106
static void set_rgb_color(int fgcolor, int bgcolor)
101
{
107
{
102
    async_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
108
    async_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
103
}
109
}
104
 
110
 
105
/** Transparent putchar */
111
/** Transparent putchar */
106
static void tran_putch(char c, int row, int col)
112
static void tran_putch(char c, int row, int col)
107
{
113
{
108
    async_msg_3(fbphone, FB_PUTCHAR, c, row, col);
114
    async_msg_3(fbphone, FB_PUTCHAR, c, row, col);
109
}
115
}
110
 
116
 
111
/** Redraw the button showing state of a given console */
117
/** Redraw the button showing state of a given console */
112
static void redraw_state(int consnum)
118
static void redraw_state(int consnum)
113
{
119
{
114
    char data[5];
120
    char data[5];
115
    int i;
121
    int i;
116
    enum butstate state = console_state[consnum];
122
    enum butstate state = console_state[consnum];
117
 
123
 
118
    vp_switch(cstatus_vp[consnum]);
124
    vp_switch(cstatus_vp[consnum]);
119
    if (ic_pixmaps[state] != -1)
125
    if (ic_pixmaps[state] != -1)
120
        async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum],
126
        async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum],
121
            ic_pixmaps[state]);
127
            ic_pixmaps[state]);
122
 
128
 
123
    if (state != CONS_DISCONNECTED && state != CONS_KERNEL &&
129
    if (state != CONS_DISCONNECTED && state != CONS_KERNEL &&
124
        state != CONS_DISCONNECTED_SEL) {
130
        state != CONS_DISCONNECTED_SEL) {
125
        snprintf(data, 5, "%d", consnum + 1);
131
        snprintf(data, 5, "%d", consnum + 1);
126
        for (i = 0; data[i]; i++)
132
        for (i = 0; data[i]; i++)
127
            tran_putch(data[i], 1, 2 + i);
133
            tran_putch(data[i], 1, 2 + i);
128
    }
134
    }
129
}
135
}
130
 
136
 
131
/** Notification run on changing console (except kernel console) */
137
/** Notification run on changing console (except kernel console) */
132
void gcons_change_console(int consnum)
138
void gcons_change_console(int consnum)
133
{
139
{
134
    int i;
140
    int i;
135
 
141
 
136
    if (!use_gcons)
142
    if (!use_gcons)
137
        return;
143
        return;
138
 
144
 
139
    if (active_console == KERNEL_CONSOLE) {
145
    if (active_console == KERNEL_CONSOLE) {
140
        for (i = 0; i < CONSOLE_COUNT; i++)
146
        for (i = 0; i < CONSOLE_COUNT; i++)
141
            redraw_state(i);
147
            redraw_state(i);
142
        if (animation != -1)
148
        if (animation != -1)
143
            async_msg_1(fbphone, FB_ANIM_START, animation);
149
            async_msg_1(fbphone, FB_ANIM_START, animation);
144
    } else {
150
    } else {
145
        if (console_state[active_console] == CONS_DISCONNECTED_SEL)
151
        if (console_state[active_console] == CONS_DISCONNECTED_SEL)
146
            console_state[active_console] = CONS_DISCONNECTED;
152
            console_state[active_console] = CONS_DISCONNECTED;
147
        else
153
        else
148
            console_state[active_console] = CONS_IDLE;
154
            console_state[active_console] = CONS_IDLE;
149
        redraw_state(active_console);
155
        redraw_state(active_console);
150
    }
156
    }
151
    active_console = consnum;
157
    active_console = consnum;
152
 
158
 
153
    if (console_state[consnum] == CONS_DISCONNECTED) {
159
    if (console_state[consnum] == CONS_DISCONNECTED) {
154
        console_state[consnum] = CONS_DISCONNECTED_SEL;
160
        console_state[consnum] = CONS_DISCONNECTED_SEL;
155
        redraw_state(consnum);
161
        redraw_state(consnum);
156
    } else
162
    } else
157
        console_state[consnum] = CONS_SELECTED;
163
        console_state[consnum] = CONS_SELECTED;
158
    redraw_state(consnum);
164
    redraw_state(consnum);
159
 
165
 
-
 
166
    vp_invalidate(console_vp);
160
    vp_switch(console_vp);
167
    vp_switch(console_vp);
161
}
168
}
162
 
169
 
163
/** Notification function that gets called on new output to virtual console */
170
/** Notification function that gets called on new output to virtual console */
164
void gcons_notify_char(int consnum)
171
void gcons_notify_char(int consnum)
165
{
172
{
166
    if (!use_gcons)
173
    if (!use_gcons)
167
        return;
174
        return;
168
 
175
 
169
    if (consnum == active_console ||
176
    if (consnum == active_console ||
170
        console_state[consnum] == CONS_HAS_DATA)
177
        console_state[consnum] == CONS_HAS_DATA)
171
        return;
178
        return;
172
 
179
 
173
    console_state[consnum] = CONS_HAS_DATA;
180
    console_state[consnum] = CONS_HAS_DATA;
174
 
181
 
175
    if (active_console == KERNEL_CONSOLE)
182
    if (active_console == KERNEL_CONSOLE)
176
        return;
183
        return;
177
 
184
 
178
    redraw_state(consnum);
185
    redraw_state(consnum);
179
   
186
   
180
    vp_switch(console_vp);
187
    vp_switch(console_vp);
181
}
188
}
182
 
189
 
183
/** Notification function called on service disconnect from console */
190
/** Notification function called on service disconnect from console */
184
void gcons_notify_disconnect(int consnum)
191
void gcons_notify_disconnect(int consnum)
185
{
192
{
186
    if (!use_gcons)
193
    if (!use_gcons)
187
        return;
194
        return;
188
    if (active_console == consnum)
195
    if (active_console == consnum)
189
        console_state[consnum] = CONS_DISCONNECTED_SEL;
196
        console_state[consnum] = CONS_DISCONNECTED_SEL;
190
    else
197
    else
191
        console_state[consnum] = CONS_DISCONNECTED;
198
        console_state[consnum] = CONS_DISCONNECTED;
192
   
199
   
193
    if (active_console == KERNEL_CONSOLE)
200
    if (active_console == KERNEL_CONSOLE)
194
        return;
201
        return;
195
   
202
   
196
    redraw_state(consnum);
203
    redraw_state(consnum);
197
    vp_switch(console_vp);
204
    vp_switch(console_vp);
198
}
205
}
199
 
206
 
200
/** Notification function called on console connect */
207
/** Notification function called on console connect */
201
void gcons_notify_connect(int consnum)
208
void gcons_notify_connect(int consnum)
202
{
209
{
203
    if (!use_gcons)
210
    if (!use_gcons)
204
        return;
211
        return;
205
    if (active_console == consnum)
212
    if (active_console == consnum)
206
        console_state[consnum] = CONS_SELECTED;
213
        console_state[consnum] = CONS_SELECTED;
207
    else
214
    else
208
        console_state[consnum] = CONS_IDLE;
215
        console_state[consnum] = CONS_IDLE;
209
 
216
 
210
    if (active_console == KERNEL_CONSOLE)
217
    if (active_console == KERNEL_CONSOLE)
211
        return;
218
        return;
212
 
219
 
213
    redraw_state(consnum);
220
    redraw_state(consnum);
214
    vp_switch(console_vp);
221
    vp_switch(console_vp);
215
}
222
}
216
 
223
 
217
/** Change to kernel console */
224
/** Change to kernel console */
218
void gcons_in_kernel(void)
225
void gcons_in_kernel(void)
219
{
226
{
220
    if (animation != -1)
227
    if (animation != -1)
221
        async_msg_1(fbphone, FB_ANIM_STOP, animation);
228
        async_msg_1(fbphone, FB_ANIM_STOP, animation);
222
   
229
   
223
    active_console = KERNEL_CONSOLE;
230
    active_console = KERNEL_CONSOLE;
224
    vp_switch(0);
231
    vp_switch(0);
225
}
232
}
226
 
233
 
227
/** Return x, where left <= x <= right && |a-x|==min(|a-x|) is smallest */
234
/** Return x, where left <= x <= right && |a-x|==min(|a-x|) is smallest */
228
static inline int limit(int a,int left, int right)
235
static inline int limit(int a,int left, int right)
229
{
236
{
230
    if (a < left)
237
    if (a < left)
231
        a = left;
238
        a = left;
232
    if (a >= right)
239
    if (a >= right)
233
        a = right - 1;
240
        a = right - 1;
234
    return a;
241
    return a;
235
}
242
}
236
 
243
 
237
int mouse_x, mouse_y;
244
int mouse_x, mouse_y;
238
int btn_pressed, btn_x, btn_y;
245
int btn_pressed, btn_x, btn_y;
239
 
246
 
240
/** Handle mouse move
247
/** Handle mouse move
241
 *
248
 *
242
 * @param dx Delta X of mouse move
249
 * @param dx Delta X of mouse move
243
 * @param dy Delta Y of mouse move
250
 * @param dy Delta Y of mouse move
244
 */
251
 */
245
void gcons_mouse_move(int dx, int dy)
252
void gcons_mouse_move(int dx, int dy)
246
{
253
{
247
    mouse_x = limit(mouse_x + dx, 0, xres);
254
    mouse_x = limit(mouse_x + dx, 0, xres);
248
    mouse_y = limit(mouse_y + dy, 0, yres);
255
    mouse_y = limit(mouse_y + dy, 0, yres);
249
 
256
 
250
    async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
257
    async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
251
}
258
}
252
 
259
 
253
static int gcons_find_conbut(int x, int y)
260
static int gcons_find_conbut(int x, int y)
254
{
261
{
255
    int status_start = STATUS_START + (xres - 800) / 2;
262
    int status_start = STATUS_START + (xres - 800) / 2;
256
 
263
 
257
    if (y < STATUS_TOP || y >= STATUS_TOP + STATUS_HEIGHT)
264
    if (y < STATUS_TOP || y >= STATUS_TOP + STATUS_HEIGHT)
258
        return -1;
265
        return -1;
259
   
266
   
260
    if (x < status_start)
267
    if (x < status_start)
261
        return -1;
268
        return -1;
262
   
269
   
263
    if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
270
    if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
264
        return -1;
271
        return -1;
265
    if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
272
    if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
266
        return -1;
273
        return -1;
267
   
274
   
268
    return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
275
    return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
269
}
276
}
270
 
277
 
271
/** Handle mouse click
278
/** Handle mouse click
272
 *
279
 *
273
 * @param state New state (1-pressed, 0-depressed)
280
 * @param state New state (1-pressed, 0-depressed)
274
 */
281
 */
275
int gcons_mouse_btn(int state)
282
int gcons_mouse_btn(int state)
276
{
283
{
277
    int conbut;
284
    int conbut;
278
 
285
 
279
    if (state) {
286
    if (state) {
280
        conbut = gcons_find_conbut(mouse_x, mouse_y);
287
        conbut = gcons_find_conbut(mouse_x, mouse_y);
281
        if (conbut != -1) {
288
        if (conbut != -1) {
282
            btn_pressed = 1;
289
            btn_pressed = 1;
283
            btn_x = mouse_x;
290
            btn_x = mouse_x;
284
            btn_y = mouse_y;
291
            btn_y = mouse_y;
285
        }
292
        }
286
        return -1;
293
        return -1;
287
    }
294
    }
288
    if (!state && !btn_pressed)
295
    if (!state && !btn_pressed)
289
        return -1;
296
        return -1;
290
    btn_pressed = 0;
297
    btn_pressed = 0;
291
 
298
 
292
    conbut = gcons_find_conbut(mouse_x, mouse_y);
299
    conbut = gcons_find_conbut(mouse_x, mouse_y);
293
    if (conbut == gcons_find_conbut(btn_x, btn_y))
300
    if (conbut == gcons_find_conbut(btn_x, btn_y))
294
        return conbut;
301
        return conbut;
295
    return -1;
302
    return -1;
296
}
303
}
297
 
304
 
298
 
305
 
299
/** Draw a PPM pixmap to framebuffer
306
/** Draw a PPM pixmap to framebuffer
300
 *
307
 *
301
 * @param logo Pointer to PPM data
308
 * @param logo Pointer to PPM data
302
 * @param size Size of PPM data
309
 * @param size Size of PPM data
303
 * @param x Coordinate of upper left corner
310
 * @param x Coordinate of upper left corner
304
 * @param y Coordinate of upper left corner
311
 * @param y Coordinate of upper left corner
305
 */
312
 */
306
static void draw_pixmap(char *logo, size_t size, int x, int y)
313
static void draw_pixmap(char *logo, size_t size, int x, int y)
307
{
314
{
308
    char *shm;
315
    char *shm;
309
    int rc;
316
    int rc;
310
 
317
 
311
    /* Create area */
318
    /* Create area */
312
    shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
319
    shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
313
        MAP_ANONYMOUS, 0, 0);
320
        MAP_ANONYMOUS, 0, 0);
314
    if (shm == MAP_FAILED)
321
    if (shm == MAP_FAILED)
315
        return;
322
        return;
316
 
323
 
317
    memcpy(shm, logo, size);
324
    memcpy(shm, logo, size);
318
    /* Send area */
325
    /* Send area */
319
    rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
326
    rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
320
    if (rc)
327
    if (rc)
321
        goto exit;
328
        goto exit;
322
    rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
329
    rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
323
    if (rc)
330
    if (rc)
324
        goto drop;
331
        goto drop;
325
    /* Draw logo */
332
    /* Draw logo */
326
    async_msg_2(fbphone, FB_DRAW_PPM, x, y);
333
    async_msg_2(fbphone, FB_DRAW_PPM, x, y);
327
drop:
334
drop:
328
    /* Drop area */
335
    /* Drop area */
329
    async_msg_0(fbphone, FB_DROP_SHM);
336
    async_msg_0(fbphone, FB_DROP_SHM);
330
exit:      
337
exit:      
331
    /* Remove area */
338
    /* Remove area */
332
    munmap(shm, size);
339
    munmap(shm, size);
333
}
340
}
334
 
341
 
335
extern char _binary_helenos_ppm_start[0];
342
extern char _binary_helenos_ppm_start[0];
336
extern int _binary_helenos_ppm_size;
343
extern int _binary_helenos_ppm_size;
337
extern char _binary_nameic_ppm_start[0];
344
extern char _binary_nameic_ppm_start[0];
338
extern int _binary_nameic_ppm_size;
345
extern int _binary_nameic_ppm_size;
339
 
346
 
340
/** Redraws console graphics */
347
/** Redraws console graphics */
341
void gcons_redraw_console(void)
348
void gcons_redraw_console(void)
342
{
349
{
343
    int i;
350
    int i;
344
   
351
   
345
    if (!use_gcons)
352
    if (!use_gcons)
346
        return;
353
        return;
347
   
354
   
348
    vp_switch(0);
355
    vp_switch(0);
349
    set_rgb_color(MAIN_COLOR, MAIN_COLOR);
356
    set_rgb_color(MAIN_COLOR, MAIN_COLOR);
350
    clear();
357
    clear();
351
    draw_pixmap(_binary_helenos_ppm_start,
358
    draw_pixmap(_binary_helenos_ppm_start,
352
        (size_t) &_binary_helenos_ppm_size, xres - 66, 2);
359
        (size_t) &_binary_helenos_ppm_size, xres - 66, 2);
353
    draw_pixmap(_binary_nameic_ppm_start,
360
    draw_pixmap(_binary_nameic_ppm_start,
354
        (size_t) &_binary_nameic_ppm_size, 5, 17);
361
        (size_t) &_binary_nameic_ppm_size, 5, 17);
355
   
362
   
356
    for (i = 0; i < CONSOLE_COUNT; i++)
363
    for (i = 0; i < CONSOLE_COUNT; i++)
357
        redraw_state(i);
364
        redraw_state(i);
-
 
365
    vp_invalidate(console_vp);
358
    vp_switch(console_vp);
366
    vp_switch(console_vp);
359
}
367
}
360
 
368
 
361
/** Creates a pixmap on framebuffer
369
/** Creates a pixmap on framebuffer
362
 *
370
 *
363
 * @param data PPM data
371
 * @param data PPM data
364
 * @param size PPM data size
372
 * @param size PPM data size
365
 * @return Pixmap identification
373
 * @return Pixmap identification
366
 */
374
 */
367
static int make_pixmap(char *data, int size)
375
static int make_pixmap(char *data, int size)
368
{
376
{
369
    char *shm;
377
    char *shm;
370
    int rc;
378
    int rc;
371
    int pxid = -1;
379
    int pxid = -1;
372
 
380
 
373
    /* Create area */
381
    /* Create area */
374
    shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
382
    shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
375
        MAP_ANONYMOUS, 0, 0);
383
        MAP_ANONYMOUS, 0, 0);
376
    if (shm == MAP_FAILED)
384
    if (shm == MAP_FAILED)
377
        return -1;
385
        return -1;
378
 
386
 
379
    memcpy(shm, data, size);
387
    memcpy(shm, data, size);
380
    /* Send area */
388
    /* Send area */
381
    rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
389
    rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
382
    if (rc)
390
    if (rc)
383
        goto exit;
391
        goto exit;
384
    rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
392
    rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
385
    if (rc)
393
    if (rc)
386
        goto drop;
394
        goto drop;
387
 
395
 
388
    /* Obtain pixmap */
396
    /* Obtain pixmap */
389
    rc = async_req_0_0(fbphone, FB_SHM2PIXMAP);
397
    rc = async_req_0_0(fbphone, FB_SHM2PIXMAP);
390
    if (rc < 0)
398
    if (rc < 0)
391
        goto drop;
399
        goto drop;
392
    pxid = rc;
400
    pxid = rc;
393
drop:
401
drop:
394
    /* Drop area */
402
    /* Drop area */
395
    async_msg_0(fbphone, FB_DROP_SHM);
403
    async_msg_0(fbphone, FB_DROP_SHM);
396
exit:      
404
exit:      
397
    /* Remove area */
405
    /* Remove area */
398
    munmap(shm, size);
406
    munmap(shm, size);
399
 
407
 
400
    return pxid;
408
    return pxid;
401
}
409
}
402
 
410
 
403
extern char _binary_anim_1_ppm_start[0];
411
extern char _binary_anim_1_ppm_start[0];
404
extern int _binary_anim_1_ppm_size;
412
extern int _binary_anim_1_ppm_size;
405
extern char _binary_anim_2_ppm_start[0];
413
extern char _binary_anim_2_ppm_start[0];
406
extern int _binary_anim_2_ppm_size;
414
extern int _binary_anim_2_ppm_size;
407
extern char _binary_anim_3_ppm_start[0];
415
extern char _binary_anim_3_ppm_start[0];
408
extern int _binary_anim_3_ppm_size;
416
extern int _binary_anim_3_ppm_size;
409
extern char _binary_anim_4_ppm_start[0];
417
extern char _binary_anim_4_ppm_start[0];
410
extern int _binary_anim_4_ppm_size;
418
extern int _binary_anim_4_ppm_size;
411
 
419
 
412
static void make_anim(void)
420
static void make_anim(void)
413
{
421
{
414
    int an;
422
    int an;
415
    int pm;
423
    int pm;
416
 
424
 
417
    an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
425
    an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
418
    if (an < 0)
426
    if (an < 0)
419
        return;
427
        return;
420
 
428
 
421
    pm = make_pixmap(_binary_anim_1_ppm_start,
429
    pm = make_pixmap(_binary_anim_1_ppm_start,
422
        (int) &_binary_anim_1_ppm_size);
430
        (int) &_binary_anim_1_ppm_size);
423
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
431
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
424
 
432
 
425
    pm = make_pixmap(_binary_anim_2_ppm_start,
433
    pm = make_pixmap(_binary_anim_2_ppm_start,
426
        (int) &_binary_anim_2_ppm_size);
434
        (int) &_binary_anim_2_ppm_size);
427
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
435
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
428
 
436
 
429
    pm = make_pixmap(_binary_anim_3_ppm_start,
437
    pm = make_pixmap(_binary_anim_3_ppm_start,
430
        (int) &_binary_anim_3_ppm_size);
438
        (int) &_binary_anim_3_ppm_size);
431
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
439
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
432
 
440
 
433
    pm = make_pixmap(_binary_anim_4_ppm_start,
441
    pm = make_pixmap(_binary_anim_4_ppm_start,
434
        (int) &_binary_anim_4_ppm_size);
442
        (int) &_binary_anim_4_ppm_size);
435
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
443
    async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
436
 
444
 
437
    async_msg_1(fbphone, FB_ANIM_START, an);
445
    async_msg_1(fbphone, FB_ANIM_START, an);
438
 
446
 
439
    animation = an;
447
    animation = an;
440
}
448
}
441
 
449
 
442
extern char _binary_cons_selected_ppm_start[0];
450
extern char _binary_cons_selected_ppm_start[0];
443
extern int _binary_cons_selected_ppm_size;
451
extern int _binary_cons_selected_ppm_size;
444
extern char _binary_cons_idle_ppm_start[0];
452
extern char _binary_cons_idle_ppm_start[0];
445
extern int _binary_cons_idle_ppm_size;
453
extern int _binary_cons_idle_ppm_size;
446
extern char _binary_cons_has_data_ppm_start[0];
454
extern char _binary_cons_has_data_ppm_start[0];
447
extern int _binary_cons_has_data_ppm_size;
455
extern int _binary_cons_has_data_ppm_size;
448
extern char _binary_cons_kernel_ppm_start[0];
456
extern char _binary_cons_kernel_ppm_start[0];
449
extern int _binary_cons_kernel_ppm_size;
457
extern int _binary_cons_kernel_ppm_size;
450
 
458
 
451
/** Initialize nice graphical console environment */
459
/** Initialize nice graphical console environment */
452
void gcons_init(int phone)
460
void gcons_init(int phone)
453
{
461
{
454
    int rc;
462
    int rc;
455
    int i;
463
    int i;
456
    int status_start = STATUS_START;
464
    int status_start = STATUS_START;
457
   
465
   
458
    fbphone = phone;
466
    fbphone = phone;
459
   
467
   
460
    rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
468
    rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
461
    if (rc)
469
    if (rc)
462
        return;
470
        return;
463
   
471
   
464
    if ((xres < 800) || (yres < 600))
472
    if ((xres < 800) || (yres < 600))
465
        return;
473
        return;
466
   
474
   
467
    /* create console viewport */
475
    /* create console viewport */
468
    /* Align width & height to character size */
476
    /* Align width & height to character size */
469
    console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
477
    console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
470
        ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
478
        ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
471
        ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
479
        ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
472
    if (console_vp < 0)
480
    if (console_vp < 0)
473
        return;
481
        return;
474
   
482
   
475
    /* Create status buttons */
483
    /* Create status buttons */
476
    status_start += (xres - 800) / 2;
484
    status_start += (xres - 800) / 2;
477
    for (i = 0; i < CONSOLE_COUNT; i++) {
485
    for (i = 0; i < CONSOLE_COUNT; i++) {
478
        cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
486
        cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
479
            i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
487
            i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
480
            STATUS_WIDTH, STATUS_HEIGHT);
488
            STATUS_WIDTH, STATUS_HEIGHT);
481
        if (cstatus_vp[i] < 0)
489
        if (cstatus_vp[i] < 0)
482
            return;
490
            return;
483
        vp_switch(cstatus_vp[i]);
491
        vp_switch(cstatus_vp[i]);
484
        set_rgb_color(0x202020, 0xffffff);
492
        set_rgb_color(0x202020, 0xffffff);
485
    }
493
    }
486
   
494
   
487
    /* Initialize icons */
495
    /* Initialize icons */
488
    ic_pixmaps[CONS_SELECTED] =
496
    ic_pixmaps[CONS_SELECTED] =
489
        make_pixmap(_binary_cons_selected_ppm_start,
497
        make_pixmap(_binary_cons_selected_ppm_start,
490
        (int) &_binary_cons_selected_ppm_size);
498
        (int) &_binary_cons_selected_ppm_size);
491
    ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start,
499
    ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start,
492
        (int) &_binary_cons_idle_ppm_size);
500
        (int) &_binary_cons_idle_ppm_size);
493
    ic_pixmaps[CONS_HAS_DATA] =
501
    ic_pixmaps[CONS_HAS_DATA] =
494
        make_pixmap(_binary_cons_has_data_ppm_start,
502
        make_pixmap(_binary_cons_has_data_ppm_start,
495
        (int) &_binary_cons_has_data_ppm_size);
503
        (int) &_binary_cons_has_data_ppm_size);
496
    ic_pixmaps[CONS_DISCONNECTED] =
504
    ic_pixmaps[CONS_DISCONNECTED] =
497
        make_pixmap(_binary_cons_idle_ppm_start,
505
        make_pixmap(_binary_cons_idle_ppm_start,
498
        (int) &_binary_cons_idle_ppm_size);
506
        (int) &_binary_cons_idle_ppm_size);
499
    ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start,
507
    ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start,
500
        (int) &_binary_cons_kernel_ppm_size);
508
        (int) &_binary_cons_kernel_ppm_size);
501
    ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
509
    ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
502
   
510
   
503
    make_anim();
511
    make_anim();
504
   
512
   
505
    use_gcons = 1;
513
    use_gcons = 1;
506
    console_state[0] = CONS_DISCONNECTED_SEL;
514
    console_state[0] = CONS_DISCONNECTED_SEL;
507
    console_state[KERNEL_CONSOLE] = CONS_KERNEL;
515
    console_state[KERNEL_CONSOLE] = CONS_KERNEL;
508
    gcons_redraw_console();
516
    gcons_redraw_console();
509
}
517
}
510
 
518
 
511
/** @}
519
/** @}
512
 */
520
 */
513
 
521