Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: Raizor on February 04, 2012
-
I've been playing around with the MiniFMod source and I'm confused by the line highlighted below.
FSOUND_SAMPLE is a struct with a 'length' property. I'm trying to work out how the line below actually works. I would expect a reference to an instance of FSOUND_SAMPLE to be there as that doesn't look right to me at all. Am I missing something?
If I try to compile the code as C++ (instead of C), I get the following error against that line:
Error 8 error C2420: 'FSOUND_SAMPLE' : illegal symbol in second operand
Thanks
Raizor
Snippet:
CalculateLoopCount:
mov mix_count, eax
mov esi, [ecx].mixpos
mov ebp, FSOUND_OUTPUTBUFF_END
mov mix_endflag, ebp // set a flag to say mixing will end when end of output buffer is reached
cmp [ecx].speeddir, FSOUND_MIXDIR_FORWARDS
jne samplesleftbackwards
// work out how many samples left from mixpos to loop end
mov edx, [ebx].loopstart
add edx, [ebx].looplen
cmp esi, edx
jle subtractmixpos
mov edx, [ebx+FSOUND_SAMPLE.length]
-
I don't know but I would hazard a guess that it's the offset of the field and in c++ maybe something like:
offsetof(FSOUND_SAMPLE,length)
giving
mov edx,[ebx+offsetof(FSOUND_SAMPLE,length)]
That really is just a guess though.
-
Thanks Stonemonkey. From what I've managed to find so far, I think you may well be right :) K++
-
mov edx, [ebx+FSOUND_SAMPLE.length]
ebx should be a pointer to a structure of FSOUND_SAMPLE
the whole line mov edx, [ebx+FSOUND_SAMPLE.length]
transfers the data from the FSOUND_SAMPLE.lenght structure variable to edx.
small example:
Font2D struct <-Structure Font2D
FontList dd ?
NrChars dd ?
Font2D ends
.data?
BigFont Font2D <?> <-Declare a Structurevariable of Font2D
.code
mov esi,offset BigFont <- mov the startadress of BigFont into esi-Register
mov eax,dword ptr[esi+Font2D.FontList] <- Now yu have access to structure variable:
startadress of big font + offset from the
structure Font2D.FontList [Byte 0]
This line transfers the data from
BigFont.FontList to eax.
mov ebx,dword ptr[esi+Font2D.NrChars] <- Now yu have access to structure variable:
startadress of big font + offset from the
structure Font2D.NrChars[Byte 4]
This line transfers the data from
BigFont.NrChars to ebx.
-
Wonderful Energy, thanks very much! K++