Subversion Repositories HelenOS

Rev

Rev 1522 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1518 palkovsky 1
/*
2
 * Copyright (C) 2006 Ondrej Palkovsky
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
#include <ipc/fb.h>
30
#include <ipc/ipc.h>
31
 
32
#include "console.h"
33
 
34
#define CONSOLE_TOP      50
35
#define CONSOLE_MARGIN   10
36
 
37
#define STATUS_SPACE    20
38
#define STATUS_WIDTH    40
39
#define STATUS_HEIGHT   30
40
 
41
static int use_gcons = 0;
42
static ipcarg_t xres,yres;
43
 
44
static int console_vp;
45
static int cstatus_vp[CONSOLE_COUNT];
46
 
47
static int fbphone;
48
 
49
static void vp_switch(int vp)
50
{
51
    ipc_call_sync_2(fbphone,FB_VIEWPORT_SWITCH, vp, 0, NULL, NULL);
52
}
53
 
54
static int vp_create(unsigned int x, unsigned int y,
55
             unsigned int width, unsgined int height)
56
{
57
    return  ipc_call_sync_2(fbphone, (x << 16) | y, (width << 16) | height,
58
                NULL, NULL);
59
}
60
 
61
static void fb_clear(void)
62
{
63
    ipc_call_sync_2(fbphone, FB_CLEAR, 0, 0, NULL, NULL);
64
 
65
}
66
 
67
static void fb_set_style(int fgcolor, int bgcolor)
68
{
69
    ipc_call_sync_2(fbphone, );
70
}
71
 
72
void gcons_change_console(int consnum)
73
{
74
    if (!use_gcons)
75
        return;
76
 
77
    vp_switch(console_vp);
78
}
79
 
80
void gcons_notify_char(int consnum)
81
{
82
    if (!use_gcons)
83
        return;
84
 
85
    vp_switch(console_vp);
86
}
87
 
88
void gcons_redraw_console(int phone)
89
{
90
    if (!use_gcons)
91
        return;
92
 
93
    vp_switch(0);
94
    /* Set style...*/
95
    fb_clear();
96
 
97
    vp_switch(console_vp);
98
}
99
 
100
/** Initialize nice graphical console environment */
101
void gcons_init(int phone)
102
{
103
    int rc;
104
    int i;
105
 
106
    fbphone = phone;
107
 
108
    rc = ipc_call_sync_2(phone, FB_GET_RESOLUTION, 0, 0, &xres, &yres);
109
    if (rc)
110
        return;
111
 
112
    if (xres < 800 || yres < 600)
113
        return;
114
 
115
    /* create console viewport */
116
    console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, xres-2*CONSOLE_MARGIN,
117
                   yres-(CONSOLE_TOP+CONSOLE_MARGIN));
118
    if (console_vp < 0)
119
        return;
120
 
121
    /* Create status buttons */
122
    for (i=0; i < CONSOLE_COUNT; i++) {
123
        cstatus_vp[i] = vp_create(phone, CONSOLE_MARGIN+i*(STATUS_WIDTH+STATUS_SPACE),
124
                      CONSOLE_MARGIN, STATUS_WIDTH, STATUS_HEIGHT);
125
        if (cstatus_vp[i] < 0)
126
            return;
127
    }
128
 
129
    use_gcons = 1;
130
    gcons_draw_console();
131
}