OSDN Git Service

new file: 16/v2/CONSOLE.TXT
[proj16/16.git] / 16 / v2 / source / verge / MAPED / KEYBOARD.C
1 /*\r
2 Copyright (C) 1998 BJ Eirich (aka vecna)\r
3 This program is free software; you can redistribute it and/or\r
4 modify it under the terms of the GNU General Public License\r
5 as published by the Free Software Foundation; either version 2\r
6 of the License, or (at your option) any later version.\r
7 This program is distributed in the hope that it will be useful,\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
10 See the GNU General Public Lic\r
11 See the GNU General Public License for more details.\r
12 You should have received a copy of the GNU General Public License\r
13 along with this program; if not, write to the Free Software\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
15 */\r
16 \r
17 #include <stdio.h>\r
18 #include <conio.h>\r
19 #include <dos.h>\r
20 #include "timer.h"\r
21 \r
22 // ================================= Data ====================================\r
23 \r
24 char key[128];\r
25 char keycode,last_pressed=0;\r
26 char codeBuffer[16];\r
27 void (__interrupt __far *biosKeyboardHandler)();\r
28 char handlerinstalled=0;\r
29 \r
30 unsigned char key_ascii_tbl[128] =\r
31 {\r
32    0,   0,   '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 8,   9,\r
33    'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 13,  0,   'a', 's',\r
34    'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 39,  0,   0,   92,  'z', 'x', 'c', 'v',\r
35    'b', 'n', 'm', ',', '.', '/', 0,   '*', 0,   ' ', 0,   3,   3,   3,   3,   8,\r
36    3,   3,   3,   3,   3,   0,   0,   0,   0,   0,   '-', 0,   0,   0,   '+', 0,\r
37    0,   0,   0,   127, 0,   0,   92,  3,   3,   0,   0,   0,   0,   0,   0,   0,\r
38    13,  0,   '/', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   127,\r
39    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   '/', 0,   0,   0,   0,   0\r
40 };\r
41 \r
42 unsigned char key_shift_tbl[128] =\r
43 {\r
44    0,   0,   '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 126, 126,\r
45    'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 126, 0,   'A', 'S',\r
46    'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', 34,  0,   0,   '|', 'Z', 'X', 'C', 'V',\r
47    'B', 'N', 'M', '<', '>', '?', 0,   '*', 0,   1,   0,   1,   1,   1,   1,   1,\r
48    1,   1,   1,   1,   1,   0,   0,   0,   0,   0,   '-', 0,   0,   0,   '+', 0,\r
49    0,   0,   1,   127, 0,   0,   0,   1,   1,   0,   0,   0,   0,   0,   0,   0,\r
50    13,  0,   '/', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   127,\r
51    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   '/', 0,   0,   0,   0,   0\r
52 };\r
53 \r
54 // ================================= Data ====================================\r
55 \r
56 void __interrupt __far KeyboardHandler()\r
57 {\r
58   keycode=inp(0x60);\r
59   if (keycode>128)\r
60      key[keycode-128]=0;\r
61   else\r
62   {\r
63     key[keycode]=1;\r
64     last_pressed=keycode;\r
65   }\r
66   idlect=0;\r
67   outp(0x20,0x20);\r
68 }\r
69 \r
70 void InitKeyboard()\r
71 {\r
72   if (handlerinstalled) return;\r
73 \r
74   biosKeyboardHandler=_dos_getvect(0x09);\r
75   _dos_setvect(0x09, KeyboardHandler);\r
76   handlerinstalled=1;\r
77 }\r
78 \r
79 void ShutdownKeyboard()\r
80 {\r
81   if (handlerinstalled)\r
82      _dos_setvect(0x09, biosKeyboardHandler);\r
83   handlerinstalled=0;\r
84 }\r