don't click here

Yes I do believe I'm right this time

Discussion in 'Engineering & Reverse Engineering' started by fuzzbuzz, Nov 28, 2005.

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

    fuzzbuzz

    Tech Member
    625
    0
    0
    Here
    Many Many Programming/hacking tools...
    Okay, so I'm in need of a couple things, so I'd appreciate anyone who can and is willing to help me out.

    First of all, I just this morning, started to restart disassembling Sonic 1 Z80 driver, which handles the DAC drum samples. After 3 or 4 breakthroughs, I've got pretty much the whole driver commented and the sample header and format figured out, except one key element. SEGA basically developed their own way of doing sample rates using a certain number of 'nops' in between each byte of data sent to dac. This certain number of nops has something to do with the speed of the Z80. I've found the byte that defines the sample rate of the SEGA Sound, which will help me to calculate the others, and perhaps even write a convertor, but the problem is, I'm either blind or retarded, I can't find what the accepted sample rate of the SEGA sound is. It's something I never payed attention to, and I never needed it. I looked across several hacking sites, and couldn't find it. So, um, help plz. thx


    Secondly, I need a host to put all of this information up, so people can actually use it. I'd like to write a detailed guide of how the S1 Z80 driver works.


    Thirdly, This one is for StephenUK. While looking for the sample rate of the sega sound, I came across a problem in your definition of the DAC drum notes in your Sonic music hacking guide....I think it was my fault, because I seem to recall spreading the notes to several people, but I could be wrong.

    Code (Text):
    1. Sonic 1:
    2.  
    3. 81: Kick
    4. 82: Snare
    5. 83: Timpani
    6. 84: Noise; do not exist
    7. 85: Noise; do not exist
    8. 86: Silent; do not exist
    9. 87 or higher: Sega sound
    84-86 do not exist....when you're trying to play them, you're getting random pointers from the data of the Kick sample. The driver allows up to 86 being a playable drum note, but there are only 3 samples. The rest is correct.
     
  2. Ultima

    Ultima

    Games Publisher Tech Member
    2,398
    1
    18
    London, England
    Publishing mobile games!
  3. LocalH

    LocalH

    roxoring your soxors Tech Member
    Well, you could simply mod an emulator to keep track of how many DAC sample writes are done in one second - this would essentially be the sample rate. I wouldn't hack the driver itself to do so, because the simple act of adding instructions to keep track of DAC writes would change the way the DAC sounds, by inserting more instructions to the loop, since the DAC is software-timed.

    Or, you could do it mathematically - take the total number of t-states per second, figure out how many NOPs you have in the routine in one second, multiply that number by 4 (since a NOP is 4 t-states), calculate how many t-states it takes for one DAC write (including reading the data from ROM), and divide that value into the t-states left over after taking away the NOPs. That value might not be 100% accurate, but it'd likely be close enough to work, or at least give you a starting point to work from.
     
  4. StephenUK

    StephenUK

    Liquor in the front, poker in the rear Tech Member
    1,678
    0
    16
    Manchester, UK
    Quackshot Disassembly
    If you're referring to the one on the community hacking guide, it was actually written by Tweaker, so you'd be better off talking to him about it. I can update the guide as necessary though.
     
  5. fuzzbuzz

    fuzzbuzz

    Tech Member
    625
    0
    0
    Here
    Many Many Programming/hacking tools...
    Yeah, I gave those notes to Tweaker. I knew it was my fault. :P


    And localH, that's what I was going to do (the math one), I was just hoping to get the sample rate of the SEGA sound so I could have something to check my work up against.
     
  6. SGR

    SGR

    Give me the gams. Member
    Hopefully I am right. 16000, mono, 8-bit unsigned.
     
  7. Tweaker

    Tweaker

    Banned
    12,387
    2
    0
    Thanks -- I'll be sure to update my guide now.

    BTW, 88 and higher is variations of Timpani. I forget where it goes up to... I think about 8B. Then some distorted Timpani, and then more Sega goodness.
     
  8. Aurochs

    Aurochs

    Единый, могучий Советский Союз! Tech Member
    2,343
    0
    0
    Whatever catches my fancy
    Woah woah woah, you disassembled and commented the S1 Z80 code in a single day? I've been working on S2's Z80 code for about a month, and the only major breakthrough I've made is figuring out where the decompressed song data goes.

    ...

    Maybe I should just pass the torch to somebody with more time...
     
  9. Tweaker

    Tweaker

    Banned
    12,387
    2
    0
    Bahaha, I figured that out while browsing a savestate on ACCIDENT. :P

    Savestates are your friend when you disassemble Z80 stuff. Especially compressed Z80 stuff. Keep that in mind.
     
  10. Aurochs

    Aurochs

    Единый, могучий Советский Союз! Tech Member
    2,343
    0
    0
    Whatever catches my fancy
    Well, that's how I figured it out too. I dumped the Z80 RAM and hunted for the decompressed data. Took me two weeks to realize that I could do that. =(
     
  11. fuzzbuzz

    fuzzbuzz

    Tech Member
    625
    0
    0
    Here
    Many Many Programming/hacking tools...
    Code (Text):
    1. sub     81h            ; Subtract #$81 from A (note value)
    2. ld      (hl), a        ; Put A into $1FFF (queued note RAM location)
    3. cp      6              ; If A >= 6
    4. jr      nc, PlaySegaSound; Branch to this location
    Um, are you sure you're talking about Sonic 1? I tested this, and when you replace a DAC value in GHZ with 86, it plays the SEGA sound for the bass drum....kinda funny :P


    Z80 sonic 1 driver is less than 100 lines long cause it just loads dac data. The rest is the actual sample data. That's how I did it. :P And I'm not that interested in Sonic 2 right now.

    You've prolly figured out how ugly Z80 code is now, too, huh? :D
     
  12. Varion Icaria

    Varion Icaria

    He's waiting.... Tech Member
    1,019
    11
    18
    S4: Cybernetic Outbreak
    That's in S2. :P
     
  13. Tweaker

    Tweaker

    Banned
    12,387
    2
    0
    I'm positive. I speak mainly of the values inside the music, not the actual pointer values.

    Case and point, Sonic 2 has 7 sample values.

    81 - Kick
    82 - Snare
    83 - Clap
    84 - Scratch
    85 - Timpani
    86 - Tom
    87 - Bongo

    These are the sample arrangements, according to sample value. Now, below 87 (the last sample) are the manipulated samples. This is for use in music data itself.

    DAC has a master playlist of sorts. It has the sample value (81-87) and then the pitch for it to be played at. Typically, the first 7 samples are the original samples, untouched. Afterwards is different pitched samples for Toms and Timpanis... etc.

    I figure S1 has something similar to this. So I believe you're right in saying that there are 4 samples -- Kick, Snare, Timpani and Sega. But I'm saying at 88, manipulated samples start. This leads me to believe that Sonic 1 was designed with 7 samples in mind, but was then cut down. Something similar to S2, perhaps?
     
  14. fuzzbuzz

    fuzzbuzz

    Tech Member
    625
    0
    0
    Here
    Many Many Programming/hacking tools...
    well, regardless if it was designed with more than 4 samples in mind, the Z80 code I posted prevents anything at 87 or higher from being anything but the SEGA sound.
     
Thread Status:
Not open for further replies.