; Sample.asm
;
; This sample is meant to serve as a prototype for assembly language Pilot
; applications. It uses the standard startup code and implements a typical
; message loop that handles some common events. Several resources (e.g.,
; menu, icon) are included, a few inline and others from external files
; generated by PilRC.
;
; NOTE: For clarity's sake this code is not highly optimized.
;
; NOTE: Where possible this sample uses PalmOS APIs to do conversion between
; integers and strings (hex and decimal). The Palm APIs have some interesting
; limitations. StrAToI accepts signed 16-bit ints. StrIToA accepts signed
; 32-bit ints. StrIToH accepts signed 32-bit ints. My implementation of htoi
; accepts unsigned 32-bit ints. The least common denominator for all these
; routines is a signed 16-bit int so I've placed that limit on the
; conversions.
;
; Formatted for 8-space tabs. Assemble with "pila sample.asm" after creating
; the resources with "pilrc sample.rcp ."
;
; By Darrin Massena
; 29 Jul 96
; (updated 10 Sep 96)
; The 'Appl' directive sets the application's name and four character id.
Appl "Sample App", 'samp'
; Pilot.inc contains PalmOS constants, structure offsets, and API trap codes.
include "Pilot.inc"
; Startup.inc contains a standard startup function. This function must be
; the first within an application and is called by the PalmOS after the app
; is loaded. The startup function in Startup.inc (__Startup__) calls the
; application-defined function PilotMain.
global gpfldDecimal.l ;pointer to the Decimal field
global gpfldHex.l ;pointer to the Hex field
code
; ---------------------------------------------------------------------------
; DWord PilotMain(Word cmd, void *cmdPBP, Word launchflags)
; PilotMain is called by the startup code and implements a simple event
; handling loop.
proc PilotMain(cmd.w, cmdPBP.l, launchFlags.w)
local err.w
local evt.EventType
beginproc
tst.w cmd(a6) ;sysAppLaunchCmdNormalLaunch is 0
bne PmReturn ;not a normal launch, bag out
trap #8 ;break on startup for debugging
systrap FrmGotoForm(#kidfMain.w)
PmEventLoop
; Doze until an event arrives
systrap EvtGetEvent(&evt(a6), #evtWaitForever.w)
; System gets first chance to handle the event
systrap SysHandleEvent(&evt(a6))
tst.b d0 ;handled?
bne.s PmEventDone ;yep
; Menu handler gets second chance to handle the event
systrap MenuHandleEvent(&0, &evt(a6), &err(a6))
tst.b d0 ;handled?
bne.s PmEventDone ;yep
; Application handler gets third chance to handle the event
call ApplicationHandleEvent(&evt(a6))
tst.b d0 ;handled?
bne.s PmEventDone ;yep
; Form handler gets fourth chance to handle the event
call MainFormHandleEvent(&evt(a6))
tst.b d0 ;handled?
bne.s PmEventDone ;yep
; Still not handled. We're not interested in it anymore so let the
; default form handler take it.
; Application Icon Bitmap resource. Is automatically converted from Windows
; format to Pilot format and written as a 'tAIB' rather than 'Tbmp' because
; kidbAIB is a special value ($7ffe)