summaryrefslogtreecommitdiffstats
path: root/private/ntos/fw/alpha/fwsignal.c
blob: 9e0df889b0612ee09abccf0a897e4f7fb7da9342 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*++

Copyright (c) 1991  Microsoft Corporation
Copyright (c) 1992, 1993  Digital Equipment Corporation

Module Name:

    fwsignal.c

Abstract:

    This module implements the ARC firmware Signal Handling Functions.

Author:

    Lluis Abello (lluis) 24-Sep-1991


Revision History:

    22-May-1992         John DeRosa [DEC]

    Modified this for Alpha.  The vestigal interrupt and signal
    support was removed, and keyboard input is done by polling.

--*/

#include "fwp.h"
#include "iodevice.h"

extern KEYBOARD_BUFFER KbdBuffer;

//
// Keyboard static variables.
//

BOOLEAN Scan0xE0 = FALSE;

//                             1111 1 1111122222222 2 2333333333344 4 44444445555 5 5 55
// Character #         234567890123 4 5678901234567 8 9012345678901 2 34567890123 4 5 67
PCHAR NormalLookup =  "1234567890-=\b\tqwertyuiop[]\n\0asdfghjkl;'`\0\\zxcvbnm,./\0\0\0 ";
PCHAR ShiftedLookup = "!@#$%^&*()_+\b\0QWERTYUIOP{}\n\0ASDFGHJKL:\"~\0\|ZXCVBNM<>?\0\0\0 ";

extern BOOLEAN FwLeftShift;
extern BOOLEAN FwRightShift;
extern BOOLEAN FwControl;
extern BOOLEAN FwAlt;
extern BOOLEAN FwCapsLock;


VOID
StoreKeyboardChar(
    IN UCHAR Character
    )
/*++

Routine Description:

    This routine stores the given character into the circular
    buffer if there is enough room. Otherwise the character is lost.

Arguments:

    Character - Supplies the translated scan code to store into the buffer

Return Value:

    None.

--*/
{
    //
    // Store scan code in buffer if there is room.
    //
    if (((KbdBuffer.WriteIndex+1) % KBD_BUFFER_SIZE) != KbdBuffer.ReadIndex) {
        KbdBuffer.WriteIndex = (KbdBuffer.WriteIndex+1) % KBD_BUFFER_SIZE;
        KbdBuffer.Buffer[KbdBuffer.WriteIndex] = Character;
    }
}


VOID
TranslateScanCode(
    IN UCHAR Scan
    )

/*++

Routine Description:

    This routine translates the given keyboard scan code into an
    ASCII character and puts it in the circular buffer.

Arguments:

    Scan - Supplies the scan code read from the keyboard.

Return Value:

    None.

--*/

{
    UCHAR FwControlCharacter=0;
    UCHAR FwFunctionCharacter;
    BOOLEAN MakeCode;
    UCHAR Char;

    //
    // Check 0xE0, which introduces a two key sequence.
    //

    if (Scan == 0xE0) {
        Scan0xE0 = TRUE;
        return;
    }

    if (Scan0xE0 == TRUE) {

        //
        // Check for PrintScrn (used as SysRq, also found in its true Alt
        // form below).
        //

        if (Scan == KEY_PRINT_SCREEN) {
            StoreKeyboardChar(ASCII_SYSRQ);
            Scan0xE0 = FALSE;
            return;
        }
    }

    //
    // Look for scan codes that indicate shift, control, or alt keys.  Bit 7
    // of scan code indicates upward or downward keypress.
    //
    // N.B. By masking the scan code with 0x7f, both the make and break codes
    // are covered.
    //

    MakeCode = !(Scan & 0x80);
    switch (Scan & 0x7F) {

        case KEY_LEFT_SHIFT:
            FwLeftShift = MakeCode;
            return;

        case KEY_RIGHT_SHIFT:
            FwRightShift = MakeCode;
            return;

        case KEY_CONTROL:
            FwControl = MakeCode;
            Scan0xE0 = FALSE;
            return;

        case KEY_ALT:
            FwAlt = MakeCode;
            return;

        default:
            break;
    }

    //
    // The rest of the keys only do something on make.
    //

    if (MakeCode) {

        //
        // Check for control keys.
        //

        switch (Scan) {

            case KEY_UP_ARROW:
                FwControlCharacter = 'A';
                break;

            case KEY_DOWN_ARROW:
                FwControlCharacter = 'B';
                break;

            case KEY_RIGHT_ARROW:
                FwControlCharacter = 'C';
                break;

            case KEY_LEFT_ARROW:
                FwControlCharacter = 'D';
                break;

            case KEY_HOME:
                FwControlCharacter = 'H';
                break;

            case KEY_END:
                FwControlCharacter = 'K';
                break;

            case KEY_PAGE_UP:
                FwControlCharacter = '?';
                break;

            case KEY_PAGE_DOWN:
                FwControlCharacter = '/';
                break;

            case KEY_INSERT:
                FwControlCharacter = '@';
                break;

            case KEY_DELETE:
                FwControlCharacter = 'P';
                break;

            case KEY_SYS_REQUEST:
                StoreKeyboardChar(ASCII_SYSRQ);
                return;

            case KEY_ESC:
                StoreKeyboardChar(ASCII_ESC);
                return;

            case KEY_CAPS_LOCK:
                FwCapsLock = !FwCapsLock;
                return;

            case KEY_F1:
                FwControlCharacter = 'O';
                FwFunctionCharacter = 'P';
                break;

            case KEY_F2:
                FwControlCharacter = 'O';
                FwFunctionCharacter = 'Q';
                break;

            case KEY_F3:
                FwControlCharacter = 'O';
                FwFunctionCharacter = 'w';
                break;

            case KEY_F4:
                FwControlCharacter = 'O';
                FwFunctionCharacter = 'x';
                break;

            case KEY_F5:
                FwControlCharacter = 'O';
                FwFunctionCharacter = 't';
                break;

            case KEY_F6:
                FwControlCharacter = 'O';
                FwFunctionCharacter = 'u';
                break;

            case KEY_F7:
                FwControlCharacter = 'O';
                FwFunctionCharacter = 'q';
                break;

            case KEY_F8:
                FwControlCharacter = 'O';
                FwFunctionCharacter = 'r';
                break;

            case KEY_F9:
                FwControlCharacter = 'O';
                FwFunctionCharacter = 'p';
                break;

            case KEY_F10:
                FwControlCharacter = 'O';
                FwFunctionCharacter = 'M';
                break;

//            case KEY_F11:
//                FwControlCharacter = 'O';
//                FwFunctionCharacter = 'A';
//                break;
//
//            case KEY_F12:
//                FwControlCharacter = 'O';
//                FwFunctionCharacter = 'B';
//                break;

            default:

                //
                // Some kind of character.
                //

                Char = 0;

                //
                // Check for keypad + or -.  This is done here because we only
                // recognize a two keypad keys.  Full keypad support should be
                // done by a lookup table.
                //

                if (Scan == KEY_KEYPAD_MINUS) {

                    Char = '-';

                } else if (Scan == KEY_KEYPAD_PLUS) {

                    Char = '+';

                } else if (((Scan >= 16) && (Scan <= 25)) ||
                           ((Scan >= 30) && (Scan <= 38)) ||
                           ((Scan >= 44) && (Scan <= 50))) {

                    //
                    // Alphabetic character
                    //

                    if (FwControl) {

                        //
                        // Control character.
                        //
                        // This works for ^A -- ^Z.
                        //

                        Char = NormalLookup[Scan - 2] - 'A';

                    } else {

                        //
                        // ASCII alphanumeric character.   Set up to store
                        // either the main key or shifted key character.
                        //

                        if (((FwLeftShift || FwRightShift) && !FwCapsLock) ||
                            (!(FwLeftShift || FwRightShift) && FwCapsLock)) {
                            Char = ShiftedLookup[Scan - 2];
                        } else {
                            Char = NormalLookup[Scan - 2];
                        }
                    }

                } else if ((Scan > 1) && (Scan < 58)) {

                    //
                    // It is ASCII but not alpha, so do not shift on CapsLock.
                    //

                    if (FwLeftShift || FwRightShift) {
                        Char = ShiftedLookup[Scan - 2];
                    } else {
                        Char = NormalLookup[Scan - 2];
                    }
                }

                //
                // If a character, store it in buffer.
                //

                if (Char) {
                    StoreKeyboardChar(Char);
                    return;
                }
                break;
        }

        //
        // This is for ASCII_CSI sequences, not normal control characters.
        //

        if (FwControlCharacter) {
            StoreKeyboardChar(ASCII_CSI);
            StoreKeyboardChar(FwControlCharacter);
            if (FwControlCharacter == 'O') {
               StoreKeyboardChar(FwFunctionCharacter);
            }
            return;
        }
    }
}