home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Audio 4.94 - Over 11,000 Files
/
audio-11000.iso
/
msdos
/
sndbords
/
proaudio
/
pcmtlsrc
/
pcmtlsrc.arj
/
LOADPCM.ARJ
/
XMS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-10
|
9KB
|
430 lines
; /*\
; |*| $Author: BCRANE $
; |*|
; |*| $Date: 29 Jul 1992 16:58:20 $
; |*|
; |*| $Header: W:/sccs/sdkapp/xms.c_v 1.0 29 Jul 1992 16:58:20 BCRANE $
; |*|
; |*| $Log: W:/sccs/sdkapp/xms.c_v $
*
* Rev 1.0 29 Jul 1992 16:58:20 BCRANE
* Initial revision.
; |*|
; |*| $Logfile: W:/sccs/sdkapp/xms.c_v $
; |*|
; |*| $Modtimes$
; |*|
; |*| $Revision: 1.0 $
; |*|
; |*| $Workfile: xms.c $
; |*|
; \*/
/* Copyright (c) 1992. Media Vision, Inc. All Rights Reserved. */
#include <stdio.h>
#include <dos.h>
#define OKAY 0
static char *copyright= "Copyright (c) 1992. Media Vision, Inc. All Rights Reserved.";
static char *programmer= "Bart Crane";
/* XMS Internal Variables */
static int (far * xmsdriver)(); /* holds address of XMS driver function */
static unsigned int xmsversion; /* set during initxms() */
static unsigned int xmsdriverversion; /* set during initxms() */
static unsigned int hmaexists; /* set during initxms */
static unsigned char lastxmserror; /* cleared/set during each function call */
/* XMS Functions */
/* initxms() - test for existence of XMS driver, and initialize internals */
/* return 1 if XMS driver exists */
/* return 0 if no XMS driver */
/* if driver exists, retrieves address of XMS driver function and */
/* obtains version information. */
int initxms()
{
int status;
lastxmserror= 0;
_asm
{
mov ax, 4300h
int 2Fh
cmp al, 80h
mov ax, 0
jnz nodriver
inc ax
nodriver:
mov status, ax
}
if (status)
{
unsigned int segxmsdriver;
unsigned int offxmsdriver;
_asm
{
mov ax, 4310h
int 2Fh
mov offxmsdriver, bx
mov bx, es
mov segxmsdriver, bx
}
FP_SEG(xmsdriver)= segxmsdriver;
FP_OFF(xmsdriver)= offxmsdriver;
_asm
{
mov ah, 0
mov bx, seg xmsdriver
mov es, bx
mov bx, offset xmsdriver
call dword ptr es:[bx]
mov xmsversion, ax
mov xmsdriverversion, bx
mov hmaexists, dx
}
}
return(status);
}
/* getxmsversion() - get version of XMS and driver */
/* returns BCD values in DX:AX */
/* AX= XMS version */
/* DX= driver internal revision */
unsigned long getxmsversion()
{
return(xmsversion| ((unsigned long) xmsdriverversion<< 16));
}
/* havehma() - determine if HMA exists */
/* return 1 if HMA exists */
/* return 0 if no HMA */
int havehma()
{
return(hmaexists);
}
/* getxmserror() - format a string explaining last error */
/* references static variable which is set during each xms function */
/* message guaranteed to be no longer than 80 characters including null */
/* lastxmserror is a byte value from 0x80 on up, so the 0x80 is masked off */
/* making the byte value range from 0x00 on up, which is then used to */
/* index into the xmserror[] array. */
/* return nonzero (the index value) if an error happened. */
/* return 0 if no error occurred. */
static char *unknownerror= "Unknown error";
#define MAXXMSERRORS 0x34+ 1
static char *xmserror[]=
{
"Function completed successfully", /* 0 */
"XMS function not implemented", /* 0x80 */
"VDISK device detected", /* 0x81 */
"A20 error occurred", /* 0x82 */
NULL, /* 0x83 */
NULL, /* 0x84 */
NULL, /* 0x85 */
NULL, /* 0x86 */
NULL, /* 0x87 */
NULL, /* 0x88 */
NULL, /* 0x89 */
NULL, /* 0x8A */
NULL, /* 0x8B */
NULL, /* 0x8C */
NULL, /* 0x8D */
NULL, /* 0x8E */
NULL, /* 0x8F */
"HMA does not exist", /* 0x90 */
"HMA already in use", /* 0x91 */
"Requested HMA size less than /HMAMIN", /* 0x92 */
"HMA not allocated", /* 0x93 */
"A20 line still enabled", /* 0x94 */
NULL, /* 0x95 */
NULL, /* 0x96 */
NULL, /* 0x97 */
NULL, /* 0x98 */
NULL, /* 0x99 */
NULL, /* 0x9A */
NULL, /* 0x9B */
NULL, /* 0x9C */
NULL, /* 0x9D */
NULL, /* 0x9E */
NULL, /* 0x9F */
"All XMS memory already allocated", /* 0xA0 */
"All XMS handles already in use", /* 0xA1 */
"Invalid XMS handle", /* 0xA2 */
"Invalid source XMS handle", /* 0xA3 */
"Invalid source offset", /* 0xA4 */
"Invalid target XMS handle", /* 0xA5 */
"Invalid target offset", /* 0xA6 */
"Invalid length", /* 0xA7 */
"Invalid overlap", /* 0xA8 */
"Parity error occurred", /* 0xA9 */
"Block not locked", /* 0xAA */
"Block locked", /* 0xAB */
"Block lock count overflowed", /* 0xAC */
"Lock failed", /* 0xAD */
NULL, /* 0xAE */
NULL, /* 0xAF */
"Smaller UMB is available", /* 0xB0 */
"No UMB available", /* 0xB1 */
"UMB segment number invalid", /* 0xB2 */
NULL /* 0xB3 MAXXMSERRORS */
};
int getxmserror(char *buf)
{
unsigned int msg;
if (lastxmserror& 0x80)
{
msg= (unsigned int) (lastxmserror& 0x7F)+ 1;
if (msg > MAXXMSERRORS)
msg= MAXXMSERRORS;
if (buf)
if (xmserror[msg])
sprintf(buf, "%s", xmserror[msg]);
else
sprintf(buf, "%s", unknownerror);
return(msg);
}
return(OKAY);
}
unsigned long getxmsmemstat()
{
unsigned int largestxmsblock;
unsigned int totalxmsavailable;
lastxmserror= 0;
_asm
{
mov ah, 8
mov bx, seg xmsdriver
mov es, bx
mov bx, offset xmsdriver
call dword ptr es:[bx]
test bl, 80h
jz gotsome
xor bh, bh
mov lastxmserror, bx
xor ax, ax
mov dx, ax
jmp short memcheckdone
gotsome:
mov largestxmsblock, ax
mov totalxmsavailable, dx
memcheckdone:
}
return(largestxmsblock| ((unsigned long) totalxmsavailable<< 16));
}
unsigned int allocxms(unsigned int kbsize)
{
unsigned int xmshandle= 0;
lastxmserror= 0;
_asm
{
mov ah, 9
mov dx, kbsize
or dx, dx
jz whybother
mov bx, seg xmsdriver
mov es, bx
mov bx, offset xmsdriver
call dword ptr es:[bx]
or ax, ax
jnz gotmem
xor bh, bh
mov lastxmserror, bx
jmp short whybother
gotmem:
mov xmshandle, dx
whybother:
}
return(xmshandle);
}
unsigned int reallocxms(unsigned int xmshandle, unsigned int kbsize)
{
unsigned int retval= 0;
lastxmserror= 0;
_asm
{
mov ah, 0Fh
mov bx, kbsize
or bx, bx
jz whybother
mov dx, xmshandle
or dx, dx
jz whybother
mov bx, seg xmsdriver
mov es, bx
mov bx, offset xmsdriver
call dword ptr es:[bx]
or ax, ax
jnz regotmem
xor bh, bh
mov lastxmserror, bx
jmp short whybother
regotmem:
mov retval, 1
whybother:
}
return(retval);
}
unsigned long getembstatus(unsigned int xmshandle)
{
unsigned int emblockcount= 0;
unsigned int embkbsize= 0;
lastxmserror= 0;
_asm
{
mov ah, 0Eh
mov dx, xmshandle
mov bx, seg xmsdriver
mov es, bx
mov bx, offset xmsdriver
call dword ptr es:[bx]
or ax, ax
jnz gotembstatus
xor bh, bh
mov lastxmserror, bx
jmp short embstatusdone
gotembstatus:
mov al, bh
cbw
mov emblockcount, ax
mov embkbsize, dx
embstatusdone:
}
return(emblockcount| ((unsigned long) embkbsize<< 16));
}
unsigned long getxmsfreehandles(unsigned int xmshandle)
{
unsigned int embfreehandles= 0;
lastxmserror= 0;
_asm
{
mov ah, 0Eh
mov dx, xmshandle
mov bx, seg xmsdriver
mov es, bx
mov bx, offset xmsdriver
call dword ptr es:[bx]
or ax, ax
jnz gotembhandles
xor bh, bh
mov lastxmserror, bx
jmp short embhandlesdone
gotembhandles:
mov al, bl
cbw
mov embfreehandles, ax
embhandlesdone:
}
return(embfreehandles);
}
xmsmovemem(struct xmsmoves far *emm)
{
unsigned int segemm= FP_SEG(emm);
unsigned int offemm= FP_OFF(emm);
lastxmserror= 0;
_asm
{
push si
push ds
mov si, segemm
mov ds, si
mov si, offemm
mov ah, 0Bh
mov bx, seg xmsdriver
mov es, bx
mov bx, offset xmsdriver
call dword ptr es:[bx]
or ax, ax
jnz mademove
xor bh, bh
mov lastxmserror, bx
mademove:
pop ds
pop si
}
return(!lastxmserror);
}
freexms(unsigned int xmshandle)
{
lastxmserror= 0;
_asm
{
mov ah, 0Ah
mov dx, xmshandle
mov bx, seg xmsdriver
mov es, bx
mov bx, offset xmsdriver
call dword ptr es:[bx]
or ax, ax
jnz freedmem
xor bh, bx
mov lastxmserror, bx
freedmem:
}
return(!lastxmserror);
}