home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP08 / 32BIT.CPP next >
Encoding:
C/C++ Source or Header  |  1995-10-20  |  1.5 KB  |  62 lines

  1. // A set of functions to handle real-mode addresses in 32-bit mode.
  2.  
  3. #include <Dos.h>
  4. #include <Conio.h>
  5.  
  6. unsigned int BaseDs = 0u;
  7.  
  8. int InitDPMI(void)
  9.   {
  10.   REGS Register;
  11.   // Do not proceed if BaseDs has already been initialized
  12.   if (BaseDs == 0)
  13.      {
  14.      // Get the base linear address for DS.
  15.      Register.w.bx = _DS;
  16.      Register.w.ax = 0x0006;
  17.      int386(0x31, &Register, &Register);
  18.      // If we encounter an error, return zero
  19.      if (Register.x.cflag)
  20.         return 0;
  21.      // Multiply by 65,536 and mask out un-wanted bits
  22.      BaseDs = ((unsigned int)(Register.w.cx) << 16) | Register.w.dx;
  23.  
  24.      Register.w.bx = _DS;
  25.      Register.w.ax = 0x0008;
  26.      Register.w.cx = Register.w.dx = 0xFFFF;
  27.      int386(0x31, &Register, &Register);
  28.      return !Register.x.cflag;
  29.      }
  30.   else
  31.       return 1;
  32.   }
  33.  
  34. // Call this one to get a real-mode address  
  35. unsigned int GetAddress(unsigned int RMLocation)
  36.    {
  37.    if ((BaseDs == 0) && (InitDPMI() == 0))
  38.       return 0;
  39.    return (RMLocation - BaseDs);
  40.    }
  41.  
  42. // Call this one to get a real-mode address   
  43. // Don't call this one without calling InitDPMI
  44. unsigned int ConvertAddress(unsigned int Address)
  45.    {
  46.    return Address - BaseDs;
  47.    }
  48.  
  49. // Function returns video address   
  50. unsigned char *VideoAddress ()
  51.    {
  52.    return (unsigned char *)GetAddress(0xA0000UL);
  53.    }
  54.    
  55. void SetVideo (short int mode)
  56.    {
  57.    REGS regs;
  58.     regs.w.ax = mode;
  59.     regs.h.ah = 0;
  60.     int386(0x10, ®s, ®s);
  61.    }
  62.