home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / c_all592.arj / TI865.ASC < prev    next >
Text File  |  1992-04-16  |  5KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  C++                                    NUMBER  :  865
  9.   VERSION  :  All
  10.        OS  :  WIN
  11.      DATE  :  April 16, 1992                           PAGE  :  1/3
  12.  
  13.     TITLE  :  Using Windows Exported Selectors
  14.  
  15.  
  16.  
  17.  
  18.   To allow access to various physical memory locations containing
  19.   information related to the system setup or hardware devices,
  20.   versions 3.x of Microsoft Windows exports several selectors (the
  21.   selectors are more specifically exported by the KERNEL module of
  22.   Windows).  The exported selectors include the following:
  23.  
  24.        Selector   Base   Description
  25.        ========  ======  ==========================================
  26.         __0000H  00000H  Real Mode Interrupt Vector Table
  27.         __0040H  00400H  BIOS DATA AREA
  28.         __A000H  A0000H  EGA/VGA Graphics RAM
  29.         __B000H  B0000H  MDA RAM - Hercules Graphics RAM
  30.         __B800H  B8000H  CGA/EGA/VGA RAM
  31.         __C000H  C0000H  EGA/VGA BIOS - HD Adapt BIOS ROM
  32.         __D000H  D0000H  Miscellaneous
  33.         __E000H  E0000H  Miscellaneous
  34.         __F000H  F0000H  System/BIOS ROM
  35.  
  36.   To access the physical memory using the KERNEL Exported Selectors
  37.   from your Borland/Turbo C/C++ Windows Applications, the following
  38.   approach may be used:
  39.  
  40.        (1)  Declare an extern far variable ( of type WORD )
  41.             corresponding to one or more of the selectors listed
  42.             above.  For example:
  43.  
  44.                  #include <windows.h>
  45.                  extern WORD far _B000H;  // KERNEL's MDA Selector
  46.  
  47.             NOTE:  Since the Borland C/C++ Compiler automatically
  48.                    inserts a leading underscore the extern variable
  49.                    has only one underscore.
  50.  
  51.        (2)  Declare a far pointer whose segment is initialized with
  52.             the LOWORD of the address of the external variable
  53.             mentioned in section (1) above.  For example:
  54.  
  55.                  #include <windows.h>
  56.                  #include <dos.h>
  57.  
  58.                  extern WORD far _B000H;
  59.  
  60.                  void far * GetMDARamPtr()
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  C++                                    NUMBER  :  865
  75.   VERSION  :  All
  76.        OS  :  WIN
  77.      DATE  :  April 16, 1992                           PAGE  :  2/3
  78.  
  79.     TITLE  :  Using Windows Exported Selectors
  80.  
  81.  
  82.  
  83.  
  84.                  {
  85.                       void *lpMDA = MK_FP(LOWORD(&_B000H), 0x0000);
  86.                       return(lpMDA);
  87.                  }
  88.  
  89.   The far pointer obtained from section (2) can be used to access
  90.   the physical memory from a Windows Application.  Since the
  91.   selectors are exported by Windows KERNEL module, the IMPORT
  92.   library (IMPORT.LIB) provided with Borland C++/Turbo C++ for
  93.   Windows contains a reference to the selectors hence enabling the
  94.   linker to resolve the external variable defined in section (1).
  95.  
  96.   The selectors (and far pointers) must be used with caution since
  97.   the Windows 3.0 does not enable any protection attributes on the
  98.   selectors exported by Kernel.
  99.  
  100.   The following code provides an example of the technique described
  101.   above.  The current "Video Mode" is read from the BIOS Data Area
  102.   (@0040:0049) using the _0040H selector and displayed using the
  103.   Windows API function MessageBox.
  104.  
  105.   /* *********************************************************** */
  106.   /*   Using Windows Exported Selectors Example                  */
  107.   /* *********************************************************** */
  108.  
  109.   #include <windows.h>
  110.   #include <dos.h>
  111.  
  112.   extern WORD far _0040H;        // Kernel Selector: BIOS Data Area
  113.   extern WORD far _B000H;        // Kernel Selector: MDA Video RAM
  114.  
  115.   int PASCAL WinMain(HANDLE hInst, HANDLE hPrev, LPSTR CmdLine,
  116.        int nCmdShow)
  117.   {
  118.        char szBuff[80], cVideoMode;
  119.        char far *lpBDARam = (char far *)MK_FP(LOWORD(&_0040H), 0);
  120.  
  121.        cVideoMode = *(lpBDARam + 0x49);    // Video Mode: 0040:0049
  122.  
  123.        wsprintf(szBuff, "Video Mode ( _0040H:0049H): 0%Xh (%d)\n"
  124.             "Use __B000H to write mode to Mono Screen?",
  125.             cVideoMode, cVideoMode);
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  C++                                    NUMBER  :  865
  141.   VERSION  :  All
  142.        OS  :  WIN
  143.      DATE  :  April 16, 1992                           PAGE  :  3/3
  144.  
  145.     TITLE  :  Using Windows Exported Selectors
  146.  
  147.  
  148.  
  149.  
  150.        MessageBox(NULL, szBuff, "Video Mode",
  151.             MB_TASKMODAL | MB_YESNO) == IDYES)
  152.  
  153.       return(TRUE);
  154.   }
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.