The work by others to port Arduino BASIC to the Smart Response-XE device was of interest, but I wanted a few enhancements to extend battery life (auto shutdown) and I wanted an easier way to do math on the console rather than typing "PRINT" everytime I wanted to do something simple.
Thus, I did some hacking and implemented auto-shutdown after 3 minutes which can be easily redefined in host.cpp with line:
#define AutoSleep 180000
Note: AutoSleep only works when the device is idle; that is, not running a BASIC program. Thus, with the simple menu system I show later, the device will not shutdown automatically.
A really nice feature of BASIC is that quick calculations can be made directly on the console. Unfortunately, typing "PRINT" before every operation is a P.I.T.A. and totally lame. Remember when one could simply type "?" at the start and get the answer - so much faster.
On the SmartResponse-XE a "shift" key is required to generate the "?" thus 2 keystrokes. In considering this, I remembered an old compiled program I had written back in the mid-1980's for the IBM-PC ... it was compiled as "q.exe" and to add 3 and 5 one only needed to type:
q 3 + 5
and press ENTER. Of course, my program at that time handled a large number of math functions, much as are already implemented the the -XE's run-time interpreter. Thus, to minimize the keystorkes, I did an alias operation to PRINT as Q. To add 3 and 5, the
q 3 + 5
will be successful. One of the images shows a more complex operation:
Additionally, while not a hack, I wanted a way to really make use of the F1 - F10 function keys. I wrote a very basic BASIC program which others may wish (or not) to use a a template. I implemented a subroutine for calculating the hypotenuse or a right-triangle and a subroutine for converting angular degrees into the more useful radians.
The program listing is:
1 CLS
2 GOSUB 1100
5 PAUSE (50)
10 a=0; a=INKEY
20 IF a=0 THEN GOTO 5
25 a=a+17
30 IF a=1 THEN GOTO 100
35 IF a=2 THEN GOTO 200
40 IF a=3 THEN GOTO 300
45 IF a=4 THEN GOTO 400
50 IF a=5 THEN GOTO 500
55 IF a=6 THEN GOTO 600
60 IF a=7 THEN GOTO 700
65 IF a=8 THEN GOTO 800
70 IF a=9 THEN GOTO 900
75 IF a=10 THEN GOTO 1000
80 GOTO 1
100 GOSUB 190
105 PRINT "side a +": INPUT a
110 GOSUB 190
115 PRINT "a= " a " b=";:INPUT b
120 GOSUB 190
125 PRINT "a= " a " b=" b " c= "SQR(a*a+b*b)
126 PRINT ">>>>> Press any key <<<<<";
130 GOTO 1020
190 CLS
192 PRINT " /! Rt Triangle"
193 PRINT " / !"
194 PRINT " c / ! a"
195 PRINT " / !"
196 PRINT " ----!"
197 PRINT " b"
198 RETURN
199 GOTO 1
200 REM
299 GOTO 1
300 REM
399 GOTO 1
400 REM
499 GOTO 1
500 REM
599 GOTO 1
600 REM
699 GOTO 1
700 REM
799 GOTO 1
800 REM
899 GOTO 1
900 REM
999 GOTO 1
1000 CLS: PRINT " Degree to Radians calculator": PRINT
1005 PRINT "Enter Degrees ";: INPUT a
1010 PRINT a "Degrees = " (a/360*2*355/113) "Radians"
1015 PRINT "": PRINT "": PRINT "Press any key for Main Menu"
1025 a=INKEY: IF (a=0) THEN GOTO 1025
1030 goto 1
1100 PRINT "F1 Rt triangle F6" : PRINT
1120 PRINT "F2 F7" : PRINT
1130 PRINT "F3 F8" : PRINT
1140 PRINT "F4 F9" : PRINT
1150 PRINT "F5 Deg-Rad F10"
1160 RETURN
Of note, F1 - F10 map to subroutines as follows:
30 IF a=1 THEN GOTO 100
35 IF a=2 THEN GOTO 200
40 IF a=3 THEN GOTO 300
45 IF a=4 THEN GOTO 400
50 IF a=5 THEN GOTO 500
55 IF a=6 THEN GOTO 600
60 IF a=7 THEN GOTO 700
65 IF a=8 THEN GOTO 800
70 IF a=9 THEN GOTO 900
75 IF a=10 THEN GOTO 1000
It is a simplistic template for creating one's own everyday needed operations. Nice thing about the Dan Geiger / fdufnews / robinhedwards / Larry Banks / Michael Field port of Arduino BASIC to the Smart Response-XE is that the current implementation makes use of SAVE/LOAD for the internal EEPROM and MSAVE 0 - MSAVE 9 for the external FLASH inside the -XE. This then provides 11 separate templates that you can easily carry around with you.
Overall I am rather pleased that my small eBay purchase has given me a new toy. Next steps will likely be to extend the BASIC to include some more features.
Final thought: if one really wanted to, the first line in the menu system could generate all necessary constants (such as pi=3.141592654, meter=39.37, kilometer=0.621) or whatever values are pertinent to a profession. Afterward, these alpha constant names can be directly used in console calculations.
A ZIP for all needed files is attached for those wishing to play.
20230827 Added
Adding new (simple) COMMANDS to BASIC. Note, "simple" means new STATEMENTS w/o arguments, Argument implementation is similar but a few more rules.
How to successfully add command statements:
1) Pick a non-conflicting short name; ex: XYZ
2) In file BASIC_XE_n.ino, open for edit (n = 3 currently)
2a) Around line #26, increment #define TOKEN_BUF_SIZE 80
2b) Save the modified file
3) Open file basic.h for edit
3a) Create an empty line around line #86. My recent additions:
(83) #define TOKEN_Q 78 // 20230822 mrb
(84) #define TOKEN_REBOOT 79 // 20230822 mrb
(85) #define TOKEN_STATUS 80 // 20230826 mrb
(86)
3b) Create the macro for your new token name by adding it as
(86) #define TOKEN_XYZ 81 // new XYZ
3c) Increment the max number of active tokens:
(88) #define LAST_IDENT_TOKEN 81 // must match the main.ino (2a)
3d) Around line 218, add any required function prototype for new finction(s)
3e) Save the modified file
4) Open the file basic.cpp
4a) Include any new libraries around line #9. Example:
(8) #include <avr/wdt.h> // 20230822 mrb
(9)
4b) Around line #91, insert your new token name; ex. for simple token:
(88) {"Q", TKN_FMT_POST}, // 20230818 mrb
(89) {"REBOOT", TKN_FMT_POST}, // 20230822 mrb
(90) {"STATUS", TKN_FMT_POST}, // 20230826 mrb
(91) {"XYZ", TKN_FMT_POST} // XYZ simple command
(92) };
4c) The STATEMENT parser (no arguments) begins around line #1864:
(1864) int parseStmts()
(1865){
4d) Around line #1894 thru #1922, add your COMMAND into the select/case, Ex:
(1893) case TOKEN_REBOOT: softwareReset(); break; // 20230822 mrb
(1894) case TOKEN_STATUS: systemStatus(); break; // 20230826 mrb
(nnnn) case TOKEN_XYZ: <newfunctionName>(); break; //
5) Write a new function to implement your XYZ.
5a) Save file, compile, link, upload.
Examples of new functions I added:
// Token == REBOOT
inline void softwareReset() { // 20230822 mrb
asm volatile (" jmp 0");
}
// TOKEN == STATUS
int systemStatus() { // 20230826
host_cls();
host_outputFreeMem(sysVARSTART - sysPROGEND); // show memory size
host_outputString("\n Batt V= ");
host_outputFloat((getBatStat()/1000.0));
getNextToken();
return 1;
}
To implement multi-argument statements, refer to functions such as ATN
This guide is based on my implementations while interactive with the ArduinoIDE, but it may have omissions/errors as it is being written after-the-fact.
Ray
Edit 2023-September 15
Added two new tokens:
DEGREES
RADIANS
Boot-up default mode is radians for trig calculations. The token DEGREES will allow for SIN, COS, TAN, and ATN calculations in degrees. A BASIC program can switch between modes using the new keywords. Both tokens also work from the console and the status of the machine is now shown on the STATUS display: