If Only Borland Had Stuck With Turbo Modula-2 For CP/M

I have written previously about why Turbo Pascal is a Great Choice For Programming Under CP/M and now it is time to talk about what could have been. You probably haven't heard of Turbo Modula-2 for CP/M as it was only on the market for a brief period of time. However, it was a superb product and, in many ways, feels like a grown-up version of Turbo Pascal. Why TM-2 made such a fleeting appearance is shrouded in mystery. It was released in 1986 by Echelon under license from Borland and then quickly withdrawn. There doesn't seem to be any publicly documented reason for the withdrawal and it is said that Borland even denied its existence for a time. I want to show why it was a real shame this happened, and how much better a programmer's life could have been.

Integrated Development Environment

Like Turbo Pascal, Turbo Modula-2 was an Integrated Development Environment including a compiler and Wordstar based editor. On top of this TM-2 added a separate linker and library manager. The most obvious initial difference is the size of an installation: TM-2 takes up 142Kb, compared to TP's tiny 34Kb. However for this you get a lot more facilities, a bigger library and an altogether more sophisticated system.

Language Enhancements

The language itself is similar to TP and it is pretty easy to convert TP code to TM-2. With TM-2 you get many of the things that are liked about TP, including overlays, easy access to machine-code functions and a good standard library. In addition the library has been extended and you gain more numeric data types, coroutines, exceptions, procedures as parameters, typeless parameters, etc. To have these facilities on a CP/M machine in 1986 would have been incredible.


The Modula in Turbo Modula-2, of course indicates the use of modules to separate code. These are similar to Units in later versions of Turbo Pascal. They allow you you to hide data and functions within a namespace and only expose what you want to. Because of this isolation it allows the linker to only link-in functions that are used and hence reduces the executable size. In addition, because the modules are separate they can be compiled separately. Therefore when you make a change to your codebase, you only need to recompile the modules that have actually changed, which on a big project can greatly increase build speeds.

Native vs M-Code

Each module can be compiled to either native Z80 code or to M-code to be run on the built-in virtual machine. This allows you to compile code that doesn't need to run quickly to M-code, which executes more slowly, but compiles much quicker and the manual says it generally takes about 1/3 the size of native code. Then, for code that must run quickly you can set the IDE to compile to native Z80 code which runs much faster, but takes up more disk space and compiles more slowly. Because of the separate linker you can freely mix modules compiled with either native or M-code and hence get the best of both worlds.

Size and Speed Compared

To compare the performance of TP and TM-2, I am using a program based on the Prime Sieve benchmark included with TM-2.

The code for the Prime Sieve in Turbo Pascal:

program primes(input, output);

   size = 8190;

   flags : array [0..size] of boolean;
   i, prime, k, count, iter : integer;
   ch: char;

  writeln('Type Return'); readln(ch);
  writeln('10 iterations');
  for iter := 1 to 10 do
    count := 0;
    for i := 0 to size do
      flags[i] := true;

    for i := 0 to size do
      if flags[i] then
        prime := i + i + 3;
        k := i + prime;
        while k <= size do
          flags[k] := false;
          k := k + prime;
        count := count + 1;

  writeln( count, ' primes');

The code for the Prime Sieve in Turbo Modula-2:

MODULE primes;

  size = 8190;

  flags : ARRAY [ 0 .. size ] OF BOOLEAN;
  i, prime, k, count, iter : CARDINAL;
  ch : CHAR;

  WRITELN("Type Return"); READLN(ch);
  WRITELN("10 iterations");
  FOR iter := 1 TO 10 DO
    count := 0;
    FOR i := 0 TO size DO flags[i] := TRUE END;
    FOR i := 0 TO size DO
      IF flags[i] THEN
        prime := i + i + 3;
        k := i + prime;
        WHILE k <= size DO
          flags[k] := FALSE;
          k := k + prime;
        count := count + 1;
  WRITELN( count, " primes" );
END primes.

The following table shows the average results from running each test 10 times and timing their execution and build (compiling + linking). This was performed under z80pack running at 4Mhz and therefore doesn't allow for the increased disk access time of a real system. For the TM-2 tests it also doesn't include the time to manually answer the questions required to build, instead it is just the processing time.

CompilerBuildExecutionExecutable Size
Turbo Modula-2 (M-Code)6 Seconds2 Minutes 8 Seconds16Kb (123 records)
Turbo Modula-2 (Native code)9 Seconds8 Seconds16Kb (125 records)
Turbo Pascal (Native code)< 1 second24 Seconds9Kb (67 records)

Your can see from the table that there are trade-offs for each option and no-clear winner. It therefore comes down to how the compiler will be used. If you need very fast running code or have a large codebase then TM-2 will probably be a better choice. However, if your program is smaller and doesn't need to run so quickly or you are happy to rely on assembler for extra speed, then you may find TP a better option.

Should I Switch From Turbo Pascal to Turbo Modula-2?

There is a manual available online, which while a poor scan, is certainly good enough to teach the language and TM-2 is similar enough to TP that it should be fairly easy to make the switch. However, TM-2 is a bit of an unknown quantity when it comes to reliability and bugs, because not all that many people used it, compared to the huge number of Turbo Pascal users. This also means that you are less likely to get help for TM-2 than TP.

However, if you feel brave, there are certainly big advantages to be gained from TM-2, especially with larger projects. So why not download a Turbo Modula-2 archive from the retroarchive programming languages page and give it a go. If you have used, or now choose to use TM-2, do leave a comment to share your experiences.

Creative Commons License
If Only Borland Had Stuck With Turbo Modula-2 For CP/M by Lawrence Woodman is licensed under a Creative Commons Attribution 4.0 International License.

Share This Post


Related Articles

Modula-2 Compilers on CP/M

Modula-2 is a great language in general and is a good choice for programming on CP/M. There are three good compilers available for CP/M which all require a Z80 processor and we'll compare each in turn...   Read More

The Pilot Programming Language on CP/M

Pilot was created by John A. Starkweather in the early 1960s as a programming language for Computer Assisted Instruction. It has often been compared to Logo because of its use with children. However,...   Read More

The Mouse Programming Language on CP/M

Mouse is an interpreted stack orientated language designed by Peter Grogono around 1975. It was designed to be a small but powerful language for microcomputers, similar to Forth, but much simpler. On...   Read More

Turbo Pascal: A Great Choice For Programming Under CP/M

CP/M was blessed with many programming languages, each with their own strengths and weaknesses. I think that Turbo Pascal stands out from these and I'm not alone. When Turbo Pascal was released in 19...   Read More

Installing the HI-TECH Z80 C Compiler for CP/M

My language of choice is C and I am currently getting more involved with the CP/M operating system. I have therefore decided that it would be nice to have a C compiler working under CP/M. There are a...   Read More