flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Can you halp me to write timer into DLL

Author
Thread Post new topic Reply to topic
DarkLordTed



Joined: 25 Nov 2017
Posts: 14
Hello, I need some help! I need to have timer into DLL but until this timer is stanby the processor must be free to work other. I try to make loop with GetMessageA but result is not good.
Can you give me little example?
Post 10 Dec 2017, 15:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15976
Location: Qo'noS
You can use Sleep to delay execution.
Code:
invoke Sleep,1000 ;wait 1 second (1000 milliseconds)    
You can use WaitMessage to relinquish control when no message are in the queue.
Post 10 Dec 2017, 15:46
View user's profile Send private message Visit poster's website Reply with quote
DarkLordTed



Joined: 25 Nov 2017
Posts: 14
Thank you!
Post 10 Dec 2017, 17:09
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 362
Location: Belarus
DarkLordTed
I guess, it’s worth noting that you’ve probably divided your problem into two parts: easy and strange.

Asking for a blocking delay (synchronous) is really strange and, generally, smells like bad design. What problem are you REALLY trying to solve?
Post 11 Dec 2017, 11:57
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1227
Maybe look at SetTimer?
Post 11 Dec 2017, 12:58
View user's profile Send private message Reply with quote
donn



Joined: 05 Mar 2010
Posts: 106
If you're looking for something more high-resolution, I've been using QueryPerformanceCounter (https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx), which is encouraged over rdtsc/p. It's trickier to use than sleep/setTimer, but the overhead is 10s-100s of cycles with fine-grained results.

I've written some wrappers for them, but haven't spent much time on it. One version seems to work and notifies when x ms pass, or that x ms pass, the other function returns the same in microseconds. They're not tested enough, but seemed to time the correct amount of time elapsed so far. They use qpc mainly like this:

Code:
        sub rsp, 8*4
        mov rcx, [newTime.time.frequency]
        call [QueryPerformanceFrequency]
        add rsp, 8*4    


Save start time:
Code:
        mov rbx, [startTime.time]
        mov rdx, rbx
        add rdx, Time.duration                  ; Get Time.duration address
        mov r11, [rdx]
        mov qword [r11], 0                      ; Initialize as 0

        sub rsp, 8*4
        add rbx, Time.start
        mov rcx, [rbx]
        call [QueryPerformanceCounter]
        add rsp, 8*4    


query the delta time, divide by freq:

Code:
        sub rsp, 8*4
        mov rbx, [deltaTime.time]
        add rbx, Time.duration
        mov rcx, [rbx]
        call [QueryPerformanceCounter]
        add rsp, 8*4    


using a struc with ptrs:

Code:
        struc Time{
                .duration                               dq 0                    ;Address
                .frequency                              dq 0                    ;Address
                .start                                  dq 0                    ;Address
        }
    


I can post any 64-bit functions/the Time.inc file I'm using, but would need to test it a bit more and provide an integer result version. I'm currently outputting as single precision.
Post 12 Dec 2017, 17:57
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.