Page 1 of 1

How To Wait/Pause?

Posted: Wed Dec 09, 2009 1:45 am
by jgrimm
how do you pause program execution for an amount of time? what i need to do is like the BASIC sleep command, so pause 5 miliseconds is SLEEP 5. how do i do this in ps2sdk? thx

Posted: Wed Dec 09, 2009 4:33 am
by cheriff
ps2sdk contains a basic libc. The parts it implements, should be very similar to any other libc:

Code: Select all

NAME
     sleep -- suspend thread execution for an interval measured in seconds

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <unistd.h>

     unsigned int
     sleep&#40;unsigned int seconds&#41;;
and, lo and behold:

Code: Select all

cheriff@lappy386&#58;~/code/$ grep -R sleep ps2sdk/ee/libc/
ps2sdk/ee/libc/include/unistd.h&#58;unsigned int sleep&#40;unsigned int seconds&#41;;

Posted: Wed Dec 09, 2009 5:49 am
by ragnarok2040
There currently isn't anything in ps2sdk that's millisecond accurate except for clock(). You can just use CLOCKS_PER_SEC/1000 to calculate the amount of ticks per millisecond, or just define it as 576 using a macro, and compare to clock() until the period of time has passed.

Posted: Thu Dec 10, 2009 5:15 am
by jgrimm
ok thx guys it doesnt need to be to be perfect i just need somthing that counts time :)