don't click here

Is a Sonic and knuckles collection widscreen mod possible?

Discussion in 'Engineering & Reverse Engineering' started by KelvinsBrainBox, Jan 16, 2022.

  1. I wanna know if it's possible to make a widescreen mod of Sonic and knuckles collection.

    There hasn't been a lot of documentation on it so I've been messing around with it in hex and cheat engine.

    Using the sega pc reloaded patch, I was able to locate a few bytes I could change to modify the canvas(?) resolution in ddraw.dll and I got the result below.


    Notice the screen is shifted left now instead of being centered.

    Not sure which bytes I changed to get this, I'll make sure to update this when I figure it out, but this is kinda where I'm stuck right now, I can't seem to locate any more bytes that would be connected with the game resolution.

    Any tips? Thanks!
    Last edited: Jan 16, 2022
  2. Willie


    Each day the world turns Laugh 'til it all burns Member
  3. I have played air, I really enjoyed it and I'm sure origins will be pretty great too, but they're not ports. They lack the same nuances the and pc port has and even have some of thier own. Especially compared to the pc version with it's midi ost and the ability to change sound-fonts, midi files, etc. through modding. It's not really a version worth leaving in the dust merely because it's not the definitive version just as the og rom isn't. And if the genesis game can get the same treatment through patches for things like the gx wide emulator, why not S&KC?
  4. MainMemory


    Kate the Wolf Tech Member
    Yes, and someday I will make that mod.
    I've figured out most of the rendering code already, the real challenge is figuring out what parts of the game I have to edit to do it.
  5. Blue Spikeball

    Blue Spikeball

    For the record, you can use custom music with AIR. People have made multiple audio packs based on the S&KC midis, even recording the actual hardware. Since the original midis sounded differently on different MIDI synthesizers, the results vary, but I think this one sounds pretty good.
  6. LOst


    Tech Member
    Hi! Wow, I am still alive here? Anyways...

    I have been through the Sonic & Knuckles Collection for decades now, so I might be able to help.
    The main screen render code (the function) is located at offset 0x403101 in SONIC3K.EXE.
    There are multiple branches to different tile rendering code, such as AIZ's blimp, split screen for 2P competition modes. It is quite a lot of code to go through, but the actual rendering is done quite easily, optimized for whole tiles with clipping on beginning tile and end tile. It is written in assembler, but not that optimized. There are quite a lot of loops with 0xE0 (224 scan lines), meaning tiles are rendered one scan line at a time, so look for number of tiles and not pixel. Start tile and end tile will most likely be clipped and require special code.

    Basically, you can't just hack Windows API, DirectDraw calls, or window sizes to make this game wide screen (unless you want to stretch the original screen).

    The render is called from the VBlank "emulation" function, which is called directly from the Sonic game at original/default source code ~WaitForVBlank locations, and does everything from frame timing, updating looping sound effects, to dealing with the Windows message pump, making it a hybrid of a Win32 Application and a Genesis game. The offset to this function is at 0x403101.

    The DirectDraw back buffer rendering is done in a function at offset 0x40336E, which is also where the HBlank water palette color is applied.
    • Like Like x 4
    • Useful Useful x 2
    • Informative Informative x 1
    • List
  7. Asside from it being divided by tiles, I figured that's what was going on. This helps a lot, thanks.
  8. JoseTB


    Tech Member
    I also looked into the S&K Collection back in the day (there are dozens of us!) and in my opinion there is very little to be gained from modding it today. The port is nothing special, just a straight code conversion with rendering/sound/input patched in, in a "pseudo-emulation" sort of way. Eukaryot appears to have taken the same approach in the conception of Sonic 3 A.I.R; if you were to attempt patching widescreen support into S&K Collection you would only be retracing Eukaryot's steps in having to rewrite and patch the original game's code in a variety of places to be compatible with the new rendering code. So basically, go play/mod S3 A.I.R. because it's the same thing but with the widescreen work already done and better support.
    • Agree Agree x 1
    • Informative Informative x 1
    • List
  9. MainMemory


    Kate the Wolf Tech Member
    A.I.R. modding is completely incomprehensible to me. I'll keep doing S&KC, thanks.
  10. Qjimbo


    Your friendly neighbourhood lemming. Oldbie
    I was going to say I think I remember an interview where they explained that S&K collection was an assembly port. Maybe take a look at how the gx wide patch for S3&K works and try and line up the assembly code between the patched/unpatched Gen code and PC code using Ghidra?
  11. MainMemory


    Kate the Wolf Tech Member
    I use IDA, but yes, that is basically what I'm planning to do. And yeah, S&KC was incredibly obviously machine translated from 68000 ASM to x86 ASM. It's got a set of 15 variables in memory that correspond to each of the MD's 8 data and 7 address registers (a7/sp is just the esp register), and the code is incredibly redundant; every source instruction that reads from a register generates an instruction to read the memory variable into one of the x86 registers, even if the previous source instruction also read or wrote that same register.
    A while ago, I posted on Twitter an example of how insanely bloated the code gets sometimes:
    Code (Text):
    1. loc_3F9E:
    2.    move.l (a0)+,(a1)+ ; Fill 2 palette lines with title screen data
    3.    dbf d0,loc_3F9E
    Code (Text):
    1. .text:006DC26E loc_6DC26E:                             ; CODE XREF: Title_Screen+2C6↓j
    2. .text:006DC26E                 mov     edi, dword ptr reg_a0
    3. .text:006DC274                 mov     eax, [edi]
    4. .text:006DC276                 add     edi, 4
    5. .text:006DC279                 mov     dword ptr reg_a0, edi
    6. .text:006DC27F                 mov     edi, dword ptr reg_a1
    7. .text:006DC285                 mov     [edi], eax
    8. .text:006DC287                 add     edi, 4
    9. .text:006DC28A                 mov     dword ptr reg_a1, edi
    10. .text:006DC290                 test    eax, eax
    11. .text:006DC292                 pushf
    12. .text:006DC293                 mov     ax, word ptr reg_d0
    13. .text:006DC299                 dec     ax
    14. .text:006DC29B                 mov     word ptr reg_d0, ax
    15. .text:006DC2A1                 cmp     ax, 0FFFFh
    16. .text:006DC2A5                 jz      short loc_6DC2AA
    17. .text:006DC2A7                 popf
    18. .text:006DC2A8                 jmp     short loc_6DC26E
    • Informative Informative x 4
    • List
  12. Qjimbo


    Your friendly neighbourhood lemming. Oldbie
    Look like the conversion must have been at least partially automated in that case. Makes sense they would try and make their lives easier at the expense of some inefficiency.
  13. Hivebrain


    53.4N, 1.5W
    I might be remembering wrong, but didn't Sega have a 68000 to C conversion tool which they used for Sonic Jam and some PC games?
  14. Clownacy


    Tech Member
    That was used by Sonic CD PC (and its Gems Collection ports) and I think Sonic 3D Blast PC. I've seen Sonic Jam's code (edit: heh), and, from what I remember, that one was very visibly done by straight automated 68k ASM -> SH2 ASM conversion - no C in-between. Same for Sonic & Knuckles Collection (though targeting x86 ASM instead of SH2 ASM, of course).

    There was even a thread on here once by a guy claiming to have written that 68k->C converter. I don't have a link to it though (edit: found it).
    Last edited: Feb 3, 2022
    • Like Like x 1
    • Informative Informative x 1
    • List