CS 380 Lab 4 Keyboard Input Assigned 2/11/10 30 Points

Similar documents
ASCII Code - The extended ASCII table

OOstaExcel.ir. J. Abbasi Syooki. HTML Number. Device Control 1 (oft. XON) Device Control 3 (oft. Negative Acknowledgement

FD-011WU. 2D Barcode Reader User Guide V1.6CC

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

MK D Imager Barcode Scanner Configuration Guide

BD-6500BT Bluetooth 2D Barcode Scanner Configuration Guide

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, SPRING 2013

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme

The following are the data types used in the C programming language:

Characters Lesson Outline

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

RS-232 Control of the Advantage EQ281/8, EQ282/8 and Advantage SMS200

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Technical Specification. Third Party Control Protocol. AV Revolution

Chapter 2 Number System

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Chemistry Hour Exam 2

4. Specifications and Additional Information

Chapter 3. Information Representation

Number Representations

CIS-331 Fall 2014 Exam 1 Name: Total of 109 Points Version 1

2D Barcode Reader User Guide V 1.2.1

2D Hand-held Barcode Scanner User Guide

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

CIS-331 Exam 2 Fall 2015 Total of 105 Points Version 1

Acquirer JCB EMV Test Card Set

First Data Dual Interface EMV Test Card Set. Version 1.20

CIS-331 Fall 2013 Exam 1 Name: Total of 120 Points Version 1

USB-ASC232. ASCII RS-232 Controlled USB Keyboard and Mouse Cable. User Manual

CIS-331 Spring 2016 Exam 1 Name: Total of 109 Points Version 1

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

First Data EMV Test Card Set. Version 1.30

RS-232 Control of the Advantage DRI

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

First Data EMV Test Card Set. Version 2.00

PS232. RS-232 to PS/2 Keyboard Port Adapter Part # SA0009 (Version 4.0) Copyright 2003 L3 Systems, Inc. Redmond

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

Computer Control of the Advantage DRC 4+4

Do not start the test until instructed to do so!

Midterm Exam, Fall 2015 Date: October 29th, 2015

Fundamentals of Programming (C)

CIS-331 Exam 2 Fall 2014 Total of 105 Points. Version 1

First Data DCC Test Card Set. Version 1.30

C1098 JPEG Module User Manual

Locus Engineering Inc

Acquirer JCB Dual Interface EMV Test Card Set

CIS-331 Exam 2 Spring 2016 Total of 110 Points Version 1

Data Representation and Binary Arithmetic. Lecture 2

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

Request for Comments: XXXX November Registration of a Georgian Character Set draft-giasher-geostd8-00.txt

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

The cache is 4-way set associative, with 4-byte blocks, and 16 total lines

3.1. Unit 3. Binary Representation

Gateway Ascii Command Protocol

ECHO Process Instrumentation, Inc. Modbus RS485 Module. Operating Instructions. Version 1.0 June 2010

Characters & Strings in C

KB232. PS/2 Keyboard RS-232 Adapter Part # SA0008 (Version 3.0) Copyright 2003 L3 Systems, Inc. Redmond

Interac USA Interoperability EMV Test Card Set

IPDA014-2D. Embedded 2D Barcode Scan Engine. User Guide

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

User s Manual. Xi3000 Scanner. Table of Contents

Motors I Automation I Energy I Transmission & Distribution I Coatings. Modbus RTU CFW701. User s Manual

CS 537: Introduction to Operating Systems Fall 2015: Midterm Exam #1

S-Series Sensor ASCII Protocol v8.1.0

EE 109 Unit 2. Binary Representation Systems

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic:

2D BARCODE SCANNER CA-SC-20200B

Mounting Dimensions / Viewing 2 Mounting Options 3. Wiring Configuration 4. Quick Set up Procedure 5. Changing Intensity 6.

RS 232 PINOUTS. 1. We use RJ12 for all of our RS232 interfaces (Link-2-Modbus & Link-2-PC- Serial/RS232). The diagram below shows our pin out.

AutoLISP Module 6 Competency Test No.1

Visual KeyMaker. Programming Software Instructions. Contents A B

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

SPARC INTERNATIONAL. Version1 SPARC Keyboard Specification

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

CIS-331 Final Exam Spring 2015 Total of 115 Points. Version 1

LC UNI - SSI PUMPS. Clarity Control Module. Code/Rev.: M038/40D Date:

Chapter 8. Characters and Strings

n NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i

If your CNC machine memory is full, the PocketDNC gives you more storage, enabling you to store and reload proven programs at a later date.

Modbus RTU CFW100. User s Manual. Phone: Fax: Web: -

Setup Procedures 2 Batch Setup 3. Bar Code Setup Menu 5. 1 Device Selection and Default. 2 Beep and Delay Keyboard Wedge..

Configuration Manual PULSAR C CCD SCANNER. Table of Contents

Parallax Serial LCD 2 rows x 16 characters Non-backlit (#27976) 2 rows x 16 characters Backlit (#27977) 4 rows x 20 characters Backlit (#27979)

July Registration of a Cyrillic Character Set. Status of this Memo

Fundamentals of Programming

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

J2 LCM Customer Display. Manual

Do not start the test until instructed to do so!

Chapter 2 Bits, Data Types, and Operations

Positional Number System

User s Manual. Addendum to. Ranger Wedge Interface. Part No. 25-WEDGE-06A Ver. April 1999

ZN-DN312XE-M Quick User Guide

marson MT8200S 2D Handheld Scanner User Manual V / 6 / 25 - I -

Transcription:

CS 380 ab 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 INTE 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 INTE 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 ab 3: Function void putchar(char c); char getscancode(); Purpose Displays a character at the current cursor position and advance the cursor by one position. Returns a scan code form the keyboard 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) Use getscancode to get a scan code 2) Use SetsKybdState with the scan code to set the state 3) Check to see of the scan code is a break code, if so ignore it 4) Use ScanCode2Ascii to convert a valid scan code to a short value 5) 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 Y MAK E BREA K ---- - KEY MAKE BREA K ---- - KEY MAK E BREA K A 1E 9E 9 0A 8A [ 1A 9A B 30 B0 ` 29 89 INSER T E0,52 E0,D2 C 2E AE - 0C 8C HOME E0,47 E0,97 D 20 A0 = 0D 8D PG UP E0,49 E0,C9 E 12 92 \ 2B AB DEET E E0,53 E0,D3 F 21 A1 BKSP 0E 8E END E0,4F E0,CF G 22 A2 SPACE 39 B9 PG DN E0,51 E0,D1 H 23 A3 TAB 0F 8F I 17 97 CAPS 3A BA J 24 A4 K 25 A5 SHFT CTR 2A 1D AA 9D U D R E0,48 E0,C8 E0,4B E0,CB E0,50 E0,D0 E0,4D E0,CD 26 A6 GUI E0,5B E0,DB NUM 45 C5 M 32 B2 AT 38 B8 KP / E0,35 E0,B5 N 31 B1 O 18 98 R SHFT R CTR 36 B6 KP * 37 B7 E0,1D E0,9D KP - 4A CA P 19 99 R GUI E0,5C E0,DC KP + 4E CE Q 10 19 R AT E0,38 E0,B8 KP EN E0,1C E0,9C R 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 3

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 7 08 88 PRNT SCRN SCRO 8 09 89 PAUSE ACPI Scan Codes: E0,2A, E0,37 E0,B7, E0,AA. 34 B4 46 C6 / 35 B5 E1,1D,4 5 E1,9D,C 5 -NONE- 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 Y MAK E BREA K ---- - KEY MAKE BREAK ---- - KEY MAK E BREAK A 1C F0,1C 9 46 F0,46 [ 54 FO,54 B 32 F0,32 ` 0E F0,0E INSER T E0,70 E0,F0,7 0 C 21 F0,21-4E F0,4E HOME E0,6C E0,F0,6 C D 23 F0,23 = 55 FO,55 PG UP E0,7D E0,F0,7 D E 24 F0,24 \ 5D F0,5D DEET E E0,71 E0,F0,7 1 F 2B F0,2B BKSP 66 F0,66 END E0,69 E0,F0,6 9 G 34 F0,34 SPACE 29 F0,29 PG DN E0,7A E0,F0,7 A H 33 F0,33 TAB 0D F0,0D I 43 F0,43 CAPS 58 F0,58 J 3B F0,3B K 42 F0,42 SHFT CTR 4B F0,4B GUI E0,1F 12 FO,12 14 FO,14 E0,F0,1 F U D R E0,F0,7 E0,75 5 E0,F0,6 E0,6B B E0,F0,7 E0,72 2 E0,F0,7 E0,74 4 NUM 77 F0,77 M 3A F0,3A AT 11 F0,11 KP / E0,4A E0,F0,4 A R N 31 F0,31 59 F0,59 KP * 7C F0,7C SHFT O 44 F0,44 R CTR E0,14 P 4D F0,4D R GUI E0,27 Q 15 F0,15 R AT E0,11 R 2D F0,2D APPS E0,2F E0,F0,1 4 E0,F0,2 7 E0,F0,1 1 E0,F0,2 F KP - 7B F0,7B KP + 79 F0,79 KP EN E0,5A E0,F0,5 A KP. 71 F0,71 S 1B F0,1B ENTER 5A F0,5A KP 0 70 F0,70 T 2C F0,2C ESC 76 F0,76 KP 1 69 F0,69 U 3C F0,3C F1 05 F0,05 KP 2 72 F0,72 V 2A F0,2A F2 06 F0,06 KP 3 7A F0,7A 6

W 1D F0,1D F3 04 F0,04 KP 4 6B F0,6B X 22 F0,22 F4 0C F0,0C KP 5 73 F0,73 Y 35 F0,35 F5 03 F0,03 KP 6 74 F0,74 Z 1A F0,1A F6 0B F0,0B KP 7 6C F0,6C 0 45 F0,45 F7 83 F0,83 KP 8 75 F0,75 1 16 F0,16 F8 0A F0,0A KP 9 7D F0,7D 2 1E F0,1E F9 01 F0,01 ] 5B F0,5B 3 26 F0,26 F10 09 F0,09 ; 4C F0,4C 4 25 F0,25 F11 78 F0,78 ' 52 F0,52 5 2E F0,2E F12 07 F0,07, 41 F0,41 6 36 F0,36 7 3D F0,3D PRNT SCRN SCRO 8 3E F0,3E PAUSE E0,12, E0,7C E0,F0, 7C,E0, F0,12. 49 F0,49 7E F0,7E / 4A F0,4A E1,14,77, E1,F0,14, F0,77 -NONE- 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

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 BOO; BYTE8; WORD16; DWORD32; #ifndef TRUE #definetrue 1 #endif #ifndef FASE #definefase 0 #endif #defineentries(a) (sizeof(a)/sizeof(a[0])) typedef struct STATE { BOO ins ; BOO rshift ; BOO lshift ; BOO alt ; BOO ctrl ; BOO caps ; BOO scrl ; BOO num ; attribute ((packed)) STATE ; #definekybd_sts_port 0x64 #definekybd_dat_port 0x60 #definekybd_dat_rdy 0x01 #definebreak_code 0x80 #definesize 20 PRIVATE STATE state ; /* Initialized to all FASE by loader */ 9

PRIVATE BYTE8 scan_codes[size] ; PRIVATE unsigned int nq = 0 ; PRIVATE unsigned int dq = 0 ; PRIVATE unsigned int 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, alt, num, caps, shcap, shnum */ /*--*/ {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*ESC*/ {0x011B, 0x011B, 0x011B, 0x011B, 0x011B, 0x011B, 0x011B, 0x011B, /*1!*/ {0x0231, 0x0221, 0x0000, 0x7800, 0x0231, 0x0231, 0x0231, 0x0321, /*2 @*/ {0x0332, 0x0340, 0x0300, 0x7900, 0x0332, 0x0332, 0x0332, 0x0332, /*3 #*/ {0x0433, 0x0423, 0x0000, 0x7A00, 0x0433, 0x0433, 0x0423, 0x0423, /*4 $*/ {0x0534, 0x0524, 0x0000, 0x7B00, 0x0534, 0x0534, 0x0524, 0x0524, /*5 %*/ {0x0635, 0x0625, 0x0000, 0x7C00, 0x0635, 0x0635, 0x0625, 0x0625, /*6 ^*/ {0x0736, 0x075E, 0x071E, 0x7D00, 0x0736, 0x0736, 0x075E, 0x075E, /*7 &*/ {0x0837, 0x0826, 0x0000, 0x7E00, 0x0837, 0x0837, 0x0826, 0x0826, /*8 **/ {0x0938, 0x092A, 0x0000, 0x7F00, 0x0938, 0x0938, 0x092A, 0x092A, /*9 (*/ {0x0A39, 0x0A28, 0x0000, 0x8000, 0x0A39, 0x0A39, 0x0A28, 0x0A28, /*0 )*/ {0x0B30, 0x0B29, 0x0000, 0x8100, 0x0B30, 0x0B30, 0x0B29, 0x0B29, /*- _*/ {0x0C2D, 0x0C5F, 0x0000, 0x8200, 0x0C2D, 0x0C2D, 0x0C5F, 0x0C5F, /*= +*/ {0x0D3D, 0x0D2B, 0x0000, 0x8300, 0x0D3D, 0x0D3D, 0x0D2B, 0x0D2B, /*bksp*/ {0x0E08, 0x0E08, 0x0E7F, 0x0000, 0x0E08, 0x0E08, 0x0E08, 0x0E08, /*Tab*/ {0x0F09, 0x0F00, 0x0000, 0x0000, 0x0F09, 0x0F09, 0x0F00, 0x0F00, /*Q*/ {0x1071, 0x1051, 0x1011, 0x1000, 0x1071, 0x1051, 0x1051, 0x1071, /*W*/ {0x1177, 0x1057, 0x1017, 0x1100, 0x1077, 0x1057, 0x1057, 0x1077, /*E*/ {0x1265, 0x1245, 0x1205, 0x1200, 0x1265, 0x1245, 0x1245, 0x1265, /*R*/ {0x1372, 0x1352, 0x1312, 0x1300, 0x1272, 0x1252, 0x1252, 0x1272, /*T*/ {0x1474, 0x1454, 0x1414, 0x1400, 0x1474, 0x1454, 0x1454, 0x1474, /*Y*/ {0x1579, 0x1559, 0x1519, 0x1500, 0x1579, 0x1559, 0x1579, 0x1559, /*U*/ {0x1675, 0x1655, 0x1615, 0x1600, 0x1675, 0x1655, 0x1675, 0x1655, /*I*/ {0x1769, 0x1749, 0x1709, 0x1700, 0x1769, 0x1749, 0x1769, 0x1749, /*O*/ {0x186F, 0x184F, 0x180F, 0x1800, 0x186F, 0x184F, 0x186F, 0x184F, /*P*/ {0x1970, 0x1950, 0x1910, 0x1900, 0x1970, 0x1950, 0x1970, 0x1950, /*[ {*/ {0x1A5B, 0x1A7B, 0x1A1B, 0x0000, 0x1A5B, 0x1A5B, 0x1A7B, 0x1A7B, /*] */ {0x1B5D, 0x1B7D, 0x1B1D, 0x0000, 0x1B5D, 0x1B5D, 0x1B7D, 0x1B7D, /*entr*/ {0x1C0D, 0x1C0D, 0x1C0A, 0x0000, 0x1C0D, 0x1C0D, 0x1C0A, 0x1C0A, /*ctrl*/ {0x1D00, 0x1D00, 0x1D00, 0x1D00, 0x1D00, 0x1D00, 0x1D00, 0x1D00, /*A*/ {0x1E61, 0x1E41, 0x1E01, 0x1E00, 0x1E61, 0x1E41, 0x1E61, 0x1E41, /*S*/ {0x1F73, 0x1F53, 0x1F13, 0x1F00, 0x1F73, 0x1F53, 0x1F73, 0x1F53, /*D*/ {0x2064, 0x2044, 0x2004, 0x2000, 0x2064, 0x2044, 0x2064, 0x2044, /*F*/ {0x2166, 0x2146, 0x2106, 0x2100, 0x2166, 0x2146, 0x2166, 0x2146, /*G*/ {0x2267, 0x2247, 0x2207, 0x2200, 0x2267, 0x2247, 0x2267, 0x2247, /*H*/ {0x2368, 0x2348, 0x2308, 0x2300, 0x2368, 0x2348, 0x2368, 0x2348, /*J*/ {0x246A, 0x244A, 0x240A, 0x2400, 0x246A, 0x244A, 0x246A, 0x244A, 10

/*K*/ {0x256B, 0x254B, 0x250B, 0x2500, 0x256B, 0x254B, 0x256B, 0x254B, /**/ {0x266C, 0x264C, 0x260C, 0x2600, 0x266C, 0x264C, 0x266C, 0x264C, /*; :*/ {0x273B, 0x273A, 0x0000, 0x0000, 0x273B, 0x273B, 0x273A, 0x273A, /*' "*/ {0x2827, 0x2822, 0x0000, 0x0000, 0x2827, 0x2827, 0x2822, 0x2822, /*` ~*/ {0x2960, 0x297E, 0x0000, 0x0000, 0x2960, 0x2960, 0x297E, 0x297E, /*Shf*/ {0x2A00, 0x2A00, 0x2A00, 0x2A00, 0x2A00, 0x2A00, 0x2A00, 0x2A00, /*\ */ {0x2B5C, 0x2B7C, 0x2B1C, 0x0000, 0x2B5C, 0x2B5C, 0x2B7C, 0x2B7C, /*Z*/ {0x2C7A, 0x2C5A, 0x2C1A, 0x2C00, 0x2C7A, 0x2C5A, 0x2C7A, 0x2C5A, /*X*/ {0x2D78, 0x2D58, 0x2D18, 0x2D00, 0x2D78, 0x2D58, 0x2D78, 0x2D58, /*C*/ {0x2E63, 0x2E43, 0x2E03, 0x2E00, 0x2E63, 0x2E43, 0x2E63, 0x2E43, /*V*/ {0x2F76, 0x2F56, 0x2F16, 0x2F00, 0x2F76, 0x2F56, 0x2F76, 0x2F56, /*B*/ {0x3062, 0x3042, 0x3002, 0x3000, 0x3062, 0x3042, 0x3062, 0x3042, /*N*/ {0x316E, 0x314E, 0x310E, 0x3100, 0x316E, 0x314E, 0x316E, 0x314E, /*M*/ {0x326D, 0x324D, 0x320D, 0x3200, 0x326D, 0x324D, 0x326D, 0x324D, /*, <*/ {0x332C, 0x333C, 0x0000, 0x0000, 0x332C, 0x332C, 0x333C, 0x333C, /*. >*/ {0x342E, 0x343E, 0x0000, 0x0000, 0x342E, 0x342E, 0x343E, 0x343E, /*/?*/ {0x352F, 0x353F, 0x0000, 0x0000, 0x352F, 0x352F, 0x353F, 0x353F, /*rshf*/ {0x3600, 0x3600, 0x3600, 0x3600, 0x3600, 0x3600, 0x3600, 0x3600, /** PS*/ {0x372A, 0x0000, 0x3710, 0x0000, 0x372A, 0x372A, 0x0000, 0x0000, /*alt*/ {0x3800, 0x3800, 0x3800, 0x3800, 0x3800, 0x3800, 0x3800, 0x3800, /*spc*/ {0x3920, 0x3920, 0x3920, 0x0000, 0x3920, 0x3920, 0x3920, 0x3920, /*caps*/ {0x3A00, 0x3A00, 0x3A00, 0x3A00, 0x3A00, 0x3A00, 0x3A00, 0x3A00, /*F1*/ {0x3B00, 0x5400, 0x5E00, 0x6800, 0x3B00, 0x3B00, 0x5400, 0x5400, /*F2*/ {0x3C00, 0x5500, 0x5F00, 0x6900, 0x3C00, 0x3C00, 0x5500, 0x5500, /*F3*/ {0x3D00, 0x5600, 0x6000, 0x6A00, 0x3D00, 0x3D00, 0x5600, 0x5600, /*F4*/ {0x3E00, 0x5700, 0x6100, 0x6B00, 0x3E00, 0x3E00, 0x5700, 0x5700, /*F5*/ {0x3F00, 0x5800, 0x6200, 0x6C00, 0x3F00, 0x3F00, 0x5800, 0x5800, /*F6*/ {0x4000, 0x5900, 0x6300, 0x6D00, 0x4000, 0x4000, 0x5900, 0x5900, /*F7*/ {0x4100, 0x5A00, 0x6400, 0x6E00, 0x4100, 0x4100, 0x5A00, 0x5A00, /*F8*/ {0x4200, 0x5B00, 0x6500, 0x6F00, 0x4200, 0x4200, 0x5B00, 0x5B00, /*F9*/ {0x4300, 0x5C00, 0x6600, 0x7000, 0x4300, 0x4300, 0x5C00, 0x5C00, /*F10*/ {0x4400, 0x5D00, 0x6700, 0x7100, 0x4400, 0x4400, 0x5D00, 0x5D00, /*num*/ {0x4500, 0x4500, 0x4500, 0x4500, 0x4500, 0x4500, 0x4500, 0x4500, /*scrl*/ {0x4600, 0x4600, 0x4600, 0x4600, 0x4600, 0x4600, 0x4600, 0x4600, /*home*/ {0x4700, 0x4737, 0x7700, 0x0000, 0x4737, 0x4700, 0x4737, 0x4700, /*up*/ {0x4800, 0x4838, 0x0000, 0x0000, 0x4838, 0x4800, 0x4838, 0x4800, /*pgup*/ {0x4900, 0x4939, 0x8400, 0x0000, 0x4939, 0x4900, 0x4939, 0x4900, /*-*/ {0x4A2D, 0x4A2D, 0x0000, 0x0000, 0x4A2D, 0x4A2D, 0x4A2D, 0x4A2D, /*left*/ {0x4B00, 0x4B34, 0x7300, 0x0000, 0x4B34, 0x4B00, 0x4B34, 0x4B00, /*Cntr*/ {0x4C00, 0x4C35, 0x0000, 0x0000, 0x4C35, 0x4C00, 0x4C35, 0x4C00, /*rght*/ {0x4D00, 0x4D36, 0x7400, 0x0000, 0x4D36, 0x4D00, 0x4D36, 0x4D00, /*+*/ {0x4E2B, 0x4E2B, 0x0000, 0x0000, 0x4E2B, 0x4E2B, 0x4E2B, 0x4E2B, /*end*/ {0x4F00, 0x4F31, 0x7500, 0x0000, 0x4F31, 0x4F00, 0x4F31, 0x4F00, /*down*/ {0x5000, 0x5032, 0x0000, 0x0000, 0x5032, 0x5000, 0x5032, 0x5000, /*pgdn*/ {0x5100, 0x5133, 0x7600, 0x0000, 0x5133, 0x5100, 0x5133, 0x5100, /*ins*/ {0x5200, 0x5230, 0x0000, 0x0000, 0x5230, 0x5200, 0x5230, 0x5200, /*del*/ {0x5300, 0x532E, 0x0000, 0x0000, 0x532E, 0x5300, 0x532E, 0x5300, /*--*/ {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*--*/ {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*--*/ {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*F11*/ {0x5700, 0x0000, 0x0000, 0x0000, 0x5700, 0x5700, 0x0000, 0x0000, /*F12*/ {0x5800, 0x0000, 0x0000, 0x0000, 0x5800, 0x5800, 0x0000, 0x0000 ; WORD16 ScanCode2Ascii(BYTE8 code) { if (code == 0xE0 code == 0xE1) return 0x0000 ; /* ignore */ if (code & 0x80) return code << 8 ; /* KeyUp */ 11

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] ; BOO SetsKybdState(BYTE8 code) { switch (code) { case 0x36: state.rshift = TRUE ; break ; case 0xB6: state.rshift = FASE ; break ; case 0x2A: state.lshift = TRUE ; break ; case 0xAA: state.lshift = FASE ; break ; case 0x38: state.alt = TRUE ; break ; case 0xB8: state.alt = FASE ; break ; case 0x1D: state.ctrl = TRUE ; break ; case 0x9D: state.ctrl = FASE ; break ; case 0x3A: state.caps =!state.caps ; case 0xBA: break ; case 0x46: state.scrl =!state.scrl ; case 0xC6: break ; 12

return TRUE ; case 0x45: state.num =!state.num ; case 0xC5: break ; case 0x52: state.ins =!state.ins ; case 0xD2: break ; default: return FASE ; 13

ASCII Table Decimal Octal Hex Binary Value ------- ----- --- ------ ----- 000 000 000 00000000 NU (Null char.) 001 001 001 00000001 SOH (Start of Header) 002 002 002 00000010 STX (Start of Text) 003 003 003 00000011 ETX (End of Text) 004 004 004 00000100 EOT (End of Transmission) 005 005 005 00000101 ENQ (Enquiry) 006 006 006 00000110 ACK (Acknowledgment) 007 007 007 00000111 BE (Bell) 008 010 008 00001000 BS (Backspace) 009 011 009 00001001 HT (Horizontal Tab) 010 012 00A 00001010 F (ine Feed) 011 013 00B 00001011 VT (Vertical Tab) 012 014 00C 00001100 FF (Form Feed) 013 015 00D 00001101 CR (Carriage Return) 014 016 00E 00001110 SO (Shift Out) 015 017 00F 00001111 SI (Shift In) 016 020 010 00010000 DE (Data ink Escape) 017 021 011 00010001 DC1 (XON) (Device Control 1) 018 022 012 00010010 DC2 (Device Control 2) 019 023 013 00010011 DC3 (XOFF)(Device Control 3) 020 024 014 00010100 DC4 (Device Control 4) 021 025 015 00010101 NAK (Negative Acknowledgement) 022 026 016 00010110 SYN (Synchronous Idle) 023 027 017 00010111 ETB (End of Trans. Block) 024 030 018 00011000 CAN (Cancel) 025 031 019 00011001 EM (End of Medium) 026 032 01A 00011010 SUB (Substitute) 027 033 01B 00011011 ESC (Escape) 028 034 01C 00011100 FS (File Separator) 029 035 01D 00011101 GS (Group Separator) 030 036 01E 00011110 RS (Request to Send)(Record Separator) 031 037 01F 00011111 US (Unit Separator) 032 040 020 00100000 SP (Space) 033 041 021 00100001! (exclamation mark) 034 042 022 00100010 " (double quote) 035 043 023 00100011 # (number sign) 036 044 024 00100100 $ (dollar sign) 037 045 025 00100101 % (percent) 038 046 026 00100110 & (ampersand) 039 047 027 00100111 ' (single quote) 040 050 028 00101000 ( (left/opening parenthesis) 041 051 029 00101001 ) (right/closing parenthesis) 042 052 02A 00101010 * (asterisk) 043 053 02B 00101011 + (plus) 044 054 02C 00101100, (comma) 045 055 02D 00101101 - (minus or dash) 046 056 02E 00101110. (dot) 047 057 02F 00101111 / (forward slash) 048 060 030 00110000 0 049 061 031 00110001 1 050 062 032 00110010 2 051 063 033 00110011 3 052 064 034 00110100 4 053 065 035 00110101 5 054 066 036 00110110 6 055 067 037 00110111 7 056 070 038 00111000 8 057 071 039 00111001 9 058 072 03A 00111010 : (colon) 059 073 03B 00111011 ; (semi-colon) 060 074 03C 00111100 < (less than) 061 075 03D 00111101 = (equal sign) 062 076 03E 00111110 > (greater than) 063 077 03F 00111111? (question mark) 064 100 040 01000000 @ (AT symbol) 14

065 101 041 01000001 A 066 102 042 01000010 B 067 103 043 01000011 C 068 104 044 01000100 D 069 105 045 01000101 E 070 106 046 01000110 F 071 107 047 01000111 G 072 110 048 01001000 H 073 111 049 01001001 I 074 112 04A 01001010 J 075 113 04B 01001011 K 076 114 04C 01001100 077 115 04D 01001101 M 078 116 04E 01001110 N 079 117 04F 01001111 O 080 120 050 01010000 P 081 121 051 01010001 Q 082 122 052 01010010 R 083 123 053 01010011 S 084 124 054 01010100 T 085 125 055 01010101 U 086 126 056 01010110 V 087 127 057 01010111 W 088 130 058 01011000 X 089 131 059 01011001 Y 090 132 05A 01011010 Z 091 133 05B 01011011 [ (left/opening bracket) 092 134 05C 01011100 \ (back slash) 093 135 05D 01011101 ] (right/closing bracket) 094 136 05E 01011110 ^ (caret/cirumflex) 095 137 05F 01011111 _ (underscore) 096 140 060 01100000 ` 097 141 061 01100001 a 098 142 062 01100010 b 099 143 063 01100011 c 100 144 064 01100100 d 101 145 065 01100101 e 102 146 066 01100110 f 103 147 067 01100111 g 104 150 068 01101000 h 105 151 069 01101001 i 106 152 06A 01101010 j 107 153 06B 01101011 k 108 154 06C 01101100 l 109 155 06D 01101101 m 110 156 06E 01101110 n 111 157 06F 01101111 o 112 160 070 01110000 p 113 161 071 01110001 q 114 162 072 01110010 r 115 163 073 01110011 s 116 164 074 01110100 t 117 165 075 01110101 u 118 166 076 01110110 v 119 167 077 01110111 w 120 170 078 01111000 x 121 171 079 01111001 y 122 172 07A 01111010 z 123 173 07B 01111011 { (left/opening brace) 124 174 07C 01111100 (vertical bar) 125 175 07D 01111101 (right/closing brace) 126 176 07E 01111110 ~ (tilde) 127 177 07F 01111111 DE (delete) 15