.FLYINGHEAD PROGRAMMING POWER
.TITLE An introduction to programming the PalmPilot
.DEPT
.AUTHOR Alan Jay Weiner
.SUMMARY Where does the PalmPilot get all these wonderful toys? It’s a mere matter of programming. Alan Jay Weiner kicks off the first of his monthly programming columns with an introduction to programming on the PalmPilot.
The vast quantity of third-party software has certainly helped the PalmPilot achieve its prominent position as the number one pocket computer. Over and over again, on the newsgroups and maillist, people speak of the number of applications – and the ability to write their own – as strong reasons to choose the PalmPilot.
One frequently posted question is simply "how do I get started?"
Like any environment, programming the PalmPilot requires learning some things – the tools, application programming interfaces (APIs), the operating system (PalmOS), and so on. The step between "where do I start" and getting that first program running can be daunting.
In this and future articles, I’ll explore all aspects of PalmPilot program development – looking at the tools and development environments available, exploring what goes on within a program, using the PalmOS APIs, building HackMaster Hacks, and more.
Let’s start by looking at what you’ll need to begin that first program.
.H1 What platforms?
Your choice of tools will partially be dictated by your development platform. Most likely, you’re using a Macintosh, Linux or Unix, or Windows (95 or NT).
Macintosh users are cursed and blessed – the "official" development environment is a Macintosh with Metrowerks CodeWarrior. At the same time, this is the only Mac-hosted compiler which could be a problem because it can be costly (hence, cursed). The most mature of all the PalmPilot development tools, CodeWarrior on Macintosh was used to develop the built-in applications, and is the only environment capable of running "Gremlins" – an automated testing tool required for Platinum certification by Palm/3Com. So if you’re developing on a Macintosh, your choice of tools is already decided: buy the Metrowerks compiler.
Unix/Linux users are twice blessed and cursed, as they have two choices: the GCC compiler, and the Pila assembler. More about both of these in a moment.
Windows users are most-blessed (though some would argue we’re cursed just by using Windows) – CodeWarrior, GCC, Pila, and a number of other development tools run under Windows. Many of the alternative tools are only supported on Windows.
Unless you are planning for Platinum certification, there is no clear "best" development platform. This certification requires extensive testing with Gremlins, so your only choice is CodeWarrior on a Macintosh. Most developers will simply use their favorite platform – all are quite suitable.
Finally, you can develop directly on the PalmPilot itself. There are a number of PalmPilot-hosted tools, although for the most part, these aren’t suitable for "real" development; they don’t have the range of accessories necessary for building a standalone shippable application. They can be useful for quick tasks or to try out some ideas before committing to full-scale development.
.H2 Gnu C Compiler (GCC)
GCC is the user-supported compiler developed by the Free Software Foundation. Many people have worked on adapting it for PalmPilot development. Along with the GCC compiler itself, other included tools combine to create a complete development environment.
GCC has several advantages. The price is tough to beat – it’s free. The tool set is quite good; many people have developed applications using it. It’s user-supported – as new PalmPilots come out, any changes in the operating system (and changes in the APIs) need to be rolled into GCC and its support files. Despite the lack of profit motive, there are quite a few people who’ve worked on the PalmPilot GCC; it’s reasonable to believe they’ll continue this work – it’s quite possible they’ll have new-API support before Metrowerks does. On the other hand, if no one does do this support work, it will lag behind. This is the problem with Pila; it languished for most of the past year, only recently being ported to Linux with some enhancements.
Most Unix and Linux users will already be familiar with GCC, and will find it quite comfortable. Windows users will likely find it unnatural at first. It has a strong "Unix-ish" feel to it; to be expected given its Unix background.
.H1 CodeWarrior
Metrowerks’ CodeWarrior, originally only Macintosh-hosted, is now available for Windows. Given its background, it has a strong Macintosh feel to it; Macintosh developers will be quite comfortable, but Windows users will find things quite odd – menus change depending on the active window, buttons and toolbars are often strange, common key-combinations don’t work, etc. The Windows version is not quite as complete as the Macintosh version – as well as lacking Gremlins, the Windows resource constructor lacks some bitmap tools.
Release 4 is due out as I write this; it’s an improvement over Release 3, but there are still a number of rough edges for Windows-hosted development. Nothing insurmountable, but a number of inconveniences. The Windows version lags behind the Macintosh version in several features.
Overall it’s a reasonably solid tool set from a company that responds to its customers – even to the extent of adding a #pragma to handle one of my own complaints.
If your preference is C++, Release 4 improves support for C++.
CodeWarrior is $369; academic versions are available for $119. Metrowerks also bundles CodeWarrior with either a PalmPilot Personal or Professional; if you need another (or a first!) PalmPilot, this is an economical solution. Or you can do as I did, and sell the spare PalmPilot, reducing the overall cost of the compiler.
.H1 Pila and ASDK
Pila and the ASDK (Alternative Software Development Kit) are a set of tools for developing in assembly language. Some of the tools are the same as used with GCC. While this is a personal favorite of mine – well-optimized assembly code is tough to beat for size and speed – it’s not an environment I’d recommend easily. All the PalmPilot documentation is C-centric, so you’re constantly mentally converting to and from C issues – API arguments and return values, structures, etc. Some built-in macros help with this, but it takes a while to get used to it. Unless you’re very comfortable in assembler you’ll run into a number of problems which the compilers help to insulate you from – word access to odd boundaries, incorrect API arguments, failing to save and restore registers, etc.
Unfortunately, Pila is a fairly bare-bones assembler, lacking conveniences such as macros and conditional assembly. Several bugs also contribute to its inconvenience.
Worst, however, is the lack of improvements – it languished for most of the past year; only recently being ported to Linux with a few enhancements. As far as I know, the include files haven’t been updated to PalmOS version 2.
However, if you like assembler, and are up to the challenge, it’s a usable alternative. I wrote AlCalc using Pila; others have also released applications developed with Pila. Pila and the ASDK are also free.
.H1 CASL
CASL (Compact Application Solution Language) is a Windows-hosted alternative to C/C++. You build and test your CASL application on Windows, then compile it to a program which is interpreted on the PalmPilot using their run-time interpreter. This has the downside of requiring the interpreter on the PalmPilot – although if you have multiple CASL applications you only need one interpreter on the PalmPilot, so the overall memory footprint would likely be smaller than several standalone C programs.
CASL is $64.95, and demo versions are available.
.H1 PalmPilot-based tools
The first PalmPilot-hosted language was Ron Nicholson’s cbasPad – a tiny "Chipmunk BASIC" interpreter. Recently, a number of other languages have appeared – Forth, Lisp, even a Java VM is in progress! This is separate from the Jump Java compiler; Jump compiles to assembler which is then run through Pila – Jump development seems to have stalled.
One of the most promising new developments is a C compiler that runs directly on the PalmPilot – PocketC by Jeremy Dewey. Several people have already developed smaller applications with it.
PocketC is $18.50. Currently it runs only on the PalmPilot Personal and Professional; Jeremy plans to develop a version which will run on the older Pilot 1000 and 5000. The current version will run on these only if they’ve been upgraded to PalmOS 2.
While the thought of developing directly on the PalmPilot is enticing, these tools are all primitive compared to the desktop-hosted tools. And it’s a pain to write complex code structures in Graffiti.
.H1 For more info
Roadcoders at http://www.roadcoders.com is one of the best starting places for PalmPilot programming information. This site links to virtually all the other programming-related sites including FAQs, tools, utilities, sample source code, articles, and other information useful for PalmPilot program development.
3Com provides the PalmOS documentation as PDF files, readable with Adobe’s Acrobat reader. They’re big files, but absolutely necessary. In addition to the three API manuals (Developing Palm OS Applications Parts 1, 2, and 3) there are tutorial and cookbook manuals, along with FAQs, technical notes, and other tidbits of useful information.
Wade Hatter maintains a programming FAQ (see URL below). Wade wrote an excellent comparison of GCC vs. CodeWarrior which was printed in Handheld Systems magazine in November 1997.
Handheld Systems published several other PalmPilot programming articles. One of the most useful articles is Ken Albanowski’s Memory/DBMS Primer, discussing the different types of PalmOS memory storage and how it’s used.
Finally, there is a developer’s maillist hosted by 3Com, and several developer newsgroups hosted by Darrin Massena; information about these is available on Roadcoders’ web site.
Between these sites and their links to others, you should soon be in overwhelm mode!
Next month we’ll look at a small C program – we’ll examine it line-by-line to see what happens in a typical PalmPilot application.
.BEGIN_SIDEBAR
.H1 Product availability
3Com/Palm Computing is located at http://palmpilot.3com.com or http://www.palmpilot.com, or visit their developer zone at http://palmpilot.3com.com/5024.html
RoadCoders is located at http://www.roadcoders.com
cbasPad by Ron Nicholson is available at http://www.nicholson.com/rhn/pilot.html
Metrowerks CodeWarrior is available at http://www.metrowerks.com
GCC for Windows is avaiable at http://www.land-j.com/gccwin32.html and http://www.iosphere.net/~howlett/pilot/GNU_Pilot.html
PocketC is available at http://www.seashellinc.com/orbworks/pocketc.html
Handheld Systems magazine is available at http://www.cdpubs.com/hhsj/hhsj.html, or visit Ken Albanowski’s Memory/DBMS Primer, a PDF file, at http://www.cdpubs.com/hhsj/archives/54/16albano.pdf
Wade Hatler’s programming FAQ can be found at http://www.wademan.com/Pilot/Program/FAQ.htm. For a comparison of GCC and CodeWarrior see http://www.wademan.com/Pilot/Program/GCCvsCW.htm
.END_SIDEBAR
.BIO
.DISCUSS http://www.component-net.com/webx?13@@.ee6ba40


