Z80 assembly in ASM68K

Discussion in 'Utilities' started by AURORA☆FIELDS, Aug 7, 2017.

  1. AURORA☆FIELDS

    AURORA☆FIELDS so uh yes Exiled

    Joined:
    Oct 7, 2011
    Messages:
    759
    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. Devon

    Devon I'm a loser, baby, so why don't you kill me? Member

    Joined:
    Aug 26, 2013
    Messages:
    1,376
    Location:
    your mom
    Now, this is awesome. This will be very helpful in the future.
     
  3. AkumaYin

    AkumaYin Well-Known Member Exiled

    Joined:
    Aug 21, 2014
    Messages:
    157
    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 Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, 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. AURORA☆FIELDS

    AURORA☆FIELDS so uh yes Exiled

    Joined:
    Oct 7, 2011
    Messages:
    759
    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. Devon

    Devon I'm a loser, baby, so why don't you kill me? Member

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

    ProjectFM Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, 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. AURORA☆FIELDS

    AURORA☆FIELDS so uh yes Exiled

    Joined:
    Oct 7, 2011
    Messages:
    759
    Just extend the MusicBanks and music pointers table at the end to have more entries.
     
    KCEXE and ProjectFM like this.
  9. ProjectFM

    ProjectFM Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, 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
  10. AURORA☆FIELDS

    AURORA☆FIELDS so uh yes Exiled

    Joined:
    Oct 7, 2011
    Messages:
    759
    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.
  11. ProjectFM

    ProjectFM Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, Maine
    Thank you so much for the sound effects.

    I set the bank using the equate value at the beginning. The problem I have seems to be that the wrong bank is being pointed to for sound effects and the SEGA PCM.

    From studying a list file from a Sonic 3K disassembly, the bank numbers chosen seem odd. The first music bank which is shared with DAC is $1D, second is $57, third is $58, and the one shared between the SEGA PCM and sound effects is $1F. The test driver, on the other hand, puts driver numbers one after another for music, meaning that if I set $1D as the default bank, then the next two banks will be $1E and then $1F. Logically,I wonder if this is relevant to my problem or if these numbers mean nothing as long as no banks share a number. I guess I'll keep digging through the list file.

    Edit: I fixed it. It was relevant in that it made me realize that the sound bank must be at $20. Also, for some reason if you set the default music bank to 0, 3 won't for as a sound bank.
     
  12. AURORA☆FIELDS

    AURORA☆FIELDS so uh yes Exiled

    Joined:
    Oct 7, 2011
    Messages:
    759
    The music bank is relevant to the position in ROM the data appears at. Specifically, its the address/$8000. Some of the Music/DAC is from the Sonic 3 ROM, which is why the bank numbers are so high. As far as the driver itself, the bank number does not matter, as long as it actually is correct.
     
    ProjectFM likes this.
  13. Nat The Porcupine

    Nat The Porcupine Point & Click Funny Man Member

    Joined:
    Jun 23, 2017
    Messages:
    71
    Location:
    Pennsyltucky
    How did I forget to thank you for these? Seriously, I can't express my gratitude enough; this is so much better than having to put up with AS. Truth be told, if there was a set of ASM68K macros that gave SH-2 asm the same treatment, I'd be able to confidently ditch the AS macro assembler for good.
     
  14. Clownacy

    Clownacy Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,020
    The download link for this appears to be dead. Does anyone have a copy that they can share?
     
  15. AsuharaMoon

    AsuharaMoon kakyoin did you lay this egg Member

    Joined:
    Aug 15, 2013
    Messages:
    67
    There you go!
     

    Attached Files:

    ProjectFM and Clownacy like this.
  16. Clownacy

    Clownacy Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,020
    Awesome, thanks a lot.
     
    AsuharaMoon likes this.