don't click here

Sonic 1 "Mega PCM" driver

Discussion in 'Engineering & Reverse Engineering' started by vladikcomper, Jun 11, 2012.

  1. GT Koopa

    GT Koopa

    Member
    2,021
    18
    18
    Elgin, IL
    Flicky Turncoat DX, T.L.W.S. Vs M.G.W.
    Ok, +1 confirm for this problem. Tried to combine it with Markey's Sonic 128 disassembly. Double checked everything. Here is my specific report, via level selecting to Green Hill Zone act 3:

    ---

    - The "static" itself lasts as long as the dac drum sample itself, a corruption of the original sound byte.
    - Invincibility music doesn't affect it.
    -dying doesn't affect it normally.
    -hitting a 1up monitor with its jingle causes the dac drums to static.
    - When getting to the boss arena and the boss music, the dac drums play normal, HOWEVER anything after will have the corrupt dac, including dying.
    -and of course, going to a new act or the special stage causes the static problem
    -once activated, none of the above matters, it is always "on"
    -the only way it gets "fixed" is by getting a game over and going back to the SEGA screen.


    ---

    It has to be the way new music is being called up that is causing it.
     
  2. vladikcomper

    vladikcomper

    Tech Member
    205
    134
    43
    Sonic Warped
    I had a quick go on implementing Mega PCM in Sonic 1: Project 28, and it all worked out perfectly, like in the other disassemblies. I didn't have enough time and will to also apply a HQ playback guide yet, but the fact the main one worked means all the rest will do. Here's disassembly for the reference:
    https://www.dropbox.com/s/l6jzn3l9wf3isru/Sonic_1_28_with_MegaPCM.7z?dl=0

    I tested it in Kega, Gens and Regen, tried to locate samples at different offsets in ROM, both ran GHZ 3 from Level Select and got to it through the normal game play -- I couldn't reproduce the weird bug you're talking about. I even have no idea how a thing like this could happen, because the Mega PCM code is quite steady for this sort of things: it ensures offsets are correct before reading data and there is no way you could corrupt Z80 RAM or Mega PCM's variables by playing a broken sample.

    Could you PM me that buggy ROM? I'm quite interested to see what could wrong here.
     
  3. GT Koopa

    GT Koopa

    Member
    2,021
    18
    18
    Elgin, IL
    Flicky Turncoat DX, T.L.W.S. Vs M.G.W.
    PMed it to you. To have more to talk about in my current post, is the above disassembly clean, without a jump dash and other unwanted changes? Just Markey's disassembly with your sound driver attached?
     
  4. vladikcomper

    vladikcomper

    Tech Member
    205
    134
    43
    Sonic Warped
    So, I figured out GT Koopa's problem. Since two or more people had it, I think this should be highlighted.

    The bug described above occurs when you forgot to follow this part of guide in the first post:

    Basically, the old driver was hardcoded to play sample $83 with different pitches for samples ($88-$8B), in order to do this, loc_71CAC routine modified drivers code in Z80 RAM. This fix essentially was for the old driver's code as you see, for Mega PCM, it just breaks its code in a random place.

    So, by playing samples $88-$8B, the unwanted fix works and the Mega PCM code gets corrupted, which causes playback bugs.

    Yes, it's totally clean. In fact, the disassembly I posted earlier was a modified one used in S1 Hacking Studio 2, hence Jump Dash, Spin Dash and a lot of other changes. The program isn't released here yet.
     
  5. GT Koopa

    GT Koopa

    Member
    2,021
    18
    18
    Elgin, IL
    Flicky Turncoat DX, T.L.W.S. Vs M.G.W.
    Perhaps those mini steps could have numbers/letters/chronological markers so people don't miss their place?

    Edit: I say this because while following I switched back and forth through windows, and I think that was where my error was.
     
  6. vladikcomper

    vladikcomper

    Tech Member
    205
    134
    43
    Sonic Warped
    Bump.

    SSRG user 'Mike B Berry' reported me he had issues with SEGA PCM playback using Puto's custom code, which most of hacks actually use (http://info.sonicretro.org/SCHG_How-to:Fix_the_SEGA_Sound). It turned out that the problem occurred if you apply Mega PCM HQ playback guide, the SEGA PCM wasn't played in various emulators and on real hardware. Apparently, it was working in Kega, which is why I missed that. Although I did run tests in different emulators, even on hardware, my test ROM had a debug screen replacing SEGA logo, so just I couldn't see the problem.

    The fix is simple. I've added it into the guide already.

    Don't apply this if you didn't use this guide: http://forums.sonicretro.org/index.php?showtopic=29057&view=findpost&p=715140
     
  7. PsychoSk8r

    PsychoSk8r

    PsychedelAnt | Tone Turner Oldbie
    2,642
    57
    28
    Birmingham, UK
    30 Day Project: Revisited.A New Release!
    I know with enough work anything is portable, but how much work do you think it'd be if I were to attempt whacking this in Sonic 2?
     
  8. vladikcomper

    vladikcomper

    Tech Member
    205
    134
    43
    Sonic Warped
    Getting it work in Sonic 2 will require a lot of work, because it uses SMPS Z80 driver.

    The fact is, with sound engine working on the M68K side (SMPS 68k), the Z80 is completely free to process digital sound samples in a continuous loop, which means, you can utilize all the processor's resources as you like, there's nothing besides you and your code. In case of SMPS Z80, the whole sound engine is also running on the Z80 along with the DAC driver. They have to share the same memory space, which is limited to 8 KB in Z80, and, of course, the execution time. Furthermore, hardware limitations make things even harder. The Z80 can only view the game ROM through a small 32 KB window, and with sound engine in the works, it often comes that the sound engine needs to access one part of ROM to read music data, at the same time the DAC driver needs another to read samples data. They have to share bank window as well, which, of course, needs some more resources and performance.

    I'm not trying to say this is something impossible. A lot of sound engines on the Z80 could also playback DAC with no issues. But implementing a new and quite a complex DAC driver into Sonic 2 may require a lot of work.

    I have plans to attempt an SMPS Z80 port of it, not sure if this happens any soon. I'm not too familiar with SMPS Z80, as my experience with it was little. The last time I had some issues on implementing another bank switching mechanism into it (not for Mega PCM, just to have multiple banks for music and SFX). But why not try it at least, this is gonna be challenging :)
     
  9. PsychoSk8r

    PsychoSk8r

    PsychedelAnt | Tone Turner Oldbie
    2,642
    57
    28
    Birmingham, UK
    30 Day Project: Revisited.A New Release!
    Exactly what I wanted to know, thanks. =P
     
  10. Thorn

    Thorn

    Tech Member
    335
    19
    18
    Home
    Sonic 2 Retro Remix
    vladikcomper: let me ask the obvious question, then... wouldn't it be practical to set up your driver starting from the Sonic 2 "clone" sound driver (a public, on-the-wiki port of the Sonic 1 sound driver to Sonic 2)? Granted, it's not 100% identical, but it does move things back to SMPS 68k. You've probably already thought of that and it's just not obvious in your answer, but I figured I should ask directly. I've considered looking into it myself, but :effort:.
     
  11. vladikcomper

    vladikcomper

    Tech Member
    205
    134
    43
    Sonic Warped
    Ehh, frankly, I totally forgot about Clone Driver =P

    I've heard of it, but never used it myself, because I'm not hacking Sonic 2 per se. But considering it's 68K nature, this is definitely what I should be looking for. Thanks mentioning it. But that said, I'm still interested in pulling this thing with the original Sonic 2's sound driver.

    EDIT: Quoted due to new page
     
  12. ashthedragon

    ashthedragon

    Sonic Paradise Researcher
    1,428
    73
    28
    Spain
    Sonic Paradise & Sonic Ages
    Stupid question but...Can I have an already compiled .bin of Sonic 1 with the mega PCM driver working? I want to try it at real hardware but I've no idea of hot to compile asm
     
  13. vladikcomper

    vladikcomper

    Tech Member
    205
    134
    43
    Sonic Warped
    Here you go: https://dl.dropbox.com/u/44757401/Sonic_1_with_MegaPCM_HQ.7z
    This example features Mega PCM playing a digital song on the title screen and replaces some DAC samples in game.

    Actually, I've already showed two Sonic 1 disassemblies with Mega PCM in this topic. Both of them also have already compiled ROM for your convenience, see s1built.bin file.

    Also, compiling a disassembly is pretty easy, just run build.bat file. If everything is successful, assembler will generate a ROM file for you. It's usually named s1built.bin in case of a Sonic 1 disassembly.
     
  14. ashthedragon

    ashthedragon

    Sonic Paradise Researcher
    1,428
    73
    28
    Spain
    Sonic Paradise & Sonic Ages
    Thank you!
     
  15. You-Are-Pwned

    You-Are-Pwned

    Member
    76
    8
    8
    I just checked that version. Is it intentional that the Final Zone music plays in SBZ3? Could be a bug.
     
  16. vladikcomper

    vladikcomper

    Tech Member
    205
    134
    43
    Sonic Warped
    This is intentional. As well as different music in GHZ 2 and 3 and somewhere else.

    Because this isn't exactly a clean Hivebrain's disassembly, secretly, this is S1 Hacking Studio 2.0 version of disassembly, so I quickly did some music swaps and game tweaks because I was bored. A bit modified disassembly doesn't affect the way you apply Mega PCM guides at all.
     
  17. PsychoSk8r

    PsychoSk8r

    PsychedelAnt | Tone Turner Oldbie
    2,642
    57
    28
    Birmingham, UK
    30 Day Project: Revisited.A New Release!
    Anyone else working with the attempt to get this running in Sonic 2?
    So far, I've managed to use the Sonic 2 Clone Driver as a base to follow this guide, doing what's required along the way for compatibility, to get this in the game, The game runs, SMPS files that came with the clone driver play (running on the "MegaPCM.z80" Driver), but I'm getting garbled DAC ingame.
    Excuse the poor host, but here's my resulting ROM:
    http://www.mediafire.com/?f8s9ydxvyo9pjnv
    Kick and Snare are in there, but as ASM code instead ("dc.b"), as I'm having trouble with bincludes. Timpani is replaced with the kick sample for now. Oddly enough, the kick plays perfectly instead of the Sega Sound on the Sega Screen.

    Edit: After some more inspection, and getting the BINCLUDES working correctly (thanks to mainmemory), It appears that it was struggling to play the samples provided with MegaPCM, I used some custom uncompressed samples from a while ago, and it worked. I'm checking now whether it will take some compressed samples I've had laying around.
     
  18. vladikcomper

    vladikcomper

    Tech Member
    205
    134
    43
    Sonic Warped
    Good job, PsychoSk8r!

    I'm planning do a Clone Driver port as well and write a full guide, but I don't know when I can start, because now I have few other things I should finish first. Hope to get on it this month, eventually.

    As for the garbled DACs issue you had, hearing how it sounds in the ROM you've provided, it looks like Mega PCM is trying to play compressed DPCM samples as uncompressed PCM. Ensure you've changed 'pcm' to 'dpcm' in playback flags for the compressed samples.
     
  19. PsychoSk8r

    PsychoSk8r

    PsychedelAnt | Tone Turner Oldbie
    2,642
    57
    28
    Birmingham, UK
    30 Day Project: Revisited.A New Release!
    I'm glad you'll take a look too, you're bound to know MPCM better than anyone else. =P
    I've never been too big on hacking S2, but I have ported objects/routines between S1/S2 in the past (to test my limits). The Sound Driver is in, supports uncompressed custom samples, but I'll be damned if I can get dpcm working lol.
    http://www.mediafire.com/?9po8fbbx88c1cz8

    Here are my results, complete disassembly, some bonus DAC samples I've had laying around. It's not quite there yet, but getting there. Hopefully this might help you a little.
    Apologies if there are any files in there that shouldn't be, I did give the folders a quick once-over to remove unnecessary files. I think I may have left a rather large "DAC Sample" in the DAC folder (copied straight from a side-project). =P
     
  20. ValleyBell

    ValleyBell

    Tech Member
    246
    25
    28
    researching PC-98/X68000 sound drivers
    The fixed IncludeDAC macro for the Xenowhirl disassembly is:
    [68k]IncludeDAC macro Name,Extension
    Name: label *
    binclude "dac/Name.Extension"
    Name_End: label *
    endm[/68k]
    It took me a while to figure this out when I adding nicer sample tables to S2 Recreation.