gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > clock() not functioning?!?!

#12680 - IsmStudios - Sat Nov 22, 2003 2:50 pm

Hello,

I'm currently trying to finish up my first starfield for the gameboy advance and I'm trying to write code that forces all the frames to run at the same speed.

I noticed that stdlib.h & time.h so I decided to use some of the standard libraries till I figured out that clock() wasn't working. It's obviously there because the source file links...

Can anyone help me? What do the professionals do to regulate their frame-rate?

Lewis Moronta
Interactive Designer
www.ismstudios.com

#12681 - tepples - Sat Nov 22, 2003 3:14 pm

Professionals wait for the vblank. There are two ways to do this: spinning on VCOUNT or sleeping until the vblank interrupt. Until you learn more, you will want to spin on VCOUNT.

Is your starfield running at 60fps or faster? The explanation of the technique to limit at less than 60fps is more complicated than the explanation of the technique to limit at more than 60fps.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#12690 - IsmStudios - Sat Nov 22, 2003 9:29 pm

Cool--I am now using a waitVSync function and it's working great... are you saying that the resolution on mode 4 runs @ 60 hertz? So if my game is running slower than this, is it possible to wait for two vBlanks (by calling the function twice) to cap it @ 30fps?
_________________
Lewie [m80]
Interactive Designer
www.ismstudios.com
www.m80produxions.com

#12691 - IsmStudios - Sat Nov 22, 2003 9:33 pm

Any word on the clock function? I'm using the latest version of gcc.
_________________
Lewie [m80]
Interactive Designer
www.ismstudios.com
www.m80produxions.com

#12693 - tepples - Sat Nov 22, 2003 10:11 pm

It's not GCC's responsibility to add clock(). It's the C library's. The GBA port of Newlib doesn't do a lot of the hardware-specific stuff such as clock() that requires calling down to the bare hardware.

All GBA display modes run at 16777216/280896 Hz, or about 59.73 Hz. The difference is negligible except in communication or sound code.

In order to lock the speed below 60 Hz, you're going to have to split processing over multiple frames, waiting for vblank after each frame. For example, draw half the stars in one frame and half the stars in the other.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.