Z80 assembly in ASM68K

Discussion in 'Utilities' started by Natsumi, Aug 7, 2017.

  1. Natsumi

    Natsumi Markey's Member

    Joined:
    Oct 7, 2011
    Messages:
    508
    Location:
    Otter's lap
    So, I always hear AS fanboys say AS is, in fact, superior to ASM68K because AS actually assembles Z80 instructions. After having had to use AS for quite a few weeks, I just got so tired of its broken ass bullshit, that I wanted to do something about this. That, and I wanted to learn more about Z80 in general. I had intended to do that for years, but it seemed so foreign to me. Because of that, I created a set of macros for ASM68K to 100% accurately assemble Z80 code. Oh, and you may think its slow? Hah, what a joke! The worst I had any sound driver assemble, is... Half a second. And that is, S3K's sound driver, with all the DAC and some music and such. That's right, my macro set actually assembles Z80 code faster than AS does natively. So much for ASM68K's macro language having "poor set of features and a lot of restrictions", huh?

    So, banter aside, what does it actually do? Well;
    • It assembles Z80 code, including undocumented instructions,
    • It is lightweight and super fast,
    • Checks that offsets in instructions like jr and djnz, and ix/iy+ offsets are signed,
    • You can actually use Z80-style numbers (like 0F0h is completely OK),
    • properly detects the difference between immediate and address,
    • Is just super badass,
    • Works with any Z80 code (with slight modifications, see readme.txt),
    • The whole macro set is just 35KB,
    • And I will throw a Sublime Text 3 syntax highlighter in just because I can.
    • Oh, did I mention its super fast? You can assemble actual games comfortably under a second! Holy fucking shit!!!
    Ok so, the readme will have any specifics on the limitations what this brings. Afterall, its not a perfect creation, native support would always be ideal, but it still works great for what it is. I've tested a fair few things with this, including: Dual PCM, MegaPCM, Sonic 1 DAC driver, S&K sound driver, GEMS (with few changes, noted in the source), Westone sound driver, and Terpsichorean. All work 100% and I have been able to produce bit-perfect.

    That sounds great?!

    But, how do you install it? Why simply, put in LANG.ASM in the root of your disassembly (or wherever you'd wish to), and include it in. Or alternatively, make a separate build process for the driver specifically, if you wish to. Whatever is the case, any Z80 code that relies on pointers or relative jumps, should be placed between 2 z80prog macros, where the first one will specify the Z80 RAM location code is ran at. Typically, for drivers this is 0, and for anything using bank, it will be $8000+. Then just write your z80 code, with the limitations laid out in the readme. If you want examples, just check out the folders. So, what are we waiting for? The download, of course. If you find any bugs, report them to me, and I'll give in some effort to fix them up.

    Of course, here are the people who helped me with this project:
    • MarkeyJester for some help with Z80 instructions,
    • Vladikcomper for providing me with MegaPCM and Terpsichorean,
    • ValleyBell for prior help with S&K sound driver and some misc Z80 questions I threw at his way,
    • And of course SN Systems who made ASM68K, clearly the best and most powerful 68000 assembler.
     
  2. Novedicus

    Novedicus Does your mother know where you are? Member

    Joined:
    Aug 26, 2013
    Messages:
    662
    Location:
    Hell
    Now, this is awesome. This will be very helpful in the future.
     
    Natsumi likes this.
  3. Aquatari

    Aquatari High and broken Member

    Joined:
    Aug 21, 2014
    Messages:
    49
    Location:
    Spectra Valley
    I can finally stop configuring the build script to pre-compile z80 code with AS to be binclude'd into the main file, heh. Excellent work. I'll go shove this into my disassembly now...
     
  4. ProjectFM

    ProjectFM Jack of all trades; master in training Member

    Joined:
    Oct 4, 2014
    Messages:
    610
    Location:
    Portland, Maine
    I'm trying to add the Sonic & Knuckles sound driver included here to replace the Sonic & Knuckles sound driver in my hack so I can make use of SMPS2ASM to make modifying the music and sound effects easier. I've been getting the error "Attempt to seek before start of file" on the line in the sound driver pointing to the music files (3100 in smps.asm) and moving the file positions closer to the pointers results in the error appearing somewhere else.

    Also, I'd like to know if the sound driver is missing anything that would make it pointless to add it to my hack.
     
  5. Natsumi

    Natsumi Markey's Member

    Joined:
    Oct 7, 2011
    Messages:
    508
    Location:
    Otter's lap
    You forgot to add 'org 0' at the first line of the asm file responsible for building the driver (cant have any code before that org).
     
    ProjectFM likes this.
  6. Novedicus

    Novedicus Does your mother know where you are? Member

    Joined:
    Aug 26, 2013
    Messages:
    662
    Location:
    Hell
    Make sure to read the README file for any information you may need to know...
     
  7. ProjectFM

    ProjectFM Jack of all trades; master in training Member

    Joined:
    Oct 4, 2014
    Messages:
    610
    Location:
    Portland, Maine
    Thanks, Natsumi. I read through the file a few days ago and forgot about that one. That should've been the first place to check.

    Things are working pretty well. How do you allow the sound driver to read more than two songs?
     
  8. Natsumi

    Natsumi Markey's Member

    Joined:
    Oct 7, 2011
    Messages:
    508
    Location:
    Otter's lap
    Just extend the MusicBanks and music pointers table at the end to have more entries.
     
    KCEXE and ProjectFM like this.
  9. ProjectFM

    ProjectFM Jack of all trades; master in training Member

    Joined:
    Oct 4, 2014
    Messages:
    610
    Location:
    Portland, Maine
    So the music is working fine but the sound effects and the SEGA PCM are giving me trouble. I understand that, unlike the music, you don't need to tell it which bank each individual sound effect is using because they all use the sound bank you set for them (in my case $03). I also understand that you put the pointers in SFXPointers instead of MusicPointers. Are there any other differences between the music and sound effects that I need to take into account? One thing to note is that sound effects and the SEGA PCM share a bank like in Sonic 3K.

    Edit: If anyone could send me Sonic 3K's sound effects converted using Natsumi's version of SMPS2ASM, that would be very helpful. There are just so many that it would be time consuming to convert them all.
     
    Last edited: Aug 18, 2017 at 8:51 PM
  10. Natsumi

    Natsumi Markey's Member

    Joined:
    Oct 7, 2011
    Messages:
    508
    Location:
    Otter's lap
    You need to also set a proper bank for the SFX. In the test driver, it is set as an equate, but if you want to figure it out dynamically, you need to set it much like music and dac banks. Here is the converted sfx tho:
     

    Attached Files:

    ProjectFM likes this.