About the Datalink
What is it?
Download Protocol
Display Segments
Memory Map
150 vs 150s

Wristapp Programming
Creating Wristapps
Wristapp Format
The State Table
Wristapp Routines

Wristapp Programming
1 - Hello World
[This Page] 2 - Getting Input
3 - Better Input
4 - Showing Selection
5 - PassWord
6 - Day Find
7 - Playing with Sound
8 - Using Callbacks
9 - Hex Dump
10 - EEPROM Dumper
11 - Spend Watch
12 - Sound Schemes
13 - Random Numbers
14 - Hourly Chimes
15 - Lottery Picker

Sound Schemes
Sound Hardware
Sound Scheme Format

Home Send Mail

Getting Input

A program which just does output and really takes no input is not very useful.  The first stage in making a program more useful is to figure out how to allow the user to enter a value.  With this first numbers program, we allow you to enter a number by pressing the PREV/NEXT key to advance it by one each time you press the key.   This allows us to see how basic input works and a couple of the formatting/display routines.

;Name: Numbers

;Version: NUMBER

;Description: This is a simple number count program

;by John A. Toebes, VIII


;TIP:  Download your watch faster:  Download a WristApp once, then do not send it again.  It stays in the watch!

;HelpFile: watchapp.hlp

;HelpTopic: 106

            INCLUDE "WRISTAPP.I"


; (1) Program specific constants



;   Bit 0 indicates that we want to show the segments instead of the message


CURVAL      EQU   $62  	; The current value we are displaying

START	    	EQU   *


; (2) System entry point vectors

L0110:  jmp	MAIN	; The main entry point - WRIST_MAIN

L0113:  rts             ; Called when we are suspended for any reason - WRIST_SUSPEND



L0116:  rts             ; Called to handle any timers or time events - WRIST_DOTIC



L0119:	rts             ; Called when the COMM app starts and we have timers pending - WRIST_INCOMM



L011c:	rts             ; Called when the COMM app loads new data - WRIST_NEWDATA



L011f:	lda	STATETAB,X ; The state table get routine - WRIST_GETSTATE


L0123:  jmp HANDLE_STATE0



; (3) Program strings

S6_NUMBER:	timex6  "NUMBER"

S6_COUNT:   timex6  "COUNT "


; (4) State Table


        db      0

        db      EVT_ENTER,TIM2_8TIC,0 	; Initial state

        db      EVT_TIMER2,TIM_ONCE,0   ; The timer from the enter event

        db      EVT_RESUME,TIM_ONCE,0   ; Resume from a nested app

        db      EVT_DNNEXT,TIM_ONCE,0	; Next button

        db      EVT_DNPREV,TIM_ONCE,0   ; Prev button

        db      EVT_DNSET,TIM_ONCE,0    ; Set button

        db      EVT_MODE,TIM_ONCE,$FF	; Mode button

        db      EVT_END


; (5) State Table 0 Handler

; This is called to process the state events.  We will see ENTER, RESUME, DNNEXT, DNPREV, DNSET, and TIMER2



        bset	1,APP_FLAGS             ; Indicate that we can be suspended

        lda     BTNSTATE                ; Get the event

        cmp 	#EVT_DNNEXT             ; Did they press the next button?

        beq     DO_NEXT			; Yes, increment the counter

        cmp     #EVT_DNPREV             ; How about the PREV button

        beq     DO_PREV                 ; handle it

        cmp     #EVT_DNSET              ; Maybe the set button?

        beq     DO_SET                  ; Deal with it!

        cmp     #EVT_ENTER              ; Is this our initial entry?

        bne     REFRESH


; This is the initial event for starting us



        bclr    1,FLAGBYTE              ; Indicate that we need to clear the display

        jsr     CLEARSYM			; Clear the display

        lda 	#S6_NUMBER-START

        jsr 	PUT6TOP

        lda 	#S6_COUNT-START

        jsr 	PUT6MID

        lda 	#SYS8_MODE

        jmp 	PUTMSGBOT


; (6) Our only real working code...


        inc     CURVAL

	lda     CURVAL

	cmp     #100

	bne     SHOWVAL


        clr     CURVAL




      	jsr     CLEARALL

        bset    1,FLAGBYTE


	ldx     CURVAL

        jsr     FMTXLEAD0

	jmp     PUTMID34


	lda     CURVAL

 	beq     WRAPUP

	dec     CURVAL

	bra     SHOWVAL


        lda     #99

	sta     CURVAL

	bra     SHOWVAL


; (7) This is the main initialization routine which is called when we first get the app into memory



        lda     #$c0				; We want button beeps and to indicate that we have been loaded

        sta     WRISTAPP_FLAGS

        clr     FLAGBYTE			; start with a clean slate

        clr     CURVAL


We have the same 7 basic sections, but some of them are a little more filled out.

  1. Program specific constants - We have only two basic variables.  The flagbyte and the current value. 
  2. System entry point vectors - We have nothing special this time..
  3. Program strings - THe strings go here for addressability.
  4. State Table(s) - This really tells the watch how we want to operate and what events we want to handle.  See The State Table for a more complete explaination of this. For this, we want to see the down events for the NEXT, PREV, and SET buttons so that we can increment, decremet, or reset the counter as appropriate.  We also have coded the MODE button with the magic $FF which causes it to advance to the next app.
  5. State Table Handler(s) - Here we have the typical CMP/BEQ instruction sequence to quickly determine what event happened.  Note that the EVT_ENTER event causes a timer to go off which allows us to clear the screen 8/10 second after they switch to the app.
  6. Program Specific Code - The actual meat of the program.  We really only have to deal with advance/retreat/reset of the value and then displaying it after each change..
  7. Main Initialization routine - This is called once when the wristapp is first loaded.  We need to make sure that we set the appropriate bits in WRISTAPP_FLAGS.

Just pressing a button for each increment can be tedious.  Learn how to make it better with: Better Input - Update