home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctchnqs / 1991 / number6 / dynamic.src < prev    next >
Text File  |  1991-11-11  |  1KB  |  38 lines

  1. { Listing 1:  The DMT lookup function }
  2.  
  3. {  Fn DYNAMIC requires a TypeOf() ptr and a dynamic index,
  4.    and returns a method ptr or NIL.  }
  5.  
  6. function Dynamic(VMT: pointer; Index: word): pointer; assembler;
  7. asm
  8.     pushf            {Windows crashes if you diddle DF}
  9.     std            {Scan backwards}
  10.     mov    ax,[Index]    {Load the word we're searching for}
  11.     les    di,[VMT]    {es:di points to VMT}
  12.     mov    di,[es:di+4]    {Point to DMT, if any}
  13. @Check:    or    di,di        {Test for DMT existence}
  14.     jnz    @Exists
  15.     mov    ax,di        {No DMT:  Return NIL}
  16.     mov    dx,di
  17.     jmp    @Exit
  18. @Exists:
  19.     mov    cx,[es:di+6]    {The length word}
  20.     mov    bx,cx        {Make a copy}
  21.     shl    bx,1        {Double it: word addressing}
  22.     mov    si,di        {Retain a ptr to the DMT}
  23.     lea    di,[di+bx+6]    {Offset of LAST dynamic index}
  24.     repne    scasw        {Search for a match}
  25.     jne    @NoMatch
  26. @Match:    shl    cx,1        {Double the (origin 0) match index}
  27.     shl    cx,1        {Double again, for dword indexing}
  28.     add    bx,cx        {Add it to the `index list size'}
  29.     les    ax,[es:si+bx+8] {@DMT+SizeOf(Indices}+SizeOf(Hdr) }
  30.                 {    +MatchIndex*SizeOf(pointer)  }
  31.     mov    dx,es
  32.     jmp    @Exit
  33. @NoMatch:
  34.     mov    di,[es:si]    {Offset of parent's DMT}
  35.     jmp    @Check
  36. @Exit:    popf            {Give Windows back its DF}
  37. end;
  38.