forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

uclock(), usleep(), localtime() and readdir() equivalents

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
0xF



Joined: 22 Sep 2005
Posts: 1

PostPosted: Thu Sep 22, 2005 7:59 pm    Post subject: uclock(), usleep(), localtime() and readdir() equivalents Reply with quote

I'd like to know, how to get the following functionality from C:

  1. A clock with 1ms resolution or better.
  2. A sleep function with 1ms resolution or better
    (or should I spin in a loop using the above clock?)
  3. Realtime clock (year, month, day of month, day of week,
    hour, minute, second)
  4. Read memory card's or CD's directory
    (should I use fioD* from PS2SDK?)

Thank you.
Back to top
View user's profile Send private message
_tmator_



Joined: 15 Nov 2004
Posts: 19
Location: France

PostPosted: Fri Sep 23, 2005 1:08 am    Post subject: Reply with quote

Hi,

1 : See SDL timer code (SDL_Delay)
2 : Just create a thread and wait a sema sent by the thread when X ms will pass
3 : libcdvd i think but not sure
4 : See PS2MENU code in svn/ps2ware, it's a good example to know how read MC and CD'S directory
Back to top
View user's profile Send private message
DeRieux



Joined: 06 Jul 2006
Posts: 9

PostPosted: Thu Jul 06, 2006 10:16 am    Post subject: Re: usleep() Reply with quote

You can try the following code:

Code:

#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);
}


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.
Back to top
View user's profile Send private message Send e-mail
DeRieux



Joined: 06 Jul 2006
Posts: 9

PostPosted: Thu Jul 06, 2006 10:25 am    Post subject: Followup: Reply with quote

0xF wrote:
I'd like to know, how to get the following functionality from C:

  1. A clock with 1ms resolution or better.
  2. A sleep function with 1ms resolution or better
    (or should I spin in a loop using the above clock?)
  3. Realtime clock (year, month, day of month, day of week,
    hour, minute, second)
  4. Read memory card's or CD's directory
    (should I use fioD* from PS2SDK?)

Thank you.


Sleep Function - See My Last Post about cpu_ticks (in timer.h)

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?t=2842&highlight=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
Quote:

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;
};
[url][/url]
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group