Part 1 - Tarleton State University

Part 1 - Tarleton State University
CS 380 – Lab 4 Keyboard Input
Assigned 2/11/10
30 Points
In this lab we will see how a kernel can get data from the keyboard. We will adapt code
to allow us to perform a number of important operations.
Part 1
Keyboards support one or more of three broad keyboard types. Each type has a value
assigned to each key. These values are called scan codes. The default scan code
supported by all modern keyboards is the Scan Code Set 2. The mapping for scan codes
1 and 2 are found in appendices A and B.
The INTEL 8042 microcontroller converts electrical signals from the keyboard and
generates a series of make and break codes for each key. A make code is generated
whenever a key is pressed. A break code is generated whenever a key is released. A
repeat code is also generated when a key is held down longer than the typematic delay.
We need to get the make code in order to determine which key/character was pressed. In
addition, we need to know the state of the keyboard. For example, if the A key was
pressed, was it pressed in combination with the shift or alt keys.
Most make and break codes are one byte long. However, other codes are 2 to 4 bytes
long. These longer make codes start with an E0, E1, or F0. Single byte break codes
always have the most significant bit set to a 1.
Getting a Scan Code
Scan codes are obtained through interrupts or by polling. Since we haven’t set up
interrupts yet. We will need to use polling. To get a scan code from the INTEL 8042, the
byte is read from port 0x60.
The byte may or not be ready to be read. In order to determine if the scan code is ready
to be read, port 0x64 is read and the least significant bit is checked. If the bit is a zero
then the scan code is not ready to be read. If the bit is a one then the scan code can be
read from port 0x60. To read a byte from a port use the following function which uses
inline assembly code:
inline unsigned char inportb(unsigned short port) {
unsigned char ret_val;
asm volatile("inb %w1,%b0"
: "=a"(ret_val)
1
: "d"(port));
return ret_val;
};
Exercise
Add the following functions to your kernel from Lab 3:
Function
void putChar(char c);
Purpose
Displays a character at the current cursor
position and advance the cursor by one
position.
Returns a scan code form the keyboard
char getScanCode();
Test these function in your kernel. When the user enters a character don’t try to display
that character. Instead, display a single character such as the pound symbol.
Part 2
Scan codes are nice but need to be converted to determine what is the actual character.
The table in Appendices A and B hints at how a function could be written to convert scan
codes to characters. However, two functions have been provided to assist in this process:
ScanCode2Ascii – Converts scan codes to a short number
SetsKybdState – Sets up the “state” of the keyboard
These two functions and related declarations are found in Appendix C.
Exercise
Incorporate these functions into your kernel so that you are able to read and display
common ASCII characters. The general process will be to:
1)
2)
3)
4)
5)
Use getScanCode to get a scan code
Use SetsKybdState with the scan code to set the state
Check to see of the scan code is a break code, if so ignore it
Use ScanCode2Ascii to convert a valid scan code to a short value
Extract the ASCII character and display it using putChar
2
Appendix A - Keyboard Scan Codes: Set 1
Source:
http://panda.cs.ndsu.nodak.edu/%7Eachapwes/PICmicro/keyboard/scancodes1.html
*All values are in hexadecimal
101-, 102-, and 104-key keyboards:
KE MAK BREA ---KEY
Y
E
K
MAKE
BREA ---MAK BREA
KEY
K
E
K
A
1E
9E
9
0A
8A
B
30
B0
`
29
89
C
2E
AE
-
0C
8C
D
20
A0
=
0D
E
12
92
\
F
21
A1
G
22
H
[
1A
INSER
E0,52
T
HOME
9A
E0,D2
E0,47
E0,97
8D
PG UP E0,49
E0,C9
2B
AB
DELET
E0,53
E
E0,D3
BKSP
0E
8E
A2
SPACE
39
B9
23
A3
TAB
0F
8F
I
17
97
CAPS
3A
BA
J
24
A4
2A
AA
K
25
A5
1D
9D
L
26
A6
L GUI
E0,5B
E0,DB
M
32
B2
L ALT
38
N
31
B1
O
18
98
P
19
99
Q
10
R
END
E0,4F
E0,CF
PG DN E0,51
E0,D1
U
ARROW
L
ARROW
D
ARROW
R
ARROW
E0,48
E0,C8
E0,4B
E0,CB
E0,50
E0,D0
E0,4D
E0,CD
NUM
45
C5
B8
KP /
E0,35
E0,B5
36
B6
KP *
37
B7
E0,1D
E0,9D
KP -
4A
CA
R GUI
E0,5C
E0,DC
KP +
4E
CE
19
R ALT
E0,38
E0,B8
13
93
APPS
E0,5D
E0,DD
KP .
53
D3
S
1F
9F
ENTER
1C
9C
KP 0
52
D2
T
14
94
ESC
01
81
KP 1
4F
CF
U
16
96
F1
3B
BB
KP 2
50
D0
V
2F
AF
F2
3C
BC
KP 3
51
D1
W
11
91
F3
3D
BD
KP 4
4B
CB
L
SHFT
L
CTRL
R
SHFT
R
CTRL
3
KP EN E0,1C
E0,9C
X
2D
AD
F4
3E
BE
KP 5
4C
CC
Y
15
95
F5
3F
BF
KP 6
4D
CD
Z
2C
AC
F6
40
C0
KP 7
47
C7
0
0B
8B
F7
41
C1
KP 8
48
C8
1
02
82
F8
42
C2
KP 9
49
C9
2
03
83
F9
43
C3
]
1B
9B
3
04
84
F10
44
C4
;
27
A7
4
05
85
F11
57
D7
'
28
A8
5
06
86
F12
58
D8
,
33
B3
6
07
87
PRNT
SCRN
E0,2A,
E0,37
E0,B7
,
E0,AA
.
34
B4
7
08
88
SCROL
L
46
C6
/
35
B5
89
E1,1D,4
5
PAUSE
-NONEE1,9D,C
5
8
09
ACPI Scan Codes:
Key
Make Code Break Code
Power E0, 5E
E0, DE
Sleep E0, 5F
E0, DF
Wake E0, 63
E0, E3
Windows Multimedia Scan Codes:
Key
Make Code Break Code
Next Track
E0, 19
E0, 99
Previous Track
E0, 10
E0, 90
Stop
E0, 24
E0, A4
Play/Pause
E0, 22
E0, A2
Mute
E0, 20
E0, A0
Volume Up
E0, 30
E0, B0
Volume Down
E0, 2E
E0, AE
Media Select
E0, 6D
E0, ED
E-Mail
E0, 6C
E0, EC
Calculator
E0, 21
E0, A1
My Computer
E0, 6B
E0, EB
4
WWW Search
E0, 65
E0, E5
WWW Home
E0, 32
E0, B2
WWW Back
E0, 6A
E0, EA
WWW Forward E0, 69
E0, E9
WWW Stop
E0, 68
E0, E8
WWW Refresh
E0, 67
E0, E7
WWW Favorites E0, 66
E0, E6
5
Appendix B - Keyboard Scan Codes: Set 2
*All values are in hexadecimal
101-, 102-, and 104-key keyboards:
KE MAK BREA ---KEY
Y
E
K
MAKE
BREAK
---MAK
KEY
BREAK
E
A
1C
F0,1C
9
46
F0,46
B
32
F0,32
`
0E
F0,0E
C
21
F0,21
-
4E
F0,4E
D
23
F0,23
=
55
FO,55
E
24
F0,24
\
5D
F0,5D
F
2B
F0,2B
BKSP
66
F0,66
G
34
F0,34
SPACE
29
F0,29
H
33
F0,33
TAB
0D
F0,0D
I
43
F0,43
CAPS
58
F0,58
J
3B
F0,3B
12
FO,12
K
42
F0,42
14
FO,14
L
4B
F0,4B
L GUI
E0,1F
E0,F0,1
F
NUM
77
F0,77
M
3A
F0,3A
L ALT
11
F0,11
KP /
E0,4A
E0,F0,4
A
N
31
F0,31
59
F0,59
KP *
7C
F0,7C
O
44
F0,44
KP -
7B
F0,7B
P
4D
F0,4D
R GUI
E0,27
KP +
79
F0,79
Q
15
F0,15
R ALT
E0,11
R
2D
F0,2D
APPS
E0,2F
S
T
U
V
1B
2C
3C
2A
F0,1B
F0,2C
F0,3C
F0,2A
ENTER
ESC
F1
F2
5A
76
05
06
L
SHFT
L
CTRL
R
SHFT
R
CTRL
E0,14
6
E0,F0,1
4
E0,F0,2
7
E0,F0,1
1
E0,F0,2
F
F0,5A
F0,76
F0,05
F0,06
[
54
FO,54
INSER
E0,F0,7
E0,70
T
0
E0,F0,6
HOME E0,6C
C
E0,F0,7
PG UP E0,7D
D
DELET
E0,F0,7
E0,71
E
1
E0,F0,6
END E0,69
9
E0,F0,7
PG DN E0,7A
A
U
E0,F0,7
E0,75
ARROW
5
L
E0,F0,6
E0,6B
ARROW
B
D
E0,F0,7
E0,72
ARROW
2
R
E0,F0,7
E0,74
ARROW
4
KP EN E0,5A
E0,F0,5
A
KP .
71
F0,71
KP
KP
KP
KP
70
69
72
7A
F0,70
F0,69
F0,72
F0,7A
0
1
2
3
W
X
Y
Z
0
1
2
3
4
5
1D
22
35
1A
45
16
1E
26
25
2E
F0,1D
F0,22
F0,35
F0,1A
F0,45
F0,16
F0,1E
F0,26
F0,25
F0,2E
F3
F4
F5
F6
F7
F8
F9
F10
F11
F12
04
0C
03
0B
83
0A
01
09
78
07
6
36
F0,36
PRNT
SCRN
E0,12,
E0,7C
7
3D
F0,3D
SCROL
L
7E
F0,3E
E1,14,77
,
PAUSE E1,F0,14
,
F0,77
8
3E
ACPI Scan Codes:
Key
Make Code Break Code
Power E0, 37
E0, F0, 37
Sleep E0, 3F
E0, F0, 3F
Wake E0, 5E
E0, F0, 5E
Windows Multimedia Scan Codes:
Key
Make Code Break Code
Next Track
E0, 4D
E0, F0, 4D
Previous Track
E0, 15
E0, F0, 15
Stop
E0, 3B
E0, F0, 3B
Play/Pause
E0, 34
E0, F0, 34
Mute
E0, 23
E0, F0, 23
Volume Up
E0, 32
E0, F0, 32
Volume Down
E0, 21
E0, F0, 21
Media Select
E0, 50
E0, F0, 50
E-Mail
E0, 48
E0, F0, 48
7
F0,04
F0,0C
F0,03
F0,0B
F0,83
F0,0A
F0,01
F0,09
F0,78
F0,07
E0,F0,
7C,E0,
F0,12
KP
KP
KP
KP
KP
KP
]
;
'
,
F0,7E
-NONE-
4
5
6
7
8
9
6B
73
74
6C
75
7D
5B
4C
52
41
F0,6B
F0,73
F0,74
F0,6C
F0,75
F0,7D
F0,5B
F0,4C
F0,52
F0,41
.
49
F0,49
/
4A
F0,4A
Calculator
E0, 2B
E0, F0, 2B
My Computer
E0, 40
E0, F0, 40
WWW Search
E0, 10
E0, F0, 10
WWW Home
E0, 3A
E0, F0, 3A
WWW Back
E0, 38
E0, F0, 38
WWW Forward E0, 30
E0, F0, 30
WWW Stop
E0, 28
E0, F0, 28
WWW Refresh
E0, 20
E0, F0, 20
WWW Favorites E0, 18
E0, F0, 18
8
Appendix C
/* ============================================================
This code is adapted from the keyboard GCC files
============================================================ */
typedef int
typedef unsigned char
typedef unsigned short int
typedef unsigned long int
#definePRIVATE
static
#ifndef TRUE
#defineTRUE
#endif
#ifndef FALSE
#defineFALSE
#endif
BOOL;
BYTE8;
WORD16;
DWORD32;
1
0
#defineENTRIES(a) (sizeof(a)/sizeof(a[0]))
typedef struct STATE
{
BOOL ins
;
BOOL rshift ;
BOOL lshift ;
BOOL alt
;
BOOL ctrl
;
BOOL caps ;
BOOL scrl
;
BOOL num ;
} __attribute__((packed)) STATE ;
#defineKYBD_STS_PORT 0x64
#defineKYBD_DAT_PORT 0x60
#defineKYBD_DAT_RDY
#defineBREAK_CODE
0x01
0x80
#defineSIZE 20
PRIVATE STATE state ; /* Initialized to all FALSE by loader */
9
PRIVATE BYTE8
PRIVATE unsigned int
PRIVATE unsigned int
PRIVATE unsigned int
scan_codes[SIZE] ;
nq = 0 ;
dq = 0 ;
count = 0 ;
/* -------------------------------------------------------------------------------------- */
/* Scan code translation table.
*/
/* The incoming scan code from the keyboard selects a row.
*/
/* The modifier status selects the column.
*/
/* The word at the intersection of the two is the scan/ASCII code to
*/
/* put into the PC's type ahead buffer.
*/
/* If the value fetched from the table is zero, then we do not put the
*/
/* character into the type ahead buffer.
*/
/* -------------------------------------------------------------------------------------- */
PRIVATE WORD16 scan_ascii[][8] =
{
/* norm, shft,
ctrl,
/*--*/
{0x0000, 0x0000, 0x0000,
/*ESC*/
{0x011B, 0x011B, 0x011B,
/*1 !*/
{0x0231, 0x0221, 0x0000,
/*2 @*/
{0x0332, 0x0340, 0x0300,
/*3 #*/
{0x0433, 0x0423, 0x0000,
/*4 $*/
{0x0534, 0x0524, 0x0000,
/*5 %*/
{0x0635, 0x0625, 0x0000,
/*6 ^*/
{0x0736, 0x075E, 0x071E,
/*7 &*/
{0x0837, 0x0826, 0x0000,
/*8 **/
{0x0938, 0x092A, 0x0000,
/*9 (*/
{0x0A39, 0x0A28, 0x0000,
/*0 )*/
{0x0B30, 0x0B29, 0x0000,
/*- _*/
{0x0C2D, 0x0C5F, 0x0000,
/*= +*/
{0x0D3D, 0x0D2B, 0x0000,
/*bksp*/
{0x0E08, 0x0E08, 0x0E7F,
/*Tab*/
{0x0F09, 0x0F00, 0x0000,
/*Q*/
{0x1071, 0x1051, 0x1011,
/*W*/
{0x1177, 0x1057, 0x1017,
/*E*/
{0x1265, 0x1245, 0x1205,
/*R*/
{0x1372, 0x1352, 0x1312,
/*T*/
{0x1474, 0x1454, 0x1414,
/*Y*/
{0x1579, 0x1559, 0x1519,
/*U*/
{0x1675, 0x1655, 0x1615,
/*I*/
{0x1769, 0x1749, 0x1709,
/*O*/
{0x186F, 0x184F, 0x180F,
/*P*/
{0x1970, 0x1950, 0x1910,
/*[ {*/
{0x1A5B, 0x1A7B, 0x1A1B,
/*] }*/
{0x1B5D, 0x1B7D, 0x1B1D,
/*entr*/
{0x1C0D, 0x1C0D, 0x1C0A,
/*ctrl*/
{0x1D00, 0x1D00, 0x1D00,
/*A*/
{0x1E61, 0x1E41, 0x1E01,
/*S*/
{0x1F73, 0x1F53, 0x1F13,
/*D*/
{0x2064, 0x2044, 0x2004,
/*F*/
{0x2166, 0x2146, 0x2106,
/*G*/
{0x2267, 0x2247, 0x2207,
/*H*/
{0x2368, 0x2348, 0x2308,
/*J*/
{0x246A, 0x244A, 0x240A,
alt,
0x0000,
0x011B,
0x7800,
0x7900,
0x7A00,
0x7B00,
0x7C00,
0x7D00,
0x7E00,
0x7F00,
0x8000,
0x8100,
0x8200,
0x8300,
0x0000,
0x0000,
0x1000,
0x1100,
0x1200,
0x1300,
0x1400,
0x1500,
0x1600,
0x1700,
0x1800,
0x1900,
0x0000,
0x0000,
0x0000,
0x1D00,
0x1E00,
0x1F00,
0x2000,
0x2100,
0x2200,
0x2300,
0x2400,
10
num,
0x0000,
0x011B,
0x0231,
0x0332,
0x0433,
0x0534,
0x0635,
0x0736,
0x0837,
0x0938,
0x0A39,
0x0B30,
0x0C2D,
0x0D3D,
0x0E08,
0x0F09,
0x1071,
0x1077,
0x1265,
0x1272,
0x1474,
0x1579,
0x1675,
0x1769,
0x186F,
0x1970,
0x1A5B,
0x1B5D,
0x1C0D,
0x1D00,
0x1E61,
0x1F73,
0x2064,
0x2166,
0x2267,
0x2368,
0x246A,
caps,
0x0000,
0x011B,
0x0231,
0x0332,
0x0433,
0x0534,
0x0635,
0x0736,
0x0837,
0x0938,
0x0A39,
0x0B30,
0x0C2D,
0x0D3D,
0x0E08,
0x0F09,
0x1051,
0x1057,
0x1245,
0x1252,
0x1454,
0x1559,
0x1655,
0x1749,
0x184F,
0x1950,
0x1A5B,
0x1B5D,
0x1C0D,
0x1D00,
0x1E41,
0x1F53,
0x2044,
0x2146,
0x2247,
0x2348,
0x244A,
shcap,
0x0000,
0x011B,
0x0231,
0x0332,
0x0423,
0x0524,
0x0625,
0x075E,
0x0826,
0x092A,
0x0A28,
0x0B29,
0x0C5F,
0x0D2B,
0x0E08,
0x0F00,
0x1051,
0x1057,
0x1245,
0x1252,
0x1454,
0x1579,
0x1675,
0x1769,
0x186F,
0x1970,
0x1A7B,
0x1B7D,
0x1C0A,
0x1D00,
0x1E61,
0x1F73,
0x2064,
0x2166,
0x2267,
0x2368,
0x246A,
shnum */
0x0000},
0x011B},
0x0321},
0x0332},
0x0423},
0x0524},
0x0625},
0x075E},
0x0826},
0x092A},
0x0A28},
0x0B29},
0x0C5F},
0x0D2B},
0x0E08},
0x0F00},
0x1071},
0x1077},
0x1265},
0x1272},
0x1474},
0x1559},
0x1655},
0x1749},
0x184F},
0x1950},
0x1A7B},
0x1B7D},
0x1C0A},
0x1D00},
0x1E41},
0x1F53},
0x2044},
0x2146},
0x2247},
0x2348},
0x244A},
/*K*/
/*L*/
/*; :*/
/*' "*/
/*` ~*/
/*LShf*/
/*\ |*/
/*Z*/
/*X*/
/*C*/
/*V*/
/*B*/
/*N*/
/*M*/
/*, <*/
/*. >*/
/*/ ?*/
/*rshf*/
/** PS*/
/*alt*/
/*spc*/
/*caps*/
/*F1*/
/*F2*/
/*F3*/
/*F4*/
/*F5*/
/*F6*/
/*F7*/
/*F8*/
/*F9*/
/*F10*/
/*num*/
/*scrl*/
/*home*/
/*up*/
/*pgup*/
/*-*/
/*left*/
/*Cntr*/
/*rght*/
/*+*/
/*end*/
/*down*/
/*pgdn*/
/*ins*/
/*del*/
/*--*/
/*--*/
/*--*/
/*F11*/
/*F12*/
} ;
{0x256B,
{0x266C,
{0x273B,
{0x2827,
{0x2960,
{0x2A00,
{0x2B5C,
{0x2C7A,
{0x2D78,
{0x2E63,
{0x2F76,
{0x3062,
{0x316E,
{0x326D,
{0x332C,
{0x342E,
{0x352F,
{0x3600,
{0x372A,
{0x3800,
{0x3920,
{0x3A00,
{0x3B00,
{0x3C00,
{0x3D00,
{0x3E00,
{0x3F00,
{0x4000,
{0x4100,
{0x4200,
{0x4300,
{0x4400,
{0x4500,
{0x4600,
{0x4700,
{0x4800,
{0x4900,
{0x4A2D,
{0x4B00,
{0x4C00,
{0x4D00,
{0x4E2B,
{0x4F00,
{0x5000,
{0x5100,
{0x5200,
{0x5300,
{0x0000,
{0x0000,
{0x0000,
{0x5700,
{0x5800,
0x254B,
0x264C,
0x273A,
0x2822,
0x297E,
0x2A00,
0x2B7C,
0x2C5A,
0x2D58,
0x2E43,
0x2F56,
0x3042,
0x314E,
0x324D,
0x333C,
0x343E,
0x353F,
0x3600,
0x0000,
0x3800,
0x3920,
0x3A00,
0x5400,
0x5500,
0x5600,
0x5700,
0x5800,
0x5900,
0x5A00,
0x5B00,
0x5C00,
0x5D00,
0x4500,
0x4600,
0x4737,
0x4838,
0x4939,
0x4A2D,
0x4B34,
0x4C35,
0x4D36,
0x4E2B,
0x4F31,
0x5032,
0x5133,
0x5230,
0x532E,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x250B,
0x260C,
0x0000,
0x0000,
0x0000,
0x2A00,
0x2B1C,
0x2C1A,
0x2D18,
0x2E03,
0x2F16,
0x3002,
0x310E,
0x320D,
0x0000,
0x0000,
0x0000,
0x3600,
0x3710,
0x3800,
0x3920,
0x3A00,
0x5E00,
0x5F00,
0x6000,
0x6100,
0x6200,
0x6300,
0x6400,
0x6500,
0x6600,
0x6700,
0x4500,
0x4600,
0x7700,
0x0000,
0x8400,
0x0000,
0x7300,
0x0000,
0x7400,
0x0000,
0x7500,
0x0000,
0x7600,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x2500,
0x2600,
0x0000,
0x0000,
0x0000,
0x2A00,
0x0000,
0x2C00,
0x2D00,
0x2E00,
0x2F00,
0x3000,
0x3100,
0x3200,
0x0000,
0x0000,
0x0000,
0x3600,
0x0000,
0x3800,
0x0000,
0x3A00,
0x6800,
0x6900,
0x6A00,
0x6B00,
0x6C00,
0x6D00,
0x6E00,
0x6F00,
0x7000,
0x7100,
0x4500,
0x4600,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x256B,
0x266C,
0x273B,
0x2827,
0x2960,
0x2A00,
0x2B5C,
0x2C7A,
0x2D78,
0x2E63,
0x2F76,
0x3062,
0x316E,
0x326D,
0x332C,
0x342E,
0x352F,
0x3600,
0x372A,
0x3800,
0x3920,
0x3A00,
0x3B00,
0x3C00,
0x3D00,
0x3E00,
0x3F00,
0x4000,
0x4100,
0x4200,
0x4300,
0x4400,
0x4500,
0x4600,
0x4737,
0x4838,
0x4939,
0x4A2D,
0x4B34,
0x4C35,
0x4D36,
0x4E2B,
0x4F31,
0x5032,
0x5133,
0x5230,
0x532E,
0x0000,
0x0000,
0x0000,
0x5700,
0x5800,
0x254B,
0x264C,
0x273B,
0x2827,
0x2960,
0x2A00,
0x2B5C,
0x2C5A,
0x2D58,
0x2E43,
0x2F56,
0x3042,
0x314E,
0x324D,
0x332C,
0x342E,
0x352F,
0x3600,
0x372A,
0x3800,
0x3920,
0x3A00,
0x3B00,
0x3C00,
0x3D00,
0x3E00,
0x3F00,
0x4000,
0x4100,
0x4200,
0x4300,
0x4400,
0x4500,
0x4600,
0x4700,
0x4800,
0x4900,
0x4A2D,
0x4B00,
0x4C00,
0x4D00,
0x4E2B,
0x4F00,
0x5000,
0x5100,
0x5200,
0x5300,
0x0000,
0x0000,
0x0000,
0x5700,
0x5800,
0x256B,
0x266C,
0x273A,
0x2822,
0x297E,
0x2A00,
0x2B7C,
0x2C7A,
0x2D78,
0x2E63,
0x2F76,
0x3062,
0x316E,
0x326D,
0x333C,
0x343E,
0x353F,
0x3600,
0x0000,
0x3800,
0x3920,
0x3A00,
0x5400,
0x5500,
0x5600,
0x5700,
0x5800,
0x5900,
0x5A00,
0x5B00,
0x5C00,
0x5D00,
0x4500,
0x4600,
0x4737,
0x4838,
0x4939,
0x4A2D,
0x4B34,
0x4C35,
0x4D36,
0x4E2B,
0x4F31,
0x5032,
0x5133,
0x5230,
0x532E,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
WORD16 ScanCode2Ascii(BYTE8 code) {
if (code == 0xE0 || code == 0xE1) return 0x0000 ; /* ignore */
if (code & 0x80)
return code << 8 ; /* KeyUp */
11
0x254B},
0x264C},
0x273A},
0x2822},
0x297E},
0x2A00},
0x2B7C},
0x2C5A},
0x2D58},
0x2E43},
0x2F56},
0x3042},
0x314E},
0x324D},
0x333C},
0x343E},
0x353F},
0x3600},
0x0000},
0x3800},
0x3920},
0x3A00},
0x5400},
0x5500},
0x5600},
0x5700},
0x5800},
0x5900},
0x5A00},
0x5B00},
0x5C00},
0x5D00},
0x4500},
0x4600},
0x4700},
0x4800},
0x4900},
0x4A2D},
0x4B00},
0x4C00},
0x4D00},
0x4E2B},
0x4F00},
0x5000},
0x5100},
0x5200},
0x5300},
0x0000},
0x0000},
0x0000},
0x0000},
0x0000}
if (code >= ENTRIES(scan_ascii))
return 0x0000 ; /* ignore */
if (state.alt) return scan_ascii[code][3] ;
if (state.ctrl) return scan_ascii[code][2] ;
if (code >= 0x47) {
if (state.num) {
if (state.lshift || state.rshift) {
return scan_ascii[code][7] ;
}
return scan_ascii[code][4] ;
}
} else if (state.caps) {
if (state.lshift || state.rshift) {
return scan_ascii[code][6] ;
}
return scan_ascii[code][5] ;
}
if (state.lshift || state.rshift) {
return scan_ascii[code][1] ;
}
return scan_ascii[code][0] ;
}
BOOL SetsKybdState(BYTE8 code)
{
switch (code)
{
case 0x36: state.rshift = TRUE ; break ;
case 0xB6: state.rshift = FALSE ; break ;
case 0x2A: state.lshift = TRUE ; break ;
case 0xAA: state.lshift = FALSE ; break ;
case 0x38: state.alt = TRUE ; break ;
case 0xB8: state.alt = FALSE ; break ;
case 0x1D: state.ctrl = TRUE ; break ;
case 0x9D: state.ctrl = FALSE ; break ;
case 0x3A: state.caps = !state.caps ;
case 0xBA: break ;
case 0x46: state.scrl = !state.scrl ;
case 0xC6: break ;
12
case 0x45: state.num = !state.num ;
case 0xC5: break ;
case 0x52: state.ins = !state.ins ;
case 0xD2: break ;
default: return FALSE ;
}
return TRUE ;
}
13
ASCII Table
Decimal
------000
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
Octal
----000
001
002
003
004
005
006
007
010
011
012
013
014
015
016
017
020
021
022
023
024
025
026
027
030
031
032
033
034
035
036
037
040
041
042
043
044
045
046
047
050
051
052
053
054
055
056
057
060
061
062
063
064
065
066
067
070
071
072
073
074
075
076
077
100
Hex
--000
001
002
003
004
005
006
007
008
009
00A
00B
00C
00D
00E
00F
010
011
012
013
014
015
016
017
018
019
01A
01B
01C
01D
01E
01F
020
021
022
023
024
025
026
027
028
029
02A
02B
02C
02D
02E
02F
030
031
032
033
034
035
036
037
038
039
03A
03B
03C
03D
03E
03F
040
Binary
-----00000000
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00001010
00001011
00001100
00001101
00001110
00001111
00010000
00010001
00010010
00010011
00010100
00010101
00010110
00010111
00011000
00011001
00011010
00011011
00011100
00011101
00011110
00011111
00100000
00100001
00100010
00100011
00100100
00100101
00100110
00100111
00101000
00101001
00101010
00101011
00101100
00101101
00101110
00101111
00110000
00110001
00110010
00110011
00110100
00110101
00110110
00110111
00111000
00111001
00111010
00111011
00111100
00111101
00111110
00111111
01000000
Value
----NUL
(Null char.)
SOH
(Start of Header)
STX
(Start of Text)
ETX
(End of Text)
EOT
(End of Transmission)
ENQ
(Enquiry)
ACK
(Acknowledgment)
BEL
(Bell)
BS
(Backspace)
HT
(Horizontal Tab)
LF
(Line Feed)
VT
(Vertical Tab)
FF
(Form Feed)
CR
(Carriage Return)
SO
(Shift Out)
SI
(Shift In)
DLE
(Data Link Escape)
DC1 (XON) (Device Control 1)
DC2
(Device Control 2)
DC3 (XOFF)(Device Control 3)
DC4
(Device Control 4)
NAK
(Negative Acknowledgement)
SYN
(Synchronous Idle)
ETB
(End of Trans. Block)
CAN
(Cancel)
EM
(End of Medium)
SUB
(Substitute)
ESC
(Escape)
FS
(File Separator)
GS
(Group Separator)
RS
(Request to Send)(Record Separator)
US
(Unit Separator)
SP
(Space)
!
(exclamation mark)
"
(double quote)
#
(number sign)
$
(dollar sign)
%
(percent)
&
(ampersand)
'
(single quote)
(
(left/opening parenthesis)
)
(right/closing parenthesis)
*
(asterisk)
+
(plus)
,
(comma)
(minus or dash)
.
(dot)
/
(forward slash)
0
1
2
3
4
5
6
7
8
9
:
(colon)
;
(semi-colon)
<
(less than)
=
(equal sign)
>
(greater than)
?
(question mark)
@
(AT symbol)
14
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
101
102
103
104
105
106
107
110
111
112
113
114
115
116
117
120
121
122
123
124
125
126
127
130
131
132
133
134
135
136
137
140
141
142
143
144
145
146
147
150
151
152
153
154
155
156
157
160
161
162
163
164
165
166
167
170
171
172
173
174
175
176
177
041
042
043
044
045
046
047
048
049
04A
04B
04C
04D
04E
04F
050
051
052
053
054
055
056
057
058
059
05A
05B
05C
05D
05E
05F
060
061
062
063
064
065
066
067
068
069
06A
06B
06C
06D
06E
06F
070
071
072
073
074
075
076
077
078
079
07A
07B
07C
07D
07E
07F
01000001
01000010
01000011
01000100
01000101
01000110
01000111
01001000
01001001
01001010
01001011
01001100
01001101
01001110
01001111
01010000
01010001
01010010
01010011
01010100
01010101
01010110
01010111
01011000
01011001
01011010
01011011
01011100
01011101
01011110
01011111
01100000
01100001
01100010
01100011
01100100
01100101
01100110
01100111
01101000
01101001
01101010
01101011
01101100
01101101
01101110
01101111
01110000
01110001
01110010
01110011
01110100
01110101
01110110
01110111
01111000
01111001
01111010
01111011
01111100
01111101
01111110
01111111
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~
DEL
15
(left/opening bracket)
(back slash)
(right/closing bracket)
(caret/cirumflex)
(underscore)
(left/opening brace)
(vertical bar)
(right/closing brace)
(tilde)
(delete)
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement