The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ragdogz on February 02, 2009, 04:21:09 AM

Title: About Timer
Post by: ragdogz on February 02, 2009, 04:21:09 AM
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..
Title: Re: About Timer
Post by: sinsi on February 02, 2009, 04:28:57 AM
USER_TIMER_MAXIMUM  equ 0x7FFFFFFF

which is 2 million seconds?
Title: Re: About Timer
Post by: donkey on February 02, 2009, 04:37:19 AM
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.
Title: Re: About Timer
Post by: ragdogz on February 08, 2009, 01:11:54 PM
@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..
Title: Re: About Timer
Post by: PBrennick on February 08, 2009, 05:22:50 PM
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
Title: Re: About Timer
Post by: ragdogz on February 08, 2009, 07:14:54 PM
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..
Title: Re: About Timer
Post by: PBrennick on February 08, 2009, 07:46:47 PM
 :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
Title: Re: About Timer
Post by: ragdogz on February 08, 2009, 09:11:44 PM
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?
Title: Re: About Timer
Post by: PBrennick on February 09, 2009, 01:53:21 AM
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
Title: Re: About Timer
Post by: ragdogz on February 09, 2009, 01:54:49 PM
i really appreciate this. i just saw that masm32rt.inc file. now i understand..
thx very much..
Title: Re: About Timer
Post by: Mark Jones on February 10, 2009, 01:07:02 AM
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.
Title: Re: About Timer
Post by: PBrennick on February 10, 2009, 04:20:07 PM
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