ColaCalc (Version 1.3)
by Dan Wilga
Copyright ½ 1995, Gribnif Software. All Rights Reserved.
This program may be distributed without charge, provided that this text
file is present and that it and the program files are unmodified.
This program was originally ColaWare (duh!), but it's now ChocolateWare.
If you find it useful, you are encouraged to show your appreciation by
sending a quantity of chocolate candy to the address below. What kind and
how much are up to you. Please just limit yourself to chocolate, either
with or without nuts (no fruits or liquers, please).
PO Box 779
Northampton, MA 01061
What? ANOTHER calculator? Yup, another calculator. But this one's
different, I promise!
There are a number of really good calculator programs out there for the
ST. Most of them just don't fit my needs for several reasons. The simple
ones don't have what I need, and the ones that do have all of the
programming functions I want are too huge, difficult to use, and take too
much memory. And even though most of them are desk accessories, you
still can't access a desk accessory within a non-GEM program. So I've
always had to keep my old Casio calculator sitting on top of the
Enter ColaCalc. This tiny little program (about 8k) is a full-featured
programmer's calculator. No pretty dialog box, no floating point, no
linear regression, but a calculator that's always there when you need it.
And, best of all, you can change the keys to whatever you want, you
aren't stuck with what I think are good keyboard equivalents!
ColaCalc can be activated at a single keypress. The display occupies the
very bottom of your screen, and as such hides very little data. The
calculator functions include the standard operators, bit manipulation,
word size and base (binary, octal, decimal, or hex.) There is also a
special mode that lets you see the scan code generated by any key on the
ColaCalc can even insert the value in the display into your text editor
or word processor, automagically!
It is also designed to work in any standard video mode, as well as with
the TT, Falcon, MegaSTe, and Crazy Dots video board.
Run COLACALC.PRG from the desktop, or place it in your AUTO folder. If you
use a COLACALC.DAT file, then it should be in the same folder as the program.
If you are holding down the Alternate key while ColaCalc is loading, then it
will not install itself. This is a good way to keep it from installing when
it is in your AUTO folder, without having to re-boot.
IMPORTANT: If you use the Templemon debugger, ColaCalc may not be able to
be activated. Templemon uses the same vector for monitoring the keyboard
that ColaCalc does, and it may prevent ColaCalc from seeing keypresses.
In order for ColaCalc to work, it must be placed physically after
TEMPLMON.PRG in the AUTO folder.
Unless you have changed the activation keypress (see Configuration), you
can always call ColaCalc from within any program simply by pressing
Control-Undo. The only time ColaCalc may not appear is when a disk access
is occuring. To quit ColaCalc, press either Esc or Undo.
If you call ColaCalc within a text editor or word processor, you can have
it pass the value in the display to the program, to become part of the
text. Simply hold down the Alternate key while pressing Esc or Undo to
quit. As soon as you release the Alternate key, the text editor will
receive the display value, as though it had been typed on the keyboard.
It is important that you not press any of the Shift keys while this is
going on, or the editor may become confused.
Here is a diagram of what the parts of the display mean:
ulb 10100010101010001010100010101001 XOR 1.......9.
||| \ / | \ \
/ | \ --------- number ----------- | function key memories
signed/unsigned | base operator
All keyboard controls listed below are the defaults.
Signed (S key); Unsigned (U key):
These control whether or not a negative number is to be displayed with
a minus sign in front of it (signed) or if the sign bit should be
displayed as part of the number (unsigned). These can also affect
translating between word sizes (see below).
Word Size: Byte (Alt-B); Word (Alt-W); Long (Alt-L):
By setting the word size you affect how much of the number is
displayed. If, for example, the display is set for Byte, the largest
value that can be displayed is FF (hex).
When changing from a small word size to a larger one, the value is
sign-extended if the display is set to show the sign, otherwise it is
not. This means that if, for example, you are converting FF from a
byte to a word without the sign, then this will become 00FF. If, on the
other hand, the sign is being used, FF (which shows up as -1) will
still be -1 after the extension.
Base: Binary (Control-B); Octal (Control-O); Decimal (Control-D);
These control the base to display values in. In Binary mode, large
numbers will have small circles after every eight bits to indicate the
The keys 0-9 and A-F (or a-f) can be used to enter numbers. The keypad
keys will also work under the default configuration.
This portion of the display shows what function was last entered. It may
also contain "-E-" if an error occurred; if this happens, press
Function Key Memories:
The F1-F10 keys can be assigned values by pressing Shift along with the
appropriate F-key. A number can be recalled later by pressing just the
function key, without Shift. If a particular function key has a
non-zero value assigned to it, this will show up in the function key
segment of the display.
The display will not include the function key segment or the function
name if you are using low resolution.
=, Return, Enter Calculate result
Undo, Esc Quit ColaCalc
Alt-Undo, Alt-Esc Quit and type value
Clr/Home Clear display/Clear error
Shift-Fkey Set memory
Fkey Recall memory
Backspace Undo last digit typed
Help Enter/Exit Keypress mode
The first time you press Clr/Home clears the display or any error
condition, which shows up as "-E-". If you press it a second time, any
operator still waiting to be processed is cleared.
When in Keypress mode, the display shows the value for any shift keys
pressed, the scan code of the last key pressed, its ASCII value in hex,
and the actual character that key produces (if non-zero.) This is handy
for writing your own configuration file (see below). To exit Keypress
mode, press the Help key again.
Unary operators (NEG, NOT and the PEEKs) are processed immediately.
Binary operators (like + and *) are processed in the order they are
received, with the exception of * and /, which take highest precedence.
This means that:
1 + 2 * 3 is processed as 1+(2*3)
1 * 2 + 3 is processed as (1*2)+3
1 + 2 * 3 / 2 is processed as 1+((2*3)/2)
1 & 2 * 3 is processed as 1&(2*3)
If the second operand is not entered for a binary operator, then the
first operand is reused. This means that:
2 * = is processed as 2*2
4 / = is processed as 4/4
A binary operator can be replaced with another by simply entering the new
operator before typing anything else. Thus:
1 + * 4 is processed as 1*4
3 / - 2 is processed as 3-2
Key Operation Type (Unary or Binary)
--- --------- ---------------------
+ Add B
- Subtract B
* Multiply B
/ Divide B
% Modulo (result after division) B
! NOT (one's complement) U
Delete NEG (two's complement) U
& AND B
| OR B
^ XOR (exclusive or) B
left arrow ROL (rotate left) B
Control-left LSL (shift left) B
right arrow ROR (rotate right) B
Control-right LSR/ASR (shift right) B
Control-P PEEK LONG U
Left Shift-P PEEK WORD U
Alt-P PEEK BYTE U
Both ROR and ROL act just like their equivalent 68xxx instructions. The
value to be manipulated is entered first, followed by the operator, and
then the number of bits to rotate.
The Control-right arrow will use a logical shift if the display does not
show the sign. In Signed mode, an arithmetic shift is performed.
The three types of PEEK work by treating the value in the display as a
pointer into the computer's memory. The value at that memory location is
then moved into the display. For PEEK WORD and PEEK BYTE, the value is
sign-extended if the Sign mode is set. Attempting to PEEK LONG or PEEK
WORD at an odd address will generate an error.
When it first runs, ColaCalc looks for a file called COLACALC.DAT in the
same folder where COLACALC.PRG is, which contains configuration
information. This file can be modified with a text editor. Each line
contains one keyboard equivalent or function key assignment. The first
part of a line must always contain data to be read by ColaCalc; the
remainder of the line is ignored and can be used for comments. Blank
lines are ignored.
The basic layout of the file is as follows:
Default display state
Key to activate
26 Operators and display controls
10 Function key defaults
Screen buffer size
The first line must contain three characters for the default display, and
they must all be lowercase. All other values must either be in hex or
must be a single raw ASCII character. The various values can be separated
by spaces or tabs.
There are two ways that keypresses can be defined: either by ASCII value
or by scan code. To define a keypress by ASCII, enter an asterisk in the
first column and the ASCII character (either the character itself or its
hex value) in the second column. To enter a keypress by its scan code,
the first column contains the shift key status, from the table below, and
the second contains the scan code:
Key Pressed: Value:
Right Shift 1
Left Shift 2
For example, to specify the "p" key, you would use "* p". To specify
Control-Alternate-p, you would use "C 19" (8+4=C, and $19 is the scan
code.) The Keypress mode in ColaCalc (activated with the Help key) is
helpful for determining what values to use.
Screen Buffer Size
When ColaCalc first runs, it allocates all the memory it will ever use.
The largest block of memory it needs is to store the original screen
underneath the main calculator display.
Since ColaCalc usually runs from the AUTO folder, it may not be able to
know in advance how much memory to allocate for ths buffer if you use a
Crazy Dots card or a Falcon. Why? Simply because the video mode that AUTO
folder programs run in is usually different from the final mode under
these circumstances. If the final mode happens to require more memory
than ColaCalc has already allocated (based on the size of the screen when
it ran in the AUTO folder) then the calculator display will either be at
half-height, or it will not appear at all.
To avoid this problem, you can specify the number of bytes of video
memory that should always be allocated for the screen buffer in advance.
The last line of COLACALC.DAT contains this number, in hex. To calculate
it for a given screen resolution, use the following formula:
screen_width_in_pixels / 8 * bitplanes * font_height
The font_height should always be either 8 or 16. Here are some examples:
Mode screen_width (dec) planes font_height buffer_size (hex)
--------- ------------------ ------ ----------- -----------------
ST Low 320 4 8 500
ST Medium 640 2 8 500
ST High 640 1 16 500
TT Low 320 8 16 1400
TT Medium 640 4 16 1400
TT High 1280 1 16 A00
256-color 640 8 16 2800
32K-color 640 16 16 5000
Note that if you are only ever going to use ST compatible video modes,
you do not need to change this value, since all ST video modes use the
same amount of memory.
1.1: Added Alt-Esc and Alt-Undo, for stuffing keyboard buffer.
Won't ever react to Undo followed (much later) by Control.
1.2: Worked on keyboard stuffing a bit.
1.3: Fixed ROL & ROR in several ways.
Works with the Crazy Dots and the Falcon's new video modes.
Will now always use the 8 x 16 font on larger displays, even with
things like the Crazy Dots.