QUARTUS


Here's the canonical "Hello world!" program for the Palm OS®, shown on the left written in Quartus Forth, and on the right written in C. You'll have to scroll down quite a bit to see the entire C source, resource definitions, and Makefile.
The Quartus Forth version is compiled directly on-board a Palm device; the C version is compiled on a desktop system.
In the case of Quartus Forth, the resources (form and icons) are provided automatically by the compiler.

Compare them both in terms of length, and of complexity.

"Hello world!" in Quartus Forth "Hello world!" in C

In the MemoPad:

\ hello

: go
  MainForm
  ." Hello world!"
  begin  key drop  again ;

' go (id) q4hw MakePRC Hello!

That's it!

Here's the compiled Hello! app (only 4400 bytes!) for download:

It will install and run on any Palm OS device, from the most current (Palm OS 5.x) all the way back to the original Pilot with Palm OS 1.0.

File: hello.c

/***********************************************************************
 hello.c - Sample "Hello, world!" program for Palm OS.  Build with
        PRC-Tools 2.0 and Palm OS SDK 3.5 or better.

 Created 2001.02.04 by Warren Young
 $Revision: 1.1 $  $Date: 2001/09/25 08:36:32 $

 Shortened 2005.09.25 by Neal Bridges.

 This program is hereby placed into the public domain.
***********************************************************************/

#include <PalmOS.h>

#include "resource.h"


////////////////////////////////////////////////////////////////////////
// Globals

// Pointer to the currently-active form
static FormPtr gpForm;


//// StartApplication //////////////////////////////////////////////////
// Called when application is starting

static Err StartApplication ()
{
  FrmGotoForm (HelloForm);
  return 0;
}


//// StopApplication ///////////////////////////////////////////////////
// Called when application is being shut down.

static void StopApplication ()
{
  FrmCloseAllForms ();
}


//// HelloFormEventHandler /////////////////////////////////////////////
// Handle events for the "Hello, world!" form.

Boolean HelloFormEventHandler (EventPtr event)
{
  Boolean handled = false;

  switch (event->eType)
    {
    case frmOpenEvent:
      {
        gpForm = FrmGetActiveForm ();
        FrmDrawForm (gpForm);
        handled = true;
        break;
      }

    case frmCloseEvent:
      FrmEraseForm (gpForm);
      FrmDeleteForm (gpForm);
      gpForm = 0;
      handled = true;
      break;

    default:
      // -Wall warning eater: switch must handle all enum
      // elements.
      break;
    }

  return handled;
}


//// ApplicationEventHandler /////////////////////////////////////////////
// Handle global events, and pass form-specific events to each form's
// event handler.

static Boolean ApplicationEventHandler (EventPtr event)
{
  Boolean handled = false;

  switch (event->eType)
    {
    case frmLoadEvent:
      {
        FormPtr pForm = FrmInitForm (event->data.frmLoad.formID);
        FrmSetActiveForm (pForm);
        FrmSetEventHandler (pForm, HelloFormEventHandler);
        handled = true;
        break;
      }

    default:
      // -Wall warning eater: switch must handle all enum
      // elements.
      break;
    }

  return handled;
}


//// EventLoop /////////////////////////////////////////////////////////
// Global event loop.

static void EventLoop ()
{
  EventType event;
  UInt16 error;
  do
    {
      EvtGetEvent (&event, evtWaitForever);

      if (!SysHandleEvent (&event))
        {
          if (!MenuHandleEvent (0, &event, &error))
            {
              if (!ApplicationEventHandler (&event))
                {
                  FrmDispatchEvent (&event);
                }
            }
        }
    }
  while (event.eType != appStopEvent);
}


//// PilotMain /////////////////////////////////////////////////////////
// It all starts here...

UInt32 PilotMain (UInt16 launchCode, MemPtr cmdPBP, UInt16 launchFlags)
{
  Err err = 0;

  if (launchCode == sysAppLaunchCmdNormalLaunch)
    {
      if ((err = StartApplication ()) == 0)
        {
          EventLoop ();
          StopApplication ();
        }
    }

  return err;
}

File: resource.h

#define HelloForm 1100

File: hello.rcp

#include "resource.h"


VERSION ID 1 "1.00"


////////////////////////////////////////////////////////////////////////
// "Hello, world!" form

FORM HelloForm AT (0 0 160 160)
        MENUID MainMenu
        USABLE
BEGIN
        LABEL "Hello, world!" AUTOID AT (0 0)
END


////////////////////////////////////////////////////////////////////////
// The program's icon

ICON "icon.bmp"

File: icon.bmp


File: Makefile

####
# Macros

PROGRAM=hello
CC=m68k-palmos-gcc
PILRC=pilrc
OBJRES=m68k-palmos-obj-res
ICONTEXT='Hello!'
BUILDPRC=build-prc
APID=TEST
CFLAGS=-palmos3.5 -Wall -g
LFLAGS=-g

SOURCES=hello.c
OBJS=hello.o
PRC=$(PROGRAM).prc
RESOURCES=$(PROGRAM).rcp


####
# Major targets

all: $(PRC)

$(PRC): $(PROGRAM) bin.res
        $(BUILDPRC) $(PRC) $(ICONTEXT) $(APID) *.bin *.grc

$(PROGRAM): $(OBJS)
        $(CC) -o $(PROGRAM) $(OBJS) $(LFLAGS)
        $(OBJRES) $(PROGRAM)

bin.res: $(RESOURCES) resource.h icon.bmp
        $(PILRC) $(RESOURCES)
        touch bin.res

ctags:
        ctags $(SOURCES)

clean:
        rm -f *.bin *.grc *.o bin.res tags $(PRC) $(PROGRAM)

dist: clean
        rm -f ../hello.zip
        zip -9 ../hello *.[ch] *.rcp *.bmp Makefile


####
# Dependency targets

hello.o: hello.c resource.h


© 1999, 2006 Neal Bridges. All Rights Reserved.