home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 12.img / ADS2.LIB / ZCMAPHYS.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-04-27  |  6.4 KB  |  167 lines

  1. .287
  2. .386
  3.         name    zcmaphys
  4. ; (assemble this with "386asm zcmaphys")
  5. ;**************************************************************************
  6. ;     (C) Copyright 1988-1992 by Autodesk, Inc.
  7. ;     This program is copyrighted by Autodesk, Inc. and is  licensed
  8. ;     to you under the following conditions.  You may not distribute
  9. ;     or  publish the source code of this program in any form.   You
  10. ;     may  incorporate this code in object form in derivative  works
  11. ;     provided  such  derivative  works  are  (i.) are  designed and 
  12. ;     intended  to  work  solely  with  Autodesk, Inc. products, and 
  13. ;     (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright  
  14. ;     1988-1992 by Autodesk, Inc."
  15. ;     AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  16. ;     AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  17. ;     CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  18. ;     DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  19. ;     UNINTERRUPTED OR ERROR FREE.
  20. ;**************************************************************************
  21. ;*                                                                        *
  22. ;*      Zortech C++ 2.1 Runtime Initialization Physical Memory Mapping    *
  23. ;*              Module for small model, protected mode 386.               *
  24. ;*                                                                        *
  25. ;**************************************************************************
  26.  
  27.  
  28. ;Memory Layout:
  29. ;
  30. ; High memory   +---------------+
  31. ;               | END OF MEMORY | 
  32. ;               |---------------|
  33. ;               | top-of-heap   |
  34. ;               |   ...         |
  35. ;               | bottom-of-heap|
  36. ;               |---------------| 
  37. ;               | Physical mem- |
  38. ;               | ory mapped in |
  39. ;               | by 3rd party  |
  40. ;               |---------------|
  41. ;               | Physical mem- |  (This is not applicable for ADS.  This
  42. ;               | ory mapped in |   creates a common buffer for communication
  43. ;               | for ADI       |   between AutoCAD and protect mode ADI.)
  44. ;               |---------------|
  45. ;               |   stack       |
  46. ;               |   ...         |
  47. ;               | end-of-stack  |
  48. ;               |---------------|
  49. ;               |DATA   segments|
  50. ;               |CODE   segments|
  51. ; Low memory    +---------------+
  52. ;
  53. ; The memory layout above shows where physical memory is mapped into the
  54. ; linear address space of the 3rd party application.  A 3rd party can map
  55. ; in physical memory by installing a routine in map_phys_mem(), which is 
  56. ; called from within the Zortech C++ run-time initialization module.
  57. ;
  58. ; The installed routine must map a physical base address that is on a page
  59. ; boundary (a page is four kilobytes) and the amount of memory mapped must
  60. ; be a multiple of four kilobytes.  The routine must return, in EAX, the
  61. ; number of pages mapped.  (See Function 250Ah, INT 21h, in the Phar Lap
  62. ; 386|DOS-Extender Reference Manual for more details.)
  63. ;
  64. ; One page of memory is mapped on top of the stack for protect mode ADI.
  65. ; This page is mapped by code inside the runtime initializer and serves
  66. ; as the communication buffer between protect mode ADI and AutoCAD.
  67. ;
  68. ; There is limited support for this mechanism under Microsoft Windows
  69. ; and it requires that the PHARLAP.386 driver be installed (this was done
  70. ; for AutoCAD ADI driver support).  The 2509h call will succeed only for
  71. ; linear addresses that fall within the REALBREAK part of a segment.  The
  72. ; returned value is NOT a physical address, but rather an internal DOS-X
  73. ; "handle", and when passed in to the 250Ah call will succeed in mapping
  74. ; in the REALBREAK pages at the end of the segment specified in the 250Ah
  75. ; call.
  76.  
  77. ifdef   ADS
  78. map_mem_addr    equ     ads_map_mem_addr
  79. map_phys_mem    equ     ads_map_phys_mem
  80. endif   ; ADS
  81.  
  82. TRUE    EQU     1
  83. FALSE   EQU     0
  84.  
  85. DO_SAMPLE_MAP   EQU     FALSE
  86.  
  87.  
  88. DGROUP  group   CONST, _DATA, _BSS
  89. CONST   segment public word use32 'DATA'
  90. CONST   ends
  91. _BSS    segment public word use32 'BSS'
  92. _BSS    ends
  93.  
  94. _DATA   segment public word use32 'DATA'
  95. IF      DO_SAMPLE_MAP
  96.         public  map_mem_addr
  97. map_mem_addr    dd      ?
  98. m_errmsg        db      'ERROR:  Unable to map physical memory to'
  99.                 db      ' end of segment.$'
  100. ENDIF
  101. _DATA   ends
  102.  
  103.  
  104. _TEXT   segment public byte use32 'CODE'
  105.         assume  cs:_TEXT,ds:DGROUP
  106.         
  107. ;**************************************************************************
  108. ;*  map_phys_mem()                                                        *
  109. ;*                                                                        *
  110. ;*      Returns the number of physical memory pages mapped.               *
  111. ;**************************************************************************
  112.  
  113.         public  map_phys_mem
  114. map_phys_mem    proc    near
  115.  
  116. IF      DO_SAMPLE_MAP
  117.         push    ebx     
  118.         push    es
  119.  
  120.         mov     eax,0
  121.         mov     ax,cs
  122.         and     ax,3                    ; mask off rpl bits
  123.         or      ax,34h                  ; Selector mapping in 1st Meg of mem
  124.         mov     ebx,eax
  125.         mov     ax, 2508h
  126.         int     21h                     ; Get Segment Linear Base Address
  127.  
  128.         mov     ebx, ecx                ; Linear base address of segment
  129.         add     ebx, 0A0000h            ; Add in desired offset within segment
  130.         mov     ax, 2509h
  131.         int     21h                     ; Convert Linear Addr to Physical Addr
  132.  
  133.         mov     ebx, ecx                ; Physical base addr of memory to map -
  134.                                         ;    must be a multiple of 4 kilobytes
  135.         push    ds
  136.         pop     es                      ; LDT Selector of segment to modify
  137.         mov     ecx, 16                 ; # of physical 4K memory pages to map
  138.         mov     ax, 250Ah
  139.         int     21h                     ; Map physical memory at end of segment
  140.         jc      m_err
  141.  
  142.         mov     map_mem_addr, eax       ; offset in segment of mapped memory
  143.         mov     eax, 16                 ; # of mapped pages
  144.         jmp     short m_ok
  145.  
  146. m_err:
  147.         lea     edx, m_errmsg
  148.         mov     ah, 09h
  149.         int     21h                     ; Output error message
  150.         mov     eax, 0
  151.  
  152. m_ok:
  153.         pop     es
  154.         pop     ebx
  155.         ret
  156. ELSE
  157.         mov     eax,0
  158.         ret
  159. ENDIF
  160.  
  161. map_phys_mem    endp
  162.  
  163. _TEXT   ends
  164.         end
  165.