
How to wait a second?
- t0rxe
- C Programming Expert
- Posts: 139
- Joined: Dec 19, 2012
- Motto: /\OX[]
- PlayStation Model: SCPH-5502
- Location: Australia
You can make a for loop and use VSync(0) for example to make a timer.
VSync(x) is defined in the Psy-Q manual, where 'x' is the systems definitive.
You will need to do some basic math to figure out the amount of time needed to make a second.
In my example below, 10 is just a number I randomly chose, and so may be to high or to little...
EG:
VSync(x) is defined in the Psy-Q manual, where 'x' is the systems definitive.
You will need to do some basic math to figure out the amount of time needed to make a second.
In my example below, 10 is just a number I randomly chose, and so may be to high or to little...
EG:
Code: Select all
void Timer()
{
int i;
for (i=0; i<10; i++) VSync(0);
}
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"
Hi there,
The Kernel section of the Run-Time Library 4.4 document makes reference to a System Clock. Read the section on Root Counter Control. This may help you.
You could also write a VSyncCallback that increments a frame counter every VSync. You could then check the value to see if 60 frames (for NTSC) or 50 frames (for PAL) have passed.
The question doesn't give a lot of information about what you are really trying to do so I'm not sure which technique would work better for you. I haven't done either on the PlayStation so I can't supply a sample. I have done the latter for other platforms (i.e. Atari2600, Atari5200, Atari7800, Atari 8-bits computers) and it works.
For instance, if you were trying to check when a second has passed after pressing a button, you could set a counter to 0 when the button is pressed (also keeping track of when the button is released so the counter gets reset) then for each VsyncCallback increment the counter. In your loop or program you would then check if the appropriate time has elapsed (i.e. (counter % 60) == 0 for NTSC or (counter % 50) == 0 for PAL).
I hope this helps in solving your question. Please share your final solution with the forum. I'm sure it will help others as well.
The Kernel section of the Run-Time Library 4.4 document makes reference to a System Clock. Read the section on Root Counter Control. This may help you.
You could also write a VSyncCallback that increments a frame counter every VSync. You could then check the value to see if 60 frames (for NTSC) or 50 frames (for PAL) have passed.
The question doesn't give a lot of information about what you are really trying to do so I'm not sure which technique would work better for you. I haven't done either on the PlayStation so I can't supply a sample. I have done the latter for other platforms (i.e. Atari2600, Atari5200, Atari7800, Atari 8-bits computers) and it works.
For instance, if you were trying to check when a second has passed after pressing a button, you could set a counter to 0 when the button is pressed (also keeping track of when the button is released so the counter gets reset) then for each VsyncCallback increment the counter. In your loop or program you would then check if the appropriate time has elapsed (i.e. (counter % 60) == 0 for NTSC or (counter % 50) == 0 for PAL).
I hope this helps in solving your question. Please share your final solution with the forum. I'm sure it will help others as well.
-
inc^lightforce Verified
- Psy-Q Enthusiast
- Posts: 266
- Joined: Mar 07, 2013
- I am a: Programmer Windows+PS1, GFX Artist
- PlayStation Model: Black
- Location: Germany
AGREE
thats more than enough .
use this code

use this code
if you wanna wait more than 1 sec. you can change the value "i<10;" to 60 or highert0rxe wrote:Code: Select all
void Timer() { int i; for (i=0; i<10; i++) VSync(0); }
Hi there,
If my understanding of this code is correct it will call VSync 11 times. VSync(0) waits for the next VSync to execute. For NTSC machines this is every 1/60 of a second and for PAL systems every 1/50 of a second. If VSync is called 11 times then wouldn't that be 0.183 seconds for NTSC and 0.22 seconds for PAL? Is that correct?
Also, this assumes no other callbacks are happening during this tight loop. If anything (though not likely) is done while the the loop is executing then isn't it possible for a VSync to happen before the VSync(0) call? This may not matter...I don't know the context of what the original asker is planning. Maybe an exact second pause is not needed. Maybe an approximation is okay.
Again, I'm learning this system and trying to better understand. Thanks.
I'm still learning this system and would like to understand how this code waits a second.inc^lightforce wrote:AGREEthats more than enough .
use this code
if you wanna wait more than 1 sec. you can change the value "i<10;" to 60 or highert0rxe wrote:Code: Select all
void Timer() { int i; for (i=0; i<10; i++) VSync(0); }
If my understanding of this code is correct it will call VSync 11 times. VSync(0) waits for the next VSync to execute. For NTSC machines this is every 1/60 of a second and for PAL systems every 1/50 of a second. If VSync is called 11 times then wouldn't that be 0.183 seconds for NTSC and 0.22 seconds for PAL? Is that correct?
Also, this assumes no other callbacks are happening during this tight loop. If anything (though not likely) is done while the the loop is executing then isn't it possible for a VSync to happen before the VSync(0) call? This may not matter...I don't know the context of what the original asker is planning. Maybe an exact second pause is not needed. Maybe an approximation is okay.
Again, I'm learning this system and trying to better understand. Thanks.
- bizarro2011
- Serious PSXDEV User
- Posts: 118
- Joined: Mar 27, 2012
- Location: Brazil
I thought of this idea. (not tested)
try this.
void Timer(int n)
{
int i;
for (i=0; i<n; i++) VSync(0);
}
with it.
int segundos;
double n = ((double)segundos)/60.;
try this.
void Timer(int n)
{
int i;
for (i=0; i<n; i++) VSync(0);
}
with it.
int segundos;
double n = ((double)segundos)/60.;
-
Administrator Verified
- Admin / PSXDEV
- Posts: 2691
- Joined: Dec 31, 2012
- I am a: Shadow
- PlayStation Model: H2000/5502
Another way is to just do 'VSync(60)'. Depending on your setup video mode and PSX (since VSync will either use 50Hz or 60Hz), this is one way to do a delay.
The most accurate way is to use the free-running root counter and use some math to generate a seconds counter. This is how Bust A Groove does it with their dance system so it's always in sync.
The most accurate way is to use the free-running root counter and use some math to generate a seconds counter. This is how Bust A Groove does it with their dance system so it's always in sync.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.
PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.
PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.
Who is online
Users browsing this forum: No registered users and 1 guest