Turbo Pascal 7 on HP Palmtops

Running Pascal on your palmtop?
I have developed two non-trivial applications for HP Palmtop computers (in addition to a number of smaller utility programs) and the development itself took place on palmtop machines, first 95LX and later, 100LX.

At that time I did not have a laptop, and I wanted to do most of the programming when on the road - hence the choice of the development platform. More than once I have been asked by our fellow LX-ers about how it can be done. Here it is.

What do you need?
First of all, you need a copy of Turbo Pascal 7 from Borland. It can be bought for less than $100 in most software stores. Although TP7 is the latest and greatest (before Delphi, that is) Pascal on the PC platform, TP6 and TP5.5 will do just fine and the installation and use will be the same as in the case of TP7.

Some writers used to recommend Turbo Pascal 3 for HP Palmtops. I wouldn't. TP3 was a great compiler back in '86, but the language was not as powerful as the later versions from 5.0 up. First of all, it was missing the modular features of the later releases; you could not use it to build self-contained, precompiled units. This is a large setback in all but the most elementary applications. The language standard has vastly improved since then, and so have the libraries.

The bottom line: I am recommending TP7, but if you happen to have a copy of Version 5.5 or 6, you may just stay with it. (These earlier versions have a slight advantage of taking up somewhat less disk space than Version 7.)

Files to install
Only two files have to be installed on your palmtop. The easiest way to do it, is to install Turbo Pascal on a "regular" DOS computer, and then move these two files manually.
  • The command line compiler, tpc.exe. It is amazing that an advanced compiler takes only 75,400 bytes of disk space, less than a stupid splash screen of many Windows applications.
  • The Turbo Pascal runtime library, turbo.tpl - 81,888 bytes.
This looks like using about 150k of the precious RAMdisk on your palmtop, but read on, it is not difficult to reduce this amount.
Shrinking the compiler
You may shrink tpc.exe to 57,221 bytes by compressing it with Diet. This operation can be performed on your desktop PC, before moving the compiler to your LX.

Just go to DOS and type "diet tpc.exe", making sure that DOS will find Diet in its path. Then forget about what you just did, TPX will run like usual on your palmtop, with only a slight delay upon startup.

Shrinking the library
Reducing the size of turbo.tpl is almost equally simple. The library contains, among others, the Graph unit, quite large and useless on the HPLX. The Overlay unit is also something you will probably never need on the LX. These units can be deleted from the library with use of the enclosed utility tpumover.exe, installed in the Turbo Pascal bin\ directory.

Go to DOS, create a new temporary directory, copy there tpumover.exe and turbo.tpl, and then, while in that directory, type "tpumover turbo.tpl -graph -overlay". After the new turbo.tpl has been transferred to your palmtop, the temporary directory can be safely deleted. The process reduces the library size to just 44,544 bytes!

Running the compiler
After dieting the compiler and deleting unnecessary units from the runtime library, you end up with a powerful development tool installed on your palmtop and taking just 100k of the disk space.

The bad thing about command line tools is that they use command line switches, quite hard to remember. The best way around this is to create a small batch file, invoking the compiler and setting the switches the way you usually need them. The batch I'm using, p.bat, is really a one-liner:

@ECHO OFF
A:\TP\TPC %1 /$S-/$A-/$I-/$V-/L/$N+/$E+/$X+/$F+/M

Refer to the Turbo Pascal documentation what the switches mean, but I found that this combination is just right form my palmtop needs. Of course, you may have to change the compiler path from a:\tp\ to wherever you've put it.

To compile a program with the main file named, say, myprog.pas, go to DOS, switch to the directory with your Pascal source code and type p myprog. After a few seconds the compilation will be complete and myprog.exe will be created on your RAMdisk.

How much available DOS memory you need for the compilation depends on the size of the program you are compiling. The largest program I've ever built on the 95 or 100LX was my (to put it mildly) calculator, Ex, with about eight thousand lines, or 100,000 bytes of code in a total of 40 units. Turbo Pascal was quite happy compiling it in 300k of DOS memory.

The compiler speed is more than respectable. The complete recompilation of all Ex units takes about 18 seconds on my 100LX and, if I remember right, about three times longer on a 95LX (which I no longer have).

An integrated environment?
Usually program development alternates between editing the source, compiling it and running the resulting program. Having to exit the editor in order to perform the other steps is not too convenient.

On my 95LX with 500k of RAM left (after the RAMdisk, that is) I used to do all this while in DOS, from within the VDE editor. The editor allows you to define a macro taking the name of the current file as an argument so that, for example, pressing Esc-P would compile the edited file, and Esc-R - run the compiled program; all without leaving the editor.

You can do it the same way on a 100/200LX, but for that machine I have switched to another approach, working directly from the Filer, without leaving to DOS.

Thanks to Buddy I am able to do everything from the Filer. I've assigned the comma key, when pressed over a .pas file, to run p.bat with that file's name as a parameter, while in order to edit the .pas file with the buit-in Memo editor, it is enough to press Enter twice.

Pressing Enter over the .exe file will execute the compiled program. Most importantly, you do not have to exit Memo to perform the other steps (although you have to remember to save the source file before doing this).

LX-specific programming
Turbo Pascal is a DOS tool; it produces programs running under DOS. Neither the compiler, nor the runtime libraries support any LX-specific features.

In principle, with the in-line assembly code option of Turbo Pascal, you can access any low-level functionality of your HP. That is, however, quite complicated and not too well documented. This is why I am limiting myself to DOS programs running on the LX and not really interacting with the Program Manager.

There is one thing worth trying and not too difficult: LX graphics programming. Obviously, the TP runtime library does not address this issue, but the assembly code for basic graphic primitives (line, point, circle etc.) has been published by a number of authors. Based on that, I wrote myself a small Turbo Pascal graphics unit for the LX palmtops, usable on both 95 and 100/200LX. This is how Ex draws function graphs, histograms and scatter plots. If you are interested, try it!


Home: wrotniak.net | Search this site | Change font size

Photo News | The Gallery


Posted 1997/10/20; last updated 2002/06/15 Copyright © 1997-2002 by J. Andrzej Wrotniak.