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
@@ -1,127 +0,0 @@
1
- // VLISP Virtual Machine - 2006 - by Sylvain Huet
2
- // Lowcost IS Powerfull
3
-
4
- #include <string.h>
5
- #include"vmem.h"
6
- #include"vloader.h"
7
-
8
- char *bc_tabfun;
9
- int bc_nbfun;
10
- int sys_start;
11
- int global_start;
12
-
13
- int loaderGetByte(char *src)
14
- {
15
- int i;
16
- i=(src[0]&255);
17
- return i;
18
- }
19
- int loaderGetShort(char *src)
20
- {
21
- int i;
22
- i=((src[1]&255)<<8)+(src[0]&255);
23
- return i;
24
- }
25
- int loaderGetInt(char *src)
26
- {
27
- int i;
28
- i=((src[3]&255)<<24)+((src[2]&255)<<16)+((src[1]&255)<<8)+(src[0]&255);
29
- return i;
30
- }
31
-
32
- /**
33
- Charge les variables globales
34
- */
35
- char *loaderInitRec(char *src)
36
- {
37
- int l,i;
38
-
39
- l=loaderGetInt(src);
40
- src+=4;
41
- if (l==-1)
42
- {
43
- // printf("nil\n",l>>1);
44
- VPUSH(NIL);
45
- }
46
- else if (l&1)
47
- {
48
- l>>=1;
49
- if (l&1)
50
- {
51
- l>>=1;
52
- // printf("tuple %d\n",l);
53
- for(i=0;i<l;i++) src=loaderInitRec(src);
54
- VMKTAB(l);
55
- }
56
- else
57
- {
58
- l>>=1;
59
- // printf("string taille %d\n",l);
60
- VPUSH(PNTTOVAL(VMALLOCSTR(src,l)));
61
- src+=l;
62
- }
63
- }
64
- else
65
- {
66
- // printf("int %d\n",l>>1);
67
- VPUSH(l);
68
- }
69
- return src;
70
- }
71
-
72
- int loaderSizeBC(char *src)
73
- {
74
- int n,b;
75
- n=loaderGetInt(src);
76
- src+=n;
77
- b=loaderGetInt(src);
78
- src+=4+b;
79
- n+=4+b;
80
- n+=2+(loaderGetShort(src)<<2);
81
- return n;
82
- }
83
-
84
- int loaderInit(char *src)
85
- {
86
- int n,nw,i;
87
- char* src0;
88
- char* dst;
89
-
90
- n=loaderSizeBC(src);
91
- dst=(char*)vmem_heap;
92
- memcpy(dst,src,n);
93
- nw=(n+3)>>2;
94
- vmemInit(nw);
95
-
96
- src=(char*)vmem_heap;
97
-
98
- sys_start=vmem_stack-1;
99
- for(i=0;i<SYS_NB;i++) VPUSH(NIL);
100
-
101
- src0=src;
102
- n=loaderGetInt(src);
103
- src+=4;
104
- global_start=vmem_stack-1;
105
- while(((int)(src-src0))<n) src=loaderInitRec(src);
106
-
107
- n=loaderGetInt(src);
108
- src+=4;
109
-
110
- bc_tabfun=&bytecode[n+2]; // bytecode == vmem_heap == src ...
111
- bc_nbfun=loaderGetShort(src+n);
112
- n+=2+(bc_nbfun<<2);
113
- for(i=0;i<n;i++) bytecode[i]=src[i];
114
- vmemSetstart((n+3)>>2);
115
-
116
- return 0;
117
- }
118
-
119
-
120
- /**
121
- Retourne l'adresse du début d'une fonction dans le bytecode
122
- */
123
- int loaderFunstart(int funnumber)
124
- {
125
- return loaderGetInt(bc_tabfun+(funnumber<<2));
126
- }
127
-
@@ -1,589 +0,0 @@
1
- // VLISP Virtual Machine - 2006 - by Sylvain Huet
2
- // Lowcost IS Powerfull
3
-
4
- #include <string.h>
5
-
6
- #include"vmem.h"
7
- #include"vloader.h"
8
- #ifdef VSIMU
9
- #include <stdlib.h>
10
- #include<stdio.h>
11
- #include<time.h>
12
- #include <sys/time.h>
13
- #endif
14
- #ifdef VREAL
15
- #include "ML674061.h"
16
- #include "common.h"
17
- #include "irq.h"
18
- #include "spi.h"
19
- #include "led.h"
20
- #include "mem.h"
21
- #include "uart.h"
22
- #include "debug.h"
23
- #include "usbh.h"
24
-
25
- #include "delay.h"
26
- #include "audio.h"
27
- #include "motor.h"
28
- #include "usbctrl.h"
29
- #include "ml60842.h"
30
- #include "hcdmem.h"
31
- #include "hcd.h"
32
- #include "inarm.h"
33
- #include "i2c.h"
34
- #include "rt2501usb.h"
35
- #include "mem.h"
36
- #include<stdio.h>
37
- #include<string.h>
38
-
39
- #include"led.h"
40
- #include"motor.h"
41
- #include"delay.h"
42
- #include"rfid.h"
43
- #endif
44
- #include"vlog.h"
45
-
46
- void logSecho(int p,int nl)
47
- {
48
- if (p==NIL) consolestr("NIL");
49
- else consolebin((unsigned char*)VSTARTBIN(VALTOPNT(p)),VSIZEBIN(VALTOPNT(p)));
50
- if (nl) consolestr(ENDLINE);
51
- }
52
-
53
- void logIecho(int i,int nl)
54
- {
55
- if (i==NIL) consolestr("NIL");
56
- else consoleint(VALTOINT(i));
57
- if (nl) consolestr(ENDLINE);
58
- }
59
-
60
- extern int currentop;
61
- void logGC()
62
- {
63
- consolestr("#GC : sp=");consoleint(-vmem_stack);
64
- consolestr(" hp=");consoleint(vmem_heapindex);
65
- consolestr(" used=");consoleint((vmem_heapindex-vmem_stack)*100/VMEM_LENGTH);
66
- consolestr("%"ENDLINE);
67
- consolestr(" b:");consolehx((int)vmem_heap);
68
- consolestr(" bc:");consolehx((int)bytecode);
69
- consolestr(" st:");consolehx(vmem_start);
70
- consolestr(" op:");consolehx(currentop);
71
- consolestr(ENDLINE);
72
-
73
- }
74
-
75
-
76
- // pour le firmware, le "fichier" ouvert est toujours l'eeprom
77
-
78
- int sysLoad(char *dst,int i,int ldst,char *filename,int j,int len)
79
- {
80
- #ifdef VSIMU
81
- FILE *f;
82
- if ((j<0)||(i<0)||(len<=0)) return 0;
83
- if (i+len>ldst) len=ldst-i;
84
- if (len<=0) return 0;
85
- f=fopen(filename,"rb");
86
- if (!f) return 0;
87
- fseek(f,j,SEEK_SET);
88
- len=fread(dst,1,len,f);
89
- fclose(f);
90
- return len;
91
- #endif
92
- #ifdef VREAL
93
- /* set_vlsi_volume(0); //volume on 8bits, 0x00 => maximum
94
- encode_adpcm((UBYTE*)dst+i,(ldst-i-256)>>8, j);
95
- return 0;
96
- */
97
- if ((j<0)||(i<0)||(len<=0)) return 0;
98
- if (i+len>ldst) len=ldst-i;
99
- if (len<=0) return 0;
100
- if (j+len>4096) len=4096-j;
101
- if (len<=0) return 0;
102
- read_uc_flash(j,(unsigned char*)dst,len);
103
- return len;
104
- #endif
105
- }
106
-
107
- uchar buffer_temp[4096];
108
-
109
- // pour le firmware, le "fichier" ouvert est toujours l'eeprom
110
- int sysSave(char *dst,int i,int ldst,char *filename,int j,int len)
111
- {
112
- #ifdef VSIMU
113
- FILE *f;
114
- if ((j<0)||(i<0)||(len<=0)) return 0;
115
- if (i+len>ldst) len=ldst-i;
116
- if (len<=0) return 0;
117
- f=fopen(filename,"rb+");
118
- if (!f) f=fopen(filename,"wb+");
119
- if (!f) return 0;
120
- fseek(f,j,SEEK_SET);
121
- len=fwrite(dst,1,len,f);
122
- fclose(f);
123
- return len;
124
- #endif
125
- #ifdef VREAL
126
- if ((j<0)||(i<0)||(len<=0)) return 0;
127
- if (i+len>ldst) len=ldst-i;
128
- if (len<=0) return 0;
129
- if (j+len>4096) len=4096-j;
130
- if (len<=0) return 0;
131
- __disable_interrupt();
132
- write_uc_flash(j,(unsigned char*)dst,len,buffer_temp);
133
- __enable_interrupt();
134
- return len;
135
- #endif
136
- }
137
-
138
- static int firstTimeSet = 0;
139
- static struct timeval firstTime;
140
-
141
- int sysTimems()
142
- {
143
- #ifdef VSIMU
144
- int res;
145
- struct timeval tv;
146
- if (firstTimeSet) {
147
- gettimeofday(&tv, NULL);
148
- res = (tv.tv_sec - firstTime.tv_sec) * 1000;
149
- res += (tv.tv_usec - firstTime.tv_usec) / 1000;
150
- } else {
151
- gettimeofday(&firstTime, NULL);
152
- firstTimeSet = 1;
153
- res = 0;
154
- }
155
- return res;
156
- #endif // ! VSIMU
157
- #ifdef VREAL
158
- return counter_timer;
159
- #endif
160
- }
161
-
162
- int sysTime()
163
- {
164
- #ifdef VSIMU
165
- int res;
166
- static int firstTimeSet = 0;
167
- static struct timeval firstTime;
168
- struct timeval tv;
169
- if (firstTimeSet) {
170
- gettimeofday(&tv, NULL);
171
- res = (tv.tv_sec - firstTime.tv_sec);
172
- res += (tv.tv_usec >= firstTime.tv_usec) ? 0 : -1;
173
- } else {
174
- gettimeofday(&firstTime, NULL);
175
- firstTimeSet = 1;
176
- res = 0;
177
- }
178
- return res;
179
- #endif
180
- #ifdef VREAL
181
- return counter_timer_s;
182
- #endif
183
- }
184
-
185
-
186
- int rndval;
187
-
188
- // retourne une valeur al�atoire entre 0 et 65535
189
- int sysRand()
190
- {
191
- rndval=rndval*0x1234567+11;
192
- return (rndval>>8)&0xffff;
193
- }
194
- void sysSrand(int seed)
195
- {
196
- rndval=seed;
197
- }
198
-
199
-
200
- void sysCpy(char *dst,int i,int ldst,char *src,int j,int lsrc,int len)
201
- {
202
- if ((i<0)||(j<0)||(len<=0)) return;
203
- if (i+len>ldst) len=ldst-i;
204
- if (len<=0) return;
205
- if (j+len>lsrc) len=lsrc-j;
206
- if (len<=0) return;
207
- dst+=i;
208
- src+=j;
209
- while((len--)>0) *(dst++)=*(src++);
210
- }
211
-
212
- int sysCmp(char *dst,int i,int ldst,char *src,int j,int lsrc,int len)
213
- {
214
- if ((i<0)||(j<0)||(len<=0)) return 0;
215
- if ((i+len>ldst)&&(j+len>lsrc))
216
- {
217
- if (ldst-i>lsrc-j) len=ldst-i;
218
- else len=lsrc-j;
219
- }
220
- dst+=i;
221
- src+=j;
222
- while((len--)>0) if (((unsigned char)*dst)>((unsigned char)*src)) return 1;
223
- else if (((unsigned char)*(dst++))<((unsigned char)*(src++))) return -1;
224
- return 0;
225
- }
226
-
227
- int mystrcmp(char *dst,char *src,int len)
228
- {
229
- while((len--)>0) if ((*(dst++))!=(*(src++))) return 1;
230
- return 0;
231
- }
232
-
233
- void mystrcpy(char *dst,char *src,int len)
234
- {
235
- while((len--)>0) *(dst++)=*(src++);
236
- }
237
-
238
- int sysFind(char *dst,int i,int ldst,char *src,int j,int lsrc,int len)
239
- {
240
- if ((j<0)||(j+len>lsrc)) return NIL;
241
- src+=j;
242
- if (i<0) i=0;
243
- while(i+len<=ldst)
244
- {
245
- if (!mystrcmp(dst+i,src,len)) return INTTOVAL(i);
246
- i++;
247
- }
248
- return NIL;
249
- }
250
-
251
- int sysFindrev(char *dst,int i,int ldst,char *src,int j,int lsrc,int len)
252
- {
253
- if ((j<0)||(j+len>lsrc)) return NIL;
254
- src+=j;
255
- if(i+len>ldst) i=ldst-len;
256
- while(i>=0)
257
- {
258
- if (!mystrcmp(dst+i,src,len)) return INTTOVAL(i);
259
- i--;
260
- }
261
- return NIL;
262
- }
263
-
264
- int sysStrgetword(unsigned char *src,int len,int ind)
265
- {
266
- int n;
267
- if ((ind<0)||(ind+2>len)) return -1;
268
- n=(src[ind]<<8)+src[ind+1];
269
- return n;
270
- }
271
-
272
- void sysStrputword(unsigned char *src,int len,int ind,int val)
273
- {
274
- if ((ind<0)||(ind+2>len)) return;
275
- src[ind+1]=val; val>>=8;
276
- src[ind]=val;
277
- }
278
-
279
- // lecture d'une cha�ne d�cimale (s'arr�te au premier caract�re incorrect)
280
- int sysAtoi(char* src)
281
- {
282
- int x,c,s;
283
- x=s=0;
284
- if ((*src)=='-') { s=1; src++; }
285
- while(c=*src++)
286
- {
287
- if ((c>='0')&&(c<='9')) x=(x*10)+c-'0';
288
- else return (s?(-x):x);
289
- }
290
- return (s?(-x):x);
291
- }
292
-
293
- // lecture d'une cha�ne hexad�cimale (s'arr�te au premier caract�re incorrect)
294
- int sysHtoi(char* src)
295
- {
296
- int x,c;
297
- x=0;
298
- while(c=*src++)
299
- {
300
- if ((c>='0')&&(c<='9')) x=(x<<4)+c-'0';
301
- else if ((c>='A')&&(c<='F')) x=(x<<4)+c-'A'+10;
302
- else if ((c>='a')&&(c<='f')) x=(x<<4)+c-'a'+10;
303
- else return x;
304
- }
305
- return x;
306
- }
307
- void sysCtoa(int c)
308
- {
309
- unsigned char res[1];
310
- res[0]=c;
311
- VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,1)));
312
- }
313
-
314
- const int itoarsc[10]={
315
- 1000000000,100000000,10000000,
316
- 1000000 ,100000 ,10000,
317
- 1000 ,100 ,10,
318
- 1
319
- };;
320
- void sysItoa(int v)
321
- {
322
- char res[16];
323
- int ires=0;
324
- if (v==0)
325
- {
326
- res[ires++]='0';
327
- }
328
- else
329
- {
330
- int start=1;
331
- int imul=0;
332
- if (v<0)
333
- {
334
- v=-v;
335
- res[ires++]='-';
336
- }
337
- while(imul<10)
338
- {
339
- int k=0;
340
- while(v>=itoarsc[imul])
341
- {
342
- k++;
343
- v-=itoarsc[imul];
344
- }
345
- if ((k)||(!start))
346
- {
347
- start=0;
348
- res[ires++]='0'+k;
349
- }
350
- imul++;
351
- }
352
- }
353
-
354
- VPUSH(PNTTOVAL(VMALLOCSTR(res,ires)));
355
-
356
- }
357
-
358
- void sysItoh(int v)
359
- {
360
- char res[16];
361
- int ires=0;
362
- if (v==0)
363
- {
364
- res[ires++]='0';
365
- }
366
- else
367
- {
368
- int start=1;
369
- int imul=28;
370
- while(imul>=0)
371
- {
372
- int c=(v>>imul)&15;
373
- if ((c)||(!start))
374
- {
375
- start=0;
376
- res[ires++]=(c<10)?'0'+c:'a'+c-10;
377
- }
378
- imul-=4;
379
- }
380
- }
381
- VPUSH(PNTTOVAL(VMALLOCSTR(res,ires)));
382
- }
383
-
384
- void sysCtoh(int c)
385
- {
386
- unsigned char res[2];
387
- int v=(c>>4)&15;
388
- res[0]=(v<10)?'0'+v:'a'+v-10;
389
- v=c&15;
390
- res[1]=(v<10)?'0'+v:'a'+v-10;
391
- VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,2)));
392
- }
393
-
394
- void sysItobin2(int c)
395
- {
396
- unsigned char res[2];
397
- res[1]=c;
398
- c>>=8;
399
- res[0]=c;
400
- VPUSH(PNTTOVAL(VMALLOCSTR((char*)res,2)));
401
- }
402
-
403
- int sysListswitch(int p,int key)
404
- {
405
- while(p!=NIL)
406
- {
407
- int q=VALTOPNT(VFETCH(p,0));
408
- if ((q!=NIL)&&(VFETCH(q,0)==key)) return VFETCH(q,1);
409
- p=VALTOPNT(VFETCH(p,1));
410
- }
411
- return NIL;
412
- }
413
-
414
- int sysListswitchstr(int p,char* key)
415
- {
416
- while(p!=NIL)
417
- {
418
- int q=VALTOPNT(VFETCH(p,0));
419
- if (q!=NIL)
420
- {
421
- int r=VALTOPNT(VFETCH(q,0));
422
- if ((r!=NIL)&&(!strcmp(VSTARTBIN(r),key))) return VFETCH(q,1);
423
- }
424
- p=VALTOPNT(VFETCH(p,1));
425
- }
426
- return NIL;
427
- }
428
-
429
- void simuSetLed(int i,int val);
430
- void set_motor_dir(int num_motor, int sens);
431
- int get_motor_val(int i);
432
- int getButton();
433
- int get_button3();
434
- char* get_rfid();
435
-
436
- void sysLed(int led,int col)
437
- {
438
- #ifdef VSIMU
439
- simuSetLed(led,col);
440
- #endif
441
- #ifdef VREAL
442
- set_led((UWORD)led,(UWORD)col);
443
- #endif
444
- }
445
-
446
- void sysMotorset(int motor,int sens)
447
- {
448
- #ifdef VSIMU
449
- set_motor_dir(motor,sens);
450
- #endif
451
- #ifdef VREAL
452
- // char buffer[256];
453
- motor=1+(motor&1);
454
-
455
- // sprintf(buffer,"setmotor %d sens %d\r\n",motor,sens);
456
- // consolestr(buffer);
457
-
458
- if (sens==0) stop_motor(motor);
459
- else run_motor(motor,255,(sens>0)?REVERSE:FORWARD/*:REVERSE*/);
460
- #endif
461
- }
462
-
463
- int kmotor[3];
464
- int kvmotor[3];
465
-
466
- int sysMotorget(int motor)
467
- {
468
- #ifdef VSIMU
469
- return get_motor_val(motor);
470
- #endif
471
- #ifdef VREAL
472
- // char buffer[256];
473
- int k,kx;
474
- motor=1+(motor&1);
475
- kx=(int)get_motor_position(motor);
476
- /* k=(int)get_motor_position(motor);
477
- if (kmotor[motor]!=k)
478
- {
479
- kmotor[motor]=k;
480
- kvmotor[motor]++;
481
- }
482
- kx=kvmotor[motor];
483
- */
484
-
485
- // sprintf(buffer,"getmotor %d pos %x / %x\r\n",motor,k,kx);
486
- // if(motor==2)
487
- // consolestr(buffer);
488
- return kx;
489
- #endif
490
- }
491
-
492
- int sysButton2()
493
- {
494
- #ifdef VSIMU
495
- return getButton();
496
- #endif
497
- #ifdef VREAL
498
- return push_button_value();
499
- #endif
500
- }
501
-
502
- int sysButton3()
503
- {
504
- #ifdef VSIMU
505
- return get_button3();
506
- #endif
507
- #ifdef VREAL
508
- return 255-get_adc_value();
509
- #endif
510
- }
511
-
512
- char* sysRfidget()
513
- {
514
- #ifdef VSIMU
515
- return get_rfid();
516
- #endif
517
- #ifdef VREAL
518
- return get_rfid_first_device();
519
- #endif
520
- }
521
-
522
- void sysReboot()
523
- {
524
- #ifdef VSIMU
525
- printf("REBOOT NOW.....");
526
- getchar();
527
- exit(0);
528
- #endif
529
- #ifdef VREAL
530
- reset_uc();
531
- #endif
532
-
533
- }
534
-
535
- void sysFlash(char* firmware,int len)
536
- {
537
- #ifdef VSIMU
538
- printf("REBOOT AND FLASH NOW.....");
539
- getchar();
540
- exit(0);
541
- #endif
542
- #ifdef VREAL
543
- __disable_interrupt();
544
- flash_uc((unsigned char*)firmware,len,buffer_temp);
545
- #endif
546
-
547
- }
548
-
549
- const uchar inv8[128]=
550
- {
551
- 1,171,205,183,57,163,197,239,241,27,61,167,41,19,53,223,225,139,173,151,25,131,165,207,209,251,29,135,9,243,21,191,193,107,141,119,249,99,133,175,177,219,253,103,233,211,245,159,161,75,109,87,217,67,101,143,145,187,221,71,201,179,213,127,129,43,77,55,185,35,69,111,113,155,189,39,169,147,181,95,97,11,45,23,153,3,37,79,81,123,157,7,137,115,149,63,65,235,13,247,121,227,5,47,49,91,125,231,105,83,117,31,33,203,237,215,89,195,229,15,17,59,93,199,73,51,85,255
552
- };
553
-
554
- int decode8(uchar* src,int len,uchar key,uchar alpha)
555
- {
556
- while(len--)
557
- {
558
- uchar v=((*src)-alpha)*key;
559
- *(src++)=v;
560
- key=v+v+1;
561
- }
562
- return key;
563
- }
564
-
565
- int encode8(uchar* src,int len,uchar key,uchar alpha)
566
- {
567
- while(len--)
568
- {
569
- uchar v=*src;
570
- *(src++)=alpha+(v*inv8[key>>1]);
571
- key=v+v+1;
572
- }
573
- return key;
574
- }
575
-
576
-
577
-
578
- int sysCrypt(char* src,int indexsrc,int len,int lensrc,unsigned int key,int alpha)
579
- {
580
- if ((indexsrc<0)||(indexsrc+len>lensrc)||(len<=0)) return -1;
581
- return encode8(src+indexsrc,len,key,alpha);
582
- }
583
- int sysUncrypt(char* src,int indexsrc,int len,int lensrc,unsigned int key,int alpha)
584
- {
585
- if ((indexsrc<0)||(indexsrc+len>lensrc)||(len<=0)) return -1;
586
- return decode8(src+indexsrc,len,key,alpha);
587
- }
588
-
589
-