Back to my Tips and Tricks page
Here is the DJGPP version. Scroll down for the Visual C++ version.

/*
Copyright 1998 by Phil Frisbie, Jr.  phil@hawksoft.com

This reads the memory sizes that the BIOS determines at boot,
and stores in the Real Time Clock (RTC). This is small and
simple, but it took me several hours to find this on the 'net.

This code adapted to DJGPP DOS from Free-BSD.

You are free to use and modify this code, and feel free to
let me know what you think of it.
*/

#include 

#define RTC_BASELO      0x15    /* low byte of basemem size */
#define RTC_BASEHI      0x16    /* high byte of basemem size */
#define RTC_EXTLO       0x17    /* low byte of extended mem size */
#define RTC_EXTHI       0x18    /* high byte of extended mem size */


unsigned long rtcin(char data)
{
	outportb(0x70, data);
	return inportb(0x71);
}

void main(void)
{
	unsigned long biosbasemem, biosextmem;


	biosbasemem = rtcin(RTC_BASELO) + (rtcin(RTC_BASEHI)<<8);
	biosextmem = rtcin(RTC_EXTLO)+ (rtcin(RTC_EXTHI)<<8);

	printf("BIOS reports %U KB of base memory\n",biosbasemem);
	printf("BIOS reports %U KB of extended memory\n",biosextmem);
/*
Note: we add 384k to the total to compensate for the shadow ram
that is used by most motherboards
*/
	printf("BIOS reports %U MB of system memory total\n",(biosextmem + biosbasemem + 384)>>10);
}


Here is the Visual C++ version. This code compiles as a console application.
It has been tested on Windows 95, and should work on Windows 3.1 also.
I DOES NOT work on Windows NT as a console app, however, if you are writing a
device driver or service for Windows NT, this code should work.

/*
Copyright 1998 by Phil Frisbie, Jr.  phil@hawksoft.com

This reads the memory sizes that the BIOS determines at boot,
and stores in the Real Time Clock (RTC). This is small and
simple, but it took me several hours to find this on the 'net.

This code adapted to Visual C++ from Free-BSD.

You are free to use and modify this code, and feel free to
let me know what you think of it.
*/

#include 
#include 

#define RTC_BASELO      0x15    /* low byte of basemem size */
#define RTC_BASEHI      0x16    /* high byte of basemem size */
#define RTC_EXTLO       0x17    /* low byte of extended mem size */
#define RTC_EXTHI       0x18    /* high byte of extended mem size */


unsigned long rtcin(char data)
{
        _outp(0x70, data);
        return _inp(0x71);
}

void main(void)
{
        unsigned long biosbasemem, biosextmem;


        biosbasemem = rtcin(RTC_BASELO) + (rtcin(RTC_BASEHI)<<8);
        biosextmem = rtcin(RTC_EXTLO)+ (rtcin(RTC_EXTHI)<<8);

        printf("BIOS reports %u KB of base memory\n",biosbasemem);
        printf("BIOS reports %u KB of extended memory\n",biosextmem);
/*
Note: we add 384k to the total to compensate for the shadow ram
that is used by most motherboards
*/
        printf("BIOS reports %u MB of system memory total\n",(biosextmem + biosbasemem + 384)>>10);
}
Back to my Tips and Tricks page

This page hosted by GeoCities Get your own Free Home Page


1