home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / MADTRB38.ZIP / INTRDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-02-08  |  3.3 KB  |  88 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 INTR.PAS for details. }
  12.  
  13. {$I STD-ATTR.INC}
  14.  
  15.   const INTR_KEY     = #120; { Alt-1 }
  16.         INTR_VECTOR  = $80;  { Identifies the interupt being utilized. }
  17.         ZERO         = 0;
  18.         NULL_CHR     = #0;
  19.         ESC          = #27;
  20.  
  21.   type RegPack  = record
  22.                     case Boolean of
  23.                       TRUE  : (ax,bx,cx,dx,bp,si,di,ds,es,flags : Integer);
  24.                       FALSE : (al,ah,bl,bh,clo,chi,dl,dh        : Byte);
  25.                   end;
  26.  
  27.   var inchr,inctl  : Char;
  28.  
  29.   procedure Intr_80;
  30.     var regs       : RegPack;
  31.         xpos, ypos : Byte;
  32.  
  33.     begin
  34.       FillChar(regs,SizeOf(regs),ZERO);
  35.  
  36. (*The following statements store the address of the first global variable
  37.   in the interrupt vector table at the table position following the actual
  38.   interrupt being used. By doing this you provide a means by which the
  39.   interrupt routine can locate global variables used by the calling program.
  40.   Since all of my programs begin with {$I STD-ATTR.INC} the first variable
  41.   declared is always vid_attr. *)
  42.  
  43.       with regs do
  44.       begin
  45.         ah := $25; al := INTR_VECTOR + 1; ds := Dseg; dx := Ofs(vid_attr);
  46.       end; {with}
  47.       MsDos(regs);
  48.  
  49.       Intr($80,regs);       { Activate the interrupt handler at INTR_VECTOR }
  50.     end; { Intr_80 }
  51.  
  52.    procedure Read_Kbd(var inchr,inctl: Char);
  53.      var regs     : RegPack;
  54.  
  55.       begin
  56.         inctl := NULL_CHR;                 { Initialize inctl to NULL_CHR.  }
  57.         with regs do
  58.         begin
  59.           ax := ZERO;                      { ah = 0 for read next kbd char.   }
  60.           Intr($16,regs);                  { Call keyboard interrupt routine. }
  61.           inchr := Chr(al);                { Convert result to Char.          }
  62.           if (inchr = #0) then             { If function/special key pressed  }
  63.             begin                          { get scan code and handle         }
  64.               if (Chr(ah) = INTR_KEY) then { interrupt if INTR_KEY pressed.   }
  65.                 Intr_80;
  66.               inctl := Chr(ah)             { Put scan code in inctl.  }
  67.             end
  68.           else                                 { Otherwise trap conventional }
  69.             if (inchr in [#1..#31,#127]) then  { control codes as scan codes.}
  70.               inctl := inchr;
  71.         end; {with}
  72.       end; { Read_Kbd }
  73.  
  74.   begin { Display_Keys }
  75.     ClrScr;
  76.     WriteLn('Press a key to display its ASCII code or IBM scan code.');
  77.     WriteLn('Press <Alt><1> to activate interrupt $80');
  78.     WriteLn('Press <Esc> to QUIT');
  79.     repeat
  80.       Read_Kbd(inchr,inctl);
  81.       if (inchr > #0) then
  82.         WriteLn('The ASCII code for ',inchr,' is ',Ord(inchr));
  83.       if (inctl > #0) and (inchr = #0) then
  84.         WriteLn('The scan code for  ',inchr,' is ',Ord(inctl));
  85.     until (inchr = ESC);
  86.   end. { Display_Keys }
  87.  
  88.