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

  1. ; File......: PMPTR.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. ;     cpmiProtectedPtr()
  17. ;  $CATEGORY$
  18. ;     CPMI
  19. ;  $ONELINER$
  20. ;     Generate a protected mode selector from a real mode address
  21. ;  $SYNTAX$
  22. ;     SELECTOR pascal cpmiProtectedPtr( void * RMAddr, unsigned int Size )
  23. ;  $ARGUMENTS$
  24. ;     RMAddr is a protected mode address (segment:offset)
  25. ;
  26. ;     Size is the number of bytes to which RMAddr points.
  27. ;  $RETURNS$
  28. ;     A selector which maps to the same physical memory.  A null selector
  29. ;     is returned if the function fails.
  30. ;  $DESCRIPTION$
  31. ;     This function is used to obtain the protected mode equivalent of a
  32. ;     real mode pointer, which is useful when attempting to access DOS or
  33. ;     BIOS memory locations.
  34. ;
  35. ;     Note that only the selector is generated; the offset is always zero.
  36. ;
  37. ;     Be sure to free with selector with cpmiFreeSelector() when it is no
  38. ;     longer needed.
  39. ;  $EXAMPLES$
  40. ;     auto long * Timer;
  41. ;     auto long TickCount;
  42. ;
  43. ;     FP_SEG( Timer ) = cpmiProtectedPtr( ( long * ) 0x0000046C,
  44. ;                                   sizeof( long ) );
  45. ;     FP_OFF( Timer ) = 0;
  46. ;
  47. ;     TickCount = *Timer;
  48. ;
  49. ;     cpmiFreeSelector( FPSEG( Timer ) );
  50. ;  $INCLUDE$
  51. ;     CPMI.H
  52. ;  $SEEALSO$
  53. ;     cpmiRealPtr(), cpmiFreeSelector()
  54. ;  $END$
  55. ;
  56.  
  57. IDEAL
  58. P286
  59.  
  60. Public    cpmiProtectedPtr
  61.  
  62. Segment   _NanFor   Word      Public    "CODE"
  63.           Assume    CS:_NanFor
  64.  
  65. Proc      cpmiProtectedPtr    Far
  66.  
  67.           Enter     2,0                           ; Create stack frame
  68.  
  69.           Xor       AX,AX                         ; DPMI -- allocate selector
  70.           Mov       CX,1                          ; Number of selectors
  71.           Int       31h                           ; Call DPMI
  72.           JC        @@Null                        ; Bail if error
  73.  
  74.           Mov       [Word Ptr BP - 2],AX          ; Store selector
  75.           Mov       BX,AX                         ; Move selector to BX
  76.           Xor       CX,CX                         ; Clear CX
  77.           Mov       DX,[Word Ptr BP + 10]         ; Load segment value
  78.           SHL       DX,1                          ; Move high bit . . .
  79.           RCL       CX,1                          ; . . . into CX low bit
  80.           SHL       DX,1                          ; Move high bit . . .
  81.           RCL       CX,1                          ; . . . into CX low bit
  82.           SHL       DX,1                          ; Move high bit . . .
  83.           RCL       CX,1                          ; . . . into CX low bit
  84.           SHL       DX,1                          ; Move high bit . . .
  85.           RCL       CX,1                          ; . . . into CX low bit
  86.           Add       DX,[Word Ptr BP + 8]          ; Form linear address
  87.           ADC       CX,0                          ; Carry if necessary
  88.           Mov       AX,7                          ; DPMI -- set base address
  89.           Int       31h                           ; Call DPMI
  90.           JC        @@Null                        ; Bail if error
  91.  
  92.           Mov       AX,8                          ; DPMI -- set segment size
  93.           Mov       BX,[Word Ptr BP - 2]          ; Move selector to BX
  94.           Xor       CX,CX                         ; Clear size high word
  95.           Mov       DX,[Word Ptr BP + 6]          ; Get size low word
  96.           Int       31h                           ; Call DPMI
  97.           Mov       AX,[Word Ptr BP - 2]          ; Move selector to AX
  98.           JNC       @@Exit                        ; If no error, quit
  99.  
  100. @@Null:   Xor       AX,AX                         ; Create null selector
  101.  
  102. @@Exit:   Leave                                   ; Destroy stack frame
  103.           RetF      6
  104. Endp      cpmiProtectedPtr
  105. Ends      _NanFor
  106. End