Rev 1518 | Rev 1528 | Go to most recent revision | Details | Compare with Previous | 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> |
||
1522 | palkovsky | 31 | #include <async.h> |
32 | #include <stdio.h> |
||
1518 | palkovsky | 33 | |
34 | #include "console.h" |
||
1522 | palkovsky | 35 | #include "gcons.h" |
1518 | palkovsky | 36 | |
37 | #define CONSOLE_TOP 50 |
||
38 | #define CONSOLE_MARGIN 10 |
||
39 | |||
40 | #define STATUS_SPACE 20 |
||
41 | #define STATUS_WIDTH 40 |
||
42 | #define STATUS_HEIGHT 30 |
||
43 | |||
1522 | palkovsky | 44 | #define MAIN_COLOR 0x118811 |
45 | |||
1518 | palkovsky | 46 | static int use_gcons = 0; |
47 | static ipcarg_t xres,yres; |
||
48 | |||
49 | static int console_vp; |
||
50 | static int cstatus_vp[CONSOLE_COUNT]; |
||
1522 | palkovsky | 51 | static int cstat_row, cstat_col; /* Size of cstatus buttons */ |
1518 | palkovsky | 52 | |
53 | static int fbphone; |
||
54 | |||
1522 | palkovsky | 55 | enum butstate { |
56 | CONS_ACTIVE = 0, |
||
57 | CONS_IDLE, |
||
58 | CONS_HAS_INPUT |
||
59 | }; |
||
60 | |||
61 | static struct { |
||
62 | int fgcolor; |
||
63 | int bgcolor; |
||
64 | } stat_colors[] = { |
||
65 | {0xd0d0d0, 0x808080}, |
||
66 | {0xd0d0d0, 0x0}, |
||
67 | {0xd0d0d0, 0xa04040} |
||
68 | }; |
||
69 | |||
70 | static int active_console = 0; |
||
71 | |||
1518 | palkovsky | 72 | static void vp_switch(int vp) |
73 | { |
||
1522 | palkovsky | 74 | nsend_call(fbphone,FB_VIEWPORT_SWITCH, vp); |
1518 | palkovsky | 75 | } |
76 | |||
1522 | palkovsky | 77 | /** Create view port */ |
1518 | palkovsky | 78 | static int vp_create(unsigned int x, unsigned int y, |
1522 | palkovsky | 79 | unsigned int width, unsigned int height) |
1518 | palkovsky | 80 | { |
1522 | palkovsky | 81 | /* Init function, use ipc_call_sync */ |
82 | return ipc_call_sync_2(fbphone, FB_VIEWPORT_CREATE, |
||
83 | (x << 16) | y, (width << 16) | height, |
||
84 | NULL, NULL); |
||
1518 | palkovsky | 85 | } |
86 | |||
1522 | palkovsky | 87 | static void clear(void) |
1518 | palkovsky | 88 | { |
1522 | palkovsky | 89 | nsend_call(fbphone, FB_CLEAR, 0); |
1518 | palkovsky | 90 | |
91 | } |
||
92 | |||
1522 | palkovsky | 93 | static void set_style(int fgcolor, int bgcolor) |
1518 | palkovsky | 94 | { |
1522 | palkovsky | 95 | nsend_call_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor); |
1518 | palkovsky | 96 | } |
97 | |||
1522 | palkovsky | 98 | static void putch(char c, int row, int col) |
99 | { |
||
100 | nsend_call_3(fbphone, FB_PUTCHAR, c, row, col); |
||
101 | } |
||
102 | |||
103 | static void draw_stat(int consnum, enum butstate state) |
||
104 | { |
||
105 | char data[5]; |
||
106 | int i; |
||
107 | |||
108 | vp_switch(cstatus_vp[consnum]); |
||
109 | set_style(stat_colors[state].fgcolor, stat_colors[state].bgcolor); |
||
110 | clear(); |
||
111 | snprintf(data, 5, "%d", consnum+1); |
||
112 | for (i=0;data[i];i++) |
||
113 | putch(data[i], 0, i); |
||
114 | } |
||
115 | |||
1518 | palkovsky | 116 | void gcons_change_console(int consnum) |
117 | { |
||
118 | if (!use_gcons) |
||
119 | return; |
||
1522 | palkovsky | 120 | |
121 | draw_stat(active_console, CONS_IDLE); |
||
122 | active_console = consnum; |
||
123 | draw_stat(consnum, CONS_ACTIVE); |
||
1518 | palkovsky | 124 | vp_switch(console_vp); |
125 | } |
||
126 | |||
127 | void gcons_notify_char(int consnum) |
||
128 | { |
||
129 | if (!use_gcons) |
||
130 | return; |
||
131 | |||
132 | vp_switch(console_vp); |
||
133 | } |
||
134 | |||
1522 | palkovsky | 135 | void gcons_redraw_console(void) |
1518 | palkovsky | 136 | { |
1522 | palkovsky | 137 | int i; |
138 | |||
1518 | palkovsky | 139 | if (!use_gcons) |
140 | return; |
||
141 | |||
142 | vp_switch(0); |
||
1522 | palkovsky | 143 | set_style(MAIN_COLOR, MAIN_COLOR); |
144 | clear(); |
||
145 | |||
146 | for (i=0;i < CONSOLE_COUNT; i++) |
||
147 | draw_stat(i, i == active_console ? CONS_ACTIVE : CONS_IDLE); |
||
1518 | palkovsky | 148 | vp_switch(console_vp); |
149 | } |
||
150 | |||
151 | /** Initialize nice graphical console environment */ |
||
152 | void gcons_init(int phone) |
||
153 | { |
||
154 | int rc; |
||
155 | int i; |
||
156 | |||
157 | fbphone = phone; |
||
158 | |||
159 | rc = ipc_call_sync_2(phone, FB_GET_RESOLUTION, 0, 0, &xres, &yres); |
||
160 | if (rc) |
||
161 | return; |
||
162 | |||
163 | if (xres < 800 || yres < 600) |
||
164 | return; |
||
165 | |||
166 | /* create console viewport */ |
||
167 | console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, xres-2*CONSOLE_MARGIN, |
||
168 | yres-(CONSOLE_TOP+CONSOLE_MARGIN)); |
||
169 | if (console_vp < 0) |
||
170 | return; |
||
171 | |||
172 | /* Create status buttons */ |
||
173 | for (i=0; i < CONSOLE_COUNT; i++) { |
||
1522 | palkovsky | 174 | cstatus_vp[i] = vp_create(CONSOLE_MARGIN+i*(STATUS_WIDTH+STATUS_SPACE), |
1518 | palkovsky | 175 | CONSOLE_MARGIN, STATUS_WIDTH, STATUS_HEIGHT); |
176 | if (cstatus_vp[i] < 0) |
||
177 | return; |
||
178 | } |
||
179 | |||
180 | use_gcons = 1; |
||
1522 | palkovsky | 181 | gcons_redraw_console(); |
1518 | palkovsky | 182 | } |