QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Timers in C

This is a discussion on Timers in C within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; ^^ topic could someone write me an example of creating, starting and getting the time of a timer in C? ...

Reply
 
LinkBack Thread Tools
Old 04-29-2006, 03:26 PM   #1
 
Soulphalanx's Avatar
 
Join Date: Sep 2005
Location: TROY
Posts: 2,989
Trader Feedback: 0
Default Timers in C

^^ topic

could someone write me an example of creating, starting and getting the time of a timer in C?

thanks
__________________
[IMG]http://img121.imageshack.us/img121/3852/untitled1copy7rf.png[/IMG] [IMG]http://img99.imageshack.us/img99/9711/newavatarjb9.gif[/IMG]


[URL=http://forums.qj.net/showthread.php?t=9733][COLOR=DarkRed]Operation Positive Posting[/COLOR][/URL] [URL=http://forums.qj.net/showthread.php?t=49762][COLOR=Red]Guide to All Guides[/COLOR][/URL]
[URL=http://forums.qj.net/showthread.php?t=13798][COLOR=Blue]Posting Guidelines[/COLOR][/URL] [URL=http://forums.qj.net/showthread.php?t=4394][COLOR=Green]Piracy Policy[/COLOR][/URL]

[SIZE="3"][URL=http://forums.qj.net/f-general-psp-help-22/t-guide-opening-psp-disassembly-assembly-video-104303.html][COLOR=Red][B][U]PSP Disassembly Assembly Video Tutorial[/U][/B][/COLOR][/URL][/SIZE]
Soulphalanx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 05:39 PM   #2

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

...Your joking... You have the internet, resources, and your asking? PS2dev.org has the resources for such a thing, PSP-OSS's source has it, and your still asking?

Please do not ask around here to be spoon fed. you will not learn anything, Plus, i say you actually look at your freekin setup, the SDK has example already. Im sensing some script kiddies around lately...

P.S. In the C/C++ help thread, i am asking for help on rotation, which is not documented in the SDK, or in any source i can find (except rotating frames), or anywhere i could find (google), so this is not a hypicritical statement.
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 06:05 PM   #3

Muppet Magnet
 
Fanjita's Avatar
 
Join Date: Sep 2005
Location: Edinburgh, UK
Posts: 2,388
Trader Feedback: 0
Default

Oh come on, you were far worse when you first started coding. This forum is here for us to help each other.

To answer the original poster's question: I can't remember seeing any specific timer functions in the PSP API, nor do I remember any in stdlib.

However, you can easily do what you want by keeping an array of times. To start a timer, just read the current time into a slot in the array. To get how long the timer has been running, get the current time and subtract the value from the array slot. So long as you don't want to receive an event when the timer reaches a certain value, this is a nice simple way to do it.

The choice of which timer function to use is up to you. If 1-second resolution is sufficient, then you might as well use stdlib's time() function, and have your array as an array of 32-bit ints.

If you need finer resolution, then you might want to use one of the native PSP API functions, from psprtc.h.
Fanjita is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 06:20 PM   #4
 
ghostENVY's Avatar
 
Join Date: Jul 2005
Location: California
Posts: 2,408
Trader Feedback: 0
Default

im not a programmer yet but i dont like seing the lazyness of people ...thats why i started to program in c+ even though i dont have any experince its very easy
__________________
"The True Master Paralyzes His Opponent Leaving Him Vulnerable to Attack"
M.Shinoda
V.3.52 M33
[B][FONT="Times New Roman"]Thanks Deturb For Premium.[/FONT][/B]
[IMG]http://i118.photobucket.com/albums/o106/ghostENVY/Untitled-2.jpg[/IMG]
ghostENVY is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 06:39 PM   #5

Psp Dev
 
MikePiP's Avatar
 
Join Date: Jun 2005
Location: Nebraska
Posts: 228
Trader Feedback: 0
Default

Whats C+??
__________________


http://www.myspace.com/mikee_mo
MikePiP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 08:08 PM   #6
 
Join Date: Jan 2006
Posts: 4,288
Trader Feedback: 0
Default

Quote:
Originally Posted by Fanjita
Oh come on, you were far worse when you first started coding. This forum is here for us to help each other.

To answer the original poster's question: I can't remember seeing any specific timer functions in the PSP API, nor do I remember any in stdlib.

However, you can easily do what you want by keeping an array of times. To start a timer, just read the current time into a slot in the array. To get how long the timer has been running, get the current time and subtract the value from the array slot. So long as you don't want to receive an event when the timer reaches a certain value, this is a nice simple way to do it.

The choice of which timer function to use is up to you. If 1-second resolution is sufficient, then you might as well use stdlib's time() function, and have your array as an array of 32-bit ints.

If you need finer resolution, then you might want to use one of the native PSP API functions, from psprtc.h.
I was thinking about a timer myself, and I was planning on doing some sort of loop, and just have sceKernelDelayThread(what ever value for the interval's time) then add to a value. Would that work?
__________________
[URL="http://www.newlilwayne.com"]www.NewLilWayne.com[/URL]
soccerPMN is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 08:21 PM   #7

Developer
 
Join Date: Oct 2005
Posts: 408
Trader Feedback: 0
Default

Quote:
Originally Posted by soccerPMN
I was thinking about a timer myself, and I was planning on doing some sort of loop, and just have sceKernelDelayThread(what ever value for the interval's time) then add to a value. Would that work?
It'll work but it's not accurate. If you want something to happen at a certain time interval, use sceKernelLibcClock() to get the number of microseconds the program has been running.

Code:
// wait for 5 seconds to pass while doing other things
clock_t start_time = sceKernelLibcClock();

while(sceKernelLibcClock() - start_time < 5000000)
{
        // do other chores
        sceKernelDelayThread(10000);  // wait 10 milliseconds (optional)
}
Samstag is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-29-2006, 08:31 PM   #8
 
Join Date: Jan 2006
Posts: 4,288
Trader Feedback: 0
Default

Erm, well, I just want to have something to be able to countdown any number of hours and minutes, and display the remaining time. But from looking at your code, if my desired interval was one second, I would just put that where 5000000 is right now, in microseconds?
__________________
[URL="http://www.newlilwayne.com"]www.NewLilWayne.com[/URL]
soccerPMN is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-30-2006, 05:38 AM   #9

Developer
 
Join Date: Oct 2005
Posts: 408
Trader Feedback: 0
Default

Quote:
Originally Posted by soccerPMN
Erm, well, I just want to have something to be able to countdown any number of hours and minutes, and display the remaining time. But from looking at your code, if my desired interval was one second, I would just put that where 5000000 is right now, in microseconds?
Right. If you want to wait 1 second, you would use 1,000,000. If you want something to happen at a certain time of day you can use sceKernelLibcGettimeofday () but otherwise you'll have to keep track of the countdown yourself.
Samstag is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-30-2006, 10:25 AM   #10
 
Soulphalanx's Avatar
 
Join Date: Sep 2005
Location: TROY
Posts: 2,989
Trader Feedback: 0
Default

Quote:
Originally Posted by Samstag
It'll work but it's not accurate. If you want something to happen at a certain time interval, use sceKernelLibcClock() to get the number of microseconds the program has been running.

Code:
// wait for 5 seconds to pass while doing other things
clock_t start_time = sceKernelLibcClock();

while(sceKernelLibcClock() - start_time < 5000000)
{
        // do other chores
        sceKernelDelayThread(10000);  // wait 10 milliseconds (optional)
}
thanks samstag, this is exactly what im looking for

@SG57
i have searched on google and looked at the pspsdk documentation, but couldnt find any timer functions, so thats why i asked
__________________
[IMG]http://img121.imageshack.us/img121/3852/untitled1copy7rf.png[/IMG] [IMG]http://img99.imageshack.us/img99/9711/newavatarjb9.gif[/IMG]


[URL=http://forums.qj.net/showthread.php?t=9733][COLOR=DarkRed]Operation Positive Posting[/COLOR][/URL] [URL=http://forums.qj.net/showthread.php?t=49762][COLOR=Red]Guide to All Guides[/COLOR][/URL]
[URL=http://forums.qj.net/showthread.php?t=13798][COLOR=Blue]Posting Guidelines[/COLOR][/URL] [URL=http://forums.qj.net/showthread.php?t=4394][COLOR=Green]Piracy Policy[/COLOR][/URL]

[SIZE="3"][URL=http://forums.qj.net/f-general-psp-help-22/t-guide-opening-psp-disassembly-assembly-video-104303.html][COLOR=Red][B][U]PSP Disassembly Assembly Video Tutorial[/U][/B][/COLOR][/URL][/SIZE]
Soulphalanx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-30-2006, 10:58 AM   #11
 
Join Date: Oct 2005
Posts: 543
Trader Feedback: 0
Default

int timer;
float timer2;

while(1) do{
timer++;
timer2 = timer/1000;
printf("The timer is currently at %f milliseconds",timer2);
pspDebugScreenClear;
}

I think that would work, not sure about the function stuff, also needs some includes and defines.
__________________
HELP ME HAIRY LEG!!!!

I have a 1.5 (downgraded) US PSP
[code]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
( P | S | P | - | P | r | o | g | r | a | m | m | i | n | g )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
_ _ _ _ _
/ \ / \ / \ / \ / \
( A | d | m | i | n )
\_/ \_/ \_/ \_/ \_/ [/code]

Last edited by nathan42100; 04-30-2006 at 11:02 AM..
nathan42100 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-06-2006, 03:06 AM   #12
 
Nutterbutter's Avatar
 
Join Date: Jun 2006
Location: London
Posts: 645
Trader Feedback: 0
Default

Quote:
Originally Posted by nathan42100
int timer;
float timer2;

while(1) do{
timer++;
timer2 = timer/1000;
printf("The timer is currently at %f milliseconds",timer2);
pspDebugScreenClear;
}

I think that would work, not sure about the function stuff, also needs some includes and defines.
Looks very inacurate.
__________________
[b][center]
[URL="http://forums.qj.net/showthread.php?t=65032"][SIZE="3"][COLOR="Blue"]Omicron[/COLOR] - [COLOR="DeepSkyBlue"]A hacking simulation game for the PSP[/COLOR][/SIZE][/URL]

[url=http://profile.mygamercard.net/dr+nutterbutter][img]http://card.mygamercard.net/gbar/live/dr+nutterbutter.gif[/img][/url][/b][/center]
Nutterbutter is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-06-2006, 06:46 AM   #13
 
ttotto's Avatar
 
Join Date: Apr 2006
Location: Upland, California
Posts: 89
Trader Feedback: 0
Default

personally I used this in my C code:

Code:
int timer =time(NULL);
int count = 0;

void main(){
while (1){

 int count = (( timer - time (NULL))* -1);
}
return 0;
}
the time i held in the variable count.
__________________
PSP 1.5
Psp homebrew projects:
psp RTS

MY WEBPAGE
ttotto is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
timers

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 08:16 AM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us