source: rtems/c/src/lib/libbsp/i386/go32/console/inch.c @ 4ca27cf

4.104.114.84.95
Last change on this file since 4ca27cf was 4ca27cf, checked in by Joel Sherrill <joel.sherrill@…>, on 07/18/95 at 21:19:53

committing for rtems-3.2.01 snapshot

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  $Id$
3 */
4
5#include <pc.h>
6#include <go32.h>
7#include <bsp.h>
8
9/*
10 * Ports for PC keyboard
11 */
12#define KBD_CTL 0x61
13#define KBD_DATA 0x60
14#define KBD_STATUS 0x64
15
16static char key_map[] = {
170,033,'1','2','3','4','5','6','7','8','9','0','-','=','\b','\t',
18'q','w','e','r','t','y','u','i','o','p','[',']',015,0x80,
19'a','s','d','f','g','h','j','k','l',';',047,0140,0x80,
200134,'z','x','c','v','b','n','m',',','.','/',0x80,
21'*',0x80,' ',0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
220x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
230x80,0x80,0x80,'0',0177
24};
25
26static char shift_map[] = {
270,033,'!','@','#','$','%','^','&','*','(',')','_','+','\b','\t',
28'Q','W','E','R','T','Y','U','I','O','P','{','}',015,0x80,
29'A','S','D','F','G','H','J','K','L',':',042,'~',0x80,
30'|','Z','X','C','V','B','N','M','<','>','?',0x80,
31'*',0x80,' ',0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
320x80,0x80,0x80,0x80,'7','8','9',0x80,'4','5','6',0x80,
33'1','2','3','0',177
34};
35
36extern int _IBMPC_Use_Go32_IO;
37
38#define KBD_BUF_SIZE    256
39static char             kbd_buffer[ KBD_BUF_SIZE ];
40static unsigned int     kbd_first = 0;
41static unsigned int     kbd_last  = 0;
42
43/* This function can be called during a poll for input, or by an ISR.   */
44/* Basically any time you want to process a keypress.                   */
45int _IBMPC_scankey( char * ch )
46{
47        unsigned char c;
48        unsigned char outch;
49        static int shift_pressed = 0;
50        static int ctrl_pressed = 0;
51        static int caps_pressed = 0;
52
53        /* Read keyboard controller, toggle enable */
54        inport_byte( KBD_CTL, c );
55        outport_byte( KBD_CTL, c & ~0x80 );
56        outport_byte( KBD_CTL, c | 0x80 );
57        outport_byte( KBD_CTL, c & ~0x80 );
58
59        /* See if it has data */
60        inport_byte( KBD_STATUS, c );
61        if ( ( c & 0x01 ) == 0 )
62            return 0;
63
64        /* Read the data.  Handle nonsense with shift, control, etc. */
65        inport_byte( KBD_DATA, c );
66        switch ( c ) {
67        case 0x36:
68        case 0x2a:
69                shift_pressed = 1;
70                return 0;
71        case 0x3a:
72                caps_pressed = 1;
73                return 0;
74        case 0x1d:
75                ctrl_pressed = 1;
76                return 0;
77        case 0xb6:
78        case 0xaa:
79                shift_pressed = 0;
80                return 0;
81        case 0xba:
82                caps_pressed = 0;
83                return 0;
84        case 0x9d:
85                ctrl_pressed = 0;
86                return 0;
87        /*
88         * Ignore unrecognized keys--usually arrow and such
89         */
90        default:
91                if ( c & 0x80 )
92                    /* High-bit on means key is being released, not pressed */
93                    return 0;
94                if ( c == 88 )
95                    /* F12 - abort */
96                    exit( 1 );
97                if ( c > 0x39 )  {
98                    return 0;
99                }
100        }
101
102        /* Strip high bit, look up in our map */
103        c &= 127;
104        if ( ctrl_pressed )  {
105            outch = key_map[c];
106            outch &= 037;
107        } else {
108            outch = shift_pressed ? shift_map[c] : key_map[c];
109            if ( caps_pressed )  {
110                if      ( outch >= 'A' && outch <= 'Z' )  outch += 'a' - 'A';
111                else if ( outch >= 'a' && outch <= 'z' )  outch -= 'a' - 'A';
112            }
113        }
114
115        *ch = outch;
116        return 1;
117}
118
119
120void _IBMPC_keyboard_isr( rtems_unsigned32 interrupt )
121{
122    if ( _IBMPC_scankey( & kbd_buffer[ kbd_last ] ) )  {
123        /* Got one; save it if there is enough room in buffer. */
124        unsigned int next = (kbd_last + 1) % KBD_BUF_SIZE;
125        if ( next != kbd_first )
126            kbd_last = next;
127    }
128
129    /* Mark interrupt as handled */
130    outport_byte( 0x20, 0x20 );
131}
132
133
134int _IBMPC_chrdy( char * ch )
135{
136    if ( _IBMPC_Use_Go32_IO )  {
137        /* Read keyboard via BIOS: raw mode. */
138        if ( kbhit() )  {
139            *ch = getkey();
140            return 1;
141        } else {
142            return 0;
143        }
144    } else {
145        /* Check buffer our ISR builds */
146        if ( kbd_first != kbd_last )  {
147            *ch = kbd_buffer[ kbd_first ];
148            kbd_first = (kbd_first + 1) % KBD_BUF_SIZE;
149            return 1;
150        } else {
151            return 0;
152        }
153    }
154}
155
156int _IBMPC_inch( void )
157{
158    char Ch;
159    while ( ! _IBMPC_chrdy( & Ch ) )
160        continue;
161    return Ch;
162}
Note: See TracBrowser for help on using the repository browser.