March 10th, 2001
And finally here's part two of the XMS tutorial!!! I say finally because I originally submitted the first article to the QB Times, then they stopped making new issues. =( Anyways it's finally here and now we'll finish this small series off.
Last issue we covered the bare essentials of XMS. From those routines presented you can make other routines to do just about anything with XMS. One thing I've done with XMS is make a routine to read a map which I've saved in it. All I have to pass to the routine is the x and y position I want to read and the function returns the tile number at that offset. Another thing to use it for is to store graphics. No, not off screen buffers but the PUT/GET compatible arrays. This alone will save you loads of memory depending on your program. There are lots of uses for XMS, I'll leave you to discover your own. So lets get started.
What I didn't show you how to do last month was to use above 64MB of memory. Well now I will show you how to do that in a few of the functions from last month. To do this we need to use the Super Extended Memory support functions. These will make use of 32-bit registers. The funtions we'll be changing are XMSInfo, XMSAlloc, and XMSReAlloc, from last month. You might have thought that XMSPut and XMSGet needed to be changed as well, but no. So the best place to start is with XMSInfo. We'll change it to return long-integer values about the free memory.
XMSInfo PROC freemem:DWORD, totalmem:DWORD mov ah,88h ;Use function 88h call [XMSControl] ;Call the API mov bx,totalmem ;Put the value in EDX in totalmem. mov [bx],edx mov bx,freemem ;Put the value of EAX in freemem mov [bx],eax ret ENDP XMSInfo
This will return values of up to 4GB in size (all in KB). What we did was use EAX, and EDX and change function 08h to 88h.
Now lets change XMSAllocate routine. This is also really simple:
XMSAlloc PROC kb:DWORD mov ah,89h ;Use function 89h mov edx,kb ;Move kb into EDX. call [XMSControl] ;Call the API cmp ax,0001h ;Is AX = 0001h? If it is then it worked! jne AllocErr ;If it isn't then . . . too bad! =P mov ax,dx ;Move the handle into AX so its returned. ret AllocErr: ;Since we can't get a handle if it didn't work we don't ret ;want DX to get into AX. ENDP XMSAlloc
What we did there was change 09h to 89h and change DX to EDX since we want a 32-bit value for our handle size. Really for all the functions we're changing only the size of the registers and the function numbers.
Now lets change the XMSReAllocate function around:
XMSReAlloc proc handle:WORD, kb:DWORD mov ah,8Fh ;Use subfunction 8Fh mov bx,handle ;Get the handle to deallocate into DX. mov dx,[bx] mov ebx,kb ;Get the new amount to resize the handle to into EBX. call [XMSControl] ;Call the API. mov bx,handle ;Return the handle to QB. mov [bx],ax endp XMSReAlloc
And there we go! That's it. Now you can allocate and use up to 4GB of memory. Now to use this lib you should put all the functions in one .ASM file and assemble it using an assembler (I used TASM to do the above functions). Then you should link the .OBJ file into a library. I'm not going to explain in detail how to do this, there are other utilities, and tutorials to do that. The include file you need should look something like this:
DEFINT A-Z '$DYNAMIC DECLARE FUNCTION XMSInit% () DECLARE SUB XMSInfo (free&, total&) DECLARE FUNCTION XMSAlloc% (BYVAL kb&) DECLARE SUB XMSDeAlloc (handle%) DECLARE SUB XMSReAlloc (handle%, BYVAL kb&) DECLARE FUNCTION Move2XMS% (BYVAL handle%, BYVAL segm%, BYVAL offs%, BYVAL bytes&, BYVAL XMSoffs&) DECLARE FUNCTION Move2Var% (BYVAL handle%, BYVAL segm%, BYVAL offs%, BYVAL bytes&, BYVAL XMSoffs&)
And there you go! XMS fo QB!! If you still don't understand this then you might want to contact me then I can (hopefully) explain it to you. If you find any mistakes for this then also please contact me. I just hate having error's in my tutorials. =) Hope you enjoyed!
This article was written by: Fling-master - http://www.qbrpgs.com
|All site content is © Copyright 2001, HyperRealistic Games. This excludes content submitted by other people.|