home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ADC_TP3.ZIP / INT16.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-03-01  |  2.9 KB  |  84 lines

  1. (*     INT16.PAS
  2. **         The object of this exercise is to demonstrate the use
  3. **         of interrupt $16 service 0.  This function reads the next
  4. **         character form the keyboard and returns it in register AL.
  5. **         The keyboard scan code is returned in register AH.
  6. **         If a function key or one of the cursor control keys is pressed,
  7. **         AL returns zero.  Thus this function can be used to handle
  8. **         function keys in your program.  One caveat, however,  when in
  9. **         NumLock the cursor control keys return the ASCII value for the
  10. **         digits in AL and the scan code for the key in AH.  Also, with
  11. **         the Arrow Keys option of Super Key enabled and NumLock on keys
  12. **         F7..F10 return the codes as though the arrow keys had been pressed.
  13. **
  14. **         The address $0000:$0417 contains the status of the shift keys:
  15. **         BIT: 7    Ins
  16. **              6    CapsLock        if bit = 0 the key is inactive
  17. **              5    NumLock         if bit = 1 the key is active
  18. **              4    ScrollLock
  19. **              3    Alt
  20. **              2    Ctrl
  21. **              1    left shift key
  22. **              0    right shift key
  23. **                                             Bob Wooster, Dec.'85
  24. **                                             CIS 72415,1602
  25. *)
  26. {$R+,V-}
  27. program INT16;
  28. TYPE
  29.    regtype = RECORD CASE Integer OF
  30.                1 : (ax, bx, cx, dx, bp, si, ds, es, fl : Integer);
  31.                2 : (AL, AH, BL, BH, CL, CH, DL, DH : Byte);
  32.               END;
  33.  
  34.    Str2 = string[2];
  35.    Str8 = string[8];
  36.  
  37. function HexByte(b: byte): Str2;
  38. const hexchar: array[0..15] of char =
  39.    ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  40.  
  41. begin   { HexByte }
  42.    HexByte := hexchar[b div 16]+hexchar[b mod 16];
  43. end;    { HexByte }
  44.  
  45. function BinByte(b: byte): Str8;
  46. const binchar: array[0..1] of char = ('0','1');
  47. var i: 1..8;
  48. begin
  49.    BinByte := '00000000';
  50.    for i := 8 downto 1 do begin
  51.       if (b mod 2) = 1 then BinByte[i] := '1';
  52.       b := b div 2;
  53.       end;
  54. end; {BinByte}
  55.  
  56. procedure TestInt16;
  57. var r: regtype;
  58.    KeyStat: byte absolute $0000:$0417;
  59. begin   { TestInt16 }
  60.    with r do begin
  61.       AH := $00; Intr($16, r);
  62.       write('Key status =',BinByte(KeyStat),
  63.          ' AL =',Hexbyte(AL):3,' AH =',HexByte(AH):3,' ':10);
  64.       if AL>0 then
  65.          if AL<32 then writeln('Key =>  ','^',chr(AL+64))
  66.          else writeln('Key =>  ',chr(AL))
  67.       else writeln('Special key pressed');
  68.       if AL = 3 then Halt; {^C}
  69.       end { with r };
  70. end;    { TestInt16 }
  71.  
  72. {---------------MAIN------------------------------}
  73. begin
  74.    ClrScr;
  75.    Writeln('Exercise interrupt $16');
  76.    Writeln;
  77.    Writeln('Type any key...        ^C exits');
  78.    Window(1,4,80,25);   ClrScr;
  79.    repeat
  80.       TestInt16;
  81.    until false;                           { forever }
  82. end.
  83. {---------------END OF FILE INT16.PAS-------------}
  84.