don't click here

Sonic 1 "Mega PCM" driver

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

  1. vexatious

    vexatious

    Misfit
    44
    1
    8
    Hi MarkeyJester. I'm interested in using the core yamaha (including other hardware) in ways not imposed by Sega's SDKs (assuming they're real). E.g. the core yamaha can't play samplerates above 16khz according to Sega sdks, but if I can buffer two 8-bit channels at 22050khz each (or 44100khz stereo) then I can get some more flexibility from the yamaha. I'm guessing this MegaPCM has coincidence with my curiosity...

    I'm also looking for any genuine documents and/or datasheets for the core yamaha unrelated to Sega. Same request for other hardware in MarsCD.
     
  2. Alex Field

    Alex Field

    シュート! カオス・エメラルド・ザが消えようとしている! Member
    I made an optimized version of "sub_7272E" and "sub_72764".

    Firstly though, at the waitYM macro, change it to this:
    Code (Text):
    1. waitYM macro
    2. @wait\@
    3.     btst    #7,(a0)
    4.     bne.s    @wait\@
    5.     endm
    Then at "sub_7272E", change all the code upto (but not including) "word_72790".
    Code (Text):
    1. sub_7272E:                ; XREF: loc_71E6
    2.         stopZ80
    3.         lea    ($A04000).l,a0
    4.         waitYM
    5.         move.b    d0,(a0)
    6.         waitYM
    7.         move.b    d1,1(a0)
    8.         move.b    #$2A,(a0)
    9.         startZ80
    10.         rts
    11. ; End of function sub_7272E
    12.  
    13. ; ===========================================================================
    14.  
    15. loc_7275A:                ; XREF: sub_72722
    16.         move.b    1(a5),d2
    17.         bclr    #2,d2
    18.         add.b    d2,d0
    19.  
    20. ; ||||||||||||||| S U B    R O U T    I N E |||||||||||||||||||||||||||||||||||||||
    21.  
    22.  
    23. sub_72764:                ; XREF: loc_71E6A; Sound_ChkValue; sub_7256A; sub_72764
    24.         stopZ80
    25.         lea    ($A04000).l,a0
    26.         waitYM
    27.         move.b    d0,2(a0)
    28.         waitYM
    29.         move.b    d1,3(a0)
    30.         move.b    #$2A,(a0)
    31.         startZ80
    32.         rts
    33.  
    34. ; End of function sub_72764
    If you're going to reuse an address, it's faster to set it to a0. Also, because the address was set, the bottom waitYMs were no longer needed.

    Also, I not sure but the "nops" in the stopZ80 macro don't seem to be necessary (as far as I know); so remove them.
     
  3. Rrose80149

    Rrose80149

    Member
    78
    7
    8
    A problem with the Hivebrain Mega PCM. I was testing it in Sonic 1 but when getting a 1-Up in a Special Stage the FM 6 instrument went missing.
     
    Last edited: Apr 11, 2021
  4. Inferno

    Inferno

    Member
    36
    69
    18
    Sonic 1 Definitive
    That's not an issue with MegaPCM, that's a vanilla S1 sounddriver issue. (One of many)

    Which already has a wiki guide for fixing it, btw.
     
    Last edited: Apr 13, 2021
  5. Gaming Gardevoir

    Gaming Gardevoir

    Member
    9
    0
    1
    I'm having an issue installing Mega PCM with the latest Hivebrain disassembly, I can't find any of the files that the instructions of the first post are pointing to. Also, are there instructions for doing this in the GitHub disassembly? I'm trying to re-implement the Sonic 1 prototype drums and I was told I need to apply this for that to work
     
    Last edited: Aug 19, 2022
  6. You don't need to replace the sound driver to reimplement the Sonic 1 proto drums. If you're using Hivebrain 2022 or GitHub AS, it's as simple as changing one line in the sound driver and three in the DAC driver:

    Hivebrain 2022 (GitHub AS equivalents in parentheses)
    Open sound/Sound Driver.asm (s1.sounddriver.asm) and find DAC_sample_rate:
    Code (Text):
    1.  
    2. DAC_sample_rate:
    3.        dc.b  18, 21, 28, 29, $FF, $FF
    4.  
    GitHub AS lists the sample rates as hexadecimal, but is otherwise identical here.

    Add 5 to each of the first four values like so:
    Code (Text):
    1.  
    2. DAC_sample_rate:
    3.        dc.b  18+5, 21+5, 28+5, 29+5, $FF, $FF
    4.  

    Then, open sound/DAC Driver.asm (sound/z80.asm) and find PCM_Table (zPCM_Table)
    Code (Text):
    1.  
    2. PCM_Table:
    3.        zsample   dKick, 17h               ; Kick sample
    4.        zsample   dSnare, 1h               ; Snare sample
    5.        zsample   dTimpani, 1Bh               ; Timpani sample
    6.  
    The table is laid out differently in GitHub AS, but the values are the same.

    Change the pitch values from 17h, 1h, and 1Bh to 19h, 6h, and 20h respectively:
    Code (Text):
    1.  
    2. PCM_Table:
    3.        zsample   dKick, 19h               ; Kick sample
    4.        zsample   dSnare, 6h               ; Snare sample
    5.        zsample   dTimpani, 20h               ; Timpani sample
    6.  

    That's basically it.

    If you're using Hivebrain 2005 or the older ASM68K-based Git disasm, it's a little more complicated; the sound driver changes are more or less the same, but you'll need to build a replacement for the incbin'ed DAC driver. Information on that (and source of these instructions) can be found here.
     
    Last edited: Aug 26, 2022
  7. Gaming Gardevoir

    Gaming Gardevoir

    Member
    9
    0
    1
    Thanks! I actually got help from someone on this topic elsewhere, but I’m glad you posted it here too for anyone else who happens upon it. Funny story: I was doing this as part of a bugfixing spree to make a “perfect” Sonic copy for myself. Changing the drums made the filesize go up to 539kb and for some reason changing the GHZ palette to match the beta made the filesize go back to 512kb. (Those were the only two QoL changes I made)
     
  8. Brainulator

    Brainulator

    Regular garden-variety member Member
    It probably would make more sense to edit this part, then:
    Code (Text):
    1.     if Revision=0
    2.         dcb.b $62A,$FF
    3.     else
    4.         dcb.b $63C,$FF
    5.     endc
    6.         ;dcb.b ($10000-(*%$10000))-(ROM_End-SoundDriver),$FF
     
  9. Nik Pi

    Nik Pi

    Member
    Weird, but beta drums works correctly, if I just replace samples in the realese version disasm for those from the prototype..
     
  10. Cioss

    Cioss

    Member
    10
    1
    3
    France
    I'm having a weird issue with MegaPCM, For some reason WAV samples play at a very low pitch even at $01 pitch, And even if I change the rate to 8khz, it still sounds super low the exact same way. This only happens for WAV files, making it RAW works, But I'd still like to know if there's a fix for it in the future.
     
  11. Devon

    Devon

    There's nothing left but faith Tech Member
    854
    572
    93
    You are exporting it as a mono unsigned 8-bit WAV file right?
     
  12. XPointZPoint

    XPointZPoint

    That's no good! Member
    47
    13
    8
    Does anyone have the download links archived?
     
  13. Devon

    Devon

    There's nothing left but faith Tech Member
    854
    572
    93