REL_tools 1.2 -- Microsoft REL object tools in portable C
=========================================================

A library and seven programs for the Microsoft REL object format: the
format that MACRO-80, LINK-80 and LIB-80 used on CP/M, and that a
surprising amount of 8080 and Z80 software still exists only in.

    librel      the format: read it, write it, link it
    mz80        an assembler, MACRO-80 3.44 compatible, Z80 and Z180
    mlink       a linker, LINK-80 3.44 compatible
    mlib        a librarian, LIB-80 compatible

and four programs for looking at what you have:

    relmap      every link item in a file, with its bit offset
    relir       what those items mean: modules, segments, symbols
    relcmp      the first item at which two files differ
    relfix      repair MACRO-80 3.44's COMMON-block attribution

The point of the package is to make an emulator unnecessary.  Anywhere
you would have reached for a CP/M emulator and M80.COM or L80.COM, these
run natively instead -- and produce the same bytes.


Why you might want it
---------------------

REL is a bit stream.  Nothing in it is byte-aligned: a two-bit tag, a
sixteen-bit value and a three-bit length all sit wherever the previous
field left off.  That is why so few tools read it, and why the ones that
do tend to be wrong in the corners -- external reference chains, COMMON
block attribution, the relocation base of a partially-evaluated
expression.

This package was written against a real workload, the TurboDOS 1.43
reconstruction: 193 modules, about 130,000 lines of production Z80.
Every one of them is assembled by both mz80 and the original MACRO-80
and the objects compared item by item, the listings line by line, and
the whole system linked from mz80's output and compared with the
manufacturer's shipped image.


What it measures against the originals
--------------------------------------

    objects    identical=191  differs=2   failures=0
    listings   identical=193  differs=0
    link       images IDENTICAL (22272 bytes), without relfix
    mlink      8 of 8 link configurations byte-identical to LINK-80

The two differing objects are LCLUSR and SYSNIT, the two modules
MACRO-80 3.44 gets wrong: a chain head attributed to the wrong COMMON
block, and a select-common item carrying a corrupt block name.  mz80
emits the correct encoding for both.  The end-to-end link is the
evidence that this is a correction and not merely a difference -- it
repairs nothing, and the image still comes out identical.

Ten places were found where MACRO-80 3.44 contradicts its own manual.
They are listed, with the measurement behind each, in mz80/SPEC.md and
in the manual.


Building
--------

    make ; sudo make install

No configure script.  Builds with gcc 13 on Linux and clang 19 on
FreeBSD, -std=c2x, warning-free.  PREFIX, DESTDIR, CC and CFLAGS are
honoured.  Other targets:

    make test           the full suite
    make sanitize-test  the suite under ASan and UBSan
    make manual         REL_tools_manual.pdf (needs pdflatex)
    make dist           the release tarball

The comparisons against MACRO-80 and LINK-80 need the originals and a
CP/M emulator, and are skipped with a note when they are not present.
Everything else runs anywhere.

For TurboDOS specifically -- linking a system with GEN, disassembling its
modules, stamping distribution serials -- see the companion package
turbotools, which builds against this one.


Documentation
-------------

    REL_tools_manual.pdf    the manual, in six parts: the object format,
                            librel, mz80, mlink, mlib, the utilities
    man pages               librel(3), mz80(1), mlink(1), mlib(1),
                            relmap(1), relir(1), relcmp(1), relfix(1)
    mz80/SPEC.md            the assembler's specification, including
                            every measured divergence from the manual

The manual's first part documents the REL format itself -- the bit
stream, all sixteen link items, the segment model, external chains and
library format.  It is written to be read on its own by anyone who has
to deal with the format, whether or not they use this code.


Licence
-------

Two-clause BSD.  Copyright 2026 Robert Cousins.

Robert Cousins <rec@rcousins.com>
https://rcousins.com/pub/
