📄 pgdos32q.gml
字号:
ES = GetDS()
EDI = loc(MemInfo)
call fintr( interrupt_no, regs)
.code break
* Report the information returned by the DPMI host
print *,'------------------------------------------'
print *,'Largest available block (in bytes): ',
& Meminfo.LargestBlockAvail
print *,'Maximum unlocked page allocation: ',
& MemInfo.MaxUnlockedPage
print *,'Pages that can be allocated and locked: ',
& MemInfo.LargestLockablePage
print *,'Total linear address space including' //
& ' allocated pages:', MemInfo.LinAddrSpace
print *,'Number of free pages available: ',
& MemInfo.NumFreePagesAvail
print *,'Number of physical pages not in use: ',
& MemInfo.NumPhysicalPagesFree
print *,'Total physical pages managed by host: ',
& MemInfo.TotalPhysicalPages
print *,'Free linear address space (pages): ',
& MemInfo.FreeLinAddrSpace
print *,'Size of paging/file partition (pages): ',
& MemInfo.SizeOfPageFile
end
.code end
.do end
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.*
.beglevel
.section Getting Free Memory Information under DOS/4GW
.*
.np
.ix 'free memory' 'using DOS/4GW'
DOS/4GW provides a DPMI interface through interrupt 0x31.
This allows you to use DPMI service 0x0500 to get free memory
information.
The following program illustrates this procedure.
.millust begin
/*
MEMORY.C - This example shows how to get information
about free memory using DPMI call 0500h under DOS/4GW.
Note that only the first field of the structure is
guaranteed to contain a valid value; any field that
is not returned by DOS/4GW is set to -1 (0FFFFFFFFh).
Compile & Link: wcl386 -l=dos4g memory
*/
#include <i86.h>
#include <dos.h>
#include <stdio.h>
#define DPMI_INT 0x31
.millust break
struct meminfo {
unsigned LargestBlockAvail;
unsigned MaxUnlockedPage;
unsigned LargestLockablePage;
unsigned LinAddrSpace;
unsigned NumFreePagesAvail;
unsigned NumPhysicalPagesFree;
unsigned TotalPhysicalPages;
unsigned FreeLinAddrSpace;
unsigned SizeOfPageFile;
unsigned Reserved[3];
} MemInfo;
.millust break
void main()
{
union REGS regs;
struct SREGS sregs;
regs.x.eax = 0x00000500;
memset( &sregs, 0, sizeof(sregs) );
sregs.es = FP_SEG( &MemInfo );
regs.x.edi = FP_OFF( &MemInfo );
.millust break
int386x( DPMI_INT, ®s, ®s, &sregs );
printf( "Largest available block (in bytes): %lu\n",
MemInfo.LargestBlockAvail );
printf( "Maximum unlocked page allocation: %lu\n",
MemInfo.MaxUnlockedPage );
printf( "Pages that can be allocated and locked: "
"%lu\n", MemInfo.LargestLockablePage );
printf( "Total linear address space including "
"allocated pages: %lu\n",
MemInfo.LinAddrSpace );
printf( "Number of free pages available: %lu\n",
MemInfo.NumFreePagesAvail );
printf( "Number of physical pages not in use: %lu\n",
MemInfo.NumPhysicalPagesFree );
printf( "Total physical pages managed by host: %lu\n",
MemInfo.TotalPhysicalPages );
printf( "Free linear address space (pages): %lu\n",
MemInfo.FreeLinAddrSpace );
printf( "Size of paging/file partition (pages): %lu\n",
MemInfo.SizeOfPageFile );
}
.millust end
.np
.ix 'INT 31H'
Please refer to the chapter entitled :HDREF refid='int31'. for more
information on DPMI services.
.*
.section Getting Free Memory Information under the Phar Lap 386|DOS-Extender
.*
.np
.ix 'free memory' 'using Phar Lap'
Phar Lap provides memory statistics through 386|DOS-Extender System
Call 0x2520.
The following example illustrates how to use this system call from a
32-bit program.
.millust begin
/*
MEMPLS40.C - This is an example of how to get the
amount of physical memory present under Phar Lap
386|DOS-Extender v4.0.
Compile & Link: wcl386 -l=pharlap MEMPLS40
*/
#include <dos.h>
#include <stdio.h>
typedef struct {
unsigned data[25];
} pharlap_mem_status;
.millust break
/* Names suggested in Phar Lap documentation */
#define APHYSPG 5
#define SYSPHYSPG 7
#define NFREEPG 21
.millust break
unsigned long memavail( void )
{
pharlap_mem_status status;
union REGS regs;
unsigned long amount;
.millust break
regs.h.ah = 0x25;
regs.h.al = 0x20;
regs.h.bl = 0;
regs.x.edx = (unsigned int) &status;
intdos( ®s, ®s );
/* equation is given in description for nfreepg */
amount = status.data[ APHYSPG ];
amount += status.data[ SYSPHYSPG ];
amount += status.data[ NFREEPG ];
return( amount * 4096 );
}
.millust break
void main()
{
printf( "%lu bytes of memory available\n",
memavail() );
}
.millust end
.np
Please refer to the chapter entitled "386|DOS-Extender System Calls"
in Phar Lap's
.book 386|DOS-Extender Reference Manual
for more information on 386|DOS-Extender System Calls.
.*
.section Getting Free Memory Information in the 32-bit Environment under Windows 3.x
.*
.np
.ix 'free memory' 'using Windows 3.x'
Windows 3.x provides a DPMI host that you can access from a 32-bit
program.
The interface to this host is a 16-bit interface, hence there are some
considerations involved when calling Windows 3.x DPMI services from
32-bit code.
If a pointer to a data buffer is required to be passed in ES:DI, for
example, an AllocAlias16() may be used to get a 16-bit far pointer
that can be passed to Windows 3.x through these registers.
Also, an int86() call should be issued rather than an int386() call.
The following program demonstrates the techniques mentioned above.
.millust begin
/*
MEMWIN.C - This example shows how to get information
about free memory with DPMI call 0x0500 using Windows
as a DPMI host. Note that only the first field of the
structure is guaranteed to contain a valid value; any
field that is not returned by the DPMI implementation
is set to -1 (0FFFFFFFFh).
Compile & Link: wcl386 -l=win386 -zw memwin
Bind: wbind -n memwin
*/
#include <windows.h>
#include <i86.h>
#include <dos.h>
#include <stdio.h>
.millust break
struct meminfo {
unsigned LargestBlockAvail;
unsigned MaxUnlockedPage;
unsigned LargestLockablePage;
unsigned LinAddrSpace;
unsigned NumFreePagesAvail;
unsigned NumPhysicalPagesFree;
unsigned TotalPhysicalPages;
unsigned FreeLinAddrSpace;
unsigned SizeOfPageFile;
unsigned Reserved[3];
} MemInfo;
#define DPMI_INT 0x31
.millust break
void main()
{
union REGS regs;
struct SREGS sregs;
DWORD mi_16;
regs.w.ax = 0x0500;
mi_16 = AllocAlias16( &MemInfo );
sregs.es = HIWORD( mi_16 );
regs.x.di = LOWORD( mi_16 );
.millust break
int86x( DPMI_INT, ®s, ®s, &sregs );
printf( "Largest available block (in bytes): %lu\n",
MemInfo.LargestBlockAvail );
printf( "Maximum unlocked page allocation: %lu\n",
MemInfo.MaxUnlockedPage );
printf( "Pages that can be allocated and locked: "
"%lu\n", MemInfo.LargestLockablePage );
printf( "Total linear address space including "
"allocated pages: %lu\n",
MemInfo.LinAddrSpace );
printf( "Number of free pages available: %lu\n",
MemInfo.NumFreePagesAvail );
printf( "Number of physical pages not in use: %lu\n",
MemInfo.NumPhysicalPagesFree );
printf( "Total physical pages managed by host: %lu\n",
MemInfo.TotalPhysicalPages );
printf( "Free linear address space (pages): %lu\n",
MemInfo.FreeLinAddrSpace );
printf( "Size of paging/file partition (pages): %lu\n",
MemInfo.SizeOfPageFile );
FreeAlias16( mi_16 );
}
.millust end
.np
.ix 'DPMI specification'
Please refer to the
.book DOS Protected-Mode Interface (DPMI) Specification
for information on DPMI services.
In the past, the DPMI specification could be obtained free of charge
by contacting Intel Literature JP26 at 800-548-4725 or by writing
to the address below.
We have been advised that the DPMI specification is no longer
available in printed form.
.illust begin
Intel Literature JP26
3065 Bowers Avenue
P.O. Box 58065
Santa Clara, California
U.S.A. 95051-8065
.illust end
.np
However, the DPMI 1.0 specification can be obtained from the Intel ftp
site.
Here is the URL.
.code begin
ftp://ftp.intel.com/pub/IAL/software_specs/dpmiv1.zip
.code end
.pc
This ZIP file contains a Postscript version of the DPMI 1.0 specification.
.*
.endlevel
.do end
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.*
.section How do I access the first megabyte in the extended DOS environment?
.*
.np
.ix 'DOS memory'
.ix 'real-mode memory'
Many programmers require access to the first megabyte of memory in
order to look at key low memory addresses.
Under DOS, it was standard practice to use a far pointer, with the far
pointer set to the segmented address of the memory area that was being
inspected.
Under DOS extenders, this practice is not so standard.
Each DOS extender provides its own method for accessing the first
megabyte of memory.
.*
.beglevel
.*
.section Accessing the First Megabyte under Tenberry Software DOS/4GW
.*
.np
.ix 'DOS memory' 'using DOS/4GW'
.ix 'real-mode memory' 'using DOS/4GW'
Under DOS/4GW, the first megabyte of physical memory - the real memory
- is mapped as a shared linear address space.
This allows your application to access the first megabyte of memory
using a near pointer set to the linear address.
The following program demonstrates this method.
This example is similar to the screen memory access example.
.millust begin
/*
KEYSTAT.C - This example shows how to get the keyboard
status under DOS/4GW by looking at the ROM BIOS
keyboard status byte in low memory.
Compile & Link: wcl386 -l=dos4g keystat
*/
#include <stdio.h>
#include <dos.h>
.millust break
/*
Under DOS, the keyboard status byte has a segmented
address of 0x0040:0x0017. This corresponds to a
linear address of 0x417.
*/
#define LOW_AREA 0x417
.millust break
void main()
{
/* Only need a near pointer in the flat model */
char *ptr;
/* Set pointer to linear address of the first
status byte */
ptr = (char *)LOW_AREA;
.millust break
/* Caps lock state is in bit 6 */
if( *ptr & 0x40 ) {
puts( "Caps Lock on" );
}
.millust break
/* Num lock state is in bit 5 */
if( *ptr & 0x20 ) {
puts( "Num Lock on" );
}
.millust break
/* Scroll lock state is in bit 4 */
if( *ptr & 0x10 ) {
puts( "Scroll Lock on" );
}
}
.millust end
.np
Please refer to the chapter entitled :HDREF refid='linexe'. for more
information on how DOS/4GW maps the first megabyte.
.*
.section Accessing the First Megabyte under the Phar Lap 386|DOS-Extender
.*
.np
.ix 'DOS memory' 'using Phar Lap'
.ix 'real-mode memory' 'using Phar Lap'
The Phar Lap DOS extender provides access to real memory through the
special segment selector 0x34.
This allows far pointer access to the first megabyte from a 32-bit
program.
The following example illustrates this technique.
.millust begin
/*
KEYSTAPL.C - This example shows how to get the keyboard
status under 386|DOS-Extender by looking at the ROM
BIOS keyboard status byte in low memory.
Compile & Link: wcl386 -l=pharlap keystapl
*/
#include <stdio.h>
#include <dos.h>
.millust break
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -