Skip to content

bin2cpmhex.js

Peter Wilson edited this page Jan 6, 2024 · 11 revisions

Getting applications onto a bare metal CP/M box is a challenge faced by anyone looking to bootstrap a new CP/M system. Grant Searle wrote a great little utility to fill the CP/M part of this equation. He seems to change websites fairly often but at the time of writing his download utility is described on this page. Included is a Windows 'packager'. I'm a Mac user so that's not wonderfully useful. Instead I wrote this node.js utility that should run from the command line on any system with a recent version of Node installed. Typical syntax would be:

node ../path/to/bin2cpmhex.js prog.com > dnld.cpm

The file prog.com is read and a translated output produced suitable for consumption by Grant's download programme. Note output is sent to stdout so direct it where you want it.

This simple example translates a single file but it can happily generate output for whole directories. The generic syntax is:

bin2cpmhex.js file_or_directory [file_or_directory...]
  • Files
    • With .hex extension, assumed to be an intel hex file. The output filename is translated to .com and the hex content used as input to download.com.
    • Any other file is assumed to be binary and the individual bytes are converted to hex to be consumed by donwload.com
  • Directories - each entry in the directory is checked. Any that are standard files are converted as described above for files. And entries that are directories are recursively descended into and this directory process is repeated.

In this way bin2cpmhex.js can bulk convert files ready for CP/M.

Output format for an individual file is:

A:DOWNLOAD fname
U0
:{hexdata}
>LLCC

Where:

  • {hexdata} is a sequence of hex character pairs (one per byte)
  • LL is the lower 8 bits of a count of all the bytes in the hexdata set (size of binary)
  • CC is the checksum, calculated by adding every byte in the hexdata set and taking the least significant 8 bits.

Where more than one file is included in the package the above format is repeated for each file.

Patching a single file

The following syntax allows an Intel hex formatted file to be used to patch an executable CP/M file (a .com file) before writing to the output file. Disclaimer I obviously added this facility for some specific problem I was having at one point, no idea what that was now and I don't currently use this!

The syntax is:

node ../path/to/bin2cpmhex.js --patch=patch.hex prog.com > dnld.cpm

An error is generated if the number of files to be processed is not exactly one.

The programme to be converted is loaded into memory. Each data record in the patch file (patch.hex) is processed. All data records are then applied to the loaded file. The patched file is then written out ready to be fed to download.com.