home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wunderki.zip / DMTH.ASM < prev    next >
Assembly Source File  |  1993-08-16  |  2KB  |  96 lines

  1.  
  2. ; *******************************************************
  3. ; *                            *
  4. ; *     Turbo Pascal Run-time Library                   *
  5. ; *    Dynamic Method Call Dispatcher            *
  6. ; *                            *
  7. ; *     Copyright (c) 1989,92 Borland International     *
  8. ; *                            *
  9. ; *******************************************************
  10.  
  11.     TITLE    DMTH
  12.  
  13.     INCLUDE    SE.ASM
  14.  
  15. ; Virtual method table layout
  16.  
  17. vmtInstSize    EQU    (WORD PTR 0)
  18. vmtInstCheck    EQU    (WORD PTR 2)
  19. vmtDMTPtr    EQU    (WORD PTR 4)
  20. vmtReserved    EQU    (WORD PTR 6)
  21. vmtEntryTable    EQU    (DWORD PTR 8)
  22.  
  23. ; Dynamic method table layout
  24.  
  25. dmtParent    EQU    (WORD PTR 0)
  26. dmtCacheIndex    EQU    (WORD PTR 2)
  27. dmtCacheEntry    EQU    (WORD PTR 4)
  28. dmtEntryCount    EQU    (WORD PTR 6)
  29. dmtEntryTable    EQU    (WORD PTR 8)
  30.  
  31. CODE    SEGMENT    BYTE PUBLIC
  32.  
  33.     ASSUME    CS:CODE
  34.  
  35. ; Externals
  36.  
  37.     EXTRN    HaltError:NEAR
  38.  
  39. ; Publics
  40.  
  41.     PUBLIC    FindMethod,CallMethod
  42.  
  43. ; Find dynamic method
  44.  
  45. FindMethod:
  46.  
  47.     CALL    GetMethod
  48.     RETF
  49.  
  50. ; Call dynamic method
  51.  
  52. CallMethod:
  53.  
  54.     CALL    GetMethod
  55.     JMP    DWORD PTR [DI]
  56.  
  57. ; Find dynamic method
  58. ; In    AX = Dynamic method index
  59. ;    DI = Virtual method table pointer
  60. ; Out    DI = Pointer to method vector
  61.  
  62. GetMethod:
  63.  
  64.     MOV    BX,[DI].vmtDMTPtr
  65.     CMP    AX,[BX].dmtCacheIndex
  66.     JNE    @@1
  67.     MOV    DI,[BX].dmtCacheEntry
  68.     RET
  69. @@1:    MOV    SI,DS
  70.     MOV    ES,SI
  71.     MOV    SI,BX
  72.     CLD
  73. @@2:    MOV    CX,[BX].dmtEntryCount
  74.     MOV    DX,CX
  75.     LEA    DI,[BX].dmtEntryTable
  76.     REPNE    SCASW
  77.     JE    @@3
  78.     MOV    BX,ES:[BX].dmtParent
  79.     OR    BX,BX
  80.     JNE    @@2
  81.     POP    AX
  82.     MOV    AX,210
  83.     JMP    HaltError
  84. @@3:    DEC    DX
  85.     SHL    DX,1
  86.     SUB    DX,CX
  87.     SHL    DX,1
  88.     ADD    DI,DX
  89.     MOV    [SI].dmtCacheIndex,AX
  90.     MOV    [SI].dmtCacheEntry,DI
  91.     RET
  92.  
  93. CODE    ENDS
  94.  
  95.     END
  96.