(WIP) Sonic CD Disassembly

Discussion in 'Showroom' started by ralakimus, May 22, 2022.

  1. ralakimus

    ralakimus IMPOLITE AND EVIL! Member

    Joined:
    Aug 26, 2013
    Messages:
    1,113
    So, over the past several years, I have dug into Sonic CD's code. As of today, I have a disassembly of Palmtree Panic Act 1 Present (R11A), and also various core engine files. They all should build bit perfect files.

    Link

    It's kinda shit, as I'm not the greatest at formatting things, but I hope that this is useful in some capacity. At least it'll give you an idea of how Sonic CD's core engine works (spoiler: like shit), and also how 1 level works. None of the other levels have been disassembled, and I don't really have the motivation to do so right now. In the end, though, this should provide a decently solid base for hacks, if you ever desired to make one for Sonic CD (although, in my personal opinion, it'd probably be a better idea to make your own Sega CD engine and port Sonic 1 to it, or something).

    R11A is properly split up and even has SonLVL support. Only thing that's really off with it is that code documentation wasn't finished.
     
    Last edited: Jun 3, 2022
  2. ralakimus

    ralakimus IMPOLITE AND EVIL! Member

    Joined:
    Aug 26, 2013
    Messages:
    1,113
    Updated the "misc" repo. Title screen and sound test are disassembled and mostly documented. The repository now allows you to build a working ISO image, if you provide the original CD files as well.
     
    Last edited: Jun 2, 2022
  3. ralakimus

    ralakimus IMPOLITE AND EVIL! Member

    Joined:
    Aug 26, 2013
    Messages:
    1,113
  4. Nik Pi

    Nik Pi Newcomer Member

    Joined:
    Feb 14, 2022
    Messages:
    19
    Nice work! Do you think to make a full disasm, or just partially? Anyway- thank you for it. Good luck!
     
  5. ralakimus

    ralakimus IMPOLITE AND EVIL! Member

    Joined:
    Aug 26, 2013
    Messages:
    1,113
    We'll see how I feel. This definitely won't be deemed complete any time soon. There's still a shit ton of level files to go through, on top of special stages and other misc. files. I've been working on and off on this thing since 2015.
     
  6. Nik Pi

    Nik Pi Newcomer Member

    Joined:
    Feb 14, 2022
    Messages:
    19
    Yeah, I know, it's really difficult. Just... it's really cool that someone decided to do this :)
     
  7. ralakimus

    ralakimus IMPOLITE AND EVIL! Member

    Joined:
    Aug 26, 2013
    Messages:
    1,113
    Let's talk about the real reason making a full Sonic CD disassembly is a pain in the ass. It's not just that there's over 70 level files to go through, but each of them have a bunch of their own minute little quirks and differences that just throw off a bunch of things.

    Let's take LevelSizeLoad for example. In R11A, it starts like this
    Code:
    ; -------------------------------------------------------------------------
    ; Get level size and start position
    ; -------------------------------------------------------------------------
    
    LevelSizeLoad:
        moveq    #0,d0                ; Clear unused variables
        move.b    d0,unusedF740.w
        move.b    d0,unusedF741.w
        move.b    d0,unusedF746.w
        move.b    d0,unusedF748.w
        move.b    d0,eventRoutine.w        ; Clear level event routine
    Well, in R12A, it's this
    Code:
    ; -------------------------------------------------------------------------
    ; Get level size and start position
    ; -------------------------------------------------------------------------
    
    LevelSizeLoad:
        lea    objPlayerSlot.w,a6        ; Get player
    
        moveq    #0,d0                ; Clear unused variables
        move.b    d0,unusedF740.w
        move.b    d0,unusedF741.w
        move.b    d0,unusedF746.w
        move.b    d0,unusedF748.w
        move.b    d0,eventRoutine.w        ; Clear level event routine
    R11A directly accesses the player object variables, while R12A accesses them through the "a6" register. On top of that, R12A retains leftover Sonic 1 code that checks the credits, while R11A removes it.

    This is just ONE example.
     
  8. Clownacy

    Clownacy Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    948
    Oh geez, so the various level blobs may not have been built from the same codebase, but rather separately maintained ones? That's just gross.
     
  9. ralakimus

    ralakimus IMPOLITE AND EVIL! Member

    Joined:
    Aug 26, 2013
    Messages:
    1,113
    Pretty much. A good chunk files did appear to be commonly used between levels thankfully, but more per level specific things weren't. You can even see how it is in the file names found in the Gems collection version. (The files for the player object, collision, and other common objects and functions are shared, then it goes down to per zone objects, and then finally per act/time zone stuff, as you can see with files like ACT11A, DEV11A, and SCR11A)

    LevelSizeLoad appears to be lumped in with the scrolling and drawing code (makes sense considering it calls the scrolling initialization routine), which was something separately maintained, hence why we have this specific example. Still annoying to deal with. I can try my best to maintain some commonality, but I'd rather not make it an if/else hell.

    Another good reason to just port Sonic 1 or whatever to the Sega CD yourself if you really wanna use it. At this point, this is just better for documentation purposes, not so much hacking.

    EDIT: A quick visualization of the file structure in Sonic CD in Gems collection:
    [​IMG]
    ACTxxx = Object index/Null object
    BOSS_x = Boss object
    COLxx = Palette cycling/fading/data
    COLIx = Player object collision
    DEVxxx = Level tiles/blocks/chunks index
    EDTBLxxx = Debug object index
    EMIEx = Amy object
    ETx = Robot generator
    FRIENDx = Animal object
    KUZURxxx = Collapsing platform data
    MOVIEx = Metal Sonic projector
    PLAYPATx = Sonic sprite mappings
    SCRxxx = Level scroll/drawing
    ZxxACT = Object layout
    ZxxxTBL = Collision data/Level layout
    ZONETBLx = Title card mappings
     
    Last edited: Jun 5, 2022
  10. ralakimus

    ralakimus IMPOLITE AND EVIL! Member

    Joined:
    Aug 26, 2013
    Messages:
    1,113
    After bashing my head and having several drinks, I have a decent-ish split of the level code, and got R11B (Palmtree Panic Act 1 Past) disassembled and buildable, with SonLVL support. It has been pushed into the repository.

    Honestly, don't be expecting this to be the most "hack friendly" thing. I've already explained above the nature of how the original source code was assembled, and how that affects this. I am trying my best to make it manageable, and even incorporating things like SonLVL support, but I have my limitations.
     
    Clownacy and yami like this.
  11. saan1ty

    saan1ty Well-Known Member Member

    Joined:
    Mar 1, 2021
    Messages:
    66
    Location:
    North Carolina
    Like the R11A version that was playable as a genesis standalone rom (i think it was) will there be an option to build it without cd music so it can be played on the genesis or will it become cd only if you know what i mean?
     
  12. ralakimus

    ralakimus IMPOLITE AND EVIL! Member

    Joined:
    Aug 26, 2013
    Messages:
    1,113
    No, this just aims to be a buildable disassembly of Sonic CD as a whole.

    btw, just added R11C
     
  13. ralakimus

    ralakimus IMPOLITE AND EVIL! Member

    Joined:
    Aug 26, 2013
    Messages:
    1,113
    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, and also R11D was added a few days ago.

    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
  14. Nik Pi

    Nik Pi Newcomer Member

    Joined:
    Feb 14, 2022
    Messages:
    19
    @ralakimus, I have a question.
    As you can (or can't) know, if you'll change a mappings, or insert more animation frames for Sonic, and after- build it, you'll get a CHAOS from pixels instead of a level (although the level assets have not changed). I wonder why this is happening? You have already mentioned that this thing is not too friendly to hacking, but.. is there any explanation for this?
     
  15. ralakimus

    ralakimus IMPOLITE AND EVIL! Member

    Joined:
    Aug 26, 2013
    Messages:
    1,113
    Chunks are hardcoded to be located at offset $20000 in Word RAM. Shifting them away from that location causes problems. I made a guide to fix that a while back in the old R11A disassembly, or you can just go into the "data" files for each level and turn the padding using leftover data into proper align macros.
     
  16. Nik Pi

    Nik Pi Newcomer Member

    Joined:
    Feb 14, 2022
    Messages:
    19
    Thank you very much!!!!