From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: biosmemory() problem Date: Fri, 21 Nov 1997 18:56:36 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 88 Message-ID: <3475D964.1519@cs.com> References: <34748F7F DOT 13DA AT ra DOT msstate DOT edu> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp226.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Greg Moorer wrote: > > whenever I try to compile code with the biosmemory() function, djgpp > simply locks up...no error messages or anything. Has anyone else run > into this problem? For some reason, biosmemory() does not appear to work the way it should in all cases. I don't know if this problem is being looked at, nor do I know what the cause is; I don't understand DPMI all _that_ well. However, this little code snippet should return the amount of installed memory on your system, in kilobytes, with an upper limit of 64 MB. At that point, it wraps around to zero, and you can use various tricks to figure out how much you really have. A couple of notes: - The CMOS value wraps around at 64 MB. If the computer has more than this installed, the only way to find the correct value is to compare the value the CMOS reports to the free physical memory reported by _go32_dpmi_remaining_physical_memory(). If the latter is greater, then you must add 64 MB to the value obtained. I haven't tested this 100%, but it should work. - The value reported will not include memory used for ROM shadowing. On most computers, this amount is around 300 KB. In order to prevent the user from thinking he has less memory than he really does, I round the value up to the nearest megabyte. You can do this or not depending on the level of accuracy you need. - It has been suggested that certain OS's, such as Windows/NT, may report less memory than is actually installed on the system. I have never had a report of this actually happening, but be aware that it could. In any event, it should always report at least 16 MB, if the system actually has that much. #include #include #include static void usec_sleep ( int usec ); static unsigned char read_cmos ( int reg ); int installed_memory_size ( void ); /* * Routines to return the amount of physical memory installed on the host * computer. Thanks to Eli Zaretskii for this code. */ static void usec_sleep( int usec ) { uclock_t start_time = uclock (); uclock_t end_time = start_time + UMAX(1, usec * UCLOCKS_PER_SEC / 1000000); while ( uclock () < end_time ) ; } static unsigned char read_cmos( int reg ) { unsigned char al = ( reg & 0xff ) | 0x80; /* disable NMI */ outportb( 0x70, al ); usec_sleep( 2 ); /* delay for 2 microseconds */ al = inportb( 0x71 ); usec_sleep( 2 ); outportb( 0x70, 0 ); /* enable NMI */ return al; } int installed_memory_size( void ) { unsigned base_lo, base_hi, ext_lo, ext_hi; base_lo = read_cmos( 0x15 ); base_hi = read_cmos( 0x16 ); ext_lo = read_cmos( 0x17 ); ext_hi = read_cmos( 0x18 ); return ( (base_hi + ext_hi) << 8 ) + base_lo + ext_lo; } -- --------------------------------------------------------------------- | John M. Aldrich |"A competent and self-confident person| | aka Fighteer I | is incapable of jealousy in anything.| | mailto:fighteer AT cs DOT com | Jealousy is invariably a symptom of | | http://www.cs.com/fighteer | neurotic insecurity." - Lazarus Long| ---------------------------------------------------------------------