summaryrefslogtreecommitdiffstats
path: root/private/os2/os2ses/i386/kbdxlat.asm
blob: 5f282b9beb989f6451633ca944a677d9ac8fcc4c (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
;            SCCSID = @(#)kbdxlat.asm   12.21 89/07/25
;OS2SS-  Page  58,132

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;$$
;$$  Module:    kbdxlat.asm             Version:        1.2 ABIOS
;$$
;$$  History:   This module was derived from the 1.2 AT source code.
;$$             ABIOS changes were made according to the deltas between
;$$             the 1.1 ABIOS and 1.1 AT drivers.  The 1.1 ABIOS driver
;$$             was done by John Nels Fuller (Wyse).  The 1.2 ABIOS
;$$             driver was done by Alan J. Cotterman (NCR).
;$$
;$$  Notes:     Wherever possible the original 1.2 AT code is preserved.
;$$             All changes are marked with ";$$".
;$$
;$$             The only modification to this module is in testing for
;$$             keyboard type.  References to "IDFlags" have been
;$$             replaced with tests of the contents of "KbdHWIDs".
;$$
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

  Title   KBDXLAT - Translation Process
  Name    KBDXLAT
;***********************************************************************
;**                                                                   **
;**          Keyboard Device Driver Scan Code Translation             **
;**                                                                   **
;**                                                                   **
;** This file contains the scan code to character translation process **
;** code. The code in this file is only called once by KBDDD and is   **
;** not accessed by anyone else. So the entire translation process    **
;** can be replaced by replacing the routine in this file. The data   **
;** that is only used by the code in this file is in the file         **
;** KBDXDATA.ASM and it too would be replaced if this code is to be   **
;** replaced.                                                         **
;**                                                                   **
;** 6/22/93 MJarus line with os2ss were modified by os2ss.            **
;***********************************************************************
.386p   ;OS2SS-.286
.sall
.xcref
;@@ The following files are included, but xlist'd out:

.xlist
  Include struc.inc      ;Structured assembly macros.
  Include kbddd.inc      ;Keyboard Device Driver structures & equates.
  Include kbdxlat.inc    ;Translation structures & equates.
.list

  Extrn _Ow2MiscFlags:Byte          ; 704,747,771,931,1188 (EnhancedKbd)
  Extrn _Ow2MiscFlags3:Byte         ; 1089,1154,1166,...(AltPacket SecAltNumPad PauseLatch E0Packet)
  Extrn _Ow2KCBShFlgs:Word           ; 2299
  Extrn _Ow2KbdHWIDs:Word                   ;$$ Extrn IDFlags:Word
  ;Extrn OtherFlags:Byte         ; (Test OtherFlags,InterruptTime) moved to [EDI]
  ;Extrn AltTable:Byte           ; 275
  ;Extrn AltPadMap:Byte          ; 562
  ;Extrn CtlPadMap:Byte          ; 601
  ;Extrn NewExtSC:Byte           ; only CheckExtended()
  ;Extrn NewExtSCLen:ABS         ; only CheckExtended()

_TEXT   SEGMENT DWORD USE32 PUBLIC 'CODE'
        ASSUME  CS:FLAT, DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING

AltPadMap  Label Byte
        db       7,8,9,-1
        db       4,5,6,-1
        db       1,2,3
        db       0,-1

CtlPadMap  Label Byte
;       db       119,-1,132,-1
;       db       115,-1,116,-1
;       db       117,-1,118
;       db       -1,-1
        db       119,141,132,142  ;@@ Keypad 7, 8, 9, -      (PTM 5024)
        db       115,143,116,144  ;@@ Keypad 4, 5, 6, +      (PTM 5024)
        db       117,145,118      ;@@ Keypad 1, 2, 3         (PTM 5024)
        db       146,147          ;@@ Keypad 0, .            (PTM 5024)

;*****
;*  Translation for keypresses on AlphaKeys with Alt pressed. This
;*  translation is ALWAYS indexed by the Char1 value less 96 (which
;*  is ascii "a").  The translation value is the scan code that
;*  would come in on a regular PC keyboard (or PC/AT keyboard in
;*  compatability mode).
;*****
AltTable  Label  Byte
;                a, b, c, d, e, f, g, h, i, j, k, l, m
        db      30,48,46,32,18,33,34,35,23,36,37,38,50 ;
;                n, o, p, q, r, s, t, u, v, w, x, y, z
        db      49,24,25,16,19,31,20,22,47,17,45,21,44 ;

NewExtSC        LABEL BYTE

;@@             ALT+
;@@                  [  ]    ;   '   `   \   ,   .   /  Tab
                db  1Ah,1Bh,27h,28h,29h,2Bh,33h,34h,35h,0Fh

NewExtSCLen     equ $-NewExtSC                  ;@@ Used by interrupt handler.

Even                        ;Make sure we're an even number of bytes. *
;                                                                    *
;                                                                   *
;*** END OF THE TRANSLATION TABLE **********************************


;OS2SS-...
; ULONG
; Ow2KbdXlate(
;             ULONG             ScanCode,
;             PKBD_XLATE_VARS   pFlagArea,
;             PKBD_MON_PACKAGE  pMonitorPack,
;             PVOID             pTransTable
;            );

Public _Ow2KbdXlate@16
_Ow2KbdXlate@16   Proc ;------------------------------------------------------\

        push    ebp
        mov     ebp,esp
        sub     esp,8           ; for local arguments
        push    ebx
        push    ecx
        push    edx
        push    edi
        push    esi

;
; now:
;
; ebp-8  Pointer to DD of XlateTable entry for this scan code.
; ebp-4  Pointer to DD holding Offset of top of XlateTable
;
; ebp+0  old ebp
; ebp+4  Return Address
; ebp+8  ScanCode
; ebp+12 pFlagArea
; ebp+16 pMonitorPack
; ebp+20 pTransTable
;

        mov     eax, [ebp+8]
        mov     edi, [ebp+12]
        mov     esi, [ebp+16]
        mov     ebx, [ebp+20]
;        cmp     ebx,0
;        jnz     HaveTable
;                                                ; if no translate table
;        mov     ebx,Offset XlateTable           ; set the default one
;
;HaveTable:
        call    KbdXlate
        mov     al,0                            ; Error ?
        jnc     EndXlate                        ; yes - no packet
        test    [esi].DDFlags,MultiMake
        jnz     EndXlate                        ; ignore multiple make of toggle key
        test    [edi].XPSGFlags, PrevAccent
        jnz     EndXlate                        ; ignore accent char till next keystroke
        mov     ah,byte ptr [esi].DDFlags
        and     ah,KeyTypeMask
        cmp     ah,UndefKey                     ; Is this key undefined?
        je      EndXlate                        ; yes - ignore
        cmp     byte Ptr [esi+KeyPacketLen].MonFlags,-1      ; do we have two packets?
        mov     al,1                            ; assume not
        jnz     EndXlate
        mov     al,2                            ; 2 packets

EndXlate:
        and     eax,0FFh                        ; returns in al number of packets
        pop     esi
        pop     edi
        pop     edx
        pop     ecx
        pop     ebx
        mov     esp,ebp
        pop     ebp
        ret     16

_Ow2KbdXlate@16 Endp  ;-------------------------------------------------------/

KbdXlate   Proc ;------------------------------------------------------\

;***********************************************************************
;*                                                                     *
;* Subroutine Name: KbdXlate                                           *
;*                                                                     *
;* Descriptive Name: Keyboard Scan Code Translation                    *
;*                                                                     *
;* Function:   This routine translates the scan code received from     *
;*             the keyboard and places it in the Monitor Key Packet.   *
;*             It also sets all flags that are based on the scan code  *
;*             received.                                               *
;*                                                                     *
;* Entry Point: KbdXlate             Linkage: Near                     *
;*                                                                     *
;* Input:    AL=Raw Scan Code     EDI = Ptr to translation flag area   *
;*           ESI = Ptr to Monitor KeyPacket                            *
;*           EBX = Ptr to Translate Table                              *
;*                                                                     *
;* Exit-Normal: Monitor Key Packet filled in                           *
;*              AL=Raw scan code if translation successful             *
;*                                                                     *
;* Exit-Error:  If found a break of a shift key that had seen no       *
;*              make, returns 0 and CX hold the unexpected shift bits. *
;*                                                                     *
;* Effects:     All regs except SI, DI and the Seg regs may be altered *
;*              Key Packet filled in                                   *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: UnPauseChk                                             *
;*              AccCheckout                                            *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None.                                                 *
;*                                                                     *
;*                                                                     *
;***********************************************************************
  Or Byte Ptr [ESI].MonFlags,NotInserted ;OS2SS-Key isn't monitor inserted.
  And [EDI].XlateFlags,Not NormalAlt ;OS2SS-@@ Turn flag off to start
  Mov AH,AL                          ;Copy scan code into AH
  Or AH,AH                           ;Check if key break bit in
 .If <s>                             ;If it is
    Or [ESI].DDFlags,KeyBreak        ;OS2SS-Set Flag
    And AH,Not BreakBit              ;Clear the break bit from the scan code
 .Endif                              ;Endif key break bit on

  Mov DL,AL                     ;OS2SS-Now calculate...
  And EDX,07Fh                   ;OS2SS-...the index into...
  Dec EDX                        ;OS2SS-  ...XlateTable for...
  IMul EDX,KDefLen               ;OS2SS-     ...this scan code.
  Add EDX,KDefs                  ;OS2SS-Point past header to keydefs.
  Add EDX,EBX                     ;OS2SS-Add offset into table.
  Mov [EBP-8],EDX               ;OS2SS-Save Pointer to XlateTable entry for this scan code.
  Mov [EBP-4],EBX                ;OS2SS-Put table start offset on the stack.
  Mov BX,[EDX].XlateOp       ;OS2SS-Get Xlate Operation word.
  And EBX,ActionMask            ;OS2SS-Isolate translate action field.

  Mov [ESI].Key.Scan,AH              ;OS2SS-Put scan code in key packet
  Test [EDI].XlateFlags,SecPrefix    ;OS2SS-@@ Check if saw E0 prefix last time
 .If <nz>                            ;If we did
     Or [ESI].DDFlags,SecondaryKey   ;OS2SS-@@ Indicate so.
                                     ;@@ PTM 4359
    .If <AL eq 53>                   ;@@ If this is '/' on Numpad
       Test [ESI].Key.Shift,AltFlag  ;OS2SS-@@ PTM 5024
      .If <nz>                      ;@@ If ALT Key is down
          Mov [ESI].Key.Scan,0A4h    ;OS2SS-@@ Set extended scan code
      .Else                         ;@@ Else no Alt down
          Test [ESI].Key.Shift,CtlFlag ;OS2SS-@@ Check if Ctl key down
         .If <nz>                   ;@@ If it is
              Mov [ESI].Key.Scan,095h ;OS2SS-@@ Set extended scan code
         .Else                       ;@@ Else no Alt or Ctl key down
              Mov [ESI].Key.Char,'/'  ;OS2SS-@@ then it is always '/' regardless
              Mov [ESI].Key.Scan,OtherKey ;OS2SS-@@ and the scan code is EO
         .Endif                      ;@@ Endif Ctl key down
      .Endif                         ;@@ End PTM 5024
       Jmp EndActionCase            ;@@ of country/code page.
    .Endif
 .Endif

  ;From now on, ES:EDX (;OS2SS-)points to the Xlate table entry. If running in
  ;3xBox(;OS2SS-can't be), that pointer may have been created by a LOADALL, so don't
  ;allow interrupts, nor change Seg Regs. Also, the beginning offset
  ;of the translate table itself is on the top of stack.

  Mov CX,Word Ptr [EDX+2]    ;OS2SS-@@ Get Char1 and Char2 values.
  Mov DX,[ESI].Key.Shift        ;OS2SS-Get the current shift status from Key.

 .If <BX ne 7> AND    ;@@ If not a padkey clear possible Alt-nnn entry.
 .If <BX ne 14>                ;@@ Don't clear on Alt key, either.
    Mov [EDI].XAltKeyPad,0      ;OS2SS-@@ Clear Alt-nnn entry.
 .Endif
  Mov AL,CL                    ;Copy Char1 for use later.
 .If <BX gt MaxAct>            ;@@ Was the action number too big?
    Jmp NoXlate                ;Yes, so don't try to translate.
 .Endif
  Shl BX,2                     ;Make action number an offset.
  Add EBX,Offset XJumpTable    ;OS2SS-@@ Point to processor address.
  Jmp [EBX]                  ;OS2SS-Go translate.

  ;Following is the branch table for the various actions that
  ;can be performed on a keystroke. Processing re-merges at the
  ;bottom of this CASE structure, at label "EndActionCase".

Public NoXlate, AlphaKey, SpecKey, SpecKeyC, SpecKeyA, SpecKeyCA
Public FuncKey, PadKey,   SpecCtlKey,  PrtScr, SysReq, AccentKeyType
Public ShiftKeys, ToggleKey,  AltKey,  NumLock, CapsLock, ScrollLock
Public XShiftKey, XToggleKey, SpecKeyCS,   SpecKeyAS
Even
XJumpTable:
    dd  NoXlate       ;0  Invalid action code, no translate done.
    dd  AlphaKey      ;1  Alphabetical character key.
    dd  SpecKey       ;2  Special non-alpha key, no CAPSLOCK or ALT.
    dd  SpecKeyC      ;3  Special non-alpha key, with CAPSLOCK.
    dd  SpecKeyA      ;4  Special non-alpha key, with ALT.
    dd  SpecKeyCA     ;5  Special non-alpha key, w/CAPSLOCK and ALT.
    dd  FuncKey       ;6  Function keys.
    dd  PadKey        ;7  Numeric keypad keys.
    dd  SpecCtlKey    ;8  Keys that do special things with CTL.
    dd  PrtScr        ;9  The print screen key.
    dd  SysReq        ;A  The system request key.
    dd  AccentKeyType ;B  A key that affects the NEXT key (dead key).
    dd  ShiftKeys     ;C  The LSHIFT, RSHIFT, and CTL keys.
    dd  ToggleKey     ;D  General Toggle key.
    dd  AltKey        ;E  The ALT key.
    dd  NumLock       ;F  The NUMLOCK key.
    dd  CapsLock      ;10 The CAPSLOCK key.
    dd  ScrollLock    ;11 The SCROLL LOCK key.
    dd  XShiftKey     ;12 Extended shift key (for DBCS use).
    dd  XToggleKey    ;13 Extended toggle key (for DBCS use).
    dd  SpecKeyCS     ;14 Special key for NLS support.
    dd  SpecKeyAS     ;15 Special key for NLS support.

;    On entering the following routines, the following regs are set:
;
;      CL = Char1  and  CH = Char2  (both from XlateTable entry)
;      DX = ShiftFlags (same as in Key CharData record)
;      AL = Char1 also  AH = Received scan code (Breakbit cleared)
;OS2SS-    ESI = Pointer to Key Packet
;OS2SS-    EDI = Pointer to current PSG
;OS2SS-    [EBP-8] = Pointer to XlateTable entry for this scan code.
;OS2SS-    [EBP-4] = Pointer to Offset of top of XlateTable
;
;    Also, Key.Scan = AH and Key.Char = 0 on entry to the routines.

AlphaKey:                                   ;Alphabetical character key.
ifdef JAPAN
; MSKK Aug.15.1993 V-AkihiS
; Support SBCS katakana
          Test [ESI].Key.DShift, Katakana  ;OS2SS Check if Katakana or not
         .If <nz>
            Mov EBX,[EBP-8]                ;OS2SS-
            Mov AL,[EBX].Char4             ;OS2SS-Get Char4 and Char5 values. 
            Mov CX,Word Ptr [EBX+5]        ;OS2SS-
         .Endif
endif
          Test DL,AltFlag                  ;Check if Alt key is pressed.
         .If <nz>                                                ;Is it?
            And [EDI].XlateFlags,Not Use3Index  ;OS2SS-@@ Use Char3 if AltGraph
            Call AltGraphCheck              ;@@ Process if AltGraph
            Test [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ Check if it's not the AltGraph
           .If <nz>                         ;@@ If alt key is normal Alt
               Xor EBX,EBX                  ;OS2SS-Yes, so make Char1 an offset.
               Mov BL,AL                          ;OS2SS-Now make it the base.
               Mov AH,[AltTable+EBX-"a"]       ;OS2SS-Fetch Alt-[] mapped code.
               Mov [ESI].Key.Scan,AH                  ;OS2SS-Put in Key record.
               Xor AL,AL                      ;Set `extended char' code.
           .Endif
           Jmp NewLbl1
         .Endif                      ;OS2SS- (A2053)## Endif Alt is down.
   ;OS2SS-    .Else
            Test DL,CtlFlag          ;Else, check if Ctl key is pressed.
                                     ;@@ for this KCB
                                     ;@@ PTM 5992 - Begin
           .If <nz> OR               ;@@ Is it  OR?
            Test [EDI].XHotKeyShift,CtlFlag ;OS2SS-@@ Also check in interrupt shift
                                     ;@@   state
           .If <nz> AND              ;@@ Is it being held down at all
            Test [EDI].OtherFlags,InterruptTime ;OS2SS-&& PTM 3191: Make sure KBDXlate
           .If <nz>                         ;&& translations are independent.
                                     ;@@ PTM 5992 - End
                                 ;Check limit on char1 value!
              Sub AL,"a"-1       ;Yes, so convert Char1 to control code.
             .If <CL eq 'c'>                            ;Is this Ctrl-C?
                ;@@ Tell dd it's the PSUEDO-BREAK KEY.
                Or [ESI].DDFlags,PSBreakKey     ;OS2SS-
                Jmp NoPauseCheck     ;@@ Do not check if paused, Ctl-C
                                     ;@@ has priority over resuming output
             .ElseIf <CL eq 'p'>                        ;Is this Ctrl-P?
                ;@@ Tell dd it's PSUEDO-PRTECHO KEY.
                Or [ESI].DDFlags,PSPrintEchoKey ;OS2SS-
                Jmp NoPauseCheck     ;@@ Do not check if paused, Ctl-P
                                     ;@@ has priority over resuming output
             .ElseIf <CL eq 's'>                        ;Is this Ctrl-S?
                                               ;1.3-## PTR b790266
                Test [ESI].DDFlags,KeyBreak     ;OS2SS-1.3-## Make sure it isn't key break
               .If <z> AND                     ;1.3-## If zero, then its a make
               .If <[EDI].XInputMode eq 0>  ;OS2SS-@@ Right, are we in cooked mode?
                  ;@@ Yes, tell dd it's PSUEDO-PAUSE KEY.
                  Or [ESI].DDFlags,PSPauseKey   ;OS2SS-
               .Endif
             .Endif
           .Else                     ;Check for regular shifts/capslock.
ifdef JAPAN
; MSKK Aug.15.1993 V-AkihiS
; When Mode is katakana, CapsLock has no affect on this key.
              Test [ESI].Key.DShift, Katakana  ;OS2SS Check if Katakana or not
             .If <nz>                          ;OS2SS
                Mov BL,0                       ;OS2SS indicate that CapsTogl has no
                                               ;OS2SS affect on this key.
             .Else
                Mov BL, CapsTogl               ;OS2SS Set indicator that CapsLock and
                                               ;OS2SS ShiftLock affect key.
             .Endif
else
              Mov BL, CapsTogl       ;## Set indicator that CapsLock and
                                     ;## ShiftLock affect key.
endif
              Call CapsCheck         ;## Determine the shifting of the char.
           .Endif                    ;## Endif Ctrl or Interrupt time.
    ;OS2SS-   .Endif                      ;## Endif Alt is down.
NewLbl1:  ;OS2SS-
          Test [EDI].OtherFlags,InterruptTime ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@

NoPauseCheck:
          Mov [ESI].Key.Char,AL       ;OS2SS-Put xlated character into Key rec.
                                     ;&& PTM 2217 BEGIN:
          Test [ESI].DDFlags,KeyBreak ;OS2SS-&& Check if this a break or make.
         .If <z>                     ;&& If it isn't then go and check accent.
                                     ;@@ PTM 6860 - Begin
            Call AccCheckout         ;Go check if accent combo going on.
                                     ;@@ PTM 6860 - End
         .Endif                      ;&& Endif this is a make.
                                     ;&& PTM 2217 END:
          Jmp EndActionCase    ;Go to bottom of Xlate Action case table.

SpecKey:                       ;Special non-alpha key, no CAPSLOCK or ALT.
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                              ;@@
            Call UnPauseChk                    ;Go check if in pause state.
         .Endif                                ;@@
          Test DL,AltFlag                      ;Check if Alt key is pressed.
         .If <nz>                              ;Is it?
            And [EDI].XlateFlags,Not Use3Index  ;OS2SS-@@ Use Char3 if AltGraph
            Call AltGraphCheck                 ;@@ Process if AltGraph
            Test [EDI].XlateFlags,NormalAlt  ;OS2SS-## Check if it's the AltGraph
           .If <z>                          ;## If alt key is AltGraph
                                            ;## which is undefined for this key
              Mov [ESI].Key.Char,AL          ;OS2SS-## put it in CDR
              Call AccCheckout              ;## Go check if acc. combo going on.
              Jmp EndActionCase             ;## Go to bottom of Xlate Action
           .Endif                           ;## case table
            Jmp NoXlate                     ;## then Key combo is undefined
         .Endif                             ;@@ Endif Alt Key down
                                            ;## PTM 2287: BEGIN
          Mov EBX,[EBP-8]                    ;OS2SS-## Put it in BX
          Test [EBX].XTFlags1,ShiftLock   ;OS2SS-## Check if SHIFTLOCK keyboard.
         .If <nz>                           ;## If it is
             Mov BL,CapsTogl                ;## Indicate a CAPSLOCK check.
         .Endif                             ;## PTM 2287: END
          Test DL, CtlFlag                  ;## Check if Ctrl key down.
         .If <nz>                           ;## If so ...
             Call SKCtlCheck                ;## check if char has special
                                            ;## control code.
         .Else                              ;## Else Ctrl key not down,
             Mov BL,0                       ;1.3-@@ PTR B713838 Clear ShifLock Flag
             Call CapsCheck                 ;## Check for shifting.
         .Endif                             ;## Endif Ctrl down.
          Mov [ESI].Key.Char,AL              ;OS2SS-## Put Char in Key rec.
          Call AccCheckout                  ;## PTR B705184
          Jmp EndActionCase                 ;## Go to bottom of Xlate Action.

SpecKeyC:                            ;Special non-alpha key, with CAPSLOCK.
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@
          Test DL,AltFlag                   ;Check if Alt key is pressed.
         .If <nz>                           ;Is it?
            And [EDI].XlateFlags,Not Use3Index  ;OS2SS-@@ Use Char3 if AltGraph
            Call AltGraphCheck              ;@@ Process if AltGraph
            Test [EDI].XlateFlags,NormalAlt  ;OS2SS-@@ Check if it's not the AltGraph
           .If <nz>                         ;@@ If alt key is normal Alt
              Mov EBX,[EBP-8]               ;OS2SS-
             .If <[EBX].Char4 eq 0>       ;OS2SS-@@ then check if char 4 is 0
                                            ;@@ PTM 5024 - Begin
                Call CheckExtended          ;@@ See if new extended code
                                            ;@@  is defined
                .If <c>                     ;## If it is defined.
                    Call AccCheckout        ;## Go check if acc. combo going on.
                    Jmp EndActionCase       ;## Go to bottom of Xlate Action
                .Endif                      ;@@ PTM 5024 - End
                 Jmp NoXlate                ;## the key combo is undefined
             .Else                          ;@@ else if char 4 isn't 0
                Mov AL,[EBX].Char4        ;OS2SS-@@ then use it
             .Endif                         ;@@ Endif Char 4 is 0
           .Endif                           ;@@ Endif Alt key is normal Alt.
          Jmp SpecAccent                    ;@@ Go check if this is an accent
         .Endif                             ;@@ Endif Alt Key down
          Test DL, CtlFlag                  ;## Check if Ctrl key down.
         .If  <nz>                          ;## If so ...
             Call SKCtlCheck                ;## check if char has special
                                            ;## control code.
         .Else                              ;## Else Ctrl is not down.
                                            ;## PTR B704944 CapsCheck in Else
             Mov BL,CapsTogl                ;Indicate check CAPSLOCK.
             Call CapsCheck                 ;## Check for shifting.
         .Endif

SpecAccent:
         .If <AL b 8>                           ;@@ Indicate this is unprocessed
              Or [ESI].DDFlags,AccentKey         ;OS2SS-@@ accent.
              Test [ESI].DDFlags,KeyBreak        ;OS2SS-@@ Check for the key BREAK.
             .If <z>                            ;@@ Is it?
                And [EDI].XPSGFlags,Not PrevAccent ;OS2SS-@@ No, clear previous
                                                ;@@ accent number.
                Or Byte Ptr [EDI].XPSGFlags,AL   ;OS2SS-&& Save accent number
                                                ;&&  for the next key.
             .Endif
              Jmp EndActionCase   ;## Go to bottom of Xlate Action case table.
         .Endif
          Mov [ESI].Key.Char,AL    ;OS2SS-## Put Char in Key rec.
          Call AccCheckout        ;## PTR B705184
          Jmp EndActionCase       ;@@ Go to bottom of Xlate Action case table.

SpecKeyA:                              ;Special non-alpha key, with ALT.
ifdef JAPAN
; MSKK Aug.15.1993 V-AkihiS
; Support SBCS katakana
          Test [ESI].Key.DShift, Katakana  ;OS2SS Check if Katakana or not
         .If <nz>
            Mov EBX,[EBP-8]                ;OS2SS-
            Mov AL,[EBX].Char4             ;OS2SS-Get Char4 and Char5 values. 
            Mov CX,Word Ptr [EBX+5]        ;OS2SS-
         .Endif
endif
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@
                                            ;## PTM 2287: BEGIN
          Mov EBX,[EBP-8]                    ;OS2SS-## Put it in BX
          Test [EBX].XTFlags1,ShiftLock   ;OS2SS-## Check if SHIFTLOCK keyboard.
         .If <nz>                           ;## If it is
             Mov BL,CapsTogl                ;## Indicate a CAPSLOCK check.
         .Endif                             ;## PTM 2287: END
          Test DL, AltFlag                  ;## Check if Alt is down,
         .If <nz>                           ;## If it is...
             Call SKAltCheck                ;## Check for extended code.
         .Else                              ;## If it is not down,
            .if <bit dl nz CtlFlag>         ;## PTM 3327 start
               Call SKCtlCheck              ;## Check for spec. Ctrl code.
            .else
               Mov BL,0                     ;1.3-@@ PTR B713838 Clear ShifLock Flag
               Call CapsCheck               ;## Check for Shifting.
            .endif                          ;## PTM 3327 end
             Mov [ESI].Key.Char,AL           ;OS2SS-## Put Char in Key rec.
         .Endif                             ;## Endif Alt is down.
          Call AccCheckout                  ;## PTM 3126 fix stand alone accent
          Jmp EndActionCase                 ;## Go to bottom of Xlate Action.

SpecKeyCA:                   ;Special non-alpha key, w/CAPSLOCK and ALT.
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@
          Mov BL,CapsTogl                      ;Indicate check CAPSLOCK.
          Test DL, AltFlag                  ;## Check if Alt is down,
         .If <nz>                           ;## If it is...
             Call SKAltCheck                ;## Check for extended code.
         .Else                              ;## If it is not down,
             Call CapsCheck                 ;## Check for Shifting.
             Test DL, CtlFlag               ;## Check if Ctrl is down,
            .If <nz>                        ;## If it is then...
                Call SKCtlCheck             ;## Check for spec. Ctrl code.
            .Endif                          ;## Endif Ctrl is down.
         .Endif                             ;## Endif Alt is down.
          Mov [ESI].Key.Char,AL              ;OS2SS-## Put Char in Key rec.
          Jmp EndActionCase                 ;## Go to bottom of Xlate Action.

FuncKey:                                                 ;Function keys.
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@
          Test DL,AltFlag                                ;Check Alt Key.
         .If <nz>                                           ;Is it down?
            And [EDI].XlateFlags,Not Use3Index  ;OS2SS-@@ Use Char3 if AltGraph
            Call AltGraphCheck              ;@@ Process if AltGraph
            Test [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ Check if it's not the AltGraph
           .If <nz>                         ;@@ If alt key is normal Alt
               .If <CL gt 10>               ;Yes, so check if F11 or F12.
                  Add CL,128                ;If so, extended code is 139 or 140
               .Else
                  Add CL,103                ;Extended code is range 104-113.
               .Endif                       ;@@
           .Else                            ;@@ Else ALt key was Atl-Graph
                                            ;@@ PTM 6860 - Begin
                Mov [ESI].Key.Char,AL        ;OS2SS-@@ Move char 3 to key packet
                Mov CL,[ESI].Key.Scan        ;OS2SS-@@ Move scan to CL
                                            ;@@ PTM 6860 - End
           .Endif                           ;@@ Endif Alt or AltGraph check
         .Else                              ;@@ Endif no Alt key down
            Test DL,CtlFlag                 ;Check Ctl Key.
           .If <nz>                         ;Is it down?
             .If <CL gt 10>                 ;Yes, so check if F11 or F12.
                Add CL,126                 ;If so, extended code is 137 or 138.
             .Else
                Add CL,93                   ;Extended code is range 94-103.
             .Endif
           .Else
              Test DL,RShiftFlag+LShiftFlag ;Check Shift Keys.
             .If <nz>                       ;Is one down?
               .If <CL gt 10>               ;Yes, so check if F11 or F12.
                  Add CL,124              ;If so, extended code is 135 or 136.
               .Else
                  Add CL,83                 ;Extended code is range 84-93.
               .Endif
             .Else                          ;Else this is a non-shifted FKey.
               .If <CL gt 10>               ;Check if F11 or F12.
                  Add CL,122               ;If so, extended code is 133 or 134.
               .Else
                  Add CL,58                 ;Extended code is range 59-68.
               .Endif
             .Endif
           .Endif
         .Endif
          Mov [ESI].Key.Scan,CL              ;OS2SS-Put code in CharData rec.
                                     ;@@ PTM 6860 - Begin
          Call AccCheckout           ;Go check if accent combo going on.
                                     ;@@ PTM 6860 - End
          Jmp EndActionCase    ;Go to bottom of Xlate Action case table.


PadKey:                                     ;Numeric keypad keys.
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@
          Xor EBX,EBX                                ;OS2SS-Clear for use later.
          Test DL,AltFlag                        ;Check if Alt key down.
         .If <nz> NEAR                         ;Are we entering Alt-nnn?
                                 ;Maybe. First check for reboot request.
           .If <CL eq 12> AND    ;@@ And is current key mapped to Del?
                                 ;@@ PTM 6350 - Begin
            Test [ESI].DDFlags,KeyBreak ;OS2SS-@@ Check if this a break
           .If <z> AND           ;@@ If it isn't (only reboot on make of Del)
                                 ;@@ PTM 6350 - End
            Test DL,CtlFlag      ;Maybe. First check for reboot request.
           .If <nz> OR           ;Is Ctl down too
                                 ;@@ for this KCB  OR
                                 ;@@ PTM 5992 - Begin
            Test [EDI].XHotKeyShift,CtlFlag ;OS2SS-@@ Also check in interrupt shift
                                 ;@@   state
           .If <nz> AND          ;@@ Is it being held down at all
            Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
           .If <nz>                        ;&& translations are independent.
                                 ;@@ PTM 5992 - End
              ;@@ Tell dd it's the REBOOT KEY.
              ;OS2SS-BUGBUG shouldn't get here
              Or [ESI].DDFlags,RebootKey   ;OS2SS-@@
              Jmp EndActionCase                               ;Quit now.
           .Endif
            And [EDI].XlateFlags,Not Use3Index  ;OS2SS-@@ Use Char3 if AltGraph
            Call AltGraphCheck              ;@@ Process if AltGraph
            Test [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ Check if it's not the AltGraph
           .If <nz>                         ;@@ If alt key is normal Alt
                                            ;@@ PTM 5024 - BEGIN
              Test [EDI].XlateFlags,SecPrefix    ;OS2SS-@@ Check if secondary key
             .If <nz>                           ;@@ If it is
                 Add [ESI].Key.Scan,50h          ;OS2SS-@@ Make scan extended code
                 Mov [ESI].Key.Char,0            ;OS2SS-@@ Make char extended code
             .Else                              ;@@ Else primary pad key
                 Test [ESI].DDFlags,KeyBreak     ;OS2SS-Check if is a key break.
                .If <z>                         ;Is it?
                   Mov BL,CL              ;No, so make Char1 value the index.
                   Mov CL,[EBX+AltPadMap]        ;OS2SS-Get numeric value of the key.
                   Or CL,CL                     ;Check if value is -1.
                  .If <s>                       ;Is it.
                     Mov [EDI].XAltKeyPad,0      ;OS2SS-@@ Not numeric, reset.
                    .If <AH eq 83>              ;@@ If this is DEL key
                        Jmp NoXlate             ;@@ No extended value, undefined
                    .Else                       ;@@ Else extended char
                        Jmp EndActionCase       ;@@ Mark char defined
                    .Endif                      ;@@ Endif Extended Char exists
                  .Else
                     Mov AL,10                    ;Else multiply old...
                     Mul [EDI].XAltKeyPad          ;OS2SS-@@ ...accumulator by 10.
                     Add AL,CL                    ;And add new key.
                     Mov [EDI].XAltKeyPad,AL       ;OS2SS-@@ Save modified accum.
                     Jmp NoXlate                  ;Mark keystroke undefined
                  .Endif
                .Else                       ;@@ PTM 6860 - Begin Else a break
                   Jmp NoXlate              ;@@ Mark keystroke undefined
                .Endif
             .Endif                         ;@@ Endif primary or secondary key
                                            ;@@ End PTM 5024
           .Else                            ;@@
              Mov [ESI].Key.Char,AL          ;OS2SS-@@ Put Char into Key rec.
              Test [ESI].DDFlags,SecondaryKey ;OS2SS-@@ Check if G keyboard dup key.
             .If <nz>                       ;@@ Is it?
                 Mov [ESI].Key.Scan,OtherKey ;OS2SS-@@ Yes, so mark it so.
             .Endif                         ;@@
           .Endif                           ;@@ Endif normal ALT
         .Else NEAR                                    ;No Alt key down.
                                              ;@@ PTM 5024
            Test [EDI].XlateFlags,SecPrefix    ;OS2SS-@@ Check if secondary key
           .If <nz>                           ;@@ If it is
               Mov AL,OtherKey                ;@@ Set Char to E0
           .Else                              ;@@ Else regular pad key
               Xor AL,AL                      ;@@ Set Char to "extended"
           .Endif                             ;@@ End PTM 5024
            Test DL,CtlFlag                      ;Check if Ctl key down.
           .If <nz>                                              ;Is it?
              Mov BL,CL             ;Yes, so make Char1 value the index.
              Mov AH,[EBX+CtlPadMap]      ;OS2SS-Get extended value of the key.
              Mov [ESI].Key.Scan,AH    ;OS2SS-Set extended code for this key.
           .Else            ;Not Alt- or Ctl-, so figure out Num status.
             .If <CL eq 3> OR                    ;Is this the minus key?
             .If <CL eq 7>                     ;Or is this the plus key?
                Mov AL,CH        ;Yes, so use Char2 regarless of shifts.
             .Else
                Test DL,RShiftFlag+LShiftFlag      ;Check for shift key.
               .If <nz>                                    ;Is one down?
                  Or BL,NumTogl                ;Yes, so set NumLock bit.
               .Endif
                And DL,NumTogl        ;Clear all shift bits but NumLock.
                Xor DL,BL                ;Flip it if shift key was down.
               .If <nz>                           ;Is the case Num Lock?
                  Mov AL,CH                          ;Yes, so use Char2.
               .Endif
                                         ;@@ PTM 7358 - Begin
               .If <z> OR                ;@@ If we should not shift
                Test [ESI].DDFlags,SecondaryKey ;OS2SS-@@ if G keyboard dup key.
               .If <nz>                  ;@@ If it is
                 .If <CL eq 11>                    ;Is this the Ins key?
                    Test [ESI].DDFlags,KeyBreak  ;OS2SS-Yes check if key BREAK.
                   .If <nz>                                      ;Is it?
                      And [EDI].ToggleFlags,Not InsKeyDown ;OS2SS-@@ Yes clear latch.
                   .Else                             ;Not Ins Key Break.
                      Test [EDI].ToggleFlags,InsKeyDown  ;OS2SS-@@ Check if seen Ins.
                     .If <z>                                   ;Have we?
                        Or [EDI].ToggleFlags,InsKeyDown   ;OS2SS-@@ No, so set latch.
                        Xor Byte Ptr [ESI].Key.Shift,InsTogl ;OS2SS-Toggle in CDR
                     .Else      ;Otherwise this is a repeat of the make.
                        Or [ESI].DDFlags,MultiMake       ;OS2SS-So indicate so.
                     .Endif
                   .Endif
                 .Endif
               .Endif   ;@@ Endif we should set/clear insert toggle
                                         ;@@ PTM 7358 - End
             .Endif
           .Endif
            Mov [ESI].Key.Char,AL        ;OS2SS-Put character value in Key rec.
            Test [ESI].DDFlags,SecondaryKey ;OS2SS-Check if G keyboard dup key.
           .If <nz>                                              ;Is it?
              Mov [ESI].Key.Char,OtherKey            ;OS2SS-Yes, so mark it so.
           .Endif
         .Endif                ;Endif Alt key down or not check
                                     ;@@ PTM 6860 - Begin
          Call AccCheckout           ;Go check if accent combo going on.
                                     ;@@ PTM 6860 - End
          Jmp EndActionCase    ;Go to bottom of Xlate Action case table.


SpecCtlKey:                       ;Keys that do special things with CTL.
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@
          Test DL,AltFlag                        ;Check if Alt key down.
         .If <nz>                                                ;Is it?
            And [EDI].XlateFlags,Not Use3Index  ;OS2SS-@@ Use Char3 if AltGraph
            Call AltGraphCheck              ;@@ Process if AltGraph
            Test [EDI].XlateFlags,NormalAlt  ;OS2SS-@@ Check if it's not the AltGraph
           .If <nz>                         ;@@ If alt key is normal Alt
                                            ;@@ PTM 5024 - Begin
              Xor AL,AL                     ;@@ Set Char to be extended
             .If <AH eq 1Ch> AND            ;@@ If this is the Enter key
              Test [ESI].DDFlags,SecondaryKey ;OS2SS-
             .If <nz>                       ;@@ on the pad keys
                                            ;&& PTM 1270 - Don't overwrite scan
                 Mov [ESI].Key.Scan,0A6h     ;OS2SS-@@ Set extended code
             .Endif
           .Endif                           ;@@ PTM 5024 End

            Jmp SetCharField                ;&& PTM 1520 now go set char field
         .Endif
                                            ;&& PTM 1270 - Begin
          Test [ESI].DDFlags,SecondaryKey    ;OS2SS-@@ Check if G keyboard dup key.
         .If <nz>                           ;@@ Is it?
             Mov [ESI].Key.Scan,OtherKey     ;OS2SS-@@ Yes, so mark it so.
         .Endif
          Test DL,CtlFlag                   ;Check if Ctl key down.
         .If <nz>                           ;Is it?
            Mov AL,CH                       ;Yes, so use Char2.
         .Endif
       SetCharField:                        ;&& PTM 1520  Alt should have
                                            ;&& precedence when Ctrl and Alt
                                            ;&& are down.

          Mov [ESI].Key.Char,AL              ;OS2SS-Put Char into Key rec.
                                            ;&& PTM 1270 - End
                                     ;@@ PTM 6860 - Begin
          Call AccCheckout           ;Go check if accent combo going on.
                                     ;@@ PTM 6860 - End
          Jmp EndActionCase    ;Go to bottom of Xlate Action case table.

;OS2SS-BUGBUG-shouldn't get here
PrtScr:                                           ;The print screen key.
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@
          Test DL,AltFlag                        ;Check if Alt key down.
         .If <nz>                                                ;Is it?
            Test [EDI].XlateFlags,SecPrefix ;OS2SS-@@ Check if secondary key
           .If <nz> OR                     ;@@ If it is OR...
            Test _Ow2MiscFlags,EnhancedKbd     ;@@ Check if enhanced kbd
           .If <z>  OR                     ;@@ OR...If it's a regular kbd
;$$
;$$ 'IDFlags' does not exist in the 1.2 ABIOS
;$$ version.  We need to get this information from KbdHWIDs.
;$$

;$$         Test IDFlags, SuperSport       ;## Check if it is a 122 kbd

           .If < _Ow2KbdHWIDs e 0AB85h >       ;$$ If it is a 122 kbd
              Test DL,CtlFlag              ;@@ Check if Ctl key is down
             .If <nz> OR                   ;@@ If it is
                                           ;@@ for this KCB
                                           ;@@ PTM 5992 - Begin
              Test [EDI].XHotKeyShift,CtlFlag ;OS2SS-@@ Also check in interrupt shift
                                           ;@@   state
             .If <nz> AND                  ;@@ Is it being held down at all
              Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
             .If <nz>                         ;&& translations are independent.
                                           ;@@ PTM 5992 - End
                Or [ESI].DDFlags,PrintFlushKey ;OS2SS-@@ Indicate this is FlushPrtbuf
                Jmp EndActionCase           ;@@ Go to bottom of Xlate Action
                                            ;@@ case table.
             .Endif
              Jmp  NoXlate        ;Else that's undefined for this key.
                                            ;@@ PTM 5024 begin
           .Else                            ;@@ Else it Pad Key * on G kbd
              Xor AL,AL                     ;@@ Set extended code
           .Endif                           ;@@ Endif PrtScr or *
         .Else  NEAR                        ;@@ Else no Alt key down
            Test DL,CtlFlag                 ;Check if Ctl key down.
                                     ;@@ for this KCB
                                     ;@@ PTM 5992 - Begin
           .If <nz> OR               ;@@ Is it  OR?
            Test [EDI].XHotKeyShift,CtlFlag ;OS2SS-@@ Also check in interrupt shift
                                     ;@@   state
           .If <nz> AND              ;@@ Is it being held down at all
            Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                           ;&& translations are independent.
           .If <nz>
                                     ;@@ PTM 5992 - End
              Test [EDI].XlateFlags,SecPrefix ;OS2SS-@@ Check if secondary key
             .If <nz> OR                     ;@@ If it is OR...
              Test _Ow2MiscFlags,EnhancedKbd     ;@@ Check if enhanced kbd
             .If <z> OR                      ;@@ OR...If it's a regular kbd
;$$
;$$ 'IDFlags' does not exist in the 1.2 ABIOS
;$$ version.  We need to get this information from KbdHWIDs.
;$$

;$$           Test IDFlags, SuperSport       ;## Check if it is a 122 kbd

             .If < _Ow2KbdHWIDs e 0AB85h >       ;$$ If it is a 122 kbd
                  Xor AL,AL                  ;Yes so set extended code...
                  Mov [ESI].Key.Scan,CH       ;OS2SS-...for the Ctl-PrSc combination.
                  Or [ESI].DDFlags,PrintEchoKey   ;OS2SS-@@ Tell dd it's the PRINT
                                                 ;@@ ECHO KEY.
                                             ;@@ PTM 5024 - Begin
             .Else                           ;@@ Else its the keypad *
                  Xor AL,AL                  ;@@ so set extended code...
                  Mov [ESI].Key.Scan,96h      ;OS2SS-@@ for scan and char
             .Endif                          ;@@ PTM 5024 - end
           .Else                             ;@@ Else Ctrl key not down.
              Test [EDI].XlateFlags,SecPrefix ;OS2SS-@@ Check if secondary key
             .If <nz> OR                     ;@@ If it is OR...
              Test DL,RShiftFlag+LShiftFlag  ;@@ Check if a shift flag down.
             .If <nz> AND                    ;@@ If a shift key is down AND...
              Test _Ow2MiscFlags,EnhancedKbd     ;@@ Check if enhanced kbd
             .If <z> OR                      ;@@ AND...If it's a regular kbd

;$$           Test IDFlags, SuperSport       ;## Check if it is a 122 kbd
;$$
;$$ 'IDFlags' does not exist in the 1.2 ABIOS
;$$ version.  We need to get this information from KbdHWIDs.
;$$
             .If < _Ow2KbdHWIDs e 0AB85h >       ;$$ If it is a 122 kbd

                Xor AL,AL                    ;Yes, so clear char code.
                Or [ESI].DDFlags,PrtScrKey    ;OS2SS-@@ Tell dd it's PRINT SCREEN KEY.
                Test [ESI].DDFlags,KeyBreak   ;OS2SS-Check for the key BREAK.
               .If <nz>                      ;Is it?
                  And [EDI].XlateFlags,Not PSKeyDown ;OS2SS-@@ Yes, clear PS Key latch
               .Else
                  Test [EDI].XlateFlags,PSKeyDown ;OS2SS-@@ Check if seen PS key yet.
                 .If <z>                      ;Have we?
                    Or [EDI].XlateFlags,PSKeyDown ;OS2SS-@@ No, set latch saying have.
                 .Else            ;Otherwise this is a repeat of the make.
                    Or [ESI].DDFlags,MultiMake ;OS2SS-So indicate so.
                 .Endif                       ;Endif no PS key yet check
               .Endif                         ;Endif Key break or not check
             .Else                              ;@@ PTM 2606:  Shift keys not
                                                ;@@ down or not enhanced kbd.
                Test [ESI].DDFlags, KeyBreak     ;OS2SS-@@ If this is a break of the
               .If < nz >                       ;@@  PrtScr key,
                  And [EDI].XlateFlags,Not PSKeyDown     ;OS2SS-@@ Ensure latch is
                                                        ;@@  cleared.
               .Endif                           ;@@ Endif PrtScr break.
             .Endif                           ;Endif shift key down
           .Endif                             ;Endif Ctl down or not check
         .Endif                               ;@@ Endif Alt key down check
          Mov [ESI].Key.Char,AL                ;OS2SS-Put character in Key rec.
                                     ;@@ PTM 6860 - Begin
          Call AccCheckout           ;Go check if accent combo going on.
                                     ;@@ PTM 6860 - End
          Jmp EndActionCase    ;Go to bottom of Xlate Action case table.


AccentKeyType:                  ;A key that affects the NEXT key (dead key).
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@
          Test DL,AltFlag                    ;Check if ALT down.
         .If <nz>                            ;Is one?
             Or [EDI].XlateFlags,Use3Index  ;OS2SS-@@ Use Char3 if AltGraph
             Call AltGraphCheck              ;@@ Process if AltGraph
             Test [EDI].XlateFlags,NormalAlt  ;OS2SS-@@ check if it was Altgraph key
            .If <z>                          ;@@ If it was AltGraph key
              .If <CL a 7>                   ;@@ If char 3 wasn't accent
                  Mov [ESI].Key.Char,CL       ;OS2SS-@@ Put char in CDR
                  Mov [ESI].Key.Scan,AH       ;OS2SS-@@ Put scan in CDR
                  Call AccCheckOut       ;@@ Go check if accent combo (p6860)
                  Jmp EndActionCase          ;@@ And quit now
              .Else                          ;@@ Else char3 was an accent or 0
                 .If <CL eq 0>               ;@@ If Char 3 was 0
                     Jmp NoXlate             ;@@ Mark Key packet undefined
                 .Else                       ;@@ Else it was an accent
                     Xor BH,BH               ;@@ Flag no shift check
                     Jmp ShiftAccent
                 .Endif                      ;@@ Endif Char3 was 0 or not
              .Endif                         ;@@ Endif Char3 accent or not
            .Endif                           ;@@ Endif Altgraph key down
         .Endif                                ;@@ Endif ANY Alt key down
          Test [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ Check if it's not the AltGraph
         .If <nz> OR                       ;@@ If alt key is normal Alt
          Test DL,CtlFlag
         .If <nz>                          ;@@ OR CTL key is down
            Mov EBX,[EBP-8]                 ;OS2SS-
            Mov CL,[EBX].Char5           ;OS2SS-@@ Get accent entry index
                                           ;@@   for CTL or ALT character
            XOR EBX,EBX                    ;OS2SS-
            Test [EDI].XlateFlags,NormalAlt ;OS2SS-@@ Check if it's not the AltGraph
           .If <nz>                        ;@@ If alt key is normal Alt
               Mov EBX,AltAcChar            ;OS2SS-@@ So get Alt-Accent offset.
           .Endif
            Test DL,CtlFlag
           .If <nz>                        ;@@ If its the CTL key
               Mov EBX,CtlAcChar            ;OS2SS-@@ So get Ctl-Accent offset.
           .Endif
            And ECX,0FFh                      ;OS2SS-Make accent number a word.
            Dec ECX                         ;OS2SS-Accent 1 is offset zero.
            IMul ECX,AccEntryLen            ;OS2SS-Set offset of accent table entry.
            Add ECX,Accents                 ;OS2SS-Add offset of accent entries.
            Add ECX,EBX                      ;OS2SS-@@ Add offset for Ctl or Alt
                                           ;@@ accent
            Add ECX,[EBP-4]                 ;OS2SS-Point into translate table.
            Mov EBX,ECX                      ;OS2SS-Put pointer in base reg.
            Mov BX,Word Ptr [EBX]        ;OS2SS-Fetch char and scan.
            Or BX,BX         ;Check if a Scan/Char mapping for this key.
           .If <z>                         ;Is there?
               Jmp NoXlate                 ;No, so go mark untranslated.
           .Endif                          ;Else, use the mapping.
            Mov Word Ptr [ESI].Key.Char,BX  ;OS2SS-Put them into Key.
                                           ;@@ PTM 6860
            Call AccCheckout               ;Go check if accent combo going on
            Jmp EndActionCase              ;Quit now.
         .Endif
                                           ;## PTR B700738 Move 0 into BL to
          Mov BL,0                         ;## indicate that CapsTogl has no
                                           ;## affect on this key.
          Call CapsCheck                   ;## Determine shifting of character.

ShiftAccent:                                  ;@@ Merge here for accent process
         .If <nz>                             ;@@ If we should shift
            Mov CL,CH
         .Endif
         .If <CL a 7>                       ;@@ Is translate table entry
                                            ;@@  actually a character
            Mov [ESI].Key.Char,CL            ;OS2SS-@@ Put character in CDR

            .IF <bit [ESI].DDFlags z KeyBreak>  ;OS2SS-## PTM 3324 start
               Call AccCheckOut                ;@@ Go check if accent combo
            .ENDIF                             ;## PTM 3324 end

            Jmp EndActionCase    ;Go to bottom of Xlate Action case table.

         .Else                           ;@@ Else actually an accent
            Or CL,CL                     ;@@ check if accent defined.
           .If <z>                       ;@@ Is it?
              Jmp NoXlate                ;@@ No, so go mark undefined.
           .Endif
            Xor CH,CH                    ;Make accent number a word.
            Mov BX,[EDI].XPSGFlags        ;OS2SS-&& Get the translation flags
            And BX,PrevAccent            ;&& Clear all bits but previous
                                         ;&&  accent number (in BL)
            Mov AL,CL                    ;@@ Save accent number
           .If <BL eq CL> AND            ;@@ If this is same accent number
                                         ;@@  as last time AND
            Test [ESI].DDFlags,KeyBreak   ;OS2SS-@@ Check if this is a BREAK
           .If <z> AND                   ;@@ AND it is not a break

            Mov EBX,[EBP-8]                 ;OS2SS-
            Mov BX,[EBX].XlateOp       ;OS2SS-@@ Get accent flags
            Mov CL,7                     ;@@ Set highest accent number
            Sub CL,AL                    ;@@ Subtract actual accent number
            Shl BX,CL                    ;@@ Put accent flag in high bit
           .If <s>                       ;@@ AND if an accent is defined
              Mov DX,[ESI].Key.Shift  ;OS2SS-@@ Get the current shift status from Key.
              Call AccCheckOut           ;@@ Go process this key
           .Endif
           ;Indicate this is an unprocessed accent.
            Or [ESI].DDFlags,AccentKey    ;OS2SS-@@
            Test [ESI].DDFlags,KeyBreak   ;OS2SS-Check for the key BREAK.
           .If <z> NEAR                  ;Is it?
              And [EDI].XPSGFlags,Not PrevAccent ;OS2SS-@@ No, clear prev accent
              Or Byte Ptr [EDI].XPSGFlags,AL     ;OS2SS-&& Save accent number for next
                                                ;&&  key.
           .Endif
            Jmp EndActionCase    ;Go to bottom of Xlate Action case table.
         .Endif                          ;@@
SysReq:                               ;The system request key.

         ;@@ PTM 4247 - the PrtScr key on an Enhanced Keyboard
         ;@@ sends the SysReq scan code if the Alt Key is down
         ;@@ which it must be for the Print Buffer flush key combo
         ;@@ (Ctl-Alt-PrtScr).  Therefore we must check for it here.

          Test _Ow2MiscFlags,EnhancedKbd        ;@@ Check if enhanced kbd
         .If <nz> AND                       ;@@ If it is AND....
          Test [ESI].DDFlags,KeyBreak        ;@@ Check if this is a break
         .If <z> AND                        ;@@ ...AND If it's NOT (a make)
          Test DL,AltFlag                   ;@@ Check if Alt key down.
         .If <nz> AND                       ;@@ If it is AND....
          Test DL,CtlFlag                   ;@@ Check if Ctl key is down
                                            ;@@ for this KCB
                                            ;@@ PTM 5992 - Begin
         .If <nz> OR                        ;@@ Is it  OR?
          Test [EDI].XHotKeyShift,CtlFlag    ;OS2SS-@@ Also check in interrupt shift
                                            ;@@   state
         .If <nz> AND                       ;@@ Is it being held down at all
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                            ;&& translations are independent.
         .If <nz>                           ;@@ PTM 5992 - End
                           ;@@ No, so make sure this shift key's flag is set.
                Or [ESI].Key.Shift,CX   ;OS2SS-
                Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                               ;&& translations are independent.
               .If <nz>
                   Or [EDI].XHotKeyShift,CX  ;OS2SS-@@ Also set in hot key shift state
               .Endif
                ;@@ Indicate this is Flush Prt buf
                Or [ESI].DDFlags,PrintFlushKey  ;OS2SS-
                Jmp EndActionCase           ;@@ Go to bottom of Xlate Action
                                            ;@@ case table.
         .Else                              ;@@ Else (PTM 4990)
                Or [ESI].DDFlags,SysReqKey   ;OS2SS-@@ Indicate this is SysReq key
         .Endif


ShiftKeys:                            ;The LSHIFT, RSHIFT, and CTL keys.
AltKey:                                                ;And the ALT key.
          Test [EDI].XlateFlags,E1Prefix      ;OS2SS-@@ CHeck if scan code proceeded
         .If <nz> AND                       ;@@ by E1, if so AND
          Test CX,CtlFlag                   ;@@ check if this is Ctrl key
         .If <nz>                           ;@@ AND if it is Ctrl
              Test [ESI].DDFlags,KeyBreak    ;OS2SS-@@ Check if this is a break
             .If <z>                        ;@@ if it is not
                Or [EDI].XlateFlags,PseudoCtl ;OS2SS-@@ Flag this as not actually
                                             ;@@ a Ctrl key but a code
                                             ;@@ sent by Enhanced Kbd
             .Endif
              Jmp NoXlate                    ;@@ Mark key packet undefined
         .Endif
                                             ;&& PTM 3002 BEGIN:
                                             ;&& Setup alternate shift bits
                                             ;&& before checking for MultiMake.
          Mov EBX,[EBP-8]         ;OS2SS-Put XlateTable offset into a base reg.
          Mov AH,[EBX].Char3     ;OS2SS-Get alternate shift bits from entry.
          Mov EBX,[EBP-4]         ;OS2SS-
          Mov BX,[EBX].XTFlags1   ;OS2SS-@@ Get the XT header flags
          Test [ESI].DDFlags,SecondaryKey   ;OS2SS-Check if G keyboard dup key.
         .If <nz>                                                ;Is it?
            Test CX,RShiftFlag+LShiftFlag  ;@@ Is the key a shift key
           .If <nz>                        ;@@ If so....

            ;@@ If it is then this is coming from a "G" keyboard secondary
            ;@@ pad key, and NUMLOCK is on.  This combination sends
            ;@@ the following scan codes:  E0, left shift make, E0,
            ;@@ pad key make, E0, pad key break, E0, left shift break.
            ;@@ In this case, we don't want to change the shift flags
            ;@@ anywhere.

            Jmp NoXlate                     ;@@ Mark key packet undefined

           .Endif                           ;@@ Endif shift key

            Xchg CH,AH      ;Yes, so swap shift bit mask with alternate.
         .Endif                              ;&& PTM 3002 END:
                                             ;@@ PTM 6446 - BEGIN
          Test [ESI].DDFlags,KeyBreak         ;OS2SS-@@ Check if this is a MAKE
         .If <z>                             ;@@ If it is
             Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                             ;&& translations are independent.
            .If <nz> AND
             Test Byte Ptr [EDI].XHotKeyShift+1,CH ;OS2SS-@@ Check if this key down
                                             ;@@ In the system already
                                             ;@@ for Ctl and Alt
            .If <nz> OR                      ;@@ If it is OR
             Test CX,RShiftFlag+LShiftFlag   ;@@ Is the key a shift key
            .If <nz> AND                     ;@@ If so AND....
             Test [ESI].DDFlags,SecondaryKey  ;OS2SS-@@ And if this is NOT a secondary
            .If <z> AND                      ;@@ shift key code sent by a pad
                                             ;@@ key  (PTM 7506)
             Test Byte Ptr [EDI].XHotKeyShift,CL ;OS2SS-@@ Check if this key down
            .If <nz>                         ;@@ If it is
                                             ;@@ In the system already
                                             ;@@ PTM 3138 BEGIN: Flag as shift
                                             ;@@ key also, do not put in KIB.
                Or [ESI].DDFlags,MultiMake+ShiftMask ;OS2SS-@@ Indicate so and do not
                                             ;@@ update shift state.
                                             ;@@ PTM 3138 END:
                Jmp EndActionCase            ;@@ Complete translation
            .Endif                           ;@@ Endif this is a multimake
         .Endif                              ;@@ Endif this is a key make
                                             ;@@ PTM 6446 - END
          Test [ESI].DDFlags,KeyBreak        ;OS2SS-Check if this is key break.
         .If <nz> AND                       ;If it is AND...
          Test DX,CX     ;And is a key make pending for this shift flag?
         .If <z>                ;If not, this key belongs in another SG.
            Xor AL,AL                       ;Indicate not our keystroke.
            ClC        ;Differentiate from other key-break return above.
            Ret                                               ;Quit now.
         .Endif
          Test CX,RShiftFlag+LShiftFlag+SysRqFlag   ;Is the key other...
         .If <nz>                                   ;...than Ctl or Alt?
            And [EDI].XlateFlags,NOT DumpKeyOnce     ;OS2SS-@@ Cancel Dump sequence.
         .Endif
          Or [ESI].DDFlags,ShiftMask       ;OS2SS-@@ Indicate this is a shift key.
          Test BX,ShiftLock               ;@@ ShiftLock keyboard?
         .If <nz> AND                     ;Is it shift lock and...
          Test BX,ShiftToggle             ;@@ ShiftToggle Kbd?
         .If <z> AND                      ;@@ Is it NOT shift toggle and..
          Test CL,RShiftFlag+LShiftFlag   ;...is this key one of..
         .If <nz> AND                     ;     ...two shift keys?
          Test [ESI].DDFlags,KeyBreak      ;Check for the key BREAK.
         .If <z>                    ;If not, make sure ShiftLock is off.
            And DL,Not CapsTogl                            ;Turn it off.

            ;@@ Turn it off in the interrupt driven shift state for
            ;@@ hot keys also

            Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                              ;&& translations are independent.
           .If <nz>
               And Byte Ptr [EDI].XHotKeyShift+1,Not CapsTogl   ;OS2SS-
           .Endif
         .Endif
          Test [ESI].DDFlags,KeyBreak          ;OS2SS-Check for the key BREAK.
         .If <z>                              ;Is it?
            Test CX,DX                        ;@@ No, its a MAKE
           .If <nz>                           ;@@ So check if we've seen it
              Or [ESI].DDFlags,MultiMake       ;@@ If we have, indicate so.
           .Endif                             ;@@ Endif Multimake
            Or DX,CX     ;No, so make sure this shift key's flag is set.
            Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                              ;&& translations are independent.
           .If <nz>
               Or [EDI].XHotKeyShift,CX  ;OS2SS-@@ Also set in hot key shift state
           .Endif
         jmp NewLbl2
         .Endif                      ;OS2SS- (A2053)## Endif Alt is down.
   ;OS2SS-   .Else                                ;Else process key-break.
           .If <AL eq AltFlag>                ;Check is this the AltKey?
                Xor AL,AL                     ;@@ Clear out a reg
                Xchg AL,[EDI].XAltKeyPad  ;OS2SS-@@ Swap with the ALT-nnn accumulator.
                Or AL,AL              ;Check if any accumulation going on.
               .If <nz>                                        ;Was there?
                  Mov [ESI].Key.Char,AL     ;OS2SS-Yes so make a Char from total.
                  Mov [ESI].Key.Scan,0        ;OS2SS-And make the scan code zero.
                                           ;## PTR AK00370
                  Test [ESI].DDFlags,SecondaryKey ;OS2SS-## If this isn't an AltPad seq.
                 .If <z>                   ;## with right (secondary) Alt key.
                     And [ESI].DDFlags,Not (KeyBreak+KeyTypeMask)  ;OS2SS-Fix flags.
                 .Endif                    ;## Endif right Alt key.
                                           ;## PTR AK00370
                  Or _Ow2MiscFlags3,AltPacket    ;&& DCR 1713 : Indicate that
                                             ;&& we will send two packets.
                                             ;@@ PTM 6860 - Begin
                  Call AccCheckout      ;@@ check if accent combo going on.
                                              ;@@ PTM 6860 - End
               .Endif                         ;Endif accumulation going on
           .Endif                             ;@@ Endif this was an ALT key
            Mov BX,CX                     ;Save shift key values
            Not CX                        ;Make shift flags into a mask.
     ;@@ PTM 3905 - Topview does not send cursor key scan codes through
     ;@@ and if this is a Ferrari keyboard, we only get E0s from the
     ;@@ secondary cursor keys.  Then if the left ALT is pressed
     ;@@ to remove the popup, we think the ALT make was actually
     ;@@ the right alt make because it was preceded by an E0 from a
     ;@@ cursor key. And the break does not clear things up.

              Test BL,RShiftFlag+LShiftFlag   ;...is this key one of..
             .If <z>                          ;     ...two shift keys?
                Test DH,BH       ;@@ Check if this key is actually
                                 ;@@ the one that's down
               .If <z>           ;@@ If it isn't
                  And DH,CL      ;@@ Clear bit for key actually down
               .Else             ;@@ Else we've got the right key
                  And DH,CH   ;Clear upper byte shift flag for this shift key.
               .Endif
                Test DH,AH                ;Check if other shift key is down.
               .If <z>        ;Is primary or secondary shift key still down?
                  And DL,CL             ;No, so clear lower byte shift flag.
               .Endif

         ;@@ PTM 4075 - A system wide word for the shift state
         ;@@ must be maintained that is only modified by interrupts
         ;@@ and is only used for Hot Key Checking

                Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                               ;&& translations are independent. ;&& translations are independent.
               .If <nz>
                   Push EDX                     ;OS2SS-@@ Save new key packet shift
                   Mov DX,[EDI].XHotKeyShift     ;OS2SS-@@ Get hot key shift state
                   Test DH,BH       ;@@ Check if this key is actually
                                    ;@@ the one that's down
                  .If <z>           ;@@ If it isn't
                     And DH,CL      ;@@ Clear bit for key actually down
                  .Else             ;@@ Else we've got the right key
                     And DH,CH   ;Clear upper byte shift flag for this shift
                  .Endif
                   Test DH,AH                ;Check if other shift key is down.
                  .If <z>        ;Is primary or secondary shift key still down?
                     And DL,CL             ;No, so clear lower byte shift flag.
                  .Endif
                   Mov [EDI].XHotKeyShift,DX    ;OS2SS-
                   Pop EDX                      ;OS2SS-
               .Endif
             .Else
                And DL,CL             ;No, so clear lower byte shift flag.
                Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                               ;&& translations are independent.
               .If <nz>
                   And Byte Ptr [EDI].XHotKeyShift,CL   ;OS2SS-
               .Endif
             .Endif
   ;OS2SS-   .Endif
NewLbl2:  ;OS2SS-
          Mov [ESI].Key.Shift,DX                   ;OS2SS-Also save in Key rec.

          Test _Ow2MiscFlags3,AltPacket      ;&& DCR 1713 BEGIN: Check to see if an
                                         ;&& Alt-Num operation was completed.
         .If <nz>                        ;&& If so then..
                                         ;## PTR AK00370: BEGIN
             Test [ESI].DDFlags,SecondaryKey ;OS2SS-## If this is an AltPad seq.
            .If <z>                         ;## with Left (normal) Alt key.
               Call AltPadPacket            ;&& setup second of two packets for
                                            ;&& Alt-Numpad sequence.
            .Else                           ;## Else this is an AltPad seq. with
                                            ;## the right (secondary) Alt key.
                Test [ESI].DDFlags,KeyBreak  ;OS2SS-## If this is a break for the right
               .If <nz>                     ;## Alt key then...
                  Or _Ow2MiscFlags3, SecAltNumPad ;## Flag that we will have to send an
               .Endif                       ;## accumulation packet after break
                                            ;## of the Alt key in Int Handler.
            .Endif                       ;## PTR AK00370: END
         .Endif                          ;&& DCR 1713: END
                                         ;## AltPadPacket is only called for
                                         ;## AltNumPad seq. with left Alt. key.
                                         ;## PTR AK00370: END

          Jmp EndActionCase    ;Go to bottom of Xlate Action case table.

ScrollLock:                                        ;The SCROLL LOCK key.
         ;@@ This is special case of ToggleKeys because of Ctl-Break.
         ;@@ On an Enhanced keyboard, the Ctl-Break sends the following
         ;@@ set of scan codes:
         ;@@ Ctrl make-E0-ScrollLock make-E0-ScrollLock break-Ctrl break
         ;@@ so we must check if it was an AT keyboard or preceded by EO
         ;@@ before identifying it as Ctl-Break.

          And [EDI].XlateFlags,NOT DumpKeyOnce      ;OS2SS-@@ Cancel Dump sequence.
          Test [EDI].XlateFlags,SecPrefix ;OS2SS-@@ Check if secondary key
         .If <nz> OR                     ;@@ If it is OR...
          Test _Ow2MiscFlags,EnhancedKbd     ;@@ Check if enhanced kbd
         .If <z>  OR                     ;@@ OR...If it's a regular kbd
;$$
;$$ 'IDFlags' does not exist in the 1.2 ABIOS
;$$ version.  We need to get this information from KbdHWIDs.
;$$

;$$       Test IDFlags, SuperSport       ;## Check if it is a 122 kbd

         .If < _Ow2KbdHWIDs e 0AB85h >       ;$$ If it is a 122 kbd

            Test DL,CtlFlag              ;Check if Ctl also pressed.
                                         ;@@ for this KCB
                                         ;@@ PTM 5992 - Begin
           .If <nz> OR                   ;@@ Is it  OR?
            Test [EDI].XHotKeyShift,CtlFlag ;OS2SS-@@ Also check in interrupt shift
                                         ;@@   state
           .If <nz> AND                  ;@@ Is it being held down at all
            Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                           ;&& translations are independent.
           .If <nz>
                                         ;@@ PTM 5992 - End
              Mov [ESI].Key.Scan,0        ;OS2SS-Set Ctl-Break extended code.
              ;Tell dev driver it's the BREAK KEY.
              Or [ESI].DDFlags,BreakKey     ;OS2SS-@@
              Test [ESI].DDFlags,KeyBreak  ;OS2SS-Check if this is the key break.
             .If <nz>  ;If so, clear Scroll Lock down bit in Packet & PSG.
                And Byte Ptr [ESI].Key.Shift+1,Not (ScrollFlag ShR 8)
                ;OS2SS-@@ Clear bit in hot key shift status also
                Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                               ;&& translations are independent.
               .If <nz>
                   And Byte Ptr [EDI].XHotKeyShift+1,Not (ScrollFlag ShR 8)     ;OS2SS-
               .Endif
             .Else              ;Set Scroll Lock down bit in packet & PSG.
                Or Byte Ptr [ESI].Key.Shift+1,(ScrollFlag ShR 8)
                ;OS2SS-@@ Set bit in hot key shift status also
                Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                               ;&& translations are independent.
               .If <nz>
                   Or Byte Ptr [EDI].XHotKeyShift+1,(ScrollFlag ShR 8)  ;OS2SS-
               .Endif
             .Endif
              Jmp EndActionCase           ;@@ PTM 4106: Leave translation.
           .Else        ;Not Ctl-Break, fall thru to ToggleKey processing.
              Jmp ToggleKey                   ;@@
           .Endif
         .Else        ;Not Ctl-Break, fall thru to ToggleKey processing.
            Jmp ToggleKey                   ;@@
         .Endif
NumLock:                                             ;The NUMLOCK key.
          ;@@ We must check if this is the Enhanced keyboard
          ;@@ which will emulate Ctrl being down (PseudoCtl Flag
          ;@@ will be set) for the PAUSE key or an AT kbd w/ Ctl down.

          Test [EDI].XlateFlags,PseudoCtl   ;OS2SS-@@ Check if secondary kbd
                                           ;@@ emuating the Ctl key
         .If <nz> OR                       ;@@ If it is OR...
                                           ;## PTM 3128  BEGIN:
         .If <_Ow2KbdHWIDs ne FERRARI_P> AND   ;## If it's not an 88/89 AND
         .If <_Ow2KbdHWIDs ne FERRARI_G> AND   ;## If it's not a 101/102 AND
         .If <BX ne JAGUAR> AND            ;1.3-## If it's not a 122 Key JAGUAR
                                           ;## PTM 3128  END:
          Test DL,CtlFlag                  ;@@ Check if Ctl also pressed.
                                           ;@@ for this KCB
                                           ;@@ PTM 5992 - Begin
         .If <nz> OR                       ;@@ Is it  OR?
          Test [EDI].XHotKeyShift,CtlFlag  ;OS2SS-@@ Also check in interrupt shift
                                           ;@@   state
         .If <nz> AND                      ;@@ Is it being held down at all
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                           ;&& translations are independent.
         .If <nz>
                                           ;@@ PTM 5992 - End
                                           ;@@ PTM 4004:
            Test DL, AltFlag               ;@@ Check for Alt key down.
           .If < z >                       ;@@ No alt key, process Ctl-NumLk,
              Test [ESI].DDFlags,KeyBreak  ;OS2SS-@@ Check if this is a key break
             .If <nz>
                And [EDI].XlateFlags,Not PseudoCtl ;OS2SS-@@ Clear flag

                Test _Ow2MiscFlags3,PauseLatch    ;&& PTM 2344 BEGIN: If the NumLock
                                              ;&& make preceded the Ctrl make
               .If <z>                        ;&& then this is not the break of
                                              ;&& of a Pause.  Therefore do not
                                              ;&& throw the key away. Treat it
                   Jmp ToggleKey              ;&& as a normal shift break.
               .Endif                         ;&& Endif this was not the Pause.
                And _Ow2MiscFlags3,Not PauseLatch ;&& Reset the Pause sequence flag.
                                              ;&& PTM 2344 END:

                Jmp NoXlate                 ;@@ Mark Key Packet undefined
             .Else                          ;@@ Else it's a make scan code
                Or [ESI].DDFlags,PauseKey    ;OS2SS-@@ So tell dd it's the PAUSE KEY.
                Or _Ow2MiscFlags3,PauseLatch    ;&& PTM 2344: Flag the make of the
                                            ;&& NumLock to be used as a latch.
                Jmp EndActionCase           ;@@ Completed translation
             .Endif                         ;@@ Endif key break or not
           .Else                            ;&& PTM 2383: Else Alt is down
              And [EDI].XlateFlags,Not PseudoCtl ;OS2SS-@@ Clear flag
              Test DL,CtlFlag               ;&& so test if Ctrl is also down.
             .If <z>                        ;&& If Ctrl is not down then the
                Jmp NoXlate                 ;&& key sequence Alt-Pause Key
                                            ;&& is undefined.
             .Endif                         ;&& Endif Ctrl is down with Alt.
           .Endif                           ;@@ End alt key down check. PTM 4004
         .Endif
          Test DL,CtlFlag                   ;Check if Ctl also pressed.
                                            ;@@ for this KCB
                                            ;@@ PTM 5992 - Begin
         .If <nz> OR                        ;@@ Is it  OR?
          Test [EDI].XHotKeyShift,CtlFlag    ;@@ Also check in interrupt shift
                                            ;@@   state
         .If <nz> AND                       ;@@ Is it being held down at all
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                            ;&& translations are independent.
         .If <nz>
                                            ;@@ PTM 5992 - End
            Test DL,AltFlag                 ;Yes, check Alt key also.
           .If <nz>                                            ;Is it?
              Test [EDI].XlateFlags,DumpKeyOnce ;OS2SS-@@ Yes check if second time.
             .If <nz>                                          ;Is it?
                Or [ESI].DDFlags,DumpKey  ;OS2SS-@@ So tell dd it's the DUMP KEY.
             .Else
                Test [ESI].DDFlags,KeyBreak ;OS2SS-Check if this's key break.
               .If <nz>                                        ;Is it?
                  Or [EDI].XlateFlags,DumpKeyOnce ;OS2SS-@@ Yes indicate seen once.
               .Endif
             .Endif
           .Endif
            Test [ESI].DDFlags,KeyBreak ;OS2SS-Check if this's the key break.
           .If <nz>   ;If so, clear Num Lock down bit in Packet & PSG.
              And Byte Ptr [ESI].Key.Shift+1,Not (NumFlag ShR 8)
              ;@@ Clear bit in hot key shift status also
              Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                               ;&& translations are independent.
             .If <nz>
                 And Byte Ptr [EDI].XHotKeyShift+1,Not (NumFlag ShR 8)  ;OS2SS-
             .Endif
              Test [EDI].XlateFlags,DumpKeyOnce ;OS2SS-@@ PTM 7078 - Begin
             .If <z>                         ;@@ If this wasn't the dump key
                 Or [ESI].DDFlags,ShiftMask   ;OS2SS-@@ PTM 6937
                                             ;@@ Indicate this is a shift key.
             .Endif                          ;@@ PTM 7078 - End

              Test _Ow2MiscFlags3,PauseLatch    ;&& PTM 2344 BEGIN: If the NumLock
                                            ;&& make preceded the Ctrl make
             .If <z>                        ;&& then this is not the break of
                                            ;&& of a Pause.  Therefore do not
                                            ;&& throw the key away. Treat it
                 Jmp ToggleKey              ;&& as a normal shift break.
             .Endif                         ;&& Endif this was not the Pause.
              And _Ow2MiscFlags3,Not PauseLatch ;&& Reset the Pause sequence flag.
                                            ;&& PTM 2344 END:

           .Else               ;Set Num Lock down bit in packet & PSG.
              Or Byte Ptr [ESI].Key.Shift+1,(NumFlag ShR 8)     ;OS2SS-
              ;@@ Set bit in hot key shift status also
              Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                              ;&& translations are independent.
             .If <nz>
                 Or Byte Ptr [EDI].XHotKeyShift+1, (NumFlag ShR 8)      ;OS2SS-
             .Endif
              Test [EDI].XlateFlags,DumpKeyOnce ;OS2SS-@@ PTM 7078 - Begin
             .If <z>                         ;@@ If this wasn't the dump key
                 Or [ESI].DDFlags,ShiftMask   ;OS2SS-@@ PTM 6937
                                             ;@@ Indicate this is a shift key.
             .Endif                          ;@@ PTM 7078 - End
              Or _Ow2MiscFlags3,PauseLatch    ;&& PTM 2344: Flag the make of the
                                          ;&& NumLock to be used as a latch.
           .Endif
         .Else NEAR ;Not Ctl-Numlock, fall thru to common Toggle key check.

CapsLock:                                      ;The CapsLock key itself.
ToggleKey:                                   ;Or any general Toggle key.
            Mov EBX,[EBP-8]                ;OS2SS-Get translate table offset.
            Test [ESI].DDFlags,SecondaryKey    ;OS2SS-Check if G kbd dup key.
           .If <nz>                                            ;Is it?
              Mov CH,[EBX].Char3     ;OS2SS-Yes, so get mask for that key.
           .Endif
            And [EDI].XlateFlags,NOT DumpKeyOnce  ;OS2SS-@@ Cancel Dump sequence.
            Mov EBX,[EBP-4]                ;OS2SS-Get translate table offset.
            Or [ESI].DDFlags,ShiftMask   ;OS2SS-@@ Indicate this is a shift key.
            Test Word Ptr [EBX+XTFlags1],ShiftLock  ;OS2SS-ShiftLock type?
           .If <nz> AND                    ;Is it shift lock and...
            Test Word Ptr [EBX+XTFlags1],ShiftToggle ;OS2SS-@@ ShiftLock Toggle?
           .If <z> AND                     ;@@ Is it shift lock latch and...
           .If <AL eq CapsTogl>            ;...is it the CapsLock key?
              Test [ESI].DDFlags,KeyBreak     ;OS2SS-Check for the key BREAK.
             .If <z>                        ;If not, set ShiftLock on.
                Or [ESI].Key.Shift,CX              ;OS2SS-And in the Key rec.
               ;@@ Set bit in hot key shift status also
                Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                               ;&& translations are independent.
               .If <nz>
                   Or [EDI].XHotKeyShift,CX     ;OS2SS-
               .Endif
             .Else                 ;On key-break, only clear DOWN bit.
                Not CX                        ;Make shift bits a mask.
                And Byte Ptr [ESI].Key.Shift+1,CH  ;OS2SS-And in the Key rec.
               ;@@ Clear bit in hot key shift status also
                Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                               ;&& translations are independent.
               .If <nz>
                   And Byte Ptr [EDI].XHotKeyShift+1,CH ;OS2SS-
               .Endif
             .Endif
           .Else                   ;This is not a shift-lock keyboard.
              Test [ESI].DDFlags,KeyBreak     ;OS2SS-Check for the key BREAK.
             .If <nz>                                          ;Is it?
                Not CX                ;Yes, so make shift bits a mask.
                And Byte Ptr [ESI].Key.Shift+1,CH  ;OS2SS-And in the Key rec.

               ;@@ Clear bit in hot key shift status also

                Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                               ;&& translations are independent.
               .If <nz>
                   And Byte Ptr [EDI].XHotKeyShift+1,CH ;OS2SS-
               .Endif
                And [EDI].ToggleFlags,CL        ;OS2SS-@@ Clear latch for this key.
             .Else
                Or Byte Ptr [ESI].Key.Shift+1,CH   ;OS2SS-And in the Key rec.

               ;@@ Set bit in hot key shift status also

                Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                               ;&& translations are independent.
               .If <nz>
                   Or Byte Ptr [EDI].XHotKeyShift+1,CH  ;OS2SS-
               .Endif
                Test [EDI].ToggleFlags,CL  ;OS2SS-@@ Check if seen this key yet.
               .If <z>                                       ;Have we?
                  Or [EDI].ToggleFlags,CL ;OS2SS-@@ No so set latch saying we have.
                  Xor Byte Ptr [ESI].Key.Shift,CL  ;OS2SS-And in the Key rec.
                 ;@@ Set Latch in hot key shift status also
                  Test [EDI].OtherFlags,InterruptTime  ;OS2SS-&& PTM 3191: Make sure KBDXlate
                                                ;&& translations are independent.
                 .If <nz>
                     Xor Byte Ptr [EDI].XHotKeyShift,CL
                 .Endif
               .Else          ;Otherwise this is a repeat of the make.
                  Or [ESI].DDFlags,MultiMake           ;OS2SS-So indicate so.
               .Endif
             .Endif
           .Endif
         .Endif               ;Endif from NumLock plus Ctl test above.
          Jmp EndActionCase ;Go bottom of Xlate Action case table.

SpecKeyCS:                                  ;@@ Special key for NLS support.
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@
          Test DL,AltFlag                   ;@@ Check if Alt key down.
         .If <nz>                           ;@@ Is it?
            And [EDI].XlateFlags,Not Use3Index ;OS2SS-@@ Use Char3 if AltGraph
            Call AltGraphCheck               ;@@ Process if AltGraph
            Test [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ Check if it's not the AltGraph
           .If <nz>                          ;@@ If alt key is normal Alt
                                             ;@@ PTM 5024 - Begin
                Call CheckExtended           ;@@ See if new extended code
                                             ;@@  is defined
                .If <c>                      ;## If it is ...
                    Jmp EndActionCase        ;## the key combo is defined
                .Endif                       ;## Endif there was one defined
                 Jmp NoXlate                 ;## get out now.
           .Endif                            ;## Endif normal Alt.
            Jmp SKCSEnd                      ;##
         .Else NEAR                          ;@@ Else no Alt key down
            Test DL,RShiftFlag+LShiftFlag    ;@@ Is a shift key down
            Mov EBX,[EBP-8]                ;OS2SS-Get translate table offset.
           .If <nz>                          ;@@ Yes so,
               Test DL,CapsTogl              ;@@ See if capslock is on
              .If <nz>                       ;@@ If it is
                 Mov AL,[EBX].Char5        ;OS2SS-@@ Use character 5
              .Else                          ;@@ If it is not then...
                 Mov AL,CH                   ;@@ Use char 2
              .Endif                         ;@@ Endif CapsLock is on.
           .Else NEAR                        ;@@ Else no shift key down
               Test DL,CapsTogl              ;@@ See if capslock is on
              .If <nz>                       ;@@ If it is
                 Mov AL,[EBX].Char4        ;OS2SS-@@ Use character 4
              .Endif
           .Endif                           ;## Endif shift key down.
            Test DL, CtlFlag                ;## Check if Ctrl is down,
           .If <nz>                         ;## If it is then...
               Call SKCtlCheck              ;## Check for spec. Ctrl code.
           .Endif                           ;## Endif Ctrl is down.
         .Endif                             ;## Endif Alt is down.
SKCSEnd:
         .If <AL b 8> AND                 ;## If this was an accent key index
         .If <AL a 0>                     ;##
            Or [ESI].DDFlags,AccentKey     ;OS2SS-## Indicate this is an
                                          ;## unprocessed accent.
            Test [ESI].DDFlags,KeyBreak    ;OS2SS-## Check for the key BREAK.
           .If <z>                        ;## Is it?
              And [EDI].XPSGFlags,Not PrevAccent;OS2SS-## No, clear prev accent num
              Or Byte Ptr [EDI].XPSGFlags,AL   ;OS2SS-## Save accent num for next key
           .Endif
         .Else                    ;## Else this is not an accent table entry
            Mov [ESI].Key.Char,AL  ;OS2SS-## Put character into key packet
            Call AccCheckOut      ;## Check for valid accent
         .Endif                   ;## Endif this is an accent index.
          Jmp EndActionCase       ;## Go to bottom of Xlate Action case table.

SpecKeyAS:                                 ;@@ Special key for NLS support.
          Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
         .If <nz>                           ;@@
            Call UnPauseChk                 ;Go check if in pause state.
         .Endif                             ;@@
          Test DL,AltFlag                   ;@@ Check if Alt key down.
         .If <nz>                           ;@@ Is it?
            And [EDI].XlateFlags,Not Use3Index  ;OS2SS-@@ Use Char3 if AltGraph
            Call AltGraphCheck              ;@@ Process if AltGraph
            Test [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ Check if it's not the AltGraph
           .If <nz>                         ;@@ If alt key is normal Alt
              Mov EBX,[EBP-8]                ;OS2SS-Get translate table offset.
              Mov AL,[EBX].Char4 ;OS2SS-@@ Use char4
              Mov [ESI].Key.Scan,AL ;OS2SS-@@ Put it in the scan code field to
              Jmp SpecKeyEnd               ;@@ Go to merge
           .Endif
         .Else                             ;@@ Else no Alt key down
            Test DL,RShiftFlag+LShiftFlag  ;@@ Is a shift key down
           .If <nz>                        ;@@ Yes so,
                 Mov AL,CH                 ;@@ Use char 2
                 Jmp SpecKeyEnd            ;@@ Go to merge
           .Endif                          ;@@ Else no shift key down
         .Endif                            ;## Endif Alt key down.
          Test DL, CtlFlag                 ;## Check if Ctrl is down
         .If <nz>                          ;## If it is then...
             Call SKCtlCheck               ;## Check for special control code.
         .Endif                            ;## Endif Ctrl is down

SpecKeyEnd:
         .If <AL b 8> AND                ;@@ If this was an accent key index
         .If <AL a 0>
            Or [ESI].DDFlags,AccentKey    ;OS2SS-@@ Indicate this is an
                                         ;@@ unprocessed accent.
            Test [ESI].DDFlags,KeyBreak   ;OS2SS-@@ Check for the key BREAK.
           .If <z>                       ;@@ Is it?
              And [EDI].XPSGFlags,Not PrevAccent ;OS2SS-## No, clear prev accent num
              Or Byte Ptr [EDI].XPSGFlags,AL    ;OS2SS-## Save accent num for next key
           .Endif
         .Else                      ;## Else this is not an accent table entry
            Mov [ESI].Key.Char,AL    ;OS2SS-## Put character into key packet
            Call AccCheckOut        ;## Check for vaild accent.
         .Endif                     ;## Endif this is an accent table entry.
          Jmp EndActionCase         ;## Go to bottom of Xlate Action case table.

XShiftKey:                          ;Extended shift key (for DBCS use).
XToggleKey:                         ;Extended toggle key (for DBCS use).

NoXlate:                        ;Invalid action code, no translate done.
  And [EDI].XlateFlags,NOT DumpKeyOnce     ;OS2SS-@@ Cancel Dump sequence.
  Or [ESI].DDFlags,UndefKey                ;OS2SS-@@ Mark this key undefined.


EndActionCase:  ;*** This is the end of the Xlate Action case table ***.

  Test [ESI].DDFlags, UndefKey              ;OS2SS-## DCR 357:  BEGIN
 .If <z> AND                               ;## This logic tests to see if the
  Test _Ow2MiscFlags3, AltPacket               ;## current keypacket is for an
 .If <z>                                   ;## extended keystroke or not.
     Mov BL,[ESI].Key.Char                  ;OS2SS-## If it is then bit 1 of the Status
    .If <BL eq 0> OR                       ;## field in the keypacket is turned
     Test [EDI].XlateFlags, SecPrefix       ;OS2SS-## on.
    .If <nz>                               ;##
        Or [ESI].Key.Status, EXTENDEDCODE   ;OS2SS-## Turn the bit on in the Status.
    .Endif                                 ;##
 .Endif                                    ;## DCR 357:  END
                                       ;## PTR B702484: BEGIN
  Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
                                       ;## create an extra packet for the E0.
 .If <nz> AND                          ;## PTR B702484: END
  Test [EDI].XlateFlags,SecPrefix       ;OS2SS-&& PTM 2382: Test to see if an E0 or E1
                                       ;&& came before this packet.
 .If <nz> AND                          ;&& If E0 or E1 did precede then,
  Test [EDI].XlateFlags, E1Prefix       ;OS2SS-&& Check to see if it was an E0.
 .If <z>                               ;&& If it was the E0 then,
     Or _Ow2MiscFlags3, E0Packet           ;&& signal an E0 packet coming up.
     Call  MakeE0Packet                ;&& Call MakeE0Packet to manufacture an
                                       ;&& extra packet to precede this one.
 .Endif                                ;&& Endif an E0 preceded this packet.


  Mov BX,[ESI].DDFlags                  ;OS2SS-&& PTM 965 - Always zero out
 .If <BX eq ShiftMask> OR              ;&& char and scan fields for
 .If <BX eq ShiftMask+KeyBreak> OR     ;&& shift packets
 .If <BX eq ShiftMask+SecondaryKey> OR
 .If <BX eq ShiftMask+KeyBreak+SecondaryKey>
     Mov Word Ptr [ESI].Key.Char, 0     ;OS2SS-@@ PTM 2244:  Zero out Character/
                                       ;@@  Scan Code fields in CharData
                                       ;@@  Record for Japan compatability.
     And [ESI].Key.Status, NOT EXTENDEDCODE
                                       ;OS2SS-## DCR 357: Do NOT indicate that this
                                       ;## is an extended scan instead of
                                       ;## an E0 char., if this is a shift pac.
     Test [EDI].XInputMode,SHIFTREPORT  ;OS2SS-&& (P13303) Are we in Shift rep. mode?
    .If <nz>                           ;@@ If so......
        Or [ESI].Key.Status,1           ;OS2SS-@@ Flag as shift report packet
    .Endif                             ;@@ Endif Shift Report
 .Endif                                ;@@ Endif Shift Report
  And [EDI].XlateFlags,Not SecPrefix+E1Prefix         ;OS2SS-Clear indicator.
  Mov AL,Byte Ptr [ESI].MonFlags+1    ;OS2SS-Get the original scan code back.
  Stc                                  ;OS2SS-
  Ret

KbdXlate Endp  ;-------------------------------------------------------/

Public  CapsCheck
CapsCheck Proc ;-----------------------------------------------------\
;************** START OF SPECIFICATIONS ********************************
;*                                                                     *
;* Subroutine Name: CapsCheck                                          *
;*                                                                     *
;* Descriptive Name: Check IF character should be shifted              *
;*                                                                     *
;* Function:   This routine checks IF a characer should be shifted.    *
;*             It checks IF CapsLock, ShiftLock or the shift key       *
;*             effect this key.  IF the char should be shifted,        *
;*             then it places Char2 in AL.                             *
;*                                                                     *
;*    Notes:                                                           *
;*                                                                     *
;* Entry Point: CapsCheck              Linkage: Near                   *
;*                                                                     *
;* Input: AL = CHAR1 from translate table                              *
;*        CH = CHAR2 from translate table                              *
;*        DX = ShiftFlags                                              *
;*        AH = Scan code w/ break bit cleared                          *
;*        BX = SHIFTLOCK & CAPSLOCK effect indicators                  *
;*                                                                     *
;* Exit-Normal: AL = ASCII character after shift checking              *
;*                                                                     *
;* Exit-Error:  None                                                   *
;*                                                                     *
;* Effects:     AX, BX, registers, carry flag changed.                 *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: None                                                   *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************

   Xor BH,BH                       ;## Prepare a byte.
   Test DL,RShiftFlag+LShiftFlag   ;## Check if Shift key down.
  .If <nz>                         ;## Is one of them?
     Or BH,CapsTogl                ;## Yes, so prepare to check Capslock.
  .Endif                           ;## Endif a shift key is down
   And DL,BL                       ;## Isolate Capslock flag.
   Push EBX                         ;OS2SS-## Save BX for now
   Mov EBX,[EBP-4]                ;OS2SS-## And put it in BX
   Test [EBX].XTFlags1,ShiftLock ;OS2SS-## Check if Shiftlock  kbd
   Pop EBX                          ;OS2SS-## Restore BX
  .If <nz>                         ;## If it is then...
     Test BL, CapsTogl             ;## Check if shift lock effects key type.
    .If <nz>                       ;## If it does then...
       Or BH,DL                    ;## either Capslock, Shift,
                                   ;## or both will cause shifting
    .Else                          ;## If it does not
       Or BH,BH                    ;## fix the zero flag.
    .Endif                         ;## Endif shift lock effects key type.
  .Else                            ;## Else its a CapsLock kbd
     Test BL, CapsTogl             ;## Check if CapsLock effects key type.
    .If <nz>                       ;## If it does then...
       Xor BH,DL                   ;## Add Capslock & ShiftFlag to decide state.
    .Else                          ;## If it does not
       Or BH,BH                    ;## fix the zero flag.
    .Endif                         ;## Endif CapsLock effects key type.
  .Endif                           ;## Endif shift lock keyboard.
  .If <nz>                         ;## Should key be capitalized?
     Mov AL,CH                     ;## Yes, so use Char2.
  .Endif                           ;##
   Ret

CapsCheck Endp  ;-------------------------------------------------------/

Public  SKCtlCheck
SKCtlCheck Proc ;-----------------------------------------------------\
;************** START OF SPECIFICATIONS ********************************
;*                                                                     *
;* Subroutine Name: SKCtlCheck                                         *
;*                                                                     *
;* Descriptive Name: Check IF character has special control code       *
;*                                                                     *
;* Function:   This routine checks IF a character or scan code has a   *
;*             special control code associated with it.                *
;*             IF it does then it sets the appropriate ASCII/scan      *
;*             codes.                                                  *
;*                                                                     *
;*    Notes:  Ctl key is already known to be down                      *
;*                                                                     *
;* Entry Point: SKCtlCheck             Linkage: Near                   *
;*                                                                     *
;* Input: AH = Scan code w/ break bit cleared                          *
;*                                                                     *
;* Exit-Normal: AL = ASCII character after special control code check  *
;*                                                                     *
;* Exit-Error:  None                                                   *
;*                                                                     *
;* Effects:     AX                                                     *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: None                                                   *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************

  .If <AH eq 3>                   ;@@ Is this Ctl-2?
     Xor AL,AL                    ;@@ Yes, so set extended code.
  .ElseIf <AH eq 7>               ;@@ Is this Ctl-6?
     Mov AL,30                    ;@@ Yes, so set ASCII "RS" code.
                                  ;@@ PTR B702484 and PTM 5024 - Begin
  .ElseIf <AH eq 15>              ;@@ Is this Ctl-Tab?
     Xor AL,AL                    ;@@ Yes, so set extended code.
     Mov [ESI].Key.Scan,94h        ;OS2SS-@@ Yes, so set extended code.
                                  ;@@ PTR B702484 and PTM 5024 - End
  .ElseIf <AH eq 26>              ;@@ Is this Ctl-[?
     Mov AL,27                    ;@@ Yes, so set "Esc" code.
  .ElseIf <AH eq 27>              ;@@ Is this Ctl-]?
     Mov AL,29                    ;@@ Yes, so set ASCII "GS" code.
  .ElseIf <AH eq 43>              ;@@ Is this Ctl-\?
     Mov AL,28                    ;@@ Yes, so set ASCII "FS" code.
  .ElseIf <AL eq "-">             ;@@ Is this Ctl-dash?
     Mov AL,31                    ;@@ Yes, so set ASCII "US" code.
                                  ;1.3-## PTR 4862 BEGIN:
  .ElseIf <AH eq 12>              ;1.3-## Is this the key for scan code 12.
     Mov AL,31                    ;1.3-## Yes, so set ASCII "US" code.
                                  ;1.3-## PTR 4862 END.
  .ElseIf <AL eq " ">             ;@@ Is this the space key?
     ;Value in AL is correct.     ;@@ Yes, so leave as is.
  .Else                           ;@@ If here, combo is undefined.
     Mov AL, -1                   ;@@ Go mark Undefined.
     Or [ESI].DDFlags,UndefKey     ;OS2SS-## PTR B702142 Mark this key undefined.
  .Endif                          ;@@
   Ret                            ;@@ Endif Ctl key down check

SKCtlCheck Endp  ;-------------------------------------------------------/

Public  SKAltCheck
SKAltCheck Proc ;-----------------------------------------------------\
;************** START OF SPECIFICATIONS ********************************
;*                                                                     *
;* Subroutine Name: SKAltCheck                                         *
;*                                                                     *
;* Descriptive Name: Check IF character has extended code              *
;*                                                                     *
;* Function:   This routine checks IF a characer or scan code has a    *
;*             special extended code associated with it.               *
;*             IF it does then it sets the appropriate ASCII/scan      *
;*             codes.                                                  *
;*                                                                     *
;*    Notes:  Alt key is already known to be down                      *
;*                                                                     *
;* Entry Point: SKAltCheck             Linkage: Near                   *
;*                                                                     *
;* Input: DI = Per Session Data Area Address                           *
;*        SI = Key Packet Address                                      *
;*        DX = ShiftFlags                                              *
;*        AH = Scan code w/ break bit cleared                          *
;*                                                                     *
;* Exit-Normal: AL = ASCII character after special control code check  *
;*                                                                     *
;* Exit-Error:  None                                                   *
;*                                                                     *
;* Effects:     AX, BX, registers, carry flag changed.                 *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: AltGraphCheck   CheckExtended                          *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************

  And [EDI].XlateFlags,Not Use3Index  ;OS2SS-@@ Use Char3 if AltGraph
  Call AltGraphCheck              ;@@ Process if AltGraph
  Test [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ Check if it's not the AltGraph
 .If <nz>                    ;@@ If alt key is normal Alt
   .If <AL eq " ">           ;@@ Is this the space key?
      Mov [ESI].Key.Char,AL   ;OS2SS-@@ Yes, so leave as is.
                             ;@@ PTM 5024 - Begin
   .Else                     ;@@ Set extended code for others
      Call CheckExtended     ;@@ Go check if this is new extended
                             ;@@ scan code
     .If <nc>                ;@@ If it is, everything is set up
                             ;@@ otherwise it's old so
         Add AH,118           ;@@ calculate extended code.
         Mov [ESI].Key.Scan,AH ;OS2SS-@@ Put extended code in Key rec.
     .Endif
                             ;@@ PTM 5024 - End
   .Endif
 .Else                       ;@@ else it was AltGraph
    Mov [ESI].Key.Char,AL     ;OS2SS-@@ Yes, so leave as is.
 .Endif                      ;@@ Endif UNDEFINED or normal ALT
  Ret

SKAltCheck Endp  ;-----------------------------------------------------/

Public  AccCheckOut
AccCheckout Proc ;-----------------------------------------------------\
;***********************************************************************
;*                                                                     *
;* Subroutine Name: AccCheckout                                        *
;*                                                                     *
;* Descriptive Name: Check and Process Valid Accents                   *
;*                                                                     *
;* Function:   This routine is called from KbdXlate and checks if an   *
;*             accent key was hit prior to the current key.  If so,    *
;*             a check is made to see if the key is affected by that   *
;*             accent and if it is                                     *
;*             the value specified by the accent table entry is put in *
;*             the key packet and control returns to KbdXlate.         *
;*             If the key is not affected by that accent, then it is   *
;*             put in a seperate keypacket and control returns to      *
;*             KbdXlate to process the current key.                    *
;*                                                                     *
;* Entry Point: AccCheckout          Linkage: Near                     *
;*                                                                     *
;* Input:    Beginning offset of translate table on the stack          *
;*                                                                     *
;* Exit-Normal: Monitor Key Packet filled in                           *
;*                                                                     *
;* Exit-Error:  N/A                                                    *
;*                                                                     *
;* Effects:     BX                                                     *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: BadAccent                                              *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************


    ;Check if last key seen was an accent key.
    Push EBX                             ;OS2SS-@@ Save BX
    Mov BX,[EDI].XPSGFlags               ;OS2SS-&& Get flags from PSG.
    And BX,PrevAccent                   ;&& Isolate previous accent number
                                        ;&&  field.
   .If <nz> NEAR                        ;Was there one?
      Push EDI                           ;OS2SS-Yes, save index reg for now.

      ;Translate table offset now four words back on the stack.

      And EBX,0FFh                         ;OS2SS-Clear upper byte of accent number.
      Mov EDI,EBX                         ;OS2SS-Put accent number in index reg.
      Dec EDI                            ;OS2SS-Accent entry 1 has offset zero.
      IMul EDI,AccEntryLen     ;OS2SS-Set offset of correct accent table entry.
      Add EDI,Accents         ;OS2SS-Set offset within overall translate table.
      Add EDI,[EBP-4]                  ;OS2SS-Add offset of translate table itself.
      Push ECX                           ;OS2SS-And save...
      Push EDX                           ;OS2SS-..other regs.
      Mov EDX,[EBP-8]            ;OS2SS-Get Xlate Operation word.
      Mov DX,[EDX].XlateOp            ;OS2SS-Get Xlate Operation word.
      Mov CL,7                          ;Set # of bits to highest accent no.
      Sub CL,BL                         ;Subtract actual accent number.
      Mov EBX,EDI                         ;OS2SS-Save accent table entry offset.
      Or DX,DX             ;## PTM 2329: Make sure that if the max. number
                           ;## of accents are used that the flags bits are
                           ;## correctly for DX.
      Shl DX,CL            ;Shift Accent Flags left by calculated count.
     .If <ns>           ;So is this key affected by the previous accent?
          Mov ECX,[EBP-4]          ;OS2SS-@@ Get the XT header
          Mov CX,[ECX].XTFlags1          ;OS2SS-@@ Get the XT header flags.
          Mov EDI,[ESP+8]                         ;OS2SS- Restore OtherFlag index.
          Call BadAccent                      ;No! Go take care of things.
     .Else                       ;Accent flags say this key is accented.
        Pop EDX                             ;OS2SS-Restore shift flags for now.
        Push EDX                                   ;OS2SS-But leave them saved.
        Push EAX                                        ;OS2SS-Save AX for now.
        Mov AL,[ESI].Key.Char       ;OS2SS-@@ PTM 6860
        Mov ECX,20                  ;OS2SS-Set max pairs in Accent table entry.
        Add EDI,AcMap1       ;Point to  first pair in accent table entry.
TLoop: ;Top of loop looking for current scan code in accent table entry.
        Mov DX,[EDI]                               ;OS2SS-Pick up next pair.
       .If <DX eq 0>               ;@@ PTM 6860 - Begin If we are at the end
                                   ;@@ of the list
          Mov ECX,1                 ;OS2SS-@@ Set end of loop condition
       .ElseIf <AL eq DL>          ;@@ Else Have we found a match?
          Jmp Short XLoop                       ;Yes, so exit from loop.
       .Endif
        Add EDI,2                                 ;Increment our pointer.
        Loop TLoop                                              ;Repeat.
XLoop:  Or CX,CX                 ;Check if no match before end of entry.
       .If <z>                                            ;Is that true?
            Mov ECX,[EBP-4]          ;OS2SS-@@ Get the XT header
            Mov CX,[ECX].XTFlags1          ;OS2SS-@@ Get the XT header flags.
            Mov EDI,[ESP+12]                         ;OS2SS- Restore OtherFlag index.
            Call BadAccent                      ;No! Go take care of things.
       .Else                ;Else we found our accented character value!
          Mov [ESI].Key.Char,DH                  ;OS2SS-Put it in CharData rec.
;          Mov [ESI].Key.Scan,0        ;OS2SS-Zero scan code for accented chars.
          Or [ESI].DDFlags,AccentedKey     ;OS2SS-Indicate accent affected key.
       .Endif
        Pop EAX                                              ;Restore AX.
     .Endif
      Pop EDX                                            ;Restore the...
      Pop ECX                                            ;..altered regs.
      Pop EDI                                         ;Restore PSG index.
      And [EDI].XPSGFlags,Not PrevAccent     ;OS2SS-@@ Clear previous accent field.
   .Endif
    Pop EBX                          ;@@ Restore BX
    Test [ESI].DDFlags,AccentedKey   ;OS2SS-Check if accent affected key.
   .If <nz> OR                      ;Did it?
   .If <[ESI].DDFlags e BadKeyCombo> ;OS2SS-@@ check if this was an invalid combo?
      Pop EBX                        ;OS2SS-Throw away original return address.
      Jmp EndActionCase             ;And quit now.
   .Endif
    Ret                                                    ;Else return.

AccCheckout Endp ;-----------------------------------------------------/

Public  BadAccent
BadAccent Proc  ;------------------------------------------------------\

;***********************************************************************
;*                                                                     *
;* Subroutine Name: BadAccent                                          *
;*                                                                     *
;* Descriptive Name: Process an Accent that does Not Apply to a Char   *
;*                                                                     *
;* Function:   Set up a KeyPacket that must be passed as a standalone  *
;*             character                                               *
;*                                                                     *
;* Entry Point: BadAccent            Linkage: Near                     *
;*                                                                     *
;* Input:    SI = @ of KeyPacket                                       *
;*           Empty KeyPacket2 immediately follows KeyPacket            *
;*           ES:BX = @ of Accent Table Entry for accent to pass        *
;*           CX = Translate Table Header Flags                         *
;*                                                                     *
;* Exit-Normal: Monitor Key Packet filled in                           *
;*                                                                     *
;* Exit-Error:  N/A                                                    *
;*                                                                     *
;* Effects:     CX                                                     *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: CopyPacket                                             *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************
  Push ESI      ;OS2SS-
  Push EDI      ;OS2SS-
  Test CX,AccentPass              ;@@ Check if key packets should be passed
 .If <z> OR                       ;@@ If not... OR
  Test [EDI].OtherFlags,InterruptTime  ;OS2SS-@@ If it's interrupt time
 .If <z>                          ;@@ Tell Int Handler to beep
     Mov [ESI].DDFlags,BadKeyCombo ;OS2SS-@@ or strategy proc to return invalid parm.
 .Else                            ;@@ Else key packets should be passed
     Call CopyPacket              ;&& PTM 2382: Make a copy of the first
                                  ;&& packet into the extra packet.

    ;Now ESI has incremented to point to KeyPacket2.
     Mov Byte Ptr [ESI].MonFlags+1,0     ;OS2SS-Zero the original scan code field.
     Mov [ESI].DDFlags,AccentedKey+AccentKey ;OS2SS-@@ Indicate printable accent char.
     Mov CX,[EBX]               ;OS2SS-Get char/scan to pass from accent entry.
     Mov Word Ptr [ESI].Key.Char,CX                      ;OS2SS-Put in KeyPacket2.
     Mov Byte Ptr [ESI].MonFlags,-1         ;OS2SS-Tell KBDDD to pass two packets.
 .Endif
  Pop EDI
  Pop ESI
  Ret

BadAccent Endp  ;------------------------------------------------------/

Public AltPadPacket
AltPadPacket  Proc       ;---------------------------------------------\

;***********************************************************************
;*                                                                     *
;* Subroutine Name: AltPadPacket                                       *
;*                                                                     *
;* Descriptive Name: Set up a KeyPacket for the Break of the Alt Key   *
;*                                                                     *
;* Function:   A monitor packet is set up so that on Alt-Numpad        *
;*             sequences the break of the Alt key is not lost.         *
;*                                                                     *
;* Entry Point: AltPadPacket         Linkage: Near                     *
;*                                                                     *
;* Input:    SI = @ of KeyPacket                                       *
;*           Empty KeyPacket2 immediately follows KeyPacket            *
;*                                                                     *
;* Exit-Normal: Monitor Key Packet filled in                           *
;*                                                                     *
;* Exit-Error:  N/A                                                    *
;*                                                                     *
;* Effects:     None, Registers are preserved.                         *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: CopyPacket                                             *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************
                                     ;&& DCR 1713 BEGIN:
  Push ESI                            ;OS2SS-&& Save the registers
  Push EDI                            ;OS2SS-&& that we will use here
  Push ECX                            ;OS2SS-&& to duplicate the first packet.
  Call CopyPacket                    ;&& PTM 2382: Make a copy of the first
                                     ;&& packet into the extra packet.

    ;&& Now ESI has been incremented to point to KeyPacket2.

  Or [ESI].DDFlags,ShiftMask+KeyBreak ;OS2SS-&& Indicate that this is shift packet.
  Mov word ptr [ESI].Key.Char,0       ;OS2SS-&& Zero out the original char field.
  Mov Byte Ptr [ESI].MonFlags,-1      ;OS2SS-&& Tell KBDDD to pass two packets.
  Pop ECX                             ;OS2SS-&& Restore registers.
  Pop EDI                             ;OS2SS-&&
  Test [EDI].XInputMode,SHIFTREPORT   ;OS2SS-&& Are we in shift report mode ?
 .If <nz>                            ;&& If so then...
     Or [ESI].Key.Status,1            ;OS2SS-&& flag this as a shift report packet.
 .Endif                              ;&& Endif a shift report packet.
  Pop ESI                             ;OS2SS-&&
  Ret                                ;&& DCR 1713 END:

AltPadPacket Endp  ;------------------------------------------------------/

Public MakeE0Packet
MakeE0Packet Proc       ;---------------------------------------------\

;***********************************************************************
;*                                                                     *
;* Subroutine Name: MakeE0Packet                                       *
;*                                                                     *
;* Descriptive Name: Set up a KeyPacket for the E0 scan code           *
;*                                                                     *
;* Function:   A monitor packet is set up for the E0 scan code packet  *
;*             that should have preceded the current scan code.        *
;*                                                                     *
;* Note:   This routine added for CP111 PTM 2382.  An E0 keypacket     *
;*         is now manufactured and passed in combination with the      *
;*         packet that follows the E0 scan code.  This change was      *
;*         made in order to ensure that the E0 packet would always     *
;*         end up in the correct screen group.                         *
;*                                                                     *
;* Entry Point: MakeE0Packet         Linkage: Near                     *
;*                                                                     *
;* Input:    SI = @ of KeyPacket                                       *
;*           Empty KeyPacket2 immediately follows KeyPacket            *
;*                                                                     *
;* Exit-Normal: Monitor Key Packet filled in                           *
;*                                                                     *
;* Exit-Error:  N/A                                                    *
;*                                                                     *
;* Effects:     None, Registers are preserved.                         *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: CopyPacket                                             *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************
                                     ;&& PTM 2382 BEGIN:
  Push ESI                           ;OS2SS-&& Save the registers
  Push EDI                           ;OS2SS-&& that we will use here
  Push ECX                           ;OS2SS-&& to duplicate the first packet.

  Call CopyPacket                    ;&& PTM 2382: Make a copy of the first
                                     ;&& packet into the extra packet.

    ;&& Now ESI has been incremented to point to KeyPacket2.

  Mov Byte Ptr [ESI].MonFlags,0      ;OS2SS-&& Init monitor flags low byte to zero.
  Mov Byte Ptr [ESI].MonFlags+1,OtherKey ;OS2SS-&& Put Scan Code in MonFlags high byte.
  Mov [ESI].DDFlags, 0               ;OS2SS-&& Clear the flag bits for new packet.
  Or [ESI].DDFlags, SecPrefixCode    ;OS2SS-&& Indicate this is a secondary prefix.
  Mov CX, [_Ow2KCBShFlgs]                ;&& Get the saved Shift Flags.
  Mov [ESI].Key.Shift,CX             ;OS2SS-&& Put Shift Flags in packet.
  Mov [ESI].Key.Char,0               ;OS2SS-&& Zero out the original char field.
  Mov [ESI].Key.Scan,0               ;OS2SS-&& Zero out the original Scan field.

  Mov Byte Ptr [ESI].MonFlags,-1     ;OS2SS-&& Tell KBDDD to pass two packets.

  Pop ECX                            ;OS2SS-&& Restore registers.
  Pop EDI                            ;OS2SS-&&
  Pop ESI                            ;OS2SS-&&
  Ret                                ;&& PTM 2382 END:

MakeE0Packet Endp  ;------------------------------------------------------/

Public  CopyPacket
CopyPacket Proc ;-----------------------------------------------------\
;***********************************************************************
;*                                                                     *
;* Subroutine Name: CopyPacket                                         *
;*                                                                     *
;* Descriptive Name: Copy KeyPacket1 to KeyPacket2                     *
;*                                                                     *
;* Function:   This routine is called from BadAccent, AltPadPacket,    *
;*             and MakeE0Packet.  It's purpose is to duplicate the     *
;*             first keypacket to the extra  keypacket which follows   *
;*             the first.  This is done so that the Interrupt Handler  *
;*             can pass both keypackets on the same interrupt.         *
;*                                                                     *
;* Entry Point: CopyPacket           Linkage: Near                     *
;*                                                                     *
;* Input:    SI = @ of KeyPacket                                       *
;*           Empty KeyPacket2 immediately follows KeyPacket            *
;*                                                                     *
;* Exit-Normal: Monitor Key Packet copyed                              *
;*                                                                     *
;* Exit-Error:  N/A                                                    *
;*                                                                     *
;* Effects:                                                            *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: None                                                   *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************

  Mov ECX,KeyPacketLen               ;OS2SS-&& Set length of packets.
  Mov EDI,ESI                        ;OS2SS-&& Point to...
  Add EDI,ECX                        ;OS2SS-&& ...KeyPacket2.
CopyLoop:                            ;&& Loop copying packet.
     Mov CH,[ESI]                    ;OS2SS-&& Get byte from first packet.
     Mov [EDI],CH                    ;OS2SS-&& Put in Packet2.
     Xor CH,CH                       ;&& Fix counter reg.
     Inc ESI                          ;OS2SS-&& Increment source ptr.
     Inc EDI                          ;OS2SS-&& Increment dest ptr.
     Loop CopyLoop                   ;&& Repeat for all bytes.
   Ret

CopyPacket Endp  ;------------------------------------------------------/


Public UnPauseChk
UnPauseChk Proc  ;-----------------------------------------------------\
;***********************************************************************
;*                                                                     *
;* Subroutine Name: UnPauseChk                                         *
;*                                                                     *
;* Descriptive Name: Check For Key to End Pause Mode                   *
;*                                                                     *
;* Function: Checks if key signalled the end of Pause mode.            *
;*           If it did, this routine resets the flag and               *
;*           returns to the the end of KbdXlate.  Otherwise            *
;*           it just returns                                           *
;*                                                                     *
;* Entry Point: UnPauseChk           Linkage: Near                     *
;*                                                                     *
;* Input:    None                                                      *
;*                                                                     *
;* Exit-Normal: Nothing affected                                       *
;*                                                                     *
;* Exit-Error:  N/A                                                    *
;*                                                                     *
;* Effects:     Nothing                                                *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: None                                                   *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************

  And [EDI].XlateFlags,NOT DumpKeyOnce ;OS2SS-@@ If here, also cancels Dump sequence.
  Test [EDI].XPSGFlags,NowPaused       ;OS2SS-@@ Check if in paused state.
 .If <nz> AND                                                   ;Are we?
  Test [ESI].DDFlags,KeyBreak               ;OS2SS-Yes, and is this a key Make?
 .If <z>                                                         ;Is it?
    And [ESI].DDFlags, NOT KeyTypeMask ;OS2SS-&& PTM 3940: Indicate Wake-Up key.
    Or [ESI].DDFlags,WakeUpKey         ;OS2SS-&& PTM 3940:
    Pop ECX                                        ;OS2SS-Purge return address.
    Jmp EndActionCase                                       ;That's all.
 .Endif
  Ret

UnPauseChk Endp  ;-----------------------------------------------------/

Public AltGraphCheck
AltGraphCheck  Proc      ;@@ ------------------------------------------\
;@@ B
;************** START OF SPECIFICATIONS ********************************
;*                                                                     *
;* Subroutine Name: AtlGraphCheck                                      *
;*                                                                     *
;* Descriptive Name: Process an Alt-Graph character input              *
;*                                                                     *
;* Function:   This routine processes a key type that is affected      *
;*             by Alt-Graph if an Alt key is down.  If the Alt key     *
;*             down is not the Alt-Graph key or the Alt-Graph combo,   *
;*             it will set the carry and return.                       *
;*                                                                     *
;*    Notes:   Upon entry to this routine, an Alt key is known to be   *
;*             down                                                    *
;*                                                                     *
;* Entry Point: AltGraphCheck          Linkage: Near                   *
;*                                                                     *
;* Input: DI = Per Session Data Area Address                           *
;*        SI = Key Packet Address                                      *
;*        ES = Translate Table Selector                                *
;*        SS:SP+2 = Offset of translate table                          *
;*        BP = Offset of scan code entry in translate table            *
;*        DX = ShiftFlags                                              *
;*        CharToUse = Which character to use if Alt-Graph is down      *
;*                                                                     *
;* Exit-Normal: Carry set = process as normal Alt key down             *
;*              Carry clear = key has been processed                   *
;*                 AL= ASCII character to use                          *
;*                           OR                                        *
;*                 CharToUse = UNDEFINED                               *
;* Exit-Error:  None                                                   *
;*                                                                     *
;* Effects:     AX, registers, carry flag changed.                     *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: None                                                   *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************
;@@ E
  Push EBX                    ;OS2SS-
  Push ESI                    ;OS2SS-
  Mov  EBX, [EBP-8]           ;OS2SS-Pointer to XlateTable entry for this scan code.
  Mov  ESI, [EBP-4]           ;OS2SS-Pointer to XlateTable top

 .If <[EBX].Char3 eq 0>        ;OS2SS-@@ If Char 3 is 0
    Or [EDI].XlateFlags,NormalAlt ;OS2SS-@@ indicate that only Normal ALT is down
 .Else NEAR                      ;@@ Else Alt-Graph character is defined
    Mov AL,[EBX].Char3            ;OS2SS-@@ Get Char3 from translate table
   .If <[ESI].XTKbdType eq ATKbd> ;OS2SS-@@ If an AT kbd translate table
      Test [ESI].XTFlags1,ShftAlt ;OS2SS-@@ check if we should use Shift-Alt as
     .If <nz>                       ;@@ as the Alt-Graph combo, if so...
        Test DL,RShiftFlag+LShiftFlag   ;@@ Check if a shift key is down
       .If <nz>                     ;@@ If it is
           And [EDI].XlateFlags,Not NormalAlt ;OS2SS-@@ specify to caller
                                             ;@@ that it's Alt-Graph
           Test [EDI].XlateFlags,Use3Index  ;OS2SS-@@ if we're supposed to use it
          .If <nz>                         ;@@ as an index
             Mov CL,AL
             Xor AL,AL
          .Endif
       .Else     ;@@ supposed to use Shift-Alt combo, but shift isn't down
           Mov AL,[EBX].Char1     ;OS2SS-@@ Restore Char1
           Or [EDI].XlateFlags,NormalAlt ;OS2SS-@@ indicate that only Normal ALT is down
       .Endif    ;@@ Endif shift key down check
     .Else       ;@@ Shift-Alt is not Alt-Graph combo, so it is Ctl-Alt
        Test DL,CtlFlag   ;@@ Check if a ctl key is down
       .If <nz>                     ;@@ If it is
           And [EDI].XlateFlags,Not NormalAlt ;OS2SS-@@ specify to caller
                                             ;@@ that it's Alt-Graph
           Test [EDI].XlateFlags,Use3Index  ;OS2SS-@@ if we're supposed to use it
          .If <nz>                         ;@@ as an index
             Mov CL,AL
             Xor AL,AL
          .Endif
       .Else     ;@@ supposed to use Ctl-Alt combo, but Ctl isn't down
           Or [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ indicate only Normal ALT is down
           Mov AL,[EBX].Char1     ;OS2SS-@@ Restore Char1
       .Endif    ;@@ Endif Ctlt key down check
     .Endif      ;@@ Endif Shift-Alt is Alt-Graph combo or not check
   .Else         ;@@ Else it's an Enhanced Keyboard
      Test [ESI].XTFlags1,AltGrafL ;OS2SS-@@ check if we should use Left Alt key
     .If <nz>                       ;@@ as the Alt-Graph key, if so...
        Test DX,LAltFlag            ;@@ Check if left Alt key is down
       .If <nz>                     ;@@ If it is
           And [EDI].XlateFlags,Not NormalAlt ;OS2SS-@@ specify to caller
                                             ;@@ that it's Alt-Graph
           Test [EDI].XlateFlags,Use3Index  ;OS2SS-@@ if we're supposed to use it
          .If <nz>                         ;@@ as an index
             Mov CL,AL
             Xor AL,AL
          .Endif
       .Else     ;@@ supposed to use Left Alt key, but it isn't the one down
           Or [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ indicate that only
                                          ;@@ Normal ALT is down
           Mov AL,[EBX].Char1     ;OS2SS-@@ Restore Char1
       .Endif    ;@@ Endif Left Alt key down check
     .Else       ;@@ Left Alt Key is not Alt-Graph key, so check if it is Right

         Test [ESI].XTFlags1,AltGrafR ;OS2SS-@@ check if we should use Right Alt key
        .If <nz>                        ;@@ as the Alt-Graph key, if so...
            Test DX,RAltFlag            ;@@ Check if right Alt Key is down
           .If <nz>                     ;@@ If it is
               And [EDI].XlateFlags,Not NormalAlt ;OS2SS-@@ specify that it's Alt-Graph
               Test [EDI].XlateFlags,Use3Index  ;OS2SS-@@ if we're supposed to use it
              .If <nz>                         ;@@ as an index
                   Mov CL,AL
                   Xor AL,AL
              .Endif
           .Else     ;@@ supposed to use Right Alt Key, but it isn't down
               Or [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ indicate that only Normal
               Mov AL,[EBX].Char1           ;@@ Restore Char1
           .Endif    ;@@ Endif Right Alt Key down check
        .Else        ;@@ Else Alt-Graph is neither Left nor Right Alt Key
            Or [EDI].XlateFlags,NormalAlt   ;OS2SS-@@ indicate that only Normal
            Mov AL,[EBX].Char1     ;@@ Restore Char1
        .Endif       ;@@ Endif Right key is Alt-Graph or not check
     .Endif          ;@@ Endif Left ALt key is Alt-Graph or not check
   .Endif            ;@@ Endif At or Enhanced Keyboard
 .Endif              ;@@ Endif Char 3 is 0 or not
  Pop ESI                    ;OS2SS-
  Pop EBX                    ;OS2SS-
  Ret

AltGraphCheck Endp ;@@-------------------------------------------/

Public  CheckExtended
CheckExtended  Proc      ;@@ ------------------------------------------\
;@@ B
;************** START OF SPECIFICATIONS ********************************
;*                                                                     *
;* Subroutine Name: CheckExtended                                      *
;*                                                                     *
;* Descriptive Name: Checks for extended codes.                        *
;*                                                                     *
;* Function:   This routine checks if a scan code has an associated    *
;*             extended scan code that goes with it.  If it does,      *
;*             it sets the appropriate fields (scan & char) in the     *
;*             key packet and returns.                                 *
;*                                                                     *
;*    Notes:   Upon entry to this routine, an Alt key is known to be   *
;*             down                                                    *
;*                                                                     *
;* Entry Point: CheckExtended          Linkage: Near                   *
;*                                                                     *
;* Input: DI = Per Session Data Area Address                           *
;*        SI = Key Packet Address                                      *
;*        DX = ShiftFlags                                              *
;*        AH = Scan code w/ break bit cleared                          *
;*                                                                     *
;* Exit-Normal: Carry set = Key has new extended code associated w/ it *
;*              Carry clear = Key does not have new extended code      *
;*                                                                     *
;* Exit-Error:  None                                                   *
;*                                                                     *
;OS2SS- Effects:     AX, registers, carry flag changed.                *
;*                                                                     *
;* Internal References:                                                *
;*    Routines: None                                                   *
;*                                                                     *
;* External References:                                                *
;*    Routines:  None                                                  *
;*                                                                     *
;***********************************************************************
  Push EBX                    ;OS2SS-
                             ;@@ PTM 5024 - BEGIN
  Mov EBX, Offset NewExtSC   ;OS2SS-@@ Get the offset of the table that
                             ;@@ contains the scan codes that have new
                             ;@@ extended codes associated with them
  Mov CX,0                   ;@@ Start at beginning of table
 .While <CX ne NewExtSCLen>  ;@@ While we haven't searched entire table
    .If <AH eq [EBX]>         ;OS2SS-@@ If we found the scan code
        Mov [ESI].Key.Char,0  ;OS2SS-@@ Say its an extended
        Mov CX,NewExtSCLen   ;@@ Set end of loop condition
        Mov EBX,0             ;OS2SS-@@ Set found indicator
    .Else                    ;@@ Else this isn't the scan code
        Inc CX               ;@@ Increment loop counter
        Inc EBX               ;OS2SS-@@ Increment pointer into table
    .Endif                   ;@@ Endif found scan code we're looking for
 .EndWhile                   ;@@ EndWhile we haven't searched entire table
 .If <EBX eq 0>               ;OS2SS-@@ If we found the scan code
   .If <AH eq 0Fh>           ;@@ If it's the tab key
      Mov [ESI].Key.Scan,0A5h ;OS2SS-@@ Set extended code for tab key
   .Endif                    ;@@ Endif it's the tab key
    Stc                      ;@@ Tell caller extended char. exists.
 .Else                       ;@@ Else we didn't find Scan code in table
    Clc                      ;@@ tell caller
 .Endif                      ;@@
  Pop EBX                     ;OS2SS-
  Ret                        ;@@
                             ;@@ PTM 5024 - END
;@@ E
CheckExtended Endp ;@@-------------------------------------------/

_TEXT   ends
  End