			      D C A L C
			      =========

			          by

 		              Bob Hepple

What is it?
===========

DCALC is  a  (fairly) portable,  character  based implementation of  a
Reverse Polish Notation calculator as popularised  by Hewlett-Packard.
I wrote it because I thought  it stupid  to sit at a $100,000 computer
whirring away at X Mips and Y Mflops (or even at  my home  PC) and yet
still need to rumage about for  a physical  calculator  to work out my
mortgage  or Hex to decimal  conversions (yes,  I know  about 'dc' and
'bc' but who wants  to use them? Who CAN  use them?) Oh yes,  I nearly
forgot - I hate calculators (or calculator  programs) with an '=' sign
on them.

Who is it designed for?

Anyone who  likes   RPN/stack  calculators    and   needs   statistic,
scientific, financial and number-base conversion functions.

I had a  lot of   fun building    DCALC, but I   am not  so   keen  on
documentation so I won't  try  to explain the  workings  of  RPN. Look
elsewhere!!

CALC is a very simple program to add  numbers  found on stdin. Invoked
with argument +, -, * or / calc uses the  appropriate argument instead
of +.

calc.el is intended to allow emacs to add up a region in emacs.

Running DCALC.
==============

Under  UNIX, DCALC  just runs  as a normal  text-based  program  under
(System V) curses. Just make sure the termcap  entry for your terminal
can support function keys.

On  the PC  under MSDOS, DCALC  can run  in  one of two  ways  - as an
ordinary program or as a Terminate & Stay Resident program.

To run as an ordinary program, just type 'DCALC' at the COMMAND.COM or
shell prompt. The DCALC window and function keys labels  pop up at the
bottom of the screen. To stop DCALC, press the ESC key.

To run as  a TSR program, type  'DCALC -I'  at the COMMAND.COM prompt.
DCALC installs itself and waits for you to type one of the 'hot' keys.
DCALC takes up about 75K of RAM while memory resident.

To get rid  of DCALC when  it  is  resident, type  'DCALC  -R' at  the
COMMAND.COM prompt. Don't try to uninstall DCALC while there are still
TSR programs in memory which were loaded AFTER DCALC was loaded.  Peel
them out layer by layer.

I have not  tested DCALC with many  other  PC TSR's as it's  about the
only one I use.

Using DCALC
===========

There is a pop-up help  window available  once DCALC is running - just
toggle it on and off by pressing 'H' or F8.

Since   Unix terminals  and the  PC  lack the  specialised keys   of a
calculator, there is a mapping of keyboard to function -  see the help
window for details. For example, the CHS (change sign) function of the
calculator   is  carried out  by the ','   key on the terminal  or  PC
keyboard.  What the heck - I wasn't using ',' for anything else!

There  are some small  differences  in keyboard mapping between the PC
and  Unix implementations since   not all  (Unix)    terminals  can be
guaranteed to have 'PgUp' 'PgDn' and 'Del' buttons.  Also, to  exit in
Unix, use ^D (Control-D) or q rather than ESCAPE. Sigh. I have assumed that
the terminal has  a termcap entry  with at least 8 function  keys (k1,
k2, ...  k8 in TERMCAP). Just in case, you can use control w e r t y u
i or o in place of f1-f8 - but beware: if you don't have function keys
there is no way to exit 'ASCII' mode!

One advantage that DCALC has  over an  ordinary calculator is that you
can  see all the  registers.  Just press '@'  to  toggle the  register
window on and off.

Another advantage is  that you don't need  to buy three calculators to
get the main  scientific,  financial  and computer  science functions.

Yet  another advantage is that the  display  can show ASCII characters
and  do  ASCII to   DECIMAL/OCTAL etc conversions.  There  is a slight
difference between the PC and Unix versions in that the PC version can
display control codes  as well as ordinary  characters.  Unix versions
embolden ASCII values over 127 (bit 8 set).

Some programming notes.
=======================

The code is not very clever - a fast hack really.  The main calculator
engine  is in 'dcalc.c' -  this is pretty   well platform independent.

Unix  versions need to compile-in 'curse.c'.   

PC  versions either  need 'curse.c'  plus a (public domain) version of
curses or compile-in 'ibm.c' and Blaise computing's excellent 'Turbo C
Tools' version 5.00.  There are  some  flags in 'dcalc.h'  to tell the
compiler how to proceed.  These should be all  you need  to change. In
particualr, there is  a flag 'TSR' that  controls the inclusion of TSR
code. Small compile model is required.

The code  has only  been tested under  MSDOS with  Turbo C, SCO  Xenix
2.3.{13} and  with SunOS  4.0 with  the System  V compiler (because  I
haven't learned bsd yet!) and with Linux 2.0.36 (RedHat 5.2)

The OpenLook version uses devGuide to produce the various files from
the devGuide source code file ov.G. These files can then be compiled
with the Makefile provided. The `makefile' (lowercase m) works for
the other environments.

As of 1999.2.3, the only version supported is Linux, but other Unix
systems will be easy to compile.

KNOWN BUGS:
===========

There are always bugs.

The PC TSR version of DCALC does not  always  pop up properly  - eg in
COMMAND.COM - you may need to  press  one other key  (any key will do)
before DCALC pops up. But it works anyway!

It works OK in HP's AdvLink though - and that has to be a feat!

Emboldening of ASCII characters > 127 does not work!

In the OpenLook version, Math errors appear to be caught by the window
manager/system and print ugly messages on stderr. Compiling-in a
matherr() routine does not make any difference. I have not seen a
workaround for this in the limited documentation I have. Probably
buried deep in the 7 O'Reilly volumes on X! Let me know if you have
a fix!

Bob Hepple

bhepple@bit.net.au

Wed Jun 26 1991
Tue Jan 21 1992
Wed Oct 20 1993 - added Linux and ncurses support
Wed Feb 03 1999 - re-released for Linux with GPL
