-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathkeyboard.c
1924 lines (1624 loc) · 44.9 KB
/
keyboard.c
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Keyboard handling stuff
*
* This file belongs to FreeMiNT. It's not in the original MiNT 1.12
* distribution.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Konrad M. Kokoszkiewicz <draco@atari.org>
*
* TO DO:
*
* - a possibility to map scancodes to other scancodes (before processing)
* - deadkey support (expand translation tables with new vectors?)
* - translation tables in text form (avoid mktbl)
* - three phases of translation (scancode -> unicode -> ISO)?
*
* CHANGES:
* - Ozk: 4 June 2005.
* Moved handling of keyboard delay/repeat from VBL interrupt to
* roottimeouts.
* - joska: 15 December 2009.
* Added handling of deadkeys.
*
* UNRESOLVED:
* - Ozk: Since we cannot completely take over the keyboard interrupt when
* running on Milan hardware, and that Milan TOS calls ikbdsys vector
* for each repeated key, we cannot control those things by ourselves.
* So, we need to pass calls to Kbrate() to the ROM.
* - joska: I'm not 100% sure what Ozk really means here. Milan TOS does
* not call anything when a key is repeated - the PS/2 keyboard handles
* key repeat itself so the Milan actually doesn't know the difference
* between a normal keypress and a repeated one. On Milan, Kbrate() informs
* the keyboard of the new repeat-rate. I don't see any need to change
* this.
*
*/
# include "libkern/libkern.h" /* strcpy(), strcat(), ksprintf() */
# include "mint/asm.h" /* spl7() */
# include "mint/errno.h"
# include "mint/mint.h" /* FATAL() */
# include "mint/signal.h" /* SIGQUIT */
# include "arch/intr.h" /* click */
# include "arch/init_intr.h" /* syskey */
# include "arch/timer.h" /* get_hz_200() */
# include "arch/tosbind.h"
# include "arch/syscall.h"
# include "bios.h" /* kbshft, kintr, *keyrec, ... */
# include "biosfs.h" /* struct tty */
# include "cookie.h" /* get_cookie(), set_cookie() */
# include "debug.h" /* do_func_key() */
# include "dev-mouse.h" /* mshift */
# include "dos.h" /* s_hutdown() */
# include "dossig.h" /* p_kill() */
# include "global.h" /* tosver, machine, *sysdir */
# include "init.h" /* boot_printf() */
# include "info.h" /* messages */
# include "k_exec.h" /* sys_pexec() */
# include "k_fds.h" /* fp_alloc() */
# include "kmemory.h" /* kmalloc(), kfree() */
# include "keyboard.h" /* struct cad, struct keytbl */
# include "memory.h" /* get_region(), attach_region() */
# include "proc.h" /* rootproc */
# include "random.h" /* add_keyboard_randomness() */
# include "signal.h" /* killgroup() */
# include "timeout.h" /* addroottimeout() */
# ifndef NO_AKP_KEYBOARD
/* The _AKP cookie value consists of:
*
* bits 0-7 keyboard nationality
* bits 8-15 desktop nationality
*
* Actually some documentations say the opposite, but they lie.
*
* _AKP codes for the keyboard (the low byte of the low word)
* are as follows:
*
* 127 = all nationalities supported (?)
*
* 0 = USA 8 = Ger.Suisse 16 = Hungary 24 = Romania
* 1 = Germany 9 = Turkey 17 = Poland 25 = Bulgaria
* 2 = France 10 = Finnland 18 = Lituania 26 = Slovenia
* 3 = England 11 = Norway 19 = Russia 27 = Croatia
* 4 = Spain 12 = Danmark 20 = Estonia 28 = Serbia
* 5 = Italy 13 = S. Arabia 21 = Bialorus 29 = Montenegro
* 6 = Sweden 14 = Netherlands 22 = Ukraina 30 = Macedonia
* 7 = Fr.Suisse 15 = Czech 23 = Slovakia 31 = Greece
*
* 32 = Latvia 40 = Vietnam 48 = Bangladesh
* 33 = Israel 41 = India
* 34 = Sou. Africa 42 = Iran
* 35 = Portugal 43 = Mongolia
* 36 = Belgium 44 = Nepal
* 37 = Japan 45 = Laos
* 38 = China 46 = Kambodja
* 39 = Korea 47 = Indonesia
*
* The rest of codes are reserved for future extensions. Add ones,
* if you find a missing one. Consider there are various countries
* which all speak the same language, like all South America
* speaks Spanish or Portughese, the North America English or French
* etc.
*
*/
# if 0
# define WITHOUT_TOS
# endif
# define KBD_USA
# include "key_tables.h"
static const uchar modifiers[] =
{
/* Don't add CAPS here, it's handled separately */
CONTROL, RSHIFT, LSHIFT, ALTERNATE, CLRHOME, INSERT,
ALTGR, 0
};
/* Masks correspond to the above modifier scancodes */
static const uchar mmasks[] =
{
MM_CTRL, MM_RSHIFT, MM_LSHIFT, MM_ALTERNATE, MM_CLRHOME, MM_INSERT,
MM_ALTGR
};
/* Exported variables */
long iso_8859_code; /* this is 2 for ISO-8859-2, 3 for ISO-8859-3 etc., or 0 for default/undefined */
short kbd_pc_style_caps = 0; /* PC-style vs. Atari-style for Caps operation */
short kbd_mpixels = 8; /* mouse pixel steps */
short kbd_mpixels_fine = 1; /* mouse pixel steps in 'fine' mode */
struct cad_def cad[3]; /* for halt, warm and cold resp. */
int has_kbdvec = false; /* true if kbdvec present */
/* Auxiliary variables for ikbd_scan() */
static short cad_lock; /* semaphore to avoid scheduling shutdown() twice */
static short kbd_lock; /* semaphore to temporarily block the keyboard processing */
static long hz_ticks; /* place for saving the hz_200 timer value */
/* Alt/numpad */
static uchar numin[8]; /* buffer for storing ASCII code typed in via numpad */
static ushort numidx; /* index for the buffer above (0 = empty, 3 = full) */
/* Variables that deal with keyboard autorepeat */
static IOREC_T *last_iorec;
static uchar last_key[4]; /* last pressed key */
//static short key_pressed; /* flag for keys pressed/released (0 = no key is pressed) */
//static ushort keydel; /* keybard delay rate and keyboard repeat rate, respectively */
//static ushort krpdel;
//static ushort kdel, krep; /* actual counters */
static long keydel_time;
static long keyrep_time;
static TIMEOUT *m_to;
#ifndef MILAN
static TIMEOUT *k_to;
#endif
static ushort mouse_step;
/* keyboard table pointers */
static struct keytab *tos_keytab = &sys_keytab; /* see key_tables.h provide full table for any configuration */
static struct keytab *user_keytab = NULL;
static char *keytab_buffer = NULL;
static long keytab_size = 0;
static MEMREGION *user_keytab_region = NULL;
# define ROOT_TIMEOUT 1
# define CAD_TIMEOUT 5*200
/* Mouse event timeouts */
# define MOUSE_UP 0
# define MOUSE_DOWN 1
# define MOUSE_RIGHT 2
# define MOUSE_LEFT 3
# define MOUSE_LCLICK 5
# define MOUSE_RCLICK 6
# define MOUSE_TIMEOUT 40
static short keep_sending; /* flag for mouse packets auto-repetition */
static char mouse_packet[6];
static char mbuttons_state;
#define MOUSE_RBUTTON_DOWN 0x01
#define MOUSE_LBUTTON_DOWN 0x02
/* Mouse movements in four directions */
static void
mouse_up(PROC *p, long pixels)
{
long to;
mouse_packet[0] = 0xf8 + mbuttons_state; /* header */
mouse_packet[1] = 0; /* X axis */
mouse_packet[2] = -pixels; /* Y axis */
send_packet(syskey->mousevec, mouse_packet, mouse_packet + 3);
if (keep_sending)
{
if (!mouse_step)
{
to = 500;
mouse_step++;
}
else
to = 10;
m_to = addroottimeout(to, mouse_up, 0);
if (m_to) m_to->arg = pixels;
}
else
mouse_step = 0, m_to = NULL;
}
static void
mouse_down(PROC *p, long pixels)
{
long to;
mouse_packet[0] = 0xf8 + mbuttons_state; /* header */
mouse_packet[1] = 0; /* X axis */
mouse_packet[2] = pixels; /* Y axis */
send_packet(syskey->mousevec, mouse_packet, mouse_packet + 3);
if (keep_sending)
{
if (!mouse_step)
{
to = 500; //keydel;
mouse_step++;
}
else
to = 10; //krpdel;
m_to = addroottimeout(to, mouse_down, 0);
if (m_to) m_to->arg = pixels;
}
else
mouse_step = 0, m_to = NULL;
}
static void
mouse_left(PROC *p, long pixels)
{
long to;
mouse_packet[0] = 0xf8 + mbuttons_state; /* header */
mouse_packet[1] = -pixels; /* X axis */
mouse_packet[2] = 0; /* Y axis */
send_packet(syskey->mousevec, mouse_packet, mouse_packet + 3);
if (keep_sending)
{
if (!mouse_step)
{
to = 500; //keydel;
mouse_step++;
}
else
to = 10; //krpdel;
m_to = addroottimeout(to, mouse_left, 0);
if (m_to) m_to->arg = pixels;
}
else
mouse_step = 0, m_to = NULL;
}
static void
mouse_right(PROC *p, long pixels)
{
long to;
mouse_packet[0] = 0xf8 + mbuttons_state; /* header */
mouse_packet[1] = pixels; /* X axis */
mouse_packet[2] = 0; /* Y axis */
send_packet(syskey->mousevec, mouse_packet, mouse_packet + 3);
if (keep_sending)
{
if (!mouse_step)
{
to = 500; //keydel;
mouse_step++;
}
else
to = 10; //krpdel;
m_to = addroottimeout(to, mouse_right, 0);
if (m_to) m_to->arg = pixels;
}
else
mouse_step = 0, m_to = NULL;
}
/* Generate "no button" packet, simulating the mouse key release */
static void
mouse_noclick(PROC *p, long arg)
{
mouse_packet[0] = 0xf8 + mbuttons_state; /* header */
mouse_packet[1] = 0; /* X axis */
mouse_packet[2] = 0; /* Y axis */
send_packet(syskey->mousevec, mouse_packet, mouse_packet + 3);
}
/* Generate right click */
/* Note: Atari Compendium is wrong (as usual), when states that right
* click generates packet 0xfa, and left - 0xf9. This is exactly the
* other way around.
*/
static void
mouse_rclick(PROC *p, long arg)
{
mouse_packet[0] = 0xf8 + mbuttons_state; /* header */
mouse_packet[1] = 0; /* X axis */
mouse_packet[2] = 0; /* Y axis */
*kbshft &= ~MM_ALTERNATE;
send_packet(syskey->mousevec, mouse_packet, mouse_packet + 3);
*kbshft |= MM_ALTERNATE;
}
/* Generate left click */
static void
mouse_lclick(PROC *p, long arg)
{
mouse_packet[0] = 0xf8 + mbuttons_state; /* header */
mouse_packet[1] = 0; /* X axis */
mouse_packet[2] = 0; /* Y axis */
*kbshft &= ~MM_ALTERNATE;
send_packet(syskey->mousevec, mouse_packet, mouse_packet + 3);
*kbshft |= MM_ALTERNATE;
}
/* Generate double left click */
static void
mouse_dclick(PROC *p, long arg)
{
mouse_lclick(p, arg);
mbuttons_state &= ~MOUSE_LBUTTON_DOWN;
mouse_noclick(p, arg);
mbuttons_state |= MOUSE_LBUTTON_DOWN;
addroottimeout(MOUSE_TIMEOUT, mouse_lclick, 0);
}
static void
set_mouse_timeout( void _cdecl (*f)(PROC *, long arg), short make, short delta, long to)
{
if (make)
{
if (!m_to)
{
m_to = addroottimeout(to, f, 1);
if (m_to)
m_to->arg = delta;
}
}
else if (m_to)
{
cancelroottimeout(m_to);
m_to = NULL;
mouse_step = 0;
}
}
static bool
is_eiffel_mouse_key(ushort scan)
{
return ((scan >= 0x59 && scan <= 0x5f) && scan != 0x5b)
|| scan == 0x37;
}
# ifndef MILAN
static void put_key_into_buf(IOREC_T *iorec, uchar c0, uchar c1, uchar c2, uchar c3);
static void
kbd_repeat(PROC *p, long arg)
{
put_key_into_buf(last_iorec, last_key[0], last_key[1], last_key[2], last_key[3]);
kbdclick(last_key[1]);
k_to = addroottimeout(keyrep_time, kbd_repeat, 1);
}
static void
set_keyrepeat_timeout(short make)
{
if (make)
{
if (k_to)
cancelroottimeout(k_to);
k_to = addroottimeout(keydel_time, kbd_repeat, 1);
}
else if (k_to)
{
cancelroottimeout(k_to);
k_to = NULL;
}
}
# endif
INLINE short
generate_mouse_event(uchar shift, ushort scan, ushort make)
{
short delta = (shift & MM_ESHIFT) ? kbd_mpixels_fine : kbd_mpixels;
switch (scan)
{
case UP_ARROW:
{
set_mouse_timeout(mouse_up, make, delta, ROOT_TIMEOUT);
if ((keep_sending = make))
kbdclick(scan);
return -1;
}
case DOWN_ARROW:
{
set_mouse_timeout(mouse_down, make, delta, ROOT_TIMEOUT);
if ((keep_sending = make))
kbdclick(scan);
return -1;
}
case RIGHT_ARROW:
{
set_mouse_timeout(mouse_right, make, delta, ROOT_TIMEOUT);
if ((keep_sending = make))
kbdclick(scan);
return -1;
}
case LEFT_ARROW:
{
set_mouse_timeout(mouse_left, make, delta, ROOT_TIMEOUT);
if ((keep_sending = make))
kbdclick(scan);
return -1;
}
case INSERT:
{
if (make)
{
mbuttons_state |= MOUSE_LBUTTON_DOWN;
if (shift & MM_RSHIFT)
addroottimeout(ROOT_TIMEOUT, mouse_dclick, 1);
else
addroottimeout(ROOT_TIMEOUT, mouse_lclick, 1);
kbdclick(scan);
}
else
{
/* Generate "release" packet */
mbuttons_state &= ~MOUSE_LBUTTON_DOWN;
addroottimeout(MOUSE_TIMEOUT, mouse_noclick, 0);
}
return -1;
}
case CLRHOME:
{
if (make)
{
mbuttons_state |= MOUSE_RBUTTON_DOWN;
addroottimeout(ROOT_TIMEOUT, mouse_rclick, 1);
kbdclick(scan);
}
else
{
/* Generate "release" packet */
mbuttons_state &= ~MOUSE_RBUTTON_DOWN;
addroottimeout(MOUSE_TIMEOUT, mouse_noclick, 0);
}
return -1;
}
}
return 0;
}
/* Routine called after the user hit Ctrl/Alt/Del
*/
static void
ctrl_alt_del(PROC *p, long arg)
{
switch (cad[arg].action)
{
/* 1 is to signal a pid */
case 1:
{
if (sys_p_kill(cad[arg].par.pid, cad[arg].aux.arg) < 0)
sys_s_hutdown(arg);
cad_lock = 0;
break;
}
/* 2 shall be to exec a program
* with a path pointed to by par.path
*/
case 2:
{
if (sys_pexec (100, cad[arg].par.path, cad[arg].aux.cmd, cad[arg].env) < 0)
sys_s_hutdown(arg);
cad_lock = 0;
break;
}
/* 0 is default */
default:
{
sys_s_hutdown(arg);
break;
}
}
cad_lock = 0;
}
/* synchronous Ctrl/Alt/F? callback
* for the debug facilities
*/
static void
ctrl_alt_Fxx (PROC *p, long arg)
{
do_func_key (arg);
}
/* Similar callback for the Alt/Help.
*
* To avoid problems with the actual current directory,
* the program gets its path as the command line.
* Or shall we explicitly force it to that?
*
* Also a problem here:
* since the program is executed directly by the kernel,
* it can at most get the same environment as init has.
*
*/
static void
alt_help(PROC *p, long arg)
{
char pname[32], cmdln[32];
ksprintf(pname, sizeof(pname), "%salthelp.sys", sysdir);
ksprintf(cmdln, sizeof(cmdln), " %salthelp.sys", sysdir);
cmdln[0] = (char)(strlen(cmdln) - 1);
sys_pexec(100, pname, cmdln, _base->p_env);
}
/* The handler
*/
static void
put_key_into_buf(IOREC_T *iorec, uchar c0, uchar c1, uchar c2, uchar c3)
{
char *new_buf_pos;
# if 0
/* bit 2 of conterm variable decides, whether we
* put the shift status to the buffer or not.
*/
if ((*(uchar *)0x0484L & 0x04) == 0)
c0 = 0;
# endif
// display("c0 %x, c1 %x, c2 %x, c3 %x", c0, c1, c2, c3);
iorec->tail += 4;
if (iorec->tail >= iorec->buflen)
iorec->tail = 0;
/* Precalculating this saves some memory */
new_buf_pos = iorec->bufaddr + iorec->tail;
*new_buf_pos++ = c0;
*new_buf_pos++ = c1;
*new_buf_pos++ = c2;
*new_buf_pos++ = c3;
/* c1 == 0 means that this "keypress" was generated
* by typing on the numpad while holding Alt down.
* We don't want this to be repeated.
*/
if (c1)
{
last_iorec = iorec;
last_key[0] = c0;
last_key[1] = c1;
last_key[2] = c2;
last_key[3] = c3;
}
kintr = 1;
}
/* Translate scancode into ASCII according to the keyboard
* translation tables.
*/
static const uchar iso_1_ctype[128] =
{
/* 0x80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xa0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xb0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xc0 */ _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu,
/* 0xd0 */ _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, 0x00, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu,
/* 0xe0 */ _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl,
/* 0xf0 */ _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, 0x00, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl
};
static const uchar iso_1_tolower[128] =
{
/* 0x80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xa0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xb0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xc0 */ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
/* 0xd0 */ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0x00, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
/* 0xe0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xf0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const uchar iso_1_toupper[128] =
{
/* 0x80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xa0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xb0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xc0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xd0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xe0 */ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
/* 0xf0 */ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0x00, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf
};
static const uchar iso_2_ctype[128] =
{
/* 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F */
/* 0x80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xa0 */ 0x00, _CTu, 0x00, _CTu, 0x00, _CTu, _CTu, 0x00, 0x00, _CTu, _CTu, _CTu, _CTu, 0x00, _CTu, _CTu,
/* 0xb0 */ 0x00, _CTl, 0x00, _CTl, 0x00, _CTl, _CTl, 0x00, 0x00, _CTl, _CTl, _CTl, _CTl, 0x00, _CTl, _CTl,
/* 0xc0 */ _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu,
/* 0xd0 */ _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, 0x00, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, _CTu, 0x00,
/* 0xe0 */ _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl,
/* 0xf0 */ _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, 0x00, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, _CTl, 0x00
};
static const uchar iso_2_tolower[128] =
{
/* 0x80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xa0 */ 0x00, 0xB1, 0x00, 0xB3, 0x00, 0xB5, 0xB6, 0x00, 0x00, 0xB9, 0xBA, 0xBB, 0xBC, 0x00, 0xBE, 0xBF,
/* 0xb0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xc0 */ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
/* 0xd0 */ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x00, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x00,
/* 0xe0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xf0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const uchar iso_2_toupper[128] =
{
/* 0x80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xa0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xb0 */ 0xA0, 0xA1, 0x00, 0xA3, 0x00, 0xA5, 0xA6, 0x00, 0x00, 0xA9, 0xAA, 0xAB, 0xAC, 0x00, 0xAE, 0xAF,
/* 0xc0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xd0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0xe0 */ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
/* 0xf0 */ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0x00, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0x00
};
static const uchar *iso_tables[] =
{
NULL, iso_1_ctype, iso_2_ctype, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL
};
static const uchar *iso_tolower_tables[] =
{
NULL, iso_1_tolower, iso_2_tolower, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL
};
static const uchar *iso_toupper_tables[] =
{
NULL, iso_1_toupper, iso_2_toupper, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL
};
INLINE uchar
iso_isupper(uchar c)
{
const uchar *table;
if (c < 128)
return isupper(c);
table = iso_tables[iso_8859_code];
if (table == NULL)
return isupper(c);
c -= 128;
return table[c] & _CTu;
}
INLINE uchar
iso_islower(uchar c)
{
const uchar *table;
if (c < 128)
return islower(c);
table = iso_tables[iso_8859_code];
if (table == NULL)
return islower(c);
c -= 128;
return table[c] & _CTl;
}
INLINE uchar
iso_tolower(uchar asc)
{
const uchar *table;
uchar c;
if (asc < 128)
return tolower(asc);
if (iso_isupper(asc))
{
table = iso_tolower_tables[iso_8859_code];
if (table == NULL)
return tolower(asc);
c = asc - 128;
if (table[c])
return table[c];
}
return asc;
}
INLINE uchar
iso_toupper(uchar asc)
{
const uchar *table;
uchar c;
if (asc < 128)
return toupper(asc);
if (iso_islower(asc))
{
table = iso_toupper_tables[iso_8859_code];
if (table == NULL)
return toupper(asc);
c = asc - 128;
if (table[c])
return table[c];
}
return asc;
}
INLINE uchar
scan2asc(uchar scancode)
{
uchar asc = 0, *vec, shift = *kbshft;
/* The AKP table structure is:
* ss, aa, ss, aa, ss, aa, 0
* where 'ss' is scancode and 'aa' is corresponding
* ASCII value.
*/
if (shift & (MM_ALTERNATE | MM_ALTGR))
{
if (shift & MM_ALTGR)
vec = user_keytab->altgr;
else
{
if (shift & MM_CTRL)
{
vec = NULL;
if (shift & MM_ESHIFT)
asc = user_keytab->shift[scancode];
else
asc = user_keytab->unshift[scancode];
}
else if (shift & MM_ESHIFT)
vec = user_keytab->altshift;
else if (shift & MM_CAPS)
vec = user_keytab->altcaps;
else
vec = user_keytab->alt;
}
while (vec && *vec)
{
if (vec[0] == scancode)
{
asc = vec[1];
break;
}
vec++; vec++;
}
}
else
{
/* Shift/1 should give "!" regardless of the Caps state
*/
if (shift & MM_ESHIFT)
vec = user_keytab->shift;
else if (shift & MM_CAPS)
vec = user_keytab->caps;
else
vec = user_keytab->unshift;
if (vec)
asc = vec[scancode];
}
/* We can optionally emulate the PC-like behaviour of Caps/Shift */
if (kbd_pc_style_caps)
{
if (((shift & MM_ALTGR) == 0) && (shift & MM_CAPS) && (shift & MM_ESHIFT))
asc = iso_tolower(asc);
}
/* Ctrl key works as this regardless of the Alt/AltGr state.
* Otherwise the keyboard shortcuts (like Ctrl/Alt/Q) don't work
* anymore in N.AES.
*/
if (shift & MM_CTRL)
{
if (asc == 0x0d)
asc = 0x0a; /* God bless great ideas */
if ((asc & 0x80) == 0)
asc &= 0x1f;
}
return asc;
}
# undef SCANCODE_TESTING
# ifdef SCANCODE_TESTING
static void
output_scancode(PROC *p, long arg)
{
uchar ascii;
ascii = scan2asc((ushort)arg);
DEBUG(("Scancode: %02lx, ASCII %02x", arg, (short)ascii));
}
# endif
/* Keyboard interrupt routine.
*
* The scancode is passed from newkeys(), which in turn is called
* by BIOS.
*
*/
/* `scancode' is short, but only low byte matters. The high byte
* is zeroed by newkeys().
*/
struct scanb_entry
{
IOREC_T *iorec;
unsigned short scan;
};
static TIMEOUT *ikbd_to = NULL;
static int scanb_head = 0;
static int scanb_tail = 0;
static struct scanb_entry scanb[16];
static void _cdecl IkbdScan(PROC *, long);
void _cdecl
ikbd_scan(ushort scancode, IOREC_T *rec)
{
int tail = (scanb_tail + 1) & 0xf;
if (tail != scanb_head)
{
scanb[scanb_tail].iorec = rec;
scanb[scanb_tail].scan = scancode;
scanb_tail = tail;
}
# ifdef WITH_SINGLE_TASK_SUPPORT
if( curproc->modeflags & M_SINGLE_TASK )
{
# ifdef DEBUG_INFO
extern short in_kernel;
DEBUG(("ikbd_scan directly for '%s' head=%d p_flags=%lx slices=%d in_kernel=%x", curproc->name, scanb_head, curproc->p_mem->base->p_flags, curproc->slices, in_kernel ));
# endif
IkbdScan( curproc, 1);
}
else
# endif
if (!ikbd_to)
{
ikbd_to = addroottimeout(0L, IkbdScan, 1);
}
}
static void _cdecl
IkbdScan(PROC *p, long arg)
{
do
{
IOREC_T *iorec;
ushort scancode;
ushort mod = 0, clk = 0, x = 0, scan, make;
uchar shift = *kbshft, ascii;
iorec = scanb[scanb_head].iorec;
scancode = scanb[scanb_head].scan;
scanb_head = (scanb_head + 1) & 0xf;
TRACE(("ikbd_scan: scancode=%x, rec=%p, h=%i, t=%i", scancode, iorec, scanb_head, scanb_tail));
scan = scancode & 0xff;
if (is_eiffel_mouse_key(scan))
{
put_key_into_buf(iorec, shift, (uchar)scan, 0, 0);
continue; //goto again;
}
/* This is set during various keyboard table initializations
* e.g. when the user calls Bioskeys(), to prevent processing
* go according to incomplete keyboard translation tables.
*/
if (kbd_lock)
break;
# ifdef SCANCODE_TESTING
{
TIMEOUT *t;
t = addroottimeout (ROOT_TIMEOUT, (void _cdecl (*)(PROC *))output_scancode, 1);
if (t)
t->arg = scancode;