don't click here

Sonic CD decompilation

Discussion in 'Engineering & Reverse Engineering' started by BenoitRen, Jul 17, 2023.

  1. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    I got Collision Chaos to compile. Here's a first look:

     
  2. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    Let's dive into Tidal Tempest!



    Looks like there are some issues to fix.
     
  3. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    No Quartz Quadrant yet, so here's a progress update on Tidal Tempest.

    The cause of the missing background tiles is because after setting up a lookup table I forgot to call cg_change. However, the resulting changing background tiles are incorrect, and I haven't been able to figure out what I'm doing wrong. R32 also has changing background tiles, and they're wrong there, as well. I didn't notice before because the ones in R32 show high in the middle of the level.

    There were no water currents due to forgetting to call watercoli. But the currents don't work properly. It seems as if Sonic is only in his floating state for one frame. I found one error in watercoli, but correcting it didn't fix the issue.

    Next, I went through all the objects so they'd select the correct sprite ids depending on the loaded level. Tidal Tempest has a lot more objects, so this was a pain.

    After fixing Sonic falling through the floor in R43D (error in collision map lookup table), I played through the level. The first phase of Robotnik's boss fight, his escape routes are wrong somehow. The second phase executes correctly.

    No progress on the underwater palette always being applied.
     
  4. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    This version is now officially better than Sonic Gems Collection's; the water palette has been implemented! The water currents aren't playing nice yet, however.



    Technical explanation:

    The game maintains a global variable called hintposi (or: horizontal interrupt position). It contains the scanline number where a H-interrupt occurs. In the original, a H-interrupt is used to change the current palette to the water palette while the screen is being drawn.

    In the C version, we do the drawing ourselves, so we just need to know where to switch palettes, or if the entire screen is submerged (by reading waterflag). Switching palettes between colorwk and colorwk3 is as easy as incrementing every pixel by 64.

    I'm not sure why Sonic Gems Collection didn't implement the water palette. At first I thought it was because they likely didn't have access to RDX's source code. But that doesn't make sense, because, if that's the case, they had to reverse engineer all the other drawing routines as well. Maybe they just forgot. It's only used in one round of the game, after all.
     
    • Like Like x 6
    • Informative Informative x 1
    • List
  5. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    Ran out of ideas for the water currents, so I moved on to Quartz Quadrant, which I just got to compile. Here's a first look:



    Cleaning this up should be faster, as this round has a normal amount of objects.
     
  6. Overlord

    Overlord

    Now playable in Smash Bros Ultimate Moderator
    19,635
    1,145
    93
    Long-term happiness
    I'm assuming there will be an option in this to use the original soundtrack, incidentally?
     
  7. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    Yes, you will be able to choose the soundtrack.
     
  8. Blastfrog

    Blastfrog

    See ya starside. Member
    Will that include the different assignment in some spots like in Stardust Speedway 3 and different timers to account for certain jingles?
     
  9. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    I intend to correct what I can, but I'm not familiar with all the differences (yet).
     
  10. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    Quartz Quadrant was already very tidy. I only had to clean up two objects!

    On to Wacky Workbench!

     
  11. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    Stardust Speedway is already here!

     
  12. Ch1pper

    Ch1pper

    Fighting the Battle of Who Could Care Less Member
    884
    115
    43
    Life.
    I love the glitched badnik objects. Makes me smile. Gives each of your milestone videos the vibes of "this is an WIP beta" you'd see in old magazine/trailer footage.
     
  13. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    At last, here's Metallic Madness! Though it seems I can't proceed past a certain point. ...Wait, I just remembered that this round has its own version of SCRCHK. That's probably why. Enjoy the WIP! ;)

     
  14. Brainulator

    Brainulator

    Regular garden-variety member Member
    Are you sure it's not just the ring-crusher crushing you?
     
  15. nineko

    nineko

    I am the Holy Cat Tech Member
    6,421
    585
    93
    italy
    I have to agree with Brainulator's hypothesis. Still, fantastic work except that I still hate the FM jump sound but that's not your fault.
     
  16. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    Sonic was indeed being crushed by a piston.

    I don't like the FM jump sound, either. But it should be possible to replace it. Sonic & Knuckles Collection's sound effects seem to have the same format.

    I'm done with Metallic Madness!

    Also, thanks to a fellow reverse engineer, I can now compile a PS2 ELF that's really close to the real thing, so I could verify my decompilation in even more detail. This made me correct some more errors, including those that caused the water currents in Tidal Tempest to misbehave. They now work perfectly!

    Next I'll tackle either the title screen or the Special Stage. Both will involve the implementation of the Mega CD's scaling capabilities. Not sure how I will tackle that.
     
  17. Clownacy

    Clownacy

    Tech Member
    1,178
    895
    93
    I just finished adding support for the Mega CD's scaling capabilities to my emulator, so I can provide code and give advice.
     
  18. Devon

    Devon

    Do not contact me. Tech Member
    1,584
    1,966
    93
    The title screen (and its related screens and easter eggs) was actually completely rewritten from scratch in the 90s PC port, so I am led to believe that the clouds are handled much differently from the special stages, which *were* ported from the original Sega CD version.
     
    • Informative Informative x 5
    • List
  19. BenoitRen

    BenoitRen

    Tech Member
    960
    583
    93
    Not only were the different screens rewritten, they seem to call the graphics API (HMX?) directly instead of telling the control program what and where it wants something drawn. This might take some time to figure out.
     
  20. Blastfrog

    Blastfrog

    See ya starside. Member
    Wouldn't it be neat to merge the code from all 70 stages into one unified engine? It would make modding much easier.

    Not requesting this, just saying I think I think it'd be a cool idea for a project. Maybe I could give it a shot once this gets released as a little coding practice, perhaps I could start small and try to merge all of the time periods of Palmtree Panic 1, and then merge 2 and 3 into it from there. I'd have to write branches in to account for any differences, probably using a text diff tool to isolate any discrepancies.