Subversion Repositories HelenOS

Rev

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

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