Timing in NES, other than waiting for VBLANK

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

User avatar
Petruza
Posts: 307
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Timing in NES, other than waiting for VBLANK

Post by Petruza »

Hi, is it possible to meassure time in the NES other than waiting for VBLANK?
This gives a precision of a 60th of a second, in NTSC, but what if you want more precision? is it possible?
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

There's APU frame IRQs (which is nearly the same rate as NMIs -- about 60 Hz).

There's also DMC IRQs which have an adjustable timer and can happen pretty quick (by my math... once about every 432 cycles.. which works out to about 4143 Hz). The problem with these though is they use the DMC which means if you're using the DMC for timing, you can't use it for audio. Plus using the DMC can interfere with joypad reads, which means you need to repeatedly read joypad data until you get two nonconflicting returns.

Some mappers also have a much simpler CPU cycle counter. But then you have to use that mapper, of course.

Other than that, I can't think of any. Only other way really is to count cycles (which you can't do from C).
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Timing in NES, other than waiting for VBLANK

Post by tepples »

Petruza wrote:Hi, is it possible to meassure time in the NES other than waiting for VBLANK?
The best answer depends on your answer to the following: Of what event are you trying to measure the time?
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Post by Bregalad »

Altough the VBlank may not happen exactly 60 times per second (50 respectively for PAL consoles), I guess it's still the most accurate method.
Useless, lumbering half-wits don't scare us.
User avatar
Petruza
Posts: 307
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Re: Timing in NES, other than waiting for VBLANK

Post by Petruza »

tepples wrote:
Petruza wrote:Hi, is it possible to meassure time in the NES other than waiting for VBLANK?
The best answer depends on your answer to the following: Of what event are you trying to measure the time?
I want to make a metronome. But maybe 60 hz are enough.

PS: Tepples, don't take it personal, but your avatar annoys me a lot :? can I make one for you? maybe with some NES character...
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Post by Bregalad »

Hmmh, your avatar is much weirder too (altough it doesn't annoy me). A face viewed by front and face at the same time is really weird.
Useless, lumbering half-wits don't scare us.
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

The easy way to get flexible timing at 60hz is to use sub-frame counting with 16-bit adds. Just make it so the lower byte is never reset (always carries over).

To your timer (16-bit variable), you'd add values like these every frame to get these rates:
$0100 = 60Hz.
$0001 = 1/256Hz
$0180 = 90Hz

I guess you actually could just ditch the high byte and trigger a beat whenever the low byte wraps around (check carry flag).
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Bregalad wrote:Hmmh, your avatar is much weirder too (altough it doesn't annoy me). A face viewed by front and face at the same time is really weird.
Looks like a texture map to me.

But then, if you just want to make a metronome for tempos between 40 and 240 beats per minute, here's how you could do it:

Code: Select all

while not done:
    wait for vblank
    update display
    counter = counter + selected_beats_per_minute
    if counter >= frames_per_minute:
        counter -= frames_per_minute
        beep
The value of frames_per_minute depends on whether you're on NTSC (use 3606) or PAL (use 3000).
User avatar
Petruza
Posts: 307
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Post by Petruza »

In [url=http://nesdev.com/bbs/viewtopic.php?p=41472#41472]this post[/url], Bregalad wrote:Hmmh, your avatar is much weirder too (altough it doesn't annoy me). A face viewed by front and face at the same time is really weird.
Tepples' avatar is not weird at all, it just annoys me, I'm not sure why.
UncleSporky
Posts: 388
Joined: Sat Nov 17, 2007 8:44 pm

Post by UncleSporky »

A strange thing to talk about, but it does make him seem constantly annoyed. If he's comfortable with it then I don't know why he'd change it though, I know I'm hesitant to give up stuff like that when I've used it for ages.

What's that kid from?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

UncleSporky wrote:What's that kid from?
Pinocchio 2
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Post by Zepper »

Whoa... :) and made by Filmation!
User avatar
Petruza
Posts: 307
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Post by Petruza »

tepples wrote:
UncleSporky wrote:What's that kid from?
Pinocchio 2
Does the name "Pin Eight" have to do with that?
Because in spanish Pin 8 would be "Pin ocho" the same as Pinocchio.
User avatar
Petruza
Posts: 307
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Post by Petruza »

UncleSporky wrote:it does make him seem constantly annoyed.
You're right, that's maybe what annoys me.
Maybe in my subconscious I think tepples is always bothered by something, like Pinnochio seems to be :D
User avatar
BMF54123
Posts: 410
Joined: Mon Aug 28, 2006 2:52 am
Contact:

Post by BMF54123 »

Petruza wrote:Does the name "Pin Eight" have to do with that?
Because in spanish Pin 8 would be "Pin ocho" the same as Pinocchio.
Whoa. That's deep.
Post Reply