home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / TPOWER53.ZIP / TPASM.ARC / TPEMS.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-10  |  6.6 KB  |  270 lines

  1. ;******************************************************
  2. ;            TPEMS.ASM 5.07
  3. ;             EMS routines
  4. ;     Copyright (c) TurboPower Software 1987.
  5. ; Portions copyright (c) Sunny Hill Software 1985, 1986
  6. ;     and used under license to    TurboPower Software
  7. ;         All rights reserved.
  8. ;******************************************************
  9.  
  10.     INCLUDE    TPCOMMON.ASM
  11.  
  12. ;******************************************************    Equates
  13.  
  14. EmsErrorCode    =    0FFFFh
  15.  
  16. ;******************************************************    Macros
  17.  
  18. EmsCall        MACRO EmsFunction
  19.         MOV    AH,EmsFunction    ;function code into AH
  20.         INT    67h        ;call the EMM
  21.         ENDM
  22.  
  23. EmsWordResult    MACRO RegName
  24.         LOCAL    EWRexit
  25.         OR    AH,AH        ;AH = 0    means success
  26.         MOV    AX,RegName    ;assume    success
  27.         JZ    EWRexit        ;Done if not 0
  28.         MOV    AX,EmsErrorCode    ;$FFFF for failure
  29.     EWRExit:
  30.         ENDM
  31.  
  32. EmsByteResult    MACRO RegName
  33.         LOCAL    EBRexit
  34.         OR    AH,AH        ;AH = 0    means success
  35.         JZ    EWRexit        ;Return    value in AL if 0
  36.         SetZero    AX        ;Else AL = 0
  37.     EWRExit:
  38.         ENDM
  39.  
  40. EmsBoolean    MACRO
  41.         LOCAL    EBexit
  42.         CMP    AH,0        ;AH = 0    means success
  43.         MOV    AX,1        ;Assume    success
  44.         JE    EBexit        ;Done if OK
  45.         DEC    AX        ;Else AX = 0
  46.     EBexit:
  47.         ENDM
  48.  
  49. ;******************************************************    Code
  50.  
  51. CODE    SEGMENT    BYTE PUBLIC
  52.  
  53.     ASSUME    CS:CODE
  54.  
  55.     PUBLIC    EmsStatusOK, EmsPagesAvail, EmsTotalPages, EmsPageFramePtr
  56.     PUBLIC    AllocateEmsPages, MapEmsPage, DeallocateEmsHandle, EmsVersion,
  57.     PUBLIC    SaveEmsContext,    RestoreEmsContext, EmsActiveHandles,
  58.     PUBLIC    EmsPagesOwned
  59.  
  60. ;******************************************************    EmsStatusOK
  61.  
  62. ;function EmsStatusOK :    Boolean;
  63.  
  64. ;Returns true if the EMM reports its status as being OK.
  65.  
  66. EmsStatusOK    PROC FAR
  67.  
  68.     EmsCall    40h            ;Get manager status function
  69.     EmsBoolean            ;Set AX
  70.     RET
  71.  
  72. EmsStatusOK    ENDP
  73.  
  74. ;******************************************************    EmsPagesAvail
  75.  
  76. ;function EmsPagesAvail    : Word;
  77.  
  78. ;Returns the number of available pages from the    expanded memory    manager,
  79. ; or EmsErrorCode in case of error.
  80.  
  81. EmsPagesAvail    PROC FAR
  82.  
  83.     EmsCall    42h            ;Get number of pages function
  84.     EmsWordResult    BX        ;If successful,    return value in    BX
  85.     RET
  86.  
  87. EmsPagesAvail    ENDP
  88.  
  89. ;******************************************************    EmsTotalPages
  90.  
  91. ;function EmsTotalPages    {: Word} ;
  92.  
  93. ;Returns total number of pages of EMS memory, including    allocated pages,
  94. ;or EmsErrorCode in case of error.
  95.  
  96. EmsTotalPages    PROC FAR
  97.  
  98.     EmsCall    42h            ;Get number of pages function
  99.     EmsWordResult    DX        ;If successful,    return value in    DX
  100.     RET
  101.  
  102. EmsTotalPages    ENDP
  103.  
  104. ;******************************************************    EmsPageFramePtr
  105.  
  106. ;function EmsPageFramePtr : Pointer;
  107.  
  108. ;Returns a pointer to the page frame used by the EMM. Returns nil pointer
  109. ;in case of error.
  110.  
  111. EmsPageFramePtr    PROC FAR
  112.  
  113.     EmsCall    41h            ;Get page frame    segment
  114.     OR    AH,AH            ;Check for error
  115.     MOV    AX,0            ;Offset    is zero    in any case
  116.     MOV    DX,BX            ;Segment from DX to BX
  117.     JZ    FramePtrExit        ;Done if AH = 0
  118.     SetZero    DX            ;Else DX = 0
  119. FramePtrExit:
  120.     RET
  121.  
  122. EmsPageFramePtr    ENDP
  123.  
  124. ;******************************************************    AllocateEmsPages
  125.  
  126. ;function AllocateEmsPages(NumPages : Word) : Word
  127.  
  128. ;Allocates the indicated number    of pages and returns a handle.
  129. ;Returns EmsErrorCode in case of error.
  130.  
  131. AllocNum    EQU    WORD PTR SS:[BX+4]
  132.  
  133. AllocateEmsPages    PROC FAR
  134.  
  135.     StackFrame
  136.     MOV    BX,AllocNum        ;BX = NumPages
  137.     EmsCall    43h            ;Get handle and    allocate memory
  138.     EmsWordResult    DX        ;If successful,    return value in    DX
  139.     RET    2
  140.  
  141. AllocateEmsPages    ENDP
  142.  
  143. ;******************************************************    MapEmsPage
  144.  
  145. ;function MapEmsPage(Handle, LogicalPage, PhysicalPage : Word) : Boolean;
  146.  
  147. ;Maps the specified LogicalPage    associated with    Handle into PhysicalPage
  148. ; (0-3). Returns true if successful.}
  149.  
  150. MapHandle    EQU    WORD PTR SS:[BX+8]
  151. MapLogPage    EQU    WORD PTR SS:[BX+6]
  152. MapPhysPage    EQU    BYTE PTR SS:[BX+4]
  153.  
  154. MapEmsPage    PROC FAR
  155.  
  156.     StackFrame
  157.     MOV    AL,MapPhysPage        ;AL = PhysicalPage
  158.     MOV    DX,MapHandle        ;DX = Handle
  159.     MOV    BX,MapLogPage        ;BX = LogicalPage
  160.     EmsCall    44h            ;Map memory function
  161.     EmsBoolean            ;Set AX
  162.     RET    6
  163.  
  164. MapEmsPage    ENDP
  165.  
  166. ;******************************************************    DeallocateEmsHandle
  167.  
  168. ;function DeallocateEmsHandle(Handle : Word) : Boolean;
  169.  
  170. ;Deallocates the indicated handle and the memory associated with it.
  171.  
  172. EmsHandle    EQU    WORD PTR SS:[BX+4]
  173.  
  174. DeallocateEmsHandle    PROC FAR
  175.  
  176.     StackFrame
  177.     MOV    DX,EmsHandle        ;DX = Handle
  178.     EmsCall    45h            ;Release handle    function
  179.     EmsBoolean            ;Set AX
  180.     RET    2
  181.  
  182. DeallocateEmsHandle    ENDP
  183.  
  184. ;******************************************************    EmsVersion
  185.  
  186. ;function EmsVersion : Byte;
  187.  
  188. ;Returns a BCD version number of the EMM handle. To check for version 3.2
  189. ;or greater for    example, use: 'if EmsVersion >= $32 then'. Returns 0 in
  190. ;case of error.
  191.  
  192. EmsVersion    PROC FAR
  193.  
  194.     EmsCall    46h            ;Get EMM version function
  195.     EmsByteResult            ;Return    value in AL
  196.     RET
  197.  
  198. EmsVersion    ENDP
  199.  
  200. ;******************************************************    SaveEmsContext
  201.  
  202. ;function SaveEmsContext(Handle    : Word)    : Boolean;
  203.  
  204. ;Saves the EMM context for resident programs. The handle passed    must have
  205. ;been allocated    with a call to AllocateEmsPages. Returns true if
  206. ;successful.
  207.  
  208. SaveEmsContext    PROC FAR
  209.  
  210.     StackFrame
  211.     MOV    DX,EmsHandle        ;DX = Handle
  212.     EmsCall    47h            ;Save mapping context function
  213.     EmsBoolean            ;Set AX
  214.     RET    2
  215.  
  216. SaveEmsContext    ENDP
  217.  
  218. ;******************************************************    RestoreEmsContext
  219.  
  220. ;function RestoreEmsContext(Handle : Word) : Boolean;
  221.  
  222. ;Restores the mapping context of the EMM driver    for the    handle specified.
  223. ;The handle should the same one    used in    a prior    call to    SaveEmsContext.
  224. ;Returns true if successful.
  225.  
  226. RestoreEmsContext    PROC FAR
  227.  
  228.     StackFrame
  229.     MOV    DX,EmsHandle        ;DX = Handle
  230.     EmsCall    48h            ;Restore mapping context function
  231.     EmsBoolean            ;Set AX
  232.     RET    2
  233.  
  234. RestoreEmsContext    ENDP
  235.  
  236. ;******************************************************    EmsActiveHandles
  237.  
  238. ;function EmsActiveHandles : Word;
  239.  
  240. ;Returns the number of active EMS handles, EmsErrorCode    in case    of error
  241.  
  242. EmsActiveHandles    PROC FAR
  243.  
  244.     EmsCall    4Bh            ;Get number of EMM handles
  245.     EmsWordResult    BX        ;If successful,    return value in    BX
  246.     RET
  247.  
  248. EmsActiveHandles    ENDP
  249.  
  250.  
  251. ;******************************************************    EmsPagesOwned
  252.  
  253. ;function EmsPagesOwned(Handle : Word) : Word;
  254.  
  255. ;Returns the number of pages owned by Handle, or EmsErrorCode in case of error.
  256.  
  257. EmsPagesOwned    PROC FAR
  258.  
  259.     StackFrame
  260.     MOV    DX,EmsHandle        ;DX = Handle
  261.     EmsCall    4Ch            ;Get pages owned by handle function
  262.     EmsWordResult    BX        ;If successful,    return value in    BX
  263.     RET    2
  264.  
  265. EmsPagesOwned    ENDP
  266.  
  267. CODE    ENDS
  268.  
  269.     END
  270.