Mercurial > otakunoraifu
annotate scn2k/scn2k_cmd.cc @ 47:5f548e5957a8
* get rid of the "deprecated conversion from string constant to ‘char*’" warnings
author | thib |
---|---|
date | Wed, 15 Apr 2009 20:26:32 +0000 |
parents | a85cdca1980a |
children | 15a18fbe6f21 |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno | |
3 * All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * 3. The name of the author may not be used to endorse or promote products | |
14 * derived from this software without specific prior written permission. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | |
27 | |
28 | |
29 #include"scn2k.h" | |
30 | |
31 #include<stdlib.h> | |
32 #include<stdarg.h> | |
33 #include<stdio.h> | |
34 #include<string.h> | |
35 #include<string> | |
36 #include"system/file.h" | |
37 | |
38 using namespace std; | |
39 | |
40 | |
41 // #define SCN_DUMP | |
42 /* Ãí°ÕÅÀ¡§ @@@ ¤Çɽµ */ | |
43 | |
44 | |
45 | |
46 //bool debug_flag = true; | |
47 bool debug_flag = false; | |
48 void dprintf(const char* fmt, ...) { | |
49 if (debug_flag) { | |
50 va_list ap; va_start(ap, fmt); | |
51 vprintf(fmt, ap); | |
52 va_end(ap); | |
53 } | |
54 } | |
55 | |
56 | |
57 void eprintf(const char* fmt, ...) { | |
58 va_list ap; va_start(ap, fmt); | |
59 // vprintf(fmt, ap); | |
60 va_end(ap); | |
61 } | |
62 | |
63 /************************************************************** | |
64 ** Flag | |
65 */ | |
66 | |
67 Flags::Flags(void) { | |
68 int i,j; | |
69 for (i=0; i<=TYPE_VARMAX; i++) { | |
70 for (j=0; j<2000; j++) { | |
71 var[i][j] = 0; | |
72 } | |
73 } | |
74 sys = 0; | |
75 } | |
76 | |
77 bool Flags::IsInt(int type) const { | |
78 int v = type % 26; | |
43
01aa5ddf7dc8
A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents:
29
diff
changeset
|
79 return (v >= 0 && v < 7) || v == 25; |
0 | 80 } |
81 | |
82 int Flags::MaxIndex(int type) const { | |
83 switch (type / 26) { | |
84 case 1: | |
85 return 63999; | |
86 case 2: | |
87 return 31999; | |
88 case 3: | |
89 return 15999; | |
90 case 4: | |
91 return 7999; | |
92 default: | |
93 return 1999; | |
94 } | |
95 } | |
96 | |
97 int Flags::operator()() const { | |
98 return sys; // rand() % 10000; | |
99 } | |
100 | |
101 int Flags::operator() (VarInfo info) const { | |
102 return Get(info.type, info.number); | |
103 } | |
104 | |
105 int Flags::Get(int type, int number) const { | |
106 int index = type % 26; | |
107 type /= 26; | |
108 if (index == 25) { | |
109 if (var[7][number] != 0) return var[7][number]; | |
110 if (cgm_data.find(number) == cgm_data.end()) return 0; | |
111 else return 1; | |
112 } | |
113 if (index == 10) index = 8; | |
114 if (index == 11) index = 9; | |
115 if (index > TYPE_VARMAX || uint(type) > 4) return 0; | |
116 if (type == 0) { | |
117 // A[]..G[], Z[] ¤òľ¤ËÆɤà | |
118 if (uint(number) >= 2000) return 0; | |
119 return var[index][number]; | |
120 } else { | |
121 // Ab[]..G4b[], Z8b[] ¤Ê¤É¤òÆɤà | |
122 int factor = 1 << (type - 1); | |
123 int eltsize = 32 / factor; | |
124 if (uint(number) >= (64000 / factor)) return 0; | |
125 return (var[index][number / eltsize] >> ((number % eltsize) * factor)) & ((1 << factor) - 1); | |
126 } | |
127 } | |
128 | |
129 void Flags::Set(VarInfo info, int value) { | |
130 int type = info.type / 26; | |
131 int index = info.type % 26; | |
132 if (index == 25) { | |
133 if (uint(info.number) >= 2000) return; | |
134 if (value == 0) | |
135 cgm_data.erase(info.number); | |
136 else | |
137 cgm_data.insert(info.number); | |
138 index = 7; | |
139 } | |
140 if (index == 10) index = 8; | |
141 if (index == 11) index = 9; | |
142 if (index < 0 || index > TYPE_VARMAX) { | |
143 fprintf(stderr,"Error: invalid access to Var<%d>[%d]\n",info.type,info.number); | |
144 } | |
145 if (type == 0) { | |
146 // A[]..G[], Z[] ¤òľ¤Ë½ñ¤¯ | |
147 if (uint(info.number) >= 2000) return; | |
148 var[index][info.number] = value; | |
149 } else { | |
150 // Ab[]..G4b[], Z8b[] ¤Ê¤É¤ò½ñ¤¯ | |
151 int factor = 1 << (type - 1); | |
152 int eltsize = 32 / factor; | |
153 int eltmask = (1 << factor) - 1; | |
154 int shift = (info.number % eltsize) * factor; | |
155 if (uint(info.number) >= (64000 / factor)) return; | |
156 var[index][info.number / eltsize] = | |
157 (var[index][info.number / eltsize] & ~(eltmask << shift)) | |
158 | (value & eltmask) << shift; | |
159 } | |
160 } | |
161 | |
162 void Flags::SetSys(int value) { | |
163 sys = value; | |
164 } | |
165 void Flags::SetStr(VarInfo info, string val) { | |
166 switch(info.type) { | |
167 case TYPE_VARLOCSTR: | |
168 if (info.number >= 3) return; | |
169 loc_str[info.number] = val; | |
170 break; | |
171 case TYPE_VARSYSSTR: | |
172 if (info.number >= 2000) return; | |
173 sys_str[info.number] = val; | |
174 break; | |
175 case TYPE_VARSTR: | |
176 if (info.number >= 2000) return; | |
177 str[info.number] = val; | |
178 break; | |
179 } | |
180 return; | |
181 } | |
182 void Flags::Str(int type, unsigned int number, char* buf, int sz) const { | |
183 if (sz <= 0) return; | |
184 buf[0] = 0; | |
185 const string* sptr; | |
186 switch(type) { | |
187 case TYPE_VARLOCSTR: | |
188 if (number >= 3) return; | |
189 sptr = &loc_str[number]; | |
190 break; | |
191 case TYPE_VARSYSSTR: | |
192 if (number >= 2000) return; | |
193 sptr = &sys_str[number]; | |
194 break; | |
195 case TYPE_VARSTR: | |
196 if (number >= 2000) return; | |
197 sptr = &str[number]; | |
198 break; | |
199 } | |
200 | |
201 int len = sptr->length(); | |
202 if (sz-1 > len) sz = len; | |
203 sptr->copy(buf, sz, 0); | |
204 buf[sz] = 0; | |
205 return; | |
206 } | |
207 string Flags::Str(int type, unsigned int number) const { | |
208 switch(type) { | |
209 case TYPE_VARLOCSTR: | |
210 if (number >= 3) return ""; | |
211 return loc_str[number]; | |
212 case TYPE_VARSYSSTR: | |
213 if (number >= 2000) return ""; | |
214 return sys_str[number]; | |
215 case TYPE_VARSTR: | |
216 if (number >= 2000) return ""; | |
217 return str[number]; | |
218 } | |
219 return ""; | |
220 } | |
221 | |
222 void Flags::Save(string& save) { | |
223 char buf[1024]; | |
224 save = "\n[Flags]\n"; | |
225 int i,j; | |
226 for (i=0; i<=TYPE_NONSYSVARMAX; i++) { | |
227 for (j=0; j<2000; j++) { | |
228 if (var[i][j] != 0) { | |
229 sprintf(buf, "V<%d>[%04d]=%d\n",i,j,var[i][j]); | |
230 save += buf; | |
231 } | |
232 } | |
233 } | |
234 for (j=0; j<2000; j++) { | |
235 if (str[j].length() != 0) { | |
236 sprintf(buf, "V<C>[%04d]=%s\n", j, str[j].c_str()); | |
237 save += buf; | |
238 } | |
239 } | |
240 } | |
241 void Flags::Load(const char* save) { | |
242 int i,j; | |
243 for (i=0; i<=TYPE_NONSYSVARMAX; i++) { | |
244 for (j=0; j<2000; j++) { | |
245 var[i][j] = 0; | |
246 } | |
247 } | |
248 sys = 0; | |
249 for (j=0; j<2000; j++) { | |
250 str[j] = ""; | |
251 } | |
252 | |
253 save = strstr(save, "\n[Flags]\n"); | |
254 | |
255 if (save) { | |
256 save += strlen("\n[Flags]\n"); | |
257 do { | |
258 if (save[0] == '[') break; // next section | |
259 if (strncmp(save, "V<",2) == 0) { | |
260 if (strncmp(save, "V<C>[",5) == 0) { // string | |
261 char buf[1024]; | |
262 int n; | |
263 if (sscanf(save, "V<C>[%04d]=",&n) == 1) { | |
264 char* s = strchr(save, '='); | |
265 s++; | |
266 char* send = strchr(s, '\n'); | |
267 int slen = send - s; | |
268 strncpy(buf, s, slen); | |
269 buf[slen] = 0; | |
270 if (n >= 0 && n < 2000) str[n] = buf; | |
271 } | |
272 } else if (save[2] >= '0' && save[2] <= '9') { | |
273 int c,n,v; | |
274 if (sscanf(save, "V<%d>[%04d]=%d\n",&c,&n,&v) == 3) { | |
275 if (c >= 0 && c <= TYPE_NONSYSVARMAX && n >= 0 && n < 2000) | |
276 var[c][n] = v; | |
277 } | |
278 } | |
279 } | |
280 save = strchr(save, '\n'); | |
281 if (save) save++; | |
282 } while (save); | |
283 } | |
284 return; | |
285 } | |
286 | |
287 void Flags::SaveSys(string& save) { | |
288 char buf[1024]; | |
289 int j; | |
290 save = "\n[Flags]\n"; | |
291 for (j=0; j<2000; j++) { | |
292 if (var[6][j] != 0) { | |
293 sprintf(buf, "V<6>[%04d]=%d\n",j,var[6][j]); | |
294 save += buf; | |
295 } | |
296 } | |
297 for (j=0; j<2000; j++) { | |
298 if (var[7][j] != 0) { | |
299 sprintf(buf, "V<25>[%04d]=%d\n",j,var[7][j]); | |
300 save += buf; | |
301 } | |
302 } | |
303 for (j=0; j<2000; j++) { | |
304 if (sys_str[j].length() != 0) { | |
305 sprintf(buf, "V<M>[%04d]=%s\n", j, sys_str[j].c_str()); | |
306 save += buf; | |
307 } | |
308 } | |
309 } | |
310 void Flags::LoadSys(const char* save) { | |
311 int i,j; | |
312 for (i=6; i<=7; i++) { | |
313 for (j=0; j<2000; j++) { | |
314 var[i][j] = 0; | |
315 } | |
316 } | |
317 for (j=0; j<2000; j++) { | |
318 sys_str[j] = ""; | |
319 } | |
320 sys = 0; | |
321 | |
322 save = strstr(save, "\n[Flags]\n"); | |
323 | |
324 if (save) { | |
325 save += strlen("\n[Flags]\n"); | |
326 do { | |
327 if (save[0] == '[') break; // next section | |
328 if (strncmp(save, "V<",2) == 0) { | |
329 if (strncmp(save, "V<M>[",5) == 0) { // string | |
330 char buf[1024]; | |
331 int n; | |
332 if (sscanf(save, "V<M>[%04d]=",&n) == 1) { | |
333 char* s = strchr(save, '='); | |
334 s++; | |
335 char* send = strchr(s, '\n'); | |
336 int slen = send - s; | |
337 strncpy(buf, s, slen); | |
338 buf[slen] = 0; | |
339 if (n >= 0 && n < 2000) sys_str[n] = buf; | |
340 } | |
341 } else if (save[2] >= '0' && save[2] <= '9') { | |
342 int c,n,v; | |
343 if (sscanf(save, "V<%d>[%04d]=%d\n",&c,&n,&v) == 3) { | |
344 if (c == 6 && n >= 0 && n < 2000) | |
345 var[6][n] = v; | |
346 else if (c == 25 && n >= 0 && n < 2000) | |
347 var[7][n] = v; | |
348 } | |
349 } | |
350 } | |
351 save = strchr(save, '\n'); | |
352 if (save) save++; | |
353 } while (save); | |
354 } | |
355 return; | |
356 } | |
357 | |
358 bool Flags::Exec(Cmd& cmd) { | |
359 if (cmd.cmd_type == CMD_FLAGS) { // ÂåÆþ±é»» | |
360 if (cmd.args.size() != 2) return false; | |
361 Set(cmd.args[0], cmd.args[1].value); | |
362 cmd.clear(); | |
363 return true; | |
364 } | |
365 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0a) { // ʸ»úÎó±é»» | |
366 VarInfo arg1 = cmd.args[0]; | |
367 switch(cmd.cmd3) { | |
368 case 0: | |
369 if (cmd.cmd4 == 0) { | |
370 SetStr(arg1, cmd.Str(cmd.args[1])); | |
371 } else if (cmd.cmd4 == 1) { | |
372 string s = cmd.Str(cmd.args[1]); | |
373 const char* sc = s.c_str(); | |
374 int len = cmd.args[2].value; | |
43
01aa5ddf7dc8
A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents:
29
diff
changeset
|
375 int i; |
01aa5ddf7dc8
A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents:
29
diff
changeset
|
376 for (i=0; i < sc[i] && len != 0; i++, len--) { |
0 | 377 if (sc[i]<0 && sc[i+1]!=0) i++; |
378 } | |
379 s.erase(i); // Á´³Ñ¤Ç len ʸ»ú¤Þ¤ÇÀÚ¤êµÍ¤á¤ë | |
380 SetStr(arg1, s); | |
381 // fprintf(stderr,"Set[%d,%d]<-%s\n",arg1.type,arg1.number,s.c_str()); | |
382 } else break; | |
383 cmd.clear(); | |
384 break; | |
385 case 1: | |
386 if (cmd.cmd4 == 0) { | |
387 SetStr(arg1, ""); | |
388 cmd.clear(); | |
389 } else if (cmd.cmd4 == 1) { | |
390 // Îΰè»ØÄê¤Çʸ»úÎ󥯥ꥢ | |
391 VarInfo v1 = cmd.args[0]; | |
392 VarInfo v2 = cmd.args[1]; | |
393 eprintf("memclear(str). Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); | |
394 if (v1.type != v2.type || (v1.type != TYPE_VARSTR && v1.type != TYPE_VARSYSSTR && v1.type != TYPE_VARLOCSTR)) { | |
395 eprintf(" error: bad args\n"); | |
396 } else { | |
397 if (v1.number < 0) v1.number = 0; | |
398 if (v2.number > 2000) v2.number = 2000; | |
399 for (; v1.number <= v2.number; v1.number++) { | |
400 SetStr(v1, ""); | |
401 } | |
402 } | |
403 cmd.clear(); | |
404 } | |
405 case 2: | |
406 SetStr(arg1, Str(arg1.type,arg1.number) + cmd.Str(cmd.args[1])); | |
407 // fprintf(stderr,"Append[%d,%d]<-%s(%d:%d)\n",arg1.type,arg1.number,Str(arg1.type,arg1.number).c_str(),cmd.args[1].type,cmd.args[1].number); | |
408 cmd.clear(); | |
409 break; | |
410 case 3: | |
411 SetSys(strlen(cmd.Str(cmd.args[0]))); | |
412 cmd.clear(); | |
413 break; | |
414 case 4: | |
415 { int v = strcmp(cmd.Str(cmd.args[0]), cmd.Str(cmd.args[1])); | |
416 // string s1=cmd.Str(cmd.args[0]); | |
417 // string s2=cmd.Str(cmd.args[1]); | |
418 // fprintf(stderr,"Cmp %s(%d:%d):%s(%d:%d):%d\n",s1.c_str(),cmd.args[0].type,cmd.args[0].number,s2.c_str(),cmd.args[1].type,cmd.args[1].number,v); | |
419 if (v < 0) SetSys(-1); | |
420 else if (v > 0) SetSys(1); | |
421 else SetSys(0); | |
422 cmd.clear(); | |
423 break; } | |
424 case 5: // substring, index from left | |
425 case 6: // substring, index from right | |
426 // Á´³ÑÂбþ¤é¤·¤¤ | |
13 | 427 //FIXME: Make sure it works properly |
0 | 428 { int offset = cmd.args[2].value; |
429 int len = strlen(cmd.Str(cmd.args[1])); | |
430 string str = cmd.Str(cmd.args[1]); | |
431 const char* s = str.c_str(); | |
432 if (cmd.cmd3 == 6) offset = len - offset; | |
433 if (offset < 0) offset = 0; | |
434 // ÀèƬ N ʸ»ú¤òÆɤßÈô¤Ð¤¹ | |
435 int i; | |
436 int offset_top = 0; | |
437 for (i=0; i<offset && s[offset_top] != 0; i++) { | |
438 if (s[offset_top] < 0 && s[offset_top+1] != 0) offset_top += 2; | |
439 else offset_top += 1; | |
440 } | |
441 if (s[offset_top] == 0) { | |
442 SetStr(arg1, ""); | |
443 } else if (cmd.cmd4 == 0) { // ŤµÀ©¸Â¤Ê¤· | |
13 | 444 SetStr(arg1, string(s, offset_top, len-offset_top)); |
0 | 445 } else { // cmd.cmd4 == 1 |
446 int slen = cmd.args[3].value; | |
447 int offset_end = offset_top; | |
448 for (i=0; i<slen && s[offset_end] != 0; i++) { | |
449 if (s[offset_end] < 0 && s[offset_end]+1 != 0) offset_end += 2; | |
450 else offset_end += 1; | |
451 } | |
452 string result(s, offset_top, offset_end-offset_top); | |
453 SetStr(arg1, result); | |
454 } | |
455 cmd.clear(); | |
456 break; } | |
457 case 7: {// strlen w/ kanji | |
458 const char* s = cmd.Str(cmd.args[0]); int i; | |
459 for (i=0; *s != 0; i++) { | |
460 if (*s < 0 && s[1] != 0) s += 2; | |
461 else s++; | |
462 } | |
463 SetSys(i); | |
464 cmd.clear(); | |
465 break; } | |
466 case 8: // ʸ»úÎó¤òÀڤäÆû¤¯¤¹¤ë | |
467 if (cmd.args[1].value <= 0) { | |
468 SetStr(arg1, ""); | |
469 } else if (cmd.args[1].value < strlen(cmd.Str(cmd.args[1]))) { | |
470 Str(arg1.type,arg1.number).erase(cmd.args[1].value); | |
471 } | |
472 cmd.clear(); | |
473 break; | |
474 case 0x0e: // ´Á»ú¥â¡¼¥É¤Çitoa | |
475 { | |
476 int arg1 = cmd.args[0].value; | |
477 string result; | |
478 char wc[3]; wc[2]=0; | |
479 char buf[20]; | |
480 if (cmd.cmd4 == 0) { | |
481 sprintf(buf, "%d", arg1); | |
482 } else { // cmd.cmd4 == 1 | |
483 char fmt[20]; | |
484 sprintf(fmt, "%%%dd", cmd.args[2].value); | |
485 sprintf(buf, fmt, arg1); | |
486 } | |
487 int i; | |
488 for (i=0; buf[i] != 0; i++) { | |
489 if (buf[i] == ' ') { | |
44 | 490 wc[0] = 0x81; // ' ' in SHIFT_JIS |
491 wc[1] = 0x40; | |
0 | 492 } else if (buf[i] == '-') { |
44 | 493 wc[0] = 0x81; // '-' in SHIFT_JIS |
494 wc[1] = 0x7c; | |
0 | 495 } else if (isdigit(buf[i])) { |
44 | 496 wc[0] = 0x82; // number in SHIFT_JIS |
0 | 497 wc[1] = buf[i] - '0' + 0x4f; |
498 } else { | |
499 continue; | |
500 } | |
501 result += wc; | |
502 } | |
503 SetStr(cmd.args[1], result); | |
504 cmd.clear(); | |
505 } | |
506 break; | |
507 case 0x0f: case 0x11: // itoa (0x11 ¤ÎÊý¤Ï zero padding ¤¹¤ë¤Ã¤Ý¤¤) | |
508 if (cmd.cmd4 == 0) { | |
509 int arg1 = cmd.args[0].value; | |
510 char buf[1024]; sprintf(buf, "%d", arg1); | |
511 SetStr(cmd.args[1], buf); | |
512 cmd.clear(); | |
513 } else if (cmd.cmd4 == 1) { | |
514 // ´Á»ú(SJIS) : 82 [4f+N] | |
515 // ¤ä¤Ï¤ê´Á»ú¤¸¤ã¤Ê¤¤¡© | |
516 int arg1 = cmd.args[0].value; | |
517 char buf[1024]; char fmt[1024]; | |
518 if (cmd.cmd3 == 0x0f) { | |
519 sprintf(fmt, "%%%dd",cmd.args[2].value); /* ¶õÇò¤Ç¥Ñ¥Ç¥£¥ó¥° */ | |
520 } else { | |
521 sprintf(fmt, "%%0%dd",cmd.args[2].value); | |
522 } | |
523 sprintf(buf, fmt, arg1); | |
524 SetStr(cmd.args[1], buf); | |
525 cmd.clear(); | |
526 } | |
527 break; | |
528 case 0x64: // ʸ»úÎó¤Îɽ¼¨ : °ú¿ô¤ò¥Æ¥¥¹¥È¥¦¥£¥ó¥É¥¦¤Ëɽ¼¨ | |
529 if (cmd.cmd4 == 1) { | |
530 char buf[256]; | |
531 snprintf(buf, 255, "%d", Get(cmd.args[0].type, cmd.args[0].number)); | |
532 cmd.args[0].type = TYPE_STR; | |
533 cmd.args[0].value = cmd.AddStr(buf); | |
534 cmd.cmd4 = 0; | |
535 } | |
536 | |
537 #if 0 | |
538 @@@ | |
539 save 27 | |
540 ¤È¤â¤è¥á¥¬¥Í¤Î¤È¤³¤í | |
541 - ¥ª¥Ö¥¸¥§¥¯¥È´ØÏ¢¡§seen9061:0 ¸Æ¤Ó½Ð¤·¤Ç¹õ¤¤Çطʲè¤ò¤«¤µ¤Í¤ë¤È¤³¤í¡¢ÊѤˤʤë | |
542 @@@ | |
543 ¡ó£Ø¤ÇÃÖ´¹¤¹¤ë̾Á°¤ÎÀßÄê¡£0x51e ¤ÇÆɤߤÀ¤·¡£¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤´¤È¤ËÊݸ¤µ¤ì¤ë¤Ï¤º¤Ê¤Î¤Ç¼ÂÁõ¤ò¹Í¤¨¤ë¤³¤È | |
544 ¡ó¤Ï0-3 (4 °Ê¹ß¤Ï»È¤Ã¤Æ¤Ê¤¤¡Ë¤Ç¡¢½í¡¢½©À¸¡¢½í¡¢°Ë¿áÀèÀ¸¡¢¤Ê¤É | |
545 StrVar ¤ò³ÈÄ¥¤·¤ÆÂåÆþ¤¹¤ë¤³¤È | |
546 ½é´üÃͤϤ³¤ÎÊÕ | |
547 Text¦¤ËǼ¤á¡¢¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤Ç¤âƱ¤¸¤è¤¦¤Ë¤¹¤Ù¤¤À¤í¤¦¤Ê¤¢ | |
548 args:0,"½í" | |
549 args:1,"½©À¸" | |
550 args:2,"½í" | |
551 args:3,"°Ë¿áÀèÀ¸" | |
552 args:4,"ÊþÌ餯¤ó" | |
553 args:5,"²¬ºê¤µ¤ó" | |
554 | |
555 | |
556 106737 : 0x23 - cmd 01-04:051f:00[ 2] | |
557 args:0,"¸Å²Ï" | |
558 106758 : line 1712 | |
559 106761 : 0x23 - cmd 01-04:051f:00[ 2] | |
560 args:2,"¸Å²Ï" | |
561 106782 : line 1713 | |
562 106785 : 0x23 - cmd 01-04:051f:00[ 2] | |
563 args:4,"²¬ºê¤µ¤ó" | |
564 | |
565 47382 : 0x23 - cmd 01-04:051e:00[ 2] | |
566 args:4,V<18>[0](=0) | |
567 | |
568 47408 : 0x23 - cmd 01-0a:0004:00[ 2] | |
569 args:V<18>[0](=0),"²¬ºê¤µ¤ó" | |
570 47437 : expr: V<0>[1000](=0)=V<sys> | |
571 47451 : 0x23 - cmd 01-0a:0004:00[ 2] | |
572 args:V<18>[0](=0),"ÊþÌ餯¤ó" | |
573 47480 : expr: V<0>[1001](=0)=V<sys> | |
574 47494 : V<0>[1000](=0)==0(=true)-> 47589 | |
575 47526 : 0x23 - cmd 01-04:0514:00[ 2] | |
576 args:0,V<18>[0](=0) /* NAME.A ¤òµ¢¤¹ */ | |
577 47552 : 0x23 - cmd 01-0a:0002:00[ 2] | |
578 args:V<18>[0](=0),"¤µ¤ó" | |
579 47577 : jmp -> 47672 | |
580 47589 : V<0>[1001](=0)==0(=true)-> 47672 | |
581 47621 : 0x23 - cmd 01-04:0514:00[ 2] | |
582 args:1,V<18>[0](=0) /* NAME.B ¤òµ¢¤¹ */ | |
583 47647 : 0x23 - cmd 01-0a:0002:00[ 2] | |
584 args:V<18>[0](=0),"¤¯¤ó" | |
585 47672 : pos. 279 | |
586 47675 : 0x23 - cmd 01-0a:0064:00[ 1] | |
587 args:V<18>[0](=0) | |
588 | |
589 #endif | |
590 cmd.cmd_type = CMD_TEXT; | |
591 break; | |
592 } | |
593 } | |
594 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0b) { // ¿ôÃÍÊÑ¿ô±é»» | |
595 if (cmd.cmd3 == 0 && cmd.cmd4 == 0) { | |
596 /* Ê£¿ô¤ÎÊÑ¿ô¤ò¥»¥Ã¥È */ | |
597 VarInfo v1 = cmd.args[0]; | |
598 eprintf("set multiple-var Var[%d]<%d> <- ",v1.type, v1.number); | |
599 int i; | |
600 if (cmd.args.size() < cmd.argc) { | |
601 eprintf(" error: argsize changed %d -> %d\n",cmd.argc, cmd.args.size()); | |
602 cmd.argc = cmd.args.size(); | |
603 } | |
604 for (i=0; i<cmd.argc; i++) { | |
605 eprintf("%d, ",cmd.args[i+1].value); | |
606 Set(v1, cmd.args[i+1].value); | |
607 v1.number++; | |
608 } | |
609 eprintf("\n"); | |
610 cmd.clear(); | |
611 } else if (cmd.cmd3 == 1 && cmd.cmd4 == 0) { | |
612 /* Îΰè»ØÄê¤ÇÊÑ¿ô¤ò¥¯¥ê¥¢ */ | |
613 VarInfo v1 = cmd.args[0]; | |
614 VarInfo v2 = cmd.args[1]; | |
615 eprintf("memclear. Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); | |
616 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n"); | |
617 else { | |
618 if (v1.number < 0) v1.number = 0; | |
619 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type); | |
620 for (; v1.number <= v2.number; v1.number++) | |
621 Set(v1, 0); | |
622 } | |
623 cmd.clear(); | |
624 } else if (cmd.cmd3 == 1 && cmd.cmd4 == 1) { | |
625 /* Îΰè»ØÄê¤ÇÊÑ¿ô¤ò¥»¥Ã¥È */ | |
626 VarInfo v1 = cmd.args[0]; | |
627 VarInfo v2 = cmd.args[1]; | |
628 int value = cmd.args[2].value; | |
629 eprintf("memset. Var[%d]<%d> - Var[%d]<%d> <- %d\n",v1.type, v1.number, v2.type, v2.number, value); | |
630 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n"); | |
631 else { | |
632 if (v1.number < 0) v1.number = 0; | |
633 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type); | |
634 for (; v1.number <= v2.number; v1.number++) | |
635 Set(v1, value); | |
636 } | |
637 cmd.clear(); | |
638 } else if (cmd.cmd3 == 4 && cmd.cmd4 == 1) { // Îΰ襯¥ê¥¢(sysfunc.txt) | |
639 VarInfo v1 = cmd.args[0]; | |
640 int step = cmd.args[1].value; | |
641 int deal = cmd.args[2].value; | |
642 int val = cmd.args[3].value; | |
643 eprintf("memclear. Var[%d]<%d> step %d deal %d <- val %d\n",v1.type, v1.number, step, deal, val); | |
644 int i; for (i=0; i<deal; i++) { | |
645 Set(v1, val); | |
646 v1.number += step; | |
647 } | |
648 cmd.clear(); | |
649 } else if (cmd.cmd3 == 0x64 && cmd.cmd4 == 0) { //Îΰè¤Ç¿ôÃͤò¹ç·×¤¹¤ë | |
650 VarInfo v1 = cmd.args[0]; | |
651 VarInfo v2 = cmd.args[1]; | |
652 eprintf("sum var. Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); | |
653 int sum = 0; | |
654 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n"); | |
655 else { | |
656 if (v1.number < 0) v1.number = 0; | |
657 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type); | |
658 for (; v1.number <= v2.number; v1.number++) | |
659 sum += (*this)(v1); | |
660 } | |
661 eprintf(" ret %d\n",sum); | |
662 cmd.SetSysvar(sum); | |
663 } | |
664 } | |
665 return false; | |
666 } | |
667 | |
668 /********************************************************************* | |
669 ** Cmd | |
670 */ | |
671 | |
672 /* ¿ôÃÍ num := 0x24 0xff <int num> */ | |
673 /* ÊÑ¿ô var := 0x24 <uchar type> 0x5b <exp> 0x5d */ | |
674 /* ¹à token := num | var | 0x28 <exp> 0x29 | <plus|minus> token */ | |
675 | |
676 int Cmd::GetLeftToken(const char*& d, VarInfo& info) { | |
677 bool var_flag = true; | |
678 int minus_flag = 0; | |
679 int value = 0; | |
680 if (d[0] == 0x5c && (d[1] == 1 || d[1] == 0) ) { | |
681 if (d[1] == 1) {dprintf("minus-"); minus_flag ^= 1;} | |
682 else dprintf("plus-"); | |
683 d += 2; | |
684 var_flag = false; | |
685 } | |
686 if (d[0] == 0x24 && ((unsigned const char*)d)[1] == 0xff) { | |
687 // if ( (d[0] == 0x30 || d[0] == 0x31) && d[1] == 0x24 && ((unsigned const char*)d)[2] == 0xff) /* @@@ not supported; selection Æâ¤Ç¡¢0x30|0x31 ¤¬Éտ魯¤ë¤³¤È¤¬¤¢¤ë */ | |
688 // numerical atom | |
689 d += 6; | |
690 value = read_little_endian_int(d-4); | |
691 dprintf("%d",value); | |
692 var_flag = false; | |
693 } else if (d[0] == 0x24 && *(unsigned char*)(d+1) == 0xc8) { | |
694 dprintf("V<sys>"); | |
695 d += 2; | |
696 info.type = TYPE_SYS; info.number = 0; | |
697 value = info.value = flags(); | |
698 } else if (d[0] == 0x24 && d[2] == 0x5b) { | |
699 // 0x24,<type>,0x5b,<expr>,0x5d-terminated term | |
700 info.type = *(unsigned char*)(d+1); | |
701 d += 3; | |
702 dprintf("V<%d>[",info.type); | |
703 info.number = GetExpression(d); | |
704 dprintf("]"); | |
705 if (*d == 0x5d) d++; | |
706 else SetError(); | |
707 if (info.type == TYPE_VARSTR || info.type == TYPE_VARSYSSTR || info.type == TYPE_VARLOCSTR) { | |
708 value = 0; | |
709 info.value = StrVar(info.type, info.number); | |
710 } else { | |
711 value = info.value = flags(info); | |
712 } | |
713 dprintf("(=%d)",value); | |
714 } else SetError(); | |
715 | |
716 if (minus_flag) value = -value; | |
717 if (!var_flag) { | |
718 info.type = TYPE_VAL; | |
719 info.value = value; | |
720 } | |
721 return value; | |
722 } | |
723 | |
47
5f548e5957a8
* get rid of the "deprecated conversion from string constant to ‘char*’" warnings
thib
parents:
44
diff
changeset
|
724 static const char* op_str[70] = { |
0 | 725 // 0 1 2 3 4 5 6 7 8 9 |
726 "+", "-", "*", "/", "%", "&", "|", "^", "<<", ">>", // +00 | |
727 "err.","err.","err.","err.","err.","err.","err.","err.","err.","err.", // +10 | |
728 "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=", // +20 | |
729 "=", "err.","err.","err.","err.","err.","err.","err.","err.","err.", // +30 | |
730 "==", "!=", "<=", "<", ">=", ">", "err.","err.","err.","err.", // +40 | |
731 "err.","err.","err.","err.","err.","err.","err.","err.","err.","err.", // +50 | |
732 "&&", "||", "err.","err.","err.","err.","err.","err.","err.","err.", // +60 | |
733 }; | |
734 | |
735 static int op_pri_tbl[12] = { | |
736 // + - * / % & | ^ << >> | |
737 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10}; | |
738 | |
739 inline int op_pri(int op) { | |
740 if (op > 11) return 10; | |
741 return op_pri_tbl[op]; | |
742 } | |
743 inline int op_pri_cond(int op) { | |
744 if (op <= 11) return op_pri_tbl[op]; | |
745 else if (op < 50) return 7; | |
746 else if (op == 60) return 8; | |
747 else if (op == 61) return 8; | |
748 else return 10; | |
749 } | |
750 | |
751 | |
752 inline int eval(int v1, int op, int v2) { | |
753 switch(op) { | |
754 case 0: return v1+v2; | |
755 case 1: return v1-v2; | |
756 case 2: return v1*v2; | |
757 case 3: return v2!=0 ? v1/v2 : v1; | |
758 case 4: return v2!=0 ? v1%v2 : v1; | |
759 case 5: return v1&v2; | |
760 case 6: return v1|v2; | |
761 case 7: return v1^v2; | |
762 case 8: return v1<<v2; | |
763 case 9: return v1>>v2; | |
764 case 40: return v1 == v2; | |
765 case 41: return v1 != v2; | |
766 case 42: return v1 <= v2; | |
767 case 43: return v1 < v2; | |
768 case 44: return v1 >= v2; | |
769 case 45: return v1 > v2; | |
770 case 60: return v1 && v2; | |
771 case 61: return v1 || v2; | |
772 } | |
773 return v2; | |
774 } | |
775 | |
776 /* ±é»»»Ò op := 0x5c <uchar op> */ | |
777 /* ¿ô¼° exp: [op] <token> [op <token> [...]] */ | |
778 int Cmd::GetExpression(const char*& d, VarInfo* info_ptr) { | |
779 #define STACK_DEPTH 1024 | |
780 #define OP_LB 11 | |
781 char op_stack[STACK_DEPTH]; | |
782 int val_stack[STACK_DEPTH]; | |
783 int stack_count = 0; | |
784 | |
785 // Âè°ì¹à¤ÎÆɤ߹þ¤ß | |
786 while(*d == 0x28) { | |
787 d++; | |
788 dprintf("("); | |
789 op_stack[stack_count++] = OP_LB; | |
790 } | |
791 VarInfo info; | |
792 int value = GetLeftToken(d, info); | |
793 | |
794 while(*d == 0x29 && stack_count > 0 && op_stack[stack_count-1] == OP_LB) { | |
795 d++; | |
796 dprintf(")"); | |
797 stack_count--; | |
798 } | |
799 | |
800 if (*d != 0x5c && stack_count == 0) { | |
801 if (info_ptr) *info_ptr = info; | |
802 return value; // ñ½ã¤Êleft-term¤Ï¤³¤³¤Ç½ªÎ»¡£Í¸ú¤Êinfo_ptr¤òµ¢¤¹¡Ê²ÄǽÀ¤¬¤¢¤ë¡Ë | |
803 } | |
804 | |
805 while(*d == 0x5c) { | |
806 int op_type = *(unsigned char*)(d+1); | |
807 d += 2; | |
808 if (op_type < 70) dprintf("%s",op_str[op_type]); | |
809 else dprintf("err."); | |
810 if (op_type >= 10) SetError(); | |
811 int cur_pri = op_pri(op_type); | |
812 while(stack_count != 0 && op_pri(op_stack[stack_count-1]) <= cur_pri) { | |
813 // Í¥Àè½ç°Ì¤Î¹â¤¤¡¢Àè¹Ô¤¹¤ë±é»»¤ò¹Ô¤¦ | |
814 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value); | |
815 stack_count--; | |
816 } | |
817 val_stack[stack_count] = value; | |
818 op_stack[stack_count++] = op_type; | |
819 while(*d == 0x28) { | |
820 d++; | |
821 dprintf("("); | |
822 op_stack[stack_count++] = OP_LB; | |
823 } | |
824 if (stack_count >= STACK_DEPTH) SetError(); | |
825 value = GetLeftToken(d, info); | |
826 | |
827 while (*d != 0x5c && stack_count > 0) { | |
828 // ̤¼Â¹Ô¤Î±é»»¤ò½ª¤ï¤é¤»¤ë | |
829 if (op_stack[stack_count-1] != OP_LB) { | |
830 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value); | |
831 stack_count--; | |
832 } else if (*d == 0x29) { /* op_stack == OP_LB */ | |
833 // bracket ½ªÃ¼¤¬¤¢¤ì¤Ð¡¢ÊĤ¸¤Æ¤ª¤¯ | |
834 d++; | |
835 dprintf(")"); | |
836 stack_count--; | |
837 } else break; // error | |
838 } | |
839 } | |
840 if (stack_count) SetError(); // unbalanced bracket | |
841 dprintf("(=%d)",value); | |
842 if (info_ptr) { | |
843 info_ptr->type = TYPE_VAL; | |
844 info_ptr->value = value; | |
845 } | |
846 return value; | |
847 } | |
848 | |
849 // ¾ò·ïʬ´ôÀìÍѤˡ¢¾ò·ï±é»»¤È»»½Ñ±é»»¤Îº®¹ç¤ò¸¡ÃΤǤ¤ëÀìÍѥ롼¥Á¥ó¡ÊËÜÍè¤ÏGetExpression¤Çº¹¤·»Ù¤¨¤Ê¤¤) | |
850 int Cmd::GetExpressionCond(const char*& d) { | |
851 char op_stack[STACK_DEPTH]; | |
852 int val_stack[STACK_DEPTH]; | |
853 int valattr_stack[STACK_DEPTH]; | |
854 #define ATTR_VAL 0 | |
855 #define ATTR_FLAG 1 | |
856 int stack_count = 0; | |
857 | |
858 // Âè°ì¹à¤ÎÆɤ߹þ¤ß | |
859 while(*d == 0x28) { | |
860 d++; | |
861 dprintf("("); | |
862 op_stack[stack_count++] = OP_LB; | |
863 } | |
864 VarInfo info; | |
865 int value = GetLeftToken(d, info); | |
866 while(*d == 0x29 && stack_count > 0 && op_stack[stack_count-1] == OP_LB) { | |
867 d++; | |
868 dprintf(")"); | |
869 stack_count--; | |
870 } | |
871 bool valattr = ATTR_VAL; | |
872 | |
873 while(*d == 0x5c) { | |
874 int op_type = *(unsigned char*)(d+1); | |
875 d += 2; | |
876 if (op_type < 70) dprintf("%s",op_str[op_type]); | |
877 else dprintf("err."); | |
878 int cur_pri = op_pri_cond(op_type); | |
879 while(stack_count != 0 && op_pri_cond(op_stack[stack_count-1]) <= cur_pri) { | |
880 // Í¥Àè½ç°Ì¤Î¹â¤¤¡¢Àè¹Ô¤¹¤ë±é»»¤ò¹Ô¤¦ | |
881 if (op_stack[stack_count-1] >= 60) { | |
882 if (valattr_stack[stack_count-1] != ATTR_FLAG || valattr != ATTR_FLAG) SetError(); | |
883 } else { | |
884 if (valattr_stack[stack_count-1] != ATTR_VAL || valattr != ATTR_VAL) SetError(); | |
885 } | |
886 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value); | |
887 if (op_stack[stack_count-1] >= 40) valattr = ATTR_FLAG; | |
888 stack_count--; | |
889 } | |
890 val_stack[stack_count] = value; | |
891 valattr_stack[stack_count] = valattr; | |
892 op_stack[stack_count++] = op_type; | |
893 while(*d == 0x28) { | |
894 d++; | |
895 dprintf("("); | |
896 op_stack[stack_count++] = OP_LB; | |
897 } | |
898 if (stack_count >= STACK_DEPTH) SetError(); | |
899 value = GetLeftToken(d, info); | |
900 valattr = ATTR_VAL; | |
901 | |
902 while (*d != 0x5c && stack_count > 0) { | |
903 // ̤¼Â¹Ô¤Î±é»»¤ò½ª¤ï¤é¤»¤ë | |
904 if (op_stack[stack_count-1] != OP_LB) { | |
905 if (op_stack[stack_count-1] >= 60) { | |
906 if (valattr_stack[stack_count-1] != ATTR_FLAG || valattr != ATTR_FLAG) SetError(); | |
907 } else { | |
908 if (valattr_stack[stack_count-1] != ATTR_VAL || valattr != ATTR_VAL) SetError(); | |
909 } | |
910 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value); | |
911 if (op_stack[stack_count-1] >= 40) valattr = ATTR_FLAG; | |
912 stack_count--; | |
913 // bracket ½ªÃ¼¤¬¤¢¤ì¤Ð¡¢ÊĤ¸¤Æ¤ª¤¯ | |
914 } else if (*d == 0x29) { /* op_stack == OP_LB */ | |
915 d++; | |
916 dprintf(")"); | |
917 stack_count--; | |
918 } else break; // error | |
919 } | |
920 } | |
921 if (stack_count) SetError(); // unbalanced bracket | |
922 if (value) dprintf("(=true)"); | |
923 else dprintf("(=false)"); | |
924 return value; | |
925 } | |
926 | |
927 | |
928 /* | |
929 str = | |
930 arg = | |
931 args = 0x28 <exp> [[0x2c] <exp> [[0x2c] <exp> [...] ]] | |
932 */ | |
933 | |
934 int Cmd::GetArgs(const char*& d) { | |
935 if (*d != 0x28) return 0; /* °ú¿ô¤Ê¤· */ | |
936 d++; | |
937 dprintf("args:"); | |
938 VarInfo var; | |
939 int i; for (i=0; i<100 ; i++) { | |
940 /* number, variable, string ¤Î¼ïÊ̤ʤ¯ÃͤòÆÀ¤ë */ | |
941 if (*d == 0x61) { // ¤è¤¯¤ï¤«¤é¤Ê¤¤(ÃÒÂ奢¥Õ¥¿¡¼) | |
29
d229cce98f50
* no more (or, at least, less) duplicate code between scn2kdump and the rest
thib
parents:
21
diff
changeset
|
942 dprintf("@%d",d[1]); |
0 | 943 d += 2; |
944 if (*d == 0x28) { | |
945 dprintf("{"); | |
946 GetArgs(d); // (A,B,C)À᤬´Þ¤Þ¤ì¤ë¤³¤È¤¬¤¢¤ë | |
947 dprintf("}"); | |
948 } else { | |
949 dprintf("{}"); | |
950 } | |
951 } else if (d[0] == 0x0a || d[0] == 0x40) { // ¤è¤¯¤ï¤«¤é¤Ê¤¤ (Little Busters!) | |
952 int var; | |
953 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;} | |
954 else { var = read_little_endian_short(d+1); d += 3;} | |
955 dprintf("line %d; ",var); | |
956 } else if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0)) || *d == 0x28) { | |
957 GetExpression(d, &var); | |
958 args.push_back(var); | |
959 } else if (StrType(d)) { | |
960 var.type = TYPE_STR; | |
961 var.value = GetString(d); | |
962 args.push_back(var); | |
963 } else SetError(); | |
964 if (*d == 0x29) break; | |
965 if (*d == 0x2c) {d++;} // ¼¡¤Î arg ¤¬±é»»»Ò¤Ç»Ï¤Þ¤ë¡¢¤Ê¤É¤¬¤Ê¤±¤ì¤Ð¸ºß¤·¤Ê¤¤ | |
966 dprintf(","); | |
967 } | |
968 if (*d == 0x29) d++; | |
969 else SetError(); | |
970 return i; | |
971 } | |
972 | |
973 int Cmd::GetArgsSpecial(int normal_args,const char*& d) { | |
974 if (*d != 0x28) return 0; /* °ú¿ô¤Ê¤· */ | |
975 d++; | |
976 dprintf("args:"); | |
977 int i; for (i=0; i<normal_args; i++) { | |
978 /* number, variable, string ¤Î¼ïÊ̤ʤ¯ÃͤòÆÀ¤ë */ | |
979 if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0)) || *d == 0x28) { | |
980 GetExpression(d); | |
981 } else if (StrType(d)) { | |
982 GetString(d); | |
983 } else SetError(); | |
984 if (*d == 0x29) break; | |
985 if (*d == 0x2c) {d++;} // ¼¡¤Î arg ¤¬±é»»»Ò¤Ç»Ï¤Þ¤ë¡¢¤Ê¤É¤¬¤Ê¤±¤ì¤Ð¸ºß¤·¤Ê¤¤ | |
986 dprintf(","); | |
987 } | |
988 for (i=0; i<argc ; i++) { | |
989 if (*d == 0x28) { | |
990 /* | |
991 ** cmd 01-22:0c1c, 01-22:0835 | |
992 ** Princess Bride ¤Î¥«¡¼¥É¤¬Íî¤Á¤ë¥¢¥Ë¥á¤Î¾ìÌÌ | |
993 ** ¤Ê¤ª¡¢_PBCARDANM* ¤Î²èÁü¤Ï¤³¤Î¥³¥Þ¥ó¥É¤Ç¤Î¤ß»È¤ï¤ì¤Æ¤¤¤ë¤Î¤Ç¡¢Æüì½èÍý¤È¤·¤Æ̵»ë¤¹¤ë¤³¤È¤â²Äǽ | |
994 ** | |
995 ** cmd 01-04:0276, 026c, 0270 | |
996 ** Ê£¿ô¤Î enum ¤¬ args ¤Î¿ô¤À¤±Â³¤¯½èÍý¡£Æüì½èÍý¤È¤·¤ÆʬΥ¤¹¤ë | |
997 */ | |
998 dprintf("enum.<"); | |
999 /* (...) ¤ÏÎóµó·¿ or ¹½Â¤ÂΤβÄǽÀ¤¬¤¢¤ë */ | |
1000 const char* d_orig = d; | |
1001 int pt = args.size(); args.push_back(VarInfo(0)); | |
1002 int count = GetArgs(d); | |
1003 args[pt] = VarInfo(count); | |
1004 dprintf(">"); | |
1005 } else if (*d == 0x61 && (d[1] >= 0x00 && d[1] <= 0x04) && d[2] == 0x28 ) { | |
1006 /* »È¤ï¤ì¤ë¥³¥Þ¥ó¥É¤Ï 01-21:004b, 01-28:0064 ¤Î¤¤¤º¤ì¤«¡ÊR,C,PB,LO) | |
1007 ** ¤½¤ì¤é¤Î¥³¥Þ¥ó¥É¤Ï | |
1008 ** arg1: ²èÁü¥Õ¥¡¥¤¥ë̾ | |
1009 ** arg2 : Sel ÈÖ¹æ | |
1010 ** ¤é¤·¤¯¡¢arg3 °Ê¹ß¤¬ 0x61 <00-04> (a,b,c,...) ¤È¤Ê¤ë¡Ê¥À¥ó¥×¾å¤Ï enum ¤Èɽµ¤µ¤ì¤ë) | |
1011 ** () Æâ¤Î°ú¿ô¤Ï¤µ¤Þ¤¶¤Þ¤Ç¡¢a ¤Î¤ß¡Ê²èÁü¥Õ¥¡¥¤¥ë̾¡Ë¡¢ | |
1012 ** a,b b=SEL? | |
1013 ** a,b,c (b,c)=ºÂɸ¡© | |
1014 ** a,(b,c,d,e,f,g) b-g = src / dest? | |
1015 ** ¤é¤·¤¤ | |
1016 */ | |
1017 dprintf("kasane. #%d <",d[1]); | |
1018 d += 2; | |
1019 int pt = args.size(); args.push_back(VarInfo(0)); | |
1020 int count = GetArgs(d); | |
1021 args[pt] = VarInfo(count); | |
1022 dprintf(">"); | |
1023 } else if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0))) { | |
1024 /* cmd 01-15:0028 ; »Ï¤á¤Ë 0x24 À᤬¤¢¤ê¡¢Â³¤¤¤Æ 0x28 Àá¤Ë¤Ê¤ë */ | |
1025 VarInfo var; | |
1026 GetExpression(d, &var); | |
1027 args.push_back(var); | |
1028 i--; // ¤³¤Î°ú¿ô¤Ïargc ¤Î¿ô¤Ë¤ÏÆþ¤é¤Ê¤¤ | |
1029 } else SetError(); | |
1030 if (d[0] == 0x0a || d[0] == 0x40) { | |
1031 /* cmd 01-15:0028 ; 0x28 Àá¤Î¸å¤ËËè²ó 0x0a À᤬Íè¤ë */ | |
1032 int var; | |
1033 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;} | |
1034 else { var = read_little_endian_short(d+1); d += 3;} | |
1035 dprintf("line %d; ",var); | |
1036 } | |
1037 if (*d == 0x29) break; | |
1038 if (*d == 0x2c) {d++;} // ¼¡¤Î arg ¤¬±é»»»Ò¤Ç»Ï¤Þ¤ë¡¢¤Ê¤É¤¬¤Ê¤±¤ì¤Ð¸ºß¤·¤Ê¤¤ | |
1039 dprintf(","); | |
1040 } | |
1041 if (*d == 0x29) d++; | |
1042 else SetError(); | |
1043 return 0; | |
1044 } | |
1045 | |
1046 /* switch | |
1047 <exp> | |
1048 0x7b | |
1049 <exp> <int> | |
1050 ... | |
1051 0x7d | |
1052 */ | |
1053 | |
1054 int Cmd::GetSwitch(const char*& d) { | |
1055 if (*d != 0x28) {SetError(); return -1;} | |
1056 d++; | |
1057 dprintf("switch. "); | |
1058 int var = GetExpression(d); | |
1059 if (*d != 0x29) {SetError(); return -1;} | |
1060 d++; | |
1061 dprintf("->\n"); | |
1062 if (*d == 0x7b) { | |
1063 d++; | |
1064 } else SetError(); | |
1065 | |
1066 int default_jmp = -1; int jmpto = -1; | |
1067 int i; for (i=0; i<argc; i++) { | |
1068 dprintf("\t"); | |
1069 if (*d++ != 0x28) {SetError(); return -1;} | |
1070 if (*d != 0x29) { | |
1071 int item = GetExpression(d); | |
1072 if (*d++ != 0x29) {SetError(); return -1;} | |
1073 int jmp = read_little_endian_int(d); | |
1074 if (var == item) { | |
1075 dprintf("(selected)"); | |
1076 jmpto = jmp; | |
1077 } | |
1078 dprintf(" -> %d\n", jmp); | |
1079 } else { | |
1080 d++; | |
1081 default_jmp = read_little_endian_int(d); | |
1082 } | |
1083 d += 4; | |
1084 } | |
1085 if (default_jmp != -1) { | |
1086 dprintf("default -> %d\n",default_jmp); | |
1087 if (jmpto == -1) jmpto = default_jmp; | |
1088 } | |
1089 if (*d == 0x7d) { | |
1090 d++; | |
1091 } else SetError(); | |
1092 return jmpto; | |
1093 } | |
1094 /* simple switch | |
1095 <exp> | |
1096 0x7b | |
1097 <int> | |
1098 ... | |
1099 0x7d | |
1100 */ | |
1101 int Cmd::GetSimpleSwitch(const char*& d) { | |
1102 if (*d != 0x28) {SetError(); return -1;} | |
1103 d++; | |
1104 dprintf("simple switch. "); | |
1105 int var = GetExpression(d); | |
1106 if (*d != 0x29) {SetError(); return -1;} | |
1107 d++; | |
1108 dprintf(" ->\n"); | |
1109 int jumpto = -1; | |
1110 if (*d == 0x7b) { | |
1111 d++; | |
1112 } else SetError(); | |
1113 int i; for (i=0; i<argc; i++) { | |
1114 int j = read_little_endian_int(d); | |
1115 d += 4; | |
1116 dprintf("\t%d -> %d\n", i+1, j); | |
1117 if (var == i) jumpto = j; | |
1118 } | |
1119 if (*d == 0x7d) { | |
1120 d++; | |
1121 } else SetError(); | |
1122 return jumpto; | |
1123 } | |
1124 | |
1125 /* | |
1126 selection | |
1127 ? <exp> | |
1128 0x7b | |
1129 <0x0a|0x40> <ushort | uint> | |
1130 */ | |
1131 void Cmd::GetSelection(const char*& d) { | |
1132 dprintf("selection. "); | |
1133 if (*d == 0x28) { | |
1134 d++; | |
1135 GetExpression(d); | |
1136 if (*d != 0x29) { SetError(); return;} | |
1137 d++; | |
1138 } | |
1139 if (*d == 0x7b) { | |
1140 d++; | |
1141 dprintf("{\n\t"); | |
1142 } else SetError(); | |
1143 int arg_count = 0; | |
1144 string text = ""; | |
1145 int cond_result = false; | |
1146 int sel_no = 0; | |
1147 while(*d != 0x7d) { | |
1148 if (d[0] == 0x0a || d[0] == 0x40) { | |
1149 int var; | |
1150 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;} | |
1151 else { var = read_little_endian_short(d+1); d += 3;} | |
1152 dprintf("Line %d; ",var); | |
1153 if (text.length() != 0) { | |
1154 if (cond_result) ; // ¾ò·ïÀ᤬ true ¤Ê¤éɽ¼¨¤·¤Ê¤¤ | |
1155 else { | |
1156 const char* str = text.c_str(); | |
1157 VarInfo var; | |
1158 var.type = TYPE_STR; | |
1159 var.value = CopyString(str); | |
1160 args.push_back(var); | |
1161 var.type = TYPE_VAL; | |
1162 var.value = sel_no; | |
1163 args.push_back(var); | |
1164 } | |
1165 sel_no++; | |
1166 } | |
1167 text = ""; | |
1168 cond_result = false; | |
1169 } else if (d[0] == 0x2c) { | |
1170 dprintf(":comma:"); | |
1171 } else if (d[0] == 0x28) { | |
1172 dprintf(":cond:"); | |
1173 d++; | |
1174 while(d[0] != 0x29) { | |
1175 int result = GetExpressionCond(d); // PRINT- Àá¤Ç¤Ê¤¤¤Ð¤¢¤¤¡¢¾ò·ïɽ¼¨¡£¼¡¤Ïʸ»úÀá¡¢¤Þ¤¿¤ÏPRINTÀá¤Î¤Ï¤º | |
1176 if (*d == 0x32) { // 0x32 ¤Ê¤é¡¢¸½ºß¤Î¾ò·ïÀá¤òɽ¼¨¤·¤Ê¤¤ | |
1177 d++; dprintf("##"); | |
1178 cond_result = result; | |
1179 } else if (*d == 0x31) { // 0x31 ¤Ê¤é¡¢¸½ºß¤Î¾ò·ïÀá¤òɽ¼¨¤¹¤ë | |
1180 // Little Busters! : ¤³¤Î¾ò·ï¤ÇÀµ¤·¤¤¤«¤Ï̤¸¡¾Ú | |
1181 d++; dprintf("***"); | |
1182 cond_result = !result; | |
1183 } | |
1184 dprintf(":"); | |
1185 } | |
1186 d++; | |
1187 } else if (StrType(d)) { | |
1188 int strpt = GetString(d); | |
1189 text += strheap + strpt; | |
1190 arg_count++; | |
1191 dprintf("\n\t"); | |
1192 } else if (*d == 0x23 && strncmp(d,"###PRINT",8) == 0) { | |
1193 d += 8; | |
1194 if (d[0] != 0x28) SetError(); | |
1195 else { // ʸ»úÊÑ¿ô¤ÎÆâÍƤÎɽ¼¨ | |
1196 d++; | |
1197 dprintf("Print."); | |
1198 VarInfo info; | |
1199 GetLeftToken(d, info); | |
1200 if (d[0] != 0x29 || info.type == -1) SetError(); | |
1201 d++; | |
21
d1bb7b365816
Fixed dynamic strings in selections (Fuko Pranks for instance)
thib
parents:
13
diff
changeset
|
1202 dprintf(";");/* |
0 | 1203 // ¿ôÃͤòÁ´³Ñʸ»ú¤ËÊÑ´¹¤·¤ÆÅÐÏ¿ |
1204 char str[10], str2[20]; // itoa | |
1205 sprintf(str, "%d", info.value); | |
1206 int i; for (i=0; str[i] != 0; i++) { | |
1207 str2[i*2] = 0xa3; | |
1208 str2[i*2+1] = 0xb0 + str[i]-'0'; | |
1209 } | |
21
d1bb7b365816
Fixed dynamic strings in selections (Fuko Pranks for instance)
thib
parents:
13
diff
changeset
|
1210 str2[i*2] = 0;*/ |
d1bb7b365816
Fixed dynamic strings in selections (Fuko Pranks for instance)
thib
parents:
13
diff
changeset
|
1211 text += strheap + info.value; |
0 | 1212 } |
1213 } else { SetError(); break;} | |
1214 } | |
1215 d++; | |
1216 /* @@@ */ | |
1217 /* °ìÃפ·¤Ê¤¤¾ì¹ç¤¬¤¢¤ë¤Î¤Ç¥³¥á¥ó¥È¥¢¥¦¥È */ | |
1218 // if (arg_count != argc) SetError(); | |
1219 dprintf("\n}\n"); | |
1220 return; | |
1221 } | |
1222 | |
1223 void Cmd::GetCmd(Flags& flags_orig, const char*& d ) { | |
1224 if (d == 0) { SetError(); return;} | |
1225 if (cmd_type != CMD_NOP) return; | |
1226 | |
1227 cmdstr[0] = 0; | |
1228 rawdata = d; | |
1229 if (*d == 0x23) { /* ¥³¥Þ¥ó¥É */ | |
1230 cmd_type = CMD_OTHER; | |
1231 cmd1 = *(unsigned const char*)(d+1); | |
1232 cmd2 = *(unsigned const char*)(d+2); | |
1233 cmd3 = read_little_endian_short(d+3); | |
1234 argc = read_little_endian_short(d+5); | |
1235 cmd4 = *(unsigned const char*)(d+7); | |
1236 d += 8; | |
1237 /* verbose */ | |
1238 // dprintf(" 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n",cmd1,cmd2,cmd3,cmd4,argc); | |
29
d229cce98f50
* no more (or, at least, less) duplicate code between scn2kdump and the rest
thib
parents:
21
diff
changeset
|
1239 sprintf(cmdstr, "%02x-%02x:%04x:%02x : %s",cmd1,cmd2,cmd3,cmd4, CmdDescr(cmd1,cmd2,cmd3,cmd4)); |
0 | 1240 /* °ú¿ô¤òÆÀ¤ë */ |
1241 /* Æüì°ú¿ô¤Î¤â¤Î */ | |
1242 int is_special = 0; | |
1243 if (cmd1 == 0) { | |
1244 if (cmd2 == 1) { | |
1245 int jump_arg = -1; | |
1246 if (cmd3 == 0 || cmd3 == 5) { | |
1247 /* gosub / goto */ | |
1248 jump_arg =read_little_endian_int(d); | |
1249 d += 4; | |
1250 if (cmd3 == 0) | |
1251 dprintf("\tjmp -> %d\n", jump_arg); | |
1252 else /* cmd3 == 5 */ | |
1253 dprintf("\tcall -> %d\n", jump_arg); | |
1254 is_special = 1; | |
1255 } else if (cmd3 == 1 || cmd3 == 2) { | |
1256 /* conditional jump (if / unless) */ | |
1257 if (*d++ != 0x28) { SetError(); return;} | |
1258 dprintf("\t"); | |
1259 int cond = GetExpressionCond(d); | |
1260 if (cmd3 == 1) cond = !cond; // µÕ¤Ë¤Ê¤ë | |
1261 if (*d++ != 0x29) { SetError(); return; } | |
1262 int jumpto = read_little_endian_int(d); | |
1263 d += 4; | |
1264 dprintf("-> %d\n", jumpto); | |
1265 if (! cond) jump_arg = jumpto; /* condition ¤¬Ëþ¤¿¤µ¤ì¤Ê¤¤¾ì¹ç¡¢¥¸¥ã¥ó¥× */ | |
1266 is_special = 1; | |
1267 } else if (cmd3 == 4) { | |
1268 /* switch to */ | |
1269 jump_arg = GetSwitch(d); | |
1270 is_special = 1; | |
1271 } else if (cmd3 == 8 || cmd3 == 3) { | |
1272 /* switch to */ | |
1273 jump_arg = GetSimpleSwitch(d); | |
1274 is_special = 1; | |
1275 } else if (cmd3 == 16) { // call with parameters | |
1276 GetArgs(d); | |
1277 jump_arg = read_little_endian_int(d); | |
1278 d += 4; | |
1279 is_special = 1; | |
1280 } else goto retry; | |
1281 if (jump_arg == -1) { | |
1282 cmd_type = CMD_NOP; | |
1283 } | |
1284 else { | |
1285 cmd_type = CMD_JMP; | |
1286 args.push_back(VarInfo(jump_arg)); | |
1287 } | |
1288 } else if (cmd2 == 2 && (cmd3 == 0 || cmd3 == 1 || cmd3 == 2 || cmd3 == 3 || cmd3 == 0x0d) ) { | |
1289 /* selection */ | |
1290 GetSelection(d); | |
1291 is_special = 1; | |
1292 } | |
1293 } | |
1294 retry: | |
1295 /* °ìÈÌ°ú¿ô¤Î¤â¤Î */ | |
1296 if (!is_special) { | |
29
d229cce98f50
* no more (or, at least, less) duplicate code between scn2kdump and the rest
thib
parents:
21
diff
changeset
|
1297 dprintf(" 0x23 - cmd %02x-%02x:%04x:%02x[%2d] : %s\n",cmd1,cmd2,cmd3,cmd4,argc,CmdDescr(cmd1,cmd2,cmd3,cmd4)); |
0 | 1298 dprintf("\t"); |
1299 if (cmd1 == 1 && cmd2 == 0x22 && (cmd3 == 0xc1c || cmd3 == 0x835)) GetArgsSpecial(3, d); | |
1300 else if (cmd1 == 1 && cmd2 == 0x0b && cmd3 == 0x65) GetArgsSpecial(0, d); | |
1301 else if (cmd1 == 1 && cmd2 == 0x15 && cmd3 == 0x28) GetArgsSpecial(0, d); | |
1302 else if (cmd1 == 1 && cmd2 == 4 && (cmd3 == 0x26c || cmd3 == 0x26d || cmd3 == 0x270 || cmd3 == 0x276)) GetArgsSpecial(0, d); | |
1303 else if (cmd1 == 1 && cmd2 == 4 && cmd3 == 0x586) GetArgsSpecial(1, d); | |
43
01aa5ddf7dc8
A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents:
29
diff
changeset
|
1304 else if (cmd1 == 1 && ((cmd2 == 0x21 && cmd3 == 0x4b) || (cmd2 == 0x28 && cmd3 == 0x64))) GetArgsSpecial(2,d); |
0 | 1305 else GetArgs(d); |
1306 dprintf("\n"); | |
1307 | |
1308 } | |
1309 } else if (*d == 0x24) { /* ÂåÆþ±é»» */ | |
1310 if (d[1] == 0x12 || d[2] != 0x5b) SetError(); | |
1311 dprintf("expr: "); | |
1312 sprintf(cmdstr, "expr"); | |
1313 | |
1314 VarInfo info; | |
1315 int value = GetLeftToken(d, info); | |
1316 if (d[0] != 0x5c) SetError(); | |
1317 int type = d[1]; | |
1318 if (type < 20 || type > 30) SetError(); | |
1319 else dprintf("%s",op_str[type]); | |
1320 d += 2; | |
1321 int value2 = GetExpression(d); | |
1322 // ÂåÆþ¾ðÊó¤òËä¤á¹þ¤à | |
1323 if (type != 30) value2 = eval(value, type-20, value2); | |
1324 cmd_type = CMD_FLAGS; | |
1325 args.push_back(info); | |
1326 args.push_back(value2); | |
1327 dprintf("\n"); | |
1328 } else if (StrType(d)) { /* ʸ»ú½ÐÎÏ */ | |
1329 VarInfo info; | |
1330 info.type = TYPE_STR; | |
1331 info.value = GetString(d); | |
1332 args.push_back(info); | |
1333 cmd_type = CMD_TEXT; | |
1334 dprintf("\n"); | |
1335 } else if (*d == 0x0a || *d == 0x40 || *d == 0x21) { /* ¥Ç¥Ð¥Ã¥°Íѥǡ¼¥¿¤È´ûÆɥե饰 */ | |
1336 cmd_type = CMD_NOP; | |
1337 if (*d == 0x0a) { | |
1338 dprintf("line "); | |
1339 d++; | |
1340 int l; | |
1341 if (system_version == 0) { | |
1342 l = read_little_endian_int(d); | |
1343 d += 4; | |
1344 } else { | |
1345 l = read_little_endian_short(d); | |
1346 d += 2; | |
1347 } | |
1348 dprintf("%d\n", l); | |
1349 } else { /* 0x40, 0x21 */ | |
1350 // ´ûÆÉ¥Þ¡¼¥«¡¼¤é¤·¤¤¡£¥¨¥ó¥È¥ê¡¼¥Ý¥¤¥ó¥È¤È¥»¡¼¥Ö¥Ý¥¤¥ó¥È¤â»È¤ï¤ì¤ë¡£ | |
1351 // RealLive 1.2.5¤«¤é¡¢0x40¤Ï¥»¡¼¥Ö¥Ý¥¤¥ó¥È¡¢0x21¤Ï¥¨¥ó¥È¥ê¡¼¥Ý¥¤¥ó¥È¡£ | |
1352 // 1.2.5°ÊÁ°¡¢¤É¤Á¤é¤â0x40¤¬»È¤ï¤ì¤ë¡£ | |
1353 int kidoku_index; | |
1354 d++; | |
1355 if (system_version == 0) { | |
1356 kidoku_index = read_little_endian_int(d); | |
1357 d += 4; | |
1358 } else { | |
1359 kidoku_index = read_little_endian_short(d); | |
1360 d += 2; | |
1361 } | |
1362 dprintf("kidoku marker %d\n", kidoku_index); | |
1363 // text_readflag¤Ï¡¢¤³¤Îkidoku_index¤ò»È¤Ã¤¿¤éÎɤ¤¤«¤Ê¡£ | |
1364 } | |
1365 } else if (*d == 0x2c) { /* ??? */ | |
1366 dprintf("commd;0x2c\n"); // conditional jump ¤Î¹Ô¤Àè¤Ë¤è¤¯¤¢¤ë¤é¤·¤¤¡Ê¾ï¤Ë¡¢¤«¤Ï¤ï¤«¤é¤Ê¤¤¡Ë | |
1367 d++; | |
1368 } else { | |
1369 SetError(); | |
1370 } | |
1371 return; | |
1372 } | |
1373 void Cmd::clear(void) { | |
1374 cmd_type = CMD_NOP; | |
1375 ResetString(); | |
1376 args.clear(); | |
1377 errorflag = false; | |
1378 pos = -1; | |
1379 } | |
1380 | |
1381 char Cmd::strtype[256] = { | |
1382 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +00 */ | |
1383 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +10 */ // 0123456789ABCDEF | |
1384 1,0,3,0, 0,0,0,1, 0,0,0,0, 0,1,1,0, /* +20 */ // !"#$%&'()*+,-./ | |
1385 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, /* +30 */ // 0123456789:;<=>? | |
1386 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, /* +40 */ // @ABCDEFGHIJKLMNO | |
1387 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, /* +50 */ // PQRSTUVWXYZ[\]^_ | |
1388 0,0,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, /* +60 */ // `abcdefghijklmno | |
1389 1,1,1,1, 1,1,1,1, 1,1,1,1, 0,0,0,0, /* +70 */ // pqrstuvwxyz{|}~ | |
1390 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, /* +80 */ | |
1391 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, /* +90 */ | |
1392 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +A0 */ | |
1393 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +B0 */ | |
1394 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +C0 */ | |
1395 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +D0 */ | |
1396 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, /* +E0 */ | |
1397 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,0,0 /* +F0 */ | |
1398 }; | |
1399 | |
1400 int Cmd::GetString(const char*& d) { | |
1401 int retnum = -1; | |
1402 bool quote_flag = false; | |
1403 int stype; | |
1404 retnum = strend; | |
1405 while(1) { | |
1406 if (*d == '\\') { | |
1407 d++; | |
1408 strheap[strend++] = *d++; | |
1409 } else if (*d == '"') { | |
1410 if (quote_flag) quote_flag = false; | |
1411 else quote_flag = true; | |
1412 d++; | |
1413 } else if (quote_flag) { | |
1414 strheap[strend++] = *d++; | |
43
01aa5ddf7dc8
A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents:
29
diff
changeset
|
1415 } else if ((stype = StrType(d))) { |
0 | 1416 strheap[strend++] = *d++; |
1417 if (stype == 2) strheap[strend++] = *d++; | |
1418 } else break; | |
1419 } | |
1420 strheap[strend++] = 0; | |
1421 dprintf("\"%s\"", strheap + retnum); | |
1422 if (strend >= STRHEAP_SIZE) { | |
1423 dprintf("Error: string heap overflow\n"); | |
1424 } | |
1425 return retnum; | |
1426 } | |
1427 | |
1428 int Cmd::CopyString(const char* d) { | |
1429 int retnum = strend; | |
1430 int len = strlen(d); | |
1431 memcpy(strheap+strend, d, len+1); | |
1432 strend += len+1; | |
1433 d += len+1; | |
1434 return retnum; | |
1435 } | |
1436 | |
1437 int Cmd::StrVar(int type, int var_num) { | |
1438 int retnum = strend; | |
1439 flags.Str(type, var_num, strheap+strend, STRHEAP_SIZE-strend); | |
1440 strend += strlen(strheap+strend)+1; | |
1441 return retnum; | |
1442 } | |
1443 | |
1444 void Cmd::SetSysvar(int n, int val) { | |
1445 VarInfo info; | |
1446 if (cmd_type != CMD_SYSVAR) { | |
1447 args.clear(); | |
1448 } | |
1449 cmd_type = CMD_SYSVAR; | |
1450 | |
1451 info.type = TYPE_SYS; | |
1452 info.number = n; | |
1453 info.value = val; | |
1454 args.push_back(info); | |
1455 } | |
1456 void Cmd::SetFlagvar(VarInfo info, int val) { | |
1457 if (cmd_type != CMD_SYSVAR) { | |
1458 args.clear(); | |
1459 } | |
1460 cmd_type = CMD_SYSVAR; | |
1461 | |
1462 info.value = val; | |
1463 args.push_back(info); | |
1464 } | |
1465 | |
1466 void Cmd::SetStrvar(VarInfo info, const string& s) { | |
1467 if (cmd_type != CMD_SYSVAR) { | |
1468 args.clear(); | |
1469 } | |
1470 | |
1471 cmd_type = CMD_SYSVAR; | |
1472 const char* ss = s.c_str(); | |
1473 info.value = CopyString(ss); | |
1474 args.push_back(info); | |
1475 } | |
1476 | |
1477 void Cmd::read(const CmdSimplified& from) { | |
1478 errorflag = false; | |
1479 ResetString(); | |
1480 | |
1481 cmd_type = Cmdtype(from.type); | |
1482 cmd1 = from.cmd1; | |
1483 cmd2 = from.cmd2; | |
1484 cmd3 = from.cmd3; | |
1485 cmd4 = from.cmd4; | |
1486 argc = from.argc; | |
1487 /* args ¤ÎÆɤ߹þ¤ß */ | |
1488 args.clear(); | |
1489 char* d = from.args; | |
1490 if (d == 0) return; | |
1491 while(*d != TYPE_END) { | |
1492 VarInfo info; | |
1493 switch(*d) { | |
1494 case TYPE_VAL: | |
1495 info.type = TYPE_VAL; | |
1496 info.number = 0; | |
1497 info.value = read_little_endian_int(d+1); | |
1498 d += 5; | |
1499 args.push_back(info); | |
1500 break; | |
1501 case TYPE_STR: | |
1502 info.type = TYPE_STR; | |
1503 info.number = 0; | |
1504 d++; | |
1505 info.value = CopyString( d); | |
1506 d += strlen(d)+1; | |
1507 args.push_back(info); | |
1508 break; | |
1509 default: | |
1510 fprintf(stderr,"Cmd::read: Invalid Load Data\n"); | |
1511 *d = TYPE_END; | |
1512 } | |
1513 } | |
1514 return; | |
1515 } | |
1516 void Cmd::write(CmdSimplified& to, char*& buffer) const { | |
1517 /* | |
1518 if (cmd_type != CMD_OTHER) { | |
1519 fprintf(stderr,"Cmd::write: Invalid Cmd during Saving Data\n"); | |
1520 to.cmd1 = 0; to.cmd2 = 0; to.cmd3 = 0; to.cmd4 = 0; to.argc = 0; to.args = 0; | |
1521 return; | |
1522 } | |
1523 */ | |
1524 to.type = cmd_type; | |
1525 to.cmd1 = cmd1; | |
1526 to.cmd2 = cmd2; | |
1527 to.cmd3 = cmd3; | |
1528 to.cmd4 = cmd4; | |
1529 to.argc = argc; | |
1530 /* args ¤Î½ñ¤¹þ¤ß */ | |
1531 if (args.empty()) { | |
1532 to.args = 0; | |
1533 } else { | |
1534 to.args = buffer; | |
1535 char* d = to.args; | |
1536 vector<VarInfo>::const_iterator it; | |
1537 for (it = args.begin(); it != args.end(); it++) { | |
1538 int type = it->type; | |
1539 if ( (type >= 0 && type < 7) || type == TYPE_VAL || type == char(TYPE_SYS)) { // digits | |
1540 *d++ = TYPE_VAL; | |
1541 write_little_endian_int(d, it->value); | |
1542 d += 4; | |
1543 } else if (type == TYPE_VARSTR || type == TYPE_VARSYSSTR || type == TYPE_VARLOCSTR || type == TYPE_STR) { // string | |
1544 *d++ = TYPE_STR; | |
1545 const char* s = Str(*it); | |
1546 int len = strlen(s); | |
1547 memcpy(d, s, len+1); | |
1548 d += len+1; | |
1549 } else { | |
1550 fprintf(stderr,"Cmd::write: Invalid Cmd args during Saving Data\n"); | |
1551 } | |
1552 } | |
1553 *d++ = TYPE_END; | |
1554 buffer = d; | |
1555 } | |
1556 } | |
1557 void CmdSimplified::copy(const CmdSimplified& from, char*& args_buffer) { | |
1558 *this = from; | |
1559 if (args == 0) return; | |
1560 char* args_old = from.args; | |
1561 /* args ¤Î¥³¥Ô¡¼ */ | |
1562 while(*args_old != TYPE_END) { | |
1563 if (*args_old == TYPE_VAL) { | |
1564 args_old += 5; | |
1565 } else { /* TYPE_STR */ | |
1566 args_old += strlen(args_old)+1; | |
1567 } | |
1568 } | |
1569 args_old++; | |
1570 int args_len = args_old - from.args; | |
1571 memmove(args_buffer, from.args, args_len); | |
1572 args = args_buffer; | |
1573 args_buffer += args_len; | |
1574 } | |
1575 void CmdSimplified::Save(string& saveret) { | |
1576 char buf[1024]; | |
1577 sprintf(buf, "%02x-%02x:%04x:%02x(%02d),", cmd1, cmd2, cmd3, cmd4, argc); | |
1578 saveret += buf; | |
1579 | |
1580 /* args ¤Î¥³¥Ô¡¼ */ | |
1581 char* d = args; | |
1582 while(d && *d != TYPE_END) { | |
1583 if (*d == TYPE_VAL) { | |
1584 d++; | |
1585 sprintf(buf, "%d,", read_little_endian_int(d)); | |
1586 d += 4; | |
1587 } else { /* TYPE_STR ¤È²¾Äê */ | |
1588 d++; | |
1589 if (strlen(d) > 1000) d[1000] = 0; // ¤¢¤ê¤¨¤Ê¤¤¡¦¡¦¡¦ | |
1590 int i; int cnt = 0; | |
1591 buf[cnt++] = '"'; | |
1592 for (i=0; d[i] != 0; i++) { | |
1593 if (d[i] == '"') buf[cnt++] = '"'; | |
1594 buf[cnt++] = d[i]; | |
1595 } | |
1596 buf[cnt++]='"'; | |
1597 buf[cnt++] = ','; | |
1598 buf[cnt++] = 0; | |
1599 d += strlen(d)+1; | |
1600 } | |
1601 saveret += buf; | |
1602 } | |
1603 saveret += 'E'; | |
1604 } | |
1605 | |
1606 void CmdSimplified::Load(const char* save, char*& args_buffer) { | |
1607 args = args_buffer; | |
1608 | |
1609 type = CMD_OTHER; | |
1610 sscanf(save, "%02x-%02x:%04x:%02x(%02d),", &cmd1, &cmd2, &cmd3, &cmd4, &argc); | |
1611 save = strchr(save, ','); | |
1612 if (save == 0) { | |
1613 *args_buffer++ = TYPE_END; | |
1614 return; | |
1615 } | |
1616 save++; | |
1617 while(*save != 'E' && *save != '\n' && *save != '\0') { | |
1618 if (isdigit(*save)) { | |
1619 int v; | |
1620 sscanf(save,"%d,",&v); | |
1621 *args_buffer++ = TYPE_VAL; | |
1622 write_little_endian_int(args_buffer, v); | |
1623 args_buffer+= 4; | |
1624 save = strchr(save, ','); | |
1625 if (save) save++; | |
1626 } else { // *save == '"' | |
1627 save++; | |
1628 *args_buffer++ = TYPE_STR; | |
1629 while(1) { | |
1630 if (*save == 0) break; | |
1631 if (*save == '"') { | |
1632 if (save[1] != '"') break; | |
1633 save++; | |
1634 } | |
1635 *args_buffer++ = *save++; | |
1636 } | |
1637 save += 2; | |
1638 *args_buffer++ = 0; | |
1639 } | |
1640 } | |
1641 *args_buffer++ = TYPE_END; | |
1642 return; | |
1643 } | |
1644 | |
1645 #ifdef SCN_DUMP | |
1646 void usage(void) { | |
1647 fprintf(stderr,"usage : scn2kdump [inputfile] [outputfile]\n"); | |
1648 fprintf(stderr," inputfile: seen.txt(default)\n"); | |
1649 fprintf(stderr," outputfile: seen.txt_out(default)\n"); | |
1650 exit(-1); | |
1651 } | |
1652 int main(int argc, char** argv) { | |
1653 /* determine file names */ | |
1654 bool verbose = false; | |
1655 char* inname = "seen.txt"; | |
1656 char* outname = 0; | |
1657 if (argc > 2 && strcmp(argv[1],"-v") == 0) { | |
1658 int i; for (i=1; i<argc; i++) argv[i] = argv[i+1]; | |
1659 argc--; | |
1660 verbose = true; | |
1661 } | |
1662 switch(argc) { | |
1663 case 1: break; | |
1664 case 2: inname = argv[1]; break; | |
1665 case 3: inname = argv[1]; outname = argv[2]; break; | |
1666 default: usage(); | |
1667 } | |
1668 /* open output file */ | |
1669 FILE* outstream = stdout; | |
1670 /* create archive instance */ | |
1671 SCN2kFILE archive(inname); | |
1672 archive.Init(); | |
1673 if (archive.Deal() == 0) { | |
1674 fprintf(stderr,"Cannot open / Invalid archive file %s\n",inname); | |
1675 usage(); | |
1676 } | |
1677 /* dump files */ | |
1678 archive.InitList(); | |
1679 char* fname; | |
1680 fprintf(stderr,"Dump start\n"); | |
1681 int system_version = 0; | |
1682 while( (fname = archive.ListItem()) != 0) { | |
1683 ARCINFO* info = archive.Find(fname,""); | |
1684 if (info == 0) continue; | |
1685 char* data = info->CopyRead(); | |
1686 char* d = data; | |
1687 char* dend = d + info->Size(); | |
1688 /* version ³Îǧ */ | |
1689 if (read_little_endian_int(d) == 0x1cc) { | |
1690 system_version = 0; | |
1691 } else if (read_little_endian_int(d) == 0x1d0) { | |
1692 system_version = 1; | |
1693 } else { | |
1694 continue; | |
1695 } | |
1696 if (read_little_endian_int(d+4) == 0x1adb2) ; // little busters! | |
1697 else if (read_little_endian_int(d+4) != 0x2712) continue; | |
1698 int header_size; | |
1699 if (system_version == 0) { | |
1700 header_size = 0x1cc + read_little_endian_int(d+0x20) * 4; | |
1701 } else { | |
1702 header_size = read_little_endian_int(d+0x20); | |
1703 } | |
1704 d += header_size; | |
1705 | |
1706 const char* dcur = d; | |
1707 const char* dstart = d; | |
1708 fprintf(stderr,"Dumping %s\n",fname); | |
1709 Flags flags; | |
1710 /* ºÇ½é¤«¤éºÇ¸å¤Þ¤Ç¥³¥Þ¥ó¥É¼èÆÀ -> ½ÐÎϤò·«¤êÊÖ¤¹ */ | |
1711 while(dcur<dend) { | |
1712 const char* dprev = dcur; | |
1713 Cmd cmd(flags, system_version); cmd.ClearError(); | |
1714 | |
1715 /* end? */ | |
1716 if (*dcur == -1) { | |
1717 /* 0xff x 32byte + 0x00 : end sign */ | |
1718 int i; for (i=0; i<0x20; i++) | |
1719 if (dcur[i] != -1) break; | |
1720 if (i == 0x20 && dcur[i] == 0) break; | |
1721 } | |
1722 dprintf("%d : ",dcur-dstart); | |
1723 cmd.GetCmd(flags, dcur); | |
1724 if (cmd.IsError()) { | |
1725 fprintf(outstream, "Error at %6d\n",dprev-dstart); | |
1726 while(dcur < dend) { | |
1727 if (*dcur == 0x29 && dcur[1] == 0x0a) {dcur++;break;} | |
1728 dcur++; | |
1729 } | |
1730 dprev -= 2*16; | |
1731 int ilen = (dcur-dprev+15)/16; | |
1732 int i; for (i=0; i<ilen; i++) { | |
1733 fprintf(outstream, "%6d: ",dprev-dstart); | |
1734 int j; for (j=0; j<16; j++) { | |
1735 if (dprev >= dend) break; | |
1736 if (dprev < data) continue; | |
1737 fprintf(outstream, "%02x ",*(unsigned char*)(dprev)); | |
1738 dprev++; | |
1739 } | |
1740 fprintf(outstream, "\n"); | |
1741 } | |
1742 } | |
1743 } | |
1744 delete info; | |
1745 } | |
1746 return 0; | |
1747 } | |
1748 #endif | |
1749 |