MaxZ80 - Chapter 4

M80 =CMD
BASCOM =MOTYL/Z/O
L80 MOTYL,CMD,MOTYL/N/E

The first line assembles CMD.MAC, producing CMD.REL. This is the first
example we've had of M80.COM, which is an assembler. Assemblers turn
low-level, assembler language instructions into .HEX or .REL files. M80.COM
generates .REL files. The second and third lines above should look more
familiar. The third line links the relocatable libraries MOTYL.REL and
CMD.REL and produces MOTYL.COM.

MOTYL.COM is a simple program that displays the command tail. For example,

7:09 A7:MOTYL>>MOTYL  TIME FLIES LIKE AN ARROW BUT FRUIT FLIES LIKE A BANANA!
TIME FLIES LIKE AN ARROW BUT FRUIT FLIES LIKE A BANANA!
The length of the command tail was 55.

7:10 A7:MOTYL>>

CMD grabs whatever it finds in the tail of the command you issue and puts it
in a string variable in the BASIC program, in MOTYL's case, FOOBAR$.

I lost the source code for CMD.MAC. Assembler language source code is much
more readable than the code it gets converted into. As I was interested to
learn again how CMD worked, I did something I knew wouldn't exactly work but
I thought it might bring me closer to rebuilding the source code. I turned
CMD.REL into CMD.COM with the command

L80 CMD,CMD/N/E

I knew CMD was not designed to run on its own as a .COM file. But I also knew
I had a program that did the reverse of what an assembler followed by a
linker do. Such a program is called a disassembler. Z80DIS.COM is such a
program. I ran it against CMD.COM and it generated source code. This source
code wasn't exactly what the author of CMD.MAC wrote, nor did I expect it to
be. I knew CMD.MAC had a line in it that itself CALLed a routine that was in
the relocatable library OBSLIB.REL. This routine is named $SASA. I was
reminded of its name when I ran the above link job, which announced

-$SASA  012B
1 Undefined Global(s)

Howard Goldstein, a friend of CMD.MAC author Pete Motyl, helped make the
needed adjustments to what the disassembler produced to recreate essentially
what Pete originally wrote. Things like

L0103
      NOP
L0104
      NOP
      NOP

got turned into

      DSEG
      EXTRN $SASA
TLEN: DEFS 1       ;STORAGE FOR TAIL LENGTH
TPTR: DEFS 2       ;STORAGE FOR PTR TO BEGINNING OF TAIL
      CSEG

and
 
      CALL 0000H

got turned into

      CALL $SASA  ;PUT COMMAND TAIL INTO PASSED VARIABLE

In Chapter 9, where we'll talk about CP/M's Transient Buffer Area, CMD.MAC
will be mentioned again.