home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xmm12.zip / XMM.ASM < prev    next >
Assembly Source File  |  1992-07-05  |  60KB  |  1,555 lines

  1. ;--------------------------------------------------------------------------
  2. ;  MODULE :        XMM                           INITIAL : 19891127 v 1.00
  3. ;  AUTHOR :        Jeroen W. Pluimers            UPDATE :  19920705 v 1.20
  4. ;
  5. ;  DESCRIPTION :   eXtended Memory Manager
  6. ;
  7. ;  HISTORY :       19891127 - 1.00 - jwp
  8. ;
  9. ;                      initial translation from XMS 2.0 specification
  10. ;
  11. ;                  19909322 - 1.11 - jwp
  12. ;
  13. ;                      final XMS 2.0 implementation
  14. ;
  15. ;                  19920705 - 1.20 - jwp
  16. ;
  17. ;                      incorporation of XMS 3.0 specification
  18. ;
  19. ;                      incorporation of XMS 3.0 specification
  20. ;                      compiled for Turbo Pascal 6.0
  21. ;                      documentation fixup for XMS 3.0
  22. ;
  23. ;  COMPUTER :      NEAT-AT, ERC 386/25
  24. ;  COMPILER :      TASM 1.0, TASM 2.01
  25. ;  LINKER :        TURBO PASCAL 5.0, 5.5 and 6.0
  26. ;
  27. ;  COPYRIGHT :     (c) 1989-1992 Pluimers Software Ontwikkeling.
  28. ;--------------------------------------------------------------------------
  29.                 Ideal
  30.                 Masm51
  31.  
  32.                 %title  "XMM - eXtended Memory Manager"
  33.                 %pagesize 70,132
  34.  
  35.                 Model   TPascal
  36.  
  37.                 DataSeg
  38. ;----------------------------------------------------------------------------
  39. ; there is nothing in the data segment.
  40. ;----------------------------------------------------------------------------
  41.  
  42.                 CodeSeg
  43.  
  44. ;----------------------------------------------------------------------------
  45. ; Macro to convert from XMS success/fail to
  46. ; a form more acceptable for TURBO PASCAL.  IE.
  47. ;
  48. ; AX =  1 becomes AL = 0
  49. ; AX <> 1 becomes AL = BL
  50. ;----------------------------------------------------------------------------
  51. Macro       SuccessFail
  52. Local       Success
  53.  
  54.     dec    ax
  55.     jz    Success
  56.         mov     al, bl
  57. Success:
  58.  
  59. EndM
  60.  
  61.  
  62.  
  63.  
  64. ;----------------------------------------------------------------------------
  65. ; Initialised data must reside in the code segment.
  66. ;----------------------------------------------------------------------------
  67.  
  68. XMM_Initialised dw      0
  69.  
  70. ; XMM_Control points to a routine that returns XMMNotInitialised (80h)
  71. ; for each XMM call until XMMInstalled is called.
  72.  
  73. label   XMM_Control     DWord
  74.                 dw      OFFSET XMM_NotInitialised
  75.                 dw      Code
  76.  
  77.  
  78.  
  79.  
  80. ;---------------------------------------------------------------------------
  81. ;  ROUTINE :     XMM_NotInitialised
  82. ;
  83. ;  DESCRIPTION : Routine called for each XMM function call, when the XMM
  84. ;                is not initialised with a call to XMMInstalled.
  85. ;
  86. ;  RETURNS :     XMMNotInitialised.
  87. ;---------------------------------------------------------------------------}
  88. Proc   XMM_NotInitialised FAR
  89.  
  90.             xor     ax, ax                          ; Immediate failure
  91.             mov     bl, 80h                         ; Not Implemented
  92.  
  93.             ret
  94.  
  95. EndP
  96.  
  97.  
  98.  
  99.  
  100. ;---------------------------------------------------------------------------
  101. ;  ROUTINE :     XMMInstalled
  102. ;
  103. ;  DESCRIPTION : THIS ROUTINE MUST BE CALLED BEFORE ANY OTHER ROUTINE
  104. ;                OR ALL THE OTHER ROUTINES WILL FAIL WITH ERROR CODE $80.
  105. ;
  106. ;  RETURNS :     False - No XMM driver found.
  107. ;                True  - An XMM driver has been found.
  108. ;
  109. ;  POST :        Internal pointer to XMM driver is established.
  110. ;
  111. ;  PASCAL :      Function XMMInstalled : Boolean;
  112. ;---------------------------------------------------------------------------
  113. Proc    XMMInstalled    FAR
  114. Public  XMMInstalled
  115.  
  116.             cmp     [XMM_Initialised], 0
  117.             jne     @@Already_Initialised
  118.             mov     ax, 4300h                       ; Test for XMM
  119.             int     2fh
  120.             cmp     al, 80h
  121.             jne     @@NoDriver
  122.  
  123.             mov     ax, 4310h                       ; Get Control Function
  124.             int     2fh
  125.             mov     [word ptr cs:XMM_Control], bx
  126.             mov     [word ptr cs:XMM_Control+2], es
  127.             inc     [XMM_Initialised]
  128.  
  129.     @@NoDriver:
  130.  
  131.     @@Already_Initialised:
  132.  
  133.             mov     ax, [XMM_Initialised]
  134.  
  135. EndP
  136.  
  137.  
  138.  
  139.  
  140. ;---------------------------------------------------------------------------
  141. ;  ROUTINE :     XMMVersion
  142. ;
  143. ;  DESCRIPTION : Get version numbers. Both the XMS version number and the
  144. ;                driver internal revision number are encoded as follows :
  145. ;                  Low byte  = minor part.
  146. ;                  High byte = major part.
  147. ;                e.g. XMSversion $0277 would mean version 2.77.
  148. ;                The HMAAvailable indicates the existence of the HMA (not
  149. ;                its availability) and is intended mainly for installation
  150. ;                programs.
  151. ;
  152. ;  OUT :         XMSversion   - XMS version number.
  153. ;                XMSrevision  - Driver internal revision number.
  154. ;                HMAAvailable - False - no HMA detected.
  155. ;                               True  - HMA has been detected.
  156. ;
  157. ;  RETURNS :     XMMNotImplemented - XMMInstalled has not been called.
  158. ;                XMMOk             - Always if XMMInstalled has been called.
  159. ;
  160. ;  PRE :         XMMInstalled must have been called first.
  161. ;
  162. ;  PASCAL :      Function XMMVersion(Var XMSversion,
  163. ;                                        XMSrevision  : Word;
  164. ;                                    Var HMAAvailable : Boolean) : Byte;
  165. ;
  166. ;  XMS :         ARGS:   AH = 00h
  167. ;                RETS:   AX = XMS version number (BCD encoded)
  168. ;                        BX = Driver internal revision number.
  169. ;                        DX = 0001h if the HMA exists, 0000h otherwise.
  170. ;                ERRS:   None.
  171. ;---------------------------------------------------------------------------}
  172. Proc    XMMVersion  FAR XMSVersion   : DWord,   \
  173.                         Revision     : DWord,   \
  174.                         HMAAvailable : DWord
  175. Public  XMMVersion
  176.  
  177.             xor     ah,ah                       ; Function 0
  178.             call    [XMM_Control]
  179.  
  180.             les     di,[XMSVersion]
  181.             mov     [Word Ptr es:di],ax
  182.  
  183.             les     di,[Revision]
  184.             mov     [Word Ptr es:di],bx
  185.  
  186.             les     di,[HMAAvailable]
  187.             mov     [Word Ptr es:di],dx
  188.  
  189.             xor     al,al                       ; return XMMOk
  190.  
  191.             ret
  192.  
  193. EndP
  194.  
  195.  
  196.  
  197.  
  198. ;---------------------------------------------------------------------------
  199. ;  ROUTINE :     XMMRequestHMA
  200. ;
  201. ;  DESCRIPTION : Attempts to reserve the whole 64K-16 byte high memory
  202. ;                area for the caller.
  203. ;                If the HMA is currently unused, the caller's size
  204. ;                parameter is compared to the /HMAMIN= parameter on
  205. ;                the driver's command line.
  206. ;                If the value passed by the caller is greater than or
  207. ;                equal to the amount specified by the driver's
  208. ;                parameter, the request succeeds.
  209. ;                This provides the ability to ensure that programs
  210. ;                which use the HMA efficiently have priority over
  211. ;                those which do not.
  212. ;                NOTE: See the sections "Prioritizing HMA Usage" and
  213. ;                      "High Memory Area Restrictions" in the
  214. ;                      documentation for more information.
  215. ;
  216. ;  IN :          SpaceNeeded - Number of bytes in the HMA needed by caller.
  217. ;                              It is recommended that if the caller is
  218. ;                              an application program this value is
  219. ;                              set to 65535 and if the caller is a TSR
  220. ;                              the real number of bytes is used.
  221. ;
  222. ;  RETURNS :     XMMOk              - the HMA is assigned to the caller.
  223. ;                XMMNotImplemented  - the function is not implemented.
  224. ;                XMMVDiskFound      - a VDISK device is detected.
  225. ;                XMMHMANotExist     - the HMA does not exist.
  226. ;                XMMHAMInUse        - the HMA is already in use.
  227. ;                XMMHAMMinSize      - SpaceNeeded is less than the /HMAMIN=
  228. ;                                     environment parameter.
  229. ;
  230. ;  PRE :         XMMInstalled must have been called first.
  231. ;
  232. ;  PASCAL :      Function XMMRequestHMA (SpaceNeeded : Word) : Byte;
  233. ;
  234. ;  XMS :         ARGS:   AH = 01h
  235. ;                        If the caller is a TSR or device driver,
  236. ;                            DX = Space needed in the HMA by the caller in
  237. ;                                 bytes
  238. ;                        If the caller is an application program,
  239. ;                            DX = FFFFh
  240. ;                RETS:   AX = 0001h if the HMA is assigned to the caller,
  241. ;                             0000h otherwise.
  242. ;                ERRS:   BL = 80h if the function is not implemented.
  243. ;                        BL = 81h if a VDISK device is detected.
  244. ;                        BL = 90h if the HMA does not exist.
  245. ;                        BL = 91h if the HMA is already in use.
  246. ;                        BL = 92h if DX is less than the /HMAMIN= parameter.
  247. ;---------------------------------------------------------------------------
  248. Proc    XMMRequestHMA FAR SpaceNeeded : Word
  249. Public  XMMRequestHMA
  250.  
  251.             mov     ah,1
  252.             mov     dx,[SpaceNeeded]
  253.  
  254.             call    [XMM_Control]
  255.  
  256.             SuccessFail
  257.  
  258.             ret
  259.  
  260. EndP
  261.  
  262.  
  263.  
  264.  
  265. ;---------------------------------------------------------------------------
  266. ;  ROUTINE :     XMMReleaseHMA
  267. ;
  268. ;  DESCRIPTION : Releases the high memory area and allows other
  269. ;                programs to use it.
  270. ;                Programs which allocate the HMA must release it
  271. ;                before exiting.
  272. ;                When the HMA has been released, any code or data
  273. ;                stored in it becomes invalid and should not be
  274. ;                accessed.
  275. ;
  276. ;  RETURNS :     XMMOk              - the HMA is successfully released.
  277. ;                XMMNotImplemented  - the function is not implemented.
  278. ;                XMMVDiskFound      - a VDISK device is detected.
  279. ;                XMMHMANotExist     - the HMA does not exist.
  280. ;                XMMNotAllocated    - the HMA was not allocated.
  281. ;
  282. ;  PRE :         XMMInstalled must have been called first.
  283. ;
  284. ;  PASCAL :      Function XMMReleaseHMA : Byte;
  285. ;
  286. ;  XMS :         ARGS:   AH = 02h
  287. ;                RETS:   AX = 0001h if the HMA is successfully released,
  288. ;                             0000h otherwise.
  289. ;                ERRS:   BL = 80h if the function is not implemented.
  290. ;                        BL = 81h if a VDISK device is detected.
  291. ;                        BL = 90h if the HMA does not exist.
  292. ;                        BL = 93h if the HMA was not allocated.
  293. ;---------------------------------------------------------------------------
  294. Proc    XMMReleaseHMA FAR
  295. Public  XMMReleaseHMA
  296.  
  297.             mov     ah,2
  298.  
  299.             call    [XMM_Control]
  300.  
  301.             SuccessFail
  302.  
  303.             ret
  304.  
  305. EndP
  306.  
  307.  
  308.  
  309.  
  310. ;---------------------------------------------------------------------------
  311. ;  ROUTINE :     XMMGlobalEnableA20
  312. ;
  313. ;  DESCRIPTION : Attempts to enable the A20 line.
  314. ;                It should only be used by programs which have control
  315. ;                of the HMA.
  316. ;                The A20 line should be turned off via
  317. ;                XMMGlobalDisableA20 before a program releases control
  318. ;                of the system.
  319. ;                NOTE: On many machines, toggling the A20 line is a
  320. ;                      relatively slow operation.
  321. ;
  322. ;  RETURNS :     XMMOk              - the A20 line is enabled.
  323. ;                XMMNotImplemented  - the function is not implemented.
  324. ;                XMMVDiskFound      - a VDISK device is detected.
  325. ;                XMMA20Err          - and A20 error occurs.
  326. ;
  327. ;  PRE :         XMMInstalled must have been called first.
  328. ;
  329. ;  PASCAL :      Function XMMGlobalEnableA20 : Byte;
  330. ;
  331. ;  XMS :         ARGS:   AH = 03h
  332. ;                RETS:   AX = 0001h if the A20 line is enabled,
  333. ;                             0000h otherwise.
  334. ;                ERRS:   BL = 80h if the function is not implemented.
  335. ;                        BL = 81h if a VDISK device is detected.
  336. ;                        BL = 82h if an A20 error occurs.
  337. ;---------------------------------------------------------------------------
  338. Proc    XMMGlobalEnableA20 FAR
  339. Public  XMMGlobalEnableA20
  340.  
  341.             mov     ah,3
  342.             call    [XMM_Control]
  343.  
  344.             SuccessFail
  345.  
  346.             ret
  347.  
  348. EndP
  349.  
  350.  
  351.  
  352.  
  353. ;---------------------------------------------------------------------------
  354. ;  ROUTINE :     XMMGlobalDisableA20
  355. ;
  356. ;  DESCRIPTION : Attempts to disable the A20 line.
  357. ;                It should only be used by programs which have control
  358. ;                of the HMA.
  359. ;                The A20 line should be disabled before a program
  360. ;                releases control of the system.
  361. ;                NOTE: On many machines, toggling the A20 line is a
  362. ;                      relatively slow operation.
  363. ;
  364. ;  RETURNS :     XMMOk              - the A20 line is disabled.
  365. ;                XMMNotImplemented  - the function is not implemented.
  366. ;                XMMVDiskFound      - a VDISK device is detected.
  367. ;                XMMA20Err          - and A20 error occurs.
  368. ;                XMMA20StillEnabled - the A20 line is still enabled.
  369. ;
  370. ;  PRE :         XMMInstalled must have been called first.
  371. ;
  372. ;  PASCAL :      Function XMMGlobalDisableA20 : Byte;
  373. ;
  374. ;  XMS :         ARGS:   AH = 04h
  375. ;                RETS:   AX = 0001h if the A20 line is disabled,
  376. ;                             0000h otherwise.
  377. ;                ERRS:   BL = 80h if the function is not implemented.
  378. ;                        BL = 81h if a VDISK device is detected.
  379. ;                        BL = 82h if an A20 error occurs.
  380. ;                        BL = 94h if the A20 line is still enabled.
  381. ;---------------------------------------------------------------------------
  382. Proc    XMMGlobalDisableA20 FAR
  383. Public  XMMGlobalDisableA20
  384.  
  385.             mov     ah,4
  386.             call    [XMM_Control]
  387.  
  388.             SuccessFail
  389.  
  390.             ret
  391.  
  392. EndP
  393.  
  394.  
  395.  
  396.  
  397. ;---------------------------------------------------------------------------
  398. ;  ROUTINE :     XMMLocalEnableA20
  399. ;
  400. ;  DESCRIPTION : Attempts to enable the A20 line.
  401. ;                It should only be used by programs which need direct
  402. ;                access to extended memory.
  403. ;                Programs which use this function should call
  404. ;                XMMLocalDisableA20 before releasing control of the
  405. ;                system.
  406. ;                NOTE: On many machines, toggling the A20 line is a
  407. ;                      relatively slow operation.
  408. ;
  409. ;  RETURNS :     XMMOk              - the A20 line is enabled.
  410. ;                XMMNotImplemented  - the function is not implemented.
  411. ;                XMMVDiskFound      - a VDISK device is detected.
  412. ;                XMMA20Err          - and A20 error occurs.
  413. ;
  414. ;  PRE :         XMMInstalled must have been called first.
  415. ;
  416. ;  PASCAL :      Function XMMLocalEnableA20 : Byte;
  417. ;
  418. ;  XMS :         ARGS:   AH = 05h
  419. ;                RETS:   AX = 0001h if the A20 line is enabled,
  420. ;                             0000h otherwise.
  421. ;                ERRS:   BL = 80h if the function is not implemented.
  422. ;                        BL = 81h if a VDISK device is detected.
  423. ;                        BL = 82h if an A20 error occurs.
  424. ;---------------------------------------------------------------------------
  425. Proc    XMMLocalEnableA20 FAR
  426. Public  XMMLocalEnableA20
  427.  
  428.             mov     ah,5
  429.             call    [XMM_Control]
  430.  
  431.  
  432.             SuccessFail
  433.  
  434.             ret
  435.  
  436. EndP
  437.  
  438.  
  439.  
  440.  
  441. ;---------------------------------------------------------------------------
  442. ;  ROUTINE :     XMMLocalDisableA20
  443. ;
  444. ;  DESCRIPTION : Cancels a previous call to XMMLocalEnableA20.
  445. ;                It should only be used by programs which need direct
  446. ;                access to extended memory.
  447. ;                Previous calls to XMMLocalEnableA20 must be canceled
  448. ;                before releasing control of the system.
  449. ;                NOTE: On many machines, toggling the A20 line is a
  450. ;                      relatively slow operation.
  451. ;
  452. ;  RETURNS :     XMMOk              - the A20 line is disabled.
  453. ;                XMMNotImplemented  - the function is not implemented.
  454. ;                XMMVDiskFound      - a VDISK device is detected.
  455. ;                XMMA20Err          - and A20 error occurs.
  456. ;                XMMA20StillEnabled - the A20 line is still enabled.
  457. ;
  458. ;  PRE :         XMMInstalled must have been called first.
  459. ;
  460. ;  PASCAL :      Function XMMLocalDisableA20 : Byte;
  461. ;
  462. ;  XMS :         ARGS:   AH = 06h
  463. ;                RETS:   AX = 0001h if the function succeeds,
  464. ;                             0000h otherwise.
  465. ;                ERRS:   BL = 80h if the function is not implemented.
  466. ;                        BL = 81h if a VDISK device is detected.
  467. ;                        BL = 82h if an A20 error occurs.
  468. ;                        BL = 94h if the A20 line is still enabled.
  469. ;---------------------------------------------------------------------------
  470. Proc    XMMLocalDisableA20 FAR
  471. Public  XMMLocalDisableA20
  472.  
  473.             mov     ah,6
  474.             call    [XMM_Control]
  475.  
  476.             SuccessFail
  477.  
  478.             ret
  479.  
  480. EndP
  481.  
  482.  
  483.  
  484.  
  485. ;---------------------------------------------------------------------------
  486. ;  ROUTINE :     XMMQueryA20
  487. ;
  488. ;  DESCRIPTION : Checks to see if the A20 line is physically enabled.
  489. ;                It does this in a hardware independent manner by
  490. ;                seeing if "memory wrap" occurs.
  491. ;
  492. ;  OUT :         A20IsOn  - False - the A20 line is not physically enabled.
  493. ;                           True  - the A20 line us physically enabled.
  494. ;
  495. ;  RETURNS :     XMMOk              - the function succeeds.
  496. ;                XMMNotImplemented  - the function is not implemented.
  497. ;                XMMVDiskFound      - a VDISK device is detected.
  498. ;
  499. ;  PRE :         XMMInstalled must have been called first.
  500. ;
  501. ;  PASCAL :      Function XMMQueryA20 (Var A20IsOn : Boolean) : Byte;
  502. ;
  503. ;  XMS :         ARGS:   AH = 07h
  504. ;                RETS:   AX = 0001h if the A20 line is physically enabled,
  505. ;                             0000h otherwise.
  506. ;                ERRS:   BL = 00h if the function succeeds.
  507. ;                        BL = 80h if the function is not implemented.
  508. ;                        BL = 81h if a VDISK device is detected.
  509. ;---------------------------------------------------------------------------
  510. Proc    XMMQueryA20 FAR A20IsOn : DWord
  511. Public  XMMQueryA20
  512.  
  513.             mov     ah,7
  514.  
  515.             call    [XMM_Control]
  516.  
  517.             les     di,[A20IsOn]
  518.             mov     [Byte Ptr es:di],al
  519.  
  520.             mov     al,bl
  521.  
  522.             ret
  523.  
  524. EndP
  525.  
  526.  
  527.  
  528.  
  529. ;---------------------------------------------------------------------------
  530. ;  ROUTINE :     XMMQueryFree
  531. ;
  532. ;  DESCRIPTION : Returns the size of the largest available extended
  533. ;                memory block and total free memory in the system.
  534. ;                NOTE: The 64K HMA is not included in the returned
  535. ;                      value even if it is not in use.
  536. ;
  537. ;  OUT :         LargestFree - Size of the largest free extended
  538. ;                              memory block in K-bytes.
  539. ;                TotalFree   - Total amount of free extended memory in
  540. ;                              K-bytes.
  541. ;
  542. ;  RETURNS :     XMMOk              - the function succeeds.
  543. ;                XMMNotImplemented  - the function is not implemented.
  544. ;                XMMVDiskFound      - a VDISK device is detected.
  545. ;                XMMOutOfMemory     - all available extended memory is
  546. ;                                     allocated.
  547. ;
  548. ;  PRE :         XMMInstalled must have been called first.
  549. ;
  550. ;  PASCAL :      Function XMMQueryFree (Var LargestFree,
  551. ;                                           TotalFree : Word): Byte;
  552. ;
  553. ;  XMS :         ARGS:   AH = 08h
  554. ;                RETS:   AX = Size of the largest free extended memory block
  555. ;                             in K-bytes.
  556. ;                        DX = Total amount of free extended memory in K-bytes.
  557. ;                ERRS:   BL = 00h if the function succeeds.
  558. ;                        BL = 80h if the function is not implemented.
  559. ;                        BL = 81h if a VDISK device is detected.
  560. ;                        BL = A0h if all extended memory is allocated.
  561. ;---------------------------------------------------------------------------
  562. Proc    XMMQueryFree FAR    LargestFree : DWord,    \
  563.                             TotalFree   : DWord
  564. Public  XMMQueryFree
  565.  
  566.             mov     ah,8
  567.  
  568.             call    [XMM_Control]
  569.  
  570.             les     di,[LargestFree]
  571.             mov     [Word ptr es:di],ax
  572.  
  573.             les     di,[TotalFree]
  574.             mov     [Word ptr es:di],dx
  575.  
  576.             mov     al,bl
  577.  
  578.             ret
  579.  
  580. EndP
  581.  
  582.  
  583.  
  584.  
  585. ;---------------------------------------------------------------------------
  586. ;  ROUTINE :     XMMAllocateEMB
  587. ;
  588. ;  DESCRIPTION : Attempts to allocate a block of the given size out of
  589. ;                the pool of free extended memory.
  590. ;                If a block is available, it is reserved for the
  591. ;                caller and a 16-bit handle to that block is returned.
  592. ;                The handle should be used in all subsequent extended
  593. ;                memory calls.
  594. ;                If no memory was allocated, the returned handle is
  595. ;                null.
  596. ;
  597. ;                NOTE: Extended memory handles are scarce resources.
  598. ;                      Programs should try to allocate as few as
  599. ;                      possible at any one time.
  600. ;                      When all of a driver's handles are in use, any
  601. ;                      free extended memory is unavailable.
  602. ;
  603. ;  IN :          BlockSize - Amount of extended memory being requested
  604. ;                            in K-bytes.
  605. ;
  606. ;  OUT :         Handle    - 16-bit handle to the allocated block.
  607. ;
  608. ;  RETURNS :     XMMOk              - the block is allocated.
  609. ;                XMMNotImplemented  - the function is not implemented.
  610. ;                XMMVDiskFound      - a VDISK device is detected.
  611. ;                XMMOutOfMemory     - all available extended memory is
  612. ;                                     allocated.
  613. ;                XMMOutOfHandles    - all available extended memory
  614. ;                                     handles are in use.
  615. ;
  616. ;  PRE :         XMMInstalled must have been called first.
  617. ;
  618. ;  PASCAL :      Function XMMAllocateEMB (    BlockSize : Word;
  619. ;                                         Var Handle    : Word) : Byte;
  620. ;
  621. ;  XMS :         ARGS:   AH = 09h
  622. ;                        DX = Amount of extended memory being requested
  623. ;                             in K-bytes.
  624. ;                RETS:   AX = 0001h if the block is allocated,
  625. ;                             0000h otherwise.
  626. ;                        DX = 16-bit handle to the allocated block.
  627. ;                ERRS:   BL = 80h if the function is not implemented.
  628. ;                        BL = 81h if a VDISK device is detected.
  629. ;                        BL = A0h if all available extended memory is
  630. ;                                 allocated.
  631. ;                        BL = A1h if all available extended memory
  632. ;                                 handles are in use.
  633. ;---------------------------------------------------------------------------
  634. Proc    XMMAllocateEMB FAR  BlockSize : Word,   \
  635.                             Handle    : DWord
  636. Public  XMMAllocateEMB
  637.  
  638.             mov     ah,9
  639.             mov     dx,[BlockSize]
  640.  
  641.             call    [XMM_Control]
  642.  
  643.             les     di,[Handle]
  644.             mov     [Word ptr es:di],dx
  645.  
  646.             SuccessFail
  647.  
  648.             ret
  649.  
  650. EndP
  651.  
  652.  
  653.  
  654.  
  655. ;---------------------------------------------------------------------------
  656. ;  ROUTINE :     XMMFreeEMB
  657. ;
  658. ;  DESCRIPTION : This function frees a block of extended memory which
  659. ;                was previously allocated using XMMAllocateEMB.
  660. ;                Programs which allocate extended memory should free
  661. ;                their memory blocks before exiting.
  662. ;                When an extended memory buffer is freed, its handle
  663. ;                and all data stored in it become invalid and should
  664. ;                not be accessed.
  665. ;
  666. ;  IN :          Handle - 16-bit handle to the allocated block which
  667. ;                         should be freed.
  668. ;
  669. ;  RETURNS :     XMMOk              - the block is allocated.
  670. ;                XMMNotImplemented  - the function is not implemented.
  671. ;                XMMVDiskFound      - a VDISK device is detected.
  672. ;                XMMInvalidHandle   - the handle is invalid.
  673. ;                XMMEMBLocked       - the block is locked.
  674. ;
  675. ;  PRE :         XMMInstalled must have been called first.
  676. ;
  677. ;  PASCAL :      Function XMMFreeEMB (Handle : Word) : Byte;
  678. ;
  679. ;  XMS :         ARGS:   AH = 0Ah
  680. ;                        DX = Handle to the allocated block which should
  681. ;                             be freed.
  682. ;                RETS:   AX = 0001h if the block is successfully freed,
  683. ;                             0000h otherwise.
  684. ;                ERRS:   BL = 80h if the function is not implemented.
  685. ;                        BL = 81h if a VDISK device is detected.
  686. ;                        BL = A2h if the handle is invalid.
  687. ;                        BL = ABh if the handle is locked.
  688. ;---------------------------------------------------------------------------
  689. Proc    XMMFreeEMB FAR  Handle : Word
  690. Public  XMMFreeEMB
  691.  
  692.             mov     ah,0Ah
  693.             mov     dx,[Handle]
  694.  
  695.             call    [XMM_Control]
  696.  
  697.  
  698.             SuccessFail
  699.  
  700.             ret
  701.  
  702. EndP
  703.  
  704.  
  705.  
  706.  
  707. ;---------------------------------------------------------------------------
  708. ;  ROUTINE :     XMMMoveEMB
  709. ;
  710. ;  DESCRIPTION : This function attempts to transfer a block of data
  711. ;                from one location to another.
  712. ;                It is primarily intended for moving blocks of data
  713. ;                between conventional memory and extended memory,
  714. ;                however it can be used for moving blocks within
  715. ;                conventional memory and within extended memory.
  716. ;
  717. ;                NOTE: If SourceHandle is set to 0000h, the
  718. ;                      SourceOffset is interpreted as a standard
  719. ;                      segment:offset pair which refers to memory that
  720. ;                      is directly accessible by the processor.
  721. ;                      The segment:offset pair is stored in Intel
  722. ;                      DWORD notation.  The same is true for
  723. ;                      DestHandle and DestOffset.
  724. ;
  725. ;                SourceHandle and DestHandle do not have to refer to
  726. ;                locked memory blocks.
  727. ;
  728. ;                Length must be even.  Although not required,
  729. ;                WORD-aligned moves can be significantly faster on
  730. ;                most machines. DWORD aligned move can be even faster
  731. ;                on 80386 machines.
  732. ;
  733. ;                If the source and destination blocks overlap, only
  734. ;                forward moves (i.e. where the source base is greater ????
  735. ;                than the destination base) are guaranteed to work
  736. ;                properly.
  737. ;
  738. ;                Programs should not enable the A20 line before
  739. ;                calling this function.  The state of the A20 line is
  740. ;                preserved.
  741. ;
  742. ;                This function is guaranteed to provide a reasonable
  743. ;                number of interrupt windows during long transfers.
  744. ;
  745. ;                The MoveStruc is a structure of type ExtMemMoveRec which
  746. ;                is defined as follows :
  747. ;
  748. ;                  ExtMemMoveRec Record Case Boolean of
  749. ;                    False :
  750. ;                     (Length       : Longint; number of bytes to transfer
  751. ;                      SourceHandle : Word;    Handle of source block
  752. ;                      SourceOffset : Longint; offset into source
  753. ;                      DestHandle   : Word;    Handle of destination block
  754. ;                      DestOffset   : Longint; offset into dest block
  755. ;                     );
  756. ;                   True :
  757. ;                     (TheLenght    : Longint; lenght must be even !
  758. ;                      ZeroSource   : Word;    zero sourcehandle means a
  759. ;                      SourcePtr    : Pointer; ptr to "normal" memory
  760. ;                      ZeroDest     : Word;    zero dest handle means a
  761. ;                      DestPtr      : Pointer; ptr to "normal" memory
  762. ;                     );
  763. ;                  End; (* ExtMemMoveRec *)
  764. ;
  765. ;  IN :          MoveStruc - Pointer to an Extended Memory Move
  766. ;                            Structure (see above).
  767. ;
  768. ;  RETURNS :     XMMOk              - the move is successful.
  769. ;                XMMNotImplemented  - the function is not implemented.
  770. ;                XMMVDiskFound      - a VDISK device is detected.
  771. ;                XMMA20Err          - an A20 error occurs.
  772. ;                XMMSourceHanldeInv - the SourceHandle is invalid.
  773. ;                XMMSourceOffsetInv - the SourceOffset is invalid.
  774. ;                XMMDestHanleInv    - the DestHandle is invalid.
  775. ;                XMMDestOffset      - the DestOffset is invalid.
  776. ;                XMMLenInv          - the Length is invalid.
  777. ;                XMMOverlap         - the move has an invalid overlap.
  778. ;                XMMParity          - a parity error occurs.
  779. ;
  780. ;  PRE :         XMMInstalled must have been called first.
  781. ;
  782. ;  PASCAL :      Function XMMMoveEMB (MoveRec : XMMMoveRec) : Byte;
  783. ;
  784. ;  XMS :         ARGS:   AH = 0Bh
  785. ;                        DS:SI = Pointer to an Extended Memory Move Structure.
  786. ;                RETS:   AX = 0001h if the move is successful,
  787. ;                             0000h otherwise.
  788. ;                ERRS:   BL = 80h if the function is not implemented.
  789. ;                        BL = 81h if a VDISK device is detected.
  790. ;                        BL = 82h if an A20 error occurs.
  791. ;                        BL = A3h if the SourceHandle is invalid.
  792. ;                        BL = A4h if the SourceOffset is invalid.
  793. ;                        BL = A5h if the DestHandle is invalid.
  794. ;                        BL = A6h if the DestOffset is invalid.
  795. ;                        BL = A7h if the Length is invalid.
  796. ;                        BL = A8h if the move has an invalid overlap.
  797. ;                        BL = A9h if a parity error occurs.
  798. ;---------------------------------------------------------------------------
  799. Struc   XMMMoveRec
  800.     Length              dd  ?   ; 32-bit number of bytes to transfer
  801.     SourceHandle        dw  ?   ; Handle of source block
  802.     SourceOffset        dd  ?   ; 32-bit offset into source
  803.     DestHandle          dw  ?   ; Handle of destination block
  804.     DestOffset          dd  ?   ; 32-bit offset into destination block
  805. EndS
  806.  
  807. Proc    XMMMoveEMB FAR  MoveRec : XMMMoveRec
  808. Public  XMMMoveEMB
  809.  
  810.             push    ds
  811.  
  812.             mov     ah,0Bh
  813.             push    ss
  814.             pop     ds
  815.             lea     si,[MoveRec]                ; DS:SI => Description
  816.  
  817.             call    [XMM_Control]
  818.  
  819.             SuccessFail
  820.  
  821.             pop     ds
  822.  
  823.             ret
  824.  
  825. EndP
  826.  
  827.  
  828.  
  829.  
  830. ;---------------------------------------------------------------------------
  831. ;  ROUTINE :     XMMLockEMB
  832. ;
  833. ;  DESCRIPTION : Locks an extended memory block and returns its base
  834. ;                address as a 32-bit linear address.
  835. ;                Locked memory blocks are guaranteed not to move.
  836. ;                The 32-bit pointer is only valid while the block is
  837. ;                locked because unlocked blocks may be moved by the
  838. ;                XMS driver.
  839. ;                Locked blocks should be unlocked as soon as possible.
  840. ;
  841. ;                NOTE: A block does not have to be locked before using
  842. ;                      XMMMoveEMB.
  843. ;
  844. ;                "Lock counts" are maintained for EMBs.
  845. ;
  846. ;  IN :          Handle - Extended memory block handle to lock.
  847. ;
  848. ;  OUT :         Linear - 32-bit linear address of the locked block.
  849. ;
  850. ;  RETURNS :     XMMOk              - the block is locked.
  851. ;                XMMNotImplemented  - the function is not implemented.
  852. ;                XMMVDiskFound      - a VDISK device is detected.
  853. ;                XMMInvalidHandle   - the handle is invalid.
  854. ;                XMMLockOverflow    - the block's lock count overflows.
  855. ;                XMMLockFail        - the lock fails.
  856. ;
  857. ;  PRE :         XMMInstalled must have been called first.
  858. ;
  859. ;  PASCAL :      Function XMMLockEMB (    Handle : Word;
  860. ;                                     Var Linear : Longint) : Byte;
  861. ;
  862. ;  XMS :         ARGS:   AH = 0Ch
  863. ;                        DX = Extended memory block handle to lock
  864. ;                RETS:   AX = 0001h if the block is locked,
  865. ;                             0000h otherwise.
  866. ;                        DX:BX = 32-bit linear address of the locked block.
  867. ;                ERRS:   BL = 80h if the function is not implemented.
  868. ;                        BL = 81h if a VDISK device is detected.
  869. ;                        BL = A2h if the handle is invalid.
  870. ;                        BL = ACh if the block's lock count overflows.
  871. ;                        BL = ADh if the lock fails.
  872. ;---------------------------------------------------------------------------
  873. Proc    XMMLockEMB FAR  Handle : Word,  \
  874.                         Linear : DWord
  875. Public  XMMLockEMB
  876.  
  877.             mov     ah,0Ch
  878.             mov     dx,[Handle]
  879.  
  880.             call    [XMM_Control]
  881.  
  882.             les     di,[Linear]
  883.             mov     [Word ptr es:di],bx         ; low word
  884.             mov     [word ptr es:di+2],dx       ; high word
  885.  
  886.             SuccessFail
  887.  
  888.             ret
  889.  
  890. EndP
  891.  
  892.  
  893.  
  894.  
  895. ;---------------------------------------------------------------------------
  896. ;  ROUTINE :     XMMUnLockEMB
  897. ;
  898. ;  DESCRIPTION : Unlocks a locked extended memory block.  Any 32-bit
  899. ;                pointers into the block become invalid and should no
  900. ;                longer be used.
  901. ;
  902. ;  IN :          Handle - Extended memory block handle to unlock.
  903. ;
  904. ;  RETURNS :     XMMOk              - the block is unlocked.
  905. ;                XMMNotImplemented  - the function is not implemented.
  906. ;                XMMVDiskFound      - a VDISK device is detected.
  907. ;                XMMInvalidHandle   - the handle is invalid.
  908. ;                XMMEMBUnlocked     - the block is not locked.
  909. ;
  910. ;  PRE :         XMMInstalled must have been called first.
  911. ;
  912. ;  PASCAL :      Function XMMUnLockEMB (Handle : Word) : Byte;
  913. ;
  914. ;  XMS :         ARGS:   AH = 0Dh
  915. ;                        DX = Extended memory block handle to unlock.
  916. ;                RETS:   AX = 0001h if the block is unlocked,
  917. ;                             0000h otherwise.
  918. ;                ERRS:   BL = 80h if the function is not implemented.
  919. ;                        BL = 81h if a VDISK device is detected.
  920. ;                        BL = A2h if the handle is invalid.
  921. ;                        BL = AAh if the block is not locked.
  922. ;---------------------------------------------------------------------------
  923. Proc    XMMUnLockEMB FAR    Handle : Word
  924. Public  XMMUnLockEMB
  925.  
  926.             mov     ah,0Dh
  927.             mov     dx,[Handle]
  928.  
  929.             call    [XMM_Control]
  930.  
  931.             SuccessFail
  932.  
  933.             ret
  934.  
  935. EndP
  936.  
  937.  
  938.  
  939.  
  940. ;---------------------------------------------------------------------------
  941. ;  ROUTINE :     XMMGetHandleInfo
  942. ;
  943. ;  DESCRIPTION : Returns additional information about an extended
  944. ;                memory block to the caller.
  945. ;
  946. ;                NOTE: To get the block's base address, use XMMLockEMB.
  947. ;
  948. ;  IN :          Handle      - Extended memory block handle.
  949. ;
  950. ;  OUT :         LockCount   - The block's lock count.
  951. ;                FreeHandles - Number of free EMB handles in the system.
  952. ;                BlockLength - The block's length in K-bytes.
  953. ;
  954. ;
  955. ;  RETURNS :     XMMOk              - the block's information is found.
  956. ;                XMMNotImplemented  - the function is not implemented.
  957. ;                XMMVDiskFound      - a VDISK device is detected.
  958. ;                XMMInvalidHandle   - the handle is invalid.
  959. ;
  960. ;  PRE :         XMMInstalled must have been called first.
  961. ;
  962. ;  PASCAL :      Function XMMGetHandleInfo (    Handle      : Word;
  963. ;                                           Var LockCount,
  964. ;                                               FreeHandles : Byte;
  965. ;                                           Var BlockLength : Word) : Byte;
  966. ;
  967. ;  XMS :         ARGS:   AH = 0Eh
  968. ;                        DX = Extended memory block handle
  969. ;                RETS:   AX = 0001h if the block's information is found,
  970. ;                             0000h otherwise.
  971. ;                        BH = The block's lock count.
  972. ;                        BL = Number of free EMB handles in the system.
  973. ;                        DX = The block's length in K-bytes.
  974. ;                ERRS:   BL = 80h if the function is not implemented.
  975. ;                        BL = 81h if a VDISK device is detected.
  976. ;                        BL = A2h if the handle is invalid.
  977. ;---------------------------------------------------------------------------
  978. Proc    XMMGetHandleInfo FAR    Handle      : Word,     \
  979.                                 LockCount   : DWord,    \
  980.                                 FreeHandles : DWord,    \
  981.                                 BlockLength : DWord
  982. Public  XMMGetHandleInfo
  983.  
  984.             mov     ah,0Eh
  985.             mov     dx,[Handle]
  986.  
  987.             call    [XMM_Control]
  988.  
  989.             les     di,[LockCount]
  990.             mov     [Byte ptr es:di],bh
  991.  
  992.             les     di,[FreeHandles]
  993.             mov     [Byte ptr es:di],bl
  994.  
  995.             les     di,[BlockLength]
  996.             mov     [Word ptr es:di],dx
  997.  
  998.             SuccessFail
  999.  
  1000.             ret
  1001.  
  1002. EndP
  1003.  
  1004.  
  1005.  
  1006.  
  1007. ;---------------------------------------------------------------------------
  1008. ;  ROUTINE :     XMMReallocateEMB
  1009. ;
  1010. ;  DESCRIPTION : Attempts to reallocate an unlocked extended memory
  1011. ;                block so that it becomes the newly specified size.
  1012. ;                If the new size is smaller than the old block's size,
  1013. ;                all data at the upper end of the old block is lost.
  1014. ;
  1015. ;  IN :          Handle  - Unlocked extended memory block handle to
  1016. ;                          reallocate.
  1017. ;                NewSize - New size for the extended memory block in
  1018. ;                          K-bytes.
  1019. ;
  1020. ;  RETURNS :     XMMOk              - the block is reallocated.
  1021. ;                XMMNotImplemented  - the function is not implemented.
  1022. ;                XMMVDiskFound      - a VDISK device is detected.
  1023. ;                XMMOutOfMemory     - all available extended memory is
  1024. ;                                     allocated.
  1025. ;                XMMOutOfHandles    - all available extended memory
  1026. ;                                     handles are in use.
  1027. ;                XMMInvalidHandle   - the handle is invalid.
  1028. ;                XMMEMBLocked       - the block is locked.
  1029. ;
  1030. ;  PRE :         XMMInstalled must have been called first.
  1031. ;
  1032. ;  PASCAL :      Function XMMReallocateEMB (Handle,
  1033. ;                                           NewSize : Word) : Byte;
  1034. ;
  1035. ;  XMS :         ARGS:   AH = 0Fh
  1036. ;                        BX = New size for the extended memory block
  1037. ;                             in K-bytes.
  1038. ;                        DX = Unlocked extended memory block handle to
  1039. ;                             reallocate.
  1040. ;                RETS:   AX = 0001h if the block is reallocated,
  1041. ;                             0000h otherwise.
  1042. ;                ERRS:   BL = 80h if the function is not implemented.
  1043. ;                        BL = 81h if a VDISK device is detected.
  1044. ;                        BL = A0h if all available extended memory is
  1045. ;                                 allocated.
  1046. ;                        BL = A1h if all available extended memory
  1047. ;                                 handles are in use.
  1048. ;                        BL = A2h if the handle is invalid.
  1049. ;                        BL = ABh if the block is locked.
  1050. ;---------------------------------------------------------------------------
  1051. Proc    XMMReallocateEMB FAR    Handle  : Word, \
  1052.                                 NewSize : Word
  1053. Public  XMMReallocateEMB
  1054.  
  1055.             mov     ah,0Fh
  1056.             mov     dx,[Handle]
  1057.             mov     bx,[NewSize]
  1058.  
  1059.             call    [XMM_Control]
  1060.  
  1061.             SuccessFail
  1062.  
  1063.             ret
  1064.  
  1065. EndP
  1066.  
  1067.  
  1068.  
  1069.  
  1070. ;---------------------------------------------------------------------------
  1071. ;  ROUTINE :     XMMRequestUMB
  1072. ;
  1073. ;  DESCRIPTION : Attempts to allocate an upper memory block to the
  1074. ;                caller. If the function fails, the size of the
  1075. ;                largest free UMB is returned in DX.
  1076. ;
  1077. ;                NOTE: By definition UMBs are located below the 1MB
  1078. ;                      address boundary.
  1079. ;                      The A20 Line does not need to be enabled before
  1080. ;                      accessing an allocated UMB.
  1081. ;                      This function does not need to be implemented
  1082. ;                      by an XMS driver.
  1083. ;
  1084. ;                UMBs are paragraph aligned.
  1085. ;
  1086. ;                To determine the size of the largest available UMB,
  1087. ;                attempt to allocate one with a size of FFFFh.
  1088. ;
  1089. ;                UMBs are unaffected by EMS calls.
  1090. ;
  1091. ;  IN :          RequestSize - Size of requested memory block in
  1092. ;                              paragraphs (one paragraph is 16 bytes).
  1093. ;
  1094. ;  OUT :         UMBSeg      - Segment number of the upper memory block.
  1095. ;                BlockSize   - If the request is granted, actual size
  1096. ;                              in paragraphs of the allocated block in
  1097. ;                              paragraphs.
  1098. ;                              Otherwise, size of the largest
  1099. ;                              available UMB in paragraphs.
  1100. ;
  1101. ;  RETURNS :     XMMOk              - the request is granted.
  1102. ;                XMMNotImplemented  - the function is not implemented.
  1103. ;                XMMUMBSizeTooBig   - a smaller UMB is available.
  1104. ;                XMMNoUMBs          - no UMBs are available.
  1105. ;
  1106. ;  PRE :         XMMInstalled must have been called first.
  1107. ;
  1108. ;  PASCAL :      Function XMMRequestUMB (    RequestSize : Word;
  1109. ;                                        Var UMBSeg,
  1110. ;                                            BlockSize   : Word) : Byte;
  1111. ;
  1112. ;  XMS :         ARGS:   AH = 10h
  1113. ;                        DX = Size of requested memory block in paragraphs.
  1114. ;                RETS:   AX = 0001h if the request is granted,
  1115. ;                             0000h otherwise.
  1116. ;                        BX = Segment number of the upper memory block.
  1117. ;                        If the request is granted,
  1118. ;                            DX = Actual size of the allocated block
  1119. ;                                 in paragraphs.
  1120. ;                        otherwise,
  1121. ;                            DX = Size of the largest available UMB
  1122. ;                                 in paragraphs.
  1123. ;                ERRS:   BL = 80h if the function is not implemented.
  1124. ;                        BL = B0h if a smaller UMB is available.
  1125. ;                        BL = B1h if no UMBs are available.
  1126. ;---------------------------------------------------------------------------
  1127. Proc    XMMRequestUMB FAR   RequestSize : Word,     \
  1128.                             UMBSeg      : DWord,    \
  1129.                             BlockSize   : DWord
  1130. Public  XMMRequestUMB
  1131.  
  1132.             mov     ah,10h
  1133.             mov     dx,[RequestSize]
  1134.  
  1135.             call    [XMM_Control]
  1136.  
  1137.             les     di,[UMBSeg]
  1138.             mov     [Word ptr es:di],bx
  1139.  
  1140.             les     di,[BlockSize]
  1141.             mov     [Word ptr es:di],dx
  1142.  
  1143.             SuccessFail
  1144.  
  1145.             ret
  1146.  
  1147. EndP
  1148.  
  1149.  
  1150.  
  1151.  
  1152. ;---------------------------------------------------------------------------
  1153. ;  ROUTINE :     XMMReleaseUMB
  1154. ;
  1155. ;  DESCRIPTION : This function frees a previously allocated upper
  1156. ;                memory block.
  1157. ;                When an UMB has been released, any code or data
  1158. ;                stored in it becomes invalid and should not be
  1159. ;                accessed.
  1160. ;
  1161. ;                NOTE: This function does not need to be implemented
  1162. ;                      by an XMS driver.
  1163. ;
  1164. ;  IN :          UMBSeg - Segment number of the upper memory block.
  1165. ;
  1166. ;  RETURNS :     XMMOk              - the block was released.
  1167. ;                XMMNotImplemented  - the function is not implemented.
  1168. ;                XMMInvalidUMB      - the UMB segment number is invalid.
  1169. ;
  1170. ;  PRE :         XMMInstalled must have been called first.
  1171. ;
  1172. ;  PASCAL :      Function XMMReleaseUMB (UMBSeg : Word) : Byte;
  1173. ;
  1174. ;  XMS :         ARGS:   AH = 11h
  1175. ;                        DX = Segment number of the upper memory block.
  1176. ;                RETS:   AX = 0001h if the block was released,
  1177. ;                             0000h otherwise.
  1178. ;                ERRS:   BL = 80h if the function is not implemented.
  1179. ;                        BL = B2h if the UMB segment number is invalid.
  1180. ;---------------------------------------------------------------------------
  1181. Proc    XMMReleaseUMB FAR   UMBSeg : Word
  1182. Public  XMMReleaseUMB
  1183.  
  1184.             mov     ah,11h
  1185.             mov     dx,[UMBSeg]
  1186.  
  1187.             call    [XMM_Control]
  1188.  
  1189.             SuccessFail
  1190.  
  1191.             ret
  1192.  
  1193. EndP
  1194.  
  1195.  
  1196.  
  1197.  
  1198. ;---------------------------------------------------------------------------
  1199. ;  ROUTINE :     XMMReallocateUMB
  1200. ;
  1201. ;  DESCRIPTION : This function attempts to reallocate an Upper Memory
  1202. ;                Block to a newly specified size. If the new size is
  1203. ;                smaller than the old block's size, all data at the
  1204. ;                upper end of the block is lost.
  1205. ;
  1206. ;                NOTE: This function does not need to be implemented
  1207. ;                      by an XMS driver.
  1208. ;
  1209. ;  IN :          UMBSeg - Segment number of the upper memory block.
  1210. ;
  1211. ;  RETURNS :     XMMOk              - the block was released.
  1212. ;                XMMNotImplemented  - the function is not implemented.
  1213. ;                XMMUMBSizeTooBig   - a smaller UMB is available.
  1214. ;                XMMInvalidUMB      - the UMB segment number is invalid.
  1215. ;
  1216. ;  PRE :         XMMInstalled must have been called first.
  1217. ;
  1218. ;  PASCAL :      Function XMMReallocateUMB (RequestSize : Word;
  1219. ;                                           UMBSeg : Word) : Byte;
  1220. ;
  1221. ;                ARGS:   AH = 12h
  1222. ;                        BX = New size for UMB in paragraphs
  1223. ;                        DX = Segment number of the UMB to reallocate
  1224. ;
  1225. ;                RETS:   AX = 1 if the block was reallocated, 0 otherwise
  1226. ;
  1227. ;                ERRS:   BL = 80h if the function is not implemented.
  1228. ;                        BL = B0h if no UMB large enough to satisfy the
  1229. ;                                 request is available.
  1230. ;                                 In this event, DX is returned with the size
  1231. ;                                 of the largest UMB that is available.
  1232. ;                        BL = B2h if the UMB segment number is invalid.
  1233. ;---------------------------------------------------------------------------
  1234. Proc    XMMReallocateUMB FAR   RequestSize : Word,     \
  1235.                                UMBSeg      : Word
  1236. Public  XMMReallocateUMB
  1237.  
  1238.             mov     ah,12h
  1239.             mov     bx,[RequestSize]
  1240.             mov     dx,[UMBSeg]
  1241.  
  1242.             call    [XMM_Control]
  1243.  
  1244.             SuccessFail
  1245.  
  1246.             ret
  1247.  
  1248. EndP
  1249.  
  1250.  
  1251.  
  1252.  
  1253. P386N  ; code below only works on 386 processors
  1254.  
  1255.  
  1256.  
  1257.  
  1258. ;---------------------------------------------------------------------------
  1259. ;  ROUTINE :     XMMQueryAnyFree
  1260. ;
  1261. ;  DESCRIPTION : This function uses 32-bit values to return the size of
  1262. ;                available memory, thus allowing returns up to 4GByte.
  1263. ;                Additionally, it returns the highest known physical
  1264. ;                memory address, that is, the physical address of the
  1265. ;                last byte of memory.  There may be discontinuities in
  1266. ;                the memory map below this address.
  1267. ;
  1268. ;                The memory pool reported on is the same as that
  1269. ;                reported on by the existing Query Free Extended Memory
  1270. ;                function 08h.  If the highest memory address is not
  1271. ;                more than 64 Mb, then these two functions will return
  1272. ;                the same results.
  1273. ;
  1274. ;                Because of its reliance on 32-bit registers, this
  1275. ;                function is only available on 80386 and higher
  1276. ;                processors.  XMS drivers on 80286 machines should
  1277. ;                return error code 80h if this function is called.
  1278. ;
  1279. ;                If error code 81h is returned, the value in ECX will
  1280. ;                still be valid.  If error code A0h is returned, EAX and
  1281. ;                EDX will be 0, and ECX will still be valid.
  1282. ;
  1283. ;  OUT :         LargestFree - Size of the largest free extended
  1284. ;                              memory block in K-bytes.
  1285. ;                LastByte    - Physical address of the last byte in memory.
  1286. ;                TotalFree   - Total amount of free extended memory in
  1287. ;                              K-bytes.
  1288. ;
  1289. ;  RETURNS :     XMMOk              - the function succeeds.
  1290. ;                XMMNotImplemented  - the function is not implemented.
  1291. ;                XMMVDiskFound      - a VDISK device is detected.
  1292. ;                XMMOutOfMemory     - all available extended memory is
  1293. ;                                     allocated.
  1294. ;
  1295. ;  PRE :         XMMInstalled must have been called first.
  1296. ;
  1297. ;  PASCAL :      Function XMMQueryAnyFree (Var LargestFree,
  1298. ;                                              LastByte,
  1299. ;                                              TotalFree : LongInt): Byte;
  1300. ;
  1301. ;  XMS :         ARGS:   AH = 88h
  1302. ;                RETS:   AX = Size of the largest free extended memory block
  1303. ;                             in K-bytes.
  1304. ;                        DX = Total amount of free extended memory in K-bytes.
  1305. ;                RETS:   EAX = Size of largest free extended memory block in Kb.
  1306. ;                        BL = 0 if no error occurs, otherwise it takes an error code.
  1307. ;                        ECX = Highest ending address of any memory block.
  1308. ;                        EDX = Total amount of free memory in Kb.
  1309. ;
  1310. ;                ERRS:   BL = 00h if the function succeeds.
  1311. ;                        BL = 80h if the function is not implemented.
  1312. ;                        BL = 81h if a VDISK device is detected.
  1313. ;                        BL = A0h if all extended memory is allocated.
  1314. ;---------------------------------------------------------------------------
  1315. Proc    XMMQueryAnyFree FAR LargestFree : DWord,    \
  1316.                             LastByte    : DWord,    \
  1317.                             TotalFree   : DWord
  1318. Public  XMMQueryAnyFree
  1319.  
  1320.             mov     ah,88h
  1321.  
  1322.             call    [XMM_Control]
  1323.  
  1324.             les     di,[LargestFree]
  1325.             mov     [DWord ptr es:di],eax
  1326.  
  1327.             les     di,[LastByte]
  1328.             mov     [DWord ptr es:di],ecx
  1329.  
  1330.             les     di,[TotalFree]
  1331.             mov     [DWord ptr es:di],edx
  1332.  
  1333.             mov     al,bl
  1334.  
  1335.             ret
  1336.  
  1337. EndP
  1338.  
  1339.  
  1340.  
  1341.  
  1342. ;---------------------------------------------------------------------------
  1343. ;  ROUTINE :     XMMAllocateAnyEMB
  1344. ;
  1345. ;  DESCRIPTION : This function is similar to the existing Allocate
  1346. ;                Extended Memory 09h, except that it uses a 32-bit
  1347. ;                instead of a 16-bit value to specify the amount of
  1348. ;                memory requested.  It allocates from the same memory
  1349. ;                and handle pool as the current function.
  1350. ;
  1351. ;                Since it requires a 32-bit register, this function can
  1352. ;                be supported only on 80386 and higher processors, and
  1353. ;                XMS drivers on 80286 machines should return error code
  1354. ;                80h.
  1355. ;
  1356. ;  IN :          BlockSize - Amount of extended memory being requested
  1357. ;                            in K-bytes.
  1358. ;
  1359. ;  OUT :         Handle    - 16-bit handle to the allocated block.
  1360. ;
  1361. ;  RETURNS :     XMMOk              - the block is allocated.
  1362. ;                XMMNotImplemented  - the function is not implemented.
  1363. ;                XMMVDiskFound      - a VDISK device is detected.
  1364. ;                XMMOutOfMemory     - all available extended memory is
  1365. ;                                     allocated.
  1366. ;                XMMOutOfHandles    - all available extended memory
  1367. ;                                     handles are in use.
  1368. ;
  1369. ;  PRE :         XMMInstalled must have been called first.
  1370. ;
  1371. ;  PASCAL :      Function XMMAllocateAnyEMB (    BlockSize : Longint;
  1372. ;                                            Var Handle    : Word) : Byte;
  1373. ;
  1374. ;  XMS :         ARGS:   AH = 89h
  1375. ;                        EDX = Amount of extended memory being requested
  1376. ;                             in K-bytes.
  1377. ;                RETS:   AX = 0001h if the block is allocated,
  1378. ;                             0000h otherwise.
  1379. ;                        DX = 16-bit handle to the allocated block.
  1380. ;                ERRS:   BL = 80h if the function is not implemented.
  1381. ;                        BL = 81h if a VDISK device is detected.
  1382. ;                        BL = A0h if all available extended memory is
  1383. ;                                 allocated.
  1384. ;                        BL = A1h if all available extended memory
  1385. ;                                 handles are in use.
  1386. ;---------------------------------------------------------------------------
  1387. Proc    XMMAllocateAnyEMB FAR  BlockSize : DWord,   \
  1388.                                Handle    : DWord
  1389. Public  XMMAllocateAnyEMB
  1390.  
  1391.             mov     ah,89h
  1392.             mov     edx,[BlockSize]
  1393.  
  1394.             call    [XMM_Control]
  1395.  
  1396.             les     di,[Handle]
  1397.             mov     [Word ptr es:di],dx
  1398.  
  1399.             SuccessFail
  1400.  
  1401.             ret
  1402.  
  1403. EndP
  1404.  
  1405.  
  1406.  
  1407.  
  1408. ;---------------------------------------------------------------------------
  1409. ;  ROUTINE :     XMMGetExtendedHandleInfo
  1410. ;
  1411. ;  DESCRIPTION : This function is similar to the Get EMB Handle
  1412. ;                Information function. Since it uses a 32-bit register
  1413. ;                to report the block size, it can be used to get
  1414. ;                information on blocks larger than 64 Mb.  It also uses
  1415. ;                a 16-bit instead of 8-bit register to report the number
  1416. ;                of free handles, allowing the handle pool to be
  1417. ;                extended beyond 256 entries.
  1418. ;
  1419. ;                Because of its reliance on a 32-bit register, this
  1420. ;                function is available on 80386 and higher processors.
  1421. ;                XMS drivers on 80286 machines should return error code
  1422. ;                80h if this function is called.
  1423. ;
  1424. ;  IN :          Handle      - Extended memory block handle.
  1425. ;
  1426. ;  OUT :         LockCount   - The block's lock count.
  1427. ;                FreeHandles - Number of free EMB handles in the system.
  1428. ;                BlockLength - The block's length in K-bytes.
  1429. ;
  1430. ;
  1431. ;  RETURNS :     XMMOk              - the block's information is found.
  1432. ;                XMMNotImplemented  - the function is not implemented.
  1433. ;                XMMVDiskFound      - a VDISK device is detected.
  1434. ;                XMMInvalidHandle   - the handle is invalid.
  1435. ;
  1436. ;  PRE :         XMMInstalled must have been called first.
  1437. ;
  1438. ;  PASCAL :      Function XMMGetExtendedHandleInfo (    Handle      : Word;
  1439. ;                                                   Var LockCount   : Byte;
  1440. ;                                                   Var FreeHandles : Word;
  1441. ;                                                   Var BlockLength : Longint) : Byte;
  1442. ;
  1443. ;  XMS :         ARGS:   AH = 8Eh
  1444. ;                        DX = Extended memory block handle.
  1445. ;
  1446. ;                RETS:   AX = 1 if the block's information is found, 0 if not
  1447. ;                        BH = Block lock count
  1448. ;                        CX = Number of free EMB handles in the system
  1449. ;                        EDX = Block's length in Kb.
  1450. ;
  1451. ;                ERRS:   BL = 80h if the function is not implemented.
  1452. ;                        BL = 81h if a VDISK device is detected.
  1453. ;                        BL = A2h if the handle is invalid.
  1454. ;---------------------------------------------------------------------------
  1455. Proc    XMMGetExtendedHandleInfo FAR    Handle      : Word,     \
  1456.                                         LockCount   : DWord,    \
  1457.                                         FreeHandles : DWord,    \
  1458.                                         BlockLength : DWord
  1459. Public  XMMGetExtendedHandleInfo
  1460.  
  1461.             mov     ah,8Eh
  1462.             mov     dx,[Handle]
  1463.  
  1464.             call    [XMM_Control]
  1465.  
  1466.             les     di,[LockCount]
  1467.             mov     [Byte ptr es:di],bh
  1468.  
  1469.             les     di,[FreeHandles]
  1470.             mov     [Word ptr es:di],cx
  1471.  
  1472.             les     di,[BlockLength]
  1473.             mov     [DWord ptr es:di],edx
  1474.  
  1475.             SuccessFail
  1476.  
  1477.             ret
  1478.  
  1479. EndP
  1480.  
  1481.  
  1482.  
  1483.  
  1484. ;---------------------------------------------------------------------------
  1485. ;  ROUTINE :     XMMReallocateAnyEMB
  1486. ;
  1487. ;  DESCRIPTION : This function is similar to the existing Reallocate
  1488. ;                Extended Memory, except that it uses a 32-bit instead
  1489. ;                of a 16-bit value to specify the amount of memory
  1490. ;                requested.  It allocates from the same memory and
  1491. ;                handle pool as the current function.
  1492. ;
  1493. ;                Since it requires a 32-bit register, this function can
  1494. ;                be supported only on 80386 and higher processors, and
  1495. ;                XMS drivers on 80286 machines should return error code
  1496. ;                80h.
  1497. ;
  1498. ;  IN :          Handle  - Unlocked extended memory block handle to
  1499. ;                          reallocate.
  1500. ;                NewSize - New size for the extended memory block in
  1501. ;                          K-bytes.
  1502. ;
  1503. ;  RETURNS :     XMMOk              - the block is reallocated.
  1504. ;                XMMNotImplemented  - the function is not implemented.
  1505. ;                XMMVDiskFound      - a VDISK device is detected.
  1506. ;                XMMOutOfMemory     - all available extended memory is
  1507. ;                                     allocated.
  1508. ;                XMMOutOfHandles    - all available extended memory
  1509. ;                                     handles are in use.
  1510. ;                XMMInvalidHandle   - the handle is invalid.
  1511. ;                XMMEMBLocked       - the block is locked.
  1512. ;
  1513. ;  PRE :         XMMInstalled must have been called first.
  1514. ;
  1515. ;  PASCAL :      Function XMMReallocateAnyEMB (Handle,
  1516. ;                                              NewSize : Longint) : Byte;
  1517. ;
  1518. ;  XMS :         ARGS:   AH = 8Fh
  1519. ;                        EBX = New size for extended memory block, in Kb.
  1520. ;                        DX = Unlocked handle for memory block to be resized.
  1521. ;
  1522. ;                RETS:   AX = 1 if the block is reallocated, 0 if not
  1523. ;
  1524. ;                ERRS:   BL = 80h if the function is not implemented.
  1525. ;                        BL = 81h if a VDISK device is detected.
  1526. ;                        BL = A0h if all available extended memory is allocated.
  1527. ;                        BL = A1h if all available extended memory handles are in use.
  1528. ;                        BL = A2h if the handle is invalid.
  1529. ;                        BL = ABh if the block is locked.
  1530. ;---------------------------------------------------------------------------
  1531. Proc    XMMReallocateAnyEMB FAR    Handle  : Word, \
  1532.                                    NewSize : DWord
  1533. Public  XMMReallocateAnyEMB
  1534.  
  1535.             mov     ah,8Fh
  1536.             mov     dx,[Handle]
  1537.             mov     ebx,[NewSize]
  1538.  
  1539.             call    [XMM_Control]
  1540.  
  1541.             SuccessFail
  1542.  
  1543.             ret
  1544.  
  1545. EndP
  1546.  
  1547.  
  1548.  
  1549.     
  1550.  
  1551.  
  1552.  
  1553. EndS
  1554. End
  1555.