Category : C Source Code
Archive   : XPMALLOC.ZIP
Filename : XPMDEMO.C
Output of file : XPMDEMO.C contained in archive : XPMALLOC.ZIP
** This source is provided as an example of how to use the functions in
** XPMALLOC.LIB. There are several functions in this source that begin
** with "ss"(). They are responsible for displaying the text that describes
** the Expanded Memory system. They serve no other function.
**
** Complete function descriptions are given in XPMANUAL.DOC.
****************************************************************************/
/*
** Externs used for DEMO program only
*/
extern void ssLogo(void);
extern void ssInstr(void);
extern void ssInstr2(void);
extern void ssInstr3(void);
extern void ssInstr4(void);
extern void ssInstr5(void);
extern void ssInstr6(void);
extern void ssInstr7(void);
extern void ssInstr8(void);
#include
#include
#include
#include
#include
#include "xpmalloc.h"
typXPMINFO xpmInfo; /* System info structure */
/*
** Allocate 3 arrays of different data type.
** Each 16K large. Int, Long, Float.
** Accept user input and display data
*/
int allocMultArrays()
{
long i;
int err;
long j;
long memAvail,arraySize;
long intSize,longSize,floatSize;
int numOfArrays;
char arrayInput[20];
char indexInput[20];
float floatVal;
long longVal;
int intVal;
int arrayIndex;
int valueIndex;
char ch;
typXPMALLOC *intArray;
typXPMALLOC *longArray;
typXPMALLOC *floatArray;
setCursor(11,26);
printf("Press any key to Begin...");
getch();
setCursor(11,25);
printf(" ");
/*
** Check if available expanded memory for 32K arrays
*/
if (xpmInfo.pagesAvail < 3) /* need 3 pages for 16K arrays */
memAvail = xpmInfo.pagesAvail * 16383;
else
memAvail = 49149;
/*
** Calculate array size
*/
arraySize = (memAvail / 3);
/*
** Total array sizes are limited to arraySize
** therefore, number of items = arraySize / sizeof(data type)
*/
intSize = arraySize / sizeof(int);
longSize = arraySize / sizeof(long);
floatSize = arraySize / sizeof(float);
/*
** Allocate EXPANDED MEMORY integer array
*/
setCursor(6,3);
printf("Allocating integer array...");
intArray = (typXPMALLOC *)xpmalloc(intSize,(long)sizeof(int),&err);
if ( intArray == (typXPMALLOC *)NULL )
return(err);
/*
** Fill array with data - starting at 0
*/
printf("Filling integer array with %ld items...",intSize);
for (i=0;i
xpmPutInt(intArray,i,(int)(i % 16383));
}
printf("DONE");
/*
** Allocate EXPANDED MEMORY long int array
*/
setCursor(7,3);
printf("Allocating long array...");
longArray = (typXPMALLOC *)xpmalloc(longSize,(long)sizeof(long),&err);
if ( longArray == (typXPMALLOC *)NULL )
return(err);
/*
** Fill array with data - starting at 0
*/
printf("Filling long array with %ld items...",longSize);
for (i=0;i
xpmPutLong(longArray,i,i);
}
printf("DONE");
/*
** Allocate EXPANDED MEMORY float array
*/
setCursor(8,3);
printf("Allocating float array...");
floatArray = (typXPMALLOC *)xpmalloc(floatSize,(long)sizeof(float),&err);
if ( floatArray == (typXPMALLOC *)NULL )
return(err);
/*
** Fill array with data - starting at 0.0
*/
printf("Filling float array with %ld items...",floatSize);
for (i=0;i
xpmPutFloat(floatArray,i,(i*1.) );
}
printf("DONE");
/*
** After arrays are allocated and filled
** let user input array index and display data.
*/
setCursor(10,10);
printf("1 - Int | 2 - Long | 3 - Float");
for (;;)
{
/*
** Get array index from user
*/
strcpy(arrayInput,"");
while (!strcmp(arrayInput,""))
{
setCursor(13,10);
printf("Enter array number [1,2,3,q=quit]: ");
gets(arrayInput);
if (!strcmp(arrayInput,"q"))
break;
arrayIndex = atoi(arrayInput);
if (arrayIndex > 3 || arrayIndex < 1)
{
setCursor(13,44);
printf(" ");
strcpy(arrayInput,"");
}
}
if (!strcmp(arrayInput,"q")) /* Quit */
break;
/*
** Get value index from user
*/
strcpy(indexInput,"");
while (!strcmp(indexInput,""))
{
setCursor(14,10);
printf("Enter array index : ");
gets(indexInput);
valueIndex = atoi(indexInput);
if (valueIndex < 0)
{
setCursor(14,29);
printf(" ");
strcpy(indexInput,"");
}
}
/*
** Clear input lines
*/
setCursor(13,44);
printf(" ");
setCursor(14,29);
printf(" ");
/*
** "Get" data and display
*/
switch (arrayIndex)
{
case 1:
err = xpmGetInt(intArray,(long)valueIndex,&intVal);
if (err == -3)
{
setCursor(16,10);
printf("Index out of range - Press any key");
getch();
setCursor(16,10);
printf(" ");
}
else
if (!err)
{
setCursor(15,10);
printf("Integer Array value = %d ",intVal);
}
break;
case 2:
err = xpmGetLong(longArray,(long)valueIndex,&longVal);
if (err == -3)
{
setCursor(16,10);
printf("Index out of range - Press any key");
getch();
setCursor(16,10);
printf(" ");
}
else
if (!err)
{
setCursor(15,10);
printf("Long Array value = %ld ",longVal);
}
break;
case 3:
err = xpmGetFloat(floatArray,(long)valueIndex,&floatVal);
if (err == -3)
{
setCursor(16,10);
printf("Index out of range - Press any key");
getch();
setCursor(16,10);
printf(" ");
}
else
if (!err)
{
setCursor(15,10);
printf("Float Array value = %f ",floatVal);
}
break;
}
}
/*
** Free expanded memory used for demo arrays
*/
xpmFree(intArray);
xpmFree(longArray);
xpmFree(floatArray);
return(0);
}
/*
** Allocate 1 array of type long.
** 81K large.
** Accept user input and display data
*/
int allocSingleArray()
{
long i;
int err;
long memAvail,arraySize;
long longSize;
char indexInput[20];
long longVal;
int valueIndex;
char ch;
typXPMALLOC *longArray;
setCursor(11,26);
printf("Press any key to Begin...");
getch();
setCursor(11,25);
printf(" ");
/*
** Check if available expanded memory for 96K array
*/
if (xpmInfo.pagesAvail < 5) /* need 5 pages for 81K array */
memAvail = xpmInfo.pagesAvail * 16383;
else
memAvail = 81915;
/*
** Calculate array size
*/
arraySize = memAvail;
/*
** Number of items = arraySize / sizeof(data type)
*/
longSize = arraySize / sizeof(long);
/*
** Allocate EXPANDED MEMORY long int array
*/
setCursor(7,3);
printf("Allocating long array...");
longArray = (typXPMALLOC *)xpmalloc(longSize,(long)sizeof(long),&err);
if ( longArray == (typXPMALLOC *)NULL )
return(err);
/*
** Fill array with data - starting at 0
*/
printf("Filling long array with %ld items...",longSize);
for (i=0;i
xpmPutLong(longArray,i,i);
}
printf("DONE");
/*
** "Get" data and display
*/
for (;;)
{
/*
** Get value index from user
*/
strcpy(indexInput,"");
while (!strcmp(indexInput,""))
{
setCursor(14,10);
printf("Enter array index [q=quit]: ");
gets(indexInput);
if (!strcmp(indexInput,"q"))
break;
valueIndex = atoi(indexInput);
if (valueIndex < 0)
{
setCursor(14,38);
printf(" ");
strcpy(indexInput,"");
}
}
if (!strcmp(indexInput,"q"))
break;
/*
** Clear input lines
*/
setCursor(14,38);
printf(" ");
err = xpmGetLong(longArray,(long)valueIndex,&longVal);
if (err == -3)
{
setCursor(16,10);
printf("Index out of range - Press any key");
getch();
setCursor(16,10);
printf(" ");
}
else
if (!err)
{
setCursor(15,10);
printf("Long Array value = %ld ",longVal);
}
}
return(0);
}
main()
{
register i;
int index;
int err;
int numOfArrays;
typXPMALLOC *screenStr;
typXPMALLOC *border;
/*
** Initialize Expanded Memory System
*/
err = xpmInit(&xpmInfo);
if (err)
{
printf("Init error [%d]\n",err);
printf("< Return condition: %s >\n",xpmInfo.errText);
xpmFreeAll();
exit(err);
}
/*
** Allocate expanded memory for screens
*/
screenStr = (typXPMALLOC *)xpmalloc(4000L,(long)sizeof(char),&err);
if ( screenStr == (typXPMALLOC *)NULL )
{
printf("xpMalloc failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
border = (typXPMALLOC *)xpmalloc(4000L,(long)sizeof(char),&err);
if ( border == (typXPMALLOC *)NULL )
{
printf("xpMalloc failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
clrScr();
ssLogo();
/*
** Save Main Logo screen
*/
err = saveScreen(screenStr);
if (err)
{
printf("save failed...[%x]\n",err);
xpmFreeAll();
exit(-1);
}
setCursor(19,25);
printf("Press any key to begin DEMO...");
getch();
clrScr();
drawBorder(2,2,22,76);
/*
** Save border screen
*/
err = saveScreen(border);
if (err)
{
printf("save border failed...[%x]\n",err);
xpmFreeAll();
exit(-1);
}
ssInstr();
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%x]\n",err);
xpmFreeAll();
exit(-1);
}
ssInstr2();
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%x]\n",err);
xpmFreeAll();
exit(-1);
}
ssInstr3();
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
ssInstr4();
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
ssInstr5();
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
/*
** Display system information returned
** from xpmInit()
*/
setCursor(3,4);
printf("SYSTEM INFORMATION");
setCursor(4,4);
printf("ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß");
setCursor(7,4);
printf("Expanded Memory Version: %s",xpmInfo.versionString);
setCursor(8,6);
printf("Total Number of Pages: %d",xpmInfo.pageCount);
setCursor(9,12);
printf("Available Pages: %d",xpmInfo.pagesAvail);
setCursor(10,17);
printf("Page Frame: %p",xpmInfo.pageFrame);
setCursor(11,5);
printf("Number of open handles: %d",xpmInfo.openHandles);
setCursor(6,40);
printf("List of Mappable addresses:");
for (i=0;i
setCursor(8+i,45);
printf("Page#: %d => Address: %X",xpmInfo.mapAddress[i].pageNum,
xpmInfo.mapAddress[i].pageSeg);
}
setCursor(21,25);
printf("Press any key to continue...");
getch();
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
ssInstr6();
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
/*
** Allocate 3 - 16K arrays
*/
setCursor(3,4);
printf("ALLOCATE 3 - 16K ARRAYS - THREE PAGES");
setCursor(4,4);
printf("ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß");
err = allocMultArrays();
if (err)
{
printf("allocMultArrays() failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
/*
** Allocate 1 - 81K array
*/
setCursor(3,4);
printf("ALLOCATE 1 - 81K ARRAY - FIVE PAGES");
setCursor(4,4);
printf("ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß");
err = allocSingleArray();
if (err)
{
printf("allocSingleArray() failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
ssInstr7();
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
ssInstr8();
/*
** restore border
*/
err = restoreScreen(border);
if (err)
{
printf("restore border failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
setCursor(13,25);
printf("** BECOME A REGISTERED USER **");
setCursor(21,26);
printf("Press any key to continue...");
getch();
/*
** restore main logo screen
*/
err = restoreScreen(screenStr);
if (err)
{
printf("restore failed...[%d]\n",err);
xpmFreeAll();
exit(-1);
}
/*
** Release expanded memory for future use
*/
xpmFreeAll();
setCursor(19,37);
printf("THE END");
setCursor(23,0);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/