Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / zde / kbd.c
blob4ba2d3236498419b034e195d8abe24d41c94b85d
1 /*
2 * ZeX/OS
3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
24 #include "kbd.h"
27 unsigned char kbd_us[128] =
29 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
30 '9', '0', '-', '=', '\b', /* Backspace */
31 '\t', /* Tab */
32 'q', 'w', 'e', 'r', /* 19 */
33 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
34 0, /* 29 - Control */
35 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
36 '\'', '`', 0, /* Left shift */
37 '\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
38 'm', ',', '.', '/', 0, /* Right shift */
39 '*',
40 0, /* Alt */
41 ' ', /* Space bar */
42 0, /* Caps lock */
43 0, /* 59 - F1 key ... > */
44 0, 0, 0, 0, 0, 0, 0, 0,
45 0, /* < ... F10 */
46 0, /* 69 - Num lock*/
47 0, /* Scroll Lock */
48 0, /* Home key */
49 0, /* Up Arrow */
50 0, /* Page Up */
51 '-',
52 0, /* Left Arrow */
54 0, /* Right Arrow */
55 '+',
56 0, /* 79 - End key*/
57 0, /* Down Arrow */
58 0, /* Page Down */
59 0, /* Insert Key */
60 0, /* Delete Key */
61 0, 0, 0,
62 0, /* F11 Key */
63 0, /* F12 Key */
64 0, /* All other keys are undefined */
67 static char kbd_buffer[KBD_BUFFER_LEN];
68 static unsigned char kbd_buffer_pos;
70 unsigned char kbd_getkey ()
72 if (kbd_buffer_pos > 0)
73 kbd_buffer_pos --;
75 unsigned char c = kbd_buffer[kbd_buffer_pos];
77 kbd_buffer[kbd_buffer_pos] = '\0';
79 return c;
82 void kbd_update ()
84 int scancode = getkey ();
86 /*if (scancode == keycode)
87 return 1;
89 if (scancode == keycode+128)
90 return 2;
91 else
92 return 0;*/
94 /* KP_DOWN */
95 if (scancode >= 128 && kbd_buffer_pos < KBD_BUFFER_LEN) {
96 kbd_buffer[kbd_buffer_pos] = kbd_us[scancode - 128];
97 kbd_buffer_pos ++;
101 int init_kbd ()
103 /* set socket "1" to non-blocking */
104 /*int oldFlag = fcntl (1, F_GETFL, 0);
105 if (fcntl (1, F_SETFL, oldFlag | O_NONBLOCK) == -1) {
106 printf ("Cant set socket to nonblocking mode\n");
107 return -1;
110 kbd_buffer_pos = 0;
111 memset (kbd_buffer, 0, KBD_BUFFER_LEN);
113 return 0;