| View previous topic :: View next topic |
| Author |
Message |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Sep 04, 2005 8:48 am Post subject: wrong CLOCKS_PER_SEC? |
|
|
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 |
|
 |
cooleyandy
Joined: 02 Jul 2005 Posts: 41
|
Posted: Sun Sep 04, 2005 11:08 am Post subject: |
|
|
| 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 |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Wed Sep 07, 2005 8:04 am Post subject: |
|
|
LUA problems should be in the LUA forum...
Moved. _________________ Lego of my Ago! |
|
| Back to top |
|
 |
chaos
Joined: 10 Apr 2005 Posts: 135
|
Posted: Wed Sep 07, 2005 12:14 pm Post subject: |
|
|
| 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 |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Wed Sep 07, 2005 4:27 pm Post subject: |
|
|
| 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 |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Thu Sep 08, 2005 3:52 am Post subject: |
|
|
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 |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Thu Sep 08, 2005 9:09 am Post subject: |
|
|
| 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 |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Tue Oct 25, 2005 2:46 am Post subject: |
|
|
| The latest PSPSDK with GCC 4.0.2 has introduced the bug again, please patch it again. |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Tue Oct 25, 2005 6:18 am Post subject: |
|
|
| It was broken back in r1096 when the newlib patch as regenerated. It should be fixed (for good) in r1218. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Tue Oct 25, 2005 4:39 pm Post subject: |
|
|
| 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 |
|
 |
|