home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / wint1_92 / dpmi / windpmi.pas < prev    next >
Pascal/Delphi Source File  |  1991-12-23  |  4KB  |  147 lines

  1. {*********************************************************}
  2. {*                   WINDPMI.PAS 1.00                    *}
  3. {*        Copyright (c) TurboPower Software 1991.        *}
  4. {*                 All rights reserved.                  *}
  5. {*********************************************************}
  6. {$S-,R-}
  7.  
  8. unit WinDPMI;
  9.   {-Windows 3.x/TPW interface to DPMI services}
  10.  
  11. interface
  12.  
  13. uses
  14.   WinTypes,
  15.   WinProcs;
  16.  
  17. type
  18.   SegOfs =                   {structure of a pointer}
  19.    record
  20.       Ofst, Segm : Word;
  21.     end;
  22.   DoubleWord
  23.     = record
  24.         LoWord  : Word;
  25.         HiWord  : Word;
  26.       end;
  27.   DPMIRegisters =
  28.     record
  29.       drDI : LongInt;
  30.       drSI : LongInt;
  31.       drBP : LongInt;
  32.       drReserved : LongInt;
  33.       drBX : LongInt;
  34.       drDX : LongInt;
  35.       drCX : LongInt;
  36.       drAX : LongInt;
  37.       drFlags : Word;
  38.       drES : Word;
  39.       drDS : Word;
  40.       drFS : Word;
  41.       drGS : Word;
  42.       drIP : Word;
  43.       drCS : Word;
  44.       drSP : Word;
  45.       drSS : Word;
  46.     end;
  47.  
  48. function InRealMode : Boolean;
  49.   {-Returns true if Windows is operating in real mode.}
  50.  
  51. function SimulateRealModeInt(IntNo : Byte; StackWords : Word;
  52.                              var Regs : DPMIRegisters) : Word;
  53.   {-Simulates a real mode interrupt. Copies the values from the record Regs
  54.     into the physical registers. StackWords specifies the number of bytes to
  55.     copy from the protected mode to the real mode stack. Returns 0 for success
  56.     or DPMI error code.}
  57.  
  58. procedure AllocateRealModeCallbackAddr(CallbackProc : Pointer;
  59.                                       var Regs : DPMIRegisters;
  60.                                       var Callback : Pointer);
  61.   {-Allocates a real mode callback. Ensure that Regs refers to a variable that
  62.     will remain static until FreeRealModeCallBack is called. Returns the real
  63.     mode callback address in CallBack. CallbackProc specifies a protected mode
  64.     procedure to be called from the real mode callback. See DPMI
  65.     specifications for more info on the protected mode procedure. Returns Nil
  66.     in CallBack if unable to allocate a real mode callback.}
  67.  
  68. function FreeRealModeCallbackAddr(P : Pointer) : Word;
  69.   {-Frees a real mode callback previously allocated with
  70.     AllocateRealModeCallbackAddr.}
  71.  
  72. procedure GetRealModeIntVector(IntNo : Byte; var Vector : Pointer);
  73.   {-Returns the value of an interrupt vector (like GetIntVec).}
  74.  
  75. function GetCPUFlags : Byte;
  76.   {-A little routine to return the current state of the CPU flags.}
  77.  
  78. implementation
  79.  
  80.  
  81.   function SimulateRealModeInt(IntNo : Byte; StackWords : Word;
  82.                                var Regs : DPMIRegisters) : Word; Assembler;
  83.   asm
  84.     xor     bx,bx
  85.     mov     bl,IntNo
  86.     mov     cx,StackWords
  87.     les     di,Regs
  88.     mov     ax,0300h
  89.     int     31h
  90.     jc      @@ExitPoint
  91.     xor     ax,ax
  92.   @@ExitPoint:
  93.   end;
  94.  
  95.   function GetCPUFlags : Byte; Assembler;
  96.   asm
  97.     lahf
  98.     mov     al,ah
  99.   end;
  100.  
  101.   function InRealMode : Boolean;
  102.   begin
  103.     InRealMode := GetWinFlags and wf_PMode = 0;
  104.   end;
  105.  
  106.   procedure AllocateRealModeCallbackAddr(CallbackProc : Pointer;
  107.                                         var Regs : DPMIRegisters;
  108.                                         var Callback : Pointer); Assembler;
  109.   asm
  110.     push    ds
  111.     lds     si,CallbackProc
  112.     les     di,Regs
  113.     mov     ax,0303h
  114.     int     31h
  115.     jnc     @@Exitpoint
  116.     xor     cx,cx
  117.     xor     dx,dx
  118.   @@ExitPoint:
  119.     les     di,Callback
  120.     mov     word ptr es:[di],dx
  121.     mov     word ptr es:[di+2],cx
  122.     pop     ds
  123.   end;
  124.  
  125.   function FreeRealModeCallbackAddr(P : Pointer) : Word; Assembler;
  126.   asm
  127.     mov     cx,word ptr P+2
  128.     mov     dx,word ptr P
  129.     mov     ax,0304h
  130.     int     31h
  131.     jc      @@ExitPoint
  132.     xor     ax,ax
  133.   @@ExitPoint:
  134.   end;
  135.  
  136.   procedure GetRealModeIntVector(IntNo : Byte; var Vector : Pointer); Assembler;
  137.   asm
  138.     mov     ax,0200h
  139.     mov     bl,IntNo
  140.     int     31h
  141.     les     di,Vector
  142.     mov     word ptr es:[di],dx
  143.     mov     word ptr es:[di+2],cx
  144.   end;
  145.  
  146. end.
  147.