don't click here

How to expand the DAC samples using jman sound driver

Discussion in 'Engineering & Reverse Engineering' started by Mairtrus, Oct 1, 2008.

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

    Mairtrus

    Get a load of this!! Tech Member
    27
    0
    0
    Mendoza, Argentina
    Sonic Z. The Z DOESN'T means nothing.
    ( ;) Information irrelevant. Do not feel obliged to read it, it's just that I have the soul of a writer)

    Well, all started exactly a week ago when, tired of listening my port of Evening Star playing noise sounds every time it tried to play a Tom, or something like that. So, motivated by my adventurous spirit, I decided to finally start to work to expand the DAC samples, only for find later a seemingly insurmountable problem: the limited memory size of the Z80 (where the samples are stored). Fortunately, I remembered that jman had created a solution on this, and here it is, after tortuous days of experiments and whole nights downloading porn doing tests... A COMPLETE GUIDE ON HOW TO CORRECTLY SET UP THE JMAN'S SOUND DRIVER!

    (End of the irrelevant data. Enjoy the guide :v: )

    Before you begin, I want to make a clarification. By default, the original sound driver(the one who brings Sonic 1) is compressed. I will explain how to mount the new sound driver uncompressed, for a simple reason: it is necessary to know the final location of the samples, which can be very , VERY annoying. Either way, the space occupied by the uncompressed sound driver is not so big as to worry about compressing it to save some space.

    Made the clarification, we come to the guide.

    To do this, we will need 3 elements:
    1) The sound driver (of course), can be downloaded from here
    Also,as a recommendation, read everything on the first post, only to know something more information.
    2) The hex editor of your choice.
    3) A bank of samples. Whatever. It's your choise. Are available: Sonic 2 and Sonic 2 Beta samples, Sonic 3 samples and Sonic Spinball samples
    Just for didactical purposes, I will show ho to do this with original decompressed samples provided by jman here.

    Now, some useful information.

    First, the "ROM bank" (bytes 6/7) is precisely the offset where the DAC samples are, with a small rarity: Due to the architecture of the Z80, each offset of the bank are rounded to the nearest 15 bit (16 if you count the fisrt bit as a 1).
    So, if your bank starts at the offset $76A46, the value that you will put in the sound driver is $76A (ROMBank/$100), but the Z80 will use the offset $70000. Similarly, if the offset is $7B22F, the Z80 will use $78000.

    Second, the location of the PCM (bytes 1/2) sample ever starts whith a $8000. This mean, the $8000 is the zero. Any value above will be positive, and anyone below will be negative.

    Third, due the "rarity" of the Z80, the location of sample will have a format that respect the first and second point. So, for example, if our first sample is in $76A46, the ROM Bank will be $70000 (Z80), and our sample location will be $6A46 (Real offset-Z80 offset) + $8000, so it give to us $EA46 (Credits to Windows's Calc).

    Now, we're going to gutting a little the sound driver.

    Open the file "Z80_new.bin" in the hex editor, and ERASE ALL after the byte $200. You will get a 512 bytes file. Now, save it where you want. For didactical purposes, I saved it on ...\sound\dac\ , inside the main folder of the disassembly, and with it, the decompressed samples.

    Then go to the label "Kos_Z80" and replace this:
    Code (ASM):
    1. Kos_Z80:    incbin  sound\z80_1.bin
    2.         dc.w ((SegaPCM&$FF)<<8)+((SegaPCM&$FF00)>>8)
    3.         dc.b $21
    4.         dc.w (((EndOfRom-SegaPCM)&$FF)<<8)+(((EndOfRom-SegaPCM)&$FF00)>>8)
    5.         incbin  sound\z80_2.bin
    6.         even
    Whit this:
    Code (ASM):
    1. Z80_Driver: incbin  sound\dac\z80_new.bin
    2.         even

    Simple, right?

    Having done this, we need to create the table that was erased from the "Z80_new.bin" file.
    The table format is as follow, so paste it 15 times, changing the the value on the label acording due the number of sample that you are defining.
    Code (ASM):
    1. DacPCM0:
    2.         incbin  sound\dac\dac1d.bin
    3.         even
    4. DacPCM1:
    5.         incbin  sound\dac\dac2d.bin
    6.         even
    7. DacPCM2:
    8.         incbin  sound\dac\dac3d.bin
    9.         even
    Now, this is the configuration that need each PCM definition:
    Code (ASM):
    1. DacDef0:
    2.         dc.w    ((($8000+(DacPCM0-(DacPCM0&$FFFF8000)))&$FF)<<8)+((($8000+(DacPCM0-(DacPCM0&$FFFF8000)))&$FF00)>>8)
    3.         dc.w    $5203
    4.         dc.b    $80
    5.         dc.w    (((DacPCM0/$100)&$FF)<<8)+(((DacPCM0/$100)&$FF00)>>8)
    6.         dc.b    $00
    The explanation of this is some lines above. But, this need some changes. You need to change each line where it says "DacPCM0" by the number of the actual DAC that you are defining.
    Another change that is really necesary to do: change the pitch (byte 5). I tried a lot of diferents values, but I cannot distinguish what are the normal values for each sample. Sorry. :( :( :(

    Remember what the values for the weight of each sample (bytes 3/4) is its real weight/2, and is little endian (you need to swap the bytes).

    Now, we need to modify the method to load the sound driver, but is needed the final weight of the entirely sound driver. So, if periodically you add new samples, you will need to calculate again the weight of the Z80+the PCM table definition. So, add this after the last include:
    Code (ASM):
    1. Z80_Size:
    2.         dc.w    DacPCM0-Z80_Driver
    Then, go to the label "SoundDriverLoad", and change this:
    Code (ASM):
    1.         lea (Kos_Z80).l,a0  ; load sound driver
    2.         lea ($A00000).l,a1
    3.         bsr.w   KosDec      ; decompress
    Whit this:
    Code (ASM):
    1.         moveq   #0,d0
    2.         lea (Z80_Driver).l,a0   ; load the sound driver
    3.         lea ($A00000).l,a1      ; load the destiny offset
    4.         move.w  (Z80_Size).l,d0     ; load the weight of the sound driver
    5.         sub.w   #1,d0
    6.  
    7. SoundDriver_Z80:
    8.         move.b  (a0)+,(a1)+
    9.         dbf d0,SoundDriver_Z80
    Finally, save, build and test.

    Just two more point before the end.
    First, due to my total ignorance of how work the multi-bank slot (slot E, by default), I leave it for a future update of this guide, unless someone explain their use before me.
    Second, isn't really necesary add a definition to play the SEGA sound, because the fix made by Puto works perfectly. So, you gain another slot!

    Criticism, mistakes, ideas, insults, everything will be well received.
     
  2. Nicogens

    Nicogens

    Don't. Member
    77
    0
    6
    Argentina
    Sonic Overhauled (lmao)
    Oh god, that guide is so usefull ;) , I will use it on my hack.
     
  3. Spanner

    Spanner

    The Tool Member
    Woo, I might try this and get S3K's DAC in my hack. Nice work. ;)
     
  4. jman2050

    jman2050

    Teh Sonik Haker Tech Member
    634
    4
    18
    I applaud you for making this, though I'm confused as to how you can be ignorant about the multi-bank slot when I explained it rather clearly in the topic you linked :P
     
  5. Eduardo Knuckles

    Eduardo Knuckles

    Not a loved one, but the most hated person. Banned
    414
    10
    18
    Someplace somewhere
    Project S.A.M.G.
    Do you can post a example from a sample set on it?
     
  6. Mairtrus

    Mairtrus

    Get a load of this!! Tech Member
    27
    0
    0
    Mendoza, Argentina
    Sonic Z. The Z DOESN'T means nothing.
    Thank you guys!!

    No matter. This happens in every aspect of my life. I can solve the most difficult problems and fuck it in the most simplest details.

    I thought it had been clear enough, but why not?
    It should see the sound driver like this, to play the 3 Sonic 1 original PCM samples.
    Code (ASM):
    1. Z80_Driver: incbin  sound\dac\z80_new.bin
    2.         even
    3. ; ===========================================================================
    4. ;   Definitions
    5. ; ===========================================================================
    6. DacDef0:
    7.         dc.w    ((($8000+(DacPCM0-(DacPCM0&$FFFF8000)))&$FF)<<8)+((($8000+(DacPCM0-(DacPCM0&$FFFF8000)))&$FF00)>>8)
    8.         dc.w    $5203
    9.         dc.b    $80
    10.         dc.w    (((DacPCM0/$100)&$FF)<<8)+(((DacPCM0/$100)&$FF00)>>8)
    11.         dc.b    $00
    12.  
    13. DacDef1:
    14.         dc.w    ((($8000+(DacPCM1-(DacPCM1&$FFFF8000)))&$FF)<<8)+((($8000+(DacPCM1-(DacPCM1&$FFFF8000)))&$FF00)>>8)
    15.         dc.w    $7007
    16.         dc.b    $88
    17.         dc.w    (((DacPCM1/$100)&$FF)<<8)+(((DacPCM1/$100)&$FF00)>>8)
    18.         dc.b    $00
    19.  
    20. DacDef2:
    21.         dc.w    ((($8000+(DacPCM2-(DacPCM2&$FFFF8000)))&$FF)<<8)+((($8000+(DacPCM2-(DacPCM2&$FFFF8000)))&$FF00)>>8)
    22.         dc.w    $1610
    23.         dc.b    $81
    24.         dc.w    (((DacPCM2/$100)&$FF)<<8)+(((DacPCM2/$100)&$FF00)>>8)
    25.         dc.b    $00
    26.  
    27. DacDef3:
    28.         dc.w    0
    29.         dc.w    0
    30.         dc.b    0
    31.         dc.w    0
    32.         dc.b    0
    33.  
    34. DacDef4:
    35.         dc.w    0
    36.         dc.w    0
    37.         dc.b    0
    38.         dc.w    0
    39.         dc.b    0
    40.  
    41. DacDef5:
    42.         dc.w    0
    43.         dc.w    0
    44.         dc.b    0
    45.         dc.w    0
    46.         dc.b    0
    47.  
    48. DacDef6:
    49.         dc.w    0
    50.         dc.w    0
    51.         dc.b    0
    52.         dc.w    0
    53.         dc.b    0
    54.  
    55. DacDef7:
    56.         dc.w    0
    57.         dc.w    0
    58.         dc.b    0
    59.         dc.w    0
    60.         dc.b    0
    61.  
    62. DacDef8:
    63.         dc.w    0
    64.         dc.w    0
    65.         dc.b    0
    66.         dc.w    0
    67.         dc.b    0
    68.  
    69. DacDef9:
    70.         dc.w    0
    71.         dc.w    0
    72.         dc.b    0
    73.         dc.w    0
    74.         dc.b    0
    75.  
    76. DacDefA:
    77.         dc.w    0
    78.         dc.w    0
    79.         dc.b    0
    80.         dc.w    0
    81.         dc.b    0
    82.  
    83. DacDefB:
    84.         dc.w    0
    85.         dc.w    0
    86.         dc.b    0
    87.         dc.w    0
    88.         dc.b    0
    89.  
    90. DacDefC:
    91.         dc.w    0
    92.         dc.w    0
    93.         dc.b    0
    94.         dc.w    0
    95.         dc.b    0
    96.  
    97. DacDefD:
    98.         dc.w    0
    99.         dc.w    0
    100.         dc.b    0
    101.         dc.w    0
    102.         dc.b    0
    103.  
    104. DacDefE:
    105.         dc.w    0
    106.         dc.w    0
    107.         dc.b    0
    108.         dc.w    0
    109.         dc.b    0
    110. ; =============================================================
    111. ;   Samples
    112. ; =============================================================
    113. DacPCM0:
    114.         incbin  sound\dac\dac1d.bin
    115.         even
    116. DacPCM1:
    117.         incbin  sound\dac\dac2d.bin
    118.         even
    119. DacPCM2:
    120.         incbin  sound\dac\dac3d.bin
    121.         even
    122.  
    123. Z80_Size:
    124.         dc.w    DacPCM0-Z80_Driver
    Just be careful with the pitches!!
     
  7. Master3k

    Master3k

    Member
    278
    0
    0
    Good job! Finally I'll be able to put more samples in...

    Quick question, though:

    Is there any way to remove it from the DAC list? Or I would need to remove the PCM itself from the ROM?
     
  8. Mairtrus

    Mairtrus

    Get a load of this!! Tech Member
    27
    0
    0
    Mendoza, Argentina
    Sonic Z. The Z DOESN'T means nothing.
    No really. It have now the index $90, but is hardcoded, so if you want to play the SEGA sound via the sound driver, you will need to add a new definition. But my attempt to do this was failed because the sound driver doesn't load correctly the weight of the sega pcm, so applying the Puto's fix, all work fine!!!
     
  9. Spanner

    Spanner

    The Tool Member
    Wow, I really shouldn't ask this question but does each dac*d.bin carry only one sample or what? I'm a bit confused with this anyway.
     
  10. Tweaker

    Tweaker

    Banned
    12,387
    2
    0
    Ideally, yes. Technically, you could put more than one sample in a single file, but it would be more or less pointless.
     
Thread Status:
Not open for further replies.