flat assembler
Message board for the users of flat assembler.

Index > Windows > clock in fasm

Author
Thread Post new topic Reply to topic
sylwek32



Joined: 27 Apr 2006
Posts: 339
sylwek32 23 Sep 2006, 13:10
hello,
how to program a good clock in fasm?
need tutorials or examples..
Post 23 Sep 2006, 13:10
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 23 Sep 2006, 17:04
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 Cool
Post 23 Sep 2006, 17:04
View user's profile Send private message Reply with quote
sylwek32



Joined: 27 Apr 2006
Posts: 339
sylwek32 24 Sep 2006, 00:13
i just want a simple looking analog good clock. it should show the time and should have < or ~1ms of rate.
Post 24 Sep 2006, 00:13
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.