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 ?
-
Verified
- Legendary Programmer
- Posts: 256
- Joined: Aug 13, 2012
- 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 Verified
- C Programming Expert
- Posts: 250
- Joined: Mar 21, 2012
- I am a: Programmer
- Motto: Never settle
- PlayStation Model: SCPH-7502
- Discord: ShendoXT
- Location: Croatia, EU
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);
Dev console: SCPH-7502, FreePSXBoot, CH340 serial cable.
-
Verified
- Legendary Programmer
- Posts: 256
- Joined: Aug 13, 2012
- I am a: Programmer
- PlayStation Model: Net Yaroze
- Location: France
- Contact:
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/
-
Verified
- Extreme PSXDEV User
- Posts: 221
- Joined: Oct 21, 2021
- I am a: Programmer, Gamer
- PlayStation Model: SCPH-1000
- Location: USA
- Contact:
I had this same exact problem and Googled it, was not expecting such a detailed and simple explanation. Thanks.Shendo wrote: ↑August 8th, 2013, 11:39 am 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: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*/
To read the value of the counter call this function:Code: Select all
int CounterMaxValue = 240; /*This means this counter resets every 240 HBlanks*/ SetRCnt(RCntCNT1, CounterMaxValue, RCntIntr); StartRCnt(RCntCNT1);
So to measure something you could do something like this:Code: Select all
GetRCnt(RCntCNT1);
There is also a possibility of using events for running a certain function when counter reaches zero.Code: Select all
ResetRCnt(RCntCNT1); OldValue = GetRCnt(RCntCNT1); DoSomething(); NewValue = GetRCnt(RCntCNT1) - OldValue; printf("It took %d HBlanks to execute DoSomething", NewValue);
Who is online
Users browsing this forum: No registered users and 2 guests