News:

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

Make clock run fast

Started by thomasantony, June 15, 2005, 10:52:55 AM

Previous topic - Next topic

thomasantony

Hi,
  Is it possible to make the windows clock run faster? :bdg

Thomas
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

chep

Maybe set up a timer every 500ms and advance the clock of 500ms, it will run 2 times faster.

I don't know how to change the clock though.

Pseudocode :
SETUP 500ms TIMER

TimerProc:
  STOP TIMER (to avoid recursion?)
  clock = clock + 500ms
  SETUP 500ms TIMER
ENDP


But this requires the program to be resident.

I feel sorry for the poor person to whom you'll make the trick. :cheekygreen:

thomasantony

Hmm,
  Maybe I can use GetSystemTime and SetSystemTime. But thats gotta be a hell lot slow if I do it twice a second!!

Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

thomas_remkus

I'm just a noob, so I'll call this pseudo code ...

time_warp:
LOCAL st:SYSTEMTIME
invoke GetSystemTime, addr st
invoke Sleep, 10
invoke SetSystemTime, st
goto time_warp


Just start this and let it run. Again, it's very simple and done incorrectly as when I was trying to make a sample of this working is all came out wrong. But, I just wanted to share my idea.

thomasantony

No,

  I think you should increment the seconds or minutes value of the SYSTEMTIME struct.

Thomas
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

thomas_remkus

My bad code also has a design flaw. Basically, get the current time, sleep 1, set the clock back, wait for a sort of random amount of time, start the hell all over.

LOCAL st:SYSTEMTIME
time_warp:
invoke GetSystemTime, addr st
invoke Sleep, 1
invoke SetSystemTime, st
invoke Sleep, ((st.wMinute + st.wSecond) * 10)
goto time_warp


Again, I know this code won't run but it doesn't mean that I haven't been trying. I know there must be something with the "add" and such. If anyone wants to make this bad code actually work please do ... because that's what I am working on trying to get running.

thomas

Mark Jones

I think the sleep intervals need to be much longer. 1000ms = 1 second, so if you wanted to "subtract half a second" to each second of time, you'd want something like:


LOCAL st:SYSTEMTIME
time_warp:
invoke GetSystemTime, addr st  ; might need to be "offset st" or just "st"
invoke Sleep, 500
invoke SetSystemTime, st
invoke Sleep, 500
goto time_warp


...perhaps. Untested. :)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

thomas_remkus

In effect, you are making the clock seem twice as slow. Any time they are the same number you will get this effect. So if you put in 1 and 1 then you will get the same effect in theory. If you put 2 and 1 then you will have a slower computer clock, and something like 1 and 2 will make you seem faster.

Of course, I am trying to get this actually working .... for some strange educational purpose.

thomas

chep

To adjust the time more easily you'd better use FILETIME structures :
Quote from: MSDNA file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 (UTC).
Using a SYSTEMTIME structure for *accelerating* the clock would require you to propagate the change into all "higher" fields of the structure, which is plain overkill.


To *accelerate* the clock (here, add 500ms every 500ms so it runs twice faster) :
QuoteLOCAL st:SYSTEMTIME
LOCAL ft:FILETIME
time_warp:
; get system time in a FILETIME structure (64bits, in 100's of nanoseconds)
invoke GetSystemTimeAsFileTime, ADDR ft

; convert milliseconds to 100's of nanoseconds, and add it
add ft.dwLowDateTime, 500*10000 ; number_of_milliseconds*10000
adc ft.dwHighDateTime, 0 ; propagate carry

; convert back to a SYSTEMTIME structure
invoke FileTimeToSystemTime, ADDR ft, ADDR st
; set system time
invoke SetSystemTime, ADDR st

invoke Sleep, 500
jmp time_warp

not tested, but it should work I think. :wink