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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
/*
 * Stefan's basic interpreter.  
 *
 * Playing around with frugal programming. 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]
 * 
 * Architectures and the definitions from the Arduino IDE. 
 * 
 * Arduino hardware settings , set here what you need or
 * use one of the predefined configurations below.
 * 
 * If HARDWAREHEURISTICS is set, some of the settings below 
 * are activated automatically for some platforms. If you want
 * to control ALL settings below manually, undef HARDWAREHEURISTICS 
 *
 * Input/output methods ARUINOPICOSERIAL, ARDUINOPS2
 *  ARDUINOUSBKBD, ARDUINOZX81KBD, ARDUINOI2CKBD, GIGAUSBKBD
 *	ARDUINOPRT, DISPLAYCANSCROLL, ARDUINOLCDI2C,
 *	ARDUINOTFT, ARDUINONOKIA51, ARDUINOILI9488,
 *  ARDUINOSSD1306, ARDUINOMCUFRIEND
 * Storage ARDUINOEEPROM, ARDUINOSD, ESPSPIFFS, RP2040LITTLEFS
 * storage ARDUINOEFS, SM32SDIO, ESP32FAT, ESPSDMMC
 * sensors ARDUINOWIRE, ARDUINOSIMPLEWIRE, ARDUINOSENSORS
 * network ARDUINORF24, ARDUNIOMQTT 
 * memory ARDUINOSPIRAM
 * real time clocks ARDUINORTC, ARDUINORTCEMULATION
 * 
 * Secial features
 *  ARDUINOPGMEEPROM: makes the EEPROM primary program store
 *  HASMSTAB: counts characters, prerequisite for MSTAB in languages
 *  BUILDIN: include buildin programs 
 *  
 * Instead of setting all this manually, you can use one of the 
 * predefined hardware models. They are stored in board and are sources
 * here later in the code to override some of the defaults. Custom configurations
 * coming with BASIC are: 
 * 
 *  dummy.h: 
 *      do nothing.
 *  avrlcd.h:
 *      a AVR system with a LCD shield
 *  avrmcufriend.h:
 *      a AVR system with a parallel TFT 
 *  wemosshield.h: 
 *      a ESP8266 UNO lookalike with a modified datalogger shield
 *      great hardware for small BASIC based IoT projects.
 *  megashield.h: 
 *      an Arduino Mega with Ethernet Shield optional keyboard 
 *      and i2c display
 *  megatft.h: 
 *  duetft.h:
 *      TFT 7inch screen systems, standalone
 *  nanoboard.h:
 *      Arduino Nano Every board with PS2 keyboard and sensor 
 *      kit.
 *  megaboard.h:
 *      A board for the MEGA with 64 kB RAM, SD Card, and real time
 *      clock.
 *  unoboard.h:
 *      A board for an UNO with 64kB memory and EEPROM disk
 *      fits into an UNO flash only with integer
 *  esp01board.h:
 *      ESP01 based board as a sensor / MQTT interface
 * rp2040board.h:
 *      A ILI9488 hardware design based on an Arduino connect RP2040.
 * rp2040board2.h:
 *      like the one above but based on the Pi Pico core
 * esp32board.h:
 *      same like above with an ESP32 core
 * mkboard.h:
 *      a digital signage and low energy board
 * tdeck.h: 
 *      the LILYGO T-Deck - not yet finished
 * ttgovga.h:
 *      the TTGO VGA 1.4 board with VGA output
 */
#define PREDEFINEDBOARD "boards/dummy.h"

/* undef this if you want to overide all defaults, then use the settings below */
#define HARDWAREHEURISTICS

/* 
 * These are the individual settings. Logic: 
 * PREDEFINEDBOARD is set, and some of the settings below are
 * activated automatically.
 * HARDWAREHEURISTICS is set, some of the settings below are
 * activated automatically depending on the hardware.
 * HARDWAREHEURISTICS is not set, all settings below are
 * have to be set manually.
 * 
 * Important: HARDWAREHEURISTICS is processed last in the code
 * so it can override all settings below.
 * 
 * In one sentence:
 * First PREDEFINEDBOARD, then manual settings, then HARDWAREHEURISTICS.
 */
/*
#undef ARDUINOPICOSERIAL 
#undef ARDUINOPS2
#undef ARDUINOUSBKBD
#undef ARDUINOZX81KBD
#undef ARDUINOI2CKBD
#undef GIGAUSBKBD
#undef ARDUINOPRT
#undef DISPLAYCANSCROLL
#undef ARDUINOLCDI2C
#undef ARDUINONOKIA51
#undef ARDUINOILI9488
#undef ARDUINOSSD1306
#undef ARDUINOMCUFRIEND
#undef ARDUINOEDP47
#undef ARDUINOGRAPHDUMMY
#undef LCDSHIELD
#undef ARDUINOTFT
#undef ARDUINOVGA
#undef TFTESPI
#undef ARDUINOEEPROM
#undef ARDUINOI2CEEPROM
#undef ARDUINOEFS
#undef ARDUINOSD
#undef ESPSDMMC
#undef ESPSPIFFS
#undef ESP32FAT
#undef RP2040LITTLEFS
#undef STM32SDIO
#undef GIGAUSBFS
#undef ARDUINORTC
#undef ARDUINORTCEMULATION
#undef ARDUINOTONEEMULATION
#undef ARDUINOWIRE
#undef ARDUINOSIMPLEWIRE
#undef ARDUINOWIRESLAVE
#undef ARDUINORF24
#undef ARDUINOETH
#undef ARDUINOMQTT 
#undef ARDUINOSENSORS
#undef ARDUINOSPIRAM 
#undef STANDALONE
#undef STANDALONESECONDSERIAL
*/
// #define ALTSERIAL Serial

/* we debug the runtime library and where the logging goes */
#define RTDEBUG 1
#define RTDEBUGSTREAM 1

/* the memory size, set to 0 means determine automatically 
 leaving it undefined means zero. setting it larger than 16 bit
 make the address_t 32bit */

#define MEMSIZE 0

/* experimental features, don't use unless you know the code */
/* 
 * this setting uses the EEPROM as program storage 
 * The idea is to create a virtual memory layout starting from 0 with the EEPROM
 * from elength() and then adding the BASIC RAM to it. himem and top need to be 
 * handled carefully. 
 */
#undef ARDUINOPGMEEPROM

/* IO control, emulate real tab by counting characters, on by default
  but overriden for very small boards - see hardware heuristics  */
#define HASMSTAB

/* VT52 settings, on by default but override further down for very 
  small boards, check the hardware heuristics section if you need VT52
  on small AVR boards */
#define HASVT52
#undef VT52WIRING 

/* 
 * Experimental BUILDIN feature, implemented as a filesystem. 
 * Buildin BASIC programs are stored in the flash memory of the Arduino.
 * They appear as files in the filesystem.
 */
#undef HASBUILDIN
/* this is the demo module */
#define BUILDINMODULE "buildin/buildin-games.h"
/* a small tutorial */
// #define BUILDINMODULE "buildin/buildin-tutorial.h"
/* test program for Arduinos */
// #define BUILDINMODULE "buildin/buildin-arduinotest.h"
/* a games module */
// #define BUILDINMODULE "buildin/buildin-games.h"

/* interrupts for the EVENT command, this is needed to use Arduino interrupts */
#define ARDUINOINTERRUPTS

/* 
 * handle the break condition in the background. 
 * Off by default but needed for some keyboards. 
 * On an UNO 170 bytes overhead if on and 5% 
 * performance loss. If any system runs background 
 * tasks anyway, better to switch it on.
 */
#undef BREAKINBACKGROUND

/* 
 * This code measures the fast ticker frequency in microseconds 
 * It counts the number of tokens drawn plus statements executed.
 */
#undef FASTTICKERPROFILE

/* the default EEPROM dummy size */
#define EEPROMSIZE 1024

/* 
 * PIN settings and I2C addresses for various hardware configurations
 *	used a few heuristics and then the hardware definitions above 
 *
 *	#define SDPIN sets the SD CS pin - can be left as a default for most HW configs
 *   	TTGO needs it as default definitions in the board file are broken
 *	#define PS2DATAPIN, PS2IRQPIN sets PS2 pin
 */

/* PS2 Keyboard pins for AVR - use one interrupt pin 2 and one date pin 
    5 not 4 because 4 conflicts with SDPIN of the standard SD shield */

#define PS2DATAPIN 3
#define PS2IRQPIN  2

/* 
 *  Pin settings for the ZX81 Keyboard
 *  first the 8 rows, then the 5 columns or the keyboard
 * 
 * MEGAs have many pins and default is to use the odd pins on the side
 * UNOs, NANOs, and others use the lower pins by default avoiding the 
 * pin 13 which is LED and doesn't work with standard schematics 
 */
#ifdef ARDUINO_AVR_MEGA2560
#define ZX81PINS 37, 35, 33, 31, 29, 27, 25, 23, 47, 45, 43, 41, 39
#else
#define ZX81PINS 7, 8, 9, 10, 11, 12, A0, A1, 2, 3, 4, 5, 6
#endif

/* Ethernet - 10 is the default */
/* #define ETHPIN 10 */

/* The Pretzelboard definitions for Software Serial, conflicts with SPI */
#define SOFTSERIALRX 11
#define SOFTSERIALTX 12

/* near field pin settings for CE and CSN*/
#define RF24CEPIN 8
#define RF24CSNPIN 9

/* use standard I2C pins almost always */
#undef SDA_PIN
#undef SCL_PIN

/*
 *	BREAKCHAR is the character stopping the program on Ardunios
 *  BREAKPIN can be set, it is a pin that needs to go to low to stop a BASIC program
 *    This should be done in hardware*.h
 *  BREAKSIGNAL can also be set, should be done in hardware*.h
 */
#define BREAKCHAR '#'

/* set this is you want pin 4 on low interrupting the interpreter */
/* #define BREAKPIN 4 */
#undef BREAKPIN

/* the primary serial stream aka serial aka sream 1 */
#ifndef ALTSERIAL
#define SERIALPORT Serial
#else 
#define SERIALPORT ALTSERIAL
#endif

/* the secondary serial port aka prt aka stream 4 */
#ifndef PRTSERIAL
#define PRTSERIAL Serial1
#endif

/* 
 *  this is soft SPI for SD cards on MEGAs using 
 *  pins 10-13, a patched SD library is needed 
 *  for this: https://github.com/slviajero/SoftSD
 *  only needed for MEGA boards with an UNO shield
 */
#define SOFTWARE_SPI_FOR_SD

/* 
 *  list of default i2c addresses
 *
 * some clock modules do have their EEPROM at 0x57. 
 * 0x050 this is the default lowest adress of standard EEPROMs
 * Configurable range is between 0x50 and 0x57 for modules with jumpers. 
 * Some clock modules do have their EEPROM at 0x57. 
 * 
 * Clock default for the size is 4096. Define your EFS EEPROM and I2C EEPROM
 * size here. One parameter set is for EFS and one parameter set is for 
 * plain serial EEPROMs.
 * 
 * RTCs are often at 0x68 
 */
#define EFSEEPROMADDR 0x050
/* #define EFSEEPROMSIZE 32768 */

#define RTCI2CADDR 0x068

/* the size of the plain I2C EEPROM, typically a clock */
/* #define I2CEEPROMADDR 0x057 */
/* #define I2CEEPROMSIZE 4096 */
/* definition for an external EEPROM */
#define I2CEEPROMADDR 0x050

/* is the I2C EEPROM buffered, left open here for the board file to decided - defaults to unbuffered */
/* #define ARDUINOI2CEEPROM_BUFFERED */

/* use the direct i2c code and bypass the Wire library on AVR 
 * default off here, board file and heuristics to decide, this 
 * is currently only implemented on ARDUINO_ARCH_AVR and tested on UNO 
 */
#undef ARDUINODIRECTI2C

/*
 * Sensor library code - configure your sensors here, will go to a 
* separate file in the future
 */
#ifdef ARDUINOSENSORS
#undef ARDUINODHT
#define DHTTYPE DHT22
#define DHTPIN 2
#define ARDUINOSHT
#define ARDUINOMQ2
#define MQ2PIN A0
#undef ARDUINOLMS6
#undef ARDUINOAHT
#undef ARDUINOBMP280
#undef ARDUINOBME280
#endif


#if defined(ARDUINOSHT) || defined(ARDUINOLMS6) || defined(ARDUINOAHT) || defined(ARDUINOBMP280) || defined(ARDUINOBME280)
#define ARDUINOSIMPLEWIRE
#endif

/*
 * Keyboard configuation code, currently only GERMAN and US are supported
 * This is used for PS2, FABGL and USB. USB very raw.
 * ZX81 is not supported with different languages, I only have a UK one.
 */

#define ARDUINOKBDLANG_GERMAN
//#define ARDUINOKBDLANG_US 

/*
 * The heuristics. These are things that normally would make sense on a 
 * board.
 */

/* 
 *  Buffer sizes depending on what we are doing.
 */

 #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_LGT8F)
 /* the small memory model with shallow stacks and small buffers */
 #define BUFSIZE     80
 #define STACKSIZE   15
 #define GOSUBDEPTH  4
 #define FORDEPTH    4
 #define LINECACHESIZE 4
 #else 
 /* the for larger microcontrollers */
 #define BUFSIZE     128
 #define STACKSIZE   64
 #define GOSUBDEPTH  8
 #define FORDEPTH    8
 #define LINECACHESIZE 16
 #endif
 
#ifdef HARDWAREHEURISTICS
/* UNOS are very common. Small memory, we put the program into EEPROM and make everything small */
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) 
#define ARDUINOEEPROM
#define ARDUINOPICOSERIAL
#define ARDUINOPGMEEPROM
#define ARDUINODIRECTI2C
#undef  ARDUINOI2CEEPROM_BUFFERED
#undef  LINECACHESIZE
#undef  HASMSTAB
#define MEMSIZE 512
#endif
/* der Pro */
#if defined(ARDUINO_AVR_PRO)
#define ARDUINOEEPROM
#define ARDUINOPGMEEPROM
#undef  LINECACHESIZE
#undef  HASMSTAB
#undef  HASVT52
#define MEMSIZE 768
#endif
/* on a DUEMILA we allocate just as little main memory as possible, currenly not working because sketch too big 
 * needs to be checked */
#if defined(ARDUINO_AVR_DUEMILANOVE)
#define ARDUINOEEPROM
#define ARDUINOPICOSERIAL
#define ARDUINOPGMEEPROM
#undef  LINECACHESIZE
#undef  HASMSTAB
#define MEMSIZE 128
#undef  HASVT52
#endif
/* tested for LTQF32 Mini EVB - very low memory as core needs a lot */
#if defined(ARDUINO_ARCH_LGT8F)
#define ARDUINOEEPROM
#define ARDUINOPICOSERIAL
#undef LINECACHESIZE
#undef HASMSTAB
#define MEMSIZE 256
#define ARDUINOPGMEEPROM
#undef HASVT52
#endif
/* all AVR 8 bit boards have an EEPROM (most probably) */
#if defined(ARDUINO_ARCH_AVR)
#define ARDUINOEEPROM
#endif
/* megaAVR boards have an EEPROM */
#if defined(ARDUINO_ARCH_MEGAAVR)
#define ARDUINOEEPROM
#endif
/* LEONARDO boards */
#if defined(ARDUINO_AVR_LEONARDO)
/* to be done */ 
#endif
/* all ESPs best are compiled with ESPSPIFFS predefined */
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#define ESPSPIFFS
#endif
/* all ESPs best have EEPROM emulation */
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#define ARDUINOEEPROM
#define ESPSPIFFS
#endif
/* all RP2040 boards best are compiled with RP2040LITTLEFS predefined */
#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED_RP2040)
#define RP2040LITTLEFS
#endif
/* use the EEPROM dummy of the NRESESA boards */
#if defined(ARDUINO_ARCH_RENESAS)
#define ARDUINOEEPROM
#endif
/* for XMC there is an EEPROM emulation, which needs: https://github.com/slviajero/XMCEEPROMLib */
#if defined(ARDUINO_ARCH_XMC)
#define ARDUINOEEPROM
#endif
/* the China Nano clones. Super fast but with very small flash. */ 
#if defined(ARDUINO_ARCH_LGT8F)
#undef HASMSTAB
#endif
#endif

/*
 * Now source the the hardware models if this is set.
 */
#ifdef PREDEFINEDBOARD
#include PREDEFINEDBOARD
#endif

/*
 * Here, dependencies are handled. Some settings require others to be set
 * first. 
 * 
 * Examples:
 *  Many filesystems and displays need SPI.
 *  Some components need Wire. 
 *  Some platforms do not have tone, so we need to emulate it.
 */

/* 
 *  DUE has no tone, we switch to emulation mode automatically.
 */
#ifdef ARDUINO_SAM_DUE
#define ARDUINOTONEEMULATION
#endif

/*
 * Some settings, defaults, and dependencies
 * 
 * HASWIRE is set to start wire. Some libraries do this again.
 * 
 * Handling Wire and SPI is tricky as some of the libraries 
 * also include and start SPI and Wire code. 
 * 
 * HASIMPLEWIRE avoids the overhead of importing the entire 
 * filesystem code. It only activates plain Wire and provides
 * the WIRE command in basic.
 */

/*
 * Safety net for ARDUINODIRECTI2C, architectures that are 
 * not AVR 8 bit and do not have TWDR are not supported.
 */
#if !defined(ARDUINO_ARCH_AVR) || !defined(TWDR)
#undef ARDUINODIRECTI2C
#endif

/* a clock needs wire */
#ifdef ARDUINORTC
#define HASSIMPLEWIRE
#endif

/* a display needs wire */
#if defined(ARDUINOLCDI2C) || defined(ARDUINOSSD1306) 
#define HASSIMPLEWIRE
#endif

/* EEPROM storage needs wire */
#if defined(ARDUINOEFS)
#define HASSIMPLEWIRE
#endif

/* external EEPROMs also need wire */
#if defined(ARDUINOI2CEEPROM)
#define HASSIMPLEWIRE
#endif

/* external EEPROM buffered needs full wire support, because EFS not ported */
#if defined(ARDUINOI2CEEPROM) && defined(ARDUINOI2CEEPROM_BUFFERED)
#define HASWIRE
#endif

/* plain Wire support also needs wire ;-) */
#if defined(ARDUINOWIRE) || defined(ARDUINOWIRESLAVE)
#define HASWIRE
#endif

/* and I2C Keyboard needs wire */
#if defined(ARDUINOI2CKBD)
#define HASSIMPLEWIRE
#endif

/* the BASIC command/function WIRE */
#if defined (ARDUINOSIMPLEWIRE)
#define HASSIMPLEWIRE
#endif

/* radio needs SPI */
#if defined(ARDUINORF24)
#define ARDUINOSPI
#endif

/* a filesystem needs SPI */
#if defined(ARDUINOSD) || defined(ESPSPIFFS) || defined(ESP32FAT)
#define ARDUINOSPI
#endif

/* networking may need SPI */
#if defined(ARDUINOMQTT)
#define ARDUINOSPI
#endif

/* the NOKIA and ILI9488 display needs SPI */
#if defined(ARDUINONOKIA51) || defined(ARDUINOILI9488) || defined(TFTESPI)
#define ARDUINOSPI
#endif

/* the RAM chips */
#if defined(ARDUINOSPIRAM)
#define ARDUINOSPI
#endif

/* Networking and keyboards need the background task capability */
#if defined(ARDUINOMQTT) || defined(ARDUINOETH) || defined(ARDUINOUSBKBD) || defined(ARDUINOZX81KBD) || defined(ARDUINOI2CKBD) || defined(GIGAUSBKBD)
#define BASICBGTASK
#endif

/* the ESP8266 needs to run the background task calls for the scheduler */
#if defined(ARDUINO_ARCH_ESP8266)
#define BASICBGTASK
#endif

/* Break in background needs background tasks as well */
#if defined(BREAKINBACKGROUND)
#define BASICBGTASK
#endif

/* picoserial is not a available on many platforms */
#ifdef ARDUINOPICOSERIAL
#ifndef UCSR0A
#undef ARDUINOPICOSERIAL
#endif
#endif

/* 
 *  incompatibilities and library stuff
 */
/* these platforms have no EEPROM and no emulation built-in */
#if defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED_GIGA)
#undef ARDUINOEEPROM
#endif

/*
 * SD filesystems with the standard SD driver
 * for MEGA 256 a soft SPI solution is needed 
 * if standard shields are used, this is a patched
 * SD library https://github.com/slviajero/SoftSD
 */
#ifdef ARDUINOSD
#define FILESYSTEMDRIVER
#endif

/*
 * ESPSPIFFS tested on ESP8266 and ESP32
 * supports formating in BASIC
 */ 
#ifdef ESPSPIFFS
#define FILESYSTEMDRIVER
#endif

/*
 * ESP32FAT tested on ESP32
 * supports formating in BASIC
 */ 
#ifdef ESP32FAT
#define FILESYSTEMDRIVER
#endif

/*
 * RP2040 internal filesystem 
 * This is test code from https://github.com/slviajero/littlefs
 * and the main branch is actively developed
 */
#ifdef RP2040LITTLEFS
#define FILESYSTEMDRIVER
#endif

/*
 * STM32 SDIO driver for he SD card slot of the STM32F4 boards (and others)
 */
#ifdef STM32SDIO 
#define FILESYSTEMDRIVER
#endif

/* 
 *  The USB filesystem of the GIGA board
 */
#ifdef GIGAUSBFS
#define FILESYSTEMDRIVER
#define NEEDSUSB
#endif

/*
 * external flash file systems override internal filesystems
 * currently BASIC can only have one filesystem
 */ 
#ifdef ARDUINOSD
#undef ESPSPIFFS
#undef ESP32FAT
#undef RP2040LITTLEFS
#undef GIAGUSBFS
#endif

/*
 * support for external EEPROMs as filesystem
 * overriding all other filessystems. This is a minimalistic
 * filesystem meant for very small systems with not enough 
 * memory for real filesystems
 * https://github.com/slviajero/EepromFS
 */ 
#ifdef ARDUINOEFS
#undef ESPSPIFFS
#undef ESP32FAT
#undef RP2040LITTLEFS
#undef ARDUINOSD
#undef STM32SDIO
#undef GIGAUSBFS
#define FILESYSTEMDRIVER
#endif

/*
 * The build in file system for read only programs, only 
 * if there is no other file system present
 */
#if defined(HASBUILDIN)
#define FILESYSTEMDRIVER
#include BUILDINMODULE
#endif

/*
 * Software SPI only on Mega2560
 */
#ifndef ARDUINO_AVR_MEGA2560
#undef SOFTWARE_SPI_FOR_SD
#endif

/*
 * I used these two articles 
 * https://randomnerdtutorials.com/esp8266-deep-sleep-with-arduino-ide/
 * https://randomnerdtutorials.com/esp32-deep-sleep-arduino-ide-wake-up-sources/
 * for this very simple implementation - needs to be improved (pass data from sleep
 * state to sleep state via EEPROM)
 */
/* this is done only here now to make sure HASCLOCK is set properly */ 

#if defined(ARDUINO_ARCH_SAMD) 
#define HASBUILTINRTC
#endif

/* STM32duino have the same structure */
#if defined(ARDUINO_ARCH_STM32)
#define HASBUILTINRTC
#endif

/* the NRENESA board have a buildin RTC as well */
#if defined(ARDUINO_ARCH_RENESAS)
#define HASBUILTINRTC
#endif

/* 
 * global variables for a standard LCD shield. 
 * Includes the standard Arduino LiquidCrystal library
 */
#ifdef LCDSHIELD 
#define DISPLAYDRIVER
#define HASKEYPAD
#undef DISPLAYHASCOLOR
#undef DISPLAYHASGRAPH
#endif
 
/* 
 * A LCD display connnected via I2C, uses the standard 
 * Arduino I2C display library.
 */ 
#ifdef ARDUINOLCDI2C
#define DISPLAYDRIVER
#undef DISPLAYHASCOLOR
#undef DISPLAYHASGRAPH
#endif

/* 
 * A Nokia 5110 with ug8lib2 - can scroll quite well
 * https://github.com/olikraus/u8g2/wiki/u8g2reference
 * This is a buffered display it has a dspupdate() function 
 * it also needs to call dspgraphupdate() after each graphic 
 * operation
 *
 * default PIN settings here are for ESP8266, using the standard 
 * SPI SS for 15 for CS/CE, and 0 for DC, 2 for reset
 *
 */ 
#ifdef ARDUINONOKIA51
#define DISPLAYDRIVER
#define DISPLAYPAGEMODE
#undef DISPLAYHASCOLOR /* display driver not color aware for this display */
#define DISPLAYHASGRAPH
#endif

/*
 * 4.7 inch epaper displays are derived from the NOKIA51 code, no grayscales 
 * at the moment. Forcing the font into rectangles and hoping this works.
 * 
 * Epapers bypass the display driver here and use a graphics based display 
 * mode instead
 */
#ifdef ARDUINOEDP47
#define GRAPHDISPLAYDRIVER
#define DISPLAYPAGEMODE
#undef DISPLAYHASCOLOR /* display driver not color aware for this display */
#define DISPLAYHASGRAPH
#endif
 

/* 
 * Small SSD1306 OLED displays with I2C interface
 * This is a buffered display it has a dspupdate() function 
 * it also needs to call dspgraphupdate() after each graphic 
 * operation
 */ 
#ifdef ARDUINOSSD1306
#define DISPLAYDRIVER
#define DISPLAYPAGEMODE
#undef DISLAYHASCOLOR /* display driver not color aware for this display */
#define DISPLAYHASGRAPH
#endif

/* 
 * A ILI9488 with Jarett Burkets version of Adafruit GFX and patches
 * by Stefan Lenz
 * currently only slow software scrolling implemented in BASIC
 * 
 * https://github.com/slviajero/ILI9488
 * 
 * we use 9, 8, 7 as CS, CE, RST by default and A7 for the led brightness control
 */ 
 
#ifdef ARDUINOILI9488
#define DISPLAYDRIVER
#define DISPLAYHASCOLOR
#define DISPLAYHASGRAPH
#endif

/* 
 * A MCUFRIEND parallel port display for the various tft shields 
 * This implementation is mainly for Arduino MEGA
 * 
 * currently only slow software scrolling implemented in BASIC
 * 
 */ 

#ifdef ARDUINOMCUFRIEND
#define DISPLAYDRIVER
#define DISPLAYHASCOLOR
#define DISPLAYHASGRAPH
#endif

/*
 * The driver for the TFT_eSPI graphics of the T-Deck from Lilygo
 * currently not finished 
 */

#ifdef TFTESPI
#define DISPLAYDRIVER
#define DISPLAYHASCOLOR
#define DISPLAYHASGRAPH
#endif

/* 
 * A no operations graphics dummy  
 * Tests the BASIC side of the graphics code without triggering 
 * any output
 */ 
#ifdef ARDUINOGRAPHDUMMY
#define DISPLAYDRIVER
#undef DISPLAYHASCOLOR
#define DISPLAYHASGRAPH
#endif

/*
 * SD1963 TFT display code with UTFT.
 * Tested witth SD1963 800*480 board. 
 *	it is mainly intended for a MEGA or DUE as a all in one system
 *	this is for a MEGA shield and the CTE DUE shield, for the due 
 *	you need to read the comment in Arduino/libraries/UTFT/hardware/arm
 *	HW_ARM_defines.h -> uncomment the DUE shield
 * See also 
  * https://github.com/slviajero/tinybasic/wiki/Projects:-4.-A-standalone-computer-with-a-TFT-screen-based-on-a-DUE
 */
#ifdef ARDUINOTFT
#define DISPLAYDRIVER
#define DISPLAYHASCOLOR 
#define DISPLAYHASGRAPH
#endif

/* 
 * Keyboard code for either the Fablib Terminal class or 
 * PS2Keyboard - please note that you need the ESP patched 
 * version here as mentioned above
 * 
 * sets HASKEYBOARD to inform basic about this capability
 * 
 * keyboards can implement 
 * 	kbdbegin()
 * they need to provide
 * 	kbdavailable(), kbdread(), kbdcheckch()
 * the later is for interrupting running BASIC code
 */
#if defined(ARDUINO_TTGO_T7_V14_Mini32) && defined(ARDUINOVGA)
#define PS2FABLIB
#define HASKEYBOARD
#define DISPLAYHASCOLOR
#define DISPLAYHASGRAPH
#endif 

#if defined(ARDUINO) && defined(ARDUINOPS2)
#define PS2KEYBOARD
#define HASKEYBOARD
#endif 

#if defined(ARDUINO) && defined(ARDUINOUSBKBD)
#define HASKEYBOARD
#define USBKEYBOARD
#endif

#if defined(ARDUINOZX81KBD)
#define HASKEYBOARD
#define ZX81KEYBOARD
#endif

/* BREAKINBACKGROUND is needed here to avoid slowdown, probably also for the other keyboards */
#if defined(ARDUINOI2CKBD)
#define HASKEYBOARD
#define I2CKEYBOARD
#define BREAKINBACKGROUND
#endif

/* set the HASKEYBOARD feature to tell BASIC about it */
#if defined(GIGAUSBKBD)
#define HASKEYBOARD
#define GIGAUSBKEYBOARD
#endif

/* 
 * Arduino Real Time clock. The interface here offers the values as number_t 
 * combining all values. 
 * 
 * The code does not use an RTC library any more all the rtc support is 
 * builtin now. 
 * 
 * A clock must activate the macro #define HASCLOCK to make the clock 
 * available in BASIC.
 * 
 * The following software models are supported
 *  - Built-in clocks of STM32 and MKR and NRESAS and XIAO are supported by default 
 *      as RTCZero type code
 *  - Built-in clocks of ESP32 are supported by default with a time structure type code
 *  - Built-in clocks of GIGA the same as ESP32
 *  - I2C clocks can be activated: DS1307, DS3231, and DS3232
 *  - A Real Time Clock emulation is possible using millis()
 * 
 * rtcget accesses the internal registers of the clock. 
 * Registers 0-6 are bcd transformed to return 
 * seconds, minutes, hours, day of week, day, month, year
 * 
 * On I2C clocks registers 7-255 are returned as memory cells
 */

 #if defined(ARDUINORTC) || defined(HASBUILTINRTC) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINORTCEMULATION) || defined(ARDUINO_ARCH_MBED_GIGA)
 #define HASCLOCK
 #endif

/* 
 * External EEPROM is handled through an EFS filesystem object  
 * see https://github.com/slviajero/EepromFS 
 * for details. Here the most common parameters are set as a default.
*/
#ifdef ARDUINOEFS
#undef ARDUINOI2CEEPROM
#endif

/* 
 *  Tell BASIC we have a second serial port
 */
#ifdef ARDUINOPRT
#define HASSERIAL1
#endif

/* 
 *  Tell BASIC we have a radio adapter
 */
#ifdef ARDUINORF24
#define HASRF24
#endif

/* 
 *  Tell BASIC we have MQTT and make sure one low level
 *  interface is available
 */
#ifdef ARDUINOMQTT
#define HASMQTT
#ifndef ARDUINOETH
#define ARDUINOWIFI
#endif
#endif

/* 
 *  handling the PROGMEM macros 
 */

 /*
 * if the PROGMEM macro is define we compile on the Arduino IDE
 *  we undef all hardware settings otherwise a little odd
 */
#ifdef ARDUINO_ARCH_MBED
#define PROGMEM
#endif

#ifdef PROGMEM
#define ARDUINOPROGMEM
#else
#undef ARDUINOPROGMEM
#define PROGMEM
#endif

/* on XMC we circumvent progmem */
#ifdef ARDUINO_ARCH_XMC
#undef ARDUINOPROGMEM
#define PROGMEM
#endif


/* the code to address EEPROMs directly */
/* only AVR controllers are tested with this, don't use elsewhere, there are multiple bugs */
#if defined(ARDUINOPGMEEPROM) & ! ( defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_LGT8F) )
#undef ARDUINOPGMEEPROM
#endif

#ifdef ARDUINOPGMEEPROM
#define USEMEMINTERFACE
#define EEPROMMEMINTERFACE
#else 
#undef EEPROMMEMINTERFACE
#endif

/* the SPI RAM interface */
#ifdef ARDUINOSPIRAM
#define USEMEMINTERFACE
#define SPIRAMINTERFACE
#endif

/* 
 * to handle strings in situations with a memory interface two more buffers are 
 * needed they store intermediate results of string operations. The buffersize 
 * limits the maximum string length indepents of how big strings are set. 
 * 
 * default is 128, on an MEGA 512 is possible
 */
#ifdef ARDUINO_AVR_MEGA2560
#define SPIRAMSBSIZE 512
#else
#define SPIRAMSBSIZE 128
#endif


/*
 * Does the platform has command line args and do we want to use them 
 * Arduinos don't have them
 */
#undef HASARGS

/*
 * How restrictive are we on function recursive calls to protect the stack
 * On 8 bit Arduinos this needs to be limited strictly
 */
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) || defined(ARDUINO_ARCH_LGT8F) || defined(ARDUINO_AVR_PRO)
#define FNLIMIT 4
#elif defined(ARDUINO_ARCH_ESP8266)
#define FNLIMIT 64
#elif defined(ARDUINO_ARCH_ESP32)
#define FNLIMIT 128
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED_RP2040)
#define FNLIMIT 128
#elif defined(ARDUINO_ARCH_SAM) && defined(ARDUINO_ARCH_SAMD)
#define FNLIMIT 64
#elif defined(ARDUINO_ARCH_XMC)
#define FNLIMIT 64
#elif defined(ARDUINO_ARCH_SMT32)
#define FNLIMIT 128
#elif defined(ARDUINO_ARCH_RENESAS)
#define FNLIMIT 32
#else
#define FNLIMIT 128
#endif

/* 
 *  here the runtime environment makes a good guess which 
 *  language can be supported by the boards. This is tricky
 *  it may not always work. 
 *  
 *  MEGAAVR does BASICFULL but this leaves little room for hardware drivers
 *  LEONARDO currently broken, to much flash allocated.
 */
#if defined(ARDUINO_ARCH_AVR)
#if defined(ARDUINO_AVR_DUEMILANOVE)
#define BASICPALOALTO
#endif
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_PRO)
#define BASICSIMPLE
#endif
#if defined(ARDUINO_AVR_LEONARDO)
#define BASICSMALL
#endif
#if defined(ARDUINO_AVR_MEGA2560)
#define BASICFULL
#endif
#elif defined(ARDUINO_ARCH_LGT8F)
#define BASICSIMPLE
#elif defined(ARDUINO_ARCH_MEGAAVR)
#define BASICFULL
#elif defined(ARDUINO_ARCH_ESP8266)
#define BASICFULL
#elif defined(ARDUINO_ARCH_ESP32)
#define BASICFULL
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED_RP2040)
#define BASICFULL
#elif defined(ARDUINO_ARCH_SAM) && defined(ARDUINO_ARCH_SAMD)
#define BASICFULL
#elif defined(ARDUINO_ARCH_XMC)
#define BASICFULL
#elif defined(ARDUINO_ARCH_SMT32)
#define BASICFULL
#elif defined(ARDUINO_ARCH_RENESAS)
#define BASICFULL
#else
#define BASICFULL
#endif