;
; FILE KBD.ASM                                             	
;                                                               
; COPYRIGHT 1980, 1981, 1982, 1983 CONVERGENT TECHNOLOGIES, INC.
; ALL RIGHTS RESERVED						
;								
; THIS PROGRAM IS FURNISHED UNDER A LICENSE RESTRICTING ITS USE	
; SOLELY FOR THE OPERATION OF A DESIGNATED COMPUTER FOR A	
; PARTICULAR PURPOSE, AND MAY NOT BE COPIED OR OTHERWISE USED	
; WITHOUT THE PRIOR WRITTEN CONSENT OF CONVERGENT TECHNOLOGIES,	
; INC.  TITLE TO AND OWNERSHIP OF THE PROGRAM, INCLUDING ITS	
; SOURCE CODE, SHALL AT ALL TIMES REMAIN IN CONVERGENT		
; TECHNOLOGIES. 						
;								
;

$INCLUDE (kbd.mdf)
PUBLIC prgInfoIKey, pDiacriticTable, pSpecialKeys, fAltKbdEncoding
PUBLIC pEscKeys, cEscKeys

DGroup	GROUP	Data, LookupSeg, ExpansionSeg

Data	SEGMENT	PUBLIC	'Data'
prgInfoIKey		DD rgInfoIKey
pSpecialKeys	DD iKbd
fAltKbdEncoding DB 0 ; set to true is using alternate 4 byte encoding table,
					 ; also change rgInfoIkey below.


;
; SPECIAL CHARACTER DEFINITIONS                               
;	The following keyboard codes are used by CTOS when in	
; character mode.  They are used to look up (in the Keyboard	
; Translation Table) the byte value to be returned to the	
; caller of ReadKbd.  If you wish to change the		
; location of the CODE , SHIFT, LOCK, ACTION, or	
; FINISH keys then simply change the following SET macros and	
; the appropriate entries in the Keyboard Translation Table.	
;

SET(LeftCodeKey, 4Ch)
SET(RightCodeKey, 4Dh)
SET(LeftShiftKey, 48h)
SET(RightShiftKey, 49h)
SET(LockKey, 45h)
SET(FinishKey, 04h)
SET(ActionKey, 43h)

iKbd		LABEL	WORD	; Beginning of specialkey list.
	DW 061h		; 'a': Debugger, single process mode.
	DW 062h		; 'b': Debugger, multi process mode.
	DW 07Fh		; <delete>: Forget typeahead buffer.
	DW 044h		; <overtype>: Blank screen (force screen timeout).
	DW LeftCodeKey		
	DW RightCodeKey
	DW FinishKey
	DW ActionKey
	DW LockKey
	DW LeftShiftKey
	DW RightShiftKey
	DW 0FFFFh		;iKeyShift2  reserved BT
	DW 0FFFFh		;iKey00		 reserved BT
	DW 0FFFFh		;iKey000	 reserved BT

;
;  Keyboard Translation Table					
;								
; rgInfoIKey (128) ARRAY OF (Unshifted Value, Shifted Value,	
; Attributes)   						
;								
; The attributes are OR'd together from the following bit	
; masks:							
;								
; 0xxxxxxx (00h) ... does not respond to Lock key as shifted	
;		     value					
; 1xxxxxxx (80h) ... responds to Lock key as shifted value	
;								
; x00xxxxx (00h) ... no repeating when a key is held down	
; x01xxxxx (20h) ... repeating starts after 0.2 seconds		
; x10xxxxx (40h) ... repeating starts after 0.4 seconds		
; x11xxxxx (60h) ... repeating starts after 0.7 seconds		
;								
; xxx00xxx (00h) ... repeat rate is  1 per second		
; xxx01xxx (08h) ... repeat rate is 10 per second		
; xxx10xxx (10h) ... repeat rate is 20 per second		
; xxx11xxx (18h) ... repeat rate is 30 per second		
;
; xxxxxxx1 (01h) ... diacritical key when shifted
; xxxxxx1x (02h) ... diacritical key when unshifted
;								
;


attrControl				EQU 000h + 000h + 000h	;no shift lock, no repeat
attrAlpha 				EQU 080h + 060h + 010h	;shift lock, repeats
attrRepeat				EQU 000h + 060h + 010h	;repeats
attrRepeatFast				EQU 000h + 040h + 018h	;repeats, faster
attrShiftDia				EQU 01h; diacritcal key when shifted
attrUnShiftDia				EQU 02h; diacritcal key when unshifted
attrBothDia				EQU 03h; diacritcal key when shifted or unshifted


rgInfoIkey			LABEL		BYTE

; Table entry:				Meaning(s):
DB	0,   0C0h, attrControl 		; 000	 help
DB	01h, 0C1h, attrRepeatFast 	; 001	 uparrow
DB	02h, 0C2h, attrControl 		; 002	 mark
DB	0Dh, 0C3h, attrControl 		; 003	 bound
DB	04h, 0C4h, attrControl 		; 004	 finish
DB	05h, 0C5h, attrControl 		; 005	 prev page
DB	06h,  10h, attrRepeat 		; 006	 1214
DB	07h, 0C7h, attrControl 		; 007	 cancel
DB	08h,  08h, attrRepeat	 	; 008	 backspace
DB	09h,  09h, attrControl 		; 009	 tab
DB	0Ah,  0Ah, attrRepeat 		; 00A	 return
DB	0Bh, 0CBh, attrRepeatFast 	; 00B	 downarrow
DB	0Ch, 0CCh, attrControl 		; 00C	 next page
DB	0Ah,  0Ah, attrRepeat 		; 00D	 next
DB	0Eh, 0CEh, attrRepeatFast 	; 00E	 leftarrow
DB	12h, 0D2h, attrRepeatFast 	; 00F	 rightarrow

DB	80h,  81h, attrControl 		; 010	 (SHL)
DB	11h, 0D1h, attrRepeat 		; 011	 scrollup
DB	0Fh, 0CFh, attrControl 		; 012	 move
DB	13h, 0D3h, attrRepeat 		; 013	 scrolldown
DB	14h, 0D4h, attrControl 		; 014	 copy
DB	15h, 0D5h, attrControl	 	; 015	 f1
DB	16h, 0D6h, attrControl 		; 016	 f2
DB	17h, 0D7h, attrControl 		; 017	 f3
DB	18h, 0D8h, attrControl 		; 018	 f4
DB	19h, 0D9h, attrControl 		; 019	 f5
DB	1Ah, 0DAh, attrControl 		; 01A	 f6
DB	1Bh, 0C9h, attrControl 		; 01B	 GO
DB	1Ch, 0DCh, attrControl 		; 01C	 f7
DB	1Dh, 0CDh, attrControl	 	; 01D	 f8
DB	1Eh, 0CAh, attrControl	 	; 01E	 f9
DB	1Fh, 0DFh, attrControl	 	; 01F	 f10

DB	20h,  20h, attrRepeat 		; 020	 space
DB	39h,  39h, attrRepeat 		; 021	 9 9
DB	82h,  83h, attrControl 		; 022	 (SHL)
DB	84h,  85h, attrControl 		; 023	 (0)
DB	86h,  87h, attrControl 		; 024	 (NEXT)
DB	0,    0,   0			; 025
DB	0,    0,   0			; 026
DB	27h,  22h, attrRepeat 		; 027	  
DB	0,    0,   0			; 028
DB	0,    0,   0			; 029
DB	0,    0,   0			; 02A
DB	3Dh,  2Bh, attrRepeat 		; 02B	 + =
DB	2Ch,  2Ch, attrRepeat 		; 02C	 , ,
DB	2Dh,  5Fh, attrRepeat 		; 02D	  _
DB	2Eh,  2Eh, attrRepeat 		; 02E	 . .
DB	2Fh,  3Fh, attrRepeat 		; 02F	  ?

DB	30h,  29h, attrRepeat 		; 030	 0 )
DB	31h,  21h, attrRepeat 		; 031	 1 
DB	32h,  40h, attrRepeat 		; 032	 2 @
DB	33h,  23h, attrRepeat 		; 033	 3 
DB	34h,  24h, attrRepeat 		; 034	 4 $
DB	35h,  25h, attrRepeat 		; 035	 5 percent
DB	36h,  03h, attrRepeat 		; 036	 6 cent
DB	37h,  26h, attrRepeat 		; 037	 7 
DB	38h,  2Ah, attrRepeat 		; 038	 8 *
DB	39h,  28h, attrRepeat 		; 039	 9 (
DB	0,    0,   0			; 03A
DB	3Bh,  3Ah, attrRepeat 		; 03B	 ; :
DB	0,    0,   0			; 03C
DB	0,    0,   0			; 03D
DB	0,    0,   0			; 03E
DB	0,    0,   0          		; 03F	 3F = iKeyInvalid

DB	0,    0,   0          		; 040	 40 = iKeyNoKeys
DB	36h,  36h, attrRepeat 		; 041	 6 6
DB	2Dh,  2Dh, attrRepeat 		; 042	  
DB	0,    0,   0 			; 043	 reset
DB	0D0h,0D0h, attrControl	 	; 044	 overtype
DB	0,    0,   attrControl	 	; 045	 lock
DB	32h,  32h, attrRepeat 		; 046	 2 2
DB	33h,  33h, attrRepeat 		; 047	 3 3
DB	0,    0,   0 			; 048	 shift
DB	0,    0,   0 			; 049	 shift
DB	30h,  30h, attrRepeat 		; 04A	 0 0
DB	2Eh,  2Eh, attrRepeat 		; 04B	 . .
DB	0,    0,   0 			; 04C	 code
DB	0,    0,   0 			; 04D	 code
DB	0,    0,   0			; 04E
DB	0,    0,   0			; 04F

DB	0,    0,   0			; 050
DB	0,    0,   0			; 051
DB	0,    0,   0			; 052
DB	0,    0,   0			; 053
DB	0,    0,   0			; 054
DB	0,    0,   0			; 055
DB	0,    0,   0			; 056
DB	0,    0,   0			; 057
DB	0,    0,   0			; 058
DB	0,    0,   0			; 059
DB	0,    0,   0			; 05A
DB	5Bh,  3Ch, attrRepeat 		; 05B	 [ <
DB	37h,  7Ch, attrRepeat 		; 05C	 7 |
DB	5Dh,  3Eh, attrRepeat 		; 05D	 ] >
DB	5Eh,  7Eh, attrRepeat 		; 05E	 ^ 
DB	0,    0,   0			; 05F

DB	31h,  60h, attrRepeat 		; 060	 1 
DB	61h,  41h, attrAlpha 		; 061	 a A
DB	62h,  42h, attrAlpha 		; 062	 b B
DB	63h,  43h, attrAlpha 		; 063	 c C
DB	64h,  44h, attrAlpha 		; 064	 d D
DB	65h,  45h, attrAlpha 		; 065	 e E
DB	66h,  46h, attrAlpha 		; 066	 f F
DB	67h,  47h, attrAlpha 		; 067	 g G
DB	68h,  48h, attrAlpha 		; 068	 h H
DB	69h,  49h, attrAlpha 		; 069	 i I
DB	6Ah,  4Ah, attrAlpha 		; 06A	 j J
DB	6Bh,  4Bh, attrAlpha 		; 06B	 k K
DB	6Ch,  4Ch, attrAlpha 		; 06C	 l L
DB	6Dh,  4Dh, attrAlpha 		; 06D	 m M
DB	6Eh,  4Eh, attrAlpha 		; 06E	 n N
DB	6Fh,  4Fh, attrAlpha 		; 06F	 o O

DB	70h,  50h, attrAlpha 		; 070	 p P
DB	71h,  51h, attrAlpha 		; 071	 q Q
DB	72h,  52h, attrAlpha 		; 072	 r R
DB	73h,  53h, attrAlpha 		; 073	 s S
DB	74h,  54h, attrAlpha 		; 074	 t T
DB	75h,  55h, attrAlpha 		; 075	 u U
DB	76h,  56h, attrAlpha 		; 076	 v V
DB	77h,  57h, attrAlpha 		; 077	 w W
DB	78h,  58h, attrAlpha 		; 078	 x X
DB	79h,  59h, attrAlpha 		; 079	 y Y
DB	7Ah,  5Ah, attrAlpha 		; 07A	 z Z
DB	34h,  7Bh, attrRepeat 		; 07B	 4 {
DB	38h,  5Ch, attrRepeat 		; 07C	 8 backslash
DB	35h,  7Dh, attrRepeat 		; 07D	 5 }
DB	0,    0,   0			; 07E
DB	7Fh,0C8h, attrRepeat 		; 07F	 del


InitDiacriticalTables

;
; Diacritical Keys:
;	Diacritical keys are a mechanism to map a regular key into a foriegn
;	key by a twokey sequence. To define the twokey sequence and the
;	resultant key use the macro below. The first argument is the diacritical
;	key, the second parameter is the following key in the sequence and
;	the third key is the resultant. The macro below, which is commented
;	out, would set SHIFT NEXT PAGE (0CCh) as the diacritic key, and the
;	the two key sequence SHIFT NEXT PAGE, '1' (31h) would  	result 	in the 
;	character '2' (32h).
;
;	The attribute for the diacritical key must also be set in the encoding 
;	table 	above. The diacritcal attributes are:
;
;		attrShiftDia				:if the key is diacritical when shifted
;		attrUnShiftDia				:if the key is diacritical when unshifted
;		attrBothDia				:if the key is diacritical shifted and unshifted
;
' DiacritcalSet (0CCh, 31h, 32h) 

EndDiacriticalTables




;
; The macros below define keyboard keys which when depressed result in
; multiple keystrokes being returned to keyboard clients. 
;
; All keys values represent unencoded keystrokes. Any key on the keyboard
; may be defined as a multibyte escape key. Also, different results may be
; defined depending on the shift and code key state. See the CTOS Reference
; manual Appendix C1 for unencoded value of keyboard keys.
;
; The resulting key sequences must include downstrokes as well as upstrokes
; as well as any shift state required to produce the keyboard characters
; desired. An upstroke is the key value OR'ed with 80h.
;
; The two examples below are 'commented out' by the notation '
; preceding each macro.
;
; In the first example below, the key '0' on the numeric pad (unencoded 
; value 4Ah) is defined to produce 6 keyboard events  
;		downstroke 'a' (61h)
;		upstroke 'a' (0E1h)
;		downstroke 'b' (62h)
;		upstroke 'b' (0E2h)
;		downstroke 'c' (63h)
;		upstroke 'c' (0E3h)
; These 6 keyboard events would produce the 3 keyboard characters 'abc'.
;
; In the second example the key '0' on the numeric pad is depressed when the
; shift or shift lock keys are active would produce the keyboard characters
; '[sys]<sys>'. Note that the first keystroke in this list is shift 
; upstroke (0C8h) which turns off the shift state caused by the invoking
; key, shift'0'.
;
;
;
;
Unshifted EQU 0
Shifted   EQU 3
Coded	  EQU 4
Shift2ed  EQU 8


InitEscapeKeys
'DefEscapeKey(4Ah, Unshifted) (61h,0E1h,62h,0E2h,63h,0E3h)
'DefEscapeKey(4Ah, Shifted) (0C8h,5Bh,0DBh,73h,0F3h,79h,0F9h,73h,0F3h,5Dh,0DDh,48h,5Bh,0C8h,0DBh,73h,0F3h,79h,0F9h,73h,0F3h,48h,5Dh,0C8h,0DDh)
EndEscapeKeys

Data	ENDS
END
eat 		; 037	 7 
DB	38h,  2Ah, 