Migrated from GitHub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +33 -0
- data/Basic1/IotBasic/IoTBasic.ino +0 -0
- data/Basic1/IotBasic/MANUAL.md +1975 -0
- data/Basic1/IotBasic/basic.h +1526 -0
- data/Basic1/IotBasic/font/firasans.h +0 -0
- data/Basic1/IotBasic/hardware-arduino.h +0 -0
- data/Basic1/IotBasic/wifisettings.h +5 -0
- data/Basic1/TinyVT52/TinyVT52.ino +110 -0
- data/Basic1/TinyVT52/basic.h +1312 -0
- data/Basic1/TinyVT52/hardware-arduino.h +0 -0
- data/Basic1/TinybasicArduino/TinybasicArduino.ino +0 -0
- data/Basic1/TinybasicArduino/basic.h +1526 -0
- data/Basic1/TinybasicArduino/hardware-arduino.h +0 -0
- data/Basic1/TinybasicArduino/wifisettings.h +5 -0
- data/Basic1/basic.c +0 -0
- data/Basic1/basic.h +1526 -0
- data/Basic1/hardware-arduino.h +0 -0
- data/Basic1/hardware-posix.h +1502 -0
- data/Basic2/IoTBasic/IoTBasic.ino +0 -0
- data/Basic2/IoTBasic/Makefile +91 -0
- data/Basic2/IoTBasic/basic.h +831 -0
- data/Basic2/IoTBasic/boards/aim65.h +6 -0
- data/Basic2/IoTBasic/boards/avrlcd.h +3 -0
- data/Basic2/IoTBasic/boards/avrmcufriend.h +3 -0
- data/Basic2/IoTBasic/boards/duetft.h +16 -0
- data/Basic2/IoTBasic/boards/dummy.h +0 -0
- data/Basic2/IoTBasic/boards/esp01board.h +25 -0
- data/Basic2/IoTBasic/boards/esp32board.h +13 -0
- data/Basic2/IoTBasic/boards/esp32cam.h +3 -0
- data/Basic2/IoTBasic/boards/megaboard.h +14 -0
- data/Basic2/IoTBasic/boards/megashield.h +13 -0
- data/Basic2/IoTBasic/boards/megatft.h +14 -0
- data/Basic2/IoTBasic/boards/mkr1010board.h +18 -0
- data/Basic2/IoTBasic/boards/nanoboard.h +14 -0
- data/Basic2/IoTBasic/boards/rp2040board.h +14 -0
- data/Basic2/IoTBasic/boards/rp2040board2.h +17 -0
- data/Basic2/IoTBasic/boards/tdeck.h +69 -0
- data/Basic2/IoTBasic/boards/ttgovga.h +75 -0
- data/Basic2/IoTBasic/boards/unoboard.h +7 -0
- data/Basic2/IoTBasic/boards/wemosshield.h +15 -0
- data/Basic2/IoTBasic/buildin/buildin-arduinotest.h +84 -0
- data/Basic2/IoTBasic/buildin/buildin-games.h +324 -0
- data/Basic2/IoTBasic/buildin/buildin-tutorial.h +288 -0
- data/Basic2/IoTBasic/buildin/buildin.h +41 -0
- data/Basic2/IoTBasic/font/firasans.h +0 -0
- data/Basic2/IoTBasic/hardware.h +1091 -0
- data/Basic2/IoTBasic/language.h +464 -0
- data/Basic2/IoTBasic/runtime.cpp +0 -0
- data/Basic2/IoTBasic/runtime.h +1205 -0
- data/Basic2/IoTBasic/src/FlashStorage_SAMD/FlashAsEEPROM_SAMD.h +49 -0
.gitattributes
CHANGED
@@ -57,3 +57,36 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
57 |
# Video files - compressed
|
58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
# Video files - compressed
|
58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
60 |
+
data/docs/BASICs/101_BASIC_Computer_Games_Mar75.pdf filter=lfs diff=lfs merge=lfs -text
|
61 |
+
data/docs/BASICs/AltairBasic_1275.pdf filter=lfs diff=lfs merge=lfs -text
|
62 |
+
data/docs/BASICs/Apple2AppleSoftBASICRef1977.pdf filter=lfs diff=lfs merge=lfs -text
|
63 |
+
data/docs/BASICs/ECMA-55_1st_edition_january_1978.pdf filter=lfs diff=lfs merge=lfs -text
|
64 |
+
data/docs/BASICs/Kilobaud_1977_June.pdf filter=lfs diff=lfs merge=lfs -text
|
65 |
+
data/docs/BASICs/TinyBASIC-2.0.pdf filter=lfs diff=lfs merge=lfs -text
|
66 |
+
data/docs/BASICs/aim65_basic.pdf filter=lfs diff=lfs merge=lfs -text
|
67 |
+
data/docs/BASICs/apple1_basic_manual.pdf filter=lfs diff=lfs merge=lfs -text
|
68 |
+
data/docs/components/ABX00053-datasheet.pdf filter=lfs diff=lfs merge=lfs -text
|
69 |
+
data/docs/components/Atmel-8869-SEEPROM-AT24CS32-Datasheet.pdf filter=lfs diff=lfs merge=lfs -text
|
70 |
+
data/docs/components/BMP280datasheet.pdf filter=lfs diff=lfs merge=lfs -text
|
71 |
+
data/docs/components/BST-BME280_DS001-10.pdf filter=lfs diff=lfs merge=lfs -text
|
72 |
+
data/docs/components/DS1307.pdf filter=lfs diff=lfs merge=lfs -text
|
73 |
+
data/docs/components/DS3231[[:space:]]Real[[:space:]]Time[[:space:]]Clock[[:space:]]Connection[[:space:]]Diagrams.pdf filter=lfs diff=lfs merge=lfs -text
|
74 |
+
data/docs/components/DS3231[[:space:]]Real[[:space:]]Time[[:space:]]Clock[[:space:]]Datenblatt[[:space:]]AZ-Delivery[[:space:]]Vertriebs[[:space:]]GmbH.pdf filter=lfs diff=lfs merge=lfs -text
|
75 |
+
data/docs/components/DS3231.pdf filter=lfs diff=lfs merge=lfs -text
|
76 |
+
data/docs/components/DS3232.pdf filter=lfs diff=lfs merge=lfs -text
|
77 |
+
data/docs/components/Digispark.pdf filter=lfs diff=lfs merge=lfs -text
|
78 |
+
data/docs/components/ESP8266-01[[:space:]]USB-Stick[[:space:]]DE.pdf filter=lfs diff=lfs merge=lfs -text
|
79 |
+
data/docs/components/KeyboardController.pages filter=lfs diff=lfs merge=lfs -text
|
80 |
+
data/docs/components/PS2Keyboard[[:space:]]Library,[[:space:]]Connect[[:space:]]a[[:space:]]keyboard[[:space:]]for[[:space:]]user[[:space:]]input.pdf filter=lfs diff=lfs merge=lfs -text
|
81 |
+
data/docs/components/Pinout-NANOevery_latest.pdf filter=lfs diff=lfs merge=lfs -text
|
82 |
+
data/docs/components/Programming+the+Wemos+Mega+Wifi+Board.pdf filter=lfs diff=lfs merge=lfs -text
|
83 |
+
data/docs/components/RK-10290_410.pdf filter=lfs diff=lfs merge=lfs -text
|
84 |
+
data/docs/components/SSD1306.pdf filter=lfs diff=lfs merge=lfs -text
|
85 |
+
data/docs/components/SSD1963_v1.6.pdf filter=lfs diff=lfs merge=lfs -text
|
86 |
+
data/docs/components/ThermalprinterSpecs.pdf filter=lfs diff=lfs merge=lfs -text
|
87 |
+
data/docs/components/doc0336.pdf filter=lfs diff=lfs merge=lfs -text
|
88 |
+
data/docs/components/vga32_v1.4.pdf filter=lfs diff=lfs merge=lfs -text
|
89 |
+
data/docs/img/IMG_7220.mov filter=lfs diff=lfs merge=lfs -text
|
90 |
+
data/docs/tutorial/BASIC[[:space:]]on[[:space:]]Arduinos[[:space:]]-[[:space:]]Introduction.epub filter=lfs diff=lfs merge=lfs -text
|
91 |
+
data/docs/tutorial/BASIC[[:space:]]on[[:space:]]Arduinos[[:space:]]-[[:space:]]Introduction.pages filter=lfs diff=lfs merge=lfs -text
|
92 |
+
data/misc/UTFT.pdf filter=lfs diff=lfs merge=lfs -text
|
data/Basic1/IotBasic/IoTBasic.ino
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic1/IotBasic/MANUAL.md
ADDED
@@ -0,0 +1,1975 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Stefan's IoT BASIC in a nutshell
|
2 |
+
|
3 |
+
## Version information
|
4 |
+
|
5 |
+
This manual is for the released version 1.3 of Stefan's IoT BASIC interpreter.
|
6 |
+
|
7 |
+
## BASIC language sets
|
8 |
+
|
9 |
+
This BASIC interpreter is structured in language sets. They can be compiled into the code separately. With every language set there are more features and command. This makes it adaptable to the purpose. The manual is structured according to the language sets.
|
10 |
+
|
11 |
+
The intepreter has two data types - numbers and strings. The number type can be set at compile time. It is either an integer or foating point. Depending on the definition of number_t in the code the interpreter can use everything from 16 bit integers to 64 bit floats as basic number type.
|
12 |
+
|
13 |
+
Arrays and string variables are part of the Apple 1 language sets. Strings are static, i.e. they reserve the entire length of the string on the heap. Depending on the definition of the string index type in the code, strings can be either 255 characters or 65535 characters maximum length.
|
14 |
+
|
15 |
+
Array can be maximum two dimensional and string arrays can be one dimensional.
|
16 |
+
|
17 |
+
Variable names are maximum two letters or one letter and one digit.
|
18 |
+
|
19 |
+
Keywords ad variable names are not case sensitive. They are printed as uppercase with the LIST command. Strings and string constants are case sensitive.
|
20 |
+
|
21 |
+
There is a set of examples program in examples/00tutorial. They are referred to here as "the tutorial".
|
22 |
+
|
23 |
+
As a proof of concept many of the 101 BASIC computer games in David Ahl's original book from 1975 have been ported. Look into examples/14games for some 70s gaming fun.
|
24 |
+
|
25 |
+
Most Arduino built-in examples from https://docs.arduino.cc/built-in-examples/ have been ported to BASIC. They are in examples in the folders 01-10.
|
26 |
+
|
27 |
+
## Core language set
|
28 |
+
|
29 |
+
### Introduction
|
30 |
+
|
31 |
+
The core language set is based on the Palo Alto BASIC language. This is the grandfather of all the Tinybasics currently on the market. Commands are PRINT, LET, INPUT, GOTO, GOSUB, RETURN, IF, FOR, TO, STEP, NEXT, STOP, REM, LIST, NEW, RUN, ABS, INT, RND, SIZE.
|
32 |
+
|
33 |
+
In the core language set there are 26 static variables A-Z and a special array @() which addresses the free memory. If an EEPROM is present or the EEPROM dummy is compiled to the code, the array @E() addresses the EEPROM.
|
34 |
+
|
35 |
+
### PRINT
|
36 |
+
|
37 |
+
PRINT prints a list of expressions and string constants. The separator ';'' causes data to be concatenated while ','' inserts a space. This is different from MS BASIC print where ','' prints into data fields and ';'' inserts spaces is numbers are printed. Formatted printing is supported with the '#' modifier.
|
38 |
+
|
39 |
+
Examples:
|
40 |
+
|
41 |
+
PRINT "Hello World"
|
42 |
+
|
43 |
+
PRINT A, B, C
|
44 |
+
|
45 |
+
PRINT #6, A, B, C
|
46 |
+
|
47 |
+
Tutorial programs: hello.bas and table.bas.
|
48 |
+
|
49 |
+
A positive number aligns to the right Palo Alto BASIC style. A negative number aligns to the right side. Setting #0 removes the format.
|
50 |
+
|
51 |
+
BASIC I/O is stream based. Streams are numbered. The console I/O on a POSIX system or Serial on an Arduino is stream number 1. Other prefefined stream numbers are 2 for displays, 4 for secondary serial and 16 for files. Please look at the file I/O section and the hardware driver chapter for more information.
|
52 |
+
|
53 |
+
Printing to a display would be done with
|
54 |
+
|
55 |
+
PRINT &2, "Hello World"
|
56 |
+
|
57 |
+
while
|
58 |
+
|
59 |
+
PRINT &16, "Hello World"
|
60 |
+
|
61 |
+
prints to a file.
|
62 |
+
|
63 |
+
PRINT ends a line with LF. No CR is sent at the end of a line.
|
64 |
+
|
65 |
+
### LET
|
66 |
+
|
67 |
+
LET assigns an expression to a variable. It can be ommited and is only added to the language set to ensure compatibility. Typical LET statement would be
|
68 |
+
|
69 |
+
LET A=10
|
70 |
+
|
71 |
+
A=B/2+C
|
72 |
+
|
73 |
+
Expression evaluation is done left to right with multiplication and division precedence before addition and subtraction. Comparision have lowest precedence and evalute true to -1 and false to 0. This is not C style boolean logic but closer to the old MS BASIC definition. With this, NOT, AND and OR in the Apple 1 language set can be used as bitwise operators because NOT -1 is 0.
|
74 |
+
|
75 |
+
Strings evaluate to the ASCII value of the first character.
|
76 |
+
|
77 |
+
A="A" : PRINT A
|
78 |
+
|
79 |
+
outputs 65.
|
80 |
+
|
81 |
+
The operator % calculates the integer divisions modulus. Example:
|
82 |
+
|
83 |
+
B=A%2
|
84 |
+
|
85 |
+
to test divisibility.
|
86 |
+
|
87 |
+
### INPUT
|
88 |
+
|
89 |
+
INPUT accepts a list of string constants and variable. String constants are output and variable request a user input. A "?" prompt is only displayed if not string constant has been supplied. Example:
|
90 |
+
|
91 |
+
INPUT "Input a number", A
|
92 |
+
|
93 |
+
INPUT "First number: ", A, "Second number: ", B
|
94 |
+
|
95 |
+
Unlike MS BASIC comma separated lists cannot be used as input values.
|
96 |
+
|
97 |
+
INPUT A, B
|
98 |
+
|
99 |
+
would prompt for two separate number inputs even if two number like e.g. 17,19 are enters after the first prompt. This saves memory. Please look at IOT extension for a way to split lists.
|
100 |
+
|
101 |
+
In version 1.3. INPUT cannot read elements of string arrays. Only not indexed string variables are implemented.
|
102 |
+
|
103 |
+
Like PRINT, the & modifier can be used to specify an input stream.
|
104 |
+
|
105 |
+
INPUT &2, A
|
106 |
+
|
107 |
+
would read data from the keyboard of a Arduino standalone system.
|
108 |
+
|
109 |
+
### GOTO
|
110 |
+
|
111 |
+
GOTO branches to the line number specified. Expressions are accepted. Examples:
|
112 |
+
|
113 |
+
GOTO 100
|
114 |
+
|
115 |
+
GOTO 100+I
|
116 |
+
|
117 |
+
The later statement can be used to program ON GOTO constructs of Dartmouth BASIC.
|
118 |
+
|
119 |
+
BASIC has a line cache and remembers jump targets to speed up the code.
|
120 |
+
|
121 |
+
### GOSUB and RETURN
|
122 |
+
|
123 |
+
GOSUB is identical to GOTO and saves the location after the GOSUB statement to a return stack. RETURN ends the execution of the subroutine.
|
124 |
+
|
125 |
+
The GOSUB stack is shallow with a depth of 4 elements on small Arduinos. This can be increased at compile time.
|
126 |
+
|
127 |
+
### IF
|
128 |
+
|
129 |
+
IF expects an expression and executes the command after it if the condition is true. 0 is interpreted as false and all non zero values as true. Examples:
|
130 |
+
|
131 |
+
IF A=0 GOTO 100
|
132 |
+
|
133 |
+
IF B=A PRINT "Equal"
|
134 |
+
|
135 |
+
There is not THEN in the core language set. THEN is part of the Apple 1 language set.
|
136 |
+
|
137 |
+
### FOR loops
|
138 |
+
|
139 |
+
FOR have the form
|
140 |
+
|
141 |
+
FOR I=1 TO 10 STEP 2: PRINT I: NEXT I
|
142 |
+
|
143 |
+
Specifying the parameter I in NEXT is optional. STEP can be ommited and defaults to STEP 1.
|
144 |
+
|
145 |
+
Unline in other BASIC dialects the loops.
|
146 |
+
|
147 |
+
FOR I=10: PRINT I: NEXT
|
148 |
+
|
149 |
+
and
|
150 |
+
|
151 |
+
FOR I: PRINT I: NEXT
|
152 |
+
|
153 |
+
are legal. They generate infinite loops that can be interrupted with the BREAK command which
|
154 |
+
is part of the extension language set.
|
155 |
+
|
156 |
+
All parameters in FOR loops are evaluated once when the FOR statement is read. FOR loops use the memory location as jump target in NEXT. They are faster than GOTO loops.
|
157 |
+
|
158 |
+
The statement NEXT I, J to terminate two loops is not supported. Each loop needs to have their own NEXT statement.
|
159 |
+
|
160 |
+
### STOP
|
161 |
+
|
162 |
+
STOP stops a program. There is no END in the core language set.
|
163 |
+
|
164 |
+
### REM
|
165 |
+
|
166 |
+
Comment line start with the REM statement. As BASIC tokenizes the entire input, comments should be enclosed in comments. Example:
|
167 |
+
|
168 |
+
10 REM "This is a comment"
|
169 |
+
|
170 |
+
### LIST
|
171 |
+
|
172 |
+
Lists the program lines. Examples:
|
173 |
+
|
174 |
+
LIST
|
175 |
+
|
176 |
+
LIST 10
|
177 |
+
|
178 |
+
LIST 10, 100
|
179 |
+
|
180 |
+
The first statement lists the entire program, the second only line 10. The last statement lists all line between 10 and 100.
|
181 |
+
|
182 |
+
### NEW
|
183 |
+
|
184 |
+
Deletes all variables and the program.
|
185 |
+
|
186 |
+
### RUN
|
187 |
+
|
188 |
+
Starts to run a program. A line can be specified as first line to be executed. RUN deletes all variables and clears the stacks. GOTO linnumber can be used for a warm start of a program.
|
189 |
+
|
190 |
+
### ABS
|
191 |
+
|
192 |
+
Calculates the absolute value of a number. Example:
|
193 |
+
|
194 |
+
A=ABS(B)
|
195 |
+
|
196 |
+
### INT
|
197 |
+
|
198 |
+
Calculates the integer value of a number. Example:
|
199 |
+
|
200 |
+
A=INT(B)
|
201 |
+
|
202 |
+
### RND
|
203 |
+
|
204 |
+
Calculates a random number. The builtin random number generator is a 16/32 bit congruence code and is good enough for games and simple applications but repeats itself rather fast. The argument of the function is the upper bound.
|
205 |
+
|
206 |
+
On an integer BASIC
|
207 |
+
|
208 |
+
PRINT RND(8)
|
209 |
+
|
210 |
+
would produce numbers from 0 to 7, while
|
211 |
+
|
212 |
+
PRINT RND(-8)
|
213 |
+
|
214 |
+
would produce numbers between -8 and -1.
|
215 |
+
|
216 |
+
The random number seed can be changes by using the special variable @R. See the "special variable" section for more information.
|
217 |
+
|
218 |
+
### SIZE
|
219 |
+
|
220 |
+
Outputs the space between the top of the program and the bottom of the variable heap. It is the free memory the interpreter has.
|
221 |
+
|
222 |
+
### Storing programs with SAVE and LOAD
|
223 |
+
|
224 |
+
LOAD and SAVE are part of the core language set if the hardware has a filesystem. On POSIX systems (Mac, Windows, Linux) they take a file name as argument. Default is "file.bas".
|
225 |
+
|
226 |
+
Arduino systems with only EEPROM support save the program to the EEPROM in binary format, overwriting all data on the EEPROM by it.
|
227 |
+
|
228 |
+
If a file system is compiled to the Arduino code. The commands work like on a POSIX system. LOAD "!" and SAVE "!" can be used in these cases to access programs stored in EEPROM.
|
229 |
+
|
230 |
+
File names must be strings. To load a program you need to enter
|
231 |
+
|
232 |
+
LOAD "myprog.bas"
|
233 |
+
|
234 |
+
i.e. with the filename enclosed quotes.
|
235 |
+
|
236 |
+
### Special variables and arrays
|
237 |
+
|
238 |
+
The character @ is a valid first character in variable names and addresses special variables. These variables give access to system properties.
|
239 |
+
|
240 |
+
@() is an array of numbers starting from the top of memory down to the program area. It can be used like any other array in BASIC. Indexing starts at 1.
|
241 |
+
|
242 |
+
@ is the upper array boundary of the array @() i.e. the number of elements in the array.
|
243 |
+
|
244 |
+
The program area is protected by BASIC. The maximum index prevents a program to overwrite the program.
|
245 |
+
|
246 |
+
@E() is the EEPROM array. It indexes the entire EEPROM area down from the highest address.
|
247 |
+
|
248 |
+
@E is the number of elements in the EEPROM array. Unlike with the memory array @() there is no protection of saved programs in the EEPROM. @E() can overwrite the program space.
|
249 |
+
|
250 |
+
@R is the random number seed. It can be written and read.
|
251 |
+
|
252 |
+
@O is the currently active output stream.
|
253 |
+
|
254 |
+
@I is the currently active input stream.
|
255 |
+
|
256 |
+
@C is the next character of the input stream or output stream.
|
257 |
+
|
258 |
+
@A is the number of available character of the current input stream.
|
259 |
+
|
260 |
+
@S is the I/O error status. See the file I/O section for more information on it.
|
261 |
+
|
262 |
+
@V is the number of characters processed in VAL().
|
263 |
+
|
264 |
+
@U is the user variable. It can be used to extend BASIC.
|
265 |
+
|
266 |
+
The variables @O, @I, @C, and @A can be used for byte I/O on any stream.
|
267 |
+
|
268 |
+
The array @T() is the real time clock array. @T$ is a string containing date and time. See the hardware drivers section for more information.
|
269 |
+
|
270 |
+
The string @A$ is the command line argument on POSIX systems. See the hardware section for more details.
|
271 |
+
|
272 |
+
## Apple 1 language set
|
273 |
+
|
274 |
+
### Introduction
|
275 |
+
|
276 |
+
The Apple 1 language set is based on an early version of the Apple Integer BASIC. I never worked with the language and just took the information from the the manual. The language set adds many useful features like arrays, strings, two letter variables, boolean expressions and a few functions.
|
277 |
+
|
278 |
+
### Variables
|
279 |
+
|
280 |
+
In addition to the static variable A-Z all two letter combinations which are not a keyword are legal variable names. Examples:
|
281 |
+
|
282 |
+
A0, BX, TT
|
283 |
+
|
284 |
+
Variables are placed on a heap that is searched every time a variable is used. Variables which are used often should be initialised early in the code. This makes BASIC programs faster. Static variables A-Z are accessed approximately 30% faster than heap variables. They should be used for loops.
|
285 |
+
|
286 |
+
### Strings
|
287 |
+
|
288 |
+
String variables can also have two characters followed by the $ symbol. Example:
|
289 |
+
|
290 |
+
ME$="Hello World"
|
291 |
+
|
292 |
+
Unlike in the original Apple 1 BASIC, strings can be used without explicitely dimensioning them. They are auto dimensioned to length 32. Strings are static. The entire space is allocated on the heap and stays reserved. This is very different from MS BASIC with a dynamic heap. The saves memory but requires a garbage collector. Static strings like in this BASIC need more memory but make the execution of time critical code more deterministic.
|
293 |
+
|
294 |
+
A string can be dimensioned with DIM to any length. Example:
|
295 |
+
|
296 |
+
DIM A\$(100), C\$(2)
|
297 |
+
|
298 |
+
A string of maximum 100 bytes and a string of 2 bytes are created. The maximum length of a string is 65535 in the default settings of the code. See the hardware section of the manual for more information on this.
|
299 |
+
|
300 |
+
Strings are arrays of signed integer. String handling is done through the substring notation. Example:
|
301 |
+
|
302 |
+
A\$="Hello World"
|
303 |
+
|
304 |
+
PRINT A\$(1,4), A\$(6,6), A\$(6)
|
305 |
+
|
306 |
+
yields
|
307 |
+
|
308 |
+
Hello W World
|
309 |
+
|
310 |
+
as an output.
|
311 |
+
|
312 |
+
Substrings can be the lefthandside of an expression
|
313 |
+
|
314 |
+
A\$="Hello World"
|
315 |
+
|
316 |
+
A\$(12)=" today"
|
317 |
+
|
318 |
+
PRINT A\$
|
319 |
+
|
320 |
+
outputs
|
321 |
+
|
322 |
+
Hello world today
|
323 |
+
|
324 |
+
Please look into the tutorial files string1.bas - string3.bas for more information. The commands LEFT\$, RIGHT\$, and MID\$ do not exist and are not needed.
|
325 |
+
|
326 |
+
The length of a string can be found with the LEN command. Example:
|
327 |
+
|
328 |
+
A\$="Hello"
|
329 |
+
|
330 |
+
PRINT LEN(A\$)
|
331 |
+
|
332 |
+
String arrays are possible if the BASIC interpreter is compiled with the respective option. This is an extension of the Apple 1 language set.
|
333 |
+
|
334 |
+
### Arrays
|
335 |
+
|
336 |
+
Arrays are autodimensioned to length 10. They start with index 1. If a different array length is needed the DIM command can be used. Example:
|
337 |
+
|
338 |
+
DIM A(100)
|
339 |
+
|
340 |
+
Array variables can be used like normal variables except that they cannot be active variables in a FOR loop.
|
341 |
+
|
342 |
+
Compiled with the multidim options arrays can be two dimensional. This is an extension of the Apple 1 language set.
|
343 |
+
|
344 |
+
Arrays range from 1 to the maximum index by default. The statement above reserves array elements from A(1) to A(100).
|
345 |
+
|
346 |
+
With
|
347 |
+
|
348 |
+
SET 12,0
|
349 |
+
|
350 |
+
the array lower bound can be changed to 0. The array ranges from A(0) to A(99) now. It still has 100 elements. SET 12 can be used to set any postive lower bound. This holds for all arrays except the special arrays starting with @. It can be changed at any time as SET 12 only modifies the offset but not the memory location.
|
351 |
+
|
352 |
+
### Logical expressions NOT, AND, OR
|
353 |
+
|
354 |
+
Logical operators NOT, AND, and OR have lowest precedence. They are at the same time bitwise logical operations on integers. Example:
|
355 |
+
|
356 |
+
PRINT NOT 0
|
357 |
+
|
358 |
+
yields -1 which is an integer with all bits set. Logical expressions like
|
359 |
+
|
360 |
+
IF A=10 AND B=11 THEN PRINT "Yes"
|
361 |
+
|
362 |
+
can be formed.
|
363 |
+
|
364 |
+
### Memory access with PEEK and POKE
|
365 |
+
|
366 |
+
PEEK is a function which reads one byte of BASIC memory. Example:
|
367 |
+
|
368 |
+
PRINT PEEK(0)
|
369 |
+
|
370 |
+
outputs the first byte of BASIC memory.
|
371 |
+
|
372 |
+
POKE writes a byte of memory. Example:
|
373 |
+
|
374 |
+
POKE 1024, 0
|
375 |
+
|
376 |
+
If PEEK and POKE are used with negative numbers they address the EEPROM of an Arduino. -1 is the first memory cell of the EEPROM. Peek and poke return bytes as signed 8 bit integers.
|
377 |
+
|
378 |
+
### THEN
|
379 |
+
|
380 |
+
THEN is added for comaptibity reasons. Typical statements would be
|
381 |
+
|
382 |
+
IF A=0 THEN PRINT "Zero"
|
383 |
+
|
384 |
+
IF B=10 THEN 100
|
385 |
+
|
386 |
+
### END
|
387 |
+
|
388 |
+
END ends a program. On systems with EEPROM dummies in flash memory, END also flushed the buffer. On system with file operations, END flushed the file buffers.
|
389 |
+
|
390 |
+
### CLR
|
391 |
+
|
392 |
+
CLR removes all variables and stacks.
|
393 |
+
|
394 |
+
### HIMEM
|
395 |
+
|
396 |
+
HIMEM is the topmost free memory cell. The difference SIZE-HIMEM is the size of the stored program.
|
397 |
+
|
398 |
+
### TAB
|
399 |
+
|
400 |
+
TAB outputs n whitespace characters. Example:
|
401 |
+
|
402 |
+
TAB 20: PRINT "Hello"
|
403 |
+
|
404 |
+
### SGN
|
405 |
+
|
406 |
+
The SGN function is 1 for positive arguments and -1 for negative arguments. SGN(0)=0.
|
407 |
+
|
408 |
+
### Multidim and String Array capability
|
409 |
+
|
410 |
+
If BASIC is compiled with the HASMULTIDIM option, arrays can be twodimensional. Example:
|
411 |
+
|
412 |
+
DIM A(8,9)
|
413 |
+
|
414 |
+
A(5,6)=10
|
415 |
+
|
416 |
+
The compile option HASSTRINGARRAYS activates one dimensional string arrays.
|
417 |
+
|
418 |
+
DIM A\$(32,10)
|
419 |
+
|
420 |
+
dimensions an array of 10 strings of length 32. Assignments are done use double subscripts
|
421 |
+
|
422 |
+
A\$()(3)="Hello"
|
423 |
+
|
424 |
+
A\$()(4)="World"
|
425 |
+
|
426 |
+
PRINT A\$()(3), A\$()(4)
|
427 |
+
|
428 |
+
outputs
|
429 |
+
|
430 |
+
Hello World
|
431 |
+
|
432 |
+
The first pair of parentheses are the substring part and the second pair the array index.
|
433 |
+
|
434 |
+
## Stefan's extension language set
|
435 |
+
|
436 |
+
### Introduction
|
437 |
+
|
438 |
+
The language extensions here are things I found useful and that were missing in Apple Integer BASIC. They are rather simple extensions of the language.
|
439 |
+
|
440 |
+
### FOR loops with CONT and BREAK
|
441 |
+
|
442 |
+
FOR loops can be ended with BREAK. Example:
|
443 |
+
|
444 |
+
10 FOR I=1 TO 10
|
445 |
+
|
446 |
+
20 PRINT I
|
447 |
+
|
448 |
+
30 IF I=8 THEN BREAK
|
449 |
+
|
450 |
+
40 NEXT
|
451 |
+
|
452 |
+
will end the loop after the 8th iteration. BREAK always ends the innermost loop just like the C break command.
|
453 |
+
|
454 |
+
Alternatively CONT can be used to move forward in a loop. Example:
|
455 |
+
|
456 |
+
10 FOR I=1 TO 10
|
457 |
+
|
458 |
+
20 IF I%2=0 THEN CONT
|
459 |
+
|
460 |
+
30 PRINT I
|
461 |
+
|
462 |
+
40 NEXT
|
463 |
+
|
464 |
+
will only display the odd values. CONT skips the entire rest of the loop and skips to the next I.
|
465 |
+
|
466 |
+
Using CONT and BREAK reduces the number of GOTO statements in a program and makes them more readable.
|
467 |
+
|
468 |
+
### Command line CONT
|
469 |
+
|
470 |
+
In interactive mode, CONT has a different function. It restarts a program previously stopped with STOP.
|
471 |
+
|
472 |
+
### ELSE
|
473 |
+
|
474 |
+
ELSE can be used after THEN in one line.
|
475 |
+
|
476 |
+
IF A=0 THEN PRINT "Zero" ELSE PRINT "Not zero"
|
477 |
+
|
478 |
+
In programs ELSE can also be on the subsequent line
|
479 |
+
|
480 |
+
10 IF A=0 THEN PRINT "Zero"
|
481 |
+
|
482 |
+
20 ELSE PRINT "Not zero"
|
483 |
+
|
484 |
+
### Character output with PUT and GET
|
485 |
+
|
486 |
+
Single characters can be written and read with the PUT and GET statement. Like PRINT and INPUT, these commands can take the I/O stream as an argument after the & modifier. Example:
|
487 |
+
|
488 |
+
GET &2, A
|
489 |
+
|
490 |
+
reads a character into variable A from the keyboard I/O stream.
|
491 |
+
|
492 |
+
PUT &2, "H", 65
|
493 |
+
|
494 |
+
writes to characters to the display I/O stream. The behaviour of PUT and GET is hardware dependent. On Arduinos they are non blocking byte streams. On POSIX systems GET is blocking input.
|
495 |
+
|
496 |
+
### Low level functions USR
|
497 |
+
|
498 |
+
USR is a two argument function accessing system properties. See the program hinv.bas in the tutorial for examples. USR can also be used to quickly add functionality to the interpreter. This will be explained in the hardware section of the manual.
|
499 |
+
|
500 |
+
Example for USR:
|
501 |
+
|
502 |
+
PRINT "The EEPROM size is ", USR(0,10)
|
503 |
+
|
504 |
+
### Low level calls CALL
|
505 |
+
|
506 |
+
CALL expects a numerical expression as an argumen. Currently only CALL 0 is implemented. It flushes all open files and ends the interpreter on POSIX systems. On Arduinos CALL 0 restarts the interpreter.
|
507 |
+
|
508 |
+
### Setting system properties with SET
|
509 |
+
|
510 |
+
SET is a two argument function setting system property. Please look into the hardware section of the manual for more information.
|
511 |
+
|
512 |
+
Example:
|
513 |
+
|
514 |
+
SET 0, 1
|
515 |
+
|
516 |
+
activates the debug mode of the interpreter.
|
517 |
+
|
518 |
+
SET 0, 0
|
519 |
+
|
520 |
+
ends the debug mode.
|
521 |
+
|
522 |
+
### SQR
|
523 |
+
|
524 |
+
On an integer BASIC the function calculates an integer approximation of the square root. It is the number closest to the exact result. It can be larger or smaller then the exact result. Example:
|
525 |
+
|
526 |
+
PRINT SQR(8)
|
527 |
+
|
528 |
+
In floating point system the library function is used.
|
529 |
+
|
530 |
+
See math.bas in the tutorial for more information.
|
531 |
+
|
532 |
+
### POW
|
533 |
+
|
534 |
+
This two argument function calulates the n-th power of a number. It replaces the '^' operator of some BASIC dialects. Example:
|
535 |
+
|
536 |
+
PRINT POW(2,4)
|
537 |
+
|
538 |
+
In integer systems POW calculates the result in a loop. It returns 0 for negative arguments of the exponent. In floating point systems the C function pow() is used and the result is returned.
|
539 |
+
|
540 |
+
See math.bas in the tutorial for more information.
|
541 |
+
|
542 |
+
### MAP
|
543 |
+
|
544 |
+
MAP is taken from the Arduino library. It maps an integer in a certain range to another ranges using (at least) 32 bit arithmetic. This is useful on 16 bit integer systems. Example:
|
545 |
+
|
546 |
+
M=MAP(V, 1000, 0, 200, 100)
|
547 |
+
|
548 |
+
maps the variable V from the range 0 to 1000 to the range 100 to 200.
|
549 |
+
|
550 |
+
See math.bas in the tutorial for more information.
|
551 |
+
|
552 |
+
### CLS
|
553 |
+
|
554 |
+
Clears the screen on display systems. See VT52 capabilities for more information.
|
555 |
+
|
556 |
+
### Debugging with DUMP
|
557 |
+
|
558 |
+
DUMP writes a memory and EEPROM range to the output. Example:
|
559 |
+
|
560 |
+
DUMP 0, 100
|
561 |
+
|
562 |
+
writes the first 100 bytes of the program memory.
|
563 |
+
|
564 |
+
DUMP !0, 100
|
565 |
+
|
566 |
+
writes the first 100 bytes of the EEPROM.
|
567 |
+
|
568 |
+
### Error Message capability
|
569 |
+
|
570 |
+
Error messages are stored in Arduino program memory. For systems with low program memory undefining the #HASERRORMSG flag removes explicit error messages.
|
571 |
+
|
572 |
+
### Terminal emulation and VT52 capability on display systems
|
573 |
+
|
574 |
+
BASIC has a minimal set of terminal control characters build in. Compiling the code with the HASVT52 option adds a subset of the VT52 terminal commands for systems with displays.
|
575 |
+
|
576 |
+
Most importantly
|
577 |
+
|
578 |
+
PUT &2, 12
|
579 |
+
|
580 |
+
clears the screen.
|
581 |
+
|
582 |
+
The special variables @X, @Y contain the cursor position. The variables are read write.
|
583 |
+
|
584 |
+
@X=10: @Y=10: PUT "X"
|
585 |
+
|
586 |
+
would write the letter X at position 10, 10.
|
587 |
+
|
588 |
+
The array @D() is the display character buffer by column and row. It is also read write and can be used to display characters directly.
|
589 |
+
|
590 |
+
Please look into the hardware section for the display driver commands.
|
591 |
+
|
592 |
+
## Arduino I/O language set
|
593 |
+
|
594 |
+
### Introduction
|
595 |
+
|
596 |
+
Most of the standard Arduino I/O functions are available on BASIC. The Arduino standard examples have been ported to BASIC to showcase how they are used. Please look into the repo under examples/01basics to examples/10starter for these programs.
|
597 |
+
|
598 |
+
### PINM
|
599 |
+
|
600 |
+
PINM sets a pin to input, output, or input-pullup. Example:
|
601 |
+
|
602 |
+
PINM 10, 0
|
603 |
+
|
604 |
+
PINM 11, 1
|
605 |
+
|
606 |
+
PINM 12, 2
|
607 |
+
|
608 |
+
sets pin 10 to input, pin 11 to output, and pin 12 to input with the pullup active. The values for the second argument may be implementation specific. Some microcontroller cores use additional values. The number given in BASIC is directly handed through to the pinMode() C++ function.
|
609 |
+
|
610 |
+
### DWRITE, DREAD, and LED
|
611 |
+
|
612 |
+
Digital I/O is done with DWRITE and DREAD. Examples:
|
613 |
+
|
614 |
+
DWRITE 11, 1
|
615 |
+
|
616 |
+
A=DREAD(10)
|
617 |
+
|
618 |
+
sets pin 11 to high and reads the value of pin 10 to variable A.
|
619 |
+
|
620 |
+
The constant LED is the builtin LED on system. This can be microcontroller dependent.
|
621 |
+
|
622 |
+
PINM LED, 1
|
623 |
+
|
624 |
+
DWRITE LED, 1
|
625 |
+
|
626 |
+
lights the buildin led.
|
627 |
+
|
628 |
+
### AWRITE, AREAD, and AZERO
|
629 |
+
|
630 |
+
For analog I/O the command AWRITE and the function AREAD can be used. The pin number in these commands has to be the low level pin code of the microcontroller. For Arduino AVR systems the lowest analog pin number is the pin after the highest digital pin. On an UNO this is 14. The constant AZERO is the number of the lowest analog pin. Example:
|
631 |
+
|
632 |
+
PINM AZERO, 1
|
633 |
+
|
634 |
+
PINM AZERO+1, 1
|
635 |
+
|
636 |
+
PINM AZERO+2, 0
|
637 |
+
|
638 |
+
sets the analog pin a0 and a1 of an Arduino to output and the pin a2 to input.
|
639 |
+
|
640 |
+
AWRITE AZERO, 100
|
641 |
+
|
642 |
+
AWRITE AZERO+1, 200
|
643 |
+
|
644 |
+
V=AREAD(AZERO+2)
|
645 |
+
|
646 |
+
write 100 to pin a0, 200 to pin a1 and reads pin a2.
|
647 |
+
|
648 |
+
Pin numbering can be tricky. More information can be found in the hardware section.
|
649 |
+
|
650 |
+
### Timing with MILLIS and DELAY
|
651 |
+
|
652 |
+
DELAY triggers a delay of n ms. Example:
|
653 |
+
|
654 |
+
DELAY 1000
|
655 |
+
|
656 |
+
waits for one second.
|
657 |
+
|
658 |
+
The function MILLIS measures the time in milliseconds divided by a divisor. Example:
|
659 |
+
|
660 |
+
A=MILLIS(1)
|
661 |
+
|
662 |
+
B=MILLIS(1000)
|
663 |
+
|
664 |
+
A contains the time since start in milliseconds. B is the time since start in seconds. The divisor can be used in 16 bit systems to control overflow of a variable.
|
665 |
+
|
666 |
+
### PULSE and PLAY extensions
|
667 |
+
|
668 |
+
Two more compley Arduino I/O function are available from BASIC.
|
669 |
+
|
670 |
+
PULSE reads a pulse on a pin if used as a function. The first argument is the pin number, the second whether a LOW=0 or HIGH=1 state is expected. The third argument is the timeout in milliseconds. Note the difference to the original Arduino pulseIN(). The low level Arduino commands delivers the pulse length in microseconds. PULSE delivers the pulse length in 10 microsecond units to be compatible with integer BASIC number ranges. Example:
|
671 |
+
|
672 |
+
A=PULSE(4, 0, 100)
|
673 |
+
|
674 |
+
PULSE was named PULSEIN in ealier vesions of BASIC. This was changed in version 1.4.
|
675 |
+
|
676 |
+
As a command, PULSE writes pulses on a pin. Example:
|
677 |
+
|
678 |
+
PULSE 4, 10
|
679 |
+
|
680 |
+
writes a 100 microsecond pulse on pin 4. Optional arguments are the value the pin is to be changed. Default is 1 assuming that the pin has been set to 0 before. Example:
|
681 |
+
|
682 |
+
DWRITE 4, 1
|
683 |
+
|
684 |
+
PULSE 4, 10, 0
|
685 |
+
|
686 |
+
writes a 100 microsecond LOW pulse to the pin and then sets the pin again to HIGH=1.
|
687 |
+
|
688 |
+
An number of repetitions and an intervall can be specified as well. Example:
|
689 |
+
|
690 |
+
PULSE 4, 1, 1, 10, 100
|
691 |
+
|
692 |
+
writes 10 pulses with 1000 ms time difference of length 10 microseconds on pin 4.
|
693 |
+
|
694 |
+
The time unit of PULSE can be changes with SET 14, timeunit. Example:
|
695 |
+
|
696 |
+
SET 14, 1
|
697 |
+
|
698 |
+
sets the unit PULSE uses to 1 microsecond.
|
699 |
+
|
700 |
+
PLAY is a wrapper around the Arduino tone() function for Arduino systems. For ESP32 VGA systems it is mapped to the sound generator function of the FabGL library. More information on this can be found in the hardware section.
|
701 |
+
|
702 |
+
## File I/O language set
|
703 |
+
|
704 |
+
### Introduction
|
705 |
+
|
706 |
+
For systems with a filesystem there is a set of file access commands. Only one directory is supported. The file system command cannot handle subdirectories. One open file for read and one open file for write or append is supported. The file I/O commands mask the different underlying filesystems. Currently EEPROM EFS, SD, ESPSPIFFS and LittleFS are supported. Look for more information in the hardware section.
|
707 |
+
|
708 |
+
### Opening and closing files with OPEN and CLOSE
|
709 |
+
|
710 |
+
Files are opened with the OPEN command. Open needs a filename and optionally a file open mode as argument. As a file open mode 0 is read, 1 is write and 2 is append. Read mode is the default is no argument is given. Examples:
|
711 |
+
|
712 |
+
OPEN "data.txt"
|
713 |
+
|
714 |
+
OPEN "data.txt", 0
|
715 |
+
|
716 |
+
OPEN "temp.txt", 1
|
717 |
+
|
718 |
+
OPEN "append.txt", 2
|
719 |
+
|
720 |
+
The first two commands are equivalent, the file "data.txt" is opened for read. The second line opens "temp.txt" for write. A new file is created if it doesn't exist. If the file exists writing starts at the beginning and existing data is overwritten. The third commands opens the file for append.
|
721 |
+
|
722 |
+
File name lengths are filesystem specific. The maximum length in BASIC is 32 characters.
|
723 |
+
|
724 |
+
Files that have been written need to be closed not to lose the data. CLOSE without an argument closes the read file. This is not really necessary. CLOSE 1 or CLOSE 2 close the write file. Opening a new file automatically closes an open file.
|
725 |
+
|
726 |
+
OPEN and CLOSE and be used to open and close other I/O streams as well. For this, a file modifier can be added. Example:
|
727 |
+
|
728 |
+
OPEN &7, 64, 1
|
729 |
+
|
730 |
+
This command opens the Wire stream for write addressing the device 64 as a target.
|
731 |
+
|
732 |
+
If the modifier & is ommited, it is always assumed that the file stream &16 is meant.
|
733 |
+
|
734 |
+
See the hardware section for more information on supported filesystems.
|
735 |
+
|
736 |
+
### DOS commands CATALOG, DELETE, FDISK
|
737 |
+
|
738 |
+
CATALOG lists the files in the filesystem. Am optional string pattern can be used to list only file that begin with it. Example:
|
739 |
+
|
740 |
+
CATALOG
|
741 |
+
|
742 |
+
CATALOG "da"
|
743 |
+
|
744 |
+
The first command lists all file, the second one all file beginning with the pattern "da".
|
745 |
+
|
746 |
+
DELETE deletes one file. The name has to match exactly. No pattern matching is supported.
|
747 |
+
|
748 |
+
FDISK formats a file system. This is not supported for all file systems. Arguments depend on the hardware implementation. Please look in the hardware section for more information.
|
749 |
+
|
750 |
+
### Reading and writing with INPUT, PRINT, and the error variable @S
|
751 |
+
|
752 |
+
Files can be written and read with PRINT and INPUT adding the file stream modifier. The I/O stream number for files is 16. Example:
|
753 |
+
|
754 |
+
PRINT &16, "Hello World"
|
755 |
+
|
756 |
+
writes "Hello World" to the open write file.
|
757 |
+
|
758 |
+
INPUT &16, A\$
|
759 |
+
|
760 |
+
reads the string A\$ from the file. INPUT can have comma seperated arguments. Each variable expects the input in a new line of the file. Like for in console input, INPUT does not split the I/O. Example:
|
761 |
+
|
762 |
+
INPUT &16, A, B
|
763 |
+
|
764 |
+
would read the first line of the file as a number into variable A and the second line into variable B.
|
765 |
+
|
766 |
+
I/O operations ususally report no errors on the console and keep the the program running if an error occurs. The variable @S contains the error status of the operation. @S has to be reset explicitly before using it because it remembers and error status of previous operations and is never reset by the interpreter. Example:
|
767 |
+
|
768 |
+
@S=0
|
769 |
+
|
770 |
+
INPUT &16, A$
|
771 |
+
|
772 |
+
IF @S=-1 THEN PRINT "End of file reached"
|
773 |
+
|
774 |
+
@S takes the value -1 for the end of file condition. For general error it takes the value 1.
|
775 |
+
|
776 |
+
Tutorial: fileio.bas
|
777 |
+
|
778 |
+
### Character IO with GET and PUT
|
779 |
+
|
780 |
+
Like PRINT and INPUT, the byte I/O command can take a stream modifier. Example:
|
781 |
+
|
782 |
+
GET &16, A
|
783 |
+
|
784 |
+
would read one byte from the file putting the signed ASCII value to variable A.
|
785 |
+
|
786 |
+
## Float language set
|
787 |
+
|
788 |
+
### Introduction
|
789 |
+
|
790 |
+
Floating point arithemtic is taken from the standard C float library of the platform. The size of the numbers is the size of the base type number_t in the C code. It is set to float as a default but can be changed to double.
|
791 |
+
|
792 |
+
### SIN, COS, TAN, ATAN
|
793 |
+
|
794 |
+
The trigonometric function are standard BASIC. They are using radians as angle format. Examples:
|
795 |
+
|
796 |
+
PI=4* ATAN(1)
|
797 |
+
|
798 |
+
PRINT SIN(PI)* SIN(PI)+COS(PI)* COS(PI)
|
799 |
+
|
800 |
+
PI is not a predefined constant but can be calculated using ATAN. The second line should output 1.
|
801 |
+
|
802 |
+
Tutorial: trig.bas
|
803 |
+
|
804 |
+
### LOG and EXP
|
805 |
+
|
806 |
+
LOG is the natural logarithm and EXP the exponantial function.
|
807 |
+
|
808 |
+
Tutorial: stir.bas
|
809 |
+
|
810 |
+
### Floating point precision
|
811 |
+
|
812 |
+
Floating point numbers are displayed as integers if they are smaller then 1e8. Numbers from 1e8 on are displayed in exponential notation. Numbers smaller then 1e-8 are also displayed in exponential notation.
|
813 |
+
|
814 |
+
The biggest accurate integer in a 32 bit float is 16777216. The number can be recalled in BASIC by USR(0, 5).
|
815 |
+
|
816 |
+
## Dartmouth language set
|
817 |
+
|
818 |
+
### Introduction
|
819 |
+
|
820 |
+
Since the early days of BASIC there were a few language features which I summarized as Dartmouth extension. DATA and DEF were in the First Edition of Dartmouth BASIC in the early 1960. ON appeared in the Fourth Edition in 1968.
|
821 |
+
|
822 |
+
### DATA, READ, and RESTORE
|
823 |
+
|
824 |
+
Data statements can be anywhere in the program. Data items can be strings or numbers. Example:
|
825 |
+
|
826 |
+
10 DATA "Hello", 3.141, "A"
|
827 |
+
|
828 |
+
READ A\$ : PRINT A\$
|
829 |
+
|
830 |
+
READ A: PRINT A
|
831 |
+
|
832 |
+
READ C: PRINT C
|
833 |
+
|
834 |
+
Will print
|
835 |
+
|
836 |
+
Hello
|
837 |
+
|
838 |
+
3.141
|
839 |
+
|
840 |
+
65
|
841 |
+
|
842 |
+
Strings have to be in quotes. Reading data with the READ command converts the data in the same way than the assignment commands. Strings reading numbers with contain the respective ASCII character. Numbers reading strings will contain the numerical ASCII code.
|
843 |
+
|
844 |
+
Unlike other BASIC versions, reading past the end of DATA will not lead to an error. The status variable @S will contain the value 1 once one reads past the last DATA item. @S is to reset explicitely after this.
|
845 |
+
|
846 |
+
RESTORE resets the data pointer.
|
847 |
+
|
848 |
+
From BASIC v1.4 on argument lists are also supported in READ.
|
849 |
+
|
850 |
+
In READ, the two index substring notation like A\$(3,3) is not yet supported. READ will interpret this as A\$(3) and append the read string.
|
851 |
+
|
852 |
+
RESTORE can also be used with an argument. In the code segment
|
853 |
+
|
854 |
+
10 RESTORE 3
|
855 |
+
|
856 |
+
20 READ A: PRINT A
|
857 |
+
|
858 |
+
30 DATA 1, 4, 9, 16
|
859 |
+
|
860 |
+
the READ statement will access the third argument of the DATA list, hence the output will be 9.
|
861 |
+
|
862 |
+
DATA can be used in expressions. After the code above has run
|
863 |
+
|
864 |
+
PRINT DATA
|
865 |
+
|
866 |
+
will output 4 indicating that the data pointer will read the 4th argument after the next read. This feature can be used to store a position of the DATA list and then return to it.
|
867 |
+
|
868 |
+
10 R=DATA
|
869 |
+
|
870 |
+
20 ... some lines doing many READs
|
871 |
+
|
872 |
+
100 RESTORE R
|
873 |
+
|
874 |
+
the data pointer will be reset to the original position before reading was done.
|
875 |
+
|
876 |
+
Tutorial: readdata.bas
|
877 |
+
|
878 |
+
### DEF FN
|
879 |
+
|
880 |
+
Functions can have one numerical argument and a two character name. Example:
|
881 |
+
|
882 |
+
10 DEF FN TK(X) = X+SIN(X)
|
883 |
+
|
884 |
+
Functions have to be DEFed before use.
|
885 |
+
|
886 |
+
Tutorial: func.bas
|
887 |
+
|
888 |
+
### ON
|
889 |
+
|
890 |
+
ON is used in combination with GOTO or GOSUB arguments. Examples:
|
891 |
+
|
892 |
+
10 ON X GOTO 100,200,300
|
893 |
+
|
894 |
+
Tutorial: ongo.bas
|
895 |
+
|
896 |
+
## Darkarts language set
|
897 |
+
|
898 |
+
### Introduction
|
899 |
+
|
900 |
+
The dark arts language set contain a set of command which can cause evil. BASIC is a beginner language and protects the user from dangerous things. This makes it somehow rigid. The three dark arts commands give access to the inner working of the heap and the program storage. They have side effects and can destroy a running program. CLR is extended in dark arts. It can delete variables from the heap.
|
901 |
+
|
902 |
+
### MALLOC
|
903 |
+
|
904 |
+
MALLOC allocates a junk of memory on the heap and returns the address. The function receives two arguments. One is the identifier. It is a 16 bit integer. The second argument is the number of bytes to be reserved. Example:
|
905 |
+
|
906 |
+
A = MALLOC(1, 64)
|
907 |
+
|
908 |
+
This reserves 64 bytes which can be accessed with PEEK and POKE as 8 bit signed integers.
|
909 |
+
|
910 |
+
MALLOC helps to reserve storage in a controlled way. It is no side effects and can be used savely as long as the POKEs stay within the allocated range.
|
911 |
+
|
912 |
+
Tutorial: malloc.bas
|
913 |
+
|
914 |
+
### FIND
|
915 |
+
|
916 |
+
FIND finds a memory segement on the heap. It can be used to find memory segements allocated with MALLOC but it also finds variables, strings and arrays.
|
917 |
+
|
918 |
+
In all of these examples the argument of the function is the name of an object and not an expression. It has to be the pure string or array without any subscripts.
|
919 |
+
|
920 |
+
All heap variables can be searched. Example:
|
921 |
+
|
922 |
+
A0=10
|
923 |
+
|
924 |
+
PRINT FIND(A0)
|
925 |
+
|
926 |
+
This command outputs the address of the variable A0. The variable is stored with the least significant byte first. The size of the variable area is the size of number_t. It is 2 bytes for integer BASICs and 4 bytes for floating point BASICs.
|
927 |
+
|
928 |
+
Arrays are searched by specifiying the array name without arguments. Example:
|
929 |
+
|
930 |
+
DIM A(8)
|
931 |
+
|
932 |
+
PRINT FIND(A())
|
933 |
+
|
934 |
+
Arrays are stored like variables with the lowest array element first.
|
935 |
+
|
936 |
+
Strings can be searched as well. Example:
|
937 |
+
|
938 |
+
A\$="Hello World"
|
939 |
+
|
940 |
+
PRINT FIND(A\$)
|
941 |
+
|
942 |
+
This command outputs the address of a string. If A$ is a pure string and not a string array, the first byte is the least significant byte of the length of the string. The second byte is the most significant byte of the length for 16 bit strings. All following bytes are payload. Strings are not necessarily 0 terminated. One has to process the length in all code accessing strings directly.
|
943 |
+
|
944 |
+
If a memory segment allocated with MALLOC needs to be searched, a numerical expression can be specified. Example:
|
945 |
+
|
946 |
+
A = MALLOC(1, 64)
|
947 |
+
|
948 |
+
PRINT FIND(1)
|
949 |
+
|
950 |
+
If the segment to be searched is stored in a variable, FIND has to be called like in this example:
|
951 |
+
|
952 |
+
M=1
|
953 |
+
|
954 |
+
PRINT FIND((M))
|
955 |
+
|
956 |
+
Note the inner braces around M. They are needed here as they trigger expression evaluation. This is unusual for BASIC interpreters.
|
957 |
+
|
958 |
+
FIND itself has no side effects but POKEing around in the heap area can kill the interpreter if the structure of the heap list is destroyed.
|
959 |
+
|
960 |
+
Tutorial: find.bas
|
961 |
+
|
962 |
+
### EVAL
|
963 |
+
|
964 |
+
EVAL adds a new line to the BASIC code at runtime. Doing so has many side effects and EVAL does not protect you in any way. Examples:
|
965 |
+
|
966 |
+
10 EVAL 20, "PRINT X"
|
967 |
+
|
968 |
+
20 PRINT "Hello World"
|
969 |
+
|
970 |
+
RUN
|
971 |
+
|
972 |
+
LIST
|
973 |
+
|
974 |
+
In the examples above line 20 is replaced by the string in the EVAL command.
|
975 |
+
|
976 |
+
EVAL includes the line to the program heap. This changes memory addresses of all code behind the inserted line. FOR loops, GOSUB commands, the linenumber cache and READ/DATA statements use plain memory addresses. This means that the DATA pointer, all active FOR loops and active GOSUBs break. A safe way to use EVAL is to change only lines further down in the code outside of any active FOR loop and to RESTORE the DATA pointer after EVAL.
|
977 |
+
|
978 |
+
See eval.bas in the tutorial for more information.
|
979 |
+
|
980 |
+
### CLR
|
981 |
+
|
982 |
+
In the standard language sets CLR deletes all variables and resets stacks and caches. With dark arts enables it is extended to delete variables from the heap. Example:
|
983 |
+
|
984 |
+
10 DIM A(10)
|
985 |
+
|
986 |
+
20 CLR A()
|
987 |
+
|
988 |
+
30 DIM A(20)
|
989 |
+
|
990 |
+
In this example the array A() is deleted and can be redefined.
|
991 |
+
|
992 |
+
All variables defined after A() are also deleted. Example:
|
993 |
+
|
994 |
+
10 DIM A(10)
|
995 |
+
|
996 |
+
20 B$="Hello World"
|
997 |
+
|
998 |
+
30 CLR A()
|
999 |
+
|
1000 |
+
40 DIM A(20)
|
1001 |
+
|
1002 |
+
In this examples B$ is also deleted. All variables defined after the object to be clear are deleted as well. The heap is simply reset to the previous state. This mechanism can be used to define local variables in subroutines. Simply clear the first variable defined in the subroutine before calling RETURN.
|
1003 |
+
|
1004 |
+
|
1005 |
+
## IOT language set
|
1006 |
+
|
1007 |
+
### Introduction
|
1008 |
+
|
1009 |
+
The IoT language set are commands needed to use IoT services. They help to implement I/O function. This part of the interpreter is under active development. Some commands may change in the future.
|
1010 |
+
|
1011 |
+
### AVAIL
|
1012 |
+
|
1013 |
+
AVAIL returns the number of characters ready for input on an input stream. Example:
|
1014 |
+
|
1015 |
+
PRINT AVAIL(4)
|
1016 |
+
|
1017 |
+
returns the number of characters on input stream 4 which is the secondary serial port. The function is hardware dependent.
|
1018 |
+
|
1019 |
+
### String commands INSTR, VAL, and STR
|
1020 |
+
|
1021 |
+
INSTR finds a character in a string and returns the index. Example:
|
1022 |
+
|
1023 |
+
A\$="1, 2, 3"
|
1024 |
+
|
1025 |
+
A=INSTR(",", A\$)
|
1026 |
+
|
1027 |
+
finds the first comma in the string. INSTR can be used to split strings. See splitstr.bas in the tutorial for more information.
|
1028 |
+
|
1029 |
+
VAL scans a string for a number and returns the value. If no number is found the return value is 0. Example:
|
1030 |
+
|
1031 |
+
A\$="125"
|
1032 |
+
|
1033 |
+
A=VAL(A$)
|
1034 |
+
|
1035 |
+
VAL uses the special variable @V to report back the number of characters in the number. The status of the conversion is stored in @S. If @S is 0 after a conversion a number was found. Otherwise @S is 1. @V is set to the number of characters only if the conversion was succesful.
|
1036 |
+
|
1037 |
+
STR converts a number to a string. Example:
|
1038 |
+
|
1039 |
+
A\$=STR(125)
|
1040 |
+
|
1041 |
+
Tutorial: splitstr.bas, converst.bas
|
1042 |
+
|
1043 |
+
### SENSOR
|
1044 |
+
|
1045 |
+
SENSOR is the generic sensor interface. It handles sensor drivers in the hardware dependent code. The first argument of the function is the sensor number. The second argument can be used to indentify interal properties of the sensor. If the second argument is zero, SENSOR returns if the sensor code is available. Example:
|
1046 |
+
|
1047 |
+
10 IF NOT SENSOR(1, 0) THEN PRINT "no DHT11 sensor detected": END
|
1048 |
+
|
1049 |
+
20 PRINT SENSOR(1, 2)
|
1050 |
+
|
1051 |
+
The first command looks if there is a DHT temperature sensor. The second command read the temperature value.
|
1052 |
+
|
1053 |
+
### SLEEP
|
1054 |
+
|
1055 |
+
SLEEP puts a system into deep sleep mode. It requires one argument which is the sleep time in milliseconds. The command is currently only implemented on ESP8266 and ESP32 systems. The microcontroller restarts after deep sleep. This command needs to be used with an autostart program.
|
1056 |
+
|
1057 |
+
### NETSTAT
|
1058 |
+
|
1059 |
+
In command mode NETSTAT displays the network status. It is implemented for all Wifi systems and Arduino Ethernet. As a arithemtic constant it returns a network status. With 0 the system is not connected. 1 means connected but no MQTT connection. 3 is network and MQTT connected.
|
1060 |
+
|
1061 |
+
The network code is under active development.
|
1062 |
+
|
1063 |
+
## Timers and interrupts
|
1064 |
+
|
1065 |
+
BASIC can handle time interrupt right now. Interrupts of external sources are in preparation. There are two timers implemented. The AFTER timer causes an action once and is then reset. The EVERY timer triggers events periodically until stopped. Both timers use millis() as time source. Timer events are only processed if a program is running. In interactive mode both timers are stopped but continue running.
|
1066 |
+
|
1067 |
+
### AFTER
|
1068 |
+
|
1069 |
+
The AFTER timer is started with the command
|
1070 |
+
|
1071 |
+
10 AFTER 1000 GOTO 100
|
1072 |
+
|
1073 |
+
After 1000 milliseconds the interpreter branches to line 100. The command
|
1074 |
+
|
1075 |
+
10 AFTER 500 GOSUB 200
|
1076 |
+
|
1077 |
+
will GOSUB to line 200. A RETURN will resume program execution whereevery the program has been interrupted.
|
1078 |
+
|
1079 |
+
AFTER 0
|
1080 |
+
|
1081 |
+
disables the execution of the after command.
|
1082 |
+
|
1083 |
+
AFTER 1000
|
1084 |
+
|
1085 |
+
will start the after timer again with a new time period of 1000 ms. The GOTO and GOSUB argument of the previous after are reused.
|
1086 |
+
|
1087 |
+
### EVERY
|
1088 |
+
|
1089 |
+
EVERY syntax is exactly like AFTER but the event is running periodically.
|
1090 |
+
|
1091 |
+
### EVENT
|
1092 |
+
|
1093 |
+
EVENT listens to an interrupt and branches to a line number. In the statement
|
1094 |
+
|
1095 |
+
EVENT 2,0 GOSUB 1000
|
1096 |
+
|
1097 |
+
pin 2 is used as an interrupt pin with mode 0, which is interrupt on low. Every time the pin goes to low BASIC calls the subroutine at line 1000.
|
1098 |
+
|
1099 |
+
EVENT 2,0
|
1100 |
+
|
1101 |
+
without the GOSUB argument deletes the interrupt.
|
1102 |
+
|
1103 |
+
After the event is processed, the interrupt is automatically disabled. The RETURN statement enables the interrupt again.
|
1104 |
+
|
1105 |
+
Allowed interrupt modes are
|
1106 |
+
|
1107 |
+
0: LOW
|
1108 |
+
|
1109 |
+
1: CHANGE
|
1110 |
+
|
1111 |
+
2: FALLING
|
1112 |
+
|
1113 |
+
3: RISING
|
1114 |
+
|
1115 |
+
The EVENT statement does not set the pin mode of the pin. This has to be done with PINM in the BASIC program. A typical program could look like this:
|
1116 |
+
|
1117 |
+
10 PINM 2,2
|
1118 |
+
|
1119 |
+
20 EVENT 2,2 GOSUB 1000
|
1120 |
+
|
1121 |
+
30 Some code
|
1122 |
+
|
1123 |
+
1000 PRINT "Event triggered": RETURN
|
1124 |
+
|
1125 |
+
The PINM command sets the pin to INPUT_PULLUP and the EVENT commands waits for the pin to be pulled down to low. It triggers the interrupt on the falling signal. While the PRINT statement is processed, no further interrupt is accepted. After return the interrupt is reenabled.
|
1126 |
+
|
1127 |
+
Events can be disabled with the command
|
1128 |
+
|
1129 |
+
EVENT STOP
|
1130 |
+
|
1131 |
+
Events can be reenabled with the command
|
1132 |
+
|
1133 |
+
EVENT CONT
|
1134 |
+
|
1135 |
+
### Credits and a word on timing
|
1136 |
+
|
1137 |
+
Both AFTER and EVERY have been taken from the legendary Locomotive BASIC. In this BASIC dialect, only GOSUB was available and the time scale was 20 ms. There were 4 individual timers. Full featured Locomotive BASIC timers are on the feature list for future releases.
|
1138 |
+
|
1139 |
+
BASIC can handle 1ms interrupts even on an Arduino UNO if there is not much I/O going on. Typically, 35 BASIC commands are processed in a ms by the interpreter core. It is good practice to disable interrupts with EVERY 0 at the beginning of the interrupt subroutine and to reenable it with EVERY n immediately before return.
|
1140 |
+
|
1141 |
+
## Error handling
|
1142 |
+
|
1143 |
+
### Errors in general
|
1144 |
+
|
1145 |
+
In BASIC there are to types of error. Some conditions are just exceptions and the program will coninue normally. Examples are reading past the end of a file or reading past the last DATA item. These operations set the flag @S to an appropriate value. BASIC language errors clear the stacks, print an error message and the program is terminated. Variables and the program pointer are preserved. The program can be continued with CONT. Effectively, an error leads to a STOP of the program plus loss of GOSUB and FOR stack information by default.
|
1146 |
+
|
1147 |
+
### Error trapping
|
1148 |
+
|
1149 |
+
If BASIC is compiled with the HASERRORHANDLING option, error behaviour can be controlled with the ERROR command.
|
1150 |
+
|
1151 |
+
The code line
|
1152 |
+
|
1153 |
+
10 ERROR GOTO 1000
|
1154 |
+
|
1155 |
+
would jump to line 1000 when an error is encountered. As the FOR and GOSUB stacks are cleared on error, the code from 1000 on must handle all operations to restart the program if needed. After the jump, the error handling is reset to normal behaviour, i.e. stop on error. Using the keyword ERROR as a variable returns the error code.
|
1156 |
+
|
1157 |
+
ERROR STOP
|
1158 |
+
|
1159 |
+
will switch of error handling and go to normal behaviour. It also resets the error code to 0.
|
1160 |
+
|
1161 |
+
ERROR CONT
|
1162 |
+
|
1163 |
+
causes the program to continue even in case of an error.
|
1164 |
+
|
1165 |
+
### Error codes
|
1166 |
+
|
1167 |
+
Currently the following error codes are supported.
|
1168 |
+
|
1169 |
+
Syntax error: 10
|
1170 |
+
|
1171 |
+
Number error: 11
|
1172 |
+
|
1173 |
+
Division by zero: 12
|
1174 |
+
|
1175 |
+
Unknown line: 13
|
1176 |
+
|
1177 |
+
Return not possible: 14
|
1178 |
+
|
1179 |
+
Next not possible: 15
|
1180 |
+
|
1181 |
+
Gosub not possible: 16
|
1182 |
+
|
1183 |
+
For not possible: 17
|
1184 |
+
|
1185 |
+
Out of memory: 18
|
1186 |
+
|
1187 |
+
Stack error: 19
|
1188 |
+
|
1189 |
+
Wrong dimensioning: 20
|
1190 |
+
|
1191 |
+
Index or parameter out of range: 21
|
1192 |
+
|
1193 |
+
String operation error: 22
|
1194 |
+
|
1195 |
+
Error in variable handling: 23
|
1196 |
+
|
1197 |
+
File errors: 24
|
1198 |
+
|
1199 |
+
Function errors: 25
|
1200 |
+
|
1201 |
+
Number or type of arguments wrong: 26
|
1202 |
+
|
1203 |
+
EEPROM errors: 27
|
1204 |
+
|
1205 |
+
SDcard errors: 28
|
1206 |
+
|
1207 |
+
Some of the errors are technical errors and should never appear if the interpreter works properly.
|
1208 |
+
|
1209 |
+
## Graphics language set
|
1210 |
+
|
1211 |
+
### Introduction
|
1212 |
+
|
1213 |
+
The graphics language set is a thin layer over the low level graphics functions of the graphics driver. They try to be as generic as possible and avoid driver specific code. Some of the commands behave differently on different platforms. The graphics commands were first implemented with an SD1963 TFT in mind. Currently various monochrome and color displays are supported.
|
1214 |
+
|
1215 |
+
### COLOR
|
1216 |
+
|
1217 |
+
Sets the color of the graphics pen. COLOR either accepts either 3 arguments for rgb color or one argument for vga like colors. The exact color palette depends on the graphics driver. Example:
|
1218 |
+
|
1219 |
+
COLOR 255
|
1220 |
+
|
1221 |
+
COLOR 100, 100, 100
|
1222 |
+
|
1223 |
+
### PLOT
|
1224 |
+
|
1225 |
+
PLOT draws one pixel on the display. The coordinate system starts at the upper left corner of the display. First arguments is the x coordinate, second argument is the y coordinate. Example:
|
1226 |
+
|
1227 |
+
PLOT 100, 100
|
1228 |
+
|
1229 |
+
A pixel is drawn in the colour specified by the COLOR command.
|
1230 |
+
|
1231 |
+
### LINE
|
1232 |
+
|
1233 |
+
LINE draws a line from one point to another. Example:
|
1234 |
+
|
1235 |
+
LINE 100, 100, 200, 200
|
1236 |
+
|
1237 |
+
### CIRCLE and FCIRCLE
|
1238 |
+
|
1239 |
+
CIRCLE and FCIRCLE draw a circle or filled circle around a point on the canvas with radius r. The last argument is the radius. Example:
|
1240 |
+
|
1241 |
+
CIRCLE 100, 100, 50
|
1242 |
+
|
1243 |
+
### RECT and FRECT
|
1244 |
+
|
1245 |
+
RECT and FRECT draw a rectangle or filled rectangle. The first pair of argument is the left lower corner. The second pair is the right upper corner. Example:
|
1246 |
+
|
1247 |
+
RECT 100, 100, 200, 200
|
1248 |
+
|
1249 |
+
# Hardware drivers
|
1250 |
+
|
1251 |
+
## I/O Streams
|
1252 |
+
|
1253 |
+
### Introduction
|
1254 |
+
|
1255 |
+
BASIC I/O goes through input output streams. Every stream has an integer number. Sending data to a stream sends it through to a device driver. These device drivers handle the underlying OS or microcontroller cores. The logic is as close as possible to the Arduino stream class.
|
1256 |
+
|
1257 |
+
Streams are
|
1258 |
+
|
1259 |
+
1: Console input and output
|
1260 |
+
|
1261 |
+
2: Keyboard or keypad input and display output
|
1262 |
+
|
1263 |
+
4: Secondary serial stream
|
1264 |
+
|
1265 |
+
7: I2C protocol
|
1266 |
+
|
1267 |
+
8: RF24 radio interface
|
1268 |
+
|
1269 |
+
9: MQTT network connection
|
1270 |
+
|
1271 |
+
16: File I/O
|
1272 |
+
|
1273 |
+
All other stream numbers are currently unused but will be allocated to drivers in the future. The stream numbers below 32 should not be used for extensions.
|
1274 |
+
|
1275 |
+
Stream numbers are agruments of the modifier of OPEN, CLOSE, PRINT, INPUT, GET and PUT. Typical commands would look like:
|
1276 |
+
|
1277 |
+
INPUT &2, A$
|
1278 |
+
|
1279 |
+
PRINT &4, "Hello world"
|
1280 |
+
|
1281 |
+
GET $2, A
|
1282 |
+
|
1283 |
+
PUT &16, "A", "B"
|
1284 |
+
|
1285 |
+
The expression after & is the I/O stream number.
|
1286 |
+
|
1287 |
+
There is a default I/O stream compiled into the code. For systems not compiled with the STANDALONE option this default stream is the console stream 1. If the STANDALONE option is used, the default stream is 2.
|
1288 |
+
|
1289 |
+
The active I/O stream can be changed by stetting the special variable @O for output and @I for input. The two code lines
|
1290 |
+
|
1291 |
+
10 @O=2: PRINT "Hello World"
|
1292 |
+
|
1293 |
+
and
|
1294 |
+
|
1295 |
+
10 PRINT &2, "Hello World"
|
1296 |
+
|
1297 |
+
both write "Hello World" to the display.
|
1298 |
+
|
1299 |
+
The active I/O stream is always reset to the default stream once the interpreter changes to interactive mode. This is a failsafe to avoid a program to shut out a user permanently.
|
1300 |
+
|
1301 |
+
The default stream can be changed permanently with the SET command.
|
1302 |
+
|
1303 |
+
SET 3,0 sets the default output stream to console.
|
1304 |
+
|
1305 |
+
SET 3,1 sets the default output stream to display.
|
1306 |
+
|
1307 |
+
SET 5,0 sets the default input stream to console.
|
1308 |
+
|
1309 |
+
SET 5,1 sets the default input stream to display.
|
1310 |
+
|
1311 |
+
### Serial Stream
|
1312 |
+
|
1313 |
+
Stream 1 is the default serial I/O stream on Arduino IDE programmed microcontrollers and it is standard input and output on POSIX like systems. The behaviour of stream 1 differed between the two version.
|
1314 |
+
|
1315 |
+
On microcontrollers stream 1 is a true byte I/O stream and non blocking. The command
|
1316 |
+
|
1317 |
+
GET A
|
1318 |
+
|
1319 |
+
will return immediately and return 0 in the variable A if no character is available on the stream. The function AVAIL(1) or the special variable @A will return the correct number of characters in the serial buffer. If there is no character, the result will be 0.
|
1320 |
+
|
1321 |
+
On POSIX systems, getchar() is used on OS level. This means that I/O on stream 1 is blocking.
|
1322 |
+
|
1323 |
+
GET A
|
1324 |
+
|
1325 |
+
will wait for a character. AVAIL(1) or @A will always return 1 to make sure that a program like this
|
1326 |
+
|
1327 |
+
10 IF AVAIL(1) THEN GET A
|
1328 |
+
|
1329 |
+
runs correctly on both archtitectures.
|
1330 |
+
|
1331 |
+
For line oriented input with the INPUT command, the difference is irrelevant. INPUT works in the same way on both system types.
|
1332 |
+
|
1333 |
+
There is currently no mechanism to change the precompiled baud rate of the serial stream at runtime of a BASIC program. Default in the interpreter code is 9600 baud. This can be changed at compile time by changing serial_baudrate in the code.
|
1334 |
+
|
1335 |
+
A line end is LF, which means ASCII 10. This is UNIX style end of line. DOS and other systems usually send CR LF which is 13 10 in decimal ASCII. If you use a terminal program to interact with BASIC, "only LF", should be configured in the settings. Currently stream 1 cannot be reconfigured to use LF CR. Stream 4, the secondary serial stream, can use CR LF. This is mostly relevant for input.
|
1336 |
+
|
1337 |
+
### Display and keyboard drivers
|
1338 |
+
|
1339 |
+
Keyboard and display are accessed through stream 2. Only one device can be present, i.e. one keyboard and one display. Multidisplay or multikeyboard systems are not supported. Stream 3 is reserved for these usecases but currently not implemented.
|
1340 |
+
|
1341 |
+
BASIC currently supports either PS2 keyboards and the keypad of the LCDSHIELD as input device. For PS2 keyboards on standard Arduino systems the patches PS2keyboard library should be downloaded from my repo for optimal functionality. It implements keyboard.peek() which has a few advantages.
|
1342 |
+
|
1343 |
+
PS2 keyboard input is buffered and non blocking. AVAIL(2) gives the correct number of characters in the keyboard buffer.
|
1344 |
+
|
1345 |
+
GET &2, A
|
1346 |
+
|
1347 |
+
return 0 if no character is present and the ASCII value if a character is there.
|
1348 |
+
|
1349 |
+
GET &2, A$
|
1350 |
+
|
1351 |
+
transfers the result directly in the string A$ as a first character. The string is empty if no key was pressed.
|
1352 |
+
|
1353 |
+
The keymap is compiled into the code. A few standard US or European keymaps are supported.
|
1354 |
+
|
1355 |
+
If the code is compiled with the LCDSHIELD option, the keys of the shield can be used to input data. The "select" key of the shield is mapped to ASCII 10 means "end of line". The arrow keys of the shield are mapped to the digits 1 to 4.
|
1356 |
+
|
1357 |
+
INPUT &2, A
|
1358 |
+
|
1359 |
+
can be used on an lcd shield for number input. The command returns after select and A has a valid number. Alternatively
|
1360 |
+
|
1361 |
+
INPUT &2, A$
|
1362 |
+
|
1363 |
+
will enter a string consisting of the digits 1 to 4.
|
1364 |
+
|
1365 |
+
GET &2, A
|
1366 |
+
|
1367 |
+
will contain either 0 if no key is pressed or the ASCII code of the key. The command will wait until the key is released. Keypad input is unbuffered. No interrupt or timer function is currently implemented on keypads. This will change for future releases of the code.
|
1368 |
+
|
1369 |
+
ASCII output to a display is sent through the output stream 2. Displays are handled by a generic display driver. For low memory systems the display driver supports a non scrolling / unbuffered mode. Only a few basic display functions are supported. If there is enough memory, the display driver can be compiled in scrolling / buffered mode. For the the option DISPLAYCANSCROLL has to be defined in hardware-arduino.h. All characters are buffered in a display buffer which can be accessed byte wise.
|
1370 |
+
|
1371 |
+
In non buffered mode the display driver has the following functions:
|
1372 |
+
|
1373 |
+
The cursor of the display can be accessed special variables @X and @Y. Both variables are read/write. One can find out where the cursor is and set its position. Output with PUT &2 and PRINT &2 goes to the next cursor postion.
|
1374 |
+
|
1375 |
+
ASCII character 7 is the bell character. It calls the dspbell() function which is empty by default. Any action can be implemented here.
|
1376 |
+
|
1377 |
+
ASCII character 8 is backspace and delete. This is needed for compatibility with certain terminals.
|
1378 |
+
|
1379 |
+
ASCII character 9 is tab to the next multiple of 8 tab stop.
|
1380 |
+
|
1381 |
+
ASCII character 10 goes to the beginning of next line (Unix style LF).
|
1382 |
+
|
1383 |
+
ASCII character 11 is vertical tab, going to the next line in the same column.
|
1384 |
+
|
1385 |
+
ASCII character 12 clears the display. PUT &2, 12 is clear screen on the display.
|
1386 |
+
|
1387 |
+
ASCII character 13 goes to the beginning of the currently line (true CR).
|
1388 |
+
|
1389 |
+
ASCII character 127 goes back one cursor position and clears the character. It is "delete".
|
1390 |
+
|
1391 |
+
ASCII character 27 (ESC) sets the terminal to esc mode and triggers vt52 character interpretation.
|
1392 |
+
|
1393 |
+
ASCII character 2 (STX) sends the cursor to the home position. This feature will also be used for Epaper support in the future.
|
1394 |
+
|
1395 |
+
ASCII character 3 (ETX) is used for page mode displays to trigger the redraw.
|
1396 |
+
|
1397 |
+
Buffered displays add scrolling. Once the cursor goes beyond the last line, the display is redraw with the first line disappearing. This is simple line based software scrolling.
|
1398 |
+
|
1399 |
+
Each character in the display is buffered a display buffer. This buffer can be accessed through the special array D(). Writing to the array immediately display the character on the display. Reading from it gives the displayed character at the index position. The array starts from 1. The index advances by column and then by row.
|
1400 |
+
|
1401 |
+
Currently LCD displays 16x2 and 20x4, Nokia 5110, ILI9486, ILI9488, SSD1306, and SD1963 are supported. All these displays use 8x8 or 16x16 fonts. Nokia has 10 columns and 6 rows. SSD1306 character buffer dimension depend on the display size. 16x8 is the most common size. ILI9488 has 20 columns and 30 rows. It is portrait mode by default. A 7 inch SD1963 has 50 columns and 30 rows. ILI9486 displays are based on the MCUFRIEND library with parallel access.
|
1402 |
+
|
1403 |
+
Some displays use page based low level graphics drivers. These displays mirror the entire canvas in memory on a pixel basis. When one draws to the canvas, nothing is shown until an update command transfers the buffer to the display. SPI bus based monochrome display use this technique. The ILI9488 and SSD1306 Oled driver use this mechanism. By default these displays behave like the other displays and page mode is of. Drawing of graphics and text appears slow.
|
1404 |
+
|
1405 |
+
Activating the page mode is done with
|
1406 |
+
|
1407 |
+
SET 10, 1
|
1408 |
+
|
1409 |
+
after this all updates stay in memory until an ETX code is sent with
|
1410 |
+
|
1411 |
+
PUT &2, 3
|
1412 |
+
|
1413 |
+
only then the display is redrawn. The display can be set back to character mode by
|
1414 |
+
|
1415 |
+
SET 10, 0
|
1416 |
+
|
1417 |
+
For epaper displays page mode is default. Epaper disply integration is in preparation.
|
1418 |
+
|
1419 |
+
In addition to the displays, VGA output is supported with the FabGL library on ESP32 systems. These systems are described in the special systems section.
|
1420 |
+
|
1421 |
+
### VT52 terminal emulation
|
1422 |
+
|
1423 |
+
If compiled with HASVT52, BASIC has a full VT52 terminal emulation, including many of the GEMDOS addons. Please look at the wikipedia page https://en.wikipedia.org/wiki/VT52 for a full list of the originally supported ESC sequences.
|
1424 |
+
|
1425 |
+
All standard commands except the keypad and graphics sequences are supported. All GEMDOS extensions except reverse video are supported where it makes sense. On color displays, the color code is sent as a VGA color in the range from 0 to 15.
|
1426 |
+
|
1427 |
+
The most useful VT52 sequences in a BASIC program are the ons manipulating entire line.
|
1428 |
+
|
1429 |
+
PUT &2, 27, "L"
|
1430 |
+
|
1431 |
+
inserts a line, while
|
1432 |
+
|
1433 |
+
PUT &2, 27, "M"
|
1434 |
+
|
1435 |
+
deletes a line.
|
1436 |
+
|
1437 |
+
ON LCD displays, switching on the cursor is supported.
|
1438 |
+
|
1439 |
+
PUT &2, 27, "e"
|
1440 |
+
|
1441 |
+
switches on a blinking cursor, while
|
1442 |
+
|
1443 |
+
PUT &2, 27, "f"
|
1444 |
+
|
1445 |
+
switches it off again.
|
1446 |
+
|
1447 |
+
The following ESC sequences are supported right now
|
1448 |
+
|
1449 |
+
ESC A Cursor up - Move cursor one line upwards.
|
1450 |
+
|
1451 |
+
ESC B Cursor down - Move cursor one line downwards.
|
1452 |
+
|
1453 |
+
ESC C Cursor right - Move cursor one column to the right.
|
1454 |
+
|
1455 |
+
ESC D Cursor left - Move cursor one column to the left.
|
1456 |
+
|
1457 |
+
ESC H Cursor home - Move cursor to the upper left corner.
|
1458 |
+
|
1459 |
+
ESC I Reverse line feed - Insert a line above the cursor, then move the cursor into it.
|
1460 |
+
|
1461 |
+
ESC J Clear to end of screen - Clear screen from cursor onwards.
|
1462 |
+
|
1463 |
+
ESC K Clear to end of line - Clear line from cursor onwards.
|
1464 |
+
|
1465 |
+
ESC L Insert line - Insert a line.
|
1466 |
+
|
1467 |
+
ESC M Delete line - Remove line.
|
1468 |
+
|
1469 |
+
ESC Yrc Set cursor position - Move cursor to position c,r, encoded as single characters.
|
1470 |
+
|
1471 |
+
ESC Z ident Identify what the terminal is, see notes below.
|
1472 |
+
|
1473 |
+
ESC E Clear screen - Clear screen and place cursor at top left corner.
|
1474 |
+
|
1475 |
+
ESC b# Foreground color - Set text colour to the selected value (only implemented on color displays).
|
1476 |
+
|
1477 |
+
ESC c# Background color - Set background colour (only implemented on color displays).
|
1478 |
+
|
1479 |
+
ESC d Clear to start of screen - Clear screen from the cursor up to the home position.
|
1480 |
+
|
1481 |
+
ESC e Enable cursor - Makes the cursor visible on the screen (only implemented on LCDs).
|
1482 |
+
|
1483 |
+
ESC f Disable cursor - Makes the cursor invisible (only implemented on LCDs).
|
1484 |
+
|
1485 |
+
ESC j Save cursor - Saves the current position of the cursor in memory.
|
1486 |
+
|
1487 |
+
ESC k Restore cursor - Return the cursor to the settings previously saved with j.
|
1488 |
+
|
1489 |
+
ESC l Clear line - Erase the entire line and positions the cursor on the left.
|
1490 |
+
|
1491 |
+
ESC o Clear to start of line - Clear current line from the start to the left side to the cursor.
|
1492 |
+
|
1493 |
+
ESC p Reverse video - Switch on inverse video text (implemented but with no function).
|
1494 |
+
|
1495 |
+
ESC q Normal video - Switch off inverse video text (implemented but with no function).
|
1496 |
+
|
1497 |
+
ESC v Wrap on - Enable line wrap, removing the need for CR/LF at line endings.
|
1498 |
+
|
1499 |
+
ESC w Wrap off - Disable line wrap.
|
1500 |
+
|
1501 |
+
### VT52 graphics extension
|
1502 |
+
|
1503 |
+
On displays with graphics capabilities, the graphics commands can also be sent to the display with ESC sequences. This is not part of the standard VT52 command set and also not part of the GEMDOS extension.
|
1504 |
+
|
1505 |
+
The graphics code uses three general purpose registers x, y, and z. x and y are 14 bit registers while z is a 7 bit register. Setting a register is done with the sequences
|
1506 |
+
|
1507 |
+
ESC x low high
|
1508 |
+
|
1509 |
+
ESC y low high
|
1510 |
+
|
1511 |
+
ESC z char
|
1512 |
+
|
1513 |
+
Like in cursor control the arguments are transfered as printable characters. 32 is subtracted from the ASCII value of low, high or char.
|
1514 |
+
|
1515 |
+
Graphics commands are initiated by
|
1516 |
+
|
1517 |
+
ESC g command
|
1518 |
+
|
1519 |
+
where command is one character. The following graphics sequences are currently implemented
|
1520 |
+
|
1521 |
+
ESC g s - set the graphics cursor to position x and y
|
1522 |
+
|
1523 |
+
ESC g p - plot a point at the graphics cursor
|
1524 |
+
|
1525 |
+
ESC g l - draw a line from the graphics cursor to position x and y
|
1526 |
+
|
1527 |
+
ESC g L - draw a line from the graphics cursor to position x and y and move the graphics cursor to x, y
|
1528 |
+
|
1529 |
+
ESC g r - draw a rectangle between the graphics cursor position and x, y (like RECT)
|
1530 |
+
|
1531 |
+
ESC g R - draw a filled rectangle
|
1532 |
+
|
1533 |
+
ESC g c - draw a circle at graphics cursor position with radius x
|
1534 |
+
|
1535 |
+
ESC g C draw filled circle
|
1536 |
+
|
1537 |
+
Color is set with ESC c.
|
1538 |
+
|
1539 |
+
### Secondary serial stream
|
1540 |
+
|
1541 |
+
The secondary serial stream is addressed through stream number 4. For microcontroller platforms with a hardware secondary serial port, the Serial1 object on the Arduino library is used. This can be changed in hardware-arduino.h by modifiying the functions beginning with prt. For microcontrollers without multiple hardware serial ports Softwareserial is used. The RX and TX pins are set through the macro SOFTSERIALRX and SOFTSERIALTX. Default are pin 11 and 12. This conflicts with the SPI pins. If SPI is to be used the soft serial pins have to be changed.
|
1542 |
+
|
1543 |
+
Default baudrate on the secondary serial port is 9600 baud.
|
1544 |
+
|
1545 |
+
The secondary serial port implements a blockmode function. Blockmode is on by default. Without blockmode an INPUT command would wait until a LF is received. This means that
|
1546 |
+
|
1547 |
+
INPUT &4, A$
|
1548 |
+
|
1549 |
+
would never return if the sender on the serial port does not send LF. If a modem with AT commands or any other device is on the input port, the BASIC program would stop indefinitely if the sender side misbehaves. With blockmode active, the INPUT command handles I/O differently.
|
1550 |
+
|
1551 |
+
With the command
|
1552 |
+
|
1553 |
+
SET 7, 1
|
1554 |
+
|
1555 |
+
the blockmode parameter can be set to 1. In this mode the entire serial buffer is transfered to the string A$. The number of characters waiting in the serial buffer for transfer can be found by the function AVAIL(4). This number of character is in the string after INPUT &4 with the length of the string set to the value of AVAIL(4) before INPUT. Immediately after read, AVAIL(4) is zero. For secondary serial blockmode 1 is the default.
|
1556 |
+
|
1557 |
+
Setting the blockmode parameter to a value greater 1 the timeout mode is activated. INPUT reads all characters in the buffer and waits timeout microseconds for further input until it returns. It also returns if the string is full. Example:
|
1558 |
+
|
1559 |
+
SET 7, 500
|
1560 |
+
|
1561 |
+
INPUT &4, A$
|
1562 |
+
|
1563 |
+
In this mode the INPUT command would read all characters, wait for 500ms for further input, and returns latest after this 500ms or when the string is full.
|
1564 |
+
|
1565 |
+
For communication with modems, the secondary serial channel has one more parameter. Normally only LF is sent after the end of a line. Some modems and other devices on a serial port expect a LF CR sequence at the end of a line. The communication is blocked if CR is not sent. With the command
|
1566 |
+
|
1567 |
+
SET 6, 1
|
1568 |
+
|
1569 |
+
CR mode is activated. A print command to the serial channel like
|
1570 |
+
|
1571 |
+
PRINT &4, "AT"
|
1572 |
+
|
1573 |
+
would print the characters "A", "T", followed by a LF (ASCII 10) and a CR (ASCII 13).
|
1574 |
+
|
1575 |
+
Answer of a model could be collected with the input sequence above.
|
1576 |
+
|
1577 |
+
Unlike the primary serial port, the baudrate of the secondary port can be changed by the BASIC program. Example:
|
1578 |
+
|
1579 |
+
SET 8, 31250
|
1580 |
+
|
1581 |
+
would set the baudrate to the standard MIDI baudrate of 31250. Any allowed baudrate of the hardware platform can be used. The serial port is reset after this command.
|
1582 |
+
|
1583 |
+
### Wire communication
|
1584 |
+
|
1585 |
+
Stream &7 is used for Wire i.e. the I2C protocol. BASIC uses the implementation of the Arduino Wire library and the Wire object. Actually, the I2C protocol is very compley and the Wire library hides this complexity making it a byte stream. PRINT, INPUT, GET and PUT can deal well with byte streams, therefore most of the Wire libraries functionality can be used from BASIC. There is a master and a slave mode implementation.
|
1586 |
+
|
1587 |
+
In master mode, the OPEN statement for the I2C stream is used in read mode. Example:
|
1588 |
+
|
1589 |
+
OPEN &7, 104
|
1590 |
+
|
1591 |
+
prepares I2C to control the slave with address 104. This address is a real time clock. Any valid I2C slave address can be used as an argument in the OPEN statement. OPEN &7 does not transfer any data and it also does not make any calls to the Wire library except if the microcontroller was in slave mode before. Then OPEN restarts the Wire object in master mode.
|
1592 |
+
|
1593 |
+
Sending data can be done with PUT for sequences with just a few bytes. Alternatively the information can be collected in a string and then sent with print. Examples:
|
1594 |
+
|
1595 |
+
PUT &7, 0
|
1596 |
+
|
1597 |
+
sends a null byte to the device.
|
1598 |
+
|
1599 |
+
PRINT &7, A\$
|
1600 |
+
|
1601 |
+
sends as many bytes as are stored in A$ to the device. LEN(A$) is the number of bytes transferred. The maximum is 31 bytes, a limit given by the wire libraries internal buffers.
|
1602 |
+
|
1603 |
+
Requesting a byte from the device can either be done with GET or with INPUT.
|
1604 |
+
|
1605 |
+
GET &7, A
|
1606 |
+
|
1607 |
+
requests one byte from the device.
|
1608 |
+
|
1609 |
+
INPUT &7, A\$
|
1610 |
+
|
1611 |
+
requests as many bytes as fit into the string, maximum 32. After INPUT the string will always have a length of 32 bytes on AVR. The Wire library does not transmit the number of transferred bytes properly despite some comments that indicate otherwise in the documentation. The library returns the number of requested bytes.
|
1612 |
+
|
1613 |
+
One can request fewer bytes than fit into the string by using the # modifier in the INPUT command.
|
1614 |
+
|
1615 |
+
INPUT &7, #8, A$
|
1616 |
+
|
1617 |
+
would request 8 bytes from the device. The length of the string will be 8 after the command. Again, this does not mean that the device really sent 8 bytes.
|
1618 |
+
|
1619 |
+
On stream 7 the status variable @S is set after each transmission to the status of the request or sent method. From this one can detect if the transmission has worked.
|
1620 |
+
|
1621 |
+
Wire can be reopen in master mode if one want to communicate with another device by a new OPEN command with a different address. This way multiple devices can be controlled.
|
1622 |
+
|
1623 |
+
See examples/13wire/master* for more info on master mode. This is a port of the example programs of the Arduino library from C++ to BASIC. It shows how easy it is to use Wire from BASIC.
|
1624 |
+
|
1625 |
+
Slave mode is open with OPEN in write mode, i.e. with 1 as a thrid parameter. Example:
|
1626 |
+
|
1627 |
+
OPEN &7, 8, 1
|
1628 |
+
|
1629 |
+
makes your BASIC Arduino a slave that listens on Wire port 8. This OPEN statement stops the Wire object, interaction with devices where the Arduino has to be master is no longer possible. Any open in master mode will stop the slave mode.
|
1630 |
+
|
1631 |
+
After slave mode is started the BASIC program continues normally. In the background there is an interrupt handler collecting the data the master sends. The program has to check periodically to see if the master has sent or requested data.
|
1632 |
+
|
1633 |
+
If the master has sent data, AVAIL(7) will be larger than 0. The data sent by the master can be collected by
|
1634 |
+
|
1635 |
+
INPUT &7, A\$
|
1636 |
+
|
1637 |
+
and then processed by the program. It the master sends additional data before the BASIC program has recalled the message, the buffer is overwritten. Only one transaction is stored. This means that a Wire slave needs to check AVAIL(7) in a tight loop.
|
1638 |
+
|
1639 |
+
If the master has requested data, USR(7, 1) has the number of requested bytes. The program should now prepare a string with this number of bytes and send it with
|
1640 |
+
|
1641 |
+
PRINT &7, A\$
|
1642 |
+
|
1643 |
+
After this, USR(7, 1) will be zero once the master has collected the data from the buffer.
|
1644 |
+
|
1645 |
+
Alternatively, the slave can deposite data in the buffer before the master has even requested it. A master request at a later time will be answered with the data. This would be useful for sensors of all kind. The slave measures data, puts it in the buffer with PRINT &7 and waits a while e.g. with DELAY until it does the next measurement. The new data overwrite the old one after every measurement cycle. A master can request data asynchronously at any time and will receive the data in the buffer. This BASIC program does not need to handle this.
|
1646 |
+
|
1647 |
+
See examples/13wire/slave* for more info on slave mode.
|
1648 |
+
|
1649 |
+
There is a number of example programs in examples/13wire to show how Wire programming works.
|
1650 |
+
|
1651 |
+
### Radio communication
|
1652 |
+
|
1653 |
+
Stream &8 is used for RF2401 radio communication. For this, BASIC needs to be compiled with the ARDUINORF24 flag and the respective pin definitions set. The open statement can be used to open one stream for read and one writing simulataneously. Example:
|
1654 |
+
|
1655 |
+
OPEN &8, "0815x", 0
|
1656 |
+
|
1657 |
+
OPEN &8, "0815y", 1
|
1658 |
+
|
1659 |
+
The first command opens a stream for reading, using the string given as file name to generate the 5 byte pipe address. The second command opens a write pipe with a different pipe address.
|
1660 |
+
|
1661 |
+
OPEN on the radio interface sets @S if there is in a error in the module communication. Typically this would mean that the module is not connected properly.
|
1662 |
+
|
1663 |
+
After opening INPUT, PRINT, PUT and GET on stream &8 work similar to Wire. The maximum message length is restricted by the unterlying library to 32 bytes.
|
1664 |
+
|
1665 |
+
The radio module is started with maximum power. To power it down SET 9, x can be used. x is an integer between 0 and 3. 3 is maximum power and 0 is minumum power.
|
1666 |
+
|
1667 |
+
### MQTT
|
1668 |
+
|
1669 |
+
Stream &9 is used for networking with MQTT. MQTT is the only network protocoll that is supported and the code is experimental. The network code is generic and more protocols will be integrated in the future.
|
1670 |
+
|
1671 |
+
Supported network adapters are Ardunio Ethernet shields, ESP8266 and ESP32 WLAN, Arduino MKR and RP2040 WifiNINA. These network codes have some timing needs like yielding the CPU and refreshing DHCP leases. BASIC integrates this in the central statement loop processing all time critical tasks in the function byield(). This code is best tested and very stable on ESP8266 and ESP32. Other platforms are alpha.
|
1672 |
+
|
1673 |
+
For Wifi systems, the SSID and password are hardcoded in the BASIC interpreter binary by setting the respective lines in "wifisettings.h". In this file there are two lines defining the MQTT server and port. This data is also compiled into the code. Currently only unencrypted and unautheticated MQTT is supported as this is only a toy. The fiths line in the code is a MAC address which is needed for the Arduino Ethernet shield. For all other hardware platforms this line is ignored.
|
1674 |
+
|
1675 |
+
After startup of the microcontroller it tries to connect to Wifi or Ethernet. The command NETSTAT can be used to see the connection status. This command is meant for interactive use only.
|
1676 |
+
|
1677 |
+
Finding the connection status in a program can be done by using NETSTAT as a function.
|
1678 |
+
|
1679 |
+
PRINT NETSTAT
|
1680 |
+
|
1681 |
+
or
|
1682 |
+
|
1683 |
+
A=NETSTAT
|
1684 |
+
|
1685 |
+
will return 0 is the network is not connected, 1 if the network is connected but MQTT is not connected, 3 is network and MQTT are connected. More status values will be added here in the future.
|
1686 |
+
|
1687 |
+
An MQTT topic an be open with the OPEN command using the topic name as a file name. Example:
|
1688 |
+
|
1689 |
+
OPEN &9, "iotbasic/data", 1
|
1690 |
+
|
1691 |
+
would open the topic "iotbasic/data" for writing because 1 was provided as a third parameter.
|
1692 |
+
|
1693 |
+
OPEN &9, "iotbasic/command", 0
|
1694 |
+
|
1695 |
+
would open the topic "iotbasic/command" for read.
|
1696 |
+
|
1697 |
+
There can be one read and write topic simulataneously. After opening the topics, data can be written by the commands PRINT, INPUT, GET, and PUT.
|
1698 |
+
|
1699 |
+
Every command will generate one MQTT message.
|
1700 |
+
|
1701 |
+
PRINT &9, "humidity", A
|
1702 |
+
|
1703 |
+
would send a message consisting of the string "humidity" and a number from variable A.
|
1704 |
+
|
1705 |
+
The maximum MQTT message length is hardcode to 128 bytes but can be extended. The maximum topic length is 32 bytes.
|
1706 |
+
|
1707 |
+
Incoming messages are buffered in the background. A new message overwrites the old one as there is only one buffer. The function AVAIL(9) has the number of bytes currently in the buffer. If AVAIL(9) is greater then 0 then
|
1708 |
+
|
1709 |
+
INPUT &9, A\$
|
1710 |
+
|
1711 |
+
transfers the entire message into A\$. From the string the message can be parsed with INSTR and VAL if numerical data was sent. The implementation is "binary data safe". Any set of bytes can be send as a message and be processed.
|
1712 |
+
|
1713 |
+
On POSIX systems not networking is supported as I haven't found a suitable multi platform MQTT library and was too lazy to write one myself.
|
1714 |
+
|
1715 |
+
The network code will be extended in version 1.4. Currently it is only a proof of concept.
|
1716 |
+
|
1717 |
+
### Filesystems
|
1718 |
+
|
1719 |
+
BASIC runs on very different platforms. From small 8 bit AVR based system to 64 bit Macs. These computers have different filesystems and capabilities. The BASIC commands are designed to make a minimal file I/O possible. Only one directory is supported. One file can be open for reading and another for writing simulateously. Stream &16 is used for file I/O.
|
1720 |
+
|
1721 |
+
Supported filesystems are SD on all microcontroller platforms that have it, ESPSPIFFS for ESP8266 and ESP32, LittleFS for Arduino MKR and RP2040 based systems. The file system driver removed leading rootfs names and everything else starting with a '/'. It shows a flat namespace of filenames. BASIC itself limits filenames to a maximum of 32 bytes. Some filesystems cannot handle this. In this case the name is truncated. No check is made if the filename is legal for the particular filesystem. For ESPSPIFFS and LittleFS the FDISK command is supported. Example:
|
1722 |
+
|
1723 |
+
FDISK
|
1724 |
+
|
1725 |
+
would answer with the prompt
|
1726 |
+
|
1727 |
+
Format disk (y/N)?
|
1728 |
+
|
1729 |
+
and then format the disk. No parameters are used here.
|
1730 |
+
|
1731 |
+
In addition to the standard filesystems, I developed a minimalist EEPROM filesystem. This filesystem partitions an I2C EEPROM into n equal size slots that can be used for files. Formating this filesystem requires the number of slots as a parameter. Example:
|
1732 |
+
|
1733 |
+
FDISK 4
|
1734 |
+
|
1735 |
+
would partition the EEPROM to 4 equal slot. For the very common 32kB serial EEPROM it would mean that 4 files of maximum of 8k can be stored. The EEPROM size has to be hard coded into the BASIC interpeter at the moment. This will change in the future.
|
1736 |
+
|
1737 |
+
On POSIX and SD no formating is supported.
|
1738 |
+
|
1739 |
+
### Real time clock support
|
1740 |
+
|
1741 |
+
Currently the built-in clocks of ESP32, STM32 and Arduino MKR and I2C clocks DS1307, DS3231 and DS3232 are supported and can be accessed through the special array @T() and the special string @T$. The array elements are
|
1742 |
+
|
1743 |
+
@T(0): seconds
|
1744 |
+
|
1745 |
+
@T(1): minutes
|
1746 |
+
|
1747 |
+
@T(2): hours
|
1748 |
+
|
1749 |
+
@T(3): days
|
1750 |
+
|
1751 |
+
@T(4): month
|
1752 |
+
|
1753 |
+
@T(5): year (0-99)
|
1754 |
+
|
1755 |
+
@T(6): day of week (0-6)
|
1756 |
+
|
1757 |
+
@T(7): temperature (DS1307 only)
|
1758 |
+
|
1759 |
+
@T(8): direct bytewise access to the clocks registers. On a DS1307 the addresses from 8 onwards are the NVRAM memory. On DS3231 and DS3232 these are the clock internal registers for alarm followed by the memory on DS3232.
|
1760 |
+
|
1761 |
+
Real time clock support for I2C is now built-in. No external library is used for this. For STM32 and Ardunio MKR the clock and low power libraries are automatically used by BASIC.
|
1762 |
+
|
1763 |
+
For systems without a hardware clock ARDUINORTCEMULATION can be activated in hardware-ardunio.h. It uses millis() to emulate a Unix style real time clock.
|
1764 |
+
|
1765 |
+
## Special systems and hardware components
|
1766 |
+
|
1767 |
+
### Introduction
|
1768 |
+
|
1769 |
+
The hardware section of the interpreter contains mechanism to make the platform look the same. This works for many platforms but there are exceptions. BASIC language features work differently on these systems. In this chapter these exceptions are described.
|
1770 |
+
|
1771 |
+
### POSIX systems
|
1772 |
+
|
1773 |
+
Systems compiled with the POSIX hardware driver use the features of the OS for most I/O operations. They differ from Arduino's and other MCU in some aspects.
|
1774 |
+
|
1775 |
+
Ususally BASIC is started from the command line on these systems. The BASIC interpreter can be started with a file argument. In this case the interpreter starts and runs the file and terminates after the program has ended.
|
1776 |
+
|
1777 |
+
./basic file.bas
|
1778 |
+
|
1779 |
+
will run the program and after completion the OS shell command prompt will reappear.
|
1780 |
+
|
1781 |
+
The compiler flag TERMINATEAFTERRUN controls this feature. It is set to 1 by default. If set to 0 in basic.h, BASIC will not terminate after the end of the program.
|
1782 |
+
|
1783 |
+
./basic file.bas hello
|
1784 |
+
|
1785 |
+
will pass the argument to the special string @A$. Only the first argument is processed and stored in the string. Multiple arguments need to be quoted
|
1786 |
+
|
1787 |
+
./basic file.bas "hello world"
|
1788 |
+
|
1789 |
+
will pass both words to @A$.
|
1790 |
+
|
1791 |
+
### Wemos D1R1 systems and shields
|
1792 |
+
|
1793 |
+
These UNO form factor 8266 are really popular as they are cheap and powerful. BASIC supports these boards as datalogger and standalone systems. They are not really UNO hardware compatible, so some precautions are required.
|
1794 |
+
|
1795 |
+
BASIC uses the raw ESP822 pinout on the right side of this table:
|
1796 |
+
|
1797 |
+
static const uint8_t D0 = 3;
|
1798 |
+
|
1799 |
+
static const uint8_t D1 = 1;
|
1800 |
+
|
1801 |
+
static const uint8_t D2 = 16;
|
1802 |
+
|
1803 |
+
static const uint8_t D3 = 5;
|
1804 |
+
|
1805 |
+
static const uint8_t D4 = 4;
|
1806 |
+
|
1807 |
+
static const uint8_t D5 = 14;
|
1808 |
+
|
1809 |
+
static const uint8_t D6 = 12;
|
1810 |
+
|
1811 |
+
static const uint8_t D7 = 13;
|
1812 |
+
|
1813 |
+
static const uint8_t D8 = 0;
|
1814 |
+
|
1815 |
+
static const uint8_t D9 = 2;
|
1816 |
+
|
1817 |
+
static const uint8_t D10 = 15;
|
1818 |
+
|
1819 |
+
static const uint8_t D11 = 13;
|
1820 |
+
|
1821 |
+
static const uint8_t D12 = 12;
|
1822 |
+
|
1823 |
+
static const uint8_t D13 = 14;
|
1824 |
+
|
1825 |
+
static const uint8_t D14 = 4;
|
1826 |
+
|
1827 |
+
static const uint8_t D15 = 5;
|
1828 |
+
|
1829 |
+
The values on the lefthand side are the lables on the board.
|
1830 |
+
|
1831 |
+
A good discussion can be found here: https://forum.arduino.cc/t/wemos-d1-pins/523831
|
1832 |
+
|
1833 |
+
More on ESP8266: https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html
|
1834 |
+
|
1835 |
+
### ESP32 VGA with FabGL
|
1836 |
+
|
1837 |
+
BASIC runs on TTGO VGA ESP32 hardware boards. These boards are specifically designed for retro computin applications. They have a PS2 keyboard and mouse, a VGA adapter and an SD card slot. Many old OSes and computer games can run on them.
|
1838 |
+
|
1839 |
+
I ported the BASIC interpreter to it with a VGA 640x200 screen. The sound generator and the SD is also supported. This makes the TTGO VGA board a fully function 64 kB home computer.
|
1840 |
+
|
1841 |
+
Unlike other systems with displays, the generic BASIC display driver is not used. Instead, the built-in VT52 terminal emulation of the graphics library FabGL processes text output. This means that cursor positioning with the special variables @X and @X as well as the display array @D() does not exist on these systems. Cursor positioning has to be done with the standard VT52 control sequences. See the extensive documentation of FabGL for more information http://www.fabglib.org.
|
1842 |
+
|
1843 |
+
The sound generator of FabGL can be used with the BASIC PLAY command but the syntax is different from Arduinos. PLAY is called like this
|
1844 |
+
|
1845 |
+
PLAY n, frequency, duration, volume.
|
1846 |
+
|
1847 |
+
The parameters volume and duration are optional. Duration is measured in ms. This is like Arduinos. Setting the volume is not possible for Arduinos. The parameter is directly passed to the FabGL library. On Arduinos this parameter is ignored.
|
1848 |
+
|
1849 |
+
The first parameter n would be the pin number in an Arduino configuation. For FabGL it sets the wave form generator instead. The following values are possible:
|
1850 |
+
|
1851 |
+
128: Sine wave
|
1852 |
+
|
1853 |
+
129: Symmetric square wave
|
1854 |
+
|
1855 |
+
130: Sawtooth
|
1856 |
+
|
1857 |
+
131: Triangle
|
1858 |
+
|
1859 |
+
132: VIC noise
|
1860 |
+
|
1861 |
+
133: noise
|
1862 |
+
|
1863 |
+
256-511: Square wave with variable duty cycles, pulse length is n-255.
|
1864 |
+
|
1865 |
+
TTGO VGA hardware is supported for graphics with a 16 color VGA palette. Colors are mapped to this palette if the COLOR command is used with rgb color arguments as best as possible.
|
1866 |
+
|
1867 |
+
The SD card is supported but some cards will cause stability problems of the system.
|
1868 |
+
|
1869 |
+
Networking is possible but not really supported. There are internal memory conflicts that required to reduce BASIC RAM to 10 kB. This will be solved in version 1.4 of the interpreter.
|
1870 |
+
|
1871 |
+
### SPI RAM systems
|
1872 |
+
|
1873 |
+
8bit AVR systems have rather small RAM sizes. The UNO has just 2 kB which limits the number of appliactions. Otherwise an Arduino UNO would be a great computer for BASIC. The RAM limitation of the smaller 8bit microcontrollers can be removed by using 64kB serial RAM modules. The chips are really cheap and the can be connected easily.
|
1874 |
+
|
1875 |
+
Activating the ARDUINOSPIRAM flag on compile time will use the SPI RAM interface for memory access. If a 16 bit integer BASIC is compiled, the computer will show 32 kB of BASIC memory. If a floating point BASIC is compiled, it will see 64 kB of memory. Only 64 kByte ATMEGA 23LCV512 SPI RAM modules are supported. There is no library needed, the device driver is integrated in BASIC.
|
1876 |
+
|
1877 |
+
All BASIC commands work the same. Most of them with a similar performance as local RAM. This is due to the fact that the interpreter has two memory access mechanisms, one for the program token stream and one for read/write of variables. Both are buffered separately, reducing SPI memory access.
|
1878 |
+
|
1879 |
+
The one exception is string commands. Strings have to be copied to local memory, can be processed there and have to be compied back. String buffers of 128 bytes handle this task. For this reason, the maximum string length is restructed to 128 bytes when using the SPI RAM interface. Also, string commands should not be nested in complicated expressions. This part of the code is not tested a lot. String code is considerably slower then in direct memory situations but still faster than many old 8 bit homecomputers.
|
1880 |
+
|
1881 |
+
Well behaved BASIC programs like the game library of David Ahl in examples/14games have been tested and run on SPI RAM.
|
1882 |
+
|
1883 |
+
### Raspberry PI Wiring
|
1884 |
+
|
1885 |
+
BASIC for Raspberry PI uses the wiring pinout and not the header pinout. Please look at this table for more details: http://wiringpi.com/pins/
|
1886 |
+
|
1887 |
+
Some more can be found here: https://pi4j.com/1.2/pins/model-b-plus.html
|
1888 |
+
|
1889 |
+
## Low level commands
|
1890 |
+
|
1891 |
+
### SET
|
1892 |
+
|
1893 |
+
SET changes internal variables of the interpreter. Set has two arguments, the variable or class to be changed and a value. There is no systematic in the numbering of the variables and classes.
|
1894 |
+
|
1895 |
+
SET 0,n switches on the debug mode. The token stream in the statement loop is displayed. SET 0,0 resets the interpreter to normal mode. SET 0,1 shows the token stream of the statement loop. SET 0,2 shows the entire token stream, including arithmetic operations, SET 0,3 displays the memory addresses with this data. The latter two settings produce a lot of output and are meant for interpreter testing.
|
1896 |
+
|
1897 |
+
SET 1,1 activates the autorun mode of the EEPROM. SET 1,0 resets the autorun mode. SET 1,255 marks the EEPROM as not to contain a program. SET 1,1 should only be used if a program was stored with SAVE "!" to the EEPROM. There is no safety net here. A running program in EEPROM autorun mode can always interrupted by sending the break character. This is '#' by default and defined in the BREAKCHAR macro. Alternatively the BREAKPIN macro can be defined in hardware-arduino.h. This this case the pin it is set to will interrupt the program if set to low.
|
1898 |
+
|
1899 |
+
SET 2,1 sets the output to display mode, SET 2,0 to serial mode. This is a deprecated feature. Using @O is a better way to do this.
|
1900 |
+
|
1901 |
+
SET 3,1 sets the default output to display, SET 3,0 to serial mode. This is a risky command. If the output channel is not connected to a device the user can control, they are locked out.
|
1902 |
+
|
1903 |
+
SET 4,1 sets the input to keyboard mode, SET 4,0 to serial mode. This is a deprecated feature. Using @I is a better way to do this.
|
1904 |
+
|
1905 |
+
SET 5,1 sets the default input to keyboard, SET 5,0 to serial mode. This is a risky command. If the input channel is not connected to a device the user can control, you they are locked out.
|
1906 |
+
|
1907 |
+
SET 6,1 sets the CR output of the secondary serial port. A CR is sent after each line. SET 6,0 switches of CR. Default is off.
|
1908 |
+
|
1909 |
+
SET 7,1 switches on blockmode of the secondary serial port input. SET 7, timeout with a number timeout>1 sets an input timeout in ms. In both cases INPUT &4 does not wait for a line feed. SET 7,0 resets block mode.
|
1910 |
+
|
1911 |
+
SET 8,baud will set the baudrate of the secondary serial port and resets the port. Default is 9600.
|
1912 |
+
|
1913 |
+
SET 9,n will set the radio signal strength. n is between 0 and 3. 3 is maximal signal strength.
|
1914 |
+
|
1915 |
+
SET 10,1 sets the display update to page mode. In this mode the display does not display text or graphics until am ETX (ASCII 3) is sent.
|
1916 |
+
|
1917 |
+
SET 11,1 sets the TAB command to Microsoft mode. In this mode the TAB position is the absolute character count and not a relative postion. SET 11,0 resets the behaviout.
|
1918 |
+
|
1919 |
+
SET 12,0 sets the lower bound of all arrays to 0. This means that arrays with 8 elements DIMed with DIM A(8) go from 0 to 7 instead of 1 to 8. SET 12, 1 resets the value. This command does not change the array or anything in memory. It merely adds an offset. Any positive value can be used as an argument.
|
1920 |
+
|
1921 |
+
SET 13, 1 sets the keypad to repeat mode. This setting is only used in analog keypads of LCD shields. These keypads normally block on key press until the key is released. This makes GET a semi blocking function. With SET 13, 1 the GET command does not block. It directly returns the pressed key and does not wait for key release. SET 13, 0 resets to blocking mode.
|
1922 |
+
|
1923 |
+
More SET parameter will be implemented in the future.
|
1924 |
+
|
1925 |
+
### USR
|
1926 |
+
|
1927 |
+
USR calls a low level function, passes one value to it and returns the value. Typically USR would be used like
|
1928 |
+
|
1929 |
+
A=USR(function, parameter)
|
1930 |
+
|
1931 |
+
USR(0,x) returns an interpreter parameter or capability. The program can find out which platform it is running on. Please look at examples/00tutorial/hinv.bas for a list of the parameters and return values.
|
1932 |
+
|
1933 |
+
Function numbers 1 to 31 are assigned to the I/O streams. Currently only USR(f, 0) is implemented for all I/O streams. They output the status of the stream.
|
1934 |
+
|
1935 |
+
Function numbers 32 and above can be used to implement individual commands. See below for more information.
|
1936 |
+
|
1937 |
+
### CALL
|
1938 |
+
|
1939 |
+
Currently only CALL 0 is implemented. Call 0 flushes all buffers. On POSIX systems it ends the interpreter and returns to the OS. On Arduino AVR and ESP the microcontroller kernel is restarted.
|
1940 |
+
|
1941 |
+
CALL parameters 0 to 31 are reserved. Values from 32 on can be used for implementing own commands. See below for more information.
|
1942 |
+
|
1943 |
+
### SLEEP
|
1944 |
+
|
1945 |
+
SLEEP n enters sleep mode. This is only implemented on ESPs and SAMD right now. n is the time in milliseconds. For ESP8266 the wiring for sleep mode has to be right. ESP32 can awake from SLEEP without additional wiring. ESPs restart after wakeup. An autorun program is needed for this. Once the restart happens, the program starts from the beginning. Reentry has to be handled in the program. On Arduino SAMD the interpreter uses the low power library. The program resumes after the sleep command. Sleep is experimental right now.
|
1946 |
+
|
1947 |
+
### Stopping programs
|
1948 |
+
|
1949 |
+
There are two mechanism implemented to stop programs. One listens to the default input stream, in general this is either default serial or the keyboard. The other monitors a pin.
|
1950 |
+
|
1951 |
+
If BREAKCHAR is defined in the BASIC code, this character will stop the program if it is encountered in the input stream. It has to be found as a first character. Default BREAKCHAR is '#'. BREAKCHAR only works on Arduino implementations with keyboard and serial I/O. Posix systems cannot use BREAKCHAR as I/O is blocking on them.
|
1952 |
+
|
1953 |
+
If BREAKPIN is defined, the interpreter will stop once this pin is pulled to low. By default, BREAKPIN is not defined, i.e. there is no BREAKPIN. This mechanism is for use cases where using BREAKCHAR is not practical. One can implement a separate stop button with it.
|
1954 |
+
|
1955 |
+
If HASSIGNALS is defined in hardware-posix.h then Ctrl-C will stop a running program. This does not work on Arduino because there are no POSIX signals on the platform. This feature is alpha and currently only briefly tested on Mac and Windows.
|
1956 |
+
|
1957 |
+
### Extending basic
|
1958 |
+
|
1959 |
+
The BASIC interpreter has several mechanisms to extend the language set without having to work directly with the interpreter data structures.
|
1960 |
+
|
1961 |
+
USR(N, X) with N greater than 32 will call the function usrfunction(). It gets both arguments as values and can return one number as reault.
|
1962 |
+
|
1963 |
+
CALL N with N greater than 32 will call the function usrcall(). It gets N as an argument.
|
1964 |
+
|
1965 |
+
@U is a special variable. Reading it will call getusrvar(), writing it will call setusrvar().
|
1966 |
+
|
1967 |
+
@U() is a special array. Reading it will call getusrarray(), writing it will call setusrarray(). In both cases the index is the array is passed on as argument.
|
1968 |
+
|
1969 |
+
@U$ is the user string. It is read only. Reading it will trigger the function makeusrarray(). It can pass an set of characters to BASIC.
|
1970 |
+
|
1971 |
+
|
1972 |
+
|
1973 |
+
|
1974 |
+
|
1975 |
+
|
data/Basic1/IotBasic/basic.h
ADDED
@@ -0,0 +1,1526 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*
|
3 |
+
* $Id: basic.h,v 1.13 2023/07/16 14:17:08 stefan Exp stefan $
|
4 |
+
*
|
5 |
+
* Stefan's basic interpreter
|
6 |
+
*
|
7 |
+
* Playing around with frugal programming. See the licence file on
|
8 |
+
* https://github.com/slviajero/tinybasic for copyright/left.
|
9 |
+
* (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
|
10 |
+
*
|
11 |
+
* Author: Stefan Lenz, [email protected]
|
12 |
+
*
|
13 |
+
* basic.h are the core defintions and function protypes
|
14 |
+
*
|
15 |
+
*/
|
16 |
+
|
17 |
+
/*
|
18 |
+
* if the PROGMEM macro is define we compile on the Arduino IDE
|
19 |
+
* we undef all hardware settings otherwise a little odd
|
20 |
+
*/
|
21 |
+
#ifdef ARDUINO_ARCH_MBED
|
22 |
+
#define PROGMEM
|
23 |
+
#endif
|
24 |
+
|
25 |
+
#ifdef PROGMEM
|
26 |
+
#define ARDUINOPROGMEM
|
27 |
+
#else
|
28 |
+
#undef ARDUINO
|
29 |
+
#undef ARDUINOSD
|
30 |
+
#undef ARDUINORF24
|
31 |
+
#undef ARDUINORTC
|
32 |
+
#undef ARDUINOEEPROM
|
33 |
+
#undef ARDUINOEEPROMI2C
|
34 |
+
#undef ARDUINOWIRE
|
35 |
+
#endif
|
36 |
+
|
37 |
+
/*
|
38 |
+
* MSDOS, Mac, Linux and Windows
|
39 |
+
*/
|
40 |
+
#ifndef ARDUINO
|
41 |
+
typedef unsigned char uint8_t;
|
42 |
+
#define PROGMEM
|
43 |
+
#include <stdio.h>
|
44 |
+
#include <stdlib.h>
|
45 |
+
#ifdef HASFLOAT
|
46 |
+
#include <math.h>
|
47 |
+
#include <float.h>
|
48 |
+
#endif
|
49 |
+
#include <time.h>
|
50 |
+
#include <sys/types.h>
|
51 |
+
#include <sys/timeb.h>
|
52 |
+
#ifndef MSDOS
|
53 |
+
#include <dirent.h>
|
54 |
+
#include <unistd.h>
|
55 |
+
#else
|
56 |
+
#include <dir.h>
|
57 |
+
#include <dos.h>
|
58 |
+
#endif
|
59 |
+
#ifdef MINGW
|
60 |
+
#include <windows.h>
|
61 |
+
#endif
|
62 |
+
#endif
|
63 |
+
|
64 |
+
|
65 |
+
#if defined(ARDUINO_ARCH_AVR)
|
66 |
+
/* the small memory model with shallow stacks and small buffers */
|
67 |
+
#define BUFSIZE 80
|
68 |
+
#define STACKSIZE 15
|
69 |
+
#define GOSUBDEPTH 4
|
70 |
+
#define FORDEPTH 4
|
71 |
+
#define LINECACHESIZE 4
|
72 |
+
#else
|
73 |
+
/* the for larger microcontrollers */
|
74 |
+
#ifdef ARDUINO
|
75 |
+
#define BUFSIZE 128
|
76 |
+
#define STACKSIZE 64
|
77 |
+
#define GOSUBDEPTH 8
|
78 |
+
#define FORDEPTH 8
|
79 |
+
#define LINECACHESIZE 16
|
80 |
+
#else
|
81 |
+
/* for real computers */
|
82 |
+
#define BUFSIZE 256
|
83 |
+
#define STACKSIZE 256
|
84 |
+
#define GOSUBDEPTH 64
|
85 |
+
#define FORDEPTH 64
|
86 |
+
#define LINECACHESIZE 64
|
87 |
+
#endif
|
88 |
+
#endif
|
89 |
+
|
90 |
+
/* on the real small systems we remove the linecache and set a fixed memory size*/
|
91 |
+
#ifdef ARDUINO_AVR_DUEMILANOVE
|
92 |
+
#undef LINECACHESIZE
|
93 |
+
#if MEMSIZE == 0
|
94 |
+
#define MEMSIZE 512
|
95 |
+
#endif
|
96 |
+
#endif
|
97 |
+
|
98 |
+
/* more duffers and vars */
|
99 |
+
#define SBUFSIZE 32
|
100 |
+
#define VARSIZE 26
|
101 |
+
/* default sizes of arrays and strings if they are not DIMed */
|
102 |
+
#define ARRAYSIZEDEF 10
|
103 |
+
#define STRSIZEDEF 32
|
104 |
+
|
105 |
+
/*
|
106 |
+
* the time intervall in ms needed for
|
107 |
+
* ESP8266 yields, network client loops
|
108 |
+
* and other timing related functions
|
109 |
+
*/
|
110 |
+
#define LONGYIELDINTERVAL 1000
|
111 |
+
#define YIELDINTERVAL 32
|
112 |
+
#define YIELDTIME 2
|
113 |
+
|
114 |
+
/* the default EEPROM dummy size */
|
115 |
+
#define EEPROMSIZE 1024
|
116 |
+
|
117 |
+
/* after run behaviour on POSIX systems, 1 to terminate if started
|
118 |
+
on the command line with a file argument, 0 to stay active and
|
119 |
+
show a BASIC prompt*/
|
120 |
+
#define TERMINATEAFTERRUN 1
|
121 |
+
|
122 |
+
/*
|
123 |
+
* The tokens for the BASIC keywords
|
124 |
+
*
|
125 |
+
* All single character operators are their own tokens
|
126 |
+
* ASCII values above 0x7f are used for tokens of keywords.
|
127 |
+
* EOL is a token
|
128 |
+
*/
|
129 |
+
#define EOL 0
|
130 |
+
#define NUMBER -127
|
131 |
+
#define LINENUMBER -126
|
132 |
+
#define STRING -125
|
133 |
+
#define VARIABLE -124
|
134 |
+
#define STRINGVAR -123
|
135 |
+
#define ARRAYVAR -122
|
136 |
+
/* multi character tokens - BASEKEYWORD (3) */
|
137 |
+
#define GREATEREQUAL -121
|
138 |
+
#define LESSEREQUAL -120
|
139 |
+
#define NOTEQUAL -119
|
140 |
+
/* this is the Palo Alto Language Set (19) */
|
141 |
+
#define TPRINT -118
|
142 |
+
#define TLET -117
|
143 |
+
#define TINPUT -116
|
144 |
+
#define TGOTO -115
|
145 |
+
#define TGOSUB -114
|
146 |
+
#define TRETURN -113
|
147 |
+
#define TIF -112
|
148 |
+
#define TFOR -111
|
149 |
+
#define TTO -110
|
150 |
+
#define TSTEP -109
|
151 |
+
#define TNEXT -108
|
152 |
+
#define TSTOP -107
|
153 |
+
#define TLIST -106
|
154 |
+
#define TNEW -105
|
155 |
+
#define TRUN -104
|
156 |
+
#define TABS -103
|
157 |
+
#define TRND -102
|
158 |
+
#define TSIZE -101
|
159 |
+
#define TREM -100
|
160 |
+
/* this is the Apple 1 language set in addition to Palo Alto (14) */
|
161 |
+
#define TNOT -99
|
162 |
+
#define TAND -98
|
163 |
+
#define TOR -97
|
164 |
+
#define TLEN -96
|
165 |
+
#define TSGN -95
|
166 |
+
#define TPEEK -94
|
167 |
+
#define TDIM -93
|
168 |
+
#define TCLR -92
|
169 |
+
#define THIMEM -91
|
170 |
+
#define TTAB -90
|
171 |
+
#define TTHEN -89
|
172 |
+
#define TEND -88
|
173 |
+
#define TPOKE -87
|
174 |
+
/* Stefan's tinybasic additions (14) */
|
175 |
+
#define TCONT -86
|
176 |
+
#define TSQR -85
|
177 |
+
#define TPOW -84
|
178 |
+
#define TMAP -83
|
179 |
+
#define TDUMP -82
|
180 |
+
#define TBREAK -81
|
181 |
+
#define TSAVE -80
|
182 |
+
#define TLOAD -79
|
183 |
+
#define TGET -78
|
184 |
+
#define TPUT -77
|
185 |
+
#define TSET -76
|
186 |
+
#define TCLS -75
|
187 |
+
#define TLOCATE -74
|
188 |
+
#define TELSE -73
|
189 |
+
/* Arduino functions (10) */
|
190 |
+
#define TPINM -72
|
191 |
+
#define TDWRITE -71
|
192 |
+
#define TDREAD -70
|
193 |
+
#define TAWRITE -69
|
194 |
+
#define TAREAD -68
|
195 |
+
#define TDELAY -67
|
196 |
+
#define TMILLIS -66
|
197 |
+
#define TTONE -65
|
198 |
+
#define TPULSE -64
|
199 |
+
#define TAZERO -63
|
200 |
+
#define TLED -62
|
201 |
+
/* the DOS functions (5) */
|
202 |
+
#define TCATALOG -61
|
203 |
+
#define TDELETE -60
|
204 |
+
#define TOPEN -59
|
205 |
+
#define TCLOSE -58
|
206 |
+
#define TFDISK -57
|
207 |
+
/* low level access of internal routines (2) */
|
208 |
+
#define TUSR -56
|
209 |
+
#define TCALL -55
|
210 |
+
/* mathematical functions (7) */
|
211 |
+
#define TSIN -54
|
212 |
+
#define TCOS -53
|
213 |
+
#define TTAN -52
|
214 |
+
#define TATAN -51
|
215 |
+
#define TLOG -50
|
216 |
+
#define TEXP -49
|
217 |
+
#define TINT -48
|
218 |
+
/* graphics - experimental - rudimentary (7) */
|
219 |
+
#define TCOLOR -47
|
220 |
+
#define TPLOT -46
|
221 |
+
#define TLINE -45
|
222 |
+
#define TCIRCLE -44
|
223 |
+
#define TRECT -43
|
224 |
+
#define TFCIRCLE -42
|
225 |
+
#define TFRECT -41
|
226 |
+
/* the Dartmouth extensions (6) */
|
227 |
+
#define TDATA -40
|
228 |
+
#define TREAD -39
|
229 |
+
#define TRESTORE -38
|
230 |
+
#define TDEF -37
|
231 |
+
#define TFN -36
|
232 |
+
#define TON -35
|
233 |
+
/* darkarts (3) */
|
234 |
+
#define TMALLOC -34
|
235 |
+
#define TFIND -33
|
236 |
+
#define TEVAL -32
|
237 |
+
/* iot extensions (9) */
|
238 |
+
#define TERROR -31
|
239 |
+
#define TAVAIL -30
|
240 |
+
#define TSTR -29
|
241 |
+
#define TINSTR -28
|
242 |
+
#define TVAL -27
|
243 |
+
#define TNETSTAT -26
|
244 |
+
#define TSENSOR -25
|
245 |
+
#define TWIRE -24
|
246 |
+
#define TSLEEP -23
|
247 |
+
/* events and interrupts */
|
248 |
+
#define TAFTER -22
|
249 |
+
#define TEVERY -21
|
250 |
+
#define TEVENT -20
|
251 |
+
/* experimental structured commands, currently partially implemented */
|
252 |
+
#define TWHILE -19
|
253 |
+
#define TWEND -18
|
254 |
+
#define TREPEAT -17
|
255 |
+
#define TUNTIL -16
|
256 |
+
#define TSWITCH -15
|
257 |
+
#define TCASE -14
|
258 |
+
#define TSWEND -13
|
259 |
+
#define TDO -12
|
260 |
+
#define TDEND -11
|
261 |
+
/* these are multibyte token extension, currently unused */
|
262 |
+
/* using them would allow over 1000 BASIC keywords */
|
263 |
+
#define TEXT1 -3
|
264 |
+
/* end of tokens */
|
265 |
+
/* constants used for some obscure purposes */
|
266 |
+
#define TBUFFER -2
|
267 |
+
/* UNKNOWN is not used in the current code, the
|
268 |
+
* lexer tokenizes everything blindly. There is a UNKNOWN hook
|
269 |
+
* in statement for a grammar aware lexer */
|
270 |
+
#define UNKNOWN -1
|
271 |
+
|
272 |
+
/* extension tokens can be in the range from -128 to -255
|
273 |
+
* one needs to set HASLONGTOKENS
|
274 |
+
*/
|
275 |
+
#undef HASLONGTOKEN
|
276 |
+
#define TTOKEN1 -128
|
277 |
+
|
278 |
+
|
279 |
+
/* the number of keywords, and the base index of the keywords
|
280 |
+
* the number is irrelevant but BASEKEYWORD is used */
|
281 |
+
#define NKEYWORDS 3+19+13+14+11+5+2+7+7+6+12+3+9
|
282 |
+
#define BASEKEYWORD -121
|
283 |
+
|
284 |
+
/*
|
285 |
+
* Interpreter states
|
286 |
+
* SRUN means running from a programm
|
287 |
+
* SINT means interactive mode
|
288 |
+
* SERUN means running directly from EEPROM
|
289 |
+
* (enum would be the right way of doing this.)
|
290 |
+
* BREAKCHAR is the character stopping the program on Ardunios
|
291 |
+
* BREAKPIN can be set, it is a pin that needs to go to low to stop a BASIC program
|
292 |
+
* This should be done in hardware*.h
|
293 |
+
* BREAKSIGNAL can also be set, should be done in hardware*.h
|
294 |
+
*/
|
295 |
+
#define SINT 0
|
296 |
+
#define SRUN 1
|
297 |
+
#define SERUN 2
|
298 |
+
#define BREAKCHAR '#'
|
299 |
+
|
300 |
+
/*
|
301 |
+
* Input and output channels
|
302 |
+
*/
|
303 |
+
#define OSERIAL 1
|
304 |
+
#define ODSP 2
|
305 |
+
#define OPRT 4
|
306 |
+
#define OWIRE 7
|
307 |
+
#define ORADIO 8
|
308 |
+
#define OMQTT 9
|
309 |
+
#define OFILE 16
|
310 |
+
|
311 |
+
#define ISERIAL 1
|
312 |
+
#define IKEYBOARD 2
|
313 |
+
#define ISERIAL1 4
|
314 |
+
#define IWIRE 7
|
315 |
+
#define IRADIO 8
|
316 |
+
#define IMQTT 9
|
317 |
+
#define IFILE 16
|
318 |
+
|
319 |
+
/*
|
320 |
+
* All BASIC keywords for the tokens
|
321 |
+
*/
|
322 |
+
const char sge[] PROGMEM = "=>";
|
323 |
+
const char sle[] PROGMEM = "<=";
|
324 |
+
const char sne[] PROGMEM = "<>";
|
325 |
+
/* Palo Alto language set */
|
326 |
+
const char sprint[] PROGMEM = "PRINT";
|
327 |
+
const char slet[] PROGMEM = "LET";
|
328 |
+
const char sinput[] PROGMEM = "INPUT";
|
329 |
+
const char sgoto[] PROGMEM = "GOTO";
|
330 |
+
const char sgosub[] PROGMEM = "GOSUB";
|
331 |
+
const char sreturn[] PROGMEM = "RETURN";
|
332 |
+
const char sif[] PROGMEM = "IF";
|
333 |
+
const char sfor[] PROGMEM = "FOR";
|
334 |
+
const char sto[] PROGMEM = "TO";
|
335 |
+
const char sstep[] PROGMEM = "STEP";
|
336 |
+
const char snext[] PROGMEM = "NEXT";
|
337 |
+
const char sstop[] PROGMEM = "STOP";
|
338 |
+
const char slist[] PROGMEM = "LIST";
|
339 |
+
const char snew[] PROGMEM = "NEW";
|
340 |
+
const char srun[] PROGMEM = "RUN";
|
341 |
+
const char sabs[] PROGMEM = "ABS";
|
342 |
+
const char srnd[] PROGMEM = "RND";
|
343 |
+
const char ssize[] PROGMEM = "SIZE";
|
344 |
+
const char srem[] PROGMEM = "REM";
|
345 |
+
/* Apple 1 language set */
|
346 |
+
#ifdef HASAPPLE1
|
347 |
+
const char snot[] PROGMEM = "NOT";
|
348 |
+
const char sand[] PROGMEM = "AND";
|
349 |
+
const char sor[] PROGMEM = "OR";
|
350 |
+
const char slen[] PROGMEM = "LEN";
|
351 |
+
const char ssgn[] PROGMEM = "SGN";
|
352 |
+
const char speek[] PROGMEM = "PEEK";
|
353 |
+
const char sdim[] PROGMEM = "DIM";
|
354 |
+
const char sclr[] PROGMEM = "CLR";
|
355 |
+
const char shimem[] PROGMEM = "HIMEM";
|
356 |
+
const char stab[] PROGMEM = "TAB";
|
357 |
+
const char sthen[] PROGMEM = "THEN";
|
358 |
+
const char sbend[] PROGMEM = "END";
|
359 |
+
const char spoke[] PROGMEM = "POKE";
|
360 |
+
#endif
|
361 |
+
/* Stefan's basic additions */
|
362 |
+
#ifdef HASSTEFANSEXT
|
363 |
+
const char scont[] PROGMEM = "CONT";
|
364 |
+
const char ssqr[] PROGMEM = "SQR";
|
365 |
+
const char spow[] PROGMEM = "POW";
|
366 |
+
const char smap[] PROGMEM = "MAP";
|
367 |
+
const char sdump[] PROGMEM = "DUMP";
|
368 |
+
const char sbreak[] PROGMEM = "BREAK";
|
369 |
+
#endif
|
370 |
+
/* LOAD and SAVE is always there */
|
371 |
+
const char ssave[] PROGMEM = "SAVE";
|
372 |
+
const char sload[] PROGMEM = "LOAD";
|
373 |
+
#ifdef HASSTEFANSEXT
|
374 |
+
const char sget[] PROGMEM = "GET";
|
375 |
+
const char sput[] PROGMEM = "PUT";
|
376 |
+
const char sset[] PROGMEM = "SET";
|
377 |
+
const char scls[] PROGMEM = "CLS";
|
378 |
+
const char slocate[] PROGMEM = "LOCATE";
|
379 |
+
const char selse[] PROGMEM = "ELSE";
|
380 |
+
#endif
|
381 |
+
/* Arduino functions */
|
382 |
+
#ifdef HASARDUINOIO
|
383 |
+
const char spinm[] PROGMEM = "PINM";
|
384 |
+
const char sdwrite[] PROGMEM = "DWRITE";
|
385 |
+
const char sdread[] PROGMEM = "DREAD";
|
386 |
+
const char sawrite[] PROGMEM = "AWRITE";
|
387 |
+
const char saread[] PROGMEM = "AREAD";
|
388 |
+
const char sdelay[] PROGMEM = "DELAY";
|
389 |
+
const char smillis[] PROGMEM = "MILLIS";
|
390 |
+
const char sazero[] PROGMEM = "AZERO";
|
391 |
+
const char sled[] PROGMEM = "LED";
|
392 |
+
#endif
|
393 |
+
#ifdef HASTONE
|
394 |
+
const char stone[] PROGMEM = "PLAY";
|
395 |
+
#endif
|
396 |
+
#ifdef HASPULSE
|
397 |
+
const char spulse[] PROGMEM = "PULSE";
|
398 |
+
#endif
|
399 |
+
/* DOS functions */
|
400 |
+
#ifdef HASFILEIO
|
401 |
+
const char scatalog[] PROGMEM = "CATALOG";
|
402 |
+
const char sdelete[] PROGMEM = "DELETE";
|
403 |
+
const char sfopen[] PROGMEM = "OPEN";
|
404 |
+
const char sfclose[] PROGMEM = "CLOSE";
|
405 |
+
const char sfdisk[] PROGMEM = "FDISK";
|
406 |
+
#endif
|
407 |
+
/* low level access functions */
|
408 |
+
#ifdef HASSTEFANSEXT
|
409 |
+
const char susr[] PROGMEM = "USR";
|
410 |
+
const char scall[] PROGMEM = "CALL";
|
411 |
+
#endif
|
412 |
+
/* mathematics */
|
413 |
+
#ifdef HASFLOAT
|
414 |
+
const char ssin[] PROGMEM = "SIN";
|
415 |
+
const char scos[] PROGMEM = "COS";
|
416 |
+
const char stan[] PROGMEM = "TAN";
|
417 |
+
const char satan[] PROGMEM = "ATAN";
|
418 |
+
const char slog[] PROGMEM = "LOG";
|
419 |
+
const char sexp[] PROGMEM = "EXP";
|
420 |
+
#endif
|
421 |
+
/* INT is always needed to make float/int programs compatible */
|
422 |
+
const char sint[] PROGMEM = "INT";
|
423 |
+
/* elemetars graphics */
|
424 |
+
#ifdef HASGRAPH
|
425 |
+
const char scolor[] PROGMEM = "COLOR";
|
426 |
+
const char splot[] PROGMEM = "PLOT";
|
427 |
+
const char sline[] PROGMEM = "LINE";
|
428 |
+
const char scircle[] PROGMEM = "CIRCLE";
|
429 |
+
const char srect[] PROGMEM = "RECT";
|
430 |
+
const char sfcircle[] PROGMEM = "FCIRCLE";
|
431 |
+
const char sfrect[] PROGMEM = "FRECT";
|
432 |
+
#endif
|
433 |
+
/* Dartmouth BASIC extensions */
|
434 |
+
#ifdef HASDARTMOUTH
|
435 |
+
const char sdata[] PROGMEM = "DATA";
|
436 |
+
const char sread[] PROGMEM = "READ";
|
437 |
+
const char srestore[] PROGMEM = "RESTORE";
|
438 |
+
const char sdef[] PROGMEM = "DEF";
|
439 |
+
const char sfn[] PROGMEM = "FN";
|
440 |
+
const char son[] PROGMEM = "ON";
|
441 |
+
#endif
|
442 |
+
/* The Darkarts commands unthinkable in Dartmouth */
|
443 |
+
#ifdef HASDARKARTS
|
444 |
+
const char smalloc[] PROGMEM = "MALLOC";
|
445 |
+
const char sfind[] PROGMEM = "FIND";
|
446 |
+
const char seval[] PROGMEM = "EVAL";
|
447 |
+
#endif
|
448 |
+
/* complex error handling */
|
449 |
+
#ifdef HASERRORHANDLING
|
450 |
+
const char serror[] PROGMEM = "ERROR";
|
451 |
+
#endif
|
452 |
+
/* iot extensions */
|
453 |
+
#ifdef HASIOT
|
454 |
+
const char savail[] PROGMEM = "AVAIL";
|
455 |
+
const char sstr[] PROGMEM = "STR";
|
456 |
+
const char sinstr[] PROGMEM = "INSTR";
|
457 |
+
const char sval[] PROGMEM = "VAL";
|
458 |
+
const char snetstat[] PROGMEM = "NETSTAT";
|
459 |
+
const char ssensor[] PROGMEM = "SENSOR";
|
460 |
+
const char swire[] PROGMEM = "WIRE";
|
461 |
+
const char ssleep[] PROGMEM = "SLEEP";
|
462 |
+
#endif
|
463 |
+
/* events and interrupts */
|
464 |
+
#ifdef HASTIMER
|
465 |
+
const char safter[] PROGMEM = "AFTER";
|
466 |
+
const char severy[] PROGMEM = "EVERY";
|
467 |
+
#endif
|
468 |
+
#ifdef HASEVENTS
|
469 |
+
const char sevent[] PROGMEM = "EVENT";
|
470 |
+
#endif
|
471 |
+
#ifdef HASSTRUCT
|
472 |
+
const char swhile[] PROGMEM = "WHILE";
|
473 |
+
const char swend[] PROGMEM = "WEND";
|
474 |
+
const char srepeat[] PROGMEM = "REPEAT";
|
475 |
+
const char suntil[] PROGMEM = "UNTIL";
|
476 |
+
const char sswitch[] PROGMEM = "SWITCH";
|
477 |
+
const char scase[] PROGMEM = "CASE";
|
478 |
+
const char sswend[] PROGMEM = "SWEND";
|
479 |
+
const char sdo[] PROGMEM = "DO";
|
480 |
+
const char sdend[] PROGMEM = "DEND";
|
481 |
+
#endif
|
482 |
+
|
483 |
+
|
484 |
+
/* zero terminated keyword storage */
|
485 |
+
const char* const keyword[] PROGMEM = {
|
486 |
+
sge, sle, sne, sprint, slet, sinput,
|
487 |
+
sgoto, sgosub, sreturn, sif, sfor, sto,
|
488 |
+
sstep, snext, sstop, slist, snew, srun,
|
489 |
+
sabs, srnd, ssize, srem,
|
490 |
+
#ifdef HASAPPLE1
|
491 |
+
snot, sand, sor, slen, ssgn, speek, sdim,
|
492 |
+
sclr, shimem, stab, sthen,
|
493 |
+
sbend, spoke,
|
494 |
+
#endif
|
495 |
+
#ifdef HASSTEFANSEXT
|
496 |
+
scont, ssqr, spow, smap, sdump, sbreak,
|
497 |
+
#endif
|
498 |
+
ssave, sload,
|
499 |
+
#ifdef HASSTEFANSEXT
|
500 |
+
sget, sput, sset, scls, slocate, selse,
|
501 |
+
#endif
|
502 |
+
#ifdef HASARDUINOIO
|
503 |
+
spinm, sdwrite, sdread, sawrite, saread,
|
504 |
+
sdelay, smillis, sazero, sled,
|
505 |
+
#endif
|
506 |
+
#ifdef HASTONE
|
507 |
+
stone,
|
508 |
+
#endif
|
509 |
+
#ifdef HASPULSE
|
510 |
+
spulse,
|
511 |
+
#endif
|
512 |
+
#ifdef HASFILEIO
|
513 |
+
scatalog, sdelete, sfopen, sfclose, sfdisk,
|
514 |
+
#endif
|
515 |
+
#ifdef HASSTEFANSEXT
|
516 |
+
susr, scall,
|
517 |
+
#endif
|
518 |
+
#ifdef HASFLOAT
|
519 |
+
ssin, scos, stan, satan, slog, sexp,
|
520 |
+
#endif
|
521 |
+
sint,
|
522 |
+
#ifdef HASGRAPH
|
523 |
+
scolor, splot, sline, scircle, srect,
|
524 |
+
sfcircle, sfrect,
|
525 |
+
#endif
|
526 |
+
#ifdef HASDARTMOUTH
|
527 |
+
sdata, sread, srestore, sdef, sfn, son,
|
528 |
+
#endif
|
529 |
+
#ifdef HASDARKARTS
|
530 |
+
smalloc, sfind, seval,
|
531 |
+
#endif
|
532 |
+
/* complex error handling */
|
533 |
+
#ifdef HASERRORHANDLING
|
534 |
+
serror,
|
535 |
+
#endif
|
536 |
+
#ifdef HASIOT
|
537 |
+
savail, sstr, sinstr, sval,
|
538 |
+
snetstat, ssensor, swire, ssleep,
|
539 |
+
#endif
|
540 |
+
#ifdef HASTIMER
|
541 |
+
safter, severy,
|
542 |
+
#endif
|
543 |
+
#ifdef HASEVENTS
|
544 |
+
sevent,
|
545 |
+
#endif
|
546 |
+
#ifdef HASSTRUCT
|
547 |
+
swhile, swend, srepeat, suntil, sswitch, scase, sswend,
|
548 |
+
sdo, sdend,
|
549 |
+
#endif
|
550 |
+
0
|
551 |
+
};
|
552 |
+
|
553 |
+
/* the zero terminated token dictonary needed for scalability */
|
554 |
+
const signed char tokens[] PROGMEM = {
|
555 |
+
GREATEREQUAL, LESSEREQUAL, NOTEQUAL, TPRINT, TLET,
|
556 |
+
TINPUT, TGOTO, TGOSUB, TRETURN, TIF, TFOR, TTO, TSTEP,
|
557 |
+
TNEXT, TSTOP, TLIST, TNEW, TRUN, TABS, TRND, TSIZE, TREM,
|
558 |
+
#ifdef HASAPPLE1
|
559 |
+
TNOT, TAND, TOR, TLEN, TSGN, TPEEK, TDIM, TCLR,
|
560 |
+
THIMEM, TTAB, TTHEN, TEND, TPOKE,
|
561 |
+
#endif
|
562 |
+
#ifdef HASSTEFANSEXT
|
563 |
+
TCONT, TSQR, TPOW, TMAP, TDUMP, TBREAK,
|
564 |
+
#endif
|
565 |
+
TSAVE, TLOAD,
|
566 |
+
#ifdef HASSTEFANSEXT
|
567 |
+
TGET, TPUT, TSET, TCLS, TLOCATE, TELSE,
|
568 |
+
#endif
|
569 |
+
#ifdef HASARDUINOIO
|
570 |
+
TPINM, TDWRITE, TDREAD, TAWRITE, TAREAD, TDELAY, TMILLIS,
|
571 |
+
TAZERO, TLED,
|
572 |
+
#endif
|
573 |
+
#ifdef HASTONE
|
574 |
+
TTONE,
|
575 |
+
#endif
|
576 |
+
#ifdef HASPULSE
|
577 |
+
TPULSE,
|
578 |
+
#endif
|
579 |
+
#ifdef HASFILEIO
|
580 |
+
TCATALOG, TDELETE, TOPEN, TCLOSE, TFDISK,
|
581 |
+
#endif
|
582 |
+
#ifdef HASSTEFANSEXT
|
583 |
+
TUSR, TCALL,
|
584 |
+
#endif
|
585 |
+
#ifdef HASFLOAT
|
586 |
+
TSIN, TCOS, TTAN, TATAN, TLOG, TEXP,
|
587 |
+
#endif
|
588 |
+
TINT,
|
589 |
+
#ifdef HASGRAPH
|
590 |
+
TCOLOR, TPLOT, TLINE, TCIRCLE, TRECT,
|
591 |
+
TFCIRCLE, TFRECT,
|
592 |
+
#endif
|
593 |
+
#ifdef HASDARTMOUTH
|
594 |
+
TDATA, TREAD, TRESTORE, TDEF, TFN, TON,
|
595 |
+
#endif
|
596 |
+
#ifdef HASDARKARTS
|
597 |
+
TMALLOC, TFIND, TEVAL,
|
598 |
+
#endif
|
599 |
+
#ifdef HASERRORHANDLING
|
600 |
+
TERROR,
|
601 |
+
#endif
|
602 |
+
#ifdef HASIOT
|
603 |
+
TAVAIL, TSTR, TINSTR, TVAL, TNETSTAT,
|
604 |
+
TSENSOR, TWIRE, TSLEEP,
|
605 |
+
#endif
|
606 |
+
#ifdef HASTIMER
|
607 |
+
TAFTER, TEVERY,
|
608 |
+
#endif
|
609 |
+
#ifdef HASEVENTS
|
610 |
+
TEVENT,
|
611 |
+
#endif
|
612 |
+
#ifdef HASSTRUCT
|
613 |
+
TWHILE, TWEND, TREPEAT, TUNTIL, TSWITCH, TCASE, TSWEND,
|
614 |
+
TDO, TDEND,
|
615 |
+
#endif
|
616 |
+
0
|
617 |
+
};
|
618 |
+
|
619 |
+
/*
|
620 |
+
* the message catalog
|
621 |
+
*/
|
622 |
+
#define MFILE 0
|
623 |
+
#define MPROMPT 1
|
624 |
+
#define MGREET 2
|
625 |
+
#define MLINE 3
|
626 |
+
#define MNUMBER 4
|
627 |
+
#define MVARIABLE 5
|
628 |
+
#define MARRAY 6
|
629 |
+
#define MSTRING 7
|
630 |
+
#define MSTRINGVAR 8
|
631 |
+
#define EGENERAL 9
|
632 |
+
#define EUNKNOWN 10
|
633 |
+
#define ENUMBER 11
|
634 |
+
#define EDIVIDE 12
|
635 |
+
#define ELINE 13
|
636 |
+
#define EOUTOFMEMORY 14
|
637 |
+
#define ESTACK 15
|
638 |
+
#define EORANGE 16
|
639 |
+
#define ESTRING 17
|
640 |
+
#define EVARIABLE 18
|
641 |
+
#define ELOOP 19
|
642 |
+
#define EFILE 20
|
643 |
+
#define EFUN 21
|
644 |
+
#define EARGS 22
|
645 |
+
#define EEEPROM 23
|
646 |
+
#define ESDCARD 24
|
647 |
+
|
648 |
+
const char mfile[] PROGMEM = "file.bas";
|
649 |
+
const char mprompt[] PROGMEM = "> ";
|
650 |
+
const char mgreet[] PROGMEM = "Stefan's Basic 1.4";
|
651 |
+
const char mline[] PROGMEM = "LINE";
|
652 |
+
const char mnumber[] PROGMEM = "NUMBER";
|
653 |
+
const char mvariable[] PROGMEM = "VARIABLE";
|
654 |
+
const char marray[] PROGMEM = "ARRAY";
|
655 |
+
const char mstring[] PROGMEM = "STRING";
|
656 |
+
const char mstringv[] PROGMEM = "STRINGVAR";
|
657 |
+
const char egeneral[] PROGMEM = "Error";
|
658 |
+
#ifdef HASERRORMSG
|
659 |
+
const char eunknown[] PROGMEM = "Syntax";
|
660 |
+
const char enumber[] PROGMEM = "Number";
|
661 |
+
const char edivide[] PROGMEM = "Div by 0";
|
662 |
+
const char eline[] PROGMEM = "Unknown Line";
|
663 |
+
const char emem[] PROGMEM = "Memory";
|
664 |
+
const char estack[] PROGMEM = "Stack";
|
665 |
+
const char erange[] PROGMEM = "Range";
|
666 |
+
const char estring[] PROGMEM = "String";
|
667 |
+
const char evariable[] PROGMEM = "Variable";
|
668 |
+
const char eloop[] PROGMEM = "Loop";
|
669 |
+
const char efile[] PROGMEM = "File";
|
670 |
+
const char efun[] PROGMEM = "Function";
|
671 |
+
const char eargs[] PROGMEM = "Args";
|
672 |
+
const char eeeprom[] PROGMEM = "EEPROM";
|
673 |
+
const char esdcard[] PROGMEM = "SD card";
|
674 |
+
#endif
|
675 |
+
|
676 |
+
const char* const message[] PROGMEM = {
|
677 |
+
mfile, mprompt, mgreet,
|
678 |
+
mline, mnumber, mvariable, marray,
|
679 |
+
mstring, mstringv,
|
680 |
+
egeneral
|
681 |
+
#ifdef HASERRORMSG
|
682 |
+
, eunknown, enumber, edivide, eline,
|
683 |
+
emem, estack, erange,
|
684 |
+
estring, evariable, eloop, efile, efun, eargs,
|
685 |
+
eeeprom, esdcard
|
686 |
+
#endif
|
687 |
+
};
|
688 |
+
|
689 |
+
/*
|
690 |
+
* code for variable numbers and addresses sizes
|
691 |
+
* the original code was 16 bit but can be extended here
|
692 |
+
* to arbitrary types
|
693 |
+
*
|
694 |
+
* number_t is the type for numerical work - either float or int
|
695 |
+
* wnumber_t is the type containing the largest printable integer,
|
696 |
+
* for float keep this int on 32 bit and long on 8 bit unless you
|
697 |
+
* want to use very long integers, like 64 or 128 bit types.
|
698 |
+
* address_t is an unsigned type adddressing memory, default 16bit
|
699 |
+
* mem_t is a SIGNED 8bit character type.
|
700 |
+
* index_t is a SIGNED minimum 16 bit integer type
|
701 |
+
*
|
702 |
+
* works with the tacit assumption that
|
703 |
+
* sizeof(number_t) >= sizeof(address_t)
|
704 |
+
* and that the entire memory is smaller than the positive
|
705 |
+
* part of number type (!!)
|
706 |
+
*
|
707 |
+
* we assume that float >= 4 bytes in the following
|
708 |
+
*
|
709 |
+
* maxnum: the maximum accurate(!) integer of a
|
710 |
+
* 32 bit float
|
711 |
+
* strindexsize: the index size of strings either
|
712 |
+
* 1 byte or 2 bytes - no other values supported
|
713 |
+
*/
|
714 |
+
#ifdef HASFLOAT
|
715 |
+
typedef float number_t;
|
716 |
+
const number_t maxnum=16777216;
|
717 |
+
typedef long wnumber_t;
|
718 |
+
#else
|
719 |
+
typedef int number_t;
|
720 |
+
typedef int wnumber_t;
|
721 |
+
const number_t maxnum=(number_t)~((number_t)1<<(sizeof(number_t)*8-1));
|
722 |
+
#endif
|
723 |
+
typedef unsigned short address_t; /* this type addresses memory */
|
724 |
+
const int numsize=sizeof(number_t);
|
725 |
+
const int addrsize=sizeof(address_t);
|
726 |
+
const int eheadersize=sizeof(address_t)+1;
|
727 |
+
const int strindexsize=2; /* default in the meantime, strings up to unsigned 16 bit length */
|
728 |
+
const address_t maxaddr=(address_t)(~0);
|
729 |
+
typedef signed char mem_t; /* a signed 8 bit type for the memory */
|
730 |
+
typedef int index_t; /* this type counts at least 16 bit */
|
731 |
+
#ifndef HASLONGTOKENS
|
732 |
+
typedef signed char token_t; /* the type of tokens, normally mem_t with a maximum of 127 commands and data types */
|
733 |
+
#else
|
734 |
+
typedef short token_t; /* token type extension, allows an extra of 127 commands and symbols */
|
735 |
+
#endif
|
736 |
+
|
737 |
+
/* this type maps numbers to bytes */
|
738 |
+
typedef struct {mem_t l; mem_t h;} twobytes_t;
|
739 |
+
typedef union { number_t i; address_t a; twobytes_t b; mem_t c[sizeof(number_t)]; } accu_t;
|
740 |
+
|
741 |
+
/* the memreader function type */
|
742 |
+
typedef mem_t (*memreader_t)(address_t);
|
743 |
+
|
744 |
+
/*
|
745 |
+
* system type identifiers
|
746 |
+
*/
|
747 |
+
|
748 |
+
#define SYSTYPE_UNKNOWN 0
|
749 |
+
#define SYSTYPE_AVR 1
|
750 |
+
#define SYSTYPE_ESP8266 2
|
751 |
+
#define SYSTYPE_ESP32 3
|
752 |
+
#define SYSTYPE_RP2040 4
|
753 |
+
#define SYSTYPE_SAM 5
|
754 |
+
#define SYSTYPE_XMC 6
|
755 |
+
#define SYSTYPE_SMT32 7
|
756 |
+
#define SYSTYPE_NRENESA 8
|
757 |
+
#define SYSTYPE_POSIX 32
|
758 |
+
#define SYSTYPE_MSDOS 33
|
759 |
+
#define SYSTYPE_MINGW 34
|
760 |
+
#define SYSTYPE_RASPPI 35
|
761 |
+
|
762 |
+
/*
|
763 |
+
* The basic interpreter is implemented as a stack machine
|
764 |
+
* with global variable for the interpreter state, the memory
|
765 |
+
* and the arithmetic during run time.
|
766 |
+
*/
|
767 |
+
|
768 |
+
/* the stack, all BASIC arithmetic is done here */
|
769 |
+
number_t stack[STACKSIZE];
|
770 |
+
address_t sp=0;
|
771 |
+
|
772 |
+
/* a small buffer to process string arguments, mostly used for Arduino PROGMEM */
|
773 |
+
char sbuffer[SBUFSIZE];
|
774 |
+
|
775 |
+
/* the input buffer, the lexer can tokenize this and run from it, bi is an index to this.
|
776 |
+
bi must be global as it is the program cursor in interactive mode */
|
777 |
+
char ibuffer[BUFSIZE] = "\0";
|
778 |
+
char *bi;
|
779 |
+
|
780 |
+
/* a static array of variables A-Z for the small systems that have no heap */
|
781 |
+
number_t vars[VARSIZE];
|
782 |
+
|
783 |
+
/* the BASIC working memory, either malloced or allocated as a global array */
|
784 |
+
#if MEMSIZE != 0
|
785 |
+
mem_t mem[MEMSIZE];
|
786 |
+
#else
|
787 |
+
mem_t* mem;
|
788 |
+
#endif
|
789 |
+
address_t himem, memsize;
|
790 |
+
|
791 |
+
/* the for stack - remembers the variable, indices, and optionally a type for stuctured BASIC */
|
792 |
+
struct forstackitem {mem_t varx; mem_t vary; address_t here; number_t to; number_t step;
|
793 |
+
#ifdef HASSTRUCT
|
794 |
+
mem_t type;
|
795 |
+
#endif
|
796 |
+
} forstack[FORDEPTH];
|
797 |
+
index_t forsp = 0;
|
798 |
+
|
799 |
+
/* the GOSUB stack remembers an address to jump to */
|
800 |
+
address_t gosubstack[GOSUBDEPTH];
|
801 |
+
index_t gosubsp = 0;
|
802 |
+
|
803 |
+
/* this variable stores the location in pushlocation() and poplocation(), used to rewind the program cursor */
|
804 |
+
address_t slocation;
|
805 |
+
|
806 |
+
/* arithmetic accumulators - used by many statements, y may be obsolete in future*/
|
807 |
+
number_t x, y;
|
808 |
+
|
809 |
+
/* the names of a variable and small integer accumulator */
|
810 |
+
mem_t xc, yc;
|
811 |
+
|
812 |
+
/* an address accumulator, used a lot in string operations */
|
813 |
+
address_t ax;
|
814 |
+
|
815 |
+
/* z is another accumulator used to convert numbers and addressed to bytes and vice versa */
|
816 |
+
/* this union is used to store larger objects into byte oriented memory */
|
817 |
+
accu_t z;
|
818 |
+
|
819 |
+
/* string index registers */
|
820 |
+
char *ir, *ir2;
|
821 |
+
|
822 |
+
/* the active token */
|
823 |
+
token_t token;
|
824 |
+
|
825 |
+
/* the curent error, can be a token, hance token type */
|
826 |
+
token_t er;
|
827 |
+
|
828 |
+
/* a trapable error */
|
829 |
+
mem_t ert;
|
830 |
+
|
831 |
+
/* the interpreter state, interactive, run or run from EEPROM */
|
832 |
+
mem_t st;
|
833 |
+
|
834 |
+
/* the current program location or "cursor" */
|
835 |
+
address_t here;
|
836 |
+
|
837 |
+
/* the topmost byte of a program in memory, beginning of free BASIC RAM */
|
838 |
+
address_t top;
|
839 |
+
|
840 |
+
/* the number of variables on the heap */
|
841 |
+
address_t nvars = 0;
|
842 |
+
|
843 |
+
/* used to format output with # */
|
844 |
+
mem_t form = 0;
|
845 |
+
|
846 |
+
/* counts the outputed characters on streams 0-3, used to emulate a real tab */
|
847 |
+
#ifdef HASMSTAB
|
848 |
+
mem_t charcount[3]; /* devices 1-4 support tabing */
|
849 |
+
mem_t reltab = 0;
|
850 |
+
#endif
|
851 |
+
|
852 |
+
/* the lower limit of the array is one by default, can be a variable */
|
853 |
+
#ifdef HASARRAYLIMIT
|
854 |
+
address_t arraylimit = 1;
|
855 |
+
#else
|
856 |
+
const address_t arraylimit = 1;
|
857 |
+
#endif
|
858 |
+
|
859 |
+
/* the number of arguments parsed from a command */
|
860 |
+
mem_t args;
|
861 |
+
|
862 |
+
/* the random number seed, this is unsigned hence address_t */
|
863 |
+
#ifndef HASFLOAT
|
864 |
+
address_t rd;
|
865 |
+
#else
|
866 |
+
unsigned long rd;
|
867 |
+
#endif
|
868 |
+
|
869 |
+
/* output and input channels, used to direct output to various devices */
|
870 |
+
mem_t id;
|
871 |
+
mem_t od;
|
872 |
+
|
873 |
+
/* default IO - not constant, can be changed at runtime through a user call */
|
874 |
+
mem_t idd = ISERIAL;
|
875 |
+
mem_t odd = OSERIAL;
|
876 |
+
|
877 |
+
/* the runtime debuglevel */
|
878 |
+
mem_t debuglevel = 0;
|
879 |
+
|
880 |
+
/* DATA pointer, where is the current READ statement */
|
881 |
+
#ifdef HASDARTMOUTH
|
882 |
+
address_t data = 0;
|
883 |
+
address_t datarc = 1;
|
884 |
+
#endif
|
885 |
+
|
886 |
+
/*
|
887 |
+
* process command line arguments in the POSIX world
|
888 |
+
* bnointafterrun is a flag to remember if called as command
|
889 |
+
* line argument, in this case we don't return to interactive
|
890 |
+
*/
|
891 |
+
#ifndef ARDUINO
|
892 |
+
int bargc;
|
893 |
+
char** bargv;
|
894 |
+
mem_t bnointafterrun = 0;
|
895 |
+
#endif
|
896 |
+
|
897 |
+
/*
|
898 |
+
* Yield counter, we count when we did yield the last time
|
899 |
+
* lastyield controlls the client loops of network functions
|
900 |
+
* like mqtt, scanned keyboard, and USB.
|
901 |
+
*
|
902 |
+
* lastlongyield controls longterm functions like DHCP lease
|
903 |
+
* renewal in Ethernet
|
904 |
+
*
|
905 |
+
* there variables are only needed if the platform has background
|
906 |
+
* tasks
|
907 |
+
*/
|
908 |
+
long lastyield=0;
|
909 |
+
long lastlongyield=0;
|
910 |
+
|
911 |
+
/* formaters lastouttoken and spaceafterkeyword to make a nice LIST */
|
912 |
+
mem_t lastouttoken;
|
913 |
+
mem_t spaceafterkeyword;
|
914 |
+
mem_t outliteral = 0;
|
915 |
+
mem_t lexliteral = 0;
|
916 |
+
|
917 |
+
/*
|
918 |
+
* the cache for the heap search - helps the string code
|
919 |
+
* the last found object on the heap is remembered. This is needed
|
920 |
+
* because the string code sometime searches the heap twice during the
|
921 |
+
* same operation.
|
922 |
+
*/
|
923 |
+
#ifdef HASAPPLE1
|
924 |
+
mem_t bfindc, bfindd, bfindt;
|
925 |
+
address_t bfinda, bfindz;
|
926 |
+
#endif
|
927 |
+
|
928 |
+
/*
|
929 |
+
* a variable for some string operations
|
930 |
+
*/
|
931 |
+
int vlength;
|
932 |
+
|
933 |
+
/* the timer code - very simple needs to to to a struct */
|
934 |
+
/* timer type */
|
935 |
+
typedef struct {
|
936 |
+
mem_t enabled;
|
937 |
+
unsigned long last;
|
938 |
+
unsigned long interval;
|
939 |
+
mem_t type;
|
940 |
+
address_t linenumber;
|
941 |
+
} btimer_t;
|
942 |
+
|
943 |
+
#ifdef HASTIMER
|
944 |
+
btimer_t after_timer = {0, 0, 0, 0, 0};
|
945 |
+
btimer_t every_timer = {0, 0, 0, 0, 0};
|
946 |
+
#endif
|
947 |
+
|
948 |
+
/* the event code */
|
949 |
+
#ifdef HASEVENTS
|
950 |
+
|
951 |
+
#define EVENTLISTSIZE 4
|
952 |
+
|
953 |
+
/* event type */
|
954 |
+
typedef struct {
|
955 |
+
mem_t enabled;
|
956 |
+
mem_t pin;
|
957 |
+
mem_t mode;
|
958 |
+
mem_t type;
|
959 |
+
address_t linenumber;
|
960 |
+
mem_t active;
|
961 |
+
} bevent_t;
|
962 |
+
|
963 |
+
/* the event list */
|
964 |
+
int nevents = 0;
|
965 |
+
int ievent = 0;
|
966 |
+
static mem_t events_enabled = 1;
|
967 |
+
static volatile bevent_t eventlist[EVENTLISTSIZE];
|
968 |
+
|
969 |
+
/* the extension of the GOSUB stack */
|
970 |
+
static mem_t gosubarg[GOSUBDEPTH];
|
971 |
+
|
972 |
+
/* handle the event list */
|
973 |
+
mem_t addevent(mem_t, mem_t, mem_t, address_t);
|
974 |
+
void deleteevent(mem_t);
|
975 |
+
volatile bevent_t* findevent(mem_t);
|
976 |
+
mem_t eventindex(mem_t);
|
977 |
+
#endif
|
978 |
+
|
979 |
+
#ifdef HASERRORHANDLING
|
980 |
+
/* the error handler type, very simple for now */
|
981 |
+
typedef struct {
|
982 |
+
mem_t type;
|
983 |
+
address_t linenumber;
|
984 |
+
} berrorh_t;
|
985 |
+
|
986 |
+
berrorh_t berrorh = {0 , 0};
|
987 |
+
mem_t erh = 0;
|
988 |
+
#endif
|
989 |
+
|
990 |
+
/* the string for real time clocks */
|
991 |
+
char rtcstring[20] = { 0 };
|
992 |
+
|
993 |
+
/* the units pulse operates on, in microseconds*/
|
994 |
+
short bpulseunit = 10;
|
995 |
+
|
996 |
+
/* only needed for POSIXNONBLOCKING */
|
997 |
+
mem_t breakcondition = 0;
|
998 |
+
|
999 |
+
/*
|
1000 |
+
* Function prototypes, ordered by layers
|
1001 |
+
* HAL - hardware abstraction
|
1002 |
+
* Layer 0 - memory and I/O
|
1003 |
+
* Layer 1 - Program storage and control
|
1004 |
+
* Layer 2 - Where stuff happens
|
1005 |
+
*/
|
1006 |
+
|
1007 |
+
/*
|
1008 |
+
* HAL - see hardware-*.h
|
1009 |
+
* This is the hardware abstraction layer of the BASIC
|
1010 |
+
* interpreter
|
1011 |
+
*/
|
1012 |
+
|
1013 |
+
/* setup codes */
|
1014 |
+
void timeinit();
|
1015 |
+
void wiringbegin();
|
1016 |
+
|
1017 |
+
/* low level mem and hardware features */
|
1018 |
+
long freeRam();
|
1019 |
+
long freememorysize();
|
1020 |
+
void restartsystem();
|
1021 |
+
void activatesleep(long t);
|
1022 |
+
|
1023 |
+
/* start the spi bus */
|
1024 |
+
void spibegin();
|
1025 |
+
|
1026 |
+
/*
|
1027 |
+
* the hardware interface display driver functions, need to be
|
1028 |
+
* implemented for the display driver to work
|
1029 |
+
* dspupdate() only for display like Epapers
|
1030 |
+
*/
|
1031 |
+
void dspbegin();
|
1032 |
+
void dspprintchar(char, mem_t, mem_t);
|
1033 |
+
void dspclear();
|
1034 |
+
void dspupdate();
|
1035 |
+
|
1036 |
+
/* keyboard code */
|
1037 |
+
void kbdbegin();
|
1038 |
+
int kbdstat(char);
|
1039 |
+
char kbdavailable();
|
1040 |
+
char kbdread();
|
1041 |
+
char kbdcheckch();
|
1042 |
+
|
1043 |
+
/* graphics functions */
|
1044 |
+
void rgbcolor(int, int, int);
|
1045 |
+
void vgacolor(short c);
|
1046 |
+
void vgascale(int*, int*);
|
1047 |
+
void plot(int, int);
|
1048 |
+
void line(int, int, int, int);
|
1049 |
+
void rect(int, int, int, int);
|
1050 |
+
void frect(int, int, int, int);
|
1051 |
+
void circle(int, int, int);
|
1052 |
+
void fcircle(int, int, int);
|
1053 |
+
|
1054 |
+
/* text output to a VGA display */
|
1055 |
+
void vgabegin();
|
1056 |
+
int vgastat(char);
|
1057 |
+
void vgawrite(char);
|
1058 |
+
|
1059 |
+
/* generic display code */
|
1060 |
+
void dspwrite(char);
|
1061 |
+
void dspbegin();
|
1062 |
+
int dspstat(char);
|
1063 |
+
char dspwaitonscroll();
|
1064 |
+
char dspactive();
|
1065 |
+
void dspsetupdatemode(char);
|
1066 |
+
char dspgetupdatemode();
|
1067 |
+
void dspgraphupdate();
|
1068 |
+
void dspsetscrollmode(char, short);
|
1069 |
+
void dspsetcursor(short, short);
|
1070 |
+
void dspbufferclear();
|
1071 |
+
void dspscroll(mem_t, mem_t);
|
1072 |
+
void dspreversescroll(mem_t);
|
1073 |
+
void dspvt52(char *);
|
1074 |
+
|
1075 |
+
/* real time clock */
|
1076 |
+
char* rtcmkstr();
|
1077 |
+
void rtcset(uint8_t, short);
|
1078 |
+
short rtcget(short);
|
1079 |
+
|
1080 |
+
/* network and mqtt functions */
|
1081 |
+
void netbegin();
|
1082 |
+
char netconnected();
|
1083 |
+
void mqttsetname();
|
1084 |
+
void mqttbegin();
|
1085 |
+
int mqttstat(char);
|
1086 |
+
int mqttstate();
|
1087 |
+
void mqttsubscribe(char*);
|
1088 |
+
void mqttsettopic(char*);
|
1089 |
+
void mqttouts(char *, short);
|
1090 |
+
void mqttins(char *, short);
|
1091 |
+
char mqttinch();
|
1092 |
+
|
1093 |
+
/* low level EEPROM handling */
|
1094 |
+
void ebegin();
|
1095 |
+
void eflush();
|
1096 |
+
address_t elength();
|
1097 |
+
mem_t eread(address_t);
|
1098 |
+
void eupdate(address_t, mem_t);
|
1099 |
+
|
1100 |
+
/* arduino io functions */
|
1101 |
+
void aread();
|
1102 |
+
void dread();
|
1103 |
+
void awrite(address_t, address_t);
|
1104 |
+
void dwrite(address_t, address_t);
|
1105 |
+
void pinm(address_t, address_t);
|
1106 |
+
void bmillis();
|
1107 |
+
void bpulsein();
|
1108 |
+
void xpulse();
|
1109 |
+
void bpulseout(short);
|
1110 |
+
void btone(short);
|
1111 |
+
|
1112 |
+
/* timing control for ESP and network */
|
1113 |
+
void byield();
|
1114 |
+
void bdelay(unsigned long);
|
1115 |
+
void fastticker();
|
1116 |
+
void yieldfunction();
|
1117 |
+
void longyieldfunction();
|
1118 |
+
|
1119 |
+
/* the file interface */
|
1120 |
+
char* mkfilename(const char*);
|
1121 |
+
const char* rmrootfsprefix(const char*);
|
1122 |
+
void fsbegin(char);
|
1123 |
+
int fsstat(char);
|
1124 |
+
void filewrite(char);
|
1125 |
+
char fileread();
|
1126 |
+
char ifileopen(const char*);
|
1127 |
+
void ifileclose();
|
1128 |
+
char ofileopen(char*, const char*);
|
1129 |
+
void ofileclose();
|
1130 |
+
int fileavailable();
|
1131 |
+
void rootopen();
|
1132 |
+
int rootnextfile();
|
1133 |
+
int rootisfile();
|
1134 |
+
const char* rootfilename();
|
1135 |
+
long rootfilesize();
|
1136 |
+
void rootfileclose();
|
1137 |
+
void rootclose();
|
1138 |
+
void removefile(char*);
|
1139 |
+
void formatdisk(short);
|
1140 |
+
|
1141 |
+
/* low level serial code */
|
1142 |
+
void picogetchar(char);
|
1143 |
+
void picowrite(char);
|
1144 |
+
void picobegin(unsigned long);
|
1145 |
+
void picoins(char, short);
|
1146 |
+
void serialbegin();
|
1147 |
+
int serialstat(char);
|
1148 |
+
char serialread();
|
1149 |
+
void serialwrite(char);
|
1150 |
+
short serialcheckch();
|
1151 |
+
short serialavailable();
|
1152 |
+
void serialflush();
|
1153 |
+
void consins(char*, short);
|
1154 |
+
void prtbegin();
|
1155 |
+
int prtstat(char);
|
1156 |
+
void prtset(int);
|
1157 |
+
char prtopen(char *, int);
|
1158 |
+
void prtclose();
|
1159 |
+
char prtread();
|
1160 |
+
void prtwrite(char);
|
1161 |
+
short prtcheckch();
|
1162 |
+
short prtavailable();
|
1163 |
+
|
1164 |
+
/* generic wire access */
|
1165 |
+
void wirebegin();
|
1166 |
+
int wirestat(char);
|
1167 |
+
void wireopen(char, char);
|
1168 |
+
void wireins(char*, uint8_t);
|
1169 |
+
void wireouts(char*, uint8_t);
|
1170 |
+
short wireavailable();
|
1171 |
+
short wirereadbyte(short);
|
1172 |
+
void wirewritebyte(short, short);
|
1173 |
+
|
1174 |
+
/* RF24 radio input */
|
1175 |
+
int radiostat(char);
|
1176 |
+
void radioset(int);
|
1177 |
+
#ifdef ARDUINO
|
1178 |
+
uint64_t pipeaddr(char*);
|
1179 |
+
#else
|
1180 |
+
long pipeaddr(char*);
|
1181 |
+
#endif
|
1182 |
+
void iradioopen(char*);
|
1183 |
+
void oradioopen(char*);
|
1184 |
+
void radioins(char*, short);
|
1185 |
+
void radioouts(char* , short);
|
1186 |
+
short radioavailable();
|
1187 |
+
|
1188 |
+
/* sensor control */
|
1189 |
+
void sensorbegin();
|
1190 |
+
number_t sensorread(short, short);
|
1191 |
+
|
1192 |
+
/* SPI RAM code */
|
1193 |
+
address_t spirambegin();
|
1194 |
+
void spiramrawwrite(address_t, mem_t);
|
1195 |
+
mem_t spiramrawread(address_t );
|
1196 |
+
|
1197 |
+
/*
|
1198 |
+
* Layer 0 functions - I/O and memory management
|
1199 |
+
*/
|
1200 |
+
|
1201 |
+
/* make room for BASIC */
|
1202 |
+
address_t ballocmem();
|
1203 |
+
|
1204 |
+
/* handle files im EEPROM */
|
1205 |
+
void eload();
|
1206 |
+
void esave();
|
1207 |
+
char autorun();
|
1208 |
+
|
1209 |
+
/* the variable heap from Apple 1 BASIC */
|
1210 |
+
address_t bmalloc(mem_t, mem_t, mem_t, address_t);
|
1211 |
+
address_t bfind(mem_t, mem_t, mem_t);
|
1212 |
+
address_t bfree(mem_t, mem_t, mem_t);
|
1213 |
+
address_t blength (mem_t, mem_t, mem_t);
|
1214 |
+
|
1215 |
+
/* normal variables of number_t */
|
1216 |
+
number_t getvar(mem_t, mem_t);
|
1217 |
+
void setvar(mem_t, mem_t, number_t);
|
1218 |
+
void clrvars();
|
1219 |
+
|
1220 |
+
/* low level memory access packing n*8bit bit into n 8 bit objects
|
1221 |
+
e* is for Arduino EEPROM */
|
1222 |
+
void getnumber(address_t, mem_t);
|
1223 |
+
void setnumber(address_t, mem_t);
|
1224 |
+
void egetnumber(address_t, mem_t);
|
1225 |
+
void esetnumber(address_t, mem_t);
|
1226 |
+
void pgetnumber(address_t, mem_t);
|
1227 |
+
|
1228 |
+
/* array and string handling */
|
1229 |
+
/* the multidim extension is experimental, here only 2 array dimensions implemented as test */
|
1230 |
+
address_t createarray(mem_t, mem_t, address_t, address_t);
|
1231 |
+
void array(mem_t, mem_t, mem_t, address_t, address_t, number_t*);
|
1232 |
+
address_t createstring(char, char, address_t, address_t);
|
1233 |
+
char* getstring(char, char, address_t, address_t);
|
1234 |
+
number_t arraydim(char, char);
|
1235 |
+
address_t stringdim(char, char);
|
1236 |
+
address_t lenstring(char, char, address_t);
|
1237 |
+
void setstringlength(char, char, address_t, address_t);
|
1238 |
+
void setstring(char, char, address_t, char *, address_t, address_t);
|
1239 |
+
|
1240 |
+
/* the user defined extension functions */
|
1241 |
+
number_t getusrvar();
|
1242 |
+
void setusrvar(number_t);
|
1243 |
+
number_t getusrarray(address_t);
|
1244 |
+
void setusrarray(address_t, number_t);
|
1245 |
+
void makeusrstring();
|
1246 |
+
number_t usrfunction(address_t, number_t);
|
1247 |
+
void usrcall(address_t);
|
1248 |
+
|
1249 |
+
/* get keywords and tokens from PROGMEM */
|
1250 |
+
char* getkeyword(unsigned short);
|
1251 |
+
char* getmessage(char);
|
1252 |
+
signed char gettokenvalue(char);
|
1253 |
+
void printmessage(char);
|
1254 |
+
|
1255 |
+
/* error handling */
|
1256 |
+
void error(token_t);
|
1257 |
+
void reseterror();
|
1258 |
+
void debugtoken();
|
1259 |
+
void bdebug(const char*);
|
1260 |
+
|
1261 |
+
/* the arithemtic stack */
|
1262 |
+
void push(number_t);
|
1263 |
+
number_t pop();
|
1264 |
+
address_t popaddress();
|
1265 |
+
void drop();
|
1266 |
+
void clearst();
|
1267 |
+
|
1268 |
+
/* READ DATA handling */
|
1269 |
+
void clrdata();
|
1270 |
+
|
1271 |
+
/* FOR NEXT GOSUB stacks */
|
1272 |
+
void pushforstack();
|
1273 |
+
void popforstack();
|
1274 |
+
void dropforstack();
|
1275 |
+
void clrforstack();
|
1276 |
+
void pushgosubstack(mem_t);
|
1277 |
+
void popgosubstack();
|
1278 |
+
void dropgosubstack();
|
1279 |
+
void clrgosubstack();
|
1280 |
+
|
1281 |
+
/* general I/O initialisation */
|
1282 |
+
void ioinit();
|
1283 |
+
void iodefaults();
|
1284 |
+
|
1285 |
+
/* signal handling */
|
1286 |
+
void signalon();
|
1287 |
+
void signaloff();
|
1288 |
+
void signalhandler(int);
|
1289 |
+
|
1290 |
+
/* character and string I/O functions */
|
1291 |
+
/* we live in world where char may be signed or unsigned and keep it
|
1292 |
+
that way on the lowest level, hence this function, fully defined here,
|
1293 |
+
mostly inlined anyway*/
|
1294 |
+
int cheof(int c) { if ((c == -1) || (c == 255)) return 1; else return 0; }
|
1295 |
+
/* input */
|
1296 |
+
char inch();
|
1297 |
+
char checkch();
|
1298 |
+
short availch();
|
1299 |
+
void inb(char*, index_t);
|
1300 |
+
void ins(char*, address_t);
|
1301 |
+
|
1302 |
+
/* output */
|
1303 |
+
void outch(char);
|
1304 |
+
void outcr();
|
1305 |
+
void outspc();
|
1306 |
+
void outs(char*, address_t);
|
1307 |
+
void outsc(const char*);
|
1308 |
+
void outscf(const char *, index_t);
|
1309 |
+
|
1310 |
+
/* I/O of number_t - floats and integers */
|
1311 |
+
address_t parsenumber(char*, number_t*);
|
1312 |
+
address_t parsenumber2(char*, number_t*);
|
1313 |
+
address_t writenumber(char*, wnumber_t);
|
1314 |
+
address_t writenumber2(char*, number_t);
|
1315 |
+
address_t tinydtostrf(number_t, index_t, char*);
|
1316 |
+
char innumber(number_t*);
|
1317 |
+
void outnumber(number_t);
|
1318 |
+
|
1319 |
+
/*
|
1320 |
+
* Layer 1 functions, provide data and do the heavy lifting
|
1321 |
+
* for layer 2 including lexical analysis, storing programs
|
1322 |
+
* and expression evaluation
|
1323 |
+
*/
|
1324 |
+
|
1325 |
+
/* lexical analysis */
|
1326 |
+
void whitespaces();
|
1327 |
+
void nexttoken();
|
1328 |
+
|
1329 |
+
/* storing and retrieving programs */
|
1330 |
+
char nomemory(number_t);
|
1331 |
+
void storetoken();
|
1332 |
+
mem_t memread(address_t);
|
1333 |
+
mem_t memread2(address_t);
|
1334 |
+
void memwrite2(address_t, mem_t);
|
1335 |
+
void gettoken();
|
1336 |
+
void firstline();
|
1337 |
+
void nextline();
|
1338 |
+
|
1339 |
+
void clrlinecache();
|
1340 |
+
void addlinecache(address_t, address_t);
|
1341 |
+
address_t findinlinecache(address_t);
|
1342 |
+
void findline(address_t);
|
1343 |
+
address_t myline(address_t);
|
1344 |
+
void moveblock(address_t, address_t, address_t);
|
1345 |
+
void zeroblock(address_t, address_t);
|
1346 |
+
void diag();
|
1347 |
+
void storeline();
|
1348 |
+
|
1349 |
+
/* read arguments from the token stream and process them */
|
1350 |
+
char termsymbol();
|
1351 |
+
char expect(token_t, mem_t);
|
1352 |
+
char expectexpr();
|
1353 |
+
void parsearguments();
|
1354 |
+
void parsenarguments(char);
|
1355 |
+
void parsesubscripts();
|
1356 |
+
void parsefunction(void (*)(), short);
|
1357 |
+
void parseoperator(void (*)());
|
1358 |
+
void parsesubstring();
|
1359 |
+
|
1360 |
+
/* mathematics and other functions for int and float */
|
1361 |
+
void xabs();
|
1362 |
+
void xsgn();
|
1363 |
+
void xpeek();
|
1364 |
+
void xmap();
|
1365 |
+
void rnd();
|
1366 |
+
void sqr();
|
1367 |
+
void xpow();
|
1368 |
+
number_t bpow(number_t, number_t);
|
1369 |
+
|
1370 |
+
/* string values and string evaluation */
|
1371 |
+
char stringvalue();
|
1372 |
+
void streval();
|
1373 |
+
|
1374 |
+
/* floating point functions */
|
1375 |
+
void xsin();
|
1376 |
+
void xcos();
|
1377 |
+
void xtan();
|
1378 |
+
void xatan();
|
1379 |
+
void xlog();
|
1380 |
+
void xexp();
|
1381 |
+
void xint();
|
1382 |
+
|
1383 |
+
/* expression evaluation */
|
1384 |
+
void factor();
|
1385 |
+
void term();
|
1386 |
+
void addexpression();
|
1387 |
+
void compexpression();
|
1388 |
+
void notexpression();
|
1389 |
+
void andexpression();
|
1390 |
+
void expression();
|
1391 |
+
|
1392 |
+
/*
|
1393 |
+
* Layer 2 - statements and functions
|
1394 |
+
* use the global variables
|
1395 |
+
*/
|
1396 |
+
|
1397 |
+
/* basic commands of the core language set */
|
1398 |
+
void xprint();
|
1399 |
+
void lefthandside(address_t*, address_t*, address_t*, mem_t*);
|
1400 |
+
void assignnumber(signed char, char, char, address_t, address_t, char);
|
1401 |
+
void assignment();
|
1402 |
+
void showprompt();
|
1403 |
+
void xinput();
|
1404 |
+
void xgoto();
|
1405 |
+
void xreturn();
|
1406 |
+
void xif();
|
1407 |
+
|
1408 |
+
/* FOR NEXT loops */
|
1409 |
+
void findnextcmd();
|
1410 |
+
void findbraket(token_t, token_t);
|
1411 |
+
void xfor();
|
1412 |
+
void xbreak();
|
1413 |
+
void xcont();
|
1414 |
+
void xnext();
|
1415 |
+
|
1416 |
+
/* WHILE WEND*/
|
1417 |
+
void xwhile();
|
1418 |
+
void xwend();
|
1419 |
+
|
1420 |
+
/* REPEAT UNTIL */
|
1421 |
+
void xrepeat();
|
1422 |
+
void xuntil();
|
1423 |
+
|
1424 |
+
/* control commands and misc */
|
1425 |
+
void outputtoken();
|
1426 |
+
void xlist();
|
1427 |
+
void xrun();
|
1428 |
+
void xnew();
|
1429 |
+
void xrem();
|
1430 |
+
void xclr();
|
1431 |
+
void xdim();
|
1432 |
+
void xpoke();
|
1433 |
+
void xtab();
|
1434 |
+
void xdump();
|
1435 |
+
void dumpmem(address_t, address_t, char);
|
1436 |
+
void xlocate();
|
1437 |
+
|
1438 |
+
/* file access and other i/o */
|
1439 |
+
void stringtobuffer(char*);
|
1440 |
+
void getfilename(char*, char);
|
1441 |
+
void xsave();
|
1442 |
+
void xload(const char*);
|
1443 |
+
void xget();
|
1444 |
+
void xput();
|
1445 |
+
void xset();
|
1446 |
+
void xnetstat();
|
1447 |
+
|
1448 |
+
/* Arduino IO control interface */
|
1449 |
+
void xdwrite();
|
1450 |
+
void xawrite();
|
1451 |
+
void xpinm();
|
1452 |
+
void xdelay();
|
1453 |
+
void xtone();
|
1454 |
+
|
1455 |
+
/* graphics commands */
|
1456 |
+
void xcolor();
|
1457 |
+
void xplot();
|
1458 |
+
void xline();
|
1459 |
+
void xrect();
|
1460 |
+
void xcircle();
|
1461 |
+
void xfrect();
|
1462 |
+
void xfcircle();
|
1463 |
+
|
1464 |
+
/* the darkarts */
|
1465 |
+
void xmalloc();
|
1466 |
+
void xfind();
|
1467 |
+
void xeval();
|
1468 |
+
|
1469 |
+
/* IoT commands */
|
1470 |
+
void xassign();
|
1471 |
+
void xavail();
|
1472 |
+
void xfsensor();
|
1473 |
+
void xsleep();
|
1474 |
+
void xwire();
|
1475 |
+
void xfwire();
|
1476 |
+
|
1477 |
+
/* timers */
|
1478 |
+
void xafter();
|
1479 |
+
void xevent();
|
1480 |
+
|
1481 |
+
/* File I/O functions */
|
1482 |
+
char streq(const char*, char*);
|
1483 |
+
void xcatalog();
|
1484 |
+
void xdelete();
|
1485 |
+
void xopen();
|
1486 |
+
void xfopen();
|
1487 |
+
void xclose();
|
1488 |
+
void xfdisk();
|
1489 |
+
|
1490 |
+
/* low level access functions */
|
1491 |
+
void xcall();
|
1492 |
+
void xusr();
|
1493 |
+
|
1494 |
+
/* the dartmouth stuff */
|
1495 |
+
void xdata();
|
1496 |
+
void nextdatarecord();
|
1497 |
+
void xread();
|
1498 |
+
void xrestore();
|
1499 |
+
void xdef();
|
1500 |
+
void xfn();
|
1501 |
+
void xon();
|
1502 |
+
|
1503 |
+
/* timers and interrupts */
|
1504 |
+
void xtimer();
|
1505 |
+
void resettimer(btimer_t*);
|
1506 |
+
|
1507 |
+
/* structured BASIC extensions */
|
1508 |
+
void xwhile();
|
1509 |
+
void xwend();
|
1510 |
+
void xrepeat();
|
1511 |
+
void xuntil();
|
1512 |
+
void xswitch();
|
1513 |
+
void xcase();
|
1514 |
+
void xendswitch();
|
1515 |
+
|
1516 |
+
/* the emulation of tone using the byield loop */
|
1517 |
+
void toggletone();
|
1518 |
+
void playtone(int, int, int);
|
1519 |
+
|
1520 |
+
/* the statement loop */
|
1521 |
+
void statement();
|
1522 |
+
|
1523 |
+
/* the extension functions */
|
1524 |
+
void bsetup();
|
1525 |
+
void bloop();
|
1526 |
+
|
data/Basic1/IotBasic/font/firasans.h
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic1/IotBasic/hardware-arduino.h
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic1/IotBasic/wifisettings.h
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const char* ssid = "myssid";
|
2 |
+
const char* password = "mypasswd";
|
3 |
+
const char* mqtt_server = "test.mosquitto.org";
|
4 |
+
const short mqtt_port = 1883;
|
5 |
+
byte mac[] = {0xDE, 0xAD, 0xBE, 0xE9, 0xE9, 0xE9};
|
data/Basic1/TinyVT52/TinyVT52.ino
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*
|
3 |
+
* $Id: TinyVT52.ino,v 1.1 2022/12/13 19:00:16 stefan Exp stefan $
|
4 |
+
*
|
5 |
+
* Stefan's TinyVT52 derived from the IoT BASIC interpreter
|
6 |
+
*
|
7 |
+
* See the licence file on
|
8 |
+
* https://github.com/slviajero/tinybasic for copyright/left.
|
9 |
+
* (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
|
10 |
+
*
|
11 |
+
* Author: Stefan Lenz, [email protected]
|
12 |
+
*
|
13 |
+
* Device drivers and low level I/O routines are used from the BASIC code
|
14 |
+
* These definitions are in basic.h and hardware-arduino.h. These two files
|
15 |
+
* are exactly identical to the BASIC language files to make sure that further
|
16 |
+
* work on the device drivers can be used here without changes.
|
17 |
+
*
|
18 |
+
* To use the terminal, the hardware definition in hardware-arduino.h need to be set
|
19 |
+
*
|
20 |
+
* Any one of the following macros need to be defined
|
21 |
+
*
|
22 |
+
* Always set #define DISPLAYCANSCROLL
|
23 |
+
*
|
24 |
+
* Displays: define one(!) of the following displays in hardware
|
25 |
+
* ARDUINOLCDI2C, ARDUINONOKIA51, ARDUINOILI9488, ARDUINOSSD1306
|
26 |
+
* ARDUINOMCUFRIEND, ARDUINOGRAPHDUMMY, LCDSHIELD, ARDUINOTFT
|
27 |
+
*
|
28 |
+
* Keyboards:
|
29 |
+
* ARDUINOPS2, ARDUINOUSBKBD (alpha!!), ARDUINOZX81KBD
|
30 |
+
*
|
31 |
+
* Printers:
|
32 |
+
* ARDUINOPRT
|
33 |
+
*
|
34 |
+
*/
|
35 |
+
|
36 |
+
/* which serial port is used for terminal I/O */
|
37 |
+
#define SERIALPORT Serial
|
38 |
+
|
39 |
+
/* which serial port is used for printer IO */
|
40 |
+
#define PRTSERIAL Serial3
|
41 |
+
|
42 |
+
/* the only language feature of BASIC that we need is the VT52 component */
|
43 |
+
#define HASVT52
|
44 |
+
|
45 |
+
/* should the VT52 also handle Wiring */
|
46 |
+
#define VT52WIRING
|
47 |
+
|
48 |
+
/* the device driver code from BASIC */
|
49 |
+
#include "basic.h"
|
50 |
+
#include "hardware-arduino.h"
|
51 |
+
|
52 |
+
/* XON and XOFF characters */
|
53 |
+
#define XON 0x11
|
54 |
+
#define XOFF 0x13
|
55 |
+
|
56 |
+
/* a shallow buffer */
|
57 |
+
#define VT52BUFSIZE 64
|
58 |
+
char vt52sbuf[VT52BUFSIZE];
|
59 |
+
int vt52sbi = 0;
|
60 |
+
|
61 |
+
void setup() {
|
62 |
+
|
63 |
+
/* start the terminal interface */
|
64 |
+
SERIALPORT.begin(9600);
|
65 |
+
|
66 |
+
/* start the display stream */
|
67 |
+
dspbegin();
|
68 |
+
|
69 |
+
/* if a printer port is defined, start the printer, this is Serial1 of Software Serial */
|
70 |
+
#if defined(ARDUINOPRT)
|
71 |
+
prtbegin();
|
72 |
+
#endif
|
73 |
+
|
74 |
+
/* if any wire subsystem is requested, start it as well */
|
75 |
+
#if defined(NEEDSWIRE)
|
76 |
+
wirebegin();
|
77 |
+
#endif
|
78 |
+
|
79 |
+
/* and then there is SPI */
|
80 |
+
#if defined(ARDUINOSPI)
|
81 |
+
spibegin();
|
82 |
+
#endif
|
83 |
+
|
84 |
+
}
|
85 |
+
|
86 |
+
void loop() {
|
87 |
+
char ch;
|
88 |
+
|
89 |
+
/* first test, just use the serial port as in */
|
90 |
+
|
91 |
+
/* read a chunk of characters */
|
92 |
+
/* display output is slow, it is an operation at the timescale of 10 ms per character, XOFF while we do it*/
|
93 |
+
if (SERIALPORT.available()) {
|
94 |
+
/* send XOFF to hold the output */
|
95 |
+
SERIALPORT.write(XOFF);
|
96 |
+
/* free the serial buffer immediately to be ready for characters sent before XOFF could be processes*/
|
97 |
+
while (SERIALPORT.available() && vt52bi < VT52BUFSIZE) vt52sbuf[vt52bi++]=SERIALPORT.read();
|
98 |
+
/* now empty the buffer completely */
|
99 |
+
for (int i=0; i<vt52bi; i++) dspwrite(vt52sbuf[i]);
|
100 |
+
vt52bi=0;
|
101 |
+
/* send XON to continue output */
|
102 |
+
SERIALPORT.write(XON);
|
103 |
+
}
|
104 |
+
|
105 |
+
/* send all characters from the display to the serial stream */
|
106 |
+
while (kbdavailable()) {
|
107 |
+
ch=kbdread();
|
108 |
+
SERIALPORT.write(ch);
|
109 |
+
}
|
110 |
+
}
|
data/Basic1/TinyVT52/basic.h
ADDED
@@ -0,0 +1,1312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*
|
3 |
+
* $Id: basic.h,v 1.9 2022/08/15 18:08:56 stefan Exp stefan $
|
4 |
+
*
|
5 |
+
* Stefan's basic interpreter
|
6 |
+
*
|
7 |
+
* Playing around with frugal programming. See the licence file on
|
8 |
+
* https://github.com/slviajero/tinybasic for copyright/left.
|
9 |
+
* (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
|
10 |
+
*
|
11 |
+
* Author: Stefan Lenz, [email protected]
|
12 |
+
*
|
13 |
+
* basic.h are the core defintions and function protypes
|
14 |
+
*
|
15 |
+
*/
|
16 |
+
|
17 |
+
/*
|
18 |
+
* if the PROGMEM macro is define we compile on the Arduino IDE
|
19 |
+
* we undef all hardware settings otherwise a little odd
|
20 |
+
*/
|
21 |
+
#ifdef ARDUINO_ARCH_MBED
|
22 |
+
#define PROGMEM
|
23 |
+
#endif
|
24 |
+
|
25 |
+
#ifdef PROGMEM
|
26 |
+
#define ARDUINOPROGMEM
|
27 |
+
#else
|
28 |
+
#undef ARDUINO
|
29 |
+
#undef ARDUINOSD
|
30 |
+
#undef ARDUINORF24
|
31 |
+
#undef ARDUINORTC
|
32 |
+
#undef ARDUINOEEPROM
|
33 |
+
#undef ARDUINOEEPROMI2C
|
34 |
+
#undef ARDUINOWIRE
|
35 |
+
#endif
|
36 |
+
|
37 |
+
/*
|
38 |
+
* MSDOS, Mac, Linux and Windows
|
39 |
+
*/
|
40 |
+
#ifndef ARDUINO
|
41 |
+
typedef unsigned char uint8_t;
|
42 |
+
#define PROGMEM
|
43 |
+
#include <stdio.h>
|
44 |
+
#include <stdlib.h>
|
45 |
+
#ifdef HASFLOAT
|
46 |
+
#include <math.h>
|
47 |
+
#include <float.h>
|
48 |
+
#endif
|
49 |
+
#include <time.h>
|
50 |
+
#include <sys/types.h>
|
51 |
+
#include <sys/timeb.h>
|
52 |
+
#ifndef MSDOS
|
53 |
+
#include <dirent.h>
|
54 |
+
#include <unistd.h>
|
55 |
+
#else
|
56 |
+
#include <dir.h>
|
57 |
+
#include <dos.h>
|
58 |
+
#endif
|
59 |
+
#ifdef MINGW
|
60 |
+
#include <windows.h>
|
61 |
+
#endif
|
62 |
+
#ifdef RASPPI
|
63 |
+
#include <wiringPi.h>
|
64 |
+
#endif
|
65 |
+
#endif
|
66 |
+
|
67 |
+
|
68 |
+
#if defined(ARDUINO_ARCH_AVR)
|
69 |
+
/* the small memory model with shallow stacks and small buffers */
|
70 |
+
#define BUFSIZE 80
|
71 |
+
#define STACKSIZE 15
|
72 |
+
#define GOSUBDEPTH 4
|
73 |
+
#define FORDEPTH 4
|
74 |
+
#define LINECACHESIZE 4
|
75 |
+
#else
|
76 |
+
/* the for larger microcontrollers and real computers */
|
77 |
+
#define BUFSIZE 128
|
78 |
+
#define STACKSIZE 64
|
79 |
+
#define GOSUBDEPTH 8
|
80 |
+
#define FORDEPTH 8
|
81 |
+
#define LINECACHESIZE 16
|
82 |
+
#endif
|
83 |
+
/* more duffers and vars */
|
84 |
+
#define SBUFSIZE 32
|
85 |
+
#define VARSIZE 26
|
86 |
+
/* default sizes of arrays and strings if they are not DIMed */
|
87 |
+
#define ARRAYSIZEDEF 10
|
88 |
+
#define STRSIZEDEF 32
|
89 |
+
|
90 |
+
/*
|
91 |
+
* the time intervall in ms needed for
|
92 |
+
* ESP8266 yields, network client loops
|
93 |
+
* and other timing related functions
|
94 |
+
*/
|
95 |
+
#define LONGYIELDINTERVAL 1000
|
96 |
+
#define YIELDINTERVAL 32
|
97 |
+
#define YIELDTIME 2
|
98 |
+
|
99 |
+
/* the default EEPROM dummy size */
|
100 |
+
#define EEPROMSIZE 1024
|
101 |
+
|
102 |
+
/*
|
103 |
+
* The tokens for the BASIC keywords
|
104 |
+
*
|
105 |
+
* All single character operators are their own tokens
|
106 |
+
* ASCII values above 0x7f are used for tokens of keywords.
|
107 |
+
* EOL is a token
|
108 |
+
*/
|
109 |
+
#define EOL 0
|
110 |
+
#define NUMBER -127
|
111 |
+
#define LINENUMBER -126
|
112 |
+
#define STRING -125
|
113 |
+
#define VARIABLE -124
|
114 |
+
#define STRINGVAR -123
|
115 |
+
#define ARRAYVAR -122
|
116 |
+
/* multi character tokens - BASEKEYWORD (3) */
|
117 |
+
#define GREATEREQUAL -121
|
118 |
+
#define LESSEREQUAL -120
|
119 |
+
#define NOTEQUAL -119
|
120 |
+
/* this is the Palo Alto Language Set (19) */
|
121 |
+
#define TPRINT -118
|
122 |
+
#define TLET -117
|
123 |
+
#define TINPUT -116
|
124 |
+
#define TGOTO -115
|
125 |
+
#define TGOSUB -114
|
126 |
+
#define TRETURN -113
|
127 |
+
#define TIF -112
|
128 |
+
#define TFOR -111
|
129 |
+
#define TTO -110
|
130 |
+
#define TSTEP -109
|
131 |
+
#define TNEXT -108
|
132 |
+
#define TSTOP -107
|
133 |
+
#define TLIST -106
|
134 |
+
#define TNEW -105
|
135 |
+
#define TRUN -104
|
136 |
+
#define TABS -103
|
137 |
+
#define TRND -102
|
138 |
+
#define TSIZE -101
|
139 |
+
#define TREM -100
|
140 |
+
/* this is the Apple 1 language set in addition to Palo Alto (14) */
|
141 |
+
#define TNOT -99
|
142 |
+
#define TAND -98
|
143 |
+
#define TOR -97
|
144 |
+
#define TLEN -96
|
145 |
+
#define TSGN -95
|
146 |
+
#define TPEEK -94
|
147 |
+
#define TDIM -93
|
148 |
+
#define TCLR -92
|
149 |
+
#define THIMEM -91
|
150 |
+
#define TTAB -90
|
151 |
+
#define TTHEN -89
|
152 |
+
#define TEND -88
|
153 |
+
#define TPOKE -87
|
154 |
+
/* Stefan's tinybasic additions (12) */
|
155 |
+
#define TCONT -86
|
156 |
+
#define TSQR -85
|
157 |
+
#define TPOW -84
|
158 |
+
#define TMAP -83
|
159 |
+
#define TDUMP -82
|
160 |
+
#define TBREAK -81
|
161 |
+
#define TSAVE -80
|
162 |
+
#define TLOAD -79
|
163 |
+
#define TGET -78
|
164 |
+
#define TPUT -77
|
165 |
+
#define TSET -76
|
166 |
+
#define TCLS -75
|
167 |
+
/* Arduino functions (10) */
|
168 |
+
#define TPINM -74
|
169 |
+
#define TDWRITE -73
|
170 |
+
#define TDREAD -72
|
171 |
+
#define TAWRITE -71
|
172 |
+
#define TAREAD -70
|
173 |
+
#define TDELAY -69
|
174 |
+
#define TMILLIS -68
|
175 |
+
#define TTONE -67
|
176 |
+
#define TPULSEIN -66
|
177 |
+
#define TAZERO -65
|
178 |
+
#define TLED -64
|
179 |
+
/* the DOS functions (5) */
|
180 |
+
#define TCATALOG -63
|
181 |
+
#define TDELETE -62
|
182 |
+
#define TOPEN -61
|
183 |
+
#define TCLOSE -60
|
184 |
+
#define TFDISK -59
|
185 |
+
/* low level access of internal routines (2) */
|
186 |
+
#define TUSR -58
|
187 |
+
#define TCALL -57
|
188 |
+
/* mathematical functions (7) */
|
189 |
+
#define TSIN -56
|
190 |
+
#define TCOS -55
|
191 |
+
#define TTAN -54
|
192 |
+
#define TATAN -53
|
193 |
+
#define TLOG -52
|
194 |
+
#define TEXP -51
|
195 |
+
#define TINT -50
|
196 |
+
/* graphics - experimental - rudimentary (7) */
|
197 |
+
#define TCOLOR -49
|
198 |
+
#define TPLOT -48
|
199 |
+
#define TLINE -47
|
200 |
+
#define TCIRCLE -46
|
201 |
+
#define TRECT -45
|
202 |
+
#define TFCIRCLE -44
|
203 |
+
#define TFRECT -43
|
204 |
+
/* the Dartmouth extensions (6) */
|
205 |
+
#define TDATA -42
|
206 |
+
#define TREAD -41
|
207 |
+
#define TRESTORE -40
|
208 |
+
#define TDEF -39
|
209 |
+
#define TFN -38
|
210 |
+
#define TON -37
|
211 |
+
/* the latecomer ELSE */
|
212 |
+
#define TELSE -36
|
213 |
+
/* darkarts (3) */
|
214 |
+
#define TMALLOC -35
|
215 |
+
#define TFIND -34
|
216 |
+
#define TEVAL -33
|
217 |
+
/* iot extensions (9) */
|
218 |
+
#define TASSIGN -32
|
219 |
+
#define TAVAIL -31
|
220 |
+
#define TSTR -30
|
221 |
+
#define TINSTR -29
|
222 |
+
#define TVAL -28
|
223 |
+
#define TNETSTAT -27
|
224 |
+
#define TSENSOR -26
|
225 |
+
#define TWIRE -25
|
226 |
+
#define TSLEEP -24
|
227 |
+
/* constants used for some obscure purposes */
|
228 |
+
#define TBUFFER -2
|
229 |
+
/* UNKNOWN is not used in the current code, the
|
230 |
+
* lexer tokenizes everything blindly. There is a UNKNOWN hook
|
231 |
+
* in statement for a grammar aware lexer */
|
232 |
+
#define UNKNOWN -1
|
233 |
+
|
234 |
+
/* the number of keywords, and the base index of the keywords */
|
235 |
+
#define NKEYWORDS 3+19+13+12+11+5+2+7+7+7+12
|
236 |
+
#define BASEKEYWORD -121
|
237 |
+
|
238 |
+
/*
|
239 |
+
* Interpreter states
|
240 |
+
* SRUN means running from a programm
|
241 |
+
* SINT means interactive mode
|
242 |
+
* SERUN means running directly from EEPROM
|
243 |
+
* (enum would be the right way of doing this.)
|
244 |
+
* BREAKCHAR is the character stopping the program on Ardunios
|
245 |
+
* BREAKPIN can be set, it is a pin that needs to go to low to stop a BASIC program
|
246 |
+
* This should be done in hardware*.h
|
247 |
+
*
|
248 |
+
*/
|
249 |
+
#define SINT 0
|
250 |
+
#define SRUN 1
|
251 |
+
#define SERUN 2
|
252 |
+
#define BREAKCHAR '#'
|
253 |
+
|
254 |
+
/*
|
255 |
+
* Arduino input and output channels
|
256 |
+
*/
|
257 |
+
#define OSERIAL 1
|
258 |
+
#define ODSP 2
|
259 |
+
#define OPRT 4
|
260 |
+
#define OWIRE 7
|
261 |
+
#define ORADIO 8
|
262 |
+
#define OMQTT 9
|
263 |
+
#define OFILE 16
|
264 |
+
|
265 |
+
#define ISERIAL 1
|
266 |
+
#define IKEYBOARD 2
|
267 |
+
#define ISERIAL1 4
|
268 |
+
#define IWIRE 7
|
269 |
+
#define IRADIO 8
|
270 |
+
#define IMQTT 9
|
271 |
+
#define IFILE 16
|
272 |
+
|
273 |
+
/*
|
274 |
+
* All BASIC keywords for the tokens
|
275 |
+
*/
|
276 |
+
const char sge[] PROGMEM = "=>";
|
277 |
+
const char sle[] PROGMEM = "<=";
|
278 |
+
const char sne[] PROGMEM = "<>";
|
279 |
+
/* Palo Alto language set */
|
280 |
+
const char sprint[] PROGMEM = "PRINT";
|
281 |
+
const char slet[] PROGMEM = "LET";
|
282 |
+
const char sinput[] PROGMEM = "INPUT";
|
283 |
+
const char sgoto[] PROGMEM = "GOTO";
|
284 |
+
const char sgosub[] PROGMEM = "GOSUB";
|
285 |
+
const char sreturn[] PROGMEM = "RETURN";
|
286 |
+
const char sif[] PROGMEM = "IF";
|
287 |
+
const char sfor[] PROGMEM = "FOR";
|
288 |
+
const char sto[] PROGMEM = "TO";
|
289 |
+
const char sstep[] PROGMEM = "STEP";
|
290 |
+
const char snext[] PROGMEM = "NEXT";
|
291 |
+
const char sstop[] PROGMEM = "STOP";
|
292 |
+
const char slist[] PROGMEM = "LIST";
|
293 |
+
const char snew[] PROGMEM = "NEW";
|
294 |
+
const char srun[] PROGMEM = "RUN";
|
295 |
+
const char sabs[] PROGMEM = "ABS";
|
296 |
+
const char srnd[] PROGMEM = "RND";
|
297 |
+
const char ssize[] PROGMEM = "SIZE";
|
298 |
+
const char srem[] PROGMEM = "REM";
|
299 |
+
/* Apple 1 language set */
|
300 |
+
#ifdef HASAPPLE1
|
301 |
+
const char snot[] PROGMEM = "NOT";
|
302 |
+
const char sand[] PROGMEM = "AND";
|
303 |
+
const char sor[] PROGMEM = "OR";
|
304 |
+
const char slen[] PROGMEM = "LEN";
|
305 |
+
const char ssgn[] PROGMEM = "SGN";
|
306 |
+
const char speek[] PROGMEM = "PEEK";
|
307 |
+
const char sdim[] PROGMEM = "DIM";
|
308 |
+
const char sclr[] PROGMEM = "CLR";
|
309 |
+
const char shimem[] PROGMEM = "HIMEM";
|
310 |
+
const char stab[] PROGMEM = "TAB";
|
311 |
+
const char sthen[] PROGMEM = "THEN";
|
312 |
+
const char sbend[] PROGMEM = "END";
|
313 |
+
const char spoke[] PROGMEM = "POKE";
|
314 |
+
#endif
|
315 |
+
/* Stefan's basic additions */
|
316 |
+
#ifdef HASSTEFANSEXT
|
317 |
+
const char scont[] PROGMEM = "CONT";
|
318 |
+
const char ssqr[] PROGMEM = "SQR";
|
319 |
+
const char spow[] PROGMEM = "POW";
|
320 |
+
const char smap[] PROGMEM = "MAP";
|
321 |
+
const char sdump[] PROGMEM = "DUMP";
|
322 |
+
const char sbreak[] PROGMEM = "BREAK";
|
323 |
+
#endif
|
324 |
+
/* LOAD and SAVE is always there */
|
325 |
+
const char ssave[] PROGMEM = "SAVE";
|
326 |
+
const char sload[] PROGMEM = "LOAD";
|
327 |
+
#ifdef HASSTEFANSEXT
|
328 |
+
const char sget[] PROGMEM = "GET";
|
329 |
+
const char sput[] PROGMEM = "PUT";
|
330 |
+
const char sset[] PROGMEM = "SET";
|
331 |
+
const char scls[] PROGMEM = "CLS";
|
332 |
+
#endif
|
333 |
+
/* Arduino functions */
|
334 |
+
#ifdef HASARDUINOIO
|
335 |
+
const char spinm[] PROGMEM = "PINM";
|
336 |
+
const char sdwrite[] PROGMEM = "DWRITE";
|
337 |
+
const char sdread[] PROGMEM = "DREAD";
|
338 |
+
const char sawrite[] PROGMEM = "AWRITE";
|
339 |
+
const char saread[] PROGMEM = "AREAD";
|
340 |
+
const char sdelay[] PROGMEM = "DELAY";
|
341 |
+
const char smillis[] PROGMEM = "MILLIS";
|
342 |
+
const char sazero[] PROGMEM = "AZERO";
|
343 |
+
const char sled[] PROGMEM = "LED";
|
344 |
+
#endif
|
345 |
+
#ifdef HASTONE
|
346 |
+
const char stone[] PROGMEM = "PLAY";
|
347 |
+
#endif
|
348 |
+
#ifdef HASPULSE
|
349 |
+
const char splusein[] PROGMEM = "PULSEIN";
|
350 |
+
#endif
|
351 |
+
/* DOS functions */
|
352 |
+
#ifdef HASFILEIO
|
353 |
+
const char scatalog[] PROGMEM = "CATALOG";
|
354 |
+
const char sdelete[] PROGMEM = "DELETE";
|
355 |
+
const char sfopen[] PROGMEM = "OPEN";
|
356 |
+
const char sfclose[] PROGMEM = "CLOSE";
|
357 |
+
const char sfdisk[] PROGMEM = "FDISK";
|
358 |
+
#endif
|
359 |
+
/* low level access functions */
|
360 |
+
#ifdef HASSTEFANSEXT
|
361 |
+
const char susr[] PROGMEM = "USR";
|
362 |
+
const char scall[] PROGMEM = "CALL";
|
363 |
+
#endif
|
364 |
+
/* mathematics */
|
365 |
+
#ifdef HASFLOAT
|
366 |
+
const char ssin[] PROGMEM = "SIN";
|
367 |
+
const char scos[] PROGMEM = "COS";
|
368 |
+
const char stan[] PROGMEM = "TAN";
|
369 |
+
const char satan[] PROGMEM = "ATAN";
|
370 |
+
const char slog[] PROGMEM = "LOG";
|
371 |
+
const char sexp[] PROGMEM = "EXP";
|
372 |
+
#endif
|
373 |
+
/* INT is always needed to make float/int programs compatible */
|
374 |
+
const char sint[] PROGMEM = "INT";
|
375 |
+
/* elemetars graphics */
|
376 |
+
#ifdef HASGRAPH
|
377 |
+
const char scolor[] PROGMEM = "COLOR";
|
378 |
+
const char splot[] PROGMEM = "PLOT";
|
379 |
+
const char sline[] PROGMEM = "LINE";
|
380 |
+
const char scircle[] PROGMEM = "CIRCLE";
|
381 |
+
const char srect[] PROGMEM = "RECT";
|
382 |
+
const char sfcircle[] PROGMEM = "FCIRCLE";
|
383 |
+
const char sfrect[] PROGMEM = "FRECT";
|
384 |
+
#endif
|
385 |
+
/* Dartmouth BASIC extensions */
|
386 |
+
#ifdef HASDARTMOUTH
|
387 |
+
const char sdata[] PROGMEM = "DATA";
|
388 |
+
const char sread[] PROGMEM = "READ";
|
389 |
+
const char srestore[] PROGMEM = "RESTORE";
|
390 |
+
const char sdef[] PROGMEM = "DEF";
|
391 |
+
const char sfn[] PROGMEM = "FN";
|
392 |
+
const char son[] PROGMEM = "ON";
|
393 |
+
#endif
|
394 |
+
/* a latecomer the ELSE command */
|
395 |
+
#ifdef HASSTEFANSEXT
|
396 |
+
const char selse[] PROGMEM = "ELSE";
|
397 |
+
#endif
|
398 |
+
/* The Darkarts commands unthinkable in Dartmouth */
|
399 |
+
#ifdef HASDARKARTS
|
400 |
+
const char smalloc[] PROGMEM = "MALLOC";
|
401 |
+
const char sfind[] PROGMEM = "FIND";
|
402 |
+
const char seval[] PROGMEM = "EVAL";
|
403 |
+
#endif
|
404 |
+
/* iot extensions */
|
405 |
+
#ifdef HASIOT
|
406 |
+
const char sassign[] PROGMEM = "ASSIGN";
|
407 |
+
const char savail[] PROGMEM = "AVAIL";
|
408 |
+
const char sstr[] PROGMEM = "STR";
|
409 |
+
const char sinstr[] PROGMEM = "INSTR";
|
410 |
+
const char sval[] PROGMEM = "VAL";
|
411 |
+
const char snetstat[] PROGMEM = "NETSTAT";
|
412 |
+
const char ssensor[] PROGMEM = "SENSOR";
|
413 |
+
const char swire[] PROGMEM = "WIRE";
|
414 |
+
const char ssleep[] PROGMEM = "SLEEP";
|
415 |
+
#endif
|
416 |
+
|
417 |
+
/* zero terminated keyword storage */
|
418 |
+
const char* const keyword[] PROGMEM = {
|
419 |
+
sge, sle, sne, sprint, slet, sinput,
|
420 |
+
sgoto, sgosub, sreturn, sif, sfor, sto,
|
421 |
+
sstep, snext, sstop, slist, snew, srun,
|
422 |
+
sabs, srnd, ssize, srem,
|
423 |
+
#ifdef HASAPPLE1
|
424 |
+
snot, sand, sor, slen, ssgn, speek, sdim,
|
425 |
+
sclr, shimem, stab, sthen,
|
426 |
+
sbend, spoke,
|
427 |
+
#endif
|
428 |
+
#ifdef HASSTEFANSEXT
|
429 |
+
scont, ssqr, spow, smap, sdump, sbreak,
|
430 |
+
#endif
|
431 |
+
ssave, sload,
|
432 |
+
#ifdef HASSTEFANSEXT
|
433 |
+
sget, sput, sset, scls,
|
434 |
+
#endif
|
435 |
+
#ifdef HASARDUINOIO
|
436 |
+
spinm, sdwrite, sdread, sawrite, saread,
|
437 |
+
sdelay, smillis, sazero, sled,
|
438 |
+
#endif
|
439 |
+
#ifdef HASTONE
|
440 |
+
stone,
|
441 |
+
#endif
|
442 |
+
#ifdef HASPULSE
|
443 |
+
splusein,
|
444 |
+
#endif
|
445 |
+
#ifdef HASFILEIO
|
446 |
+
scatalog, sdelete, sfopen, sfclose, sfdisk,
|
447 |
+
#endif
|
448 |
+
#ifdef HASSTEFANSEXT
|
449 |
+
susr, scall,
|
450 |
+
#endif
|
451 |
+
#ifdef HASFLOAT
|
452 |
+
ssin, scos, stan, satan, slog, sexp,
|
453 |
+
#endif
|
454 |
+
sint,
|
455 |
+
#ifdef HASGRAPH
|
456 |
+
scolor, splot, sline, scircle, srect,
|
457 |
+
sfcircle, sfrect,
|
458 |
+
#endif
|
459 |
+
#ifdef HASDARTMOUTH
|
460 |
+
sdata, sread, srestore, sdef, sfn, son,
|
461 |
+
#endif
|
462 |
+
#ifdef HASSTEFANSEXT
|
463 |
+
selse,
|
464 |
+
#endif
|
465 |
+
#ifdef HASDARKARTS
|
466 |
+
smalloc, sfind, seval,
|
467 |
+
#endif
|
468 |
+
#ifdef HASIOT
|
469 |
+
sassign, savail, sstr, sinstr, sval,
|
470 |
+
snetstat, ssensor, swire, ssleep,
|
471 |
+
#endif
|
472 |
+
0
|
473 |
+
};
|
474 |
+
|
475 |
+
/* the zero terminated token dictonary needed for scalability */
|
476 |
+
const signed char tokens[] PROGMEM = {
|
477 |
+
GREATEREQUAL, LESSEREQUAL, NOTEQUAL, TPRINT, TLET,
|
478 |
+
TINPUT, TGOTO, TGOSUB, TRETURN, TIF, TFOR, TTO, TSTEP,
|
479 |
+
TNEXT, TSTOP, TLIST, TNEW, TRUN, TABS, TRND, TSIZE, TREM,
|
480 |
+
#ifdef HASAPPLE1
|
481 |
+
TNOT, TAND, TOR, TLEN, TSGN, TPEEK, TDIM, TCLR,
|
482 |
+
THIMEM, TTAB, TTHEN, TEND, TPOKE,
|
483 |
+
#endif
|
484 |
+
#ifdef HASSTEFANSEXT
|
485 |
+
TCONT, TSQR, TPOW, TMAP, TDUMP, TBREAK,
|
486 |
+
#endif
|
487 |
+
TSAVE, TLOAD,
|
488 |
+
#ifdef HASSTEFANSEXT
|
489 |
+
TGET, TPUT, TSET, TCLS,
|
490 |
+
#endif
|
491 |
+
#ifdef HASARDUINOIO
|
492 |
+
TPINM, TDWRITE, TDREAD, TAWRITE, TAREAD, TDELAY, TMILLIS,
|
493 |
+
TAZERO, TLED,
|
494 |
+
#endif
|
495 |
+
#ifdef HASTONE
|
496 |
+
TTONE,
|
497 |
+
#endif
|
498 |
+
#ifdef HASPULSE
|
499 |
+
TPULSEIN,
|
500 |
+
#endif
|
501 |
+
#ifdef HASFILEIO
|
502 |
+
TCATALOG, TDELETE, TOPEN, TCLOSE, TFDISK,
|
503 |
+
#endif
|
504 |
+
#ifdef HASSTEFANSEXT
|
505 |
+
TUSR, TCALL,
|
506 |
+
#endif
|
507 |
+
#ifdef HASFLOAT
|
508 |
+
TSIN, TCOS, TTAN, TATAN, TLOG, TEXP,
|
509 |
+
#endif
|
510 |
+
TINT,
|
511 |
+
#ifdef HASGRAPH
|
512 |
+
TCOLOR, TPLOT, TLINE, TCIRCLE, TRECT,
|
513 |
+
TFCIRCLE, TFRECT,
|
514 |
+
#endif
|
515 |
+
#ifdef HASDARTMOUTH
|
516 |
+
TDATA, TREAD, TRESTORE, TDEF, TFN, TON,
|
517 |
+
#endif
|
518 |
+
#ifdef HASSTEFANSEXT
|
519 |
+
TELSE,
|
520 |
+
#endif
|
521 |
+
#ifdef HASDARKARTS
|
522 |
+
TMALLOC, TFIND, TEVAL,
|
523 |
+
#endif
|
524 |
+
#ifdef HASIOT
|
525 |
+
TASSIGN, TAVAIL, TSTR, TINSTR, TVAL, TNETSTAT,
|
526 |
+
TSENSOR, TWIRE, TSLEEP,
|
527 |
+
#endif
|
528 |
+
0
|
529 |
+
};
|
530 |
+
|
531 |
+
/*
|
532 |
+
* the message catalog
|
533 |
+
*/
|
534 |
+
#define MFILE 0
|
535 |
+
#define MPROMPT 1
|
536 |
+
#define MGREET 2
|
537 |
+
#define MLINE 3
|
538 |
+
#define MNUMBER 4
|
539 |
+
#define MVARIABLE 5
|
540 |
+
#define MARRAY 6
|
541 |
+
#define MSTRING 7
|
542 |
+
#define MSTRINGVAR 8
|
543 |
+
#define EGENERAL 9
|
544 |
+
#define EUNKNOWN 10
|
545 |
+
#define ENUMBER 11
|
546 |
+
#define EDIVIDE 12
|
547 |
+
#define ELINE 13
|
548 |
+
#define ERETURN 14
|
549 |
+
#define ENEXT 15
|
550 |
+
#define EGOSUB 16
|
551 |
+
#define EFOR 17
|
552 |
+
#define EOUTOFMEMORY 18
|
553 |
+
#define ESTACK 19
|
554 |
+
#define EDIM 20
|
555 |
+
#define EORANGE 21
|
556 |
+
#define ESTRING 22
|
557 |
+
#define EVARIABLE 23
|
558 |
+
#define EFILE 24
|
559 |
+
#define EFUN 25
|
560 |
+
#define EARGS 26
|
561 |
+
#define EEEPROM 27
|
562 |
+
#define ESDCARD 28
|
563 |
+
|
564 |
+
const char mfile[] PROGMEM = "file.bas";
|
565 |
+
const char mprompt[] PROGMEM = "> ";
|
566 |
+
const char mgreet[] PROGMEM = "Stefan's Basic 1.4a";
|
567 |
+
const char mline[] PROGMEM = "LINE";
|
568 |
+
const char mnumber[] PROGMEM = "NUMBER";
|
569 |
+
const char mvariable[] PROGMEM = "VARIABLE";
|
570 |
+
const char marray[] PROGMEM = "ARRAY";
|
571 |
+
const char mstring[] PROGMEM = "STRING";
|
572 |
+
const char mstringv[] PROGMEM = "STRINGVAR";
|
573 |
+
const char egeneral[] PROGMEM = "Error";
|
574 |
+
#ifdef HASERRORMSG
|
575 |
+
const char eunknown[] PROGMEM = "Syntax";
|
576 |
+
const char enumber[] PROGMEM = "Number";
|
577 |
+
const char edivide[] PROGMEM = "Div by 0";
|
578 |
+
const char eline[] PROGMEM = "Unknown Line";
|
579 |
+
const char ereturn[] PROGMEM = "Return";
|
580 |
+
const char enext[] PROGMEM = "Next";
|
581 |
+
const char egosub[] PROGMEM = "GOSUB";
|
582 |
+
const char efor[] PROGMEM = "FOR";
|
583 |
+
const char emem[] PROGMEM = "Memory";
|
584 |
+
const char estack[] PROGMEM = "Stack";
|
585 |
+
const char edim[] PROGMEM = "DIM";
|
586 |
+
const char erange[] PROGMEM = "Range";
|
587 |
+
const char estring[] PROGMEM = "String";
|
588 |
+
const char evariable[] PROGMEM = "Variable";
|
589 |
+
const char efile[] PROGMEM = "File";
|
590 |
+
const char efun[] PROGMEM = "Function";
|
591 |
+
const char eargs[] PROGMEM = "Args";
|
592 |
+
const char eeeprom[] PROGMEM = "EEPROM";
|
593 |
+
const char esdcard[] PROGMEM = "SD card";
|
594 |
+
#endif
|
595 |
+
|
596 |
+
const char* const message[] PROGMEM = {
|
597 |
+
mfile, mprompt, mgreet,
|
598 |
+
mline, mnumber, mvariable, marray,
|
599 |
+
mstring, mstringv,
|
600 |
+
egeneral
|
601 |
+
#ifdef HASERRORMSG
|
602 |
+
, eunknown, enumber, edivide, eline, ereturn,
|
603 |
+
enext, egosub, efor, emem, estack, edim, erange,
|
604 |
+
estring, evariable, efile, efun, eargs,
|
605 |
+
eeeprom, esdcard
|
606 |
+
#endif
|
607 |
+
};
|
608 |
+
|
609 |
+
/*
|
610 |
+
* code for variable numbers and addresses sizes
|
611 |
+
* the original code was 16 bit but can be extended here
|
612 |
+
* to arbitrary types
|
613 |
+
*
|
614 |
+
* number_t is the type for numerical work - either float or int
|
615 |
+
* wnumber_t is the type containing the largest printable integer,
|
616 |
+
* for float keep this int on 32 bit and long on 8 bit unless you
|
617 |
+
* want to use very long integers, like 64 or 128 bit types.
|
618 |
+
* address_t is an unsigned type adddressing memory
|
619 |
+
* mem_t is a SIGNED 8bit character type.
|
620 |
+
* index_t is a SIGNED minimum 16 bit integer type
|
621 |
+
*
|
622 |
+
* works with the tacit assumption that
|
623 |
+
* sizeof(number_t) >= sizeof(address_t)
|
624 |
+
* and that the entire memory is smaller than the positive
|
625 |
+
* part of number type (!!)
|
626 |
+
*
|
627 |
+
* we assume that float >= 4 bytes in the following
|
628 |
+
*
|
629 |
+
* maxnum: the maximum accurate(!) integer of a
|
630 |
+
* 32 bit float
|
631 |
+
* strindexsize: the index size of strings either
|
632 |
+
* 1 byte or 2 bytes - no other values supported
|
633 |
+
*
|
634 |
+
*
|
635 |
+
*/
|
636 |
+
#ifdef HASFLOAT
|
637 |
+
typedef float number_t;
|
638 |
+
const number_t maxnum=16777216;
|
639 |
+
typedef long wnumber_t;
|
640 |
+
#else
|
641 |
+
typedef int number_t;
|
642 |
+
typedef int wnumber_t;
|
643 |
+
const number_t maxnum=(number_t)~((number_t)1<<(sizeof(number_t)*8-1));
|
644 |
+
#endif
|
645 |
+
typedef unsigned short address_t; /* this type addresses memory */
|
646 |
+
const int numsize=sizeof(number_t);
|
647 |
+
const int addrsize=sizeof(address_t);
|
648 |
+
const int eheadersize=sizeof(address_t)+1;
|
649 |
+
const int strindexsize=2; /* default in the meantime, strings up to unsigned 16 bit length */
|
650 |
+
const address_t maxaddr=(address_t)(~0);
|
651 |
+
typedef signed char mem_t; /* a signed 8 bit type for the memory */
|
652 |
+
typedef short index_t; /* this type counts at least 16 bit */
|
653 |
+
|
654 |
+
/*
|
655 |
+
* system type identifiers
|
656 |
+
*/
|
657 |
+
|
658 |
+
#define SYSTYPE_UNKNOWN 0
|
659 |
+
#define SYSTYPE_AVR 1
|
660 |
+
#define SYSTYPE_ESP8266 2
|
661 |
+
#define SYSTYPE_ESP32 3
|
662 |
+
#define SYSTYPE_RP2040 4
|
663 |
+
#define SYSTYPE_SAM 5
|
664 |
+
#define SYSTYPE_POSIX 32
|
665 |
+
#define SYSTYPE_MSDOS 33
|
666 |
+
|
667 |
+
/*
|
668 |
+
* The basic interpreter is implemented as a stack machine
|
669 |
+
* with global variable for the interpreter state, the memory
|
670 |
+
* and the arithmetic during run time.
|
671 |
+
*
|
672 |
+
* stack is the stack memory and sp controls the stack.
|
673 |
+
*
|
674 |
+
* ibuffer is an input buffer and *bi a pointer to it.
|
675 |
+
*
|
676 |
+
* sbuffer is a short buffer for arduino progmem access.
|
677 |
+
*
|
678 |
+
* vars is a static array of 26 single character variables.
|
679 |
+
*
|
680 |
+
* mem is the working memory of the basic interperter.
|
681 |
+
*
|
682 |
+
* x, y, xc, yc are two n*8 bit and two 8 bit accumulators.
|
683 |
+
*
|
684 |
+
* ax, ax are address type accumulators.
|
685 |
+
*
|
686 |
+
* z is a mixed n*8 bit accumulator
|
687 |
+
*
|
688 |
+
* ir, ir2 are general index registers for string processing.
|
689 |
+
*
|
690 |
+
* token contains the actually processes token.
|
691 |
+
*
|
692 |
+
* er is the nontrapable error status
|
693 |
+
*
|
694 |
+
* ert is the trapable error status
|
695 |
+
*
|
696 |
+
* st, here and top are the interpreter runtime controls.
|
697 |
+
*
|
698 |
+
* nvars is the number of vars the interpreter has stored.
|
699 |
+
*
|
700 |
+
* form is used for number formation Palo Alto BASIC style.
|
701 |
+
*
|
702 |
+
* charcount counts the printed characters to create a real TAB
|
703 |
+
* only implemented on the serial stream
|
704 |
+
* reltab controls if the relative char mechanisms is active
|
705 |
+
*
|
706 |
+
* rd is the random number storage.
|
707 |
+
*
|
708 |
+
* fnc counts the depth of for - next loop nesting
|
709 |
+
*
|
710 |
+
* args is the global arg count variable
|
711 |
+
*
|
712 |
+
* id and od are the input and output model for an arduino
|
713 |
+
* they are set to serial by default
|
714 |
+
*
|
715 |
+
* idd and odd are the default values of the above
|
716 |
+
*
|
717 |
+
* debuglevel is the statement loop debug level
|
718 |
+
*
|
719 |
+
* data is the data pointer of the READ/DATA mechanism
|
720 |
+
*
|
721 |
+
* static keyword here is obsolete on most platforms
|
722 |
+
*
|
723 |
+
*/
|
724 |
+
|
725 |
+
static number_t stack[STACKSIZE];
|
726 |
+
static address_t sp=0;
|
727 |
+
|
728 |
+
static char sbuffer[SBUFSIZE];
|
729 |
+
|
730 |
+
static char ibuffer[BUFSIZE] = "\0";
|
731 |
+
static char *bi;
|
732 |
+
|
733 |
+
static number_t vars[VARSIZE];
|
734 |
+
|
735 |
+
#if MEMSIZE != 0
|
736 |
+
static mem_t mem[MEMSIZE];
|
737 |
+
#else
|
738 |
+
static mem_t* mem;
|
739 |
+
#endif
|
740 |
+
static address_t himem, memsize;
|
741 |
+
|
742 |
+
static struct {mem_t varx; mem_t vary; address_t here; number_t to; number_t step;} forstack[FORDEPTH];
|
743 |
+
static index_t forsp = 0;
|
744 |
+
static mem_t fnc;
|
745 |
+
|
746 |
+
static address_t gosubstack[GOSUBDEPTH];
|
747 |
+
static index_t gosubsp = 0;
|
748 |
+
|
749 |
+
static number_t x, y;
|
750 |
+
static mem_t xc, yc;
|
751 |
+
|
752 |
+
static address_t ax, ay;
|
753 |
+
|
754 |
+
/* this union is used to store larger objects into byte oriented memory */
|
755 |
+
struct twobytes {mem_t l; mem_t h;};
|
756 |
+
static union accunumber { number_t i; address_t a; struct twobytes b; mem_t c[sizeof(number_t)]; } z;
|
757 |
+
|
758 |
+
static char *ir, *ir2;
|
759 |
+
static mem_t token;
|
760 |
+
static mem_t er;
|
761 |
+
static mem_t ert;
|
762 |
+
|
763 |
+
static mem_t st;
|
764 |
+
static address_t here;
|
765 |
+
static address_t top;
|
766 |
+
|
767 |
+
static address_t nvars = 0;
|
768 |
+
|
769 |
+
static mem_t form = 0;
|
770 |
+
|
771 |
+
#ifdef HASMSTAB
|
772 |
+
static mem_t charcount = 0;
|
773 |
+
static mem_t reltab = 0;
|
774 |
+
#endif
|
775 |
+
|
776 |
+
#ifdef HASARRAYLIMIT
|
777 |
+
static address_t arraylimit = 1;
|
778 |
+
#else
|
779 |
+
const static address_t arraylimit = 1;
|
780 |
+
#endif
|
781 |
+
|
782 |
+
static mem_t args;
|
783 |
+
|
784 |
+
/* this is unsigned hence address_t */
|
785 |
+
static address_t rd;
|
786 |
+
|
787 |
+
/* output and input vector */
|
788 |
+
static mem_t id;
|
789 |
+
static mem_t od;
|
790 |
+
|
791 |
+
/* default IO - not constant, can be changed at runtime
|
792 |
+
through a user call */
|
793 |
+
static mem_t idd = ISERIAL;
|
794 |
+
static mem_t odd = OSERIAL;
|
795 |
+
|
796 |
+
/* the runtime debuglevel */
|
797 |
+
static mem_t debuglevel = 0;
|
798 |
+
|
799 |
+
/* data pointer */
|
800 |
+
#ifdef HASDARTMOUTH
|
801 |
+
static address_t data = 0;
|
802 |
+
#endif
|
803 |
+
|
804 |
+
/*
|
805 |
+
* process command line arguments in the POSIX world
|
806 |
+
* bnointafterrun is a flag to remember if called as command
|
807 |
+
* line argument, in this case we don't return to interactive
|
808 |
+
*/
|
809 |
+
#ifndef ARDUINO
|
810 |
+
int bargc;
|
811 |
+
char** bargv;
|
812 |
+
mem_t bnointafterrun = 0;
|
813 |
+
#endif
|
814 |
+
|
815 |
+
/*
|
816 |
+
* Yield counter, we count when we did yield the last time
|
817 |
+
* lastyield controlls the client loops of network functions
|
818 |
+
* like mqtt, scanned keyboard, and USB.
|
819 |
+
*
|
820 |
+
* lastlongyield controls longterm functions like DHCP lease
|
821 |
+
* renewal in Ethernet
|
822 |
+
*
|
823 |
+
* there variables are only needed if the platform has background
|
824 |
+
* tasks
|
825 |
+
*/
|
826 |
+
static long lastyield=0;
|
827 |
+
static long lastlongyield=0;
|
828 |
+
|
829 |
+
/* formaters lastouttoken and spaceafterkeyword to make a nice LIST */
|
830 |
+
static mem_t lastouttoken;
|
831 |
+
static mem_t spaceafterkeyword;
|
832 |
+
|
833 |
+
/*
|
834 |
+
* the cache for the heap search - helps the string code
|
835 |
+
* the last found object on the heap is remembered. This is needed
|
836 |
+
* because the string code sometime searches the heap twice during the
|
837 |
+
* same operation.
|
838 |
+
*/
|
839 |
+
#ifdef HASAPPLE1
|
840 |
+
static mem_t bfindc, bfindd, bfindt;
|
841 |
+
static address_t bfinda, bfindz;
|
842 |
+
#endif
|
843 |
+
|
844 |
+
/* the interrupt vector - not yet implemented */
|
845 |
+
#ifdef HASINTERRUPTS
|
846 |
+
static short interruptvector;
|
847 |
+
#endif
|
848 |
+
|
849 |
+
/*
|
850 |
+
* Function prototypes, ordered by layers
|
851 |
+
* HAL - hardware abstraction
|
852 |
+
* Layer 0 - memory and I/O
|
853 |
+
* Layer 1 - Program storage and control
|
854 |
+
* Layer 2 - Where stuff happens
|
855 |
+
*/
|
856 |
+
|
857 |
+
/*
|
858 |
+
* HAL - see hardware-*.h
|
859 |
+
* This is the hardware abstraction layer of the BASIC
|
860 |
+
* interpreter
|
861 |
+
*/
|
862 |
+
|
863 |
+
/* setup codes */
|
864 |
+
void timeinit();
|
865 |
+
void wiringbegin();
|
866 |
+
|
867 |
+
/* low level mem and hardware features */
|
868 |
+
long freeRam();
|
869 |
+
long freememorysize();
|
870 |
+
void restartsystem();
|
871 |
+
void activatesleep(long t);
|
872 |
+
|
873 |
+
/* start the spi bus */
|
874 |
+
void spibegin();
|
875 |
+
|
876 |
+
/*
|
877 |
+
* the hardware interface display driver functions, need to be
|
878 |
+
* implemented for the display driver to work
|
879 |
+
* dspupdate() only for display like Epapers
|
880 |
+
*/
|
881 |
+
void dspbegin();
|
882 |
+
void dspprintchar(char, mem_t, mem_t);
|
883 |
+
void dspclear();
|
884 |
+
void dspupdate();
|
885 |
+
|
886 |
+
/* keyboard code */
|
887 |
+
void kbdbegin();
|
888 |
+
int kbdstat(char);
|
889 |
+
char kbdavailable();
|
890 |
+
char kbdread();
|
891 |
+
char kbdcheckch();
|
892 |
+
|
893 |
+
/* graphics functions */
|
894 |
+
void rgbcolor(int, int, int);
|
895 |
+
void vgacolor(short c);
|
896 |
+
void vgascale(int*, int*);
|
897 |
+
void plot(int, int);
|
898 |
+
void line(int, int, int, int);
|
899 |
+
void rect(int, int, int, int);
|
900 |
+
void frect(int, int, int, int);
|
901 |
+
void circle(int, int, int);
|
902 |
+
void fcircle(int, int, int);
|
903 |
+
|
904 |
+
/* text output to a VGA display */
|
905 |
+
void vgabegin();
|
906 |
+
int vgastat(char);
|
907 |
+
void vgawrite(char);
|
908 |
+
|
909 |
+
/* generic display code */
|
910 |
+
void dspwrite(char);
|
911 |
+
void dspbegin();
|
912 |
+
int dspstat(char);
|
913 |
+
char dspwaitonscroll();
|
914 |
+
char dspactive();
|
915 |
+
void dspsetupdatemode(char);
|
916 |
+
char dspgetupdatemode();
|
917 |
+
void dspgraphupdate();
|
918 |
+
void dspsetscrollmode(char, short);
|
919 |
+
void dspsetcursor(short, short);
|
920 |
+
void dspbufferclear();
|
921 |
+
void dspscroll(mem_t, mem_t);
|
922 |
+
void dspreversescroll(mem_t);
|
923 |
+
void dspvt52(char *);
|
924 |
+
|
925 |
+
/* real time clock */
|
926 |
+
char* rtcmkstr();
|
927 |
+
void rtcset(uint8_t, short);
|
928 |
+
short rtcget(short);
|
929 |
+
|
930 |
+
/* network and mqtt functions */
|
931 |
+
void netbegin();
|
932 |
+
char netconnected();
|
933 |
+
void mqttsetname();
|
934 |
+
void mqttbegin();
|
935 |
+
int mqttstat(char);
|
936 |
+
int mqttstate();
|
937 |
+
void mqttsubscribe(char*);
|
938 |
+
void mqttsettopic(char*);
|
939 |
+
void mqttouts(char *, short);
|
940 |
+
void mqttins(char *, short);
|
941 |
+
char mqttinch();
|
942 |
+
|
943 |
+
/* low level EEPROM handling */
|
944 |
+
void ebegin();
|
945 |
+
void eflush();
|
946 |
+
address_t elength();
|
947 |
+
short eread(address_t);
|
948 |
+
void eupdate(address_t, short);
|
949 |
+
|
950 |
+
/* arduino io functions */
|
951 |
+
void aread();
|
952 |
+
void dread();
|
953 |
+
void awrite(number_t, number_t);
|
954 |
+
void dwrite(number_t, number_t);
|
955 |
+
void pinm(number_t, number_t);
|
956 |
+
void bmillis();
|
957 |
+
void bpulsein();
|
958 |
+
void btone(short);
|
959 |
+
|
960 |
+
/* timing control for ESP and network */
|
961 |
+
void byield();
|
962 |
+
void yieldfunction();
|
963 |
+
void longyieldfunction();
|
964 |
+
|
965 |
+
/* the file interface */
|
966 |
+
char* mkfilename(const char*);
|
967 |
+
const char* rmrootfsprefix(const char*);
|
968 |
+
void fsbegin(char);
|
969 |
+
int fsstat(char);
|
970 |
+
void filewrite(char);
|
971 |
+
char fileread();
|
972 |
+
char ifileopen(const char*);
|
973 |
+
void ifileclose();
|
974 |
+
char ofileopen(char*, const char*);
|
975 |
+
void ofileclose();
|
976 |
+
int fileavailable();
|
977 |
+
void rootopen();
|
978 |
+
int rootnextfile();
|
979 |
+
int rootisfile();
|
980 |
+
const char* rootfilename();
|
981 |
+
int rootfilesize();
|
982 |
+
void rootfileclose();
|
983 |
+
void rootclose();
|
984 |
+
void formatdisk(short i);
|
985 |
+
|
986 |
+
/* low level serial code */
|
987 |
+
void picogetchar(char);
|
988 |
+
void picowrite(char);
|
989 |
+
void picobegin(uint32_t);
|
990 |
+
void picoins(char, short);
|
991 |
+
void serialbegin();
|
992 |
+
int serialstat(char);
|
993 |
+
char serialread();
|
994 |
+
void serialwrite(char);
|
995 |
+
short serialcheckch();
|
996 |
+
short serialavailable();
|
997 |
+
void consins(char*, short);
|
998 |
+
void prtbegin();
|
999 |
+
int prtstat(char);
|
1000 |
+
void prtset(int);
|
1001 |
+
char prtopen(char *, int);
|
1002 |
+
void prtclose();
|
1003 |
+
char prtread();
|
1004 |
+
void prtwrite(char);
|
1005 |
+
short prtcheckch();
|
1006 |
+
short prtavailable();
|
1007 |
+
|
1008 |
+
/* generic wire access */
|
1009 |
+
void wirebegin();
|
1010 |
+
int wirestat(char);
|
1011 |
+
void wireopen(char, char);
|
1012 |
+
void wireins(char*, uint8_t);
|
1013 |
+
void wireouts(char*, uint8_t);
|
1014 |
+
short wireavailable();
|
1015 |
+
|
1016 |
+
/* RF24 radio input */
|
1017 |
+
int radiostat(char);
|
1018 |
+
void radioset(int);
|
1019 |
+
#ifdef ARDUINO
|
1020 |
+
uint64_t pipeaddr(char*);
|
1021 |
+
#else
|
1022 |
+
long pipeaddr(char*);
|
1023 |
+
#endif
|
1024 |
+
void iradioopen(char*);
|
1025 |
+
void oradioopen(char*);
|
1026 |
+
void radioins(char*, short);
|
1027 |
+
void radioouts(char* , short);
|
1028 |
+
short radioavailable();
|
1029 |
+
|
1030 |
+
/* sensor control */
|
1031 |
+
void sensorbegin();
|
1032 |
+
number_t sensorread(short, short);
|
1033 |
+
|
1034 |
+
/* SPI RAM code */
|
1035 |
+
address_t spirambegin();
|
1036 |
+
void spiramrawwrite(address_t, mem_t);
|
1037 |
+
mem_t spiramrawread(address_t );
|
1038 |
+
|
1039 |
+
/*
|
1040 |
+
* Layer 0 functions - I/O and memory management
|
1041 |
+
*/
|
1042 |
+
|
1043 |
+
/* make room for BASIC */
|
1044 |
+
address_t ballocmem();
|
1045 |
+
|
1046 |
+
/* handle files im EEPROM */
|
1047 |
+
void eload();
|
1048 |
+
void esave();
|
1049 |
+
char autorun();
|
1050 |
+
|
1051 |
+
/* the variable heap from Apple 1 BASIC */
|
1052 |
+
address_t bmalloc(mem_t, mem_t, mem_t, address_t);
|
1053 |
+
address_t bfind(mem_t, mem_t, mem_t);
|
1054 |
+
address_t blength (mem_t, mem_t, mem_t);
|
1055 |
+
|
1056 |
+
/* normal variables of number_t */
|
1057 |
+
void createvar(mem_t, mem_t);
|
1058 |
+
number_t getvar(mem_t, mem_t);
|
1059 |
+
void setvar(mem_t, mem_t, number_t);
|
1060 |
+
void clrvars();
|
1061 |
+
|
1062 |
+
/* low level memory access packing n*8bit bit into n 8 bit objects
|
1063 |
+
e* is for Arduino EEPROM */
|
1064 |
+
void getnumber(address_t, mem_t);
|
1065 |
+
void setnumber(address_t, mem_t);
|
1066 |
+
void egetnumber(address_t, mem_t);
|
1067 |
+
void esetnumber(address_t, mem_t);
|
1068 |
+
|
1069 |
+
/* array and string handling */
|
1070 |
+
/* the multidim extension is experimental, here only 2 array dimensions implemented as test */
|
1071 |
+
address_t createarray(mem_t, mem_t, address_t, address_t);
|
1072 |
+
void array(mem_t, mem_t, mem_t, address_t, address_t, number_t*);
|
1073 |
+
address_t createstring(char, char, address_t, address_t);
|
1074 |
+
char* getstring(char, char, address_t, address_t);
|
1075 |
+
number_t arraydim(char, char);
|
1076 |
+
address_t stringdim(char, char);
|
1077 |
+
address_t lenstring(char, char, address_t);
|
1078 |
+
void setstringlength(char, char, address_t, address_t);
|
1079 |
+
void setstring(char, char, address_t, char *, address_t, address_t);
|
1080 |
+
|
1081 |
+
/* get keywords and tokens from PROGMEM */
|
1082 |
+
char* getkeyword(unsigned short);
|
1083 |
+
char* getmessage(char);
|
1084 |
+
signed char gettokenvalue(char);
|
1085 |
+
void printmessage(char);
|
1086 |
+
|
1087 |
+
/* error handling */
|
1088 |
+
void error(mem_t);
|
1089 |
+
void reseterror();
|
1090 |
+
void debugtoken();
|
1091 |
+
void bdebug(const char*);
|
1092 |
+
|
1093 |
+
/* the arithemtic stack */
|
1094 |
+
void push(number_t);
|
1095 |
+
number_t pop();
|
1096 |
+
void drop();
|
1097 |
+
void clearst();
|
1098 |
+
|
1099 |
+
/* READ DATA handling */
|
1100 |
+
void clrdata();
|
1101 |
+
|
1102 |
+
/* FOR NEXT GOSUB stacks */
|
1103 |
+
void pushforstack();
|
1104 |
+
void popforstack();
|
1105 |
+
void dropforstack();
|
1106 |
+
void clrforstack();
|
1107 |
+
void pushgosubstack();
|
1108 |
+
void popgosubstack();
|
1109 |
+
void dropgosubstack();
|
1110 |
+
void clrgosubstack();
|
1111 |
+
|
1112 |
+
/* general I/O initialisation */
|
1113 |
+
void ioinit();
|
1114 |
+
void iodefaults();
|
1115 |
+
|
1116 |
+
/* character and string I/O functions */
|
1117 |
+
/* input */
|
1118 |
+
char inch();
|
1119 |
+
char checkch();
|
1120 |
+
short availch();
|
1121 |
+
void inb(char*, short);
|
1122 |
+
void ins(char*, address_t);
|
1123 |
+
|
1124 |
+
/* output */
|
1125 |
+
void outch(char);
|
1126 |
+
void outcr();
|
1127 |
+
void outspc();
|
1128 |
+
void outs(char*, address_t);
|
1129 |
+
void outsc(const char*);
|
1130 |
+
void outscf(const char *, short);
|
1131 |
+
|
1132 |
+
/* I/O of number_t - floats and integers */
|
1133 |
+
address_t parsenumber(char*, number_t*);
|
1134 |
+
address_t parsenumber2(char*, number_t*);
|
1135 |
+
address_t writenumber(char*, wnumber_t);
|
1136 |
+
address_t writenumber2(char*, number_t);
|
1137 |
+
char innumber(number_t*);
|
1138 |
+
void outnumber(number_t);
|
1139 |
+
|
1140 |
+
/*
|
1141 |
+
* Layer 1 functions, provide data and do the heavy lifting
|
1142 |
+
* for layer 2 including lexical analysis, storing programs
|
1143 |
+
* and expression evaluation
|
1144 |
+
*/
|
1145 |
+
|
1146 |
+
/* lexical analysis */
|
1147 |
+
void whitespaces();
|
1148 |
+
void nexttoken();
|
1149 |
+
|
1150 |
+
/* storing and retrieving programs */
|
1151 |
+
char nomemory(number_t);
|
1152 |
+
void storetoken();
|
1153 |
+
mem_t memread(address_t);
|
1154 |
+
mem_t memread2(address_t);
|
1155 |
+
void memwrite2(address_t, mem_t);
|
1156 |
+
void gettoken();
|
1157 |
+
void firstline();
|
1158 |
+
void nextline();
|
1159 |
+
|
1160 |
+
void clrlinecache();
|
1161 |
+
void addlinecache(address_t, address_t);
|
1162 |
+
address_t findinlinecache(address_t);
|
1163 |
+
void findline(address_t);
|
1164 |
+
address_t myline(address_t);
|
1165 |
+
void moveblock(address_t, address_t, address_t);
|
1166 |
+
void zeroblock(address_t, address_t);
|
1167 |
+
void diag();
|
1168 |
+
void storeline();
|
1169 |
+
|
1170 |
+
/* read arguments from the token stream and process them */
|
1171 |
+
char termsymbol();
|
1172 |
+
char expect(mem_t, mem_t);
|
1173 |
+
char expectexpr();
|
1174 |
+
void parsearguments();
|
1175 |
+
void parsenarguments(char);
|
1176 |
+
void parsesubscripts();
|
1177 |
+
void parsefunction(void (*)(), short);
|
1178 |
+
void parseoperator(void (*)());
|
1179 |
+
void parsesubstring();
|
1180 |
+
|
1181 |
+
/* mathematics and other functions for int and float */
|
1182 |
+
void xabs();
|
1183 |
+
void xsgn();
|
1184 |
+
void xpeek();
|
1185 |
+
void xmap();
|
1186 |
+
void rnd();
|
1187 |
+
void sqr();
|
1188 |
+
void xpow();
|
1189 |
+
|
1190 |
+
/* string values and string evaluation */
|
1191 |
+
char stringvalue();
|
1192 |
+
void streval();
|
1193 |
+
|
1194 |
+
/* floating point functions */
|
1195 |
+
void xsin();
|
1196 |
+
void xcos();
|
1197 |
+
void xtan();
|
1198 |
+
void xatan();
|
1199 |
+
void xlog();
|
1200 |
+
void xexp();
|
1201 |
+
void xint();
|
1202 |
+
|
1203 |
+
/* expression evaluation */
|
1204 |
+
void factor();
|
1205 |
+
void term();
|
1206 |
+
void addexpression();
|
1207 |
+
void compexpression();
|
1208 |
+
void notexpression();
|
1209 |
+
void andexpression();
|
1210 |
+
void expression();
|
1211 |
+
|
1212 |
+
/*
|
1213 |
+
* Layer 2 - statements and functions
|
1214 |
+
* use the global variables
|
1215 |
+
*/
|
1216 |
+
|
1217 |
+
/* basic commands of the core language set */
|
1218 |
+
void xprint();
|
1219 |
+
void lefthandside(address_t*, address_t*, address_t*, mem_t*);
|
1220 |
+
void assignnumber(signed char, char, char, address_t, address_t, char);
|
1221 |
+
void assignment();
|
1222 |
+
void showprompt();
|
1223 |
+
void xinput();
|
1224 |
+
void xgoto();
|
1225 |
+
void xreturn();
|
1226 |
+
void xif();
|
1227 |
+
|
1228 |
+
/* optional FOR NEXT loops */
|
1229 |
+
void findnextcmd();
|
1230 |
+
void xfor();
|
1231 |
+
void xbreak();
|
1232 |
+
void xcont();
|
1233 |
+
void xnext();
|
1234 |
+
|
1235 |
+
/* control commands and misc */
|
1236 |
+
void outputtoken();
|
1237 |
+
void xlist();
|
1238 |
+
void xrun();
|
1239 |
+
void xnew();
|
1240 |
+
void xrem();
|
1241 |
+
void xclr();
|
1242 |
+
void xdim();
|
1243 |
+
void xpoke();
|
1244 |
+
void xtab();
|
1245 |
+
void xdump();
|
1246 |
+
void dumpmem(address_t, address_t);
|
1247 |
+
|
1248 |
+
/* file access and other i/o */
|
1249 |
+
void stringtobuffer();
|
1250 |
+
void getfilename(char*, char);
|
1251 |
+
void xsave();
|
1252 |
+
void xload(const char* f);
|
1253 |
+
void xget();
|
1254 |
+
void xput();
|
1255 |
+
void xset();
|
1256 |
+
void xnetstat();
|
1257 |
+
|
1258 |
+
/* Arduino IO control interface */
|
1259 |
+
void xdwrite();
|
1260 |
+
void xawrite();
|
1261 |
+
void xpinm();
|
1262 |
+
void xdelay();
|
1263 |
+
void xtone();
|
1264 |
+
|
1265 |
+
/* graphics commands */
|
1266 |
+
void xcolor();
|
1267 |
+
void xplot();
|
1268 |
+
void xline();
|
1269 |
+
void xrect();
|
1270 |
+
void xcircle();
|
1271 |
+
void xfrect();
|
1272 |
+
void xfcircle();
|
1273 |
+
|
1274 |
+
/* the darkarts */
|
1275 |
+
void xmalloc();
|
1276 |
+
void xfind();
|
1277 |
+
void xfind2();
|
1278 |
+
void xeval();
|
1279 |
+
|
1280 |
+
/* IoT commands */
|
1281 |
+
void xassign();
|
1282 |
+
void xavail();
|
1283 |
+
void xfsensor();
|
1284 |
+
void xsleep();
|
1285 |
+
|
1286 |
+
/* File I/O functions */
|
1287 |
+
char streq(const char*, char*);
|
1288 |
+
void xcatalog();
|
1289 |
+
void xdelete();
|
1290 |
+
void xopen();
|
1291 |
+
void xfopen();
|
1292 |
+
void xclose();
|
1293 |
+
void xfdisk();
|
1294 |
+
|
1295 |
+
/* low level access functions */
|
1296 |
+
void xcall();
|
1297 |
+
void xusr();
|
1298 |
+
|
1299 |
+
/* the dartmouth stuff */
|
1300 |
+
void xdata();
|
1301 |
+
void nextdatarecord();
|
1302 |
+
void xread();
|
1303 |
+
void xrestore();
|
1304 |
+
void xdef();
|
1305 |
+
void xfn();
|
1306 |
+
void xon();
|
1307 |
+
|
1308 |
+
/* the statement loop */
|
1309 |
+
void statement();
|
1310 |
+
|
1311 |
+
/* stub for the interrupt code */
|
1312 |
+
void handleinterrupt();
|
data/Basic1/TinyVT52/hardware-arduino.h
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic1/TinybasicArduino/TinybasicArduino.ino
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic1/TinybasicArduino/basic.h
ADDED
@@ -0,0 +1,1526 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*
|
3 |
+
* $Id: basic.h,v 1.13 2023/07/16 14:17:08 stefan Exp stefan $
|
4 |
+
*
|
5 |
+
* Stefan's basic interpreter
|
6 |
+
*
|
7 |
+
* Playing around with frugal programming. See the licence file on
|
8 |
+
* https://github.com/slviajero/tinybasic for copyright/left.
|
9 |
+
* (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
|
10 |
+
*
|
11 |
+
* Author: Stefan Lenz, [email protected]
|
12 |
+
*
|
13 |
+
* basic.h are the core defintions and function protypes
|
14 |
+
*
|
15 |
+
*/
|
16 |
+
|
17 |
+
/*
|
18 |
+
* if the PROGMEM macro is define we compile on the Arduino IDE
|
19 |
+
* we undef all hardware settings otherwise a little odd
|
20 |
+
*/
|
21 |
+
#ifdef ARDUINO_ARCH_MBED
|
22 |
+
#define PROGMEM
|
23 |
+
#endif
|
24 |
+
|
25 |
+
#ifdef PROGMEM
|
26 |
+
#define ARDUINOPROGMEM
|
27 |
+
#else
|
28 |
+
#undef ARDUINO
|
29 |
+
#undef ARDUINOSD
|
30 |
+
#undef ARDUINORF24
|
31 |
+
#undef ARDUINORTC
|
32 |
+
#undef ARDUINOEEPROM
|
33 |
+
#undef ARDUINOEEPROMI2C
|
34 |
+
#undef ARDUINOWIRE
|
35 |
+
#endif
|
36 |
+
|
37 |
+
/*
|
38 |
+
* MSDOS, Mac, Linux and Windows
|
39 |
+
*/
|
40 |
+
#ifndef ARDUINO
|
41 |
+
typedef unsigned char uint8_t;
|
42 |
+
#define PROGMEM
|
43 |
+
#include <stdio.h>
|
44 |
+
#include <stdlib.h>
|
45 |
+
#ifdef HASFLOAT
|
46 |
+
#include <math.h>
|
47 |
+
#include <float.h>
|
48 |
+
#endif
|
49 |
+
#include <time.h>
|
50 |
+
#include <sys/types.h>
|
51 |
+
#include <sys/timeb.h>
|
52 |
+
#ifndef MSDOS
|
53 |
+
#include <dirent.h>
|
54 |
+
#include <unistd.h>
|
55 |
+
#else
|
56 |
+
#include <dir.h>
|
57 |
+
#include <dos.h>
|
58 |
+
#endif
|
59 |
+
#ifdef MINGW
|
60 |
+
#include <windows.h>
|
61 |
+
#endif
|
62 |
+
#endif
|
63 |
+
|
64 |
+
|
65 |
+
#if defined(ARDUINO_ARCH_AVR)
|
66 |
+
/* the small memory model with shallow stacks and small buffers */
|
67 |
+
#define BUFSIZE 80
|
68 |
+
#define STACKSIZE 15
|
69 |
+
#define GOSUBDEPTH 4
|
70 |
+
#define FORDEPTH 4
|
71 |
+
#define LINECACHESIZE 4
|
72 |
+
#else
|
73 |
+
/* the for larger microcontrollers */
|
74 |
+
#ifdef ARDUINO
|
75 |
+
#define BUFSIZE 128
|
76 |
+
#define STACKSIZE 64
|
77 |
+
#define GOSUBDEPTH 8
|
78 |
+
#define FORDEPTH 8
|
79 |
+
#define LINECACHESIZE 16
|
80 |
+
#else
|
81 |
+
/* for real computers */
|
82 |
+
#define BUFSIZE 256
|
83 |
+
#define STACKSIZE 256
|
84 |
+
#define GOSUBDEPTH 64
|
85 |
+
#define FORDEPTH 64
|
86 |
+
#define LINECACHESIZE 64
|
87 |
+
#endif
|
88 |
+
#endif
|
89 |
+
|
90 |
+
/* on the real small systems we remove the linecache and set a fixed memory size*/
|
91 |
+
#ifdef ARDUINO_AVR_DUEMILANOVE
|
92 |
+
#undef LINECACHESIZE
|
93 |
+
#if MEMSIZE == 0
|
94 |
+
#define MEMSIZE 512
|
95 |
+
#endif
|
96 |
+
#endif
|
97 |
+
|
98 |
+
/* more duffers and vars */
|
99 |
+
#define SBUFSIZE 32
|
100 |
+
#define VARSIZE 26
|
101 |
+
/* default sizes of arrays and strings if they are not DIMed */
|
102 |
+
#define ARRAYSIZEDEF 10
|
103 |
+
#define STRSIZEDEF 32
|
104 |
+
|
105 |
+
/*
|
106 |
+
* the time intervall in ms needed for
|
107 |
+
* ESP8266 yields, network client loops
|
108 |
+
* and other timing related functions
|
109 |
+
*/
|
110 |
+
#define LONGYIELDINTERVAL 1000
|
111 |
+
#define YIELDINTERVAL 32
|
112 |
+
#define YIELDTIME 2
|
113 |
+
|
114 |
+
/* the default EEPROM dummy size */
|
115 |
+
#define EEPROMSIZE 1024
|
116 |
+
|
117 |
+
/* after run behaviour on POSIX systems, 1 to terminate if started
|
118 |
+
on the command line with a file argument, 0 to stay active and
|
119 |
+
show a BASIC prompt*/
|
120 |
+
#define TERMINATEAFTERRUN 1
|
121 |
+
|
122 |
+
/*
|
123 |
+
* The tokens for the BASIC keywords
|
124 |
+
*
|
125 |
+
* All single character operators are their own tokens
|
126 |
+
* ASCII values above 0x7f are used for tokens of keywords.
|
127 |
+
* EOL is a token
|
128 |
+
*/
|
129 |
+
#define EOL 0
|
130 |
+
#define NUMBER -127
|
131 |
+
#define LINENUMBER -126
|
132 |
+
#define STRING -125
|
133 |
+
#define VARIABLE -124
|
134 |
+
#define STRINGVAR -123
|
135 |
+
#define ARRAYVAR -122
|
136 |
+
/* multi character tokens - BASEKEYWORD (3) */
|
137 |
+
#define GREATEREQUAL -121
|
138 |
+
#define LESSEREQUAL -120
|
139 |
+
#define NOTEQUAL -119
|
140 |
+
/* this is the Palo Alto Language Set (19) */
|
141 |
+
#define TPRINT -118
|
142 |
+
#define TLET -117
|
143 |
+
#define TINPUT -116
|
144 |
+
#define TGOTO -115
|
145 |
+
#define TGOSUB -114
|
146 |
+
#define TRETURN -113
|
147 |
+
#define TIF -112
|
148 |
+
#define TFOR -111
|
149 |
+
#define TTO -110
|
150 |
+
#define TSTEP -109
|
151 |
+
#define TNEXT -108
|
152 |
+
#define TSTOP -107
|
153 |
+
#define TLIST -106
|
154 |
+
#define TNEW -105
|
155 |
+
#define TRUN -104
|
156 |
+
#define TABS -103
|
157 |
+
#define TRND -102
|
158 |
+
#define TSIZE -101
|
159 |
+
#define TREM -100
|
160 |
+
/* this is the Apple 1 language set in addition to Palo Alto (14) */
|
161 |
+
#define TNOT -99
|
162 |
+
#define TAND -98
|
163 |
+
#define TOR -97
|
164 |
+
#define TLEN -96
|
165 |
+
#define TSGN -95
|
166 |
+
#define TPEEK -94
|
167 |
+
#define TDIM -93
|
168 |
+
#define TCLR -92
|
169 |
+
#define THIMEM -91
|
170 |
+
#define TTAB -90
|
171 |
+
#define TTHEN -89
|
172 |
+
#define TEND -88
|
173 |
+
#define TPOKE -87
|
174 |
+
/* Stefan's tinybasic additions (14) */
|
175 |
+
#define TCONT -86
|
176 |
+
#define TSQR -85
|
177 |
+
#define TPOW -84
|
178 |
+
#define TMAP -83
|
179 |
+
#define TDUMP -82
|
180 |
+
#define TBREAK -81
|
181 |
+
#define TSAVE -80
|
182 |
+
#define TLOAD -79
|
183 |
+
#define TGET -78
|
184 |
+
#define TPUT -77
|
185 |
+
#define TSET -76
|
186 |
+
#define TCLS -75
|
187 |
+
#define TLOCATE -74
|
188 |
+
#define TELSE -73
|
189 |
+
/* Arduino functions (10) */
|
190 |
+
#define TPINM -72
|
191 |
+
#define TDWRITE -71
|
192 |
+
#define TDREAD -70
|
193 |
+
#define TAWRITE -69
|
194 |
+
#define TAREAD -68
|
195 |
+
#define TDELAY -67
|
196 |
+
#define TMILLIS -66
|
197 |
+
#define TTONE -65
|
198 |
+
#define TPULSE -64
|
199 |
+
#define TAZERO -63
|
200 |
+
#define TLED -62
|
201 |
+
/* the DOS functions (5) */
|
202 |
+
#define TCATALOG -61
|
203 |
+
#define TDELETE -60
|
204 |
+
#define TOPEN -59
|
205 |
+
#define TCLOSE -58
|
206 |
+
#define TFDISK -57
|
207 |
+
/* low level access of internal routines (2) */
|
208 |
+
#define TUSR -56
|
209 |
+
#define TCALL -55
|
210 |
+
/* mathematical functions (7) */
|
211 |
+
#define TSIN -54
|
212 |
+
#define TCOS -53
|
213 |
+
#define TTAN -52
|
214 |
+
#define TATAN -51
|
215 |
+
#define TLOG -50
|
216 |
+
#define TEXP -49
|
217 |
+
#define TINT -48
|
218 |
+
/* graphics - experimental - rudimentary (7) */
|
219 |
+
#define TCOLOR -47
|
220 |
+
#define TPLOT -46
|
221 |
+
#define TLINE -45
|
222 |
+
#define TCIRCLE -44
|
223 |
+
#define TRECT -43
|
224 |
+
#define TFCIRCLE -42
|
225 |
+
#define TFRECT -41
|
226 |
+
/* the Dartmouth extensions (6) */
|
227 |
+
#define TDATA -40
|
228 |
+
#define TREAD -39
|
229 |
+
#define TRESTORE -38
|
230 |
+
#define TDEF -37
|
231 |
+
#define TFN -36
|
232 |
+
#define TON -35
|
233 |
+
/* darkarts (3) */
|
234 |
+
#define TMALLOC -34
|
235 |
+
#define TFIND -33
|
236 |
+
#define TEVAL -32
|
237 |
+
/* iot extensions (9) */
|
238 |
+
#define TERROR -31
|
239 |
+
#define TAVAIL -30
|
240 |
+
#define TSTR -29
|
241 |
+
#define TINSTR -28
|
242 |
+
#define TVAL -27
|
243 |
+
#define TNETSTAT -26
|
244 |
+
#define TSENSOR -25
|
245 |
+
#define TWIRE -24
|
246 |
+
#define TSLEEP -23
|
247 |
+
/* events and interrupts */
|
248 |
+
#define TAFTER -22
|
249 |
+
#define TEVERY -21
|
250 |
+
#define TEVENT -20
|
251 |
+
/* experimental structured commands, currently partially implemented */
|
252 |
+
#define TWHILE -19
|
253 |
+
#define TWEND -18
|
254 |
+
#define TREPEAT -17
|
255 |
+
#define TUNTIL -16
|
256 |
+
#define TSWITCH -15
|
257 |
+
#define TCASE -14
|
258 |
+
#define TSWEND -13
|
259 |
+
#define TDO -12
|
260 |
+
#define TDEND -11
|
261 |
+
/* these are multibyte token extension, currently unused */
|
262 |
+
/* using them would allow over 1000 BASIC keywords */
|
263 |
+
#define TEXT1 -3
|
264 |
+
/* end of tokens */
|
265 |
+
/* constants used for some obscure purposes */
|
266 |
+
#define TBUFFER -2
|
267 |
+
/* UNKNOWN is not used in the current code, the
|
268 |
+
* lexer tokenizes everything blindly. There is a UNKNOWN hook
|
269 |
+
* in statement for a grammar aware lexer */
|
270 |
+
#define UNKNOWN -1
|
271 |
+
|
272 |
+
/* extension tokens can be in the range from -128 to -255
|
273 |
+
* one needs to set HASLONGTOKENS
|
274 |
+
*/
|
275 |
+
#undef HASLONGTOKEN
|
276 |
+
#define TTOKEN1 -128
|
277 |
+
|
278 |
+
|
279 |
+
/* the number of keywords, and the base index of the keywords
|
280 |
+
* the number is irrelevant but BASEKEYWORD is used */
|
281 |
+
#define NKEYWORDS 3+19+13+14+11+5+2+7+7+6+12+3+9
|
282 |
+
#define BASEKEYWORD -121
|
283 |
+
|
284 |
+
/*
|
285 |
+
* Interpreter states
|
286 |
+
* SRUN means running from a programm
|
287 |
+
* SINT means interactive mode
|
288 |
+
* SERUN means running directly from EEPROM
|
289 |
+
* (enum would be the right way of doing this.)
|
290 |
+
* BREAKCHAR is the character stopping the program on Ardunios
|
291 |
+
* BREAKPIN can be set, it is a pin that needs to go to low to stop a BASIC program
|
292 |
+
* This should be done in hardware*.h
|
293 |
+
* BREAKSIGNAL can also be set, should be done in hardware*.h
|
294 |
+
*/
|
295 |
+
#define SINT 0
|
296 |
+
#define SRUN 1
|
297 |
+
#define SERUN 2
|
298 |
+
#define BREAKCHAR '#'
|
299 |
+
|
300 |
+
/*
|
301 |
+
* Input and output channels
|
302 |
+
*/
|
303 |
+
#define OSERIAL 1
|
304 |
+
#define ODSP 2
|
305 |
+
#define OPRT 4
|
306 |
+
#define OWIRE 7
|
307 |
+
#define ORADIO 8
|
308 |
+
#define OMQTT 9
|
309 |
+
#define OFILE 16
|
310 |
+
|
311 |
+
#define ISERIAL 1
|
312 |
+
#define IKEYBOARD 2
|
313 |
+
#define ISERIAL1 4
|
314 |
+
#define IWIRE 7
|
315 |
+
#define IRADIO 8
|
316 |
+
#define IMQTT 9
|
317 |
+
#define IFILE 16
|
318 |
+
|
319 |
+
/*
|
320 |
+
* All BASIC keywords for the tokens
|
321 |
+
*/
|
322 |
+
const char sge[] PROGMEM = "=>";
|
323 |
+
const char sle[] PROGMEM = "<=";
|
324 |
+
const char sne[] PROGMEM = "<>";
|
325 |
+
/* Palo Alto language set */
|
326 |
+
const char sprint[] PROGMEM = "PRINT";
|
327 |
+
const char slet[] PROGMEM = "LET";
|
328 |
+
const char sinput[] PROGMEM = "INPUT";
|
329 |
+
const char sgoto[] PROGMEM = "GOTO";
|
330 |
+
const char sgosub[] PROGMEM = "GOSUB";
|
331 |
+
const char sreturn[] PROGMEM = "RETURN";
|
332 |
+
const char sif[] PROGMEM = "IF";
|
333 |
+
const char sfor[] PROGMEM = "FOR";
|
334 |
+
const char sto[] PROGMEM = "TO";
|
335 |
+
const char sstep[] PROGMEM = "STEP";
|
336 |
+
const char snext[] PROGMEM = "NEXT";
|
337 |
+
const char sstop[] PROGMEM = "STOP";
|
338 |
+
const char slist[] PROGMEM = "LIST";
|
339 |
+
const char snew[] PROGMEM = "NEW";
|
340 |
+
const char srun[] PROGMEM = "RUN";
|
341 |
+
const char sabs[] PROGMEM = "ABS";
|
342 |
+
const char srnd[] PROGMEM = "RND";
|
343 |
+
const char ssize[] PROGMEM = "SIZE";
|
344 |
+
const char srem[] PROGMEM = "REM";
|
345 |
+
/* Apple 1 language set */
|
346 |
+
#ifdef HASAPPLE1
|
347 |
+
const char snot[] PROGMEM = "NOT";
|
348 |
+
const char sand[] PROGMEM = "AND";
|
349 |
+
const char sor[] PROGMEM = "OR";
|
350 |
+
const char slen[] PROGMEM = "LEN";
|
351 |
+
const char ssgn[] PROGMEM = "SGN";
|
352 |
+
const char speek[] PROGMEM = "PEEK";
|
353 |
+
const char sdim[] PROGMEM = "DIM";
|
354 |
+
const char sclr[] PROGMEM = "CLR";
|
355 |
+
const char shimem[] PROGMEM = "HIMEM";
|
356 |
+
const char stab[] PROGMEM = "TAB";
|
357 |
+
const char sthen[] PROGMEM = "THEN";
|
358 |
+
const char sbend[] PROGMEM = "END";
|
359 |
+
const char spoke[] PROGMEM = "POKE";
|
360 |
+
#endif
|
361 |
+
/* Stefan's basic additions */
|
362 |
+
#ifdef HASSTEFANSEXT
|
363 |
+
const char scont[] PROGMEM = "CONT";
|
364 |
+
const char ssqr[] PROGMEM = "SQR";
|
365 |
+
const char spow[] PROGMEM = "POW";
|
366 |
+
const char smap[] PROGMEM = "MAP";
|
367 |
+
const char sdump[] PROGMEM = "DUMP";
|
368 |
+
const char sbreak[] PROGMEM = "BREAK";
|
369 |
+
#endif
|
370 |
+
/* LOAD and SAVE is always there */
|
371 |
+
const char ssave[] PROGMEM = "SAVE";
|
372 |
+
const char sload[] PROGMEM = "LOAD";
|
373 |
+
#ifdef HASSTEFANSEXT
|
374 |
+
const char sget[] PROGMEM = "GET";
|
375 |
+
const char sput[] PROGMEM = "PUT";
|
376 |
+
const char sset[] PROGMEM = "SET";
|
377 |
+
const char scls[] PROGMEM = "CLS";
|
378 |
+
const char slocate[] PROGMEM = "LOCATE";
|
379 |
+
const char selse[] PROGMEM = "ELSE";
|
380 |
+
#endif
|
381 |
+
/* Arduino functions */
|
382 |
+
#ifdef HASARDUINOIO
|
383 |
+
const char spinm[] PROGMEM = "PINM";
|
384 |
+
const char sdwrite[] PROGMEM = "DWRITE";
|
385 |
+
const char sdread[] PROGMEM = "DREAD";
|
386 |
+
const char sawrite[] PROGMEM = "AWRITE";
|
387 |
+
const char saread[] PROGMEM = "AREAD";
|
388 |
+
const char sdelay[] PROGMEM = "DELAY";
|
389 |
+
const char smillis[] PROGMEM = "MILLIS";
|
390 |
+
const char sazero[] PROGMEM = "AZERO";
|
391 |
+
const char sled[] PROGMEM = "LED";
|
392 |
+
#endif
|
393 |
+
#ifdef HASTONE
|
394 |
+
const char stone[] PROGMEM = "PLAY";
|
395 |
+
#endif
|
396 |
+
#ifdef HASPULSE
|
397 |
+
const char spulse[] PROGMEM = "PULSE";
|
398 |
+
#endif
|
399 |
+
/* DOS functions */
|
400 |
+
#ifdef HASFILEIO
|
401 |
+
const char scatalog[] PROGMEM = "CATALOG";
|
402 |
+
const char sdelete[] PROGMEM = "DELETE";
|
403 |
+
const char sfopen[] PROGMEM = "OPEN";
|
404 |
+
const char sfclose[] PROGMEM = "CLOSE";
|
405 |
+
const char sfdisk[] PROGMEM = "FDISK";
|
406 |
+
#endif
|
407 |
+
/* low level access functions */
|
408 |
+
#ifdef HASSTEFANSEXT
|
409 |
+
const char susr[] PROGMEM = "USR";
|
410 |
+
const char scall[] PROGMEM = "CALL";
|
411 |
+
#endif
|
412 |
+
/* mathematics */
|
413 |
+
#ifdef HASFLOAT
|
414 |
+
const char ssin[] PROGMEM = "SIN";
|
415 |
+
const char scos[] PROGMEM = "COS";
|
416 |
+
const char stan[] PROGMEM = "TAN";
|
417 |
+
const char satan[] PROGMEM = "ATAN";
|
418 |
+
const char slog[] PROGMEM = "LOG";
|
419 |
+
const char sexp[] PROGMEM = "EXP";
|
420 |
+
#endif
|
421 |
+
/* INT is always needed to make float/int programs compatible */
|
422 |
+
const char sint[] PROGMEM = "INT";
|
423 |
+
/* elemetars graphics */
|
424 |
+
#ifdef HASGRAPH
|
425 |
+
const char scolor[] PROGMEM = "COLOR";
|
426 |
+
const char splot[] PROGMEM = "PLOT";
|
427 |
+
const char sline[] PROGMEM = "LINE";
|
428 |
+
const char scircle[] PROGMEM = "CIRCLE";
|
429 |
+
const char srect[] PROGMEM = "RECT";
|
430 |
+
const char sfcircle[] PROGMEM = "FCIRCLE";
|
431 |
+
const char sfrect[] PROGMEM = "FRECT";
|
432 |
+
#endif
|
433 |
+
/* Dartmouth BASIC extensions */
|
434 |
+
#ifdef HASDARTMOUTH
|
435 |
+
const char sdata[] PROGMEM = "DATA";
|
436 |
+
const char sread[] PROGMEM = "READ";
|
437 |
+
const char srestore[] PROGMEM = "RESTORE";
|
438 |
+
const char sdef[] PROGMEM = "DEF";
|
439 |
+
const char sfn[] PROGMEM = "FN";
|
440 |
+
const char son[] PROGMEM = "ON";
|
441 |
+
#endif
|
442 |
+
/* The Darkarts commands unthinkable in Dartmouth */
|
443 |
+
#ifdef HASDARKARTS
|
444 |
+
const char smalloc[] PROGMEM = "MALLOC";
|
445 |
+
const char sfind[] PROGMEM = "FIND";
|
446 |
+
const char seval[] PROGMEM = "EVAL";
|
447 |
+
#endif
|
448 |
+
/* complex error handling */
|
449 |
+
#ifdef HASERRORHANDLING
|
450 |
+
const char serror[] PROGMEM = "ERROR";
|
451 |
+
#endif
|
452 |
+
/* iot extensions */
|
453 |
+
#ifdef HASIOT
|
454 |
+
const char savail[] PROGMEM = "AVAIL";
|
455 |
+
const char sstr[] PROGMEM = "STR";
|
456 |
+
const char sinstr[] PROGMEM = "INSTR";
|
457 |
+
const char sval[] PROGMEM = "VAL";
|
458 |
+
const char snetstat[] PROGMEM = "NETSTAT";
|
459 |
+
const char ssensor[] PROGMEM = "SENSOR";
|
460 |
+
const char swire[] PROGMEM = "WIRE";
|
461 |
+
const char ssleep[] PROGMEM = "SLEEP";
|
462 |
+
#endif
|
463 |
+
/* events and interrupts */
|
464 |
+
#ifdef HASTIMER
|
465 |
+
const char safter[] PROGMEM = "AFTER";
|
466 |
+
const char severy[] PROGMEM = "EVERY";
|
467 |
+
#endif
|
468 |
+
#ifdef HASEVENTS
|
469 |
+
const char sevent[] PROGMEM = "EVENT";
|
470 |
+
#endif
|
471 |
+
#ifdef HASSTRUCT
|
472 |
+
const char swhile[] PROGMEM = "WHILE";
|
473 |
+
const char swend[] PROGMEM = "WEND";
|
474 |
+
const char srepeat[] PROGMEM = "REPEAT";
|
475 |
+
const char suntil[] PROGMEM = "UNTIL";
|
476 |
+
const char sswitch[] PROGMEM = "SWITCH";
|
477 |
+
const char scase[] PROGMEM = "CASE";
|
478 |
+
const char sswend[] PROGMEM = "SWEND";
|
479 |
+
const char sdo[] PROGMEM = "DO";
|
480 |
+
const char sdend[] PROGMEM = "DEND";
|
481 |
+
#endif
|
482 |
+
|
483 |
+
|
484 |
+
/* zero terminated keyword storage */
|
485 |
+
const char* const keyword[] PROGMEM = {
|
486 |
+
sge, sle, sne, sprint, slet, sinput,
|
487 |
+
sgoto, sgosub, sreturn, sif, sfor, sto,
|
488 |
+
sstep, snext, sstop, slist, snew, srun,
|
489 |
+
sabs, srnd, ssize, srem,
|
490 |
+
#ifdef HASAPPLE1
|
491 |
+
snot, sand, sor, slen, ssgn, speek, sdim,
|
492 |
+
sclr, shimem, stab, sthen,
|
493 |
+
sbend, spoke,
|
494 |
+
#endif
|
495 |
+
#ifdef HASSTEFANSEXT
|
496 |
+
scont, ssqr, spow, smap, sdump, sbreak,
|
497 |
+
#endif
|
498 |
+
ssave, sload,
|
499 |
+
#ifdef HASSTEFANSEXT
|
500 |
+
sget, sput, sset, scls, slocate, selse,
|
501 |
+
#endif
|
502 |
+
#ifdef HASARDUINOIO
|
503 |
+
spinm, sdwrite, sdread, sawrite, saread,
|
504 |
+
sdelay, smillis, sazero, sled,
|
505 |
+
#endif
|
506 |
+
#ifdef HASTONE
|
507 |
+
stone,
|
508 |
+
#endif
|
509 |
+
#ifdef HASPULSE
|
510 |
+
spulse,
|
511 |
+
#endif
|
512 |
+
#ifdef HASFILEIO
|
513 |
+
scatalog, sdelete, sfopen, sfclose, sfdisk,
|
514 |
+
#endif
|
515 |
+
#ifdef HASSTEFANSEXT
|
516 |
+
susr, scall,
|
517 |
+
#endif
|
518 |
+
#ifdef HASFLOAT
|
519 |
+
ssin, scos, stan, satan, slog, sexp,
|
520 |
+
#endif
|
521 |
+
sint,
|
522 |
+
#ifdef HASGRAPH
|
523 |
+
scolor, splot, sline, scircle, srect,
|
524 |
+
sfcircle, sfrect,
|
525 |
+
#endif
|
526 |
+
#ifdef HASDARTMOUTH
|
527 |
+
sdata, sread, srestore, sdef, sfn, son,
|
528 |
+
#endif
|
529 |
+
#ifdef HASDARKARTS
|
530 |
+
smalloc, sfind, seval,
|
531 |
+
#endif
|
532 |
+
/* complex error handling */
|
533 |
+
#ifdef HASERRORHANDLING
|
534 |
+
serror,
|
535 |
+
#endif
|
536 |
+
#ifdef HASIOT
|
537 |
+
savail, sstr, sinstr, sval,
|
538 |
+
snetstat, ssensor, swire, ssleep,
|
539 |
+
#endif
|
540 |
+
#ifdef HASTIMER
|
541 |
+
safter, severy,
|
542 |
+
#endif
|
543 |
+
#ifdef HASEVENTS
|
544 |
+
sevent,
|
545 |
+
#endif
|
546 |
+
#ifdef HASSTRUCT
|
547 |
+
swhile, swend, srepeat, suntil, sswitch, scase, sswend,
|
548 |
+
sdo, sdend,
|
549 |
+
#endif
|
550 |
+
0
|
551 |
+
};
|
552 |
+
|
553 |
+
/* the zero terminated token dictonary needed for scalability */
|
554 |
+
const signed char tokens[] PROGMEM = {
|
555 |
+
GREATEREQUAL, LESSEREQUAL, NOTEQUAL, TPRINT, TLET,
|
556 |
+
TINPUT, TGOTO, TGOSUB, TRETURN, TIF, TFOR, TTO, TSTEP,
|
557 |
+
TNEXT, TSTOP, TLIST, TNEW, TRUN, TABS, TRND, TSIZE, TREM,
|
558 |
+
#ifdef HASAPPLE1
|
559 |
+
TNOT, TAND, TOR, TLEN, TSGN, TPEEK, TDIM, TCLR,
|
560 |
+
THIMEM, TTAB, TTHEN, TEND, TPOKE,
|
561 |
+
#endif
|
562 |
+
#ifdef HASSTEFANSEXT
|
563 |
+
TCONT, TSQR, TPOW, TMAP, TDUMP, TBREAK,
|
564 |
+
#endif
|
565 |
+
TSAVE, TLOAD,
|
566 |
+
#ifdef HASSTEFANSEXT
|
567 |
+
TGET, TPUT, TSET, TCLS, TLOCATE, TELSE,
|
568 |
+
#endif
|
569 |
+
#ifdef HASARDUINOIO
|
570 |
+
TPINM, TDWRITE, TDREAD, TAWRITE, TAREAD, TDELAY, TMILLIS,
|
571 |
+
TAZERO, TLED,
|
572 |
+
#endif
|
573 |
+
#ifdef HASTONE
|
574 |
+
TTONE,
|
575 |
+
#endif
|
576 |
+
#ifdef HASPULSE
|
577 |
+
TPULSE,
|
578 |
+
#endif
|
579 |
+
#ifdef HASFILEIO
|
580 |
+
TCATALOG, TDELETE, TOPEN, TCLOSE, TFDISK,
|
581 |
+
#endif
|
582 |
+
#ifdef HASSTEFANSEXT
|
583 |
+
TUSR, TCALL,
|
584 |
+
#endif
|
585 |
+
#ifdef HASFLOAT
|
586 |
+
TSIN, TCOS, TTAN, TATAN, TLOG, TEXP,
|
587 |
+
#endif
|
588 |
+
TINT,
|
589 |
+
#ifdef HASGRAPH
|
590 |
+
TCOLOR, TPLOT, TLINE, TCIRCLE, TRECT,
|
591 |
+
TFCIRCLE, TFRECT,
|
592 |
+
#endif
|
593 |
+
#ifdef HASDARTMOUTH
|
594 |
+
TDATA, TREAD, TRESTORE, TDEF, TFN, TON,
|
595 |
+
#endif
|
596 |
+
#ifdef HASDARKARTS
|
597 |
+
TMALLOC, TFIND, TEVAL,
|
598 |
+
#endif
|
599 |
+
#ifdef HASERRORHANDLING
|
600 |
+
TERROR,
|
601 |
+
#endif
|
602 |
+
#ifdef HASIOT
|
603 |
+
TAVAIL, TSTR, TINSTR, TVAL, TNETSTAT,
|
604 |
+
TSENSOR, TWIRE, TSLEEP,
|
605 |
+
#endif
|
606 |
+
#ifdef HASTIMER
|
607 |
+
TAFTER, TEVERY,
|
608 |
+
#endif
|
609 |
+
#ifdef HASEVENTS
|
610 |
+
TEVENT,
|
611 |
+
#endif
|
612 |
+
#ifdef HASSTRUCT
|
613 |
+
TWHILE, TWEND, TREPEAT, TUNTIL, TSWITCH, TCASE, TSWEND,
|
614 |
+
TDO, TDEND,
|
615 |
+
#endif
|
616 |
+
0
|
617 |
+
};
|
618 |
+
|
619 |
+
/*
|
620 |
+
* the message catalog
|
621 |
+
*/
|
622 |
+
#define MFILE 0
|
623 |
+
#define MPROMPT 1
|
624 |
+
#define MGREET 2
|
625 |
+
#define MLINE 3
|
626 |
+
#define MNUMBER 4
|
627 |
+
#define MVARIABLE 5
|
628 |
+
#define MARRAY 6
|
629 |
+
#define MSTRING 7
|
630 |
+
#define MSTRINGVAR 8
|
631 |
+
#define EGENERAL 9
|
632 |
+
#define EUNKNOWN 10
|
633 |
+
#define ENUMBER 11
|
634 |
+
#define EDIVIDE 12
|
635 |
+
#define ELINE 13
|
636 |
+
#define EOUTOFMEMORY 14
|
637 |
+
#define ESTACK 15
|
638 |
+
#define EORANGE 16
|
639 |
+
#define ESTRING 17
|
640 |
+
#define EVARIABLE 18
|
641 |
+
#define ELOOP 19
|
642 |
+
#define EFILE 20
|
643 |
+
#define EFUN 21
|
644 |
+
#define EARGS 22
|
645 |
+
#define EEEPROM 23
|
646 |
+
#define ESDCARD 24
|
647 |
+
|
648 |
+
const char mfile[] PROGMEM = "file.bas";
|
649 |
+
const char mprompt[] PROGMEM = "> ";
|
650 |
+
const char mgreet[] PROGMEM = "Stefan's Basic 1.4";
|
651 |
+
const char mline[] PROGMEM = "LINE";
|
652 |
+
const char mnumber[] PROGMEM = "NUMBER";
|
653 |
+
const char mvariable[] PROGMEM = "VARIABLE";
|
654 |
+
const char marray[] PROGMEM = "ARRAY";
|
655 |
+
const char mstring[] PROGMEM = "STRING";
|
656 |
+
const char mstringv[] PROGMEM = "STRINGVAR";
|
657 |
+
const char egeneral[] PROGMEM = "Error";
|
658 |
+
#ifdef HASERRORMSG
|
659 |
+
const char eunknown[] PROGMEM = "Syntax";
|
660 |
+
const char enumber[] PROGMEM = "Number";
|
661 |
+
const char edivide[] PROGMEM = "Div by 0";
|
662 |
+
const char eline[] PROGMEM = "Unknown Line";
|
663 |
+
const char emem[] PROGMEM = "Memory";
|
664 |
+
const char estack[] PROGMEM = "Stack";
|
665 |
+
const char erange[] PROGMEM = "Range";
|
666 |
+
const char estring[] PROGMEM = "String";
|
667 |
+
const char evariable[] PROGMEM = "Variable";
|
668 |
+
const char eloop[] PROGMEM = "Loop";
|
669 |
+
const char efile[] PROGMEM = "File";
|
670 |
+
const char efun[] PROGMEM = "Function";
|
671 |
+
const char eargs[] PROGMEM = "Args";
|
672 |
+
const char eeeprom[] PROGMEM = "EEPROM";
|
673 |
+
const char esdcard[] PROGMEM = "SD card";
|
674 |
+
#endif
|
675 |
+
|
676 |
+
const char* const message[] PROGMEM = {
|
677 |
+
mfile, mprompt, mgreet,
|
678 |
+
mline, mnumber, mvariable, marray,
|
679 |
+
mstring, mstringv,
|
680 |
+
egeneral
|
681 |
+
#ifdef HASERRORMSG
|
682 |
+
, eunknown, enumber, edivide, eline,
|
683 |
+
emem, estack, erange,
|
684 |
+
estring, evariable, eloop, efile, efun, eargs,
|
685 |
+
eeeprom, esdcard
|
686 |
+
#endif
|
687 |
+
};
|
688 |
+
|
689 |
+
/*
|
690 |
+
* code for variable numbers and addresses sizes
|
691 |
+
* the original code was 16 bit but can be extended here
|
692 |
+
* to arbitrary types
|
693 |
+
*
|
694 |
+
* number_t is the type for numerical work - either float or int
|
695 |
+
* wnumber_t is the type containing the largest printable integer,
|
696 |
+
* for float keep this int on 32 bit and long on 8 bit unless you
|
697 |
+
* want to use very long integers, like 64 or 128 bit types.
|
698 |
+
* address_t is an unsigned type adddressing memory, default 16bit
|
699 |
+
* mem_t is a SIGNED 8bit character type.
|
700 |
+
* index_t is a SIGNED minimum 16 bit integer type
|
701 |
+
*
|
702 |
+
* works with the tacit assumption that
|
703 |
+
* sizeof(number_t) >= sizeof(address_t)
|
704 |
+
* and that the entire memory is smaller than the positive
|
705 |
+
* part of number type (!!)
|
706 |
+
*
|
707 |
+
* we assume that float >= 4 bytes in the following
|
708 |
+
*
|
709 |
+
* maxnum: the maximum accurate(!) integer of a
|
710 |
+
* 32 bit float
|
711 |
+
* strindexsize: the index size of strings either
|
712 |
+
* 1 byte or 2 bytes - no other values supported
|
713 |
+
*/
|
714 |
+
#ifdef HASFLOAT
|
715 |
+
typedef float number_t;
|
716 |
+
const number_t maxnum=16777216;
|
717 |
+
typedef long wnumber_t;
|
718 |
+
#else
|
719 |
+
typedef int number_t;
|
720 |
+
typedef int wnumber_t;
|
721 |
+
const number_t maxnum=(number_t)~((number_t)1<<(sizeof(number_t)*8-1));
|
722 |
+
#endif
|
723 |
+
typedef unsigned short address_t; /* this type addresses memory */
|
724 |
+
const int numsize=sizeof(number_t);
|
725 |
+
const int addrsize=sizeof(address_t);
|
726 |
+
const int eheadersize=sizeof(address_t)+1;
|
727 |
+
const int strindexsize=2; /* default in the meantime, strings up to unsigned 16 bit length */
|
728 |
+
const address_t maxaddr=(address_t)(~0);
|
729 |
+
typedef signed char mem_t; /* a signed 8 bit type for the memory */
|
730 |
+
typedef int index_t; /* this type counts at least 16 bit */
|
731 |
+
#ifndef HASLONGTOKENS
|
732 |
+
typedef signed char token_t; /* the type of tokens, normally mem_t with a maximum of 127 commands and data types */
|
733 |
+
#else
|
734 |
+
typedef short token_t; /* token type extension, allows an extra of 127 commands and symbols */
|
735 |
+
#endif
|
736 |
+
|
737 |
+
/* this type maps numbers to bytes */
|
738 |
+
typedef struct {mem_t l; mem_t h;} twobytes_t;
|
739 |
+
typedef union { number_t i; address_t a; twobytes_t b; mem_t c[sizeof(number_t)]; } accu_t;
|
740 |
+
|
741 |
+
/* the memreader function type */
|
742 |
+
typedef mem_t (*memreader_t)(address_t);
|
743 |
+
|
744 |
+
/*
|
745 |
+
* system type identifiers
|
746 |
+
*/
|
747 |
+
|
748 |
+
#define SYSTYPE_UNKNOWN 0
|
749 |
+
#define SYSTYPE_AVR 1
|
750 |
+
#define SYSTYPE_ESP8266 2
|
751 |
+
#define SYSTYPE_ESP32 3
|
752 |
+
#define SYSTYPE_RP2040 4
|
753 |
+
#define SYSTYPE_SAM 5
|
754 |
+
#define SYSTYPE_XMC 6
|
755 |
+
#define SYSTYPE_SMT32 7
|
756 |
+
#define SYSTYPE_NRENESA 8
|
757 |
+
#define SYSTYPE_POSIX 32
|
758 |
+
#define SYSTYPE_MSDOS 33
|
759 |
+
#define SYSTYPE_MINGW 34
|
760 |
+
#define SYSTYPE_RASPPI 35
|
761 |
+
|
762 |
+
/*
|
763 |
+
* The basic interpreter is implemented as a stack machine
|
764 |
+
* with global variable for the interpreter state, the memory
|
765 |
+
* and the arithmetic during run time.
|
766 |
+
*/
|
767 |
+
|
768 |
+
/* the stack, all BASIC arithmetic is done here */
|
769 |
+
number_t stack[STACKSIZE];
|
770 |
+
address_t sp=0;
|
771 |
+
|
772 |
+
/* a small buffer to process string arguments, mostly used for Arduino PROGMEM */
|
773 |
+
char sbuffer[SBUFSIZE];
|
774 |
+
|
775 |
+
/* the input buffer, the lexer can tokenize this and run from it, bi is an index to this.
|
776 |
+
bi must be global as it is the program cursor in interactive mode */
|
777 |
+
char ibuffer[BUFSIZE] = "\0";
|
778 |
+
char *bi;
|
779 |
+
|
780 |
+
/* a static array of variables A-Z for the small systems that have no heap */
|
781 |
+
number_t vars[VARSIZE];
|
782 |
+
|
783 |
+
/* the BASIC working memory, either malloced or allocated as a global array */
|
784 |
+
#if MEMSIZE != 0
|
785 |
+
mem_t mem[MEMSIZE];
|
786 |
+
#else
|
787 |
+
mem_t* mem;
|
788 |
+
#endif
|
789 |
+
address_t himem, memsize;
|
790 |
+
|
791 |
+
/* the for stack - remembers the variable, indices, and optionally a type for stuctured BASIC */
|
792 |
+
struct forstackitem {mem_t varx; mem_t vary; address_t here; number_t to; number_t step;
|
793 |
+
#ifdef HASSTRUCT
|
794 |
+
mem_t type;
|
795 |
+
#endif
|
796 |
+
} forstack[FORDEPTH];
|
797 |
+
index_t forsp = 0;
|
798 |
+
|
799 |
+
/* the GOSUB stack remembers an address to jump to */
|
800 |
+
address_t gosubstack[GOSUBDEPTH];
|
801 |
+
index_t gosubsp = 0;
|
802 |
+
|
803 |
+
/* this variable stores the location in pushlocation() and poplocation(), used to rewind the program cursor */
|
804 |
+
address_t slocation;
|
805 |
+
|
806 |
+
/* arithmetic accumulators - used by many statements, y may be obsolete in future*/
|
807 |
+
number_t x, y;
|
808 |
+
|
809 |
+
/* the names of a variable and small integer accumulator */
|
810 |
+
mem_t xc, yc;
|
811 |
+
|
812 |
+
/* an address accumulator, used a lot in string operations */
|
813 |
+
address_t ax;
|
814 |
+
|
815 |
+
/* z is another accumulator used to convert numbers and addressed to bytes and vice versa */
|
816 |
+
/* this union is used to store larger objects into byte oriented memory */
|
817 |
+
accu_t z;
|
818 |
+
|
819 |
+
/* string index registers */
|
820 |
+
char *ir, *ir2;
|
821 |
+
|
822 |
+
/* the active token */
|
823 |
+
token_t token;
|
824 |
+
|
825 |
+
/* the curent error, can be a token, hance token type */
|
826 |
+
token_t er;
|
827 |
+
|
828 |
+
/* a trapable error */
|
829 |
+
mem_t ert;
|
830 |
+
|
831 |
+
/* the interpreter state, interactive, run or run from EEPROM */
|
832 |
+
mem_t st;
|
833 |
+
|
834 |
+
/* the current program location or "cursor" */
|
835 |
+
address_t here;
|
836 |
+
|
837 |
+
/* the topmost byte of a program in memory, beginning of free BASIC RAM */
|
838 |
+
address_t top;
|
839 |
+
|
840 |
+
/* the number of variables on the heap */
|
841 |
+
address_t nvars = 0;
|
842 |
+
|
843 |
+
/* used to format output with # */
|
844 |
+
mem_t form = 0;
|
845 |
+
|
846 |
+
/* counts the outputed characters on streams 0-3, used to emulate a real tab */
|
847 |
+
#ifdef HASMSTAB
|
848 |
+
mem_t charcount[3]; /* devices 1-4 support tabing */
|
849 |
+
mem_t reltab = 0;
|
850 |
+
#endif
|
851 |
+
|
852 |
+
/* the lower limit of the array is one by default, can be a variable */
|
853 |
+
#ifdef HASARRAYLIMIT
|
854 |
+
address_t arraylimit = 1;
|
855 |
+
#else
|
856 |
+
const address_t arraylimit = 1;
|
857 |
+
#endif
|
858 |
+
|
859 |
+
/* the number of arguments parsed from a command */
|
860 |
+
mem_t args;
|
861 |
+
|
862 |
+
/* the random number seed, this is unsigned hence address_t */
|
863 |
+
#ifndef HASFLOAT
|
864 |
+
address_t rd;
|
865 |
+
#else
|
866 |
+
unsigned long rd;
|
867 |
+
#endif
|
868 |
+
|
869 |
+
/* output and input channels, used to direct output to various devices */
|
870 |
+
mem_t id;
|
871 |
+
mem_t od;
|
872 |
+
|
873 |
+
/* default IO - not constant, can be changed at runtime through a user call */
|
874 |
+
mem_t idd = ISERIAL;
|
875 |
+
mem_t odd = OSERIAL;
|
876 |
+
|
877 |
+
/* the runtime debuglevel */
|
878 |
+
mem_t debuglevel = 0;
|
879 |
+
|
880 |
+
/* DATA pointer, where is the current READ statement */
|
881 |
+
#ifdef HASDARTMOUTH
|
882 |
+
address_t data = 0;
|
883 |
+
address_t datarc = 1;
|
884 |
+
#endif
|
885 |
+
|
886 |
+
/*
|
887 |
+
* process command line arguments in the POSIX world
|
888 |
+
* bnointafterrun is a flag to remember if called as command
|
889 |
+
* line argument, in this case we don't return to interactive
|
890 |
+
*/
|
891 |
+
#ifndef ARDUINO
|
892 |
+
int bargc;
|
893 |
+
char** bargv;
|
894 |
+
mem_t bnointafterrun = 0;
|
895 |
+
#endif
|
896 |
+
|
897 |
+
/*
|
898 |
+
* Yield counter, we count when we did yield the last time
|
899 |
+
* lastyield controlls the client loops of network functions
|
900 |
+
* like mqtt, scanned keyboard, and USB.
|
901 |
+
*
|
902 |
+
* lastlongyield controls longterm functions like DHCP lease
|
903 |
+
* renewal in Ethernet
|
904 |
+
*
|
905 |
+
* there variables are only needed if the platform has background
|
906 |
+
* tasks
|
907 |
+
*/
|
908 |
+
long lastyield=0;
|
909 |
+
long lastlongyield=0;
|
910 |
+
|
911 |
+
/* formaters lastouttoken and spaceafterkeyword to make a nice LIST */
|
912 |
+
mem_t lastouttoken;
|
913 |
+
mem_t spaceafterkeyword;
|
914 |
+
mem_t outliteral = 0;
|
915 |
+
mem_t lexliteral = 0;
|
916 |
+
|
917 |
+
/*
|
918 |
+
* the cache for the heap search - helps the string code
|
919 |
+
* the last found object on the heap is remembered. This is needed
|
920 |
+
* because the string code sometime searches the heap twice during the
|
921 |
+
* same operation.
|
922 |
+
*/
|
923 |
+
#ifdef HASAPPLE1
|
924 |
+
mem_t bfindc, bfindd, bfindt;
|
925 |
+
address_t bfinda, bfindz;
|
926 |
+
#endif
|
927 |
+
|
928 |
+
/*
|
929 |
+
* a variable for some string operations
|
930 |
+
*/
|
931 |
+
int vlength;
|
932 |
+
|
933 |
+
/* the timer code - very simple needs to to to a struct */
|
934 |
+
/* timer type */
|
935 |
+
typedef struct {
|
936 |
+
mem_t enabled;
|
937 |
+
unsigned long last;
|
938 |
+
unsigned long interval;
|
939 |
+
mem_t type;
|
940 |
+
address_t linenumber;
|
941 |
+
} btimer_t;
|
942 |
+
|
943 |
+
#ifdef HASTIMER
|
944 |
+
btimer_t after_timer = {0, 0, 0, 0, 0};
|
945 |
+
btimer_t every_timer = {0, 0, 0, 0, 0};
|
946 |
+
#endif
|
947 |
+
|
948 |
+
/* the event code */
|
949 |
+
#ifdef HASEVENTS
|
950 |
+
|
951 |
+
#define EVENTLISTSIZE 4
|
952 |
+
|
953 |
+
/* event type */
|
954 |
+
typedef struct {
|
955 |
+
mem_t enabled;
|
956 |
+
mem_t pin;
|
957 |
+
mem_t mode;
|
958 |
+
mem_t type;
|
959 |
+
address_t linenumber;
|
960 |
+
mem_t active;
|
961 |
+
} bevent_t;
|
962 |
+
|
963 |
+
/* the event list */
|
964 |
+
int nevents = 0;
|
965 |
+
int ievent = 0;
|
966 |
+
static mem_t events_enabled = 1;
|
967 |
+
static volatile bevent_t eventlist[EVENTLISTSIZE];
|
968 |
+
|
969 |
+
/* the extension of the GOSUB stack */
|
970 |
+
static mem_t gosubarg[GOSUBDEPTH];
|
971 |
+
|
972 |
+
/* handle the event list */
|
973 |
+
mem_t addevent(mem_t, mem_t, mem_t, address_t);
|
974 |
+
void deleteevent(mem_t);
|
975 |
+
volatile bevent_t* findevent(mem_t);
|
976 |
+
mem_t eventindex(mem_t);
|
977 |
+
#endif
|
978 |
+
|
979 |
+
#ifdef HASERRORHANDLING
|
980 |
+
/* the error handler type, very simple for now */
|
981 |
+
typedef struct {
|
982 |
+
mem_t type;
|
983 |
+
address_t linenumber;
|
984 |
+
} berrorh_t;
|
985 |
+
|
986 |
+
berrorh_t berrorh = {0 , 0};
|
987 |
+
mem_t erh = 0;
|
988 |
+
#endif
|
989 |
+
|
990 |
+
/* the string for real time clocks */
|
991 |
+
char rtcstring[20] = { 0 };
|
992 |
+
|
993 |
+
/* the units pulse operates on, in microseconds*/
|
994 |
+
short bpulseunit = 10;
|
995 |
+
|
996 |
+
/* only needed for POSIXNONBLOCKING */
|
997 |
+
mem_t breakcondition = 0;
|
998 |
+
|
999 |
+
/*
|
1000 |
+
* Function prototypes, ordered by layers
|
1001 |
+
* HAL - hardware abstraction
|
1002 |
+
* Layer 0 - memory and I/O
|
1003 |
+
* Layer 1 - Program storage and control
|
1004 |
+
* Layer 2 - Where stuff happens
|
1005 |
+
*/
|
1006 |
+
|
1007 |
+
/*
|
1008 |
+
* HAL - see hardware-*.h
|
1009 |
+
* This is the hardware abstraction layer of the BASIC
|
1010 |
+
* interpreter
|
1011 |
+
*/
|
1012 |
+
|
1013 |
+
/* setup codes */
|
1014 |
+
void timeinit();
|
1015 |
+
void wiringbegin();
|
1016 |
+
|
1017 |
+
/* low level mem and hardware features */
|
1018 |
+
long freeRam();
|
1019 |
+
long freememorysize();
|
1020 |
+
void restartsystem();
|
1021 |
+
void activatesleep(long t);
|
1022 |
+
|
1023 |
+
/* start the spi bus */
|
1024 |
+
void spibegin();
|
1025 |
+
|
1026 |
+
/*
|
1027 |
+
* the hardware interface display driver functions, need to be
|
1028 |
+
* implemented for the display driver to work
|
1029 |
+
* dspupdate() only for display like Epapers
|
1030 |
+
*/
|
1031 |
+
void dspbegin();
|
1032 |
+
void dspprintchar(char, mem_t, mem_t);
|
1033 |
+
void dspclear();
|
1034 |
+
void dspupdate();
|
1035 |
+
|
1036 |
+
/* keyboard code */
|
1037 |
+
void kbdbegin();
|
1038 |
+
int kbdstat(char);
|
1039 |
+
char kbdavailable();
|
1040 |
+
char kbdread();
|
1041 |
+
char kbdcheckch();
|
1042 |
+
|
1043 |
+
/* graphics functions */
|
1044 |
+
void rgbcolor(int, int, int);
|
1045 |
+
void vgacolor(short c);
|
1046 |
+
void vgascale(int*, int*);
|
1047 |
+
void plot(int, int);
|
1048 |
+
void line(int, int, int, int);
|
1049 |
+
void rect(int, int, int, int);
|
1050 |
+
void frect(int, int, int, int);
|
1051 |
+
void circle(int, int, int);
|
1052 |
+
void fcircle(int, int, int);
|
1053 |
+
|
1054 |
+
/* text output to a VGA display */
|
1055 |
+
void vgabegin();
|
1056 |
+
int vgastat(char);
|
1057 |
+
void vgawrite(char);
|
1058 |
+
|
1059 |
+
/* generic display code */
|
1060 |
+
void dspwrite(char);
|
1061 |
+
void dspbegin();
|
1062 |
+
int dspstat(char);
|
1063 |
+
char dspwaitonscroll();
|
1064 |
+
char dspactive();
|
1065 |
+
void dspsetupdatemode(char);
|
1066 |
+
char dspgetupdatemode();
|
1067 |
+
void dspgraphupdate();
|
1068 |
+
void dspsetscrollmode(char, short);
|
1069 |
+
void dspsetcursor(short, short);
|
1070 |
+
void dspbufferclear();
|
1071 |
+
void dspscroll(mem_t, mem_t);
|
1072 |
+
void dspreversescroll(mem_t);
|
1073 |
+
void dspvt52(char *);
|
1074 |
+
|
1075 |
+
/* real time clock */
|
1076 |
+
char* rtcmkstr();
|
1077 |
+
void rtcset(uint8_t, short);
|
1078 |
+
short rtcget(short);
|
1079 |
+
|
1080 |
+
/* network and mqtt functions */
|
1081 |
+
void netbegin();
|
1082 |
+
char netconnected();
|
1083 |
+
void mqttsetname();
|
1084 |
+
void mqttbegin();
|
1085 |
+
int mqttstat(char);
|
1086 |
+
int mqttstate();
|
1087 |
+
void mqttsubscribe(char*);
|
1088 |
+
void mqttsettopic(char*);
|
1089 |
+
void mqttouts(char *, short);
|
1090 |
+
void mqttins(char *, short);
|
1091 |
+
char mqttinch();
|
1092 |
+
|
1093 |
+
/* low level EEPROM handling */
|
1094 |
+
void ebegin();
|
1095 |
+
void eflush();
|
1096 |
+
address_t elength();
|
1097 |
+
mem_t eread(address_t);
|
1098 |
+
void eupdate(address_t, mem_t);
|
1099 |
+
|
1100 |
+
/* arduino io functions */
|
1101 |
+
void aread();
|
1102 |
+
void dread();
|
1103 |
+
void awrite(address_t, address_t);
|
1104 |
+
void dwrite(address_t, address_t);
|
1105 |
+
void pinm(address_t, address_t);
|
1106 |
+
void bmillis();
|
1107 |
+
void bpulsein();
|
1108 |
+
void xpulse();
|
1109 |
+
void bpulseout(short);
|
1110 |
+
void btone(short);
|
1111 |
+
|
1112 |
+
/* timing control for ESP and network */
|
1113 |
+
void byield();
|
1114 |
+
void bdelay(unsigned long);
|
1115 |
+
void fastticker();
|
1116 |
+
void yieldfunction();
|
1117 |
+
void longyieldfunction();
|
1118 |
+
|
1119 |
+
/* the file interface */
|
1120 |
+
char* mkfilename(const char*);
|
1121 |
+
const char* rmrootfsprefix(const char*);
|
1122 |
+
void fsbegin(char);
|
1123 |
+
int fsstat(char);
|
1124 |
+
void filewrite(char);
|
1125 |
+
char fileread();
|
1126 |
+
char ifileopen(const char*);
|
1127 |
+
void ifileclose();
|
1128 |
+
char ofileopen(char*, const char*);
|
1129 |
+
void ofileclose();
|
1130 |
+
int fileavailable();
|
1131 |
+
void rootopen();
|
1132 |
+
int rootnextfile();
|
1133 |
+
int rootisfile();
|
1134 |
+
const char* rootfilename();
|
1135 |
+
long rootfilesize();
|
1136 |
+
void rootfileclose();
|
1137 |
+
void rootclose();
|
1138 |
+
void removefile(char*);
|
1139 |
+
void formatdisk(short);
|
1140 |
+
|
1141 |
+
/* low level serial code */
|
1142 |
+
void picogetchar(char);
|
1143 |
+
void picowrite(char);
|
1144 |
+
void picobegin(unsigned long);
|
1145 |
+
void picoins(char, short);
|
1146 |
+
void serialbegin();
|
1147 |
+
int serialstat(char);
|
1148 |
+
char serialread();
|
1149 |
+
void serialwrite(char);
|
1150 |
+
short serialcheckch();
|
1151 |
+
short serialavailable();
|
1152 |
+
void serialflush();
|
1153 |
+
void consins(char*, short);
|
1154 |
+
void prtbegin();
|
1155 |
+
int prtstat(char);
|
1156 |
+
void prtset(int);
|
1157 |
+
char prtopen(char *, int);
|
1158 |
+
void prtclose();
|
1159 |
+
char prtread();
|
1160 |
+
void prtwrite(char);
|
1161 |
+
short prtcheckch();
|
1162 |
+
short prtavailable();
|
1163 |
+
|
1164 |
+
/* generic wire access */
|
1165 |
+
void wirebegin();
|
1166 |
+
int wirestat(char);
|
1167 |
+
void wireopen(char, char);
|
1168 |
+
void wireins(char*, uint8_t);
|
1169 |
+
void wireouts(char*, uint8_t);
|
1170 |
+
short wireavailable();
|
1171 |
+
short wirereadbyte(short);
|
1172 |
+
void wirewritebyte(short, short);
|
1173 |
+
|
1174 |
+
/* RF24 radio input */
|
1175 |
+
int radiostat(char);
|
1176 |
+
void radioset(int);
|
1177 |
+
#ifdef ARDUINO
|
1178 |
+
uint64_t pipeaddr(char*);
|
1179 |
+
#else
|
1180 |
+
long pipeaddr(char*);
|
1181 |
+
#endif
|
1182 |
+
void iradioopen(char*);
|
1183 |
+
void oradioopen(char*);
|
1184 |
+
void radioins(char*, short);
|
1185 |
+
void radioouts(char* , short);
|
1186 |
+
short radioavailable();
|
1187 |
+
|
1188 |
+
/* sensor control */
|
1189 |
+
void sensorbegin();
|
1190 |
+
number_t sensorread(short, short);
|
1191 |
+
|
1192 |
+
/* SPI RAM code */
|
1193 |
+
address_t spirambegin();
|
1194 |
+
void spiramrawwrite(address_t, mem_t);
|
1195 |
+
mem_t spiramrawread(address_t );
|
1196 |
+
|
1197 |
+
/*
|
1198 |
+
* Layer 0 functions - I/O and memory management
|
1199 |
+
*/
|
1200 |
+
|
1201 |
+
/* make room for BASIC */
|
1202 |
+
address_t ballocmem();
|
1203 |
+
|
1204 |
+
/* handle files im EEPROM */
|
1205 |
+
void eload();
|
1206 |
+
void esave();
|
1207 |
+
char autorun();
|
1208 |
+
|
1209 |
+
/* the variable heap from Apple 1 BASIC */
|
1210 |
+
address_t bmalloc(mem_t, mem_t, mem_t, address_t);
|
1211 |
+
address_t bfind(mem_t, mem_t, mem_t);
|
1212 |
+
address_t bfree(mem_t, mem_t, mem_t);
|
1213 |
+
address_t blength (mem_t, mem_t, mem_t);
|
1214 |
+
|
1215 |
+
/* normal variables of number_t */
|
1216 |
+
number_t getvar(mem_t, mem_t);
|
1217 |
+
void setvar(mem_t, mem_t, number_t);
|
1218 |
+
void clrvars();
|
1219 |
+
|
1220 |
+
/* low level memory access packing n*8bit bit into n 8 bit objects
|
1221 |
+
e* is for Arduino EEPROM */
|
1222 |
+
void getnumber(address_t, mem_t);
|
1223 |
+
void setnumber(address_t, mem_t);
|
1224 |
+
void egetnumber(address_t, mem_t);
|
1225 |
+
void esetnumber(address_t, mem_t);
|
1226 |
+
void pgetnumber(address_t, mem_t);
|
1227 |
+
|
1228 |
+
/* array and string handling */
|
1229 |
+
/* the multidim extension is experimental, here only 2 array dimensions implemented as test */
|
1230 |
+
address_t createarray(mem_t, mem_t, address_t, address_t);
|
1231 |
+
void array(mem_t, mem_t, mem_t, address_t, address_t, number_t*);
|
1232 |
+
address_t createstring(char, char, address_t, address_t);
|
1233 |
+
char* getstring(char, char, address_t, address_t);
|
1234 |
+
number_t arraydim(char, char);
|
1235 |
+
address_t stringdim(char, char);
|
1236 |
+
address_t lenstring(char, char, address_t);
|
1237 |
+
void setstringlength(char, char, address_t, address_t);
|
1238 |
+
void setstring(char, char, address_t, char *, address_t, address_t);
|
1239 |
+
|
1240 |
+
/* the user defined extension functions */
|
1241 |
+
number_t getusrvar();
|
1242 |
+
void setusrvar(number_t);
|
1243 |
+
number_t getusrarray(address_t);
|
1244 |
+
void setusrarray(address_t, number_t);
|
1245 |
+
void makeusrstring();
|
1246 |
+
number_t usrfunction(address_t, number_t);
|
1247 |
+
void usrcall(address_t);
|
1248 |
+
|
1249 |
+
/* get keywords and tokens from PROGMEM */
|
1250 |
+
char* getkeyword(unsigned short);
|
1251 |
+
char* getmessage(char);
|
1252 |
+
signed char gettokenvalue(char);
|
1253 |
+
void printmessage(char);
|
1254 |
+
|
1255 |
+
/* error handling */
|
1256 |
+
void error(token_t);
|
1257 |
+
void reseterror();
|
1258 |
+
void debugtoken();
|
1259 |
+
void bdebug(const char*);
|
1260 |
+
|
1261 |
+
/* the arithemtic stack */
|
1262 |
+
void push(number_t);
|
1263 |
+
number_t pop();
|
1264 |
+
address_t popaddress();
|
1265 |
+
void drop();
|
1266 |
+
void clearst();
|
1267 |
+
|
1268 |
+
/* READ DATA handling */
|
1269 |
+
void clrdata();
|
1270 |
+
|
1271 |
+
/* FOR NEXT GOSUB stacks */
|
1272 |
+
void pushforstack();
|
1273 |
+
void popforstack();
|
1274 |
+
void dropforstack();
|
1275 |
+
void clrforstack();
|
1276 |
+
void pushgosubstack(mem_t);
|
1277 |
+
void popgosubstack();
|
1278 |
+
void dropgosubstack();
|
1279 |
+
void clrgosubstack();
|
1280 |
+
|
1281 |
+
/* general I/O initialisation */
|
1282 |
+
void ioinit();
|
1283 |
+
void iodefaults();
|
1284 |
+
|
1285 |
+
/* signal handling */
|
1286 |
+
void signalon();
|
1287 |
+
void signaloff();
|
1288 |
+
void signalhandler(int);
|
1289 |
+
|
1290 |
+
/* character and string I/O functions */
|
1291 |
+
/* we live in world where char may be signed or unsigned and keep it
|
1292 |
+
that way on the lowest level, hence this function, fully defined here,
|
1293 |
+
mostly inlined anyway*/
|
1294 |
+
int cheof(int c) { if ((c == -1) || (c == 255)) return 1; else return 0; }
|
1295 |
+
/* input */
|
1296 |
+
char inch();
|
1297 |
+
char checkch();
|
1298 |
+
short availch();
|
1299 |
+
void inb(char*, index_t);
|
1300 |
+
void ins(char*, address_t);
|
1301 |
+
|
1302 |
+
/* output */
|
1303 |
+
void outch(char);
|
1304 |
+
void outcr();
|
1305 |
+
void outspc();
|
1306 |
+
void outs(char*, address_t);
|
1307 |
+
void outsc(const char*);
|
1308 |
+
void outscf(const char *, index_t);
|
1309 |
+
|
1310 |
+
/* I/O of number_t - floats and integers */
|
1311 |
+
address_t parsenumber(char*, number_t*);
|
1312 |
+
address_t parsenumber2(char*, number_t*);
|
1313 |
+
address_t writenumber(char*, wnumber_t);
|
1314 |
+
address_t writenumber2(char*, number_t);
|
1315 |
+
address_t tinydtostrf(number_t, index_t, char*);
|
1316 |
+
char innumber(number_t*);
|
1317 |
+
void outnumber(number_t);
|
1318 |
+
|
1319 |
+
/*
|
1320 |
+
* Layer 1 functions, provide data and do the heavy lifting
|
1321 |
+
* for layer 2 including lexical analysis, storing programs
|
1322 |
+
* and expression evaluation
|
1323 |
+
*/
|
1324 |
+
|
1325 |
+
/* lexical analysis */
|
1326 |
+
void whitespaces();
|
1327 |
+
void nexttoken();
|
1328 |
+
|
1329 |
+
/* storing and retrieving programs */
|
1330 |
+
char nomemory(number_t);
|
1331 |
+
void storetoken();
|
1332 |
+
mem_t memread(address_t);
|
1333 |
+
mem_t memread2(address_t);
|
1334 |
+
void memwrite2(address_t, mem_t);
|
1335 |
+
void gettoken();
|
1336 |
+
void firstline();
|
1337 |
+
void nextline();
|
1338 |
+
|
1339 |
+
void clrlinecache();
|
1340 |
+
void addlinecache(address_t, address_t);
|
1341 |
+
address_t findinlinecache(address_t);
|
1342 |
+
void findline(address_t);
|
1343 |
+
address_t myline(address_t);
|
1344 |
+
void moveblock(address_t, address_t, address_t);
|
1345 |
+
void zeroblock(address_t, address_t);
|
1346 |
+
void diag();
|
1347 |
+
void storeline();
|
1348 |
+
|
1349 |
+
/* read arguments from the token stream and process them */
|
1350 |
+
char termsymbol();
|
1351 |
+
char expect(token_t, mem_t);
|
1352 |
+
char expectexpr();
|
1353 |
+
void parsearguments();
|
1354 |
+
void parsenarguments(char);
|
1355 |
+
void parsesubscripts();
|
1356 |
+
void parsefunction(void (*)(), short);
|
1357 |
+
void parseoperator(void (*)());
|
1358 |
+
void parsesubstring();
|
1359 |
+
|
1360 |
+
/* mathematics and other functions for int and float */
|
1361 |
+
void xabs();
|
1362 |
+
void xsgn();
|
1363 |
+
void xpeek();
|
1364 |
+
void xmap();
|
1365 |
+
void rnd();
|
1366 |
+
void sqr();
|
1367 |
+
void xpow();
|
1368 |
+
number_t bpow(number_t, number_t);
|
1369 |
+
|
1370 |
+
/* string values and string evaluation */
|
1371 |
+
char stringvalue();
|
1372 |
+
void streval();
|
1373 |
+
|
1374 |
+
/* floating point functions */
|
1375 |
+
void xsin();
|
1376 |
+
void xcos();
|
1377 |
+
void xtan();
|
1378 |
+
void xatan();
|
1379 |
+
void xlog();
|
1380 |
+
void xexp();
|
1381 |
+
void xint();
|
1382 |
+
|
1383 |
+
/* expression evaluation */
|
1384 |
+
void factor();
|
1385 |
+
void term();
|
1386 |
+
void addexpression();
|
1387 |
+
void compexpression();
|
1388 |
+
void notexpression();
|
1389 |
+
void andexpression();
|
1390 |
+
void expression();
|
1391 |
+
|
1392 |
+
/*
|
1393 |
+
* Layer 2 - statements and functions
|
1394 |
+
* use the global variables
|
1395 |
+
*/
|
1396 |
+
|
1397 |
+
/* basic commands of the core language set */
|
1398 |
+
void xprint();
|
1399 |
+
void lefthandside(address_t*, address_t*, address_t*, mem_t*);
|
1400 |
+
void assignnumber(signed char, char, char, address_t, address_t, char);
|
1401 |
+
void assignment();
|
1402 |
+
void showprompt();
|
1403 |
+
void xinput();
|
1404 |
+
void xgoto();
|
1405 |
+
void xreturn();
|
1406 |
+
void xif();
|
1407 |
+
|
1408 |
+
/* FOR NEXT loops */
|
1409 |
+
void findnextcmd();
|
1410 |
+
void findbraket(token_t, token_t);
|
1411 |
+
void xfor();
|
1412 |
+
void xbreak();
|
1413 |
+
void xcont();
|
1414 |
+
void xnext();
|
1415 |
+
|
1416 |
+
/* WHILE WEND*/
|
1417 |
+
void xwhile();
|
1418 |
+
void xwend();
|
1419 |
+
|
1420 |
+
/* REPEAT UNTIL */
|
1421 |
+
void xrepeat();
|
1422 |
+
void xuntil();
|
1423 |
+
|
1424 |
+
/* control commands and misc */
|
1425 |
+
void outputtoken();
|
1426 |
+
void xlist();
|
1427 |
+
void xrun();
|
1428 |
+
void xnew();
|
1429 |
+
void xrem();
|
1430 |
+
void xclr();
|
1431 |
+
void xdim();
|
1432 |
+
void xpoke();
|
1433 |
+
void xtab();
|
1434 |
+
void xdump();
|
1435 |
+
void dumpmem(address_t, address_t, char);
|
1436 |
+
void xlocate();
|
1437 |
+
|
1438 |
+
/* file access and other i/o */
|
1439 |
+
void stringtobuffer(char*);
|
1440 |
+
void getfilename(char*, char);
|
1441 |
+
void xsave();
|
1442 |
+
void xload(const char*);
|
1443 |
+
void xget();
|
1444 |
+
void xput();
|
1445 |
+
void xset();
|
1446 |
+
void xnetstat();
|
1447 |
+
|
1448 |
+
/* Arduino IO control interface */
|
1449 |
+
void xdwrite();
|
1450 |
+
void xawrite();
|
1451 |
+
void xpinm();
|
1452 |
+
void xdelay();
|
1453 |
+
void xtone();
|
1454 |
+
|
1455 |
+
/* graphics commands */
|
1456 |
+
void xcolor();
|
1457 |
+
void xplot();
|
1458 |
+
void xline();
|
1459 |
+
void xrect();
|
1460 |
+
void xcircle();
|
1461 |
+
void xfrect();
|
1462 |
+
void xfcircle();
|
1463 |
+
|
1464 |
+
/* the darkarts */
|
1465 |
+
void xmalloc();
|
1466 |
+
void xfind();
|
1467 |
+
void xeval();
|
1468 |
+
|
1469 |
+
/* IoT commands */
|
1470 |
+
void xassign();
|
1471 |
+
void xavail();
|
1472 |
+
void xfsensor();
|
1473 |
+
void xsleep();
|
1474 |
+
void xwire();
|
1475 |
+
void xfwire();
|
1476 |
+
|
1477 |
+
/* timers */
|
1478 |
+
void xafter();
|
1479 |
+
void xevent();
|
1480 |
+
|
1481 |
+
/* File I/O functions */
|
1482 |
+
char streq(const char*, char*);
|
1483 |
+
void xcatalog();
|
1484 |
+
void xdelete();
|
1485 |
+
void xopen();
|
1486 |
+
void xfopen();
|
1487 |
+
void xclose();
|
1488 |
+
void xfdisk();
|
1489 |
+
|
1490 |
+
/* low level access functions */
|
1491 |
+
void xcall();
|
1492 |
+
void xusr();
|
1493 |
+
|
1494 |
+
/* the dartmouth stuff */
|
1495 |
+
void xdata();
|
1496 |
+
void nextdatarecord();
|
1497 |
+
void xread();
|
1498 |
+
void xrestore();
|
1499 |
+
void xdef();
|
1500 |
+
void xfn();
|
1501 |
+
void xon();
|
1502 |
+
|
1503 |
+
/* timers and interrupts */
|
1504 |
+
void xtimer();
|
1505 |
+
void resettimer(btimer_t*);
|
1506 |
+
|
1507 |
+
/* structured BASIC extensions */
|
1508 |
+
void xwhile();
|
1509 |
+
void xwend();
|
1510 |
+
void xrepeat();
|
1511 |
+
void xuntil();
|
1512 |
+
void xswitch();
|
1513 |
+
void xcase();
|
1514 |
+
void xendswitch();
|
1515 |
+
|
1516 |
+
/* the emulation of tone using the byield loop */
|
1517 |
+
void toggletone();
|
1518 |
+
void playtone(int, int, int);
|
1519 |
+
|
1520 |
+
/* the statement loop */
|
1521 |
+
void statement();
|
1522 |
+
|
1523 |
+
/* the extension functions */
|
1524 |
+
void bsetup();
|
1525 |
+
void bloop();
|
1526 |
+
|
data/Basic1/TinybasicArduino/hardware-arduino.h
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic1/TinybasicArduino/wifisettings.h
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const char* ssid = "daheim-iot";
|
2 |
+
const char* password = "xacobeo7";
|
3 |
+
const char* mqtt_server = "test.mosquitto.org";
|
4 |
+
const short mqtt_port = 1883;
|
5 |
+
byte mac[] = {0xDE, 0xAD, 0xBE, 0xE9, 0xE9, 0xE9};
|
data/Basic1/basic.c
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic1/basic.h
ADDED
@@ -0,0 +1,1526 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*
|
3 |
+
* $Id: basic.h,v 1.13 2023/07/16 14:17:08 stefan Exp stefan $
|
4 |
+
*
|
5 |
+
* Stefan's basic interpreter
|
6 |
+
*
|
7 |
+
* Playing around with frugal programming. See the licence file on
|
8 |
+
* https://github.com/slviajero/tinybasic for copyright/left.
|
9 |
+
* (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
|
10 |
+
*
|
11 |
+
* Author: Stefan Lenz, [email protected]
|
12 |
+
*
|
13 |
+
* basic.h are the core defintions and function protypes
|
14 |
+
*
|
15 |
+
*/
|
16 |
+
|
17 |
+
/*
|
18 |
+
* if the PROGMEM macro is define we compile on the Arduino IDE
|
19 |
+
* we undef all hardware settings otherwise a little odd
|
20 |
+
*/
|
21 |
+
#ifdef ARDUINO_ARCH_MBED
|
22 |
+
#define PROGMEM
|
23 |
+
#endif
|
24 |
+
|
25 |
+
#ifdef PROGMEM
|
26 |
+
#define ARDUINOPROGMEM
|
27 |
+
#else
|
28 |
+
#undef ARDUINO
|
29 |
+
#undef ARDUINOSD
|
30 |
+
#undef ARDUINORF24
|
31 |
+
#undef ARDUINORTC
|
32 |
+
#undef ARDUINOEEPROM
|
33 |
+
#undef ARDUINOEEPROMI2C
|
34 |
+
#undef ARDUINOWIRE
|
35 |
+
#endif
|
36 |
+
|
37 |
+
/*
|
38 |
+
* MSDOS, Mac, Linux and Windows
|
39 |
+
*/
|
40 |
+
#ifndef ARDUINO
|
41 |
+
typedef unsigned char uint8_t;
|
42 |
+
#define PROGMEM
|
43 |
+
#include <stdio.h>
|
44 |
+
#include <stdlib.h>
|
45 |
+
#ifdef HASFLOAT
|
46 |
+
#include <math.h>
|
47 |
+
#include <float.h>
|
48 |
+
#endif
|
49 |
+
#include <time.h>
|
50 |
+
#include <sys/types.h>
|
51 |
+
#include <sys/timeb.h>
|
52 |
+
#ifndef MSDOS
|
53 |
+
#include <dirent.h>
|
54 |
+
#include <unistd.h>
|
55 |
+
#else
|
56 |
+
#include <dir.h>
|
57 |
+
#include <dos.h>
|
58 |
+
#endif
|
59 |
+
#ifdef MINGW
|
60 |
+
#include <windows.h>
|
61 |
+
#endif
|
62 |
+
#endif
|
63 |
+
|
64 |
+
|
65 |
+
#if defined(ARDUINO_ARCH_AVR)
|
66 |
+
/* the small memory model with shallow stacks and small buffers */
|
67 |
+
#define BUFSIZE 80
|
68 |
+
#define STACKSIZE 15
|
69 |
+
#define GOSUBDEPTH 4
|
70 |
+
#define FORDEPTH 4
|
71 |
+
#define LINECACHESIZE 4
|
72 |
+
#else
|
73 |
+
/* the for larger microcontrollers */
|
74 |
+
#ifdef ARDUINO
|
75 |
+
#define BUFSIZE 128
|
76 |
+
#define STACKSIZE 64
|
77 |
+
#define GOSUBDEPTH 8
|
78 |
+
#define FORDEPTH 8
|
79 |
+
#define LINECACHESIZE 16
|
80 |
+
#else
|
81 |
+
/* for real computers */
|
82 |
+
#define BUFSIZE 256
|
83 |
+
#define STACKSIZE 256
|
84 |
+
#define GOSUBDEPTH 64
|
85 |
+
#define FORDEPTH 64
|
86 |
+
#define LINECACHESIZE 64
|
87 |
+
#endif
|
88 |
+
#endif
|
89 |
+
|
90 |
+
/* on the real small systems we remove the linecache and set a fixed memory size*/
|
91 |
+
#ifdef ARDUINO_AVR_DUEMILANOVE
|
92 |
+
#undef LINECACHESIZE
|
93 |
+
#if MEMSIZE == 0
|
94 |
+
#define MEMSIZE 512
|
95 |
+
#endif
|
96 |
+
#endif
|
97 |
+
|
98 |
+
/* more duffers and vars */
|
99 |
+
#define SBUFSIZE 32
|
100 |
+
#define VARSIZE 26
|
101 |
+
/* default sizes of arrays and strings if they are not DIMed */
|
102 |
+
#define ARRAYSIZEDEF 10
|
103 |
+
#define STRSIZEDEF 32
|
104 |
+
|
105 |
+
/*
|
106 |
+
* the time intervall in ms needed for
|
107 |
+
* ESP8266 yields, network client loops
|
108 |
+
* and other timing related functions
|
109 |
+
*/
|
110 |
+
#define LONGYIELDINTERVAL 1000
|
111 |
+
#define YIELDINTERVAL 32
|
112 |
+
#define YIELDTIME 2
|
113 |
+
|
114 |
+
/* the default EEPROM dummy size */
|
115 |
+
#define EEPROMSIZE 1024
|
116 |
+
|
117 |
+
/* after run behaviour on POSIX systems, 1 to terminate if started
|
118 |
+
on the command line with a file argument, 0 to stay active and
|
119 |
+
show a BASIC prompt*/
|
120 |
+
#define TERMINATEAFTERRUN 1
|
121 |
+
|
122 |
+
/*
|
123 |
+
* The tokens for the BASIC keywords
|
124 |
+
*
|
125 |
+
* All single character operators are their own tokens
|
126 |
+
* ASCII values above 0x7f are used for tokens of keywords.
|
127 |
+
* EOL is a token
|
128 |
+
*/
|
129 |
+
#define EOL 0
|
130 |
+
#define NUMBER -127
|
131 |
+
#define LINENUMBER -126
|
132 |
+
#define STRING -125
|
133 |
+
#define VARIABLE -124
|
134 |
+
#define STRINGVAR -123
|
135 |
+
#define ARRAYVAR -122
|
136 |
+
/* multi character tokens - BASEKEYWORD (3) */
|
137 |
+
#define GREATEREQUAL -121
|
138 |
+
#define LESSEREQUAL -120
|
139 |
+
#define NOTEQUAL -119
|
140 |
+
/* this is the Palo Alto Language Set (19) */
|
141 |
+
#define TPRINT -118
|
142 |
+
#define TLET -117
|
143 |
+
#define TINPUT -116
|
144 |
+
#define TGOTO -115
|
145 |
+
#define TGOSUB -114
|
146 |
+
#define TRETURN -113
|
147 |
+
#define TIF -112
|
148 |
+
#define TFOR -111
|
149 |
+
#define TTO -110
|
150 |
+
#define TSTEP -109
|
151 |
+
#define TNEXT -108
|
152 |
+
#define TSTOP -107
|
153 |
+
#define TLIST -106
|
154 |
+
#define TNEW -105
|
155 |
+
#define TRUN -104
|
156 |
+
#define TABS -103
|
157 |
+
#define TRND -102
|
158 |
+
#define TSIZE -101
|
159 |
+
#define TREM -100
|
160 |
+
/* this is the Apple 1 language set in addition to Palo Alto (14) */
|
161 |
+
#define TNOT -99
|
162 |
+
#define TAND -98
|
163 |
+
#define TOR -97
|
164 |
+
#define TLEN -96
|
165 |
+
#define TSGN -95
|
166 |
+
#define TPEEK -94
|
167 |
+
#define TDIM -93
|
168 |
+
#define TCLR -92
|
169 |
+
#define THIMEM -91
|
170 |
+
#define TTAB -90
|
171 |
+
#define TTHEN -89
|
172 |
+
#define TEND -88
|
173 |
+
#define TPOKE -87
|
174 |
+
/* Stefan's tinybasic additions (14) */
|
175 |
+
#define TCONT -86
|
176 |
+
#define TSQR -85
|
177 |
+
#define TPOW -84
|
178 |
+
#define TMAP -83
|
179 |
+
#define TDUMP -82
|
180 |
+
#define TBREAK -81
|
181 |
+
#define TSAVE -80
|
182 |
+
#define TLOAD -79
|
183 |
+
#define TGET -78
|
184 |
+
#define TPUT -77
|
185 |
+
#define TSET -76
|
186 |
+
#define TCLS -75
|
187 |
+
#define TLOCATE -74
|
188 |
+
#define TELSE -73
|
189 |
+
/* Arduino functions (10) */
|
190 |
+
#define TPINM -72
|
191 |
+
#define TDWRITE -71
|
192 |
+
#define TDREAD -70
|
193 |
+
#define TAWRITE -69
|
194 |
+
#define TAREAD -68
|
195 |
+
#define TDELAY -67
|
196 |
+
#define TMILLIS -66
|
197 |
+
#define TTONE -65
|
198 |
+
#define TPULSE -64
|
199 |
+
#define TAZERO -63
|
200 |
+
#define TLED -62
|
201 |
+
/* the DOS functions (5) */
|
202 |
+
#define TCATALOG -61
|
203 |
+
#define TDELETE -60
|
204 |
+
#define TOPEN -59
|
205 |
+
#define TCLOSE -58
|
206 |
+
#define TFDISK -57
|
207 |
+
/* low level access of internal routines (2) */
|
208 |
+
#define TUSR -56
|
209 |
+
#define TCALL -55
|
210 |
+
/* mathematical functions (7) */
|
211 |
+
#define TSIN -54
|
212 |
+
#define TCOS -53
|
213 |
+
#define TTAN -52
|
214 |
+
#define TATAN -51
|
215 |
+
#define TLOG -50
|
216 |
+
#define TEXP -49
|
217 |
+
#define TINT -48
|
218 |
+
/* graphics - experimental - rudimentary (7) */
|
219 |
+
#define TCOLOR -47
|
220 |
+
#define TPLOT -46
|
221 |
+
#define TLINE -45
|
222 |
+
#define TCIRCLE -44
|
223 |
+
#define TRECT -43
|
224 |
+
#define TFCIRCLE -42
|
225 |
+
#define TFRECT -41
|
226 |
+
/* the Dartmouth extensions (6) */
|
227 |
+
#define TDATA -40
|
228 |
+
#define TREAD -39
|
229 |
+
#define TRESTORE -38
|
230 |
+
#define TDEF -37
|
231 |
+
#define TFN -36
|
232 |
+
#define TON -35
|
233 |
+
/* darkarts (3) */
|
234 |
+
#define TMALLOC -34
|
235 |
+
#define TFIND -33
|
236 |
+
#define TEVAL -32
|
237 |
+
/* iot extensions (9) */
|
238 |
+
#define TERROR -31
|
239 |
+
#define TAVAIL -30
|
240 |
+
#define TSTR -29
|
241 |
+
#define TINSTR -28
|
242 |
+
#define TVAL -27
|
243 |
+
#define TNETSTAT -26
|
244 |
+
#define TSENSOR -25
|
245 |
+
#define TWIRE -24
|
246 |
+
#define TSLEEP -23
|
247 |
+
/* events and interrupts */
|
248 |
+
#define TAFTER -22
|
249 |
+
#define TEVERY -21
|
250 |
+
#define TEVENT -20
|
251 |
+
/* experimental structured commands, currently partially implemented */
|
252 |
+
#define TWHILE -19
|
253 |
+
#define TWEND -18
|
254 |
+
#define TREPEAT -17
|
255 |
+
#define TUNTIL -16
|
256 |
+
#define TSWITCH -15
|
257 |
+
#define TCASE -14
|
258 |
+
#define TSWEND -13
|
259 |
+
#define TDO -12
|
260 |
+
#define TDEND -11
|
261 |
+
/* these are multibyte token extension, currently unused */
|
262 |
+
/* using them would allow over 1000 BASIC keywords */
|
263 |
+
#define TEXT1 -3
|
264 |
+
/* end of tokens */
|
265 |
+
/* constants used for some obscure purposes */
|
266 |
+
#define TBUFFER -2
|
267 |
+
/* UNKNOWN is not used in the current code, the
|
268 |
+
* lexer tokenizes everything blindly. There is a UNKNOWN hook
|
269 |
+
* in statement for a grammar aware lexer */
|
270 |
+
#define UNKNOWN -1
|
271 |
+
|
272 |
+
/* extension tokens can be in the range from -128 to -255
|
273 |
+
* one needs to set HASLONGTOKENS
|
274 |
+
*/
|
275 |
+
#undef HASLONGTOKEN
|
276 |
+
#define TTOKEN1 -128
|
277 |
+
|
278 |
+
|
279 |
+
/* the number of keywords, and the base index of the keywords
|
280 |
+
* the number is irrelevant but BASEKEYWORD is used */
|
281 |
+
#define NKEYWORDS 3+19+13+14+11+5+2+7+7+6+12+3+9
|
282 |
+
#define BASEKEYWORD -121
|
283 |
+
|
284 |
+
/*
|
285 |
+
* Interpreter states
|
286 |
+
* SRUN means running from a programm
|
287 |
+
* SINT means interactive mode
|
288 |
+
* SERUN means running directly from EEPROM
|
289 |
+
* (enum would be the right way of doing this.)
|
290 |
+
* BREAKCHAR is the character stopping the program on Ardunios
|
291 |
+
* BREAKPIN can be set, it is a pin that needs to go to low to stop a BASIC program
|
292 |
+
* This should be done in hardware*.h
|
293 |
+
* BREAKSIGNAL can also be set, should be done in hardware*.h
|
294 |
+
*/
|
295 |
+
#define SINT 0
|
296 |
+
#define SRUN 1
|
297 |
+
#define SERUN 2
|
298 |
+
#define BREAKCHAR '#'
|
299 |
+
|
300 |
+
/*
|
301 |
+
* Input and output channels
|
302 |
+
*/
|
303 |
+
#define OSERIAL 1
|
304 |
+
#define ODSP 2
|
305 |
+
#define OPRT 4
|
306 |
+
#define OWIRE 7
|
307 |
+
#define ORADIO 8
|
308 |
+
#define OMQTT 9
|
309 |
+
#define OFILE 16
|
310 |
+
|
311 |
+
#define ISERIAL 1
|
312 |
+
#define IKEYBOARD 2
|
313 |
+
#define ISERIAL1 4
|
314 |
+
#define IWIRE 7
|
315 |
+
#define IRADIO 8
|
316 |
+
#define IMQTT 9
|
317 |
+
#define IFILE 16
|
318 |
+
|
319 |
+
/*
|
320 |
+
* All BASIC keywords for the tokens
|
321 |
+
*/
|
322 |
+
const char sge[] PROGMEM = "=>";
|
323 |
+
const char sle[] PROGMEM = "<=";
|
324 |
+
const char sne[] PROGMEM = "<>";
|
325 |
+
/* Palo Alto language set */
|
326 |
+
const char sprint[] PROGMEM = "PRINT";
|
327 |
+
const char slet[] PROGMEM = "LET";
|
328 |
+
const char sinput[] PROGMEM = "INPUT";
|
329 |
+
const char sgoto[] PROGMEM = "GOTO";
|
330 |
+
const char sgosub[] PROGMEM = "GOSUB";
|
331 |
+
const char sreturn[] PROGMEM = "RETURN";
|
332 |
+
const char sif[] PROGMEM = "IF";
|
333 |
+
const char sfor[] PROGMEM = "FOR";
|
334 |
+
const char sto[] PROGMEM = "TO";
|
335 |
+
const char sstep[] PROGMEM = "STEP";
|
336 |
+
const char snext[] PROGMEM = "NEXT";
|
337 |
+
const char sstop[] PROGMEM = "STOP";
|
338 |
+
const char slist[] PROGMEM = "LIST";
|
339 |
+
const char snew[] PROGMEM = "NEW";
|
340 |
+
const char srun[] PROGMEM = "RUN";
|
341 |
+
const char sabs[] PROGMEM = "ABS";
|
342 |
+
const char srnd[] PROGMEM = "RND";
|
343 |
+
const char ssize[] PROGMEM = "SIZE";
|
344 |
+
const char srem[] PROGMEM = "REM";
|
345 |
+
/* Apple 1 language set */
|
346 |
+
#ifdef HASAPPLE1
|
347 |
+
const char snot[] PROGMEM = "NOT";
|
348 |
+
const char sand[] PROGMEM = "AND";
|
349 |
+
const char sor[] PROGMEM = "OR";
|
350 |
+
const char slen[] PROGMEM = "LEN";
|
351 |
+
const char ssgn[] PROGMEM = "SGN";
|
352 |
+
const char speek[] PROGMEM = "PEEK";
|
353 |
+
const char sdim[] PROGMEM = "DIM";
|
354 |
+
const char sclr[] PROGMEM = "CLR";
|
355 |
+
const char shimem[] PROGMEM = "HIMEM";
|
356 |
+
const char stab[] PROGMEM = "TAB";
|
357 |
+
const char sthen[] PROGMEM = "THEN";
|
358 |
+
const char sbend[] PROGMEM = "END";
|
359 |
+
const char spoke[] PROGMEM = "POKE";
|
360 |
+
#endif
|
361 |
+
/* Stefan's basic additions */
|
362 |
+
#ifdef HASSTEFANSEXT
|
363 |
+
const char scont[] PROGMEM = "CONT";
|
364 |
+
const char ssqr[] PROGMEM = "SQR";
|
365 |
+
const char spow[] PROGMEM = "POW";
|
366 |
+
const char smap[] PROGMEM = "MAP";
|
367 |
+
const char sdump[] PROGMEM = "DUMP";
|
368 |
+
const char sbreak[] PROGMEM = "BREAK";
|
369 |
+
#endif
|
370 |
+
/* LOAD and SAVE is always there */
|
371 |
+
const char ssave[] PROGMEM = "SAVE";
|
372 |
+
const char sload[] PROGMEM = "LOAD";
|
373 |
+
#ifdef HASSTEFANSEXT
|
374 |
+
const char sget[] PROGMEM = "GET";
|
375 |
+
const char sput[] PROGMEM = "PUT";
|
376 |
+
const char sset[] PROGMEM = "SET";
|
377 |
+
const char scls[] PROGMEM = "CLS";
|
378 |
+
const char slocate[] PROGMEM = "LOCATE";
|
379 |
+
const char selse[] PROGMEM = "ELSE";
|
380 |
+
#endif
|
381 |
+
/* Arduino functions */
|
382 |
+
#ifdef HASARDUINOIO
|
383 |
+
const char spinm[] PROGMEM = "PINM";
|
384 |
+
const char sdwrite[] PROGMEM = "DWRITE";
|
385 |
+
const char sdread[] PROGMEM = "DREAD";
|
386 |
+
const char sawrite[] PROGMEM = "AWRITE";
|
387 |
+
const char saread[] PROGMEM = "AREAD";
|
388 |
+
const char sdelay[] PROGMEM = "DELAY";
|
389 |
+
const char smillis[] PROGMEM = "MILLIS";
|
390 |
+
const char sazero[] PROGMEM = "AZERO";
|
391 |
+
const char sled[] PROGMEM = "LED";
|
392 |
+
#endif
|
393 |
+
#ifdef HASTONE
|
394 |
+
const char stone[] PROGMEM = "PLAY";
|
395 |
+
#endif
|
396 |
+
#ifdef HASPULSE
|
397 |
+
const char spulse[] PROGMEM = "PULSE";
|
398 |
+
#endif
|
399 |
+
/* DOS functions */
|
400 |
+
#ifdef HASFILEIO
|
401 |
+
const char scatalog[] PROGMEM = "CATALOG";
|
402 |
+
const char sdelete[] PROGMEM = "DELETE";
|
403 |
+
const char sfopen[] PROGMEM = "OPEN";
|
404 |
+
const char sfclose[] PROGMEM = "CLOSE";
|
405 |
+
const char sfdisk[] PROGMEM = "FDISK";
|
406 |
+
#endif
|
407 |
+
/* low level access functions */
|
408 |
+
#ifdef HASSTEFANSEXT
|
409 |
+
const char susr[] PROGMEM = "USR";
|
410 |
+
const char scall[] PROGMEM = "CALL";
|
411 |
+
#endif
|
412 |
+
/* mathematics */
|
413 |
+
#ifdef HASFLOAT
|
414 |
+
const char ssin[] PROGMEM = "SIN";
|
415 |
+
const char scos[] PROGMEM = "COS";
|
416 |
+
const char stan[] PROGMEM = "TAN";
|
417 |
+
const char satan[] PROGMEM = "ATAN";
|
418 |
+
const char slog[] PROGMEM = "LOG";
|
419 |
+
const char sexp[] PROGMEM = "EXP";
|
420 |
+
#endif
|
421 |
+
/* INT is always needed to make float/int programs compatible */
|
422 |
+
const char sint[] PROGMEM = "INT";
|
423 |
+
/* elemetars graphics */
|
424 |
+
#ifdef HASGRAPH
|
425 |
+
const char scolor[] PROGMEM = "COLOR";
|
426 |
+
const char splot[] PROGMEM = "PLOT";
|
427 |
+
const char sline[] PROGMEM = "LINE";
|
428 |
+
const char scircle[] PROGMEM = "CIRCLE";
|
429 |
+
const char srect[] PROGMEM = "RECT";
|
430 |
+
const char sfcircle[] PROGMEM = "FCIRCLE";
|
431 |
+
const char sfrect[] PROGMEM = "FRECT";
|
432 |
+
#endif
|
433 |
+
/* Dartmouth BASIC extensions */
|
434 |
+
#ifdef HASDARTMOUTH
|
435 |
+
const char sdata[] PROGMEM = "DATA";
|
436 |
+
const char sread[] PROGMEM = "READ";
|
437 |
+
const char srestore[] PROGMEM = "RESTORE";
|
438 |
+
const char sdef[] PROGMEM = "DEF";
|
439 |
+
const char sfn[] PROGMEM = "FN";
|
440 |
+
const char son[] PROGMEM = "ON";
|
441 |
+
#endif
|
442 |
+
/* The Darkarts commands unthinkable in Dartmouth */
|
443 |
+
#ifdef HASDARKARTS
|
444 |
+
const char smalloc[] PROGMEM = "MALLOC";
|
445 |
+
const char sfind[] PROGMEM = "FIND";
|
446 |
+
const char seval[] PROGMEM = "EVAL";
|
447 |
+
#endif
|
448 |
+
/* complex error handling */
|
449 |
+
#ifdef HASERRORHANDLING
|
450 |
+
const char serror[] PROGMEM = "ERROR";
|
451 |
+
#endif
|
452 |
+
/* iot extensions */
|
453 |
+
#ifdef HASIOT
|
454 |
+
const char savail[] PROGMEM = "AVAIL";
|
455 |
+
const char sstr[] PROGMEM = "STR";
|
456 |
+
const char sinstr[] PROGMEM = "INSTR";
|
457 |
+
const char sval[] PROGMEM = "VAL";
|
458 |
+
const char snetstat[] PROGMEM = "NETSTAT";
|
459 |
+
const char ssensor[] PROGMEM = "SENSOR";
|
460 |
+
const char swire[] PROGMEM = "WIRE";
|
461 |
+
const char ssleep[] PROGMEM = "SLEEP";
|
462 |
+
#endif
|
463 |
+
/* events and interrupts */
|
464 |
+
#ifdef HASTIMER
|
465 |
+
const char safter[] PROGMEM = "AFTER";
|
466 |
+
const char severy[] PROGMEM = "EVERY";
|
467 |
+
#endif
|
468 |
+
#ifdef HASEVENTS
|
469 |
+
const char sevent[] PROGMEM = "EVENT";
|
470 |
+
#endif
|
471 |
+
#ifdef HASSTRUCT
|
472 |
+
const char swhile[] PROGMEM = "WHILE";
|
473 |
+
const char swend[] PROGMEM = "WEND";
|
474 |
+
const char srepeat[] PROGMEM = "REPEAT";
|
475 |
+
const char suntil[] PROGMEM = "UNTIL";
|
476 |
+
const char sswitch[] PROGMEM = "SWITCH";
|
477 |
+
const char scase[] PROGMEM = "CASE";
|
478 |
+
const char sswend[] PROGMEM = "SWEND";
|
479 |
+
const char sdo[] PROGMEM = "DO";
|
480 |
+
const char sdend[] PROGMEM = "DEND";
|
481 |
+
#endif
|
482 |
+
|
483 |
+
|
484 |
+
/* zero terminated keyword storage */
|
485 |
+
const char* const keyword[] PROGMEM = {
|
486 |
+
sge, sle, sne, sprint, slet, sinput,
|
487 |
+
sgoto, sgosub, sreturn, sif, sfor, sto,
|
488 |
+
sstep, snext, sstop, slist, snew, srun,
|
489 |
+
sabs, srnd, ssize, srem,
|
490 |
+
#ifdef HASAPPLE1
|
491 |
+
snot, sand, sor, slen, ssgn, speek, sdim,
|
492 |
+
sclr, shimem, stab, sthen,
|
493 |
+
sbend, spoke,
|
494 |
+
#endif
|
495 |
+
#ifdef HASSTEFANSEXT
|
496 |
+
scont, ssqr, spow, smap, sdump, sbreak,
|
497 |
+
#endif
|
498 |
+
ssave, sload,
|
499 |
+
#ifdef HASSTEFANSEXT
|
500 |
+
sget, sput, sset, scls, slocate, selse,
|
501 |
+
#endif
|
502 |
+
#ifdef HASARDUINOIO
|
503 |
+
spinm, sdwrite, sdread, sawrite, saread,
|
504 |
+
sdelay, smillis, sazero, sled,
|
505 |
+
#endif
|
506 |
+
#ifdef HASTONE
|
507 |
+
stone,
|
508 |
+
#endif
|
509 |
+
#ifdef HASPULSE
|
510 |
+
spulse,
|
511 |
+
#endif
|
512 |
+
#ifdef HASFILEIO
|
513 |
+
scatalog, sdelete, sfopen, sfclose, sfdisk,
|
514 |
+
#endif
|
515 |
+
#ifdef HASSTEFANSEXT
|
516 |
+
susr, scall,
|
517 |
+
#endif
|
518 |
+
#ifdef HASFLOAT
|
519 |
+
ssin, scos, stan, satan, slog, sexp,
|
520 |
+
#endif
|
521 |
+
sint,
|
522 |
+
#ifdef HASGRAPH
|
523 |
+
scolor, splot, sline, scircle, srect,
|
524 |
+
sfcircle, sfrect,
|
525 |
+
#endif
|
526 |
+
#ifdef HASDARTMOUTH
|
527 |
+
sdata, sread, srestore, sdef, sfn, son,
|
528 |
+
#endif
|
529 |
+
#ifdef HASDARKARTS
|
530 |
+
smalloc, sfind, seval,
|
531 |
+
#endif
|
532 |
+
/* complex error handling */
|
533 |
+
#ifdef HASERRORHANDLING
|
534 |
+
serror,
|
535 |
+
#endif
|
536 |
+
#ifdef HASIOT
|
537 |
+
savail, sstr, sinstr, sval,
|
538 |
+
snetstat, ssensor, swire, ssleep,
|
539 |
+
#endif
|
540 |
+
#ifdef HASTIMER
|
541 |
+
safter, severy,
|
542 |
+
#endif
|
543 |
+
#ifdef HASEVENTS
|
544 |
+
sevent,
|
545 |
+
#endif
|
546 |
+
#ifdef HASSTRUCT
|
547 |
+
swhile, swend, srepeat, suntil, sswitch, scase, sswend,
|
548 |
+
sdo, sdend,
|
549 |
+
#endif
|
550 |
+
0
|
551 |
+
};
|
552 |
+
|
553 |
+
/* the zero terminated token dictonary needed for scalability */
|
554 |
+
const signed char tokens[] PROGMEM = {
|
555 |
+
GREATEREQUAL, LESSEREQUAL, NOTEQUAL, TPRINT, TLET,
|
556 |
+
TINPUT, TGOTO, TGOSUB, TRETURN, TIF, TFOR, TTO, TSTEP,
|
557 |
+
TNEXT, TSTOP, TLIST, TNEW, TRUN, TABS, TRND, TSIZE, TREM,
|
558 |
+
#ifdef HASAPPLE1
|
559 |
+
TNOT, TAND, TOR, TLEN, TSGN, TPEEK, TDIM, TCLR,
|
560 |
+
THIMEM, TTAB, TTHEN, TEND, TPOKE,
|
561 |
+
#endif
|
562 |
+
#ifdef HASSTEFANSEXT
|
563 |
+
TCONT, TSQR, TPOW, TMAP, TDUMP, TBREAK,
|
564 |
+
#endif
|
565 |
+
TSAVE, TLOAD,
|
566 |
+
#ifdef HASSTEFANSEXT
|
567 |
+
TGET, TPUT, TSET, TCLS, TLOCATE, TELSE,
|
568 |
+
#endif
|
569 |
+
#ifdef HASARDUINOIO
|
570 |
+
TPINM, TDWRITE, TDREAD, TAWRITE, TAREAD, TDELAY, TMILLIS,
|
571 |
+
TAZERO, TLED,
|
572 |
+
#endif
|
573 |
+
#ifdef HASTONE
|
574 |
+
TTONE,
|
575 |
+
#endif
|
576 |
+
#ifdef HASPULSE
|
577 |
+
TPULSE,
|
578 |
+
#endif
|
579 |
+
#ifdef HASFILEIO
|
580 |
+
TCATALOG, TDELETE, TOPEN, TCLOSE, TFDISK,
|
581 |
+
#endif
|
582 |
+
#ifdef HASSTEFANSEXT
|
583 |
+
TUSR, TCALL,
|
584 |
+
#endif
|
585 |
+
#ifdef HASFLOAT
|
586 |
+
TSIN, TCOS, TTAN, TATAN, TLOG, TEXP,
|
587 |
+
#endif
|
588 |
+
TINT,
|
589 |
+
#ifdef HASGRAPH
|
590 |
+
TCOLOR, TPLOT, TLINE, TCIRCLE, TRECT,
|
591 |
+
TFCIRCLE, TFRECT,
|
592 |
+
#endif
|
593 |
+
#ifdef HASDARTMOUTH
|
594 |
+
TDATA, TREAD, TRESTORE, TDEF, TFN, TON,
|
595 |
+
#endif
|
596 |
+
#ifdef HASDARKARTS
|
597 |
+
TMALLOC, TFIND, TEVAL,
|
598 |
+
#endif
|
599 |
+
#ifdef HASERRORHANDLING
|
600 |
+
TERROR,
|
601 |
+
#endif
|
602 |
+
#ifdef HASIOT
|
603 |
+
TAVAIL, TSTR, TINSTR, TVAL, TNETSTAT,
|
604 |
+
TSENSOR, TWIRE, TSLEEP,
|
605 |
+
#endif
|
606 |
+
#ifdef HASTIMER
|
607 |
+
TAFTER, TEVERY,
|
608 |
+
#endif
|
609 |
+
#ifdef HASEVENTS
|
610 |
+
TEVENT,
|
611 |
+
#endif
|
612 |
+
#ifdef HASSTRUCT
|
613 |
+
TWHILE, TWEND, TREPEAT, TUNTIL, TSWITCH, TCASE, TSWEND,
|
614 |
+
TDO, TDEND,
|
615 |
+
#endif
|
616 |
+
0
|
617 |
+
};
|
618 |
+
|
619 |
+
/*
|
620 |
+
* the message catalog
|
621 |
+
*/
|
622 |
+
#define MFILE 0
|
623 |
+
#define MPROMPT 1
|
624 |
+
#define MGREET 2
|
625 |
+
#define MLINE 3
|
626 |
+
#define MNUMBER 4
|
627 |
+
#define MVARIABLE 5
|
628 |
+
#define MARRAY 6
|
629 |
+
#define MSTRING 7
|
630 |
+
#define MSTRINGVAR 8
|
631 |
+
#define EGENERAL 9
|
632 |
+
#define EUNKNOWN 10
|
633 |
+
#define ENUMBER 11
|
634 |
+
#define EDIVIDE 12
|
635 |
+
#define ELINE 13
|
636 |
+
#define EOUTOFMEMORY 14
|
637 |
+
#define ESTACK 15
|
638 |
+
#define EORANGE 16
|
639 |
+
#define ESTRING 17
|
640 |
+
#define EVARIABLE 18
|
641 |
+
#define ELOOP 19
|
642 |
+
#define EFILE 20
|
643 |
+
#define EFUN 21
|
644 |
+
#define EARGS 22
|
645 |
+
#define EEEPROM 23
|
646 |
+
#define ESDCARD 24
|
647 |
+
|
648 |
+
const char mfile[] PROGMEM = "file.bas";
|
649 |
+
const char mprompt[] PROGMEM = "> ";
|
650 |
+
const char mgreet[] PROGMEM = "Stefan's Basic 1.4";
|
651 |
+
const char mline[] PROGMEM = "LINE";
|
652 |
+
const char mnumber[] PROGMEM = "NUMBER";
|
653 |
+
const char mvariable[] PROGMEM = "VARIABLE";
|
654 |
+
const char marray[] PROGMEM = "ARRAY";
|
655 |
+
const char mstring[] PROGMEM = "STRING";
|
656 |
+
const char mstringv[] PROGMEM = "STRINGVAR";
|
657 |
+
const char egeneral[] PROGMEM = "Error";
|
658 |
+
#ifdef HASERRORMSG
|
659 |
+
const char eunknown[] PROGMEM = "Syntax";
|
660 |
+
const char enumber[] PROGMEM = "Number";
|
661 |
+
const char edivide[] PROGMEM = "Div by 0";
|
662 |
+
const char eline[] PROGMEM = "Unknown Line";
|
663 |
+
const char emem[] PROGMEM = "Memory";
|
664 |
+
const char estack[] PROGMEM = "Stack";
|
665 |
+
const char erange[] PROGMEM = "Range";
|
666 |
+
const char estring[] PROGMEM = "String";
|
667 |
+
const char evariable[] PROGMEM = "Variable";
|
668 |
+
const char eloop[] PROGMEM = "Loop";
|
669 |
+
const char efile[] PROGMEM = "File";
|
670 |
+
const char efun[] PROGMEM = "Function";
|
671 |
+
const char eargs[] PROGMEM = "Args";
|
672 |
+
const char eeeprom[] PROGMEM = "EEPROM";
|
673 |
+
const char esdcard[] PROGMEM = "SD card";
|
674 |
+
#endif
|
675 |
+
|
676 |
+
const char* const message[] PROGMEM = {
|
677 |
+
mfile, mprompt, mgreet,
|
678 |
+
mline, mnumber, mvariable, marray,
|
679 |
+
mstring, mstringv,
|
680 |
+
egeneral
|
681 |
+
#ifdef HASERRORMSG
|
682 |
+
, eunknown, enumber, edivide, eline,
|
683 |
+
emem, estack, erange,
|
684 |
+
estring, evariable, eloop, efile, efun, eargs,
|
685 |
+
eeeprom, esdcard
|
686 |
+
#endif
|
687 |
+
};
|
688 |
+
|
689 |
+
/*
|
690 |
+
* code for variable numbers and addresses sizes
|
691 |
+
* the original code was 16 bit but can be extended here
|
692 |
+
* to arbitrary types
|
693 |
+
*
|
694 |
+
* number_t is the type for numerical work - either float or int
|
695 |
+
* wnumber_t is the type containing the largest printable integer,
|
696 |
+
* for float keep this int on 32 bit and long on 8 bit unless you
|
697 |
+
* want to use very long integers, like 64 or 128 bit types.
|
698 |
+
* address_t is an unsigned type adddressing memory, default 16bit
|
699 |
+
* mem_t is a SIGNED 8bit character type.
|
700 |
+
* index_t is a SIGNED minimum 16 bit integer type
|
701 |
+
*
|
702 |
+
* works with the tacit assumption that
|
703 |
+
* sizeof(number_t) >= sizeof(address_t)
|
704 |
+
* and that the entire memory is smaller than the positive
|
705 |
+
* part of number type (!!)
|
706 |
+
*
|
707 |
+
* we assume that float >= 4 bytes in the following
|
708 |
+
*
|
709 |
+
* maxnum: the maximum accurate(!) integer of a
|
710 |
+
* 32 bit float
|
711 |
+
* strindexsize: the index size of strings either
|
712 |
+
* 1 byte or 2 bytes - no other values supported
|
713 |
+
*/
|
714 |
+
#ifdef HASFLOAT
|
715 |
+
typedef float number_t;
|
716 |
+
const number_t maxnum=16777216;
|
717 |
+
typedef long wnumber_t;
|
718 |
+
#else
|
719 |
+
typedef int number_t;
|
720 |
+
typedef int wnumber_t;
|
721 |
+
const number_t maxnum=(number_t)~((number_t)1<<(sizeof(number_t)*8-1));
|
722 |
+
#endif
|
723 |
+
typedef unsigned short address_t; /* this type addresses memory */
|
724 |
+
const int numsize=sizeof(number_t);
|
725 |
+
const int addrsize=sizeof(address_t);
|
726 |
+
const int eheadersize=sizeof(address_t)+1;
|
727 |
+
const int strindexsize=2; /* default in the meantime, strings up to unsigned 16 bit length */
|
728 |
+
const address_t maxaddr=(address_t)(~0);
|
729 |
+
typedef signed char mem_t; /* a signed 8 bit type for the memory */
|
730 |
+
typedef int index_t; /* this type counts at least 16 bit */
|
731 |
+
#ifndef HASLONGTOKENS
|
732 |
+
typedef signed char token_t; /* the type of tokens, normally mem_t with a maximum of 127 commands and data types */
|
733 |
+
#else
|
734 |
+
typedef short token_t; /* token type extension, allows an extra of 127 commands and symbols */
|
735 |
+
#endif
|
736 |
+
|
737 |
+
/* this type maps numbers to bytes */
|
738 |
+
typedef struct {mem_t l; mem_t h;} twobytes_t;
|
739 |
+
typedef union { number_t i; address_t a; twobytes_t b; mem_t c[sizeof(number_t)]; } accu_t;
|
740 |
+
|
741 |
+
/* the memreader function type */
|
742 |
+
typedef mem_t (*memreader_t)(address_t);
|
743 |
+
|
744 |
+
/*
|
745 |
+
* system type identifiers
|
746 |
+
*/
|
747 |
+
|
748 |
+
#define SYSTYPE_UNKNOWN 0
|
749 |
+
#define SYSTYPE_AVR 1
|
750 |
+
#define SYSTYPE_ESP8266 2
|
751 |
+
#define SYSTYPE_ESP32 3
|
752 |
+
#define SYSTYPE_RP2040 4
|
753 |
+
#define SYSTYPE_SAM 5
|
754 |
+
#define SYSTYPE_XMC 6
|
755 |
+
#define SYSTYPE_SMT32 7
|
756 |
+
#define SYSTYPE_NRENESA 8
|
757 |
+
#define SYSTYPE_POSIX 32
|
758 |
+
#define SYSTYPE_MSDOS 33
|
759 |
+
#define SYSTYPE_MINGW 34
|
760 |
+
#define SYSTYPE_RASPPI 35
|
761 |
+
|
762 |
+
/*
|
763 |
+
* The basic interpreter is implemented as a stack machine
|
764 |
+
* with global variable for the interpreter state, the memory
|
765 |
+
* and the arithmetic during run time.
|
766 |
+
*/
|
767 |
+
|
768 |
+
/* the stack, all BASIC arithmetic is done here */
|
769 |
+
number_t stack[STACKSIZE];
|
770 |
+
address_t sp=0;
|
771 |
+
|
772 |
+
/* a small buffer to process string arguments, mostly used for Arduino PROGMEM */
|
773 |
+
char sbuffer[SBUFSIZE];
|
774 |
+
|
775 |
+
/* the input buffer, the lexer can tokenize this and run from it, bi is an index to this.
|
776 |
+
bi must be global as it is the program cursor in interactive mode */
|
777 |
+
char ibuffer[BUFSIZE] = "\0";
|
778 |
+
char *bi;
|
779 |
+
|
780 |
+
/* a static array of variables A-Z for the small systems that have no heap */
|
781 |
+
number_t vars[VARSIZE];
|
782 |
+
|
783 |
+
/* the BASIC working memory, either malloced or allocated as a global array */
|
784 |
+
#if MEMSIZE != 0
|
785 |
+
mem_t mem[MEMSIZE];
|
786 |
+
#else
|
787 |
+
mem_t* mem;
|
788 |
+
#endif
|
789 |
+
address_t himem, memsize;
|
790 |
+
|
791 |
+
/* the for stack - remembers the variable, indices, and optionally a type for stuctured BASIC */
|
792 |
+
struct forstackitem {mem_t varx; mem_t vary; address_t here; number_t to; number_t step;
|
793 |
+
#ifdef HASSTRUCT
|
794 |
+
mem_t type;
|
795 |
+
#endif
|
796 |
+
} forstack[FORDEPTH];
|
797 |
+
index_t forsp = 0;
|
798 |
+
|
799 |
+
/* the GOSUB stack remembers an address to jump to */
|
800 |
+
address_t gosubstack[GOSUBDEPTH];
|
801 |
+
index_t gosubsp = 0;
|
802 |
+
|
803 |
+
/* this variable stores the location in pushlocation() and poplocation(), used to rewind the program cursor */
|
804 |
+
address_t slocation;
|
805 |
+
|
806 |
+
/* arithmetic accumulators - used by many statements, y may be obsolete in future*/
|
807 |
+
number_t x, y;
|
808 |
+
|
809 |
+
/* the names of a variable and small integer accumulator */
|
810 |
+
mem_t xc, yc;
|
811 |
+
|
812 |
+
/* an address accumulator, used a lot in string operations */
|
813 |
+
address_t ax;
|
814 |
+
|
815 |
+
/* z is another accumulator used to convert numbers and addressed to bytes and vice versa */
|
816 |
+
/* this union is used to store larger objects into byte oriented memory */
|
817 |
+
accu_t z;
|
818 |
+
|
819 |
+
/* string index registers */
|
820 |
+
char *ir, *ir2;
|
821 |
+
|
822 |
+
/* the active token */
|
823 |
+
token_t token;
|
824 |
+
|
825 |
+
/* the curent error, can be a token, hance token type */
|
826 |
+
token_t er;
|
827 |
+
|
828 |
+
/* a trapable error */
|
829 |
+
mem_t ert;
|
830 |
+
|
831 |
+
/* the interpreter state, interactive, run or run from EEPROM */
|
832 |
+
mem_t st;
|
833 |
+
|
834 |
+
/* the current program location or "cursor" */
|
835 |
+
address_t here;
|
836 |
+
|
837 |
+
/* the topmost byte of a program in memory, beginning of free BASIC RAM */
|
838 |
+
address_t top;
|
839 |
+
|
840 |
+
/* the number of variables on the heap */
|
841 |
+
address_t nvars = 0;
|
842 |
+
|
843 |
+
/* used to format output with # */
|
844 |
+
mem_t form = 0;
|
845 |
+
|
846 |
+
/* counts the outputed characters on streams 0-3, used to emulate a real tab */
|
847 |
+
#ifdef HASMSTAB
|
848 |
+
mem_t charcount[3]; /* devices 1-4 support tabing */
|
849 |
+
mem_t reltab = 0;
|
850 |
+
#endif
|
851 |
+
|
852 |
+
/* the lower limit of the array is one by default, can be a variable */
|
853 |
+
#ifdef HASARRAYLIMIT
|
854 |
+
address_t arraylimit = 1;
|
855 |
+
#else
|
856 |
+
const address_t arraylimit = 1;
|
857 |
+
#endif
|
858 |
+
|
859 |
+
/* the number of arguments parsed from a command */
|
860 |
+
mem_t args;
|
861 |
+
|
862 |
+
/* the random number seed, this is unsigned hence address_t */
|
863 |
+
#ifndef HASFLOAT
|
864 |
+
address_t rd;
|
865 |
+
#else
|
866 |
+
unsigned long rd;
|
867 |
+
#endif
|
868 |
+
|
869 |
+
/* output and input channels, used to direct output to various devices */
|
870 |
+
mem_t id;
|
871 |
+
mem_t od;
|
872 |
+
|
873 |
+
/* default IO - not constant, can be changed at runtime through a user call */
|
874 |
+
mem_t idd = ISERIAL;
|
875 |
+
mem_t odd = OSERIAL;
|
876 |
+
|
877 |
+
/* the runtime debuglevel */
|
878 |
+
mem_t debuglevel = 0;
|
879 |
+
|
880 |
+
/* DATA pointer, where is the current READ statement */
|
881 |
+
#ifdef HASDARTMOUTH
|
882 |
+
address_t data = 0;
|
883 |
+
address_t datarc = 1;
|
884 |
+
#endif
|
885 |
+
|
886 |
+
/*
|
887 |
+
* process command line arguments in the POSIX world
|
888 |
+
* bnointafterrun is a flag to remember if called as command
|
889 |
+
* line argument, in this case we don't return to interactive
|
890 |
+
*/
|
891 |
+
#ifndef ARDUINO
|
892 |
+
int bargc;
|
893 |
+
char** bargv;
|
894 |
+
mem_t bnointafterrun = 0;
|
895 |
+
#endif
|
896 |
+
|
897 |
+
/*
|
898 |
+
* Yield counter, we count when we did yield the last time
|
899 |
+
* lastyield controlls the client loops of network functions
|
900 |
+
* like mqtt, scanned keyboard, and USB.
|
901 |
+
*
|
902 |
+
* lastlongyield controls longterm functions like DHCP lease
|
903 |
+
* renewal in Ethernet
|
904 |
+
*
|
905 |
+
* there variables are only needed if the platform has background
|
906 |
+
* tasks
|
907 |
+
*/
|
908 |
+
long lastyield=0;
|
909 |
+
long lastlongyield=0;
|
910 |
+
|
911 |
+
/* formaters lastouttoken and spaceafterkeyword to make a nice LIST */
|
912 |
+
mem_t lastouttoken;
|
913 |
+
mem_t spaceafterkeyword;
|
914 |
+
mem_t outliteral = 0;
|
915 |
+
mem_t lexliteral = 0;
|
916 |
+
|
917 |
+
/*
|
918 |
+
* the cache for the heap search - helps the string code
|
919 |
+
* the last found object on the heap is remembered. This is needed
|
920 |
+
* because the string code sometime searches the heap twice during the
|
921 |
+
* same operation.
|
922 |
+
*/
|
923 |
+
#ifdef HASAPPLE1
|
924 |
+
mem_t bfindc, bfindd, bfindt;
|
925 |
+
address_t bfinda, bfindz;
|
926 |
+
#endif
|
927 |
+
|
928 |
+
/*
|
929 |
+
* a variable for some string operations
|
930 |
+
*/
|
931 |
+
int vlength;
|
932 |
+
|
933 |
+
/* the timer code - very simple needs to to to a struct */
|
934 |
+
/* timer type */
|
935 |
+
typedef struct {
|
936 |
+
mem_t enabled;
|
937 |
+
unsigned long last;
|
938 |
+
unsigned long interval;
|
939 |
+
mem_t type;
|
940 |
+
address_t linenumber;
|
941 |
+
} btimer_t;
|
942 |
+
|
943 |
+
#ifdef HASTIMER
|
944 |
+
btimer_t after_timer = {0, 0, 0, 0, 0};
|
945 |
+
btimer_t every_timer = {0, 0, 0, 0, 0};
|
946 |
+
#endif
|
947 |
+
|
948 |
+
/* the event code */
|
949 |
+
#ifdef HASEVENTS
|
950 |
+
|
951 |
+
#define EVENTLISTSIZE 4
|
952 |
+
|
953 |
+
/* event type */
|
954 |
+
typedef struct {
|
955 |
+
mem_t enabled;
|
956 |
+
mem_t pin;
|
957 |
+
mem_t mode;
|
958 |
+
mem_t type;
|
959 |
+
address_t linenumber;
|
960 |
+
mem_t active;
|
961 |
+
} bevent_t;
|
962 |
+
|
963 |
+
/* the event list */
|
964 |
+
int nevents = 0;
|
965 |
+
int ievent = 0;
|
966 |
+
static mem_t events_enabled = 1;
|
967 |
+
static volatile bevent_t eventlist[EVENTLISTSIZE];
|
968 |
+
|
969 |
+
/* the extension of the GOSUB stack */
|
970 |
+
static mem_t gosubarg[GOSUBDEPTH];
|
971 |
+
|
972 |
+
/* handle the event list */
|
973 |
+
mem_t addevent(mem_t, mem_t, mem_t, address_t);
|
974 |
+
void deleteevent(mem_t);
|
975 |
+
volatile bevent_t* findevent(mem_t);
|
976 |
+
mem_t eventindex(mem_t);
|
977 |
+
#endif
|
978 |
+
|
979 |
+
#ifdef HASERRORHANDLING
|
980 |
+
/* the error handler type, very simple for now */
|
981 |
+
typedef struct {
|
982 |
+
mem_t type;
|
983 |
+
address_t linenumber;
|
984 |
+
} berrorh_t;
|
985 |
+
|
986 |
+
berrorh_t berrorh = {0 , 0};
|
987 |
+
mem_t erh = 0;
|
988 |
+
#endif
|
989 |
+
|
990 |
+
/* the string for real time clocks */
|
991 |
+
char rtcstring[20] = { 0 };
|
992 |
+
|
993 |
+
/* the units pulse operates on, in microseconds*/
|
994 |
+
short bpulseunit = 10;
|
995 |
+
|
996 |
+
/* only needed for POSIXNONBLOCKING */
|
997 |
+
mem_t breakcondition = 0;
|
998 |
+
|
999 |
+
/*
|
1000 |
+
* Function prototypes, ordered by layers
|
1001 |
+
* HAL - hardware abstraction
|
1002 |
+
* Layer 0 - memory and I/O
|
1003 |
+
* Layer 1 - Program storage and control
|
1004 |
+
* Layer 2 - Where stuff happens
|
1005 |
+
*/
|
1006 |
+
|
1007 |
+
/*
|
1008 |
+
* HAL - see hardware-*.h
|
1009 |
+
* This is the hardware abstraction layer of the BASIC
|
1010 |
+
* interpreter
|
1011 |
+
*/
|
1012 |
+
|
1013 |
+
/* setup codes */
|
1014 |
+
void timeinit();
|
1015 |
+
void wiringbegin();
|
1016 |
+
|
1017 |
+
/* low level mem and hardware features */
|
1018 |
+
long freeRam();
|
1019 |
+
long freememorysize();
|
1020 |
+
void restartsystem();
|
1021 |
+
void activatesleep(long t);
|
1022 |
+
|
1023 |
+
/* start the spi bus */
|
1024 |
+
void spibegin();
|
1025 |
+
|
1026 |
+
/*
|
1027 |
+
* the hardware interface display driver functions, need to be
|
1028 |
+
* implemented for the display driver to work
|
1029 |
+
* dspupdate() only for display like Epapers
|
1030 |
+
*/
|
1031 |
+
void dspbegin();
|
1032 |
+
void dspprintchar(char, mem_t, mem_t);
|
1033 |
+
void dspclear();
|
1034 |
+
void dspupdate();
|
1035 |
+
|
1036 |
+
/* keyboard code */
|
1037 |
+
void kbdbegin();
|
1038 |
+
int kbdstat(char);
|
1039 |
+
char kbdavailable();
|
1040 |
+
char kbdread();
|
1041 |
+
char kbdcheckch();
|
1042 |
+
|
1043 |
+
/* graphics functions */
|
1044 |
+
void rgbcolor(int, int, int);
|
1045 |
+
void vgacolor(short c);
|
1046 |
+
void vgascale(int*, int*);
|
1047 |
+
void plot(int, int);
|
1048 |
+
void line(int, int, int, int);
|
1049 |
+
void rect(int, int, int, int);
|
1050 |
+
void frect(int, int, int, int);
|
1051 |
+
void circle(int, int, int);
|
1052 |
+
void fcircle(int, int, int);
|
1053 |
+
|
1054 |
+
/* text output to a VGA display */
|
1055 |
+
void vgabegin();
|
1056 |
+
int vgastat(char);
|
1057 |
+
void vgawrite(char);
|
1058 |
+
|
1059 |
+
/* generic display code */
|
1060 |
+
void dspwrite(char);
|
1061 |
+
void dspbegin();
|
1062 |
+
int dspstat(char);
|
1063 |
+
char dspwaitonscroll();
|
1064 |
+
char dspactive();
|
1065 |
+
void dspsetupdatemode(char);
|
1066 |
+
char dspgetupdatemode();
|
1067 |
+
void dspgraphupdate();
|
1068 |
+
void dspsetscrollmode(char, short);
|
1069 |
+
void dspsetcursor(short, short);
|
1070 |
+
void dspbufferclear();
|
1071 |
+
void dspscroll(mem_t, mem_t);
|
1072 |
+
void dspreversescroll(mem_t);
|
1073 |
+
void dspvt52(char *);
|
1074 |
+
|
1075 |
+
/* real time clock */
|
1076 |
+
char* rtcmkstr();
|
1077 |
+
void rtcset(uint8_t, short);
|
1078 |
+
short rtcget(short);
|
1079 |
+
|
1080 |
+
/* network and mqtt functions */
|
1081 |
+
void netbegin();
|
1082 |
+
char netconnected();
|
1083 |
+
void mqttsetname();
|
1084 |
+
void mqttbegin();
|
1085 |
+
int mqttstat(char);
|
1086 |
+
int mqttstate();
|
1087 |
+
void mqttsubscribe(char*);
|
1088 |
+
void mqttsettopic(char*);
|
1089 |
+
void mqttouts(char *, short);
|
1090 |
+
void mqttins(char *, short);
|
1091 |
+
char mqttinch();
|
1092 |
+
|
1093 |
+
/* low level EEPROM handling */
|
1094 |
+
void ebegin();
|
1095 |
+
void eflush();
|
1096 |
+
address_t elength();
|
1097 |
+
mem_t eread(address_t);
|
1098 |
+
void eupdate(address_t, mem_t);
|
1099 |
+
|
1100 |
+
/* arduino io functions */
|
1101 |
+
void aread();
|
1102 |
+
void dread();
|
1103 |
+
void awrite(address_t, address_t);
|
1104 |
+
void dwrite(address_t, address_t);
|
1105 |
+
void pinm(address_t, address_t);
|
1106 |
+
void bmillis();
|
1107 |
+
void bpulsein();
|
1108 |
+
void xpulse();
|
1109 |
+
void bpulseout(short);
|
1110 |
+
void btone(short);
|
1111 |
+
|
1112 |
+
/* timing control for ESP and network */
|
1113 |
+
void byield();
|
1114 |
+
void bdelay(unsigned long);
|
1115 |
+
void fastticker();
|
1116 |
+
void yieldfunction();
|
1117 |
+
void longyieldfunction();
|
1118 |
+
|
1119 |
+
/* the file interface */
|
1120 |
+
char* mkfilename(const char*);
|
1121 |
+
const char* rmrootfsprefix(const char*);
|
1122 |
+
void fsbegin(char);
|
1123 |
+
int fsstat(char);
|
1124 |
+
void filewrite(char);
|
1125 |
+
char fileread();
|
1126 |
+
char ifileopen(const char*);
|
1127 |
+
void ifileclose();
|
1128 |
+
char ofileopen(char*, const char*);
|
1129 |
+
void ofileclose();
|
1130 |
+
int fileavailable();
|
1131 |
+
void rootopen();
|
1132 |
+
int rootnextfile();
|
1133 |
+
int rootisfile();
|
1134 |
+
const char* rootfilename();
|
1135 |
+
long rootfilesize();
|
1136 |
+
void rootfileclose();
|
1137 |
+
void rootclose();
|
1138 |
+
void removefile(char*);
|
1139 |
+
void formatdisk(short);
|
1140 |
+
|
1141 |
+
/* low level serial code */
|
1142 |
+
void picogetchar(char);
|
1143 |
+
void picowrite(char);
|
1144 |
+
void picobegin(unsigned long);
|
1145 |
+
void picoins(char, short);
|
1146 |
+
void serialbegin();
|
1147 |
+
int serialstat(char);
|
1148 |
+
char serialread();
|
1149 |
+
void serialwrite(char);
|
1150 |
+
short serialcheckch();
|
1151 |
+
short serialavailable();
|
1152 |
+
void serialflush();
|
1153 |
+
void consins(char*, short);
|
1154 |
+
void prtbegin();
|
1155 |
+
int prtstat(char);
|
1156 |
+
void prtset(int);
|
1157 |
+
char prtopen(char *, int);
|
1158 |
+
void prtclose();
|
1159 |
+
char prtread();
|
1160 |
+
void prtwrite(char);
|
1161 |
+
short prtcheckch();
|
1162 |
+
short prtavailable();
|
1163 |
+
|
1164 |
+
/* generic wire access */
|
1165 |
+
void wirebegin();
|
1166 |
+
int wirestat(char);
|
1167 |
+
void wireopen(char, char);
|
1168 |
+
void wireins(char*, uint8_t);
|
1169 |
+
void wireouts(char*, uint8_t);
|
1170 |
+
short wireavailable();
|
1171 |
+
short wirereadbyte(short);
|
1172 |
+
void wirewritebyte(short, short);
|
1173 |
+
|
1174 |
+
/* RF24 radio input */
|
1175 |
+
int radiostat(char);
|
1176 |
+
void radioset(int);
|
1177 |
+
#ifdef ARDUINO
|
1178 |
+
uint64_t pipeaddr(char*);
|
1179 |
+
#else
|
1180 |
+
long pipeaddr(char*);
|
1181 |
+
#endif
|
1182 |
+
void iradioopen(char*);
|
1183 |
+
void oradioopen(char*);
|
1184 |
+
void radioins(char*, short);
|
1185 |
+
void radioouts(char* , short);
|
1186 |
+
short radioavailable();
|
1187 |
+
|
1188 |
+
/* sensor control */
|
1189 |
+
void sensorbegin();
|
1190 |
+
number_t sensorread(short, short);
|
1191 |
+
|
1192 |
+
/* SPI RAM code */
|
1193 |
+
address_t spirambegin();
|
1194 |
+
void spiramrawwrite(address_t, mem_t);
|
1195 |
+
mem_t spiramrawread(address_t );
|
1196 |
+
|
1197 |
+
/*
|
1198 |
+
* Layer 0 functions - I/O and memory management
|
1199 |
+
*/
|
1200 |
+
|
1201 |
+
/* make room for BASIC */
|
1202 |
+
address_t ballocmem();
|
1203 |
+
|
1204 |
+
/* handle files im EEPROM */
|
1205 |
+
void eload();
|
1206 |
+
void esave();
|
1207 |
+
char autorun();
|
1208 |
+
|
1209 |
+
/* the variable heap from Apple 1 BASIC */
|
1210 |
+
address_t bmalloc(mem_t, mem_t, mem_t, address_t);
|
1211 |
+
address_t bfind(mem_t, mem_t, mem_t);
|
1212 |
+
address_t bfree(mem_t, mem_t, mem_t);
|
1213 |
+
address_t blength (mem_t, mem_t, mem_t);
|
1214 |
+
|
1215 |
+
/* normal variables of number_t */
|
1216 |
+
number_t getvar(mem_t, mem_t);
|
1217 |
+
void setvar(mem_t, mem_t, number_t);
|
1218 |
+
void clrvars();
|
1219 |
+
|
1220 |
+
/* low level memory access packing n*8bit bit into n 8 bit objects
|
1221 |
+
e* is for Arduino EEPROM */
|
1222 |
+
void getnumber(address_t, mem_t);
|
1223 |
+
void setnumber(address_t, mem_t);
|
1224 |
+
void egetnumber(address_t, mem_t);
|
1225 |
+
void esetnumber(address_t, mem_t);
|
1226 |
+
void pgetnumber(address_t, mem_t);
|
1227 |
+
|
1228 |
+
/* array and string handling */
|
1229 |
+
/* the multidim extension is experimental, here only 2 array dimensions implemented as test */
|
1230 |
+
address_t createarray(mem_t, mem_t, address_t, address_t);
|
1231 |
+
void array(mem_t, mem_t, mem_t, address_t, address_t, number_t*);
|
1232 |
+
address_t createstring(char, char, address_t, address_t);
|
1233 |
+
char* getstring(char, char, address_t, address_t);
|
1234 |
+
number_t arraydim(char, char);
|
1235 |
+
address_t stringdim(char, char);
|
1236 |
+
address_t lenstring(char, char, address_t);
|
1237 |
+
void setstringlength(char, char, address_t, address_t);
|
1238 |
+
void setstring(char, char, address_t, char *, address_t, address_t);
|
1239 |
+
|
1240 |
+
/* the user defined extension functions */
|
1241 |
+
number_t getusrvar();
|
1242 |
+
void setusrvar(number_t);
|
1243 |
+
number_t getusrarray(address_t);
|
1244 |
+
void setusrarray(address_t, number_t);
|
1245 |
+
void makeusrstring();
|
1246 |
+
number_t usrfunction(address_t, number_t);
|
1247 |
+
void usrcall(address_t);
|
1248 |
+
|
1249 |
+
/* get keywords and tokens from PROGMEM */
|
1250 |
+
char* getkeyword(unsigned short);
|
1251 |
+
char* getmessage(char);
|
1252 |
+
signed char gettokenvalue(char);
|
1253 |
+
void printmessage(char);
|
1254 |
+
|
1255 |
+
/* error handling */
|
1256 |
+
void error(token_t);
|
1257 |
+
void reseterror();
|
1258 |
+
void debugtoken();
|
1259 |
+
void bdebug(const char*);
|
1260 |
+
|
1261 |
+
/* the arithemtic stack */
|
1262 |
+
void push(number_t);
|
1263 |
+
number_t pop();
|
1264 |
+
address_t popaddress();
|
1265 |
+
void drop();
|
1266 |
+
void clearst();
|
1267 |
+
|
1268 |
+
/* READ DATA handling */
|
1269 |
+
void clrdata();
|
1270 |
+
|
1271 |
+
/* FOR NEXT GOSUB stacks */
|
1272 |
+
void pushforstack();
|
1273 |
+
void popforstack();
|
1274 |
+
void dropforstack();
|
1275 |
+
void clrforstack();
|
1276 |
+
void pushgosubstack(mem_t);
|
1277 |
+
void popgosubstack();
|
1278 |
+
void dropgosubstack();
|
1279 |
+
void clrgosubstack();
|
1280 |
+
|
1281 |
+
/* general I/O initialisation */
|
1282 |
+
void ioinit();
|
1283 |
+
void iodefaults();
|
1284 |
+
|
1285 |
+
/* signal handling */
|
1286 |
+
void signalon();
|
1287 |
+
void signaloff();
|
1288 |
+
void signalhandler(int);
|
1289 |
+
|
1290 |
+
/* character and string I/O functions */
|
1291 |
+
/* we live in world where char may be signed or unsigned and keep it
|
1292 |
+
that way on the lowest level, hence this function, fully defined here,
|
1293 |
+
mostly inlined anyway*/
|
1294 |
+
int cheof(int c) { if ((c == -1) || (c == 255)) return 1; else return 0; }
|
1295 |
+
/* input */
|
1296 |
+
char inch();
|
1297 |
+
char checkch();
|
1298 |
+
short availch();
|
1299 |
+
void inb(char*, index_t);
|
1300 |
+
void ins(char*, address_t);
|
1301 |
+
|
1302 |
+
/* output */
|
1303 |
+
void outch(char);
|
1304 |
+
void outcr();
|
1305 |
+
void outspc();
|
1306 |
+
void outs(char*, address_t);
|
1307 |
+
void outsc(const char*);
|
1308 |
+
void outscf(const char *, index_t);
|
1309 |
+
|
1310 |
+
/* I/O of number_t - floats and integers */
|
1311 |
+
address_t parsenumber(char*, number_t*);
|
1312 |
+
address_t parsenumber2(char*, number_t*);
|
1313 |
+
address_t writenumber(char*, wnumber_t);
|
1314 |
+
address_t writenumber2(char*, number_t);
|
1315 |
+
address_t tinydtostrf(number_t, index_t, char*);
|
1316 |
+
char innumber(number_t*);
|
1317 |
+
void outnumber(number_t);
|
1318 |
+
|
1319 |
+
/*
|
1320 |
+
* Layer 1 functions, provide data and do the heavy lifting
|
1321 |
+
* for layer 2 including lexical analysis, storing programs
|
1322 |
+
* and expression evaluation
|
1323 |
+
*/
|
1324 |
+
|
1325 |
+
/* lexical analysis */
|
1326 |
+
void whitespaces();
|
1327 |
+
void nexttoken();
|
1328 |
+
|
1329 |
+
/* storing and retrieving programs */
|
1330 |
+
char nomemory(number_t);
|
1331 |
+
void storetoken();
|
1332 |
+
mem_t memread(address_t);
|
1333 |
+
mem_t memread2(address_t);
|
1334 |
+
void memwrite2(address_t, mem_t);
|
1335 |
+
void gettoken();
|
1336 |
+
void firstline();
|
1337 |
+
void nextline();
|
1338 |
+
|
1339 |
+
void clrlinecache();
|
1340 |
+
void addlinecache(address_t, address_t);
|
1341 |
+
address_t findinlinecache(address_t);
|
1342 |
+
void findline(address_t);
|
1343 |
+
address_t myline(address_t);
|
1344 |
+
void moveblock(address_t, address_t, address_t);
|
1345 |
+
void zeroblock(address_t, address_t);
|
1346 |
+
void diag();
|
1347 |
+
void storeline();
|
1348 |
+
|
1349 |
+
/* read arguments from the token stream and process them */
|
1350 |
+
char termsymbol();
|
1351 |
+
char expect(token_t, mem_t);
|
1352 |
+
char expectexpr();
|
1353 |
+
void parsearguments();
|
1354 |
+
void parsenarguments(char);
|
1355 |
+
void parsesubscripts();
|
1356 |
+
void parsefunction(void (*)(), short);
|
1357 |
+
void parseoperator(void (*)());
|
1358 |
+
void parsesubstring();
|
1359 |
+
|
1360 |
+
/* mathematics and other functions for int and float */
|
1361 |
+
void xabs();
|
1362 |
+
void xsgn();
|
1363 |
+
void xpeek();
|
1364 |
+
void xmap();
|
1365 |
+
void rnd();
|
1366 |
+
void sqr();
|
1367 |
+
void xpow();
|
1368 |
+
number_t bpow(number_t, number_t);
|
1369 |
+
|
1370 |
+
/* string values and string evaluation */
|
1371 |
+
char stringvalue();
|
1372 |
+
void streval();
|
1373 |
+
|
1374 |
+
/* floating point functions */
|
1375 |
+
void xsin();
|
1376 |
+
void xcos();
|
1377 |
+
void xtan();
|
1378 |
+
void xatan();
|
1379 |
+
void xlog();
|
1380 |
+
void xexp();
|
1381 |
+
void xint();
|
1382 |
+
|
1383 |
+
/* expression evaluation */
|
1384 |
+
void factor();
|
1385 |
+
void term();
|
1386 |
+
void addexpression();
|
1387 |
+
void compexpression();
|
1388 |
+
void notexpression();
|
1389 |
+
void andexpression();
|
1390 |
+
void expression();
|
1391 |
+
|
1392 |
+
/*
|
1393 |
+
* Layer 2 - statements and functions
|
1394 |
+
* use the global variables
|
1395 |
+
*/
|
1396 |
+
|
1397 |
+
/* basic commands of the core language set */
|
1398 |
+
void xprint();
|
1399 |
+
void lefthandside(address_t*, address_t*, address_t*, mem_t*);
|
1400 |
+
void assignnumber(signed char, char, char, address_t, address_t, char);
|
1401 |
+
void assignment();
|
1402 |
+
void showprompt();
|
1403 |
+
void xinput();
|
1404 |
+
void xgoto();
|
1405 |
+
void xreturn();
|
1406 |
+
void xif();
|
1407 |
+
|
1408 |
+
/* FOR NEXT loops */
|
1409 |
+
void findnextcmd();
|
1410 |
+
void findbraket(token_t, token_t);
|
1411 |
+
void xfor();
|
1412 |
+
void xbreak();
|
1413 |
+
void xcont();
|
1414 |
+
void xnext();
|
1415 |
+
|
1416 |
+
/* WHILE WEND*/
|
1417 |
+
void xwhile();
|
1418 |
+
void xwend();
|
1419 |
+
|
1420 |
+
/* REPEAT UNTIL */
|
1421 |
+
void xrepeat();
|
1422 |
+
void xuntil();
|
1423 |
+
|
1424 |
+
/* control commands and misc */
|
1425 |
+
void outputtoken();
|
1426 |
+
void xlist();
|
1427 |
+
void xrun();
|
1428 |
+
void xnew();
|
1429 |
+
void xrem();
|
1430 |
+
void xclr();
|
1431 |
+
void xdim();
|
1432 |
+
void xpoke();
|
1433 |
+
void xtab();
|
1434 |
+
void xdump();
|
1435 |
+
void dumpmem(address_t, address_t, char);
|
1436 |
+
void xlocate();
|
1437 |
+
|
1438 |
+
/* file access and other i/o */
|
1439 |
+
void stringtobuffer(char*);
|
1440 |
+
void getfilename(char*, char);
|
1441 |
+
void xsave();
|
1442 |
+
void xload(const char*);
|
1443 |
+
void xget();
|
1444 |
+
void xput();
|
1445 |
+
void xset();
|
1446 |
+
void xnetstat();
|
1447 |
+
|
1448 |
+
/* Arduino IO control interface */
|
1449 |
+
void xdwrite();
|
1450 |
+
void xawrite();
|
1451 |
+
void xpinm();
|
1452 |
+
void xdelay();
|
1453 |
+
void xtone();
|
1454 |
+
|
1455 |
+
/* graphics commands */
|
1456 |
+
void xcolor();
|
1457 |
+
void xplot();
|
1458 |
+
void xline();
|
1459 |
+
void xrect();
|
1460 |
+
void xcircle();
|
1461 |
+
void xfrect();
|
1462 |
+
void xfcircle();
|
1463 |
+
|
1464 |
+
/* the darkarts */
|
1465 |
+
void xmalloc();
|
1466 |
+
void xfind();
|
1467 |
+
void xeval();
|
1468 |
+
|
1469 |
+
/* IoT commands */
|
1470 |
+
void xassign();
|
1471 |
+
void xavail();
|
1472 |
+
void xfsensor();
|
1473 |
+
void xsleep();
|
1474 |
+
void xwire();
|
1475 |
+
void xfwire();
|
1476 |
+
|
1477 |
+
/* timers */
|
1478 |
+
void xafter();
|
1479 |
+
void xevent();
|
1480 |
+
|
1481 |
+
/* File I/O functions */
|
1482 |
+
char streq(const char*, char*);
|
1483 |
+
void xcatalog();
|
1484 |
+
void xdelete();
|
1485 |
+
void xopen();
|
1486 |
+
void xfopen();
|
1487 |
+
void xclose();
|
1488 |
+
void xfdisk();
|
1489 |
+
|
1490 |
+
/* low level access functions */
|
1491 |
+
void xcall();
|
1492 |
+
void xusr();
|
1493 |
+
|
1494 |
+
/* the dartmouth stuff */
|
1495 |
+
void xdata();
|
1496 |
+
void nextdatarecord();
|
1497 |
+
void xread();
|
1498 |
+
void xrestore();
|
1499 |
+
void xdef();
|
1500 |
+
void xfn();
|
1501 |
+
void xon();
|
1502 |
+
|
1503 |
+
/* timers and interrupts */
|
1504 |
+
void xtimer();
|
1505 |
+
void resettimer(btimer_t*);
|
1506 |
+
|
1507 |
+
/* structured BASIC extensions */
|
1508 |
+
void xwhile();
|
1509 |
+
void xwend();
|
1510 |
+
void xrepeat();
|
1511 |
+
void xuntil();
|
1512 |
+
void xswitch();
|
1513 |
+
void xcase();
|
1514 |
+
void xendswitch();
|
1515 |
+
|
1516 |
+
/* the emulation of tone using the byield loop */
|
1517 |
+
void toggletone();
|
1518 |
+
void playtone(int, int, int);
|
1519 |
+
|
1520 |
+
/* the statement loop */
|
1521 |
+
void statement();
|
1522 |
+
|
1523 |
+
/* the extension functions */
|
1524 |
+
void bsetup();
|
1525 |
+
void bloop();
|
1526 |
+
|
data/Basic1/hardware-arduino.h
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic1/hardware-posix.h
ADDED
@@ -0,0 +1,1502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*
|
3 |
+
* $Id: hardware-posix.h,v 1.7 2023/07/16 14:17:08 stefan Exp stefan $
|
4 |
+
*
|
5 |
+
* Stefan's basic interpreter
|
6 |
+
*
|
7 |
+
* Playing around with frugal programming. See the licence file on
|
8 |
+
* https://github.com/slviajero/tinybasic for copyright/left.
|
9 |
+
* (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
|
10 |
+
*
|
11 |
+
* Author: Stefan Lenz, [email protected]
|
12 |
+
*
|
13 |
+
* Hardware definition file coming with basic.c aka TinybasicArduino.ino
|
14 |
+
*
|
15 |
+
* Link to some of the POSIX OS features to mimic a microcontroller platform
|
16 |
+
* See hardware-arduino for more details on the interface.
|
17 |
+
*
|
18 |
+
* Supported: filesystem, real time clock, (serial) I/O on the text console
|
19 |
+
* Not supported: radio, wire, SPI, MQTT
|
20 |
+
*
|
21 |
+
* Partially supported: Wiring library on Raspberry PI
|
22 |
+
*
|
23 |
+
*/
|
24 |
+
|
25 |
+
#if ! defined(ARDUINO) && ! defined(__HARDWAREH__)
|
26 |
+
#define __HARDWAREH__
|
27 |
+
|
28 |
+
/*
|
29 |
+
* Hardware flags of the POSIX systems
|
30 |
+
* POSIXTERMINAL, POSIXVT52TOANSI: ensure compatibility of BASIC programs
|
31 |
+
* control characters of BASIC are translated to ANSI, bringing the Aruino
|
32 |
+
* VT52 commands to POSIX
|
33 |
+
* POSIXSIGNALS: enables signal handling of ^C interrupting programs
|
34 |
+
* POSIXNONBLOCKING: non blocking I/O to handle GET and the BREAKCHAR
|
35 |
+
* tricky on DOS, not very portable, experimental, use signals instead
|
36 |
+
* POSIXFRAMEBUFFER: directly draw to the frame buffer of Raspberry PI
|
37 |
+
* only tested on this platform
|
38 |
+
* POSIXWIRE: simple Raspberry PI wire code
|
39 |
+
* POSIXMQTT: analogous to ARDUINOMQTT, send and receive MQTT messages (unfinished)
|
40 |
+
* POSIXWIRING: use the (deprectated) wiring code for gpio on Raspberry Pi
|
41 |
+
* POSIXPIGPIO: use the pigpio library on a Raspberry PI
|
42 |
+
*/
|
43 |
+
|
44 |
+
#define POSIXTERMINAL
|
45 |
+
#define POSIXVT52TOANSI
|
46 |
+
#define POSIXSIGNALS
|
47 |
+
#undef POSIXNONBLOCKING
|
48 |
+
#undef POSIXFRAMEBUFFER
|
49 |
+
#undef POSIXWIRE
|
50 |
+
#undef POSIXMQTT
|
51 |
+
#undef POSIXWIRING
|
52 |
+
#undef POSIXPIGPIO
|
53 |
+
|
54 |
+
/* simulates SPI RAM, only test code, keep undefed if you don't want to do something special */
|
55 |
+
#undef SPIRAMSIMULATOR
|
56 |
+
|
57 |
+
/* use a serial port as printer interface - unfinished - similar to Arduino */
|
58 |
+
#define ARDUINOPRT
|
59 |
+
|
60 |
+
/* used pins and other parameters */
|
61 |
+
|
62 |
+
/* set this is you want pin 4 on low interrupting the interpreter */
|
63 |
+
/* #define BREAKPIN 4 */
|
64 |
+
#undef BREAKPIN
|
65 |
+
|
66 |
+
/* the SIGNAL the interpreters listens to for interrupt */
|
67 |
+
#define BREAKSIGNAL SIGINT
|
68 |
+
|
69 |
+
/* in case of non blocking IO turn on background tasks */
|
70 |
+
#ifdef POSIXNONBLOCKING
|
71 |
+
#define BASICBGTASK
|
72 |
+
#endif
|
73 |
+
|
74 |
+
/* frame buffer health check - currently only supported on Raspberry */
|
75 |
+
#ifndef RASPPI
|
76 |
+
#undef POSIXFRAMEBUFFER
|
77 |
+
#endif
|
78 |
+
|
79 |
+
/* wire parameters for Raspberry*/
|
80 |
+
#define POSIXI2CBUS 1
|
81 |
+
|
82 |
+
/* Wiring Code, which library to use */
|
83 |
+
#ifdef POSIXWIRING
|
84 |
+
#include <wiringPi.h>
|
85 |
+
#endif
|
86 |
+
|
87 |
+
#ifdef POSIXPIGPIO
|
88 |
+
#include <pigpiod_if2.h>
|
89 |
+
#undef POSIXWIRING
|
90 |
+
static int pigpio_pi = 0;
|
91 |
+
#endif
|
92 |
+
|
93 |
+
/*
|
94 |
+
* the system type and system capabilities
|
95 |
+
*/
|
96 |
+
|
97 |
+
#if defined(MSDOS)
|
98 |
+
const char bsystype = SYSTYPE_MSDOS
|
99 |
+
#elif defined(RASPPI)
|
100 |
+
const char bsystype = SYSTYPE_PASPPI
|
101 |
+
#elif defined(MINGW)
|
102 |
+
const char bsystype = SYSTYPE_MINGW
|
103 |
+
#else
|
104 |
+
const char bsystype = SYSTYPE_POSIX;
|
105 |
+
#endif
|
106 |
+
|
107 |
+
/*
|
108 |
+
* Arduino default serial baudrate and serial flags for the
|
109 |
+
* two supported serial interfaces. Set to 0 on POSIX OSes
|
110 |
+
*/
|
111 |
+
const int serial_baudrate = 0;
|
112 |
+
const int serial1_baudrate = 0;
|
113 |
+
char sendcr = 0;
|
114 |
+
short blockmode = 0;
|
115 |
+
|
116 |
+
/* handling time, remember when we started, needed in millis() */
|
117 |
+
struct timeb start_time;
|
118 |
+
void timeinit() { ftime(&start_time); }
|
119 |
+
|
120 |
+
/* starting wiring for raspberry */
|
121 |
+
void wiringbegin() {
|
122 |
+
#ifdef POSIXWIRING
|
123 |
+
wiringPiSetup();
|
124 |
+
#endif
|
125 |
+
#ifdef POSIXPIGPIO
|
126 |
+
pigpio_pi=pigpio_start("localhost","8888");
|
127 |
+
printf("** GPIO started with result %d\n", pigpio_pi);
|
128 |
+
printf("** pigpio version %d.\n", get_pigpio_version(pigpio_pi));
|
129 |
+
printf("** Hardware revision %d.\n", get_hardware_revision(pigpio_pi));
|
130 |
+
#endif
|
131 |
+
}
|
132 |
+
|
133 |
+
/*
|
134 |
+
* signal handling
|
135 |
+
*/
|
136 |
+
#ifdef POSIXSIGNALS
|
137 |
+
#include <signal.h>
|
138 |
+
mem_t breaksignal = 0;
|
139 |
+
|
140 |
+
/* simple signal handler */
|
141 |
+
void signalhandler(int sig){
|
142 |
+
breaksignal=1;
|
143 |
+
signal(BREAKSIGNAL, signalhandler);
|
144 |
+
}
|
145 |
+
|
146 |
+
/* activate signal handling */
|
147 |
+
void signalon() {
|
148 |
+
signal(BREAKSIGNAL, signalhandler);
|
149 |
+
}
|
150 |
+
|
151 |
+
/* deactivate signal handling unused and not yet done*/
|
152 |
+
void signaloff() {}
|
153 |
+
|
154 |
+
#endif
|
155 |
+
|
156 |
+
/*
|
157 |
+
* helper functions OS, heuristic on how much memory is
|
158 |
+
* available in BASIC
|
159 |
+
*/
|
160 |
+
long freememorysize() {
|
161 |
+
#ifdef MSDOS
|
162 |
+
return 48000;
|
163 |
+
#else
|
164 |
+
return 65536;
|
165 |
+
#endif
|
166 |
+
}
|
167 |
+
|
168 |
+
long freeRam() {
|
169 |
+
return freememorysize();
|
170 |
+
}
|
171 |
+
|
172 |
+
/*
|
173 |
+
* the sleep and restart functions
|
174 |
+
*/
|
175 |
+
void restartsystem() { exit(0);}
|
176 |
+
void activatesleep(long t) {}
|
177 |
+
|
178 |
+
/*
|
179 |
+
* start the SPI bus
|
180 |
+
*/
|
181 |
+
void spibegin() {}
|
182 |
+
|
183 |
+
|
184 |
+
/*
|
185 |
+
* DISPLAY driver code section, the hardware models define a set of
|
186 |
+
* of functions and definitions needed for the display driver. These are
|
187 |
+
*
|
188 |
+
* dsp_rows, dsp_columns: size of the display
|
189 |
+
* dspbegin(), dspprintchar(c, col, row), dspclear()
|
190 |
+
*
|
191 |
+
* All displays which have this functions can be used with the
|
192 |
+
* generic display driver below.
|
193 |
+
*
|
194 |
+
* Graphics displays need to implement the functions
|
195 |
+
*
|
196 |
+
* rgbcolor(), vgacolor()
|
197 |
+
* plot(), line(), rect(), frect(), circle(), fcircle()
|
198 |
+
*
|
199 |
+
* Color is currently either 24 bit or 4 bit 16 color vga.
|
200 |
+
*/
|
201 |
+
const int dsp_rows=0;
|
202 |
+
const int dsp_columns=0;
|
203 |
+
void dspsetupdatemode(char c) {}
|
204 |
+
void dspwrite(char c){}
|
205 |
+
void dspbegin() {}
|
206 |
+
int dspstat(char c) {return 0; }
|
207 |
+
char dspwaitonscroll() { return 0; }
|
208 |
+
char dspactive() {return 0; }
|
209 |
+
void dspsetscrollmode(char c, short l) {}
|
210 |
+
void dspsetcursor(short c, short r) {}
|
211 |
+
|
212 |
+
#ifndef POSIXFRAMEBUFFER
|
213 |
+
/* these are the graphics commands */
|
214 |
+
void rgbcolor(int r, int g, int b) {}
|
215 |
+
void vgacolor(short c) {}
|
216 |
+
void plot(int x, int y) {}
|
217 |
+
void line(int x0, int y0, int x1, int y1) {}
|
218 |
+
void rect(int x0, int y0, int x1, int y1) {}
|
219 |
+
void frect(int x0, int y0, int x1, int y1) {}
|
220 |
+
void circle(int x0, int y0, int r) {}
|
221 |
+
void fcircle(int x0, int y0, int r) {}
|
222 |
+
|
223 |
+
/* stubs for the vga code part analogous to ESP32 */
|
224 |
+
void vgabegin(){}
|
225 |
+
void vgawrite(char c){}
|
226 |
+
#else
|
227 |
+
/*
|
228 |
+
* This is the first draft of the linux framebuffer code
|
229 |
+
* currently very raw, works only if the framebuffer is 24 bit
|
230 |
+
* very few checks, all kind of stuff can go wrong here.
|
231 |
+
*
|
232 |
+
* Main ideas and some part of the code came from this
|
233 |
+
* article https://www.mikrocontroller.net/topic/379335
|
234 |
+
* by Andy W.
|
235 |
+
*
|
236 |
+
* Bresenham's algorithm came from the Wikipedia article
|
237 |
+
* and this very comprehensive discussion
|
238 |
+
* http://members.chello.at/~easyfilter/bresenham.html
|
239 |
+
* by Alois Zingl from the Vienna Technikum. I also recommend
|
240 |
+
* his thesis: http://members.chello.at/%7Eeasyfilter/Bresenham.pdf
|
241 |
+
*
|
242 |
+
*/
|
243 |
+
#include <sys/fcntl.h>
|
244 |
+
#include <sys/ioctl.h>
|
245 |
+
#include <linux/fb.h>
|
246 |
+
#include <sys/mman.h>
|
247 |
+
#include <string.h>
|
248 |
+
|
249 |
+
/* 'global' variables to store screen info */
|
250 |
+
char *framemem = 0;
|
251 |
+
int framedesc = 0;
|
252 |
+
|
253 |
+
/* info from the frame buffer itself */
|
254 |
+
struct fb_var_screeninfo vinfo;
|
255 |
+
struct fb_fix_screeninfo finfo;
|
256 |
+
struct fb_var_screeninfo orig_vinfo;
|
257 |
+
|
258 |
+
/* the color variable of the frame buffer */
|
259 |
+
long framecolor = 0xffffff;
|
260 |
+
int framevgacolor = 0x0f;
|
261 |
+
long framescreensize = 0;
|
262 |
+
int framecolordepth = 0;
|
263 |
+
|
264 |
+
/* prepare the framebuffer device */
|
265 |
+
void vgabegin() {
|
266 |
+
|
267 |
+
/* see if we can open the framebuffer device */
|
268 |
+
framedesc = open("/dev/fb0", O_RDWR);
|
269 |
+
if (!framedesc) {
|
270 |
+
printf("** error opening frame buffer \n");
|
271 |
+
return;
|
272 |
+
}
|
273 |
+
|
274 |
+
/* now get the variable info of the screen */
|
275 |
+
if (ioctl(framedesc, FBIOGET_VSCREENINFO, &vinfo)) {
|
276 |
+
printf("** error reading screen information \n");
|
277 |
+
return;
|
278 |
+
}
|
279 |
+
printf("** detected screen %dx%d, %dbpp \n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
|
280 |
+
|
281 |
+
/* BASIC currently does 24 bit color only */
|
282 |
+
memcpy(&orig_vinfo, &vinfo, sizeof(struct fb_var_screeninfo));
|
283 |
+
/*
|
284 |
+
vinfo.bits_per_pixel = 24;
|
285 |
+
if (ioctl(framedesc, FBIOPUT_VSCREENINFO, &vinfo)) {
|
286 |
+
printf("** error setting variable information \n");
|
287 |
+
return;
|
288 |
+
}
|
289 |
+
*/
|
290 |
+
|
291 |
+
/* how much color have we got */
|
292 |
+
framecolordepth = vinfo.bits_per_pixel;
|
293 |
+
|
294 |
+
/* get the fixed information of the screen */
|
295 |
+
if (ioctl(framedesc, FBIOGET_FSCREENINFO, &finfo)) {
|
296 |
+
printf("Error reading fixed information.\n");
|
297 |
+
return;
|
298 |
+
}
|
299 |
+
|
300 |
+
/* now ready to memory map the screen - evil, we assume 24 bit without checking */
|
301 |
+
|
302 |
+
framescreensize = (framecolordepth/8) * vinfo.xres * vinfo.yres;
|
303 |
+
framemem = (char*)mmap(0, framescreensize, PROT_READ | PROT_WRITE, MAP_SHARED, framedesc, 0);
|
304 |
+
if ((int)framemem == -1) {
|
305 |
+
printf("** error failed to mmap.\n");
|
306 |
+
framemem=0;
|
307 |
+
return;
|
308 |
+
}
|
309 |
+
|
310 |
+
/* if all went well we have valid non -1 framemem and can continue */
|
311 |
+
}
|
312 |
+
|
313 |
+
/* this function does not exist in the ESP32 world because we don't care there */
|
314 |
+
void vgaend() {
|
315 |
+
if ((int)framemem) munmap(framemem, framescreensize);
|
316 |
+
if (ioctl(framedesc, FBIOPUT_VSCREENINFO, &orig_vinfo)) {
|
317 |
+
printf("** error re-setting variable information \n");
|
318 |
+
}
|
319 |
+
close(framedesc);
|
320 |
+
}
|
321 |
+
|
322 |
+
/* set the color variable depending on the color depth*/
|
323 |
+
void rgbcolor(int r, int g, int b) {
|
324 |
+
switch (framecolordepth/8) {
|
325 |
+
case 4:
|
326 |
+
framecolor = (((long)r << 16) & 0x00ff0000) | (((long)g << 8) & 0x0000ff00) | ((long)b & 0x000000ff); /* untested */
|
327 |
+
break;
|
328 |
+
case 3:
|
329 |
+
framecolor = (((long)r << 16) & 0x00ff0000) | (((long)g << 8) & 0x0000ff00) | ((long)b & 0x000000ff);
|
330 |
+
break;
|
331 |
+
case 2:
|
332 |
+
framecolor = ((long) (r & 0xff) >> 3) << 10 | ((long) (g & 0xff) >> 2) << 6 | ((long) (b & 0xff) >> 3); /* untested */
|
333 |
+
break;
|
334 |
+
case 1:
|
335 |
+
framecolor = ((long) (r & 0xff) >> 5) << 5 | ((long) (g & 0xff) >> 5) << 2 | ((long) (b & 0xff) >> 6); /* untested */
|
336 |
+
break;
|
337 |
+
}
|
338 |
+
}
|
339 |
+
|
340 |
+
/* this is taken from the Arduino TFT code */
|
341 |
+
void vgacolor(short c) {
|
342 |
+
short base=128;
|
343 |
+
framevgacolor=c;
|
344 |
+
if (c==8) { rgbcolor(64, 64, 64); return; }
|
345 |
+
if (c>8) base=255;
|
346 |
+
rgbcolor(base*(c&1), base*((c&2)/2), base*((c&4)/4));
|
347 |
+
}
|
348 |
+
|
349 |
+
/* plot directly into the framebuffer */
|
350 |
+
void plot(int x, int y) {
|
351 |
+
unsigned long pix_offset;
|
352 |
+
|
353 |
+
/* is everything in range, no error here */
|
354 |
+
if (x < 0 || y < 0 || x >= vinfo.xres || y >= vinfo.yres) return;
|
355 |
+
|
356 |
+
/* find the memory location */
|
357 |
+
pix_offset = (framecolordepth/8) * x + y * finfo.line_length;
|
358 |
+
|
359 |
+
if (pix_offset < 0 || pix_offset+ (framecolordepth/8-1) > framescreensize) return;
|
360 |
+
|
361 |
+
/* write to the buffer */
|
362 |
+
switch (framecolordepth/8) {
|
363 |
+
case 4:
|
364 |
+
*((char*)(framemem + pix_offset )) = (unsigned char)(framecolor & 0x000000ff);
|
365 |
+
*((char*)(framemem + pix_offset+1)) = (unsigned char)((framecolor >> 8) & 0x000000ff);
|
366 |
+
*((char*)(framemem + pix_offset+3)) = (unsigned char)((framecolor >> 16) & 0x000000ff);
|
367 |
+
break;
|
368 |
+
case 3:
|
369 |
+
*((char*)(framemem + pix_offset )) = (unsigned char)(framecolor & 0x000000ff);
|
370 |
+
*((char*)(framemem + pix_offset+1)) = (unsigned char)((framecolor >> 8) & 0x000000ff);
|
371 |
+
*((char*)(framemem + pix_offset+2)) = (unsigned char)((framecolor >> 16) & 0x000000ff);
|
372 |
+
break;
|
373 |
+
case 2:
|
374 |
+
*((char*)(framemem + pix_offset )) = (unsigned char)((framecolor & 0x1f) + (((framecolor >> 5) & 0x03) << 6));
|
375 |
+
*((char*)(framemem + pix_offset+1)) = (unsigned char)((framecolor >> 7) & 0xff);
|
376 |
+
break;
|
377 |
+
case 1:
|
378 |
+
*((char*)(framemem + pix_offset )) = (unsigned char)(framecolor & 0x000000ff);
|
379 |
+
break;
|
380 |
+
}
|
381 |
+
|
382 |
+
}
|
383 |
+
|
384 |
+
/* Bresenham's algorith from Wikipedia */
|
385 |
+
void line(int x0, int y0, int x1, int y1) {
|
386 |
+
int dx, dy, sx, sy;
|
387 |
+
int error, e2;
|
388 |
+
|
389 |
+
dx=abs(x0-x1);
|
390 |
+
sx=x0 < x1 ? 1 : -1;
|
391 |
+
dy=-abs(y1-y0);
|
392 |
+
sy=y0 < y1 ? 1 : -1;
|
393 |
+
error=dx+dy;
|
394 |
+
|
395 |
+
while(1) {
|
396 |
+
plot(x0, y0);
|
397 |
+
if (x0 == x1 && y0 == y1) break;
|
398 |
+
e2=2*error;
|
399 |
+
if (e2 > dy) {
|
400 |
+
if (x0 == x1) break;
|
401 |
+
error=error+dy;
|
402 |
+
x0=x0+sx;
|
403 |
+
}
|
404 |
+
if (e2 <= dx) {
|
405 |
+
if (y0 == y1) break;
|
406 |
+
error=error+dx;
|
407 |
+
y0=y0+sy;
|
408 |
+
}
|
409 |
+
}
|
410 |
+
}
|
411 |
+
|
412 |
+
/* rects could also be drawn with hline and vline */
|
413 |
+
void rect(int x0, int y0, int x1, int y1) {
|
414 |
+
line(x0, y0, x1, y0);
|
415 |
+
line(x1, y0, x1, y1);
|
416 |
+
line(x1, y1, x0, y1);
|
417 |
+
line(x0, y1, x0, y0);
|
418 |
+
}
|
419 |
+
|
420 |
+
/* filled rect, also just using line right now */
|
421 |
+
void frect(int x0, int y0, int x1, int y1) {
|
422 |
+
int dx, sx;
|
423 |
+
int x;
|
424 |
+
sx=x0 < x1 ? 1 : -1;
|
425 |
+
for(x=x0; x != x1; x=x+sx) line(x, y0, x, y1);
|
426 |
+
}
|
427 |
+
|
428 |
+
/* Bresenham for circles, based on Alois Zingl's work */
|
429 |
+
void circle(int x0, int y0, int r) {
|
430 |
+
int x, y, err;
|
431 |
+
x=-r;
|
432 |
+
y=0;
|
433 |
+
err=2-2*r;
|
434 |
+
do {
|
435 |
+
plot(x0-x, y0+y);
|
436 |
+
plot(x0-y, y0-x);
|
437 |
+
plot(x0+x, y0-y);
|
438 |
+
plot(x0+y, y0+x);
|
439 |
+
r=err;
|
440 |
+
if (r <= y) err+=++y*2+1;
|
441 |
+
if (r > x || err > y) err+=++x*2+1;
|
442 |
+
} while (x < 0);
|
443 |
+
}
|
444 |
+
|
445 |
+
/* for filled circles draw lines instead of points */
|
446 |
+
void fcircle(int x0, int y0, int r) {
|
447 |
+
int x, y, err;
|
448 |
+
x=-r;
|
449 |
+
y=0;
|
450 |
+
err=2-2*r;
|
451 |
+
do {
|
452 |
+
line(x0-x, y0+y, x0+x, y0+y);
|
453 |
+
line(x0+x, y0-y, x0-x, y0-y);
|
454 |
+
r=err;
|
455 |
+
if (r <= y) err+=++y*2+1;
|
456 |
+
if (r > x || err > y) err+=++x*2+1;
|
457 |
+
} while (x < 0);
|
458 |
+
}
|
459 |
+
|
460 |
+
/* not needed really, now, later yes ;-) */
|
461 |
+
void vgawrite(char c) {}
|
462 |
+
#endif
|
463 |
+
|
464 |
+
/*
|
465 |
+
* Keyboard code stubs
|
466 |
+
* keyboards can implement
|
467 |
+
* kbdbegin()
|
468 |
+
* they need to provide
|
469 |
+
* kbdavailable(), kbdread(), kbdcheckch()
|
470 |
+
* the later is for interrupting running BASIC code
|
471 |
+
*/
|
472 |
+
void kbdbegin() {}
|
473 |
+
int kbdstat(char c) {return 0; }
|
474 |
+
char kbdavailable(){ return 0;}
|
475 |
+
char kbdread() { return 0;}
|
476 |
+
char kbdcheckch() { return 0;}
|
477 |
+
|
478 |
+
/* vt52 code stubs - unused here - needed for basic.c */
|
479 |
+
mem_t vt52avail() {return 0;}
|
480 |
+
char vt52read() { return 0; }
|
481 |
+
|
482 |
+
/* Display driver would be here, together with vt52 */
|
483 |
+
|
484 |
+
/*
|
485 |
+
* Real Time clock code
|
486 |
+
*/
|
487 |
+
#define HASCLOCK
|
488 |
+
|
489 |
+
void rtcbegin() {}
|
490 |
+
|
491 |
+
short rtcget(short i) {
|
492 |
+
struct timeb thetime;
|
493 |
+
struct tm *ltime;
|
494 |
+
ftime(&thetime);
|
495 |
+
ltime=localtime(&thetime.time);
|
496 |
+
switch (i) {
|
497 |
+
case 0:
|
498 |
+
return ltime->tm_sec;
|
499 |
+
case 1:
|
500 |
+
return ltime->tm_min;
|
501 |
+
case 2:
|
502 |
+
return ltime->tm_hour;
|
503 |
+
case 3:
|
504 |
+
return ltime->tm_wday;
|
505 |
+
case 4:
|
506 |
+
return ltime->tm_mday;
|
507 |
+
case 5:
|
508 |
+
return ltime->tm_mon+1;
|
509 |
+
case 6:
|
510 |
+
return ltime->tm_year-100;
|
511 |
+
default:
|
512 |
+
return 0;
|
513 |
+
}
|
514 |
+
}
|
515 |
+
|
516 |
+
void rtcset(uint8_t i, short v) {}
|
517 |
+
|
518 |
+
|
519 |
+
/*
|
520 |
+
* Wifi and MQTT code
|
521 |
+
*/
|
522 |
+
#ifndef POSIXMQTT
|
523 |
+
void netbegin() {}
|
524 |
+
char netconnected() { return 0; }
|
525 |
+
void mqttbegin() {}
|
526 |
+
int mqttstat(char c) {return 0; }
|
527 |
+
int mqttstate() {return -1;}
|
528 |
+
void mqttsubscribe(char *t) {}
|
529 |
+
void mqttsettopic(char *t) {}
|
530 |
+
void mqttouts(char *m, short l) {}
|
531 |
+
void mqttins(char *b, short nb) { z.a=0; };
|
532 |
+
char mqttinch() {return 0;};
|
533 |
+
#else
|
534 |
+
/* we use mosquitto */
|
535 |
+
#include <mosquitto.h>
|
536 |
+
/* we assume to be on the network */
|
537 |
+
void netbegin() {}
|
538 |
+
char netconnected() { return 1; }
|
539 |
+
/* the mqtt code */
|
540 |
+
void mqttbegin() {}
|
541 |
+
int mqttstat(char c) {return 0; }
|
542 |
+
int mqttstate() {return -1;}
|
543 |
+
void mqttsubscribe(char *t) {}
|
544 |
+
void mqttsettopic(char *t) {}
|
545 |
+
void mqttouts(char *m, short l) {}
|
546 |
+
void mqttins(char *b, short nb) { z.a=0; };
|
547 |
+
char mqttinch() {return 0;};
|
548 |
+
#endif
|
549 |
+
|
550 |
+
/*
|
551 |
+
* EEPROM handling, these function enable the @E array and
|
552 |
+
* loading and saving to EEPROM with the "!" mechanism
|
553 |
+
* a filesystem based dummy
|
554 |
+
*/
|
555 |
+
signed char eeprom[EEPROMSIZE];
|
556 |
+
void ebegin(){
|
557 |
+
int i;
|
558 |
+
FILE* efile;
|
559 |
+
for (i=0; i<EEPROMSIZE; i++) eeprom[i]=-1;
|
560 |
+
efile=fopen("eeprom.dat", "r");
|
561 |
+
if (efile) fread(eeprom, EEPROMSIZE, 1, efile);
|
562 |
+
}
|
563 |
+
|
564 |
+
void eflush(){
|
565 |
+
FILE* efile;
|
566 |
+
efile=fopen("eeprom.dat", "w");
|
567 |
+
if (efile) fwrite(eeprom, EEPROMSIZE, 1, efile);
|
568 |
+
fclose(efile);
|
569 |
+
}
|
570 |
+
|
571 |
+
address_t elength() { return EEPROMSIZE; }
|
572 |
+
void eupdate(address_t a, mem_t c) { if (a>=0 && a<EEPROMSIZE) eeprom[a]=c; }
|
573 |
+
mem_t eread(address_t a) { if (a>=0 && a<EEPROMSIZE) return eeprom[a]; else return -1; }
|
574 |
+
|
575 |
+
/*
|
576 |
+
* the wrappers of the arduino io functions, to avoid
|
577 |
+
*/
|
578 |
+
#if !defined(POSIXWIRING) && !defined(POSIXPIGPIO)
|
579 |
+
void aread(){ pop(); push(0); }
|
580 |
+
void dread(){ pop(); push(0); }
|
581 |
+
void awrite(address_t p, address_t v){}
|
582 |
+
void dwrite(address_t p, address_t v){}
|
583 |
+
void pinm(address_t p, address_t m){}
|
584 |
+
#endif
|
585 |
+
|
586 |
+
#ifdef POSIXWIRING
|
587 |
+
void aread(){ push(analogRead(pop())); }
|
588 |
+
void dread(){ push(digitalRead(pop())); }
|
589 |
+
|
590 |
+
|
591 |
+
void awrite(address_t p, address_t v){
|
592 |
+
if (v >= 0 && v<256) analogWrite(p, v);
|
593 |
+
else error(EORANGE);
|
594 |
+
}
|
595 |
+
|
596 |
+
void dwrite(address_t p, address_t v){
|
597 |
+
if (v == 0) digitalWrite(p, LOW);
|
598 |
+
else if (v == 1) digitalWrite(p, HIGH);
|
599 |
+
else error(EORANGE);
|
600 |
+
}
|
601 |
+
|
602 |
+
/* pin Modes without range check, values in wiringPi are different from Arduino*/
|
603 |
+
void pinm(address_t p, address_t m){
|
604 |
+
if (m>=0) pinMode(p, m);
|
605 |
+
else error(EORANGE);
|
606 |
+
}
|
607 |
+
#endif
|
608 |
+
|
609 |
+
/* the pigpio library */
|
610 |
+
#ifdef POSIXPIGPIO
|
611 |
+
|
612 |
+
|
613 |
+
void aread(){ pop(); push(0); }
|
614 |
+
|
615 |
+
|
616 |
+
void dread(){
|
617 |
+
push(gpio_read(pigpio_pi, pop()));
|
618 |
+
}
|
619 |
+
|
620 |
+
void awrite(address_t p, address_t v){
|
621 |
+
set_PWM_dutycycle(pigpio_pi, p, v);
|
622 |
+
}
|
623 |
+
|
624 |
+
|
625 |
+
void dwrite(address_t p, address_t v){
|
626 |
+
gpio_write(pigpio_pi, p, v);
|
627 |
+
}
|
628 |
+
|
629 |
+
void pinm(address_t p, address_t m){
|
630 |
+
set_mode(pigpio_pi, p, m);
|
631 |
+
}
|
632 |
+
#endif
|
633 |
+
|
634 |
+
/* we need to do millis by hand except for RASPPI with wiring */
|
635 |
+
#if !defined(POSIXWIRING)
|
636 |
+
unsigned long millis() {
|
637 |
+
struct timeb thetime;
|
638 |
+
ftime(&thetime);
|
639 |
+
return (thetime.time-start_time.time)*1000+(thetime.millitm-start_time.millitm);
|
640 |
+
}
|
641 |
+
#endif
|
642 |
+
|
643 |
+
void bpulsein() { pop(); pop(); pop(); push(0); }
|
644 |
+
void bpulseout(short a) { while (a--) pop(); }
|
645 |
+
void btone(short a) { pop(); pop(); if (a == 3) pop(); }
|
646 |
+
|
647 |
+
/* the POSIX code has no yield as it runs on an OS */
|
648 |
+
void yieldfunction() {}
|
649 |
+
|
650 |
+
void longyieldfunction() {
|
651 |
+
#ifdef BASICBGTASK
|
652 |
+
/* polling for the BREAKCHAR */
|
653 |
+
#ifdef POSIXNONBLOCKING
|
654 |
+
if (checkch() == BREAKCHAR) breakcondition=1;
|
655 |
+
#endif
|
656 |
+
#endif
|
657 |
+
}
|
658 |
+
|
659 |
+
void yieldschedule() {}
|
660 |
+
|
661 |
+
/*
|
662 |
+
* The file system driver - all methods needed to support BASIC fs access
|
663 |
+
* MSDOS to be done
|
664 |
+
*
|
665 |
+
* file system code is a wrapper around the POSIX API
|
666 |
+
*/
|
667 |
+
void fsbegin(char v) {}
|
668 |
+
#define FILESYSTEMDRIVER
|
669 |
+
FILE* ifile;
|
670 |
+
FILE* ofile;
|
671 |
+
#ifndef MSDOS
|
672 |
+
DIR* root;
|
673 |
+
struct dirent* file;
|
674 |
+
#else
|
675 |
+
void* root;
|
676 |
+
void* file;
|
677 |
+
#endif
|
678 |
+
|
679 |
+
/* POSIX OSes always have filesystems */
|
680 |
+
int fsstat(char c) {return 1; }
|
681 |
+
|
682 |
+
/*
|
683 |
+
* File I/O function on an Arduino
|
684 |
+
*
|
685 |
+
* filewrite(), fileread(), fileavailable() as byte access
|
686 |
+
* open and close is handled separately by (i/o)file(open/close)
|
687 |
+
* only one file can be open for write and read at the same time
|
688 |
+
*/
|
689 |
+
void filewrite(char c) {
|
690 |
+
if (ofile)
|
691 |
+
fputc(c, ofile);
|
692 |
+
else
|
693 |
+
ert=1;
|
694 |
+
}
|
695 |
+
|
696 |
+
char fileread(){
|
697 |
+
char c;
|
698 |
+
if (ifile) c=fgetc(ifile); else { ert=1; return 0; }
|
699 |
+
if (cheof(c)) ert=-1;
|
700 |
+
return c;
|
701 |
+
}
|
702 |
+
|
703 |
+
char ifileopen(const char* filename){
|
704 |
+
ifile=fopen(filename, "r");
|
705 |
+
// return (int) ifile;
|
706 |
+
return ifile!=0;
|
707 |
+
}
|
708 |
+
|
709 |
+
void ifileclose(){
|
710 |
+
if (ifile) fclose(ifile);
|
711 |
+
ifile=0;
|
712 |
+
}
|
713 |
+
|
714 |
+
char ofileopen(char* filename, const char* m){
|
715 |
+
ofile=fopen(filename, m);
|
716 |
+
// return (int) ofile;
|
717 |
+
return ofile!=0;
|
718 |
+
}
|
719 |
+
|
720 |
+
void ofileclose(){
|
721 |
+
if (ofile) fclose(ofile);
|
722 |
+
ofile=0;
|
723 |
+
}
|
724 |
+
|
725 |
+
int fileavailable(){ return !feof(ifile); }
|
726 |
+
|
727 |
+
/*
|
728 |
+
* directory handling for the catalog function
|
729 |
+
* these methods are needed for a walkthtrough of
|
730 |
+
* one directory
|
731 |
+
*
|
732 |
+
* rootopen()
|
733 |
+
* while rootnextfile()
|
734 |
+
* if rootisfile() print rootfilename() rootfilesize()
|
735 |
+
* rootfileclose()
|
736 |
+
* rootclose()
|
737 |
+
*/
|
738 |
+
#ifdef MSDOS
|
739 |
+
#include <dos.h>
|
740 |
+
#include <dir.h>
|
741 |
+
struct ffblk *bffblk;
|
742 |
+
#endif
|
743 |
+
|
744 |
+
void rootopen() {
|
745 |
+
#ifndef MSDOS
|
746 |
+
root=opendir ("./");
|
747 |
+
#else
|
748 |
+
(void) findfirst("*.*", bffblk, 0);
|
749 |
+
#endif
|
750 |
+
}
|
751 |
+
|
752 |
+
int rootnextfile() {
|
753 |
+
#ifndef MSDOS
|
754 |
+
file = readdir(root);
|
755 |
+
return (file != 0);
|
756 |
+
#else
|
757 |
+
return (findnext(bffblk) == 0);
|
758 |
+
#endif
|
759 |
+
}
|
760 |
+
|
761 |
+
int rootisfile() {
|
762 |
+
#if !defined(MSDOS) && !defined(MINGW)
|
763 |
+
return (file->d_type == DT_REG);
|
764 |
+
#else
|
765 |
+
return 1;
|
766 |
+
#endif
|
767 |
+
}
|
768 |
+
|
769 |
+
const char* rootfilename() {
|
770 |
+
#ifndef MSDOS
|
771 |
+
return (file->d_name);
|
772 |
+
#else
|
773 |
+
return (bffblk->ff_name);
|
774 |
+
#endif
|
775 |
+
}
|
776 |
+
|
777 |
+
long rootfilesize() {
|
778 |
+
#ifndef MSDOS
|
779 |
+
return 0;
|
780 |
+
#else
|
781 |
+
return (bffblk->ff_fsize);
|
782 |
+
#endif
|
783 |
+
}
|
784 |
+
|
785 |
+
void rootfileclose() {}
|
786 |
+
void rootclose(){
|
787 |
+
#ifndef MSDOS
|
788 |
+
(void) closedir(root);
|
789 |
+
#endif
|
790 |
+
}
|
791 |
+
|
792 |
+
/*
|
793 |
+
* remove method for files
|
794 |
+
*/
|
795 |
+
void removefile(char *filename) {
|
796 |
+
remove(filename);
|
797 |
+
}
|
798 |
+
|
799 |
+
/*
|
800 |
+
* formatting for fdisk of the internal filesystems
|
801 |
+
*/
|
802 |
+
void formatdisk(short i) {
|
803 |
+
outsc("Format not implemented on this platform\n");
|
804 |
+
}
|
805 |
+
|
806 |
+
/*
|
807 |
+
* Primary serial code, if NONBLOCKING is set,
|
808 |
+
* platform dependent I/O is used. This means that
|
809 |
+
* UNIXes use fcntl() to implement a serialcheckch
|
810 |
+
* and MSDOS as well als WIndows use kbhit().
|
811 |
+
* This serves only to interrupt programs with
|
812 |
+
* BREAKCHAR at the moment.
|
813 |
+
*/
|
814 |
+
#ifdef POSIXNONBLOCKING
|
815 |
+
#if !defined(MSDOS) && !defined(MINGW)
|
816 |
+
#include <fcntl.h>
|
817 |
+
|
818 |
+
/* we need to poll the serial port in non blocking mode
|
819 |
+
this slows it down so that we don't block an entire core
|
820 |
+
read speed here is one character per millisecond which
|
821 |
+
is 8000 baud, no one can type that fast but tedious when
|
822 |
+
from stdin */
|
823 |
+
/*
|
824 |
+
void freecpu() {
|
825 |
+
struct timespec intervall;
|
826 |
+
struct timespec rtmp;
|
827 |
+
intervall.tv_sec=0;
|
828 |
+
intervall.tv_nsec=1000000;
|
829 |
+
nanosleep(&intervall, &rtmp);
|
830 |
+
}
|
831 |
+
*/
|
832 |
+
|
833 |
+
/* for non blocking I/O try to modify the stdin file descriptor */
|
834 |
+
void serialbegin() {
|
835 |
+
/* we keep I/O mostly blocking here */
|
836 |
+
/*
|
837 |
+
fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
|
838 |
+
*/
|
839 |
+
}
|
840 |
+
|
841 |
+
/* get and unget the character in a non blocking way */
|
842 |
+
short serialcheckch(){
|
843 |
+
fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
|
844 |
+
int ch=getchar();
|
845 |
+
ungetc(ch, stdin);
|
846 |
+
fcntl(0, F_SETFL, fcntl(0, F_GETFL) & ~O_NONBLOCK);
|
847 |
+
return ch;
|
848 |
+
}
|
849 |
+
|
850 |
+
/* check EOF, don't use feof()) here */
|
851 |
+
short serialavailable() {
|
852 |
+
if (cheof(serialcheckch())) return 0; else return 1;
|
853 |
+
}
|
854 |
+
|
855 |
+
/* two versions of serialread */
|
856 |
+
char serialread() {
|
857 |
+
char ch;
|
858 |
+
/* blocking to let the OS handle the wait - this means: no call to byield() in interaction */
|
859 |
+
ch=getchar();
|
860 |
+
return ch;
|
861 |
+
/* this is the code that waits - calls byield() often just like on the Arduino */
|
862 |
+
/*
|
863 |
+
while (cheof(serialcheckch())) { byield(); freecpu(); }
|
864 |
+
return getchar();
|
865 |
+
*/
|
866 |
+
}
|
867 |
+
|
868 |
+
/* flushes the serial code in non blocking mode */
|
869 |
+
void serialflush() {
|
870 |
+
fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
|
871 |
+
while (!cheof(getchar()));
|
872 |
+
fcntl(0, F_SETFL, fcntl(0, F_GETFL) & ~O_NONBLOCK);
|
873 |
+
}
|
874 |
+
#else
|
875 |
+
/* the non blocking MSDOS and MINGW code */
|
876 |
+
#include <conio.h>
|
877 |
+
/* we go way back in time here and do it like DOS did it */
|
878 |
+
void serialbegin(){}
|
879 |
+
|
880 |
+
/* we go through the terminal on read */
|
881 |
+
char serialread() {
|
882 |
+
return getchar();
|
883 |
+
}
|
884 |
+
|
885 |
+
/* check if a key is hit, get it and return it */
|
886 |
+
short serialcheckch(){
|
887 |
+
if (kbhit()) return getch();
|
888 |
+
}
|
889 |
+
|
890 |
+
/* simple version */
|
891 |
+
short serialavailable() {
|
892 |
+
return 1;
|
893 |
+
}
|
894 |
+
|
895 |
+
/* simple version */
|
896 |
+
void serialflush() { }
|
897 |
+
#endif
|
898 |
+
#else
|
899 |
+
/* the blocking code only uses puchar and getchar */
|
900 |
+
void serialbegin(){}
|
901 |
+
char serialread() { return getchar(); }
|
902 |
+
short serialcheckch(){ return 1; }
|
903 |
+
short serialavailable() { return 1; }
|
904 |
+
void serialflush() {}
|
905 |
+
#endif
|
906 |
+
|
907 |
+
int serialstat(char c) {
|
908 |
+
if (c == 0) return 1;
|
909 |
+
if (c == 1) return serial_baudrate;
|
910 |
+
return 0;
|
911 |
+
}
|
912 |
+
|
913 |
+
/* send the CSI sequence to start with ANSI */
|
914 |
+
void sendcsi() {
|
915 |
+
putchar(27); putchar('['); /* CSI */
|
916 |
+
}
|
917 |
+
|
918 |
+
/* the vt52 state engine */
|
919 |
+
#ifdef POSIXVT52TOANSI
|
920 |
+
#include <stdlib.h>
|
921 |
+
mem_t dspesc = 0;
|
922 |
+
mem_t vt52s = 0;
|
923 |
+
int cursory = 0;
|
924 |
+
mem_t vt52active = 1;
|
925 |
+
|
926 |
+
/* something little */
|
927 |
+
uint8_t vt52number(char c) {
|
928 |
+
uint8_t b=c;
|
929 |
+
if (b>31) return b-32; else return 0;
|
930 |
+
}
|
931 |
+
|
932 |
+
/* set the cursor */
|
933 |
+
void dspsetcursory(int i) {
|
934 |
+
cursory=i;
|
935 |
+
}
|
936 |
+
|
937 |
+
/* remember the position */
|
938 |
+
void dspsetcursorx(int i) {
|
939 |
+
sendcsi();
|
940 |
+
printf("%d;%dH", abs(cursory)+1, abs(i)+1);
|
941 |
+
}
|
942 |
+
|
943 |
+
/* set colors, vga here */
|
944 |
+
void dspsetfgcolor(int co) {
|
945 |
+
sendcsi();
|
946 |
+
if (co < 8) {
|
947 |
+
putchar('3');
|
948 |
+
} else {
|
949 |
+
putchar('9');
|
950 |
+
co=co-8;
|
951 |
+
}
|
952 |
+
putchar('0'+co);
|
953 |
+
putchar('m');
|
954 |
+
}
|
955 |
+
|
956 |
+
void dspsetbgcolor(int co) {
|
957 |
+
sendcsi();
|
958 |
+
if (co < 8) {
|
959 |
+
putchar('4');
|
960 |
+
} else {
|
961 |
+
putchar('1'); putchar('0');
|
962 |
+
co=co-8;
|
963 |
+
}
|
964 |
+
putchar('0'+co);
|
965 |
+
putchar('m');
|
966 |
+
}
|
967 |
+
|
968 |
+
/* vt52 state engine, a smaller version of the Arduino code*/
|
969 |
+
void dspvt52(char* c){
|
970 |
+
|
971 |
+
/* reading and processing multi byte commands */
|
972 |
+
switch (vt52s) {
|
973 |
+
case 'Y':
|
974 |
+
if (dspesc == 2) {
|
975 |
+
dspsetcursory(vt52number(*c));
|
976 |
+
dspesc=1;
|
977 |
+
*c=0;
|
978 |
+
return;
|
979 |
+
}
|
980 |
+
if (dspesc == 1) {
|
981 |
+
dspsetcursorx(vt52number(*c));
|
982 |
+
*c=0;
|
983 |
+
}
|
984 |
+
vt52s=0;
|
985 |
+
break;
|
986 |
+
case 'b':
|
987 |
+
dspsetfgcolor(vt52number(*c));
|
988 |
+
*c=0;
|
989 |
+
vt52s=0;
|
990 |
+
break;
|
991 |
+
case 'c':
|
992 |
+
dspsetbgcolor(vt52number(*c));
|
993 |
+
*c=0;
|
994 |
+
vt52s=0;
|
995 |
+
break;
|
996 |
+
}
|
997 |
+
|
998 |
+
/* commands of the terminal in text mode */
|
999 |
+
switch (*c) {
|
1000 |
+
case 'v': /* GEMDOS / TOS extension enable wrap */
|
1001 |
+
break;
|
1002 |
+
case 'w': /* GEMDOS / TOS extension disable wrap */
|
1003 |
+
break;
|
1004 |
+
case '^': /* Printer extensions - print on */
|
1005 |
+
break;
|
1006 |
+
case '_': /* Printer extensions - print off */
|
1007 |
+
break;
|
1008 |
+
case 'W': /* Printer extensions - print without display on */
|
1009 |
+
break;
|
1010 |
+
case 'X': /* Printer extensions - print without display off */
|
1011 |
+
break;
|
1012 |
+
case 'V': /* Printer extensions - print cursor line */
|
1013 |
+
break;
|
1014 |
+
case ']': /* Printer extension - print screen */
|
1015 |
+
break;
|
1016 |
+
case 'F': /* enter graphics mode */
|
1017 |
+
break;
|
1018 |
+
case 'G': /* exit graphics mode */
|
1019 |
+
break;
|
1020 |
+
case 'Z': // Ident
|
1021 |
+
break;
|
1022 |
+
case '=': // alternate keypad on
|
1023 |
+
case '>': // alternate keypad off
|
1024 |
+
break;
|
1025 |
+
case 'b': // GEMDOS / TOS extension text color
|
1026 |
+
case 'c': // GEMDOS / TOS extension background color
|
1027 |
+
vt52s=*c;
|
1028 |
+
dspesc=1;
|
1029 |
+
*c=0;
|
1030 |
+
return;
|
1031 |
+
case 'e': // GEMDOS / TOS extension enable cursor
|
1032 |
+
break;
|
1033 |
+
case 'f': // GEMDOS / TOS extension disable cursor
|
1034 |
+
break;
|
1035 |
+
case 'p': // GEMDOS / TOS extension reverse video
|
1036 |
+
break;
|
1037 |
+
case 'q': // GEMDOS / TOS extension normal video
|
1038 |
+
break;
|
1039 |
+
case 'A': // cursor up
|
1040 |
+
sendcsi();
|
1041 |
+
putchar('A');
|
1042 |
+
break;
|
1043 |
+
case 'B': // cursor down
|
1044 |
+
sendcsi();
|
1045 |
+
putchar('B');
|
1046 |
+
break;
|
1047 |
+
case 'C': // cursor right
|
1048 |
+
sendcsi();
|
1049 |
+
putchar('C');
|
1050 |
+
break;
|
1051 |
+
case 'D': // cursor left
|
1052 |
+
sendcsi();
|
1053 |
+
putchar('D');
|
1054 |
+
break;
|
1055 |
+
case 'E': // GEMDOS / TOS extension clear screen
|
1056 |
+
*c=12;
|
1057 |
+
dspesc=0;
|
1058 |
+
return;
|
1059 |
+
case 'H': // cursor home
|
1060 |
+
*c=2;
|
1061 |
+
dspesc=0;
|
1062 |
+
return;
|
1063 |
+
case 'Y': // Set cursor position
|
1064 |
+
vt52s='Y';
|
1065 |
+
dspesc=2;
|
1066 |
+
*c=0;
|
1067 |
+
return;
|
1068 |
+
case 'J': // clear to end of screen
|
1069 |
+
sendcsi();
|
1070 |
+
putchar('J');
|
1071 |
+
break;
|
1072 |
+
case 'd': // GEMDOS / TOS extension clear to start of screen
|
1073 |
+
sendcsi();
|
1074 |
+
putchar('1'); putchar('J');
|
1075 |
+
break;
|
1076 |
+
case 'K': // clear to the end of line
|
1077 |
+
sendcsi();
|
1078 |
+
putchar('K');
|
1079 |
+
break;
|
1080 |
+
case 'l': // GEMDOS / TOS extension clear line
|
1081 |
+
sendcsi();
|
1082 |
+
putchar('2'); putchar('K');
|
1083 |
+
break;
|
1084 |
+
case 'o': // GEMDOS / TOS extension clear to start of line
|
1085 |
+
sendcsi();
|
1086 |
+
putchar('1'); putchar('K');
|
1087 |
+
break;
|
1088 |
+
case 'k': // GEMDOS / TOS extension restore cursor
|
1089 |
+
break;
|
1090 |
+
case 'j': // GEMDOS / TOS extension save cursor
|
1091 |
+
break;
|
1092 |
+
case 'I': // reverse line feed
|
1093 |
+
putchar(27);
|
1094 |
+
putchar('M');
|
1095 |
+
break;
|
1096 |
+
case 'L': // Insert line
|
1097 |
+
break;
|
1098 |
+
case 'M': // Delete line - questionable
|
1099 |
+
sendcsi();
|
1100 |
+
putchar('2'); putchar('K');
|
1101 |
+
break;
|
1102 |
+
}
|
1103 |
+
dspesc=0;
|
1104 |
+
*c=0;
|
1105 |
+
}
|
1106 |
+
#endif
|
1107 |
+
|
1108 |
+
void serialwrite(char c) {
|
1109 |
+
|
1110 |
+
/* the vt52 state engine */
|
1111 |
+
#ifdef POSIXVT52TOANSI
|
1112 |
+
if (dspesc) {
|
1113 |
+
dspvt52(&c);
|
1114 |
+
if (c == 0) return;
|
1115 |
+
}
|
1116 |
+
|
1117 |
+
/* ESC is caught here and we only listen to VT52 not to ANSI */
|
1118 |
+
if (c == 27 && vt52active) {
|
1119 |
+
dspesc=1;
|
1120 |
+
return;
|
1121 |
+
}
|
1122 |
+
#endif
|
1123 |
+
|
1124 |
+
/* this is the character translation routine to convert the Arduino
|
1125 |
+
style characters 12 for CLS and 2 for HOME to ANSI, makes
|
1126 |
+
BASIC programs more compatible */
|
1127 |
+
#ifdef POSIXTERMINAL
|
1128 |
+
switch (c) {
|
1129 |
+
/* form feed is clear screen - compatibility with Arduino code */
|
1130 |
+
case 12:
|
1131 |
+
sendcsi();
|
1132 |
+
putchar('2'); putchar('J');
|
1133 |
+
/* home sequence in the arduino code */
|
1134 |
+
case 2:
|
1135 |
+
sendcsi();
|
1136 |
+
putchar('H');
|
1137 |
+
return;
|
1138 |
+
}
|
1139 |
+
#endif
|
1140 |
+
|
1141 |
+
/* finally send the plain character */
|
1142 |
+
putchar(c);
|
1143 |
+
}
|
1144 |
+
|
1145 |
+
|
1146 |
+
/*
|
1147 |
+
* reading from the console with inch
|
1148 |
+
* this mixes interpreter levels as inch is used here
|
1149 |
+
* this code needs to go to the main interpreter section after
|
1150 |
+
* thorough rewrite
|
1151 |
+
*/
|
1152 |
+
void consins(char *b, short nb) {
|
1153 |
+
char c;
|
1154 |
+
|
1155 |
+
z.a=1;
|
1156 |
+
while(z.a < nb) {
|
1157 |
+
c=inch();
|
1158 |
+
if (c == '\r') c=inch();
|
1159 |
+
if (c == '\n' || cheof(c)) { /* terminal character is either newline or EOF */
|
1160 |
+
break;
|
1161 |
+
} else {
|
1162 |
+
b[z.a++]=c;
|
1163 |
+
}
|
1164 |
+
}
|
1165 |
+
b[z.a]=0x00;
|
1166 |
+
z.a--;
|
1167 |
+
b[0]=(unsigned char)z.a;
|
1168 |
+
}
|
1169 |
+
|
1170 |
+
/*
|
1171 |
+
* handling the second serial interface - only done on Mac so far
|
1172 |
+
* test code
|
1173 |
+
*
|
1174 |
+
* Tried to learn from https://www.pololu.com/docs/0J73/15.5
|
1175 |
+
*
|
1176 |
+
*/
|
1177 |
+
#ifdef ARDUINOPRT
|
1178 |
+
#include <fcntl.h>
|
1179 |
+
#if !defined(MSDOS) && !defined(MINGW)
|
1180 |
+
#include <termios.h>
|
1181 |
+
#endif
|
1182 |
+
|
1183 |
+
/* the file name of the printer port */
|
1184 |
+
int prtfile;
|
1185 |
+
|
1186 |
+
/* the buffer to read one character */
|
1187 |
+
char prtbuf = 0;
|
1188 |
+
|
1189 |
+
|
1190 |
+
void prtbegin() {}
|
1191 |
+
|
1192 |
+
char prtopen(char* filename, int mode) {
|
1193 |
+
#if !defined(MSDOS) && !defined(MINGW)
|
1194 |
+
|
1195 |
+
/* try to open the device file */
|
1196 |
+
prtfile=open(filename, O_RDWR | O_NOCTTY);
|
1197 |
+
if (prtfile == -1) {
|
1198 |
+
perror(filename);
|
1199 |
+
return 0;
|
1200 |
+
}
|
1201 |
+
|
1202 |
+
/* get rid of garbage */
|
1203 |
+
tcflush(prtfile, TCIOFLUSH);
|
1204 |
+
|
1205 |
+
/* configure the device */
|
1206 |
+
struct termios opt;
|
1207 |
+
(void) tcgetattr(prtfile, &opt);
|
1208 |
+
|
1209 |
+
|
1210 |
+
/* raw terminal settings
|
1211 |
+
opt.c_iflag &= ~(INLCR | IGNCR | ICRNL | IXON | IXOFF);
|
1212 |
+
opt.c_oflag &= ~(ONLCR | OCRNL);
|
1213 |
+
opt.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
|
1214 |
+
*/
|
1215 |
+
|
1216 |
+
/* timeout settings on read 100ms, read every character */
|
1217 |
+
opt.c_cc[VTIME] = 1;
|
1218 |
+
opt.c_cc[VMIN] = 0;
|
1219 |
+
|
1220 |
+
/* set the baudrate */
|
1221 |
+
switch (mode) {
|
1222 |
+
case 9600:
|
1223 |
+
cfsetospeed(&opt, B9600);
|
1224 |
+
break;
|
1225 |
+
default:
|
1226 |
+
cfsetospeed(&opt, B9600);
|
1227 |
+
break;
|
1228 |
+
}
|
1229 |
+
cfsetispeed(&opt, cfgetospeed(&opt));
|
1230 |
+
|
1231 |
+
/* set the termin attributes */
|
1232 |
+
tcsetattr(prtfile, TCSANOW, &opt);
|
1233 |
+
#endif
|
1234 |
+
|
1235 |
+
return 1;
|
1236 |
+
}
|
1237 |
+
|
1238 |
+
void prtclose() {
|
1239 |
+
if (prtfile) close(prtfile);
|
1240 |
+
}
|
1241 |
+
|
1242 |
+
int prtstat(char c) {return 1; }
|
1243 |
+
void prtset(int s) {}
|
1244 |
+
|
1245 |
+
/* write the characters byte by byte */
|
1246 |
+
void prtwrite(char c) {
|
1247 |
+
int i=write(prtfile, &c, 1);
|
1248 |
+
if (i != 1) ert=1;
|
1249 |
+
}
|
1250 |
+
|
1251 |
+
/* read just one byte, map no bytes to EOF = -1 */
|
1252 |
+
char prtread() {
|
1253 |
+
char c;
|
1254 |
+
|
1255 |
+
/* something in the buffer? return it! */
|
1256 |
+
if (prtbuf) {
|
1257 |
+
c=prtbuf;
|
1258 |
+
prtbuf=0;
|
1259 |
+
} else {
|
1260 |
+
/* try to read */
|
1261 |
+
int i=read(prtfile, &c, 1);
|
1262 |
+
if (i < 0) {
|
1263 |
+
ert=1;
|
1264 |
+
return 0;
|
1265 |
+
}
|
1266 |
+
if (i == 0) return -1;
|
1267 |
+
}
|
1268 |
+
return c;
|
1269 |
+
}
|
1270 |
+
|
1271 |
+
/* not yet implemented */
|
1272 |
+
short prtcheckch(){
|
1273 |
+
if (!prtbuf) { /* try to read */
|
1274 |
+
int i=read(prtfile, &prtbuf, 1);
|
1275 |
+
if (i <= 0) prtbuf=0;
|
1276 |
+
}
|
1277 |
+
return prtbuf;
|
1278 |
+
}
|
1279 |
+
|
1280 |
+
short prtavailable(){
|
1281 |
+
return prtcheckch()!=0;
|
1282 |
+
}
|
1283 |
+
|
1284 |
+
#else
|
1285 |
+
void prtbegin() {}
|
1286 |
+
int prtstat(char c) {return 0; }
|
1287 |
+
void prtset(int s) {}
|
1288 |
+
void prtwrite(char c) {}
|
1289 |
+
char prtread() {return 0;}
|
1290 |
+
short prtcheckch(){ return 0; }
|
1291 |
+
short prtavailable(){ return 0; }
|
1292 |
+
#endif
|
1293 |
+
|
1294 |
+
|
1295 |
+
/*
|
1296 |
+
* The wire code
|
1297 |
+
*/
|
1298 |
+
#if defined(POSIXWIRE) && defined(POSIXPIGPIO)
|
1299 |
+
#define HASWIRE
|
1300 |
+
uint8_t wire_slaveid = 0;
|
1301 |
+
|
1302 |
+
/* open the wire connection in pigpio */
|
1303 |
+
void wirebegin() {
|
1304 |
+
}
|
1305 |
+
|
1306 |
+
/* we return the handle here, inconsistent with the Arduino code */
|
1307 |
+
int wirestat(char c) {
|
1308 |
+
return 1;
|
1309 |
+
}
|
1310 |
+
|
1311 |
+
void wireopen(char s, char m) {
|
1312 |
+
if (m == 0) {
|
1313 |
+
wire_slaveid=s;
|
1314 |
+
} else if ( m == 1 ) {
|
1315 |
+
outsc("** wire slave mode not implemented"); outcr();
|
1316 |
+
} else
|
1317 |
+
error(EORANGE);
|
1318 |
+
}
|
1319 |
+
|
1320 |
+
|
1321 |
+
/* read a number of bytes, depending on the string length */
|
1322 |
+
void wireins(char *b, uint8_t l) {
|
1323 |
+
int handle;
|
1324 |
+
|
1325 |
+
handle=i2c_open(pigpio_pi, POSIXI2CBUS, wire_slaveid, 0);
|
1326 |
+
if (handle < 0) {
|
1327 |
+
printf("** wire handle %d returned \n", handle);
|
1328 |
+
ert=1;
|
1329 |
+
}
|
1330 |
+
|
1331 |
+
z.a=i2c_read_device(pigpio_pi, handle, b+1, l);
|
1332 |
+
|
1333 |
+
if (z.a < 0) {
|
1334 |
+
ert=-1;
|
1335 |
+
z.a=0;
|
1336 |
+
}
|
1337 |
+
b[0]=z.a;
|
1338 |
+
|
1339 |
+
i2c_close(pigpio_pi, handle);
|
1340 |
+
}
|
1341 |
+
|
1342 |
+
|
1343 |
+
|
1344 |
+
void wireouts(char *b, uint8_t l) {
|
1345 |
+
int handle;
|
1346 |
+
|
1347 |
+
handle=i2c_open(pigpio_pi, POSIXI2CBUS, wire_slaveid, 0);
|
1348 |
+
if (handle < 0) {
|
1349 |
+
printf("** wire handle %d returned \n", handle);
|
1350 |
+
ert=1;
|
1351 |
+
}
|
1352 |
+
|
1353 |
+
if (i2c_write_device(pigpio_pi, handle, b, l) < 0) ert=-1;
|
1354 |
+
|
1355 |
+
i2c_close(pigpio_pi, handle);
|
1356 |
+
}
|
1357 |
+
|
1358 |
+
short wireavailable() { return 1; }
|
1359 |
+
|
1360 |
+
/* the register access functions */
|
1361 |
+
short wirereadbyte(short port) {
|
1362 |
+
int res, handle;
|
1363 |
+
handle=i2c_open(pigpio_pi, POSIXI2CBUS, port, 0);
|
1364 |
+
if (handle < 0) {
|
1365 |
+
printf("** wire handle %d returned \n", handle);
|
1366 |
+
ert=1;
|
1367 |
+
return -1;
|
1368 |
+
}
|
1369 |
+
|
1370 |
+
res=i2c_read_byte(pigpio_pi, handle);
|
1371 |
+
i2c_close(pigpio_pi, handle);
|
1372 |
+
return res;
|
1373 |
+
}
|
1374 |
+
|
1375 |
+
/* use the simple wire byte function */
|
1376 |
+
void wirewritebyte(short port, short data) {
|
1377 |
+
int res, handle;
|
1378 |
+
handle=i2c_open(pigpio_pi, POSIXI2CBUS, port, 0);
|
1379 |
+
if (handle < 0) { ert=1; return; }
|
1380 |
+
|
1381 |
+
ert=i2c_write_byte(pigpio_pi, handle, data);
|
1382 |
+
|
1383 |
+
i2c_close(pigpio_pi, handle);
|
1384 |
+
}
|
1385 |
+
|
1386 |
+
|
1387 |
+
/* this code used the write byte function twice */
|
1388 |
+
/*
|
1389 |
+
void wirewriteword(short port, short data1, short data2) {
|
1390 |
+
int res, handle;
|
1391 |
+
handle=i2c_open(pigpio_pi, POSIXI2CBUS, port, 0);
|
1392 |
+
if (handle < 0) { ert=1; return; }
|
1393 |
+
|
1394 |
+
ert=i2c_write_byte(pigpio_pi, handle, data1);
|
1395 |
+
ert+=i2c_write_byte(pigpio_pi, handle, data2);
|
1396 |
+
|
1397 |
+
i2c_close(pigpio_pi, handle);
|
1398 |
+
}
|
1399 |
+
*/
|
1400 |
+
|
1401 |
+
/* use the raw access function in a buffer */
|
1402 |
+
void wirewriteword(short port, short data1, short data2) {
|
1403 |
+
int res, handle;
|
1404 |
+
mem_t buf[2];
|
1405 |
+
|
1406 |
+
handle=i2c_open(pigpio_pi, POSIXI2CBUS, port, 0);
|
1407 |
+
if (handle < 0) { ert=1; return; }
|
1408 |
+
|
1409 |
+
buf[0]=data1;
|
1410 |
+
buf[1]=data2;
|
1411 |
+
|
1412 |
+
if (i2c_write_device(pigpio_pi, handle, buf, 2) <0 ) ert=-1;
|
1413 |
+
|
1414 |
+
i2c_close(pigpio_pi, handle);
|
1415 |
+
}
|
1416 |
+
|
1417 |
+
#else
|
1418 |
+
void wirebegin() {}
|
1419 |
+
int wirestat(char c) {return 0; }
|
1420 |
+
void wireopen(char s, char m) {}
|
1421 |
+
void wireins(char *b, uint8_t l) { b[0]=0; z.a=0; }
|
1422 |
+
void wireouts(char *b, uint8_t l) {}
|
1423 |
+
short wireavailable() { return 1; }
|
1424 |
+
short wirereadbyte(short port) { return 0; }
|
1425 |
+
void wirewritebyte(short port, short data) { return; }
|
1426 |
+
void wirewriteword(short port, short data1, short data2) { return; }
|
1427 |
+
#endif
|
1428 |
+
|
1429 |
+
/*
|
1430 |
+
* Read from the radio interface, radio is always block
|
1431 |
+
* oriented.
|
1432 |
+
*/
|
1433 |
+
int radiostat(char c) {return 0; }
|
1434 |
+
void radioset(int s) {}
|
1435 |
+
void radioins(char *b, short nb) { b[0]=0; b[1]=0; z.a=0; }
|
1436 |
+
void radioouts(char *b, short l) {}
|
1437 |
+
void iradioopen(char *filename) {}
|
1438 |
+
void oradioopen(char *filename) {}
|
1439 |
+
short radioavailable() { return 0; }
|
1440 |
+
|
1441 |
+
/* Arduino sensors */
|
1442 |
+
void sensorbegin() {}
|
1443 |
+
number_t sensorread(short s, short v) {return 0;};
|
1444 |
+
|
1445 |
+
/*
|
1446 |
+
* Experimental code to simulate 64kb SPI SRAM modules
|
1447 |
+
*
|
1448 |
+
* currently used to test the string code of the mem
|
1449 |
+
* interface
|
1450 |
+
*
|
1451 |
+
*/
|
1452 |
+
|
1453 |
+
#ifdef SPIRAMSIMULATOR
|
1454 |
+
#define USEMEMINTERFACE
|
1455 |
+
|
1456 |
+
static mem_t* spiram;
|
1457 |
+
|
1458 |
+
/* the RAM begin method sets the RAM to byte mode */
|
1459 |
+
address_t spirambegin() {
|
1460 |
+
spiram=(mem_t*)malloc(65536);
|
1461 |
+
if (maxnum>32767) return 65534; else return 32766;
|
1462 |
+
}
|
1463 |
+
|
1464 |
+
/* the simple unbuffered byte write, with a cast to signed char */
|
1465 |
+
void spiramrawwrite(address_t a, mem_t c) {spiram[a]=c;}
|
1466 |
+
|
1467 |
+
/* the simple unbuffered byte read, with a cast to signed char */
|
1468 |
+
mem_t spiramrawread(address_t a) {return spiram[a];}
|
1469 |
+
|
1470 |
+
/* the buffers calls, also only simulated here */
|
1471 |
+
|
1472 |
+
void spiram_rwbufferwrite(address_t a, mem_t c) {spiram[a]=c;}
|
1473 |
+
|
1474 |
+
mem_t spiram_rwbufferread(address_t a) {return spiram[a];}
|
1475 |
+
|
1476 |
+
mem_t spiram_robufferread(address_t a) {return spiram[a];}
|
1477 |
+
|
1478 |
+
/* to handle strings in SPIRAM situations two more buffers are needed
|
1479 |
+
* they store intermediate results of string operations. The buffersize
|
1480 |
+
* limits the maximum string length indepents of how big strings are set
|
1481 |
+
*/
|
1482 |
+
#define SPIRAMSBSIZE 128
|
1483 |
+
char spistrbuf1[SPIRAMSBSIZE];
|
1484 |
+
char spistrbuf2[SPIRAMSBSIZE];
|
1485 |
+
#endif
|
1486 |
+
|
1487 |
+
/* stub for events */
|
1488 |
+
#ifdef HASEVENTS
|
1489 |
+
mem_t enableevent(mem_t pin) {
|
1490 |
+
int i;
|
1491 |
+
if ((i=eventindex(pin))<0) return 0;
|
1492 |
+
else {
|
1493 |
+
eventlist[i].enabled=1;
|
1494 |
+
return 1;
|
1495 |
+
}
|
1496 |
+
}
|
1497 |
+
void disableevent(mem_t pin) {}
|
1498 |
+
#endif
|
1499 |
+
|
1500 |
+
|
1501 |
+
#endif
|
1502 |
+
|
data/Basic2/IoTBasic/IoTBasic.ino
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic2/IoTBasic/Makefile
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
###############################################################################
|
2 |
+
# Makefile to compile code with arduino-cli for defined boards
|
3 |
+
# on the command line.
|
4 |
+
#
|
5 |
+
# Author: Dirk Selbach, [email protected]
|
6 |
+
# Inspired by: https://github.com/digiampietro/arduino-makefile/tree/master
|
7 |
+
#
|
8 |
+
# Build targets:
|
9 |
+
# 1) Build all defined boards
|
10 |
+
# make all
|
11 |
+
# 2) Build ELF for an individual board
|
12 |
+
# make build/<short-name-of-the-board>/IoTBasic.ino.elf
|
13 |
+
# e.g. make build/d1_mini/IoTBasic.ino.elf to build ELF for d1_mini board
|
14 |
+
# 3) Remove build dir for all boards
|
15 |
+
# make clean
|
16 |
+
# 4) Remove build dir for an individual board
|
17 |
+
# TODO
|
18 |
+
#
|
19 |
+
# Adding additional boards:
|
20 |
+
# 1) Get FQBN name of the board you want to add: arduino-cli board listall
|
21 |
+
# 2) Add the FQBN to the list in FQBN variable below
|
22 |
+
# 3) Add short name (last part of FQBN) to the list in SBN variable below
|
23 |
+
#
|
24 |
+
###############################################################################
|
25 |
+
|
26 |
+
# Let's check if arduino-cli is installed
|
27 |
+
ifeq (, $(shell which arduino-cli))
|
28 |
+
$(error "arduino-cli command not found. Please install and add to PATH. See: https://arduino.github.io/arduino-cli/1.2/")
|
29 |
+
endif
|
30 |
+
|
31 |
+
OSFAMILY := $(shell ( uname | sed "s/-.*//" ))
|
32 |
+
MAKE_DIR := $(PWD)
|
33 |
+
GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
|
34 |
+
|
35 |
+
ifdef GIT_VERSION
|
36 |
+
CFLAGS = --build-property compiler.cpp.extra_flags=-DMYVERSION=\"$(GIT_VERSION)\"
|
37 |
+
else
|
38 |
+
CFLAGS =
|
39 |
+
endif
|
40 |
+
|
41 |
+
# Fully qualified board name
|
42 |
+
# For a full list of FQBNs see: arduino-cli board listall
|
43 |
+
# To add a board add the FQBN to the list and the sort name to the SBN list below.
|
44 |
+
FQBN := esp32:esp32:d1_mini32 esp8266:esp8266:d1_mini esp8266:esp8266:nodemcuv2
|
45 |
+
|
46 |
+
# board short names (=last part of the FQBN)
|
47 |
+
SBN := d1_mini32 d1_mini nodemcuv2
|
48 |
+
|
49 |
+
# Rule to extract the FQBN based on the short name
|
50 |
+
get_full_name = $(filter %$(1),$(FQBN))
|
51 |
+
|
52 |
+
# Verbosity level, e.g., -v for verbose output
|
53 |
+
#VFLAG := -v
|
54 |
+
VFLAG :=
|
55 |
+
|
56 |
+
# Sources and headers
|
57 |
+
SRCINO := $(wildcard *.ino)
|
58 |
+
SRC := $(wildcard *.ino *.c *.cpp mylib/*/*.ino)
|
59 |
+
HDRS := $(wildcard *.h mylib/*/*.h)
|
60 |
+
|
61 |
+
# Build directory (subdirs for the boards will be created within ELF build target)
|
62 |
+
BUILD_DIR := build
|
63 |
+
|
64 |
+
# Define the .elf output file for each board
|
65 |
+
ELF_FILES := $(addprefix $(BUILD_DIR)/,$(addsuffix /$(SRCINO).elf,$(SBN)))
|
66 |
+
|
67 |
+
$(info OSFAMILY is [${OSFAMILY}])
|
68 |
+
$(info MAKE_DIR is [${MAKE_DIR}])
|
69 |
+
$(info BUILD_DIR is [${BUILD_DIR}])
|
70 |
+
$(info SRCINO is [${SRCINO}])
|
71 |
+
$(info SRC is [${SRC}])
|
72 |
+
$(info HDRS is [${HDRS}])
|
73 |
+
$(info ELF_FILES is [${ELF_FILES}])
|
74 |
+
|
75 |
+
# Default target to build for all boards
|
76 |
+
all: $(ELF_FILES)
|
77 |
+
.PHONY: all
|
78 |
+
|
79 |
+
# Build target for each board
|
80 |
+
$(ELF_FILES): $(SRC) $(HDRS)
|
81 |
+
# echo "target: $@ prereq: $<"
|
82 |
+
@echo "Building for board: $(call get_full_name,$(patsubst build/%/IoTBasic.ino.elf,%,$@))"
|
83 |
+
@mkdir -p $(dir $@)
|
84 |
+
arduino-cli compile -b $(call get_full_name,$(patsubst build/%/IoTBasic.ino.elf,%,$@)) --build-path $(dir $@) $(VFLAG) $(CFLAGS)
|
85 |
+
|
86 |
+
# Cleanup build dir (all boards)
|
87 |
+
clean:
|
88 |
+
@echo "Cleaning the build directory completely"
|
89 |
+
rm -rf $(BUILD_DIR)
|
90 |
+
.PHONY: clean
|
91 |
+
|
data/Basic2/IoTBasic/basic.h
ADDED
@@ -0,0 +1,831 @@
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*
|
3 |
+
* $Id: basic.h,v 1.1 2023/09/27 15:23:20 stefan Exp stefan $
|
4 |
+
*
|
5 |
+
* Stefan's basic interpreter
|
6 |
+
*
|
7 |
+
* See the licence file on
|
8 |
+
* https://github.com/slviajero/tinybasic for copyright/left.
|
9 |
+
* (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
|
10 |
+
*
|
11 |
+
* Author: Stefan Lenz, [email protected]
|
12 |
+
*
|
13 |
+
* basic.h are the core defintions and function protypes.
|
14 |
+
*
|
15 |
+
*/
|
16 |
+
|
17 |
+
/*
|
18 |
+
* A few of the buffers and vars come from hardware.h. These are
|
19 |
+
*
|
20 |
+
* #define BUFSIZE
|
21 |
+
* #define STACKSIZE
|
22 |
+
* #define GOSUBDEPTH
|
23 |
+
* #define FORDEPTH
|
24 |
+
* #define LINECACHESIZE
|
25 |
+
*
|
26 |
+
* They depend on the hardware architecture and are configured there.
|
27 |
+
*
|
28 |
+
*/
|
29 |
+
|
30 |
+
/* Additional buffers and vars, VARSIZE only needed for Tinybasics */
|
31 |
+
#define SBUFSIZE 16*sizeof(number_t)
|
32 |
+
#define VARSIZE 26
|
33 |
+
|
34 |
+
/* Default sizes of arrays and strings if they are not DIMed */
|
35 |
+
#define ARRAYSIZEDEF 10
|
36 |
+
#define STRSIZEDEF 32
|
37 |
+
|
38 |
+
/* the maximum name length */
|
39 |
+
#define MAXNAME 32
|
40 |
+
|
41 |
+
/*
|
42 |
+
* The tokens for the BASIC keywords
|
43 |
+
*
|
44 |
+
* All single character operators are their own tokens
|
45 |
+
* ASCII values above 0x7f are used for tokens of keywords.
|
46 |
+
* EOL is a token.
|
47 |
+
*
|
48 |
+
* The two byte tokens are possible to extend the language beyond
|
49 |
+
* 127 keywords.
|
50 |
+
*/
|
51 |
+
#define EOL 0
|
52 |
+
#define NUMBER -127
|
53 |
+
#define LINENUMBER -126
|
54 |
+
#define STRING -125
|
55 |
+
#define VARIABLE -124
|
56 |
+
#define STRINGVAR -123
|
57 |
+
#define ARRAYVAR -122
|
58 |
+
/* multi character tokens - BASEKEYWORD (3) */
|
59 |
+
#define GREATEREQUAL -121
|
60 |
+
#define LESSEREQUAL -120
|
61 |
+
#define NOTEQUAL -119
|
62 |
+
/* this is the Palo Alto Language Set (19) */
|
63 |
+
#define TPRINT -118
|
64 |
+
#define TLET -117
|
65 |
+
#define TINPUT -116
|
66 |
+
#define TGOTO -115
|
67 |
+
#define TGOSUB -114
|
68 |
+
#define TRETURN -113
|
69 |
+
#define TIF -112
|
70 |
+
#define TFOR -111
|
71 |
+
#define TTO -110
|
72 |
+
#define TSTEP -109
|
73 |
+
#define TNEXT -108
|
74 |
+
#define TSTOP -107
|
75 |
+
#define TLIST -106
|
76 |
+
#define TNEW -105
|
77 |
+
#define TRUN -104
|
78 |
+
#define TABS -103
|
79 |
+
#define TRND -102
|
80 |
+
#define TSIZE -101
|
81 |
+
#define TREM -100
|
82 |
+
/* this is the Apple 1 language set in addition to Palo Alto (14) */
|
83 |
+
#define TNOT -99
|
84 |
+
#define TAND -98
|
85 |
+
#define TOR -97
|
86 |
+
#define TLEN -96
|
87 |
+
#define TSGN -95
|
88 |
+
#define TPEEK -94
|
89 |
+
#define TDIM -93
|
90 |
+
#define TCLR -92
|
91 |
+
#define THIMEM -91
|
92 |
+
#define TTAB -90
|
93 |
+
#define TTHEN -89
|
94 |
+
#define TEND -88
|
95 |
+
#define TPOKE -87
|
96 |
+
/* Stefan's tinybasic additions (14) */
|
97 |
+
#define TCONT -86
|
98 |
+
#define TSQR -85
|
99 |
+
#define TPOW -84
|
100 |
+
#define TMAP -83
|
101 |
+
#define TDUMP -82
|
102 |
+
#define TBREAK -81
|
103 |
+
#define TSAVE -80
|
104 |
+
#define TLOAD -79
|
105 |
+
#define TGET -78
|
106 |
+
#define TPUT -77
|
107 |
+
#define TSET -76
|
108 |
+
#define TCLS -75
|
109 |
+
#define TLOCATE -74
|
110 |
+
#define TELSE -73
|
111 |
+
/* Arduino functions (10) */
|
112 |
+
#define TPINM -72
|
113 |
+
#define TDWRITE -71
|
114 |
+
#define TDREAD -70
|
115 |
+
#define TAWRITE -69
|
116 |
+
#define TAREAD -68
|
117 |
+
#define TDELAY -67
|
118 |
+
#define TMILLIS -66
|
119 |
+
#define TTONE -65
|
120 |
+
#define TPULSE -64
|
121 |
+
#define TAZERO -63
|
122 |
+
#define TLED -62
|
123 |
+
/* the DOS functions (5) */
|
124 |
+
#define TCATALOG -61
|
125 |
+
#define TDELETE -60
|
126 |
+
#define TOPEN -59
|
127 |
+
#define TCLOSE -58
|
128 |
+
#define TFDISK -57
|
129 |
+
/* low level access of internal routines (2) */
|
130 |
+
#define TUSR -56
|
131 |
+
#define TCALL -55
|
132 |
+
/* mathematical functions (7) */
|
133 |
+
#define TSIN -54
|
134 |
+
#define TCOS -53
|
135 |
+
#define TTAN -52
|
136 |
+
#define TATAN -51
|
137 |
+
#define TLOG -50
|
138 |
+
#define TEXP -49
|
139 |
+
#define TINT -48
|
140 |
+
/* graphics - rudimentary (7) */
|
141 |
+
#define TCOLOR -47
|
142 |
+
#define TPLOT -46
|
143 |
+
#define TLINE -45
|
144 |
+
#define TCIRCLE -44
|
145 |
+
#define TRECT -43
|
146 |
+
#define TFCIRCLE -42
|
147 |
+
#define TFRECT -41
|
148 |
+
/* the Dartmouth extensions (6) */
|
149 |
+
#define TDATA -40
|
150 |
+
#define TREAD -39
|
151 |
+
#define TRESTORE -38
|
152 |
+
#define TDEF -37
|
153 |
+
#define TFN -36
|
154 |
+
#define TON -35
|
155 |
+
/* darkarts (3) */
|
156 |
+
#define TMALLOC -34
|
157 |
+
#define TFIND -33
|
158 |
+
#define TEVAL -32
|
159 |
+
/* iot extensions (9) */
|
160 |
+
#define TERROR -31
|
161 |
+
#define TAVAIL -30
|
162 |
+
#define TSTR -29
|
163 |
+
#define TINSTR -28
|
164 |
+
#define TVAL -27
|
165 |
+
#define TNETSTAT -26
|
166 |
+
#define TSENSOR -25
|
167 |
+
#define TWIRE -24
|
168 |
+
#define TSLEEP -23
|
169 |
+
/* events and interrupts */
|
170 |
+
#define TAFTER -22
|
171 |
+
#define TEVERY -21
|
172 |
+
#define TEVENT -20
|
173 |
+
/* structured commands */
|
174 |
+
#define TWHILE -19
|
175 |
+
#define TWEND -18
|
176 |
+
#define TREPEAT -17
|
177 |
+
#define TUNTIL -16
|
178 |
+
#define TSWITCH -15
|
179 |
+
#define TCASE -14
|
180 |
+
#define TSWEND -13
|
181 |
+
#define TDO -12
|
182 |
+
#define TDEND -11
|
183 |
+
/* multiline function extension */
|
184 |
+
#define TFEND -10
|
185 |
+
/* these are multibyte token extension, currently unused */
|
186 |
+
/* using them would allow over 1000 BASIC keywords */
|
187 |
+
#define TEXT7 -9
|
188 |
+
#define TEXT6 -8
|
189 |
+
#define TEXT5 -7
|
190 |
+
#define TEXT4 -6
|
191 |
+
#define TEXT3 -5
|
192 |
+
#define TEXT2 -4
|
193 |
+
#define TEXT1 -3
|
194 |
+
/* end of tokens */
|
195 |
+
/* constants used for some purposes other than token */
|
196 |
+
/* Indentifying a buffer on the heap */
|
197 |
+
#define TBUFFER -2
|
198 |
+
/* UNKNOWN is not used in the current code, the
|
199 |
+
* lexer tokenizes everything blindly. There is a UNKNOWN hook
|
200 |
+
* in statement for a grammar aware lexer */
|
201 |
+
#define UNKNOWN -1
|
202 |
+
|
203 |
+
/* alternative implementation using positive token values */
|
204 |
+
#define TASC 1
|
205 |
+
#define TCHR 2
|
206 |
+
#define TRIGHT 3
|
207 |
+
#define TLEFT 4
|
208 |
+
#define TMID 5
|
209 |
+
#define TSPC 6
|
210 |
+
|
211 |
+
/* The editor and other helpers */
|
212 |
+
#define TEDIT 7
|
213 |
+
#define THELP 8
|
214 |
+
|
215 |
+
/* bitwise operations, avoid 10 as a token value */
|
216 |
+
#define TSHL 9
|
217 |
+
#define TSHR 11
|
218 |
+
#define TBIT 12
|
219 |
+
/*
|
220 |
+
* Extension tokens can be in the range from -128 upwards.
|
221 |
+
* one needs to set HASLONGTOKENS. Currently ony one set of
|
222 |
+
* extension tokens is implemented ranging from -128 to -255.
|
223 |
+
*
|
224 |
+
* **** right now unused and untested **** */
|
225 |
+
|
226 |
+
#define TCAM -128
|
227 |
+
|
228 |
+
/* BASEKEYWORD is used by the lexer. From this keyword on it tries to match. */
|
229 |
+
#define BASEKEYWORD -121
|
230 |
+
|
231 |
+
/*
|
232 |
+
* Interpreter states
|
233 |
+
* SRUN means running from a programm
|
234 |
+
* SINT means interactive mode
|
235 |
+
* SERUN means running directly from EEPROM
|
236 |
+
* (enum would be the right way of doing this.)
|
237 |
+
*/
|
238 |
+
#define SINT 0
|
239 |
+
#define SRUN 1
|
240 |
+
#define SERUN 2
|
241 |
+
|
242 |
+
/*
|
243 |
+
* the message catalog
|
244 |
+
*/
|
245 |
+
#define MFILE 0
|
246 |
+
#define MPROMPT 1
|
247 |
+
#define MGREET 2
|
248 |
+
#define MLINE 3
|
249 |
+
#define MNUMBER 4
|
250 |
+
#define MVARIABLE 5
|
251 |
+
#define MARRAY 6
|
252 |
+
#define MSTRING 7
|
253 |
+
#define MSTRINGVAR 8
|
254 |
+
#define EGENERAL 9
|
255 |
+
#define EUNKNOWN 10
|
256 |
+
#define ENUMBER 11
|
257 |
+
#define EDIVIDE 12
|
258 |
+
#define ELINE 13
|
259 |
+
#define EOUTOFMEMORY 14
|
260 |
+
#define ESTACK 15
|
261 |
+
#define EORANGE 16
|
262 |
+
#define ESTRING 17
|
263 |
+
#define EVARIABLE 18
|
264 |
+
#define ELOOP 19
|
265 |
+
#define EFILE 20
|
266 |
+
#define EFUN 21
|
267 |
+
#define EARGS 22
|
268 |
+
#define EEEPROM 23
|
269 |
+
#define ESDCARD 24
|
270 |
+
#define MBASICLANGSET 25
|
271 |
+
#define MLANGSET 26
|
272 |
+
#define MKEYWORDS 27
|
273 |
+
|
274 |
+
|
275 |
+
/*
|
276 |
+
* code for variable numbers and addresses sizes
|
277 |
+
* the original code was 16 bit but can be extended here
|
278 |
+
* to arbitrary types
|
279 |
+
*
|
280 |
+
* number_t is the type for numerical work - either float or int
|
281 |
+
* wnumber_t is the type containing the largest printable integer,
|
282 |
+
* for float keep this int on 32 bit and long on 8 bit unless you
|
283 |
+
* want to use very long integers, like 64 or 128 bit types.
|
284 |
+
* address_t is an unsigned type adddressing memory, default 16bit
|
285 |
+
* mem_t is a SIGNED 8bit character type.
|
286 |
+
* index_t is a SIGNED minimum 16 bit integer type
|
287 |
+
*
|
288 |
+
* works with the tacit assumption that
|
289 |
+
* sizeof(number_t) >= sizeof(address_t)
|
290 |
+
* and that the entire memory is smaller than the positive
|
291 |
+
* part of number type (!!)
|
292 |
+
*
|
293 |
+
* we assume that float >= 4 bytes in the following
|
294 |
+
*
|
295 |
+
* maxnum: the maximum accurate(!) integer of a
|
296 |
+
* 32 bit float
|
297 |
+
* strindexsize: the index size of strings either
|
298 |
+
* 1 byte or 2 bytes - no other values supported
|
299 |
+
*/
|
300 |
+
#ifdef HASFLOAT
|
301 |
+
#ifdef HAS64BIT
|
302 |
+
typedef double number_t;
|
303 |
+
typedef long long wnumber_t;
|
304 |
+
#else
|
305 |
+
typedef float number_t;
|
306 |
+
typedef long long wnumber_t;
|
307 |
+
#endif
|
308 |
+
#else
|
309 |
+
#ifdef HAS64BIT
|
310 |
+
typedef int64_t number_t;
|
311 |
+
typedef int64_t wnumber_t;
|
312 |
+
#elif defined(HAS32BITINT)
|
313 |
+
typedef int32_t number_t;
|
314 |
+
typedef int32_t wnumber_t;
|
315 |
+
#else
|
316 |
+
typedef int number_t;
|
317 |
+
typedef int wnumber_t;
|
318 |
+
#endif
|
319 |
+
#endif
|
320 |
+
/* default is 16bit addresses and max 64k memory, setting MEMSIZE in hardware.h overrides this */
|
321 |
+
#if !defined(MEMSIZE) || MEMSIZE < 65536
|
322 |
+
typedef uint16_t address_t; /* this type addresses memory */
|
323 |
+
#else
|
324 |
+
/* use this for large memory systems, tested occassionally */
|
325 |
+
typedef uint32_t address_t;
|
326 |
+
#endif
|
327 |
+
typedef int8_t mem_t; /* a signed 8 bit type for the memory */
|
328 |
+
typedef int index_t; /* this type counts at least 16 bit */
|
329 |
+
#ifndef HASLONGTOKENS
|
330 |
+
typedef int8_t token_t; /* the type of tokens, normally mem_t with a maximum of 127 commands and data types */
|
331 |
+
#else
|
332 |
+
typedef int16_t token_t; /* token type extension, allows more commands and symbols */
|
333 |
+
#endif
|
334 |
+
|
335 |
+
/* the memreader function type, a function accessing memory has to have this shape */
|
336 |
+
typedef mem_t (*memreader_t)(address_t);
|
337 |
+
typedef void (*memwriter_t)(address_t, mem_t);
|
338 |
+
|
339 |
+
/* the worker function type - experimental */
|
340 |
+
typedef void (*bworkfunction_t)();
|
341 |
+
|
342 |
+
/* the location type, this is the cursor on the actual interpreter location */
|
343 |
+
typedef struct {
|
344 |
+
address_t location;
|
345 |
+
token_t token;
|
346 |
+
} blocation_t;
|
347 |
+
|
348 |
+
|
349 |
+
/* the new string type used in the reimplementation of the string functions */
|
350 |
+
/*
|
351 |
+
* stringlength_t is the maximum length of a string, currently only 2 bytes is really tested.
|
352 |
+
* one byte lengthes may work, will be fixed soon to arbitrary types
|
353 |
+
*
|
354 |
+
* string_t says where we can find a string. It is either in BASIC memory and has a valid BASIC memory
|
355 |
+
* address a, or it is in C memory outside mem[]. Then ir says where the string can be found.
|
356 |
+
* This is necessary because BASIC can handle different memory layouts, EEPROM models and serial
|
357 |
+
* memory chips. We cannot simply rely on data to be found in BASIC memory like in old 8 bit
|
358 |
+
* computers or all in C memory like on modern Linux/Windows/Mac systems.
|
359 |
+
*
|
360 |
+
* Components of the string_t:
|
361 |
+
* - the address of the string in BASIC memory
|
362 |
+
* - the C memory pointer ir to the string location, if this is 0, the string is somewhere outside C memory
|
363 |
+
* - the length of the entire string
|
364 |
+
* - the dimension of the string strdim, this is the length of the memory segment reserved for the string
|
365 |
+
* - the dimension of the string array, arraydim
|
366 |
+
*/
|
367 |
+
|
368 |
+
typedef uint16_t stringlength_t;
|
369 |
+
|
370 |
+
typedef struct {
|
371 |
+
address_t address;
|
372 |
+
char* ir;
|
373 |
+
stringlength_t length;
|
374 |
+
address_t strdim;
|
375 |
+
address_t arraydim;
|
376 |
+
} string_t;
|
377 |
+
|
378 |
+
/*
|
379 |
+
* Two types for identifiying objects and lefthandsides.
|
380 |
+
* name_t is the type for variable names and types.
|
381 |
+
* lhsobject_t identifies an assignable object like variables,
|
382 |
+
* arrays and strings.
|
383 |
+
*
|
384 |
+
* Currently name_t only implements two letter objects and lhsobject_t
|
385 |
+
* only implements two dimensional arrays and one dimensional strings.
|
386 |
+
*/
|
387 |
+
typedef struct {
|
388 |
+
token_t token;
|
389 |
+
mem_t c[MAXNAME];
|
390 |
+
mem_t l;
|
391 |
+
} name_t;
|
392 |
+
|
393 |
+
/* used to identify mostly lefthandsides and some righthandsides with these conventions */
|
394 |
+
typedef struct {
|
395 |
+
name_t name; /* the name of a variable */
|
396 |
+
address_t i; /* the start value of a substring or the first index of a number array */
|
397 |
+
address_t j; /* the second index of an array */
|
398 |
+
address_t i2; /* the second value of a substring string */
|
399 |
+
mem_t ps; /* flag to indicate a pure string */
|
400 |
+
} lhsobject_t;
|
401 |
+
|
402 |
+
/* heap objects have a name a size and a payload address */
|
403 |
+
typedef struct {
|
404 |
+
name_t name;
|
405 |
+
address_t address;
|
406 |
+
address_t size;
|
407 |
+
} heap_t;
|
408 |
+
|
409 |
+
/*
|
410 |
+
* a general loop time, needed for the reimplementation of all loops
|
411 |
+
* the loop time knows the variable of a for loop or alternatively
|
412 |
+
* the type of the for loop. For this the token field of the name is
|
413 |
+
* reused. At also knows the here address of the loops beginning and optinally
|
414 |
+
* the end and the step
|
415 |
+
*/
|
416 |
+
typedef struct {
|
417 |
+
name_t var;
|
418 |
+
address_t varaddress; /* experimental to speed up loops */
|
419 |
+
address_t here;
|
420 |
+
number_t to;
|
421 |
+
number_t step;
|
422 |
+
} bloop_t;
|
423 |
+
|
424 |
+
/*
|
425 |
+
* The accumulator type, used for the stack and the
|
426 |
+
* arithmetic operations.
|
427 |
+
*/
|
428 |
+
typedef union {
|
429 |
+
number_t n;
|
430 |
+
address_t a;
|
431 |
+
index_t i;
|
432 |
+
stringlength_t s;
|
433 |
+
mem_t c[sizeof(number_t)];
|
434 |
+
} accu_t;
|
435 |
+
|
436 |
+
/* the timer type, knows the linenumber and all the data of the timer */
|
437 |
+
typedef struct {
|
438 |
+
mem_t enabled;
|
439 |
+
unsigned long last;
|
440 |
+
unsigned long interval;
|
441 |
+
mem_t type;
|
442 |
+
address_t linenumber;
|
443 |
+
} btimer_t;
|
444 |
+
|
445 |
+
/*
|
446 |
+
* The events API for Arduino with interrupt service routines
|
447 |
+
* analogous to the timer API.
|
448 |
+
*
|
449 |
+
* we use raw modes here
|
450 |
+
*
|
451 |
+
* #define CHANGE 1
|
452 |
+
* #define FALLING 2
|
453 |
+
* #define RISING 3
|
454 |
+
*
|
455 |
+
*/
|
456 |
+
|
457 |
+
/* event type for external events */
|
458 |
+
typedef struct {
|
459 |
+
mem_t enabled;
|
460 |
+
mem_t pin;
|
461 |
+
mem_t mode;
|
462 |
+
mem_t type;
|
463 |
+
address_t linenumber;
|
464 |
+
mem_t active;
|
465 |
+
} bevent_t;
|
466 |
+
|
467 |
+
/*
|
468 |
+
* Function prototypes, ordered by layers
|
469 |
+
* HAL - hardware abstraction
|
470 |
+
* Layer 0 - memory and I/O
|
471 |
+
* Layer 1 - Program storage and control
|
472 |
+
* Layer 2 - Where stuff happens
|
473 |
+
*/
|
474 |
+
|
475 |
+
/*
|
476 |
+
* Layer 0 functions - I/O and memory management
|
477 |
+
*/
|
478 |
+
|
479 |
+
/* event types and functions */
|
480 |
+
void bintroutine0();
|
481 |
+
void bintroutine1();
|
482 |
+
void bintroutine2();
|
483 |
+
void bintroutine3();
|
484 |
+
mem_t enableevent(mem_t);
|
485 |
+
void disableevent(mem_t);
|
486 |
+
mem_t eventindex(mem_t);
|
487 |
+
mem_t addevent(mem_t, mem_t, mem_t, address_t);
|
488 |
+
void deleteevent(mem_t);
|
489 |
+
volatile bevent_t* findevent(mem_t);
|
490 |
+
|
491 |
+
/* make room for BASIC */
|
492 |
+
address_t ballocmem();
|
493 |
+
|
494 |
+
/* handle files im EEPROM */
|
495 |
+
void eload();
|
496 |
+
void esave();
|
497 |
+
|
498 |
+
/* starts programs from the filesystem */
|
499 |
+
char autorun();
|
500 |
+
|
501 |
+
/* display a startup banner */
|
502 |
+
void displaybanner();
|
503 |
+
|
504 |
+
/* the variable heap from Apple 1 BASIC */
|
505 |
+
address_t bmalloc(name_t*, address_t);
|
506 |
+
address_t bfind(name_t*);
|
507 |
+
address_t bfree(name_t*);
|
508 |
+
address_t blength (name_t*);
|
509 |
+
|
510 |
+
/* normal variables of number_t */
|
511 |
+
number_t getvar(name_t*);
|
512 |
+
void setvar(name_t*, number_t);
|
513 |
+
void clrvars();
|
514 |
+
|
515 |
+
/* the new set of functions for memory access */
|
516 |
+
number_t getnumber(address_t, memreader_t);
|
517 |
+
address_t getaddress(address_t, memreader_t);
|
518 |
+
stringlength_t getstrlength(address_t, memreader_t);
|
519 |
+
void setnumber(address_t, memwriter_t, number_t);
|
520 |
+
void setaddress(address_t, memwriter_t, address_t);
|
521 |
+
void setstrlength(address_t, memwriter_t, stringlength_t);
|
522 |
+
|
523 |
+
/* setting names */
|
524 |
+
address_t setname_heap(address_t, name_t*);
|
525 |
+
address_t setname_pgm(address_t, name_t*);
|
526 |
+
address_t getname(address_t, name_t*, memreader_t);
|
527 |
+
mem_t cmpname(name_t*, name_t*);
|
528 |
+
void zeroname(name_t*);
|
529 |
+
void zeroheap(heap_t*);
|
530 |
+
|
531 |
+
/* array and string handling */
|
532 |
+
/* the multidim extension is experimental, here only 2 array dimensions implemented as test */
|
533 |
+
address_t createarray(name_t*, address_t, address_t);
|
534 |
+
void array(lhsobject_t*, mem_t, number_t*);
|
535 |
+
address_t createstring(name_t*, address_t, address_t);
|
536 |
+
void getstring(string_t*, name_t*, address_t, address_t);
|
537 |
+
void setstringlength(name_t*, address_t, address_t);
|
538 |
+
|
539 |
+
/* the user defined extension functions */
|
540 |
+
number_t getusrvar();
|
541 |
+
void setusrvar(number_t);
|
542 |
+
number_t getusrarray(address_t);
|
543 |
+
void setusrarray(address_t, number_t);
|
544 |
+
void makeusrstring();
|
545 |
+
number_t usrfunction(address_t, number_t);
|
546 |
+
void usrcall(address_t);
|
547 |
+
|
548 |
+
/* get keywords and tokens from PROGMEM */
|
549 |
+
char* getkeyword(address_t);
|
550 |
+
char* getmessage(char);
|
551 |
+
token_t gettokenvalue(address_t);
|
552 |
+
void printmessage(char);
|
553 |
+
|
554 |
+
/* error handling */
|
555 |
+
void error(token_t);
|
556 |
+
void reseterror();
|
557 |
+
void debugtoken();
|
558 |
+
void bdebug(const char*);
|
559 |
+
|
560 |
+
/* the arithemtic stack */
|
561 |
+
void push(number_t);
|
562 |
+
number_t pop();
|
563 |
+
address_t popaddress();
|
564 |
+
void drop();
|
565 |
+
void clearst();
|
566 |
+
|
567 |
+
/* READ DATA handling */
|
568 |
+
void clrdata();
|
569 |
+
|
570 |
+
/* FOR NEXT GOSUB stacks */
|
571 |
+
void pushforstack(name_t*, number_t, number_t);
|
572 |
+
void popforstack(name_t*, number_t*, number_t*);
|
573 |
+
void dropforstack();
|
574 |
+
void clrforstack();
|
575 |
+
void pushgosubstack(mem_t);
|
576 |
+
void popgosubstack();
|
577 |
+
void dropgosubstack();
|
578 |
+
void clrgosubstack();
|
579 |
+
|
580 |
+
/* handling location rewinds */
|
581 |
+
void pushlocation(blocation_t*);
|
582 |
+
void poplocation(blocation_t*);
|
583 |
+
|
584 |
+
/* signal handling */
|
585 |
+
void signalon();
|
586 |
+
void signaloff();
|
587 |
+
void signalhandler(int);
|
588 |
+
|
589 |
+
/* output */
|
590 |
+
void outcr();
|
591 |
+
void outspc();
|
592 |
+
void outsc(const char*);
|
593 |
+
void outscf(const char *, index_t);
|
594 |
+
|
595 |
+
/* console logger as external function for runtime */
|
596 |
+
void consolelog(char*);
|
597 |
+
void consolelognum(int);
|
598 |
+
|
599 |
+
/* output a name */
|
600 |
+
void outname(name_t*);
|
601 |
+
|
602 |
+
/* I/O of number_t - floats and integers */
|
603 |
+
address_t parsenumber(char*, number_t*);
|
604 |
+
address_t parsenumbern(char*, number_t*); /* can do hex,oct,bin */
|
605 |
+
address_t parsenumber2(char*, number_t*);
|
606 |
+
address_t writenumber(char*, wnumber_t);
|
607 |
+
address_t writenumbern(char*, wnumber_t, mem_t); /* can do hex,oct,bin */
|
608 |
+
address_t writenumber2(char*, number_t);
|
609 |
+
address_t tinydtostrf(number_t, index_t, char*);
|
610 |
+
int innumber(number_t*, char*, address_t);
|
611 |
+
void outnumber(number_t);
|
612 |
+
|
613 |
+
/*
|
614 |
+
* Layer 1 functions, provide data and do the heavy lifting
|
615 |
+
* for layer 2 including lexical analysis, storing programs
|
616 |
+
* and expression evaluation
|
617 |
+
*/
|
618 |
+
|
619 |
+
/* lexical analysis */
|
620 |
+
void whitespaces();
|
621 |
+
void nexttoken();
|
622 |
+
|
623 |
+
/* storing and retrieving programs */
|
624 |
+
char nomemory(number_t);
|
625 |
+
void storetoken();
|
626 |
+
mem_t memread(address_t);
|
627 |
+
mem_t memread2(address_t);
|
628 |
+
void memwrite2(address_t, mem_t);
|
629 |
+
mem_t beread(address_t);
|
630 |
+
void beupdate(address_t, mem_t);
|
631 |
+
void gettoken();
|
632 |
+
void firstline();
|
633 |
+
void nextline();
|
634 |
+
|
635 |
+
void clrlinecache();
|
636 |
+
void addlinecache(address_t, address_t);
|
637 |
+
address_t findinlinecache(address_t);
|
638 |
+
void findline(address_t);
|
639 |
+
address_t myline(address_t);
|
640 |
+
void moveblock(address_t, address_t, address_t);
|
641 |
+
void zeroblock(address_t, address_t);
|
642 |
+
void diag();
|
643 |
+
void storeline();
|
644 |
+
|
645 |
+
/* read arguments from the token stream and process them */
|
646 |
+
char termsymbol();
|
647 |
+
char expect(token_t, mem_t);
|
648 |
+
char expectexpr();
|
649 |
+
void parsearguments();
|
650 |
+
void parsenarguments(char);
|
651 |
+
void parsesubscripts();
|
652 |
+
void parsefunction(void (*)(), short);
|
653 |
+
void parseoperator(void (*)());
|
654 |
+
void parsesubstring();
|
655 |
+
|
656 |
+
/* mathematics and other functions for int and float */
|
657 |
+
void xabs();
|
658 |
+
void xsgn();
|
659 |
+
void xpeek();
|
660 |
+
void xmap();
|
661 |
+
number_t rnd();
|
662 |
+
void xrnd();
|
663 |
+
void sqr();
|
664 |
+
void xpow();
|
665 |
+
number_t bpow(number_t, number_t);
|
666 |
+
|
667 |
+
/* string values and string evaluation */
|
668 |
+
void parsestringvar(string_t*, lhsobject_t*);
|
669 |
+
char stringvalue(string_t*);
|
670 |
+
void streval();
|
671 |
+
|
672 |
+
/* floating point functions */
|
673 |
+
void xsin();
|
674 |
+
void xcos();
|
675 |
+
void xtan();
|
676 |
+
void xatan();
|
677 |
+
void xlog();
|
678 |
+
void xexp();
|
679 |
+
void xint();
|
680 |
+
|
681 |
+
/* expression evaluation */
|
682 |
+
void factor();
|
683 |
+
void power();
|
684 |
+
void term();
|
685 |
+
void addexpression();
|
686 |
+
void compexpression();
|
687 |
+
void notexpression();
|
688 |
+
void andexpression();
|
689 |
+
void expression();
|
690 |
+
|
691 |
+
/* real time clock string stuff */
|
692 |
+
void rtcmkstr();
|
693 |
+
|
694 |
+
/*
|
695 |
+
* Layer 2 - statements and functions
|
696 |
+
* use the global variables
|
697 |
+
*/
|
698 |
+
|
699 |
+
/* basic commands of the core language set */
|
700 |
+
void xprint();
|
701 |
+
void getstringtobuffer(string_t*, char*, stringlength_t);
|
702 |
+
void lefthandside(lhsobject_t*);
|
703 |
+
void assignnumber(lhsobject_t, number_t);
|
704 |
+
void assignstring(string_t*, string_t*, stringlength_t);
|
705 |
+
void assignment();
|
706 |
+
void showprompt();
|
707 |
+
void xinput();
|
708 |
+
void xgoto();
|
709 |
+
void xreturn();
|
710 |
+
void xif();
|
711 |
+
|
712 |
+
/* FOR NEXT loops */
|
713 |
+
void findnextcmd();
|
714 |
+
void findbraket(token_t, token_t);
|
715 |
+
void xfor();
|
716 |
+
void xbreak();
|
717 |
+
void xcont();
|
718 |
+
void xnext();
|
719 |
+
|
720 |
+
/* WHILE WEND*/
|
721 |
+
void xwhile();
|
722 |
+
void xwend();
|
723 |
+
|
724 |
+
/* REPEAT UNTIL */
|
725 |
+
void xrepeat();
|
726 |
+
void xuntil();
|
727 |
+
|
728 |
+
/* control commands and misc */
|
729 |
+
void outputtoken();
|
730 |
+
void xlist();
|
731 |
+
void xrun();
|
732 |
+
void xnew();
|
733 |
+
void xrem();
|
734 |
+
void xclr();
|
735 |
+
void xdim();
|
736 |
+
void xpoke();
|
737 |
+
void xtab();
|
738 |
+
void xdump();
|
739 |
+
void dumpmem(address_t, address_t, char);
|
740 |
+
void xlocate();
|
741 |
+
|
742 |
+
/* file access and other i/o */
|
743 |
+
void stringtobuffer(char*, string_t*);
|
744 |
+
void getfilename(char*, char);
|
745 |
+
void xsave();
|
746 |
+
void xload(const char*);
|
747 |
+
void xget();
|
748 |
+
void xput();
|
749 |
+
void xset();
|
750 |
+
void xnetstat();
|
751 |
+
|
752 |
+
/* Arduino IO control interface */
|
753 |
+
void xaread();
|
754 |
+
void xdread();
|
755 |
+
void xdwrite();
|
756 |
+
void xawrite();
|
757 |
+
void xpinm();
|
758 |
+
void xdelay();
|
759 |
+
void xtone();
|
760 |
+
void btone(int);
|
761 |
+
void bpulsein();
|
762 |
+
|
763 |
+
/* graphics commands */
|
764 |
+
void xcolor();
|
765 |
+
void xplot();
|
766 |
+
void xline();
|
767 |
+
void xrect();
|
768 |
+
void xcircle();
|
769 |
+
void xfrect();
|
770 |
+
void xfcircle();
|
771 |
+
|
772 |
+
/* the darkarts */
|
773 |
+
void xmalloc();
|
774 |
+
void xfind();
|
775 |
+
void xeval();
|
776 |
+
|
777 |
+
/* IoT commands */
|
778 |
+
void xavail();
|
779 |
+
void xfsensor();
|
780 |
+
void xsleep();
|
781 |
+
void xwire();
|
782 |
+
void xfwire();
|
783 |
+
|
784 |
+
/* timers */
|
785 |
+
void xafter();
|
786 |
+
void xevent();
|
787 |
+
|
788 |
+
/* File I/O functions */
|
789 |
+
char streq(const char*, char*);
|
790 |
+
void xcatalog();
|
791 |
+
void xdelete();
|
792 |
+
void xopen();
|
793 |
+
void xfopen();
|
794 |
+
void xclose();
|
795 |
+
void xfdisk();
|
796 |
+
|
797 |
+
/* low level access functions */
|
798 |
+
void xcall();
|
799 |
+
void xusr();
|
800 |
+
|
801 |
+
/* the dartmouth stuff */
|
802 |
+
void xdata();
|
803 |
+
void nextdatarecord();
|
804 |
+
void xread();
|
805 |
+
void xrestore();
|
806 |
+
void xdef();
|
807 |
+
void xfn(mem_t);
|
808 |
+
void xon();
|
809 |
+
|
810 |
+
/* timers and interrupts */
|
811 |
+
void xtimer();
|
812 |
+
void resettimer(btimer_t*);
|
813 |
+
|
814 |
+
/* structured BASIC extensions */
|
815 |
+
void xwhile();
|
816 |
+
void xwend();
|
817 |
+
void xrepeat();
|
818 |
+
void xuntil();
|
819 |
+
void xswitch();
|
820 |
+
void xcase();
|
821 |
+
void xendswitch();
|
822 |
+
|
823 |
+
/* the editor */
|
824 |
+
void xedit();
|
825 |
+
|
826 |
+
/* the statement loop */
|
827 |
+
void statement();
|
828 |
+
|
829 |
+
/* the extension functions */
|
830 |
+
void bsetup();
|
831 |
+
void bloop();
|
data/Basic2/IoTBasic/boards/aim65.h
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* the AIM 65 lookalike */
|
2 |
+
#define ARDUINOPS2
|
3 |
+
#define DISPLAYCANSCROLL
|
4 |
+
#define ARDUINOLCDI2C
|
5 |
+
#define ARDUINOEEPROM
|
6 |
+
#define STANDALONE
|
data/Basic2/IoTBasic/boards/avrlcd.h
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
/* an AVR ARDUINO (UNO or MEGA) with the classical LCD shield */
|
2 |
+
#define DISPLAYCANSCROLL
|
3 |
+
#define LCDSHIELD
|
data/Basic2/IoTBasic/boards/avrmcufriend.h
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
/* an AVR ARDUINO (UNO or MEGA) with a parallel TFT */
|
2 |
+
#define DISPLAYCANSCROLL
|
3 |
+
#define ARDUINOMCUFRIEND
|
data/Basic2/IoTBasic/boards/duetft.h
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* DUE with a TFT shield, standalone by default
|
3 |
+
*/
|
4 |
+
#undef ARDUINOEEPROM
|
5 |
+
#define ARDUINOPS2
|
6 |
+
#undef ARDUINOUSBKBD
|
7 |
+
#define DISPLAYCANSCROLL
|
8 |
+
#define ARDUINOTFT
|
9 |
+
#define ARDUINOSD
|
10 |
+
#define ARDUINOWIRE
|
11 |
+
#define ARDUINOPRT
|
12 |
+
#define ARDUINORTC
|
13 |
+
#define PS2DATAPIN 9
|
14 |
+
#define PS2IRQPIN 8
|
15 |
+
#define SDPIN 53
|
16 |
+
#define STANDALONE
|
data/Basic2/IoTBasic/boards/dummy.h
ADDED
File without changes
|
data/Basic2/IoTBasic/boards/esp01board.h
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
i/* an ESP01 board, using the internal flash
|
2 |
+
* with the ESP01-8266 only pins 0 and 2 are usable freely
|
3 |
+
* on ESP01-ESP32C3 this is 9 and 2 while 2 is an analog pin
|
4 |
+
* 9 cannot be pulled on low by any peripheral on boot because this
|
5 |
+
* brings the board to flash mode
|
6 |
+
*/
|
7 |
+
#undef ARDUINOEEPROM
|
8 |
+
#define ESPSPIFFS
|
9 |
+
#define ARDUINOMQTT
|
10 |
+
#define ARDUINOWIRE
|
11 |
+
#if defined(ARDUINOWIRE) && defined(ARDUINO_ARCH_ESP8266)
|
12 |
+
#define SDA_PIN 0
|
13 |
+
#define SCL_PIN 2
|
14 |
+
#endif
|
15 |
+
/* see: https://github.com/espressif/arduino-esp32/issues/6376
|
16 |
+
* nothing should block the port, e.g. DHT or anything
|
17 |
+
*/
|
18 |
+
#if defined(ARDUINOWIRE) && defined(ARDUINO_ARCH_ESP32)
|
19 |
+
#define SDA_PIN 9
|
20 |
+
#define SCL_PIN 2
|
21 |
+
#endif
|
22 |
+
/*
|
23 |
+
*
|
24 |
+
* Currently only 8=SDA and 9=SCL works / tested with AHT10
|
25 |
+
*/
|
data/Basic2/IoTBasic/boards/esp32board.h
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* an ESP32 board with an ILI9488 display,
|
2 |
+
some SD problems here with some hardware */
|
3 |
+
#define ILI_CS 12
|
4 |
+
#define ILI_DC 27
|
5 |
+
#define ILI_RST 14
|
6 |
+
#define ILI_LED 26
|
7 |
+
#undef ARDUINOPICOSERIAL
|
8 |
+
#define ESPSPIFFS
|
9 |
+
#define DISPLAYCANSCROLL
|
10 |
+
#define ARDUINOILI9488
|
11 |
+
#define ARDUINOEEPROM
|
12 |
+
#define ARDUINOMQTT
|
13 |
+
#define ARDUINOWIRE
|
data/Basic2/IoTBasic/boards/esp32cam.h
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
/* the ESP32 camera */
|
2 |
+
/* needs an MMC SD card and has its own drivers */
|
3 |
+
#define ESPSDCAM
|
data/Basic2/IoTBasic/boards/megaboard.h
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* A board for the MEGA with 64 kB RAM, SD Card, and real time clock
|
3 |
+
*/
|
4 |
+
#undef ARDUINOPICOSERIAL
|
5 |
+
#define DISPLAYCANSCROLL
|
6 |
+
#define ARDUINOLCDI2C
|
7 |
+
#define ARDUINOEEPROM
|
8 |
+
#define ARDUINOPRT
|
9 |
+
#define ARDUINOSD
|
10 |
+
#define ARDUINOWIRE
|
11 |
+
#define ARDUINORTC
|
12 |
+
#define ARDUINOSPIRAM
|
13 |
+
#define RAMPIN 53
|
14 |
+
#define SDPIN 49
|
data/Basic2/IoTBasic/boards/megashield.h
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Mega with a Ethernet shield
|
3 |
+
* standalone capable, Ethernet is not enabled by default
|
4 |
+
*/
|
5 |
+
#define ARDUINOEEPROM
|
6 |
+
#define ARDUINOPS2
|
7 |
+
#define DISPLAYCANSCROLL
|
8 |
+
#define ARDUINOLCDI2C
|
9 |
+
#define ARDUINOSD
|
10 |
+
#define ARDUINOWIRE
|
11 |
+
#define ARDUINOPRT
|
12 |
+
#define SDPIN 4
|
13 |
+
//#define ARDUINOETH
|
data/Basic2/IoTBasic/boards/megatft.h
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* MEGA with a TFT shield, standalone by default
|
3 |
+
*/
|
4 |
+
#define ARDUINOEEPROM
|
5 |
+
#define ARDUINOPS2
|
6 |
+
#define DISPLAYCANSCROLL
|
7 |
+
#define ARDUINOTFT
|
8 |
+
#define ARDUINOSD
|
9 |
+
#define ARDUINOWIRE
|
10 |
+
#define ARDUINOPRT
|
11 |
+
#define PS2DATAPIN 18
|
12 |
+
#define PS2IRQPIN 19
|
13 |
+
#define SDPIN 53
|
14 |
+
#define STANDALONE
|
data/Basic2/IoTBasic/boards/mkr1010board.h
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* a board based on the Arduino MKR 1010 Wifi
|
2 |
+
* made for low energy games
|
3 |
+
*/
|
4 |
+
#define ILI_CS 7
|
5 |
+
#define ILI_DC 4
|
6 |
+
#define ILI_RST 6
|
7 |
+
#define ILI_LED A3
|
8 |
+
#undef ARDUINOPICOSERIAL
|
9 |
+
#define DISPLAYCANSCROLL
|
10 |
+
#define ARDUINOILI9488
|
11 |
+
#define ARDUINOEFS
|
12 |
+
#define ARDUINOMQTT
|
13 |
+
#define ARDUINOWIRE
|
14 |
+
/* EEPROM emulation is possible, takes 2k of memory */
|
15 |
+
#undef ARDUINOEEPROM
|
16 |
+
/* careful with the setting, lockout possible easily */
|
17 |
+
#undef ARDUINOUSBKBD
|
18 |
+
#undef STANDALONE
|
data/Basic2/IoTBasic/boards/nanoboard.h
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*Arduino Nano Every board with PS2 keyboard and sensor
|
3 |
+
*/
|
4 |
+
#undef ARDUINOPICOSERIAL
|
5 |
+
#define ARDUINOPS2
|
6 |
+
#define DISPLAYCANSCROLL
|
7 |
+
#define ARDUINOLCDI2C
|
8 |
+
#define ARDUINOEEPROM
|
9 |
+
#define ARDUINOPRT
|
10 |
+
#define ARDUINOEFS
|
11 |
+
#define ARDUINORTC
|
12 |
+
#define ARDUINOWIRE
|
13 |
+
#define EFSEEPROMADDR 0x050 /* use clock EEPROM 0x057, set to 0x050 for external EEPROM */
|
14 |
+
#define STANDALONE
|
data/Basic2/IoTBasic/boards/rp2040board.h
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* an RP2040 based board with an ILI9488 display */
|
2 |
+
#undef ARDUINOPICOSERIAL
|
3 |
+
#define DISPLAYCANSCROLL
|
4 |
+
#define ARDUINOILI9488
|
5 |
+
#undef ARDUINOEEPROM
|
6 |
+
#define ARDUINOI2CEEPROM
|
7 |
+
#define ARDUINOPRT
|
8 |
+
#define ARDUINOSD
|
9 |
+
#undef RP2040LITTLEFS
|
10 |
+
#define ARDUINOWIRE
|
11 |
+
#define ARDUINORTC
|
12 |
+
#define ARDUINOPS2
|
13 |
+
#define ARDUINOMQTT
|
14 |
+
#define STANDALONE
|
data/Basic2/IoTBasic/boards/rp2040board2.h
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* an RP2040 Raspberry Pi Pico based board with an ILI9488 display */
|
2 |
+
#undef ARDUINOPICOSERIAL
|
3 |
+
#define DISPLAYCANSCROLL
|
4 |
+
#define ARDUINOILI9488
|
5 |
+
#undef ARDUINOEEPROM
|
6 |
+
#undef ARDUINOPRT
|
7 |
+
#undef ARDUINOSD
|
8 |
+
#define RP2040LITTLEFS
|
9 |
+
#undef ARDUINOWIRE
|
10 |
+
#undef ARDUINORTC
|
11 |
+
#undef ARDUINOPS2
|
12 |
+
#undef ARDUINOMQTT
|
13 |
+
#undef STANDALONE
|
14 |
+
#define ILI_LED A2
|
15 |
+
#define ILI_CS 15
|
16 |
+
#define ILI_RST 14
|
17 |
+
#define ILI_DC 13
|
data/Basic2/IoTBasic/boards/tdeck.h
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
i/*
|
2 |
+
* The Liligo T-Deck configuration
|
3 |
+
* supports the internal FFAT right now, SD not yet done
|
4 |
+
*/
|
5 |
+
/* these are the PIN definition from Lilygos utilities.h file */
|
6 |
+
#define BOARD_POWERON 10
|
7 |
+
#define BOARD_I2S_WS 5
|
8 |
+
#define BOARD_I2S_BCK 7
|
9 |
+
#define BOARD_I2S_DOUT 6
|
10 |
+
#define BOARD_I2C_SDA 18
|
11 |
+
#define BOARD_I2C_SCL 8
|
12 |
+
#define BOARD_BAT_ADC 4
|
13 |
+
#define BOARD_TOUCH_INT 16
|
14 |
+
#define BOARD_KEYBOARD_INT 46
|
15 |
+
#define BOARD_SDCARD_CS 39
|
16 |
+
#define BOARD_TFT_CS 12
|
17 |
+
#define RADIO_CS_PIN 9
|
18 |
+
#define BOARD_TFT_DC 11
|
19 |
+
#define BOARD_TFT_BACKLIGHT 42
|
20 |
+
#define BOARD_SPI_MOSI 41
|
21 |
+
#define BOARD_SPI_MISO 38
|
22 |
+
#define BOARD_SPI_SCK 40
|
23 |
+
#define BOARD_TBOX_G02 2
|
24 |
+
#define BOARD_TBOX_G01 3
|
25 |
+
#define BOARD_TBOX_G04 1
|
26 |
+
#define BOARD_TBOX_G03 15
|
27 |
+
#define BOARD_ES7210_MCLK 48
|
28 |
+
#define BOARD_ES7210_LRCK 21
|
29 |
+
#define BOARD_ES7210_SCK 47
|
30 |
+
#define BOARD_ES7210_DIN 14
|
31 |
+
#define RADIO_BUSY_PIN 13
|
32 |
+
#define RADIO_RST_PIN 17
|
33 |
+
#define RADIO_DIO1_PIN 45
|
34 |
+
#define BOARD_BOOT_PIN 0
|
35 |
+
#define BOARD_BL_PIN 42
|
36 |
+
#define BOARD_GPS_TX_PIN 43
|
37 |
+
#define BOARD_GPS_RX_PIN 44
|
38 |
+
#ifndef RADIO_FREQ
|
39 |
+
#define RADIO_FREQ 868.0
|
40 |
+
#endif
|
41 |
+
#ifndef RADIO_BANDWIDTH
|
42 |
+
#define RADIO_BANDWIDTH 125.0
|
43 |
+
#endif
|
44 |
+
#ifndef RADIO_SF
|
45 |
+
#define RADIO_SF 10
|
46 |
+
#endif
|
47 |
+
#ifndef RADIO_CR
|
48 |
+
#define RADIO_CR 6
|
49 |
+
#endif
|
50 |
+
#ifndef RADIO_TX_POWER
|
51 |
+
#define RADIO_TX_POWER 22
|
52 |
+
#endif
|
53 |
+
#define DEFAULT_OPA 100
|
54 |
+
/* and now the BASIC stuff begins */
|
55 |
+
/* either use the buildin FAT as a file system */
|
56 |
+
#undef ESP32FAT
|
57 |
+
/* or the SD card */
|
58 |
+
#define ARDUINOSD
|
59 |
+
#define SDPIN BOARD_SDCARD_CS
|
60 |
+
/* the display */
|
61 |
+
#define TFTESPI
|
62 |
+
#define DISPLAYCANSCROLL
|
63 |
+
/*the keyboard */
|
64 |
+
#define ARDUINOI2CKBD
|
65 |
+
#define SDA_PIN BOARD_I2C_SDA
|
66 |
+
#define SCL_PIN BOARD_I2C_SCL
|
67 |
+
#define I2CKBDADDR 0x55
|
68 |
+
/* can run standalone now */
|
69 |
+
#define STANDALONE
|
data/Basic2/IoTBasic/boards/ttgovga.h
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* VGA system with SD card, based on the TTGO VGA 1.4
|
3 |
+
* ESP32
|
4 |
+
* standalone by default, with MQTT
|
5 |
+
*/
|
6 |
+
#define ARDUINOEEPROM
|
7 |
+
#define ARDUINOVGA
|
8 |
+
#define ARDUINOSD
|
9 |
+
#define SDPIN 13
|
10 |
+
#define STANDALONE
|
11 |
+
/*
|
12 |
+
* This is a large screen with 48 kB memory, good fonts.
|
13 |
+
* with these settings a circle is round in my old 4:3 TFT.
|
14 |
+
* should work for most situations. Ideally the canvas
|
15 |
+
* matches the TFT screen resolution.
|
16 |
+
*
|
17 |
+
* Set COLUMNS and ROW for a smaller terminal.
|
18 |
+
*
|
19 |
+
* The font is set automatically. Can be changed here for
|
20 |
+
* smaller terminals.
|
21 |
+
*/
|
22 |
+
#define TTGOVGACONTROLLER VGA16Controller
|
23 |
+
#define TTGOVGARESOLUTION VGA_512x384_60Hz
|
24 |
+
#define TTGOVGAFONT FONT_8x16
|
25 |
+
#define TTGOVGACOLUMNS -1
|
26 |
+
#define TTGOVGAROWS -1
|
27 |
+
#define MEMSIZE 48000
|
28 |
+
#undef ARDUINOMQTT
|
29 |
+
// Runnings configs:
|
30 |
+
/* VGA4 and network - flickery screen 640*480 */
|
31 |
+
/*
|
32 |
+
#define TTGOVGACONTROLLER VGA4Controller
|
33 |
+
#define TTGOVGACOLUMNS -1
|
34 |
+
#define TTGOVGAROWS -1
|
35 |
+
#define MEMSIZE 48000
|
36 |
+
#define ARDUINOMQTT
|
37 |
+
*/
|
38 |
+
/* VGA4 and network - flickery screen 640*480 */
|
39 |
+
/*
|
40 |
+
#define TTGOVGACONTROLLER VGA4Controller
|
41 |
+
#define TTGOVGARESOLUTION VGA_512x384_60Hz
|
42 |
+
#define TTGOVGACOLUMNS -1
|
43 |
+
#define TTGOVGAROWS -1
|
44 |
+
#define MEMSIZE 64000
|
45 |
+
#define ARDUINOMQTT
|
46 |
+
*/
|
47 |
+
/* VGA16, no network, stable sreen 640*480 */
|
48 |
+
/*
|
49 |
+
#define TTGOVGACONTROLLER VGA16Controller
|
50 |
+
#define TTGOVGACOLUMNS -1
|
51 |
+
#define TTGOVGAROWS -1
|
52 |
+
#define MEMSIZE 32000
|
53 |
+
#undef ARDUINOMQTT
|
54 |
+
*/
|
55 |
+
/* full VGA controller at 320*200 an 32 kB */
|
56 |
+
/*
|
57 |
+
#define TTGOVGACONTROLLER VGAController
|
58 |
+
#define TTGOVGARESOLUTION VGA_320x200_75HzRetro
|
59 |
+
#define TTGOVGAFONT FONT_8x8
|
60 |
+
#define TTGOVGACOLUMNS -1
|
61 |
+
#define TTGOVGAROWS -1
|
62 |
+
#define MEMSIZE 32000
|
63 |
+
#undef ARDUINOMQTT
|
64 |
+
*/
|
65 |
+
/* A 4:3 screen with full VGA */
|
66 |
+
/*
|
67 |
+
#define TTGOVGACONTROLLER VGAController
|
68 |
+
#define TTGOVGARESOLUTION VGA_400x300_60Hz
|
69 |
+
#define TTGOVGAFONT FONT_8x8
|
70 |
+
#define TTGOVGACOLUMNS -1
|
71 |
+
#define TTGOVGAROWS -1
|
72 |
+
#define MEMSIZE 32000
|
73 |
+
#undef ARDUINOMQTT
|
74 |
+
*/
|
75 |
+
|
data/Basic2/IoTBasic/boards/unoboard.h
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* a UNO shield with memory and EFS EEPROM */
|
2 |
+
#define ARDUINOEEPROM
|
3 |
+
#define ARDUINOSPIRAM
|
4 |
+
#define ARDUINOEFS
|
5 |
+
#define ARDUINOWIRE
|
6 |
+
#define EFSEEPROMADDR 0x050
|
7 |
+
#define EFSEEPROMSIZE 65534
|
data/Basic2/IoTBasic/boards/wemosshield.h
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* a Wemos ESP8266 with a mdified datalogger shield
|
3 |
+
* standalone capable, with Wire and MQTT.
|
4 |
+
*/
|
5 |
+
#define ARDUINOEEPROM
|
6 |
+
#define ARDUINOPS2
|
7 |
+
#define DISPLAYCANSCROLL
|
8 |
+
#define ARDUINOLCDI2C
|
9 |
+
#define ARDUINOSD
|
10 |
+
#define ARDUINORTC
|
11 |
+
#define ARDUINOWIRE
|
12 |
+
#define SDPIN D8
|
13 |
+
#define PS2DATAPIN D2
|
14 |
+
#define PS2IRQPIN D9
|
15 |
+
#define ARDUINOMQTT
|
data/Basic2/IoTBasic/buildin/buildin-arduinotest.h
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const char buildin_pgm1[] PROGMEM = {
|
2 |
+
"10 REM Test program for integer BASICs\n"
|
3 |
+
"100 PRINT \"*** Core language features ***\"\n"
|
4 |
+
"110 A=5: B=19: C=A-B: D=A+B: E=A*B: F=INT(B/A)\n"
|
5 |
+
"120 PRINT \"Math:\"\n"
|
6 |
+
"130 PRINT A,B,C,D,E,F\n"
|
7 |
+
"140 PRINT A,B,A-B,A+B,A*B,INT(B/A)\n"
|
8 |
+
"150 PRINT \"5 19 -14 24 95 3\"\n"
|
9 |
+
"200 PRINT \"Loop and GOTO:\"\n"
|
10 |
+
"210 FOR I=1 TO 10\n"
|
11 |
+
"220 PRINT I,\n"
|
12 |
+
"230 NEXT: PRINT \n"
|
13 |
+
"240 FOR I=1\n"
|
14 |
+
"250 PRINT I,: IF I=10 BREAK\n"
|
15 |
+
"260 NEXT: PRINT\n"
|
16 |
+
"270 I=1\n"
|
17 |
+
"280 PRINT I,: I=I+1: IF I<=10: GOTO 280\n"
|
18 |
+
"290 PRINT\n"
|
19 |
+
"300 PRINT \"GOSUB and RETURN\"\n"
|
20 |
+
"310 GOSUB 340\n"
|
21 |
+
"320 PRINT \"Returned\"\n"
|
22 |
+
"330 GOTO 400\n"
|
23 |
+
"340 PRINT \"In GOSUB\"\n"
|
24 |
+
"350 RETURN\n"
|
25 |
+
"400 PRINT \"Functions\"\n"
|
26 |
+
"410 A=-1: B=1: @R=1\n"
|
27 |
+
"420 PRINT SGN(A), SGN(B), ABS(A), RND(10)\n"
|
28 |
+
"430 PRINT \"-1 1 1\"\n"
|
29 |
+
"500 PRINT \"*** Arduino features ***\"\n"
|
30 |
+
"510 PRINT \"Blink\"\n"
|
31 |
+
"520 PINM LED, 1\n"
|
32 |
+
"530 FOR I=1 TO 4: DWRITE LED, 1: DELAY 200: DWRITE LED, 0: NEXT\n"
|
33 |
+
"540 PRINT \"Time\"\n"
|
34 |
+
"550 PRINT MILLIS(1): DELAY 200: PRINT MILLIS(1)\n"
|
35 |
+
"560 PRINT \"EEPROM\"\n"
|
36 |
+
"570 PRINT \"Size:\", @E\n"
|
37 |
+
"580 FOR I=1 TO 4: PRINT I, @E(I): NEXT\n"
|
38 |
+
"590 @E(1)=10: PRINT \"10=\",@E(1)\n"
|
39 |
+
"600 PRINT \"*** Dartmouth features ***\"\n"
|
40 |
+
"610 DEF FNF(X)=X*X \n"
|
41 |
+
"620 X=5: PRINT \"X=\", X \n"
|
42 |
+
"630 PRINT \"FNF(7)=\", FNF(7)\n"
|
43 |
+
"640 PRINT \"X=\",X \n"
|
44 |
+
"650 FOR I=1 TO 3\n"
|
45 |
+
"660 ON I GOSUB 700, 710, 720\n"
|
46 |
+
"670 NEXT\n"
|
47 |
+
"680 GOTO 800\n"
|
48 |
+
"700 PRINT \"One\": RETURN\n"
|
49 |
+
"710 PRINT \"Two\": RETURN\n"
|
50 |
+
"720 PRINT \"Three\": RETURN\n"
|
51 |
+
"730 DATA \"Hello\", \"World\", 31414\n"
|
52 |
+
"800 READ A$, B$: PRINT A$,B$\n"
|
53 |
+
"810 READ A: PRINT \"PI is\",A\n"
|
54 |
+
"820 PRINT \"DATA pointer is\", DATA\n"
|
55 |
+
"900 PRINT \"*** Strings ***\"\n"
|
56 |
+
"910 A$=\"Hello World\"\n"
|
57 |
+
"920 PRINT A$, \":\", LEN(A$)\n"
|
58 |
+
"930 FOR I=1 TO LEN(A$)\n"
|
59 |
+
"940 PRINT TAB(I-1);A$(I)\n"
|
60 |
+
"950 NEXT\n"
|
61 |
+
"960 FOR I=1 TO LEN(A$)\n"
|
62 |
+
"970 PRINT A$(1,I)\n"
|
63 |
+
"980 NEXT\n"
|
64 |
+
"990 B$=\"Arduino says \"\n"
|
65 |
+
"1000 B$=B$+A$: PRINT B$\n"
|
66 |
+
"1010 B$=STR$(A): PRINT \"PI is\", B$\n"
|
67 |
+
"1020 B=VAL(B$): PRINT \"PI is\", B \n"
|
68 |
+
"1030 PRINT \"String length pointer is\", @V\n"
|
69 |
+
"1040 FOR I=1 TO 5\n"
|
70 |
+
"1050 PRINT TAB(I-1);MID$(A$,I,LEN(A$)-2*I+1)\n"
|
71 |
+
"1060 NEXT\n"
|
72 |
+
"1070 FOR I=1 TO 5: PRINT LEFT$(A$,I): NEXT\n"
|
73 |
+
"1080 FOR I=1 TO 5: PRINT TAB(5-I);RIGHT$(A$,I): NEXT\n"
|
74 |
+
"\f"
|
75 |
+
};
|
76 |
+
const char buildin_pgm1_name[] PROGMEM = "*corep.bas";
|
77 |
+
const char* const buildin_programs[] PROGMEM = {
|
78 |
+
buildin_pgm1,
|
79 |
+
0
|
80 |
+
};
|
81 |
+
const char* const buildin_program_names[] PROGMEM = {
|
82 |
+
buildin_pgm1_name,
|
83 |
+
0
|
84 |
+
};
|
data/Basic2/IoTBasic/buildin/buildin-games.h
ADDED
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const char buildin_pgm1[] PROGMEM = {
|
2 |
+
"10 REM \"TIC TAC TOE from 101 BASIC games\"\n"
|
3 |
+
"20 REM \"by David Ahl.\"\n"
|
4 |
+
"30 REM \"Ported to Stefan's BASIC in 2021\"\n"
|
5 |
+
"40 REM \"The machine goes first\"\n"
|
6 |
+
"100 PRINT \"Welcome to tictactoe\"\n"
|
7 |
+
"110 PRINT \"The game board is numbered:\"\n"
|
8 |
+
"120 PRINT\n"
|
9 |
+
"130 PRINT \"1 2 3\"\n"
|
10 |
+
"140 PRINT \"8 9 4\"\n"
|
11 |
+
"150 PRINT \"7 6 5\"\n"
|
12 |
+
"160 PRINT\n"
|
13 |
+
"200 REM \"Main Program\"\n"
|
14 |
+
"210 PRINT \"Staring a new game\"\n"
|
15 |
+
"230 A=9\n"
|
16 |
+
"240 M=A\n"
|
17 |
+
"250 GOSUB 800 \n"
|
18 |
+
"260 P=M\n"
|
19 |
+
"270 B=P%8+1\n"
|
20 |
+
"280 M=B\n"
|
21 |
+
"290 GOSUB 800 \n"
|
22 |
+
"300 Q=M\n"
|
23 |
+
"310 IF Q=(B+3)%8+1 GOTO 360\n"
|
24 |
+
"320 C=(B+3)%8+1\n"
|
25 |
+
"330 M=C\n"
|
26 |
+
"340 GOSUB 900 \n"
|
27 |
+
"350 GOTO 640 \n"
|
28 |
+
"360 C=(B+1)%8+1\n"
|
29 |
+
"370 M=C\n"
|
30 |
+
"380 GOSUB 800 \n"
|
31 |
+
"390 R=M\n"
|
32 |
+
"400 IF R=(C+3)%8+1 GOTO 450\n"
|
33 |
+
"410 D=(C+3)%8+1\n"
|
34 |
+
"420 M=D\n"
|
35 |
+
"430 GOSUB 900\n"
|
36 |
+
"440 GOTO 640 \n"
|
37 |
+
"450 IF P%2<>0 GOTO 500\n"
|
38 |
+
"460 D=(C+6)%8+1\n"
|
39 |
+
"470 M=D\n"
|
40 |
+
"480 GOSUB 900\n"
|
41 |
+
"490 GOTO 640 \n"
|
42 |
+
"500 D=(C+2)%8+1\n"
|
43 |
+
"510 M=D\n"
|
44 |
+
"520 GOSUB 800 \n"
|
45 |
+
"530 S=M\n"
|
46 |
+
"540 IF S=(D+3)%8+1 GOTO 590\n"
|
47 |
+
"550 E=(D+3)%8+1\n"
|
48 |
+
"560 M=E\n"
|
49 |
+
"570 GOSUB 900\n"
|
50 |
+
"580 REM \"Game is a draw\"\n"
|
51 |
+
"590 E=(D+5)%8+1\n"
|
52 |
+
"600 M=E\n"
|
53 |
+
"610 GOSUB 900\n"
|
54 |
+
"620 PRINT \"The game is a draw.\"\n"
|
55 |
+
"630 GOTO 200\n"
|
56 |
+
"640 PRINT \"and wins! ********\"\n"
|
57 |
+
"650 GOTO 200\n"
|
58 |
+
"800 REM \"Subroutine to ask user for the move\"\n"
|
59 |
+
"810 GOSUB 900\n"
|
60 |
+
"820 INPUT \"Your move? \", M\n"
|
61 |
+
"830 RETURN\n"
|
62 |
+
"900 REM \"Subroutine to display move\"\n"
|
63 |
+
"910 PRINT \"Computer moves:\",M\n"
|
64 |
+
"920 RETURN\n"
|
65 |
+
"\f"
|
66 |
+
};
|
67 |
+
const char buildin_pgm1_name[] PROGMEM = "*tictac.bas";
|
68 |
+
const char buildin_pgm2[] PROGMEM = {
|
69 |
+
"10 REM \"Rocket from 101 Basic Games\"\n"
|
70 |
+
"20 REM \"Ported to Stefan's BASIC in 2021\"\n"
|
71 |
+
"30 PRINT\n"
|
72 |
+
"100 PRINT \"LUNAR LANDING SIMULATION\"\n"
|
73 |
+
"110 PRINT \"----- ------- ----------\":PRINT \n"
|
74 |
+
"120 INPUT \"DO YOU WANT INSTRUCTIONS (YES OR NO)? \";A$\n"
|
75 |
+
"130 IF A$(1,1)=\"N\" OR A$(1,1)=\"n\" THEN 390\n"
|
76 |
+
"140 CLS \n"
|
77 |
+
"150 PRINT \n"
|
78 |
+
"200 PRINT \"YOU ARE LANDING ON THE MOON AND AND HAVE\"\n"
|
79 |
+
"210 PRINT \"TAKEN OVER MANUAL CONTROL 1000 FEET\"\n"
|
80 |
+
"215 PRINT \"ABOVE A GOOD LANDING SPOT.\": PRINT \n"
|
81 |
+
"220 PRINT \"YOU HAVE A DOWNWARD VELOCITY OF 50 FEET/SEC.\"\n"
|
82 |
+
"225 PRINT \"150 UNITS OF FUEL REMAIN.\": PRINT \n"
|
83 |
+
"230 PRINT \"HERE ARE THE RULES THAT GOVERN YOUR DESCENT\"\n"
|
84 |
+
"240 PRINT \"(1) AFTER EACH SECOND THE HEIGHT, VELOCITY, AND\"\n"
|
85 |
+
"250 PRINT \" REMAINING FUEL WILL BE REPORTED BY YOUR\"\n"
|
86 |
+
"255 PRINT \" ON-BOARD COMPUTER.\"\n"
|
87 |
+
"260 PRINT \"(2) AFTER THE REPORT A '?' WILL APPEAR. ENTER\"\n"
|
88 |
+
"270 PRINT \" THE NUMBER OF UNITS OF FUEL YOU WISH TO BURN\"\n"
|
89 |
+
"280 PRINT \" DURING THE NEXT SECOND. EACH UNIT OF FUEL\"\n"
|
90 |
+
"285 PRINT \" WILL SLOW YOUR DESCENT BY 1 FOOT/SEC.\"\n"
|
91 |
+
"310 PRINT \"(3) THE MAXIMUM THRUST OF YOUR ENGINE IS \"\n"
|
92 |
+
"315 PRINT \" 30 FEET/SEC/SEC OR 30 UNITS OF FUEL\"\n"
|
93 |
+
"320 PRINT \" PER SECOND.\"\n"
|
94 |
+
"330 PRINT \"(4) WHEN YOU CONTACT THE LUNAR SURFACE. YOUR \"\n"
|
95 |
+
"340 PRINT \" DESCENT ENGINE WILL AUTOMATICALLY SHUT DOWN\"\n"
|
96 |
+
"345 PRINT \" AND YOU WILL BE GIVEN A REPORT OF YOUR \"\n"
|
97 |
+
"350 PRINT \" LANDING SPEED AND REMAINING FUEL.\"\n"
|
98 |
+
"360 PRINT \"(5) IF YOU RUN OUT OF FUEL THE '?' WILL NO\"\n"
|
99 |
+
"370 PRINT \" LONGER APPEAR BUT YOUR SECOND BY SECOND\"\n"
|
100 |
+
"380 PRINT \" REPORT WILL CONTINUE UNTIL YOU CONTACT THE\"\n"
|
101 |
+
"385 PRINT \" LUNAR SURFACE.\":PRINT \n"
|
102 |
+
"390 PRINT \"BEGINNING LANDING PROCEDURE..........\":PRINT \n"
|
103 |
+
"400 PRINT \"G O O D L U C K ! ! !\"\n"
|
104 |
+
"420 PRINT\n"
|
105 |
+
"425 INPUT \"Read to go - press return \", A$\n"
|
106 |
+
"426 CLS \n"
|
107 |
+
"430 PRINT \"SEC FEET SPEED FUEL \"\n"
|
108 |
+
"450 PRINT\n"
|
109 |
+
"455 T=0: H=1000: V=50: F=150\n"
|
110 |
+
"490 PRINT #6,T,H,V,F;\" I\";\n"
|
111 |
+
"495 TAB(H/70): PRINT \"*\"\n"
|
112 |
+
"500 INPUT B\n"
|
113 |
+
"510 IF B<0 THEN 650\n"
|
114 |
+
"520 IF B>30 THEN B=30\n"
|
115 |
+
"530 IF B>F THEN B=F\n"
|
116 |
+
"540 V1=V-B+5\n"
|
117 |
+
"560 F=F-B\n"
|
118 |
+
"570 H=H-(V+V1)/2\n"
|
119 |
+
"580 IF H<=0 THEN 670\n"
|
120 |
+
"590 T=T+1\n"
|
121 |
+
"600 V=V1\n"
|
122 |
+
"610 IF F>0 THEN 490\n"
|
123 |
+
"615 IF B=0 THEN 640\n"
|
124 |
+
"620 PRINT \"**** OUT OF FUEL ****\"\n"
|
125 |
+
"640 PRINT #6,T,H,V,F;\" I\";\n"
|
126 |
+
"645 TAB(H/70): PRINT \"*\"\n"
|
127 |
+
"650 B=0\n"
|
128 |
+
"660 GOTO 540\n"
|
129 |
+
"670 PRINT \"***** CONTACT *****\"\n"
|
130 |
+
"680 H=H+(V1+V)/2\n"
|
131 |
+
"690 IF B=5 THEN 720\n"
|
132 |
+
"700 D=(-V+SQR(V*V+H*(10-2*B)))/(5-B)\n"
|
133 |
+
"710 GOTO 730\n"
|
134 |
+
"720 D=H/V\n"
|
135 |
+
"730 V1=V+(5-B)*D\n"
|
136 |
+
"760 PRINT \"TOUCHDOWN AT\"; T+D; \"SECONDS.\"\n"
|
137 |
+
"770 PRINT \"LANDING VELOCITY=\"; V1; \"FEET/SEC.\"\n"
|
138 |
+
"780 PRINT F; \"UNITS OF FUEL REMAINING.\"\n"
|
139 |
+
"790 IF V1<>0 THEN 810\n"
|
140 |
+
"800 PRINT \"CONGRATULATIONS! A PERFECT LANDING!!\"\n"
|
141 |
+
"805 PRINT \"YOUR LICENSE WILL BE RENEWED.......LATER.\"\n"
|
142 |
+
"810 IF ABS(V1)<2 THEN 840\n"
|
143 |
+
"820 PRINT \"***** SORRY, BUT YOU BLEW IT!!!!\"\n"
|
144 |
+
"830 PRINT \"APPROPRIATE CONDOLENCES WILL BE SENT TO YOUR NEXT OF KIN.\"\n"
|
145 |
+
"840 PRINT\n"
|
146 |
+
"850 INPUT \"ANOTHER MISSION? \"; A$\n"
|
147 |
+
"860 IF A$(1,1)=\"Y\" OR A$(1,1)=\"y\" THEN 390\n"
|
148 |
+
"870 PRINT: PRINT \"CONTROL OUT.\": PRINT \n"
|
149 |
+
"999 END \n"
|
150 |
+
"\f"
|
151 |
+
};
|
152 |
+
const char buildin_pgm2_name[] PROGMEM = "*rocket.bas";
|
153 |
+
const char buildin_pgm3[] PROGMEM = {
|
154 |
+
"100 REM \"NIM\"\n"
|
155 |
+
"110 REM \"Ported by Stefan in 2022\"\n"
|
156 |
+
"120 REM\n"
|
157 |
+
"210 DIM A(100),B(100,11),D(2)\n"
|
158 |
+
"220 PRINT \"THIS IS THE GAME OF NIM.\"\n"
|
159 |
+
"230 PRINT \"DO YOU WANT INSTRUCTIONS\";\n"
|
160 |
+
"240 INPUT Z$\n"
|
161 |
+
"250 IF Z$=\"NO\" THEN 440\n"
|
162 |
+
"260 IF Z$=\"no\" THEN 440\n"
|
163 |
+
"270 IF Z$=\"YES\" THEN 310\n"
|
164 |
+
"280 IF Z$=\"yes\" THEN 310\n"
|
165 |
+
"290 PRINT \"PLEASE ANSWER YES OR NO\"\n"
|
166 |
+
"300 GOTO 240\n"
|
167 |
+
"310 PRINT \"THE GAME IS PLAYED WITH A NUMBER OF PILES OF OBJECTS.\"\n"
|
168 |
+
"320 PRINT \"ANY NUMBER OF OBJECTS ARE REMOVED FROM ONE PILE BY YOU AND\"\n"
|
169 |
+
"330 PRINT \"THE MACHINE ALTERNATELY. ON YOUR TURN, YOU MAY TAKE\"\n"
|
170 |
+
"340 PRINT \"ALL THE OBJECTS THAT REMAIN IN ANY PILE, BUT YOU MUST\"\n"
|
171 |
+
"350 PRINT \"TAKE AT LEAST ONE OBJECT, AND YOU MAY TAKE OBJECTS FROM\"\n"
|
172 |
+
"360 PRINT \"ONLY ONE PILE ON A SINGLE TURN. YOU MUST SPECIFY WHETHER\"\n"
|
173 |
+
"370 PRINT \"WINNING IS DEFINED AS TAKING OR NOT TAKING THE LAST OBJECT,\"\n"
|
174 |
+
"380 PRINT \"THE NUMBER OF PILES IN THE GAME, AND HOW MANY OBJECTS ARE\"\n"
|
175 |
+
"390 PRINT \"ORIGINALLY IN EACH PILE. EACH PILE MAY CONTAIN A\"\n"
|
176 |
+
"400 PRINT \"DIFFERENT NUMBER OF OBJECTS.\"\n"
|
177 |
+
"410 PRINT \"THE MACHINE WILL SHOW ITS MOVE BY LISTING EACH PILE AND THE\"\n"
|
178 |
+
"420 PRINT \"NUMBER OF OBJECTS REMAINING IN THE PILES AFTER EACH OF ITS\"\n"
|
179 |
+
"430 PRINT \"MOVES.\"\n"
|
180 |
+
"440 PRINT\n"
|
181 |
+
"450 PRINT \"ENTER WIN OPTION - 1 TO TAKE LAST, 2 TO AVOID LAST\";\n"
|
182 |
+
"460 INPUT W\n"
|
183 |
+
"470 IF W=1 THEN 490\n"
|
184 |
+
"480 IF W<>2 THEN 450\n"
|
185 |
+
"490 PRINT \"ENTER NUMBER OF PILES\";\n"
|
186 |
+
"500 INPUT N\n"
|
187 |
+
"510 IF N>100 THEN 490\n"
|
188 |
+
"520 IF N<1 THEN 490\n"
|
189 |
+
"530 IF N<>INT(N) THEN 490\n"
|
190 |
+
"540 PRINT \"ENTER PILE SIZES\"\n"
|
191 |
+
"550 FOR I=1 TO N\n"
|
192 |
+
"560 PRINT I;\n"
|
193 |
+
"570 INPUT A(I)\n"
|
194 |
+
"580 IF A(I)>2000 THEN 560\n"
|
195 |
+
"590 IF A(I)<1 THEN 560\n"
|
196 |
+
"600 IF A(I)<>INT(A(I)) THEN 560\n"
|
197 |
+
"610 NEXT I\n"
|
198 |
+
"620 PRINT \"DO YOU WANT TO MOVE FIRST\";\n"
|
199 |
+
"630 INPUT Q9$\n"
|
200 |
+
"640 IF Q9$=\"YES\" THEN 1450\n"
|
201 |
+
"650 IF Q9$=\"yes\" THEN 1450\n"
|
202 |
+
"660 IF Q9$=\"NO\" THEN 700\n"
|
203 |
+
"670 IF Q9$=\"no\" THEN 700\n"
|
204 |
+
"680 PRINT \"PLEASE ANSWER YES OR NO.\"\n"
|
205 |
+
"690 GOTO 630\n"
|
206 |
+
"700 IF W=1 THEN 940\n"
|
207 |
+
"710 LET C=0\n"
|
208 |
+
"720 FOR I=1 TO N\n"
|
209 |
+
"730 IF A(I)=0 THEN 770\n"
|
210 |
+
"740 LET C=C+1\n"
|
211 |
+
"750 IF C=3 THEN 840\n"
|
212 |
+
"760 LET D(C)=I\n"
|
213 |
+
"770 NEXT I\n"
|
214 |
+
"780 IF C=2 THEN 920\n"
|
215 |
+
"790 IF A(D(1))>1 THEN 820\n"
|
216 |
+
"800 PRINT \"MACHINE LOSES\"\n"
|
217 |
+
"810 GOTO 1640\n"
|
218 |
+
"820 PRINT \"MACHINE WINS\"\n"
|
219 |
+
"830 GOTO 1640\n"
|
220 |
+
"840 LET C=0\n"
|
221 |
+
"850 FOR I=1 TO N\n"
|
222 |
+
"860 IF A(I)>1 THEN 940\n"
|
223 |
+
"870 IF A(I)=0 THEN 890\n"
|
224 |
+
"880 LET C=C+1\n"
|
225 |
+
"890 NEXT I\n"
|
226 |
+
"900 IF C/2<>INT(C/2) THEN 800\n"
|
227 |
+
"910 GOTO 940\n"
|
228 |
+
"920 IF A(D(1))=1 THEN 820\n"
|
229 |
+
"930 IF A(D(2))=1 THEN 820\n"
|
230 |
+
"940 FOR I=1 TO N\n"
|
231 |
+
"950 LET E=A(I)\n"
|
232 |
+
"960 FOR J=0 TO 10\n"
|
233 |
+
"970 LET F=E/2\n"
|
234 |
+
"980 LET B(I,J+1)=2*(F-INT(F))\n"
|
235 |
+
"990 LET E=INT(F)\n"
|
236 |
+
"1000 NEXT J\n"
|
237 |
+
"1010 NEXT I\n"
|
238 |
+
"1020 FOR J=10 TO 0 STEP -1\n"
|
239 |
+
"1030 LET C=0\n"
|
240 |
+
"1040 LET H=0\n"
|
241 |
+
"1050 FOR I=1 TO N\n"
|
242 |
+
"1060 IF B(I,J+1)=0 THEN 1110\n"
|
243 |
+
"1070 LET C=C+1\n"
|
244 |
+
"1080 IF A(I)<=H THEN 1110\n"
|
245 |
+
"1090 LET H=A(I)\n"
|
246 |
+
"1100 LET G=I\n"
|
247 |
+
"1110 NEXT I\n"
|
248 |
+
"1120 IF C/2<>INT(C/2) THEN 1190\n"
|
249 |
+
"1130 NEXT J\n"
|
250 |
+
"1140 LET E=INT(N*RND(1)+1)\n"
|
251 |
+
"1150 IF A(E)=0 THEN 1140\n"
|
252 |
+
"1160 LET F=INT(A(E)*RND(1)+1)\n"
|
253 |
+
"1170 LET A(E)=A(E)-F\n"
|
254 |
+
"1180 GOTO 1380\n"
|
255 |
+
"1190 LET A(G)=0\n"
|
256 |
+
"1200 FOR J=0 TO 10\n"
|
257 |
+
"1210 LET B(G,J+1)=0\n"
|
258 |
+
"1220 LET C=0\n"
|
259 |
+
"1230 FOR I=1 TO N\n"
|
260 |
+
"1240 IF B(I,J+1)=0 THEN 1260\n"
|
261 |
+
"1250 LET C=C+1\n"
|
262 |
+
"1260 NEXT I\n"
|
263 |
+
"1270 LET A(G)=A(G)+2*(C/2-INT(C/2))*POW(2,J)\n"
|
264 |
+
"1280 NEXT J\n"
|
265 |
+
"1290 IF W=1 THEN 1380\n"
|
266 |
+
"1300 LET C=0\n"
|
267 |
+
"1310 FOR I=1 TO N\n"
|
268 |
+
"1320 IF A(I)>1 THEN 1380\n"
|
269 |
+
"1330 IF A(I)=0 THEN 1350\n"
|
270 |
+
"1340 LET C=C+1\n"
|
271 |
+
"1350 NEXT I\n"
|
272 |
+
"1360 IF C/2<>INT(C/2) THEN 1380\n"
|
273 |
+
"1370 LET A(G)=1-A(G)\n"
|
274 |
+
"1380 PRINT \"PILE SIZE\"\n"
|
275 |
+
"1390 FOR I=1 TO N\n"
|
276 |
+
"1400 PRINT #8;I,A(I)\n"
|
277 |
+
"1410 NEXT I\n"
|
278 |
+
"1420 IF W=2 THEN 1450\n"
|
279 |
+
"1430 GOSUB 1570\n"
|
280 |
+
"1440 IF Z=1 THEN 820\n"
|
281 |
+
"1450 PRINT \"YOUR MOVE - PILE, NUMBER TO BE REMOVED\";\n"
|
282 |
+
"1460 INPUT X,Y\n"
|
283 |
+
"1470 IF X>N THEN 1450\n"
|
284 |
+
"1480 IF X<1 THEN 1450\n"
|
285 |
+
"1490 IF X<>INT(X) THEN 1450\n"
|
286 |
+
"1500 IF Y>A(X) THEN 1450\n"
|
287 |
+
"1510 IF Y<1 THEN 1450\n"
|
288 |
+
"1520 IF Y<>INT(Y) THEN 1450\n"
|
289 |
+
"1530 LET A(X)=A(X)-Y\n"
|
290 |
+
"1540 GOSUB 1570\n"
|
291 |
+
"1550 IF Z=1 THEN 800\n"
|
292 |
+
"1560 GOTO 700\n"
|
293 |
+
"1570 LET Z=0\n"
|
294 |
+
"1580 FOR I=1 TO N\n"
|
295 |
+
"1590 IF A(I)=0 THEN 1610\n"
|
296 |
+
"1600 RETURN\n"
|
297 |
+
"1610 NEXT I\n"
|
298 |
+
"1620 LET Z=1\n"
|
299 |
+
"1630 RETURN\n"
|
300 |
+
"1640 PRINT \"DO YOU WANT TO PLAY ANOTHER GAME\";\n"
|
301 |
+
"1650 INPUT Q9$\n"
|
302 |
+
"1660 IF Q9$=\"YES\" THEN 1720\n"
|
303 |
+
"1670 IF Q9$=\"yes\" THEN 1720\n"
|
304 |
+
"1680 IF Q9$=\"NO\" THEN 1730\n"
|
305 |
+
"1690 IF Q9$=\"no\" THEN 1730\n"
|
306 |
+
"1700 PRINT \"PLEASE. YES OR NO.\"\n"
|
307 |
+
"1710 GOTO 1650 \n"
|
308 |
+
"1720 GOTO 440\n"
|
309 |
+
"1730 END\n"
|
310 |
+
"\f"
|
311 |
+
};
|
312 |
+
const char buildin_pgm3_name[] PROGMEM = "*nim.bas";
|
313 |
+
const char* const buildin_programs[] PROGMEM = {
|
314 |
+
buildin_pgm1,
|
315 |
+
buildin_pgm2,
|
316 |
+
buildin_pgm3,
|
317 |
+
0
|
318 |
+
};
|
319 |
+
const char* const buildin_program_names[] PROGMEM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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const char buildin_pgm1[] PROGMEM = {
|
2 |
+
"100 REM \"CALCULATING PI FOR HUNDREDS OF DIGITS\"\n"
|
3 |
+
"110 REM \"THX TO ROSETTACODE.ORG FOR THE BASE OF THE PROGRAM\"\n"
|
4 |
+
"120 REM \"SHOULD BE A BENCHMARK FOR THE BASIC INTERPRETER/COMPILER\"\n"
|
5 |
+
"130 REM \"WRITTEN IN 2023 FOR FORUM.CLASSIC-COMPUTING.DE BY PETER DASSOW\"\n"
|
6 |
+
"135 REM \"Ported to IoT BASIC by Guido Lehwalder\"\n"
|
7 |
+
"136 REM \"Added some IoT BASIC features - Stefan Lenz, 2023\"\n"
|
8 |
+
"137 CLS\n"
|
9 |
+
"140 PRINT \"Calculating Pi as a BASIC benchmark.\"\n"
|
10 |
+
"150 PRINT \"Enter number of digits: \";\n"
|
11 |
+
"160 INPUT S$\n"
|
12 |
+
"170 IF S$=\"\" THEN PRINT \"Nothing done.\": END\n"
|
13 |
+
"180 N=VAL(S$): IF N<1 THEN PRINT \"Not a valid number.\": GOTO 150\n"
|
14 |
+
"190 REM \"N DETERMINES ALSO THE ARRAY (ABOUT 3-4 TIMES BIGGER)\"\n"
|
15 |
+
"200 LN=INT(10*N/3)+16\n"
|
16 |
+
"204 REM \"@ is the space on the heap for numbers, reserve 64 bytes\"\n"
|
17 |
+
"205 IF LN>(@-64) THEN PRINT \"Not enough memory\": GOTO 150\n"
|
18 |
+
"210 ND=1\n"
|
19 |
+
"220 SM=MILLIS(1)\n"
|
20 |
+
"225 REM \"Delete the array if already there\"\n"
|
21 |
+
"230 IF FIND(A())<>0 THEN CLR A()\n"
|
22 |
+
"235 REM \"Then redim\"\n"
|
23 |
+
"240 DIM A(LN)\n"
|
24 |
+
"250 N9=0\n"
|
25 |
+
"260 PD=0\n"
|
26 |
+
"270 REM\n"
|
27 |
+
"280 FOR J=1 TO LN\n"
|
28 |
+
"290 A(J)=2\n"
|
29 |
+
"300 NEXT J\n"
|
30 |
+
"310 REM \"Use of the modulo operator % speeds things up\"\n"
|
31 |
+
"320 FOR J=1 TO N\n"
|
32 |
+
"330 Q=0\n"
|
33 |
+
"340 FOR I=LN TO 1 STEP -1\n"
|
34 |
+
"350 X=10*A(I)+Q*I\n"
|
35 |
+
"360 A(I)=X%(2*I-1)\n"
|
36 |
+
"370 Q=INT(X/(2*I-1))\n"
|
37 |
+
"380 NEXT I\n"
|
38 |
+
"390 A(1)=Q%10\n"
|
39 |
+
"400 Q=INT(Q/10)\n"
|
40 |
+
"410 IF Q=9 THEN N9=N9+1: GOTO 610\n"
|
41 |
+
"420 IF Q<>10 THEN GOTO 540\n"
|
42 |
+
"430 REM \"Q==10\"\n"
|
43 |
+
"440 D=PD+1: GOSUB 670\n"
|
44 |
+
"450 IF N9<=0 THEN GOTO 500\n"
|
45 |
+
"460 FOR K=1 TO N9\n"
|
46 |
+
"470 D=0: GOSUB 670\n"
|
47 |
+
"480 NEXT K\n"
|
48 |
+
"490 REM \"END IF\"\n"
|
49 |
+
"500 PD=0\n"
|
50 |
+
"510 N9=0\n"
|
51 |
+
"520 GOTO 610\n"
|
52 |
+
"530 REM \"Q<>10\"\n"
|
53 |
+
"540 D=PD: GOSUB 670\n"
|
54 |
+
"550 PD=Q\n"
|
55 |
+
"560 IF N9=0 THEN GOTO 610\n"
|
56 |
+
"570 FOR K=1 TO N9\n"
|
57 |
+
"580 D=9: GOSUB 670\n"
|
58 |
+
"590 NEXT K\n"
|
59 |
+
"600 N9=0\n"
|
60 |
+
"610 NEXT J\n"
|
61 |
+
"620 C$=(\"0\"+PD%10)\n"
|
62 |
+
"621 PRINT C$\n"
|
63 |
+
"630 EM=MILLIS(1)-SM\n"
|
64 |
+
"635 PRINT \"Calculation time \";EM/1000;\" seconds.\"\n"
|
65 |
+
"640 GOTO 140\n"
|
66 |
+
"650 REM\n"
|
67 |
+
"660 REM \"OUTPUT DIGITS\"\n"
|
68 |
+
"670 C$=(\"0\"+D%10)\n"
|
69 |
+
"671 IF ND=0 THEN PRINT C$;: RETURN\n"
|
70 |
+
"680 IF D=0 THEN RETURN\n"
|
71 |
+
"691 PRINT C$;\".\";\n"
|
72 |
+
"700 ND=0\n"
|
73 |
+
"710 RETURN\n"
|
74 |
+
"\f"
|
75 |
+
};
|
76 |
+
const char buildin_pgm1_name[] PROGMEM = "*cpinew2.bas";
|
77 |
+
const char buildin_pgm2[] PROGMEM = {
|
78 |
+
"10 REM \"Solves the Euler 9 problem \"\n"
|
79 |
+
"20 REM \"See https://projecteuler.net/problem=9 for details\"\n"
|
80 |
+
"30 REM \"with a number theoretical approach\"\n"
|
81 |
+
"100 PRINT \"Enter the circumference K of a triangle\"\n"
|
82 |
+
"110 PRINT \"The program finds a pythagorean triangle\"\n"
|
83 |
+
"120 PRINT \"a^2 + b^2 = c^2\"\n"
|
84 |
+
"130 INPUT \"K= (0 to end) \",K \n"
|
85 |
+
"140 IF K=0 THEN END \n"
|
86 |
+
"150 IF K%2=0 THEN U=K/2: GOTO 200 \n"
|
87 |
+
"160 PRINT \"K is odd, no solution\": GOTO 130 \n"
|
88 |
+
"200 REM \"Main Program\"\n"
|
89 |
+
"210 F=0 \n"
|
90 |
+
"220 X=SQR(U/2)\n"
|
91 |
+
"230 FOR I=1 TO X \n"
|
92 |
+
"240 IF U%I<>0 THEN CONT \n"
|
93 |
+
"250 FOR J=1 TO I \n"
|
94 |
+
"260 D=I+J \n"
|
95 |
+
"270 IF U%D<>0 THEN CONT \n"
|
96 |
+
"280 IF D%2=0 THEN CONT \n"
|
97 |
+
"290 R=I: Q=J \n"
|
98 |
+
"300 GOSUB 800 \n"
|
99 |
+
"310 IF R<>1 THEN CONT \n"
|
100 |
+
"320 A=I*I-J*J \n"
|
101 |
+
"330 B=2*I*J \n"
|
102 |
+
"340 C=I*I+J*J \n"
|
103 |
+
"350 PRINT \"Primitive triple\",A ,B, C \n"
|
104 |
+
"360 PRINT \"Circumference=\",A+B+C \n"
|
105 |
+
"370 S=K/(A+B+C)\n"
|
106 |
+
"380 PRINT \"Scale with\",S \n"
|
107 |
+
"390 PRINT \"Solution \",A*S, B*S, C*S \n"
|
108 |
+
"400 F=1 \n"
|
109 |
+
"420 NEXT \n"
|
110 |
+
"430 NEXT \n"
|
111 |
+
"440 REM \"All solutions found\"\n"
|
112 |
+
"450 IF F=0 THEN PRINT \"No solution\"\n"
|
113 |
+
"460 GOTO 130 \n"
|
114 |
+
"800 REM \"Find GCD\"\n"
|
115 |
+
"810 IF R=Q THEN RETURN \n"
|
116 |
+
"820 IF R>Q THEN R=R-Q \n"
|
117 |
+
"830 IF Q>R THEN Q=Q-R \n"
|
118 |
+
"840 GOTO 810 \n"
|
119 |
+
"\f"
|
120 |
+
};
|
121 |
+
const char buildin_pgm2_name[] PROGMEM = "*euler9.bas";
|
122 |
+
const char buildin_pgm3[] PROGMEM = {
|
123 |
+
"10 REM \"Calculates the Fibonacci numbers\"\n"
|
124 |
+
"20 REM \"And the Golden Ratio on an Integer BASIC\"\n"
|
125 |
+
"200 REM \"Main program\"\n"
|
126 |
+
"210 N=19\n"
|
127 |
+
"220 DIM A(N)\n"
|
128 |
+
"230 A(1)=1\n"
|
129 |
+
"240 A(2)=1\n"
|
130 |
+
"250 FOR I=3 TO N\n"
|
131 |
+
"260 IF A(I)>16000 THEN BREAK\n"
|
132 |
+
"270 A(I)=A(I-1)+A(I-2)\n"
|
133 |
+
"280 Q=A(I): D=A(I-1)\n"
|
134 |
+
"290 PRINT #4;I,Q,D;\n"
|
135 |
+
"300 GOSUB 500\n"
|
136 |
+
"310 NEXT\n"
|
137 |
+
"320 END\n"
|
138 |
+
"500 REM \"Print a decimal ratio of a fraction\"\n"
|
139 |
+
"520 Z=INT(Q/D)\n"
|
140 |
+
"530 PRINT \" \";Z;\".\";\n"
|
141 |
+
"540 FOR J=1 TO 10\n"
|
142 |
+
"550 Z=Q%D\n"
|
143 |
+
"560 Q=Z*10\n"
|
144 |
+
"570 Z=INT(Q/D)\n"
|
145 |
+
"580 PRINT Z;\n"
|
146 |
+
"590 NEXT\n"
|
147 |
+
"600 PRINT \" \"\n"
|
148 |
+
"610 RETURN\n"
|
149 |
+
"\f"
|
150 |
+
};
|
151 |
+
const char buildin_pgm3_name[] PROGMEM = "*fibo.bas";
|
152 |
+
const char buildin_pgm4[] PROGMEM = {
|
153 |
+
"100 REM \"Calculate the first N prime numbers\"\n"
|
154 |
+
"110 REM \"and output them!\"\n"
|
155 |
+
"200 CLR \n"
|
156 |
+
"210 INPUT \"How many primes (0=stop)? \", N \n"
|
157 |
+
"220 IF N=0 THEN 500\n"
|
158 |
+
"230 DIM P(N): P(1)=2: P(2)=3: I=2 \n"
|
159 |
+
"240 IF I=N THEN 360\n"
|
160 |
+
"250 K=P(I)\n"
|
161 |
+
"260 K=K+2 \n"
|
162 |
+
"270 L=SQR(K)\n"
|
163 |
+
"280 J=1 \n"
|
164 |
+
"290 D=P(J)\n"
|
165 |
+
"310 M=K%D \n"
|
166 |
+
"320 IF M=0 THEN 260\n"
|
167 |
+
"330 IF D<L THEN J=J+1: GOTO 290 \n"
|
168 |
+
"340 I=I+1: P(I)=K \n"
|
169 |
+
"350 GOTO 240 \n"
|
170 |
+
"360 PRINT \"The first\",N ,\"primes are:\"\n"
|
171 |
+
"370 FOR J=1 TO N \n"
|
172 |
+
"380 PRINT #4,J ,P(J)\n"
|
173 |
+
"390 NEXT \n"
|
174 |
+
"400 GOTO 200\n"
|
175 |
+
"500 END\n"
|
176 |
+
"\f"
|
177 |
+
};
|
178 |
+
const char buildin_pgm4_name[] PROGMEM = "*primes.bas";
|
179 |
+
const char buildin_pgm5[] PROGMEM = {
|
180 |
+
"10 REM \"Calculate Factorial and Stirlings function\"\n"
|
181 |
+
"20 REM \"\"\n"
|
182 |
+
"100 REM \"Factorial\"\n"
|
183 |
+
"110 L=20 \n"
|
184 |
+
"120 DIM F(L)\n"
|
185 |
+
"130 F(1)=1\n"
|
186 |
+
"140 FOR I=2 TO L\n"
|
187 |
+
"150 F(I)=F(I-1)*I \n"
|
188 |
+
"160 NEXT \n"
|
189 |
+
"200 REM \"Stirling\"\n"
|
190 |
+
"210 P1=4*ATAN(1)\n"
|
191 |
+
"220 DEF FNS(N)=SQR(2*P1*N)*EXP(N*(LOG(N)-1))\n"
|
192 |
+
"300 REM \"Print table\"\n"
|
193 |
+
"305 PRINT \"N\";: TAB(4) \n"
|
194 |
+
"310 PRINT \"FACT(N)\";: TAB(6)\n"
|
195 |
+
"315 PRINT \"STIR(N)\";: TAB(6)\n"
|
196 |
+
"320 PRINT \"Accuracy (%)\"\n"
|
197 |
+
"330 FOR I=1 TO L\n"
|
198 |
+
"340 PRINT #4, I, #12, F(I), FNS(I), (F(I)-FNS(I))/F(I)*100\n"
|
199 |
+
"350 NEXT\n"
|
200 |
+
"400 END\n"
|
201 |
+
"\f"
|
202 |
+
};
|
203 |
+
const char buildin_pgm5_name[] PROGMEM = "*stir.bas";
|
204 |
+
const char buildin_pgm6[] PROGMEM = {
|
205 |
+
"10 REM \"TIC TAC TOE from 101 BASIC games\"\n"
|
206 |
+
"20 REM \"by David Ahl.\"\n"
|
207 |
+
"30 REM \"Ported to Stefan's BASIC in 2021\"\n"
|
208 |
+
"40 REM \"The machine goes first\"\n"
|
209 |
+
"100 PRINT \"Welcome to tictactoe\"\n"
|
210 |
+
"110 PRINT \"The game board is numbered:\"\n"
|
211 |
+
"120 PRINT\n"
|
212 |
+
"130 PRINT \"1 2 3\"\n"
|
213 |
+
"140 PRINT \"8 9 4\"\n"
|
214 |
+
"150 PRINT \"7 6 5\"\n"
|
215 |
+
"160 PRINT\n"
|
216 |
+
"200 REM \"Main Program\"\n"
|
217 |
+
"210 PRINT \"Staring a new game\"\n"
|
218 |
+
"230 A=9\n"
|
219 |
+
"240 M=A\n"
|
220 |
+
"250 GOSUB 800 \n"
|
221 |
+
"260 P=M\n"
|
222 |
+
"270 B=P%8+1\n"
|
223 |
+
"280 M=B\n"
|
224 |
+
"290 GOSUB 800 \n"
|
225 |
+
"300 Q=M\n"
|
226 |
+
"310 IF Q=(B+3)%8+1 GOTO 360\n"
|
227 |
+
"320 C=(B+3)%8+1\n"
|
228 |
+
"330 M=C\n"
|
229 |
+
"340 GOSUB 900 \n"
|
230 |
+
"350 GOTO 640 \n"
|
231 |
+
"360 C=(B+1)%8+1\n"
|
232 |
+
"370 M=C\n"
|
233 |
+
"380 GOSUB 800 \n"
|
234 |
+
"390 R=M\n"
|
235 |
+
"400 IF R=(C+3)%8+1 GOTO 450\n"
|
236 |
+
"410 D=(C+3)%8+1\n"
|
237 |
+
"420 M=D\n"
|
238 |
+
"430 GOSUB 900\n"
|
239 |
+
"440 GOTO 640 \n"
|
240 |
+
"450 IF P%2<>0 GOTO 500\n"
|
241 |
+
"460 D=(C+6)%8+1\n"
|
242 |
+
"470 M=D\n"
|
243 |
+
"480 GOSUB 900\n"
|
244 |
+
"490 GOTO 640 \n"
|
245 |
+
"500 D=(C+2)%8+1\n"
|
246 |
+
"510 M=D\n"
|
247 |
+
"520 GOSUB 800 \n"
|
248 |
+
"530 S=M\n"
|
249 |
+
"540 IF S=(D+3)%8+1 GOTO 590\n"
|
250 |
+
"550 E=(D+3)%8+1\n"
|
251 |
+
"560 M=E\n"
|
252 |
+
"570 GOSUB 900\n"
|
253 |
+
"580 REM \"Game is a draw\"\n"
|
254 |
+
"590 E=(D+5)%8+1\n"
|
255 |
+
"600 M=E\n"
|
256 |
+
"610 GOSUB 900\n"
|
257 |
+
"620 PRINT \"The game is a draw.\"\n"
|
258 |
+
"630 GOTO 200\n"
|
259 |
+
"640 PRINT \"and wins! ********\"\n"
|
260 |
+
"650 GOTO 200\n"
|
261 |
+
"800 REM \"Subroutine to ask user for the move\"\n"
|
262 |
+
"810 GOSUB 900\n"
|
263 |
+
"820 INPUT \"Your move? \", M\n"
|
264 |
+
"830 RETURN\n"
|
265 |
+
"900 REM \"Subroutine to display move\"\n"
|
266 |
+
"910 PRINT \"Computer moves:\",M\n"
|
267 |
+
"920 RETURN\n"
|
268 |
+
"\f"
|
269 |
+
};
|
270 |
+
const char buildin_pgm6_name[] PROGMEM = "*tictac.bas";
|
271 |
+
const char* const buildin_programs[] PROGMEM = {
|
272 |
+
buildin_pgm1,
|
273 |
+
buildin_pgm2,
|
274 |
+
buildin_pgm3,
|
275 |
+
buildin_pgm4,
|
276 |
+
buildin_pgm5,
|
277 |
+
buildin_pgm6,
|
278 |
+
0
|
279 |
+
};
|
280 |
+
const char* const buildin_program_names[] PROGMEM = {
|
281 |
+
buildin_pgm1_name,
|
282 |
+
buildin_pgm2_name,
|
283 |
+
buildin_pgm3_name,
|
284 |
+
buildin_pgm4_name,
|
285 |
+
buildin_pgm5_name,
|
286 |
+
buildin_pgm6_name,
|
287 |
+
0
|
288 |
+
};
|
data/Basic2/IoTBasic/buildin/buildin.h
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* This is the demo code for the buildin programs.
|
3 |
+
*
|
4 |
+
* Format of the buildin program store:
|
5 |
+
*
|
6 |
+
* programs are one long string terminated by FF \f.
|
7 |
+
* lines are terminated by newline.
|
8 |
+
*
|
9 |
+
* Programs can have any name, * as a prefix is used to
|
10 |
+
* distinguish them from other programs. This is not yet
|
11 |
+
* implemented.
|
12 |
+
*/
|
13 |
+
|
14 |
+
const char buildin_pgm1[] PROGMEM = {
|
15 |
+
"10 print \"hello world\"\n"
|
16 |
+
"20 end\n"
|
17 |
+
"\f"
|
18 |
+
};
|
19 |
+
|
20 |
+
const char buildin_pgm1_name[] PROGMEM = "*hello.bas";
|
21 |
+
|
22 |
+
const char buildin_pgm2[] PROGMEM = {
|
23 |
+
"10 PI=22000/7\n"
|
24 |
+
"20 PRINT 'PI=',INT(PI)\n"
|
25 |
+
"30 END\n"
|
26 |
+
"\f"
|
27 |
+
};
|
28 |
+
|
29 |
+
const char buildin_pgm2_name[] PROGMEM = "*pi.bas";
|
30 |
+
|
31 |
+
const char* const buildin_programs[] PROGMEM = {
|
32 |
+
buildin_pgm1,
|
33 |
+
buildin_pgm2,
|
34 |
+
0
|
35 |
+
};
|
36 |
+
|
37 |
+
const char* const buildin_program_names[] PROGMEM = {
|
38 |
+
buildin_pgm1_name,
|
39 |
+
buildin_pgm2_name,
|
40 |
+
0
|
41 |
+
};
|
data/Basic2/IoTBasic/font/firasans.h
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic2/IoTBasic/hardware.h
ADDED
@@ -0,0 +1,1091 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Stefan's basic interpreter.
|
3 |
+
*
|
4 |
+
* Playing around with frugal programming. See the licence file on
|
5 |
+
* https://github.com/slviajero/tinybasic for copyright/left.
|
6 |
+
* (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
|
7 |
+
*
|
8 |
+
* Author: Stefan Lenz, [email protected]
|
9 |
+
*
|
10 |
+
* Architectures and the definitions from the Arduino IDE.
|
11 |
+
*
|
12 |
+
* Arduino hardware settings , set here what you need or
|
13 |
+
* use one of the predefined configurations below.
|
14 |
+
*
|
15 |
+
* If HARDWAREHEURISTICS is set, some of the settings below
|
16 |
+
* are activated automatically for some platforms. If you want
|
17 |
+
* to control ALL settings below manually, undef HARDWAREHEURISTICS
|
18 |
+
*
|
19 |
+
* Input/output methods ARUINOPICOSERIAL, ARDUINOPS2
|
20 |
+
* ARDUINOUSBKBD, ARDUINOZX81KBD, ARDUINOI2CKBD, GIGAUSBKBD
|
21 |
+
* ARDUINOPRT, DISPLAYCANSCROLL, ARDUINOLCDI2C,
|
22 |
+
* ARDUINOTFT, ARDUINONOKIA51, ARDUINOILI9488,
|
23 |
+
* ARDUINOSSD1306, ARDUINOMCUFRIEND
|
24 |
+
* Storage ARDUINOEEPROM, ARDUINOSD, ESPSPIFFS, RP2040LITTLEFS
|
25 |
+
* storage ARDUINOEFS, SM32SDIO, ESP32FAT, ESPSDMMC
|
26 |
+
* sensors ARDUINOWIRE, ARDUINOSIMPLEWIRE, ARDUINOSENSORS
|
27 |
+
* network ARDUINORF24, ARDUNIOMQTT
|
28 |
+
* memory ARDUINOSPIRAM
|
29 |
+
* real time clocks ARDUINORTC, ARDUINORTCEMULATION
|
30 |
+
*
|
31 |
+
* Secial features
|
32 |
+
* ARDUINOPGMEEPROM: makes the EEPROM primary program store
|
33 |
+
* HASMSTAB: counts characters, prerequisite for MSTAB in languages
|
34 |
+
* BUILDIN: include buildin programs
|
35 |
+
*
|
36 |
+
* Instead of setting all this manually, you can use one of the
|
37 |
+
* predefined hardware models. They are stored in board and are sources
|
38 |
+
* here later in the code to override some of the defaults. Custom configurations
|
39 |
+
* coming with BASIC are:
|
40 |
+
*
|
41 |
+
* dummy.h:
|
42 |
+
* do nothing.
|
43 |
+
* avrlcd.h:
|
44 |
+
* a AVR system with a LCD shield
|
45 |
+
* avrmcufriend.h:
|
46 |
+
* a AVR system with a parallel TFT
|
47 |
+
* wemosshield.h:
|
48 |
+
* a ESP8266 UNO lookalike with a modified datalogger shield
|
49 |
+
* great hardware for small BASIC based IoT projects.
|
50 |
+
* megashield.h:
|
51 |
+
* an Arduino Mega with Ethernet Shield optional keyboard
|
52 |
+
* and i2c display
|
53 |
+
* megatft.h:
|
54 |
+
* duetft.h:
|
55 |
+
* TFT 7inch screen systems, standalone
|
56 |
+
* nanoboard.h:
|
57 |
+
* Arduino Nano Every board with PS2 keyboard and sensor
|
58 |
+
* kit.
|
59 |
+
* megaboard.h:
|
60 |
+
* A board for the MEGA with 64 kB RAM, SD Card, and real time
|
61 |
+
* clock.
|
62 |
+
* unoboard.h:
|
63 |
+
* A board for an UNO with 64kB memory and EEPROM disk
|
64 |
+
* fits into an UNO flash only with integer
|
65 |
+
* esp01board.h:
|
66 |
+
* ESP01 based board as a sensor / MQTT interface
|
67 |
+
* rp2040board.h:
|
68 |
+
* A ILI9488 hardware design based on an Arduino connect RP2040.
|
69 |
+
* rp2040board2.h:
|
70 |
+
* like the one above but based on the Pi Pico core
|
71 |
+
* esp32board.h:
|
72 |
+
* same like above with an ESP32 core
|
73 |
+
* mkboard.h:
|
74 |
+
* a digital signage and low energy board
|
75 |
+
* tdeck.h:
|
76 |
+
* the LILYGO T-Deck - not yet finished
|
77 |
+
* ttgovga.h:
|
78 |
+
* the TTGO VGA 1.4 board with VGA output
|
79 |
+
*/
|
80 |
+
#define PREDEFINEDBOARD "boards/dummy.h"
|
81 |
+
|
82 |
+
/* undef this if you want to overide all defaults, then use the settings below */
|
83 |
+
#define HARDWAREHEURISTICS
|
84 |
+
|
85 |
+
/*
|
86 |
+
* These are the individual settings. Logic:
|
87 |
+
* PREDEFINEDBOARD is set, and some of the settings below are
|
88 |
+
* activated automatically.
|
89 |
+
* HARDWAREHEURISTICS is set, some of the settings below are
|
90 |
+
* activated automatically depending on the hardware.
|
91 |
+
* HARDWAREHEURISTICS is not set, all settings below are
|
92 |
+
* have to be set manually.
|
93 |
+
*
|
94 |
+
* Important: HARDWAREHEURISTICS is processed last in the code
|
95 |
+
* so it can override all settings below.
|
96 |
+
*
|
97 |
+
* In one sentence:
|
98 |
+
* First PREDEFINEDBOARD, then manual settings, then HARDWAREHEURISTICS.
|
99 |
+
*/
|
100 |
+
/*
|
101 |
+
#undef ARDUINOPICOSERIAL
|
102 |
+
#undef ARDUINOPS2
|
103 |
+
#undef ARDUINOUSBKBD
|
104 |
+
#undef ARDUINOZX81KBD
|
105 |
+
#undef ARDUINOI2CKBD
|
106 |
+
#undef GIGAUSBKBD
|
107 |
+
#undef ARDUINOPRT
|
108 |
+
#undef DISPLAYCANSCROLL
|
109 |
+
#undef ARDUINOLCDI2C
|
110 |
+
#undef ARDUINONOKIA51
|
111 |
+
#undef ARDUINOILI9488
|
112 |
+
#undef ARDUINOSSD1306
|
113 |
+
#undef ARDUINOMCUFRIEND
|
114 |
+
#undef ARDUINOEDP47
|
115 |
+
#undef ARDUINOGRAPHDUMMY
|
116 |
+
#undef LCDSHIELD
|
117 |
+
#undef ARDUINOTFT
|
118 |
+
#undef ARDUINOVGA
|
119 |
+
#undef TFTESPI
|
120 |
+
#undef ARDUINOEEPROM
|
121 |
+
#undef ARDUINOI2CEEPROM
|
122 |
+
#undef ARDUINOEFS
|
123 |
+
#undef ARDUINOSD
|
124 |
+
#undef ESPSDMMC
|
125 |
+
#undef ESPSPIFFS
|
126 |
+
#undef ESP32FAT
|
127 |
+
#undef RP2040LITTLEFS
|
128 |
+
#undef STM32SDIO
|
129 |
+
#undef GIGAUSBFS
|
130 |
+
#undef ARDUINORTC
|
131 |
+
#undef ARDUINORTCEMULATION
|
132 |
+
#undef ARDUINOTONEEMULATION
|
133 |
+
#undef ARDUINOWIRE
|
134 |
+
#undef ARDUINOSIMPLEWIRE
|
135 |
+
#undef ARDUINOWIRESLAVE
|
136 |
+
#undef ARDUINORF24
|
137 |
+
#undef ARDUINOETH
|
138 |
+
#undef ARDUINOMQTT
|
139 |
+
#undef ARDUINOSENSORS
|
140 |
+
#undef ARDUINOSPIRAM
|
141 |
+
#undef STANDALONE
|
142 |
+
#undef STANDALONESECONDSERIAL
|
143 |
+
*/
|
144 |
+
// #define ALTSERIAL Serial
|
145 |
+
|
146 |
+
/* we debug the runtime library and where the logging goes */
|
147 |
+
#define RTDEBUG 1
|
148 |
+
#define RTDEBUGSTREAM 1
|
149 |
+
|
150 |
+
/* the memory size, set to 0 means determine automatically
|
151 |
+
leaving it undefined means zero. setting it larger than 16 bit
|
152 |
+
make the address_t 32bit */
|
153 |
+
|
154 |
+
#define MEMSIZE 0
|
155 |
+
|
156 |
+
/* experimental features, don't use unless you know the code */
|
157 |
+
/*
|
158 |
+
* this setting uses the EEPROM as program storage
|
159 |
+
* The idea is to create a virtual memory layout starting from 0 with the EEPROM
|
160 |
+
* from elength() and then adding the BASIC RAM to it. himem and top need to be
|
161 |
+
* handled carefully.
|
162 |
+
*/
|
163 |
+
#undef ARDUINOPGMEEPROM
|
164 |
+
|
165 |
+
/* IO control, emulate real tab by counting characters, on by default
|
166 |
+
but overriden for very small boards - see hardware heuristics */
|
167 |
+
#define HASMSTAB
|
168 |
+
|
169 |
+
/* VT52 settings, on by default but override further down for very
|
170 |
+
small boards, check the hardware heuristics section if you need VT52
|
171 |
+
on small AVR boards */
|
172 |
+
#define HASVT52
|
173 |
+
#undef VT52WIRING
|
174 |
+
|
175 |
+
/*
|
176 |
+
* Experimental BUILDIN feature, implemented as a filesystem.
|
177 |
+
* Buildin BASIC programs are stored in the flash memory of the Arduino.
|
178 |
+
* They appear as files in the filesystem.
|
179 |
+
*/
|
180 |
+
#undef HASBUILDIN
|
181 |
+
/* this is the demo module */
|
182 |
+
#define BUILDINMODULE "buildin/buildin-games.h"
|
183 |
+
/* a small tutorial */
|
184 |
+
// #define BUILDINMODULE "buildin/buildin-tutorial.h"
|
185 |
+
/* test program for Arduinos */
|
186 |
+
// #define BUILDINMODULE "buildin/buildin-arduinotest.h"
|
187 |
+
/* a games module */
|
188 |
+
// #define BUILDINMODULE "buildin/buildin-games.h"
|
189 |
+
|
190 |
+
/* interrupts for the EVENT command, this is needed to use Arduino interrupts */
|
191 |
+
#define ARDUINOINTERRUPTS
|
192 |
+
|
193 |
+
/*
|
194 |
+
* handle the break condition in the background.
|
195 |
+
* Off by default but needed for some keyboards.
|
196 |
+
* On an UNO 170 bytes overhead if on and 5%
|
197 |
+
* performance loss. If any system runs background
|
198 |
+
* tasks anyway, better to switch it on.
|
199 |
+
*/
|
200 |
+
#undef BREAKINBACKGROUND
|
201 |
+
|
202 |
+
/*
|
203 |
+
* This code measures the fast ticker frequency in microseconds
|
204 |
+
* It counts the number of tokens drawn plus statements executed.
|
205 |
+
*/
|
206 |
+
#undef FASTTICKERPROFILE
|
207 |
+
|
208 |
+
/* the default EEPROM dummy size */
|
209 |
+
#define EEPROMSIZE 1024
|
210 |
+
|
211 |
+
/*
|
212 |
+
* PIN settings and I2C addresses for various hardware configurations
|
213 |
+
* used a few heuristics and then the hardware definitions above
|
214 |
+
*
|
215 |
+
* #define SDPIN sets the SD CS pin - can be left as a default for most HW configs
|
216 |
+
* TTGO needs it as default definitions in the board file are broken
|
217 |
+
* #define PS2DATAPIN, PS2IRQPIN sets PS2 pin
|
218 |
+
*/
|
219 |
+
|
220 |
+
/* PS2 Keyboard pins for AVR - use one interrupt pin 2 and one date pin
|
221 |
+
5 not 4 because 4 conflicts with SDPIN of the standard SD shield */
|
222 |
+
|
223 |
+
#define PS2DATAPIN 3
|
224 |
+
#define PS2IRQPIN 2
|
225 |
+
|
226 |
+
/*
|
227 |
+
* Pin settings for the ZX81 Keyboard
|
228 |
+
* first the 8 rows, then the 5 columns or the keyboard
|
229 |
+
*
|
230 |
+
* MEGAs have many pins and default is to use the odd pins on the side
|
231 |
+
* UNOs, NANOs, and others use the lower pins by default avoiding the
|
232 |
+
* pin 13 which is LED and doesn't work with standard schematics
|
233 |
+
*/
|
234 |
+
#ifdef ARDUINO_AVR_MEGA2560
|
235 |
+
#define ZX81PINS 37, 35, 33, 31, 29, 27, 25, 23, 47, 45, 43, 41, 39
|
236 |
+
#else
|
237 |
+
#define ZX81PINS 7, 8, 9, 10, 11, 12, A0, A1, 2, 3, 4, 5, 6
|
238 |
+
#endif
|
239 |
+
|
240 |
+
/* Ethernet - 10 is the default */
|
241 |
+
/* #define ETHPIN 10 */
|
242 |
+
|
243 |
+
/* The Pretzelboard definitions for Software Serial, conflicts with SPI */
|
244 |
+
#define SOFTSERIALRX 11
|
245 |
+
#define SOFTSERIALTX 12
|
246 |
+
|
247 |
+
/* near field pin settings for CE and CSN*/
|
248 |
+
#define RF24CEPIN 8
|
249 |
+
#define RF24CSNPIN 9
|
250 |
+
|
251 |
+
/* use standard I2C pins almost always */
|
252 |
+
#undef SDA_PIN
|
253 |
+
#undef SCL_PIN
|
254 |
+
|
255 |
+
/*
|
256 |
+
* BREAKCHAR is the character stopping the program on Ardunios
|
257 |
+
* BREAKPIN can be set, it is a pin that needs to go to low to stop a BASIC program
|
258 |
+
* This should be done in hardware*.h
|
259 |
+
* BREAKSIGNAL can also be set, should be done in hardware*.h
|
260 |
+
*/
|
261 |
+
#define BREAKCHAR '#'
|
262 |
+
|
263 |
+
/* set this is you want pin 4 on low interrupting the interpreter */
|
264 |
+
/* #define BREAKPIN 4 */
|
265 |
+
#undef BREAKPIN
|
266 |
+
|
267 |
+
/* the primary serial stream aka serial aka sream 1 */
|
268 |
+
#ifndef ALTSERIAL
|
269 |
+
#define SERIALPORT Serial
|
270 |
+
#else
|
271 |
+
#define SERIALPORT ALTSERIAL
|
272 |
+
#endif
|
273 |
+
|
274 |
+
/* the secondary serial port aka prt aka stream 4 */
|
275 |
+
#ifndef PRTSERIAL
|
276 |
+
#define PRTSERIAL Serial1
|
277 |
+
#endif
|
278 |
+
|
279 |
+
/*
|
280 |
+
* this is soft SPI for SD cards on MEGAs using
|
281 |
+
* pins 10-13, a patched SD library is needed
|
282 |
+
* for this: https://github.com/slviajero/SoftSD
|
283 |
+
* only needed for MEGA boards with an UNO shield
|
284 |
+
*/
|
285 |
+
#define SOFTWARE_SPI_FOR_SD
|
286 |
+
|
287 |
+
/*
|
288 |
+
* list of default i2c addresses
|
289 |
+
*
|
290 |
+
* some clock modules do have their EEPROM at 0x57.
|
291 |
+
* 0x050 this is the default lowest adress of standard EEPROMs
|
292 |
+
* Configurable range is between 0x50 and 0x57 for modules with jumpers.
|
293 |
+
* Some clock modules do have their EEPROM at 0x57.
|
294 |
+
*
|
295 |
+
* Clock default for the size is 4096. Define your EFS EEPROM and I2C EEPROM
|
296 |
+
* size here. One parameter set is for EFS and one parameter set is for
|
297 |
+
* plain serial EEPROMs.
|
298 |
+
*
|
299 |
+
* RTCs are often at 0x68
|
300 |
+
*/
|
301 |
+
#define EFSEEPROMADDR 0x050
|
302 |
+
/* #define EFSEEPROMSIZE 32768 */
|
303 |
+
|
304 |
+
#define RTCI2CADDR 0x068
|
305 |
+
|
306 |
+
/* the size of the plain I2C EEPROM, typically a clock */
|
307 |
+
/* #define I2CEEPROMADDR 0x057 */
|
308 |
+
/* #define I2CEEPROMSIZE 4096 */
|
309 |
+
/* definition for an external EEPROM */
|
310 |
+
#define I2CEEPROMADDR 0x050
|
311 |
+
|
312 |
+
/* is the I2C EEPROM buffered, left open here for the board file to decided - defaults to unbuffered */
|
313 |
+
/* #define ARDUINOI2CEEPROM_BUFFERED */
|
314 |
+
|
315 |
+
/* use the direct i2c code and bypass the Wire library on AVR
|
316 |
+
* default off here, board file and heuristics to decide, this
|
317 |
+
* is currently only implemented on ARDUINO_ARCH_AVR and tested on UNO
|
318 |
+
*/
|
319 |
+
#undef ARDUINODIRECTI2C
|
320 |
+
|
321 |
+
/*
|
322 |
+
* Sensor library code - configure your sensors here, will go to a
|
323 |
+
* separate file in the future
|
324 |
+
*/
|
325 |
+
#ifdef ARDUINOSENSORS
|
326 |
+
#undef ARDUINODHT
|
327 |
+
#define DHTTYPE DHT22
|
328 |
+
#define DHTPIN 2
|
329 |
+
#define ARDUINOSHT
|
330 |
+
#define ARDUINOMQ2
|
331 |
+
#define MQ2PIN A0
|
332 |
+
#undef ARDUINOLMS6
|
333 |
+
#undef ARDUINOAHT
|
334 |
+
#undef ARDUINOBMP280
|
335 |
+
#undef ARDUINOBME280
|
336 |
+
#endif
|
337 |
+
|
338 |
+
|
339 |
+
#if defined(ARDUINOSHT) || defined(ARDUINOLMS6) || defined(ARDUINOAHT) || defined(ARDUINOBMP280) || defined(ARDUINOBME280)
|
340 |
+
#define ARDUINOSIMPLEWIRE
|
341 |
+
#endif
|
342 |
+
|
343 |
+
/*
|
344 |
+
* Keyboard configuation code, currently only GERMAN and US are supported
|
345 |
+
* This is used for PS2, FABGL and USB. USB very raw.
|
346 |
+
* ZX81 is not supported with different languages, I only have a UK one.
|
347 |
+
*/
|
348 |
+
|
349 |
+
#define ARDUINOKBDLANG_GERMAN
|
350 |
+
//#define ARDUINOKBDLANG_US
|
351 |
+
|
352 |
+
/*
|
353 |
+
* The heuristics. These are things that normally would make sense on a
|
354 |
+
* board.
|
355 |
+
*/
|
356 |
+
|
357 |
+
/*
|
358 |
+
* Buffer sizes depending on what we are doing.
|
359 |
+
*/
|
360 |
+
|
361 |
+
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_LGT8F)
|
362 |
+
/* the small memory model with shallow stacks and small buffers */
|
363 |
+
#define BUFSIZE 80
|
364 |
+
#define STACKSIZE 15
|
365 |
+
#define GOSUBDEPTH 4
|
366 |
+
#define FORDEPTH 4
|
367 |
+
#define LINECACHESIZE 4
|
368 |
+
#else
|
369 |
+
/* the for larger microcontrollers */
|
370 |
+
#define BUFSIZE 128
|
371 |
+
#define STACKSIZE 64
|
372 |
+
#define GOSUBDEPTH 8
|
373 |
+
#define FORDEPTH 8
|
374 |
+
#define LINECACHESIZE 16
|
375 |
+
#endif
|
376 |
+
|
377 |
+
#ifdef HARDWAREHEURISTICS
|
378 |
+
/* UNOS are very common. Small memory, we put the program into EEPROM and make everything small */
|
379 |
+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO)
|
380 |
+
#define ARDUINOEEPROM
|
381 |
+
#define ARDUINOPICOSERIAL
|
382 |
+
#define ARDUINOPGMEEPROM
|
383 |
+
#define ARDUINODIRECTI2C
|
384 |
+
#undef ARDUINOI2CEEPROM_BUFFERED
|
385 |
+
#undef LINECACHESIZE
|
386 |
+
#undef HASMSTAB
|
387 |
+
#define MEMSIZE 512
|
388 |
+
#endif
|
389 |
+
/* der Pro */
|
390 |
+
#if defined(ARDUINO_AVR_PRO)
|
391 |
+
#define ARDUINOEEPROM
|
392 |
+
#define ARDUINOPGMEEPROM
|
393 |
+
#undef LINECACHESIZE
|
394 |
+
#undef HASMSTAB
|
395 |
+
#undef HASVT52
|
396 |
+
#define MEMSIZE 768
|
397 |
+
#endif
|
398 |
+
/* on a DUEMILA we allocate just as little main memory as possible, currenly not working because sketch too big
|
399 |
+
* needs to be checked */
|
400 |
+
#if defined(ARDUINO_AVR_DUEMILANOVE)
|
401 |
+
#define ARDUINOEEPROM
|
402 |
+
#define ARDUINOPICOSERIAL
|
403 |
+
#define ARDUINOPGMEEPROM
|
404 |
+
#undef LINECACHESIZE
|
405 |
+
#undef HASMSTAB
|
406 |
+
#define MEMSIZE 128
|
407 |
+
#undef HASVT52
|
408 |
+
#endif
|
409 |
+
/* tested for LTQF32 Mini EVB - very low memory as core needs a lot */
|
410 |
+
#if defined(ARDUINO_ARCH_LGT8F)
|
411 |
+
#define ARDUINOEEPROM
|
412 |
+
#define ARDUINOPICOSERIAL
|
413 |
+
#undef LINECACHESIZE
|
414 |
+
#undef HASMSTAB
|
415 |
+
#define MEMSIZE 256
|
416 |
+
#define ARDUINOPGMEEPROM
|
417 |
+
#undef HASVT52
|
418 |
+
#endif
|
419 |
+
/* all AVR 8 bit boards have an EEPROM (most probably) */
|
420 |
+
#if defined(ARDUINO_ARCH_AVR)
|
421 |
+
#define ARDUINOEEPROM
|
422 |
+
#endif
|
423 |
+
/* megaAVR boards have an EEPROM */
|
424 |
+
#if defined(ARDUINO_ARCH_MEGAAVR)
|
425 |
+
#define ARDUINOEEPROM
|
426 |
+
#endif
|
427 |
+
/* LEONARDO boards */
|
428 |
+
#if defined(ARDUINO_AVR_LEONARDO)
|
429 |
+
/* to be done */
|
430 |
+
#endif
|
431 |
+
/* all ESPs best are compiled with ESPSPIFFS predefined */
|
432 |
+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
433 |
+
#define ESPSPIFFS
|
434 |
+
#endif
|
435 |
+
/* all ESPs best have EEPROM emulation */
|
436 |
+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
437 |
+
#define ARDUINOEEPROM
|
438 |
+
#define ESPSPIFFS
|
439 |
+
#endif
|
440 |
+
/* all RP2040 boards best are compiled with RP2040LITTLEFS predefined */
|
441 |
+
#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED_RP2040)
|
442 |
+
#define RP2040LITTLEFS
|
443 |
+
#endif
|
444 |
+
/* use the EEPROM dummy of the NRESESA boards */
|
445 |
+
#if defined(ARDUINO_ARCH_RENESAS)
|
446 |
+
#define ARDUINOEEPROM
|
447 |
+
#endif
|
448 |
+
/* for XMC there is an EEPROM emulation, which needs: https://github.com/slviajero/XMCEEPROMLib */
|
449 |
+
#if defined(ARDUINO_ARCH_XMC)
|
450 |
+
#define ARDUINOEEPROM
|
451 |
+
#endif
|
452 |
+
/* the China Nano clones. Super fast but with very small flash. */
|
453 |
+
#if defined(ARDUINO_ARCH_LGT8F)
|
454 |
+
#undef HASMSTAB
|
455 |
+
#endif
|
456 |
+
#endif
|
457 |
+
|
458 |
+
/*
|
459 |
+
* Now source the the hardware models if this is set.
|
460 |
+
*/
|
461 |
+
#ifdef PREDEFINEDBOARD
|
462 |
+
#include PREDEFINEDBOARD
|
463 |
+
#endif
|
464 |
+
|
465 |
+
/*
|
466 |
+
* Here, dependencies are handled. Some settings require others to be set
|
467 |
+
* first.
|
468 |
+
*
|
469 |
+
* Examples:
|
470 |
+
* Many filesystems and displays need SPI.
|
471 |
+
* Some components need Wire.
|
472 |
+
* Some platforms do not have tone, so we need to emulate it.
|
473 |
+
*/
|
474 |
+
|
475 |
+
/*
|
476 |
+
* DUE has no tone, we switch to emulation mode automatically.
|
477 |
+
*/
|
478 |
+
#ifdef ARDUINO_SAM_DUE
|
479 |
+
#define ARDUINOTONEEMULATION
|
480 |
+
#endif
|
481 |
+
|
482 |
+
/*
|
483 |
+
* Some settings, defaults, and dependencies
|
484 |
+
*
|
485 |
+
* HASWIRE is set to start wire. Some libraries do this again.
|
486 |
+
*
|
487 |
+
* Handling Wire and SPI is tricky as some of the libraries
|
488 |
+
* also include and start SPI and Wire code.
|
489 |
+
*
|
490 |
+
* HASIMPLEWIRE avoids the overhead of importing the entire
|
491 |
+
* filesystem code. It only activates plain Wire and provides
|
492 |
+
* the WIRE command in basic.
|
493 |
+
*/
|
494 |
+
|
495 |
+
/*
|
496 |
+
* Safety net for ARDUINODIRECTI2C, architectures that are
|
497 |
+
* not AVR 8 bit and do not have TWDR are not supported.
|
498 |
+
*/
|
499 |
+
#if !defined(ARDUINO_ARCH_AVR) || !defined(TWDR)
|
500 |
+
#undef ARDUINODIRECTI2C
|
501 |
+
#endif
|
502 |
+
|
503 |
+
/* a clock needs wire */
|
504 |
+
#ifdef ARDUINORTC
|
505 |
+
#define HASSIMPLEWIRE
|
506 |
+
#endif
|
507 |
+
|
508 |
+
/* a display needs wire */
|
509 |
+
#if defined(ARDUINOLCDI2C) || defined(ARDUINOSSD1306)
|
510 |
+
#define HASSIMPLEWIRE
|
511 |
+
#endif
|
512 |
+
|
513 |
+
/* EEPROM storage needs wire */
|
514 |
+
#if defined(ARDUINOEFS)
|
515 |
+
#define HASSIMPLEWIRE
|
516 |
+
#endif
|
517 |
+
|
518 |
+
/* external EEPROMs also need wire */
|
519 |
+
#if defined(ARDUINOI2CEEPROM)
|
520 |
+
#define HASSIMPLEWIRE
|
521 |
+
#endif
|
522 |
+
|
523 |
+
/* external EEPROM buffered needs full wire support, because EFS not ported */
|
524 |
+
#if defined(ARDUINOI2CEEPROM) && defined(ARDUINOI2CEEPROM_BUFFERED)
|
525 |
+
#define HASWIRE
|
526 |
+
#endif
|
527 |
+
|
528 |
+
/* plain Wire support also needs wire ;-) */
|
529 |
+
#if defined(ARDUINOWIRE) || defined(ARDUINOWIRESLAVE)
|
530 |
+
#define HASWIRE
|
531 |
+
#endif
|
532 |
+
|
533 |
+
/* and I2C Keyboard needs wire */
|
534 |
+
#if defined(ARDUINOI2CKBD)
|
535 |
+
#define HASSIMPLEWIRE
|
536 |
+
#endif
|
537 |
+
|
538 |
+
/* the BASIC command/function WIRE */
|
539 |
+
#if defined (ARDUINOSIMPLEWIRE)
|
540 |
+
#define HASSIMPLEWIRE
|
541 |
+
#endif
|
542 |
+
|
543 |
+
/* radio needs SPI */
|
544 |
+
#if defined(ARDUINORF24)
|
545 |
+
#define ARDUINOSPI
|
546 |
+
#endif
|
547 |
+
|
548 |
+
/* a filesystem needs SPI */
|
549 |
+
#if defined(ARDUINOSD) || defined(ESPSPIFFS) || defined(ESP32FAT)
|
550 |
+
#define ARDUINOSPI
|
551 |
+
#endif
|
552 |
+
|
553 |
+
/* networking may need SPI */
|
554 |
+
#if defined(ARDUINOMQTT)
|
555 |
+
#define ARDUINOSPI
|
556 |
+
#endif
|
557 |
+
|
558 |
+
/* the NOKIA and ILI9488 display needs SPI */
|
559 |
+
#if defined(ARDUINONOKIA51) || defined(ARDUINOILI9488) || defined(TFTESPI)
|
560 |
+
#define ARDUINOSPI
|
561 |
+
#endif
|
562 |
+
|
563 |
+
/* the RAM chips */
|
564 |
+
#if defined(ARDUINOSPIRAM)
|
565 |
+
#define ARDUINOSPI
|
566 |
+
#endif
|
567 |
+
|
568 |
+
/* Networking and keyboards need the background task capability */
|
569 |
+
#if defined(ARDUINOMQTT) || defined(ARDUINOETH) || defined(ARDUINOUSBKBD) || defined(ARDUINOZX81KBD) || defined(ARDUINOI2CKBD) || defined(GIGAUSBKBD)
|
570 |
+
#define BASICBGTASK
|
571 |
+
#endif
|
572 |
+
|
573 |
+
/* the ESP8266 needs to run the background task calls for the scheduler */
|
574 |
+
#if defined(ARDUINO_ARCH_ESP8266)
|
575 |
+
#define BASICBGTASK
|
576 |
+
#endif
|
577 |
+
|
578 |
+
/* Break in background needs background tasks as well */
|
579 |
+
#if defined(BREAKINBACKGROUND)
|
580 |
+
#define BASICBGTASK
|
581 |
+
#endif
|
582 |
+
|
583 |
+
/* picoserial is not a available on many platforms */
|
584 |
+
#ifdef ARDUINOPICOSERIAL
|
585 |
+
#ifndef UCSR0A
|
586 |
+
#undef ARDUINOPICOSERIAL
|
587 |
+
#endif
|
588 |
+
#endif
|
589 |
+
|
590 |
+
/*
|
591 |
+
* incompatibilities and library stuff
|
592 |
+
*/
|
593 |
+
/* these platforms have no EEPROM and no emulation built-in */
|
594 |
+
#if defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED_GIGA)
|
595 |
+
#undef ARDUINOEEPROM
|
596 |
+
#endif
|
597 |
+
|
598 |
+
/*
|
599 |
+
* SD filesystems with the standard SD driver
|
600 |
+
* for MEGA 256 a soft SPI solution is needed
|
601 |
+
* if standard shields are used, this is a patched
|
602 |
+
* SD library https://github.com/slviajero/SoftSD
|
603 |
+
*/
|
604 |
+
#ifdef ARDUINOSD
|
605 |
+
#define FILESYSTEMDRIVER
|
606 |
+
#endif
|
607 |
+
|
608 |
+
/*
|
609 |
+
* ESPSPIFFS tested on ESP8266 and ESP32
|
610 |
+
* supports formating in BASIC
|
611 |
+
*/
|
612 |
+
#ifdef ESPSPIFFS
|
613 |
+
#define FILESYSTEMDRIVER
|
614 |
+
#endif
|
615 |
+
|
616 |
+
/*
|
617 |
+
* ESP32FAT tested on ESP32
|
618 |
+
* supports formating in BASIC
|
619 |
+
*/
|
620 |
+
#ifdef ESP32FAT
|
621 |
+
#define FILESYSTEMDRIVER
|
622 |
+
#endif
|
623 |
+
|
624 |
+
/*
|
625 |
+
* RP2040 internal filesystem
|
626 |
+
* This is test code from https://github.com/slviajero/littlefs
|
627 |
+
* and the main branch is actively developed
|
628 |
+
*/
|
629 |
+
#ifdef RP2040LITTLEFS
|
630 |
+
#define FILESYSTEMDRIVER
|
631 |
+
#endif
|
632 |
+
|
633 |
+
/*
|
634 |
+
* STM32 SDIO driver for he SD card slot of the STM32F4 boards (and others)
|
635 |
+
*/
|
636 |
+
#ifdef STM32SDIO
|
637 |
+
#define FILESYSTEMDRIVER
|
638 |
+
#endif
|
639 |
+
|
640 |
+
/*
|
641 |
+
* The USB filesystem of the GIGA board
|
642 |
+
*/
|
643 |
+
#ifdef GIGAUSBFS
|
644 |
+
#define FILESYSTEMDRIVER
|
645 |
+
#define NEEDSUSB
|
646 |
+
#endif
|
647 |
+
|
648 |
+
/*
|
649 |
+
* external flash file systems override internal filesystems
|
650 |
+
* currently BASIC can only have one filesystem
|
651 |
+
*/
|
652 |
+
#ifdef ARDUINOSD
|
653 |
+
#undef ESPSPIFFS
|
654 |
+
#undef ESP32FAT
|
655 |
+
#undef RP2040LITTLEFS
|
656 |
+
#undef GIAGUSBFS
|
657 |
+
#endif
|
658 |
+
|
659 |
+
/*
|
660 |
+
* support for external EEPROMs as filesystem
|
661 |
+
* overriding all other filessystems. This is a minimalistic
|
662 |
+
* filesystem meant for very small systems with not enough
|
663 |
+
* memory for real filesystems
|
664 |
+
* https://github.com/slviajero/EepromFS
|
665 |
+
*/
|
666 |
+
#ifdef ARDUINOEFS
|
667 |
+
#undef ESPSPIFFS
|
668 |
+
#undef ESP32FAT
|
669 |
+
#undef RP2040LITTLEFS
|
670 |
+
#undef ARDUINOSD
|
671 |
+
#undef STM32SDIO
|
672 |
+
#undef GIGAUSBFS
|
673 |
+
#define FILESYSTEMDRIVER
|
674 |
+
#endif
|
675 |
+
|
676 |
+
/*
|
677 |
+
* The build in file system for read only programs, only
|
678 |
+
* if there is no other file system present
|
679 |
+
*/
|
680 |
+
#if defined(HASBUILDIN)
|
681 |
+
#define FILESYSTEMDRIVER
|
682 |
+
#include BUILDINMODULE
|
683 |
+
#endif
|
684 |
+
|
685 |
+
/*
|
686 |
+
* Software SPI only on Mega2560
|
687 |
+
*/
|
688 |
+
#ifndef ARDUINO_AVR_MEGA2560
|
689 |
+
#undef SOFTWARE_SPI_FOR_SD
|
690 |
+
#endif
|
691 |
+
|
692 |
+
/*
|
693 |
+
* I used these two articles
|
694 |
+
* https://randomnerdtutorials.com/esp8266-deep-sleep-with-arduino-ide/
|
695 |
+
* https://randomnerdtutorials.com/esp32-deep-sleep-arduino-ide-wake-up-sources/
|
696 |
+
* for this very simple implementation - needs to be improved (pass data from sleep
|
697 |
+
* state to sleep state via EEPROM)
|
698 |
+
*/
|
699 |
+
/* this is done only here now to make sure HASCLOCK is set properly */
|
700 |
+
|
701 |
+
#if defined(ARDUINO_ARCH_SAMD)
|
702 |
+
#define HASBUILTINRTC
|
703 |
+
#endif
|
704 |
+
|
705 |
+
/* STM32duino have the same structure */
|
706 |
+
#if defined(ARDUINO_ARCH_STM32)
|
707 |
+
#define HASBUILTINRTC
|
708 |
+
#endif
|
709 |
+
|
710 |
+
/* the NRENESA board have a buildin RTC as well */
|
711 |
+
#if defined(ARDUINO_ARCH_RENESAS)
|
712 |
+
#define HASBUILTINRTC
|
713 |
+
#endif
|
714 |
+
|
715 |
+
/*
|
716 |
+
* global variables for a standard LCD shield.
|
717 |
+
* Includes the standard Arduino LiquidCrystal library
|
718 |
+
*/
|
719 |
+
#ifdef LCDSHIELD
|
720 |
+
#define DISPLAYDRIVER
|
721 |
+
#define HASKEYPAD
|
722 |
+
#undef DISPLAYHASCOLOR
|
723 |
+
#undef DISPLAYHASGRAPH
|
724 |
+
#endif
|
725 |
+
|
726 |
+
/*
|
727 |
+
* A LCD display connnected via I2C, uses the standard
|
728 |
+
* Arduino I2C display library.
|
729 |
+
*/
|
730 |
+
#ifdef ARDUINOLCDI2C
|
731 |
+
#define DISPLAYDRIVER
|
732 |
+
#undef DISPLAYHASCOLOR
|
733 |
+
#undef DISPLAYHASGRAPH
|
734 |
+
#endif
|
735 |
+
|
736 |
+
/*
|
737 |
+
* A Nokia 5110 with ug8lib2 - can scroll quite well
|
738 |
+
* https://github.com/olikraus/u8g2/wiki/u8g2reference
|
739 |
+
* This is a buffered display it has a dspupdate() function
|
740 |
+
* it also needs to call dspgraphupdate() after each graphic
|
741 |
+
* operation
|
742 |
+
*
|
743 |
+
* default PIN settings here are for ESP8266, using the standard
|
744 |
+
* SPI SS for 15 for CS/CE, and 0 for DC, 2 for reset
|
745 |
+
*
|
746 |
+
*/
|
747 |
+
#ifdef ARDUINONOKIA51
|
748 |
+
#define DISPLAYDRIVER
|
749 |
+
#define DISPLAYPAGEMODE
|
750 |
+
#undef DISPLAYHASCOLOR /* display driver not color aware for this display */
|
751 |
+
#define DISPLAYHASGRAPH
|
752 |
+
#endif
|
753 |
+
|
754 |
+
/*
|
755 |
+
* 4.7 inch epaper displays are derived from the NOKIA51 code, no grayscales
|
756 |
+
* at the moment. Forcing the font into rectangles and hoping this works.
|
757 |
+
*
|
758 |
+
* Epapers bypass the display driver here and use a graphics based display
|
759 |
+
* mode instead
|
760 |
+
*/
|
761 |
+
#ifdef ARDUINOEDP47
|
762 |
+
#define GRAPHDISPLAYDRIVER
|
763 |
+
#define DISPLAYPAGEMODE
|
764 |
+
#undef DISPLAYHASCOLOR /* display driver not color aware for this display */
|
765 |
+
#define DISPLAYHASGRAPH
|
766 |
+
#endif
|
767 |
+
|
768 |
+
|
769 |
+
/*
|
770 |
+
* Small SSD1306 OLED displays with I2C interface
|
771 |
+
* This is a buffered display it has a dspupdate() function
|
772 |
+
* it also needs to call dspgraphupdate() after each graphic
|
773 |
+
* operation
|
774 |
+
*/
|
775 |
+
#ifdef ARDUINOSSD1306
|
776 |
+
#define DISPLAYDRIVER
|
777 |
+
#define DISPLAYPAGEMODE
|
778 |
+
#undef DISLAYHASCOLOR /* display driver not color aware for this display */
|
779 |
+
#define DISPLAYHASGRAPH
|
780 |
+
#endif
|
781 |
+
|
782 |
+
/*
|
783 |
+
* A ILI9488 with Jarett Burkets version of Adafruit GFX and patches
|
784 |
+
* by Stefan Lenz
|
785 |
+
* currently only slow software scrolling implemented in BASIC
|
786 |
+
*
|
787 |
+
* https://github.com/slviajero/ILI9488
|
788 |
+
*
|
789 |
+
* we use 9, 8, 7 as CS, CE, RST by default and A7 for the led brightness control
|
790 |
+
*/
|
791 |
+
|
792 |
+
#ifdef ARDUINOILI9488
|
793 |
+
#define DISPLAYDRIVER
|
794 |
+
#define DISPLAYHASCOLOR
|
795 |
+
#define DISPLAYHASGRAPH
|
796 |
+
#endif
|
797 |
+
|
798 |
+
/*
|
799 |
+
* A MCUFRIEND parallel port display for the various tft shields
|
800 |
+
* This implementation is mainly for Arduino MEGA
|
801 |
+
*
|
802 |
+
* currently only slow software scrolling implemented in BASIC
|
803 |
+
*
|
804 |
+
*/
|
805 |
+
|
806 |
+
#ifdef ARDUINOMCUFRIEND
|
807 |
+
#define DISPLAYDRIVER
|
808 |
+
#define DISPLAYHASCOLOR
|
809 |
+
#define DISPLAYHASGRAPH
|
810 |
+
#endif
|
811 |
+
|
812 |
+
/*
|
813 |
+
* The driver for the TFT_eSPI graphics of the T-Deck from Lilygo
|
814 |
+
* currently not finished
|
815 |
+
*/
|
816 |
+
|
817 |
+
#ifdef TFTESPI
|
818 |
+
#define DISPLAYDRIVER
|
819 |
+
#define DISPLAYHASCOLOR
|
820 |
+
#define DISPLAYHASGRAPH
|
821 |
+
#endif
|
822 |
+
|
823 |
+
/*
|
824 |
+
* A no operations graphics dummy
|
825 |
+
* Tests the BASIC side of the graphics code without triggering
|
826 |
+
* any output
|
827 |
+
*/
|
828 |
+
#ifdef ARDUINOGRAPHDUMMY
|
829 |
+
#define DISPLAYDRIVER
|
830 |
+
#undef DISPLAYHASCOLOR
|
831 |
+
#define DISPLAYHASGRAPH
|
832 |
+
#endif
|
833 |
+
|
834 |
+
/*
|
835 |
+
* SD1963 TFT display code with UTFT.
|
836 |
+
* Tested witth SD1963 800*480 board.
|
837 |
+
* it is mainly intended for a MEGA or DUE as a all in one system
|
838 |
+
* this is for a MEGA shield and the CTE DUE shield, for the due
|
839 |
+
* you need to read the comment in Arduino/libraries/UTFT/hardware/arm
|
840 |
+
* HW_ARM_defines.h -> uncomment the DUE shield
|
841 |
+
* See also
|
842 |
+
* https://github.com/slviajero/tinybasic/wiki/Projects:-4.-A-standalone-computer-with-a-TFT-screen-based-on-a-DUE
|
843 |
+
*/
|
844 |
+
#ifdef ARDUINOTFT
|
845 |
+
#define DISPLAYDRIVER
|
846 |
+
#define DISPLAYHASCOLOR
|
847 |
+
#define DISPLAYHASGRAPH
|
848 |
+
#endif
|
849 |
+
|
850 |
+
/*
|
851 |
+
* Keyboard code for either the Fablib Terminal class or
|
852 |
+
* PS2Keyboard - please note that you need the ESP patched
|
853 |
+
* version here as mentioned above
|
854 |
+
*
|
855 |
+
* sets HASKEYBOARD to inform basic about this capability
|
856 |
+
*
|
857 |
+
* keyboards can implement
|
858 |
+
* kbdbegin()
|
859 |
+
* they need to provide
|
860 |
+
* kbdavailable(), kbdread(), kbdcheckch()
|
861 |
+
* the later is for interrupting running BASIC code
|
862 |
+
*/
|
863 |
+
#if defined(ARDUINO_TTGO_T7_V14_Mini32) && defined(ARDUINOVGA)
|
864 |
+
#define PS2FABLIB
|
865 |
+
#define HASKEYBOARD
|
866 |
+
#define DISPLAYHASCOLOR
|
867 |
+
#define DISPLAYHASGRAPH
|
868 |
+
#endif
|
869 |
+
|
870 |
+
#if defined(ARDUINO) && defined(ARDUINOPS2)
|
871 |
+
#define PS2KEYBOARD
|
872 |
+
#define HASKEYBOARD
|
873 |
+
#endif
|
874 |
+
|
875 |
+
#if defined(ARDUINO) && defined(ARDUINOUSBKBD)
|
876 |
+
#define HASKEYBOARD
|
877 |
+
#define USBKEYBOARD
|
878 |
+
#endif
|
879 |
+
|
880 |
+
#if defined(ARDUINOZX81KBD)
|
881 |
+
#define HASKEYBOARD
|
882 |
+
#define ZX81KEYBOARD
|
883 |
+
#endif
|
884 |
+
|
885 |
+
/* BREAKINBACKGROUND is needed here to avoid slowdown, probably also for the other keyboards */
|
886 |
+
#if defined(ARDUINOI2CKBD)
|
887 |
+
#define HASKEYBOARD
|
888 |
+
#define I2CKEYBOARD
|
889 |
+
#define BREAKINBACKGROUND
|
890 |
+
#endif
|
891 |
+
|
892 |
+
/* set the HASKEYBOARD feature to tell BASIC about it */
|
893 |
+
#if defined(GIGAUSBKBD)
|
894 |
+
#define HASKEYBOARD
|
895 |
+
#define GIGAUSBKEYBOARD
|
896 |
+
#endif
|
897 |
+
|
898 |
+
/*
|
899 |
+
* Arduino Real Time clock. The interface here offers the values as number_t
|
900 |
+
* combining all values.
|
901 |
+
*
|
902 |
+
* The code does not use an RTC library any more all the rtc support is
|
903 |
+
* builtin now.
|
904 |
+
*
|
905 |
+
* A clock must activate the macro #define HASCLOCK to make the clock
|
906 |
+
* available in BASIC.
|
907 |
+
*
|
908 |
+
* The following software models are supported
|
909 |
+
* - Built-in clocks of STM32 and MKR and NRESAS and XIAO are supported by default
|
910 |
+
* as RTCZero type code
|
911 |
+
* - Built-in clocks of ESP32 are supported by default with a time structure type code
|
912 |
+
* - Built-in clocks of GIGA the same as ESP32
|
913 |
+
* - I2C clocks can be activated: DS1307, DS3231, and DS3232
|
914 |
+
* - A Real Time Clock emulation is possible using millis()
|
915 |
+
*
|
916 |
+
* rtcget accesses the internal registers of the clock.
|
917 |
+
* Registers 0-6 are bcd transformed to return
|
918 |
+
* seconds, minutes, hours, day of week, day, month, year
|
919 |
+
*
|
920 |
+
* On I2C clocks registers 7-255 are returned as memory cells
|
921 |
+
*/
|
922 |
+
|
923 |
+
#if defined(ARDUINORTC) || defined(HASBUILTINRTC) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINORTCEMULATION) || defined(ARDUINO_ARCH_MBED_GIGA)
|
924 |
+
#define HASCLOCK
|
925 |
+
#endif
|
926 |
+
|
927 |
+
/*
|
928 |
+
* External EEPROM is handled through an EFS filesystem object
|
929 |
+
* see https://github.com/slviajero/EepromFS
|
930 |
+
* for details. Here the most common parameters are set as a default.
|
931 |
+
*/
|
932 |
+
#ifdef ARDUINOEFS
|
933 |
+
#undef ARDUINOI2CEEPROM
|
934 |
+
#endif
|
935 |
+
|
936 |
+
/*
|
937 |
+
* Tell BASIC we have a second serial port
|
938 |
+
*/
|
939 |
+
#ifdef ARDUINOPRT
|
940 |
+
#define HASSERIAL1
|
941 |
+
#endif
|
942 |
+
|
943 |
+
/*
|
944 |
+
* Tell BASIC we have a radio adapter
|
945 |
+
*/
|
946 |
+
#ifdef ARDUINORF24
|
947 |
+
#define HASRF24
|
948 |
+
#endif
|
949 |
+
|
950 |
+
/*
|
951 |
+
* Tell BASIC we have MQTT and make sure one low level
|
952 |
+
* interface is available
|
953 |
+
*/
|
954 |
+
#ifdef ARDUINOMQTT
|
955 |
+
#define HASMQTT
|
956 |
+
#ifndef ARDUINOETH
|
957 |
+
#define ARDUINOWIFI
|
958 |
+
#endif
|
959 |
+
#endif
|
960 |
+
|
961 |
+
/*
|
962 |
+
* handling the PROGMEM macros
|
963 |
+
*/
|
964 |
+
|
965 |
+
/*
|
966 |
+
* if the PROGMEM macro is define we compile on the Arduino IDE
|
967 |
+
* we undef all hardware settings otherwise a little odd
|
968 |
+
*/
|
969 |
+
#ifdef ARDUINO_ARCH_MBED
|
970 |
+
#define PROGMEM
|
971 |
+
#endif
|
972 |
+
|
973 |
+
#ifdef PROGMEM
|
974 |
+
#define ARDUINOPROGMEM
|
975 |
+
#else
|
976 |
+
#undef ARDUINOPROGMEM
|
977 |
+
#define PROGMEM
|
978 |
+
#endif
|
979 |
+
|
980 |
+
/* on XMC we circumvent progmem */
|
981 |
+
#ifdef ARDUINO_ARCH_XMC
|
982 |
+
#undef ARDUINOPROGMEM
|
983 |
+
#define PROGMEM
|
984 |
+
#endif
|
985 |
+
|
986 |
+
|
987 |
+
/* the code to address EEPROMs directly */
|
988 |
+
/* only AVR controllers are tested with this, don't use elsewhere, there are multiple bugs */
|
989 |
+
#if defined(ARDUINOPGMEEPROM) & ! ( defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_LGT8F) )
|
990 |
+
#undef ARDUINOPGMEEPROM
|
991 |
+
#endif
|
992 |
+
|
993 |
+
#ifdef ARDUINOPGMEEPROM
|
994 |
+
#define USEMEMINTERFACE
|
995 |
+
#define EEPROMMEMINTERFACE
|
996 |
+
#else
|
997 |
+
#undef EEPROMMEMINTERFACE
|
998 |
+
#endif
|
999 |
+
|
1000 |
+
/* the SPI RAM interface */
|
1001 |
+
#ifdef ARDUINOSPIRAM
|
1002 |
+
#define USEMEMINTERFACE
|
1003 |
+
#define SPIRAMINTERFACE
|
1004 |
+
#endif
|
1005 |
+
|
1006 |
+
/*
|
1007 |
+
* to handle strings in situations with a memory interface two more buffers are
|
1008 |
+
* needed they store intermediate results of string operations. The buffersize
|
1009 |
+
* limits the maximum string length indepents of how big strings are set.
|
1010 |
+
*
|
1011 |
+
* default is 128, on an MEGA 512 is possible
|
1012 |
+
*/
|
1013 |
+
#ifdef ARDUINO_AVR_MEGA2560
|
1014 |
+
#define SPIRAMSBSIZE 512
|
1015 |
+
#else
|
1016 |
+
#define SPIRAMSBSIZE 128
|
1017 |
+
#endif
|
1018 |
+
|
1019 |
+
|
1020 |
+
/*
|
1021 |
+
* Does the platform has command line args and do we want to use them
|
1022 |
+
* Arduinos don't have them
|
1023 |
+
*/
|
1024 |
+
#undef HASARGS
|
1025 |
+
|
1026 |
+
/*
|
1027 |
+
* How restrictive are we on function recursive calls to protect the stack
|
1028 |
+
* On 8 bit Arduinos this needs to be limited strictly
|
1029 |
+
*/
|
1030 |
+
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) || defined(ARDUINO_ARCH_LGT8F) || defined(ARDUINO_AVR_PRO)
|
1031 |
+
#define FNLIMIT 4
|
1032 |
+
#elif defined(ARDUINO_ARCH_ESP8266)
|
1033 |
+
#define FNLIMIT 64
|
1034 |
+
#elif defined(ARDUINO_ARCH_ESP32)
|
1035 |
+
#define FNLIMIT 128
|
1036 |
+
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED_RP2040)
|
1037 |
+
#define FNLIMIT 128
|
1038 |
+
#elif defined(ARDUINO_ARCH_SAM) && defined(ARDUINO_ARCH_SAMD)
|
1039 |
+
#define FNLIMIT 64
|
1040 |
+
#elif defined(ARDUINO_ARCH_XMC)
|
1041 |
+
#define FNLIMIT 64
|
1042 |
+
#elif defined(ARDUINO_ARCH_SMT32)
|
1043 |
+
#define FNLIMIT 128
|
1044 |
+
#elif defined(ARDUINO_ARCH_RENESAS)
|
1045 |
+
#define FNLIMIT 32
|
1046 |
+
#else
|
1047 |
+
#define FNLIMIT 128
|
1048 |
+
#endif
|
1049 |
+
|
1050 |
+
/*
|
1051 |
+
* here the runtime environment makes a good guess which
|
1052 |
+
* language can be supported by the boards. This is tricky
|
1053 |
+
* it may not always work.
|
1054 |
+
*
|
1055 |
+
* MEGAAVR does BASICFULL but this leaves little room for hardware drivers
|
1056 |
+
* LEONARDO currently broken, to much flash allocated.
|
1057 |
+
*/
|
1058 |
+
#if defined(ARDUINO_ARCH_AVR)
|
1059 |
+
#if defined(ARDUINO_AVR_DUEMILANOVE)
|
1060 |
+
#define BASICPALOALTO
|
1061 |
+
#endif
|
1062 |
+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_PRO)
|
1063 |
+
#define BASICSIMPLE
|
1064 |
+
#endif
|
1065 |
+
#if defined(ARDUINO_AVR_LEONARDO)
|
1066 |
+
#define BASICSMALL
|
1067 |
+
#endif
|
1068 |
+
#if defined(ARDUINO_AVR_MEGA2560)
|
1069 |
+
#define BASICFULL
|
1070 |
+
#endif
|
1071 |
+
#elif defined(ARDUINO_ARCH_LGT8F)
|
1072 |
+
#define BASICSIMPLE
|
1073 |
+
#elif defined(ARDUINO_ARCH_MEGAAVR)
|
1074 |
+
#define BASICFULL
|
1075 |
+
#elif defined(ARDUINO_ARCH_ESP8266)
|
1076 |
+
#define BASICFULL
|
1077 |
+
#elif defined(ARDUINO_ARCH_ESP32)
|
1078 |
+
#define BASICFULL
|
1079 |
+
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED_RP2040)
|
1080 |
+
#define BASICFULL
|
1081 |
+
#elif defined(ARDUINO_ARCH_SAM) && defined(ARDUINO_ARCH_SAMD)
|
1082 |
+
#define BASICFULL
|
1083 |
+
#elif defined(ARDUINO_ARCH_XMC)
|
1084 |
+
#define BASICFULL
|
1085 |
+
#elif defined(ARDUINO_ARCH_SMT32)
|
1086 |
+
#define BASICFULL
|
1087 |
+
#elif defined(ARDUINO_ARCH_RENESAS)
|
1088 |
+
#define BASICFULL
|
1089 |
+
#else
|
1090 |
+
#define BASICFULL
|
1091 |
+
#endif
|
data/Basic2/IoTBasic/language.h
ADDED
@@ -0,0 +1,464 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
*
|
3 |
+
* $Id: language.h,v 1.1 2024/02/25 04:43:16 stefan Exp stefan $
|
4 |
+
*
|
5 |
+
* Stefan's IoT BASIC interpreter
|
6 |
+
*
|
7 |
+
* See the licence file on
|
8 |
+
* https://github.com/slviajero/tinybasic for copyright/left.
|
9 |
+
* (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
|
10 |
+
*
|
11 |
+
* Author: Stefan Lenz, [email protected]
|
12 |
+
*
|
13 |
+
* This is the language definition file. Edit this to set the language
|
14 |
+
* capabilities.
|
15 |
+
*
|
16 |
+
* MEMSIZE was moved to hardware.h now as it is a hardware setting.
|
17 |
+
*
|
18 |
+
*/
|
19 |
+
|
20 |
+
/*
|
21 |
+
* DEBUG switches on compiled debug mode. Consider using runtime
|
22 |
+
* debug with SET 0,x before using this.
|
23 |
+
*/
|
24 |
+
#define DEBUG 0
|
25 |
+
|
26 |
+
/*
|
27 |
+
* Interpreter feature sets, choose one of the predefines or undefine all predefines and set the
|
28 |
+
* features in custom settings
|
29 |
+
*
|
30 |
+
* BASICFULL: full language set, use this with flash >32kB - ESPs, MKRs, Mega2560, RP2040, UNO R4
|
31 |
+
* BASICINTEGER: integer BASIC with full language, use this with flash >32kB
|
32 |
+
* BASICSIMPLE: integer BASIC with reduced language set, 32kB capable - for UNOs with a lot of device drivers
|
33 |
+
* BASICSIMPLEWITHFLOAT: a small floating point BASIC, 32kB capable, for UNOs - good for UNOs with the need of float
|
34 |
+
* BASICTINYWITHFLOAT: a floating point tinybasic, if you have 32kB and need complex device drivers
|
35 |
+
* BASICMINIMAL: minimal language, just Palo Alto plus Arduino I/O, works on 168 with 1kB RAM and 16kB flash
|
36 |
+
*
|
37 |
+
* The board will try to find the best language model for it's size and capabilities. Relies on the
|
38 |
+
* information hardware.h produces. It set one of the language models:
|
39 |
+
*
|
40 |
+
* BASICFULL, BASICSIMPLE, BASICMINIMAL.
|
41 |
+
*
|
42 |
+
* Setting NOLANGUAGEHEURISTICS and then one of the models below will override this
|
43 |
+
* selection.
|
44 |
+
*/
|
45 |
+
#define LANGUAGEHEURISTICS
|
46 |
+
|
47 |
+
#ifndef LANGUAGEHEURISTICS
|
48 |
+
#undef BASICFULL
|
49 |
+
#undef BASICINTEGER
|
50 |
+
#undef BASICSIMPLE
|
51 |
+
#undef BASICMINIMAL
|
52 |
+
#undef BASICPALOALTO
|
53 |
+
#undef BASICSIMPLEWITHFLOAT
|
54 |
+
#undef BASICTINYWITHFLOAT
|
55 |
+
#endif
|
56 |
+
|
57 |
+
/*
|
58 |
+
* Custom settings undef all the the language sets above when you are using this. Not all language
|
59 |
+
* features work in all combinations.
|
60 |
+
*
|
61 |
+
* HASAPPLE1: Apple 1 BASIC compatibility. This is the base for all other features.
|
62 |
+
* In this version the interpreter has a heap, a string pool and one dimensional arrays.
|
63 |
+
* HASARDUINOIO: Arduino I/O functions, including millis() timer.
|
64 |
+
* HASFILEIO: file I/O functions, including open, close, read, write, remove, rename.
|
65 |
+
* HASTONE: tone() and noTone() functions for sound output mapped to the PLAY command.
|
66 |
+
* HASPULSE: pulseIn() function for measuring pulse lengths. Pulse output. Both mapped to the PULSE command.
|
67 |
+
* HASSTEFANSEXT: Stefan's BASIC extensions, including ELSE, PUT, GET, advanced FOR loops, SQR and POW.
|
68 |
+
* HASERRORMSG: error messages for syntax and runtime errors.
|
69 |
+
* HASVT52: VT52 terminal emulation for text output -> moved to hardware.h
|
70 |
+
* HASFLOAT: floating point support.
|
71 |
+
* HASGRAPH: graphics support, including line, circle, rectangle, fill, color.
|
72 |
+
* HASDARTMOUTH: Dartmouth BASIC compatibility: single line DEF FN, ON, READ, DATA.
|
73 |
+
* HASDARKARTS: Dark Arts BASIC is MALLOC, FIND, CLR for individual variables and EVAL for self modifying code.
|
74 |
+
* HASIOT: IoT functions, Wire access, Sensor functions, MQTT. Needs strings and heap. STR, VAL, INSTR are
|
75 |
+
* part of this. MQTT support only on Arduino-
|
76 |
+
* HASMULTIDIM: two dimensional arrays and one dimensional string arrays.
|
77 |
+
* HASTIMER: timer functions, AFTER and EVERY for periodic execution of programs.
|
78 |
+
* HASEVENTS: event handling, EVENT command.
|
79 |
+
* HASERRORHANDLING: error handling with ERROR GOTO.
|
80 |
+
* HASSTRUCT: structured language elements, WHILE WEND, REPEAT UNTIL, SWITCH CASE. Multi line IF THEN ELSE
|
81 |
+
* with the DO DEND construct.
|
82 |
+
* HASMSSTRINGS: MS Basic compatible strings, RIGHT$, LEFT$, MID$, ASC, CHR$, and string addition with +.
|
83 |
+
* Compatibility to MS BASICs is limited as this BASIC has only inplace string operations-
|
84 |
+
* HASMULTILINEFUNCTIONS: multi line functions, DEF FN, FEND.
|
85 |
+
* HASEDITOR: line editor for the console.
|
86 |
+
* HASTINYBASICINPUT: Tiny BASIC compatible input using the expression parser. Expressions and variables
|
87 |
+
* are valid number input with it. Default now but can have odd side effects.
|
88 |
+
* HASLONGNAMES: long variable names, up to 16 characters. Name length is set by MAXNAME in basic.h and
|
89 |
+
* can be any value <128 bytes. Names are still only uppercase and all names will be uppercased by lexer.
|
90 |
+
* HASHELP: show the commands of the interpreter. Will be extended to a help system.
|
91 |
+
* HASFULLINSTR: the full C64 style INSTR command. Without this flag INSTR only accepts
|
92 |
+
* a single character as argument. This is much faster and leaner on an Arduino.
|
93 |
+
* This macro is activated when HASMSSTRINGS is set.
|
94 |
+
* HASLOOPOPT: optimizes the FOR loops for speed. This is a trade off between speed and
|
95 |
+
* memory. It is activated by default. Speeup is about 10% on a Mac. On platforms
|
96 |
+
* with low memory bandwidth it is much more.
|
97 |
+
* HASNUMSYSTEM: constants can be hex, octal, binary or decimal. This is not activated by
|
98 |
+
* default. Currently only implemented in VAL() and STR().
|
99 |
+
* HASBITWISE: has bitwise operations >>, << and the function BIT -> removed and default now.
|
100 |
+
*
|
101 |
+
* If you want to set everything manually, set NOLANGUAGEHEURISTICS above
|
102 |
+
*/
|
103 |
+
|
104 |
+
#ifndef LANGUAGEHEURISTICS
|
105 |
+
#define HASAPPLE1
|
106 |
+
#define HASARDUINOIO
|
107 |
+
#define HASFILEIO
|
108 |
+
#define HASTONE
|
109 |
+
#define HASPULSE
|
110 |
+
#define HASSTEFANSEXT
|
111 |
+
#define HASERRORMSG
|
112 |
+
#define HASFLOAT
|
113 |
+
#define HASGRAPH
|
114 |
+
#define HASDARTMOUTH
|
115 |
+
#define HASDARKARTS
|
116 |
+
#define HASIOT
|
117 |
+
#define HASMULTIDIM
|
118 |
+
#define HASTIMER
|
119 |
+
#define HASEVENTS
|
120 |
+
#define HASERRORHANDLING
|
121 |
+
#define HASSTRUCT
|
122 |
+
#define HASMSSTRINGS
|
123 |
+
#define HASMULTILINEFUNCTIONS
|
124 |
+
#define HASEDITOR
|
125 |
+
#define HASTINYBASICINPUT
|
126 |
+
#define HASLONGNAMES
|
127 |
+
#define HASHELP
|
128 |
+
#define HASFULLINSTR
|
129 |
+
#define HASLOOPOPT
|
130 |
+
#define HASNUMSYSTEM
|
131 |
+
#endif
|
132 |
+
|
133 |
+
|
134 |
+
/*
|
135 |
+
*
|
136 |
+
* Odd stuff - these things change the behaviour of BASIC in some aspects.
|
137 |
+
* They can be used to make the interpreter compatible with other dialects.
|
138 |
+
*
|
139 |
+
* POWERRIGHTTOLEFT: normally the ^ operator works from left to right
|
140 |
+
* which means 2^3^2 = (2^3)^2 = 8^2 = 64. Setting this flag would
|
141 |
+
* change the behaviour to 2^3^2 = 2^(3^2) = 512
|
142 |
+
* MSARRAYLIMITS: in BASIC arrays start at 1 and DIM A(10) creates 10
|
143 |
+
* elements. With MSARRAYLIMITS defined, arrays start at 0 and have
|
144 |
+
* n+1 elements. This can be changed at any time with SET 21,0 or 1.
|
145 |
+
* SUPPRESSSUBSTRINGS: switch off substring logic by default, makes only sense with
|
146 |
+
* HASMSSTRINGS activated. With this, the syntax of strings and string
|
147 |
+
* arrays is comaptible to MS strings (only used to preset the variable now).
|
148 |
+
* SET 20 can change this at runtime.
|
149 |
+
* USELONGJUMP: use the longjmp feature of C. This greatly simplifies
|
150 |
+
* error handling at the cost of portability to some MCU platforms
|
151 |
+
* currently only experimental. It costs memory for the jump buffer.
|
152 |
+
* Don't use it on very small systems. LONGJUMP must be set to 0 or 1 as
|
153 |
+
* it is used in boolean expression in the code
|
154 |
+
* BOOLEANMODE: switch the behaviour of BASICs boolean operators. Default (-1)
|
155 |
+
* is to cast all numbers to signed 16bit and then do bitwise arithemtic.
|
156 |
+
* In this mode false is 0 and -1 is true. (1) is C style boolean arithemtic.
|
157 |
+
* In this mode true is 1 and false is 0. AND and OR still do bitwise operations
|
158 |
+
* but NOT is C not. SET 19,1 or -1 can change this at runtime.
|
159 |
+
* HAS64BIT: 64 bit floating point support on platforms that have a 64 bit double.
|
160 |
+
* Counterexample: AVR 8bit does not have 64 bit floating point.
|
161 |
+
* HAS32BITINT: 32 bit integer support on 8 bit platforms.
|
162 |
+
* HASPOWER: the POWER operator ^ is available in addition to the POW function.
|
163 |
+
* HASUSRCALL: the USR and CALL functions. On small systems they need a lot
|
164 |
+
* of flash and can be disabled.
|
165 |
+
*/
|
166 |
+
|
167 |
+
#undef POWERRIGHTTOLEFT
|
168 |
+
#undef MSARRAYLIMITS
|
169 |
+
#undef SUPPRESSSUBSTRINGS
|
170 |
+
#define USELONGJUMP 0
|
171 |
+
#define BOOLEANMODE -1
|
172 |
+
#undef HAS64BIT
|
173 |
+
#undef HAS32BITINT
|
174 |
+
#define HASPOWER
|
175 |
+
#define HASUSRCALL
|
176 |
+
|
177 |
+
/* Palo Alto plus Arduino functions */
|
178 |
+
#ifdef BASICMINIMAL
|
179 |
+
#undef HASAPPLE1
|
180 |
+
#define HASARDUINOIO
|
181 |
+
#undef HASFILEIO
|
182 |
+
#undef HASTONE
|
183 |
+
#undef HASPULSE
|
184 |
+
#undef HASSTEFANSEXT
|
185 |
+
#undef HASERRORMSG
|
186 |
+
#undef HASFLOAT
|
187 |
+
#undef HASGRAPH
|
188 |
+
#undef HASDARTMOUTH
|
189 |
+
#undef HASDARKARTS
|
190 |
+
#undef HASIOT
|
191 |
+
#undef HASMULTIDIM
|
192 |
+
#undef HASTIMER
|
193 |
+
#undef HASEVENTS
|
194 |
+
#undef HASERRORHANDLING
|
195 |
+
#undef HASSTRUCT
|
196 |
+
#undef HASMSSTRINGS
|
197 |
+
#undef HASMULTILINEFUNCTIONS
|
198 |
+
#undef HASEDITOR
|
199 |
+
#define HASTINYBASICINPUT
|
200 |
+
#undef HASLONGNAMES
|
201 |
+
#undef HASHELP
|
202 |
+
#undef HASFULLINSTR
|
203 |
+
#undef HASLOOPOPT
|
204 |
+
#undef HASNUMSYSTEM
|
205 |
+
#undef HASPOWER
|
206 |
+
#undef HASUSRCALL
|
207 |
+
#endif
|
208 |
+
|
209 |
+
/* the original Palo Alto Tinybasic, this is the real minimum */
|
210 |
+
#ifdef BASICPALOALTO
|
211 |
+
#undef HASAPPLE1
|
212 |
+
#undef HASARDUINOIO
|
213 |
+
#undef HASFILEIO
|
214 |
+
#undef HASTONE
|
215 |
+
#undef HASPULSE
|
216 |
+
#undef HASSTEFANSEXT
|
217 |
+
#undef HASERRORMSG
|
218 |
+
#undef HASFLOAT
|
219 |
+
#undef HASGRAPH
|
220 |
+
#undef HASDARTMOUTH
|
221 |
+
#undef HASDARKARTS
|
222 |
+
#undef HASIOT
|
223 |
+
#undef HASMULTIDIM
|
224 |
+
#undef HASTIMER
|
225 |
+
#undef HASEVENTS
|
226 |
+
#undef HASERRORHANDLING
|
227 |
+
#undef HASSTRUCT
|
228 |
+
#undef HASMSSTRINGS
|
229 |
+
#undef HASMULTILINEFUNCTIONS
|
230 |
+
#undef HASEDITOR
|
231 |
+
#define HASTINYBASICINPUT
|
232 |
+
#undef HASLONGNAMES
|
233 |
+
#undef HASHELP
|
234 |
+
#undef HASLOOPOPT
|
235 |
+
#undef HASNUMSYSTEM
|
236 |
+
#undef HASBITWISE
|
237 |
+
#undef HASFULLINSTR
|
238 |
+
#undef HASLOOPOPT
|
239 |
+
#undef HASNUMSYSTEM
|
240 |
+
#undef HASPOWER
|
241 |
+
#undef HASUSRCALL
|
242 |
+
#endif
|
243 |
+
|
244 |
+
/* all features minus float and tone */
|
245 |
+
#ifdef BASICINTEGER
|
246 |
+
#define HASAPPLE1
|
247 |
+
#define HASARDUINOIO
|
248 |
+
#define HASFILEIO
|
249 |
+
#define HASTONE
|
250 |
+
#define HASPULSE
|
251 |
+
#define HASSTEFANSEXT
|
252 |
+
#define HASERRORMSG
|
253 |
+
#undef HASFLOAT
|
254 |
+
#define HASGRAPH
|
255 |
+
#define HASDARTMOUTH
|
256 |
+
#define HASDARKARTS
|
257 |
+
#define HASIOT
|
258 |
+
#define HASMULTIDIM
|
259 |
+
#define HASTIMER
|
260 |
+
#define HASEVENTS
|
261 |
+
#define HASERRORHANDLING
|
262 |
+
#define HASSTRUCT
|
263 |
+
#define HASMSSTRINGS
|
264 |
+
#define HASMULTILINEFUNCTIONS
|
265 |
+
#define HASEDITOR
|
266 |
+
#define HASTINYBASICINPUT
|
267 |
+
#define HASLONGNAMES
|
268 |
+
#define HASHELP
|
269 |
+
#define HASFULLINSTR
|
270 |
+
#define HASLOOPOPT
|
271 |
+
#define HASNUMSYSTEM
|
272 |
+
#endif
|
273 |
+
|
274 |
+
/* a simple integer basic for small systems mainly the UNO */
|
275 |
+
#ifdef BASICSIMPLE
|
276 |
+
#define HASAPPLE1
|
277 |
+
#define HASARDUINOIO
|
278 |
+
#define HASFILEIO
|
279 |
+
#define HASTONE
|
280 |
+
#define HASPULSE
|
281 |
+
#define HASSTEFANSEXT
|
282 |
+
#define HASERRORMSG
|
283 |
+
#undef HASFLOAT
|
284 |
+
#undef HASGRAPH
|
285 |
+
#define HASDARTMOUTH
|
286 |
+
#undef HASDARKARTS
|
287 |
+
#define HASIOT
|
288 |
+
#undef HASMULTIDIM
|
289 |
+
#define HASTIMER
|
290 |
+
#define HASEVENTS
|
291 |
+
#define HASERRORHANDLING
|
292 |
+
#undef HASSTRUCT
|
293 |
+
#undef HASMSSTRINGS
|
294 |
+
#undef HASMULTILINEFUNCTIONS
|
295 |
+
#undef HASEDITOR
|
296 |
+
#define HASTINYBASICINPUT
|
297 |
+
#undef HASLONGNAMES
|
298 |
+
#undef HASHELP
|
299 |
+
#undef HASFULLINSTR
|
300 |
+
#undef HASLOOPOPT
|
301 |
+
#undef HASNUMSYSTEM
|
302 |
+
#undef HASPOWER
|
303 |
+
#undef HASUSRCALL
|
304 |
+
#endif
|
305 |
+
|
306 |
+
/* a small integer BASIC for 32kB systems with big cores */
|
307 |
+
#ifdef BASICSMALL
|
308 |
+
#define HASAPPLE1
|
309 |
+
#define HASARDUINOIO
|
310 |
+
#undef HASFILEIO
|
311 |
+
#undef HASTONE
|
312 |
+
#undef HASPULSE
|
313 |
+
#define HASSTEFANSEXT
|
314 |
+
#define HASERRORMSG
|
315 |
+
#undef HASFLOAT
|
316 |
+
#undef HASGRAPH
|
317 |
+
#undef HASDARTMOUTH
|
318 |
+
#undef HASDARKARTS
|
319 |
+
#define HASIOT
|
320 |
+
#undef HASMULTIDIM
|
321 |
+
#define HASTIMER
|
322 |
+
#define HASEVENTS
|
323 |
+
#define HASERRORHANDLING
|
324 |
+
#undef HASSTRUCT
|
325 |
+
#undef HASMSSTRINGS
|
326 |
+
#undef HASMULTILINEFUNCTIONS
|
327 |
+
#undef HASEDITOR
|
328 |
+
#define HASTINYBASICINPUT
|
329 |
+
#undef HASLONGNAMES
|
330 |
+
#undef HASHELP
|
331 |
+
#undef HASFULLINSTR
|
332 |
+
#undef HASLOOPOPT
|
333 |
+
#undef HASNUMSYSTEM
|
334 |
+
#undef HASPOWER
|
335 |
+
#undef HASUSRCALL
|
336 |
+
#endif
|
337 |
+
|
338 |
+
|
339 |
+
/* all features activated */
|
340 |
+
#ifdef BASICFULL
|
341 |
+
#define HASAPPLE1
|
342 |
+
#define HASARDUINOIO
|
343 |
+
#define HASFILEIO
|
344 |
+
#define HASTONE
|
345 |
+
#define HASPULSE
|
346 |
+
#define HASSTEFANSEXT
|
347 |
+
#define HASERRORMSG
|
348 |
+
#define HASFLOAT
|
349 |
+
#define HASGRAPH
|
350 |
+
#define HASDARTMOUTH
|
351 |
+
#define HASDARKARTS
|
352 |
+
#define HASIOT
|
353 |
+
#define HASMULTIDIM
|
354 |
+
#define HASTIMER
|
355 |
+
#define HASEVENTS
|
356 |
+
#define HASERRORHANDLING
|
357 |
+
#define HASSTRUCT
|
358 |
+
#define HASMSSTRINGS
|
359 |
+
#define HASMULTILINEFUNCTIONS
|
360 |
+
#define HASEDITOR
|
361 |
+
#define HASTINYBASICINPUT
|
362 |
+
#define HASLONGNAMES
|
363 |
+
#define HASHELP
|
364 |
+
#define HASFULLINSTR
|
365 |
+
#define HASLOOPOPT
|
366 |
+
#define HASNUMSYSTEM
|
367 |
+
#endif
|
368 |
+
|
369 |
+
/* a simple BASIC with float support */
|
370 |
+
#ifdef BASICSIMPLEWITHFLOAT
|
371 |
+
#define HASAPPLE1
|
372 |
+
#define HASARDUINOIO
|
373 |
+
#undef HASFILEIO
|
374 |
+
#undef HASTONE
|
375 |
+
#undef HASPULSE
|
376 |
+
#define HASSTEFANSEXT
|
377 |
+
#define HASERRORMSG
|
378 |
+
#define HASFLOAT
|
379 |
+
#undef HASGRAPH
|
380 |
+
#define HASDARTMOUTH
|
381 |
+
#undef HASDARKARTS
|
382 |
+
#undef HASIOT
|
383 |
+
#undef HASMULTIDIM
|
384 |
+
#undef HASTIMER
|
385 |
+
#undef HASEVENTS
|
386 |
+
#undef HASERRORHANDLING
|
387 |
+
#undef HASSTRUCT
|
388 |
+
#undef HASMSSTRINGS
|
389 |
+
#undef HASMULTILINEFUNCTIONS
|
390 |
+
#undef HASEDITOR
|
391 |
+
#define HASTINYBASICINPUT
|
392 |
+
#undef HASLONGNAMES
|
393 |
+
#undef HASHELP
|
394 |
+
#undef HASFULLINSTR
|
395 |
+
#undef HASLOOPOPT
|
396 |
+
#undef HASNUMSYSTEM
|
397 |
+
#undef HASPOWER
|
398 |
+
#undef HASUSRCALL
|
399 |
+
#endif
|
400 |
+
|
401 |
+
/* a Tinybasic with float support */
|
402 |
+
#ifdef BASICTINYWITHFLOAT
|
403 |
+
#define HASAPPLE1
|
404 |
+
#define HASARDUINOIO
|
405 |
+
#undef HASFILEIO
|
406 |
+
#undef HASTONE
|
407 |
+
#undef HASPULSE
|
408 |
+
#define HASSTEFANSEXT
|
409 |
+
#define HASERRORMSG
|
410 |
+
#define HASFLOAT
|
411 |
+
#undef HASGRAPH
|
412 |
+
#undef HASDARTMOUTH
|
413 |
+
#undef HASDARKARTS
|
414 |
+
#undef HASIOT
|
415 |
+
#undef HASMULTIDIM
|
416 |
+
#undef HASTIMER
|
417 |
+
#undef HASEVENTS
|
418 |
+
#undef HASERRORHANDLING
|
419 |
+
#undef HASSTRUCT
|
420 |
+
#undef HASMSSTRINGS
|
421 |
+
#undef HASMULTILINEFUNCTIONS
|
422 |
+
#undef HASEDITOR
|
423 |
+
#define HASTINYBASICINPUT
|
424 |
+
#undef HASLONGNAMES
|
425 |
+
#undef HASHELP
|
426 |
+
#undef HASFULLINSTR
|
427 |
+
#undef HASLOOPOPT
|
428 |
+
#undef HASNUMSYSTEM
|
429 |
+
#undef HASPOWER
|
430 |
+
#undef HASUSRCALL
|
431 |
+
#endif
|
432 |
+
|
433 |
+
/*
|
434 |
+
* Language feature dependencies
|
435 |
+
*
|
436 |
+
* Dartmouth and darkarts needs the heap which is in Apple 1
|
437 |
+
* IoT needs strings and the heap, also Apple 1
|
438 |
+
*
|
439 |
+
* String arrays need multi dimensional capabilities
|
440 |
+
*
|
441 |
+
* The structured language set needs ELSE from STEFANSEXT
|
442 |
+
*
|
443 |
+
*/
|
444 |
+
#if defined(HASMULTILINEFUNCTIONS)
|
445 |
+
#define HASDARTMOUTH
|
446 |
+
#endif
|
447 |
+
|
448 |
+
#if defined(HASDARTMOUTH) || defined(HASDARKARTS) || defined(HASIOT) || defined(HASMSSTRINGS)
|
449 |
+
#define HASAPPLE1
|
450 |
+
#endif
|
451 |
+
|
452 |
+
#if defined(HASSTRUCT)
|
453 |
+
#define HASSTEFANSEXT
|
454 |
+
#endif
|
455 |
+
|
456 |
+
/* MS strings also bring the full INSTR */
|
457 |
+
#if defined(HASMSSTRINGS)
|
458 |
+
#define HASFULLINSTR
|
459 |
+
#endif
|
460 |
+
|
461 |
+
/* dependencies on the hardware */
|
462 |
+
#if !defined(DISPLAYHASGRAPH)
|
463 |
+
#undef HASGRAPH
|
464 |
+
#endif
|
data/Basic2/IoTBasic/runtime.cpp
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/Basic2/IoTBasic/runtime.h
ADDED
@@ -0,0 +1,1205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Stefan's basic interpreter.
|
3 |
+
*
|
4 |
+
* Prototypes for the runtime environment of the BASIC interpreter.
|
5 |
+
*
|
6 |
+
* Needs to be included by runtime.c or runtime.cpp and basic.c as
|
7 |
+
* it describes the interface between the BASIC interpreter and the
|
8 |
+
* runtime environment.
|
9 |
+
*
|
10 |
+
* Most configurable parameters are in hardware.h.
|
11 |
+
*
|
12 |
+
* Author: Stefan Lenz, [email protected]
|
13 |
+
*
|
14 |
+
*/
|
15 |
+
|
16 |
+
#if !defined(__RUNTIMEH__)
|
17 |
+
#define __RUNTIMEH__
|
18 |
+
|
19 |
+
/*
|
20 |
+
* The system type identifiers
|
21 |
+
*
|
22 |
+
* SYSTYPE_UNKNOWN: unknown system, typically an unknown Arduino
|
23 |
+
* SYSTYPE_AVR: an AVR based Arduino, like the UNO, NANO, MEGA, PRO
|
24 |
+
* SYSTYPE_ESP8266: an ESP8266 based Arduino, like the Wemos D1, very common and generic
|
25 |
+
* SYSTYPE_ESP32: an ESP32 based Arduino, like the Wemos Lolin32, very common and generic
|
26 |
+
* SYSTYPE_RP2040: a Raspberry PI Pico, the first RP2040 based Arduino
|
27 |
+
* SYSTYPE_SAM: a SAM based Arduino, like the DUE
|
28 |
+
* SYSTYPE_XMC: an XMC based Arduino, like the Infineon XMC1100
|
29 |
+
* SYSTYPE_SMT32: an STM32 based Arduino, like the Blue Pill
|
30 |
+
* SYSTYPE_NRENESA: a Renesas based Arduino, like the R4 Wifi and Minimal
|
31 |
+
* SYSTYPE_GIGA: Arduino GIGA board
|
32 |
+
* SYSTYPE_POSIX: a POSIX system, like Linux, MacOS
|
33 |
+
* SYSTYPE_MSDOS: a DOS system, like FreeDOS
|
34 |
+
* SYSTYPE_MINGW: a Windows system with MinGW
|
35 |
+
* SYSTYPE_RASPPI: a Raspberry PI system
|
36 |
+
*
|
37 |
+
* Number ranges from 0-31 are reserved for Arduino systems
|
38 |
+
* Number ranges from 32-63 are reserved for POSIX systems
|
39 |
+
*/
|
40 |
+
|
41 |
+
#define SYSTYPE_UNKNOWN 0
|
42 |
+
#define SYSTYPE_AVR 1
|
43 |
+
#define SYSTYPE_ESP8266 2
|
44 |
+
#define SYSTYPE_ESP32 3
|
45 |
+
#define SYSTYPE_RP2040 4
|
46 |
+
#define SYSTYPE_SAM 5
|
47 |
+
#define SYSTYPE_XMC 6
|
48 |
+
#define SYSTYPE_SMT32 7
|
49 |
+
#define SYSTYPE_NRENESA 8
|
50 |
+
#define SYSTYPE_GIGA 9
|
51 |
+
#define SYSTYPE_POSIX 32
|
52 |
+
#define SYSTYPE_MSDOS 33
|
53 |
+
#define SYSTYPE_MINGW 34
|
54 |
+
#define SYSTYPE_RASPPI 35
|
55 |
+
|
56 |
+
/*
|
57 |
+
* Input and output channels.
|
58 |
+
*
|
59 |
+
* The channels are used to identify the I/O devices in the
|
60 |
+
* runtime environment.
|
61 |
+
*
|
62 |
+
* NULL is the memory channel outputting to a buffer.
|
63 |
+
* SERIAL is the standard serial channel and the default device.
|
64 |
+
* DSP is the display channel.
|
65 |
+
* GRAPH is the additional graphics display channel.
|
66 |
+
* PRT is the second serial channel used for printing and communication
|
67 |
+
* with external devices.
|
68 |
+
* WIRE is the I2C channel.
|
69 |
+
* RADIO is the RF24 channel.
|
70 |
+
* MQTT is the MQTT channel.
|
71 |
+
* FILE is the file system channel.
|
72 |
+
*/
|
73 |
+
|
74 |
+
#define ONULL 0
|
75 |
+
#define OSERIAL 1
|
76 |
+
#define ODSP 2
|
77 |
+
#define OGRAPH 3
|
78 |
+
#define OPRT 4
|
79 |
+
#define OWIRE 7
|
80 |
+
#define ORADIO 8
|
81 |
+
#define OMQTT 9
|
82 |
+
#define OFILE 16
|
83 |
+
|
84 |
+
#define INULL 0
|
85 |
+
#define ISERIAL 1
|
86 |
+
#define IKEYBOARD 2
|
87 |
+
#define IGRAPH 3
|
88 |
+
#define ISERIAL1 4
|
89 |
+
#define IWIRE 7
|
90 |
+
#define IRADIO 8
|
91 |
+
#define IMQTT 9
|
92 |
+
#define IFILE 16
|
93 |
+
|
94 |
+
/*
|
95 |
+
* Global variables of the runtime env, visible to BASIC.
|
96 |
+
* These are the variables that BASIC provides to the runtime
|
97 |
+
* environment. They are used all over the BASIC code. Some
|
98 |
+
* could be encapsulated as function calls calls.
|
99 |
+
*
|
100 |
+
* Variables to control the io device channels.
|
101 |
+
*
|
102 |
+
* id: the current input device
|
103 |
+
* od: the current output device
|
104 |
+
* idd: the default input device in interactive mode
|
105 |
+
* odd: the default output device in interactive mode
|
106 |
+
* ioer: the io error
|
107 |
+
*/
|
108 |
+
extern int8_t id;
|
109 |
+
extern int8_t od;
|
110 |
+
extern int8_t idd;
|
111 |
+
extern int8_t odd;
|
112 |
+
extern int8_t ioer;
|
113 |
+
|
114 |
+
/*
|
115 |
+
* Io control flags.
|
116 |
+
*
|
117 |
+
* These flags are used to control the I/O devices.
|
118 |
+
* kbdrepeat: the keyboard repeat flag for the keypad of a shield
|
119 |
+
* only used by SET and defined in the keypad code
|
120 |
+
* blockmode: the blockmode flag, switch a channel to blockmode
|
121 |
+
* sendcr: the sendcr flag, send a carriage return after a newline if true
|
122 |
+
*/
|
123 |
+
|
124 |
+
extern uint8_t kbdrepeat;
|
125 |
+
extern uint8_t blockmode;
|
126 |
+
extern uint8_t sendcr;
|
127 |
+
|
128 |
+
/* breaks, signaly back that the breakcondition has been detected */
|
129 |
+
extern char breakcondition;
|
130 |
+
|
131 |
+
/* counts the outputed characters on streams 0-4, used to emulate a real tab */
|
132 |
+
extern uint8_t charcount[5]; /* devices 0-4 support tabing */
|
133 |
+
|
134 |
+
/* the memory buffer comes from BASIC in this version, it is the input buffer for lines */
|
135 |
+
extern char ibuffer[BUFSIZE];
|
136 |
+
|
137 |
+
/* only needed in POSIX worlds */
|
138 |
+
extern uint8_t breaksignal;
|
139 |
+
extern uint8_t vt52active;
|
140 |
+
|
141 |
+
/* the string buffer the interpreter needs, here to be known by BASIC */
|
142 |
+
extern char spistrbuf1[SPIRAMSBSIZE], spistrbuf2[SPIRAMSBSIZE];
|
143 |
+
|
144 |
+
/*
|
145 |
+
* the mqtt variable the interpreter needs.
|
146 |
+
* The following parameters are configured here:
|
147 |
+
*
|
148 |
+
* MQTTLENGTH: the length of the mqtt topic, restricted to 32 by default.
|
149 |
+
* MQTTBLENGTH: the length of the mqtt buffer, 128 by default.
|
150 |
+
* MQTTNAMELENGTH: the length of the autogenerated mqtt name, 12 by default.
|
151 |
+
* The mqtt name is used to identify the device in the mqtt network.
|
152 |
+
*
|
153 |
+
* mqtt_otopic: the outgoing topic
|
154 |
+
* mqtt_itopic: the incoming topic
|
155 |
+
* mqttname: the name of the device in the mqtt network
|
156 |
+
*/
|
157 |
+
|
158 |
+
#define MQTTLENGTH 32
|
159 |
+
#define MQTTBLENGTH 128
|
160 |
+
#define MQTTNAMELENGTH 12
|
161 |
+
|
162 |
+
extern char mqtt_otopic[MQTTLENGTH];
|
163 |
+
extern char mqtt_itopic[MQTTLENGTH];
|
164 |
+
extern char mqttname[];
|
165 |
+
|
166 |
+
/* a byte in the runtime memory containing the system type */
|
167 |
+
extern uint8_t bsystype;
|
168 |
+
|
169 |
+
/*
|
170 |
+
* Console logger functions for the runtime code. Runtime does not know
|
171 |
+
* anything about output deviced. BASIC is to provide this. This
|
172 |
+
* is used for debugging and logging.
|
173 |
+
*/
|
174 |
+
|
175 |
+
extern void consolelog(char*);
|
176 |
+
extern void consolelognum(int);
|
177 |
+
|
178 |
+
/*
|
179 |
+
* Statup function. They start the runtime environment.
|
180 |
+
*
|
181 |
+
* The functions timeinit(), wiringbegin(), signalon()
|
182 |
+
* are always empty on Arduino, they are only used in
|
183 |
+
* the POSIX branch of the code.
|
184 |
+
*
|
185 |
+
* timeinit() initializes the time functions.
|
186 |
+
* wiringbegin() initializes the wiring functions, this is needed on
|
187 |
+
* Raspberry PI.
|
188 |
+
* signalon() initializes the signal handling, this is needed on
|
189 |
+
* Unix like systems and Windows.
|
190 |
+
*
|
191 |
+
* BASIC calls these functions once to start the timing, wiring, and
|
192 |
+
* signal handling.
|
193 |
+
*/
|
194 |
+
|
195 |
+
void timeinit();
|
196 |
+
void wiringbegin();
|
197 |
+
void signalon();
|
198 |
+
|
199 |
+
/*
|
200 |
+
* Start the SPI bus. Called once on start. Needed on Arduino.
|
201 |
+
* Empty in the POSIX branch of the code.
|
202 |
+
*
|
203 |
+
* Some libraries also try to start the SPI which may lead to on override of
|
204 |
+
* the PIN settings if the library code is not clean - currenty no conflict known.
|
205 |
+
* for the libraries used here. Old SD card libraries have problems as they always
|
206 |
+
* start the SPI bus with default settings and cannot get the settings from the
|
207 |
+
* SPI.begin() call. In these cases patching of the SD library is needed.
|
208 |
+
*/
|
209 |
+
|
210 |
+
void spibegin();
|
211 |
+
|
212 |
+
/*
|
213 |
+
* Memory allocation functions.
|
214 |
+
*
|
215 |
+
* BASIC calls freememorysize() to detemine how much memory can be allocated
|
216 |
+
* savely on the heap.
|
217 |
+
* BASIC calls restartsystem() for a complete reboot.
|
218 |
+
* freeRam() is the actual free heap. Used by freememorysize() and in USR()
|
219 |
+
*
|
220 |
+
* Arduino data from https://docs.arduino.cc/learn/programming/memory-guide
|
221 |
+
*/
|
222 |
+
|
223 |
+
long freememorysize(); /* determine how much actually to allocate */
|
224 |
+
void restartsystem(); /* cold start of the MCU */
|
225 |
+
long freeRam(); /* try to find the free heap after alocating all globals */
|
226 |
+
|
227 |
+
/* Test function for real time clock interrupt, currently not useable.
|
228 |
+
Kept for the future. */
|
229 |
+
void rtcsqw();
|
230 |
+
void aftersleepinterrupt(void);
|
231 |
+
void activatesleep(long);
|
232 |
+
|
233 |
+
/*
|
234 |
+
* The main IO interface. This is how BASIC uses I/O functions.
|
235 |
+
*
|
236 |
+
* ioinit(): called at setup to initialize what ever io is needed
|
237 |
+
* iostat(): check which io devices are available
|
238 |
+
* iodefaults(): called at setup and while changing to interactive mode
|
239 |
+
* to set the default io devices
|
240 |
+
* cheof(): checks for end of file condition on the current input stream
|
241 |
+
* inch(): gets one character from the current input stream and waits for it
|
242 |
+
* checkch(): checks for one character on the current input stream, non blocking
|
243 |
+
* availch(): checks for available characters on the current input stream
|
244 |
+
* inb(): reads a block of characters from the current input stream
|
245 |
+
* ins(): reads an entire line from the current input stream, usually by consins()
|
246 |
+
* outch(): prints one ascii character to the current output stream
|
247 |
+
* outs(): prints a string of characters to the current output stream
|
248 |
+
*/
|
249 |
+
|
250 |
+
void ioinit();
|
251 |
+
int iostat(int);
|
252 |
+
void iodefaults();
|
253 |
+
int cheof(int);
|
254 |
+
char inch();
|
255 |
+
char checkch();
|
256 |
+
uint16_t availch();
|
257 |
+
uint16_t inb(char*, int16_t);
|
258 |
+
uint16_t ins(char*, uint16_t);
|
259 |
+
void outch(char);
|
260 |
+
void outs(char*, uint16_t);
|
261 |
+
|
262 |
+
/*
|
263 |
+
* Timeing functions and background tasks.
|
264 |
+
*
|
265 |
+
* byield() must be called after every statement and in all
|
266 |
+
* waiting loops for I/O. BASIC gives back the unneeded
|
267 |
+
* CPU cycles by calling byield().
|
268 |
+
*
|
269 |
+
* byield() allows three levels of background tasks.
|
270 |
+
*
|
271 |
+
* BASICBGTASK controls if time for background tasks is
|
272 |
+
* needed, usually set by hardware features
|
273 |
+
*
|
274 |
+
* YIELDINTERVAL by default is 32, generating a 32 ms call
|
275 |
+
* to the network loop function. This is the frequency
|
276 |
+
* yieldfunction() is called.
|
277 |
+
*
|
278 |
+
* LONGYIELDINTERVAL by default is 1000, generating a one second
|
279 |
+
* call to maintenance functions. This is the frequency
|
280 |
+
* longyieldfunction() is called.
|
281 |
+
*
|
282 |
+
* fastticker() is called in every byield for fast I/O control.
|
283 |
+
* It is currently only used for the tone emulation.
|
284 |
+
*
|
285 |
+
* byield() calls back bloop() in the BASIC interpreter for user
|
286 |
+
* defined background tasks in an Arduino style loop() function.
|
287 |
+
*
|
288 |
+
* bdelay() is a delay function using byield() to allow for
|
289 |
+
* background tasks to run even when the main code does a delay.
|
290 |
+
*
|
291 |
+
* The yield mechanism is needed for ESP8266 yields, network client
|
292 |
+
* loops and other timing related functions.
|
293 |
+
*
|
294 |
+
* yieldschedule() is a function that calls the buildin scheduler
|
295 |
+
* of some platforms. Currently it is only used in ESP8266. The
|
296 |
+
* core on this boards does not tolerate that the loop() function
|
297 |
+
* does not return and crashes the system. This can be prevented
|
298 |
+
* by calling yieldschedule() often enough.
|
299 |
+
*/
|
300 |
+
|
301 |
+
#define LONGYIELDINTERVAL 1000
|
302 |
+
#define YIELDINTERVAL 32
|
303 |
+
|
304 |
+
void byield();
|
305 |
+
void bdelay(uint32_t);
|
306 |
+
void fastticker();
|
307 |
+
void yieldfunction();
|
308 |
+
void longyieldfunction();
|
309 |
+
void yieldschedule();
|
310 |
+
|
311 |
+
/*
|
312 |
+
* This function measures the fast ticker frequency in microseconds.
|
313 |
+
* This can be accessed with USR(0, 35) in BASIC.
|
314 |
+
* Activate this only for test purposes as it slows down the interpreter.
|
315 |
+
* The value is the shortest timeframe the interpreter can handle. Activated
|
316 |
+
* if the code is compiled with FASTTICKERPROFILE in hardware.h.
|
317 |
+
*/
|
318 |
+
|
319 |
+
void fasttickerprofile();
|
320 |
+
void clearfasttickerprofile();
|
321 |
+
int avgfastticker();
|
322 |
+
|
323 |
+
/*
|
324 |
+
* EEPROM handling, these function enable the @E array and
|
325 |
+
* loading and saving to EEPROM with the "!" mechanism
|
326 |
+
*
|
327 |
+
* The EEPROM code can address EEPROMS up to 64 kB. It returns
|
328 |
+
* signed byte values which corresponds to the definition of
|
329 |
+
* mem_t in BASIC. This is needed because running from EEPROM
|
330 |
+
* requires negative token values to be recongized.
|
331 |
+
*
|
332 |
+
* ebegin() starts the EEPROM code. Needed for the emulations.
|
333 |
+
* eflush() writes the EEPROM buffer to the EEPROM. Also this is
|
334 |
+
* mainly needed in the emulations.
|
335 |
+
* elength() returns the length of the EEPROM.
|
336 |
+
* eupdate() updates one EEPROM cell with a value. Does not flush.
|
337 |
+
* eread() reads one EEPROM cell.
|
338 |
+
*/
|
339 |
+
|
340 |
+
void ebegin();
|
341 |
+
void eflush();
|
342 |
+
uint16_t elength();
|
343 |
+
void eupdate(uint16_t, int8_t);
|
344 |
+
int8_t eread(uint16_t);
|
345 |
+
|
346 |
+
/*
|
347 |
+
* The wrappers of the arduino io functions.
|
348 |
+
*
|
349 |
+
* The normalize the differences of some of the Arduino cores
|
350 |
+
* and raspberyy PI wiring implementations.
|
351 |
+
*
|
352 |
+
* Pin numbers are the raw numerical pin values in BASIC.
|
353 |
+
* The functions are called with this raw pin number and the value.
|
354 |
+
*
|
355 |
+
* The functions are:
|
356 |
+
* aread(pin): read an analog value from a pin
|
357 |
+
* dread(pin): read a digital value from a pin
|
358 |
+
* awrite(pin, value): write an analog value to a pin
|
359 |
+
* dwrite(pin, value): write a digital value to a pin
|
360 |
+
* pinm(pin, mode): set the mode of a pin, mode is also the raw value from the core
|
361 |
+
* pulsein(pin, value, timeout): read a pulse from a pin, timeout in microseconds
|
362 |
+
* void pulseout(unit, pin, duration, val, repetition, interval): generate a pulse on a pin
|
363 |
+
* unit is the timeunit in microsecind and the duration is the pulse length in this unit.
|
364 |
+
* This is needed for system were the number_t is only 16 bit. This way longer pulses can
|
365 |
+
* be generated.
|
366 |
+
* void playtone(pin, frequency, duration, volume): generate a tone on a pin.
|
367 |
+
* frequency is the frequency in Hz, duration the duration in ms, volume the volume in percent.
|
368 |
+
* The tone is generated in the background, the function returns immediately.
|
369 |
+
* tonetoggle(): toggle the tone generation, needed for the tone emulation, this is called
|
370 |
+
* by byield() to generate the tone.
|
371 |
+
*/
|
372 |
+
|
373 |
+
uint16_t aread(uint8_t);
|
374 |
+
uint8_t dread(uint8_t);
|
375 |
+
void awrite(uint8_t, uint16_t);
|
376 |
+
void dwrite(uint8_t, uint8_t);
|
377 |
+
void pinm(uint8_t, uint8_t);
|
378 |
+
uint32_t pulsein(uint8_t, uint8_t, uint32_t);
|
379 |
+
void pulseout(uint16_t, uint8_t, uint16_t, uint16_t, uint16_t, uint16_t);
|
380 |
+
void playtone(uint8_t, uint16_t, uint16_t, uint8_t);
|
381 |
+
void tonetoggle(); /* internal function of the tone emulation, called by byield */
|
382 |
+
|
383 |
+
/*
|
384 |
+
* The break pin code. This is a pin that can be used to break the execution of the
|
385 |
+
* BASIC code. This is used as an alternative to the BREAK key in the terminal.
|
386 |
+
*
|
387 |
+
* brakepinbegin() initializes the break pin, usually a button connected to a pin.
|
388 |
+
* getbreakpin() returns the state of the break pin. This is called in statement() to
|
389 |
+
* check if the break condition is met and then change the interpreter state at the end
|
390 |
+
* of the statement.
|
391 |
+
*/
|
392 |
+
|
393 |
+
void breakpinbegin();
|
394 |
+
uint8_t getbreakpin();
|
395 |
+
|
396 |
+
/*
|
397 |
+
* The hardware port register access functions.
|
398 |
+
* They can be used to directly access hardware ports. Typically they
|
399 |
+
* call port macros like PORTB on the Arduino AVR platform. They are very
|
400 |
+
* fast and can be used to implement fast I/O functions but they are hardware
|
401 |
+
* dependent and not portable. Currently only AVR UNO and MEGA are implemented.
|
402 |
+
*
|
403 |
+
* The calling mechanism in BASIC is the special array @P()for read and write.
|
404 |
+
*/
|
405 |
+
|
406 |
+
void portwrite(uint8_t, int);
|
407 |
+
int portread(uint8_t);
|
408 |
+
void ddrwrite(uint8_t, int);
|
409 |
+
int ddrread(uint8_t);
|
410 |
+
int pinread(uint8_t);
|
411 |
+
|
412 |
+
/*
|
413 |
+
* Prototypes for the interrupt interface. This uses the standard Arduino
|
414 |
+
* interrupt functions.
|
415 |
+
*/
|
416 |
+
|
417 |
+
uint8_t pintointerrupt(uint8_t);
|
418 |
+
void attachinterrupt(uint8_t, void (*f)(), uint8_t);
|
419 |
+
void detachinterrupt(uint8_t);
|
420 |
+
|
421 |
+
/* some have PinStatus and some don't */
|
422 |
+
#if !(defined(ARDUINO_ARCH_MBED_RP2040) || defined(ARDUINO_ARCH_MBED_NANO) || \
|
423 |
+
defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_MBED_GIGA) || \
|
424 |
+
defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_MEGAAVR)) || defined(ARDUINO_SEEED_XIAO_M0)
|
425 |
+
typedef int PinStatus;
|
426 |
+
#endif
|
427 |
+
|
428 |
+
/*
|
429 |
+
* IO channel 0 - the buffer I/O device.
|
430 |
+
*
|
431 |
+
* This is a stream to write to the input buffer from BASIC.
|
432 |
+
*/
|
433 |
+
|
434 |
+
void bufferbegin();
|
435 |
+
uint8_t bufferstat(uint8_t);
|
436 |
+
void bufferwrite(char);
|
437 |
+
char bufferread();
|
438 |
+
char buffercheckch();
|
439 |
+
uint16_t bufferavailable();
|
440 |
+
uint16_t bufferins(char*, uint16_t);
|
441 |
+
void bufferouts(char*, uint16_t);
|
442 |
+
|
443 |
+
|
444 |
+
/*
|
445 |
+
* IO channel 1 - the serial I/O device.
|
446 |
+
*
|
447 |
+
* Primary serial code uses the Serial object or Picoserial on
|
448 |
+
* Arduino. On POSIX systems it uses the standard input/output.
|
449 |
+
*
|
450 |
+
* Functions are:
|
451 |
+
*
|
452 |
+
* serialbegin(): start the serial port
|
453 |
+
* serialread(): read a character from the serial port, this is blocking
|
454 |
+
* for the standard Serial object and non blocking for Picoserial.
|
455 |
+
* Picoserial is not character oriented. It read one entire line.
|
456 |
+
* serialstat(s): check the status of the serial port
|
457 |
+
* serialwrite(c): write a character to the serial port
|
458 |
+
* serialcheckch(): check if a character is available without blocking
|
459 |
+
* serialavailable(): check if characters are available
|
460 |
+
* serialflush(): flush the serial port
|
461 |
+
* serialins(s, l): read a line from the serial port
|
462 |
+
*/
|
463 |
+
|
464 |
+
void serialbegin();
|
465 |
+
char serialread();
|
466 |
+
uint8_t serialstat(uint8_t); /* state information on the serial port */
|
467 |
+
void serialwrite(char); /* write to a serial stream */
|
468 |
+
char serialcheckch(); /* check on a character, needed for breaking */
|
469 |
+
uint16_t serialavailable(); /* avail method, needed for AVAIL() */
|
470 |
+
void serialflush(); /* flush serial */
|
471 |
+
uint16_t serialins(char*, uint16_t); /* read a line from serial */
|
472 |
+
|
473 |
+
/*
|
474 |
+
* reading from the console with inch or the picoserial callback.
|
475 |
+
* consins() is used for all devices that have a character oriented
|
476 |
+
* input and creates entire lines from it.
|
477 |
+
*/
|
478 |
+
|
479 |
+
uint16_t consins(char *, uint16_t);
|
480 |
+
|
481 |
+
/*
|
482 |
+
* On Arduino Serial is a big object that needs a lot of memory
|
483 |
+
* on the smaller boards. Picoserial is smaller. It is mainly
|
484 |
+
* for the small 8bit AVR boards. It uses the UART macros directly.
|
485 |
+
*
|
486 |
+
* The picoseria has an own interrupt function. This is used to fill
|
487 |
+
* the input buffer directly on read. Write is standard like in
|
488 |
+
* the serial code. Currently picoserial is only implemented for
|
489 |
+
* AVR UNO, NANO and MEGA.
|
490 |
+
*
|
491 |
+
* As echoing is done in the interrupt routine, the code cannot be
|
492 |
+
* used to receive keystrokes from serial and then display the echo
|
493 |
+
* directly to a display. To do this the write command in picogetchar
|
494 |
+
* would have to be replaced with a outch() that then redirects to the
|
495 |
+
* display driver. This would be very tricky from the timing point of
|
496 |
+
* view if the display driver code is slow.
|
497 |
+
*
|
498 |
+
* The code for the UART control is mostly taken from PicoSerial
|
499 |
+
* https://github.com/gitcnd/PicoSerial, originally written by Chris Drake
|
500 |
+
* and published under GPL3.0 just like this code.
|
501 |
+
*
|
502 |
+
* Functions for the picoserial code are:
|
503 |
+
*
|
504 |
+
* picobegin(baud): start the picoserial port with the baud rate baud
|
505 |
+
* picowrite(c): write a character to the picoserial port
|
506 |
+
* picoins(s, l): read a line from the picoserial port
|
507 |
+
*
|
508 |
+
*/
|
509 |
+
|
510 |
+
void picobegin(uint32_t);
|
511 |
+
void picowrite(char);
|
512 |
+
uint16_t picoins(char *, uint16_t);
|
513 |
+
|
514 |
+
/*
|
515 |
+
* picogetchar: this is the interrupt service routine. It
|
516 |
+
* recieves a character and feeds it into a buffer and echos it
|
517 |
+
* back. The logic here is that the ins() code sets the buffer
|
518 |
+
* to the input buffer. Only then the routine starts writing to the
|
519 |
+
* buffer. Once a newline is received, the length information is set
|
520 |
+
* and picoa is also set to 1 indicating an available string, this stops
|
521 |
+
* recevieing bytes until the input is processed by the calling code.
|
522 |
+
*/
|
523 |
+
void picogetchar(char);
|
524 |
+
|
525 |
+
/*
|
526 |
+
* IO channel 2 - the display I/O device.
|
527 |
+
*
|
528 |
+
* DISPLAY driver code section. The display driver is a generic text and graphics
|
529 |
+
* output device. Characters are buffered in a display buffer if DISPLAYCANSCROLL
|
530 |
+
* is defined. These displays can scroll. Scrolling is handled by the display driver.
|
531 |
+
* It is soft scroll, meaning that the display buffer is scrolled and the display is
|
532 |
+
* updated. This is slow for large displays. Hardware scrolling is not yet implemented.
|
533 |
+
*
|
534 |
+
* The display driver is used by the terminal code to output text and
|
535 |
+
* graphics. It is needed because there is no standard terminal emulation on Arduino
|
536 |
+
* systems. It tries to be so generic that everything from small 16*2 LCDs to large
|
537 |
+
* TFT displays can be used. It contains a VT52 state engine to process control
|
538 |
+
* sequences.
|
539 |
+
*
|
540 |
+
* The hardware dependent part of the display driver has to implement the following
|
541 |
+
* functions:
|
542 |
+
*
|
543 |
+
* Text display functions:
|
544 |
+
*
|
545 |
+
* dsp_rows, dsp_columns: size of the display
|
546 |
+
* dspbegin(): start the display - can be empty
|
547 |
+
* dspprintchar(c, col, row): print a character at a given position
|
548 |
+
* logic here that col is the x coordinate and row the y coordinate
|
549 |
+
* for text and graphics the display coordinate system has its origin
|
550 |
+
* in the upper left corner
|
551 |
+
* dspclear(): clear the display
|
552 |
+
* dspupdate(): update the display, this function is needed for displays that
|
553 |
+
* have a buffer and can update the display after a series of prints.
|
554 |
+
* Examples are epaper displays and LCD displays like the Nokia. Writing
|
555 |
+
* directly to them is slow.
|
556 |
+
* dspsetcursor(c): switch the cursor on or off, typically used for text
|
557 |
+
* displays with blinking cursors.
|
558 |
+
* dspsetfgcolor(c): set the foreground color of the display.
|
559 |
+
* dspsetbgcolor(c): set the background color of the display.
|
560 |
+
* c is a VGA color. 4bit VGA colors are used for text displays.
|
561 |
+
* Graphics is 24 bit color rgb and 8 bit VGA color.
|
562 |
+
* dspsetreverse(c): set the reverse mode of the display, currently unused.
|
563 |
+
* dspident(): return the display type, currently unused.
|
564 |
+
*
|
565 |
+
* For displays with color, the macro DISPLAYHASCOLOR has to be defined.
|
566 |
+
* The text display buffer then contains one byte for the character and
|
567 |
+
* one byte for color and font.
|
568 |
+
*
|
569 |
+
* All displays which have these functions can be used with the
|
570 |
+
* generic display driver below. For minimal functionality only
|
571 |
+
* dspprintchar() and dspclear() are needed. The screen dimensions
|
572 |
+
* have to be set in dsp_rows and dsp_columns.
|
573 |
+
*
|
574 |
+
* Graphics displays need to implement the functions
|
575 |
+
*
|
576 |
+
* rgbcolor(r, g, b): set the color for graphics. The color
|
577 |
+
* is 24 bit rgb. This function needs to convert the byte
|
578 |
+
* values to the native color of the display.
|
579 |
+
* vgacolor(c): set the color for text. The color is a 256 VGA
|
580 |
+
* color for most displays. This function needs to convert this
|
581 |
+
* one byte value to the native color of the display.
|
582 |
+
* These two functions are called by the BASIC COLOR command.
|
583 |
+
*
|
584 |
+
* plot(x, y): plot a pixel at x, y
|
585 |
+
* line(x1, y1, x2, y2): draw a line from x1, y1 to x2, y2
|
586 |
+
* rect(x1, y1, x2, y2): draw a rectangle from x1, y1 to x2, y2
|
587 |
+
* frect(x1, y1, x2, y2): draw a filled rectangle from x1, y1 to x2, y2
|
588 |
+
* circle(x, y, r): draw a circle with center x, y and radius r
|
589 |
+
* fcircle(x, y, r): draw a filled circle with center x, y and radius r
|
590 |
+
*
|
591 |
+
*
|
592 |
+
* Color is currently either 24 bit or 8 bit 16 VGA color. BW and displays
|
593 |
+
* only have 0 and 1 as colors. Text is buffered in 4 bit VGA color (see below).
|
594 |
+
*/
|
595 |
+
|
596 |
+
/* Generate a 4 bit vga color from a given rgb color, to be checked */
|
597 |
+
uint8_t rgbtovga(uint8_t, uint8_t, uint8_t);
|
598 |
+
|
599 |
+
|
600 |
+
/* Text functions */
|
601 |
+
void dspbegin();
|
602 |
+
void dspprintchar(char, uint8_t, uint8_t);
|
603 |
+
void dspclear();
|
604 |
+
void dspupdate();
|
605 |
+
void dspsetcursor(uint8_t);
|
606 |
+
void dspsavepen();
|
607 |
+
void dsprestorepen();
|
608 |
+
void dspsetfgcolor(uint8_t);
|
609 |
+
void dspsetbgcolor(uint8_t);
|
610 |
+
void dspsetreverse(uint8_t);
|
611 |
+
uint8_t dspident();
|
612 |
+
|
613 |
+
/* Graphics functions */
|
614 |
+
void rgbcolor(uint8_t, uint8_t, uint8_t);
|
615 |
+
void vgacolor(uint8_t);
|
616 |
+
void plot(int, int);
|
617 |
+
void line(int, int, int, int);
|
618 |
+
void rect(int, int, int, int);
|
619 |
+
void frect(int, int, int, int);
|
620 |
+
void circle(int, int, int);
|
621 |
+
void fcircle(int, int, int);
|
622 |
+
|
623 |
+
/* to whom the bell tolls - implement this to you own liking, reacts to ASCII 7 */
|
624 |
+
void dspbell();
|
625 |
+
|
626 |
+
/*
|
627 |
+
* The public functions of the display driver are the following:
|
628 |
+
*
|
629 |
+
* dspouts(s, l): print a string of length l to the display. This
|
630 |
+
* function is only used for output on certain graphics displays
|
631 |
+
* These displays expect an entire string to be printed at once.
|
632 |
+
* Currently this is only implemented for epaper displays.
|
633 |
+
* dspwrite(c): print a character to the display. This function is
|
634 |
+
* the main output method for text displays. It prints a character
|
635 |
+
* at the current cursor position and updates the cursor position.
|
636 |
+
* For vt52 capable displays, the character goes through the vt52
|
637 |
+
* state engine and it processed there.
|
638 |
+
* dspstat(s): check the status of the display. It returns 1 if the
|
639 |
+
* display is present and 0 if it is not.
|
640 |
+
* dspactive(): check if the display is the current output device.
|
641 |
+
* This function is used to control scrolling in the LIST command.
|
642 |
+
* dspwaitonscroll(): this function waits for character input if the
|
643 |
+
* display wants to scroll. This is used in the LIST command to
|
644 |
+
* wait for a keypress before scrolling the display. It returns the
|
645 |
+
* character that was pressed. This can also be used to end the output
|
646 |
+
* of the LIST command.
|
647 |
+
* dspsetupdatemode(m): set the update mode of the display. Valid update
|
648 |
+
* modes are 0, 1, 2. 0 is character mode, 1 is line mode, 2 is page mode.
|
649 |
+
* In character mode, the display is updated after every character. In line
|
650 |
+
* mode, the display is updated after every line. In page mode, the display
|
651 |
+
* is updated after an ETX character. This function is only used for displays
|
652 |
+
* that implement the dspupdate() function.
|
653 |
+
* dspgetupdatemode(): get the current update mode of the display.
|
654 |
+
* dspgraphupdate(): update the display after a series of graphics commands. While
|
655 |
+
* dspsetupdatemode() and dspgetupdatemode() control the update from the text buffer,
|
656 |
+
* dspgraphupdate() controls the update from the graphics buffer. See for example
|
657 |
+
* the Nokia display as an example. This function must be called after graphics
|
658 |
+
* operations to update the display. Typically this is done in the graphics functions
|
659 |
+
* like line(), rect(), circle(), etc.
|
660 |
+
* dspsetcursorx(x): set the x coordinate of the cursor
|
661 |
+
* dspsetcursory(y): set the y coordinate of the cursor
|
662 |
+
* dspgetcursorx(): get the x coordinate of the cursor
|
663 |
+
* dspgetcursory(): get the y coordinate of the cursor
|
664 |
+
*/
|
665 |
+
|
666 |
+
void dspouts(char*, uint16_t);
|
667 |
+
void dspwrite(char);
|
668 |
+
uint8_t dspstat(uint8_t);
|
669 |
+
uint8_t dspactive();
|
670 |
+
char dspwaitonscroll();
|
671 |
+
void dspsetupdatemode(uint8_t);
|
672 |
+
uint8_t dspgetupdatemode();
|
673 |
+
void dspgraphupdate();
|
674 |
+
void dspsetcursorx(uint8_t);
|
675 |
+
void dspsetcursory(uint8_t);
|
676 |
+
uint8_t dspgetcursorx();
|
677 |
+
uint8_t dspgetcursory();
|
678 |
+
|
679 |
+
/*
|
680 |
+
* These are the buffer control functions for the display driver.
|
681 |
+
*
|
682 |
+
* Color handling:
|
683 |
+
*
|
684 |
+
* Non scrolling displays simply use the pen color of the display
|
685 |
+
* stored in dspfgcolor() to paint the information on the screen.
|
686 |
+
*
|
687 |
+
* For scrolling displays we store the color information of every
|
688 |
+
* character in the display buffer to enable scrolling with color.
|
689 |
+
* To limit the storage requirements, this code translates the color
|
690 |
+
* to a 4 bit VGA color. This means that if BASIC uses 24 bit colors,
|
691 |
+
* the color may change at scroll
|
692 |
+
*
|
693 |
+
* For color displays the buffer is a 16 bit object. The lower 8 bits
|
694 |
+
* plus the sign are the character, higher 7 the color and font.
|
695 |
+
* For monochrome just the character is stored in an 8 bit object.
|
696 |
+
*
|
697 |
+
* The type dspbuffer_t is defined according to the display type.
|
698 |
+
*
|
699 |
+
* The following functions are used to control the display buffer:
|
700 |
+
*
|
701 |
+
* dspget(): get a character from the display buffer in form of a linear
|
702 |
+
* address. This is only used for the special array @D() in BASIC.
|
703 |
+
* It allows direct access to the display buffer.
|
704 |
+
* dspgetrc(r, c): get a character from the display buffer at row r and column c.
|
705 |
+
* This is used for the print function of the vt52 terminal. An entire display
|
706 |
+
* can be sent to the printer device OPRT
|
707 |
+
* dspgetc(c): get a character from the current line at column c. Also this is
|
708 |
+
* used for the print function of the VT52 terminal. This only sents the
|
709 |
+
* current line to the printer device OPRT.
|
710 |
+
* For both functions the actual print code is in the VT52 object.
|
711 |
+
* These three functions are somewhat redundant.
|
712 |
+
*
|
713 |
+
* dspsetxy(c, x, y): set a character at x, y in the display buffer and on the
|
714 |
+
* display. This function is needed for various control sequences of the VT52
|
715 |
+
* terminal.
|
716 |
+
* dspset(c, v): set a character at a linear address in the display buffer. Also u
|
717 |
+
* used for the @D() array in BASIC.
|
718 |
+
*
|
719 |
+
* dspsetscrollmode(m, l): set the scroll mode. m is the mode and l is the number
|
720 |
+
* of lines to be scrolled. Mode 0 means that dspwaitonscroll() does not
|
721 |
+
* wait for keyboard input. Mode 1 is wait for input.
|
722 |
+
* dspbufferclear(): clears the input buffer.
|
723 |
+
* dspscroll(l, t): do the actual scrolling. l is the number of lines to be scrolled.
|
724 |
+
* t is the topmost line included in the scroll. O by default.
|
725 |
+
* dspreversescroll(l): reverse scroll from line l downward.
|
726 |
+
*/
|
727 |
+
|
728 |
+
#ifdef DISPLAYHASCOLOR
|
729 |
+
typedef short dspbuffer_t;
|
730 |
+
#else
|
731 |
+
typedef char dspbuffer_t;
|
732 |
+
#endif
|
733 |
+
|
734 |
+
dspbuffer_t dspget(uint16_t);
|
735 |
+
dspbuffer_t dspgetrc(uint8_t, uint8_t);
|
736 |
+
dspbuffer_t dspgetc(uint8_t);
|
737 |
+
|
738 |
+
void dspsetxy(dspbuffer_t, uint8_t, uint8_t);
|
739 |
+
void dspset(uint16_t, dspbuffer_t);
|
740 |
+
void dspsetscrollmode(uint8_t, uint8_t);
|
741 |
+
|
742 |
+
void dspbufferclear();
|
743 |
+
void dspscroll(uint8_t, uint8_t);
|
744 |
+
void dspreversescroll(uint8_t);
|
745 |
+
|
746 |
+
/*
|
747 |
+
* A VT52 state engine is implemented and works for buffered and
|
748 |
+
* unbuffered displays. Only buffered displays have the full VT52
|
749 |
+
* feature set including most of the GEMDOS extensions described here:
|
750 |
+
* https://en.wikipedia.org/wiki/VT52
|
751 |
+
*
|
752 |
+
* The VT52 state engine processes sequences of the form <ESC> char.
|
753 |
+
*
|
754 |
+
* In addition to this, it also gives back certain return values.
|
755 |
+
* The can be read by vt52read() and vt52avail().
|
756 |
+
* vt52push() is used to push characters into the VT52 buffer.
|
757 |
+
* vt52number() is used to convert a character into the VT52 number format.
|
758 |
+
* vt52graphcommand() is a VT52 extension to display graphics on the screen.
|
759 |
+
*/
|
760 |
+
|
761 |
+
char vt52read();
|
762 |
+
uint8_t vt52avail();
|
763 |
+
void vt52push(char);
|
764 |
+
uint8_t vt52number(char);
|
765 |
+
void vt52graphcommand(uint8_t);
|
766 |
+
|
767 |
+
/*
|
768 |
+
* this is a special part of the vt52 code with this, the terminal
|
769 |
+
* can control the digital and analog pins.
|
770 |
+
*
|
771 |
+
* It is meant for situations where the terminal is controlled by a (powerful)
|
772 |
+
* device with no or very few I/O pins. It can use the pins of the Arduino through
|
773 |
+
* the terminal.
|
774 |
+
*
|
775 |
+
* This works as long as everything stays within the terminals timescale.
|
776 |
+
* On a 9600 baud interface, the character processing time is 1ms, everything
|
777 |
+
* slower than approximately 10ms can be done through the serial line.
|
778 |
+
*/
|
779 |
+
|
780 |
+
void vt52wiringcommand(uint8_t);
|
781 |
+
|
782 |
+
/* the vt52 state engine */
|
783 |
+
void dspvt52(char*);
|
784 |
+
|
785 |
+
/*
|
786 |
+
* Code for the VGA system of Fabgl. This is a full VT52 terminal. The
|
787 |
+
* display driver is not used for this.
|
788 |
+
*/
|
789 |
+
|
790 |
+
void vgabegin();
|
791 |
+
int vgastat(uint8_t);
|
792 |
+
void vgascale(int*, int*);
|
793 |
+
void vgawrite(char);
|
794 |
+
void vgaend();
|
795 |
+
|
796 |
+
/*
|
797 |
+
* IO channel 2 (input) - the keyboard I/O device.
|
798 |
+
*
|
799 |
+
* Keyboard code for either the Fablib Terminal class,
|
800 |
+
* PS2Keyboard or other keyboards.
|
801 |
+
*
|
802 |
+
* PS2Keyboard: please note that you need the patched
|
803 |
+
* version here as mentioned above.
|
804 |
+
*
|
805 |
+
* Keyboards implement kbdbegin() which is called at startup
|
806 |
+
* and kbdstat() which is called to check if the keyboard is
|
807 |
+
* available.
|
808 |
+
*
|
809 |
+
* Keyboards need to provide the following functions:
|
810 |
+
*
|
811 |
+
* kbdavailable(): check if a character is available
|
812 |
+
* kbdread(): read a character from the keyboard
|
813 |
+
* kbdcheckch(): check if a character is available without blocking
|
814 |
+
* kbdins(): read a line from the keyboard
|
815 |
+
*
|
816 |
+
* kbdcheckch() is for interrupting running BASIC code with a
|
817 |
+
* BREAKCHAR character from the keyboard. If this functions is
|
818 |
+
* not implemented, the BREAKCHAR character is ignored.
|
819 |
+
*
|
820 |
+
* kbdins() is usually using consins() to read a line from the
|
821 |
+
* keyboard repeatedly calling kbdread() until a newline is
|
822 |
+
* received. A keyboard can also bring its on kbdins() function.
|
823 |
+
*/
|
824 |
+
|
825 |
+
void kbdbegin();
|
826 |
+
uint8_t kbdstat(uint8_t);
|
827 |
+
uint8_t kbdavailable();
|
828 |
+
char kbdread();
|
829 |
+
char kbdcheckch();
|
830 |
+
uint16_t kbdins(char*, uint16_t);
|
831 |
+
|
832 |
+
/* IO channel 3 - reserved for future use */
|
833 |
+
|
834 |
+
/*
|
835 |
+
* IO channel 4 - the second serial I/O device.
|
836 |
+
*
|
837 |
+
* This is the (mostly) the Serial1 object
|
838 |
+
* on Arduino. On POSIX systems this opens a serial port like /dev/ttyUSB1.
|
839 |
+
* This &4 in BASIC.
|
840 |
+
*
|
841 |
+
* Functions are:
|
842 |
+
*
|
843 |
+
* prtbegin(): start the serial port
|
844 |
+
* prtopen(name, baud): open the serial port with the baud rate baud. Only
|
845 |
+
* neded in POSIX to open the port.
|
846 |
+
* prtclose(): close the serial port
|
847 |
+
* prtstat(s): check the status of the serial port
|
848 |
+
* prtwrite(c): write a character to the serial port
|
849 |
+
* prtread(): read a character from the serial port
|
850 |
+
* prtcheckch(): check if a character is available without blocking
|
851 |
+
* prtavailable(): check if characters are available
|
852 |
+
* prtset(baud): set the baud rate of the serial port
|
853 |
+
* prtins(s, l): read a line from the serial port
|
854 |
+
*/
|
855 |
+
|
856 |
+
void prtbegin();
|
857 |
+
char prtopen(char*, uint16_t);
|
858 |
+
void prtclose();
|
859 |
+
uint8_t prtstat(uint8_t);
|
860 |
+
void prtwrite(char);
|
861 |
+
char prtread();
|
862 |
+
char prtcheckch();
|
863 |
+
uint16_t prtavailable();
|
864 |
+
void prtset(uint32_t);
|
865 |
+
uint16_t prtins(char*, uint16_t);
|
866 |
+
|
867 |
+
/*
|
868 |
+
* IO channel 7 - I2C through the Wire library.
|
869 |
+
*
|
870 |
+
* The wire code, direct access to wire communication.
|
871 |
+
*
|
872 |
+
* In master mode wire_slaveid is the I2C address bound
|
873 |
+
* to channel &7 and wire_myid is 0.
|
874 |
+
*
|
875 |
+
* In slave mode wire_myid is the devices slave address
|
876 |
+
* and wire_slaveid is 0.
|
877 |
+
*
|
878 |
+
* The maximum number of bytes the Wire library can handle
|
879 |
+
* is 32. This is given by the Wire library.
|
880 |
+
*
|
881 |
+
* Wire is handled through the following functions:
|
882 |
+
*
|
883 |
+
* wirebegin(): start the wire system.
|
884 |
+
* wireslavebegin(id): start the wire system as a slave with the id.
|
885 |
+
* wirestat(s): check if the wire system is available.
|
886 |
+
* wireavailable(): check if characters are available in slave mode.
|
887 |
+
* wireonreceive(h): set the event handler for received data on a slave.
|
888 |
+
* wireonrequest(): set the event handler for request on a slave.
|
889 |
+
* wireopen(id, slaveid): open the wire system as a master with id to
|
890 |
+
* the slave id.
|
891 |
+
* wireread(): read a character from the wire system.
|
892 |
+
* wirewrite(c): write a character to the wire system.
|
893 |
+
* wireins(l, s): read a line l from the wire system max length is s.
|
894 |
+
* wireouts(l, s): write a line l to the wire system max length is s.
|
895 |
+
* They are available in BASIC as the WIRE
|
896 |
+
* command.
|
897 |
+
*/
|
898 |
+
|
899 |
+
void wirebegin();
|
900 |
+
void wireslavebegin(uint8_t);
|
901 |
+
uint8_t wirestat(uint8_t);
|
902 |
+
uint16_t wireavailable();
|
903 |
+
void wireonreceive(int);
|
904 |
+
void wireonrequest();
|
905 |
+
void wireopen(uint8_t, uint8_t);
|
906 |
+
char wireread();
|
907 |
+
void wirewrite(char c);
|
908 |
+
uint16_t wireins(char*, uint8_t);
|
909 |
+
void wireouts(char*, uint8_t);
|
910 |
+
|
911 |
+
/* new byte wire interface for direct access */
|
912 |
+
void wirestart(uint8_t, uint8_t);
|
913 |
+
void wirewritebyte(uint8_t);
|
914 |
+
uint8_t wirestop();
|
915 |
+
int16_t wirereadbyte();
|
916 |
+
|
917 |
+
/*
|
918 |
+
* IO channel 8 - the RF24 radio I/O device.
|
919 |
+
*
|
920 |
+
* Read from the radio interface, radio is always block
|
921 |
+
* oriented. This function is called from ins for an entire
|
922 |
+
* line.
|
923 |
+
*
|
924 |
+
* In blockmode the entire message is returned in the
|
925 |
+
* receiving string while in line mode the length of the
|
926 |
+
* string is adapted. Blockmode can be used to transfer
|
927 |
+
* binary data.
|
928 |
+
*
|
929 |
+
* The radio code is rather obsolet and not used a lot.
|
930 |
+
*
|
931 |
+
* On RF24 we always read from pipe 1 and use pipe 0 for writing,
|
932 |
+
* the filename is the pipe address, by default the radio
|
933 |
+
* goes to reading mode after open and is only stopped for
|
934 |
+
* write.
|
935 |
+
*/
|
936 |
+
|
937 |
+
uint8_t radiostat(uint8_t);
|
938 |
+
uint64_t pipeaddr(const char*);
|
939 |
+
uint16_t radioins(char*, uint8_t);
|
940 |
+
void radioouts(char *, uint8_t);
|
941 |
+
uint16_t radioavailable();
|
942 |
+
char radioread();
|
943 |
+
void iradioopen(const char *);
|
944 |
+
void oradioopen(const char *);
|
945 |
+
void radioset(uint8_t);
|
946 |
+
|
947 |
+
/*
|
948 |
+
* IO channel 9 - the network I/O device.
|
949 |
+
*
|
950 |
+
* Only MQTT is implemented at the moment. Other protocols
|
951 |
+
* will be channel 10-15.
|
952 |
+
*
|
953 |
+
* Underlying networks can be the Wifi classes of the ESP, MKR, and
|
954 |
+
* STM32 cores. The network code is based on the PubSubClient library.
|
955 |
+
* Ethernet is supported with the standard Ethernet library on Arduino.
|
956 |
+
*
|
957 |
+
* On POSIX systems networking is currently not supported.
|
958 |
+
*
|
959 |
+
* No encryptionis implemented in MQTT. Only unencrypted servers can be used.
|
960 |
+
*
|
961 |
+
* Buffers are defined above in the mqtt section.
|
962 |
+
*
|
963 |
+
* MQTTLENGTH: the length of the mqtt topic, restricted to 32 by default.
|
964 |
+
* MQTTBLENGTH: the length of the mqtt buffer, 128 by default.
|
965 |
+
* MQTTNAMELENGTH: the length of the autogenerated mqtt name, 12 by default.
|
966 |
+
*
|
967 |
+
* wifisettings.h is the generic network definition file all network settings
|
968 |
+
* are compiled into the code. BASIC cannot change them at runtime.
|
969 |
+
*
|
970 |
+
* Low level network functions are:
|
971 |
+
*
|
972 |
+
* netbegin(): start the network
|
973 |
+
* netstop(): stop the network
|
974 |
+
* netreconnect(): reconnect the network
|
975 |
+
* netconnected(): check if the network is connected
|
976 |
+
*
|
977 |
+
* BASIC uses these function to control the network and reconnect if
|
978 |
+
* the connection is lost.
|
979 |
+
*/
|
980 |
+
|
981 |
+
void netbegin();
|
982 |
+
void netstop();
|
983 |
+
void netreconnect();
|
984 |
+
uint8_t netconnected();
|
985 |
+
|
986 |
+
/*
|
987 |
+
* The mqtt prototypes used by BASIC are:
|
988 |
+
*
|
989 |
+
* mqttbegin(): start the mqtt client
|
990 |
+
* mqttsetname(): set the name of the mqtt client. The name is autogenerated.
|
991 |
+
* mqttstat(s): check the status of the mqtt client
|
992 |
+
* mqttreconnect(): reconnect the mqtt client
|
993 |
+
* mqttstate(): get the state of the mqtt client (redunant to mqttstat())
|
994 |
+
* mqttsubscribe(t): subscribe to a topic
|
995 |
+
* mqttunsubscribe(): unsubscribe from a topic
|
996 |
+
* mqttsettopic(t): set the topic of the mqtt client
|
997 |
+
* mqttouts(s, l): send a string of length l to the mqtt server
|
998 |
+
* mqttwrite(c): send a character to the mqtt server.
|
999 |
+
* These two functions work buffered. The write to the MQTT output buffer. Only
|
1000 |
+
* when the buffer is full or a newline is received, the buffer is sent to the
|
1001 |
+
* server.
|
1002 |
+
* mqttread(): read a character from the mqtt input buffer.
|
1003 |
+
* mqttins(s, l): read a line from the mqtt input buffer.
|
1004 |
+
* mqttavailable(): check if characters are available in the mqtt input buffer.
|
1005 |
+
* mqttcheckch(): get the next character from the mqtt input buffer without advancing.
|
1006 |
+
*/
|
1007 |
+
|
1008 |
+
void mqttbegin();
|
1009 |
+
void mqttsetname();
|
1010 |
+
uint8_t mqttstat(uint8_t);
|
1011 |
+
uint8_t mqttreconnect();
|
1012 |
+
uint8_t mqttstate();
|
1013 |
+
void mqttsubscribe(const char*);
|
1014 |
+
void mqttunsubscribe();
|
1015 |
+
void mqttsettopic(const char*);
|
1016 |
+
void mqttouts(const char*, uint16_t);
|
1017 |
+
void mqttwrite(const char);
|
1018 |
+
char mqttread();
|
1019 |
+
uint16_t mqttins(char*, uint16_t);
|
1020 |
+
uint16_t mqttavailable();
|
1021 |
+
char mqttcheckch();
|
1022 |
+
|
1023 |
+
/*
|
1024 |
+
* The callback function of the pubsub client. This is called when a
|
1025 |
+
* message is received from the mqtt server.
|
1026 |
+
*
|
1027 |
+
* The Arduino type byte is used here because it is used this way in Pubsub.
|
1028 |
+
*/
|
1029 |
+
void mqttcallback(char*, byte*, unsigned int);
|
1030 |
+
|
1031 |
+
/*
|
1032 |
+
* IO channel 16 - the file system I/O device.
|
1033 |
+
*
|
1034 |
+
* The file system driver - all methods needed to support BASIC fs access.
|
1035 |
+
*
|
1036 |
+
* Different filesystems need different prefixes and fs objects, these
|
1037 |
+
* filesystems use the stream API in the Arduino world.
|
1038 |
+
*
|
1039 |
+
* The functions to access the filesystem are:
|
1040 |
+
*
|
1041 |
+
* fsbegin(): start the filesystem
|
1042 |
+
* fsstat(s): check the status of the filesystem
|
1043 |
+
* mkfilename(s): make a filename from a string
|
1044 |
+
* rmrootfsprefix(s): remove the prefix from a filename
|
1045 |
+
*
|
1046 |
+
* Different filesystems have different prefixes. In BASIC we
|
1047 |
+
* only show a flat file system with no path names and prefixes.
|
1048 |
+
*
|
1049 |
+
* Supported filesystems are:
|
1050 |
+
*
|
1051 |
+
* SPIFF - the internal flash file system of the ESP32 and ESP8266
|
1052 |
+
* SD - the SD card file system (no formatting)
|
1053 |
+
* EFS - the file system EFS for I2C EEPROMs
|
1054 |
+
* LittleFS - the LittleFS file system on RP2040
|
1055 |
+
* USB devices on Arduino GIGA boards
|
1056 |
+
* Posix and Windows file systems on POSIX systems
|
1057 |
+
*/
|
1058 |
+
|
1059 |
+
void fsbegin();
|
1060 |
+
uint8_t fsstat(uint8_t);
|
1061 |
+
char* mkfilename(const char*);
|
1062 |
+
const char* rmrootfsprefix(const char*);
|
1063 |
+
|
1064 |
+
/*
|
1065 |
+
* File I/O function on an Arduino:
|
1066 |
+
*
|
1067 |
+
* filewrite(c): write a character to a file
|
1068 |
+
* fileread(): read a character from a file
|
1069 |
+
* fileavailable(): check if a character is available in the file
|
1070 |
+
* ifileopen(s): open a file for input
|
1071 |
+
* ifileclose(): close a file for input
|
1072 |
+
* ofileopen(s, m): open a file for output with mode m
|
1073 |
+
* ofileclose(): close a file for output
|
1074 |
+
*
|
1075 |
+
* The wrapper and BASIC currently only support one file for read
|
1076 |
+
* and one file for write.
|
1077 |
+
*/
|
1078 |
+
|
1079 |
+
void filewrite(char);
|
1080 |
+
char fileread();
|
1081 |
+
int fileavailable(); /* is int because some of the fs do this */
|
1082 |
+
uint8_t ifileopen(const char*);
|
1083 |
+
void ifileclose();
|
1084 |
+
uint8_t ofileopen(const char*, const char*);
|
1085 |
+
void ofileclose();
|
1086 |
+
|
1087 |
+
/*
|
1088 |
+
* Directory handling for the catalog function these methods are
|
1089 |
+
* needed for a walkthtrough of one directory.
|
1090 |
+
*
|
1091 |
+
* The logic is:
|
1092 |
+
*
|
1093 |
+
* rootopen()
|
1094 |
+
* while rootnextfile()
|
1095 |
+
* if rootisfile() print rootfilename() rootfilesize()
|
1096 |
+
* rootfileclose()
|
1097 |
+
* rootclose()
|
1098 |
+
*
|
1099 |
+
* rootopen(): opens the root directory
|
1100 |
+
* rootnextfile(): gets the next file in the directory
|
1101 |
+
* rootisfile(): checks if the file is a file or something else
|
1102 |
+
* rootfilename(): gets the name of the file
|
1103 |
+
* rootfilesize(): gets the size of the file
|
1104 |
+
* rootfileclose(): closes the root file
|
1105 |
+
*/
|
1106 |
+
|
1107 |
+
void rootopen();
|
1108 |
+
uint8_t rootnextfile();
|
1109 |
+
uint8_t rootisfile();
|
1110 |
+
const char* rootfilename();
|
1111 |
+
uint32_t rootfilesize();
|
1112 |
+
void rootfileclose();
|
1113 |
+
void rootclose();
|
1114 |
+
|
1115 |
+
/* delete a file, needed in the DELETE command of BASIC */
|
1116 |
+
void removefile(const char*);
|
1117 |
+
|
1118 |
+
/*
|
1119 |
+
* Formatting for fdisk of the internal filesystems. This
|
1120 |
+
* is not implemented for all filesystems.
|
1121 |
+
*/
|
1122 |
+
void formatdisk(uint8_t);
|
1123 |
+
|
1124 |
+
/*
|
1125 |
+
* The Real Time clock. The interface here offers the values as number_t
|
1126 |
+
* combining all values.
|
1127 |
+
*
|
1128 |
+
* On Arduino, he code does not use an RTC library any more all the
|
1129 |
+
* RTC support is builtin now for standard I2C clocks.
|
1130 |
+
*
|
1131 |
+
* A clock must activate the macro #define HASCLOCK to make the clock
|
1132 |
+
* available in BASIC.
|
1133 |
+
*
|
1134 |
+
* Four software models are supported in runtime.cpp for Arduino:
|
1135 |
+
* - Built-in clocks of STM32, MKR, and ESP32 are supported by default.
|
1136 |
+
* - I2C clocks can be activated: DS1307, DS3231, and DS3232
|
1137 |
+
* - A Real Time Clock emulation using millis()
|
1138 |
+
*
|
1139 |
+
* On POSIX the standard time functions are used and mapped to this API.
|
1140 |
+
*
|
1141 |
+
* rtcget(r) accesses the internal registers of the clock.
|
1142 |
+
* r==0 is the seconds, r==1 the minutes, r==2 the hours, r==3 the
|
1143 |
+
* day of week, r==4 the day, r==5 the month, r==6 the year.
|
1144 |
+
* The day of the week feature is not supported by all clocks.
|
1145 |
+
* rtcset(r, v) sets the internal registers of the clock.
|
1146 |
+
*
|
1147 |
+
* On I2C clocks with NVRAM the registers 7-255 are accessed as
|
1148 |
+
* memory cells through these functions.
|
1149 |
+
*
|
1150 |
+
* rtcbegin() is called at startup to initialize the clock, normally
|
1151 |
+
* a dummy function.
|
1152 |
+
*
|
1153 |
+
* rtctimetoutime() converts the clock time to a unix time number.
|
1154 |
+
* rtcutimetotime() converts the unix time number to a clock time.
|
1155 |
+
* Both are private functions of the clock emulation.
|
1156 |
+
*
|
1157 |
+
* Code in these two functions is taken from the German Wikipedia
|
1158 |
+
* article on Unix time. https://de.wikipedia.org/wiki/Unixzeit
|
1159 |
+
*/
|
1160 |
+
|
1161 |
+
void rtcbegin();
|
1162 |
+
uint16_t rtcget(uint8_t);
|
1163 |
+
void rtcset(uint8_t, uint16_t);
|
1164 |
+
void rtctimetoutime();
|
1165 |
+
void rtcutimetotime();
|
1166 |
+
|
1167 |
+
/*
|
1168 |
+
* Arduino Sensor library code
|
1169 |
+
* The sensorread() is a generic function called by
|
1170 |
+
* SENSOR basic function and command. The first argument
|
1171 |
+
* is the sensor and the second argument the value.
|
1172 |
+
* sensorread(n, 0) checks if the sensorstatus.
|
1173 |
+
*/
|
1174 |
+
void sensorbegin();
|
1175 |
+
float sensorread(uint8_t, uint8_t);
|
1176 |
+
|
1177 |
+
/*
|
1178 |
+
* Experimental code to drive SPI SRAM
|
1179 |
+
*
|
1180 |
+
* Currently only the 23LCV512 is implemented, assuming a 64kB SRAM.
|
1181 |
+
* Part of code is taken in part from the SRAMsimple library.
|
1182 |
+
*
|
1183 |
+
* Two buffers are implemented:
|
1184 |
+
*
|
1185 |
+
* - a ro buffer used by memread, this buffer is mainly reading the token
|
1186 |
+
* stream at runtime.
|
1187 |
+
* - a rw buffer used by memread2 and memwrite2, this buffer is mainly accessing
|
1188 |
+
* the heap at runtime. In interactive mode this is also the interface to read
|
1189 |
+
* and write program code to memory.
|
1190 |
+
*
|
1191 |
+
*/
|
1192 |
+
|
1193 |
+
/* the RAM begin method sets the RAM to sequential mode */
|
1194 |
+
uint16_t spirambegin();
|
1195 |
+
int8_t spiramrawread(uint16_t);
|
1196 |
+
void spiram_bufferread(uint16_t, int8_t*, uint16_t);
|
1197 |
+
void spiram_bufferwrite(uint16_t, int8_t*, uint16_t);
|
1198 |
+
int8_t spiram_robufferread(uint16_t);
|
1199 |
+
void spiram_rwbufferflush(); /* flush the buffer */
|
1200 |
+
int8_t spiram_rwbufferread(uint16_t);
|
1201 |
+
void spiram_rwbufferwrite(uint16_t, int8_t); /* the buffered file write */
|
1202 |
+
void spiramrawwrite(uint16_t, int8_t); /* the simple unbuffered byte write, with a cast to signed char */
|
1203 |
+
|
1204 |
+
// defined RUNTIMEH
|
1205 |
+
#endif
|
data/Basic2/IoTBasic/src/FlashStorage_SAMD/FlashAsEEPROM_SAMD.h
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/******************************************************************************************************************************************
|
2 |
+
FlashAsEEPROM_SAMD.h
|
3 |
+
For SAMD21/SAMD51 using Flash emulated-EEPROM
|
4 |
+
|
5 |
+
The FlashStorage_SAMD library aims to provide a convenient way to store and retrieve user's data using the non-volatile flash memory
|
6 |
+
of SAMD21/SAMD51. It now supports writing and reading the whole object, not just byte-and-byte.
|
7 |
+
|
8 |
+
Based on and modified from Cristian Maglie's FlashStorage (https://github.com/cmaglie/FlashStorage)
|
9 |
+
|
10 |
+
Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD
|
11 |
+
Licensed under LGPLv3 license
|
12 |
+
|
13 |
+
Orginally written by Cristian Maglie
|
14 |
+
|
15 |
+
Copyright (c) 2015 Arduino LLC. All right reserved.
|
16 |
+
Copyright (c) 2020 Khoi Hoang.
|
17 |
+
|
18 |
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
19 |
+
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
20 |
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
22 |
+
You should have received a copy of the GNU Lesser General Public License along with this library.
|
23 |
+
If not, see (https://www.gnu.org/licenses/)
|
24 |
+
|
25 |
+
Version: 1.3.2
|
26 |
+
|
27 |
+
Version Modified By Date Comments
|
28 |
+
------- ----------- ---------- -----------
|
29 |
+
1.0.0 K Hoang 28/03/2020 Initial coding to add support to SAMD51 besides SAMD21
|
30 |
+
1.1.0 K Hoang 26/01/2021 Add supports to put() and get() for writing and reading the whole object. Fix bug.
|
31 |
+
1.2.0 K Hoang 18/08/2021 Optimize code. Add debug option
|
32 |
+
1.2.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json`
|
33 |
+
1.3.0 K Hoang 25/01/2022 Fix `multiple-definitions` linker error. Add support to many more boards.
|
34 |
+
1.3.1 K Hoang 25/01/2022 Reduce number of library files
|
35 |
+
1.3.2 K Hoang 26/01/2022 Make compatible with old libraries and codes
|
36 |
+
******************************************************************************************************************************************/
|
37 |
+
|
38 |
+
// The .hpp contains only definitions, and can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
39 |
+
// The .h contains implementations, and can be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
40 |
+
|
41 |
+
#pragma once
|
42 |
+
|
43 |
+
#ifndef FlashAsEEPROM_SAMD_h
|
44 |
+
#define FlashAsEEPROM_SAMD_h
|
45 |
+
|
46 |
+
#include <FlashStorage_SAMD.hpp>
|
47 |
+
#include <FlashStorage_SAMD_Impl.h>
|
48 |
+
|
49 |
+
#endif //#ifndef FlashAsEEPROM_SAMD_h
|