I have found the SmartResponse-XE an interesting "Arduino-compatible" device. With BASIC installed and the added "Q" token (alias for PRINT) to allow realtime evaluation of simple math. However, the math functions of "+", "-", "/", "*" all involve use of the Sym-key and is awkward when the numerals are easily accessible across the top of the keyboard.
After having written C-code for the SmartResponse-PE device, I had a working knowledge of how simple the implementation of RPN could be on the PE. Actually, it was even easier than what I had envisioned as the BASIC interpreter and libraries already had all but one necessary function.
Here I present the latest code for the SmartResponse-XE BASIC which is built upon the work of numerous others as mentioned in my previous article: Tweaking BASIC on the SmartResponse-XE.
As can be seen in the calculator image below,
the implementation adds ease-of-use by assigning math operators to the soft-function keys on either side of the keyboard. They are:
- RBT Used to Exit the RPN calculator (via reboot) back into the BASIC interpreter
- R^ Rotate the stack upwards: T becomes Z, etc. X becomes T after the roll
- CLS Foo-french for Clear La Stack: X, Y, Z, T all become 0.0 ...
- LOG Log base 10 of the value in the X register with X updated to results
- SQR Square root of the value in the X register with X updated to results
- + Traditional addition of the values in Y + X, sum in X (see notes)
- - Traditional substraction of Y - X, difference in X (see notes)
- * Traditional multiplication of Y * X, product in X (see notes)
- / Traditional division of Y / X, quotient in X (see notes)
- S Change the Sign of X, X becomes -X and -X becomes X
Notes: RPN traditionally manipulates the stack in a push and pop manner.
Entering a number into the buffer and pressing the Del (for ENTER) will move the buffer to X as a floating point number. The previous X-value will move up to Y, the previous Y will move up to Z, the previous Z will move up to T and the previous T will be discarded.
Conversely, addition (+), substraction (-), multiplication (*), and division (/) will pop the stack. When the stack drops, T value is copied to Z, previous Z is copied to Y, and X becomes the results of the math operation.
A generic explation of RPN is here.
The Arduino codebase was modified from the previous BASIC-only code to include the RPN code:
Within RPN.h and RPN.cpp are the implementations for the calculator. The BASIC code was modified only to add the TOKEN_RPN and the implementation to call the main RPN function which is implemented as a loop which repeats until the RBT (reboot) softkey is pressed. The RBT key implements a full reset of the uC and returns the microcontroller into BASIC. Please be aware that a reset does clear all of the uC SRAM as well as any program stored using the BASIC command SAVE. You should save any useful programs to flash using MSAVE 0, where 0 can be 0-9.
For anyone wishing, the two RPN files can easily be combined into a single .INO such that the calculator can be implemented on the SmartResponse-XE without the BASIC: 20231004, I have added a ZIP for the free-standing RPN calculator in Arduino format.
Note2: This BASIC implementation extends the previous post by adding additional tokens: TOKEN_DEGREES and TOKEN_RADIANS (in addition to the TOKEN_RPN.) Here are the more significant additions:
#define TOKEN_Q 78 // simple print from console, ex: Q 1+2
#define TOKEN_REBOOT 79
#define TOKEN_STATUS 80
#define TOKEN_TAN 81
#define TOKEN_SLEEP 82 // alias for BYE
#define TOKEN_DEGREES 83
#define TOKEN_RADIANS 84
#define TOKEN_RPN 85 // add RPN style calculator