X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fexmm%2Fxmem.c;h=d5e7d549e6c95fb42a189ea87e885fba7043a9b6;hb=d0908679d03eacbbbd67420ae2daa6a01f0a0bcc;hp=ff15d1ec614029f6395e223b6fa6b23f8f03e51a;hpb=d3f8280463ec0bc9aede20aa5a2c38d8f0bd0fd7;p=16.git diff --git a/src/lib/exmm/xmem.c b/src/lib/exmm/xmem.c old mode 100644 new mode 100755 index ff15d1ec..d5e7d549 --- a/src/lib/exmm/xmem.c +++ b/src/lib/exmm/xmem.c @@ -1,57 +1,62 @@ - /* - - Copyright 1994 Alec Russell, ALL rights reserved - Permission granted to use as you wish. - + Written by Alexander J. Russell 1994 + + Placed in the public Domain by Alec Russell, March 1995 + Slightly higher level xms calls than xmem.asm - + */ - + #include #include #include #include - -#include - + +#include "src\lib\exmm\xmem.h" + xms_head_t xms_head={0}; // set handle to zero - - + + /* ---------------------- alloc_xms() ----------------- February 19,1994 */ short alloc_xms(unsigned short far *size) // size in 16k blocks { return(XMS_alloc(0, size)); } - + + + /* ---------------------- xms_to_mem() ---------------- February 19,1994 */ -short xms_to_mem(unsigned short handle, void far *p, unsigned long off, unsigned short n) +short xms_to_mem(unsigned short handle, void far *p, unsigned long off, +unsigned short n) { unsigned short block, boff; - + block=off >> XMSBLOCKSHIFT; boff=off - (block << XMSBLOCKSHIFT); - + return(XMStoMem(handle, block, boff, n, p)); } - + + /* ---------------------- mem_to_xms() ---------------- February 19,1994 */ -short mem_to_xms(unsigned short handle, void far *p, unsigned long off, unsigned short n) +short mem_to_xms(unsigned short handle, void far *p, unsigned long off, +unsigned short n) { unsigned short block, boff; - + block=off >> XMSBLOCKSHIFT; boff=off - (block << XMSBLOCKSHIFT); - + return(MemToXMS(handle, block, boff, n, p)); } - + + /* ---------------------- qalloc_xms() -------------------- March 8,1994 */ xms_node_t *qalloc_xms(unsigned long size) { xms_node_t *node=NULL; xms_node_t *t1; - + if ( size <= xms_head.avail ) { // look for existing node @@ -68,7 +73,7 @@ xms_node_t *qalloc_xms(unsigned long size) else t1=t1->next; } - + if ( node == NULL ) // didn't find existing node { node=malloc(sizeof(xms_node_t)); @@ -94,39 +99,43 @@ xms_node_t *qalloc_xms(unsigned long size) } } else - pr2("out of near mem in qalloc_xms"); + printf("out of near mem in qalloc_xms"); } } else - pr2("out of xms mem in qalloc size %lu avail %lu", size, xms_head.avail); - + printf("out of xms mem in qalloc size %lu avail %lu", size, +xms_head.avail); + return(node); } - + + /* ---------------------- qfree_xms() --------------------- March 8,1994 */ void qfree_xms(xms_node_t *node) { xms_node_t *t1; - + if ( xms_head.next ) { t1=xms_head.next; while ( t1 != node && t1 ) t1=t1->next; - + if ( t1 ) { t1->used=0; } else - pr2("ERROR didn't find node qfree"); + printf("ERROR didn't find node qfree"); } else { - pr2("ATTEMPTED to qfree empty list"); + printf("ATTEMPTED to qfree empty list"); } } - + + + /* ---------------------- xms_open() ---------------------- March 8,1994 */ xms_node_t *xms_open(char *file) { @@ -135,7 +144,7 @@ xms_node_t *xms_open(char *file) FILE *fp; char *buffer; unsigned long off; - + fp=fopen(file, "rb"); if ( fp ) { @@ -148,68 +157,73 @@ xms_node_t *xms_open(char *file) off=0l; while ( (i=fread(buffer, 1, 4096, fp)) ) { - mem_to_xms(xms_head.handle, (char far *)buffer, off+node->start, i); + mem_to_xms(xms_head.handle, (char far *)buffer, +off+node->start, i); off+=i; } - + free(buffer); } else - pr2("out of mem in xms_open 1"); + printf("out of mem in xms_open 1"); } - + fclose(fp); } else - pr2("ERROR opening %s in xms_open", file); - + printf("ERROR opening %s in xms_open", file); + return(node); } - + + /* ---------------------- xms_read() ---------------------- March 8,1994 */ short xms_read(void far *buffer, unsigned short n, xms_node_t *node) { - + if ( node->off >= node->size ) return 0; - + if ( n+node->off > node->size ) n=node->size - node->off; - + xms_to_mem(xms_head.handle, buffer, node->start+node->off, n); node->off+=n; - + return(n); } - + + /* ---------------------- xms_write() ---------------------- March 8,1994 */ short xms_write(void far *buffer, unsigned short n, xms_node_t *node) { - + if ( node->off >= node->size ) return 0; - + if ( n+node->off > node->size ) n=node->size - node->off; - + mem_to_xms(xms_head.handle, buffer, node->start+node->off, n); node->off+=n; - + return(n); } - - + + /* ---------------------- xms_tell() ---------------------- March 8,1994 */ long xms_tell(xms_node_t *node) { return node->off; } - + + + /* ---------------------- xms_seek() ---------------------- March 8,1994 */ short xms_seek(xms_node_t *node, long off, short whence) { short err=0; - + switch ( whence ) { case SEEK_SET: @@ -218,14 +232,14 @@ short xms_seek(xms_node_t *node, long off, short whence) else node->off=off; break; - + case SEEK_END: if ( off > 0l || (node->size + off) < 0l ) err=1; else node->off=node->size + off; break; - + case SEEK_CUR: if ( node->off + off < 0l || node->off + off > node->size ) err=1; @@ -233,28 +247,32 @@ short xms_seek(xms_node_t *node, long off, short whence) node->off+=off; break; } - + return(err); } - + + /* ---------------------- xms_close() --------------------- March 8,1994 */ void xms_close(xms_node_t *node) { qfree_xms(node); } - + + + + /* ---------------------- init_xms() ---------------------- March 8,1994 */ short init_xms(unsigned short min_blocks) { unsigned short blocks; - + blocks=XMSblk_available(); if ( blocks >= min_blocks ) { memset(&xms_head, 0, sizeof(xms_head_t)); if ( (xms_head.handle=alloc_xms(&blocks)) ) { - pr2("blocks minus by = %u", blocks); + printf("blocks minus by = %u", blocks); min_blocks-=blocks; xms_head.avail=xms_head.total=(unsigned long)min_blocks*XMSBLOCK; blocks=min_blocks; @@ -264,15 +282,16 @@ short init_xms(unsigned short min_blocks) } else blocks=0; - + return(blocks); } - + + /* ---------------------- deinit_xms() -------------------- March 8,1994 */ void deinit_xms(void) { xms_node_t *t1, *t2; - + if ( xms_head.handle ) { XMS_dealloc(xms_head.handle); @@ -287,28 +306,31 @@ void deinit_xms(void) t2=t1->next; } } - + memset(&xms_head, 0, sizeof(xms_head_t)); } } + + + /* --------------------------- end of file ------------------------- */ -/* - -Not sure how to use this? - -call init_xms(x) to allocate a big chunk of xms. -x is in 'blocks' of 16Kb. Pick X big enough to buffer all the files -you want to place in xms. - -call xms_open("filename); for each file to be buffered. This copies the file -int xms. - -then use xms_read(), xms_write(), and xms_seek() to read the file from -xms instead of disk. - -call deinit_xms() just before exit to clean up. - -You can also use the lower level calls directly. - +/* + +Not sure how to use this? + +call init_xms(x) to allocate a big chunk of xms. +x is in 'blocks' of 16Kb. Pick X big enough to buffer all the files +you want to place in xms. + +call xms_open("filename); for each file to be buffered. This copies the file +int xms. + +then use xms_read(), xms_write(), and xms_seek() to read the file from +xms instead of disk. + +call deinit_xms() just before exit to clean up. + +You can also use the lower level calls directly. + */