boot_loader_openfirmware: Enable boot options by keyboard
Introduce a non-blocking function for checking keyboard input, and refactor existing code to share the escape key translations. The comment that key-up and key-down result in a zero char is confirmed to apply. If the space bar is pressed, enter the boot menu. If the escape key is pressed, disable the frame buffer and keep showing the usual debug output. Apparently the key press must come after console/keyboard initialization but before the "Welcome to the Haiku bootloader!" line. Closes ticket #6140. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38304 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -291,6 +291,31 @@ console_set_color(int32 foreground, int32 background)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
translate_key(char escapeCode)
|
||||||
|
{
|
||||||
|
switch (escapeCode) {
|
||||||
|
case 65:
|
||||||
|
return TEXT_CONSOLE_KEY_UP;
|
||||||
|
case 66:
|
||||||
|
return TEXT_CONSOLE_KEY_DOWN;
|
||||||
|
case 67:
|
||||||
|
return TEXT_CONSOLE_KEY_RIGHT;
|
||||||
|
case 68:
|
||||||
|
return TEXT_CONSOLE_KEY_LEFT;
|
||||||
|
// TODO: Translate the codes for the following keys. Unfortunately my OF just
|
||||||
|
// returns a '\0' character. :-/
|
||||||
|
// TEXT_CONSOLE_KEY_PAGE_UP,
|
||||||
|
// TEXT_CONSOLE_KEY_PAGE_DOWN,
|
||||||
|
// TEXT_CONSOLE_KEY_HOME,
|
||||||
|
// TEXT_CONSOLE_KEY_END,
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
console_wait_for_key(void)
|
console_wait_for_key(void)
|
||||||
{
|
{
|
||||||
@@ -304,26 +329,10 @@ console_wait_for_key(void)
|
|||||||
} while (bytesRead == 0);
|
} while (bytesRead == 0);
|
||||||
|
|
||||||
// translate the ESC sequences for cursor keys
|
// translate the ESC sequences for cursor keys
|
||||||
if (bytesRead == 3 && buffer[0] == 27 && buffer [1] == 91) {
|
if (bytesRead == 3 && buffer[0] == 27 && buffer[1] == 91) {
|
||||||
switch (buffer[2]) {
|
int key = translate_key(buffer[2]);
|
||||||
case 65:
|
if (key != 0)
|
||||||
return TEXT_CONSOLE_KEY_UP;
|
return key;
|
||||||
case 66:
|
|
||||||
return TEXT_CONSOLE_KEY_DOWN;
|
|
||||||
case 67:
|
|
||||||
return TEXT_CONSOLE_KEY_RIGHT;
|
|
||||||
case 68:
|
|
||||||
return TEXT_CONSOLE_KEY_LEFT;
|
|
||||||
// TODO: Translate the codes for the following keys. Unfortunately my OF just
|
|
||||||
// returns a '\0' character. :-/
|
|
||||||
// TEXT_CONSOLE_KEY_PAGE_UP,
|
|
||||||
// TEXT_CONSOLE_KEY_PAGE_DOWN,
|
|
||||||
// TEXT_CONSOLE_KEY_HOME,
|
|
||||||
// TEXT_CONSOLE_KEY_END,
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// put back unread chars
|
// put back unread chars
|
||||||
@@ -333,3 +342,25 @@ console_wait_for_key(void)
|
|||||||
return buffer[0];
|
return buffer[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
console_check_for_key(void)
|
||||||
|
{
|
||||||
|
char buffer[3];
|
||||||
|
ssize_t bytesRead = sInput.ReadAt(NULL, 0, buffer, 3);
|
||||||
|
if (bytesRead <= 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// translate the ESC sequences for cursor keys
|
||||||
|
if (bytesRead == 3 && buffer[0] == 27 && buffer[1] == 91) {
|
||||||
|
int key = translate_key(buffer[2]);
|
||||||
|
if (key != 0)
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
// put back unread chars
|
||||||
|
if (bytesRead > 1)
|
||||||
|
sInput.PutChars(buffer + 1, bytesRead - 1);
|
||||||
|
|
||||||
|
return buffer[0];
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern status_t console_init(void);
|
extern status_t console_init(void);
|
||||||
|
extern int console_check_for_key(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ extern uint8 __bss_start;
|
|||||||
extern uint8 _end;
|
extern uint8 _end;
|
||||||
|
|
||||||
uint32 gMachine;
|
uint32 gMachine;
|
||||||
|
static uint32 sBootOptions;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -111,8 +112,7 @@ platform_exit(void)
|
|||||||
extern "C" uint32
|
extern "C" uint32
|
||||||
platform_boot_options(void)
|
platform_boot_options(void)
|
||||||
{
|
{
|
||||||
// ToDo: implement me!
|
return sBootOptions;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -163,6 +163,17 @@ start(void *openFirmwareEntry)
|
|||||||
if (init_real_time_clock() != B_OK)
|
if (init_real_time_clock() != B_OK)
|
||||||
of_exit();
|
of_exit();
|
||||||
|
|
||||||
|
// check for key presses once
|
||||||
|
sBootOptions = 0;
|
||||||
|
int key = console_check_for_key();
|
||||||
|
if (key == 32) {
|
||||||
|
// space bar: option menu
|
||||||
|
sBootOptions |= BOOT_OPTION_MENU;
|
||||||
|
} else if (key == 27) {
|
||||||
|
// ESC: debug output
|
||||||
|
sBootOptions |= BOOT_OPTION_DEBUG_OUTPUT;
|
||||||
|
}
|
||||||
|
|
||||||
gKernelArgs.platform_args.openfirmware_entry = openFirmwareEntry;
|
gKernelArgs.platform_args.openfirmware_entry = openFirmwareEntry;
|
||||||
|
|
||||||
main(&args);
|
main(&args);
|
||||||
|
|||||||
Reference in New Issue
Block a user