flat assembler
Message board for the users of flat assembler. Index > Windows > clock in fasm
Author
 Thread  sylwek32

Joined: 27 Apr 2006
Posts: 339
sylwek32
hello,
how to program a good clock in fasm?
need tutorials or examples.. 23 Sep 2006, 13:10  cod3b453

Joined: 25 Aug 2004
Posts: 619
cod3b453
1) Are you trying to make a clock to tell the time or a stopwatch?

2) Graphical or just write text?

Whatever type it is, you'll probably want to use SetTimer & GetSystemTime.

For a graphical clock (with hands) use parametric equations:

;s = seconds
;L = Lenght of hand

;k= (seconds / max seconds) * 2Pi radians per rotation
k = (s / 60) * (2 * Pi) = (s * Pi) / 30 [rad]
y = L + Lcos(k)
x = L + Lsin(k)

Code:
```; Using FPU:

mov eax,[s]
push eax
fld dword [esp] ; st0 = s
pop eax
push dword 30
fld dword [esp] ; st0 = 30; st1 = s
pop eax
fdivp st1,st0 ; st0 = s/30
fldpi ; st0 = pi; st1 = s/30
fmulp st1,st0 ; st0 = (s* pi)/30
fsincos ; st0 = cos(k); st1 = sin(k)
fld1 ; st0 = 1; st1 = cos(k); st2 = sin(k)
fadd st1,st0 ; st0 = 1; st1 = 1+cos(k); st2 = sin(k)
faddp st2,st0 ;st0 = 1+cos(k); st1 = 1+sin(k)
mov eax,[L]
push eax
fld dword [esp] ; st0 = L; st1 = 1+cos(k); st2 = 1+sin(k)
fmul st1,st0 ; st0 = L; st1 = L + Lcos(k); st2 = 1 + sin(k)
fmulp st2,st0 ; st0 = L + Lcos(k); st1 = L + Lsin(k)
fstp dword [esp] ; st0 = L + Lsin(k)
pop eax
push eax
mov [y],eax
fstp dword [esp] ;
pop eax
mov [x],eax
```

I've just blasted that straight off so you might wanna check it, but all you have to do is add the clock's offset to [x] and [y]. You'll have to do this for each hand on the clock.

[EDIT]
This will make the clock 2L wide and 2L tall, to draw the hands draw a line from (L,L) to (x,y). To draw the hour or second locations as dots around the clock face do the same as above by making L,say, 2 pixels bigger and use setpixel(x,y) instead of lineto.
[/EDIT]

If you want to convert the values to decimal i can dig out my decimal function

HTH  23 Sep 2006, 17:04  sylwek32

Joined: 27 Apr 2006
Posts: 339
sylwek32
i just want a simple looking analog good clock. it should show the time and should have < or ~1ms of rate. 24 Sep 2006, 00:13  Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First  Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum