RE: wrapping DX
- Posted by Matthew Lewis <matthewwalkerlewis at YAHOO.COM> May 29, 2001
- 440 views
Maybe some asm guru can explain why these two approaches might give different results. First, here's the code from VC++: g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 ) 004011AE 6A 00 push 0 004011B0 8D 45 F8 lea eax,[pVertices] 004011B3 50 push eax 004011B4 6A 3C push 3Ch 004011B6 6A 00 push 0 004011B8 8B 0D D0 79 41 00 mov ecx,dword ptr [g_pVB (004179d0)] 004011BE 8B 11 mov edx,dword ptr [ecx] 004011C0 A1 D0 79 41 00 mov eax,[g_pVB (004179d0)] 004011C5 50 push eax 004011C6 FF 52 2C call dword ptr [edx+2Ch] The arguments are pushed onto the stack in reverse order, the last being g_pVB (the 'this' pointer for the vertex buffer), which also ends up in eax when the function is called (in this case--other calls use the registers differently for some reason). Next, is the code I use in fptr.e. It's more of a generic routine, designed to call any stdcall routine. Before it's called, the number of args is poked into paramcount, the address of the param list is put into memory starting at the value put into params, the pointer to the function is poked into memory at [comfunc] and the address where the return value will be stored is put into retpointer. This routine pushes the arguments being passed onto the stack (instructions #1..#12), calls the function by pointer (#14), stores the return value (#1A) and then returns to Euphoria (#21). #60, -- 0: pusha #BB,#00,#00,#00,#00, -- 1: mov ebx, paramcount (2) #B9,#00,#00,#00,#00, -- 6: mov ecx, params (7) -- B: start: #8B,#01, -- B: mov eax, [ecx] #50, -- D: push eax #83,#C1,#04, -- E: add ecx, 4 #4B, -- 11: dec ebx #75,#F7, -- 12: jnz start #FF,#15,#00,#00,#00,#00,-- 14: call dword ptr [comfunc] (22) #A3,#00,#00,#00,#00,-- 1A: mov [retpointer], eax (27) #61, -- 20: popa #C3}, -- 21: ret The above ASM has worked flawlessly on numerous other calls (including to Eu call_back's) until I ran across the vertex buffer. I've compared the function pointers when called from VC and from Eu, and they're the same. For some reason, though, something is getting messed up along the way when Eu calls anything. Matt Lewis