1 |
/* ofconsole.c -- Open Firmware console for GRUB. */ |
/* ofconsole.c -- Open Firmware console for GRUB. */ |
2 |
/* |
/* |
3 |
* GRUB -- GRand Unified Bootloader |
* GRUB -- GRand Unified Bootloader |
4 |
* Copyright (C) 2003, 2004 Free Software Foundation, Inc. |
* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. |
5 |
* |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
120 |
grub_ofconsole_readkey (int *key) |
grub_ofconsole_readkey (int *key) |
121 |
{ |
{ |
122 |
char c; |
char c; |
123 |
int actual = 0; |
grub_ssize_t actual = 0; |
124 |
|
|
125 |
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); |
grub_ieee1275_read (stdin_ihandle, &c, 1, &actual); |
126 |
|
|
207 |
return ((grub_curr_x - 1) << 8) | grub_curr_y; |
return ((grub_curr_x - 1) << 8) | grub_curr_y; |
208 |
} |
} |
209 |
|
|
210 |
|
static grub_uint16_t |
211 |
|
grub_ofconsole_getwh (void) |
212 |
|
{ |
213 |
|
grub_ieee1275_ihandle_t options; |
214 |
|
char *val; |
215 |
|
grub_ssize_t lval; |
216 |
|
static grub_uint8_t w, h; |
217 |
|
|
218 |
|
/* Once we have them, don't ask them again. */ |
219 |
|
if (!w || !h) |
220 |
|
{ |
221 |
|
if (! grub_ieee1275_finddevice ("/options", &options) |
222 |
|
&& options != -1) |
223 |
|
{ |
224 |
|
if (! grub_ieee1275_get_property_length (options, "screen-#columns", |
225 |
|
&lval) && lval != -1) |
226 |
|
{ |
227 |
|
val = grub_malloc (lval); |
228 |
|
if (val) |
229 |
|
{ |
230 |
|
if (! grub_ieee1275_get_property (options, "screen-#columns", |
231 |
|
val, lval, 0)) |
232 |
|
w = (grub_uint8_t) grub_strtoul (val, val + lval, 10); |
233 |
|
|
234 |
|
grub_free (val); |
235 |
|
} |
236 |
|
} |
237 |
|
if (! grub_ieee1275_get_property_length (options, "screen-#rows", |
238 |
|
&lval) && lval != -1) |
239 |
|
{ |
240 |
|
val = grub_malloc (lval); |
241 |
|
if (val) |
242 |
|
{ |
243 |
|
if (! grub_ieee1275_get_property (options, "screen-#rows", |
244 |
|
val, lval, 0)) |
245 |
|
h = (grub_uint8_t) grub_strtoul (val, val + lval, 10); |
246 |
|
|
247 |
|
grub_free (val); |
248 |
|
} |
249 |
|
} |
250 |
|
} |
251 |
|
} |
252 |
|
|
253 |
|
/* Use a small console by default. */ |
254 |
|
if (! w) |
255 |
|
w = 80; |
256 |
|
if (! h) |
257 |
|
h = 24; |
258 |
|
|
259 |
|
return (w << 8) | h; |
260 |
|
} |
261 |
|
|
262 |
static void |
static void |
263 |
grub_ofconsole_gotoxy (grub_uint8_t x, grub_uint8_t y) |
grub_ofconsole_gotoxy (grub_uint8_t x, grub_uint8_t y) |
264 |
{ |
{ |
293 |
static grub_err_t |
static grub_err_t |
294 |
grub_ofconsole_init (void) |
grub_ofconsole_init (void) |
295 |
{ |
{ |
296 |
char data[4]; |
unsigned char data[4]; |
297 |
grub_size_t actual; |
grub_ssize_t actual; |
298 |
int col; |
int col; |
299 |
|
|
300 |
if (grub_ieee1275_get_property (grub_ieee1275_chosen, "stdout", data, |
if (grub_ieee1275_get_property (grub_ieee1275_chosen, "stdout", data, |
339 |
.checkkey = grub_ofconsole_checkkey, |
.checkkey = grub_ofconsole_checkkey, |
340 |
.getkey = grub_ofconsole_getkey, |
.getkey = grub_ofconsole_getkey, |
341 |
.getxy = grub_ofconsole_getxy, |
.getxy = grub_ofconsole_getxy, |
342 |
|
.getwh = grub_ofconsole_getwh, |
343 |
.gotoxy = grub_ofconsole_gotoxy, |
.gotoxy = grub_ofconsole_gotoxy, |
344 |
.cls = grub_ofconsole_cls, |
.cls = grub_ofconsole_cls, |
345 |
.setcolorstate = grub_ofconsole_setcolorstate, |
.setcolorstate = grub_ofconsole_setcolorstate, |