'===========================================================================
' Subject: PB GET FREE XMS MEMORY             Date: 09-01-98 (15:11)       
'  Author: Dave Navarro, Jr.                  Code: PB                     
'  Origin: dave@powerbasic.com              Packet: MEMORY.ABC
'===========================================================================
'FUNCTION to return the total amount of free XMS memory available
'Optimized from original code in Fido Conference by unknown author.
'by Dave Navarro, Jr.
'
'WARNING!  Might not work if RUN from within the IDE.

DEFINT A-Z

'If not in the IDE
IF BIT(pbvHost, 5) = 0 THEN
  PRINT STR$(TotalFoundXms); "k bytes free XMS"
END IF

END

'----------------------------------------------------------------------------
FUNCTION TotalFoundXms() PUBLIC AS INTEGER

  DIM Pointer AS SHARED DWORD

  IF Pointer = 0 THEN
    ! push DS
    ! mov  AX, &h4310
    ! int  &h2f
    ! mov  Word Ptr Pointer[0], BX
    ! mov  Word Ptr Pointer[2], ES
    ! pop  DS
  END IF

  ! push DS
  ! mov  AH, 8
  ! mov  BL, 0
  ! call Dword Ptr Pointer
  ! mov  FUNCTION, DX
  ! pop  DS

END FUNCTION
