home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bc3.zip / REALPROC.CPP < prev    next >
C/C++ Source or Header  |  1992-02-12  |  2KB  |  65 lines

  1. //
  2. // (c) Copyright 1992, Qualitas, Inc. All Rights Reserved
  3. //
  4. // realproc.h - member functions for RealProcedure class
  5. //
  6. #include <dos.h>
  7. #include "realproc.h"
  8. #define RPStackSize 512
  9.  
  10. //
  11. // Constructor
  12. //
  13. RealProcedure::RealProcedure(void far *function, int nArgBytes)
  14. {
  15.     uLong codeBase;
  16.     uLong dataBase;
  17.  
  18.     DPMIGetSegmentBase(theCodeSel, &codeBase);
  19.     DPMIGetSegmentBase(theDataSel, &dataBase);
  20.  
  21.     argSize = (nArgBytes+1) & ~1;
  22.  
  23.     dRegs.drFlags = 0x3202;
  24.     dRegs.drIP = FP_OFF(function);
  25.     dRegs.drCS = codeBase >> 4;
  26.     dRegs.drDS = dRegs.drSS = dRegs.drES = dataBase >> 4;
  27. }
  28.  
  29. //
  30. // Call operator - this member automatically invokes the DPMI service
  31. // for calling real procedures. The argument size is given when the
  32. // object is constructed.  This member returns a reference to RealProcedure,
  33. // which can be casted to extract desired values from the real mode
  34. // call structure.  Note: because there is only one real mode call structure
  35. // per RealProcedure, a RealProcedure is not reentrant.
  36. // 
  37. RealProcedure& RealProcedure::operator()(...)
  38. {
  39.     uChar RealProcedureStack[RPStackSize];
  40.     int nArgBytes = argSize;
  41.     dpmiRegs_t far *dRegsPtr=(dpmiRegs_t far *)MK_FP(theDataSel, &dRegs);
  42.     dRegs.drSP = (uShort)&RealProcedureStack[RPStackSize];
  43.     
  44.     _asm lea    bx, [bp+4]
  45.     _asm mov    cx, nArgBytes
  46.     _asm add    bx, cx
  47.     _asm shr    cx, 1
  48.     _asm jcxz    argsPushed
  49.  
  50. pushArgs:
  51.     _asm push    ss:[bx]
  52.     _asm sub    bx, 2
  53.     _asm loop    pushArgs
  54.  
  55. argsPushed:
  56.     _asm mov    ax, 0301h
  57.     _asm xor    bh, bh
  58.     _asm mov    cx, nArgBytes
  59.     _asm les    di, dRegsPtr
  60.     _asm int    31h
  61.     _asm add    sp, nArgBytes
  62.  
  63.     return *this;
  64. }
  65.