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 

wrong CLOCKS_PER_SEC?

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



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sun Sep 04, 2005 8:48 am    Post subject: wrong CLOCKS_PER_SEC? Reply with quote

I've used this Lua Player script:

Code:

white = Color.new(255, 255, 255)
while true do
   screen:clear()
   screen:print(0, 0, "clock: " .. os.clock(), white)
   screen.waitVblankStart()
   screen.flip()
   if Controls.read():start() then break end
end


and every second 1000 is added. os.clock() is implemented like this in the lua lib:

Code:

static int io_clock (lua_State *L) {
  lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
  return 1;
}


so looks like CLOCKS_PER_SEC needs to be multiplied by 1000.
Back to top
View user's profile Send private message
cooleyandy



Joined: 02 Jul 2005
Posts: 41

PostPosted: Sun Sep 04, 2005 11:08 am    Post subject: Reply with quote

heh, looks like the same problem I have had. I asked this question also like a month ago with no response. Yes, it's 1,000,000 clock ticks per second and CLOCK_PER_SEC should be 1,000,000.
Back to top
View user's profile Send private message
Agoln



Joined: 08 Jun 2005
Posts: 326
Location: Fort Wayne, IN

PostPosted: Wed Sep 07, 2005 8:04 am    Post subject: Reply with quote

LUA problems should be in the LUA forum...

Moved.
_________________
Lego of my Ago!
Back to top
View user's profile Send private message AIM Address
chaos



Joined: 10 Apr 2005
Posts: 135

PostPosted: Wed Sep 07, 2005 12:14 pm    Post subject: Reply with quote

Agoln wrote:
LUA problems should be in the LUA forum...

Moved.


gotta love the moderation around here ;)
_________________
Chaosmachine Studios: High Quality Homebrew.
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Wed Sep 07, 2005 4:27 pm    Post subject: Reply with quote

Agoln wrote:
LUA problems should be in the LUA forum...


This is not a Lua Player problem, moved back to PSPSDK Support and Development. Try this code:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <time.h>

/* Define the module info section */
PSP_MODULE_INFO("TEST", 0, 1, 1);

/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

int main(void)
{
   pspDebugScreenInit();

   int c = 0;
   clock_t t0 = clock();
   while (1) {
      clock_t t1 = clock();
      pspDebugScreenClear();
      int delta = t1 - t0;
      pspDebugScreenPrintf("%i", delta / CLOCKS_PER_SEC);
      sceDisplayWaitVblankStart();
      sceDisplayWaitVblankStart();
      if (c++ == 300) break;
   }
   sceKernelExitGame();

   return 0;
}


clock()/CLOCKS_PER_SEC is defined to give seconds, not milliseconds, but I don't know where to change it in PSPSDK.
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Thu Sep 08, 2005 3:52 am    Post subject: Reply with quote

You wont find it in pspsdk because it is a newlib thing, seems Sony's clock function follows the POSIX standard by making clock in 1e6 units, while newlib err doesn't :P

I'll try and get around to adjusting it at some point (note: it shouldn't require a rebuild of newlib if you have it, just change it in /usr/local/pspdev/psp/include/time.h)
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Thu Sep 08, 2005 9:09 am    Post subject: Reply with quote

TyRaNiD wrote:
I'll try and get around to adjusting it at some point (note: it shouldn't require a rebuild of newlib if you have it, just change it in /usr/local/pspdev/psp/include/time.h)


Thanks, now it works.
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Tue Oct 25, 2005 2:46 am    Post subject: Reply with quote

The latest PSPSDK with GCC 4.0.2 has introduced the bug again, please patch it again.
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Tue Oct 25, 2005 6:18 am    Post subject: Reply with quote

It was broken back in r1096 when the newlib patch as regenerated. It should be fixed (for good) in r1218.
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Tue Oct 25, 2005 4:39 pm    Post subject: Reply with quote

jimparis wrote:
It was broken back in r1096 when the newlib patch as regenerated. It should be fixed (for good) in r1218.


Thanks, it works again.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP 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