GENCALC
by David F.M. Carmichael
from ZX Computing Feb/Mar.1985

A brilliant program from David F M Carmichael of Glasgow.


This program has been devised so that the ZX Spectrum and ZX
printer can be used to carry out and annotate a wide range
of calculations without the necessity of having to write
specialised programs for each case. The program operates in
a number of different modes which can be selected by codes
entered at the key board.

The main operating modes (with their appropriate codes) are:-

"type": Typewriting mode allowing full typewriting
facilities in columns 1-30 of the display with various
delete options.

"calc": Calculator mode allowing typewriting facilities
similar to the above but only in columns 1-15, while
allowing the right-hand side of the screen to be used as a
calculator. Easy interchange is possible between the typing
and calculating sub-modes.

"table": User defined formula driven table calculator which
can be used with complex arithmetical expressions with up to
3 variables. Optional total facility is available.

Two other modes are available:

"copy": Copies the screen and gives option to take a further
copy if required.

"newpage": Copies the screen as above but on completion
scrolls the display to the next page.

All the above codes are initialised in the program so that
in the event of a crash or break in the program, it can be
restarted without disturbing the display by using the
command GO TO "(whatever code appropriate)".

On running the program the prompt "Enter required mode" will
appear and the appropriate code should be entered from the
keyboard. The computer will not accept spurious codes and
will beep to indicate the fact. (Indeed all through the
program spurious entries will get the same treatment, with
one notable exception in "table" mode).

Detailed instructions for each mode are as follows:

"type": Flashing "T" cursor displayed initially. Simulates
typewriter for all key entries (except for those below). A
warning beep is given when the cursor reaches column 25 and
a double beep at column 30. The cursor automatically moves
on to the next line but there is no autorepeat for key
entry.

Special key entries (with shift where appropriate) are:-

'DELETE'   : Autorepeat backspace/delete
'ENTER'    : Autorepeat new line
'EDIT'     : Gives "Enter required mode" prompt
'STOP'     : Stop program
'Cursor    : Gives line delete cursor
 Left'      (flashing "*" in column 0).

With line delete cursor the following key entries (with
shift where appropriate) can be used.

Cursor Up    Moves cursor in appropriate
Cursor Down  direction (autorepeat).
'DELETE'     Deletes whole line to the right of the cursor.
Cursor Right Returns to normal typewriter state with "T" cursor on
             column 1 of the line to the right of the cursor.

NOTE: When the bottom of the screen is reached either by
normal typing or by use of the newline command the screen
prompt "Screen full - go to next page?" will appear. If the
'N' key is pressed this prompt will disappear and the option
of obtaining and using the delete cursor is open. If the 'Y'
key is pressed an automatic copy/newpage sequence is
initiated.

'note'    Flashing 'N' cursor shows initially. Simulates typewriter
sub-mode  as in "type" mode but only in left hand side of screen. The
          delete cursor is a flashing "+" and will only delete one
          half of the line. All control key entries are the same as
          for "type" mode with the following additions:
"N"       Cursor right goes to 'calculator' sub-mode. A flashing
cursor    "<" cursor will appear on the right of the screen
          marking the print line.
"+"       Provided that no calculation is in progress the key
cursor    entry "Cursor Left" will move the delete cursor
          (behind the screen as it were) to the right side of the
          screen. Here it can be used to delete any entries on that
          side. At this point "Cursor Right" will return the cursor to
          the left hand side of the screen. It is not possible to go
          to the calculator sub-mode directly with the "+" cursor
          on the right hand side.


"Calculator" sub-mode

The prompt will ask for number or operator entry. Number of
entries must be no more than 8 characters long. Spurious
entries will be beeped.

Relevant operators are:

"+"     for addition
"-"     for subtraction
"*"     for multiplication
"/"     for division
"+%"    calculates % and adds result to running total
"-%"    calculates % and subtracts result from running total
"sub"   gives subtotal (marked with symbol ">")
"total" gives total
"note"  returns to "note" sub-mode.


Notes

The calculator will only work if numbers are displayed in
normal notation. Where subtotals or totals are such that the
computer would require to use exponent notation for display
then a series of beeps will occur and the total or subtotal
will appear as a line of asterisks.

Automatic subtotalling takes place where this will clarify
the display.

Where the screen is filled in the 'note' sub-mode the option
to continue or to select the line delete cursor is given as
for 'type'. However if the screen is filled in 'calculator'
sub-mode the copy/newpage sequence is automatically
initiated.

2, 3 or 4 columns can be chosen and after entering the
number required the code letters for the columns are
displayed ('a' 'b' 'c' and 'd' with the right hand column
always being 'd'). Column descriptions up to seven
characters long can now be systematically entered (and
corrected if necessary).

The formula is now entered. This can be any arithmetical
expression up to 30 characters long but must use the code
letters of the columns. The computer will display "d =" and
only the right hand side of the equation is entered.

The calculator is normally set to give a max of six decimal
places but the opportunity is now given to alter this.

Entry prompts will now appear systematically (using the
column descriptions already entered). Entries with more than
seven characters will be refused (and beeped). Any non
numeric entry will also be beeped but will be accepted (for
reasons noted below). The opportunity is given to check all
entries before computation of the value in column (d) is
carried out. Non numeric entries are acceptable provided the
column is not being included in the calculation (eg. if
formula is d = b * c then column (a) can be used as columns
used for computation will result in an error. As in "calc"
any total in column (d) outwith normal numeric display will
be printed as asterisks (with appropriate beeps).

After each line the opportunity is given to continue the
calculation or to stop and if the latter the option of a
total of column (d) is given. Unlike the intermediate line
totals the total of column (d) can be displayed in either
normal or exponent notation and thus can be any number
within the range of the computer. On completion of all
calculations the computer displays the "Enter required mode"
prompt.

NOTE: If on first selecting the "table" mode the print
cursor is below line 15 the computer will automatically give
a new page. Subsequent automatic copy/newpage sequences will
take place at line 19 and the current column headings will
be displayed automatically at the top of the new page.


Technical notes

'Descriptive' variables are used throughout the program and
most of these are self explanatory.

Various flags are also used and these are noted below:

notec  :  Determines which prompt is given in 'calculator' sub-mode
          of "calc" when changing from 'note' sub-mode. (If 0 then
          'number' is prompted. If 1 then 'operator' is prompted).
subtf  :  Controls whether automatic subtotalling will take place on
          entry of certain operators. If 0 then no subtotalling
          takes place. The subtotal routine automatically resets
          this flag to 0.
calcf  :  Controls whether automatic subtotalling takes place
          after calculation. In the case of addition + subtraction
          this remains 0 but other operators such as "*" or
          "/" set this to 1. Like subtf this is reset to 0 after
          subtotalling.
cursf  :  Is set to 1 as soon as calculation starts and controls
          movement of line delete cursor to right hand side of
          screen (which can only happen when this flag = 0).
totf   :  Determines whether total is in normal or exponent
          notation and sets print position accordingly.
nof    :  Set at 1 by "no check" routine (Line 9700) if
          entry is non-numeric; otherwise 0.


Variables

The following non-descriptive variables are used:

a$,b$       General purpose non-dimensioned.
d$(4,7)     Column descriptions in 'table' mode.
e$(4,7)     Input information in 'table' mode.
a,b,c,d,e,f General purpose variables.
t           'table' total
x,y         General print position controls.
z           Special print position control used in 'table' mode
            (see line 4220 and similar).


Functions

Two used defined functions are included:

Line 9800   Controls no. of decimal points.
Line 9810   % function used in 'calc' mode.


--
Another Fine Product transcribed by:
Jim Grimwood (jimg@globalnet.co.uk), Weardale, England
--
