diff --git a/src/kernel/boot/platform/bios_ia32/keyboard.cpp b/src/kernel/boot/platform/bios_ia32/keyboard.cpp new file mode 100644 index 0000000000..bbdae64d05 --- /dev/null +++ b/src/kernel/boot/platform/bios_ia32/keyboard.cpp @@ -0,0 +1,76 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include "keyboard.h" +#include "bios.h" + +#include + + +/** Note, checking for keys doesn't seem to work in graphics + * mode, at least in Bochs. + */ + +static uint16 +check_for_key(void) +{ + bios_regs regs; + regs.eax = 0x0100; + call_bios(0x16, ®s); + + // the zero flag is set when there is no key stroke waiting for us + if (regs.flags & ZERO_FLAG) + return 0; + + // remove the key from the buffer + regs.eax = 0; + call_bios(0x16, ®s); + + return regs.eax & 0xffff; +} + + +extern "C" union key +wait_for_key(void) +{ + bios_regs regs; + regs.eax = 0; + call_bios(0x16, ®s); + + union key key; + key.ax = regs.eax & 0xffff; + + return key; +} + + +extern "C" uint32 +check_for_boot_keys(void) +{ + union key key; + uint32 options = 0; + + while ((key.ax = check_for_key()) != 0) { + dprintf("pressed %lx\n", key.ax); + switch (key.code.ascii) { + case ' ': + options |= BOOT_OPTION_MENU; + break; + case 0x1b: // escape + options |= BOOT_OPTION_DEBUG_OUTPUT; + break; + case 0: + // evaluate BIOS scan codes + // ... + break; + } + } + + dprintf("options = %ld\n", options); + panic("\n"); + return options; +} + diff --git a/src/kernel/boot/platform/bios_ia32/keyboard.h b/src/kernel/boot/platform/bios_ia32/keyboard.h new file mode 100644 index 0000000000..7978bdcd89 --- /dev/null +++ b/src/kernel/boot/platform/bios_ia32/keyboard.h @@ -0,0 +1,36 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + + +#include + + +union key { + uint16 ax; + struct { + uint8 ascii; + uint8 bios; + } code; +}; + +#define BIOS_KEY_UP 0x48 +#define BIOS_KEY_DOWN 0x50 +#define BIOS_KEY_LEFT 0x4b +#define BIOS_KEY_RIGHT 0x4d +#define BIOS_KEY_HOME 0x47 +#define BIOS_KEY_END 0x4f +#define BIOS_KEY_PAGE_UP 0x49 +#define BIOS_KEY_PAGE_DOWN 0x51 + +#ifdef __cplusplus +extern "C" { +#endif + +extern union key wait_for_key(void); +extern uint32 check_for_boot_keys(void); + +#ifdef __cplusplus +} +#endif + +#endif /* KEYBOARD_H */