REL_tools 1.5 -- 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.


What changed in 1.5
-------------------

A bug-fix release.  All four came out of building a new TurboDOS system,
tdosbox, with these tools: a workload the 193-module corpus does not
cover, because no shipped module does any of these things.

librel, and so mlink and GEN: a word in one COMMON block that names a
label in another was deposited into the OTHER block, with no error.
LINK-80 keeps two things apart that the loader had kept in one
variable: the block a COMMON-relative word is relative to, which
select-common changes, and the block bytes are deposited into, which
moves only on set-location.  MACRO-80 relies on the distinction -- it
selects the other block for the word and goes straight on depositing
in this one.  mlink/tests/run.sh has the case; every TurboDOS image
relinks byte-identically.

mz80: an undefined name in an instruction operand is now the U error
that MACRO-80 reports.  1.2 checked only DB and DW; IN, OUT, LD A,n,
LD HL,nn, JR and (IX+d) assembled a missing name as zero and said
nothing, and JR assembled a jump to 0000H.  The listing's symbol table
had marked the name U all along, which is how it was found.

mz80: .PHASE inside a named COMMON block put every phased byte at
offset 0 of the block; the location items read the wrong counter.

mz80: after a word naming a label in another COMMON block, 1.2
reselected the current block and re-set the location, two items 3.44
does not emit.  It no longer does, and the object is item-for-item
MACRO-80's.  Both of these are in mz80/tests with 3.44's own output as
the golden.

The Makefiles: every object now depends on a stamp named for the
compiler's target, so a native make in a tree last built for another
CPU rebuilds everything instead of mixing two architectures in one
archive.  That is how the first bug was nearly missed.


What changed in 1.3
-------------------

mz80 grows -I, an INCLUDE search path:

    mz80 -I ../inc -o FILMGR.rel os/FILMGR.Z80

The name as written is still tried first, in all three spellings, so an
assembly with no -I behaves exactly as it did in 1.2.  CP/M had no
directories, so MACRO-80 had no search path and needed none; this exists
for a source tree that keeps its include files in one directory and its
modules in several.  Nothing else changed.


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.  It is also built and tested on 64-bit RISC-V -- see Platforms
below.  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.


Platforms
---------

Built and tested on three architectures:

    x86-64 Linux     gcc 13, glibc
    x86-64 FreeBSD   clang 19, LLD
    riscv64 Linux    gcc 13, cross-compiled and run under qemu-user, and
                     again with a native riscv64 gcc in a container

The suite passes on all three.  The point of the third is that RISC-V
makes plain char UNSIGNED, which x86 does not on either operating
system: a byte held in a bare char and tested against a negative
sentinel behaves differently there, and a bit-stream codec is exactly
the kind of code that gets that wrong.  It does not, and the evidence is
stronger than a passing suite -- the 199 objects of the TurboDOS
reconstruction assemble to the same bytes on riscv64 as on x86-64, and
the system linked from them is identical, all 22,272 of them.

AddressSanitizer and valgrind are not run on the RISC-V side; neither
works usefully under emulation.  UndefinedBehaviorSanitizer does, and
the suite and the whole 193-module corpus are clean under it there.

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/
