Category : C++ Source Code
Archive   : C_ALL.ZIP
Filename : TI865.ASC

 
Output of file : TI865.ASC contained in archive : C_ALL.ZIP







PRODUCT : C++ NUMBER : 865
VERSION : All
OS : WIN
DATE : August 12, 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
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
#include

extern WORD far _B000H;

void far * GetMDARamPtr()













PRODUCT : C++ NUMBER : 865
VERSION : All
OS : WIN
DATE : August 12, 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
#include

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 : August 12, 1992 PAGE : 3/3

TITLE : Using Windows Exported Selectors




MessageBox(NULL, szBuff, "Video Mode",
MB_TASKMODAL | MB_YESNO) == IDYES)

return(TRUE);
}

DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.









































  3 Responses to “Category : C++ Source Code
Archive   : C_ALL.ZIP
Filename : TI865.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/