Search PalmPower's 487 Palm-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Palm programming with Quartus Forth (continued)

Here's a listing building on our hello word earlier:

\ helloworld ML 1-Feb-00
: hello ( --) ." Hello World" ;

: go
MainForm
hello
begin ekey drop again ;

To run this program, create the memo, then go into Quartus Forth and write "include helloworld." If you get an ok, then write "go". The screen should clear and "Hello World" should appear.

The "go" word definition consists of MainForm, a word which reloads a blank form, effectively clearing the screen. Next, it includes "hello", our Hello World printer routine we wrote earlier. Finally, the "go" definition includes a loop which reads events from the queue and simply drops the value from the stack (i.e., it does nothing but sit there).

As the state of the stack is so important, most words include a stack diagram which shows what's taken off the stack and anything that's put on, in the form ( off -- on ). The left bracket is a comment word terminated with the right bracket -- remember to leave a space. In a lot of cases you'll find no comments to a word, just the diagram, so it's worth getting used to reading them. As an example, here's the stack diagram for the DmCloseDatabase OS call:

DmCloseDatabase ( dbP. -- Err )

The above line shows the call expects a double cell (i.e., a 32-bit pointer value, as input and leaves a numeric error flag as output). If you've installed Quartus Forth, you'll find the rest of the Palm OS calls and a key to the types in stackdia.txt file in the docs directory.

Handling the event loop
In our original program, we simply dropped any events we were sent. Events are things that happen on the Palm device, like a screen tap, while the programming is running. Now we'll do something with them. This time we'll pick up the penDown event and print our message at that location. For this we need some more words:

  • The event names so we know to enter penDownEvent. These come from the Events collection;

  • The current co-ordinates of the pen. This is in Events, too, as the word coords@ ( -- y x);

  • A word to move the print position for the 's' word to the pen position. This needs the at ( y x --) word in the graphics collection.

Adding these pieces gives the following listing:

\ helloworld ML 1-Feb-00
needs events
needs graphics

: hello ( --) ." Hello World" ;

: handler ( ekey--)
dup penDownEvent = if
coords@ at hello
else drop then ;

: go
MainForm
hello
begin ekey handler again ;

The "needs" word means the program uses the words from the library referenced. It's like #include in C. But what's all this "dup ... = if" stuff?

Let's take it one step at a time:

  • ekey puts an event on the stack;

  • handler needs to test it to see if the event is a key, but testing it will consume the event, so we need another copy, hence dup;


« Previous  ·  1  ·  2  ·  3  ·  4  ·  Next »
Other articles you might like
Home > Phones and PDAs > Palm and Treo > Programming (24 articles)
   How PDA software is born
   Program with Simplicity
   Kinectivity 2.0 brings enterprise application developers new tools
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Other PalmPower Articles
Palm gets up to date with new Tungsten family of handhelds
Create handwritten email with riteMail
Presenter-to-Go puts PowerPoint presentations on your Palm OS handheld
Looking for the cutting edge
Gain remote access to databases and PLCs
PalmSource Open House showcases what's new in the Palm community
Analysis: handheld market share
More from the ZATZ journals
Computing Unplugged: The iPad defenders have spoken
David Gewirtz Online: CNN commentary and analysis
DominoPower: Application development, William Shatner, and the origin of the universe
OutlookPower: More about disappearing text
-- Advertisement --

ONLINE GROUP CALENDAR - FOR UP TO 100 OF YOUR CLOSEST FRIENDS
Stay organized and in control with 24/7 access to all of your important events, projects and files --whether you're at work, at home or on the road.

You can share your calendar, projects and files so everyone in your office is up to date. Plus, search your entire group to find times when everyone is available to meet, manage company resources and much more.

Organize your entire team for as low as $9.95 per year (and yes, that's where the decimal place is supposed to be!)

Tap here to get started right away.

-- Advertisement --

Sent Items Organizer
When you need to file your sent email into their proper folders based on keywords or who it's to. It's also perfect for shared mailboxes.

It also adds a "Send And File" toolbar button while you're composing (similar to the way Lotus Notes used to work) for quick and easy filing.

Find out more!

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login