home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / DDVT.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  5.2 KB  |  219 lines

  1. ;[]-----------------------------------------------------------------[]
  2. ;|      DDVT.ASM -- DDVT dispatcher                                  |
  3. ;[]-----------------------------------------------------------------[]
  4.  
  5. ;
  6. ;       C/C++ Run Time Library - Version 5.0
  7. ;       Copyright (c) 1991, 1992 by Borland International
  8. ;       All Rights Reserved.
  9.  
  10. ;memory model aliases, for the convenience of building the library
  11.  
  12. IFDEF           __s__
  13. __SMALL__       equ     1
  14. ENDIF
  15.  
  16. IFDEF           __c__
  17. __COMPACT__     equ     1
  18. ENDIF
  19.  
  20. IFDEF           __m__
  21. __MEDIUM__      equ     1
  22. ENDIF
  23.  
  24. IFDEF           __l__
  25. __LARGE__       equ     1
  26. ENDIF
  27.  
  28. IFDEF           __h__
  29. __HUGE__        equ     1
  30. ENDIF
  31.  
  32. IFNDEF __TINY__
  33.     IFNDEF __SMALL__
  34.         IFNDEF __MEDIUM__
  35.             IFNDEF __COMPACT__
  36.                 IFNDEF __LARGE__
  37.                     IFNDEF __HUGE__
  38.                         %OUT  You must supply a model symbol.
  39.                         .ERR
  40.                     ENDIF
  41.                 ENDIF
  42.             ENDIF
  43.         ENDIF
  44.     ENDIF
  45. ENDIF
  46.  
  47.                 extrn   _abort:far
  48.  
  49. ifdef   __SMALL__
  50.                 .model  small
  51. LDATA           equ     0
  52. endif
  53.  
  54. ifdef   __MEDIUM__
  55.                 .model  medium
  56. LDATA           equ     0
  57. endif
  58.  
  59. ifdef   __COMPACT__
  60.                 .model  compact
  61. LDATA           equ     1
  62. endif
  63.  
  64. ifdef   __LARGE__
  65.                 .model  large
  66. LDATA           equ     1
  67. endif
  68.  
  69. ifdef   __HUGE__
  70.                 .model  large
  71. LDATA           equ     1
  72. endif
  73.  
  74. ifdef   FARVTBL
  75. ptrSize         equ     4
  76. else
  77. ptrSize         equ     2
  78. endif
  79.  
  80. if      LDATA
  81. LES_            equ     <les>
  82. ES_             equ     <es:>
  83. else
  84. LES_            equ     <mov>
  85. ES_             equ     <   >
  86. endif
  87.  
  88.                 .code
  89.  
  90. FAIL_addr_NULL  dd      0               ; NULL 'fail' value
  91. FAIL_addr_abort dd      _abort          ; RTL  'fail' value
  92.  
  93. ;==============================================================================
  94. ;
  95. ; NULL dispatcher entry points:
  96. ;
  97.  
  98. ifdef     FARVTBL
  99.  
  100. entryname       equ     <@_DDVTdispatchNULL$qnvi>
  101.                 public  entryname
  102. entryname:      mov     ax, offset FAIL_addr_NULL
  103.                 jmp     SHORT start_dispatch
  104.  
  105. else
  106.  
  107. entryname       equ     <@_DDVTdispatchNULL$qpvi>
  108.                 public  entryname
  109. entryname:      mov     ax, offset FAIL_addr_NULL
  110.                 jmp     SHORT start_dispatch
  111.  
  112. endif
  113.  
  114. ;
  115. ; Compiler 'virtual DDVT call' entry points:
  116. ;
  117.  
  118. ifdef   FARVTBL
  119.  
  120. procname        equ     <@_DDVTdispatch$qnvi>
  121.                 public  procname
  122. procname        proc    vptr:DWORD,id:WORD
  123.  
  124. else
  125.  
  126. procname        equ     <@_DDVTdispatch$qpvi>
  127.                 public  procname
  128. procname        proc    vptr: WORD,id:WORD
  129.  
  130. endif
  131.                 mov     ax, offset FAIL_addr_abort
  132.  
  133. start_dispatch:
  134.  
  135.                 push    bp
  136.                 mov     bp, sp
  137.  
  138.                 push    si
  139.                 push    di
  140.  
  141.                 push    ax                      ; save 'fail' address
  142.  
  143. ifdef   FARVTBL
  144.                 les     bx, vptr
  145. else
  146.                 mov     bx, vptr
  147.                 push    ds
  148.                 pop     es
  149. endif
  150.  
  151.                 std
  152.  
  153. ;
  154. ; This is the loop that searches for a matching ID.
  155. ;
  156. search_loop:    mov     cx, ES_[bx-ptrSize-2]   ; get # of entries
  157.                 jcxz    search_next
  158. ;
  159. ; The table is below the # of entries, 6 bytes per entry; count is in CX.
  160. ;
  161.                 mov     dx, cx                  ; save the count
  162. ;
  163. ; Search this table for a matching ID.
  164. ;
  165.                 mov     ax, id
  166.                 lea     di, [bx-ptrSize-4]      ; point at first ID
  167.                 repne   scasw
  168.                 je      search_match
  169. ;
  170. ; No luck with this class; see if it has a base class.
  171. ;
  172. search_next:
  173.  
  174. ifdef   FARVTBL
  175.                 les     bx, es:[bx-4]           ; get base class link
  176.                 mov     ax, es
  177.                 or      ax, bx
  178. else
  179.                 mov     bx, [bx-2]              ; get base class link
  180.                 or      bx, bx
  181. endif
  182.                 jnz     search_loop             ; continue if non-zero
  183. ;
  184. ; No match; return address of the 'fail' function pointer.
  185. ;
  186.                 pop     ax                      ; pop 'fail' address
  187.                 mov     dx, cs
  188.  
  189.                 jmp     SHORT done
  190. ;
  191. ; Here if we have a match; ES:[DI] points just below the matching ID.
  192. ;
  193. search_match:   shl     dx, 1                   ; DX = 2 * count
  194.                 sub     bx, dx
  195.                 shl     cx, 1                   ; CX = 2 * count remaining
  196.                 sub     dx, cx
  197.                 shl     dx, 1                   ; DX = 4 * index of match
  198.                 add     dx, 2 + ptrSize
  199.                 sub     bx, dx
  200.  
  201.                 pop     ax                      ; throw away 'fail' addr
  202.  
  203.                 mov     ax, bx                  ; return the fn address
  204.                 mov     dx, es
  205.  
  206. done:           cld
  207.                 pop     di
  208.                 pop     si
  209.  
  210.                 pop     bp
  211.                 ret
  212.  
  213. procname        endp
  214.  
  215. ;==============================================================================
  216.                 end
  217.