home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / DDJ9403A.ZIP / ASPI.ZIP / DPMI.C < prev    next >
C/C++ Source or Header  |  1993-11-11  |  2KB  |  92 lines

  1. // ----------------------------------------------------------------------
  2. // Module DPMI.C
  3. // DLL routine for DPMI access to ASPI driver.
  4. //
  5. // Copyright (C) 1993, Brian Sawert.
  6. // All rights reserved.
  7. //
  8. // Notes:
  9. //    Compile with MEDIUM model for DLL.
  10. //    Compiling as DLL defines __DLL__ and defines _FAR as far.
  11. //
  12. // ----------------------------------------------------------------------
  13.  
  14. #include <windows.h>
  15. #include <mem.h>
  16. #include "aspi.h"                        // ASPI definitions and constants
  17.  
  18.  
  19. // -------------------- defines and macros --------------------
  20.  
  21. #define DPMI_INT    0x31                // DPMI interrupt number
  22. #define REAL_CALL    0x301                // real mode call function
  23.  
  24. typedef struct RealCall
  25.     {                                    // struct for real mode call
  26.     DWORD edi, esi, ebp, reserved, ebx, edx, ecx, eax;
  27.     WORD flags, es, ds, fs, gs, ip, cs, sp, ss;
  28.     } RealCall_t ;
  29.  
  30.  
  31. // -------------------- global variables -------------------
  32.  
  33. // -------------------- external variables -------------------
  34.  
  35.  
  36. // ----------------------------------------------------------------------
  37. // Call ASPI manager through DPMI server.
  38. //
  39. // Usage:    int AspiCall(void far *aspiproc, aspi_req_t far *ar);
  40. //
  41. // Returns 1 on success, 0 otherwise.
  42. // ----------------------------------------------------------------------
  43.  
  44. int AspiCall(void far *aspiproc, aspi_req_t far *ar)
  45.     {
  46.     RealCall_t rcs;                        // real mode call struct
  47.  
  48.     int retval = 0;
  49.     int npush;
  50.     void far *sptr;
  51.  
  52.     memset(&rcs, 0, sizeof(RealCall_t));    // clear call structure
  53.  
  54.     rcs.cs = HIWORD(aspiproc);            // point to real mode proc
  55.     rcs.ip = LOWORD(aspiproc);
  56.  
  57.     npush = sizeof(aspi_req_t far *) / sizeof(WORD);
  58.                                         // words to pass on stack
  59.     sptr = (void far *) &rcs;            // far pointer to call structure
  60.  
  61.     asm {
  62.         push di                            // save registers
  63.         push es
  64.  
  65.         sub bx, bx                        // don't reset A20 line
  66.         mov cx, npush;                    // number of words to copy to stack
  67.         les di, sptr                    // point ES:DI to call structure
  68.  
  69.         mov ax, REAL_CALL                // load function number
  70.  
  71.         push WORD PTR [ar + 2]            // push SRB address
  72.         push WORD PTR [ar]
  73.  
  74.         int DPMI_INT                    // call DPMI server
  75.  
  76.         pop ax                            // restore stack count
  77.         pop ax
  78.  
  79.         pop es                            // restore registers
  80.         pop di
  81.  
  82.         jc asm_exit                        // DPMI error
  83.  
  84.         mov retval, 1                    // return 1 for success
  85.         }
  86.  
  87.     asm_exit:
  88.  
  89.  
  90.     return(retval);
  91.     }
  92.