home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP12 / 32BIT.CPP next >
C/C++ Source or Header  |  1995-10-12  |  2KB  |  65 lines

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