mz80 -- a native MACRO-80 compatible assembler for the Z80 and Z180
===================================================================

mz80 assembles Z80 and Z180 source written in Microsoft MACRO-80 syntax and
writes a LINK-80 compatible .rel object file, an ASCII listing, and a LaTeX
listing fragment fit to drop into a book.

It exists so that the TurboDOS reconstruction can be built without an
emulator.  Until now every assembly ran M80.COM under tnylpo; the point of
this program is that anywhere one would have done that, one can run mz80
instead.


What it does

    - The full MACRO-80 language: macros, REPT/IRP/IRPC, conditionals,
      LOCAL, the special macro operators (& ;; ! % NUL), INCLUDE, .PHASE,
      .RADIX, the listing controls, and the whole expression grammar with
      MACRO-80's relocation-mode rules.
    - The complete Z80 instruction set, and the Z180 additions under .Z180
      or -c z180.
    - Correct REL output, including external chains, COMMON blocks and
      entry points.
    - Errors reported with MACRO-80's own one-character codes.

What it does not do

    - 8080 mode.  .8080 and the 8080 mnemonics are diagnosed, not
      assembled.  The reconstruction corpus is .Z80 throughout.


Building and installing

    make ; sudo make install

There is no configure script.  The REL encoder is compiled from ../tools so
that mz80, relmap, relcmp, relir and the loader all encode from one item
table; point RELDIR elsewhere if that tree is not beside this one.


Documentation

    mz80.1                 the manual page
    mz80_manual.pdf        a 49-page manual, built by "make manual"

The manual is deliberately self-contained: it describes the whole assembly
language, so a reader who has never seen Microsoft's MACRO-80 manual -- which
is out of print and wrong in eight places -- can write, assemble and link a
Z80 program from it alone.  It has worked examples and an index.


Testing

    make test

Four groups run, in increasing order of what they prove.

  1. Unit tests, for the corner cases no real source reaches: every radix
     notation, the operator precedence table, the relocation-mode arithmetic,
     symbol table growth, and malformed inputs that must be RECOGNISED.

  2. Golden encodings, for instruction forms the corpus does not use -- 45
     Z80 forms checked against MACRO-80, and every Z180 instruction checked
     against Zilog's definition, since MACRO-80 does not know them.

  3. The corpus comparison: all 193 TurboDOS modules assembled by mz80 and by
     the real MACRO-80 3.44, compared item for item, and their listings
     compared line for line.

  4. The end-to-end link: 49 modules assembled by mz80, linked by the original
     GEN, and the system image compared with one built from the manufacturer's
     own relocatables.

As of 2026-09-01:

    objects   identical=191  differs=2   mz80-failed=0
    listings  identical=193  differs=0
    link      PASS: linked images are IDENTICAL (22272 bytes)

The two differing objects are LCLUSR and SYSNIT, the two modules MACRO-80 3.44
is known to get wrong (findings F31 and F50: a chain head attributed to the
wrong COMMON block, and a select-common item with a corrupt block name).  mz80
emits the correct encoding for both -- and the link test, which never repairs
anything, is the evidence that the corrections are right rather than merely
different.  The one differing listing is a page-break inconsistency in 3.44
itself.  SPEC.md sets out all of it.

Everything above runs on both Linux (gcc, glibc) and FreeBSD (clang, LLD),
with no warnings under the full house warning set, clean under
AddressSanitizer and UndefinedBehaviorSanitizer, and the object files and
listings the two platforms produce are byte for byte identical.


Files

    mz80.h      the one header: the assembly state and every interface
    main.c      the command line and the two-pass driver
    asm.c       statement dispatch, pseudo-ops, conditionals, macros
    src.c       the source stack: files, INCLUDE, macro and repeat expansion
    lex.c       the tokeniser
    expr.c      the expression evaluator, with the relocation-mode rules
    enc.c       the Z80 and Z180 instruction encoder
    emit.c      location counters and the REL item stream
    sym.c       the symbol and COMMON block tables
    list.c      the ASCII listing
    tex.c       the LaTeX listing fragment
    util.c      allocation, string helpers, the one diagnostic path

    SPEC.md          what the program must do and where every rule comes
                     from, including everything measured from MACRO-80 3.44
                     that the manual does not say
    mz80.1           the manual page
    mz80_manual.tex  the manual
    tests/           the test suite


Licence

BSD 2-Clause, matching the rest of the reconstruction tree; see the
head of any source file.
