How-to:Port Sonic 2 Clone Driver V2 Into Sonic 2

From Sonic Retro

This page or image should be deleted.

Hello everyone! Shadow05 here and today I'm going to show you how to port the Sonic 2 Clone Driver V2.

Sonic 2 Clone Driver V2

So, what is the Sonic 2 Clone Driver v2?

This is a heavily modified version of Sonic 1's sound driver, with a greater level of compatibility with music and sounds from other Sonic titles, along with numerous bugfixes, optimisations, and added features. However, to really understand the driver, you need to understand its history, and its ties (or lack thereof) to the original Sonic 2 Clone Driver.

Both the original Sonic 2 Clone Driver and the Sonic 2 Clone Driver v2 are modified versions of Sonic 1's sound driver (modified early(?) SMPS 68k Type 1b), designed to act as total replacements of Sonic 2's sound driver (improved Z80 port of Sonic 1's driver).

At the time of the original Sonic 2 Clone Driver's creation, working with Sonic 2's driver was considered extremely difficult, compared to Sonic 1's driver. This was down to several factors, such as the driver being designed for the Z80 sound coprocessor, which sported a language few were willing to learn, and many changes to the music format. Not helping matters was also the fact that the driver was largely unexplored and lacking documentation. In contrast to Sonic 1's documented, easy-to-understand driver, Sonic 2's driver just seemed unfeasible to use, even though it had additional features, such as added DAC samples and PSG envelopes. This pushed hackers away from hacking Sonic 2.

One of the earlier efforts to counter this was the porting of Sonic 1's driver to Sonic 2. While this did help to ease the addition of custom music, compatibility with Sonic 2's original music and SFX was practically non-existent. Because of this, a hybrid was made, the original Sonic 2 Clone Driver, allowing access to Sonic 2's music, SFXs and DACs, while having the ease-of-use of Sonic 1's driver.

That was the past, however. Over time, advancements in documentation and tools have made both drivers just as easy to use, and the need for something like the original Sonic 2 Clone Driver has diminished. Still, people continue to use the ancient thing, despite the fact that it wasn't really a feature-complete replica of Sonic 2's driver to begin with: missing PSG envelopes, incorrect music/SFX priorities, broken speed-up tempos, broken tempos in general, there were many problems with the original Sonic 2 Clone Driver that made the hacks that used it suffer. Today, simply sticking to Sonic 2's driver would be a better choice.

This is why I made the Sonic 2 Clone Driver v2, an attempt at making as close a mimicry of S2's driver as possible: the aforementioned errors were corrected, and many more S2 elements were crammed in, in an effort to make the drivers near indistinguishable.

The purpose of the Sonic 2 Clone Driver v2 has changed over its lifetime: while originally meant as a simple update to replace the original Sonic 2 Clone Driver, it no longer shares the same goals as its predecessor: while the original was made for ease-of-use, the Sonic 2 Clone Driver v2 exists for the sake of pushing the Mega Drive's hardware to its limit, by avoiding the biggest bottleneck: the Z80's limitations. Problem areas such as driver size and poor DAC quality can be avoided by not using a Z80-based driver such as Sonic 2's or even Sonic 3's. This allows a hack to push its sounds to the limit, without having to downgrade to the smaller feature pool of Sonic 1's original driver.

So, what isn't the Sonic 2 Clone Driver v2?

As said before, the Sonic 2 Clone Driver v2 is not meant for the purpose of making the process of adding custom music easier, rather, it's for those that wished to implement features that the Z80 would not allow, due to its limitations. One example can be seen in the hack Sonic 2 Recreation, a hack that was based on Sonic 2, but used a 68k-based driver (a heavily modified version of the original Sonic 2 Clone Driver) because a Z80-based driver would not allow all of the features needed. The Sonic 2 Clone Driver v2 uses Vladikcomper's Mega PCM, a custom DAC driver only available for 68k-based sound drivers. Mega PCM allows for greater playback quality and control. This is just one of the things possible when the sound driver is not entirely based on the Z80.

Of course, 68k-based drivers have their downsides. Sonic 1's driver operates on the 68k, the main processor of the Mega Drive. Sonic 2's driver operates on the Z80, the sound co-processor. So, there's the obvious performance penalty on the 68k, and thus your hack's gameplay. It may not be much, but ask yourself, is it worth it? Are you going to make any good use of it? There is also the RAM requirement: Sonic 2's driver just uses the Z80's RAM. In contrast, Sonic 1's driver uses $5C0 bytes of the very RAM that has to be juggled with the level chunks, blocks, layout, decompression queues, camera RAM, and much more. Again, you can use that RAM for a million other things, so why use it on this? What would all that RAM and performance be going into? If your answer is just 'doing something that Sonic 2's driver can already do', then this driver is not for you.

You need to know if your hack's goals justify the costs. Are you doing some Mega CD work that the Z80 can't handle? If you just want to have S3K music in your hack, go use S3K's driver (or better yet, a good version of S3K's driver), or a (modern) music-porting tool.


Enhanced Mega PCM - High-quality DPCM/PCM playback, with greater playback control. Now with DAC volume control

•SMPS2ASM - Edit music and sounds in ASM, and port them with ease

•Bugfixes - A lot of them. Sonic 1's, and even Sonic 2's, sound driver is a buggy mess, but you don't have to worry about that

•Less HAX - Real support for music slots >=$E0

•More HAX - Support for music slots <$80 (Git only)

•Enough slots for up to $7C DAC samples for use by music or SFX

•'Delay on overflow' tempo algorithm. Allows for more accurate conversions of S2/S3K tempos than S1's 'delay on timeout' algorithm

•Supports music and SFX from Sonic 1 and Sonic 2

•Partially supports music and SFX from Sonic the Hedgehog 3 & Knuckles, Sonic 3D Blast, Sonic Crackers, and Knuckles' Chaotix

•All DACs (drum and voice samples) from S1, S2, S3K, S3D and Crackers

•All PSG envelopes (PSG instruments) from S1, S2, S3K, S3D and Chaotix

•All PWM samples from Chaotix

•Support for special Sonic 2 sound driver features: ◦Spin Dash SFX support (rev increases in pitch)

◦Gloop SFX support (only plays every other time it's called)

◦StopSFX sound command (used by EHZ boss' propeller)

◦Runs at full speed on PAL consoles ("PAL mode")

◦Song-sensitive PAL mode (S2's drowning theme plays slower on PAL)

◦Absolute FM voice pointers - You can put your voices anywhere, even in a universal bank, like S3K

◦Support for negative track pointers - Within range, you can point to data before or after the song itself

◦More sound queues - Currently at 4, the same as Sonic 2. Sonic 1 only had 2 working ones, and a third broken one

•Support for special Sonic 3 sound driver features: ◦PSG flags (reset, rest)

◦Universal Voice Bank

◦Continuous SFX system

◦FM voice TL output is decided by sign bit, increasing compatibility with certain voices

•Support for special Knuckles' Chaotix sound driver features: ◦PWM playback

This will be a long guide so let's go but first credits.

Original guide credits

  Varion Icaria - Puto's sound driver port.
  Esrael - Tweakers driver port, plus fixes for things broken in Puto's port, such as hanging on the title card. Extra thanks for fixing the Sega sound.
  Puto - Fixes for underwater palette stuff, as well as special stage ring stuff, and various other fixes to the original guide.
  Tweaker - Wrote the orignal guide to port Sonic 1's sound driver into Sonic 2.
  ShadowsofYesterday - Telling me the fix for the SEGA sound. (old version of the guide)
  ValleyBell - In addition to his original work on the Sonic 2 Clone Driver, he showed me numerous things I could do to fix the guide. He also helped me with the equating process. Thanks, ValleyBell!
  Caverns 4 - I wrote and updated the guide.

New guide credits Sonic 2 Clone Driver v2

Contributors to the sound driver disassemblies
Valley Bell - General help, fixes for some bugs, SMPS Research Pack, inspiration
Shobiz - Ported Spin Dash rev code
Puto - Original 68k Sega chant playback code
MarkeyJester - DAC fade-in fix, along with pointing several other bugs in S1's driver
Cinossu - S1SMPS2ASM, the basis of SMPS2ASM
Flamewing - SMPS2ASM core; pointing out S3K's additional PSG frequencies; his perfect-compression koscmp, used to compress Mega PCM
Vladikcomper - Mega PCM, this fix
Gardeguey - SH2 code used as the basis of the 'Stub SH2' program
Clownacy - For the new clone driver

Note this tutorial will be using the GitHub disassembly however if you want to do this with the GitHub Sonic 1 disassembly or the old Sonic 2 disassembly click here.

So let's start!

Clone Driver V2 Tutorial

Setting up the disassembly

First remove all the old sound driver files.

  • s2.sounddriver.asm.
  • Music DAC and PCM Folders.

Second Extract these files in the folder.

  • Everything in Sonic 2 files
  • S1 Music {it's inside Sonic 1 files}{OPTIONAL}
  • All the sound driver files outside of Sonic 2 files

If your not porting your hack to the 32X delete the following

  • Chaotix PWM Driver.bin

• Sonic 2 Clone Driver v2 - PWM Driver.asm • Sonic 2 Clone Driver v2 - PWM Samples.asm • Sonic 2 Clone Driver v2 - Stub SH2.asm

  • Chaotix music

• PWM • Stub 32X

Also you will have to update the build_source and win32 folders.

Introducing the new sound driver

First after include "s2.macros.asm" Paste this.

; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Sonic 2 Clone Driver v2 and SMPS2ASM
        include "sound/Sonic 2 Clone Driver v2 - Macros.asm"
        include "sound/Sonic 2 Clone Driver v2 - Sound IDs.asm"
        include "sound/Sonic 2 Clone Driver v2 - Compatibility.asm"
        include "sound/Sonic 2 Clone Driver v2 - RAM.asm"
        include "sound/Sonic 2 Clone Driver v2 - Constants.asm"
        include "sound/_smps2asm_inc.asm"

Then find jmp_tosounddriverload and replace everything until but not including pausegame with.

        include "sound/Sonic 2 Clone Driver v2 - Functions.asm"

And the goto sounddriverload and delete everything until but not including, ArtNem_Buzzer_Fireball also delete align 1000.

Finally goto cnop -Size_of_SEGA_sound, $8000 and delete everything upto but not including, ; end of rom.

In the area you just deleted place this

       include "sound/Sonic 2 Clone Driver v2.asm"

Deleteing leftovers

Goto snddriverinput and delete it also delete every reference to it.

Also, replace every instance of move.b #MusID_Pause,(Music_to_play).w with SMPS_PauseMusic, and move.b #MusID_Unpause,(Music_to_play).w with SMPS_UnpauseMusic. Then remove the reference to movewZ80CompSize in the line just above EndOfRom

Now under vintret insert this


s2.constants.asm still contains some code for the old sound driver. Find the Music IDs, and delete everything up to ; 2P VS results screens.

While you're in s2.constants.asm, you should allocate some RAM to the Sonic 2 Clone Driver v2. By default, for Sonic 2, it needs $39B bytes. When you've found the RAM for the driver, give it the label Clone_Driver_RAM.

There you go!

SCHG How-To Guide: Sonic the Hedgehog 2 (16-bit)
Fixing Bugs
Fix Demo Playback | Fix a Race Condition with Pattern Load Cues | Fix Super Sonic Bugs | Use Correct Height When Roll Jumping | Fix Jump Height Bug When Exiting Water | Fix Spin Dash Code and Add Spin Dash Speeds | Fix Screen Boundary Spin Dash Bug | Correct Drowning Bugs | Fix Camera Y Position for Tails | Fix Tails Subanimation Error | Fix Tails' Respawn Speeds | Fix Accidental Deletion of Scattered Rings | Fix Ring Timers | Fix Rexon Crash | Fix Monitor Collision Bug | Fix EHZ Deformation Bug | Correct CPZ Boss Attack Behavior | Fix Bug in ARZ Boss Arrow's Platform Behavior | Fix ARZ Boss Walking on Air Glitch | Fix ARZ Boss Sprite Behavior | Fix Multiple CNZ Boss Bugs | Fix HTZ Background Scrolling Mountains | Fix OOZ Launcher Speed Up Glitch | Fix DEZ Giant Mech Collision Glitch | Fix Boss Deconstruction Behavior | Fix Speed Bugs | Fix 14 Continues Cheat | Fix Debug Mode Crash
Design Choices
Remove the Air Speed Cap | Disable Floor Collision While Dying | Modify Super Sonic Transformation Methods & Behavior | Enable/Disable Tails in Certain Levels | Collide with Water After Being Hurt | Retain Rings When Returning at a Star Post | Improve the Fade In\Fade Out Progression Routines | Fix Scattered Rings' Underwater Physics | Insert LZ Water Ripple Effect | Restore Lost CPZ Boss Feature | Prevent SCZ Tornado Spin Dash Death | Improve ObjectMove Subroutines | Port S3K Rings Manager | Port S3K Object Manager | Port S3K Priority Manager | Edit Level Order with ASM‎ | Alter Ring Requirements in Special Stages | Make Special Stage Characters Use Normal DPLCs | Speed Up Ring Loss Process | Add beta spindash to Sonic 2 | Change spike behaviour in Sonic 2
Adding Features
Create Insta-kill and High Jump Monitors | Create Clone and Special Stage Monitors | Port Knuckles
Sound Features
Expand Music Index to Start at $00 | Port Sonic 1 Sound Driver | Port Sonic 2 Clone Driver | Port Sonic 3 Sound Driver | Expand the Music Index to Start at $00 (Sonic 2 Clone Driver Version) | Port Sonic 2 Clone Driver V2 | Play Different Songs Per Act
Extending the Game
Extend the Level Index Past $10 | Extend the Level Select | Extend Water Tables | Add Extra Characters | Free Up 2 Universal SSTs
[[Category:SCHG How-tos|Template:Port Sonic 2 Clone Driver V2]]