Controlling Play Speed

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

User avatar
tokumaru
Posts: 12003
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru » Fri Dec 03, 2010 6:07 pm

tepples wrote:But PAL's vblank is over three times as long. So if you have the RAM to spare for a bigger transfer buffer, and you have some CPU time to spare, you could design the engine so that the PAL version's camera can move faster.
Yeah, that's an option, but RAM isn't a very abundant resource on the NES. Also, even though the PAL VBlank is longer, the rendered frame is shorter (in CPU cycles of course, it is the same as the NTSC one visually), so the fact that you'll have to fill more buffers during that time is more likely to cause slowdown.

Tom
Posts: 68
Joined: Wed Apr 06, 2005 5:36 am
Location: Massachusetts

Post by Tom » Fri Dec 03, 2010 7:43 pm

tokumaru wrote:Tom, you might be able to deal with these problems by using a flag system similar to the one used for PPU stuff
I'm not sure I understood what you meant. Did you mean something like this?

Code: Select all

start_sound_effect:
    ; ProtectionFlag should be 0 here
    inc ProtectionFlag
    
    ; change sound engine memory
    
    ; check if nmi interrupted us
    lda ProtectionFlag
    bne skip

    ; nmi happened, and skipped update, so do it now
    jsr update_sound_engine

skip:
    lda #0
    sta ProtectionFlag
    rts

nmi:
    lda ProtectionFlag
    beq nmi_update_music

    ; in middle of critical code, delay update until after it's done
    lda #0
    sta ProtectionFlag
    rti

nmi_update_music:
    jsr update_sound_engine
    rti
That seems pretty workable. Of course, five minutes after I posted my other message I thought of a decent enough way to queue up commands for the sound engine to run during NMI, but it would require some more ram for the buffer that your method doesn't need.
tokumaru wrote:As for the sound effects, remember that the NMI routine has ways to know if a frame was missed or not, so as long as your sound engine knows the difference between music and sound effects it can delay the sound effects in case of lag frames.
Interesting. My sound engine doesn't distinguish music and sound effects, so I hadn't thought of that. Still, I think the problem is theoretical; I can't think of any existing game where the sound effects need to be synchronized with the animation. It still bugs me a little.

tepples
Posts: 22288
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Fri Dec 03, 2010 7:46 pm

Tom wrote:I think the problem is theoretical; I can't think of any existing game where the sound effects need to be synchronized with the animation.
Parappa. Beatmania. Frequency. Amplitude. Guitar Hero. DJ Hero. D+Pad Hero.

Tom
Posts: 68
Joined: Wed Apr 06, 2005 5:36 am
Location: Massachusetts

Post by Tom » Fri Dec 03, 2010 8:04 pm

tepples wrote:
Tom wrote:I think the problem is theoretical; I can't think of any existing game where the sound effects need to be synchronized with the animation.
Parappa. Beatmania. Frequency. Amplitude. Guitar Hero. DJ Hero. D+Pad Hero.
True, these types of games require synchronization. But I was thinking more generally. For instance, consider a FPS, which has a machine gun. If the animation for firing the gun includes showing shell casings, you'll want to make sure the sound of the shell casing happens in sync with the animation. But on the NES, both animations and sound effects are lot simpler, so I can't think of existing NES games where this would matter (D+Pad Hero excluded).

tepples
Posts: 22288
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Fri Dec 03, 2010 8:08 pm

Tom wrote:For instance, consider a FPS, which has a machine gun. If the animation for firing the gun includes showing shell casings, you'll want to make sure the sound of the shell casing happens in sync with the animation.
Then the shell casing should be a separate sound effect that starts when the animation starts.

User avatar
tokumaru
Posts: 12003
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru » Fri Dec 03, 2010 8:18 pm

Tom wrote:Did you mean something like this?
Yup, exactly that! =)
I can't think of any existing game where the sound effects need to be synchronized with the animation. It still bugs me a little.
Well, to be fair, stretching them by skipping updates will probably just make them sound wrong, so it's not really a good solution.

In every game I can think of, it's important that sound effects begin at the correct time, but if by any chance the video lags that doesn't really result in any weirdness.

As for the games tepples listed, I wouldn't expect those kinds of games to drop frames, since they aren't very CPU-intensive. I mean, how complicated is it to move a few graphics around and match input to internal tables?

Tom
Posts: 68
Joined: Wed Apr 06, 2005 5:36 am
Location: Massachusetts

Post by Tom » Fri Dec 03, 2010 8:28 pm

tepples wrote:Then the shell casing should be a separate sound effect that starts when the animation starts.
That'll work sometimes, but other times it won't be convenient. If you had the sound of the gunfire and the shell casing as a single recording, for instance.

Post Reply