home *** CD-ROM | disk | FTP | other *** search
- (* INT16.PAS
- ** The object of this exercise is to demonstrate the use
- ** of interrupt $16 service 0. This function reads the next
- ** character form the keyboard and returns it in register AL.
- ** The keyboard scan code is returned in register AH.
- ** If a function key or one of the cursor control keys is pressed,
- ** AL returns zero. Thus this function can be used to handle
- ** function keys in your program. One caveat, however, when in
- ** NumLock the cursor control keys return the ASCII value for the
- ** digits in AL and the scan code for the key in AH. Also, with
- ** the Arrow Keys option of Super Key enabled and NumLock on keys
- ** F7..F10 return the codes as though the arrow keys had been pressed.
- **
- ** The address $0000:$0417 contains the status of the shift keys:
- ** BIT: 7 Ins
- ** 6 CapsLock if bit = 0 the key is inactive
- ** 5 NumLock if bit = 1 the key is active
- ** 4 ScrollLock
- ** 3 Alt
- ** 2 Ctrl
- ** 1 left shift key
- ** 0 right shift key
- ** Bob Wooster, Dec.'85
- ** CIS 72415,1602
- *)
- {$R+,V-}
- program INT16;
- TYPE
- regtype = RECORD CASE Integer OF
- 1 : (ax, bx, cx, dx, bp, si, ds, es, fl : Integer);
- 2 : (AL, AH, BL, BH, CL, CH, DL, DH : Byte);
- END;
-
- Str2 = string[2];
- Str8 = string[8];
-
- function HexByte(b: byte): Str2;
- const hexchar: array[0..15] of char =
- ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
-
- begin { HexByte }
- HexByte := hexchar[b div 16]+hexchar[b mod 16];
- end; { HexByte }
-
- function BinByte(b: byte): Str8;
- const binchar: array[0..1] of char = ('0','1');
- var i: 1..8;
- begin
- BinByte := '00000000';
- for i := 8 downto 1 do begin
- if (b mod 2) = 1 then BinByte[i] := '1';
- b := b div 2;
- end;
- end; {BinByte}
-
- procedure TestInt16;
- var r: regtype;
- KeyStat: byte absolute $0000:$0417;
- begin { TestInt16 }
- with r do begin
- AH := $00; Intr($16, r);
- write('Key status =',BinByte(KeyStat),
- ' AL =',Hexbyte(AL):3,' AH =',HexByte(AH):3,' ':10);
- if AL>0 then
- if AL<32 then writeln('Key => ','^',chr(AL+64))
- else writeln('Key => ',chr(AL))
- else writeln('Special key pressed');
- if AL = 3 then Halt; {^C}
- end { with r };
- end; { TestInt16 }
-
- {---------------MAIN------------------------------}
- begin
- ClrScr;
- Writeln('Exercise interrupt $16');
- Writeln;
- Writeln('Type any key... ^C exits');
- Window(1,4,80,25); ClrScr;
- repeat
- TestInt16;
- until false; { forever }
- end.
- {---------------END OF FILE INT16.PAS-------------}