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40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/*
 *
 *	$Id: language.h,v 1.1 2024/02/25 04:43:16 stefan Exp stefan $ 
 *
 *	Stefan's IoT BASIC interpreter 
 *
 * 	See the licence file on 
 *	https://github.com/slviajero/tinybasic for copyright/left.
 *    (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
 *
 *	Author: Stefan Lenz, [email protected]
 *
 *	This is the language definition file. Edit this to set the language 
 * 	capabilities.
 * 
 * MEMSIZE was moved to hardware.h now as it is a hardware setting.
 * 
 */

/*
 *	DEBUG switches on compiled debug mode. Consider using runtime 
 * 		debug with SET 0,x before using this.
 */
#define DEBUG 0

/*
 * Interpreter feature sets, choose one of the predefines or undefine all predefines and set the 
 * features in custom settings
 *
 * BASICFULL: full language set, use this with flash >32kB - ESPs, MKRs, Mega2560, RP2040, UNO R4
 * BASICINTEGER: integer BASIC with full language, use this with flash >32kB
 * BASICSIMPLE: integer BASIC with reduced language set, 32kB capable - for UNOs with a lot of device drivers
 * BASICSIMPLEWITHFLOAT: a small floating point BASIC, 32kB capable, for UNOs - good for UNOs with the need of float
 * BASICTINYWITHFLOAT: a floating point tinybasic, if you have 32kB and need complex device drivers
 * BASICMINIMAL: minimal language, just Palo Alto plus Arduino I/O, works on 168 with 1kB RAM and 16kB flash
 * 
 * The board will try to find the best language model for it's size and capabilities. Relies on the 
 * information hardware.h produces. It set one of the language models: 
 * 
 * BASICFULL, BASICSIMPLE, BASICMINIMAL.
 * 
 * Setting NOLANGUAGEHEURISTICS and then one of the models below will override this 
 * selection.
 */
#define LANGUAGEHEURISTICS

#ifndef LANGUAGEHEURISTICS
#undef  BASICFULL
#undef	BASICINTEGER
#undef	BASICSIMPLE
#undef	BASICMINIMAL
#undef  BASICPALOALTO
#undef	BASICSIMPLEWITHFLOAT
#undef	BASICTINYWITHFLOAT
#endif

/*
 * Custom settings undef all the the language sets above when you are using this. Not all language
 * features work in all combinations.
 * 
 * HASAPPLE1: Apple 1 BASIC compatibility. This is the base for all other features.
 *  In this version the interpreter has a heap, a string pool and one dimensional arrays.
 * HASARDUINOIO: Arduino I/O functions, including millis() timer.
 * HASFILEIO: file I/O functions, including open, close, read, write, remove, rename.
 * HASTONE: tone() and noTone() functions for sound output mapped to the PLAY command.
 * HASPULSE: pulseIn() function for measuring pulse lengths. Pulse output. Both mapped to the PULSE command.
 * HASSTEFANSEXT: Stefan's BASIC extensions, including ELSE, PUT, GET, advanced FOR loops, SQR and POW.
 * HASERRORMSG: error messages for syntax and runtime errors.
 * HASVT52: VT52 terminal emulation for text output -> moved to hardware.h
 * HASFLOAT: floating point support.
 * HASGRAPH: graphics support, including line, circle, rectangle, fill, color.
 * HASDARTMOUTH: Dartmouth BASIC compatibility: single line DEF FN, ON, READ, DATA.
 * HASDARKARTS: Dark Arts BASIC is MALLOC, FIND, CLR for individual variables and EVAL for self modifying code.
 * HASIOT: IoT functions, Wire access, Sensor functions, MQTT. Needs strings and heap. STR, VAL, INSTR are 
 *  part of this. MQTT support only on Arduino-
 * HASMULTIDIM: two dimensional arrays and one dimensional string arrays.
 * HASTIMER: timer functions, AFTER and EVERY for periodic execution of programs.
 * HASEVENTS: event handling, EVENT command. 
 * HASERRORHANDLING: error handling with ERROR GOTO.
 * HASSTRUCT: structured language elements, WHILE WEND, REPEAT UNTIL, SWITCH CASE. Multi line IF THEN ELSE 
 * 	with the DO DEND construct.
 * HASMSSTRINGS: MS Basic compatible strings, RIGHT$, LEFT$, MID$, ASC, CHR$, and string addition with +.
 * 	Compatibility to MS BASICs is limited as this BASIC has only inplace string operations-
 * HASMULTILINEFUNCTIONS: multi line functions, DEF FN, FEND.
 * HASEDITOR: line editor for the console.
 * HASTINYBASICINPUT: Tiny BASIC compatible input using the expression parser. Expressions and variables 
 * 	are valid number input with it. Default now but can have odd side effects.
 * HASLONGNAMES: long variable names, up to 16 characters. Name length is set by MAXNAME in basic.h and
 * 	can be any value <128 bytes. Names are still only uppercase and all names will be uppercased by lexer.
 * HASHELP: show the commands of the interpreter. Will be extended to a help system.
 * HASFULLINSTR: the full C64 style INSTR command. Without this flag INSTR only accepts
 *	a single character as argument. This is much faster and leaner on an Arduino. 
 * 	This macro is activated when HASMSSTRINGS is set. 
 * HASLOOPOPT: optimizes the FOR loops for speed. This is a trade off between speed and 
 *  memory. It is activated by default. Speeup is about 10% on a Mac. On platforms
 *  with low memory bandwidth it is much more.
 * HASNUMSYSTEM: constants can be hex, octal, binary or decimal. This is not activated by 
 *  default. Currently only implemented in VAL() and STR().
 * HASBITWISE: has bitwise operations >>, << and the function BIT -> removed and default now.
 * 
 * If you want to set everything manually, set NOLANGUAGEHEURISTICS above
 */

#ifndef LANGUAGEHEURISTICS
#define HASAPPLE1
#define HASARDUINOIO
#define HASFILEIO
#define HASTONE
#define HASPULSE
#define HASSTEFANSEXT
#define HASERRORMSG
#define HASFLOAT
#define HASGRAPH
#define HASDARTMOUTH
#define HASDARKARTS
#define HASIOT
#define HASMULTIDIM
#define HASTIMER
#define HASEVENTS
#define HASERRORHANDLING
#define HASSTRUCT
#define HASMSSTRINGS
#define HASMULTILINEFUNCTIONS
#define HASEDITOR
#define HASTINYBASICINPUT
#define HASLONGNAMES 
#define HASHELP
#define HASFULLINSTR
#define HASLOOPOPT
#define HASNUMSYSTEM
#endif


/*
 *
 * Odd stuff - these things change the behaviour of BASIC in some aspects.
 * They can be used to make the interpreter compatible with other dialects.
 * 
 * 	POWERRIGHTTOLEFT: normally the ^ operator works from left to right 
 *		which means 2^3^2 = (2^3)^2 = 8^2 = 64. Setting this flag would 
 *		change the behaviour to 2^3^2 = 2^(3^2) = 512
 *  MSARRAYLIMITS: in BASIC arrays start at 1 and DIM A(10) creates 10 
 *      elements. With MSARRAYLIMITS defined, arrays start at 0 and have 
 *      n+1 elements. This can be changed at any time with SET 21,0 or 1.
 *  SUPPRESSSUBSTRINGS: switch off substring logic by default, makes only sense with 
 *      HASMSSTRINGS activated. With this, the syntax of strings and string 
 *      arrays is comaptible to MS strings (only used to preset the variable now).
 * 		SET 20 can change this at runtime. 
 *  USELONGJUMP: use the longjmp feature of C. This greatly simplifies 
 *      error handling at the cost of portability to some MCU platforms
 *      currently only experimental. It costs memory for the jump buffer. 
 *      Don't use it on very small systems. LONGJUMP must be set to 0 or 1 as 
 *      it is used in boolean expression in the code
 *  BOOLEANMODE: switch the behaviour of BASICs boolean operators. Default (-1)
 *      is to cast all numbers to signed 16bit and then do bitwise arithemtic.
 *      In this mode false is 0 and -1 is true. (1) is C style boolean arithemtic.
 *      In this mode true is 1 and false is 0. AND and OR still do bitwise operations
 *      but NOT is C not. SET 19,1 or -1 can change this at runtime.
 *  HAS64BIT: 64 bit floating point support on platforms that have a 64 bit double. 
 *      Counterexample: AVR 8bit does not have 64 bit floating point.
 * HAS32BITINT: 32 bit integer support on 8 bit platforms.
 * HASPOWER: the POWER operator ^ is available in addition to the POW function.
 * HASUSRCALL: the USR and CALL functions. On small systems they need a lot 
 *      of flash and can be disabled.
 */

#undef POWERRIGHTTOLEFT
#undef MSARRAYLIMITS
#undef SUPPRESSSUBSTRINGS
#define USELONGJUMP 0
#define BOOLEANMODE -1
#undef  HAS64BIT
#undef  HAS32BITINT
#define HASPOWER 
#define HASUSRCALL

/* Palo Alto plus Arduino functions */
#ifdef BASICMINIMAL
#undef HASAPPLE1
#define HASARDUINOIO
#undef HASFILEIO
#undef HASTONE
#undef HASPULSE
#undef HASSTEFANSEXT
#undef HASERRORMSG
#undef HASFLOAT
#undef HASGRAPH
#undef HASDARTMOUTH
#undef HASDARKARTS
#undef HASIOT
#undef HASMULTIDIM
#undef HASTIMER
#undef HASEVENTS
#undef HASERRORHANDLING
#undef HASSTRUCT
#undef HASMSSTRINGS
#undef HASMULTILINEFUNCTIONS
#undef HASEDITOR
#define HASTINYBASICINPUT
#undef HASLONGNAMES 
#undef HASHELP
#undef HASFULLINSTR
#undef HASLOOPOPT
#undef HASNUMSYSTEM
#undef HASPOWER
#undef HASUSRCALL
#endif

/* the original Palo Alto Tinybasic, this is the real minimum */
#ifdef BASICPALOALTO
#undef HASAPPLE1
#undef HASARDUINOIO
#undef HASFILEIO
#undef HASTONE
#undef HASPULSE
#undef HASSTEFANSEXT
#undef HASERRORMSG
#undef HASFLOAT
#undef HASGRAPH
#undef HASDARTMOUTH
#undef HASDARKARTS
#undef HASIOT
#undef HASMULTIDIM
#undef HASTIMER
#undef HASEVENTS
#undef HASERRORHANDLING
#undef HASSTRUCT
#undef HASMSSTRINGS
#undef HASMULTILINEFUNCTIONS
#undef HASEDITOR
#define HASTINYBASICINPUT
#undef HASLONGNAMES 
#undef HASHELP
#undef HASLOOPOPT
#undef HASNUMSYSTEM
#undef HASBITWISE
#undef HASFULLINSTR
#undef HASLOOPOPT
#undef HASNUMSYSTEM
#undef HASPOWER
#undef HASUSRCALL
#endif

/* all features minus float and tone */
#ifdef  BASICINTEGER
#define HASAPPLE1
#define HASARDUINOIO
#define HASFILEIO
#define HASTONE
#define HASPULSE
#define HASSTEFANSEXT
#define HASERRORMSG
#undef  HASFLOAT
#define HASGRAPH
#define HASDARTMOUTH
#define HASDARKARTS
#define HASIOT
#define HASMULTIDIM
#define HASTIMER
#define HASEVENTS
#define HASERRORHANDLING
#define HASSTRUCT
#define HASMSSTRINGS
#define HASMULTILINEFUNCTIONS
#define HASEDITOR
#define HASTINYBASICINPUT
#define HASLONGNAMES 
#define HASHELP
#define HASFULLINSTR
#define HASLOOPOPT
#define HASNUMSYSTEM
#endif

/* a simple integer basic for small systems mainly the UNO */
#ifdef  BASICSIMPLE
#define HASAPPLE1
#define HASARDUINOIO
#define HASFILEIO
#define HASTONE
#define HASPULSE
#define HASSTEFANSEXT
#define HASERRORMSG
#undef  HASFLOAT
#undef  HASGRAPH
#define HASDARTMOUTH
#undef  HASDARKARTS
#define HASIOT
#undef  HASMULTIDIM
#define HASTIMER
#define HASEVENTS
#define HASERRORHANDLING
#undef 	HASSTRUCT
#undef  HASMSSTRINGS
#undef HASMULTILINEFUNCTIONS
#undef HASEDITOR
#define HASTINYBASICINPUT
#undef HASLONGNAMES 
#undef HASHELP
#undef HASFULLINSTR
#undef HASLOOPOPT
#undef HASNUMSYSTEM
#undef HASPOWER
#undef HASUSRCALL
#endif

/* a small integer BASIC for 32kB systems with big cores */
#ifdef  BASICSMALL
#define HASAPPLE1
#define HASARDUINOIO
#undef  HASFILEIO
#undef  HASTONE
#undef  HASPULSE
#define HASSTEFANSEXT
#define HASERRORMSG
#undef  HASFLOAT
#undef  HASGRAPH
#undef  HASDARTMOUTH
#undef  HASDARKARTS
#define HASIOT
#undef  HASMULTIDIM
#define HASTIMER
#define HASEVENTS
#define HASERRORHANDLING
#undef  HASSTRUCT
#undef HASMSSTRINGS
#undef HASMULTILINEFUNCTIONS
#undef HASEDITOR
#define HASTINYBASICINPUT
#undef HASLONGNAMES 
#undef HASHELP
#undef HASFULLINSTR
#undef HASLOOPOPT
#undef HASNUMSYSTEM
#undef HASPOWER
#undef HASUSRCALL
#endif


/* all features activated */
#ifdef BASICFULL
#define HASAPPLE1
#define HASARDUINOIO
#define HASFILEIO
#define HASTONE
#define HASPULSE
#define HASSTEFANSEXT
#define HASERRORMSG
#define HASFLOAT
#define HASGRAPH
#define HASDARTMOUTH
#define HASDARKARTS
#define HASIOT
#define HASMULTIDIM
#define HASTIMER
#define HASEVENTS
#define HASERRORHANDLING
#define HASSTRUCT
#define HASMSSTRINGS
#define HASMULTILINEFUNCTIONS
#define HASEDITOR
#define HASTINYBASICINPUT
#define HASLONGNAMES 
#define HASHELP
#define HASFULLINSTR
#define HASLOOPOPT
#define HASNUMSYSTEM
#endif

/* a simple BASIC with float support */
#ifdef BASICSIMPLEWITHFLOAT
#define HASAPPLE1
#define HASARDUINOIO
#undef HASFILEIO
#undef HASTONE
#undef HASPULSE
#define HASSTEFANSEXT
#define HASERRORMSG
#define HASFLOAT
#undef HASGRAPH
#define HASDARTMOUTH
#undef HASDARKARTS
#undef HASIOT
#undef HASMULTIDIM
#undef HASTIMER
#undef HASEVENTS
#undef HASERRORHANDLING
#undef HASSTRUCT
#undef HASMSSTRINGS
#undef HASMULTILINEFUNCTIONS
#undef HASEDITOR
#define HASTINYBASICINPUT
#undef HASLONGNAMES 
#undef HASHELP
#undef HASFULLINSTR
#undef HASLOOPOPT
#undef HASNUMSYSTEM
#undef HASPOWER
#undef HASUSRCALL
#endif

/* a Tinybasic with float support */
#ifdef BASICTINYWITHFLOAT
#define HASAPPLE1
#define HASARDUINOIO
#undef HASFILEIO
#undef HASTONE
#undef HASPULSE
#define HASSTEFANSEXT
#define HASERRORMSG
#define HASFLOAT
#undef HASGRAPH
#undef HASDARTMOUTH
#undef HASDARKARTS
#undef HASIOT
#undef HASMULTIDIM
#undef HASTIMER
#undef HASEVENTS
#undef HASERRORHANDLING
#undef HASSTRUCT
#undef HASMSSTRINGS
#undef HASMULTILINEFUNCTIONS
#undef HASEDITOR
#define HASTINYBASICINPUT
#undef HASLONGNAMES 
#undef HASHELP
#undef HASFULLINSTR
#undef HASLOOPOPT
#undef HASNUMSYSTEM
#undef HASPOWER
#undef HASUSRCALL
#endif

/* 
 *	Language feature dependencies
 * 
 * Dartmouth and darkarts needs the heap which is in Apple 1
 * IoT needs strings and the heap, also Apple 1
 * 
 * String arrays need multi dimensional capabilities
 *
 * The structured language set needs ELSE from STEFANSEXT
 *
 */
#if defined(HASMULTILINEFUNCTIONS)
#define HASDARTMOUTH
#endif

#if defined(HASDARTMOUTH) || defined(HASDARKARTS) || defined(HASIOT) || defined(HASMSSTRINGS)
#define HASAPPLE1
#endif

#if defined(HASSTRUCT)
#define HASSTEFANSEXT
#endif

/* MS strings also bring the full INSTR */
#if defined(HASMSSTRINGS)
#define HASFULLINSTR
#endif

/* dependencies on the hardware */
#if !defined(DISPLAYHASGRAPH) 
#undef HASGRAPH
#endif