home *** CD-ROM | disk | FTP | other *** search
- { Listing 1: The DMT lookup function }
-
- { Fn DYNAMIC requires a TypeOf() ptr and a dynamic index,
- and returns a method ptr or NIL. }
-
- function Dynamic(VMT: pointer; Index: word): pointer; assembler;
- asm
- pushf {Windows crashes if you diddle DF}
- std {Scan backwards}
- mov ax,[Index] {Load the word we're searching for}
- les di,[VMT] {es:di points to VMT}
- mov di,[es:di+4] {Point to DMT, if any}
- @Check: or di,di {Test for DMT existence}
- jnz @Exists
- mov ax,di {No DMT: Return NIL}
- mov dx,di
- jmp @Exit
- @Exists:
- mov cx,[es:di+6] {The length word}
- mov bx,cx {Make a copy}
- shl bx,1 {Double it: word addressing}
- mov si,di {Retain a ptr to the DMT}
- lea di,[di+bx+6] {Offset of LAST dynamic index}
- repne scasw {Search for a match}
- jne @NoMatch
- @Match: shl cx,1 {Double the (origin 0) match index}
- shl cx,1 {Double again, for dword indexing}
- add bx,cx {Add it to the `index list size'}
- les ax,[es:si+bx+8] {@DMT+SizeOf(Indices}+SizeOf(Hdr) }
- { +MatchIndex*SizeOf(pointer) }
- mov dx,es
- jmp @Exit
- @NoMatch:
- mov di,[es:si] {Offset of parent's DMT}
- jmp @Check
- @Exit: popf {Give Windows back its DF}
- end;