How to port Flamewing's driver to Sonic 1?

Discussion in 'Discussion and Q&A Archive' started by Stardust Gear, Jul 13, 2014.

Thread Status:
Not open for further replies.
  1. Stardust Gear

    Stardust Gear A Programmer Member

    Joined:
    Apr 27, 2014
    Messages:
    134
    I use Hg disassembly, but you can give me hivebrain code.

    I have the "songs-sfx.zip" but how to port?
     
  2. ThomasThePencil

    ThomasThePencil resident psycho Member

    Joined:
    Jan 29, 2013
    Messages:
    910
    Location:
    the united states. where else?
    I notice that you are asking for code. That's usually frowned upon around here, since it implies laziness and general unwillingness to put in effort...though those are probably the same thing. Yes, there are programs such as SonED2 and Xm3smps/oerg and all that cool stuff, but when you want to make major changes it comes down to a base need to be able to write and understand code. Study the driver and how it is implemented in S2, or better yet, look at SuperEgg's guide on porting the S2 driver to S1. Then work from there.

    Sorry, but I don't think anyone's going to be willing to assist you if you ask for everything to be done for you. Trust me; I've made the same mistake.
     
  3. Stardust Gear

    Stardust Gear A Programmer Member

    Joined:
    Apr 27, 2014
    Messages:
    134
    I don't need S2's one. I need S3&k's driver.

    Isn't there a readme in the zip?
     
  4. ThomasThePencil

    ThomasThePencil resident psycho Member

    Joined:
    Jan 29, 2013
    Messages:
    910
    Location:
    the united states. where else?
    *facepalm*

    Re-read what I posted.
     
  5. Cinossu

    Cinossu A blend of secret herbs and spices Member

    Joined:
    Aug 14, 2007
    Messages:
    282
    Location:
    London, UK
    I won't give you code, but I'll give you the general idea of what I did to do this. There are probably tons of better methods than this, but what the hell.

    The S3K and S1 disassemblies use different assemblers, meaning that just shoving code in and hoping it'll work is a terrible idea. Now, you can convert the entire Sonic 1 disassembly to work under AS instead, but that'd take forever. Converting the S3K-side of things to asm68k is a no-go, as the code you're dealing with here is z80; as the name implies, asm68k only compiles 68k. You could find another assembler, but again, what's the point.

    SO, as a workaround, I created a very, *very* shortened down version of the S3K disassembly. It only has the SndDrvInit function at the very beginning of a bank ($80000 is the size of a bank, for reference for later), the Kosinski decompressing functionality, and the Sound Driver itself.

    Essentially, my shortened S3K disassembly looks something like this:


    cpu 68000
    include "sonic3k.macrosetup.asm" ; include a few basic macros
    include "sonic3k.constants.asm" ; include a few basic macros
    include "sonic3k.macros.asm" ; include some simplifying macros and functions

    Size_of_Snd_driver_guess = $1580
    ; Approximate size of compressed sound driver. Change when appropriate
    ; ---------------------------------------------------------------------------

    StartOfROM:
    if * <> 0
    fatal "StartOfROM was ${*} but it should be 0"
    endif

    dc.b "PROGRAMMER HAS A NAP. HOLD OUT, PROGRAMMER! "
    org $80000
    SndDrvInit:
    nop
    move.w #$100,(Z80_bus_request).l
    move.w #$100,(Z80_reset).l ; release Z80 reset

    ... etc ...

    Kos_Decomp:
    subq.l #2,sp ; make space for two bytes on the stack
    move.b (a0)+,1(sp)
    move.b (a0)+,(sp)

    ... etc ...

    Z80_Snd_Driver: include "Sound/Z80 Sound Driver.asm"

    EndOfROM: org $180000
    nop
    END

    I make all the changes to this as I want it, then build the ROM. I then make use of split.exe to split out the chunk from 80000 to 180000 (or however big you need it), and this becomes a file like sound.bin in my Sonic 1 disassembly folder.

    From here, I delete all the S1 sound driver code, include sound.bin under the label SoundDriverLoad at the end of the ROM right after aligning the ROM to the exact size of 80000. This is important; if your ROM is bigger than 80000 already, you'll need to alter the code in the S3K-side to reflect this too. (It can probably be done without this align and take into consideration other things, but when I wrote this it was easiest to keep this whole thing bank-aligned entirely.)

    I remove the old code associated with this function (SoundDriverLoad), copy over the S3K PlaySound etc. functions, remove things like the UpdateMusic call from the Vertical Interrupt, etc.

    And boom. S3K sound driver (or flamewing's) in Sonic 1. It works.
     
  6. Crash

    Crash Well-Known Member Member

    Joined:
    Jul 15, 2010
    Messages:
    302
    Location:
    Australia
    Haha, I did it the other way around: use ASM68k to build a Sonic 1 rom with the sound driver removed, and the driver init routine decompressing whatever's at the End of Rom label to the z80. Then use AS to build the flamewing driver, only modification being bincluding the Sonic 1 rom at the very start of the file. You don't have to worry about it not aligning correctly that way.
     
  7. Cinossu

    Cinossu A blend of secret herbs and spices Member

    Joined:
    Aug 14, 2007
    Messages:
    282
    Location:
    London, UK
    Ha ha, that works too; I quite like my driver bank-aligned however, for other reasons.
     
  8. MainMemory

    MainMemory Well-Known Member Member

    Joined:
    Mar 29, 2011
    Messages:
    922
  9. Cinossu

    Cinossu A blend of secret herbs and spices Member

    Joined:
    Aug 14, 2007
    Messages:
    282
    Location:
    London, UK
    Actually, I made a branch of the disassembly on GitHub that uses AS not too long ago. And in fact, there's already an AS version of the 2005 disassembly. Sure, he'd have to redo anything he's already done, but it won't nearly take forever.




    Exaggeration, obviously. Still more effort than this person seems to be willing to put in, though.
     
  10. Varion Icaria

    Varion Icaria Well-Known Member Member

    Joined:
    Apr 26, 2012
    Messages:
    77
    You know a much easier way is to use AS to compile just the Sound Driver portion, and convert everything starting at the sound Index [the Second half of the SK driver] to use ASM68K. It's much more easier and you don't have to build a rom and tack the driver on at the end.. I might put up a guide for it soon I suppose to help everybody out once I'm done with my current project.
     
Thread Status:
Not open for further replies.