I need to have a precise timer on Playstation (for example to measure things)
For the moment I use the VSync, so each VSync I increment a counter and depending on 50 or 60Hz I compute my timer.
But this is not very accurate, so I searched for a timer on psx, and the only thing I found was the Root counter.
Unfortunately the documentation on this is a bit confusing, and I really don't understand how to use the Psy-Q functions in order to get it working.
can someone help me on this ? thank you
Precise Timing, Root Counter ?
- Orion_
- Legendary Programmer
- Posts: 233
- Joined: August 13th, 2012, 2:48 am
- I am a: Programmer
- PlayStation Model: Net Yaroze
- Location: France
- Contact:
Precise Timing, Root Counter ?
Retro game development on Playstation and other consoles http://orionsoft.free.fr/
- Shendo
- C Programming Expert
- Posts: 238
- Joined: March 21st, 2012, 4:34 am
- I am a: Programmer
- Motto: Never settle
- PlayStation Model: SCPH-9002
- Location: Croatia, EU
Re: Precise Timing, Root Counter ?
There are four root counters available on PlayStation: DotClock, HBlank, SyClock/8, VBlank.
VBlank is used by many BIOS functions (Pad access, Memory Card access, etc...)
so beside using VSync() function it's not advised to mess with it.
However, other counters are freely available to the programmer, you just have to set them up properly.
First add this macros to your project:
Now, let's set up HBlank counter:
To read the value of the counter call this function:
So to measure something you could do something like this:
There is also a possibility of using events for running a certain function when counter reaches zero.
VBlank is used by many BIOS functions (Pad access, Memory Card access, etc...)
so beside using VSync() function it's not advised to mess with it.
However, other counters are freely available to the programmer, you just have to set them up properly.
First add this macros to your project:
Code: Select all
#include <libapi.h>
#define RCntCNT0 0xf2000000 /*display pixel*/
#define RCntCNT1 0xf2000001 /*horizontal sync*/
#define RCntCNT2 0xf2000002 /*one-eighth of system clock*/
#define RCntCNT3 0xf2000003 /*vertical sync target value fixed to 1*/
#define RCntIntr 0x1000 /*Interrupt mode*/
Code: Select all
int CounterMaxValue = 240; /*This means this counter resets every 240 HBlanks*/
SetRCnt(RCntCNT1, CounterMaxValue, RCntIntr);
StartRCnt(RCntCNT1);
Code: Select all
GetRCnt(RCntCNT1);
Code: Select all
ResetRCnt(RCntCNT1);
OldValue = GetRCnt(RCntCNT1);
DoSomething();
NewValue = GetRCnt(RCntCNT1) - OldValue;
printf("It took %d HBlanks to execute DoSomething", NewValue);
My PS1 consoles: 2 x SCPH-1002, SCPH-5552, SCPH-7002, 4x SCPH-9002, 2 x SCPH-102.
Dev console: SCPH-9002, MM3 - 7 wire modchip, PAL color mod, CH340 serial cable addon.
Dev console: SCPH-9002, MM3 - 7 wire modchip, PAL color mod, CH340 serial cable addon.
- Orion_
- Legendary Programmer
- Posts: 233
- Joined: August 13th, 2012, 2:48 am
- I am a: Programmer
- PlayStation Model: Net Yaroze
- Location: France
- Contact:
Re: Precise Timing, Root Counter ?
Thank you for detailed explanation.
it seems that the rootcounter are small and reseting fast, I guess it will not be compatible with my system.
I have a timer reference function which gives me a timer reference, so I can do difference between two time even if several minutes passed. I guess I would need an interrupt function who would increment a value each time a rootcounter reset or something like that.
it seems that the rootcounter are small and reseting fast, I guess it will not be compatible with my system.
I have a timer reference function which gives me a timer reference, so I can do difference between two time even if several minutes passed. I guess I would need an interrupt function who would increment a value each time a rootcounter reset or something like that.
Retro game development on Playstation and other consoles http://orionsoft.free.fr/
Who is online
Users browsing this forum: No registered users and 2 guests