home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / INTR_DMO.ZIP / MAIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-11-20  |  3.1 KB  |  81 lines

  1. program Display_Keys;
  2.  
  3. { This program is placed in the public domain by Steve Wood,
  4.   author of Using Turbo Pascal, published by Osborne/McGraw-Hill.
  5.  
  6.   The program has been modified so that when <Alt><1> is
  7.   pressed interrupt $80 is activated. Before running this
  8.   program an interrupt handler must be installed for
  9.   interrupt $80. This can be done by executing INTR.COM
  10.   program from DOS. Normally this would be done in a start-up
  11.   batch file. See the comments in READ-ME and INTR.PAS for details. }
  12.  
  13. {$I STD-ATTR.INC}
  14. {$I STD-CTV.INC}
  15.  
  16.   const INTR_KEY     = #120; { Alt-1 }
  17.         INTR_VECTOR  = $80;  { Identifies the interupt being utilized. }
  18.  
  19.   procedure Intr_80;
  20.     var ms_reg     : RegPack;
  21.         xpos, ypos : Byte;
  22.  
  23.     begin
  24.       xpos := WhereX; ypos := WhereY; { Save the cursor position. }
  25.       FillChar(ms_reg,SizeOf(ms_reg),ZERO);
  26.  
  27. (*The following statements store the address of the first program variable
  28.   in the interrupt vector table at the table position following the actual
  29.   interrupt being used. By doing this you provid a means by which the
  30.   interrupt routine can locate variables used by the calling routine.
  31.   Since all of my programs begin with {$I STD-ATTR.INC} the first variable
  32.   declared is always vid_attr. *)
  33.  
  34.       with ms_reg do
  35.       begin
  36.         ah := $25; al := INTR_VECTOR + 1; ds := Dseg; dx := Ofs(vid_attr);
  37.       end; {with}
  38.       MsDos(ms_reg);
  39.  
  40.       FillChar(ms_reg,SizeOf(ms_reg),ZERO);
  41.       Intr($80,ms_reg);     { Activate the interrupt handler at INTR_VECTOR }
  42.       GoToXY(xpos,ypos);    { Restore the cursor position upon return. }
  43.     end; { Intr_80 }
  44.  
  45.    procedure Read_Kbd(var inchr,inctl: Char);
  46.      var ms_reg     : RegPack;
  47.  
  48.       begin
  49.         inctl := NULL_CHR;                 { Initialize inctl to NULL_CHR.  }
  50.         with ms_reg do
  51.         begin
  52.           ax := ZERO;                      { ah = 0 for read next kbd char.   }
  53.           Intr($16,ms_reg);                { Call keyboard interrupt routine. }
  54.           inchr := Chr(al);                { Convert result to Char.          }
  55.           if (inchr = #0) then             { If function/special key pressed  }
  56.             begin                          { get scan code and handle         }
  57.               if (Chr(ah) = INTR_KEY) then { interrupt if INTR_KEY pressed.   }
  58.                 Intr_80;
  59.               inctl := Chr(ah)             { Put scan code in inctl.  }
  60.             end
  61.           else                                { Otherwise trap conventional }
  62.             if (inchr in [#1..#31,DEL]) then  { control codes as scan codes.}
  63.               inctl := inchr;
  64.         end; {with}
  65.       end; { Read_Kbd }
  66.  
  67.   begin { Display_Keys }
  68.     ClrScr;
  69.     WriteLn('Press a key to display its ASCII Code');
  70.     WriteLn('Press <Alt><1> to invoke interrupt $80');
  71.     WriteLn('Press <CTRL><Q> to QUIT');
  72.     repeat
  73.       Read_Kbd(inchr,inctl);
  74.       if (inchr > #0) then
  75.         WriteLn('The ASCII code for ',inchr,' is ',Ord(inchr));
  76.       if (inctl > #0) and (inchr = #0) then
  77.         WriteLn('The scan code for  ',inchr,' is ',Ord(inctl));
  78.     until (inchr = ^Q);
  79.   end. { Display_Keys }
  80.  
  81.