-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp32forth63-touch.ino
1761 lines (1672 loc) · 46.8 KB
/
esp32forth63-touch.ino
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
/ +++++++++++++++ esp32forth.ino with TOUCH Forth word added ++++++++++++++++++++++
/ ESP32forth - Adding functionality with existing C Arduino-ESP32 libraries
/ Date: 2020-01-03
/ Name: Christian Hinse
/*******************************************************************************/
/* esp32Forth, Version 6.3 : for NodeMCU ESP32S */
/*******************************************************************************/
/* 16jun25cht _63 Added TOUCH word for touch PAD. */
/* Also corrected peeek to peek. C.Hinse 2020-01-02 */
/* 16jun25cht _63 */
/* web server */
/* 16jun19cht _62 */
/* structures */
/* 14jun19cht _61 */
/* macro assembler with labels */
/* 10may19cht _54 */
/* robot tests */
/* 21jan19cht _51 */
/* 8 channel electronic organ */
/* 15jan19cht _50 */
/* Clean up for AIR robot */
/* 03jan19cht _47-49 */
/* Move to ESP32 */
/* 07jan19cht _46 */
/* delete UDP */
/* 03jan19cht _45 */
/* Move to NodeMCU ESP32S Kit */
/* 18jul17cht _44 */
/* Byte code sequencer */
/* 14jul17cht _43 */
/* Stacks in circular buffers */
/* 01jul17cht _42 */
/* Compiled as an Arduino sketch */
/* 20mar17cht _41 */
/* Compiled as an Arduino sketch */
/* Follow the ceForth model with 64 primitives */
/* Serial Monitor at 115200 baud */
/* Send and receive UDP packets in parallel with Serial Monitor */
/* Case insensitive interpreter */
/* data[] must be filled with rom42.h eForth dictionary */
/* 22jun17cht */
/* Stacks are 256 cell circular buffers, with byte pointers R and S */
/* All references to R and S are forced to (unsigned char) */
/* All multiply-divide words cleaned up */
/******************************************************************************/
#include "SPIFFS.h"
#include <WiFi.h>
#include <WebServer.h>
// #include <esp32-hal-touch.h>
const char* ssid = "VIDEOTRON3347";//type your ssid
const char* pass = "tarifa-475";//type your password
// static ip address
IPAddress ip(10,0,0,99);
IPAddress gateway(10,0,0,1);
IPAddress subnet(255,255,255,0);
WebServer server(80);
/******************************************************************************/
/* esp32Forth_51 */
/******************************************************************************/
# define FALSE 0
# define TRUE -1
# define LOGICAL ? TRUE : FALSE
# define LOWER(x,y) ((unsigned long)(x)<(unsigned long)(y))
# define pop top = stack[(unsigned char)S--]
# define push stack[(unsigned char)++S] = top; top =
# define popR rack[(unsigned char)R--]
# define pushR rack[(unsigned char)++R]
long rack_main[256] = {0};
long stack_main[256] = {0};
long rack_background[256] = {0};
long stack_background[256] = {0};
__thread long *rack;
__thread long *stack;
__thread unsigned char R, S, bytecode ;
__thread long* Pointer ;
__thread long P, IP, WP, top, links, len ;
uint8_t* cData ;
__thread long long int d, n, m ;
String HTTPin;
String HTTPout;
TaskHandle_t background_thread;
int BRAN=0,QBRAN=0,DONXT=0,DOTQP=0,STRQP=0,TOR=0,ABORQP=0;
//#include "rom_54.h" /* load dictionary */
long data[16000] = {};
int IMEDD=0x80;
int COMPO=0x40;
void HEADER(int lex, char seq[]) {
P=IP>>2;
int i;
int len=lex&31;
data[P++]=links;
IP=P<<2;
Serial.println();
Serial.print(links,HEX);
for (i=links>>2;i<P;i++)
{Serial.print(" ");Serial.print(data[i],HEX);}
links=IP;
cData[IP++]=lex;
for (i=0;i<len;i++)
{cData[IP++]=seq[i];}
while (IP&3) {cData[IP++]=0;}
Serial.println();
Serial.print(seq);
Serial.print(" ");
Serial.print(IP,HEX);
}
int CODE(int len, ... ) {
int addr=IP;
int s;
va_list argList;
va_start(argList, len);
for(; len;len--) {
s= va_arg(argList, int);
cData[IP++]=s;
Serial.print(" ");
Serial.print(s,HEX);
}
va_end(argList);
return addr;
}
int COLON(int len, ... ) {
int addr=IP;
P=IP>>2;
data[P++]=6; // dolist
va_list argList;
va_start(argList, len);
Serial.println();
Serial.print(addr,HEX);
Serial.print(" ");
Serial.print(6,HEX);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
return addr;
}
int LABEL(int len, ... ) {
int addr=IP;
P=IP>>2;
va_list argList;
va_start(argList, len);
Serial.println();
Serial.print(addr,HEX);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
return addr;
}
void BEGIN(int len, ... ) {
P=IP>>2;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" BEGIN ");
pushR=P;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void AGAIN(int len, ... ) {
P=IP>>2;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" AGAIN ");
data[P++]=BRAN;
data[P++]=popR<<2;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void UNTIL(int len, ... ) {
P=IP>>2;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" UNTIL ");
data[P++]=QBRAN;
data[P++]=popR<<2;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void WHILE(int len, ... ) {
P=IP>>2;
int k;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" WHILE ");
data[P++]=QBRAN;
data[P++]=0;
k=popR;
pushR=(P-1);
pushR=k;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void REPEAT(int len, ... ) {
P=IP>>2;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" REPEAT ");
data[P++]=BRAN;
data[P++]=popR<<2;
data[popR]=P<<2;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void IF(int len, ... ) {
P=IP>>2;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" IF ");
data[P++]=QBRAN;
pushR=P;
data[P++]=0;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void ELSE(int len, ... ) {
P=IP>>2;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" ELSE ");
data[P++]=BRAN;
data[P++]=0;
data[popR]=P<<2;
pushR=P-1;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void THEN(int len, ... ) {
P=IP>>2;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" THEN ");
data[popR]=P<<2;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void FOR(int len, ... ) {
P=IP>>2;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" FOR ");
data[P++]=TOR;
pushR=P;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void NEXT(int len, ... ) {
P=IP>>2;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" NEXT ");
data[P++]=DONXT;
data[P++]=popR<<2;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void AFT(int len, ... ) {
P=IP>>2;
int k;
Serial.println();
Serial.print(IP,HEX);
Serial.print(" AFT ");
data[P++]=BRAN;
data[P++]=0;
k=popR;
pushR=P;
pushR=P-1;
va_list argList;
va_start(argList, len);
for(; len;len--) {
int j=va_arg(argList, int);
data[P++]=j;
Serial.print(" ");
Serial.print(j,HEX);
}
IP=P<<2;
va_end(argList);
}
void DOTQ(char seq[]) {
P=IP>>2;
int i;
int len=strlen(seq);
data[P++]=DOTQP;
IP=P<<2;
cData[IP++]=len;
for (i=0;i<len;i++)
{cData[IP++]=seq[i];}
while (IP&3) {cData[IP++]=0;}
Serial.println();
Serial.print(IP,HEX);
Serial.print(" ");
Serial.print(seq);
}
void STRQ(char seq[]) {
P=IP>>2;
int i;
int len=strlen(seq);
data[P++]=STRQP;
IP=P<<2;
cData[IP++]=len;
for (i=0;i<len;i++)
{cData[IP++]=seq[i];}
while (IP&3) {cData[IP++]=0;}
Serial.println();
Serial.print(IP,HEX);
Serial.print(" ");
Serial.print(seq);
}
void ABORQ(char seq[]) {
P=IP>>2;
int i;
int len=strlen(seq);
data[P++]=ABORQP;
IP=P<<2;
cData[IP++]=len;
for (i=0;i<len;i++)
{cData[IP++]=seq[i];}
while (IP&3) {cData[IP++]=0;}
Serial.println();
Serial.print(IP,HEX);
Serial.print(" ");
Serial.print(seq);
}
void CheckSum() {
int i;
char sum=0;
Serial.println();
Serial.printf("%4x ",IP);
for (i=0;i<32;i++) {
sum += cData[IP];
Serial.printf("%2x",cData[IP++]);
}
Serial.printf(" %2x",sum);
}
/******************************************************************************/
/* ledc */
/******************************************************************************/
/* LEDC Software Fade */
// use first channel of 16 channels (started from zero)
#define LEDC_CHANNEL_0 0
// use 13 bit precission for LEDC timer
#define LEDC_TIMER_13_BIT 13
// use 5000 Hz as a LEDC base frequency
#define LEDC_BASE_FREQ 5000
// fade LED PIN (replace with LED_BUILTIN constant for built-in LED)
#define LED_PIN 5
int brightness = 255; // how bright the LED is
// Arduino like analogWrite
// value has to be between 0 and valueMax
void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) {
// calculate duty, 8191 from 2 ^ 13 - 1
uint32_t duty = (8191 / valueMax) * min(value, valueMax);
// write duty to LEDC
ledcWrite(channel, duty);
}
/******************************************************************************/
/* PRIMITIVES */
/******************************************************************************/
void next(void)
{ P = data[IP>>2];
IP += 4;
WP = P+4; }
void accep()
/* WiFiClient */
{ while (Serial.available()) {
len = Serial.readBytes(cData, top); }
Serial.write(cData, len);
top = len;
}
void qrx(void)
{ while (Serial.available() == 0) {};
push Serial.read();
push -1; }
void txsto(void)
{ Serial.write( (unsigned char) top);
char c=top;
HTTPout += c ;
pop;
}
void docon(void)
{ push data[WP>>2]; }
void dolit(void)
{ push data[IP>>2];
IP += 4;
next(); }
void dolist(void)
{ rack[(unsigned char)++R] = IP;
IP = WP;
next(); }
void exitt(void)
{ IP = (long) rack[(unsigned char)R--];
next(); }
void execu(void)
{ P = top;
WP = P + 4;
pop; }
void donext(void)
{ if(rack[(unsigned char)R]) {
rack[(unsigned char)R] -= 1 ;
IP = data[IP>>2];
} else { IP += 4; (unsigned char)R-- ; }
next(); }
void qbran(void)
{ if(top == 0) IP = data[IP>>2];
else IP += 4; pop;
next(); }
void bran(void)
{ IP = data[IP>>2];
next(); }
void store(void)
{ data[top>>2] = stack[(unsigned char)S--];
pop; }
void at(void)
{ top = data[top>>2]; }
void cstor(void)
{ cData[top] = (unsigned char) stack[(unsigned char)S--];
pop; }
void cat(void)
{ top = (long) cData[top]; }
void rpat(void) {}
void rpsto(void) {}
void rfrom(void)
{ push rack[(unsigned char)R--]; }
void rat(void)
{ push rack[(unsigned char)R]; }
void tor(void)
{ rack[(unsigned char)++R] = top; pop; }
void spat(void) {}
void spsto(void) {}
void drop(void)
{ pop; }
void dup(void)
{ stack[(unsigned char)++S] = top; }
void swap(void)
{ WP = top;
top = stack[(unsigned char)S];
stack[(unsigned char)S] = WP; }
void over(void)
{ push stack[(unsigned char)(S-1)]; }
void zless(void)
{ top = (top < 0) LOGICAL; }
void andd(void)
{ top &= stack[(unsigned char)S--]; }
void orr(void)
{ top |= stack[(unsigned char)S--]; }
void xorr(void)
{ top ^= stack[(unsigned char)S--]; }
void uplus(void)
{ stack[(unsigned char)S] += top;
top = LOWER(stack[(unsigned char)S], top); }
void nop(void)
{ next(); }
void qdup(void)
{ if(top) stack[(unsigned char)++S] = top ; }
void rot(void)
{ WP = stack[(unsigned char)(S-1)];
stack[(unsigned char)(S-1)] = stack[(unsigned char)S];
stack[(unsigned char)S] = top;
top = WP; }
void ddrop(void)
{ drop(); drop(); }
void ddup(void)
{ over(); over(); }
void plus(void)
{ top += stack[(unsigned char)S--]; }
void inver(void)
{ top = -top-1; }
void negat(void)
{ top = 0 - top; }
void dnega(void)
{ inver();
tor();
inver();
push 1;
uplus();
rfrom();
plus(); }
void subb(void)
{ top = stack[(unsigned char)S--] - top; }
void abss(void)
{ if(top < 0)
top = -top; }
void great(void)
{ top = (stack[(unsigned char)S--] > top) LOGICAL; }
void less(void)
{ top = (stack[(unsigned char)S--] < top) LOGICAL; }
void equal(void)
{ top = (stack[(unsigned char)S--] == top) LOGICAL; }
void uless(void)
{ top = LOWER(stack[(unsigned char)S], top) LOGICAL; S--; }
void ummod(void)
{ d = (long long int)((unsigned long)top);
m = (long long int)((unsigned long)stack[(unsigned char) S]);
n = (long long int)((unsigned long)stack[(unsigned char) (S - 1)]);
n += m << 32;
pop;
top = (unsigned long)(n / d);
stack[(unsigned char) S] = (unsigned long)(n%d); }
void msmod(void)
{ d = (signed long long int)((signed long)top);
m = (signed long long int)((signed long)stack[(unsigned char) S]);
n = (signed long long int)((signed long)stack[(unsigned char) S - 1]);
n += m << 32;
pop;
top = (signed long)(n / d);
stack[(unsigned char) S] = (signed long)(n%d); }
void slmod(void)
{ if (top != 0) {
WP = stack[(unsigned char) S] / top;
stack[(unsigned char) S] %= top;
top = WP;
} }
void mod(void)
{ top = (top) ? stack[(unsigned char) S--] % top : stack[(unsigned char) S--]; }
void slash(void)
{ top = (top) ? stack[(unsigned char) S--] / top : (stack[(unsigned char) S--], 0); }
void umsta(void)
{ d = (unsigned long long int)top;
m = (unsigned long long int)stack[(unsigned char) S];
m *= d;
top = (unsigned long)(m >> 32);
stack[(unsigned char) S] = (unsigned long)m; }
void star(void)
{ top *= stack[(unsigned char) S--]; }
void mstar(void)
{ d = (signed long long int)top;
m = (signed long long int)stack[(unsigned char) S];
m *= d;
top = (signed long)(m >> 32);
stack[(unsigned char) S] = (signed long)m; }
void ssmod(void)
{ d = (signed long long int)top;
m = (signed long long int)stack[(unsigned char) S];
n = (signed long long int)stack[(unsigned char) (S - 1)];
n *= m;
pop;
top = (signed long)(n / d);
stack[(unsigned char) S] = (signed long)(n%d); }
void stasl(void)
{ d = (signed long long int)top;
m = (signed long long int)stack[(unsigned char) S];
n = (signed long long int)stack[(unsigned char) (S - 1)];
n *= m;
pop; pop;
top = (signed long)(n / d); }
void pick(void)
{ top = stack[(unsigned char)(S-top)]; }
void pstor(void)
{ data[top>>2] += stack[(unsigned char)S--], pop; }
void dstor(void)
{ data[(top>>2)+1] = stack[(unsigned char)S--];
data[top>>2] = stack[(unsigned char)S--];
pop; }
void dat(void)
{ push data[top>>2];
top = data[(top>>2)+1]; }
void count(void)
{ stack[(unsigned char)++S] = top + 1;
top = cData[top]; }
void dovar(void)
{ push WP; }
void maxx(void)
{ if (top < stack[(unsigned char)S]) pop;
else (unsigned char)S--; }
void minn(void)
{ if (top < stack[(unsigned char)S]) (unsigned char)S--;
else pop; }
void audio(void)
{ WP=top; pop;
ledcWriteTone(WP,top);
pop;
}
void sendPacket(void)
{}
void poke(void)
{ Pointer = (long*)top; *Pointer = stack[(unsigned char)S--];
pop; }
void peek(void)
{ Pointer = (long*)top; top = *Pointer; }
void adc(void)
{ top= (long) analogRead(top); }
void pin(void)
{ WP=top; pop;
ledcAttachPin(top,WP);
pop;
}
void duty(void)
{ WP=top; pop;
ledcAnalogWrite(WP,top,255);
pop;
}
void freq(void)
{ WP=top; pop;
ledcSetup(WP,top,13);
pop;
}
void touch(void)
{ top= (long) touchRead(top); }
void (*primitives[82])(void) = {
/* case 0 */ nop,
/* case 1 */ accep,
/* case 2 */ qrx,
/* case 3 */ txsto,
/* case 4 */ docon,
/* case 5 */ dolit,
/* case 6 */ dolist,
/* case 7 */ exitt,
/* case 8 */ execu,
/* case 9 */ donext,
/* case 10 */ qbran,
/* case 11 */ bran,
/* case 12 */ store,
/* case 13 */ at,
/* case 14 */ cstor,
/* case 15 */ cat,
/* case 16 */ nop,
/* case 17 */ nop,
/* case 18 */ rfrom,
/* case 19 */ rat,
/* case 20 */ tor,
/* case 21 */ nop,
/* case 22 */ nop,
/* case 23 */ drop,
/* case 24 */ dup,
/* case 25 */ swap,
/* case 26 */ over,
/* case 27 */ zless,
/* case 28 */ andd,
/* case 29 */ orr,
/* case 30 */ xorr,
/* case 31 */ uplus,
/* case 32 */ next,
/* case 33 */ qdup,
/* case 34 */ rot,
/* case 35 */ ddrop,
/* case 36 */ ddup,
/* case 37 */ plus,
/* case 38 */ inver,
/* case 39 */ negat,
/* case 40 */ dnega,
/* case 41 */ subb,
/* case 42 */ abss,
/* case 43 */ equal,
/* case 44 */ uless,
/* case 45 */ less,
/* case 46 */ ummod,
/* case 47 */ msmod,
/* case 48 */ slmod,
/* case 49 */ mod,
/* case 50 */ slash,
/* case 51 */ umsta,
/* case 52 */ star,
/* case 53 */ mstar,
/* case 54 */ ssmod,
/* case 55 */ stasl,
/* case 56 */ pick,
/* case 57 */ pstor,
/* case 58 */ dstor,
/* case 59 */ dat,
/* case 60 */ count,
/* case 61 */ dovar,
/* case 62 */ maxx,
/* case 63 */ minn,
/* case 64 */ audio,
/* case 65 */ sendPacket,
/* case 66 */ poke,
/* case 67 */ peek,
/* case 68 */ adc,
/* case 69 */ pin,
/* case 70 */ duty,
/* case 71 */ freq,
/* case 72 */ touch };
int as_nop=0;
int as_accept=1;
int as_qrx=2;
int as_txsto=3;
int as_docon=4;
int as_dolit=5;
int as_dolist=6;
int as_exit=7;
int as_execu=8;
int as_donext=9;
int as_qbran=10;
int as_bran=11;
int as_store=12;
int as_at=13;
int as_cstor=14;
int as_cat=15;
int as_rpat=16;
int as_rpsto=17;
int as_rfrom=18;
int as_rat=19;
int as_tor=20;
int as_spat=21;
int as_spsto=22;
int as_drop=23;
int as_dup=24;
int as_swap=25;
int as_over=26;
int as_zless=27;
int as_andd=28;
int as_orr=29;
int as_xorr=30;
int as_uplus=31;
int as_next=32;
int as_qdup=33;
int as_rot=34;
int as_ddrop=35;
int as_ddup=36;
int as_plus=37;
int as_inver=38;
int as_negat=39;
int as_dnega=40;
int as_subb=41;
int as_abss=42;
int as_equal=43;
int as_uless=44;
int as_less=45;
int as_ummod=46;
int as_msmod=47;
int as_slmod=48;
int as_mod=49;
int as_slash=50;
int as_umsta=51;
int as_star=52;
int as_mstar=53;
int as_ssmod=54;
int as_stasl=55;
int as_pick=56;
int as_pstor=57;
int as_dstor=58;
int as_dat=59;
int as_count=60;
int as_dovar=61;
int as_max=62;
int as_min=63;
int as_tone=64;
int as_sendPacket=65;
int as_poke=66;
int as_peek=67;
int as_adc=68;
int as_pin=69;
int as_duty=70;
int as_freq=71;
int as_touch=72;
//void evaluate()
//{ while (true){
// bytecode=(unsigned char)cData[P++];
// if (bytecode) {primitives[bytecode]();}
// else {break;}
// } // break on NOP
//}
__thread int counter = 0;
void evaluate()
{ while (true){
if (counter++ > 10000) {
delay(1);
counter = 0;
}
bytecode=(unsigned char)cData[P++];
if (bytecode) {primitives[bytecode]();}
else {break;}
} // break on NOP
}
static const char *index_html =
"<!html>\n"
"<head>\n"
"<title>esp32forth</title>\n"
"<style>\n"
"body {\n"
" padding: 5px;\n"
" background-color: #111;\n"
" color: #2cf;\n"
"}\n"
"#prompt {\n"
" width: 100%;\n"
" padding: 5px;\n"
" font-family: monospace;\n"
" background-color: #ff8;\n"
"}\n"
"#output {\n"
" width: 100%;\n"
" height: 80%;\n"
" resize: none;\n"
"}\n"
"</style>\n"
"</head>\n"
"<h2>esp32forth</h2>\n"
"<link rel=\"icon\" href=\"data:,\">\n"
"<body>\n"
"Upload File: <input id=\"filepick\" type=\"file\" name=\"files[]\"></input><br/>\n"
"<button onclick=\"ask('hex')\">hex</button>\n"
"<button onclick=\"ask('decimal')\">decimal</button>\n"
"<button onclick=\"ask('words')\">words</button>\n"
"<button onclick=\"ask('$100 init hush')\">init</button>\n"
"<button onclick=\"ask('ride')\">ride</button>\n"
"<button onclick=\"ask('blow')\">blow</button>\n"
"<button onclick=\"ask('$50000 p0')\">fore</button>\n"
"<button onclick=\"ask('$a0000 p0')\">back</button>\n"
"<button onclick=\"ask('$10000 p0')\">left</button>\n"
"<button onclick=\"ask('$40000 p0')\">right</button>\n"
"<button onclick=\"ask('$90000 p0')\">spin</button>\n"
"<button onclick=\"ask('0 p0')\">stop</button>\n"
"<button onclick=\"ask('4 p0s')\">LED</button>\n"
"<button onclick=\"ask('$24 ADC . $27 ADC . $22 ADC . $23 ADC .')\">ADC</button>\n"
"<br/>\n"
"<textarea id=\"output\" readonly></textarea>\n"
"<input id=\"prompt\" type=\"prompt\"></input><br/>\n"
"<script>\n"
"var prompt = document.getElementById('prompt');\n"
"var filepick = document.getElementById('filepick');\n"
"var output = document.getElementById('output');\n"
"function httpPost(url, items, callback) {\n"
" var fd = new FormData();\n"
" for (k in items) {\n"
" fd.append(k, items[k]);\n"
" }\n"
" var r = new XMLHttpRequest();\n"
" r.onreadystatechange = function() {\n"
" if (this.readyState == XMLHttpRequest.DONE) {\n"
" if (this.status === 200) {\n"
" callback(this.responseText);\n"
" } else {\n"
" callback(null);\n"
" }\n"
" }\n"
" };\n"
" r.open('POST', url);\n"
" r.send(fd);\n"
"}\n"
"function ask(cmd, callback) {\n"
" httpPost('/input',\n"
" {cmd: cmd + '\\n'}, function(data) {\n"