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

  1.     PAGE    66,132
  2. ;****************************** MEMORY5.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. ;---------------------------------
  16. ; xms extended memory data base
  17. ;---------------------------------
  18.  
  19. xms_handle    dw    0
  20. xms_control    dd    0        ;address of driver entry point
  21. xms_initial_sz    dw    0        ;1k bytes avail.
  22.  
  23.     align    4
  24. write_xms_packet    label    dword
  25.   xms_write_len        dd    0      ;length    of write in bytes
  26.   xms_from_write_handle    dw    0    ;always zero for conventional memory
  27.   xms_from_write_offset    dw    0    ;store buffer offset here
  28.   xms_from_write_segment dw    0    ;store buffer segment here
  29.   xms_to_write_handle    dw    0    ;handle from    xms driver
  30.   xms_to_write_address    dd    0    ;byte address from start of    xms block
  31.  
  32.  
  33.     align    4
  34. read_xms_packet    label    dword
  35.   xms_read_len        dd    0      ;length of read in bytes
  36.   xms_from_read_handle    dw    0    ;from xms driver
  37.   xms_from_read_address    dd    0    ;byte address from start of xms block
  38.   xms_to_read_handle    dw    0    ;always zero
  39.   xms_to_read_offset    dw    0    ;store buffer offset here
  40.   xms_to_read_segment    dw    0    ;store buffer segment here
  41.  
  42. comment 
  43. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  44. XMS_CHECK - check XMS memory size and amount available
  45. ; check    if XMS eXtended    Memory Specification driver exists
  46. ;  inputs:  none
  47. ;  output:  es:bx = XMS    control    address    if bx not equal zero
  48. ;              ax = size of largest block available in k-bytes
  49. ;           dx = total size of avail. memory in k-bytes
  50. ;              cx = A20 line state, 0=disabled & wraping, 1=enabled
  51. ;
  52. ;           bx = zero if no XMS driver found
  53. ;
  54. ;  note:  This function must be called before other XMS functions
  55. ;         to setup the internal control address
  56. ;* * * * * * * * * * * * * *
  57. 
  58.  
  59.     public    XMS_CHECK
  60. XMS_CHECK    proc    far
  61.     mov    ax,4300h
  62.     int    2fh
  63.     cmp    al,80h        ;check if driver found
  64.     mov    bx,0        ;pre    load failure code
  65.     jne    xms_check_exit    ;jmp if driver not found
  66. ;
  67.     mov    ax,4310h
  68.     int    2fh        ;request control address
  69.     mov    cs:word ptr xms_control,bx
  70.     mov    cs:word ptr xms_control+2,es
  71. ;
  72. ; get xms status
  73. ;
  74.     mov    ah,8
  75.     call    xms_control        ;returns ax=largest block in 1k chunks
  76. ;                                                dx=total 1k blocks avail.
  77. ; querry the xms driver for state of A20 line
  78. ;
  79.     apush    ax,bx
  80.     mov    ah,07
  81.     call    xms_control
  82.     mov    cx,ax
  83.     apop    bx,ax
  84.         
  85. xms_check_exit:
  86.     retf
  87. XMS_CHECK    endp
  88.  
  89. comment 
  90. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  91. XMS_UMB_CHECK - check if UMB area allocated by XMS driver
  92. ;  inputs:  none
  93. ;  output:  if no carry
  94. ;              DX = size of largest UMB in paragraphs (16-bit blocks)
  95. ;           if carry, then function not available
  96. ;           
  97. ;* * * * * * * * * * * * * *
  98. 
  99.  
  100.     public    XMS_UMB_CHECK
  101. XMS_UMB_CHECK    proc    far
  102.     apush    ax,bx
  103.     mov    ah,10h
  104.     mov    dx,4000h
  105.     call    xms_control
  106.     cmp    ax,1
  107.     je    xuc_exit1
  108.     cmp    bl,80h
  109.     je    xuc_exit2    ;jmp if function not implemented
  110. xuc_exit1:
  111.     clc
  112.     jmp    xuc_exit
  113. xuc_exit2:
  114.     stc
  115. xuc_exit:
  116.     apop    bx,ax
  117.     retf
  118. XMS_UMB_CHECK    endp
  119.  
  120. comment 
  121. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  122. XMS_ALLOCATE - allocate xms memory
  123. ;  inputs: dx -    size needed in k-bytes
  124. ;  output: ax =    0001 if    block allocated    ok
  125. ;       dx =    handle for block allocated
  126. ;
  127. ; note: the handle in -dx- is saved internally and is not needed.
  128. ;       xms_read and xms_write will use the stored handle.  This
  129. ;       means that only one xms block can be allocated at a time.
  130. ;     
  131. ;* * * * * * * * * * * * * *
  132. 
  133.  
  134.     public    XMS_ALLOCATE
  135. XMS_ALLOCATE    proc    far
  136.     mov    ah,9
  137.     call    xms_control
  138.           mov    xms_from_read_handle,dx
  139.     mov    xms_to_write_handle,dx
  140.     mov    xms_handle,dx
  141.     retf
  142. XMS_ALLOCATE    endp
  143.  
  144. comment 
  145. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  146. XMS_READ - read XMS memory block
  147. ;   inputs:  bp:di = to address
  148. ;         dx,ax = index into memory block
  149. ;        cx = number of words to transfer
  150. ;
  151. ;  output:      ax = result code, 1 = success
  152. ;* * * * * * * * * * * * * *
  153. 
  154.  
  155.     public    XMS_READ
  156. XMS_READ    proc    far
  157.     apush    dx,cx,si
  158.     mov    word ptr [xms_from_read_address],ax
  159.     mov    word ptr [xms_from_read_address+2],dx
  160.  
  161.     shl    cx,1                ;convert words to bytes
  162.     mov    word ptr xms_read_len,cx
  163.  
  164.     mov    xms_to_read_offset,di    ;save buffer offset
  165.     mov    xms_to_read_segment,bp    ;save buffer segment
  166.  
  167.     mov    si,offset read_xms_packet
  168.     mov    ah,0bh
  169.     call    xms_control
  170.     apop    si,cx,dx
  171.     retf
  172. XMS_READ    endp
  173.  
  174. comment 
  175. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  176. XMS_WRITE - write block of data to XMS memory
  177. ;   inputs:  bp:si = from address
  178. ;        cx = number of words to transfer
  179. ;         dx,ax = index into segment
  180. ;
  181. ;  output: ax = result code, 1 = success
  182. ;* * * * * * * * * * * * * *
  183. 
  184.  
  185.     public    XMS_WRITE
  186. XMS_WRITE    proc    far
  187.     apush    dx,cx,si
  188.     mov    word ptr [xms_to_write_address],ax
  189.     mov    word ptr [xms_to_write_address+2],dx
  190.  
  191.     shl    cx,1                ;convert words to bytes
  192.     mov    word ptr xms_write_len,cx
  193.  
  194.     mov    xms_from_write_offset,si
  195.     mov    xms_from_write_segment,bp
  196.  
  197.     mov    si,offset write_xms_packet
  198.     mov    ah,0bh
  199.     call    xms_control
  200.     apop    si,cx,dx
  201.     retf
  202. XMS_WRITE    endp
  203.  
  204.  
  205. comment 
  206. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  207. XMS_RELEASE - release current XMS memory block
  208. ;  inputs:
  209. ;* * * * * * * * * * * * * *
  210. 
  211.  
  212.     public    XMS_RELEASE
  213. XMS_RELEASE    proc    far
  214.     apush    ax,dx
  215.         mov    dx,xms_handle
  216.     cmp    dx,0
  217.     je    mc_xms                ;jmp if no xms allocated
  218.     mov    ah,0ah
  219.     call    xms_control            ;release xms memory block
  220.     mov    xms_handle,0
  221. mc_xms: apop    dx,ax
  222.     retf
  223. XMS_RELEASE    endp
  224.  
  225. LIBSEG    ENDS
  226. ;;    end
  227.