don't click here

Sonic 1 Z80 Driver disassembly

Discussion in 'Engineering & Reverse Engineering' started by Puto, Sep 22, 2007.

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

    Puto

    Shin'ichi Kudō, detective. Tech Member
    2,013
    0
    16
    Portugal, Oeiras
    Part of Team Megamix, but haven't done any actual work in ages.
    In case anyone actually has a use for this, here's a disassembly of the Z80 portion of the Sonic 1 sound driver (the part that handles the DAC; it's really small anyway). Have fun.
     
  2. Varion Icaria

    Varion Icaria

    He's waiting.... Tech Member
    1,019
    11
    18
    S4: Cybernetic Outbreak
    Awesome this could come in handy, Great Job!
     
  3. drx

    drx

    mfw Researcher
    2,254
    350
    63
    :rolleyes:
    Awesome job, but there is a possibly huge error in the disassembly:

    Code (Text):
    1.     ld  a,1; a=1
    2.     ld  (ROM_Bank),a; 6000h=1
    3.     ld  b,SEGA_Bank_Minor; b=8
    4.     ld  a,SEGA_Bank; a=7
    5.    
    6. Z80_Init_Loop: 
    7.     ld  (ROM_Bank),a; 6000h=a (This sets the memory portion of the main genesis ROM that the Z80
    8.             ; will be allowed access to. To move the SEGA sound, change the "7" above this
    9.             ; to the new bank where it is located)
    10.     rrca    ; rotate right circular register a (whatever the fuck that means, I think it
    11.         ; shifts right anyway)
    12.     djnz    Z80_Init_Loop; decrement and loop if not zero
    13.     jr  Load_Sample; branch to Load_Sample
    First of all, SEGA_Bank_Minor (default value 8) isn't what you think it is. I'll explain in a sec.

    Z80 banking works by writing the first 9 bits of the 24-bit address to 6000h, starting with the 15th bit, ending with the 23rd bit (the last one). Now, this:

    Code (Text):
    1. ld  a,1; a=1
    2.     ld  (ROM_Bank),a; 6000h=1
    Takes care of the 15th bit, the part which specifies whether the bank is at xx0000 or xx8000. So if you want to change that, you have to change a in the code above to 0.

    Now, there are 8 bits left to write, which is done by the loop below (Z80_Init_Loop). Like I said before, SEGA_Bank_Minor has a different function - it serves as a loop counter. So 8 basically means the loop will be executed 8 times (for 8 consecutive bits) - DJNZ means decrement B and jump relative if B=0.

    Also, all the 8 bits are stored in the SEGA_Bank variable, so you can set that to whatever value you want and it will work.

    You probably wouldn't notice this error, but as I was working with bigger addresses ($900000+), I encoutered this.
     
  4. drx

    drx

    mfw Researcher
    2,254
    350
    63
    :rolleyes:
    Important info!

    After having a huge problem with the Sega sound, I've discovered something somewhat appaling =P

    Code (Text):
    1.     ld  de,SEGA_Location; Load the location of the SEGA sound (80h-based relative pointer to $78000 in the main ROM) to address de.
    actually needs to be:

    Code (Text):
    1.     ld  de,(SEGA_Location|$8000)
    If you're messing with $xx0000 banks, you need to do this to your PCM location. This is because the Z80 can only access 68k memory through addresses $8000-$FFFF and the Z80 code in Sonic 1 is not smart enough to add that (it probably was included in the original declaring macro though).

    So yea. Also, if you're planning on heavily relocating PCM data, I'd suggest placing the PCM in 1 bank, for obvious reasons. Unless you feel like changing the code or something.
     
Thread Status:
Not open for further replies.