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