More than once I came across a story of a heroic MicroPro programmer who in an all-night session managed to port WordStar from CP/M to DOS by patching a single byte. This is how the legend was retold by Joel Spolsky:
Now, here’s a little known fact: even DOS 1.0 was designed with a CP/M backwards compatibility mode built in. Not only did it have its own spiffy new programming interface, known to hard core programmers as INT 21, but it fully supported the old CP/M programming interface. It could almost run CP/M software. In fact, WordStar was ported to DOS by changing one single byte in the code. (Real Programmers can tell you what that byte was, I’ve long since forgotten).Joel Spolsky,
Now, that story is slightly misleading. The “spiffy new programming interface” accessible through INT 21h pretty much was the CP/M programming interface, and it wasn’t until DOS 2.0 that the INT 21h interface was significantly enhanced.
But the gist of the story does not even make sense. Although DOS was designed to make porting from CP/M easy, it was never a question of patching a byte here or there, since CP/M ran on 8080 CPUs and DOS ran on 8086/8088 processors. The processor families are certainly related, but not at all binary compatible. 8080 assembly source code could be machine translated to 8086 source and reassembled, but the code quality was reportedly less than ideal.
And yet… there is a kernel of truth in the story, even though it morphed into something highly implausible. Not unlike there really are Wang word processor symbols in the IBM PC character set, even though the stories told by Bill Gates are very difficult to take seriously.
The other day I tried to understand the very interesting disk format of Victor 9000 (aka Sirius S1) machines, and a Supplementary Technical Reference Manual from 1984 proved very helpful. Therein I found the following section that is short enough to quote in full:
6.4 How to turn a CP/M version of WordStar 3.21 into an MS-DOS version using DDT86 DDT86 DDT86 1.1 -RWS.CMD START END 03C0:0000 03C0:52FF -S0324 03C0:0324 E9 90 03C0:0325 39 90 03C0:0326 00 C3 03C0:0327 E9 90 03C0:0328 4A 90 03C0:0329 00 C3 03C0:032A 01 00 03C0:0328 00 . -S0356 03C0:0356 00 FF 03C0:0357 00 . -WWS.COM,180,52FF Use RDCPM to copy WS.COM and all overlays to an MS-DOS disc. Depending on the version of DDT86, and the version of the operating system, DDT86 may load to a different segment address. Start changing bytes at location 324 anyway. You may also find that some of your original bytes differ from those shown above, change them regardless.
In other words, one could take a CP/M-86 version of WordStar, patch a few bytes, and turn it into WordStar that could run on top of DOS. In some cases, patching a single byte (at 03C0:0356 in the example above) may have been sufficient.
To sum up, it really was possible to patch a single byte in a CP/M version of WordStar and turn it into a DOS version! And yet… not surprisingly, the truth is much less sensational than the legend.
The True Story
WordStar was arguably the killer app of CP/M. In 1981, the personal computing landscape started shifting towards 16-bit machines based on the Intel 8086/8088, of which the IBM PC was but one. According to the “official” WordStar history, sometime in late 1981 MicroPro ported WordStar to CP/M-86; note that CP/M-86 was itself probably finalized around December 1981.
In the Fall of 1981, the IBM PC with DOS was already out, but perhaps not yet a force to be reckoned with. In early 1982, the IBM PC started taking off and MicroPro did not want to be left behind. In April 1982, MicroPro started getting serious about releasing a DOS version of WordStar. Quoting the WordStar history:
In one single all-night session Jim Fox patched the CP/M-86 version of WordStar to make it run under MS-DOS on the IBM PC so that it could be demonstrated to Rubenstein. The actual port was done by a group of Irish programmers using Intel development systems, which ran the ISIS II operating system.
There is one element of the legend: Yes, there really was a programmer who turned a CP/M version of WordStar into a DOS version in an all-nighter. But it was a CP/M-86 version of WordStar, so it was porting from one 8086 OS to another with a compatible API. That is much less impressive than porting from the original 8080 CP/M to DOS, but also far more plausible.
It is clear that the DOS version of WordStar was built from the same source as the CP/M-86 version. That made good sense, both because CP/M and DOS ran on the same sort of machines and because the programming interface was compatible.
WordStar could access the DOS API through INT 21h and the CP/M-86 API through INT E0h. The interfaces were similar enough that WordStar had an internal switch which chose between the CP/M or DOS interface. This was a single byte in “user area 1” which was designed to be patched by users.
We don’t have to guess what the user area looked like because MicroPro published the listing, see e.g. page 232 in this PDF. On page 246, we see the following:
MSDOS DB 0H; SET TO 00H FOR CP/M-86,0FFH FOR MSDOS(PCDOS)
Note that the ‘MSDOS’ byte is at offset 356h in WS.CMD, which corresponds to offset 2D6h in the loaded program (as shown in the listing). Also note that the conversion process skips 180h bytes when saving WS.COM, skipping over the CP/M-86 CMD executable header.
And there we have another element of the legend. Yes, it really was possible to patch a single byte in the CP/M-86 version of WordStar to make it run on MS-DOS… because MicroPro made it that way.
Fact to Legend
There may not be contemporary written evidence, but there is no reason to doubt that a single programmer named Jim Fox did port the CP/M-86 version of WordStar to DOS in one night. The programming interface of the two operating systems is similar enough that the 8086 version of WordStar has a single code location which calls either INT 21h (DOS) or INT E0h (CP/M-86). Users could patch the one byte directing the system call choice, and that was documented by MicroPro.
In retelling, somehow this morphed into a story of a programmer porting the CP/M version of WordStar to DOS by changing one single byte. It is apparent that even though the legend is not (and can not) be true, it was not exactly made up; rather actual facts were mixed up and crucial details omitted.