News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

About Timer

Started by ragdogz, February 02, 2009, 04:21:09 AM

Previous topic - Next topic

ragdogz

Hi, i want to know about timer in assembly.
In VB, the standard timer control is limited to 65535 ms. if i want to use higher than that, than i have to add some IF conditional logic to check if the required amount of time has passed since the last interval.
but in assembly i set like this:

invoke SetTimer,hWnd,ID_TIMER,180000,0

it's for 3 minutes right? it works! why?
so, how many milliseconds limit of timer in assembly?

thx..

sinsi

USER_TIMER_MAXIMUM  equ 0x7FFFFFFF

which is 2 million seconds?
Light travels faster than sound, that's why some people seem bright until you hear them.

donkey

Quote from: sinsi on February 02, 2009, 04:28:57 AM
USER_TIMER_MAXIMUM  equ 0x7FFFFFFF

which is 2 million seconds?

2.1 Million seconds, around 25 days.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ragdogz

@sinsi & donkey
thx for your explanation

now i need some help to get the number from the user input..
what i want to do is using the number specified by the user. if the user write "10000" in the textbox then i want to use that number for sleep or timer..

.data
Msg  db "Test",0

.data?
delay db 256 dup(?)

.const
IDC_TEST equ 1000
EDIT_DELAY equ 2000

DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
...
...
.ELSEIF uMsg==WM_COMMAND
.ELSE
mov edx,wParam
shr edx,16
.if dx==BN_CLICKED
.IF ax==IDC_TEST
invoke Sleep,10000
invoke MessageBox,NULL,addr Msg,addr Msg,MB_OK
.ENDIF
.ENDIF
.ENDIF
...
...


normally i will use the above syntax to sleep 10 seconds and then show messagebox. but i want to use the number in the EDIT_DELAY for sleep.
i use this:

.IF ax==IDC_TEST
invoke GetDlgItemText,hWnd,EDIT_DELAY,addr delay,256


what's next?
thx for help..

PBrennick

You can do either of 2 things:

1. Convert the resulting string into a DWORD using atodw (or similar - I use AsciiBase)
2. Use GetDlgItemInt instead of GetDlgItemText.

Either way, you should set the ES_NUMBER flag for the editbox.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

ragdogz

Hi PBrennick, thx very much for your help.
i'm successful using atodw:

.IF ax==IDC_TEST
invoke GetDlgItemText,hWnd,EDIT_DELAY,addr delay,256
invoke atodw,addr delay
invoke Sleep,eax
invoke MessageBox,NULL,addr Msg,addr Msg,MB_OK


i didn't know atodw function before, and i found it in atodw.asm in \masm32\m32lib. now i'm gonna practice using the other way u told..
thx again for your help..

PBrennick

 :U

Just remember that ES_NUMBER will help prevent you having to deal with invalid entries whether you get the text OR the integer.

Also, you can easily access the procedures in m32lib by loading the library that they are all in.

include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib

masm32.inc will add the necessary PROTO instruction for you. This way, you do not need to add the procedure code into your source file, just add the appropriate invoke statement and you are good to go.


Paul
The GeneSys Project is available from:
The Repository or My crappy website

ragdogz

Hi again,
this is my include file after adding masm32.inc:

include c:\masm32\include\masm32.inc
include c:\masm32\include\dialogs.inc
include c:\masm32\include\windows.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc
include c:\masm32\include\ws2_32.inc


that produced error like this:

c:\masm32\include\windows.inc <98> : error A2005: symbol redefinition : CHAR

but if i put masm32 at the end, then all work fine..

include c:\masm32\include\dialogs.inc
include c:\masm32\include\windows.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc
include c:\masm32\include\ws2_32.inc
include c:\masm32\include\masm32.inc


i'm curious, is there any rule on how to write the include files position?

PBrennick

The really important one is windows.inc - place it first, always, after that, in my opinion, you should follow Hutch's lead and do it the way he does.

Look at masm32rt.inc to see what I mean. Actually that include can replace ALL the others. I have never used it but I see others use it all the time. It is a real finger saver.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

ragdogz

i really appreciate this. i just saw that masm32rt.inc file. now i understand..
thx very much..

Mark Jones

The "purists" of course may say that using a "blanket" include like this is bad form, as it does take a few more milliseconds to process all those linked includes regardless of wether or not any of them are used for the code being worked on. For beginners though, it is easy and works well.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

PBrennick

Exactly ...

What I do to avoid the chaff but still do some finger saving is use the macro method, like this:
Quote
;---------------------------------------
; Sudoku,  Version 1.1.0
; By: Paul Brennick

    .386
    .model  flat, stdcall
    option  casemap :none

    include \GeneSys\include\Windows.inc
    include \GeneSys\macros\macros.asm
    uselib  user32,kernel32,shell32,gdi32,GeneSys

Paul
The GeneSys Project is available from:
The Repository or My crappy website