ASM Sonic CD (1993) Disassembly by Ralakimus

Discussion in 'Engineering & Reverse Engineering' started by Alex Field, Jun 9, 2022.

  1. Alex Field

    Alex Field

    シュート! カオス・エメラルド・ザが消えようとしている! Member
    175
    108
    43
    Downunda, Mobius
    Sonic the Hedgehog 2+, Sonic the Hedgehog 3+
    EDIT 2: A moderator finally gave Ralakimus his password back; read below for his information.

    EDIT: Apparently Ralakimus was planning to post info about it here, but he lost his account credentials.


    This isn't mine, however I wanted to bring attention to this; former user Ralakimus previously worked on a disassembly for R11A of Sonic CD.

    Well, he recently decided to start working on several other files; these include:
    • Main and system programming.
    • Backup RAM (BRAM).
    • Sub CPU
    • Genesis/Mega Drive initalization
    • SMPS-PCM
    • Title screen
    • Sound test
    • Palmtree Panic 1 (all time periods).
    • Ending FMVs*
    All the above data can be compiled, and the title screen does work, however it will halt upon trying to load another screen. Still, I wonder what the outcome of this will be.

    Download here

    *Fun Fact: Apparently the developers got the file names for these mixed up; so GOODEND.BIN is for the bad ending, and vise-versa.
     
    Last edited: Jun 12, 2022
  2. Ralakimus

    Ralakimus

    Mommy says I'm just built different Tech Member
    627
    254
    63
    Yeah this is something I've been doing. I've been posting about it on SSRG for a bit now, but I'd like to share some additional info. Keep in mind, this is a very WIP thing.
    The repository does not provide the other CD files. You need to put them in yourself in the _Original folder.
    Just Palmtree Panic's, though.

    Now, let's talk about why the level folder is organized the way that it is. It basically has to do with how the original source code was organized and assembled. Here's a sample, using the file names found in the Gems Collection version's symbol data for reference:
    [​IMG]
    As you can see, there's a number of copy and pasted files for various things, like scrolling/level rendering, object tables, and other data. Unfortunately, things are not the most consistent between these copies. Let's take LevelSizeLoad for example.

    In R11A, it starts like this:
    Code (Text):
    1. ; -------------------------------------------------------------------------
    2. ; Get level size and start position
    3. ; -------------------------------------------------------------------------
    4.  
    5. LevelSizeLoad:
    6.     moveq    #0,d0                ; Clear unused variables
    7.     move.b    d0,unusedF740.w
    8.     move.b    d0,unusedF741.w
    9.     move.b    d0,unusedF746.w
    10.     move.b    d0,unusedF748.w
    11.     move.b    d0,eventRoutine.w        ; Clear level event routine
    In R11B, it's this:
    Code (Text):
    1. ; -------------------------------------------------------------------------
    2. ; Get level size and start position
    3. ; -------------------------------------------------------------------------
    4.  
    5. LevelSizeLoad:
    6.     lea    objPlayerSlot.w,a6        ; Get player
    7.  
    8.     moveq    #0,d0                ; Clear unused variables
    9.     move.b    d0,unusedF740.w
    10.     move.b    d0,unusedF741.w
    11.     move.b    d0,unusedF746.w
    12.     move.b    d0,unusedF748.w
    13.     move.b    d0,eventRoutine.w        ; Clear level event routine
    R11B also retains leftover Sonic 1 code for handling credits, while R11A removes it. This puts me in a tricky situation regarding how to organize things. For now, I'm just doing what the original source code did, for the most part.

    To be honest, this is turning out to be better for documentation than it is for hacking.

    btw I added R11D last night, making the entirety of Palmtree Panic Act 1 disassembled and buildable, all with SonLVL support.
     
    Last edited: Jun 9, 2022
  3. Ralakimus

    Ralakimus

    Mommy says I'm just built different Tech Member
    627
    254
    63
    tfw the demo variant of R11A in the Japanese and European version of the game was built using a slightly older version of R11A, making me have to insert more if/else statements to keep things building bit-perfect.

    Added DEMO11A.

    Also, imagine if GOODEND.BIN streamed data from BADEND.STM and BADEND.BIN streamed data from GOODEND.STM, making it so that the game has to load GOODEND.BIN for the bad ending and vice versa... Man, the development cycle must've been a pain.
     
    Last edited: Jun 10, 2022
  4. Nik Pi

    Nik Pi

    Member
    How difficult is sound editing in fmv intro and outros? As far as I remember, something like modified WAV is used there? Do you have any plans to disasm these videos?

    Sorry, if it's a stupid question... Have a nice day!
     
  5. Ralakimus

    Ralakimus

    Mommy says I'm just built different Tech Member
    627
    254
    63
    The FMV data format is fairly simple. It's just an array of packets of tiles and Ricoh PCM data. Eventually, I'll figure out a way to split out the data, or at least make a tool to make your own STM file.

    On that note, so there's a slight quirk with the audio playback. They set a PCM loop flag at the very end of wave RAM, and didn't want to overwrite it. Each packet contains 0x8000 bytes of PCM data. However, wave RAM is split into 0x1000 byte banks, which can only be accessed one at a time. Their solution was to only write 0xFFF bytes per bank written to. As a result, only 0x7FF8 bytes out of the packet are written, there's a gap around every 0x1000 bytes in wave RAM, and the last 8 bytes in a packet are skipped. I guess they figured it wasn't that noticeable enough. As it turns out, though, that loop flag isn't really necessary, as playback will just wrap back to the top of wave RAM after going past the end, which is what the FMV audio playback code does anyways with that loop flag.
     
    Last edited: Jun 20, 2022
  6. Nik Pi

    Nik Pi

    Member
    Ok. Thank you. I remember that old SCD fmv hack, where are intro was changed to Rick Roll. Will be great to have a chance to edit not only levels, but the cutscenes too!