.data?
.......................
FVX struct
x0 REAL4 ?
y0 REAL4 ?
z0 REAL4 ?
x1 REAL4 ?
y1 REAL4 ?
z1 REAL4 ?
x2 REAL4 ?
y2 REAL4 ?
z2 REAL4 ?
FVX ends

vObj DWORD ?


R0 REAL4 0.0
R1 REAL4 1.0
SIZEOFFVX equ SIZEOF FVX



heapallocate proc
invoke GetProcessHeap
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,4096*sizeof(FVX)
;up to 4096 of vertices
mov vObj,eax

mov ecx, OFFSET vObj
imul ecx, SIZEOFFVX
fld R0
fstp [FVX.x0+ecx]
fld R1
fstp [FVX.y0+ecx]
fld R0
fstp [FVX.z0+ecx]
fld R1
fstp [FVX.x1+ecx]
fld R0
fstp [FVX.y1+ecx]
fld R0
fstp [FVX.z1+ecx]
fld R0
fstp [FVX.x2+ecx]
fld R0
fstp [FVX.y2+ecx]
fld R0
fstp [FVX.z2+ecx]

ret
heapallocate endp


I am very close, I can feel it - when I do the below, I get a read error..

mov ecx,OFFSET vObj
imul ecx, SIZEOFFVX
invoke glVertex3f, ,,

Last time on this question, thanx.. and thanks Ratch for your help although I didn't follow your suggestion precisely, maybe I am hard headed.

how am I not accessing this memory correctly, or mal-defining it?
Posted on 2004-01-10 21:13:22 by drarem
Shouldn't it be


mov ecx, vObj

?

Also what are you trying to achieve by


mov ecx, OFFSET vObj
imul ecx, SIZEOFFVX

It looks wrong to me.
Posted on 2004-01-10 23:26:29 by roticv
drarem,
If you have to multiply, which you don't in this case, why use the signed IMUL instead of the unsigned MUL? You don't say where you are receiving the read error. Anyway, this is the way I would code the initialization. Ratch




00000024 FVX struct
00000000 00000000 x0 REAL4 ?
00000004 00000000 y0 REAL4 ?
00000008 00000000 z0 REAL4 ?
0000000C 00000000 x1 REAL4 ?
00000010 00000000 y1 REAL4 ?
00000014 00000000 z1 REAL4 ?
00000018 00000000 x2 REAL4 ?
0000001C 00000000 y2 REAL4 ?
00000020 00000000 z2 REAL4 ?
FVX ends

00000000 .DATA?

00000000 00000000 vObj DWORD ?

00000000 .CODE
00000000 MAIN:
00000000 heapallocate:
INVOKE GetProcessHeap
INVOKE HeapAlloc,eax,HEAP_ZERO_MEMORY,4096*FVX
;up to 4096 of vertices
00000012 A3 00000000 R MOV [vObj],EAX ;save pointer to allocated memory
00000017 B9 00001000 MOV ECX,4096 ;loop count
.REPEAT
0000001C 33 D2 XOR EDX,EDX ;EDX=0.0 in REAL4 format
0000001E 89 10 MOV [EAX.FVX.x0],EDX
00000020 89 50 08 MOV [EAX.FVX.z0],EDX
00000023 89 50 10 MOV [EAX.FVX.y1],EDX
00000026 89 50 14 MOV [EAX.FVX.z1],EDX
00000029 89 50 18 MOV [EAX.FVX.x2],EDX
0000002C 89 50 1C MOV [EAX.FVX.y2],EDX
0000002F 89 50 20 MOV [EAX.FVX.z2],EDX
00000032 BA 3F800000 MOV EDX,03F800000H ;EDX=1.0 in REAL4 format
00000037 89 50 04 MOV [EAX.FVX.y0],EDX
0000003A 89 50 0C MOV [EAX.FVX.x1],EDX
0000003D 83 C0 24 ADD EAX,FVX ;move pointer to next vertice set
00000040 49 DEC ECX ;decrement counter
.UNTIL ZERO? ;check for end of loop

00000043 C3 RET

00000044 8B 0D 00000000 R MOV ECX,[vObj]
INVOKE glVertex3f,[ECX.FVX.x0],[ECX.FVX.y0],[ECX.FVX.z0]
Posted on 2004-01-11 00:00:55 by Ratch
err I should have titled this subject, Project Doh..

It would help if I actually called heapallocate() function.. and if I knew what I was doing. I was also under
impression I couldn't mix REAL4/8 values with the registers for some weird unGodly reason. I thought those were only for FPU usage since adding/subtraction didn't handle the decimal?

Thanks Ratch, I now know another way to reference the data.. vObj.STRUCT.member_variable


I am still using FLD/FSTP for working with the vars, trying to get familiar with the FPU.

So EDX can store a REAL4 value, meaning it will keep track of the decimal also? What is REAL4 anyway a struc? I will test that next..

R05 REAL4 0.5
mov edx,R05
mul edx,R05
value of R05 = 0.25?

with the multiplication, I didn't know IMUL was signed and MUL was unsigned. Or I was probably told that before and forgot it.

And to go thru an array, I figure I can do this (untested yet):



mov ecx, ARRAY_INDEX_NUMBER

mul ecx, SIZEOFFVX ;multiply by sizeof FVX structure

invoke glVertex3f, [vObj.FVX.x0+ecx],[vObj.FVX.y0+ecx],[vObj.FVX.z0+ecx]


and it would be faster to move vObj address to a register, as Ratch used:


mov edx, vObj
....
Posted on 2004-01-11 13:44:56 by drarem
After some testing, I have concluded the following which may or may not be correct:

1) add'ing/sub'ing to edx don't work, you need the FPU when adding to it if you want to preserve the decimals.

2) see below for indexed array of vertices, I had to preserve the edx register, yes the glVertex3F calls modify the eax, ecx, and edx registers.. which means pushing and popping them to be able to use might be as fast as using reference. I might as well use a temporary variable which to copy vObj to and use math on the temporary variable.

If I didn't preserve the register used to index the array with, edx or whatever would be trashed and the array would end up waayyy out of bounds pointing to whatever the opengl calls did to them.






invoke glColor3f,R0,R0,R1
invoke glVertex3f, [vObj.FVX.x0],[vObj.FVX.y0],[vObj.FVX.z0]
invoke glColor3f,R0,R1,R1
invoke glVertex3f, [vObj.FVX.x1],[vObj.FVX.y1],[vObj.FVX.z1]
invoke glColor3f,R1,R1,R0
invoke glVertex3f, [vObj.FVX.x2],[vObj.FVX.y2],[vObj.FVX.z2]

mov edx, 1 ;point to next array of verticeses
imul edx,SIZEOFFVX ;multiply by size of fvx, since MUL does not take TWO operands that I know of.

push edx
invoke glColor3f,R0,R0,R1
pop edx
push edx
invoke glVertex3f, [vObj.FVX.x0+edx],[vObj.FVX.y0+edx],[vObj.FVX.z0+edx]
pop edx
push edx
invoke glColor3f,R0,R1,R1
pop edx
push edx
invoke glVertex3f, [vObj.FVX.x1+edx],[vObj.FVX.y1+edx],[vObj.FVX.z1+edx]
pop edx
push edx
invoke glColor3f,R1,R1,R0
pop edx
push edx
invoke glVertex3f, [vObj.FVX.x2+edx],[vObj.FVX.y2+edx],[vObj.FVX.z2+edx]
pop edx
Posted on 2004-01-11 15:24:35 by drarem
drarem,
err I should have titled this subject, Project Doh..
Hmm, maybe you should look at http://www.asmcommunity.net/board/index.php?topic=14673&highlight=fpu+tutorial or download the zipped version of the tutorial.
It would help if I actually called heapallocate() function.. and if I knew what I was doing.
HeapAlloc is well documented. It returns a pointer to where it allocated the amount of memory you asked for. Make sure you call HeapFree when you are done using the memory it allocated to your program.
I was also under impression I couldn't mix REAL4/8 values with the registers for some weird unGodly reason. I thought those were only for FPU usage since adding/subtraction didn't handle the decimal?
REAL4 is the 4 byte floating format and REAL8 is the 8 byte floating format. There is also a 10 byte floating format. All those formats will store in the 80 bit FPU stack registers where arithmetical operations can be performed. They are converted and stored in the format specified by the floating load or floating store instruction operands. Read the tutorial. Don't try to do integer type instructions (ADD, SUB,INC,etc) with numbers in floating point format. It won't work. Use the FADD, FSUB, etc instead.
I am still using FLD/FSTP for working with the vars, trying to get familiar with the FPU.

So EDX can store a REAL4 value, meaning it will keep track of the decimal also? What is REAL4 anyway a struc? I will test that next..
Any 32 bit register or 32 bit memory location can store a REAL4 number. After all, it is 4 bytes, right? The decimal point is implied by a specified format within the 32 bits, which the tutorial will explain. REAL4 is a memory type designator, not a structure, just like BYTE, WORD, DWORD, etc.


R05 REAL4 0.5
mov edx,R05
mul edx,R05
value of R05 = 0.25?
Above, you are doing an integer operation on a floating point number. That won't work. See below. Ratch


FLD [RO5]
FMUL [RO5]
FSTP [SOMEWHERE]
Posted on 2004-01-11 15:32:12 by Ratch
drarem,


invoke glColor3f,R0,R0,R1
invoke glVertex3f, [vObj.FVX.x0],[vObj.FVX.y0],[vObj.FVX.z0]
invoke glColor3f,R0,R1,R1
invoke glVertex3f, [vObj.FVX.x1],[vObj.FVX.y1],[vObj.FVX.z1]
invoke glColor3f,R1,R1,R0
invoke glVertex3f, [vObj.FVX.x2],[vObj.FVX.y2],[vObj.FVX.z2]

mov edx, 1 ;point to next array of verticeses
imul edx,SIZEOFFVX ;multiply by size of fvx, since MUL does not take TWO operands that I know of.

push edx
invoke glColor3f,R0,R0,R1
pop edx
push edx
invoke glVertex3f, [vObj.FVX.x0+edx],[vObj.FVX.y0+edx],[vObj.FVX.z0+edx]
pop edx
push edx
invoke glColor3f,R0,R1,R1
pop edx
push edx
invoke glVertex3f, [vObj.FVX.x1+edx],[vObj.FVX.y1+edx],[vObj.FVX.z1+edx]
pop edx
push edx
invoke glColor3f,R1,R1,R0
pop edx
push edx
invoke glVertex3f, [vObj.FVX.x2+edx],[vObj.FVX.y2+edx],[vObj.FVX.z2+edx]
pop edx



invoke glColor3f,R0,R0,R1
invoke glVertex3f, [vObj.FVX.x0],[vObj.FVX.y0],[vObj.FVX.z0]
invoke glColor3f,R0,R1,R1
invoke glVertex3f, [vObj.FVX.x1],[vObj.FVX.y1],[vObj.FVX.z1]
invoke glColor3f,R1,R1,R0
invoke glVertex3f, [vObj.FVX.x2],[vObj.FVX.y2],[vObj.FVX.z2]

invoke glColor3f,R0,R0,R1

invoke glVertex3f, [vObj.FVX.x0+FVX],[vObj.FVX.y0+FVX],[vObj.FVX.z0+FVX]

invoke glColor3f,R0,R1,R1

invoke glVertex3f, [vObj.FVX.x1+FVX],[vObj.FVX.y1+FVX],[vObj.FVX.z1+FVX]

invoke glColor3f,R1,R1,R0

invoke glVertex3f, [vObj.FVX.x2+FVX],[vObj.FVX.y2+FVX],[vObj.FVX.z2+FVX]

Why do you need EDX just to add FVX to the address? Unless you plan to put this into a loop. MUL always puts the result into EAX/AX/AL. The destination register does not have to be coded. Ratch
Posted on 2004-01-11 16:08:22 by Ratch
yep, I was aware I could use MUL or to EAX, I changed it anyway.. below is my posted source + 8k exe so far, it draws two triangles and you can use the arrow keys to rotate via X/Z coords..

feel free to expand but please share, including the crits. I will continue expanding this as well.

Here is my loop. I changed to mul and changed sizeoffvx from const. to dword so mul would compile. I put color3f and vertex3f in macros which save the eax - the eax along with the others appear to get trashed.
Instead of

push eax
invoke glColor3f,r,g,b
pop eax

it is

GLCOLOR3f R,G,B

much cleaner. Note: Size changing, FULLSCREEN, and MATRIX modes are not implemented. Rotating to the right will result in clipping of one of the triangles.



invoke glPushMatrix
invoke glBegin,GL_TRIANGLES

xor eax,eax ;kind of pointless in saving speed, loop isn't here..

.while eax <= 2 ;two faces so far.
mul SIZEOFFVX ;must multiply first
GLCOLOR3F R0,R0,R1
GLVERTEX3F [vObj.FVX.x0+eax],[vObj.FVX.y0+eax],[vObj.FVX.z0+eax]
GLCOLOR3F R0,R1,R1
GLVERTEX3F [vObj.FVX.x1+eax],[vObj.FVX.y1+eax],[vObj.FVX.z1+eax]
GLCOLOR3F R1,R1,R0
GLVERTEX3F [vObj.FVX.x2+eax],[vObj.FVX.y2+eax],[vObj.FVX.z2+eax]
add eax,1
.endw

invoke glEnd
invoke glPopMatrix

Posted on 2004-01-11 22:22:22 by drarem
I've reloaded a fix for the loop (see previous post), using eax to simplify the mul has complicated the code a little.. below is the loop fix:



invoke glColor3f,R1,R1,R1
mov eax,3 ;NUMBER OF FACES
mul SIZEOFFVX
mov fx,eax
xor eax,eax ;kind of pointless in saving speed, loop isn't here..

.while eax <= fx

push eax
invoke glPushMatrix
invoke glBegin,GL_TRIANGLES
pop eax
GLCOLOR3F R0,R0,R1
GLVERTEX3F [vObj.FVX.x0+eax],[vObj.FVX.y0+eax],[vObj.FVX.z0+eax]
GLCOLOR3F R0,R1,R1
GLVERTEX3F [vObj.FVX.x1+eax],[vObj.FVX.y1+eax],[vObj.FVX.z1+eax]
GLCOLOR3F R1,R1,R0
GLVERTEX3F [vObj.FVX.x2+eax],[vObj.FVX.y2+eax],[vObj.FVX.z2+eax]
push eax
invoke glEnd
pop eax
add eax,SIZEOFFVX
push eax
invoke glPopMatrix
pop eax
.endw

invoke SwapBuffers,hDC
Posted on 2004-01-11 23:07:05 by drarem