CALLHMA


, , . Small Compact. hma.asm, :

Small, Compact

Large, Huge

[bp+4]

[bp+6]

[bp+6]

[bp+8]

CALLHMA 11.2, - 11.3.

11.2. callhma\callhma.c

// =====================================================

// HIMEM.SYS

//

// (C) ., 1997

//

// E-mail: frolov@glas.apc.org

// WWW: http://www.glasnet.ru/~frolov

//

// http://www.dials.ccas.ru/frolov

// =====================================================

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <dos.h>

#include <string.h>

struct XMM_Move

{

unsigned long Length;

unsigned short SourceHandle;

unsigned long SourceOffset;

unsigned short DestHandle;

unsigned long DestOffset;

};

extern long XMM_Installed(void);

extern long XMM_Version(void);

extern long XMM_RequestHMA(unsigned);

extern long XMM_ReleaseHMA(void);

extern long XMM_GlobalEnableA20(void);

extern long XMM_GlobalDisableA20(void);

extern long XMM_EnableA20(void);

extern long XMM_DisableA20(void);

extern long XMM_QueryA20(void);

extern long XMM_QueryLargestFree(void);

extern long XMM_QueryTotalFree(void);

extern long XMM_AllocateExtended(unsigned);

extern long XMM_FreeExtended(unsigned);

extern long XMM_MoveExtended(struct XMM_Move *);

extern long XMM_LockExtended(unsigned);

extern long XMM_UnLockExtended(unsigned);

extern long XMM_GetHandleLength(unsigned);

extern long XMM_GetHandleInfo(unsigned);

extern long XMM_ReallocateExtended(unsigned, unsigned);


extern long XMM_RequestUMB(unsigned);

extern long XMM_ReleaseUMB(unsigned);

void error(char *msg, long rc);

int main(void)

{

long ver, rc, handle;

static char testmsg[] = " ";

char buf[80];

char far *ptr;

int i;

struct XMM_Move move_d;

// , HIMEM.SYS,

// ,

if (XMM_Installed())

{

printf("\nHIMEM.SYSinstalled");

ver = XMM_Version();

printf("\nver XMM: %4X,%4x",

(short)ver, (short)(ver >> 16));

}

else

{

printf("\nHIMEM.SYSnot found");

exit(-1);

}

// HMA

rc = XMM_RequestHMA(0xffff);

if(rc)

error("Request HMA error",rc);

else

{

// A20

rc = XMM_GlobalEnableA20();

if(rc)

error("Open A20 error",rc);

//

// HMA,

//

FP_SEG(ptr) = 0xffff;

FP_OFF(ptr) = 0x0010;

for(i=0; testmsg[i] != 0; i++)

ptr[i] = testmsg[i];

for(i=0; ptr[i] != 0; i++)

buf[i] = ptr[i];



buf[i] = 0;

//

printf("\n%s",buf);

// A20 HMA

rc = XMM_GlobalDisableA20();

if(rc)

error("Close A20 eror",rc);

rc = XMM_ReleaseHMA();

if(rc)

error("Free HMA error",rc);

}

// EMB 1

handle = XMM_AllocateExtended(1);

if(handle < 0)

error("Request XMB error",handle);

//

// EMB,

//

move_d.Length = strlen(testmsg) + 1;

move_d.SourceHandle = 0;



(char far*)move_d.SourceOffset = (char far*)testmsg;

move_d.DestHandle = (short)handle;

move_d.DestOffset = 0L;

rc = XMM_MoveExtended(&move_d);

if(rc < 0)

error("Copy in EMB error",rc);

move_d.Length = strlen(testmsg) + 1;

move_d.DestHandle = 0;

(char far*)move_d.DestOffset = (char far*)buf;

move_d.SourceHandle = (short)handle;

move_d.SourceOffset = 0L;

rc = XMM_MoveExtended(&move_d);

if(rc < 0)

error("Copy from EMB error",rc);

//

printf("\n%s",buf);

// EMB

rc = XMM_FreeExtended((unsigned)handle);

if(rc)

error("Free XMB error",rc);

return 0;

}

//

//

void error(char *msg, long rc)

{

rc = (unsigned char)(rc >> 24) ;

printf("\n%s, error: %02.2X\n",

msg, (unsigned char)rc);

exit(-1);

}

11.3. callhma\hma.asm

; =====================================================

;

; XMS .

; Small

;

; (C) A. Frolov, 1997

;

; E-mail: frolov@glas.apc.org

; WWW: http://www.glasnet.ru/~frolov

; or

; http://www.dials.ccas.ru/frolov

; =====================================================

.model small

.DATA

;

; XMM

XMM_Control dd ?

.CODE

;

;

c_begin macro

push bp

mov bp,sp

push si

push di

endm

c_end macro

pop di

pop si

mov sp,bp

pop bp

ret

endm

; public

public _XMM_Installed

public _XMM_Version

public _XMM_RequestHMA

public _XMM_ReleaseHMA



public _XMM_GlobalEnableA20

public _XMM_GlobalDisableA20

public _XMM_EnableA20

public _XMM_DisableA20

public _XMM_QueryA20

public _XMM_QueryLargestFree

public _XMM_QueryTotalFree

public _XMM_AllocateExtended

public _XMM_FreeExtended

public _XMM_MoveExtended

public _XMM_LockExtended

public _XMM_UnLockExtended

public _XMM_GetHandleLength

public _XMM_GetHandleInfo

public _XMM_ReallocateExtended

public _XMM_RequestUMB

public _XMM_ReleaseUMB

;**

;.Name _XMM_Installed

;.Title

;

;.Descr

; HIMEM.SYS

; .

;

;.Proto unsigned XMM_Installed(void);

;

;.Params

;

;.Return 0 - HIMEM.SYS ;

; 1 - HIMEM.SYS.

;

;**

_XMM_Installed proc near

c_begin

mov ax, 4300h

int 2fh

cmp al, 80h

jne NotInstalled

mov ax, 4310h

int 2fh

mov word ptr [XMM_Control], bx

mov word ptr [XMM_Control+2], es

mov ax,1

jmp Installed

NotInstalled:

mov ax, 0

Installed:

c_end

_XMM_Installed endp

;**

;.Name _XMM_Version

;.Title HIMEM.SYS

;

;.Descr

; HIMEM.SYS

;

;.Proto long XMM_Version(void);

;

;.Params

;

;.Return 16 ,

; - 16

;

;

;**

_XMM_Version proc near

push si

push di

xor ah, ah

call [XMM_Control]

mov dx, bx

pop di

pop si

ret



_XMM_Version endp

;**

;.Name _XMM_RequestHMA

;.Title HMA

;

;.Descr

; HMA

;

;.Proto long XMM_RequestHMA(unsigned space);

;

;.Params space -

; TSR- ,

; 0xffff ;

;

;.Return < 0 - HMA ,

; .

; 0L - HMA .

;

;**

_XMM_RequestHMA proc near

c_begin

mov ah, 1

mov dx, [bp+4]

call [XMM_Control]

xor dx, dx

dec ax

jz @success

mov dh, bl

@success:

c_end

_XMM_RequestHMA endp

;**

;.Name _XMM_ReleaseHMA

;.Title HMA

;

;.Descr

; HMA

;

;.Proto long XMM_ReleaseHMA(void);

;

;.Params

;

;.Return < 0 - HMA ,

; .

; 0L - HMA .

;

;**

_XMM_ReleaseHMA proc near

c_begin

mov ah, 2

call [XMM_Control]

xor dx, dx

dec ax

jz @success1

mov dh, bl

@success1:

c_end

_XMM_ReleaseHMA endp

;**

;.Name _XMM_GlobalEnableA20

;.Title A20

;

;.Descr ,

; HMA A20

;

;.Proto long XMM_GlobalEnableA20(void);

;

;.Params

;

;.Return < 0 - A20 ,

; .

; 0L - A20 .



;

;**

_XMM_GlobalEnableA20 proc near

c_begin

mov ah, 3

call [XMM_Control]

xor dx, dx

dec ax

jz @success2

mov dh, bl

@success2:

c_end

_XMM_GlobalEnableA20 endp

;**

;.Name _XMM_GlobalDisableA20

;.Title A20

;

;.Descr ,

; HMA A20

;

;.Proto long XMM_GlobalDisableA20(void);

;

;.Params

;

;.Return < 0 - A20 ,

; .

; 0L - A20 .

;

;**

_XMM_GlobalDisableA20 proc near

c_begin

mov ah, 4

call [XMM_Control]

xor dx, dx

dec ax

jz @success3

mov dh, bl

@success3:

c_end

_XMM_GlobalDisableA20 endp

;**

;.Name _XMM_EnableA20

;.Title A20

;

;.Descr

; .

;

;.Proto long XMM_EnableA20(void);

;

;.Params

;

;.Return < 0 - A20 ,

; .

; 0L - A20 .

;

;**

_XMM_EnableA20 proc near

c_begin

mov ah, 5

call [XMM_Control]

xor dx, dx

dec ax

jz @success4

mov dh, bl

@success4:

c_end

_XMM_EnableA20 endp

;**

;.Name _XMM_DisableA20

;.Title A20

;

;.Descr

; .

;

;.Proto long XMM_DisableA20(void);

;

;.Params

;

;.Return < 0 - A20 ,



; .

; 0L - A20 .

;

;**

_XMM_DisableA20 proc near

c_begin

mov ah, 6

call [XMM_Control]

xor dx, dx

dec ax

jz @success5

mov dh, bl

@success5:

c_end

_XMM_DisableA20 endp

;**

;.Name _XMM_QueryA20

;.Title A20

;

;.Descr

; A20

;

;.Proto long XMM_QueryA20(void);

;

;.Params

;

;.Return < 0 - ,

; .

; 0L - A20 ,

; 1L - A20 .

;

;**

_XMM_QueryA20 proc near

c_begin

mov ah, 7

call [XMM_Control]

xor dx, dx

or ax, ax

jnz @success6

mov dh, bl

@success6:

c_end

_XMM_QueryA20 endp

;**

;.Name _XMM_QueryLargestFree

;.Title

;

;.Descr

; ,

; .

;

;.Proto long XMM_QueryLargestFree(void);

;

;.Params

;

;.Return < 0 - ,

; .

; >= 0 - .

;

;**

_XMM_QueryLargestFree proc near

c_begin

mov ah, 8

call [XMM_Control]

xor dx, dx

or ax, ax

jnz @success7

mov dh, bl

@success7:

c_end

_XMM_QueryLargestFree endp

;**

;.Name _XMM_QueryTotalFree

;.Title

;

;.Descr

; .



;

;.Proto long XMM_QueryTotalFree(void);

;

;.Params

;

;.Return < 0 - ,

; .

; >= 0 - .

;

;**

_XMM_QueryTotalFree proc near

c_begin

mov ah, 8

call [XMM_Control]

or ax, ax

mov ax, dx

mov dx, 0

jnz @success8

mov dh, bl

@success8:

c_end

_XMM_QueryTotalFree endp

;**

;.Name _XMM_AllocateExtended

;.Title

;

;.Descr

; ,

; .

;

;.Proto long XMM_AllocateExtended(unsigned space);

;

;.Params space -

; ;

;

;.Return < 0 - ,

; .

; > 0L -

; .

;

;**

_XMM_AllocateExtended proc near

c_begin

mov ah, 9

mov dx, [bp+4]

call [XMM_Control]

or ax, ax

mov ax, dx

mov dx, 0

jnz @success9

mov dh, bl

@success9:

c_end

_XMM_AllocateExtended endp

;**

;.Name _XMM_FreeExtended

;.Title

;

;.Descr

; ,

; XMM_AllocateExtended().

;

;.Proto long XMM_FreeExtended(unsigned handle);

;

;.Params handle - ;

;

;.Return < 0 - ,

; .

; 0L - .

;

;**



_XMM_FreeExtended proc near

c_begin

mov ah, 0Ah

mov dx, [bp+4]

call [XMM_Control]

xor dx, dx

dec ax

jz @successA

mov dh, bl

@successA:

c_end

_XMM_FreeExtended endp

;**

;.Name _XMM_MoveExtended

;.Title

;

;.Descr

; ,

; struct XMM_Move:

;

; struct XMM_Move {

; unsigned long Length;

; unsigned short SourceHandle;

; unsigned long SourceOffset;

; unsigned short DestHandle;

; unsigned long DestOffset;

; };

;

;.Proto long XMM_MoveExtended(struct

; XMM_Move *move_descr);

;

;.Params struct XMM_Move *move_descr -

; ,

; , .

;

;.Return < 0 - ,

; .

; 0L - .

;

;**

_XMM_MoveExtended proc near

c_begin

mov ah, 0Bh

mov si, [bp+4];

call [XMM_Control]

xor dx, dx

dec ax

jz @successB

mov dh, bl

@successB:

c_end

_XMM_MoveExtended endp

;**

;.Name _XMM_LockExtended

;.Title

;

;.Descr

; 31

; .

;

;.Proto long XMM_LockExtended(unsigned handle);

;

;.Params handle - ;

;

;.Return < 0 - ,

; .



; > 0L - ,

;

; .

;

;**

_XMM_LockExtended proc near

c_begin

mov ah, 0Ch

mov dx, [bp+4]

call [XMM_Control]

xchg ax, bx

dec bx

jz XMML_Success

mov dh, al

XMML_Success:

c_end

_XMM_LockExtended endp

;**

;.Name _XMM_UnLockExtended

;.Title

;

;.Descr

; .

;

;.Proto long XMM_UnLockExtended(unsigned handle);

;

;.Params handle - ;

;

;.Return < 0 - ,

; .

; 0L - .

;

;**

_XMM_UnLockExtended proc near

c_begin

mov ah, 0Dh

mov dx, [bp+4]

call [XMM_Control]

xor dx, dx

dec ax

jz @successC

mov dh, bl

@successC:

c_end

_XMM_UnLockExtended endp

;**

;.Name _XMM_GetHandleLength

;.Title

;

;.Descr

; .

;

;.Proto long XMM_GetHandleLength(unsigned handle);

;

;.Params handle - ;

;

;.Return < 0 - ,

; .

; > 0L - .

;

;**

_XMM_GetHandleLength proc near

c_begin

mov ah, 0Eh

mov dx, [bp+4]

call [XMM_Control]

or ax, ax

mov ax, dx

mov dx, 0

jnz @successD

mov dh, bl

@successD:

c_end

_XMM_GetHandleLength endp



;**

;.Name _XMM_GetHandleInfo

;.Title

;

;.Descr

;

;

; .

;

;.Proto long XMM_GetHandleInfo(unsigned handle);

;

;.Params handle - ;

;

;.Return < 0 - ,

; .

; > 0L - -

; ;

; - .

;

;**

_XMM_GetHandleInfo proc near

c_begin

mov ah, 0Eh

mov dx, [bp+4]

call [XMM_Control]

mov dx, bx

or ax, ax

mov ax, dx

mov dx, 0

jnz @successE

mov dh, bl

@successE:

c_end

_XMM_GetHandleInfo endp

;**

;.Name _XMM_ReallocateExtended

;.Title

;

;.Descr

; .

;

;.Proto long XMM_ReallocateExtended(unsigned handle,

; unsigned new_size);

;

;.Params handle - ;

; new_size -

; ;

;

;.Return < 0 - ,

; .

; > 0L -

; .

;

;**

_XMM_ReallocateExtended proc near

c_begin

mov ah, 0Fh

mov dx, [bp+4]

mov bx, [bp+6]

call [XMM_Control]

xor dx, dx

dec ax

jz @successF

mov dh, bl

@successF:

c_end

_XMM_ReallocateExtended endp



;**

;.Name _XMM_RequestUMB

;.Title UMB

;

;.Descr

; UMB

;

;.Proto long XMM_RequestUMB(unsigned space);

;

;.Params space -

; ;

;

;.Return < 0 - UMB ,

; ;

;

; (16 );

; > 0L - UMB ,

;

; UMB, -

; UMB.

;

;**

_XMM_RequestUMB proc near

c_begin

mov ah, 10h

mov dx, [bp+4]

call [XMM_Control]

xchg bx, ax

dec bx

jz RUMB_Success

xchg ax, dx

mov dh, dl

RUMB_Success:

c_end

_XMM_RequestUMB endp

;**

;.Name _XMM_ReleaseUMB

;.Title UMB

;

;.Descr

; UMB

;

;.Proto long XMM_ReleaseUMB(unsigned segment);

;

;.Params segment - UMB*

;

;.Return < 0 - UMB ,

; .

; 0L - UMB .

;

;**

_XMM_ReleaseUMB proc near

c_begin

mov ah, 11h

mov dx, [bp+4]

call [XMM_Control]

xor dx, dx

dec ax

jz @success10

mov dh, bl

@success10:

c_end

_XMM_ReleaseUMB endp

END










Forekc.ru
, , , , , , , , , ,