xref: /haiku/src/system/boot/platform/bios_ia32/keyboard.cpp (revision d374a27286b8a52974a97dba0d5966ea026a665d)
1 /*
2  * Copyright 2004-2010, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT 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 static uint16
17 check_for_key(void)
18 {
19 	bios_regs regs;
20 	regs.eax = 0x0100;
21 	call_bios(0x16, &regs);
22 
23 	// the zero flag is set when there is no key stroke waiting for us
24 	if (regs.flags & ZERO_FLAG)
25 		return 0;
26 
27 	// remove the key from the buffer
28 	regs.eax = 0;
29 	call_bios(0x16, &regs);
30 
31 	return regs.eax & 0xffff;
32 }
33 
34 
35 extern "C" void
36 clear_key_buffer(void)
37 {
38 	while (check_for_key() != 0)
39 		;
40 }
41 
42 
43 extern "C" union key
44 wait_for_key(void)
45 {
46 	bios_regs regs;
47 	regs.eax = 0;
48 	call_bios(0x16, &regs);
49 
50 	union key key;
51 	key.ax = regs.eax & 0xffff;
52 
53 	return key;
54 }
55 
56 
57 extern "C" uint32
58 check_for_boot_keys(void)
59 {
60 	bios_regs regs;
61 	uint32 options = 0;
62 	uint32 keycode = 0;
63 	regs.eax = 0x0200;
64 	call_bios(0x16, &regs);
65 		// Read Keyboard flags. bit 0 LShift, bit 1 RShift
66 	if ((regs.eax & 0x03) != 0) {
67 		// LShift or RShift - option menu
68 		options |= BOOT_OPTION_MENU;
69 	} else {
70 		keycode = boot_key_in_keyboard_buffer();
71 		if (keycode == 0x3920) {
72 			// space - option menu
73 			options |= BOOT_OPTION_MENU;
74 		} else if (keycode == 0x011B) {
75 			// ESC - debug output
76 			options |= BOOT_OPTION_DEBUG_OUTPUT;
77  		}
78 	}
79 
80 	dprintf("options = %ld\n", options);
81 	return options;
82 }
83 
84