home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / msj / msjv4_4 / xms / scrxms.asm < prev   
Encoding:
Assembly Source File  |  1988-11-02  |  5.2 KB  |  215 lines

  1. ;****************************************************************************
  2. ;*                                        *
  3. ;*  SCRXMS.ASM -                                *
  4. ;*                                        *
  5. ;*    Adapted from the XMM C Library Routines (c) 1988 Microsoft Corp.    *
  6. ;*                                        *
  7. ;****************************************************************************
  8.  
  9.  
  10. ;============================================================================
  11. ;   DATA SEGMENT
  12. ;============================================================================
  13.  
  14. _DATA    segment WORD PUBLIC 'DATA'
  15.  
  16. XMM_Initialized dw    0        ; 1 if the XMS driver has been found
  17. XMM_Control    label    dword        ; Points to the XMS control function
  18.         dw    offset _XMM_NotInitialized
  19.         dw    seg _TEXT
  20. _DATA    ends
  21.  
  22.  
  23. DGROUP    GROUP _DATA
  24.  
  25. ;============================================================================
  26. ;   CODE SEGMENT
  27. ;============================================================================
  28.  
  29. _TEXT    segment WORD PUBLIC 'CODE'
  30.  
  31. assume cs:_TEXT
  32. assume ds:DGROUP
  33.  
  34. ;*--------------------------------------------------------------------------*
  35. ;*                                        *
  36. ;*  _XMM_NotInitialized -                            *
  37. ;*                                        *
  38. ;*    Called by default if the program hasn't called _XMM_Installed or    *
  39. ;*    if no XMS driver is found.                        *
  40. ;*                                        *
  41. ;*--------------------------------------------------------------------------*
  42.  
  43. _XMM_NotInitialized proc far
  44.  
  45.     xor    ax,ax           ; Simulate an XMS "Not Implemented" error
  46.     mov    bl,80h
  47.     ret
  48.  
  49. _XMM_NotInitialized endp
  50.  
  51.  
  52. ;*--------------------------------------------------------------------------*
  53. ;*                                        *
  54. ;*  BOOL _XMM_Installed(void);                            *
  55. ;*                                        *
  56. ;*    Called to initialize the XMM library routines.                *
  57. ;*                                        *
  58. ;*--------------------------------------------------------------------------*
  59.  
  60. public _XMM_Installed
  61.  
  62. _XMM_Installed proc near
  63.  
  64.     ; Have we already been initialized?
  65.     cmp    [XMM_Initialized],0
  66.     jne    Already_Initialized        ; Yup, return TRUE
  67.  
  68.     ; Is an XMS driver installed?
  69.     mov    ax,4300h
  70.     int    2Fh
  71.     cmp    al,80h
  72.     jne    NoDriver            ; Nope, return FALSE
  73.  
  74.     ; Get and store the address of the driver's control function.
  75.     mov    ax,4310h
  76.     int    2Fh
  77.     mov    word ptr [XMM_Control],bx
  78.     mov    word ptr [XMM_Control+2],es
  79.  
  80.     ; Set XMM_Initialized to TRUE.
  81.     inc    [XMM_Initialized]
  82.  
  83. Already_Initialized:
  84. NoDriver:
  85.     mov    ax,[XMM_Initialized]
  86.     ret
  87.  
  88. _XMM_Installed endp
  89.  
  90.  
  91. ;*--------------------------------------------------------------------------*
  92. ;*                                        *
  93. ;*  WORD _XMM_Version(void);                            *
  94. ;*                                        *
  95. ;*    Returns the driver's XMS version number.                *
  96. ;*                                        *
  97. ;*--------------------------------------------------------------------------*
  98.  
  99. public _XMM_Version
  100.  
  101. _XMM_Version proc near
  102.  
  103.     xor    ah,ah                ; Call XMS Function 0
  104.     call    [XMM_Control]            ; Sets AX to XMS Version
  105.     ret
  106.  
  107. _XMM_Version endp
  108.  
  109.  
  110. ;*--------------------------------------------------------------------------*
  111. ;*                                        *
  112. ;*  long _XMM_AllocateExtended(int SizeK);                    *
  113. ;*                                        *
  114. ;*    Allocates an Extended Memory Block and returns its handle.        *
  115. ;*                                        *
  116. ;*--------------------------------------------------------------------------*
  117.  
  118. public _XMM_AllocateExtended
  119.  
  120. _XMM_AllocateExtended proc near
  121.  
  122.     push    bp                ; Create a stack frame
  123.     mov    bp,sp
  124.  
  125.     ; Call the XMS Allocate function.
  126.     mov    ah,9
  127.     mov    dx,[bp+4]            ; [bp+4] is the parameter
  128.     call    [XMM_Control]
  129.  
  130.     ; Was there an error?
  131.     or    ax,ax
  132.     jz    AEFail                ; Yup, fail
  133.     mov    ax,dx                ; Return XMS Handle in AX
  134.     mov    dx,0                ; Zero out DX
  135.     jnz    AESuccess
  136. AEFail:
  137.     mov    dh,bl                ; Put error return in DH
  138.  
  139. AESuccess:
  140.     pop    bp                ; Restore the stack
  141.     ret
  142.  
  143. _XMM_AllocateExtended endp
  144.  
  145.  
  146. ;*--------------------------------------------------------------------------*
  147. ;*                                        *
  148. ;*  long _XMM_FreeExtended(WORD Handle);                    *
  149. ;*                                        *
  150. ;*    Deallocates an Extended Memory Block.                    *
  151. ;*                                        *
  152. ;*--------------------------------------------------------------------------*
  153.  
  154. public _XMM_FreeExtended
  155.  
  156. _XMM_FreeExtended proc near
  157.  
  158.     push    bp                ; Create a stack frame
  159.     mov    bp,sp
  160.  
  161.     ; Call the XMS FreeExtended function.
  162.     mov    ah,0Ah
  163.     mov    dx,[bp+4]            ; [bp+4] is the parameter
  164.     call    [XMM_Control]
  165.  
  166.     xor    dx,dx                ; Zero DX
  167.  
  168.     ; Was there an error?
  169.     or    ax,ax
  170.     jz    FESuccess            ; Nope, return
  171.     mov    dh,bl                ; Yup, return err code in DH
  172. FESuccess:
  173.     pop    bp                ; Restore the stack
  174.     ret
  175.  
  176. _XMM_FreeExtended endp
  177.  
  178.  
  179. ;*--------------------------------------------------------------------------*
  180. ;*                                        *
  181. ;*  long _XMM_MoveExtended(XMSMOVE *pInfo);                    *
  182. ;*                                        *
  183. ;*    Moves a block of data into/outof/within extended memory.        *
  184. ;*                                        *
  185. ;*--------------------------------------------------------------------------*
  186.  
  187. public _XMM_MoveExtended
  188.  
  189. _XMM_MoveExtended proc near
  190.  
  191.     push    bp                ; Create a stack frame
  192.     mov    bp,sp
  193.  
  194.     ; Call the XMS MoveExtended function.
  195.     mov    ah,0Bh
  196.     mov    si,[bp+4]            ; [bp+4] is the parameter
  197.     call    [XMM_Control]
  198.  
  199.     xor    dx,dx                ; Zero DX
  200.  
  201.     ; Was there an error?
  202.     or    ax,ax
  203.     jz    MESuccess            ; Nope, return
  204.     mov    dh,bl                ; Yup, return err code in DH
  205. MESuccess:
  206.     pop    bp                ; Restore the stack
  207.     ret
  208.  
  209. _XMM_MoveExtended endp
  210.  
  211.  
  212. _TEXT    ends
  213.  
  214. end
  215.