home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
c_all592.arj
/
TI865.ASC
< prev
next >
Wrap
Text File
|
1992-04-16
|
5KB
|
199 lines
PRODUCT : C++ NUMBER : 865
VERSION : All
OS : WIN
DATE : April 16, 1992 PAGE : 1/3
TITLE : Using Windows Exported Selectors
To allow access to various physical memory locations containing
information related to the system setup or hardware devices,
versions 3.x of Microsoft Windows exports several selectors (the
selectors are more specifically exported by the KERNEL module of
Windows). The exported selectors include the following:
Selector Base Description
======== ====== ==========================================
__0000H 00000H Real Mode Interrupt Vector Table
__0040H 00400H BIOS DATA AREA
__A000H A0000H EGA/VGA Graphics RAM
__B000H B0000H MDA RAM - Hercules Graphics RAM
__B800H B8000H CGA/EGA/VGA RAM
__C000H C0000H EGA/VGA BIOS - HD Adapt BIOS ROM
__D000H D0000H Miscellaneous
__E000H E0000H Miscellaneous
__F000H F0000H System/BIOS ROM
To access the physical memory using the KERNEL Exported Selectors
from your Borland/Turbo C/C++ Windows Applications, the following
approach may be used:
(1) Declare an extern far variable ( of type WORD )
corresponding to one or more of the selectors listed
above. For example:
#include <windows.h>
extern WORD far _B000H; // KERNEL's MDA Selector
NOTE: Since the Borland C/C++ Compiler automatically
inserts a leading underscore the extern variable
has only one underscore.
(2) Declare a far pointer whose segment is initialized with
the LOWORD of the address of the external variable
mentioned in section (1) above. For example:
#include <windows.h>
#include <dos.h>
extern WORD far _B000H;
void far * GetMDARamPtr()
PRODUCT : C++ NUMBER : 865
VERSION : All
OS : WIN
DATE : April 16, 1992 PAGE : 2/3
TITLE : Using Windows Exported Selectors
{
void *lpMDA = MK_FP(LOWORD(&_B000H), 0x0000);
return(lpMDA);
}
The far pointer obtained from section (2) can be used to access
the physical memory from a Windows Application. Since the
selectors are exported by Windows KERNEL module, the IMPORT
library (IMPORT.LIB) provided with Borland C++/Turbo C++ for
Windows contains a reference to the selectors hence enabling the
linker to resolve the external variable defined in section (1).
The selectors (and far pointers) must be used with caution since
the Windows 3.0 does not enable any protection attributes on the
selectors exported by Kernel.
The following code provides an example of the technique described
above. The current "Video Mode" is read from the BIOS Data Area
(@0040:0049) using the _0040H selector and displayed using the
Windows API function MessageBox.
/* *********************************************************** */
/* Using Windows Exported Selectors Example */
/* *********************************************************** */
#include <windows.h>
#include <dos.h>
extern WORD far _0040H; // Kernel Selector: BIOS Data Area
extern WORD far _B000H; // Kernel Selector: MDA Video RAM
int PASCAL WinMain(HANDLE hInst, HANDLE hPrev, LPSTR CmdLine,
int nCmdShow)
{
char szBuff[80], cVideoMode;
char far *lpBDARam = (char far *)MK_FP(LOWORD(&_0040H), 0);
cVideoMode = *(lpBDARam + 0x49); // Video Mode: 0040:0049
wsprintf(szBuff, "Video Mode ( _0040H:0049H): 0%Xh (%d)\n"
"Use __B000H to write mode to Mono Screen?",
cVideoMode, cVideoMode);
PRODUCT : C++ NUMBER : 865
VERSION : All
OS : WIN
DATE : April 16, 1992 PAGE : 3/3
TITLE : Using Windows Exported Selectors
MessageBox(NULL, szBuff, "Video Mode",
MB_TASKMODAL | MB_YESNO) == IDYES)
return(TRUE);
}