Wednesday, October 18, 2017

The S&K alone flag

23 years ago on this very day, Sonic & Knuckles was released worldwide on the Sega Genesis. Happy anniversary!


To mark the occasion, I figured it might be relevant to discuss what happens when Sonic & Knuckles boots up without a second game locked on to the cartridge.

First, how does it detect a cartridge in the lock-on slot? The game's startup routine checks for the presence of a lock-on cartridge's ROM header by comparing the longword at address $200100 with the string "SEGA". If this check fails, then the lock-on slot does not contain a valid cartridge, and control jumps to SonicAndKnucklesStartup, which handles the boot sequence both for Sonic 3 & Knuckles as well as for standalone Sonic & Knuckles:
    moveq   #-1,d1
    move.l  (SegaHeadersText).l,d0          ; test to see if SEGA is at the locked on ROM's $100
    cmp.l   (LockonHeader).l,d0
    bne.w   SonicAndKnucklesStartup
Over at SonicAndKnucklesStartup, the value in the d1 register is written to RAM address $FFAE otherwise known as the SK_alone_flag. This flag is clear when the Sonic 3 cartridge is locked on, and set when the lock-on slot is empty:
SonicAndKnucklesStartup:
    bsr.s   Test_Checksum
    move.w  d1,(SK_alone_flag).w
    ...
So, what does the flag do? Well, perhaps rather obviously, the first thing the flag is responsible for is whether to display the Sonic & Knuckles title screen, or the Sonic 3 & Knuckles one. It also defines the game title used in stage title cards, and which logo appears at the end of the credits sequence.


Recall how I mentioned that Sonic 3 & Knuckles is just a special mode of Sonic & Knuckles that is allowed to reference content from the Sonic 3 cartridge? That is the mode in which the SK_alone_flag is clear. Conversely, when the flag is set, the game cannot be granted access the Sonic 3 cartridge, because it isn't there!

As a result, setting the flag causes a whole bunch of stuff to get skipped:
  • All save functionality is disabled. The battery backup is on the Sonic 3 cartridge, so there would be no point in running the code.
  • Only Sonic & Knuckles stages appear in the demo reel, and in his demos, Sonic isn't accompanied by Tails.
  • Tails also does not appear in Sonic's continue screen.
  • Star posts will only take you to the slot machine and rolling jump bonus stages.
  • The starting positions for Mushroom Hill Zone 1 are adjusted to skip over the first special stage ring.
  • There's only a single set of special stages, since the other one is on the Sonic 3 cartridge. As such, special stage rings will never take you to Hidden Palace, and thus the Super Emeralds are inaccessible.

Interestingly, the scenes added to the ending sequence when you clear the game with all Super Emeralds do not check the flag at all. This includes the scene where Knuckles sees Sonic and Tails off, which is set in Angel Island Zone!


Beyond that, there is a surprising amount of work to prevent you from accessing Sonic 3 content using the level select:
  • If either the Tails alone or the Sonic and Tails player option is chosen, the player mode is set to Sonic alone.
  • If a Sonic 3 level is selected, the current level is forced to Mushroom Hill Zone 1.
  • Even if the first level you select is a special stage, the saved current level is also forced to Mushroom Hill 1, to prevent you from getting sent to Angel Island Zone afterwards.
  • Finally, there's no debug cheat, which prevents you from using an obscure feature that allows the player to select which special stage to play by setting the Sound Test option to the intended stage number, and then holding down the A button during the fade-in.

However, my favorite feature definitely has to be Knuckles' intro sequence, which is a perfect tie-in with Sonic and Tails' post-credits scene when the game is cleared with all Chaos Emeralds. It explains the motivation behind Knuckles' story and makes it abundantly clear that it takes place after Sonic's.


So, next time you feel like playing Sonic 3 & Knuckles, consider playing Sonic 3 and Sonic & Knuckles separately, and keep an eye out for some of these features.

That's it for my series on Lock-on Technology! I have no clue what I'm gonna write about tomorrow.

5 comments:

  1. I take it the Sonic 3 & Knuckles screens and cards, the Hyper forms, and the Super Emeralds exist in Sonic & Knuckles alone?

    I thought the debug code was inactive in S&K alone because the S3&K debug code is used for S&K's level select.

    Here's some ideas:
    *How Blue Sphere levels are generated
    *Tails remains in Sonic & Knuckles
    *Knuckles remains in Sonic 3
    *Sonic 3's code for Sonic & Knuckles
    *How Sonic & Knuckles patched Tails's Icecap Zone Act 1
    *How does Doomsday Zone work?
    *Big Arm and the Icecap spiked balls vs. Super Sonic and Super Knuckles
    *Tails's sprite when alone in the Lava Reef 2 boulder scene
    *Sonic & Knuckles locked onto the Sonic 2 Nick Arcade and Simon Wai prototypes, Sonic Classics, and every other Genesis/Mega Drive game

    I know not all of it is worthy of discussion, but come on, this is too fascinating for me to not want to read this on a daily basis! I love this blog!

    ReplyDelete
    Replies
    1. Tails remains in Sonic & Knuckles
      Sonic & Knuckles only contains the Tails data which isn't supplied by Sonic 3.

      Knuckles remains in Sonic 3
      There isn't much in the way of, sorry.

      Sonic 3's code for Sonic & Knuckles
      I can't make heads or tails of this.

      How does Doomsday Zone work?
      It works pretty well.

      Sonic & Knuckles locked onto the Sonic 2 Nick Arcade and Simon Wai prototypes, Sonic Classics, and every other Genesis/Mega Drive game
      The Sonic 2 protos share Sonic 1's serial number, so they yield the full Blue Sphere game. All other cartridges yield a single stage, unless the game can't find the "SEGA" string in the lock-on ROM header, in which case you just get regular Sonic & Knuckles.

      Delete
  2. I'd be more interested in knowing what happens when a Sonic & Knuckles stage gets loaded in Sonic 3. For example, what tells the game to use Azure Lake graphics in Mushroom Valley Zone?

    The stages also seem crash at different points, be it before the title card disappears (ie: FBZ) or shortly after.

    ReplyDelete
    Replies
    1. I second all of this, especially the S&K stages in Sonic 3. As of right now, the TCRF sub-page is a complete disaster with copied and pasted information for each zone. The screenshots for each zone (except FBZ and everything after the bonus stages) are also very inaccurate.

      Regarding this post; Does Sonic & Knuckles take the Angel Island graphics from the Sonic 3 ROM or does it have its own small set for the super emeralds ending?

      Delete
    2. Yes to the former: the danger of doing so without checking whether the Sonic 3 cartridge is present is what I was trying to imply.

      Sharp-eyed readers will notice that the ending scene calls the same function which removes the horizon line when playing as Knuckles.

      Delete