

             EXPLANATION ABOUT USER KEY ASSIGNMENTS FOR ALG48
             ================================================


If you assign the basic operation commands in ALG48 (AADD, ASUB, etc.)
to the corresponding keys of the calculator, as described in Section 3.2
of the documentation, you will notice the following two small problems
when you are in user mode:

1. In program-entry (PRG) mode you will get the ALG48 command names
   (APOW, AINV, etc.), not the regular symbols;

2. ANEG does not behave exactly like the regular +/- operation.

The program AKEYS performs a more sophisticated key assignment that
solves these problems. Below is a technical explanation by Mika
Heiskanen of what AKEYS does and why.  It was originally posted in the
newsgroup comp.sys.hp48, on 13 Apr 1996, in response to a question by
Mark Wilson.

[...] A feature of ALG48 is having algebraic aliases for the basic
operations so that in *algebraic* mode you get the standard HP
functions. The HP48 does not provide methods to by-pass the 
standard key-handler via the ROMPTR properties in any other way.

However outside of ALG48 one could consider using

	:: Do1st/2nd+: x+ xAADD ;	for + key

In PRG mode x+ would be executed instead of xAADD and so on. However
there's a slight twist here - the name Do1st/2nd+: implies that the
program executes either the first object or the remaining *stream*
starting from the second object. Not object, stream. This means that
DoKeyOb will see :: xAADD ; instead of xAADD, and this in turn means
the algebraic alias defined in ALG48 is not seen. Thus trying to type

	'1+2'

would cause xAADD to be evaluated when + is pressed, and thus 1 would be
added to whatever is on stack level 1. There is no Do1st/2nd: command,
so we'll have to write substitute code ourselves:

	:: TakeOver ' xAADD ' x+ PrgmEntry? ?SWAPDROP DoKeyOb ;

Here we have to write the TakeOver command explicitly to override
default key behaviour, previously that was implicit as the first command
in Do1st/2nd+:

We could also use

	:: TakeOver ' xAADD ' x+ PrgmEntry? AlgEntry? OR ?SWAPDROP DoKeyOb ;

but with the algebraic aliases in ALG48 this is not necessary, DoKeyOb
will automatically pass from xAADD to the algebraic alias x+. I'm merely
mentioning this should someone need similar assignments for a library
not using algebraic aliases. However we can again improve on above, like
entries.srt mentions ImmedEntry? is the negation of the combined test,
so for all practical purposes we can always use the form

	:: TakeOver ' x+ ' xAADD ImmedEntry? ?SWAPDROP DoKeyOb ;

Handling the NEG key is more complicated. If you have HACK library
installed then by excuting WKEY and pressing the NEG key you get the
program assigned to NEG key. By disassembling it with Jazz you get the
following code

::
  NoEdit?case xNEG
  PTR 110EF			( Checks for number under cursor )
  NOTcase
  :: ' xNEG DoKeyOb ;		( If none then do regular NEG )
  case PTR 391DA		( Done already - existing sign was changed )
  PTR 13EF1			( Cursor position as # )
  SWAP PTR 13F29		( Set new cursor position )
  CHR_- PTR 42CFB		( Insert character to cursor position )
  #1+ PTR 13F29			( Set old position + 1 )
  PTR 391DA			( SetDA12a3NoCh - only display area 2b changes)
;

According to my files all the unsupported entries used above are at
fixed ROM addresses, thus changing the program is safe for existing HP48
versions:

::
  NoEdit?case xANEG
  ( the rest is unchanged )
;

Following the same idea we could use NoEdit?case to handle the the
dispatching also in the + key, but then we would miss some of the useful
features. For example if ADIV is assigned with the ImmedEntry? method
and flag 5 is set we can just type 2 4 /, where / terminates the
editline as usual but it also simplifies the result to '1/2'.

The program AKEYS assigns all the keys mentioned in the ALG48
documentation, (+ - * / ^ INV and NEG), but with the system RPL 
programs instead.

