Sonic Adventure Music in Sonic 1

Discussion in 'Showroom Archive' started by Sonic 65, Oct 7, 2007.

Thread Status:
Not open for further replies.
  1. Sonic 65

    Sonic 65 Active Member Member

    Joined:
    Aug 9, 2007
    Messages:
    42
    Copy-pasta from S2B/Sonic Retro.


    prepare for a tl;dr post guys.


    As you may or may not know, I've been experimenting with different ways to play full PCMs over the past few weeks, and came up with a new S1 PCM driver based on the one that came with drx's code template which can support a 3-byte length, variable pitch, and looping (based on a looping flag). The driver doesn't work perfectly in S1 yet, there's still some distorted sound. Tweaker says the DAC works best when the 68K is frozen, but I don't know how to do that without slowing down/stopping the game, so some music sounds distorted and crappy.


    Anyway, here's the ROM. Music choices are:


    GHZ = Emerald Coast (Azure Blue Sky)


    MZ = Red Mountain (Mt. Red - A Symbol Of Pride)


    SYZ = Casinopolis (The Dreamy Stage)


    LZ = Lost World (DANGER - Chased By A Rock!)


    SLZ = Speed Highway (whatever the first song's name is)


    SBZ = Final Egg (Mechanical Resonance)


    Boss = SCD Jap. Boss Theme (yes, I know this isn't from Sonic Adventure)


    FZ = Perfect Chaos


    GHZ and LZ sound a little distorted, but they still sound like the original song.


    I'll also take this topic to release the new driver, with instructions on how to integrate it into the ROM. Here's the new sound driver. It doesn't replace the old one, but instead works as a second driver for the PCM songs. To make this driver work with the S1 ROM, first put this at the end of the ROM:



    Code:
    PCMDriverLoad:			; XREF: GameClrRAM; TitleScreen
    
    		move.w	#0,($A11200).l
    
    		move.w	#$100,($A11100).l
    
    		move.w	#$100,($A11200).l
    
    		
    
    WaitForZ80_2:
    
    		btst	#0,($A11100).l
    
    		bne	WaitForZ80_2
    
    		
    
    		lea	(Kos_Z80_2),a0
    
    		lea	($A00000).l,a1
    
    		move.W	#KosZ802End-Kos_Z80_2,d1
    
    		
    
    LoadDriver:
    
    		move.b	(a0)+,(a1)+
    
    		dbf	d1,LoadDriver
    
    		rts


    That's the subroutine that loads the PCM Driver. You'll also need to insert the second sound driver after that, which would be like this:



    Code:
    Kos_Z80_2:
    
    		incbin	sound\PCMD.bin
    
    KosZ802End:


    PCM playing is handled at the beginning of the subroutine Sound_81to9F. At the beginning of Sound_81To9F, put a jump to SoundDriverLoad, which loads the original DAC sound driver for regular songs. To actually play a PCM song, put this before the jump to SoundDriverLoad:



    Code:
    		cmpi.b	#$81,d7
    
    		beq.l	PlayMusic81
    
    		jmp	Continue8129F


    Replace the #$81 and PlayMusic81 with the respective values (e.g. #$82 and PlayMusic82) for respective songs. After that code, we need to put the actual code that plays the song, which would look like this:



    Code:
    ; ---------------------------------------------------------------------------
    
    PlayMusic81:
    
    
    
    		jsr	Sound_E4
    			move.w	#$100,($A11100).l	;Stop the Z80WaitZ80_81:		btst	#0,($A11100).l		bne	WaitZ80_81		;Wait for z80 to halt		jsr	PCMDriverLoad		move.b	#1,($a00039).l		;Turn PCM Playing Flag ON		move.b	#((Music81&0xFF0000)>>16),($a0003c).l	;addr - $__xxxx		move.b	#((Music81&0xFF00)>>8),($a0003b).l		;addr - $xx__xx		move.b	#(Music81&0xFF),($a0003a).l			;addr - $xxxx__				move.b	#(((Music82-Music81)&0xFF0000)>>16),($a0003f).l	;addr - $__xxxx		move.b	#(((Music82-Music81)&0xFF00)>>8),($a0003e).l		;addr - $xx__xx		move.b	#((Music82-Music81)&0xFF),($a0003d).l			;addr - $xxxx__		move.b	#$06,($a00046).l	;sample rate (06=8000KHz)		move.b	#$01,($a00048).l	;looping flag ($00=no,$01=yes)		move.w	#$0,($A11100).l		;Start the Z80		rts; ---------------------------------------------------------------------------
    Again, replace all respective values. The Music82-Music81 is signifying the length; Music82 starts at the end of Music81, so Music82-Music81 is the length of the song Music81.
    Make more subroutines just like that and do more compares for more PCMs you want to play. After the end of the subroutine PlayMusic81, just put the label Continue8129F. And you're done. The whole thing should look like this:



    Code:
    Sound_81to9F:				; XREF: Sound_ChkValue
    
    		cmpi.b	#$81,d7
    
    		beq.l	PlayMusic81
    
    		jmp	Continue8129F
    
    
    
    ; ---------------------------------------------------------------------------
    PlayMusic81:
    
    		jsr	Sound_E4
    
    		move.w	#$100,($A11100).l	;Stop the Z80
    
    WaitZ80_81:
    		btst	#0,($A11100).l
    		bne	WaitZ80_81		;Wait for z80 to halt
    
    		jsr	PCMDriverLoad
    
    
    
    		move.b	#1,($a00039).l		;Turn PCM Playing Flag ON
    
    
    		move.b	#((Music81&0xFF0000)>>16),($a0003c).l	;addr - $__xxxx
    		move.b	#((Music81&0xFF00)>>8),($a0003b).l		;addr - $xx__xx
    		move.b	#(Music81&0xFF),($a0003a).l			;addr - $xxxx__
    
    
    		move.b	#(((Music82-Music81)&0xFF0000)>>16),($a0003f).l	;addr - $__xxxx
    		move.b	#(((Music82-Music81)&0xFF00)>>8),($a0003e).l		;addr - $xx__xx
    		move.b	#((Music82-Music81)&0xFF),($a0003d).l			;addr - $xxxx__
    
    
    		move.b	#$06,($a00046).l	;sample rate (06=8000KHz)
    
    		move.b	#$01,($a00048).l	;looping flag ($00=no,$01=yes)
    
    		move.w	#$0,($A11100).l		;Start the Z80
    
    		rts
    
    ; ---------------------------------------------------------------------------
    
    Continue8129F:
    		jsr	SoundDriverLoad
    		cmpi.b	#$88,d7		; is "extra life" music	played?
    		bne.s	loc_72024	; if not, branch
    		tst.b	$27(a6)

    It should be fairly obvious how to add more songs. I hope you understood what to do, because I suck at explaining things =P


    Hopefully this will open up the gates to much more awesome-sounding music in Sonic games.
     
  2. Chaos Hedgie

    Chaos Hedgie I'm 30 years old, with a OC. You'll live. Member

    Joined:
    Aug 12, 2007
    Messages:
    141
    Location:
    Flint, Michigan
    They all sound horrible. But I guess this will be improved with time, eh?
     
  3. Spanner

    Spanner The Tool Member

    Joined:
    Aug 9, 2007
    Messages:
    2,570
    It's a good idea you've done, Sonic 65 but the tracks are way too buggy plus the fact I am greeted with a bleeping sound when I reset Gens. I do like having Red Mountain in Marble Zone, shame the track cut out & restarted after a minute. Also, the usual bug of 1up music cuts the track fully but that will be fixed.
     
  4. Sonic 65

    Sonic 65 Active Member Member

    Joined:
    Aug 9, 2007
    Messages:
    42
    This is the best the tracks can get, because making them better means slowing down/stopping the game. So it's either sound or game =P


    And SOTI, the reason all the tracks cut out are to conserve ROM space. I only have 4MB of space, and I have to put in 8 songs, so =P
     
  5. SaunicBoom

    SaunicBoom Well-Known Member Member

    Joined:
    Sep 14, 2007
    Messages:
    324
    Well, it's definetly something interesting, however I'd rather listen to MIDIs in a ROM hack than tracks. Perhaps you should try something like Sonic CD did by programming it to play MP3s if you want the greatest quality.
     
  6. Sonic 65

    Sonic 65 Active Member Member

    Joined:
    Aug 9, 2007
    Messages:
    42
    HAY GUYZ


    Sonic Rush music doesn't really fit with Sonic 1 levels though =P


    And I can't really do much about the quality, sadly. Sonic Boom, the actual PCM engine isn't what's making the difference (and MP3s would be hard as hell to program anyway, leave that to drx or StephenUK =P); unless the 68K is freezed into a loop, which stops the game, the DAC can't output at its full potential.
     
  7. Sonic 65

    Sonic 65 Active Member Member

    Joined:
    Aug 9, 2007
    Messages:
    42
    I figured out how to fix the crappy sound without any (noticeable =P) slowdown in gameplay.


    Fixed ROM


    New Music Choices:


    GHZ - Palmtree Panic Present Jap.


    LZ - Lost World (Chased By a Rock!"


    MZ - Sand Ocean


    SLZ - Stardust Speedway Good Future Jap.


    SYZ - Collision Chaos Present Jap.


    SBZ - Metallic Madness PResent Jap.


    Boss - SCD Boss


    FZ - Perfect Chaos


    If you want, you can compare the LZ, Boss, and FZ music from the original to this to see how the quality's improved. =P I'll put up the instructions for the fix tomorrow, I'm sleepy now, so sorry.
     
Thread Status:
Not open for further replies.