home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / NFSRC305.ZIP / CPMI / ALLOCDOS.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-01  |  2.3 KB  |  81 lines

  1. ; File......: ALLOCDOS.ASM
  2. ; Author....: Ted Means
  3. ; CIS ID....: 73067,3332
  4. ;
  5. ; This is an original work by Ted Means and is placed in the
  6. ; public domain.
  7. ;
  8. ; Modification history:
  9. ; ---------------------
  10. ;     Rev 1.0   01 Jan 1995 03:01:00   TED
  11. ;  Initial release
  12. ;
  13.  
  14. ;  $DOC$
  15. ;  $FUNCNAME$
  16. ;     cpmiAllocDOSMem()
  17. ;  $CATEGORY$
  18. ;     CPMI
  19. ;  $ONELINER$
  20. ;     Allocate a DOS memory block from the lower 640K
  21. ;  $SYNTAX$
  22. ;     SELECTOR pascal cpmiAllocDOSMem( unsigned int Size )
  23. ;  $ARGUMENTS$
  24. ;     Size is the number of bytes to allocate.
  25. ;  $RETURNS$
  26. ;     A selector which is guaranteed to map to physical memory in the
  27. ;     lower 640K.
  28. ;  $DESCRIPTION$
  29. ;     This function is useful for allocating memory that needs to exist in
  30. ;     the DOS memory pool; e.g. buffers used by real-mode interrupts.
  31. ;
  32. ;     Note that only the selector is returned; the offset is always zero.
  33. ;
  34. ;     You can obtain the real mode segment:offset of the selector by calling
  35. ;     cpmiRealPtr().
  36. ;
  37. ;     When the memory is no longer needed, be sure to call cpmiFreeDOSMem()
  38. ;     to release it.
  39. ;  $EXAMPLES$
  40. ;     char far * buffer;
  41. ;
  42. ;     FP_SEG( buffer ) = cpmiAllocateDOSMem( 48 );
  43. ;     FP_OFF( buffer ) = 0;
  44. ;
  45. ;     // Do whatever
  46. ;
  47. ;     cpmiFreeDOSMem( FP_SEG( buffer ) );
  48. ;  $INCLUDE$
  49. ;     CPMI.H
  50. ;  $SEEALSO$
  51. ;     cpmiFreeDOSMem(), cpmiResizeDOSMem(), cpmiRealPtr()
  52. ;  $END$
  53. ;
  54.  
  55. IDEAL
  56. P286
  57.  
  58. Public    cpmiAllocateDOSMem
  59.  
  60. Segment   _NanFor   Word      Public    "CODE"
  61.           Assume    CS:_NanFor
  62.  
  63. Proc      cpmiAllocateDOSMem  Far
  64.  
  65.           Enter     0,0                           ; Create stack frame
  66.  
  67.           Mov       AX,100h                       ; DPMI -- alloc DOS memory
  68.           Mov       BX,[Word Ptr BP + 6]          ; Get size in bytes
  69.           Add       BX,15                         ; Round up if necessary
  70.           SHR       BX,4                          ; Convert to paragraphs
  71.           Int       31h                           ; Call DPMI
  72.           Mov       AX,DX                         ; Move selector to AX
  73.           JNC       @@Exit                        ; If no error, return
  74.  
  75. @@Null:   Xor       AX,AX                         ; Return null selector
  76.  
  77. @@Exit:   Leave                                   ; Destroy stack frame
  78.           RetF      2
  79. Endp      cpmiAllocateDOSMem
  80. Ends      _NanFor
  81. End