View previous topic :: View next topic |
Author |
Message |
akumakuja28 Master Cheater
Reputation: 16
Joined: 28 Jun 2015 Posts: 432
|
Posted: Thu Jan 12, 2017 7:56 pm Post subject: Is thr a simple way to call mscvrt.atan |
|
|
Basically I am having a hell of time calling mscvrt.dll to do trig functions.
_________________
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Thu Jan 12, 2017 8:09 pm Post subject: |
|
|
If you are able to use Lua calls and such in what you are doing, you can use Luas math.atan function.
_________________
- Retired. |
|
Back to top |
|
 |
akumakuja28 Master Cheater
Reputation: 16
Joined: 28 Jun 2015 Posts: 432
|
Posted: Thu Jan 12, 2017 8:16 pm Post subject: |
|
|
LUA would be very easy. Just figure im this far with this mscvrt.dll I would love to finish it
_________________
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25779 Location: The netherlands
|
Posted: Thu Jan 12, 2017 8:19 pm Post subject: |
|
|
in 32-bit or 64-bit ?
it uses cdecl calling convention so:
32-bit:
Code: |
push value
call msvcrt.atan
add esp,4 //undo the param push (cdecl thing)
//eax is value
|
64-bit:
Code: |
mov rcx,value
call msvcrt.atan
|
(with 64-bit do make sure the stack is alligned, and that the function you're in has been setup for function calling, else allocate stackspace first)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
akumakuja28 Master Cheater
Reputation: 16
Joined: 28 Jun 2015 Posts: 432
|
Posted: Thu Jan 12, 2017 8:37 pm Post subject: |
|
|
Thank You DB. At least I know whr to go next.
_________________
|
|
Back to top |
|
 |
akumakuja28 Master Cheater
Reputation: 16
Joined: 28 Jun 2015 Posts: 432
|
Posted: Fri Jan 13, 2017 5:33 am Post subject: |
|
|
Well i finally got it to stop crashing. Although I see no trig value being converted anywhere. In 64-bit is stored else where(not returned to a register)?
_________________
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25779 Location: The netherlands
|
Posted: Fri Jan 13, 2017 5:56 am Post subject: |
|
|
64 bit takes params in registers rcx, rdx, r8 and r9
(return value is still eax)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4695
|
Posted: Fri Jan 13, 2017 10:02 am Post subject: |
|
|
32-bit:
Arguments go on the stack. Integer return values go in eax, fp return values go in st(0).
Code: | globalalloc(example,1024)
createthread(example)
example:
push [example+104]
push [example+100]
call msvcrt.atan
add esp,8
fstp qword ptr[example+108]
ret
example+100: // input
dq (double)1.0
example+108: // result
dq 0 |
64-bit:
Integer arguments are passed through rcx, rdx, r8, and r9. fp arguments are passed through xmm0-3. There should be storage on the stack aligned on a 16-byte boundary for the four integer arguments regardless of whether or not there are that many arguments. Excess arguments are passed through the stack above the storage for the four integer arguments. Integer return values go in rax, fp return values go in xmm0.
Code: | globalalloc(example,1024)
createthread(example)
example:
push rbp
mov rbp,rsp
and spl,F0
sub rsp,20
movsd xmm0,[example+100]
call msvcrt.atan
movsd [example+108],xmm0
mov rsp,rbp
pop rbp
ret
example+100: // input
dq (double)1.0
example+108: // result
dq 0 |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
akumakuja28 Master Cheater
Reputation: 16
Joined: 28 Jun 2015 Posts: 432
|
Posted: Fri Jan 13, 2017 4:55 pm Post subject: |
|
|
Code: |
alloc(Trig,1000)
registersymbol(Trig)
alloc(pi,1000)
registersymbol(pi)
alloc(Reg,1000)
registersymbol(Reg)
label(code)
label(return)
label(Over180)
label(Under180)
label(Finish)
/// Pre Load Values
Trig:
dq (double)234
Trig+30:
dq (double)234
// Radian Math
pi: // Unused
dq (double)3.141592653589793238462643383279
pi+10: //180/pi
dq (double)57.29577951307854999853275233034
pi+20:
dq (double)180
pi+30:
dq (double)-1
/// Cosine From Degrees
movsd xmm0,[Trig]
divsd xmm0,[pi+10]
call msvcrt.cos
movsd [Trig+10],xmm0 // Is returned as Cosine
movsd [Trig+20],xmm3 // Is returned as IDK
/// ArcCos from Cosine (Above)
movsd xmm0,[Trig+10] // Value from Call .cos
call msvcrt.acos
movsd [Trig+70],xmm0 // Is returned as Radians
movsd [Trig+80],xmm3 // Is returned as IDK
mulsd xmm0,[pi+10] // Multiply RADIANS by 180 to get Degrees
/// Value Check for Above 180
movsd xmm3,[Trig] // Intial Degree Value
comisd xmm3,[pi+20] // compare to 180 vale
jae Over180
jb Under180
Under180:
movsd [Trig+90],xmm0 // Is returned as Degrees
jmp Finish
// FUckery Math
Over180:
mulsd xmm0,[pi+30] //mul - 1
addsd xmm0,[pi+20] //Add 180 degrees
addsd xmm0,[pi+20] //Add 180 degrees
movsd [Trig+100],xmm0 // Fixed Degrees
jmp Finish
|
Well its working as expected Thank You everyone for the help.
I will admit I have seen alot of camera code and I have never seen anything like this. I mention this to ask a question.
Is this is the correct way to code this?
Or is thr a more efficient method?
And what is the relationship to Xmm3?
Also is there some documentation on this somewhere tht is written in ASM? (Searched Google like a mad man nothing turned up)
_________________
|
|
Back to top |
|
 |
|