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 1983 by Borland, as their first software development application, it was quickly adopted by schools, universities, hobbyists and professional software developers. Turbo Pascal combined ease of use, power, speed and a great manual all for the really low price of $49.95.

Why Use Turbo Pascal Under CP/M?

With TP you get an Integrated Development Environment (IDE), so that you can edit, compile and run all from the same application. Since the IDE is only 34Kb there is plenty of space left on a disk for your source code and compiled programs. This is particularly handy for single disk machines. The editor is very functional and uses a subset of the Wordstar key combinations.

Pascal was designed to be easy to compile and because TP uses a single pass compiler, compilation speed is incredibly quick. The downside of the compilation speed is that the code is quite a literal translation without much optimization. However, for many applications this won't be much of an issue compared to the increased programmer productivity.

If you need parts of your program to run faster, you can always embed inline machine code into functions/procedures or access functions in external binaries. The latter option allows you to create libraries in assembly language and use a jump table to access individual functions with the external keyword.

In 1986 Borland released Turbo Pascal 3.0 which added support for overlays. The running code could now be swapped in and out from disk as needed. With careful planning, you could escape the normal 64Kb limit and only be constrained by the capacity of the disk you are running the application from.

The standard library offers a good range of functions and TP keeps quite close to Standard Pascal as defined by Jensen & Wirth in their 'User Manual and Report'. As with all Pascal implementations, there are problems porting programs between implementations. However, if you aren't using any of the operating system specific calls, then you can easily port to the MS-DOS and CP/M-86 versions. My only gripe is that TP doesn't support procedures and functions passed as parameters.

Finally, Borland included a highly readable and very complete manual. It covered not just the IDE, language and libraries, but also detailed information on the memory layout and calling conventions from assembly language. This meant that you could quickly get up and running with few additional resources.

How to install

First download Turbo Pascal 3.01a for CP/M-80 and unzip the archive.

Put at least TINST.* and TURBO.* files onto a disk. The real advantage of not copying all the files is seen if you only have a single drive. The extra room will allow you to edit, compile and run your programs all from the same disk. For instructions on how to create a virtual disk for z80pack look at: Emulating a CP/M System With z80pack.

Boot up your CP/M system, put in the disk with TP on it and change to this drive if necessary. In my examples I am using B:

Run the TINST program to set up the screen:

B> tinst

Press S for Screen Installation and select the appropriate terminal for your set up. I'm using z80pack, so I select ANSI. You probably don't want to alter this definition so say No to altering it. Then enter the speed in Mhz of your machine. If a suitable terminal isn't listed consult the TP manual for advice.

If you want to configure additional editor commands, you can do this via the Command Installation option. At the very least, if you have them, you'll probably want to configure the page-up, page-down keys as well as the cursor keys to represent character-left, character-right, line-up and line-down. If not press Q to quit.


To start the IDE run:

B> turbo

You should now be looking at the Turbo Pascal splash screen, showing the version, copyright message and which terminal is configured. At the bottom you are asked whether to 'Include error messages'. For the moment press Y.

Now you will be presented with the main screen. You have a number of commands on this screen, which are accessed by a single letter.

To work with a pascal source file, first press W and then enter a filename. This is the file that the editor will open and it is also the file that the compiler will compile if you haven't selected a main file.

To edit the work file, press E. The editor uses Wordstar key combinations which you can read more about in the manual. For now the following keys will be useful to know:

Key commandAction
CTRL-sCharacter Left
CTRL-dCharacter Right
CTRL-eCharacter Up
CTRL-xCharacter Down
CTRL-k sSave Document
CTRL-k dQuit

You can also use any keys that you configured above with the Command Installation option in tinst.

Files are edited in memory so to save them to disk you press S from the main menu.

To compile and run the work file, or main file if selected, press R. Depending on what is set in the compiler options, this will either compile to a com file or will compile to memory.

Hello, world!

To try this with the traditional 'Hello, world!' program, set the work file to hello.pas, edit the file and enter the following, then quit the editor.

program helloworld;
  writeln('Hello, world!');

Compile and run it by pressing R from the main menu. You should see it compile and then say hello to the world.


The following video shows the creation of a FizzBuzz program using Turbo Pascal and allows us to see just how quick and easy it is.

The source code for fizzbuzz.pas used in the video is as follows:

program fizzbuzz(output);
  i: integer;
  for i := 1 to 100 do
    if i mod 15 = 0 then
      write('FizzBuzz ')
    else if i mod 3 = 0 then
      write('Fizz ')
    else if i mod 5 = 0 then
      write('Buzz ')
      write(i, ' ');

What Now?

Get the Turbo Pascal 3.0 Manual for CP/M-80, CP/M-86 and PC-DOS/MS-DOS from bitsavers.org. It is a wonderfully well-laid out manual and you should have no problems using this to learn and get the most out of Turbo Pascal. You may also want to take a look at a copy of the old Borland musuem page: Antique Software: Turbo Pascal v3.02.

You are now ready to use Turbo Pascal to write and compile applications like it was 1986.

Creative Commons License
Turbo Pascal: A Great Choice For Programming Under 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

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...   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