Message board for the users of flat assembler.
> Windows > clock in fasm
how to program a good clock in fasm?
need tutorials or examples..
|23 Sep 2006, 13:10||
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)
; 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.
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.
If you want to convert the values to decimal i can dig out my decimal function
|23 Sep 2006, 17:04||
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||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.