Powerful calculator prints out too
By James Brown
Your Atari can be the powerful, versatile desktop calculator you always wanted. Print your calculations and even text comments. This BASIC program works on all 8-bit Atari computers of any memory size, with disk or cassette.
Have you avoided buying a calculator because you thought it was silly to spend money on such a limited machine when you have a perfectly good Atari computer on your desk? Did you buy a $7.95 calculator and wish it could print a record of your figures? Did you ever want a printing calculator that could insert text comments alongside your figures?
Desktop Printing Calculator is what you need--an 8-bit Atari program that is as easy to use as a desk calculator, but considerably more powerful and flexible.
This program works like a desk calculator. You type the digits, then enter a single keystroke to perform the calculation. There are also a few control functions, such as turning on the printer. All the instructions you need are displayed onscreen.
Type in Listing 1, DESKCALC.BAS, check it with TYPO II and SAVE a copy before you RUN it.
When RUN, a list of available commands appears at the top of the screen. The abbreviations MEM, ACC and ENT appear at the bottom. These are the three registers which a calculator uses to hold the numbers you enter. Registers can store only one number at a time.
The ENTry register corresponds to your pocket calculator's display line. Whenever you enter a number, this is its first stop. This is also where your answer appears. For normal use, beginners may safely ignore the ACC and MEM registers which follow.
Most pocket calculators come with a "MEMory" register which can "remember" one number. Desktop Printing Calculator's MEM register works the same way. Unlike most other calculators, though, Desktop Printing Calculator lets you see the number in the memory register.
When you add two numbers, for example, one number is usually passed into the ACCumulator and the newer number is stored in the ENTry register.
Desktop Printing Calculator commands fall into four categories:
1. Math Commands (+, -, / etc.)
2. Printer Commands (Advance paper, etc.)
3. Register Commands (Transfer a number from one register to another.)
4. Mode Commands (Decimal or Fixed, RPN or ALG.)
ALGEBRAIC OR RPN
Desktop Printing Calculator lets you enter your calculations in two different ways. You may use the standard ALGebraic method, or Reverse Polish Notation (RPN).
Most businessmen, schoolchildren and pocket calculators use the ALGebraic method. To find the sum of 3 and 5 with this method, you'd press the following keys:
Some programmers prefer using RPN. To find the sum of 3 and 5 with RPN, you'd press the following keys:
 [RETURN]  [+] [=]
Important: Desktop Printing Calculator defaults to RPN. If you'd rather use standard algebraic notation, be sure to press the [V] key before starting your work.
%--Percentage (Automatically divides the numbcr in the ENTry register by 100.)
Advance Paper--Advances the printer paper one line. Handy for separating different calculations.
Clear Entry--Erases any number in the ENTry register and places it with a zero. This command does not affect any other register.
Decimal Float/Fixed--Determines whether your printouts will have a fixed decimal point or a floating decimal point. Fixed comes in handy when working with dollars and cents. Use float when you need more precision.
MC Clear Memory--Erases any number in the MEMory register and replaces it with zero.
MR Memory Recall--Copies the number from the MEMory register into the ENTry register.
MS Memory Store--Copies the number from the ENTry register into the MEMory register.
M+ Memory add--adds the number in the ENTry register to the number in the MEMory register and places the answer back in the MEMory register.
M- Memory Subtract--Subtracts the number in the Entry register from the number in the MEMory register and places the answer back in the MEMory register.
Note Print-- Prints a short note such as "Groceries" or "Traffic Tickets" with your calculations. These notes only appear at the printer, they are not displayed onscreen.
Printer On/Off--Controls your printer. When on, the printer will keep a record of all your calculations and print any notes you might add (see previous command).
Subtotal--Copies the number in the ACCumulator register to the ENTry register. If your printer is on, this number and the letter "S" will be printed.
Total--Copies the number in the ACCumulator register to the ENTry register, then clears the ACCumulator register. This is normally used when you want to complete one calculation and start a new one.
Version RPN/ALG--Lets you enter your calculations in either Reverse Polish Notation or ALGebraic form.
[RETURN] key--Copies the number from the ENTry register to the ACCumulator register. In RPN mode, this is often used to enter the first number of a multiplication program.
[ESC] key - Clears all registers and re-starts the program.
=--Identical to the Subtotal command, except an "=" is printed instead of an "S". This is useful when you want to show the current status of a calculation.
When using Desktop Printing Calculator with your printer (the [P] command), the number in the ENTry register will be printed at the end of every calculation. The command symbol (T, =, MS, etc.) is also printed to the right of each number.
In Floating Point mode, the numbers are left justified with a floating decimal point. In Fixed Point mode, the numbers are right justified, with two places after the decimal point. If the number is very large or very small, float format is used regardless of the mode, to allow the number to be printed correctly.
In fixed mode, numbers are cut off (not rounded) to two decimal places for printing, even though there may be more places in the value. The correct value still shows on the screen.
Finally, remember that BASIC uses an internal number representation that allows only 10 significant digits. If you try to add a very small number to a very large numher, you can expect to lose the least significant digits. (even in Floating Point mode). This happens with any calculator, so keep it in mind.
If you own the discontinued Atari CX85 numeric keypad, you'll be happy to know that Desktop Printing Calculator is completely compatible with this useful device. Just plug the CX85 into joystick port 2 and you're ready to go.
This program demonstrates how to receive characters from both the keyboard and keyyad. You can use lines 110, 810-830, and 6500-6599 in your own programs.
Line 810 tells the program to look for the keypad in joystick port 2. You can change the value of KPORT to use a different port if you like.
Line 820 is the translation table which converts the joystick codes generated by the keypad to standard ATASCII characters. The "D", "Y", and "N" represent the Delete, Yes, and No keys on the keypad. You can change these to other functions if you like ("S" and "T" for Subtotal and Total, for example).
Line 830 changes the "D" to the ATASCII delete character. The ESCAPE key on the keypad generates the same code as the 0, sc, we can't do anything special with it.
Line 6510 forces the keyboard into upper-case. This simplifies the tests else where in the calculator program.
Line 6520 reads the keyboard, but only if a key has been pressed. This is determined by checking location 764, which contains a 255 if no key has been pressed. Variable OLDKC is used to prevent the keypad from repeating rapidly if you don't get your finger off in time. When Set to zero, it means that either a keyboard key has been pressed (line 6520) or that the keypad has been checked and no key is pressed (line 6530).
If a keyboard key has been pressed, it is put in variables C and CH$ and returned; otherwise the keypad is checked.
If a key is being pressed, the STRIG function will return zero, and line 6540 will read the value.
Line 6550 checks to see if the value has changed since the last look and, if not, loops back until something else happens. If a nem: value is available, line 6560 converts it.
All that's left is to give some sound to the keystroke, and save the key value in OLDKC for next time.
James Brown is on the Information Systems staff of the Caltech Jet Propulsion Laboratory in Pasadena, California. He is editor of the JPL Atari users group newsletter.