Sonic 1 Mega PCM driver

Discussion in 'Tutorials Archive' started by vladikcomper, Jun 11, 2012.

Thread Status:
Not open for further replies.
  1. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    Sorry for the Major bump! I have yet another question. After applying this code to my hack, the SEGA intro PCM doesn't load for some odd reason. (Yes I already changed it to something else,) But every other DAC sample loads, am I going to have to fix the playback rate of the SEGA intro or is it just something that I forgot to change?
     
  2. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    Have you applied this guide? http://info.sonicretro.org/SCHG_How-to:Fix_the_SEGA_Sound
     
    With it, SEGA PCM playback should work for sure. This guide offers you code that does all playback on 68K side, it won't be handled by Mega PCM then. The old code relies on Z80 driver to play the sample, the SEGA sample should be stored in slot $8F then. Well, you can either apply that guide, or just store a SEGA sample in slot $8F, like this:
     


        DAC_Entry    $08, SegaPCM, pcm

    Then you have to remove SegaPCM label and its incbin from sonic.asm, and include it into MegaPCM.asm instead, as follows:


        IncludeDAC    SegaPCM, bin
    At last, move SegaPCM.bin from sound folder to dac one, where MegaPCM loads all samples from

    Either way should work. I just didn't included that into Mega PCM, because I assumed most of people had already applied the guide in the beginning. There is no difference between them, except for one thing. With that guide, the sample will be overpitched when you overclock 68k (this is something that happens really rarely in the emulation, but I've seen a few Gens mods suggesting overclocked CPU).
     
  3. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    I ran into the same problem again, but loaded it from MegaPCM, but now I have the playback rate. It easily plays the sample with random pitch shifts, which was corrected in the Sound_E1 routine. But since it no longer works, I suppose it would be something with the code itsself...

    Ironically enough, I am using the Sonic two-eight disassembly which already has the Sega chant code fixed. (For the most part, it is oddly unable to function after the MegaPCM is added.)
     
  4. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    Figured it out. The issue with SEGA PCM fix only occurs when you apply Mega PCM HQ playback guide. I just missed that bit, because it was properly working in Kega, that I mainly use, and I simply didn't notice it when testing in other emulators, even on hardware, because the ROM tested had a debug screen replacing SEGA logo.

    The reason PCM playback code didn't work was because Z80 wasn't stopped by the point that code was executed, as HQ playback removes a lot of Z80 stops in order to increase playback quality. If Z80 isn't stopped, 68K cannot access neither Z80, nor YM. Apparently, this wasn't emulated in Kega. I've fixed all the places where SMPS needed YM or Z80 access in my guide, but forgot about his one.

    To fix the issue, change Sound_E1 code as follows:



    Sound_E1:
    stopZ80
    lea (SegaPCM).l,a2 ; Load the SEGA PCM sample into a2. It's important that we use a2 since a0 and a1 are going to be used up ahead when reading the joypad ports
    move.l #(SegaPCM_End-SegaPCM),d3 ; Load the size of the SEGA PCM sample into d3
    move.b #$2A,($A04000).l ; $A04000 = $2A -> Write to DAC channel
    PlayPCM_Loop:
    move.b (a2)+,($A04001).l ; Write the PCM data (contained in a2) to $A04001 (YM2612 register D0)
    move.w #$14,d0 ; Write the pitch ($14 in this case) to d0
    dbf d0,* ; Decrement d0; jump to itself if not 0. (for pitch control, avoids playing the sample too fast)
    sub.l #1,d3 ; Subtract 1 from the PCM sample size
    beq.s return_PlayPCM ; If d3 = 0, we finished playing the PCM sample, so stop playing, leave this loop, and unfreeze the 68K
    lea ($FFFFF604).w,a0 ; address where JoyPad states are written
    lea ($A10003).l,a1 ; address where JoyPad states are read from
    jsr (Joypad_Read).w ; Read only the first joypad port. It's important that we do NOT do the two ports, we don't have the cycles for that
    btst #7,($FFFFF604).w ; Check for Start button
    bne.s return_PlayPCM ; If start is pressed, stop playing, leave this loop, and unfreeze the 68K
    bra.s PlayPCM_Loop ; Otherwise, continue playing PCM sample
    return_PlayPCM:
    startZ80
    addq.w #4,sp
    rts


    As for the second way, playing SEGA PCM through Mega PCM, I don't see why you had playback rate issues. HQ playback guide should resolve them. Just tried this way myself, sounds fine for me.
     
  5. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    I have yet another question. Seeing how Sonic 2's Nick Arcade Beta runs the Sonic 1 sound driver; would there a simplified way to add extra DAC samples into the Sound driver without resorting to adding MegaPCM?
     
  6. 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
    No. The S2NA driver is byte for byte exact as Sonic 1. Hell, it is still initialized by the VBlank. If you had to modify S1's driver to add in extra DAC samples, guess what, it'll be the exact same thing here. In all honesty, when I was hacking S2NA, I outright replaced the driver with S1's as a test. Nice to see I was right. 

    As a side note, I have no idea how to modify sound drivers, I just know how to port them. Just a question, why do you need the Mega PCM driver? What music are you trying to add into it? If it's Sonic 2 music, the guide I wrote yesterday is S2NA compatible, for the most part. You may have to find some VBlank routine equivalents, but it should still work nevertheless.
     
Thread Status:
Not open for further replies.