Assemblers for the Megadrive/Genesis

Discussion in 'Technical Discussion' started by FraGag, May 4, 2008.

  1. FraGag


    Tech Member
    Currently, the Disassemblies use at least three differents assemblers:
    - SNASM68k
    - ASM68K
    - The macro assembler AS

    SNASM68k, according to what I've read, was an assembler used to build official games. However, there seems to have been many complaints against it.

    ASM68K is only used for the Sonic 1 disassembly as of now. I've tried to search for some information on Google about this one, but I couldn't find anything relevant. Does someone have documentation on this assembler? I'd like to know what I can do with it, as I'm using it for my Sonic 1 "hack".

    AS is great, but there seems to be a few problems with the Sonic 1 disassembly (after replacing incbin's with binclude's and splitting dc's with more than 20 arguments - I could use some help if I'd ever like to do things ASM68K can't do). Also, it seems to be a bit slow with Sonic 2, compared to ASM68K with Sonic 1.

    tl;dr: what's the "best" assembler for Megadrive/Genesis games?
  2. I'd say AS. It's reasonably fast, it has excellent macro and function capabilities (see Xeno's disassembly), it can handle Z80 code as well as 68000 (once again see Xeno's disassembly), and loads of other goodies like nameless temporary symbols, sharefiles, etc. It's not as fast as ASM68k and lacks the optimization features, but in other areas it's far superior.

    I don't think SNASM68k was used to build Sonic games, I think it was ASM68k (though it beats me why Sega turned zero-offset optimization off while building). The site containing ASM68k documentation is down I believe, but you can download the PSY-Q systems manual (which includes info on ASM68k) here.

    About the problems you're encountering, I'm guessing it's because AS only allows double quotes for strings, while Hive's S1 disassembly uses single quotes for strings. Swapping them around shouldn't be too hard though.
  3. Spanner


    The Tool Member
    United Kingdom
    Sonic Hacking Contest
    Regarding AS, puto "padded off to the very beginning of the code" for it to work on S1 though I find ASM68K to be faster.
    There's plenty of bother in AS such as annoying errors, ASM68K is a great replacement for SNASM68K, which only requires a macro & one line fix.
    I don't know, since I haven't tried doing it on an earlier SNASM68K-based S2 assembly but I mostly prefer ASM68K.
  4. SMTP


    Tech Member
    I use ASM68K in my Sonic 2 hack.. :P
  5. FraGag


    Tech Member
    I did replace the quotes. The kind of errors that annoyed me were "addressing mode not allowed here" and "addressing mode not allowed on 68000" (both errors appeared for one line, but they appeared more than once).
  6. Dracula


    I'm watching you!
    Converting NES Mappers to MMC5
    I use - The macro assembler AS for my Sonic 2 Hack and I use ASM68K for S3k.
  7. Which are caused by coding errors. Assemblers don't cause errors by themselves, but they'll obviously complain if they're asked to assemble code containing errors.

    Sounds either like an error caused by another error or an alignment issue. You did replace all instances of even with align 2 right? Are those errors the first errors which appear, or are there others before them?
  8. drx


    mfw Researcher
  9. FraGag


    Tech Member
    Code (Text):
    1. > > >obj89.asm(9): error: addressing mode not allowed on 68000
    2. > > >          jmp   Obj89_Index(pc,d1.w)
    3. > > >obj89.asm(9): error: addressing mode not allowed here
    4. > > >          jmp   Obj89_Index(pc,d1.w)
    5. > > >obj8B.asm(8): error: addressing mode not allowed on 68000
    6. > > >          move.w  Obj8B_Index(pc,d0.w),d1
    7. > > >obj8B.asm(8): error: addressing mode not allowed here
    8. > > >          move.w  Obj8B_Index(pc,d0.w),d1
    9. > > >obj8B.asm(9): error: addressing mode not allowed on 68000
    10. > > >          jsr   Obj8B_Index(pc,d1.w)
    11. > > >obj8B.asm(9): error: addressing mode not allowed here
    12. > > >          jsr   Obj8B_Index(pc,d1.w)
    13. > > >obj8C.asm(8): error: addressing mode not allowed on 68000
    14. > > >          move.w  Obj8C_Index(pc,d0.w),d1
    15. > > >obj8C.asm(8): error: addressing mode not allowed here
    16. > > >          move.w  Obj8C_Index(pc,d0.w),d1
    17. > > >obj8C.asm(9): error: addressing mode not allowed on 68000
    18. > > >          jsr   Obj8C_Index(pc,d1.w)
    19. > > >obj8C.asm(9): error: addressing mode not allowed here
    20. > > >          jsr   Obj8C_Index(pc,d1.w)
    21. > > >sonic1.asm(6165): error: addressing mode not allowed on 68000
    22. > > >          move.w  BgScroll_Index(pc,d2.w),d2
    23. > > >sonic1.asm(6165): error: addressing mode not allowed here
    24. > > >          move.w  BgScroll_Index(pc,d2.w),d2
    25. > > >sonic1.asm(6166): error: addressing mode not allowed on 68000
    26. > > >          jmp   BgScroll_Index(pc,d2.w)
    27. > > >sonic1.asm(6166): error: addressing mode not allowed here
    28. > > >          jmp   BgScroll_Index(pc,d2.w)
    29. > > >obj15_1.asm(5): error: addressing mode not allowed on 68000
    30. > > >          jmp   Obj15_Index(pc,d1.w)
    31. > > >obj15_1.asm(5): error: addressing mode not allowed here
    32. > > >          jmp   Obj15_Index(pc,d1.w)
    Other objects don't cause this error... BTW, I've split objects in separate ASM files.
  10. Spanner


    The Tool Member
    United Kingdom
    Sonic Hacking Contest
    Those damn (pc,d1.w) errors, I hate them, that's what I'm experiencing too.
  11. FraGag


    Tech Member
    Well, I guess I'll stick to ASM68K, it seems to be the best choice so far. Also, thanks for the docs, shobiz.
  12. Hmm, have you added "padding off" to the beginning of the file? If you haven't, that could be a cause of the errors. I can't think of any other reason right now. Hayate mentioned a while back he got his Sonic 1 disassembly working perfectly with AS, perhaps you could ask him what changes he had to make?
  13. FraGag


    Tech Member
    I literally copied s2.macrosetup.asm, so yes, padding was off.
  14. Figured it out. The problem is stuff like jmp somewhere, which is supposed to be jmp (somewhere).l. Aurochs mentioned a while back things like that could cause AS to throw errors during the second pass. It's a simple regular expression search and replace fix though.

    In case anyone else is interested, I've uploaded the AS version to the wiki, at Changes are listed in the modified README.txt, and it assembles to a bit-perfect copy of the original, since the AS executable included is one with the zero-offset displacement optimization disabled thanks to SHB's instructions.
  15. Puto


    Shin'ichi Kudō, detective. Tech Member
    Portugal, Oeiras
    Part of Team Megamix, but haven't done any actual work in ages.
    I still believe that, besides the fact that it can prove that the disassembly is done right, there's no real point to disabling optimizations.
  16. I agree, but in this case I was using the modified version to ensure my changes didn't screw anything up, and for some reason didn't consider the possibility of switching back to a normal AS executable once I had checked that. It's quite easy to use search-and-replace to get rid of all 0-offset displacements though, so I think I'll just leave it as it is.
  17. FraGag


    Tech Member
    Good catch! I'd probably have figured it out if I actually compared the good ones with the erroneous ones. I'll consider this if I ever want to use AS. Thanks!