1 /* 2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 ** Distributed under the terms of the OpenBeOS License. 4 */ 5 6 7 #include "keyboard.h" 8 #include "bios.h" 9 10 #include <boot/platform.h> 11 12 13 /** Note, checking for keys doesn't seem to work in graphics 14 * mode, at least in Bochs. 15 */ 16 17 static uint16 18 check_for_key(void) 19 { 20 bios_regs regs; 21 regs.eax = 0x0100; 22 call_bios(0x16, ®s); 23 24 // the zero flag is set when there is no key stroke waiting for us 25 if (regs.flags & ZERO_FLAG) 26 return 0; 27 28 // remove the key from the buffer 29 regs.eax = 0; 30 call_bios(0x16, ®s); 31 32 return regs.eax & 0xffff; 33 } 34 35 36 extern "C" void 37 clear_key_buffer(void) 38 { 39 while (check_for_key() != 0) 40 ; 41 } 42 43 44 extern "C" union key 45 wait_for_key(void) 46 { 47 bios_regs regs; 48 regs.eax = 0; 49 call_bios(0x16, ®s); 50 51 union key key; 52 key.ax = regs.eax & 0xffff; 53 54 return key; 55 } 56 57 58 extern "C" uint32 59 check_for_boot_keys(void) 60 { 61 bios_regs regs; 62 uint32 options = 0; 63 uint32 keycode = 0; 64 regs.eax = 0x0200; 65 call_bios(0x16, ®s); 66 // Read Keyboard flags. bit 0 LShift, bit 1 RShift 67 if ((regs.eax & 0x03) != 0) { 68 // LShift or RShift - option menu 69 options |= BOOT_OPTION_MENU; 70 } else { 71 keycode = search_keyboard_buffer(); 72 if (keycode == 0x4200 || keycode == 0x8600 || keycode == 0x3920) { 73 // F8 or F12 or Space - option menu 74 options |= BOOT_OPTION_MENU; 75 } else if (keycode == 0x011B) { 76 // ESC - debug output 77 options |= BOOT_OPTION_DEBUG_OUTPUT; 78 } 79 } 80 81 dprintf("options = %ld\n", options); 82 return options; 83 } 84 85