From 0ac6aa1567e8c251272cd9d52485a1bf9fd32240 Mon Sep 17 00:00:00 2001 From: sparky4 Date: Thu, 12 Feb 2015 15:09:52 -0600 Subject: [PATCH] deleted: src/lib/exmm/EMM.EXE new file: src/lib/exmm/EMM_ALL.TXT new file: src/lib/exmm/XMEM.ALL modified: src/lib/exmm/emm.c modified: src/lib/exmm/memory.c modified: src/lib/exmm/x.bat modified: src/lib/exmm/xmem.c deleted: src/lib/exmm/xmemc.c --- src/lib/exmm/EMM.EXE | Bin 17182 -> 0 bytes src/lib/exmm/EMM_ALL.TXT | 891 +++++++++++++++++++++++++++++ src/lib/exmm/XMEM.ALL | 1140 ++++++++++++++++++++++++++++++++++++++ src/lib/exmm/emm.c | 2 +- src/lib/exmm/memory.c | 41 +- src/lib/exmm/x.bat | 2 +- src/lib/exmm/xmem.c | 186 ++++--- src/lib/exmm/xmemc.c | 316 ----------- 8 files changed, 2157 insertions(+), 421 deletions(-) delete mode 100644 src/lib/exmm/EMM.EXE create mode 100644 src/lib/exmm/EMM_ALL.TXT create mode 100644 src/lib/exmm/XMEM.ALL delete mode 100644 src/lib/exmm/xmemc.c diff --git a/src/lib/exmm/EMM.EXE b/src/lib/exmm/EMM.EXE deleted file mode 100644 index a08435355566ec62c6dcd97d8dc341d0ceb58f08..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17182 zcmeHvkAGCvnfJLfH!~rGAw>*|2&2_e2w)%( zXVIM8WZta1+m&{^)>2*8`dWX`Zh#g-0vSRCNm3yMN+=@U;UdNmC&Ofz`+lEuCn30Y z-~9vL@HxrMx#yhcInVF&Jm)g+iSg2{%*UMU7tAmw%Pg6(htQnN{26WSvU=@|{Tl5s z+UIDO(JUBqJ=%D*`=u_c8|@Q(UN(%eze{24muLsj#$x_tv}3~=dwK+89Bn7spV2O% z6*w4MjdlesWh7%Rw7b#vpglC2G5@WMjs8AkOVFm?!B{2Qf1qtgyZcVY9!4ugJCBw& z5qJaE68wF05@X+>J)OZ=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ATi?Q?Szuq~eEpJ2by>WV=pP zja@7)fjzzHl7>sec*E~_hRq{Mjp7v+GMYEl!vve--prGDdY(jhV-L$O~Phv=L zEG!bXx`R$~p!f8HBoDdSO=ZdIXsIW=q3j9q0CruW)L`n6C$r2cWi(@G|DB1YD4*(c zCcePUhn3e6q@;6FI4ejS)U>xElBIp83 z%RW+e2T@K841mU2C;pD;i|<5nIQx!G{qR`F^tOpd1Q>WSPpDdKMH4?+%&$7}U>SjjMY^KQkJrMe|U1n-F7C1$}tE873;NBV#KFg9o2Jg0Bn ziqaLU*Q|JY&8n#>Y|h%X&cW{~L*KrlvFnSS>wSuI{j<*JSFBsPW>pDhtfCof)~tVK z)k^1l{C5EJR=nWMDp8#GIA2)t+^Q0@W8JDBE6%$IdLAoYv99FV^~GzQD_1BhQrPS@ z>q}NSvCuUD&DXu0%6fD870N2-v#ZzOB{QYi_l)8zURA<8Yu2w&R0-@tDb%C`PD!C(VDgE*1zy#af#w9 zE&K6HKM{0TiXZ%+0E~4ZO-b#VA2`7O`H%EphFZY8Yk!E7*Zx?+*=v6+3~u=U|9qPQ zf|Q6uhWxC?|Li~w|9=G9Nh=#BNyBY&Qc{w|YB=n-*^(tgVv@5Ee3hKP9f9BX--rLX QL2~{Qvn1y^{0|iW7xp9(J^%m! diff --git a/src/lib/exmm/EMM_ALL.TXT b/src/lib/exmm/EMM_ALL.TXT new file mode 100644 index 00000000..9291eb62 --- /dev/null +++ b/src/lib/exmm/EMM_ALL.TXT @@ -0,0 +1,891 @@ +// Author: Chris Somers + +AJR: + This file contains 3 .h files and two .c files, and some notes + all glued together. you'll have to cut them apart to compile. + +// Author: Chris Somers + +To use memory.c, a few notes are in order. This file was originally used +in an event-driven windowing environment, so there are several headers you +won't need (so I didn't include 'em). + +AJR - I nuked all uneeded references from the code + +This code was written for Borland C/C++ v3.1 and has _not_ been tested +under any other version. The first set of conventional memory calls +(those flanked by #ifndef USEBORLIB) are to replace Borland's malloc +library when using 3rd party libraries or APIs which called DOS's malloc. +Add a -DUSEBORLIB to the compile command line to remove this code. + +The file, tasks.h (application specific - not included), optionally +#define'd EMM_SUPPORT and TCPCOM. #define the first and not the second. + +AJR - I modified these sources so this isn't neccessary - all + references to TCPCOM have been deleted. + +Add memory.p to your application to have access to the EMM calls. Don't +include memory.h - it's got static calls and variables you don't want +direct access to. + +AJR - I added memory.p to memory.c, and cleaned up memory.h so it can + be included. + + Please see emm.c for an example. + +returns.h and sizes.h just have the #defines for (duh!) return codes +and size constants. Unfortunately, the values used for some of the +return codes may not be safely changed. If they clash with codes in your +program, it might be safer to rename them than to change their values +and try to see where the EMM code got broken. + +AJR: I renamed returns.h to emmret.h and sizes.h to emmsize.h + to avoid file name clashes. + +Here are some notes on the calls: + +OpenEMM() - call this first, period. +CloseEMM() - call this last. It'll even free any EMS you forgot to free + in your program (this isn't like conventional memory, y'know) +EMMInstalled() - returns TRUE or FALSE. Use only after OpenEMM() is called. +EMMalloc() - returns a pointer to the first EMM page (EMMSeg:0000 hex). + Also stuffs a new handle into *Handle (*Handle == NULL is not + checked for, so be careful or fix the code). You gotta supply + Pages (i.e. number of 16K blocks). +EMMRealloc() - increases/decreases number of pages allocated to your handle. +EMMFree() - frees all the pages and voids the handle. +MapEMM() - places 1 to 4 Pages into the page frame starting with page, Start. +UnmapEMM() - removes the pages from the page frame so nothing else trashes + your data. +UseEMM() - same as MapEMM() but saves the frame state before mapping. +SaveEMM() - same as UnmapEMM() but restores a saved frame state after unmapping. +EMMCoreLeft() - returns the number of bytes of EMM left to allocate. + +The comments in the MapEMM() and UseEMM() (and UnmapEMM() and SaveEMM()) speak +of 'applications' and 'devices'. These refer to layers in the development +environment using this .c file. The application layer could use EMS as long +as it kept track of it's own usage. So it wouldn't have to keep track of the +environment's usage, 'devices' (i.e. lower layers) saved the page frame +state to use EMS themselves, so as not to trash the application layer's data, +and restored the original state upon returning. + + + +More notes: +Alexander J Russell wrote: + +>How do you USE emm memory? +>With xms it is obvious - you copy mem back and forth. +>What the parameters for mapemm() etc... mean isn't documented well enough +>for a newbie to use it. + +EMM is alot like XMS except that the EMM driver does the copying for you, +without really copying (the 386's LDTs are used to point to appropriate +parts of physical memory when mapping EMM). Here's how it works. +EMM has a 64K (typically) page frame in conventional memory, often at +E000-EFFF. The page frame consists of four 16K pages. When you call +EMMalloc(), you supply the number of 16K pages you need and it +returns 1) a handle, and 2) a pointer to the page frame (i.e. E000:0000). +This memory is allocated somewhere in extended memory but still +unavailable. To use it, you must 'map' it into the page frame so +conventional memory pointers can access it. The MapEMM() function +maps the pages you need (up to four) associated with that handle +into the page frame. You can now use your alloc'd memory at E000. +When you're finished accessing the memory, you can unmap it using +UnmapEMM(). This removes the mapping from the page frame so you can +map other allocations or just protect what you've already written +(i.e. writing to the page frame segment won't touch your data). +N.B. You never *have to* unmap your pages. Mapping new pages +automagically unmaps existing mappings - but it's good practice +to unmap when you're finished. + +Another way to look at EMS is to consider the page frame as a window +over the extended memory area. Mapping is like moving the window to +some area of XMS and making it available with a conventional memory +pointer - at the page frame address, which never changes. +In other words, EMS 'bank switches' segments of XMS memory into +conventional memory. + +>I think I call openemm() the use map and unmap to utilize the mem. +>what does map do, what do the parms mean? Once mapped how is the mem used. + +Pretty close. OpenEMM() makes sure the driver is loaded and gets the +page frame address (EMMSeg:0000). Then EMMalloc() reserves the specified +number of 16K pages, associates them to a handle, and gives your app the +page frame address. Then MapEMM() lets you use up to four pages at a time +(at the address returned by EMMalloc()). The parameters for MapEMM() are: +- the handle you got from EMMalloc() +- the memory page # to map to the first page frame page. +- the number of pages to map to the page frame (max. of 4) +BTW, all numbering is zero-based. + +>Could you send a quick overview of how you actually use emm mem in a dos +>program. + + -------------------- see emm.c for example --------------- + + +>Can I re-post your code and notes on my page? +Yup. Leaving my name in the comments at the top would be much appreciated. + +I learnt most of this from DOS Programmer's Reference by Terry Dettmann +from Que publishing (it's (C)1989 and I *still* use it!). You can check out +other references dealing with int67h (the EMS API) too. + +Hope I didn't leave anything out. Email me again if any points aren't clear. + +Chris S. + +AJR adds: + +memory.c, and the h files all you need to use emm! +emm.c is just a test program to show how it is used. + + +/* + ********************************************************************* + ********************************************************************* + + next file + + ********************************************************************* + ********************************************************************* +*/ + +// Cut this out as emmsize.h + +/* File: EmmSize.h + * Module: All Modules + * Author(s): Chris Somers + * Date: May 8, 1992 + * Version: V.1.0 + */ + +#ifndef _EMMSIZES_DEF +#define _EMMSIZES_DEF 1 + + +/* Module size constants */ + +#define MAXACTIONS 29 +#define MAXCHANNELS 4 +#define MAXFOCUS 3 +#define MAXBUFTYPES 64 +#define MAXEMHANDLES 64 /* up to a max of 255 */ +#define MAXTIMERS 32 +#define MAXTITEMS 128 +#define MAXQUEUES 24 +#ifdef PRINTER +#define MAXPRNS 4 +#else +#define MAXPRNS 0 +#endif +#ifdef UTSCOM +#define MAXUTSSCRNS 2 +#else +#define MAXUTSSCRNS 0 +#endif +#ifdef CAPTURE +#define MAXCAPTURE 1 +#else +#define MAXCAPTURE 0 +#endif +#define MAXIRQS 10 +#define MAXTCPDSCPTITEMS 16 /*max # of TCP connections*/ + +#define FREEBUFF 1 /* CallIODevice flag for BuffSize arrays */ +#define DSCONLY 2 /* allocate a BufDscpt, only - no buffer */ + +#define EMMPAGESIZE 0x4000 /* 16K EMM page size */ +#define SETUPLEN 32 +#define NAMELEN 40 +#define UNIXLEN 32 +#define ADDRLEN 16 +#define TITLELEN 128 +#define TSLEN 80 +#define COMMENTLEN 65 +#define PALSIZE 768 +#define QSTRLEN 254 +#define PRNBUFSIZ 2048 +#define TXTSCRNSIZE 4096 +#define UTSBUFSIZ 4096 +#define UTSSCRNSIZ 1920 +#define QMEMSIZE 15 +#define KBUFLEN 16 +#define GXBUFFSIZE 0x4000 +#define TCPNDBUFFSIZE 0x1000 /*router auto-allocation buff size*/ + /* graphics printing scale values */ +#define SCALE_HALF 1 /* value must not change */ +#define SCALE_ONE 2 +#define SCALE_QUART 3 /* value must not change */ + +#define SIXTH_SECOND 3L /* shade over 1/6 of a second*/ +#define HALF_SECOND 9L +#define ONE_SECOND 18L +#define TWO_SECONDS 36L +#define FIVE_SECONDS 91L +#define TEN_SECONDS 182L +#define HALF_MINUTE 182*3L /* same as 18.2*30, right? */ +#define ONE_MINUTE 182*6L /* same as 18.2*60, right? */ +#define TWO_MINUTES 182*12L /* same as 18.2*120, right? */ +#define FIVE_MINUTES 182*30L /* same as 18.2*300, right? */ +#define TEN_MINUTES 182*60L /* same as 18.2*600, right? */ +#define HALF_HOUR 182*180L /* same as 18.2*1800, right? */ +#define ONE_HOUR 182*360L /* same as 18.2*3600, right? */ + +#define MAXROUTMOVES 24 /*max # of routing moves at one time*/ + /*also max # of Move Complete Events*/ +/* Event Channel Defines */ + +#define MAXRECALLEVENTS 1 /*max nm of Recall Event Channels*/ +#define MAXKBDEVENTS 1 /*max nm of Kbd Event Channels*/ +#define MAXPRNEVENTS 4 /*max nm of Prt Prog & Prt Cmplte Event Chan*/ +#define MAXUTSRCVEVENTS MAXUTSSCRNS /*max nm of Uts Rx Event Chans*/ +#define MAXUTSXMTEVENTS MAXUTSSCRNS /*max nm of Uts Tx Event Chans*/ +#define MAXCAPEVENTS 2 /* max number of capture event channels */ +#define MAXOP1CMPLTEVENTS 1 /*max nm of Operation 1 Cmplt Event Channels*/ +#define MAXOP2CMPLTEVENTS 1 /*max nm of Operation 2 Cmplt Event Channels*/ +#define MAXOP3CMPLTEVENTS MAXTCPDSCPTITEMS /*max nm of Op 3 Event Chans*/ +#define MAXTCPEVENTS MAXTCPDSCPTITEMS /* max nm of TCP Event types */ + +#endif + +/* + ********************************************************************* + ********************************************************************* + + next file + + ********************************************************************* + ********************************************************************* +*/ + +// AJR notes: some of these are not used by the emm code + +// Cut this out as emmret.h + +/* File: EmmRet.h + * Module: All Modules + * Author(s): Chris Somers + * Date: May 8, 1992 + * Version: V.1.0 + */ + +#ifndef _EMM_RETURNS_DEF +#define _EMM_RETURNS_DEF 1 + +/* Module return values */ + +/* Return Values */ + +#define START 8 +#define END 7 +#define MOVABORT 6 +#define PRN_COMPLETE 5 +#define PRN_PROGRESS 4 +#define INCOMPLETE 3 +#define HAVEROOM 2 +#define SUCCESS 1 +#define TRUE 1 +#define YES 1 +#define FALSE 0 +#define NO 0 +#define NOTREADY 0 +#define NO_DATA 0 +#define NONE -1 + +/* Start of Recoverable error codes */ + +#define NO_SPACE -1001 +#define NOTPOLLING -1002 +#define ALREADYDONE -1003 +#define NO_PRN_DEV -1004 +#define OUTF_PAPER -1005 +#define NO_VIDEO -1006 +#define TIMEOUT -1007 +#define FILENOPEN -1008 +#define ABORT_REQ -1009 +#define DEV_IOERR -1010 + +#define MAXRERR 10 +#define RECOVERABLE -1999 /* all above errors are recoverable */ + +/* Start of Threadfatal error codes */ + +#define NOT_OPEN -2001 +#define NOT_ATTACHED -2002 +#define NO_CONNECTION -2003 +#define INSUFF_MEM -2004 +#define NR_TIMEOUT -2005 + +#define MAXTERR 5 +#define THREADFATAL -2999 /* above errors force task to cancel */ + +/* Start of Systemfatal error codes */ + +#define BAD_TASKNUM -3001 +#define BAD_HANDLE -3002 +#define BAD_HARDWARE -3003 +#define INVALIDACTION -3004 +#define NOFREEITEMS -3005 +#define NO_MEMORY -3006 +#define NO_EMS -3007 +#define VALUE_OUTF_RANGE -3008 +#define BAD_MODE -3009 +#define NO_PALETTE -3010 +#define BAD_DISPPAGE -3011 +#define NO_TSR -3012 +#define BUFTOOSMALL -3013 +#define BAD_NAME -3014 +#define BAD_DISPHW -3015 +#define NO_FLOPPY -3016 + +#define MAXSERR 16 +#define SYSTEMFATAL -3999 /* above errors are fatal to system */ + +#endif + +/* + ********************************************************************* + ********************************************************************* + + next file + + ********************************************************************* + ********************************************************************* +*/ + +// Cut this out as memory.h + +/* File: Memory.h + * Module: All Modules + * Author(s): Chris Somers + * Date: August 5, 1993 + * Version: V.1.1 + + modified by Alex Russell to simplify. + */ + + +#ifndef _MEMORY_DEF +#define _MEMORY_DEF 1 + +#include "emmret.h" +#include "emmsize.h" + +#define CMM 0 +#define EMM 1 + +extern int OpenEMM(void); +extern void CloseEMM(void); +extern int EMMInstalled(void); +extern void far *EMMalloc(int *Handle, int Pages); +extern int EMMRealloc(int Handle, int Pages); +extern void EMMFree(int Handle); +extern int MapEMM(int Handle, int Start, int Pages); +extern void UnmapEMM(int Handle, int Start, int Pages); +extern int UseEMM(int Handle, int Start, int Pages); +extern void SaveEMM(int Handle, int Start, int Pages); +extern unsigned long EMMCoreLeft(void); + +#endif + +/* + ********************************************************************* + ********************************************************************* + + next file + + ********************************************************************* + ********************************************************************* +*/ + + +/* File: Memory.c + * Module: All Modules + * Author(s): Chris Somers + * Date: December 1, 1992 + * Version: V.1.1 + + minor mods by Alex Russell to simplify + + Must use memory model with FAR code + + */ + + + +#if !defined(__LARGE__) && !defined(__COMPACT__) && !defined(__HUGE__) +#error Invalid memory model for compiling MEMORY.C +#endif + +#include +#include +#include + +#include "memory.h" + +// static globals -------------------------------- + +static int ActiveEMList[MAXEMHANDLES]; +static unsigned int EMMSeg; + +// forward declarations --------------------------------- + +static int EMPresent(void); +static int EMReady(void); +static unsigned int GetEMMSeg(void); +static int GetEMHandle(int NumPages); +static int EMMap(int Handle, int LogPg, int PhyPg); +static int FreeEMHandle(int Handle); +static int GetNumPages(int Handle); +static int EMStateSave(int Handle); +static void EMStateRestore(int Handle); + + +/********************************************************************/ +int +OpenEMM(void) +{ + if (!EMPresent() || !EMReady()) return(NOTREADY); + if (!(EMMSeg = GetEMMSeg())) return(NOTREADY); /*lint !e720 */ + return(SUCCESS); +} /* End of OpenEMM() */ + +/********************************************************************/ + +void +CloseEMM(void) +{ + int i; + + if (!EMMSeg) return; + for (i = 0; i < MAXEMHANDLES; i++) { + if (ActiveEMList[i]) { + FreeEMHandle(ActiveEMList[i]); + ActiveEMList[i] = 0; + } + } + EMMSeg = 0; +} /* End of CloseEMM() */ + +/********************************************************************/ + +int +EMMInstalled(void) +{ + return((EMMSeg) ? TRUE : FALSE); /* successfully opened? */ +} /* End of EMMInstalled() */ + +/********************************************************************/ + +unsigned long +EMMCoreLeft(void) +{ + unsigned Pages; + unsigned long RtnVal = 0UL; + + _asm { + mov ah,0x42 /* get EMM free page count */ + int 0x67 + or ah,ah + js InternalError /* returns 80, 81, or 84 hex on error */ + mov Pages,bx /* number of unallocated 16K pages */ + } + RtnVal = ((unsigned long)Pages << 14); /* Pages * 16K rtns bytes*/ + +InternalError: + + return(RtnVal); +} /* End of EMMCoreLeft() */ + +/********************************************************************/ + +void far * +EMMalloc(int *Handle, int Pages) +{ + int i; + char *RtnPtr = NULL; + + if (!EMMSeg) { + *Handle = NOTREADY; + return(NULL); + } + if ((Pages < 1) || (Pages > 1020)) { + *Handle = VALUE_OUTF_RANGE; + return (NULL); + } + for (i = 0; (i < MAXEMHANDLES) && (ActiveEMList[i]); i++) ; + if (i == MAXEMHANDLES) { + *Handle = NOFREEITEMS; + return (NULL); + } + if ((ActiveEMList[i] = GetEMHandle(Pages)) > 0) { + RtnPtr = MK_FP(EMMSeg, 0); + } + *Handle = ActiveEMList[i]; + return((void far *)RtnPtr); +} /* End of EMMalloc() */ + +/********************************************************************/ + +int +EMMRealloc(int Handle, int Pages) +{ + int RtnCode = FALSE; + + if (!EMMSeg || (Pages < 0) || (Pages > 1020)) { + return (FALSE); + } + _asm { + mov ah,0x51 /* change # of pages */ + mov bx,Pages + mov dx,Handle + int 0x67 + or ah,ah + js NoGo /* returns 80 to 88 hex on error */ + } + RtnCode = TRUE; + +NoGo: + + return(RtnCode); +} /* End of EMMRealloc() */ + +/********************************************************************/ + +void +EMMFree(int Handle) +{ + int i, j; + + if (!EMMSeg) return; + for (i = 0; (i < MAXEMHANDLES) && (ActiveEMList[i] != Handle); i++) ; + if (i >= MAXEMHANDLES) return; + j = 16; + while (j--) { + if (FreeEMHandle(ActiveEMList[i])) break; + } + ActiveEMList[i] = 0; +} /* End of EMMFree() */ + +/********************************************************************/ + +int /* EMM map for application */ +MapEMM(int Handle, int Start, int Pages) +{ + int i; + + if (!EMMSeg) return(NOTREADY); + for (i = 0; (i < MAXEMHANDLES) && (ActiveEMList[i] != Handle); i++) ; + if (i == MAXEMHANDLES) return (NO_DATA); + if ((GetNumPages(Handle) < Pages) || (Pages < 1) || (Pages > 4)) { + return (VALUE_OUTF_RANGE); + } + for (i = Start; i < Start + Pages; i++) { + if (!EMMap(Handle, i, i - Start)) return(NO_DATA); + } + return(SUCCESS); +} /* End of MapEMM() */ + +/********************************************************************/ + +void /* EMM unmap for application */ +UnmapEMM(int Handle, int Start, int Pages) +{ + int i, j; + + if (!EMMSeg) return; + for (i = 0; (i < MAXEMHANDLES) && (ActiveEMList[i] != Handle); i++) ; + if (i == MAXEMHANDLES) return; + j = Start + Pages; + if ((Pages < 1) || (j > 4)) return; + + for (i = Start; i < j; i++) { + EMMap(Handle, NONE, i); + } +} /* End of UnmapEMM() */ + +/********************************************************************/ + +int /* EMM map for devices - saves EMM state */ +UseEMM(int Handle, int Start, int Pages) +{ + EMStateSave(Handle); + return(MapEMM(Handle, Start, Pages)); +} /* End of UseEMM() */ + +/********************************************************************/ + +void /* EMM unmap for devices - restores EMM state */ +SaveEMM(int Handle, int Start, int Pages) +{ + UnmapEMM(Handle, Start, Pages); + EMStateRestore(Handle); +} /* End of SaveEMM() */ + +/********************************************************************/ + +static int +EMPresent(void) +{ + int i, Segment; + char EMName[] = "EMMXXXX0"; + char *s, *t; + + _asm { /* can be replaced with getvect() */ + push es + mov ax,0x3567 /* get vector for int 67h */ + int 0x21 + mov ax,es + mov Segment,ax + pop es + } + t = MK_FP(Segment, 0x0A); /* point to driver name */ + s = EMName; + for (i = 0; (i < 8) && (*s++ == *t++); i++) ; /* strncmp equivalent */ + + if (i == 8) return(TRUE); + return(FALSE); +} /*End of EMPresent() */ + +/********************************************************************/ + +static int +EMReady(void) +{ + _asm { + mov ah,0x40 /* get EM Manager Status */ + int 0x67 + or ah,ah + jns Ready /* returns 80, 81, or 84 hex on error */ + } + return(FALSE); + +Ready: + return(TRUE); +} /* End of EMReady() */ + +/********************************************************************/ + +static unsigned int +GetEMMSeg(void) +{ + unsigned int EMSegment; + + _asm { + mov ah,0x41 /* get EMM page frame segment */ + int 0x67 + or ah,ah + js NotReady /* returns 80, 81, or 84 hex on error */ + mov EMSegment,bx + } + return(EMSegment); /*lint !e530 */ + +NotReady: + return(NOTREADY); +} /* End of GetEMMSeg() */ + +/********************************************************************/ + +static int +GetEMHandle(int NumPages) +{ + int NewHandle; + + _asm { + mov ah,0x43 /* get handle and allocate EM */ + mov bx,NumPages /* number of 16K pages to allocate */ + int 0x67 + or ah,ah /* returns 80 to 89 hex on error */ + js NoHandle + mov NewHandle,dx /* retrieve handle */ + } + return(NewHandle); + +NoHandle: + return(NO_DATA); +} /* End of GetEMHandle() */ + +/********************************************************************/ + +static int +EMMap(int Handle, int LogPg, int PhyPg) +{ + int RtnCode = NO_DATA; + + _asm { + mov ax,PhyPg /* physical page: 0 - 3 in AL only */ + mov ah,0x44 /* map logical to physical page */ + mov bx,LogPg /* logical page: 0 - 1020 */ + mov dx,Handle + int 0x67 + or ah,ah /* returns 80 to 8B hex on error */ + js NoMapping + } + RtnCode = SUCCESS; + +NoMapping: + return(RtnCode); +} /* End of EMMap() */ + +/********************************************************************/ + +static int +FreeEMHandle(int Handle) +{ + _asm { + mov ah,0x45 /* free handle and deallocate EM */ + mov dx,Handle + int 0x67 + or ah,ah /* returns 80 to 86 hex on error */ + js NotFreed + } + return(SUCCESS); + +NotFreed: /* must retry if unsuccessful */ + return(NO_DATA); +} /* End of FreeEMHandle() */ + +/********************************************************************/ + +static int +GetNumPages(int Handle) +{ + int NumPages = 0; + + _asm { + mov ah,0x4C /* get allocated pages for Handle */ + mov dx,Handle + int 0x67 + or ah,ah /* returns 80 to 84 hex on error */ + js BadHandle + mov NumPages,bx + } +BadHandle: + + return(NumPages); +} /* End of GetNumPages() */ + +/********************************************************************/ + +static int +EMStateSave(int Handle) +{ + int RtnCode = NO_MEMORY; + _asm { + mov ah,0x47 /* save page map under Handle */ + mov dx,Handle + int 0x67 + or ah,ah + js Unsaved /* out of save space error */ + } + RtnCode = SUCCESS; + +Unsaved: + return(RtnCode); +} /* End of EMStateSave() */ + +/********************************************************************/ + +static void +EMStateRestore(int Handle) +{ + _asm { + mov ah,0x48 /* restore page map for Handle */ + mov dx,Handle + int 0x67 /* ignore error */ + } +} /* End of EMStateRestore() */ + +/********************************************************************/ + +/* + ********************************************************************* + ********************************************************************* + + next file + + ********************************************************************* + ********************************************************************* +*/ + +// Cut this out as emm.c + +/* File: emm.c + * Module: All Modules + * Author(s): Chris Somers + * Date: December 1, 1992 + * Version: V.1.1 + + minor mods by Alex Russell to simplify + + Must use memory model with FAR code + + */ + + +#include +#include +#include + +#include "memory.h" + +void TransformData(char *pEmmData, unsigned int len) +{ + while ( len ) + { + (*pEmmData)++; + pEmmData++; + + len--; + } +} + +void main(void) +{ + char *pEmmData; + int hEData; + + if ( OpenEMM() != SUCCESS ) + { // make sure we got EMM + printf("EMM unavailable.\n"); + exit(1); + } + else + printf("Emm available\n"); + + pEmmData = EMMalloc(&hEData, 6); // get 6 * 16K bytes - 96K + if ( pEmmData == NULL ) + { + printf("Not enough EMM or out of handles.\n"); + exit(2); + } + else + printf("emm alloced OK\n"); + + + printf("Map 1st 4 pages\n"); + MapEMM(hEData, 0, 4); // load 1st 4 pages into page frame: 0-3 + + memset(pEmmData, 0x0e, 64000u); + UnmapEMM(hEData, 0, 4); // not absolutely necessary + + printf("Map next 2 pages\n"); + MapEMM(hEData, 4, 2); // map last 2 pages: 4-5 + memset(pEmmData, 0x0e, 32768u); + + MapEMM(hEData, 0, 4); + // do some stuff with the first 64K of file data. + printf("Transform data\n"); + TransformData(pEmmData, 64000UL); + MapEMM(hEData, 4, 2); // only unmaps 1st two pages of prior 64k mapping + // do stuff with remaining 32K of data + TransformData(pEmmData, 32768UL); + UnmapEMM(hEData, 0, 4); // should unmap before freeing + + printf("Close emm\n"); + EMMFree(hEData); // finished with the file data + CloseEMM(); +} + diff --git a/src/lib/exmm/XMEM.ALL b/src/lib/exmm/XMEM.ALL new file mode 100644 index 00000000..3e504e54 --- /dev/null +++ b/src/lib/exmm/XMEM.ALL @@ -0,0 +1,1140 @@ +This file contains 3 files: +xmem.h : c include file +xmem.asm : low level basic XMS acess +xmemc.c : super easy C access via functions like fopen, fread, fwrite + xopen, xread, xwrite, xseek etc... + +FOR DOS REAL mode programs, requires HIMEM.SYS to be loaded in +config.sys. + +XMEM.H ------------- START -------------------------------------------------- +#if !defined(_XMEM_H) +#define _XMEM_H + +typedef struct xms_node + { + long start, size, off; + short used; + struct xms_node *next; + } +xms_node_t; + +typedef struct + { + int handle; + unsigned long total; + unsigned long avail; + unsigned long next_off; + xms_node_t *next; + } +xms_head_t; + +#define XMSBLOCK 16384u +#define XMSBLOCKSHIFT 14 + +extern void LSHL( unsigned long far *SHLnumber, unsigned short n ); + +extern unsigned short XMS_available( void ); + +extern unsigned short XMSblk_available( void ); + +extern short XMS_alloc(unsigned short rsrvd, + unsigned short far *size + ); +extern short XMS_dealloc(unsigned short Hdl ); +extern short XMStoMem(unsigned short Handle, // XMS handle returned by XMS_alloc() + unsigned short blk, // which 16k block to copy to + unsigned short blkAdr, // offset within 16k block + unsigned short Bytes, // bytes to copy + void far *memAdr + ); +extern short MemToXMS(unsigned short Handle, + unsigned short blk, + unsigned short blkAdr, + unsigned short Bytes, + void far *memAdr + ); + +// call these for ease +short alloc_xms(unsigned short far *size); // size in 16k blocks +// NOTE size is changed to the amount block size was altered by! +// normaly this is zero + +short xms_to_mem(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); +void deinit_xms(void); +short init_xms(unsigned short min_blocks); +void qfree_xms(xms_node_t *node); +xms_node_t *qalloc_xms(unsigned long size); +xms_node_t *xms_open(char *file); +short xms_read(void far *buffer, unsigned short n, xms_node_t *node); +short xms_write(void far *buffer, unsigned short n, xms_node_t *node); +long xms_tell(xms_node_t *node); +short xms_seek(xms_node_t *node, long off, short whence); +void xms_close(xms_node_t *node); + +extern xms_head_t xms_head; + +#endif +/* ---------------------------------- end of file --------------------- */ + +XMEM.H ------------- END -------------------------------------------------- + +xmem.asm --------------------- START -------------------------------------- +;----------------------------------------------------------------------- +; +.MODEL MEDIUM + + EXTmemError EQU 7 + XMSmemError EQU 8 + + + ShortAdr EQU 0 + LongAdr EQU 1 + +procname MACRO Pnam + PUBLIC _&Pnam& +_&Pnam& PROC FAR +ENDM + +endproc MACRO Pnam + +_&Pnam& ENDP + +ENDM + +pwrlolvl_TEXT SEGMENT WORD PUBLIC 'CODE' + + ASSUME CS:pwrlolvl_TEXT, DS:pwrlolvl_TEXT, ES:pwrlolvl_TEXT + +SUBTTL (Local Procedure) XMS_setup - find a XMS driver. +PAGE+ + + EVEN +XMSwordByte LABEL BYTE +XMSword DW 0 + +XMSmoveSTRUC STRUC + +Length DW 0 +LengthX DW 0 +SrcHandle DW 0 +SrcOffset DW 0 +SrcOffsetX DW 0 +DestHandle DW 0 +DestOffset DW 0 +DestOffsetX DW 0 + +XMSmoveSTRUC ENDS + +XMSmainGET XMSmoveSTRUC <> +XMSmainPUT XMSmoveSTRUC <> +XMSwordGET XMSmoveSTRUC <2,,,,,,OFFSET XMSword> +XMSwordPUT XMSmoveSTRUC <2,,,OFFSET XMSword> + +XMSfunctAdr DW 0, 0 + +; Don't try to call this from your programs + +XMS_setup PROC NEAR + + PUSH DS + PUSH ES + PUSH BX + + MOV AX,CS ; Set Data segment to the code segment. + MOV DS,AX ; + MOV [XMSwordGET.DestOffsetX],AX ; Set up the move data structures. + MOV [XMSwordPUT.SrcOffsetX],AX ; + + MOV AX,4300H ; See if a XMS Driver Exists. + INT 2FH ; + CMP AL,80H ; + MOV AX,0 ; + JNE XMS_setup01 ; Return 0 if not. + + MOV AX,4310H ; If so, set the driver's function + INT 2FH ; address. + MOV [XMSfunctAdr],BX ; + MOV [XMSfunctAdr+2],ES ; + + MOV AX,1 ; Return 1. + + XMS_setup01: + POP BX + POP ES + POP DS + + RET + +XMS_setup ENDP + +SUBTTL LSHL - Shift an unsigned long left +PAGE+ + + ;**************************************************************************** + ;* + ;* Shift an unsigned long integer left n number of bits. + ;* + ;**************************************************************************** + + ; + ; Stack frame definition for void LSHL( unsigned long *SHLnumber, unsigned n ); + ; + +LSHLparms STRUC + + DW 0, 0 + DW 0 +SHLadr DD ? +SHLn DW ? + +LSHLparms ENDS + +procname LSHL + + PUSH BP + MOV BP,SP + + PUSH BX + PUSH CX + PUSH DX + + PUSH DS + LDS BX,SHLadr[BP] + MOV CX,SHLn[BP] + + MOV AX,[BX] ; Get the long integer. + MOV DX,[BX+2] ; + + LSHL_01: + SHL AX,1 ; Do the long shift. + RCL DX,1 ; + LOOP LSHL_01 ; + + MOV [BX],AX ; Replace the addressed number. + MOV [BX+2],DX ; + + POP DS + POP DX + POP CX + POP BX + + POP BP + RET ; Exit + +endproc LSHL + + +SUBTTL Extended Memory - Stack template for EXTget, EXTput +PAGE+ + +EXTgpparms STRUC + + DW 0, 0 + DW 0 +extgpBase DW ? +extgpblk DW ? +extgpblkAdr DW ? +extgpBytes DW ? +extgpmemAdr DW ? + DW ? + +EXTgpparms ENDS + + + +SUBTTL Extended Memory - XMS - Return total XMS memory. +PAGE+ + + ; Use this function to detect wether or not XMS driver installed + ; + ; Stack frame definition for unsigned XMS_available( void ); + ; + ; The total XMS memory available (in 16k blocks) is returned. + ; +procname XMS_available + + PUSH BX + PUSH CX + PUSH DX + + CALL XMS_setup ; Ensure XMS memory is set. + TEST AX,AX ; + JZ XMS_available01 ; Return zero if not. + + MOV AH,08H ; Set the size function code. + CALL DWORD PTR CS:[XMSfunctAdr] ; Get the size. + TEST AX,AX ; + JZ XMS_available01 ; + + MOV AX,DX ; Set available Kbytes. + SUB AX,64 ; Subtract out the HMA (HIMEM.SYS bug). + JNC XMS_available01 ; + XOR AX,AX ; Set zero if underflow. + + XMS_available01: + MOV CL,4 ; Divide Kbytes by 16 for blocks. + SHR AX,CL ; + + POP DX + POP CX + POP BX + + RET ; Exit + +endproc XMS_available + +SUBTTL Extended Memory - XMS - Return largest block XMS mem. +PAGE+ + + ; + ; Stack frame definition for unsigned XMSblk_available( void ); + ; + ; The size of the largest block of XMS memory available, + ; (in 16Kbyte blocks) is returned. + ; +procname XMSblk_available + + PUSH BX + PUSH CX + PUSH DX + + CALL XMS_setup ; Ensure XMS memory is set. + TEST AX,AX ; + JZ XMSblk_available01 ; Return zero if not. + + MOV AH,08H ; Set the size function code. + CALL DWORD PTR CS:[XMSfunctAdr] ; Get the size. + TEST AX,AX ; + JZ XMSblk_available01 ; + + SUB DX,64 ; Subtract out the HMA (HIMEM.SYS bug). + JNC XMSblk_available0X ; + XOR DX,DX ; Set zero if underflow. + + XMSblk_available0X: + CMP AX,DX ; + JBE XMSblk_available01 ; + MOV AX,DX ; Set available Kbytes. + + XMSblk_available01: + MOV CL,4 ; Divide Kbytes by 16 for blocks. + SHR AX,CL ; + + POP DX + POP CX + POP BX + + RET ; Exit + +endproc XMSblk_available + +SUBTTL Extended Memory - XMS De-allocate a memory block. +PAGE+ + + ; + ; Stack frame definition for int XMS_dealloc( int Hdl ); + ; + ; Zero is returned if the operation fails, non-zero if success. + ; + ; its really important to do this, only other way to recover + ; XMS blocks is to re-boot + +XMSdealparms STRUC + + DW 0, 0 + DW 0 +xmsdealHdl DW ? + +XMSdealparms ENDS + + +procname XMS_dealloc + + PUSH BP + MOV BP,SP + + PUSH BX + PUSH DX + +; CALL XMS_setup ; Ensure XMS memory is set. +; TEST AX,AX ; +; JZ XMS_dealloc01 ; Return zero if not. + + MOV DX,xmsdealHdl[BP] ; Get the handle to de-allocate. + MOV AH,0AH ; + + CALL DWORD PTR CS:[XMSfunctAdr] ; De-allocate it. + + XMS_dealloc01: + POP DX + POP BX + + POP BP + RET ; Exit + +endproc XMS_dealloc + +SUBTTL Extended Memory - XMS Allocate a memory block. +PAGE+ + + ; + ; Stack frame definition for int XMS_alloc( unsigned rsrvd, *size ); + ; + ; rsrved and size are in 16K byte blocks. + ; rsrved is mem set aside for EMS, generaly zero + ; + ; Zero is returned if the operation fails. + ; Block (XMS) handle is returned if success. + ; + ; size - is reduced by the amount of XMS memory actually allocated. + ; + +XMSalparms STRUC + + DW 0, 0 + DW 0 +xmsalrsrvd DW ? +xmsalsize DD ? + +XMSalparms ENDS + +procname XMS_alloc + + PUSH BP + MOV BP,SP + + PUSH BX + PUSH CX + PUSH DX + PUSH DI + PUSH ES + PUSH DS + + MOV AX,CS ; Set the data segment to the code + MOV DS,AX ; segment. + + MOV CX,4 ; + ADD xmsalrsrvd[BP],CX ; Subtract out the HMA (HIMEM.SYS bug). + SHL xmsalrsrvd[BP],CL ; Convert reserved blocks to K-bytes. + + LES DI,xmsalsize[BP] ; Load size address. + XOR AX,AX ; + MOV BX,ES:[DI] ; Get the requested size in blocks. + + TEST BX,0F000H ; Check for more than 64 Megabytes. + JZ XMS_alloc01 ; + MOV BX,00FFFH ; + + XMS_alloc01: + MOV CL,4 ; + SHL BX,CL ; Convert to K-Bytes. + MOV CX,BX ; In CX. + JZ XMS_alloc05 ; Return zero if no size requested. + +; CALL XMS_setup ; Ensure XMS memory is set. +; TEST AX,AX ; +; JZ XMS_alloc05 ; Return zero if not. + + XOR BX,BX ; + MOV AH,08H ; Set to Query Free XMS Memory. + CALL DWORD PTR [XMSfunctAdr] ; + + SUB DX,xmsalrsrvd[BP] ; Subtract out reserved blocks. + JB XMS_alloc03 ; Ensure no borrow. + CMP AX,DX ; + JBE XMS_alloc02 ; + MOV AX,DX ; + + XMS_alloc02: + MOV DX,AX ; + CMP AX,68 ; Ensure enough memory to allocate. + + XMS_alloc03: + MOV AX,0 ; + JB XMS_alloc05 ; Exit if not. + + CMP BL,80H ; Check for errors. + JE XMS_alloc05 ; + CMP BL,81H ; + JE XMS_alloc05 ; + + CMP CX,DX ; Check actual against requested size. + JBE XMS_alloc04 ; + MOV CX,DX ; Set if actual < requested. + + XMS_alloc04: + MOV DX,CX ; Set requested size. + MOV AH,09H ; + CALL DWORD PTR [XMSfunctAdr] ; Allocate it. + DEC AX ; Check for errors. + MOV AX,0 ; + JNZ XMS_alloc05 ; + + + MOV AX,CX ; Convert allocated size in KBytes + MOV CL,4 ; to allocated blocks. + SHR AX,CL ; + + SUB ES:[DI],AX ; Subtract the blocks allocated. + MOV AX,DX ; Set to return the handle. + + XMS_alloc05: + POP DS + POP ES + POP DI + POP DX + POP CX + POP BX + + POP BP + RET ; Exit + +endproc XMS_alloc + +SUBTTL Extended Memory - XMS get, put Stack Frame definition +PAGE+ + + +XMSgpparms STRUC + + DW 0, 0 + DW 0 +xmsgpHdl DW ? +xmsgpblk DW ? +xmsgpblkAdr DW ? +xmsgpBytes DW ? +xmsgpmemAdr DD ? + +XMSgpparms ENDS + +SUBTTL Extended Memory - XMStoMem +PAGE+ + + + ; + ; Stack frame definition for int XMStoMem( unsigned Handle, + ; unsigned blk, + ; unsigned blkAdr, + ; unsigned Bytes, + ; char *memAdr + ; ); + ; + ; XMSmemError is returned if the operation fails, Zero if success. + ; + +procname XMStoMem + + PUSH BP + MOV BP,SP + + PUSH BX + PUSH CX + PUSH DX + PUSH SI + PUSH DI + PUSH ES + PUSH DS + + MOV AX,CS ; Set Data Segment to Code Segment. + MOV DS,AX ; + + MOV CX,xmsgpBytes[BP] ; Get the number of bytes to transfer. + LES BX,xmsgpmemAdr[BP] ; Get the memory address. + MOV DX,xmsgpHdl[BP] ; Get the XMS handle. + MOV [XMSmainGET.SrcHandle],DX ; Set it in the move structures. + MOV [XMSwordGET.SrcHandle],DX ; + + XOR DX,DX ; + MOV DI,xmsgpblk[BP] ; Get the block number. + SHR DI,1 ; Form the 32 bit XMS address in + RCR DX,1 ; DI:DX. + SHR DI,1 ; + RCR DX,1 ; + ADD DX,xmsgpblkAdr[BP] ; + + TEST CX,1 ; Check for an odd number of bytes + JZ XMStoMem02 ; to transfer. + + DEC CX ; Decrement to an even number of bytes. + + TEST DX,1 ; Check for an odd XMS address. + JZ XMStoMem01 ; + + ; XMS address is odd. + ; ------------------- + DEC DX ; + MOV [XMSwordGET.SrcOffset],DX ; Set the XMS address. + MOV [XMSwordGET.SrcOffsetX],DI ; + + MOV AH,0BH ; Set the XMS move, function code. + MOV SI,OFFSET XMSwordGET ; Set address of the move structure. + + PUSH BX ; + CALL DWORD PTR [XMSfunctAdr] ; Call the XMS handler. + POP BX ; + DEC AX ; Check for errors. + JNZ XMStoMem03 ; Error out if error. + + MOV AX,[XMSword] ; Get the moved word. + + MOV ES:[BX],AH ; Move the odd byte to memory. + + INC BX ; Reset the memory address. + ADD DX,2 ; And the XMS address. + + JMP XMStoMem02 ; Move the block. + + + XMStoMem01: + ; XMS address is even. + ; -------------------- + ADD DX,CX ; + MOV [XMSwordGET.SrcOffset],DX ; Set the XMS address. + SUB DX,CX ; + MOV [XMSwordGET.SrcOffsetX],DI ; + + MOV AH,0BH ; Set the XMS move, function code. + MOV SI,OFFSET XMSwordGET ; Set address of the move structure. + + PUSH BX ; + CALL DWORD PTR [XMSfunctAdr] ; Call the XMS handler. + POP BX ; + DEC AX ; Check for errors. + JNZ XMStoMem03 ; Error out if error. + + MOV AX,[XMSword] ; Get the moved word. + + XCHG DI,CX ; + MOV ES:[BX+DI],AL ; Move the odd byte to memory. + XCHG DI,CX ; + + XMStoMem02: + JCXZ XMStoMem04 ; Avoid a zero byte move. + + MOV XMSmainGET.Length,CX ; Set length for the move. + + MOV XMSmainGET.DestOffset,BX ; Set Memory address. + MOV XMSmainGET.DestOffsetX,ES ; + + MOV XMSmainGET.SrcOffset,DX ; Set XMS address. + MOV XMSmainGET.SrcOffsetX,DI ; + + MOV AH,0BH ; Set the XMS move, function code. + MOV SI,OFFSET XMSmainGET ; Set address of the move structure. + + CALL DWORD PTR [XMSfunctAdr] ; Call the XMS handler. + DEC AX ; Check for errors. + JZ XMStoMem05 + + XMStoMem03: + MOV AX,XMSmemError ; Set error code if error. + JMP XMStoMem05 ; + + XMStoMem04: + XOR AX,AX ; + + XMStoMem05: + POP DS + POP ES + POP DI + POP SI + POP DX + POP CX + POP BX + + POP BP + RET ; Exit + +endproc XMStoMem + +SUBTTL Extended Memory - MemToXMS +PAGE+ + + + ; + ; Stack frame definition for int MemToXMS( unsigned Handle, + ; unsigned blk, + ; unsigned blkAdr, + ; unsigned Bytes, + ; char *memAdr + ; ); + ; + ; XMSmemError is returned if the operation fails, Zero if success. + ; + +procname MemToXMS + + PUSH BP + MOV BP,SP + + PUSH BX + PUSH CX + PUSH DX + PUSH SI + PUSH DI + PUSH ES + PUSH DS + + MOV AX,CS ; + MOV DS,AX ; + + MOV CX,xmsgpBytes[BP] ; Get the number of bytes to transfer. + LES BX,xmsgpmemAdr[BP] ; Get the memory address. + MOV DX,xmsgpHdl[BP] ; Get the XMS handle. + MOV [XMSmainPUT.DestHandle],DX ; Set it in the move structures. + MOV [XMSwordPUT.DestHandle],DX ; + MOV [XMSwordGET.SrcHandle],DX ; + + XOR DX,DX ; + MOV DI,xmsgpblk[BP] ; Get the block number. + SHR DI,1 ; Form the 32 bit XMS address in + RCR DX,1 ; DI:DX. + SHR DI,1 ; + RCR DX,1 ; + ADD DX,xmsgpblkAdr[BP] ; + + TEST CX,1 ; Check for an odd number of bytes + JZ MemToXMS02 ; to transfer. + + DEC CX ; Decrement to an even number of bytes. + + TEST DX,1 ; Check for an odd XMS address. + JZ MemToXMS01 ; + + ; XMS address is odd. + ; ------------------- + DEC DX ; + MOV [XMSwordGET.SrcOffset],DX ; Set the XMS address. + MOV [XMSwordGET.SrcOffsetX],DI ; + MOV [XMSwordPUT.DestOffset],DX ; + MOV [XMSwordPUT.DestOffsetX],DI ; + + MOV AH,0BH ; Set the XMS move, function code. + MOV SI,OFFSET XMSwordGET ; Set address of the move structure. + + PUSH BX ; + CALL DWORD PTR [XMSfunctAdr] ; Call the XMS handler. + POP BX ; + DEC AX ; Check for errors. + JNZ MemToXMS03 ; Error out if error. + + MOV AH,ES:[BX] ; Get the odd memory byte. + + MOV [XMSwordByte+1],AH ; Put it in the moved word. + + MOV AH,0BH ; Set the XMS move, function code. + MOV SI,OFFSET XMSwordPUT ; Set address of the move structure. + + PUSH BX ; + CALL DWORD PTR [XMSfunctAdr] ; Call the XMS handler. + POP BX ; + DEC AX ; Check for errors. + JNZ MemToXMS03 ; Error out if error. + + INC BX ; Reset the memory address. + ADD DX,2 ; And the XMS address. + + JMP MemToXMS02 ; Move the block. + + MemToXMS01: + ; XMS address is even. + ; -------------------- + ADD DX,CX ; + MOV [XMSwordGET.SrcOffset],DX ; Set the XMS address. + MOV [XMSwordPUT.DestOffset],DX ; + SUB DX,CX ; + MOV [XMSwordGET.SrcOffsetX],DI ; + MOV [XMSwordPUT.DestOffsetX],DI ; + + MOV AH,0BH ; Set the XMS move, function code. + MOV SI,OFFSET XMSwordGET ; Set address of the move structure. + + PUSH BX ; + CALL DWORD PTR [XMSfunctAdr] ; Call the XMS handler. + POP BX ; + DEC AX ; Check for errors. + JNZ MemToXMS03 ; Error out if error. + + XCHG DI,CX ; + MOV AL,ES:[BX+DI] ; Get the odd memory byte. + XCHG DI,CX ; + + MOV [XMSwordByte],AL ; Set the moved word. + + MOV AH,0BH ; Set the XMS move, function code. + MOV SI,OFFSET XMSwordPUT ; Set address of the move structure. + + PUSH BX ; + CALL DWORD PTR [XMSfunctAdr] ; Call the XMS handler. + POP BX ; + DEC AX ; Check for errors. + JNZ MemToXMS03 ; Error out if error. + + MemToXMS02: + JCXZ MemToXMS04 ; Avoid a zero byte move. + + MOV XMSmainPUT.Length,CX ; Set length for the move. + + MOV XMSmainPUT.SrcOffset,BX ; Set Memory address. + MOV XMSmainPUT.SrcOffsetX,ES ; + + MOV XMSmainPUT.DestOffset,DX ; Set XMS address. + MOV XMSmainPUT.DestOffsetX,DI ; + + MOV AH,0BH ; Set the XMS move, function code. + MOV SI,OFFSET XMSmainPUT ; Set address of the move structure. + + CALL DWORD PTR [XMSfunctAdr] ; Call the XMS handler. + DEC AX ; Check for errors. + JZ MemToXMS05 + + MemToXMS03: + MOV AX,XMSmemError ; Set error code if error. + JMP MemToXMS05 ; + + MemToXMS04: + XOR AX,AX ; + + MemToXMS05: + POP DS + POP ES + POP DI + POP SI + POP DX + POP CX + POP BX + + POP BP + RET ; Exit + +endproc MemToXMS + + +SUBTTL Last Page +PAGE+ + +pwrlolvl_TEXT ENDS + + END + + +xmem.asm --------------------- END -------------------------------------- + +xmemc.c ---------------------------- START ------------------------- + +/* + + Copyright 1994 Alec Russell, ALL rights reserved + Permission granted to use as you wish. + + Slightly higher level xms calls than xmem.asm + +*/ + +#include +#include +#include +#include + +#include + +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) +{ + 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) +{ + 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 + t1=xms_head.next; + while ( t1 ) + { + if ( t1->used == 0 && t1->size >= size ) + { + t1->off=0; + t1->used=1; + node=t1; + break; + } + else + t1=t1->next; + } + + if ( node == NULL ) // didn't find existing node + { + node=malloc(sizeof(xms_node_t)); + if ( node ) + { + node->off=0; + node->used=1; + node->size=size; + node->next=NULL; + node->start=xms_head.next_off; + xms_head.avail-=size; + xms_head.next_off+=size; + if ( xms_head.next == NULL ) + { + xms_head.next=node; + } + else + { + t1=xms_head.next; + while ( t1->next ) + t1=t1->next; + t1->next=node; + } + } + else + pr2("out of near mem in qalloc_xms"); + } + } + else + pr2("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"); + } + else + { + pr2("ATTEMPTED to qfree empty list"); + } +} + +/* ---------------------- xms_open() ---------------------- March 8,1994 */ +xms_node_t *xms_open(char *file) +{ + int i; + xms_node_t *node=NULL; + FILE *fp; + char *buffer; + unsigned long off; + + fp=fopen(file, "rb"); + if ( fp ) + { + node=qalloc_xms(filelength(fileno(fp))); + if ( node ) + { + buffer=malloc(4096); + if ( buffer ) + { + off=0l; + while ( (i=fread(buffer, 1, 4096, fp)) ) + { + 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"); + } + + fclose(fp); + } + else + pr2("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: + if ( off < 0l || off > node->size ) + err=1; + 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; + else + 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); + min_blocks-=blocks; + xms_head.avail=xms_head.total=(unsigned long)min_blocks*XMSBLOCK; + blocks=min_blocks; + } + else + blocks=0; + } + 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); + if ( xms_head.next ) + { + t1=xms_head.next; + t2=t1->next; + while ( t1 ) + { + free(t1); + t1=t2; + 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. + +*/ +xmemc.c ---------------------------- END ------------------------- diff --git a/src/lib/exmm/emm.c b/src/lib/exmm/emm.c index f642fada..f76a59e1 100644 --- a/src/lib/exmm/emm.c +++ b/src/lib/exmm/emm.c @@ -17,7 +17,7 @@ #include #include -#include "memory.c" +#include "memory.h" void TransformData(char *pEmmData, unsigned int len) { diff --git a/src/lib/exmm/memory.c b/src/lib/exmm/memory.c index ce58c3e4..519ec6cb 100644 --- a/src/lib/exmm/memory.c +++ b/src/lib/exmm/memory.c @@ -23,12 +23,12 @@ #include "memory.h" -// static globals -------------------------------- + //static globals -------------------------------- static int ActiveEMList[MAXEMHANDLES]; static unsigned int EMMSeg; -// forward declarations --------------------------------- + //forward declarations --------------------------------- static int EMPresent(void); static int EMReady(void); @@ -87,13 +87,12 @@ EMMCoreLeft(void) mov ah,0x42 /* get EMM free page count */ int 0x67 or ah,ah - //js InternalError /* returns 80, 81, or 84 hex on error */ + js InternalError /* returns 80, 81, or 84 hex on error */ mov Pages,bx /* number of unallocated 16K pages */ } RtnVal = ((unsigned long)Pages << 14); /* Pages * 16K rtns bytes*/ -//InternalError: - +InternalError: return(RtnVal); } /* End of EMMCoreLeft() */ @@ -141,11 +140,11 @@ EMMRealloc(int Handle, int Pages) mov dx,Handle int 0x67 or ah,ah - //js NoGo /* returns 80 to 88 hex on error */ + js NoGo /* returns 80 to 88 hex on error */ } RtnCode = TRUE; -//NoGo: +NoGo: return(RtnCode); } /* End of EMMRealloc() */ @@ -256,11 +255,11 @@ EMReady(void) mov ah,0x40 /* get EM Manager Status */ int 0x67 or ah,ah - //jns Ready /* returns 80, 81, or 84 hex on error */ + jns Ready /* returns 80, 81, or 84 hex on error */ } return(FALSE); -//Ready: +Ready: return(TRUE); } /* End of EMReady() */ @@ -275,12 +274,12 @@ GetEMMSeg(void) mov ah,0x41 /* get EMM page frame segment */ int 0x67 or ah,ah - //js NotReady /* returns 80, 81, or 84 hex on error */ + js NotReady /* returns 80, 81, or 84 hex on error */ mov EMSegment,bx } return(EMSegment); /*lint !e530 */ -//NotReady: +NotReady: return(NOTREADY); } /* End of GetEMMSeg() */ @@ -296,12 +295,12 @@ GetEMHandle(int NumPages) mov bx,NumPages /* number of 16K pages to allocate */ int 0x67 or ah,ah /* returns 80 to 89 hex on error */ - //js NoHandle + js NoHandle mov NewHandle,dx /* retrieve handle */ } return(NewHandle); -//NoHandle: +NoHandle: return(NO_DATA); } /* End of GetEMHandle() */ @@ -319,11 +318,11 @@ EMMap(int Handle, int LogPg, int PhyPg) mov dx,Handle int 0x67 or ah,ah /* returns 80 to 8B hex on error */ - //js NoMapping + js NoMapping } RtnCode = SUCCESS; -//NoMapping: +NoMapping: return(RtnCode); } /* End of EMMap() */ @@ -337,11 +336,11 @@ FreeEMHandle(int Handle) mov dx,Handle int 0x67 or ah,ah /* returns 80 to 86 hex on error */ - //js NotFreed + js NotFreed } return(SUCCESS); -//NotFreed: /* must retry if unsuccessful */ +NotFreed: /* must retry if unsuccessful */ return(NO_DATA); } /* End of FreeEMHandle() */ @@ -357,10 +356,10 @@ GetNumPages(int Handle) mov dx,Handle int 0x67 or ah,ah /* returns 80 to 84 hex on error */ - //js BadHandle + js BadHandle mov NumPages,bx } -//BadHandle: +BadHandle: return(NumPages); } /* End of GetNumPages() */ @@ -376,11 +375,11 @@ EMStateSave(int Handle) mov dx,Handle int 0x67 or ah,ah - //js Unsaved /* out of save space error */ + js Unsaved /* out of save space error */ } RtnCode = SUCCESS; -//Unsaved: +Unsaved: return(RtnCode); } /* End of EMStateSave() */ diff --git a/src/lib/exmm/x.bat b/src/lib/exmm/x.bat index 5e8a8bfa..e1751702 100644 --- a/src/lib/exmm/x.bat +++ b/src/lib/exmm/x.bat @@ -1 +1 @@ -"wcp -mh emm.c" at +wcp -mh emm.c diff --git a/src/lib/exmm/xmem.c b/src/lib/exmm/xmem.c index ff15d1ec..d5e7d549 100644 --- 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. + */ diff --git a/src/lib/exmm/xmemc.c b/src/lib/exmm/xmemc.c deleted file mode 100644 index 0ab1de3d..00000000 --- a/src/lib/exmm/xmemc.c +++ /dev/null @@ -1,316 +0,0 @@ -/* - 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 "src\lib\xmem\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) -{ - 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) -{ - 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 - t1=xms_head.next; - while ( t1 ) - { - if ( t1->used == 0 && t1->size >= size ) - { - t1->off=0; - t1->used=1; - node=t1; - break; - } - else - t1=t1->next; - } - - if ( node == NULL ) // didn't find existing node - { - node=malloc(sizeof(xms_node_t)); - if ( node ) - { - node->off=0; - node->used=1; - node->size=size; - node->next=NULL; - node->start=xms_head.next_off; - xms_head.avail-=size; - xms_head.next_off+=size; - if ( xms_head.next == NULL ) - { - xms_head.next=node; - } - else - { - t1=xms_head.next; - while ( t1->next ) - t1=t1->next; - t1->next=node; - } - } - else - printf("out of near mem in qalloc_xms"); - } - } - else - 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 - printf("ERROR didn't find node qfree"); - } - else - { - printf("ATTEMPTED to qfree empty list"); - } -} - - - -/* ---------------------- xms_open() ---------------------- March 8,1994 */ -xms_node_t *xms_open(char *file) -{ - int i; - xms_node_t *node=NULL; - FILE *fp; - char *buffer; - unsigned long off; - - fp=fopen(file, "rb"); - if ( fp ) - { - node=qalloc_xms(filelength(fileno(fp))); - if ( node ) - { - buffer=malloc(4096); - if ( buffer ) - { - off=0l; - while ( (i=fread(buffer, 1, 4096, fp)) ) - { - mem_to_xms(xms_head.handle, (char far *)buffer, -off+node->start, i); - off+=i; - } - - free(buffer); - } - else - printf("out of mem in xms_open 1"); - } - - fclose(fp); - } - else - 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: - if ( off < 0l || off > node->size ) - err=1; - 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; - else - 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)) ) - { - printf("blocks minus by = %u", blocks); - min_blocks-=blocks; - xms_head.avail=xms_head.total=(unsigned long)min_blocks*XMSBLOCK; - blocks=min_blocks; - } - else - blocks=0; - } - 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); - if ( xms_head.next ) - { - t1=xms_head.next; - t2=t1->next; - while ( t1 ) - { - free(t1); - t1=t2; - t2=t1->next; - } - } - - memset(&xms_head, 0, sizeof(xms_head_t)); - } -} - - - -/* --------------------------- end of file ------------------------- */ -- 2.39.5