Home » Articles » CP/M development setup

CP/M development setup

Tue Jun 28, 2016

In 1974, Dr. Gary A. Kildall, while working for Intel Corporation, created CP/M as the first operating system for the new microprocessor. By 1977, CP/M had become the most popular operating system (OS) in the fledgling microcomputer (PC) industry. The largest Digital Research licensee of CP/M was a small company which had started life as Traf-0-Data, and is now known as Microsoft. In 1981, Microsoft paid Seattle Software Works for an unauthorized clone of CP/M, and Microsoft licensed this clone to IBM which marketed it as PC-DOS on the first IBM PC in 1981, and Microsoft marketed it to all other PC OEMs as MS-DOS. - Digital Research archives

If you need to do CP/M development for the fun (or for the money, heh), here are some tips on how to setup an environment for CP/M development using the Hi-Tech C compiler.

Basically you will need several things available, a Linux machine or virtual machine, Z80pack, cpmtools and the actual compiler.

Linux machine

The computer should be running a newer version of Debian, Ubuntu, Fedora or your favorite Linux distro. If you’re using Windows, you’re on your own. You can use your favorite VM manager (VirtualBox, VMWare, etc) to fire up a Linux distro virtual machine.


Download the latest version of Z80pack (1.28 currently), unpack the archive and compile the package and the required tools.

$ cd /src
$ wget http://www.autometer.de/unix4fun/z80pack/ftp/z80pack-1.28.tgz
$ tar -xzvf z80pack-1.28.tgz
$ cd z80pack-1.28/cpmsim/srcsim
$ make -f Makefile.linux
$ make -f Makefile.linux clean
$ cd /src/z80pack-1.28/cpmsim/srctools
$ make
$ make clean

The tools are installed into ~/bin so make sure you have that in your PATH (add the directory to the ~/.profile file).

Running CP/M is as easy as cd-ing into the cpmsim directory and running the wrapper script for the version of CP/M you want to run:

$ ./cpm2


$ ./cpm3


cpmtools is needed if you want (and you definitely want) to exchange files between the Linux computer and the CP/M disk images. The package should be in the package managers for all recent Linux versions, on Debian and Ubuntu is as easy as running:

$ sudo apt install cpmtools

If you can’t install the package using apt, yum, zypper or any other package manager, download the source code as a tar.gz archive and compile it using the normal ./configure && make && sudo make install procedure. There are two types of harddisk images configured by default in cpmtools and those are:

  • z80pack is a 4Mb disk image defined in /usr/local/share/diskdefs.
  • z80pack-hdb is a 512Mb disk image defined in the same file as above.

If the definitions are not found inside the /usr/local/share/diskdefs file, you need to add them manually, and this can be done by adding this to the bottom of the file:

# 4Mb disk image
diskdef z80pack-hd
    seclen 128
    tracks 255
    sectrk 128
    blocksize 2048
    maxdir 1024
    skew 0
    boottrk 0
    os 2.2

# 512Mb disk image
diskdef z80pack-hdb
    seclen 128
    tracks 256
    sectrk 16384
    blocksize 16384
    maxdir 8192
    skew 0
    boottrk 0
    os 2.2

NOTE: Speaking of the /usr/local/share/diskdefs file, if you try and create an image using mkfs.cpm you will notice an error emerging: **invalid OS type ‘2**. Do a search/replace inside that file and replace all occurrences ofos 2withos 2.2`.

To create a disk image usable by CP/M, issue the command below and you will have a new 4Mb disk image:

$ mkfs.cpm -fz80pack-hd /src/z80pack/normal.hd.cpm

or, for a 512Mb disk image (only for CP/M 3):

$ mkfs.cpm -fz80pack-hdb /src/z80pack/huge.hd.cpm

Accessing the disk image can be done easily with cpmtools’s programs.

   ... listing the directory
$ cpmls -f z80pack-hd /src/z80pack/normal.hd.cpm
   ... copying all files inside the current directory to the disk image
$ cpmcp -f z80pack-hd /src/z80pack/normal.hd.cpm *.* 0:
   ... remove the test.txt file from the disk image
$ cpmrm -f z80pack-hd /src/z80pack/normal.hd.cpm test.txt

Attach your new disk image to the CP/M simulator environment by opening the /src/z80pack-1.28/cpmsim/cpm2 in your favorite text editor and adding the disk image there.


rm -f disks/drive[ab].dsk
ln disks/library/cpm2-1.dsk disks/drivea.dsk
ln disks/library/cpm2-2.dsk disks/driveb.dsk
ln /src/z80pack/normal.hd.cpm disks/drivei.dsk
./cpmsim $*

Notice the ln /src/z80pack/normal.hd.cpm disks/drivei.dsk line. First argument is the actual location of the disk image you created using mkfs.cpm, second is the name of the disk and the letter to load into CP/M. The drive**i** image will be loaded into the I: drive. Do not use the C and D drives. Leaving the emulator is just a matter of using the bye program from the A: drive.

A> a:bye

Hi-Tech C compiler

Make sure you have the lha archiver installed on your Linux machine (should be in Debian and Ubuntu) and download the compiler archive from the z80.eu website (latest version is 3.09). Unpack it using lha:

$ lha e z80v309.exe

After unpacking, use the cpmcp command to copy all the files to your CP/M disk image:

$ cpmcp -f z80pack-hd /src/z80pack/normal.hd.cpm *.* 0:

To test the compiler using a simple Hello World program, create a hello.c file on your Linux machine, enter the code below inside the file, copy it to your disk image using cpmcp and run the compiler on it.

void main(void) {
   printf("hello, world\n");

$ cpmcp -f z80pack-hd /src/z80pack/normal.hd.cpm hello.c 0:
$ ./cpm2

and inside the simulator:

I> c -v I:hello.c

and you should get the correct output:

hello, world

  « Previous: Next: »