home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 October
/
VPR9710A.ISO
/
BENCH
/
DJ1SRC_K
/
105
/
XMS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-02
|
3KB
|
124 lines
/*
** xms.c -- C bindings for xms API - implemented
** Author: Kent Williams william@umaxc.weeg.uiowa.edu
*/
/* 1997/05/01 modified by Kimio Itoh(kitoh@nn.iij4u.or.jp)
for reduce binary size and for dead code elimination.
*/
#pragma inline
#include <stdio.h>
#include <stdlib.h>
#include "xms.h"
static void far xms_spoof(void);
static void (far * xms_entry) (void) = xms_spoof;
int xms_installed(void)
{
asm mov ax, 0x4300; /* get installation status */
asm int 0x2f; /* call driver */
asm mov ah, 1; /* return true if present */
asm cmp al, 0x80; /* are you there? */
asm je __present;
asm xor ax, ax; /* no, return false */
__present:
asm xchg ah, al; /* if present, set ax to 1 */
asm cbw;
}
static void xms_get_entry(void)
{
asm mov ax, 0x4310; /* get driver entry */
asm int 0x2f; /* call multiplex */
asm mov word ptr xms_entry, bx;
asm mov word ptr(xms_entry + 2), es;
}
static void far xms_spoof(void)
{
asm push ax bx cx dx si di es ds;
if (!xms_installed()) {
fprintf(stderr, "No XMS driver installed\n");
exit(1);
} else
xms_get_entry();
asm pop ds es di si dx cx bx ax;
xms_entry();
}
xms_extended_info *xms_query_extended_memory(void)
{
unsigned max_free_block, total_extended_memory;
static xms_extended_info x;
asm mov ah, 0x8;
asm call[xms_entry];
asm mov max_free_block, ax;
asm mov total_extended_memory, dx;
x.max_free_block = max_free_block;
x.total_extended_memory = total_extended_memory;
return &x;
}
int xms_local_enable_a20(void)
{
asm mov ah, 0x5;
asm call[xms_entry];
asm neg ax;
asm inc ax;
}
int xms_local_disable_a20(void)
{
asm mov ah, 0x6;
asm call[xms_entry];
asm neg ax;
asm inc ax;
}
int xms_emb_allocate(emb_size_K_t siz)
{
asm mov ah, 0x9;
asm mov dx, siz;
asm call[xms_entry];
asm or ax, ax; /* allocation succeed? */
asm jz alloc_failed; /* no, return 0 */
asm xchg ax, dx; /* yes, return handle */
asm jmp done;
alloc_failed:
asm not ax;
done:
}
int xms_emb_free(emb_handle_t handle)
{
asm mov ah, 0x0a;
asm mov dx, handle;
asm call[xms_entry];
asm neg ax;
asm inc ax;
}
emb_off_t xms_lock_emb(emb_handle_t handle)
{
asm mov ah, 0x0c;
asm mov dx, handle;
asm call[xms_entry];
asm or ax, ax;
asm je lock_failed;
asm mov ax, bx; /* return value in dx:ax */
asm jmp lock_done;
lock_failed:
asm mov dx, ax;
lock_done:
}
int xms_unlock_emb(emb_handle_t handle)
{
asm mov ah, 0x0d;
asm mov dx, handle;
asm call[xms_entry];
asm neg ax;
asm inc ax;
}