A Programmer's Notebook:
Utilities for CP/M-80

CONTENTS

The meat of this book is a number of source files in CP/M assembly language (MAC assembler). They are linked from the chapters where they are discussed; when you click a link, the source opens in a new window, for example: Listing 5-3.

Introduction
In which I pontificate on software as a craft.
Chapter One
In which we write a pretty trivial program but demonstrate the use of pseudo-code in design, as well as file input and screen output.
Chapter Two
In which we write two more pretty trivial programs, demonstrating different ways to display data. At the end we compare the performance of assembly language to a compiled language.
Chapter Three
In which we create a pair of programs to compress and decompress files. The compression isn't really very effective, but the approach to solving certain design problems is interesting.
Chapter Four
More finger-exercises as Your Diligent Author works rather hard to figure out an unexpectedly tough problem. At the end he humbly reveals a much better solution by someone else.
Chapter Five
In which we delve into the nuts and bolts of CP/M disk space allocation and directory layout, and write a directory dumper. An interesting way to display data is shown, which can be generalized to any program.
Chapter Six
In which we design and build a really useful program, one that would be worth re-implementing on modern systems. The careful design process, examining all the possible uses of the program, is noteworthy.
Chapter Seven
In which we write a non-trivial program which, although it is no use today, demonstrates some fairly sophisticated solutions to common problems, like the use of a DFSA for parsing text.
Appendix A
Summary command documentation for each of the programs developed in the book.
Appendix B
Documentation of the two macro libraries used in all the programs.
Appendix C
Documentation for all the useful subroutines used in the book, and how to include them in your own code.

Preface to the Online Edition

Why put online an old book about programming for an obsolete operating system—a book in which all the programs are in machine language for an obsolete CPU architecture? Certainly the audience for such a book is very limited! But, given the global scope of the internet, it isn't quite non-existent. A few people still like to putter around with the old machines and software. For their sake, I'm putting this book online where someone looking for insight into CP/M programming might find it.

Resurrecting the Files

This book was written in 1981 using, of course, a CP/M system. The files of chapter text, and the files with the small pseudo-code Figures, survived through moves from that system to an early IBM PC and then through several generations of Macintosh, to the present, but the Listings, the program source files, were lost along the way. However, I had a copy of the book still in the publisher's shrink-wrap with 8-inch diskette included. Jack Rubin, a fan of classic computers, had the equipment to read the disk, and he resurrected the source and library files so this complete online edition could be created.

The text here is almost identical to the original book. I had coded the text and the pseudo-code figures in a very regular way using a simple markup scheme, so it was quite easy to convert the files to HTML. I have fixed a couple of typos, and dropped an irrelevant footnote and two unimportant drawings. The line-drawings that remain had been done by the publisher following my pencil sketches; these I recreated using OpenOffice Draw. They are not quite identical to the originals.

Running the Programs

You can run CP/M using a software emulator, and use it to assemble and run the programs in this book. Several emulators can be found online. The one I used was SIMH. SIMH can be customized to emulate various types of hardware. I tested the programs on a version of SIMH customized to boot a CP/M system on a Z80 CPU; you can find it here.

Once you have SIMH, you can download the source and executable files from this book. They are in the form of an emulated CP/M diskette, compressed to a .zip file. Download the file linked: here. Unpack the zip file to get pnb.dsk; attach that as the second or third disk of the emulated CP/M machine.

At several points in the book I express concern about the speed at which these programs run. This concern is amusing to me now, because when I run them under SIMH, they load, run and finish almost before I have finished pressing the Return key on the command. SIMH is a software emulator but it is running on a CPU that has a clock rate about 5,000 times faster than the Z80 I used for development. The difference in disk access time is almost as great. So a program that needed 10 seconds to load and execute then finishes in 2 milliseconds now. Well, make it 20 milliseconds, to allow for the extra overhead of software emulation. Just the same there are times when a programmer needs to think about efficiency, and the examples of doing that in this book are not wrong.