- A clock with 1ms resolution or better.
-  A sleep function with 1ms resolution or better
 (or should I spin in a loop using the above clock?)
-  Realtime clock (year, month, day of month, day of week,
 hour, minute, second)
-  Read memory card's or CD's directory
 (should I use fioD* from PS2SDK?)
uclock(), usleep(), localtime() and readdir() equivalents
uclock(), usleep(), localtime() and readdir() equivalents
I'd like to know, how to get the following functionality from C:
			
			
									
									
						Re: usleep()
You can try the following code:
This will draw some text on the screen, set the screen size, and then wait a set number of cpu_ticks and clear the screen.
William
Hope this may help.
			
			
									
									
						Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <tamtypes.h>
#include <sifcmd.h>
#include <kernel.h>
#include <sifrpc.h>
#include <string.h>
#include <sys/stat.h>
#include <debug.h>
#include <timer.h>
#define clearscreen() scr_clear() /*Defines easily understood macro */
#define DrawSimpleString(char) scr_printf(char) /* ditto */
void PauseBeforeClear(int wait_timer);
void SetScreenSize(int x, int y);
int main()
{   
   
   SifInitRpc(0); 
   init_scr(); 
   
   SetScreenSize(80,25);
   DrawSimpleString("\nPause Execution for x Cpu_Ticks()\n");
   DrawSimpleString("\n..........Code By...............\n");
   DrawSimpleString("\n    William DeRieux, 5/5/2006   \n");   
   PauseBeforeClear(100); /* Timer in Cpu_Ticks()*/
  
	
	return(0);
	
}
void PauseBeforeClear(int wait_timer)
{
	int ticks = 0;
	
	do
	{
		ticks = cpu_ticks();
	}
	while (ticks != wait_timer);	
	
	if (ticks == wait_timer)
	{
		clearscreen();
	}
}
void SetScreenSize(int x, int y)
{
	scr_setXY(x,y);
}
William
Hope this may help.
Followup:
Sleep Function - See My Last Post about cpu_ticks (in timer.h)0xF wrote:I'd like to know, how to get the following functionality from C:Thank you.
- A clock with 1ms resolution or better.
- A sleep function with 1ms resolution or better
(or should I spin in a loop using the above clock?)- Realtime clock (year, month, day of month, day of week,
hour, minute, second)- Read memory card's or CD's directory
(should I use fioD* from PS2SDK?)
EDIT: The Sleep Function does wait a specified number of cpu ticks,
But, it is not consistent and is relatively unreliable...I do not
recommend using it as an actual timer, unless you just want to
pause for a little bit (not wait a specified number of seconds,
minutes, etc)
Shawn_t has a much better solution posted here:
http://forums.ps2dev.org/viewtopic.php? ... clock+tick
(I will be making an additional post there, regarding using that solution to implement a fix for the timer)
clock function - possible use cpu_ticks as well
Realtime Clock - have a look at time.h
snippet from time.h
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};

