Rev 1528 | Rev 1552 | 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> |
||
1547 | palkovsky | 33 | #include <sys/mman.h> |
34 | #include <string.h> |
||
1518 | palkovsky | 35 | |
36 | #include "console.h" |
||
1522 | palkovsky | 37 | #include "gcons.h" |
1518 | palkovsky | 38 | |
1547 | palkovsky | 39 | #define CONSOLE_TOP 65 |
1518 | palkovsky | 40 | #define CONSOLE_MARGIN 10 |
41 | |||
1547 | palkovsky | 42 | #define STATUS_START 120 |
43 | #define STATUS_SPACE 5 |
||
1518 | palkovsky | 44 | #define STATUS_WIDTH 40 |
45 | #define STATUS_HEIGHT 30 |
||
46 | |||
1547 | palkovsky | 47 | #define MAIN_COLOR 0xffffff |
1522 | palkovsky | 48 | |
1518 | palkovsky | 49 | static int use_gcons = 0; |
50 | static ipcarg_t xres,yres; |
||
51 | |||
52 | static int console_vp; |
||
53 | static int cstatus_vp[CONSOLE_COUNT]; |
||
1528 | palkovsky | 54 | static int console_has_input[CONSOLE_COUNT]; |
1522 | palkovsky | 55 | static int cstat_row, cstat_col; /* Size of cstatus buttons */ |
1518 | palkovsky | 56 | |
57 | static int fbphone; |
||
58 | |||
1522 | palkovsky | 59 | enum butstate { |
60 | CONS_ACTIVE = 0, |
||
61 | CONS_IDLE, |
||
1528 | palkovsky | 62 | CONS_HAS_INPUT, |
63 | CONS_DISCONNECTED |
||
1522 | palkovsky | 64 | }; |
65 | |||
66 | static struct { |
||
67 | int fgcolor; |
||
68 | int bgcolor; |
||
69 | } stat_colors[] = { |
||
70 | {0xd0d0d0, 0x808080}, |
||
71 | {0xd0d0d0, 0x0}, |
||
1528 | palkovsky | 72 | {0xd0d0d0, 0xa04040}, |
73 | {0xd0d0d0, 0x0} |
||
1522 | palkovsky | 74 | }; |
75 | |||
76 | static int active_console = 0; |
||
77 | |||
1518 | palkovsky | 78 | static void vp_switch(int vp) |
79 | { |
||
1522 | palkovsky | 80 | nsend_call(fbphone,FB_VIEWPORT_SWITCH, vp); |
1518 | palkovsky | 81 | } |
82 | |||
1522 | palkovsky | 83 | /** Create view port */ |
1518 | palkovsky | 84 | static int vp_create(unsigned int x, unsigned int y, |
1522 | palkovsky | 85 | unsigned int width, unsigned int height) |
1518 | palkovsky | 86 | { |
1522 | palkovsky | 87 | /* Init function, use ipc_call_sync */ |
88 | return ipc_call_sync_2(fbphone, FB_VIEWPORT_CREATE, |
||
89 | (x << 16) | y, (width << 16) | height, |
||
90 | NULL, NULL); |
||
1518 | palkovsky | 91 | } |
92 | |||
1522 | palkovsky | 93 | static void clear(void) |
1518 | palkovsky | 94 | { |
1522 | palkovsky | 95 | nsend_call(fbphone, FB_CLEAR, 0); |
1518 | palkovsky | 96 | |
97 | } |
||
98 | |||
1522 | palkovsky | 99 | static void set_style(int fgcolor, int bgcolor) |
1518 | palkovsky | 100 | { |
1522 | palkovsky | 101 | nsend_call_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor); |
1518 | palkovsky | 102 | } |
103 | |||
1522 | palkovsky | 104 | static void putch(char c, int row, int col) |
105 | { |
||
106 | nsend_call_3(fbphone, FB_PUTCHAR, c, row, col); |
||
107 | } |
||
108 | |||
109 | static void draw_stat(int consnum, enum butstate state) |
||
110 | { |
||
111 | char data[5]; |
||
112 | int i; |
||
113 | |||
114 | vp_switch(cstatus_vp[consnum]); |
||
115 | set_style(stat_colors[state].fgcolor, stat_colors[state].bgcolor); |
||
116 | clear(); |
||
1528 | palkovsky | 117 | if (state != CONS_DISCONNECTED) { |
118 | snprintf(data, 5, "%d", consnum+1); |
||
119 | for (i=0;data[i];i++) |
||
120 | putch(data[i], 0, i); |
||
121 | } |
||
1522 | palkovsky | 122 | } |
123 | |||
1518 | palkovsky | 124 | void gcons_change_console(int consnum) |
125 | { |
||
126 | if (!use_gcons) |
||
127 | return; |
||
1522 | palkovsky | 128 | |
129 | draw_stat(active_console, CONS_IDLE); |
||
130 | active_console = consnum; |
||
131 | draw_stat(consnum, CONS_ACTIVE); |
||
1528 | palkovsky | 132 | console_has_input[consnum] = 0; |
133 | |||
1518 | palkovsky | 134 | vp_switch(console_vp); |
135 | } |
||
136 | |||
137 | void gcons_notify_char(int consnum) |
||
138 | { |
||
139 | if (!use_gcons) |
||
140 | return; |
||
141 | |||
1528 | palkovsky | 142 | if (consnum == active_console || console_has_input[consnum]) |
143 | return; |
||
144 | |||
145 | console_has_input[consnum] = 1; |
||
146 | draw_stat(consnum, CONS_HAS_INPUT); |
||
147 | |||
1518 | palkovsky | 148 | vp_switch(console_vp); |
149 | } |
||
150 | |||
1547 | palkovsky | 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; |
||
1522 | palkovsky | 183 | void gcons_redraw_console(void) |
1518 | palkovsky | 184 | { |
1522 | palkovsky | 185 | int i; |
1547 | palkovsky | 186 | size_t hsize = (size_t)&_binary_helenos_ppm_size; |
1522 | palkovsky | 187 | |
1518 | palkovsky | 188 | if (!use_gcons) |
189 | return; |
||
190 | |||
191 | vp_switch(0); |
||
1522 | palkovsky | 192 | set_style(MAIN_COLOR, MAIN_COLOR); |
193 | clear(); |
||
1547 | palkovsky | 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); |
||
1522 | palkovsky | 196 | |
1547 | palkovsky | 197 | |
1522 | palkovsky | 198 | for (i=0;i < CONSOLE_COUNT; i++) |
1528 | palkovsky | 199 | draw_stat(i, i == active_console ? CONS_ACTIVE : CONS_DISCONNECTED); |
1518 | palkovsky | 200 | vp_switch(console_vp); |
201 | } |
||
202 | |||
203 | /** Initialize nice graphical console environment */ |
||
204 | void gcons_init(int phone) |
||
205 | { |
||
206 | int rc; |
||
207 | int i; |
||
208 | |||
209 | fbphone = phone; |
||
210 | |||
211 | rc = ipc_call_sync_2(phone, FB_GET_RESOLUTION, 0, 0, &xres, &yres); |
||
212 | if (rc) |
||
213 | return; |
||
214 | |||
215 | if (xres < 800 || yres < 600) |
||
216 | return; |
||
217 | |||
218 | /* create console viewport */ |
||
219 | console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, xres-2*CONSOLE_MARGIN, |
||
220 | yres-(CONSOLE_TOP+CONSOLE_MARGIN)); |
||
221 | if (console_vp < 0) |
||
222 | return; |
||
223 | |||
224 | /* Create status buttons */ |
||
225 | for (i=0; i < CONSOLE_COUNT; i++) { |
||
1547 | palkovsky | 226 | cstatus_vp[i] = vp_create(STATUS_START+CONSOLE_MARGIN+i*(STATUS_WIDTH+STATUS_SPACE), |
1518 | palkovsky | 227 | CONSOLE_MARGIN, STATUS_WIDTH, STATUS_HEIGHT); |
228 | if (cstatus_vp[i] < 0) |
||
229 | return; |
||
230 | } |
||
231 | |||
232 | use_gcons = 1; |
||
1522 | palkovsky | 233 | gcons_redraw_console(); |
1518 | palkovsky | 234 | } |