Port S2B Sound Driver into Sonic 2

Discussion in 'Tutorials Archive' started by SuperEgg, Mar 10, 2013.

Thread Status:
Not open for further replies.
  1. SuperEgg

    SuperEgg I'm a guy that knows that you know that I know Member

    Joined:
    Oct 17, 2009
    Messages:
    Location:
    THE BEST GOD DAMN STATE OF TEXAS
    Well, it's come to my attention that a few of you folks want to port in the Sonic 2 Beta Driver into Sonic 2 Final. Since I'm a nice guy and all, I'll just go ahead and just leave this for you nice folks.
     
    First off, this tutorial is 2007 friendly. You can use this for the S2 HG disasm as well, but you will have to use a little bit of common sense to actually be able to work. Now, with that out of the way, let's move on.
     
    Step One:
     
    Download this file and decompress it in the main disassembly folder. If you don't want to do all that, open the compressed file, and copy the folder "Sound Driver" into the main disassembly folder. DON'T, take the individual files out of the "Sound Driver" folder. Doing this will fuck you over.
     
    https://www.dropbox.com/s/2s997twk4v24pqz/S2BSoundDriver.zip
     
    What does this zip file contain? 
     
    The S2B sound driver and the music, sfx files, and the DAC samples.
     
    Step Two:
     
    Find "SoundDriverLoad". It should look something like this.


    ; ---------------------------------------------------------------------------
    ; Subroutine to load the sound driver
    ; ---------------------------------------------------------------------------
    ; sub_EC000:

    SoundDriverLoad:
    move sr,-(sp)
    movem.l d0-a6,-(sp)
    move #$2700,sr
    lea (Z80_Bus_Request).l,a3
    lea (Z80_Reset).l,a2
    moveq #0,d2
    move.w #$100,d1
    move.w d1,(a3) ; get Z80 bus
    move.w d1,(a2) ; release Z80 reset (was held high by console on startup) 

    Find that, and delete all of the code up to "Mus_Continue" and replace it with an rts. You should end up with this.


    ; ---------------------------------------------------------------------------
    ; Subroutine to load the sound driver
    ; ---------------------------------------------------------------------------
    ; sub_EC000:

    SoundDriverLoad:

    rts



    ; --------------------------------------------------------------------
    ; Nemesis compressed art (20 blocks)
    ; Buzzer's fireball
    ArtNem_Buzzer_Fireball: BINCLUDE "art/nemesis/Fireball 1 (Buzzer).bin"
    ; --------------------------------------------------------------------
    ; Nemesis compressed art (24 blocks)
    ; Waterfall tiles
    ArtNem_Waterfall: BINCLUDE "art/nemesis/Waterfall tiles.bin"
    ; --------------------------------------------------------------------
     
    Next, go past all the art files and find this


    ; ----------------------------------------------------------------------------------
    ; Filler (free space)
    ; ----------------------------------------------------------------------------------
    ; the PCM data has to line up with the end of the bank.

    if assembleZ80SoundDriver

    cnop -Size_of_SEGA_sound, $8000
    else
    org $F8000-Size_of_SEGA_sound ; not as much leeway here
    endif
     
    Delete everything from this point to...


    ; end of 'ROM'

    if padToPowerOfTwo && (*)&(*-1)

    cnop -1,2<

    dc.b 0

    paddingSoFar := paddingSoFar+1

    else

    even

    endif

    if MOMPASS=2

    ; "About" because it will be off by the same amount that Size_of_Snd_driver_guess is incorrect (if you changed it), and because I may have missed a small amount of internal padding somewhere

    message "rom size is ${*} bytes ({*/1024.0} kb). About ${paddingSoFar} bytes are padding. "

    endif

    ; share these symbols externally (WARNING: don't rename, move or remove these labels!)

    shared word_728C_user,Obj5F_MapUnc_7240,off_3A294,MapRUnc_Sonic,movewZ80CompSize

    EndOfRom:

    END

     
    The code above should not be tampered with.
     
    Step Three:
     
    Go back to "SoundDriverLoad" and replace the rts you placed with this
     


    include "Sound Driver/Sound_Driver.asm"
    Once that is all fine and dandy, go to the end of the ROM. Remember that end part I said not to touch, you're going to touch it after all. In the line...


    shared word_728C_user,Obj5F_MapUnc_7240,off_3A294,MapRUnc_Sonic,movewZ80CompSize

     
    Delete the last part, leaving you with this...


    shared word_728C_user,Obj5F_MapUnc_7240,off_3A294,MapRUnc_Sonic

     
    Now, I know your next question. Why? Simple reason. Remember all that old S2F sound driver I told you to remove? Well, that was part of the code. Since it was deleted, it no longer existed, thus the game yells at you.
     
    Next errors.
     
    In stock S2F, you go to "sndDriverInput" and you see this...


    sndDriverInput:
    lea (Music_to_play&$00FFFFFF).l,a0
    lea (Z80_RAM+zComRange).l,a1 ; $A01B80
     
    Yeah, a bunch of macros and code. Time to exchange it to this....


    sndDriverInput:
    lea ($FFFFE0).l,a0
    lea ($A01B80).l,a1 ; $A01B80
     
    Why? Because the S2B sound driver doesn't have this anywhere in it's setup since it isn't macros for the most part. But, the code is exactly the same. There is literally no difference except this makes that routine sound driver friendly.
     
    Now build. If you had tried to build earlier, it would've whacked out. The two fixes I've just made will make your life easier.
     
    STEP FOUR:
     
    Now since you now have a working rom, assuming you've followed the guide so far, go ahead and test it out. Assuming you haven't added much extra data or art into the rom, the Sound Driver will work fine*.
     
    * If you have, then you might as well take a steep back. Until vladikcomper fixes the driver to get rid of its reliance on preset offsets, just add everything after the driver. It's a temporary fix, but it should work for now.
     
    The next step is to fix the playlist. If you haven't noticed, the music isn't all the same in the game. With this, you'll be able to enjoy the music of S2B with the correct level music. 
     
    Go to "MusicList"


    MusicList:
    dc.b 2+$80 ; 0 ; EHZ
    dc.b 2+$80 ; 1
    dc.b 5+$80 ; 2
    dc.b 4+$80 ; 3
    dc.b 5+$80 ; 4 ; MTZ1,2
    dc.b 5+$80 ; 5 ; MTZ3
    dc.b $F+$80 ; 6 ; WFZ
    dc.b 6+$80 ; 7 ; HTZ
    dc.b $10+$80 ; 8
    dc.b $D+$80 ; 9
    dc.b 4+$80 ; 10 ; OOZ
    dc.b $B+$80 ; 11 ; MCZ
    dc.b $9+$80 ; 12 ; CNZ
    dc.b $E+$80 ; 13 ; CPZ
    dc.b $A+$80 ; 14 ; DEZ
    dc.b 7+$80 ; 15 ; ARZ
    dc.b $D+$80 ; 16 ; SCZ
    dc.b 0 ; 17

    ;----------------------------------------------------------------------------
    ; 2P Music Playlist
    ;----------------------------------------------------------------------------
    ; byte_3EB2:

    MusicList2:
    dc.b $C+$80 ; 0 ; EHZ 2P
    dc.b 2+$80 ; 1
    dc.b 5+$80 ; 2
    dc.b 4+$80 ; 3
    dc.b 5+$80 ; 4
    dc.b 5+$80 ; 5
    dc.b $F+$80 ; 6
    dc.b 6+$80 ; 7
    dc.b $10+$80 ; 8
    dc.b $D+$80 ; 9
    dc.b 4+$80 ; 10
    dc.b 3+$80 ; 11 ; MCZ 2P
    dc.b 8+$80 ; 12 ; CNZ 2P
    dc.b $E+$80 ; 13
    dc.b $A+$80 ; 14
    dc.b 7+$80 ; 15
    dc.b $D+$80 ; 16
    dc.b 0 ; 17 
     
    Replace it with this.


    MusicList:
    dc.b 2+$80 ; 0 ; EHZ
    dc.b 2+$80 ; 1
    dc.b 3+$80 ; 2
    dc.b 3+$80 ; 3
    dc.b 3+$80 ; 4 ; MTZ1,2
    dc.b 3+$80 ; 5 ; MTZ3
    dc.b 2+$90 ; 6 ; WFZ
    dc.b 6+$90 ; 7 ; HTZ
    dc.b 6+$80 ; 8
    dc.b $D+$80 ; 9
    dc.b $90 ; 10 ; OOZ
    dc.b 5+$80 ; 11 ; MCZ
    dc.b 4+$80 ; 12 ; CNZ
    dc.b $D+$80 ; 13 ; CPZ
    dc.b 8+$80 ; 14 ; DEZ
    dc.b 7+$80 ; 15 ; ARZ
    dc.b $F+$80 ; 16 ; SCZ
    dc.b 0 ; 17

    ;----------------------------------------------------------------------------
    ; 2P Music Playlist
    ;----------------------------------------------------------------------------
    ; byte_3EB2:

    MusicList2:
    dc.b 3+$90 ; 0 ; EHZ 2P
    dc.b 2+$80 ; 1
    dc.b 5+$80 ; 2
    dc.b 4+$80 ; 3
    dc.b 5+$80 ; 4
    dc.b 5+$80 ; 5
    dc.b $F+$80 ; 6
    dc.b 6+$80 ; 7
    dc.b $10+$80 ; 8
    dc.b $D+$80 ; 9
    dc.b 4+$80 ; 10
    dc.b 6+$80 ; 11 ; MCZ 2P
    dc.b 1+$80 ; 12 ; CNZ 2P
    dc.b $E+$80 ; 13
    dc.b $A+$80 ; 14
    dc.b 7+$80 ; 15
    dc.b $D+$80 ; 16
    dc.b 0 ; 17

    ; ===========================================================================
     
    Now you have proper level music. Let's move on.
     
    Step Five:
     
    Now it's time for small fixes. Most of these are to fix sound effects not playing, wrong invincibility music, and menu fixes.
     
    First off. Special Stage.
     
    Go to "SpecialStage" Once there, scroll down a little bit till you find this line.


    move.w #$92,d0
    bsr.w PlayMusic 

    Replace it with this


    move.w #$89,d0
    bsr.w PlayMusic 
    This will fix the Special Stage from playing the WFZ music.
     
    Next fix, Metal Sonic not playing the correct boss music.
     
    Go to "loc_397F0", and you'll see this.


    loc_397F0:
    addq.b #2,routine(a0)
    moveq #-$6D,d0
    bsr.w JmpTo5_PlayMusic
    bra.w JmpTo45_DisplaySprite
    Replace it with this.


    loc_397F0:
    addq.b #2,routine(a0)
    moveq #$8E,d0 ;Play Boss Music
    bsr.w JmpTo5_PlayMusic
    bra.w JmpTo45_DisplaySprite
    Next, go to the routine right below it and replace it with this.


    loc_397FE:
    move.b ($FFFFFE0F).w,d0
    andi.b #$1F,d0
    bne.s loc_3980E
    moveq #$48+$80,d0
    bsr.w JmpTo12_PlaySound
    Next, go to "loc_3984A", and change this line.


    moveq #-$12,d0
    bsr.w JmpTo12_PlaySound

    To this.


    moveq #$30+$80,d0 ; Play Spin Charge Sound
    bsr.w JmpTo12_PlaySound
    Next fix, the Final Boss doesn't play the right music.
    Next, go to "loc_3D5CA". Replace this.


    moveq #-$6C,d0
    bra.w JmpTo5_PlayMusic

    With this.


    moveq #$8C,d0 ; Final Boss Music
    bra.w JmpTo5_PlayMusic
     
    Next fix, The Flippers in CNZ have no sound, let's go add one in.
    Next, go to "loc_2B2E2". Replace this.


    move.w #$E3,d0
    jmp (PlaySound).l
    With this.


    move.w #$59+$80,d0 ; Play Beta Flipper Sound
    jmp (PlaySound).l
    It seems that our invincibility plays HTZ, that's not right. 

    Next, go to "invincible_monitor". Replace this.


    move.w #$97,d0
    jsr (PlayMusic).l
    With this.


    move.w #$95,d0 ; Play Beta Invisibility/Super Sonic Music
    jsr (PlayMusic).l

    Quick note: There was no invincibility music in S2B, so the Super Sonic played when you got the power up. The case applies here as well.


    Next, go to "Sonic_CheckGoSuper". Replace this.


    move.w #$16+$80,d0
    jmp (PlayMusic).l ; load the Super Sonic song and return
    With this.


    move.w #$95,d0 ; Play Beta Inivisiblity/Super Sonic Music
    jsr (PlayMusic).l

    So, it seems our menus play the OOZ music. Let us fix that.

    Next, go to "loc_8D6A". Replace this.


    move.b #-$6F,d0
    bsr.w JmpTo_PlayMusic
    With this.


    move.b #$94,d0 ; Play 2P mode Options Menu
    bsr.w JmpTo_PlayMusic
     
    Next, go to "MenuScreen_Options" Replace this.


    move.b #-$6F,d0
    bsr.w JmpTo_PlayMusic
    With this.


    move.b #$8B,d0 ; Play Normal Menu/Level Select Music
    bsr.w JmpTo_PlayMusic
    Here's a fix for the 2p Results Screen. 

    Go to "TwoPlayerResults", and look for this piece of code.


    move.b #-$7F,d0
    cmp.w (Level_Music).w,d0


    Replace it with this.


    move.b #$94,d0 ; Play 2P Menu Music
    cmp.w (Level_Music).w,d0


    Last Menu fix, the Level Select Menu.

    Go to "loc_9366". Replace this.


    move.b #-$6F,d0
    bsr.w JmpTo_PlayMusic


    With this.


    move.b #$8B,d0 ; Play Normal Menu/Level Select Music
    bsr.w JmpTo_PlayMusic


    Now, since we have our menu's all squared away, let's fix our boss music issues, unless you like the 2P EHZ theme.

    In order to save us time, go to these routines. 

    "LevEvents_EHZ2_Routine3"

    "LevEvents_MTZ3_Routine4"

    "LevEvents_HTZ2_Routine8"

    "LevEvents_OOZ2_Routine3"

    "LevEvents_MCZ2_Routine3"

    "loc_F318"

    "loc_F3FA"

    "loc_F55C"

     

    Look for these two lines in each of the routines.

    move.w #$93,d0
    bsr.w JmpTo3_PlayMusic



    Replace the top line.


    move.w #$93,d0


    With this.


    move.w #$8E,d0 ; Play Boss Music



    And that should fix most of your sound problems. Go and build that ROM and play. It should now work perfectly with little issues whatsoever as far as incorrect sound effects go. Bear in mind, not all sound effects exist in the driver, so there may be times that there are no sound effects when there should be. Otherwise, go crazy, you're not missing out on to much.
     
    Last edited by a moderator: Mar 10, 2013
  2. ThomasThePencil

    ThomasThePencil resident psycho Member

    Joined:
    Jan 29, 2013
    Messages:
    910
    Location:
    the united states. where else?
    Um...is the Sonic 2 Beta sound driver easier to work with than Sonic 2 Final's sound driver?
     
  3. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    If none of the pointers can be changed or moved, it makes it very tough to work with. It's practically common sense; knowing whether it is tough or not to work with. i'm puttin' money on this though, porting it was cake. Excellent guide SuperEgg. I've been long awaiting this.
     
Thread Status:
Not open for further replies.