[comp.sys.handhelds] Calendar Display Routine

sburke@jarthur.Claremont.EDU (Scott Burke) (04/19/91)

Hi.

All this calendar stuff got me thinking, so...

Here's a very simple monthly display routine for a calendar.  It requires two 
arguments: the month length (in days) and the first day of the month (0=SUN 
1=MON ... 6=SAT), and it draws the month in a Sunday-Saturday format.  It 
should be easy to whip up routines to calculate the first day of the current 
month and the current month length from the DATE command, but I leave those as 
exercises for the reader ;-)

I think my idea of a long day string that's periodically split apart is based 
on a much earlier posting by somebody else about calendar displays, but I 
really can't remember the content of that earlier post.

Scott.
sburke@jarthur.claremont.edu



@
@ CALN displays a month, given the month length (in days), and the first day
@ (0=SUN...6=SAT)
@
@
@ Input:                     Output:
@
@ 2: first day
@ 1: length        ---->     1:
@

CALN
\<<
 \-> firstday length
 \<<
  CLLCD
  "  S  M  T  W  T  F  S\010" 1 DISP             @ DISPlay weekday labels
  "                  " 1 firstday 3 * SUB        @ SUB off needed blank days

  "  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21"
  " 22 23 24 25 26 27 28 29 30 31" +             @ split for posting
  1 length 3 * SUB +                             @ SUB off needed days

  DUP SIZE DUP 21 MOD - 21
  FOR i
   i SPLIT "\010" ROT + +                        @ insert newline
  -21 STEP

  2 DISP 7 FREEZE                                @ DISPlay month string
 \>>
\>>



@
@ SPLIT chops a string into two pieces at a given position.
@
@ Note that this performs the same function as the Toolkit word SPLIT in Jim 
@ Donnelly's HP 48 Programmer's Toolkit Library TLLIB; if you have that 
@ installed, just don't send this routine to your calculator.
@
@ However, this routine performs no error checking.
@
@
@ Input:                    Output:
@
@ 2: string                 2: "ending"
@ 1: position     ---->     1: "beginning"
@

SPLIT
\<< DUP2 1 + OVER SIZE SUB 3 ROLLD 1 SWAP SUB \>>