I was not on this forum quite a long time, and it took me some time
to dig out my old XMS code; but here it is:
Code:
DEFINT A-Z TYPE EMM 'these are the parameters passed to the XMS Manager bytes AS LONG sHandle AS WORD sOffset AS DWORD dHandle AS WORD dOffset AS DWORD END TYPE DECLARE FUNCTION XMSinit (avail??, total??) DECLARE FUNCTION XMSalloc(BYVAL KB, handle) DECLARE FUNCTION XMSMove (e AS EMM) DECLARE FUNCTION XMSfree (BYVAL handle) DECLARE FUNCTION XMSredim (BYVAL handle, BYVAL KB) '========================================================= '=== Test Program ======================= '========================================================= CLS erro = XMSinit (avail??, total??) PRINT "XMSinit: Return Code "; STR$(erro) PRINT "Largest available XMS block (KB): "; STR$(avail??) PRINT "Total available XMS (KB): "; STR$(total??) IF erro THEN END DIM e AS EMM erro = XMSalloc(1, handle) PRINT "XMSalloc: Return code "; STR$(erro) PRINT "Block handle: "; STR$(handle) IF erro THEN END 'Copy part of a test string into XMS: test$ = "abcdefghijklmnopqrstuvwxyz0123456789" e.bytes = (LEN(test$)+1)\2*2 'Number of bytes must be even; else an error occurs. e.sHandle = 0 'Source of move: DOS memory e.sOffset = STRPTR32(test$) 'Source ptr: Seg./Offs. ptr into DOS memory e.dHandle = handle 'Destination of move: our XMS block e.dOffset = 0 'Destination ptr: Offset into XMS block erro = XMSMove(e) PRINT "Copying string to XMS: Return Code "; STR$(erro) 'Change our test string: test$ = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 'Overwrite 12 bytes of it with what was stored in XMS: e.bytes = 12 'Number of bytes to move e.dHandle = 0 'Destination of move: DOS memory e.dOffset = STRPTR32(test$) 'Destination ptr: Seg./Offs. of destination e.sHandle = handle 'Source of move: our XMS block e.sOffset = 4 'Source ptr: Offset into XMS block erro = XMSMove(e) PRINT "Copying string from XMS: Return Code "; STR$(erro) PRINT "Result string: "; test$ PRINT "XMSFree: Return code "; STR$(XMSFree(handle)) END '========================================================= '=== XMS Functions ======================= '========================================================= XMSManager: 'Code Segment Variable: 32-bit pointer to XMS Manager ! DW 0 ! DW 0 ' XMSinit: Check for the presence of XMS and get manager address ' Returns errorcode, or zero for success FUNCTION XMSinit (avail??, total??) PUBLIC ! push ax ! push bx ! push DX ! push es ! PUSH DI 'XMS Installation Check (should return AL = &H80) ! mov ax, &H4300 ! int &H2F ! CMP al, &H080 ! JNE XMSnotInstalled 'Get XMS Handler Address ! mov ax, &H4310 ! int &H2F ! MOV CS:XMSManager, BX ! mov CS:XMSManager[2], ES 'Get Handler Version '! mov ax, 0 '! call DWORD CS:XMSManager '! LES DI, version?? '! MOV ES:[DI], AX 'Request amount of free XMS ! mov ax, &H0800 ! mov BX, 0 ! CALL DWORD CS:XMSManager ! LES DI, avail?? ! MOV ES:[DI], AX ; largest avail. block in KB ! LES DI, total?? ! MOV ES:[DI], DX ; total XMS in KB ! MOV FUNCTION, BL ; errorcode ! JMP InstallCheckEnd XMSnotInstalled: ! LES DI, avail?? ! MOV WORD ES:[DI], &HFFFF ! MOV FUNCTION, -1 InstallCheckEnd: ! POP DI ! POP ES ! POP DX ! POP BX ! POP AX END FUNCTION 'Allocate XMS block FUNCTION XMSalloc(BYVAL KB, handle) PUBLIC ! PUSH AX ! PUSH BX ! PUSH DX ! PUSH ES ! mov ax, &H0900 ! mov dx, KB ; size in KB ! CALL DWORD CS:XMSManager ! CMP AX, 0 ! JE Failure2 ! LES BX, handle ! MOV ES:[BX], DX ! MOV FUNCTION, 0 ! JMP End2 Failure2: ! MOV FUNCTION, BL End2: ! POP ES ! POP DX ! POP BX ! POP AX END FUNCTION 'Free XMS block FUNCTION XMSfree (BYVAL handle) PUBLIC ! PUSH AX ! PUSH BX ! PUSH DX ! mov ax, &H0A00 ! mov dx, handle ! CALL DWORD CS:XMSManager ! CMP AX, 0 ! JE Failure3 ! MOV FUNCTION, 0 ! JMP End3 Failure3: ! MOV FUNCTION, BL End3: ! pop DX ! pop bx ! POP AX END FUNCTION 'Move any XMS Block (EMM structure must already be filled) FUNCTION XMSMove (e AS EMM) PUBLIC ! PUSH AX ! PUSH BX ! PUSH SI ! PUSH DS ! mov ax, &H0B00 ! LDS SI, e ! CALL DWORD CS:XMSManager ! CMP AX, 0 ! JE Failure4 ! mov FUNCTION, 0 ! JMP End4 Failure4: ! mov FUNCTION, BL End4: ! POP DS ! POP SI ! POP BX ! POP AX END FUNCTION 'Resize XMS Block '? NOT YET TESTED FUNCTION XMSredim (BYVAL handle, BYVAL KB) PUBLIC ! PUSH AX ! PUSH BX ! PUSH DX ! MOV AX, &H0F00 ! MOV DX, handle ! MOV BX, KB ! CALL DWORD CS:XMSManager ! CMP AX, 0 ! JE Failure5 ! mov FUNCTION, 0 ! JMP End5 Failure5: ! mov FUNCTION, BL End5: ! POP DX ! POP BX ! POP AX END FUNCTION
With kind regards,
Hans Ruegg
Leave a comment: