home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / msj / msjv3_1 / lim4 / get_emm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-02  |  1.8 KB  |  57 lines

  1. /*
  2.  
  3. Figure 4
  4. ========
  5.  
  6. */
  7.  
  8. /******************************************************************/
  9. /* This function gets the amount of exapnded memory needed and    */
  10. /* returns a pointer to the page from in emm_ptr_ptr.  It also    */
  11. /* assigns a name to the handle. It will return a result of 
  12. /* non-zero if it fails.                                          */
  13. /******************************************************************/
  14.  
  15. int get_expanded_memory(emm_ptr_ptr, pages, emm_handle_ptr, name)
  16.  
  17. char *(*emm_ptr_ptr);    /* pointer to expanded memory page frame */
  18. int pages;               /* number of pages to allocate */
  19. unsigned int *emm_handle_ptr;  /* pointer to emm handle */
  20. char *name;
  21.  
  22. {
  23.    /* check for number of expanded memory pages requested */
  24.  
  25.    inregs.h.ah = GET_UNALLOCATED_PAGE_COUNT ;
  26.    int86(EMM_INT, &inregs, &outregs);
  27.    if (outregs.h.ah != 0) return(1);
  28.    if (outregs.x.bx < pages) return(2);
  29.  
  30.    /* allocate pages pages - Function */
  31.  
  32.    inregs.h.ah = ALLOCATE_PAGES ;   /* Get a handle and allocate */
  33.    inregs.x.bx = pages;             /* 4 logical pages           */ 
  34.    int86(EMM_INT, &inregs, &outregs);
  35.    if (outregs.h.ah != 0) return(3);
  36.    *emm_handle_ptr = outregs.x.dx ;
  37.  
  38.    /* get page frame segment address - Function 2 */
  39.  
  40.    inregs.h.ah = GET_FRAME_ADDRESS;
  41.    int86(EMM_INT, &inregs, &outregs);
  42.    if (outregs.h.ah != 0) return(4);
  43.    *emm_ptr_ptr = (unsigned long int) (outregs.x.bx *65536);
  44.    
  45.  
  46.    /* assign name to handle  - Function 20          */
  47.  
  48.    inregs.x.ax = SET_HANDLE_NAME ;
  49.    inregs.x.dx = *emm_handle_ptr ;
  50.    inregs.x.si = FP_OFF(name) ;
  51.    segregs.ds  = FP_SEG(name);
  52.    int86x(EMM_INT, &inregs, &outregs, &segregs);
  53.    if (outregs.h.ah != 0) return(5);
  54.  
  55.    return(0);
  56.  
  57. }