This the the desk calculator program written by Edward A. Falk.
Copyright (C) Ed Falk.  Permission granted for free unlimited distribution
as long as my name and Sun Microsystems is not removed.

Any improvements, please send back to me so that I can have the option
of incorporating them into the distribution version.

	-ed falk, falk@sun.com, sun!falk



Directions for adding functions to the calculator:



1) re-read an hp calculator manual, the part that describes stack lift
    and things like that.


2) design keycaps.
    keycap naming convention is 'key.<r><c><p>' where <r> is the row
    (1-4), <c> is the column (1-9,0) and <p> is the position
    (t,m,b) (top,middle,bottom).
	a) go into iconedit and modify the keycaps as appropriate.
	b) use a regular editor and modify the keycaps so that they
	   are 32x20 (tops & bottoms) or 32x32 (middles).  Look at
	   an old keycap to see what needs to be done.
    The files key.top, key.mid & key.bot can be used as blanks.

3) add functions.
    In the file func.c, function Cmd_Parse, there is a 'switch'
    instruction that switches on a variable called "Pending_Op". 
    This is usually 'NORM', but can be values like 'RCL', 'STO',
    'HYP', 'FIX' etc. to refer to operations that are pending.  You
    should generally ignore these.

    Within the first case (NORM), there is a second switch which switches
    on the "key code".  The key code is a three digit number whose digits
    take on the form <r><c><p> where <r> and <c> are the same as for
    the keycap codes and <p> is 0-2 (top,middle,bottom).  Thus, the
    third row, first key, top part is "310".  There will be more than
    enough examples in the code.

    There is no need to worry about 'f' and 'g'.  These will have already
    modified the key code as appropriate (by changing nnn to nn0 or nn2).

    add the appropriate case, in the form:

	case nnn: EN ; LX ; computations ; break ;

    The macro EN indicates that the key terminates digit entry (most do).
    The macro LX indicates that the function sets the last-x register.
    The macro NL indicates that this function disables stack-lift (very few
	functions do this, CLX for ex.)
    The macro LF indicates that this function has no effect on stack-lift
	(very few functions do this, STO/RCL for ex.)
    Functions with neither NL or LF specified enable stack-lift.  This
	is the normal action.

    The macro Drop_Stack() drops the stack after an operation that
    uses X and Y and returns X (+-*/ for ex.).

    Example: "*" key; 2nd row, 10th column, middle:

      case 201:	EN ; LX ; yreg *= xreg ; Drop_Stack() ; break ;

    99% of mathematical functions use the EN and LX macros.  The back
    of your HP manual will tell you explicitly what functions have what
    effect on stack-lift, digit entry and last-x.

    Functions that are too complicated to put on one line of code can
    be made into functions at the end of func.c, such as the statistical
    functions etc.

    Keep potential errors in mind at ALL times.  Don't let the computer
    take it's default actions on numerical errors (which is to crash,
    usually).  If there's an error in computation, set xreg to 0.0 and
    Display_State to ERROR, otherwise set xreg to the results and
    leave Display_State alone.  

    Example: y**x function:
      case 241:	EN ; LX ; yreg = Calc_pow(yreg,xreg) ;
			    Drop_Stack() ; break ;

		:
		:

	double
	Calc_pow(y,x)
		double	x,y ;
{
		if(y>0 || (x == ((int) x)))
		  return(pow(y,x)) ;
		else
		{
		  Display_State = ERROR ;
		  return(0.0) ;
		}
	}




4) Mail changes back to falk@sun.com so I can add them to the master copy.



