home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / MEMORY6.ASM < prev    next >
Assembly Source File  |  1994-12-01  |  4KB  |  163 lines

  1.     PAGE    66,132
  2. ;****************************** MEMORY6.ASM *********************************
  3. ;
  4. ;----------------------------------------------------------------------------
  5. LIBSEG           segment byte public "LIB"
  6.         assume cs:LIBSEG , ds:nothing
  7.  
  8. ;----------------------------------------------------------------------------
  9. .xlist
  10.     include  mac.inc
  11.     include  common.inc
  12. .list
  13. ;----------------------------------------------------------------------------
  14.  
  15. ems_handle    dw    0
  16. ems_frame    dw    0        ;seg of ems page, 0=no page
  17. ems_initial_sz    dw    0        ;16k-byte pages avail
  18.  
  19. current_logical_page    dw    -1
  20.  
  21. comment 
  22. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  23. EMS_CHECK - check if EMS memory is present
  24. ;
  25. ; inputs:  none
  26. ;
  27. ; output:  if CF = 1, no Expanded Memory manager installed
  28. ;          if CF = 0, AH = EMM error code
  29. ;          if AH = 0, ES = page frame segment address
  30. ;                     BX = available pages, each page is 4k-bytes
  31. ;                     DX = total ems pages
  32. ;          registers changed  AX,BX,ES           
  33. ;
  34. ; note:  The ems page frame is stored internally for use by
  35. ;        the ems read and write functions.
  36. ;* * * * * * * * * * * * * *
  37. 
  38. emm_name  DB      'EMMXXXX0',0
  39.  
  40.     public    EMS_CHECK
  41. EMS_CHECK    proc    far
  42.     apush    cx,si,di,ds
  43.     cld
  44. ;
  45. ; get the interrupt handler attached to int 67h
  46. ;
  47.     mov    ah,35h
  48.     mov    al,67h
  49.     int    21h            ;ask DOS for int 67 handler
  50. ;
  51. ; setup to scan vector for name of EMM handler (EMMXXXX0)
  52. ;
  53.     push    cs
  54.     pop    ds
  55.     mov    si,offset emm_name    ;offset of our copy of handler name
  56.     mov    di,0ah            ;offset of name within handler
  57.     mov    cx,8            ;length of name string
  58.     repz    cmpsb
  59.     jne    no_ems            ;jmp if name not found
  60. ;
  61. ; ask EMS driver for the page frame
  62. ;
  63.     mov    ah,41h
  64.     int    67h            ;return the page frame in -bx-
  65.     or    ah,ah            ;check if error
  66.     jnz    no_ems            ; jmp if error
  67.     mov    es,bx            ;save page frame
  68.     mov    ah,42h            ;get avail. page count
  69.     int    67h
  70.     or    ah,ah
  71.     jnz    no_ems            ;jmp if error getting page count
  72.     clc
  73.     jmp    ie_exit    
  74. no_ems:
  75.     stc
  76. ie_exit:
  77.     apop    ds,di,si,cx
  78.     retf
  79. EMS_CHECK    endp
  80.  
  81. comment 
  82. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  83. EMS_ALLOCATE - allocate EMS memory
  84. ;  inputs: bx -    number of 4k pages to allocate
  85. ;  output:      if no carry, then success
  86. ;               carry = failure 
  87. ;     
  88. ;* * * * * * * * * * * * * *
  89. 
  90.  
  91.     public    EMS_ALLOCATE
  92. EMS_ALLOCATE    proc    far
  93. ;
  94. ; allocate ems pages, bx=unallocated page count
  95. ;
  96.     cmp    bx,0
  97.     je    mop_4            ;jmp if no ems pages avail.
  98.     mov    ah,43h            ;allocate pages request code
  99.     int    67h
  100.     cmp    ah,0
  101.     jne    mop_4            ;jmp if failure
  102.           mov    ems_handle,dx        ;save ems handle
  103.           clc
  104.           jmp    ea_exit
  105. mop_4:    stc
  106. ea_exit:retf
  107. EMS_ALLOCATE    endp
  108.  
  109. comment 
  110. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  111. EMS_PAGE - request page of ems memory
  112. ;   inputs:  bx = ems page needed
  113. ;
  114. ;  output:   no carry = success
  115. ;            carry = error, error code in -ah-
  116. ;* * * * * * * * * * * * * *
  117. 
  118.  
  119.     public    EMS_PAGE
  120. EMS_PAGE    proc    far
  121.     cmp    bx,CURRENT_LOGICAL_PAGE    ;check if this page is in mem.
  122.     jz    er_ok            ;jump if page in memory
  123.     mov    CURRENT_LOGICAL_PAGE,bx    ;save new logical page indicator
  124.     mov    dx,ems_handle        ;get our handle
  125.     mov    ax,4400h        ;get request code & phys. page
  126.     int    67h            ;get data from eem handler
  127.     or    ah,ah
  128.     jnz    er_err
  129. er_ok:    clc
  130.     jmp    er_exit
  131. er_err:    stc
  132. er_exit:retf
  133. EMS_PAGE    endp
  134.  
  135. comment 
  136. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  137. EMS_RELEASE - release allocated ems memory
  138. ;  inputs:  none
  139. ;  output:  none
  140. ;* * * * * * * * * * * * * *
  141. 
  142.  
  143.     public    EMS_RELEASE
  144. EMS_RELEASE    proc    far
  145. ;
  146. ; check if ems memory allocated
  147. ;
  148. mc_ems: mov    dx,ems_handle
  149.     cmp    dx,0
  150.     je    mc_exit                ;jmp if no ems allocated
  151. ;
  152. ; release ems memory block
  153. ;
  154.     mov    ah,45h
  155.     int    67h                ;release ems memory block
  156.     mov    ems_handle,0
  157. mc_exit:
  158.     retf
  159. EMS_RELEASE    endp
  160.  
  161. LIBSEG    ENDS
  162. ;;    end
  163.