Friday, September 2, 2016

Snake Rock 'n' Roll: Sound Effects List

Thus far in the series, we have examined the data and workings of the audio module with respect to the background music. In this post, we will examine its support for the sound effects in the game.

There are forty sound effects in Snake Rattle 'n' Roll. Each sound effect is played by a single APU channel, and while it is playing, any song playing in the background is suppressed: the track data continues to be read, and the state of any active effects are updated, but the song's notes never get written to the APU channel. Although the audio module supports playing a sound effect on any of the APU's four channels, Snake Rattle 'n' Roll only plays sound effects on the pulse and noise channels, never on the triangle channel.

Sound effects, like the tracks of a song, are played from tapes. The format of the tape data for sound effects is much simpler than that for song tracks. A list of the available tapes for sound effects can be located at $DB94:

SFX ID$DB94,X\$DB95,XPurpose
$00FB\DBnone
$02FB\DBBigFoot death/Snake pop/Pibbly bomb
$0410\DCPibbly Chomp
$0619\DCPibbly Ejection
$082D\DCLid Opening
$0A34\DC?? Mystery Sound Effect??
$0C3F\DCPLAY ON/1-UP
$0E65\DCControl inverter pickup
$106E\DCTongue extender pickup
$127B\DCWormhole opening
$149E\DCWormhole sucking up object
$16AE\DCBigFoot stomp/-RGGG THUD
$18BE\DCScale bell ring
$1ADC\DCExploding enemy 1/2
$1CE5\DCExploding enemy 2/2
$1EEE\DCSnake OW
$20F7\DCInvincibility diamond pickup
$220E\DDSnake death spin
$2435\DDPibbly countdown (low)
$2627\DDPibbly countdown (medium)
$2843\DDPibbly countdown (high)
$2AE3\00Score rollup (pulse)
$2C51\DDScore rollup (noise)
$2EC6\DCJaws (slow)
$3063\DDARRRGGG-
$3274\DDPibbly chunk spit
$34B1\03Crescendo (game over screen, extra continue pickup)
$368E\DDExit door point scored
$389E\DDBounce/lick enemy
$3AA3\DDLick foot
$3CBD\DDDiving splash
$3ECF\DDWater jump jet
$40E5\DDTime extension pickup
$42EA\DDTime running out beep
$4454\DCTail fin pickup
$46FB\DDWind-up key pickup
$4806\DE?? Mystery Sound Effect??
$4AF3\DBRocket take-off
$4CE6\DBAsteriod Fall
$4E0D\DESnake gulp
$50D1\DCJaws (fast)

Some observations on this table:

  • The table is two bytes per entry, and lists the low byte\high byte of the address of the start of that sound effect's tape data
  • Sound effect ID $00 is not a real sound effect; it is just a sentinel value in the table.
  • There are two sound effects ($0A and $48) whose purpose is unknown to me. I could not find any action in the game that caused them to play, and when I hacked the ROM to play them in place of other sound effects, I did not recognize them.
  • There are two other sound effects ($2A and $34) whose tape address is in RAM instead of ROM. This means that the sound effect actually played is dynamic, and can differ between runs. Sound effect $34 is particularly interesting, in that the audio module itself contains code to dynamically alter the sound effect's tape data. We shall see this firsthand in a later post, when we examine the machine code of the audio module in depth.

The sound effect list has an unusual layout. In most other cases, the tape address data would have been stored in two lists, say $D000,X and $D028,X, and the sound effect IDs would have been ordered sequentially starting from zero. Instead, the address data has been interleaved into a single table, and the sound effect IDs are incremented by two, starting from zero. It turns out that this is not accidental, because it allows a sound effect to have TWO IDs: the ID listed in the table above, or 'primary' ID, and that ID number plus one, or 'locked' ID. But what use is that?

CAUTION: the next section is a bit esoteric. Read carefully.

The audio module contains code to suppress repeat sound effects. For example, sound effect $24 was currently playing on pulse channel 1, and the game logic issued a call to play sound effect $24, it would be ignored. When the sound effect is finished, the audio module resets itself so that it is 'playing' sound effect $00, and then the game logic could issue a call to play sound effect $24 again.

The same example, mutatis mutandis, applies to any given sound effect ID, in particular, $25, the 'locked' ID for $24. The key here is that if sound effect $24 was playing, it could be overwritten by sound effect $25, and vice versa. This fact comes into play when we look at the SFX UNLOCK message we glossed over in the last post.

At the implementation level, the SFX UNLOCK message will cause the audio module to change its record of the currently-playing sound effect from a 'locked' ID to a 'primary' ID (it has no actual effect if it is executed while the audio module is already playing a sound effect by its primary ID). The sound effect will continue to play normally, but it is now able to be preempted by re-playing the sound effect's locked ID.

Snake Rattle 'n' Roll makes use of this advanced feature in a few places, but the most noticeable is in the 'pibbly countdown' at the end of each stage. While it is counting out the number of nibbly pibblys eaten, there is a sound effect being played repeatedly. When the sound effect gets about halfway through, it is started over, until the end of a countdown, when it plays to completion.

Under the hood, the game is attempting to play sound effect $25 every frame (or, 60 hz). Many of these attempts will be rejected, because the audio module is already playing that sound effect, but halfway through the effect it reaches an SFX UNLOCK message, switches to being recorded as playing sound effect $24, and is overwritten on the next frame.

End esoteric section. That was a bit weird, but it is the only complicated part of sound effects: the SFX UNLOCK message is the only control message available in sound effect tape data. We will examine the rest of the sound effect tape data in the next post.

No comments:

Post a Comment