nabaztag_hack_kit 0.1.0.beta3 → 0.1.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -2
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +2 -2
  5. data/CHANGELOG.md +17 -2
  6. data/LICENSE +21 -0
  7. data/README.md +115 -44
  8. data/Rakefile +2 -6
  9. data/bytecode/{Commands.md → _docs/commands.md} +0 -0
  10. data/bytecode/{Docs.md → _docs/grammar.md} +0 -0
  11. data/bytecode/_docs/grammar.pdf +0 -0
  12. data/bytecode/{src → _original}/README.md +0 -0
  13. data/bytecode/{src → _original}/lib/arp.mtl +0 -0
  14. data/bytecode/{src → _original}/lib/cfg.mtl +0 -0
  15. data/bytecode/{src → _original}/lib/choreos.mtl +0 -0
  16. data/bytecode/{src → _original}/lib/dhcp.mtl +0 -0
  17. data/bytecode/{src → _original}/lib/dns.mtl +0 -0
  18. data/bytecode/{src → _original}/lib/http.mtl +0 -0
  19. data/bytecode/{src → _original}/lib/tcp.mtl +0 -0
  20. data/bytecode/{src → _original}/lib/udp.mtl +0 -0
  21. data/bytecode/{src → _original}/lib/util.mtl +0 -0
  22. data/bytecode/{src → _original}/lib/var.mtl +0 -0
  23. data/bytecode/{src → _original}/lib/wav.mtl +0 -0
  24. data/bytecode/{src → _original}/lib/wifi.mtl +0 -0
  25. data/bytecode/{src → _original}/nominal-ping.mtl +0 -0
  26. data/bytecode/main.mtl +11 -11
  27. data/bytecode/test/test.mtl +8 -8
  28. data/examples/basic/Gemfile +1 -3
  29. data/examples/basic/config.ru +14 -4
  30. data/examples/record/Gemfile +0 -5
  31. data/examples/record/{config.ru.example → config.ru} +2 -2
  32. data/examples/record/server.rb +0 -2
  33. data/ext/Makefile +10 -0
  34. data/ext/bin/mtl_comp +29 -0
  35. data/{bytecode → ext}/bin/mtl_merge +0 -0
  36. data/ext/bin/mtl_simu +29 -0
  37. data/{bytecode/src/mtl → ext}/extconf.rb +0 -0
  38. data/ext/mtl_linux/.gitignore +7 -0
  39. data/ext/mtl_linux/LICENSE +21 -0
  40. data/ext/mtl_linux/Makefile +116 -0
  41. data/ext/mtl_linux/MetalC.project +196 -0
  42. data/ext/mtl_linux/conf.bin +0 -0
  43. data/{bytecode/src/mtl → ext/mtl_linux}/conf.bin.sans_password +0 -0
  44. data/{bytecode/src/mtl → ext/mtl_linux}/config.txt +0 -0
  45. data/ext/mtl_linux/inc/log.h +21 -0
  46. data/{bytecode/src/mtl → ext/mtl_linux/inc}/properties.h +0 -0
  47. data/{bytecode/src/mtl/linux_simuaudio.h → ext/mtl_linux/inc/simu/linux/simuaudio.h} +0 -0
  48. data/{bytecode/src/mtl/linux_simunet.h → ext/mtl_linux/inc/simu/linux/simunet.h} +0 -0
  49. data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simuaudio.h +18 -18
  50. data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simunet.h +0 -0
  51. data/ext/mtl_linux/inc/vcomp/compiler.h +200 -0
  52. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/file.h +11 -11
  53. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/filesystem.h +0 -0
  54. data/ext/mtl_linux/inc/vcomp/interpreter.h +121 -0
  55. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/memory.h +120 -92
  56. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/param.h +0 -0
  57. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/parser.h +27 -27
  58. data/ext/mtl_linux/inc/vcomp/prodbuffer.h +42 -0
  59. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/resource.h +1 -1
  60. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/terminal.h +8 -8
  61. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/util.h +7 -7
  62. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vaudio.h +0 -0
  63. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vbc.h +1 -1
  64. data/ext/mtl_linux/inc/vm/vbc_str.h +167 -0
  65. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vinterp.h +0 -0
  66. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vloader.h +0 -0
  67. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vlog.h +0 -0
  68. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vmem.h +0 -0
  69. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vnet.h +0 -0
  70. data/ext/mtl_linux/nominal.mtl +3959 -0
  71. data/ext/mtl_linux/src/comp/main.cpp +123 -0
  72. data/ext/mtl_linux/src/simu/dumpbc.c +2566 -0
  73. data/ext/mtl_linux/src/simu/linux/main.cpp +288 -0
  74. data/ext/mtl_linux/src/simu/linux/simu.c +309 -0
  75. data/ext/mtl_linux/src/simu/linux/simuaudio.c +44 -0
  76. data/ext/mtl_linux/src/simu/linux/simunet.c +707 -0
  77. data/ext/mtl_linux/src/simu/log.c +340 -0
  78. data/ext/mtl_linux/src/simu/properties.c +368 -0
  79. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/GTKANAL.H +0 -0
  80. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/LAYER3.C +0 -0
  81. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/TABINIT.C +0 -0
  82. data/ext/mtl_linux/src/simu/win/mp3/common.c +302 -0
  83. data/ext/mtl_linux/src/simu/win/mp3/dct64_i386.c +316 -0
  84. data/ext/mtl_linux/src/simu/win/mp3/decode_i386.c +160 -0
  85. data/ext/mtl_linux/src/simu/win/mp3/huffman.h +332 -0
  86. data/ext/mtl_linux/src/simu/win/mp3/interface.c +276 -0
  87. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/mpg123.h +34 -30
  88. data/ext/mtl_linux/src/simu/win/mp3/mpglib.h +47 -0
  89. data/ext/mtl_linux/src/simu/win/simu.c +819 -0
  90. data/ext/mtl_linux/src/simu/win/simuaudio.c +787 -0
  91. data/ext/mtl_linux/src/simu/win/simunet.c +489 -0
  92. data/ext/mtl_linux/src/vcomp/bootstrap.cpp +95 -0
  93. data/ext/mtl_linux/src/vcomp/compiler.cpp +587 -0
  94. data/ext/mtl_linux/src/vcomp/compiler_file.cpp +1253 -0
  95. data/ext/mtl_linux/src/vcomp/compiler_prog.cpp +437 -0
  96. data/ext/mtl_linux/src/vcomp/compiler_term.cpp +1500 -0
  97. data/ext/mtl_linux/src/vcomp/compiler_type.cpp +1238 -0
  98. data/ext/mtl_linux/src/vcomp/compiler_var.cpp +502 -0
  99. data/ext/mtl_linux/src/vcomp/file.cpp +100 -0
  100. data/ext/mtl_linux/src/vcomp/interpreter.cpp +93 -0
  101. data/ext/mtl_linux/src/vcomp/memory.cpp +313 -0
  102. data/ext/mtl_linux/src/vcomp/parser.cpp +584 -0
  103. data/ext/mtl_linux/src/vcomp/parser_xml.cpp +137 -0
  104. data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/prodbuffer.cpp +57 -36
  105. data/ext/mtl_linux/src/vcomp/stdlib_core.cpp +130 -0
  106. data/ext/mtl_linux/src/vcomp/terminal.cpp +80 -0
  107. data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/util.cpp +18 -11
  108. data/ext/mtl_linux/src/vm/vaudio.c +830 -0
  109. data/ext/mtl_linux/src/vm/vinterp.c +1780 -0
  110. data/ext/mtl_linux/src/vm/vloader.c +139 -0
  111. data/ext/mtl_linux/src/vm/vlog.c +782 -0
  112. data/ext/mtl_linux/src/vm/vmem.c +461 -0
  113. data/ext/mtl_linux/src/vm/vnet.c +298 -0
  114. data/{bytecode/src/mtl → ext/mtl_linux}/utils/correct_const.sh +0 -0
  115. data/lib/nabaztag_hack_kit/server.rb +4 -7
  116. data/lib/nabaztag_hack_kit/version.rb +1 -1
  117. data/lib/nabaztag_hack_kit.rb +2 -2
  118. data/nabaztag_hack_kit.gemspec +10 -11
  119. data/spec/integration/server_spec.rb +3 -3
  120. data/spec/spec_helper.rb +2 -0
  121. data/spec/unit/message_spec.rb +12 -18
  122. data/spec/unit/server_spec.rb +13 -10
  123. metadata +145 -137
  124. data/bytecode/bin/mtl_comp +0 -50
  125. data/bytecode/bin/mtl_simu +0 -49
  126. data/bytecode/src/mtl/Makefile +0 -42
  127. data/bytecode/src/mtl/README.md +0 -13
  128. data/bytecode/src/mtl/bc.cpp +0 -1891
  129. data/bytecode/src/mtl/dumpbc.c +0 -2566
  130. data/bytecode/src/mtl/linux_simu.c +0 -271
  131. data/bytecode/src/mtl/linux_simuaudio.c +0 -16
  132. data/bytecode/src/mtl/linux_simunet.c +0 -620
  133. data/bytecode/src/mtl/log.c +0 -297
  134. data/bytecode/src/mtl/log.h +0 -20
  135. data/bytecode/src/mtl/main_compiler.cpp +0 -104
  136. data/bytecode/src/mtl/main_simu.cpp +0 -221
  137. data/bytecode/src/mtl/mp3/common.c +0 -265
  138. data/bytecode/src/mtl/mp3/dct64_i386.c +0 -316
  139. data/bytecode/src/mtl/mp3/decode_i386.c +0 -155
  140. data/bytecode/src/mtl/mp3/huffman.h +0 -332
  141. data/bytecode/src/mtl/mp3/interface.c +0 -258
  142. data/bytecode/src/mtl/mp3/mpglib.h +0 -44
  143. data/bytecode/src/mtl/properties.c +0 -293
  144. data/bytecode/src/mtl/simu.c +0 -750
  145. data/bytecode/src/mtl/simuaudio.c +0 -662
  146. data/bytecode/src/mtl/simunet.c +0 -400
  147. data/bytecode/src/mtl/vaudio.c +0 -677
  148. data/bytecode/src/mtl/vbc_str.h +0 -166
  149. data/bytecode/src/mtl/vcomp/Makefile +0 -29
  150. data/bytecode/src/mtl/vcomp/bootstrap.cpp +0 -89
  151. data/bytecode/src/mtl/vcomp/compiler.cpp +0 -470
  152. data/bytecode/src/mtl/vcomp/compiler.h +0 -200
  153. data/bytecode/src/mtl/vcomp/compiler_file.cpp +0 -929
  154. data/bytecode/src/mtl/vcomp/compiler_prog.cpp +0 -250
  155. data/bytecode/src/mtl/vcomp/compiler_term.cpp +0 -1053
  156. data/bytecode/src/mtl/vcomp/compiler_type.cpp +0 -872
  157. data/bytecode/src/mtl/vcomp/compiler_var.cpp +0 -289
  158. data/bytecode/src/mtl/vcomp/file.cpp +0 -79
  159. data/bytecode/src/mtl/vcomp/interpreter.cpp +0 -85
  160. data/bytecode/src/mtl/vcomp/interpreter.h +0 -121
  161. data/bytecode/src/mtl/vcomp/memory.cpp +0 -241
  162. data/bytecode/src/mtl/vcomp/parser.cpp +0 -427
  163. data/bytecode/src/mtl/vcomp/parser_xml.cpp +0 -124
  164. data/bytecode/src/mtl/vcomp/prodbuffer.h +0 -42
  165. data/bytecode/src/mtl/vcomp/stdlib_core.cpp +0 -122
  166. data/bytecode/src/mtl/vcomp/terminal.cpp +0 -73
  167. data/bytecode/src/mtl/vinterp.c +0 -1349
  168. data/bytecode/src/mtl/vloader.c +0 -127
  169. data/bytecode/src/mtl/vlog.c +0 -589
  170. data/bytecode/src/mtl/vmem.c +0 -424
  171. data/bytecode/src/mtl/vnet.c +0 -255
  172. data/examples/basic/Procfile +0 -2
  173. data/examples/basic/server.rb +0 -14
@@ -0,0 +1,1780 @@
1
+ // VLISP Virtual Machine - 2006 - by Sylvain Huet
2
+ // Lowcost IS Powerfull
3
+
4
+ #include"vmem.h"
5
+ #include"vloader.h"
6
+ #include"vinterp.h"
7
+ #include"vlog.h"
8
+ #include"vaudio.h"
9
+ #ifdef VSIMU
10
+ #include<stdio.h>
11
+ #include<string.h>
12
+ #include"simunet.h"
13
+ #else
14
+ #include "common.h"
15
+ #endif
16
+ #include"vnet.h"
17
+
18
+ /*
19
+ #include"vbc_str.h"
20
+
21
+ void displaybc(int off,int base)
22
+ {
23
+ int v;
24
+ char *p=bytecode+off;
25
+ char* spaces=" ";
26
+ int ind=off;
27
+ int i=*p;
28
+ printf("%4d]",base);
29
+ if ((i<0)||(i>=MaxOpcode)) printf("%4d ??\n",ind);
30
+ else if ((i==OPint))
31
+ {
32
+ p++;
33
+ v=(p[0]&255)+((p[1]&255)<<8)+((p[2]&255)<<16)+((p[3]&255)<<24);
34
+ printf("%4d %s%s %d\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]),v);
35
+ ind+=4;
36
+ p+=3;
37
+ }
38
+ else if ((i==OPgoto)||(i==OPelse))
39
+ {
40
+ p++;
41
+ v=(p[0]&255)+((p[1]&255)<<8);
42
+ printf("%4d %s%s %d\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]),v);
43
+ ind+=2;
44
+ p+=1;
45
+ }
46
+ else if ((i==OPgetlocalb)||(i==OPgetglobalb)||(i==OPfetchb)||(i==OPdeftabb)||(i==OPsetlocalb)||
47
+ (i==OPmktabb)||(i==OPsetstructb)||(i==OPcallrb)||(i==OPintb))
48
+ {
49
+ p++;
50
+ v=p[0]&255;
51
+ printf("%4d %s%s %d\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]),v);
52
+ ind++;
53
+ }
54
+ else if (i==OPret)
55
+ {
56
+ printf("%4d %s%s\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]));
57
+ return;
58
+ }
59
+ else printf("%4d %s%s\n",ind,strbytecod[i],spaces+strlen(strbytecod[i]));
60
+ }
61
+ */
62
+
63
+ // test si dernier appel ?
64
+ int TFCtest(int p,int pbase)
65
+ {
66
+ int i;
67
+ while(bytecode[p]!=OPret)
68
+ {
69
+ if (bytecode[p]==OPgoto)
70
+ {
71
+ p++;
72
+ i=(bytecode[p]&255)+((bytecode[p+1]&255)<<8);
73
+ p=pbase+i;
74
+ }
75
+ else
76
+ {
77
+ return 0;
78
+ }
79
+ }
80
+ return 1;
81
+ }
82
+
83
+
84
+ int currentop=-1;
85
+ int tron=0;
86
+
87
+ // execute une fonction
88
+ // la pile doit contenir la liste d'argument, puis la fonction
89
+ // la fonction est soit un num�ro, soit un tuple [num�ro liste]
90
+ // on distingue le cas selon le fait que la valeur empil�e est un pointeur ou un entier
91
+ void interpGo()
92
+ {
93
+ int pc=-1;
94
+ int pcbase=-1;
95
+ int callstack=1;
96
+ int callstackres=1;
97
+ int op=OPexec;
98
+ int cont;
99
+ if (tron)
100
+ {
101
+ consolestr("go:");
102
+ consoleint(VSTACKGET(0));
103
+ consolestr(".");
104
+ consoleint(vmem_stack);
105
+ consolestr("/");
106
+ }
107
+
108
+ if (vmem_broken)
109
+ {
110
+ return;
111
+ }
112
+ while(1)
113
+ {
114
+ do
115
+ {
116
+ cont=0;
117
+ currentop=op;
118
+ if (tron)
119
+ {
120
+ // displaybc(pc-1,pcbase);
121
+ /*
122
+ consoleint(pc);consolestr(":");
123
+ consoleint(op);
124
+ if (op) {consolestr(":");consoleint(255&bytecode[pc]);}
125
+ consolestr("\n");
126
+ */
127
+ // if (bytecode[0x2450]==0) tron=0;
128
+ // dump(&bytecode[0x2440],32);
129
+ }
130
+ CLR_WDT;
131
+ switch(op)
132
+ {
133
+ case OPexec:
134
+ {
135
+ int p,npc,narg,nloc,i,fun;
136
+ p=VSTACKGET(0);
137
+ if (ISVALPNT(p))
138
+ {
139
+ p=VALTOPNT(p);
140
+ fun=VALTOINT(VFETCH(p,0));
141
+ VSTACKSET(0,VFETCH(p,1));
142
+ while(VSTACKGET(0)!=NIL)
143
+ {
144
+ VPUSH(VFETCH(VALTOPNT(VSTACKGET(0)),1));
145
+ VSTACKSET(1,VFETCH(VALTOPNT(VSTACKGET(1)),0));
146
+ }
147
+ // VPULL();
148
+ }
149
+ else
150
+ {
151
+ fun=VALTOINT(p);
152
+ }
153
+ VPULL();
154
+ if (fun<0)
155
+ {
156
+ op=-fun;
157
+ cont=1;
158
+ break;
159
+ }
160
+ npc=loaderFunstart(fun);
161
+ narg=bytecode[npc];
162
+ nloc=loaderGetShort(bytecode+npc+1);
163
+ npc+=3;
164
+
165
+ if (callstack<=0)
166
+ {
167
+ if (TFCtest(pc,pcbase))
168
+ {
169
+ int ncall;
170
+ pc=VALTOINT(VCALLSTACKGET(callstackres,-3));
171
+ pcbase=VALTOINT(VCALLSTACKGET(callstackres,-2));
172
+ ncall=VALTOINT(VCALLSTACKGET(callstackres,-1));
173
+ callstackres=VALTOINT(VCALLSTACKGET(callstackres,0));
174
+ for(i=0; i<narg; i++)
175
+ {
176
+ VCALLSTACKSET(callstack,i,VSTACKGET(narg-i-1));
177
+ }
178
+ vmem_stack=callstack-narg+1;
179
+ callstack=ncall;
180
+ }
181
+ }
182
+
183
+ for(i=0; i<nloc; i++)
184
+ {
185
+ VPUSH(NIL);
186
+ }
187
+ VPUSH(INTTOVAL(pc));
188
+ VPUSH(INTTOVAL(pcbase));
189
+ VPUSH(INTTOVAL(callstack));
190
+ VPUSH(INTTOVAL(callstackres));
191
+ callstack=vmem_stack+3+nloc+narg;
192
+ callstackres=vmem_stack;
193
+ pcbase=pc=npc;
194
+ }
195
+ break;
196
+ case OPret:
197
+ {
198
+ int ncall;
199
+ pc=VALTOINT(VSTACKGET(4));
200
+ pcbase=VALTOINT(VSTACKGET(3));
201
+ ncall=VALTOINT(VSTACKGET(2));
202
+ callstackres=VALTOINT(VSTACKGET(1));
203
+ VCALLSTACKSET(callstack,0,VSTACKGET(0)); // recopie le r�sultat
204
+ vmem_stack=callstack;
205
+ callstack=ncall;
206
+ }
207
+ break;
208
+ case OPintb:
209
+ VPUSH(INTTOVAL(255&bytecode[pc++]));
210
+ // if (VSTACKGET(0)==INTTOVAL(0xd5)) tron=1;
211
+ break;
212
+ case OPint:
213
+ VPUSH(INTTOVAL(loaderGetInt(&bytecode[pc])));
214
+ pc+=4;
215
+ break;
216
+ case OPnil:
217
+ VPUSH(NIL);
218
+ break;
219
+ case OPdrop:
220
+ VDROPN(1);
221
+ break;
222
+ case OPdup:
223
+ VPUSH(VSTACKGET(0));
224
+ break;
225
+ case OPgetlocalb:
226
+ VPUSH(VCALLSTACKGET(callstack,255&bytecode[pc++]));
227
+ break;
228
+ case OPgetlocal:
229
+ VSTACKSET(0,VCALLSTACKGET(callstack,VALTOINT(VSTACKGET(0))));
230
+ break;
231
+ case OPadd:
232
+ VSTACKSET(1,INTTOVAL(VALTOINT(VSTACKGET(1))+VALTOINT(VSTACKGET(0))));
233
+ VDROPN(1);
234
+ break;
235
+ case OPsub:
236
+ VSTACKSET(1,INTTOVAL(VALTOINT(VSTACKGET(1))-VALTOINT(VSTACKGET(0))));
237
+ VDROPN(1);
238
+ break;
239
+ case OPmul:
240
+ VSTACKSET(1,INTTOVAL(VALTOINT(VSTACKGET(1))*VALTOINT(VSTACKGET(0))));
241
+ VDROPN(1);
242
+ break;
243
+ case OPdiv:
244
+ VSTACKSET(1,INTTOVAL(VALTOINT(VSTACKGET(1))/VALTOINT(VSTACKGET(0))));
245
+ VDROPN(1);
246
+ break;
247
+ case OPmod:
248
+ VSTACKSET(1,INTTOVAL(VALTOINT(VSTACKGET(1))%VALTOINT(VSTACKGET(0))));
249
+ VDROPN(1);
250
+ break;
251
+ case OPand:
252
+ VSTACKSET(1,INTTOVAL(VALTOINT(VSTACKGET(1))&VALTOINT(VSTACKGET(0))));
253
+ VDROPN(1);
254
+ break;
255
+ case OPor:
256
+ VSTACKSET(1,INTTOVAL(VALTOINT(VSTACKGET(1))|VALTOINT(VSTACKGET(0))));
257
+ VDROPN(1);
258
+ break;
259
+ case OPeor:
260
+ VSTACKSET(1,INTTOVAL(VALTOINT(VSTACKGET(1))^VALTOINT(VSTACKGET(0))));
261
+ VDROPN(1);
262
+ break;
263
+ case OPshl:
264
+ VSTACKSET(1,INTTOVAL(VALTOINT(VSTACKGET(1))<<VALTOINT(VSTACKGET(0))));
265
+ VDROPN(1);
266
+ break;
267
+ case OPshr:
268
+ VSTACKSET(1,INTTOVAL(VALTOINT(VSTACKGET(1))>>VALTOINT(VSTACKGET(0))));
269
+ VDROPN(1);
270
+ break;
271
+ case OPneg:
272
+ VSTACKSET(0,INTTOVAL(-VALTOINT(VSTACKGET(0))));
273
+ break;
274
+ case OPnot:
275
+ VSTACKSET(0,INTTOVAL(~VALTOINT(VSTACKGET(0))));
276
+ break;
277
+ case OPnon:
278
+ VSTACKSET(0,INTTOVAL(VALTOINT(VSTACKGET(0))?0:1));
279
+ break;
280
+ case OPeq:
281
+ VSTACKSET(1,INTTOVAL((VSTACKGET(1)==VSTACKGET(0))?1:0));
282
+ VDROPN(1);
283
+ break;
284
+ case OPne:
285
+ VSTACKSET(1,INTTOVAL((VSTACKGET(1)!=VSTACKGET(0))?1:0));
286
+ VDROPN(1);
287
+ break;
288
+ case OPlt:
289
+ VSTACKSET(1,INTTOVAL((VALTOINT(VSTACKGET(1))<VALTOINT(VSTACKGET(0)))?1:0));
290
+ VDROPN(1);
291
+ break;
292
+ case OPgt:
293
+ VSTACKSET(1,INTTOVAL((VALTOINT(VSTACKGET(1))>VALTOINT(VSTACKGET(0)))?1:0));
294
+ VDROPN(1);
295
+ break;
296
+ case OPle:
297
+ VSTACKSET(1,INTTOVAL((VALTOINT(VSTACKGET(1))<=VALTOINT(VSTACKGET(0)))?1:0));
298
+ VDROPN(1);
299
+ break;
300
+ case OPge:
301
+ VSTACKSET(1,INTTOVAL((VALTOINT(VSTACKGET(1))>=VALTOINT(VSTACKGET(0)))?1:0));
302
+ VDROPN(1);
303
+ break;
304
+ case OPgoto:
305
+ pc=pcbase+loaderGetShort(&bytecode[pc]);
306
+ break;
307
+ case OPelse:
308
+ if (!VPULL())
309
+ {
310
+ pc=pcbase+loaderGetShort(&bytecode[pc]);
311
+ }
312
+ else
313
+ {
314
+ pc+=2;
315
+ }
316
+ break;
317
+ case OPmktabb:
318
+ VPUSH(PNTTOVAL(VMALLOCCLEAR(255&bytecode[pc++])));
319
+ break;
320
+ case OPmktab:
321
+ VPUSH(PNTTOVAL(VMALLOCCLEAR(VALTOINT(VPULL()))));
322
+ break;
323
+ case OPdeftabb:
324
+ VMKTAB(255&bytecode[pc++]);
325
+ break;
326
+ case OPdeftab:
327
+ VMKTAB(VALTOINT(VPULL()));
328
+ break;
329
+ case OPfetchb:
330
+ {
331
+ int i=255&bytecode[pc++];
332
+ int p=VSTACKGET(0);
333
+ if (p!=NIL)
334
+ {
335
+ VSTACKSET(0,VFETCH(VALTOPNT(p),i));
336
+ }
337
+ }
338
+ break;
339
+ case OPfetch:
340
+ {
341
+ int i=VPULL();
342
+ int p=VSTACKGET(0);
343
+ if ((p==NIL)||(i==NIL))
344
+ {
345
+ VSTACKSET(0,NIL);
346
+ }
347
+ else
348
+ {
349
+ i=VALTOINT(i);
350
+ p=VALTOPNT(p);
351
+ if ((i<0)||(i>=VSIZE(p)))
352
+ {
353
+ VSTACKSET(0,NIL);
354
+ }
355
+ else
356
+ {
357
+ VSTACKSET(0,VFETCH(p,i));
358
+ }
359
+ }
360
+ }
361
+ break;
362
+ case OPgetglobalb:
363
+ VPUSH(VCALLSTACKGET(global_start,255&bytecode[pc++]));
364
+ break;
365
+ case OPgetglobal:
366
+ VSTACKSET(0,VCALLSTACKGET(global_start,VALTOINT(VSTACKGET(0))));
367
+ break;
368
+ case OPSecho:
369
+ logSecho(VSTACKGET(0),0);
370
+ break;
371
+ case OPIecho:
372
+ logIecho(VSTACKGET(0),0);
373
+ break;
374
+ case OPsetlocalb:
375
+ VCALLSTACKSET(callstack,255&bytecode[pc++],VPULL());
376
+ break;
377
+ case OPsetlocal:
378
+ {
379
+ int v=VALTOINT(VPULL());
380
+ VCALLSTACKSET(callstack,v,VPULL());
381
+ }
382
+ break;
383
+ case OPsetglobal:
384
+ VCALLSTACKSET(global_start,VALTOINT(VSTACKGET(1)),VSTACKGET(0));
385
+ VSTACKSET(1,VSTACKGET(0));
386
+ VPULL();
387
+ break;
388
+ case OPsetstructb:
389
+ {
390
+ int i=255&bytecode[pc++];
391
+ int v=VPULL();
392
+ int p=VSTACKGET(0);
393
+ if ((p!=NIL)&&(i!=NIL))
394
+ {
395
+ p=VALTOPNT(p);
396
+ if ((i>=0)||(i<VSIZE(p)))
397
+ {
398
+ VSTORE(p,i,v);
399
+ }
400
+ }
401
+ }
402
+ break;
403
+ case OPsetstruct:
404
+ {
405
+ int i=VPULL();
406
+ int v=VPULL();
407
+ int p=VSTACKGET(0);
408
+ if ((p!=NIL)&&(i!=NIL))
409
+ {
410
+ i=VALTOINT(i);
411
+ p=VALTOPNT(p);
412
+ if ((i>=0)||(i<VSIZE(p)))
413
+ {
414
+ VSTORE(p,i,v);
415
+ }
416
+ }
417
+ }
418
+ break;
419
+ case OPhd:
420
+ {
421
+ int p=VSTACKGET(0);
422
+ if (p!=NIL)
423
+ {
424
+ VSTACKSET(0,VFETCH(VALTOPNT(p),0));
425
+ }
426
+ }
427
+ break;
428
+ case OPtl:
429
+ {
430
+ int p=VSTACKGET(0);
431
+ if (p!=NIL)
432
+ {
433
+ VSTACKSET(0,VFETCH(VALTOPNT(p),1));
434
+ }
435
+ }
436
+ break;
437
+ case OPsetlocal2:
438
+ VCALLSTACKSET(callstack,VALTOINT(VSTACKGET(1)),VSTACKGET(0));
439
+ VSTACKSET(1,VSTACKGET(0));
440
+ VPULL();
441
+ break;
442
+ case OPstore:
443
+ {
444
+ int v=VPULL();
445
+ int i=VPULL();
446
+ int p=VSTACKGET(0);
447
+ if ((p!=NIL)&&(i!=NIL))
448
+ {
449
+ i=VALTOINT(i);
450
+ p=VALTOPNT(p);
451
+ if ((i>=0)||(i<VSIZE(p)))
452
+ {
453
+ VSTORE(p,i,v);
454
+ }
455
+ }
456
+ VSTACKSET(0,v);
457
+ }
458
+ break;
459
+ case OPcall:
460
+ {
461
+ int p=VSTACKGET(0);
462
+ if (p==NIL)
463
+ {
464
+ VSTACKSET(1,NIL);
465
+ VPULL();
466
+ }
467
+ else
468
+ {
469
+ int n;
470
+ n=VSIZE(VALTOPNT(p));
471
+ if (n==0)
472
+ {
473
+ VPULL();
474
+ }
475
+ else
476
+ {
477
+ int i;
478
+ for(i=1; i<n; i++)
479
+ {
480
+ VPUSH(NIL);
481
+ }
482
+ p=VALTOPNT(VSTACKGET(n-1));
483
+ for(i=0; i<n; i++)
484
+ {
485
+ VSTACKSET(n-1-i,VFETCH(p,i));
486
+ }
487
+ }
488
+ VPUSH(INTTOVAL(n));
489
+ op=OPcallr;
490
+ cont=1;
491
+ }
492
+ }
493
+ break;
494
+ case OPcallrb:
495
+ {
496
+ int n=255&bytecode[pc++];
497
+ int valn=VSTACKGET(n);
498
+ if (valn==NIL)
499
+ {
500
+ VDROPN(n);
501
+ }
502
+ else
503
+ {
504
+ int i;
505
+ for(i=n; i>0; i--)
506
+ {
507
+ VSTACKSET(i,VSTACKGET(i-1));
508
+ }
509
+ VSTACKSET(0,valn);
510
+ op=OPexec;
511
+ cont=1;
512
+ }
513
+ }
514
+ break;
515
+ case OPcallr:
516
+ {
517
+ int n=VALTOINT(VPULL());
518
+ int valn=VSTACKGET(n);
519
+ if (valn==NIL)
520
+ {
521
+ VDROPN(n);
522
+ }
523
+ else
524
+ {
525
+ int i;
526
+ for(i=n; i>0; i--)
527
+ {
528
+ VSTACKSET(i,VSTACKGET(i-1));
529
+ }
530
+ VSTACKSET(0,valn);
531
+ op=OPexec;
532
+ cont=1;
533
+ }
534
+ }
535
+ break;
536
+ case OPfirst:
537
+ {
538
+ int p=VSTACKGET(0);
539
+ if (p!=NIL)
540
+ {
541
+ VPUSH(VFETCH(VALTOPNT(p),0));
542
+ }
543
+ else
544
+ {
545
+ VPUSH(NIL);
546
+ }
547
+ }
548
+ break;
549
+ case OPtime_ms:
550
+ VPUSH(INTTOVAL(sysTimems()));
551
+ break;
552
+ case OPtabnew:
553
+ {
554
+ int v=VPULL();
555
+ if (v==NIL)
556
+ {
557
+ VSTACKSET(0,NIL);
558
+ }
559
+ else
560
+ {
561
+ int p,i,v0;
562
+ v=VALTOINT(v);
563
+ p=VMALLOC(v);
564
+ v0=VSTACKGET(0);
565
+ for(i=0; i<v; i++)
566
+ {
567
+ VSTORE(p,i,v0);
568
+ }
569
+ VSTACKSET(0,PNTTOVAL(p));
570
+ }
571
+ }
572
+ break;
573
+ case OPfixarg:
574
+ {
575
+ int v=VSTACKGET(1);
576
+ if (v==NIL)
577
+ {
578
+ VPULL();
579
+ }
580
+ else
581
+ {
582
+ if (ISVALPNT(v))
583
+ {
584
+ VPUSH(VFETCH(VALTOPNT(v),1));
585
+ VSTACKSET(2,VFETCH(VALTOPNT(VSTACKGET(2)),0));
586
+ }
587
+ else
588
+ {
589
+ VPUSH(NIL);
590
+ }
591
+ VMKTAB(2);
592
+ VMKTAB(2);
593
+ }
594
+ }
595
+ break;
596
+ case OPabs:
597
+ {
598
+ int v=VALTOINT(VSTACKGET(0));
599
+ if (v<0)
600
+ {
601
+ v=-v;
602
+ }
603
+ VSTACKSET(0,INTTOVAL(v));
604
+ }
605
+ break;
606
+ case OPmax:
607
+ {
608
+ int v=VALTOINT(VPULL());
609
+ int w=VALTOINT(VSTACKGET(0));
610
+ VSTACKSET(0,INTTOVAL(v<w?w:v));
611
+ }
612
+ break;
613
+ case OPmin:
614
+ {
615
+ int v=VALTOINT(VPULL());
616
+ int w=VALTOINT(VSTACKGET(0));
617
+ VSTACKSET(0,INTTOVAL(v>w?w:v));
618
+ }
619
+ break;
620
+ case OPrand:
621
+ VPUSH(INTTOVAL(sysRand()));
622
+ break;
623
+ case OPsrand:
624
+ sysSrand(VALTOINT(VSTACKGET(0)));
625
+ break;
626
+ case OPtime:
627
+ VPUSH(INTTOVAL(sysTime()));
628
+ break;
629
+ case OPstrnew:
630
+ {
631
+ int n=VALTOINT(VSTACKGET(0));
632
+ if (n<0)
633
+ {
634
+ VSTACKSET(0,NIL);
635
+ }
636
+ else
637
+ {
638
+ VSTACKSET(0,PNTTOVAL(VMALLOCBIN(n)));
639
+ }
640
+ }
641
+ break;
642
+ case OPstrset:
643
+ {
644
+ int v=VALTOINT(VPULL());
645
+ int n=VALTOINT(VPULL());
646
+ int p=VALTOPNT(VSTACKGET(0));
647
+ if ((p!=NIL)&&(n>=0)&&(n<VSIZEBIN(p)))
648
+ {
649
+ (VSTARTBIN(p))[n]=v;
650
+ }
651
+ }
652
+ break;
653
+ case OPstrcpy:
654
+ {
655
+ int len=VPULL();
656
+ int start=VALTOINT(VPULL());
657
+ int q=VALTOPNT(VPULL());
658
+ int index=VALTOINT(VPULL());
659
+ int p=VALTOPNT(VSTACKGET(0));
660
+ if ((p!=NIL)&&(q!=NIL))
661
+ {
662
+ if (len==NIL)
663
+ {
664
+ len=VSIZEBIN(q)-start;
665
+ }
666
+ else
667
+ {
668
+ len=VALTOINT(len);
669
+ }
670
+ sysCpy(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,VSIZEBIN(q),len);
671
+ }
672
+ }
673
+ break;
674
+ case OPvstrcmp:
675
+ {
676
+ int len=VPULL();
677
+ int start=VALTOINT(VPULL());
678
+ int q=VALTOPNT(VPULL());
679
+ int index=VALTOINT(VPULL());
680
+ int p=VALTOPNT(VSTACKGET(0));
681
+ if ((p!=NIL)&&(q!=NIL))
682
+ {
683
+ if (len==NIL)
684
+ {
685
+ len=VSIZEBIN(q)-start;
686
+ if (len<VSIZEBIN(p)-index)
687
+ {
688
+ len=VSIZEBIN(p)-index;
689
+ }
690
+ }
691
+ else
692
+ {
693
+ len=VALTOINT(len);
694
+ }
695
+ VSTACKSET(0,INTTOVAL(sysCmp(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,VSIZEBIN(q),len)));
696
+ }
697
+ else
698
+ {
699
+ VSTACKSET(0,INTTOVAL((p!=NIL)?1:(q!=NIL)?-1:0));
700
+ }
701
+ }
702
+ break;
703
+ case OPstrfind:
704
+ {
705
+ int len=VPULL();
706
+ int start=VALTOINT(VPULL());
707
+ int q=VALTOPNT(VPULL());
708
+ int index=VALTOINT(VPULL());
709
+ int p=VALTOPNT(VSTACKGET(0));
710
+ if ((p!=NIL)&&(q!=NIL))
711
+ {
712
+ if (len==NIL)
713
+ {
714
+ len=VSIZEBIN(q)-start;
715
+ }
716
+ else
717
+ {
718
+ len=VALTOINT(len);
719
+ }
720
+ VSTACKSET(0,sysFind(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,VSIZEBIN(q),len));
721
+ }
722
+ else
723
+ {
724
+ VSTACKSET(0,NIL);
725
+ }
726
+ }
727
+ break;
728
+ case OPstrfindrev:
729
+ {
730
+ int len=VPULL();
731
+ int start=VALTOINT(VPULL());
732
+ int q=VALTOPNT(VPULL());
733
+ int index=VPULL();
734
+ int p=VALTOPNT(VSTACKGET(0));
735
+ if ((p!=NIL)&&(q!=NIL))
736
+ {
737
+ if (len==NIL)
738
+ {
739
+ len=VSIZEBIN(q)-start;
740
+ }
741
+ else
742
+ {
743
+ len=VALTOINT(len);
744
+ }
745
+ if (index==NIL)
746
+ {
747
+ index=VSIZEBIN(p)-1;
748
+ }
749
+ else
750
+ {
751
+ index=VALTOINT(index);
752
+ }
753
+ VSTACKSET(0,sysFindrev(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,VSIZEBIN(q),len));
754
+ }
755
+ else
756
+ {
757
+ VSTACKSET(0,NIL);
758
+ }
759
+ }
760
+ break;
761
+ case OPstrlen:
762
+ {
763
+ int p=VALTOPNT(VSTACKGET(0));
764
+ if (p!=NIL)
765
+ {
766
+ VSTACKSET(0,INTTOVAL(VSIZEBIN(p)));
767
+ }
768
+ }
769
+ break;
770
+ case OPstrget:
771
+ {
772
+ int n=VALTOINT(VPULL());
773
+ int p=VALTOPNT(VSTACKGET(0));
774
+ if ((p==NIL)||(n<0)||(n>=VSIZEBIN(p)))
775
+ {
776
+ VSTACKSET(0,NIL);
777
+ }
778
+ else
779
+ {
780
+ VSTACKSET(0,INTTOVAL(((VSTARTBIN(p))[n]&255)));
781
+ }
782
+ }
783
+ break;
784
+ case OPstrright:
785
+ {
786
+ int n=VALTOINT(VPULL()); // 2nd arg, nb of chars to keep
787
+ int p=VALTOPNT(VSTACKGET(0)); // 1st arg, pointer to the source string in stack
788
+ if(p != NIL)
789
+ {
790
+ consolestr("Nb:");
791
+ consolehx(n);
792
+ consolestr("Str:");
793
+ consolehx(p);
794
+ vmemDump();
795
+ }
796
+ else
797
+ {
798
+ VSTACKSET(0,NIL);
799
+ }
800
+
801
+ }
802
+ break;
803
+ case OPstrsub:
804
+ // vmemDump();
805
+ {
806
+ int len=VPULL();
807
+ int start=VALTOINT(VPULL());
808
+ int q=VALTOPNT(VSTACKGET(0));
809
+ if (q!=NIL)
810
+ {
811
+ if (len==NIL)
812
+ {
813
+ len=VSIZEBIN(q)-start;
814
+ }
815
+ else
816
+ {
817
+ len=VALTOINT(len);
818
+ }
819
+ if (start+len>VSIZEBIN(q))
820
+ {
821
+ len=VSIZEBIN(q)-start;
822
+ }
823
+ if ((start>=0)&&(len>=0))
824
+ {
825
+ int p=VMALLOCBIN(len);
826
+ mystrcpy(VSTARTBIN(p),VSTARTBIN(VALTOPNT(VSTACKGET(0)))+start,len);
827
+ VSTACKSET(0,PNTTOVAL(p));
828
+ }
829
+ else
830
+ {
831
+ VSTACKSET(0,NIL);
832
+ }
833
+ }
834
+ else
835
+ {
836
+ VSTACKSET(0,NIL);
837
+ }
838
+ }
839
+ // vmemDump();
840
+ break;
841
+ case OPstrcat:
842
+ {
843
+ int r;
844
+ int len=0;
845
+ int q=VALTOPNT(VSTACKGET(0));
846
+ int p=VALTOPNT(VSTACKGET(1));
847
+ if (p!=NIL)
848
+ {
849
+ len+=VSIZEBIN(p);
850
+ }
851
+ if (q!=NIL)
852
+ {
853
+ len+=VSIZEBIN(q);
854
+ }
855
+ r=VMALLOCBIN(len);
856
+ len=0;
857
+ q=VALTOPNT(VPULL());
858
+ p=VALTOPNT(VSTACKGET(0));
859
+ if (p!=NIL)
860
+ {
861
+ len=VSIZEBIN(p);
862
+ mystrcpy(VSTARTBIN(r),VSTARTBIN(p),len);
863
+ }
864
+ if (q!=NIL)
865
+ {
866
+ mystrcpy(VSTARTBIN(r)+len,VSTARTBIN(q),VSIZEBIN(q));
867
+ }
868
+ VSTACKSET(0,PNTTOVAL(r));
869
+ }
870
+ break;
871
+ case OPtablen:
872
+ {
873
+ int p=VALTOPNT(VSTACKGET(0));
874
+ if (p!=NIL)
875
+ {
876
+ VSTACKSET(0,INTTOVAL(VSIZE(p)));
877
+ }
878
+ }
879
+ break;
880
+ case OPstrcatlist:
881
+ {
882
+ int r,q;
883
+ int len=0;
884
+ int p=VALTOPNT(VSTACKGET(0));
885
+ while(p!=NIL)
886
+ {
887
+ q=VALTOPNT(VFETCH(p,0));
888
+ if (q!=NIL)
889
+ {
890
+ len+=VSIZEBIN(q);
891
+ }
892
+ p=VALTOPNT(VFETCH(p,1));
893
+ }
894
+ r=VMALLOCBIN(len);
895
+ if (r<0)
896
+ {
897
+ return;
898
+ }
899
+ len=0;
900
+ p=VALTOPNT(VSTACKGET(0));
901
+ while(p!=NIL)
902
+ {
903
+ q=VALTOPNT(VFETCH(p,0));
904
+ if (q!=NIL)
905
+ {
906
+ mystrcpy(VSTARTBIN(r)+len,VSTARTBIN(q),VSIZEBIN(q));
907
+ len+=VSIZEBIN(q);
908
+ }
909
+ p=VALTOPNT(VFETCH(p,1));
910
+ }
911
+ VSTACKSET(0,PNTTOVAL(r));
912
+ }
913
+ break;
914
+ case OPled:
915
+ sysLed(VALTOINT(VSTACKGET(1)),VALTOINT(VSTACKGET(0)));
916
+ VPULL();
917
+ break;
918
+ case OPmotorset:
919
+ sysMotorset(VALTOINT(VSTACKGET(1)),VALTOINT(VSTACKGET(0)));
920
+ VPULL();
921
+ break;
922
+ case OPmotorget:
923
+ VSTACKSET(0,INTTOVAL(sysMotorget(VALTOINT(VSTACKGET(0)))));
924
+ break;
925
+ case OPbutton2:
926
+ VPUSH(INTTOVAL(sysButton2()));
927
+ break;
928
+ case OPbutton3:
929
+ VPUSH(INTTOVAL(sysButton3()));
930
+ break;
931
+ case OPplayStart:
932
+ {
933
+ int k;
934
+ VCALLSTACKSET(sys_start,SYS_CBPLAY,VPULL());
935
+ k=VALTOINT(VPULL());
936
+ VPUSH(INTTOVAL(0));
937
+ audioPlayStart(44100,16,2,k);
938
+ }
939
+ break;
940
+ case OPplayFeed:
941
+ {
942
+ int len=VPULL();
943
+ int start=VALTOINT(VPULL());
944
+ int q=VALTOPNT(VSTACKGET(0));
945
+ if (q!=NIL)
946
+ {
947
+ if (len==NIL)
948
+ {
949
+ len=VSIZEBIN(q)-start;
950
+ }
951
+ else
952
+ {
953
+ len=VALTOINT(len);
954
+ }
955
+ if (start+len>VSIZEBIN(q))
956
+ {
957
+ len=VSIZEBIN(q)-start;
958
+ }
959
+ if ((start>=0)&&(len>=0))
960
+ {
961
+ len=audioPlayFeed(VSTARTBIN(q)+start,len);
962
+ VSTACKSET(0,INTTOVAL(len));
963
+ }
964
+ else
965
+ {
966
+ VSTACKSET(0,NIL);
967
+ }
968
+ }
969
+ else
970
+ {
971
+ audioPlayFeed(NULL,0);
972
+ VSTACKSET(0,NIL);
973
+ }
974
+ }
975
+ break;
976
+ case OPplayStop:
977
+ audioPlayStop();
978
+ VPUSH(INTTOVAL(0));
979
+ break;
980
+ case OPrecStart:
981
+ {
982
+ int freq,gain;
983
+ VCALLSTACKSET(sys_start,SYS_CBREC,VPULL());
984
+ gain=VALTOINT(VPULL());
985
+ freq=VALTOINT(VPULL());
986
+ VPUSH(INTTOVAL(0));
987
+ audioRecStart(freq,gain);
988
+ }
989
+ break;
990
+ case OPrecStop:
991
+ audioRecStop();
992
+ VPUSH(INTTOVAL(0));
993
+ break;
994
+ case OPrecVol:
995
+ {
996
+ int start=VALTOINT(VPULL());
997
+ int q=VALTOPNT(VSTACKGET(0));
998
+ if (q!=NIL)
999
+ {
1000
+ VSTACKSET(0,INTTOVAL(audioRecVol((unsigned char*)VSTARTBIN(q),VSIZEBIN(q),start)));
1001
+ }
1002
+ }
1003
+ break;
1004
+ /*
1005
+ case OPloadf:
1006
+ {
1007
+ int len=VPULL();
1008
+ int start=VALTOINT(VPULL());
1009
+ int q=VALTOPNT(VPULL());
1010
+ int index=VALTOINT(VPULL());
1011
+ int p=VALTOPNT(VSTACKGET(0));
1012
+ if ((p!=NIL)&&(q!=NIL))
1013
+ {
1014
+ if (len==NIL) len=VSIZEBIN(p)-index; else len=VALTOINT(len);
1015
+ len=sysLoad(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,len);
1016
+ VSTACKSET(0,INTTOVAL(len));
1017
+ }
1018
+ else VSTACKSET(0,NIL);
1019
+ }
1020
+ break;
1021
+ */
1022
+ case OPload:
1023
+ {
1024
+ int len=VPULL();
1025
+ int start=VALTOINT(VPULL());
1026
+ int q=VALTOPNT(VPULL());
1027
+ int index=VALTOINT(VPULL());
1028
+ int p=VALTOPNT(VSTACKGET(0));
1029
+ if ((p!=NIL)&&(q!=NIL))
1030
+ {
1031
+ if (len==NIL)
1032
+ {
1033
+ len=VSIZEBIN(p)-index;
1034
+ }
1035
+ else
1036
+ {
1037
+ len=VALTOINT(len);
1038
+ }
1039
+ len=sysLoad(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,len);
1040
+ VSTACKSET(0,INTTOVAL(len));
1041
+ }
1042
+ else
1043
+ {
1044
+ VSTACKSET(0,NIL);
1045
+ }
1046
+ }
1047
+ break;
1048
+ case OPgc:
1049
+ vmemGC();
1050
+ VPUSH(INTTOVAL((vmem_heapindex-vmem_stack)*100/VMEM_LENGTH));
1051
+ break;
1052
+ case OPsave:
1053
+ {
1054
+ int len=VPULL();
1055
+ int start=VALTOINT(VPULL());
1056
+ int q=VALTOPNT(VPULL());
1057
+ int index=VALTOINT(VPULL());
1058
+ int p=VALTOPNT(VSTACKGET(0));
1059
+ if ((p!=NIL)&&(q!=NIL))
1060
+ {
1061
+ if (len==NIL)
1062
+ {
1063
+ len=VSIZEBIN(p)-index;
1064
+ }
1065
+ else
1066
+ {
1067
+ len=VALTOINT(len);
1068
+ }
1069
+ len=sysSave(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,len);
1070
+ VSTACKSET(0,INTTOVAL(len));
1071
+ }
1072
+ else
1073
+ {
1074
+ VSTACKSET(0,NIL);
1075
+ }
1076
+ }
1077
+ break;
1078
+ case OPbytecode:
1079
+ consolestr("#################### OPbytecode"ENDLINE);
1080
+ if (VSTACKGET(0)!=NIL)
1081
+ {
1082
+ char* q;
1083
+ int env=-1;
1084
+ int p=VALTOPNT(VCALLSTACKGET(sys_start,SYS_ENV));
1085
+ audioPlayStop();
1086
+ audioRecStop();
1087
+ if (p!=NIL)
1088
+ {
1089
+ env=VSIZEBIN(p);
1090
+ memcpy(audioFifoPlay,VSTARTBIN(p),env);
1091
+ }
1092
+
1093
+ q=VSTARTBIN(VALTOPNT(VSTACKGET(0)));
1094
+ // dump(q+0x2df0,128);
1095
+
1096
+ loaderInit(q);
1097
+ // dump(&bytecode[0x2440],32);
1098
+
1099
+ if (env>=0)
1100
+ {
1101
+ // dump(audioFifoPlay,env);
1102
+ VCALLSTACKSET(sys_start,SYS_ENV,
1103
+ PNTTOVAL(VMALLOCSTR(audioFifoPlay,env)));
1104
+ }
1105
+ VPUSH(INTTOVAL(0));
1106
+ // tron=1;
1107
+ interpGo();
1108
+ // VPULL();
1109
+ consolestr("#################### OPbytecode done"ENDLINE);
1110
+ // tron=0;
1111
+ // tron=1;
1112
+
1113
+ return;
1114
+ }
1115
+ break;
1116
+ case OPloopcb:
1117
+ VCALLSTACKSET(sys_start,SYS_CBLOOP,VSTACKGET(0));
1118
+ break;
1119
+ #ifdef VSIMU
1120
+ case OPudpStart:
1121
+ VSTACKSET(0,INTTOVAL(udpcreate(VALTOINT(VSTACKGET(0)))));
1122
+ break;
1123
+ case OPudpCb:
1124
+ VCALLSTACKSET(sys_start,SYS_CBUDP,VSTACKGET(0));
1125
+ break;
1126
+ case OPudpStop:
1127
+ VSTACKSET(0,INTTOVAL(udpclose(VALTOINT(VSTACKGET(0)))));
1128
+ break;
1129
+ case OPudpSend:
1130
+ {
1131
+ int len=VPULL();
1132
+ int start=VALTOINT(VPULL());
1133
+ int q=VALTOPNT(VPULL());
1134
+ int dstport=VALTOINT(VPULL());
1135
+ int p=VALTOPNT(VPULL());
1136
+ int localport=VALTOINT(VSTACKGET(0));
1137
+ if ((p!=NIL)&&(q!=NIL))
1138
+ {
1139
+ if (len==NIL)
1140
+ {
1141
+ len=VSIZEBIN(q)-start;
1142
+ }
1143
+ else
1144
+ {
1145
+ len=VALTOINT(len);
1146
+ }
1147
+ if (start+len>VSIZEBIN(q))
1148
+ {
1149
+ len=VSIZEBIN(q)-start;
1150
+ }
1151
+ if ((start>=0)&&(len>=0))
1152
+ {
1153
+ int k=udpsend(localport,VSTARTBIN(p),dstport,VSTARTBIN(q)+start,len);
1154
+ VSTACKSET(0,INTTOVAL(k));
1155
+ }
1156
+ else
1157
+ {
1158
+ VSTACKSET(0,NIL);
1159
+ }
1160
+ }
1161
+ else
1162
+ {
1163
+ VSTACKSET(0,NIL);
1164
+ }
1165
+
1166
+ }
1167
+ break;
1168
+ case OPtcpOpen:
1169
+ {
1170
+ int port=VALTOINT(VPULL());
1171
+ int p=VALTOPNT(VSTACKGET(0));
1172
+ if (p!=NIL)
1173
+ {
1174
+ VSTACKSET(0,INTTOVAL(tcpopen(VSTARTBIN(p),port)));
1175
+ }
1176
+ }
1177
+ break;
1178
+ case OPtcpClose:
1179
+ VSTACKSET(0,INTTOVAL(tcpclose(VALTOINT(VSTACKGET(0)))));
1180
+ break;
1181
+ case OPtcpSend:
1182
+ {
1183
+ int len=VPULL();
1184
+ int start=VPULL();
1185
+ int q=VALTOPNT(VPULL());
1186
+ int tcp=VALTOINT(VSTACKGET(0));
1187
+ if (start==NIL)
1188
+ {
1189
+ start=0;
1190
+ }
1191
+ else
1192
+ {
1193
+ start=VALTOINT(start);
1194
+ }
1195
+ if (q!=NIL)
1196
+ {
1197
+ if (len==NIL)
1198
+ {
1199
+ len=VSIZEBIN(q)-start;
1200
+ }
1201
+ else
1202
+ {
1203
+ len=VALTOINT(len);
1204
+ }
1205
+ if (start+len>VSIZEBIN(q))
1206
+ {
1207
+ len=VSIZEBIN(q)-start;
1208
+ }
1209
+ if ((start>=0)&&(len>=0))
1210
+ {
1211
+ int k;
1212
+ k=tcpsend(tcp,VSTARTBIN(q)+start,len);
1213
+ if (k>=0)
1214
+ {
1215
+ start+=k;
1216
+ }
1217
+ VSTACKSET(0,INTTOVAL(start));
1218
+ }
1219
+ else
1220
+ {
1221
+ VSTACKSET(0,NIL);
1222
+ }
1223
+ }
1224
+ else
1225
+ {
1226
+ VSTACKSET(0,NIL);
1227
+ }
1228
+ }
1229
+ break;
1230
+ case OPtcpCb:
1231
+ VCALLSTACKSET(sys_start,SYS_CBTCP,VSTACKGET(0));
1232
+ break;
1233
+ case OPtcpListen:
1234
+ {
1235
+ int port=VALTOINT(VSTACKGET(0));
1236
+ VSTACKSET(0,INTTOVAL(tcpservercreate(port)));
1237
+ }
1238
+ break;
1239
+ case OPtcpEnable:
1240
+ {
1241
+ int enable=VALTOINT(VPULL());
1242
+ tcpenable(VALTOINT(VSTACKGET(0)),enable);
1243
+ }
1244
+ break;
1245
+ #endif
1246
+ case OPSecholn:
1247
+ logSecho(VSTACKGET(0),1);
1248
+ // if (tron)dump(&bytecode[0x2440],32);
1249
+ break;
1250
+ case OPIecholn:
1251
+ logIecho(VSTACKGET(0),1);
1252
+ break;
1253
+ case OPenvget:
1254
+ VPUSH(VCALLSTACKGET(sys_start,SYS_ENV));
1255
+ break;
1256
+ case OPenvset:
1257
+ VCALLSTACKSET(sys_start,SYS_ENV,VSTACKGET(0));
1258
+ break;
1259
+ case OPsndVol:
1260
+ audioVol(VALTOINT(VSTACKGET(0)));
1261
+ break;
1262
+ case OPrfidGet:
1263
+ {
1264
+ char *p;
1265
+ p=sysRfidget();
1266
+ if (!p)
1267
+ {
1268
+ VPUSH(NIL);
1269
+ }
1270
+ else
1271
+ {
1272
+ VPUSH(PNTTOVAL(VMALLOCSTR(p,8)));
1273
+ }
1274
+ }
1275
+ break;
1276
+ case OPplayTime:
1277
+ VPUSH(INTTOVAL(audioPlayTime()));
1278
+ break;
1279
+ case OPnetCb:
1280
+ VCALLSTACKSET(sys_start,SYS_CBTCP,VSTACKGET(0));
1281
+ break;
1282
+ case OPnetSend:
1283
+ {
1284
+ int speed=VALTOINT(VPULL());
1285
+ int indmac=VALTOINT(VPULL());
1286
+ int q=VALTOPNT(VPULL());
1287
+ int len=VPULL();
1288
+ int index=VALTOINT(VPULL());
1289
+ int p=VALTOPNT(VSTACKGET(0));
1290
+ if ((p!=NIL)&&(q!=NIL))
1291
+ {
1292
+ if (len==NIL)
1293
+ {
1294
+ len=VSIZEBIN(p)-index;
1295
+ }
1296
+ else
1297
+ {
1298
+ len=VALTOINT(len);
1299
+ }
1300
+ VSTACKSET(0,INTTOVAL(netSend(VSTARTBIN(p),index,len,VSIZEBIN(p),VSTARTBIN(q),indmac,VSIZEBIN(q),speed)));
1301
+ }
1302
+ else
1303
+ {
1304
+ VSTACKSET(0,NIL);
1305
+ }
1306
+ }
1307
+ break;
1308
+ case OPnetState:
1309
+ VPUSH(INTTOVAL(netState()));
1310
+ break;
1311
+ case OPnetMac:
1312
+ VPUSH(PNTTOVAL(VMALLOCSTR(netMac(),6)));
1313
+ break;
1314
+ case OPnetChk:
1315
+ {
1316
+ int val=VALTOINT(VPULL());
1317
+ int len=VPULL();
1318
+ int index=VALTOINT(VPULL());
1319
+ int p=VALTOPNT(VSTACKGET(0));
1320
+ if (p!=NIL)
1321
+ {
1322
+ if (len==NIL)
1323
+ {
1324
+ len=VSIZEBIN(p)-index;
1325
+ }
1326
+ else
1327
+ {
1328
+ len=VALTOINT(len);
1329
+ }
1330
+ VSTACKSET(0,INTTOVAL(netChk(VSTARTBIN(p),index,len,VSIZEBIN(p),val)));
1331
+ }
1332
+ else
1333
+ {
1334
+ VSTACKSET(0,INTTOVAL(val));
1335
+ }
1336
+ }
1337
+ break;
1338
+ case OPnetSetmode:
1339
+ {
1340
+ int chn=VALTOINT(VPULL());
1341
+ int p=VALTOPNT(VPULL());
1342
+ int md=VALTOINT(VSTACKGET(0));
1343
+ char* ssid=(p==NIL)?NULL:VSTARTBIN(p);
1344
+ netSetmode(md,ssid,chn);
1345
+ }
1346
+ break;
1347
+ case OPnetScan:
1348
+ {
1349
+ int p=VALTOPNT(VPULL());
1350
+ char* ssid=(p==NIL)?NULL:VSTARTBIN(p);
1351
+ netScan(ssid);
1352
+ }
1353
+ break;
1354
+ case OPnetAuth:
1355
+ {
1356
+ int key=VALTOPNT(VPULL());
1357
+ int encrypt=VALTOINT(VPULL());
1358
+ int authmode=VALTOINT(VPULL());
1359
+ int scan=VALTOPNT(VSTACKGET(0));
1360
+ if (scan!=NIL)
1361
+ {
1362
+ int ssid=VALTOPNT(VFETCH(scan,0));
1363
+ int mac=VALTOPNT(VFETCH(scan,1));
1364
+ int bssid=VALTOPNT(VFETCH(scan,2));
1365
+ int chn=VALTOINT(VFETCH(scan,4));
1366
+ int rate=VALTOINT(VFETCH(scan,5));
1367
+ if ((mac!=NIL)&&(bssid!=NIL))
1368
+ {
1369
+ netAuth((ssid==NIL)?NULL:VSTARTBIN(ssid),VSTARTBIN(mac),
1370
+ VSTARTBIN(bssid),chn,rate,authmode,
1371
+ encrypt,(key==NIL)?NULL:VSTARTBIN(key));
1372
+ }
1373
+ }
1374
+ }
1375
+ break;
1376
+ case OPnetSeqAdd:
1377
+ {
1378
+ int inc=VALTOINT(VPULL());
1379
+ int seq=VALTOPNT(VPULL());
1380
+ if ((seq==NIL)||(VSIZEBIN(seq)<4))
1381
+ {
1382
+ VPUSH(NIL);
1383
+ }
1384
+ else
1385
+ {
1386
+ netSeqAdd((unsigned char*)VSTARTBIN(seq),inc);
1387
+ }
1388
+ }
1389
+ break;
1390
+ case OPstrgetword:
1391
+ {
1392
+ int ind=VALTOINT(VPULL());
1393
+ int src=VALTOPNT(VSTACKGET(0));
1394
+ if (src!=NIL)
1395
+ {
1396
+ VSTACKSET(0,INTTOVAL(sysStrgetword((unsigned char*)VSTARTBIN(src),VSIZEBIN(src),ind)));
1397
+ }
1398
+ }
1399
+ break;
1400
+ case OPstrputword:
1401
+ {
1402
+ int val=VALTOINT(VPULL());
1403
+ int ind=VALTOINT(VPULL());
1404
+ int src=VALTOPNT(VSTACKGET(0));
1405
+ if (src!=NIL)
1406
+ {
1407
+ sysStrputword((unsigned char*)VSTARTBIN(src),VSIZEBIN(src),ind,val);
1408
+ }
1409
+ }
1410
+ break;
1411
+ case OPatoi:
1412
+ {
1413
+ int src=VALTOPNT(VSTACKGET(0));
1414
+ if (src!=NIL)
1415
+ {
1416
+ VSTACKSET(0,INTTOVAL(sysAtoi(VSTARTBIN(src))));
1417
+ }
1418
+ }
1419
+ break;
1420
+ case OPhtoi:
1421
+ {
1422
+ int src=VALTOPNT(VSTACKGET(0));
1423
+ if (src!=NIL)
1424
+ {
1425
+ VSTACKSET(0,INTTOVAL(sysHtoi(VSTARTBIN(src))));
1426
+ }
1427
+ }
1428
+ break;
1429
+ case OPitoa:
1430
+ sysItoa(VALTOINT(VPULL()));
1431
+ break;
1432
+ case OPctoa:
1433
+ {
1434
+ int val=VALTOINT(VPULL());
1435
+ sysCtoa(val);
1436
+ }
1437
+ break;
1438
+ case OPitoh:
1439
+ sysItoh(VALTOINT(VPULL()));
1440
+ break;
1441
+ case OPctoh:
1442
+ sysCtoh(VALTOINT(VPULL()));
1443
+ break;
1444
+ case OPitobin2:
1445
+ sysItobin2(VALTOINT(VPULL()));
1446
+ break;
1447
+ case OPlistswitch:
1448
+ {
1449
+ int key=VPULL();
1450
+ int p=VALTOPNT(VSTACKGET(0));
1451
+ VSTACKSET(0,sysListswitch(p,key));
1452
+ }
1453
+ break;
1454
+ case OPlistswitchstr:
1455
+ {
1456
+ int key=VPULL();
1457
+ int p=VALTOPNT(VSTACKGET(0));
1458
+ if (key==NIL)
1459
+ {
1460
+ VSTACKSET(0,sysListswitch(p,key));
1461
+ }
1462
+ else
1463
+ {
1464
+ VSTACKSET(0,sysListswitchstr(p,VSTARTBIN(VALTOPNT(key))));
1465
+ }
1466
+ }
1467
+ break;
1468
+ case OPsndRefresh:
1469
+ audioRefresh();
1470
+ VPUSH(NIL);
1471
+ break;
1472
+ case OPsndWrite:
1473
+ {
1474
+ int val=VALTOINT(VPULL());
1475
+ audioWrite(VALTOINT(VSTACKGET(0)),val);
1476
+ }
1477
+ break;
1478
+ case OPsndRead:
1479
+ VSTACKSET(0,INTTOVAL(audioRead(VALTOINT(VSTACKGET(0)))));
1480
+ break;
1481
+ case OPsndFeed:
1482
+ {
1483
+ int len=VPULL();
1484
+ int start=VPULL();
1485
+ int q=VALTOPNT(VSTACKGET(0));
1486
+ if (start==NIL)
1487
+ {
1488
+ start=0;
1489
+ }
1490
+ else
1491
+ {
1492
+ start=VALTOINT(start);
1493
+ }
1494
+ if (q!=NIL)
1495
+ {
1496
+ if (len==NIL)
1497
+ {
1498
+ len=VSIZEBIN(q)-start;
1499
+ }
1500
+ else
1501
+ {
1502
+ len=VALTOINT(len);
1503
+ }
1504
+ if (start+len>VSIZEBIN(q))
1505
+ {
1506
+ len=VSIZEBIN(q)-start;
1507
+ }
1508
+ if ((start>=0)&&(len>=0))
1509
+ {
1510
+ int k=audioFeed(VSTARTBIN(q)+start,len);
1511
+ VSTACKSET(0,INTTOVAL(k));
1512
+ }
1513
+ else
1514
+ {
1515
+ VSTACKSET(0,NIL);
1516
+ }
1517
+ }
1518
+ else
1519
+ {
1520
+ VSTACKSET(0,NIL);
1521
+ }
1522
+ }
1523
+ break;
1524
+ case OPsndAmpli:
1525
+ audioAmpli(VALTOINT(VSTACKGET(0)));
1526
+ break;
1527
+ case OPcorePP:
1528
+ VPUSH(INTTOVAL(vmem_stack));
1529
+ break;
1530
+ case OPcorePush:
1531
+ VPUSH(VSTACKGET(0));
1532
+ break;
1533
+ case OPcorePull:
1534
+ VSTACKSET(1,VSTACKGET(0));
1535
+ VPULL();
1536
+ break;
1537
+ case OPcoreBit0:
1538
+ {
1539
+ int v=VALTOINT(VPULL());
1540
+ VSTACKSET(0,(VSTACKGET(0)&0xfffffffe)|(v&1));
1541
+ }
1542
+ break;
1543
+ case OPreboot:
1544
+ {
1545
+ int w=VALTOINT(VPULL());
1546
+ int v=VALTOINT(VSTACKGET(0));
1547
+ consolestr("reboot ");
1548
+ consolehx(v);
1549
+ consolestr(".");
1550
+ consolehx(w);
1551
+ consolestr("\n");
1552
+ if ((v==0x0407FE58)&&(w==0x13fb6754))
1553
+ {
1554
+ consolestr("************REBOOT NOW");
1555
+ sysReboot();
1556
+ }
1557
+ }
1558
+ break;
1559
+ case OPstrcmp:
1560
+ {
1561
+ int q=VALTOPNT(VPULL());
1562
+ int p=VALTOPNT(VSTACKGET(0));
1563
+ if ((p!=NIL)&&(q!=NIL))
1564
+ {
1565
+ int pl=VSIZEBIN(p);
1566
+ int ql=VSIZEBIN(q);
1567
+
1568
+ VSTACKSET(0,INTTOVAL(memcmp(VSTARTBIN(p),VSTARTBIN(q),(pl>ql)?pl:ql)));
1569
+ }
1570
+ else
1571
+ {
1572
+ VSTACKSET(0,INTTOVAL((p!=NIL)?1:(q!=NIL)?-1:0));
1573
+ }
1574
+ }
1575
+ break;
1576
+ case OPadp2wav:
1577
+ {
1578
+ int len=VPULL();
1579
+ int start=VALTOINT(VPULL());
1580
+ int q=VALTOPNT(VPULL());
1581
+ int index=VALTOINT(VPULL());
1582
+ int p=VALTOPNT(VSTACKGET(0));
1583
+ if ((p!=NIL)&&(q!=NIL))
1584
+ {
1585
+ if (len==NIL)
1586
+ {
1587
+ len=VSIZEBIN(q)-start;
1588
+ }
1589
+ else
1590
+ {
1591
+ len=VALTOINT(len);
1592
+ }
1593
+ AudioAdp2wav(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,VSIZEBIN(q),len);
1594
+ }
1595
+ }
1596
+ break;
1597
+ case OPwav2adp:
1598
+ {
1599
+ int len=VPULL();
1600
+ int start=VALTOINT(VPULL());
1601
+ int q=VALTOPNT(VPULL());
1602
+ int index=VALTOINT(VPULL());
1603
+ int p=VALTOPNT(VSTACKGET(0));
1604
+ if ((p!=NIL)&&(q!=NIL))
1605
+ {
1606
+ if (len==NIL)
1607
+ {
1608
+ len=VSIZEBIN(q)-start;
1609
+ }
1610
+ else
1611
+ {
1612
+ len=VALTOINT(len);
1613
+ }
1614
+ AudioWav2adp(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,VSIZEBIN(q),len);
1615
+ }
1616
+ }
1617
+ break;
1618
+ case OPalaw2wav:
1619
+ {
1620
+ int mu=VALTOINT(VPULL());
1621
+ int len=VPULL();
1622
+ int start=VALTOINT(VPULL());
1623
+ int q=VALTOPNT(VPULL());
1624
+ int index=VALTOINT(VPULL());
1625
+ int p=VALTOPNT(VSTACKGET(0));
1626
+ if ((p!=NIL)&&(q!=NIL))
1627
+ {
1628
+ if (len==NIL)
1629
+ {
1630
+ len=VSIZEBIN(q)-start;
1631
+ }
1632
+ else
1633
+ {
1634
+ len=VALTOINT(len);
1635
+ }
1636
+ AudioAlaw2wav(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,VSIZEBIN(q),len,mu);
1637
+ }
1638
+ }
1639
+ break;
1640
+ case OPwav2alaw:
1641
+ {
1642
+ int mu=VALTOINT(VPULL());
1643
+ int len=VPULL();
1644
+ int start=VALTOINT(VPULL());
1645
+ int q=VALTOPNT(VPULL());
1646
+ int index=VALTOINT(VPULL());
1647
+ int p=VALTOPNT(VSTACKGET(0));
1648
+ if ((p!=NIL)&&(q!=NIL))
1649
+ {
1650
+ if (len==NIL)
1651
+ {
1652
+ len=VSIZEBIN(q)-start;
1653
+ }
1654
+ else
1655
+ {
1656
+ len=VALTOINT(len);
1657
+ }
1658
+ AudioWav2alaw(VSTARTBIN(p),index,VSIZEBIN(p),VSTARTBIN(q),start,VSIZEBIN(q),len,mu);
1659
+ }
1660
+ }
1661
+ break;
1662
+ case OPnetPmk:
1663
+ {
1664
+ int key=VALTOPNT(VPULL());
1665
+ int ssid=VALTOPNT(VPULL());
1666
+ if ((key==NIL)||(ssid==NIL))
1667
+ {
1668
+ VPUSH(NIL);
1669
+ }
1670
+ else
1671
+ {
1672
+ char pmk[32];
1673
+ netPmk(VSTARTBIN(ssid),VSTARTBIN(key),pmk);
1674
+ VPUSH(PNTTOVAL(VMALLOCSTR(pmk,32)));
1675
+ }
1676
+ }
1677
+ break;
1678
+ case OPflashFirmware:
1679
+ {
1680
+ int w=VALTOINT(VPULL());
1681
+ int v=VALTOINT(VPULL());
1682
+ int firmware=VALTOPNT(VSTACKGET(0));
1683
+ consolestr("flash firmware ");
1684
+ consolehx(v);
1685
+ consolestr(".");
1686
+ consolehx(w);
1687
+ consolestr("\n");
1688
+ if ((firmware!=NIL)&&(v==0x13fb6754)&&(w==0x0407FE58))
1689
+ {
1690
+ consolestr("************FLASH AND REBOOT NOW");
1691
+ sysFlash(VSTARTBIN(firmware),VSIZEBIN(firmware));
1692
+ }
1693
+ }
1694
+ break;
1695
+ case OPcrypt:
1696
+ {
1697
+ int alpha=VALTOINT(VPULL());
1698
+ int key=VALTOINT(VPULL());
1699
+ int len=VPULL();
1700
+ int index=VALTOINT(VPULL());
1701
+ int p=VALTOPNT(VSTACKGET(0));
1702
+ if (p!=NIL)
1703
+ {
1704
+ if (len==NIL)
1705
+ {
1706
+ len=VSIZEBIN(p)-index;
1707
+ }
1708
+ else
1709
+ {
1710
+ len=VALTOINT(len);
1711
+ }
1712
+ VSTACKSET(0,INTTOVAL(sysCrypt(VSTARTBIN(p),index,len,VSIZEBIN(p),key,alpha)));
1713
+ }
1714
+ else
1715
+ {
1716
+ VSTACKSET(0,NIL);
1717
+ }
1718
+ }
1719
+ break;
1720
+ case OPuncrypt:
1721
+ {
1722
+ int alpha=VALTOINT(VPULL());
1723
+ int key=VALTOINT(VPULL());
1724
+ int len=VPULL();
1725
+ int index=VALTOINT(VPULL());
1726
+ int p=VALTOPNT(VSTACKGET(0));
1727
+ if (p!=NIL)
1728
+ {
1729
+ if (len==NIL)
1730
+ {
1731
+ len=VSIZEBIN(p)-index;
1732
+ }
1733
+ else
1734
+ {
1735
+ len=VALTOINT(len);
1736
+ }
1737
+ VSTACKSET(0,INTTOVAL(sysUncrypt(VSTARTBIN(p),index,len,VSIZEBIN(p),key,alpha)));
1738
+ }
1739
+ else
1740
+ {
1741
+ VSTACKSET(0,NIL);
1742
+ }
1743
+ }
1744
+ break;
1745
+ case OPnetRssi:
1746
+ VPUSH(INTTOVAL(netRssi()));
1747
+ break;
1748
+ default:
1749
+ consolestr("unknown opcode ");
1750
+ consoleint(op);
1751
+ consolestr(" at ");
1752
+ consoleint(pc-1);
1753
+ consolestr("\n");
1754
+ // dump(bytecode,256);
1755
+ return;
1756
+ }
1757
+ /* if (bytecode[8]==0x48)
1758
+ {
1759
+ consolestr("bytecode erase ");consoleint(op);
1760
+ consolestr(" at ");consoleint(pc-1);consolestr("\n");
1761
+ dump(bytecode,256);
1762
+ }
1763
+ */
1764
+ }
1765
+ while(cont);
1766
+ currentop=-1;
1767
+ if (callstack>0)
1768
+ {
1769
+ return;
1770
+ }
1771
+ if(pc>=0)
1772
+ {
1773
+ // vmemDumpStack();
1774
+ // displaybc(pc);
1775
+
1776
+ // getchar();
1777
+ }
1778
+ op=255&bytecode[pc++];
1779
+ }
1780
+ }