Mercurial > otakunoraifu
comparison scn2k/scn2k_cmd.cc @ 65:4416cfac86ae
Convert EUC-JP files to UTF8
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Fri, 26 Nov 2010 10:53:15 +0100 |
parents | 4b9ffe15a87d |
children | e4a12dd9a51b |
comparison
equal
deleted
inserted
replaced
64:045ca45f9610 | 65:4416cfac86ae |
---|---|
37 | 37 |
38 using namespace std; | 38 using namespace std; |
39 | 39 |
40 | 40 |
41 // #define SCN_DUMP | 41 // #define SCN_DUMP |
42 /* 注意点: @@@ で表記 */ | 42 /* 羈刻 @@@ ц;荐 */ |
43 | 43 |
44 | 44 |
45 | 45 |
46 //bool debug_flag = true; | 46 //bool debug_flag = true; |
47 bool debug_flag = false; | 47 bool debug_flag = false; |
113 } | 113 } |
114 if (index == 10) index = 8; | 114 if (index == 10) index = 8; |
115 if (index == 11) index = 9; | 115 if (index == 11) index = 9; |
116 if (index > TYPE_VARMAX || uint(type) > 4) return 0; | 116 if (index > TYPE_VARMAX || uint(type) > 4) return 0; |
117 if (type == 0) { | 117 if (type == 0) { |
118 // A[]..G[], Z[] を直に読む | 118 // A[]..G[], Z[] 眼茯 |
119 if (uint(number) >= 2000) return 0; | 119 if (uint(number) >= 2000) return 0; |
120 return var[index][number]; | 120 return var[index][number]; |
121 } else { | 121 } else { |
122 // Ab[]..G4b[], Z8b[] などを読む | 122 // Ab[]..G4b[], Z8b[] 茯 |
123 int factor = 1 << (type - 1); | 123 int factor = 1 << (type - 1); |
124 int eltsize = 32 / factor; | 124 int eltsize = 32 / factor; |
125 if (uint(number) >= (64000 / factor)) return 0; | 125 if (uint(number) >= (64000 / factor)) return 0; |
126 return (var[index][number / eltsize] >> ((number % eltsize) * factor)) & ((1 << factor) - 1); | 126 return (var[index][number / eltsize] >> ((number % eltsize) * factor)) & ((1 << factor) - 1); |
127 } | 127 } |
142 if (index == 11) index = 9; | 142 if (index == 11) index = 9; |
143 if (index < 0 || index > TYPE_VARMAX) { | 143 if (index < 0 || index > TYPE_VARMAX) { |
144 fprintf(stderr,"Error: invalid access to Var<%d>[%d]\n",info.type,info.number); | 144 fprintf(stderr,"Error: invalid access to Var<%d>[%d]\n",info.type,info.number); |
145 } | 145 } |
146 if (type == 0) { | 146 if (type == 0) { |
147 // A[]..G[], Z[] を直に書く | 147 // A[]..G[], Z[] 眼吾 |
148 if (uint(info.number) >= 2000) return; | 148 if (uint(info.number) >= 2000) return; |
149 var[index][info.number] = value; | 149 var[index][info.number] = value; |
150 } else { | 150 } else { |
151 // Ab[]..G4b[], Z8b[] などを書く | 151 // Ab[]..G4b[], Z8b[] 吾 |
152 int factor = 1 << (type - 1); | 152 int factor = 1 << (type - 1); |
153 int eltsize = 32 / factor; | 153 int eltsize = 32 / factor; |
154 int eltmask = (1 << factor) - 1; | 154 int eltmask = (1 << factor) - 1; |
155 int shift = (info.number % eltsize) * factor; | 155 int shift = (info.number % eltsize) * factor; |
156 if (uint(info.number) >= (64000 / factor)) return; | 156 if (uint(info.number) >= (64000 / factor)) return; |
338 } | 338 } |
339 } | 339 } |
340 } | 340 } |
341 | 341 |
342 bool Flags::Exec(Cmd& cmd) { | 342 bool Flags::Exec(Cmd& cmd) { |
343 if (cmd.cmd_type == CMD_FLAGS) { // 代入演算 | 343 if (cmd.cmd_type == CMD_FLAGS) { // 篁eユ膊 |
344 if (cmd.args.size() != 2) return false; | 344 if (cmd.args.size() != 2) return false; |
345 Set(cmd.args[0], cmd.args[1].value); | 345 Set(cmd.args[0], cmd.args[1].value); |
346 cmd.clear(); | 346 cmd.clear(); |
347 return true; | 347 return true; |
348 } | 348 } |
349 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0a) { // 文字列演算 | 349 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0a) { // 絖羲膊 |
350 VarInfo arg1 = cmd.args[0]; | 350 VarInfo arg1 = cmd.args[0]; |
351 switch(cmd.cmd3) { | 351 switch(cmd.cmd3) { |
352 case 0: | 352 case 0: |
353 if (cmd.cmd4 == 0) { | 353 if (cmd.cmd4 == 0) { |
354 SetStr(arg1, cmd.Str(cmd.args[1])); | 354 SetStr(arg1, cmd.Str(cmd.args[1])); |
358 int len = cmd.args[2].value; | 358 int len = cmd.args[2].value; |
359 int i; | 359 int i; |
360 for (i=0; i < sc[i] && len != 0; i++, len--) { | 360 for (i=0; i < sc[i] && len != 0; i++, len--) { |
361 if (sc[i]<0 && sc[i+1]!=0) i++; | 361 if (sc[i]<0 && sc[i+1]!=0) i++; |
362 } | 362 } |
363 s.erase(i); // 全角で len 文字まで切り詰める | 363 s.erase(i); // 茹 len 絖障у荅違 |
364 SetStr(arg1, s); | 364 SetStr(arg1, s); |
365 // fprintf(stderr,"Set[%d,%d]<-%s\n",arg1.type,arg1.number,s.c_str()); | 365 // fprintf(stderr,"Set[%d,%d]<-%s\n",arg1.type,arg1.number,s.c_str()); |
366 } else break; | 366 } else break; |
367 cmd.clear(); | 367 cmd.clear(); |
368 break; | 368 break; |
369 case 1: | 369 case 1: |
370 if (cmd.cmd4 == 0) { | 370 if (cmd.cmd4 == 0) { |
371 SetStr(arg1, ""); | 371 SetStr(arg1, ""); |
372 cmd.clear(); | 372 cmd.clear(); |
373 } else if (cmd.cmd4 == 1) { | 373 } else if (cmd.cmd4 == 1) { |
374 // 領域指定で文字列クリア | 374 // 絎ф絖 |
375 VarInfo v1 = cmd.args[0]; | 375 VarInfo v1 = cmd.args[0]; |
376 VarInfo v2 = cmd.args[1]; | 376 VarInfo v2 = cmd.args[1]; |
377 eprintf("memclear(str). Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); | 377 eprintf("memclear(str). Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); |
378 if (v1.type != v2.type || (v1.type != TYPE_VARSTR && v1.type != TYPE_VARSYSSTR && v1.type != TYPE_VARLOCSTR)) { | 378 if (v1.type != v2.type || (v1.type != TYPE_VARSTR && v1.type != TYPE_VARSYSSTR && v1.type != TYPE_VARLOCSTR)) { |
379 eprintf(" error: bad args\n"); | 379 eprintf(" error: bad args\n"); |
405 else SetSys(0); | 405 else SetSys(0); |
406 cmd.clear(); | 406 cmd.clear(); |
407 break; } | 407 break; } |
408 case 5: // substring, index from left | 408 case 5: // substring, index from left |
409 case 6: // substring, index from right | 409 case 6: // substring, index from right |
410 // 全角対応らしい | 410 // 茹絲上 |
411 //FIXME: Make sure it works properly | 411 //FIXME: Make sure it works properly |
412 { int offset = cmd.args[2].value; | 412 { int offset = cmd.args[2].value; |
413 int len = strlen(cmd.Str(cmd.args[1])); | 413 int len = strlen(cmd.Str(cmd.args[1])); |
414 string str = cmd.Str(cmd.args[1]); | 414 string str = cmd.Str(cmd.args[1]); |
415 const char* s = str.c_str(); | 415 const char* s = str.c_str(); |
416 if (cmd.cmd3 == 6) offset = len - offset; | 416 if (cmd.cmd3 == 6) offset = len - offset; |
417 if (offset < 0) offset = 0; | 417 if (offset < 0) offset = 0; |
418 // 先頭 N 文字を読み飛ばす | 418 // N 絖茯翠違 |
419 int i; | 419 int i; |
420 int offset_top = 0; | 420 int offset_top = 0; |
421 for (i=0; i<offset && s[offset_top] != 0; i++) { | 421 for (i=0; i<offset && s[offset_top] != 0; i++) { |
422 if (s[offset_top] < 0 && s[offset_top+1] != 0) offset_top += 2; | 422 if (s[offset_top] < 0 && s[offset_top+1] != 0) offset_top += 2; |
423 else offset_top += 1; | 423 else offset_top += 1; |
424 } | 424 } |
425 if (s[offset_top] == 0) { | 425 if (s[offset_top] == 0) { |
426 SetStr(arg1, ""); | 426 SetStr(arg1, ""); |
427 } else if (cmd.cmd4 == 0) { // 長さ制限なし | 427 } else if (cmd.cmd4 == 0) { // 激狗 |
428 SetStr(arg1, string(s, offset_top, len-offset_top)); | 428 SetStr(arg1, string(s, offset_top, len-offset_top)); |
429 } else { // cmd.cmd4 == 1 | 429 } else { // cmd.cmd4 == 1 |
430 int slen = cmd.args[3].value; | 430 int slen = cmd.args[3].value; |
431 int offset_end = offset_top; | 431 int offset_end = offset_top; |
432 for (i=0; i<slen && s[offset_end] != 0; i++) { | 432 for (i=0; i<slen && s[offset_end] != 0; i++) { |
445 else s++; | 445 else s++; |
446 } | 446 } |
447 SetSys(i); | 447 SetSys(i); |
448 cmd.clear(); | 448 cmd.clear(); |
449 break; } | 449 break; } |
450 case 8: // 文字列を切って短くする | 450 case 8: // 絖c |
451 if (cmd.args[1].value <= 0) { | 451 if (cmd.args[1].value <= 0) { |
452 SetStr(arg1, ""); | 452 SetStr(arg1, ""); |
453 } else if (cmd.args[1].value < strlen(cmd.Str(cmd.args[1]))) { | 453 } else if (cmd.args[1].value < strlen(cmd.Str(cmd.args[1]))) { |
454 Str(arg1.type,arg1.number).erase(cmd.args[1].value); | 454 Str(arg1.type,arg1.number).erase(cmd.args[1].value); |
455 } | 455 } |
456 cmd.clear(); | 456 cmd.clear(); |
457 break; | 457 break; |
458 case 0x0e: // 漢字モードでitoa | 458 case 0x0e: // 羲√≪若itoa |
459 { | 459 { |
460 int arg1 = cmd.args[0].value; | 460 int arg1 = cmd.args[0].value; |
461 string result; | 461 string result; |
462 char wc[3]; wc[2]=0; | 462 char wc[3]; wc[2]=0; |
463 char buf[20]; | 463 char buf[20]; |
486 } | 486 } |
487 SetStr(cmd.args[1], result); | 487 SetStr(cmd.args[1], result); |
488 cmd.clear(); | 488 cmd.clear(); |
489 } | 489 } |
490 break; | 490 break; |
491 case 0x0f: case 0x11: // itoa (0x11 の方は zero padding するっぽい) | 491 case 0x0f: case 0x11: // itoa (0x11 鴻 zero padding c純) |
492 if (cmd.cmd4 == 0) { | 492 if (cmd.cmd4 == 0) { |
493 int arg1 = cmd.args[0].value; | 493 int arg1 = cmd.args[0].value; |
494 char buf[1024]; sprintf(buf, "%d", arg1); | 494 char buf[1024]; sprintf(buf, "%d", arg1); |
495 SetStr(cmd.args[1], buf); | 495 SetStr(cmd.args[1], buf); |
496 cmd.clear(); | 496 cmd.clear(); |
497 } else if (cmd.cmd4 == 1) { | 497 } else if (cmd.cmd4 == 1) { |
498 // 漢字(SJIS) : 82 [4f+N] | 498 // 羲√(SJIS) : 82 [4f+N] |
499 // やはり漢字じゃない? | 499 // 羲√鐚 |
500 int arg1 = cmd.args[0].value; | 500 int arg1 = cmd.args[0].value; |
501 char buf[1024]; char fmt[1024]; | 501 char buf[1024]; char fmt[1024]; |
502 if (cmd.cmd3 == 0x0f) { | 502 if (cmd.cmd3 == 0x0f) { |
503 sprintf(fmt, "%%%dd",cmd.args[2].value); /* 空白でパディング */ | 503 sprintf(fmt, "%%%dd",cmd.args[2].value); /* 腥榊純сc潟 */ |
504 } else { | 504 } else { |
505 sprintf(fmt, "%%0%dd",cmd.args[2].value); | 505 sprintf(fmt, "%%0%dd",cmd.args[2].value); |
506 } | 506 } |
507 sprintf(buf, fmt, arg1); | 507 sprintf(buf, fmt, arg1); |
508 SetStr(cmd.args[1], buf); | 508 SetStr(cmd.args[1], buf); |
509 cmd.clear(); | 509 cmd.clear(); |
510 } | 510 } |
511 break; | 511 break; |
512 case 0x64: // 文字列の表示 : 引数をテキストウィンドウに表示 | 512 case 0x64: // 絖茵腓 : 綣違鴻c潟茵腓 |
513 if (cmd.cmd4 == 1) { | 513 if (cmd.cmd4 == 1) { |
514 char buf[256]; | 514 char buf[256]; |
515 snprintf(buf, 255, "%d", Get(cmd.args[0].type, cmd.args[0].number)); | 515 snprintf(buf, 255, "%d", Get(cmd.args[0].type, cmd.args[0].number)); |
516 cmd.args[0].type = TYPE_STR; | 516 cmd.args[0].type = TYPE_STR; |
517 cmd.args[0].value = cmd.AddStr(buf); | 517 cmd.args[0].value = cmd.AddStr(buf); |
519 } | 519 } |
520 cmd.cmd_type = CMD_TEXT; | 520 cmd.cmd_type = CMD_TEXT; |
521 break; | 521 break; |
522 } | 522 } |
523 } | 523 } |
524 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0b) { // 数値変数演算 | 524 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0b) { // 医ゅ井膊 |
525 if (cmd.cmd3 == 0 && cmd.cmd4 == 0) { | 525 if (cmd.cmd3 == 0 && cmd.cmd4 == 0) { |
526 /* 複数の変数をセット */ | 526 /* 茲違紊違祉 */ |
527 VarInfo v1 = cmd.args[0]; | 527 VarInfo v1 = cmd.args[0]; |
528 eprintf("set multiple-var Var[%d]<%d> <- ",v1.type, v1.number); | 528 eprintf("set multiple-var Var[%d]<%d> <- ",v1.type, v1.number); |
529 int i; | 529 int i; |
530 if (cmd.args.size() < cmd.argc) { | 530 if (cmd.args.size() < cmd.argc) { |
531 eprintf(" error: argsize changed %d -> %d\n",cmd.argc, cmd.args.size()); | 531 eprintf(" error: argsize changed %d -> %d\n",cmd.argc, cmd.args.size()); |
537 v1.number++; | 537 v1.number++; |
538 } | 538 } |
539 eprintf("\n"); | 539 eprintf("\n"); |
540 cmd.clear(); | 540 cmd.clear(); |
541 } else if (cmd.cmd3 == 1 && cmd.cmd4 == 0) { | 541 } else if (cmd.cmd3 == 1 && cmd.cmd4 == 0) { |
542 /* 領域指定で変数をクリア */ | 542 /* 絎у違 */ |
543 VarInfo v1 = cmd.args[0]; | 543 VarInfo v1 = cmd.args[0]; |
544 VarInfo v2 = cmd.args[1]; | 544 VarInfo v2 = cmd.args[1]; |
545 eprintf("memclear. Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); | 545 eprintf("memclear. Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); |
546 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n"); | 546 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n"); |
547 else { | 547 else { |
550 for (; v1.number <= v2.number; v1.number++) | 550 for (; v1.number <= v2.number; v1.number++) |
551 Set(v1, 0); | 551 Set(v1, 0); |
552 } | 552 } |
553 cmd.clear(); | 553 cmd.clear(); |
554 } else if (cmd.cmd3 == 1 && cmd.cmd4 == 1) { | 554 } else if (cmd.cmd3 == 1 && cmd.cmd4 == 1) { |
555 /* 領域指定で変数をセット */ | 555 /* 絎у違祉 */ |
556 VarInfo v1 = cmd.args[0]; | 556 VarInfo v1 = cmd.args[0]; |
557 VarInfo v2 = cmd.args[1]; | 557 VarInfo v2 = cmd.args[1]; |
558 int value = cmd.args[2].value; | 558 int value = cmd.args[2].value; |
559 eprintf("memset. Var[%d]<%d> - Var[%d]<%d> <- %d\n",v1.type, v1.number, v2.type, v2.number, value); | 559 eprintf("memset. Var[%d]<%d> - Var[%d]<%d> <- %d\n",v1.type, v1.number, v2.type, v2.number, value); |
560 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n"); | 560 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n"); |
563 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type); | 563 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type); |
564 for (; v1.number <= v2.number; v1.number++) | 564 for (; v1.number <= v2.number; v1.number++) |
565 Set(v1, value); | 565 Set(v1, value); |
566 } | 566 } |
567 cmd.clear(); | 567 cmd.clear(); |
568 } else if (cmd.cmd3 == 4 && cmd.cmd4 == 1) { // 領域クリア(sysfunc.txt) | 568 } else if (cmd.cmd3 == 4 && cmd.cmd4 == 1) { // (sysfunc.txt) |
569 VarInfo v1 = cmd.args[0]; | 569 VarInfo v1 = cmd.args[0]; |
570 int step = cmd.args[1].value; | 570 int step = cmd.args[1].value; |
571 int deal = cmd.args[2].value; | 571 int deal = cmd.args[2].value; |
572 int val = cmd.args[3].value; | 572 int val = cmd.args[3].value; |
573 eprintf("memclear. Var[%d]<%d> step %d deal %d <- val %d\n",v1.type, v1.number, step, deal, val); | 573 eprintf("memclear. Var[%d]<%d> step %d deal %d <- val %d\n",v1.type, v1.number, step, deal, val); |
574 int i; for (i=0; i<deal; i++) { | 574 int i; for (i=0; i<deal; i++) { |
575 Set(v1, val); | 575 Set(v1, val); |
576 v1.number += step; | 576 v1.number += step; |
577 } | 577 } |
578 cmd.clear(); | 578 cmd.clear(); |
579 } else if (cmd.cmd3 == 0x64 && cmd.cmd4 == 0) { //領域で数値を合計する | 579 } else if (cmd.cmd3 == 0x64 && cmd.cmd4 == 0) { //ф医ゃ荐 |
580 VarInfo v1 = cmd.args[0]; | 580 VarInfo v1 = cmd.args[0]; |
581 VarInfo v2 = cmd.args[1]; | 581 VarInfo v2 = cmd.args[1]; |
582 eprintf("sum var. Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); | 582 eprintf("sum var. Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); |
583 int sum = 0; | 583 int sum = 0; |
584 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n"); | 584 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n"); |
631 | 631 |
632 /********************************************************************* | 632 /********************************************************************* |
633 ** Cmd | 633 ** Cmd |
634 */ | 634 */ |
635 | 635 |
636 /* 数値 num := 0x24 0xff <int num> */ | 636 /* 医 num := 0x24 0xff <int num> */ |
637 /* 変数 var := 0x24 <uchar type> 0x5b <exp> 0x5d */ | 637 /* 紊 var := 0x24 <uchar type> 0x5b <exp> 0x5d */ |
638 /* 項 token := num | var | 0x28 <exp> 0x29 | <plus|minus> token */ | 638 /* token := num | var | 0x28 <exp> 0x29 | <plus|minus> token */ |
639 | 639 |
640 int Cmd::GetLeftToken(const char*& d, VarInfo& info) { | 640 int Cmd::GetLeftToken(const char*& d, VarInfo& info) { |
641 bool var_flag = true; | 641 bool var_flag = true; |
642 int minus_flag = 0; | 642 int minus_flag = 0; |
643 int value = 0; | 643 int value = 0; |
646 else dprintf("plus-"); | 646 else dprintf("plus-"); |
647 d += 2; | 647 d += 2; |
648 var_flag = false; | 648 var_flag = false; |
649 } | 649 } |
650 if (d[0] == 0x24 && ((unsigned const char*)d)[1] == 0xff) { | 650 if (d[0] == 0x24 && ((unsigned const char*)d)[1] == 0xff) { |
651 // if ( (d[0] == 0x30 || d[0] == 0x31) && d[1] == 0x24 && ((unsigned const char*)d)[2] == 0xff) /* @@@ not supported; selection 内で、0x30|0x31 が付随することがある */ | 651 // if ( (d[0] == 0x30 || d[0] == 0x31) && d[1] == 0x24 && ((unsigned const char*)d)[2] == 0xff) /* @@@ not supported; selection с0x30|0x31 篁 */ |
652 // numerical atom | 652 // numerical atom |
653 d += 6; | 653 d += 6; |
654 value = read_little_endian_int(d-4); | 654 value = read_little_endian_int(d-4); |
655 dprintf("%d",value); | 655 dprintf("%d",value); |
656 var_flag = false; | 656 var_flag = false; |
744 cmdstr[0] = 0; | 744 cmdstr[0] = 0; |
745 strend = 0; | 745 strend = 0; |
746 pos = -1; | 746 pos = -1; |
747 } | 747 } |
748 | 748 |
749 /* 演算子 op := 0x5c <uchar op> */ | 749 /* 羲膊絖 op := 0x5c <uchar op> */ |
750 /* 数式 exp: [op] <token> [op <token> [...]] */ | 750 /* 医 exp: [op] <token> [op <token> [...]] */ |
751 int Cmd::GetExpression(const char*& d, VarInfo* info_ptr) { | 751 int Cmd::GetExpression(const char*& d, VarInfo* info_ptr) { |
752 #define STACK_DEPTH 1024 | 752 #define STACK_DEPTH 1024 |
753 #define OP_LB 11 | 753 #define OP_LB 11 |
754 char op_stack[STACK_DEPTH]; | 754 char op_stack[STACK_DEPTH]; |
755 int val_stack[STACK_DEPTH]; | 755 int val_stack[STACK_DEPTH]; |
756 int stack_count = 0; | 756 int stack_count = 0; |
757 | 757 |
758 // 第一項の読み込み | 758 // 膃筝茯粋昭 |
759 while(*d == 0x28) { | 759 while(*d == 0x28) { |
760 d++; | 760 d++; |
761 dprintf("("); | 761 dprintf("("); |
762 op_stack[stack_count++] = OP_LB; | 762 op_stack[stack_count++] = OP_LB; |
763 } | 763 } |
770 stack_count--; | 770 stack_count--; |
771 } | 771 } |
772 | 772 |
773 if (*d != 0x5c && stack_count == 0) { | 773 if (*d != 0x5c && stack_count == 0) { |
774 if (info_ptr) *info_ptr = info; | 774 if (info_ptr) *info_ptr = info; |
775 return value; // 単純なleft-termはここで終了。有効なinfo_ptrを帰す(可能性がある) | 775 return value; // 膣left-termх篋鴻info_ptr絽違鐚醇с鐚 |
776 } | 776 } |
777 | 777 |
778 while(*d == 0x5c) { | 778 while(*d == 0x5c) { |
779 int op_type = *(unsigned char*)(d+1); | 779 int op_type = *(unsigned char*)(d+1); |
780 d += 2; | 780 d += 2; |
781 if (op_type < 70) dprintf("%s",op_str[op_type]); | 781 if (op_type < 70) dprintf("%s",op_str[op_type]); |
782 else dprintf("err."); | 782 else dprintf("err."); |
783 if (op_type >= 10) SetError(); | 783 if (op_type >= 10) SetError(); |
784 int cur_pri = op_pri(op_type); | 784 int cur_pri = op_pri(op_type); |
785 while(stack_count != 0 && op_pri(op_stack[stack_count-1]) <= cur_pri) { | 785 while(stack_count != 0 && op_pri(op_stack[stack_count-1]) <= cur_pri) { |
786 // 優先順位の高い、先行する演算を行う | 786 // 篏蕭茵羲膊茵 |
787 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value); | 787 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value); |
788 stack_count--; | 788 stack_count--; |
789 } | 789 } |
790 val_stack[stack_count] = value; | 790 val_stack[stack_count] = value; |
791 op_stack[stack_count++] = op_type; | 791 op_stack[stack_count++] = op_type; |
796 } | 796 } |
797 if (stack_count >= STACK_DEPTH) SetError(); | 797 if (stack_count >= STACK_DEPTH) SetError(); |
798 value = GetLeftToken(d, info); | 798 value = GetLeftToken(d, info); |
799 | 799 |
800 while (*d != 0x5c && stack_count > 0) { | 800 while (*d != 0x5c && stack_count > 0) { |
801 // 未実行の演算を終わらせる | 801 // 絎茵羲膊腟 |
802 if (op_stack[stack_count-1] != OP_LB) { | 802 if (op_stack[stack_count-1] != OP_LB) { |
803 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value); | 803 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value); |
804 stack_count--; | 804 stack_count--; |
805 } else if (*d == 0x29) { /* op_stack == OP_LB */ | 805 } else if (*d == 0x29) { /* op_stack == OP_LB */ |
806 // bracket 終端があれば、閉じておく | 806 // bracket 腟腴違 |
807 d++; | 807 d++; |
808 dprintf(")"); | 808 dprintf(")"); |
809 stack_count--; | 809 stack_count--; |
810 } else break; // error | 810 } else break; // error |
811 } | 811 } |
817 info_ptr->value = value; | 817 info_ptr->value = value; |
818 } | 818 } |
819 return value; | 819 return value; |
820 } | 820 } |
821 | 821 |
822 // 条件分岐専用に、条件演算と算術演算の混合を検知できる専用ルーチン(本来はGetExpressionで差し支えない) | 822 // >散絏絨>散羲膊膊茵羲膊羞桁罎ャс絨若鰹ャGetExpressionу勲) |
823 int Cmd::GetExpressionCond(const char*& d) { | 823 int Cmd::GetExpressionCond(const char*& d) { |
824 char op_stack[STACK_DEPTH]; | 824 char op_stack[STACK_DEPTH]; |
825 int val_stack[STACK_DEPTH]; | 825 int val_stack[STACK_DEPTH]; |
826 int valattr_stack[STACK_DEPTH]; | 826 int valattr_stack[STACK_DEPTH]; |
827 #define ATTR_VAL 0 | 827 #define ATTR_VAL 0 |
828 #define ATTR_FLAG 1 | 828 #define ATTR_FLAG 1 |
829 int stack_count = 0; | 829 int stack_count = 0; |
830 | 830 |
831 // 第一項の読み込み | 831 // 膃筝茯粋昭 |
832 while(*d == 0x28) { | 832 while(*d == 0x28) { |
833 d++; | 833 d++; |
834 dprintf("("); | 834 dprintf("("); |
835 op_stack[stack_count++] = OP_LB; | 835 op_stack[stack_count++] = OP_LB; |
836 } | 836 } |
848 d += 2; | 848 d += 2; |
849 if (op_type < 70) dprintf("%s",op_str[op_type]); | 849 if (op_type < 70) dprintf("%s",op_str[op_type]); |
850 else dprintf("err."); | 850 else dprintf("err."); |
851 int cur_pri = op_pri_cond(op_type); | 851 int cur_pri = op_pri_cond(op_type); |
852 while(stack_count != 0 && op_pri_cond(op_stack[stack_count-1]) <= cur_pri) { | 852 while(stack_count != 0 && op_pri_cond(op_stack[stack_count-1]) <= cur_pri) { |
853 // 優先順位の高い、先行する演算を行う | 853 // 篏蕭茵羲膊茵 |
854 if (op_stack[stack_count-1] >= 60) { | 854 if (op_stack[stack_count-1] >= 60) { |
855 if (valattr_stack[stack_count-1] != ATTR_FLAG || valattr != ATTR_FLAG) SetError(); | 855 if (valattr_stack[stack_count-1] != ATTR_FLAG || valattr != ATTR_FLAG) SetError(); |
856 } else { | 856 } else { |
857 if (valattr_stack[stack_count-1] != ATTR_VAL || valattr != ATTR_VAL) SetError(); | 857 if (valattr_stack[stack_count-1] != ATTR_VAL || valattr != ATTR_VAL) SetError(); |
858 } | 858 } |
871 if (stack_count >= STACK_DEPTH) SetError(); | 871 if (stack_count >= STACK_DEPTH) SetError(); |
872 value = GetLeftToken(d, info); | 872 value = GetLeftToken(d, info); |
873 valattr = ATTR_VAL; | 873 valattr = ATTR_VAL; |
874 | 874 |
875 while (*d != 0x5c && stack_count > 0) { | 875 while (*d != 0x5c && stack_count > 0) { |
876 // 未実行の演算を終わらせる | 876 // 絎茵羲膊腟 |
877 if (op_stack[stack_count-1] != OP_LB) { | 877 if (op_stack[stack_count-1] != OP_LB) { |
878 if (op_stack[stack_count-1] >= 60) { | 878 if (op_stack[stack_count-1] >= 60) { |
879 if (valattr_stack[stack_count-1] != ATTR_FLAG || valattr != ATTR_FLAG) SetError(); | 879 if (valattr_stack[stack_count-1] != ATTR_FLAG || valattr != ATTR_FLAG) SetError(); |
880 } else { | 880 } else { |
881 if (valattr_stack[stack_count-1] != ATTR_VAL || valattr != ATTR_VAL) SetError(); | 881 if (valattr_stack[stack_count-1] != ATTR_VAL || valattr != ATTR_VAL) SetError(); |
882 } | 882 } |
883 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value); | 883 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value); |
884 if (op_stack[stack_count-1] >= 40) valattr = ATTR_FLAG; | 884 if (op_stack[stack_count-1] >= 40) valattr = ATTR_FLAG; |
885 stack_count--; | 885 stack_count--; |
886 // bracket 終端があれば、閉じておく | 886 // bracket 腟腴違 |
887 } else if (*d == 0x29) { /* op_stack == OP_LB */ | 887 } else if (*d == 0x29) { /* op_stack == OP_LB */ |
888 d++; | 888 d++; |
889 dprintf(")"); | 889 dprintf(")"); |
890 stack_count--; | 890 stack_count--; |
891 } else break; // error | 891 } else break; // error |
903 arg = | 903 arg = |
904 args = 0x28 <exp> [[0x2c] <exp> [[0x2c] <exp> [...] ]] | 904 args = 0x28 <exp> [[0x2c] <exp> [[0x2c] <exp> [...] ]] |
905 */ | 905 */ |
906 | 906 |
907 int Cmd::GetArgs(const char*& d) { | 907 int Cmd::GetArgs(const char*& d) { |
908 if (*d != 0x28) return 0; /* 引数なし */ | 908 if (*d != 0x28) return 0; /* 綣違 */ |
909 d++; | 909 d++; |
910 dprintf("args:"); | 910 dprintf("args:"); |
911 VarInfo var; | 911 VarInfo var; |
912 int i; for (i=0; i<100 ; i++) { | 912 int i; for (i=0; i<100 ; i++) { |
913 /* number, variable, string の種別なく値を得る */ | 913 /* number, variable, string 腮ャゃ緇 */ |
914 if (*d == 0x61) { // よくわからない(智代アフター) | 914 if (*d == 0x61) { // (坂撮≪帥) |
915 dprintf("@%d",d[1]); | 915 dprintf("@%d",d[1]); |
916 d += 2; | 916 d += 2; |
917 if (*d == 0x28) { | 917 if (*d == 0x28) { |
918 dprintf("{"); | 918 dprintf("{"); |
919 GetArgs(d); // (A,B,C)節が含まれることがある | 919 GetArgs(d); // (A,B,C)膀障 |
920 dprintf("}"); | 920 dprintf("}"); |
921 } else { | 921 } else { |
922 dprintf("{}"); | 922 dprintf("{}"); |
923 } | 923 } |
924 } else if (d[0] == 0x0a || d[0] == 0x40) { // よくわからない (Little Busters!) | 924 } else if (d[0] == 0x0a || d[0] == 0x40) { // (Little Busters!) |
925 int var; | 925 int var; |
926 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;} | 926 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;} |
927 else { var = read_little_endian_short(d+1); d += 3;} | 927 else { var = read_little_endian_short(d+1); d += 3;} |
928 dprintf("line %d; ",var); | 928 dprintf("line %d; ",var); |
929 } else if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0)) || *d == 0x28) { | 929 } else if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0)) || *d == 0x28) { |
933 var.type = TYPE_STR; | 933 var.type = TYPE_STR; |
934 var.value = GetString(d); | 934 var.value = GetString(d); |
935 args.push_back(var); | 935 args.push_back(var); |
936 } else SetError(); | 936 } else SetError(); |
937 if (*d == 0x29) break; | 937 if (*d == 0x29) break; |
938 if (*d == 0x2c) {d++;} // 次の arg が演算子で始まる、などがなければ存在しない | 938 if (*d == 0x2c) {d++;} // 罨< arg 羲膊絖у障医 |
939 dprintf(","); | 939 dprintf(","); |
940 } | 940 } |
941 if (*d == 0x29) d++; | 941 if (*d == 0x29) d++; |
942 else SetError(); | 942 else SetError(); |
943 return i; | 943 return i; |
944 } | 944 } |
945 | 945 |
946 int Cmd::GetArgsSpecial(int normal_args,const char*& d) { | 946 int Cmd::GetArgsSpecial(int normal_args,const char*& d) { |
947 if (*d != 0x28) return 0; /* 引数なし */ | 947 if (*d != 0x28) return 0; /* 綣違 */ |
948 d++; | 948 d++; |
949 dprintf("args:"); | 949 dprintf("args:"); |
950 int i; for (i=0; i<normal_args; i++) { | 950 int i; for (i=0; i<normal_args; i++) { |
951 /* number, variable, string の種別なく値を得る */ | 951 /* number, variable, string 腮ャゃ緇 */ |
952 if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0)) || *d == 0x28) { | 952 if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0)) || *d == 0x28) { |
953 GetExpression(d); | 953 GetExpression(d); |
954 } else if (StrType(d)) { | 954 } else if (StrType(d)) { |
955 GetString(d); | 955 GetString(d); |
956 } else SetError(); | 956 } else SetError(); |
957 if (*d == 0x29) break; | 957 if (*d == 0x29) break; |
958 if (*d == 0x2c) {d++;} // 次の arg が演算子で始まる、などがなければ存在しない | 958 if (*d == 0x2c) {d++;} // 罨< arg 羲膊絖у障医 |
959 dprintf(","); | 959 dprintf(","); |
960 } | 960 } |
961 for (i=0; i<argc ; i++) { | 961 for (i=0; i<argc ; i++) { |
962 if (*d == 0x28) { | 962 if (*d == 0x28) { |
963 /* | 963 /* |
964 ** cmd 01-22:0c1c, 01-22:0835 | 964 ** cmd 01-22:0c1c, 01-22:0835 |
965 ** Princess Bride のカードが落ちるアニメの場面 | 965 ** Princess Bride 若純<≪<顔 |
966 ** なお、_PBCARDANM* の画像はこのコマンドでのみ使われているので、特殊処理として無視することも可能 | 966 ** _PBCARDANM* 糸潟潟с推戎с号∴ |
967 ** | 967 ** |
968 ** cmd 01-04:0276, 026c, 0270 | 968 ** cmd 01-04:0276, 026c, 0270 |
969 ** 複数の enum が args の数だけ続く処理。特殊処理として分離する | 969 ** 茲違 enum args 違膓号≪ |
970 */ | 970 */ |
971 dprintf("enum.<"); | 971 dprintf("enum.<"); |
972 /* (...) は列挙型 or 構造体の可能性がある */ | 972 /* (...) or 罕篏醇с */ |
973 const char* d_orig = d; | 973 const char* d_orig = d; |
974 int pt = args.size(); args.push_back(VarInfo(0)); | 974 int pt = args.size(); args.push_back(VarInfo(0)); |
975 int count = GetArgs(d); | 975 int count = GetArgs(d); |
976 args[pt] = VarInfo(count); | 976 args[pt] = VarInfo(count); |
977 dprintf(">"); | 977 dprintf(">"); |
978 } else if (*d == 0x61 && (d[1] >= 0x00 && d[1] <= 0x04) && d[2] == 0x28 ) { | 978 } else if (*d == 0x61 && (d[1] >= 0x00 && d[1] <= 0x04) && d[2] == 0x28 ) { |
979 /* 使われるコマンドは 01-21:004b, 01-28:0064 のいずれか(R,C,PB,LO) | 979 /* 篏帥潟潟 01-21:004b, 01-28:0064 鐚R,C,PB,LO) |
980 ** それらのコマンドは | 980 ** 潟潟 |
981 ** arg1: 画像ファイル名 | 981 ** arg1: 糸<ゃ |
982 ** arg2 : Sel 番号 | 982 ** arg2 : Sel |
983 ** らしく、arg3 以降が 0x61 <00-04> (a,b,c,...) となる(ダンプ上は enum と表記される) | 983 ** arg3 篁ラ 0x61 <00-04> (a,b,c,...) 鐚潟筝 enum 茵荐) |
984 ** () 内の引数はさまざまで、a のみ(画像ファイル名)、 | 984 ** () 綣違障障сa 随糸<ゃ鐚 |
985 ** a,b b=SEL? | 985 ** a,b b=SEL? |
986 ** a,b,c (b,c)=座標? | 986 ** a,b,c (b,c)=綺ф鐚 |
987 ** a,(b,c,d,e,f,g) b-g = src / dest? | 987 ** a,(b,c,d,e,f,g) b-g = src / dest? |
988 ** らしい | 988 ** |
989 */ | 989 */ |
990 dprintf("kasane. #%d <",d[1]); | 990 dprintf("kasane. #%d <",d[1]); |
991 d += 2; | 991 d += 2; |
992 int pt = args.size(); args.push_back(VarInfo(0)); | 992 int pt = args.size(); args.push_back(VarInfo(0)); |
993 int count = GetArgs(d); | 993 int count = GetArgs(d); |
994 args[pt] = VarInfo(count); | 994 args[pt] = VarInfo(count); |
995 dprintf(">"); | 995 dprintf(">"); |
996 } else if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0))) { | 996 } else if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0))) { |
997 /* cmd 01-15:0028 ; 始めに 0x24 節があり、続いて 0x28 節になる */ | 997 /* cmd 01-15:0028 ; 紮 0x24 膀膓 0x28 膀 */ |
998 VarInfo var; | 998 VarInfo var; |
999 GetExpression(d, &var); | 999 GetExpression(d, &var); |
1000 args.push_back(var); | 1000 args.push_back(var); |
1001 i--; // この引数はargc の数には入らない | 1001 i--; // 綣違argc 違ャ |
1002 } else SetError(); | 1002 } else SetError(); |
1003 if (d[0] == 0x0a || d[0] == 0x40) { | 1003 if (d[0] == 0x0a || d[0] == 0x40) { |
1004 /* cmd 01-15:0028 ; 0x28 節の後に毎回 0x0a 節が来る */ | 1004 /* cmd 01-15:0028 ; 0x28 膀緇罸 0x0a 膀ャ */ |
1005 int var; | 1005 int var; |
1006 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;} | 1006 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;} |
1007 else { var = read_little_endian_short(d+1); d += 3;} | 1007 else { var = read_little_endian_short(d+1); d += 3;} |
1008 dprintf("line %d; ",var); | 1008 dprintf("line %d; ",var); |
1009 } | 1009 } |
1010 if (*d == 0x29) break; | 1010 if (*d == 0x29) break; |
1011 if (*d == 0x2c) {d++;} // 次の arg が演算子で始まる、などがなければ存在しない | 1011 if (*d == 0x2c) {d++;} // 罨< arg 羲膊絖у障医 |
1012 dprintf(","); | 1012 dprintf(","); |
1013 } | 1013 } |
1014 if (*d == 0x29) d++; | 1014 if (*d == 0x29) d++; |
1015 else SetError(); | 1015 else SetError(); |
1016 return 0; | 1016 return 0; |
1122 int var; | 1122 int var; |
1123 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;} | 1123 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;} |
1124 else { var = read_little_endian_short(d+1); d += 3;} | 1124 else { var = read_little_endian_short(d+1); d += 3;} |
1125 dprintf("Line %d; ",var); | 1125 dprintf("Line %d; ",var); |
1126 if (text.length() != 0) { | 1126 if (text.length() != 0) { |
1127 if (cond_result) ; // 条件節が true なら表示しない | 1127 if (cond_result) ; // >散膀 true 茵腓冴 |
1128 else { | 1128 else { |
1129 const char* str = text.c_str(); | 1129 const char* str = text.c_str(); |
1130 VarInfo var; | 1130 VarInfo var; |
1131 var.type = TYPE_STR; | 1131 var.type = TYPE_STR; |
1132 var.value = CopyString(str); | 1132 var.value = CopyString(str); |
1143 dprintf(":comma:"); | 1143 dprintf(":comma:"); |
1144 } else if (d[0] == 0x28) { | 1144 } else if (d[0] == 0x28) { |
1145 dprintf(":cond:"); | 1145 dprintf(":cond:"); |
1146 d++; | 1146 d++; |
1147 while(d[0] != 0x29) { | 1147 while(d[0] != 0x29) { |
1148 int result = GetExpressionCond(d); // PRINT- 節でないばあい、条件表示。次は文字節、またはPRINT節のはず | 1148 int result = GetExpressionCond(d); // PRINT- 膀с違>散茵腓冴罨<絖膀障PRINT膀 |
1149 if (*d == 0x32) { // 0x32 なら、現在の条件節を表示しない | 1149 if (*d == 0x32) { // 0x32 憜>散膀茵腓冴 |
1150 d++; dprintf("##"); | 1150 d++; dprintf("##"); |
1151 cond_result = result; | 1151 cond_result = result; |
1152 } else if (*d == 0x31) { // 0x31 なら、現在の条件節を表示する | 1152 } else if (*d == 0x31) { // 0x31 憜>散膀茵腓冴 |
1153 // Little Busters! : この条件で正しいかは未検証 | 1153 // Little Busters! : >散фc罎荐 |
1154 d++; dprintf("***"); | 1154 d++; dprintf("***"); |
1155 cond_result = !result; | 1155 cond_result = !result; |
1156 } | 1156 } |
1157 dprintf(":"); | 1157 dprintf(":"); |
1158 } | 1158 } |
1163 arg_count++; | 1163 arg_count++; |
1164 dprintf("\n\t"); | 1164 dprintf("\n\t"); |
1165 } else if (*d == 0x23 && strncmp(d,"###PRINT",8) == 0) { | 1165 } else if (*d == 0x23 && strncmp(d,"###PRINT",8) == 0) { |
1166 d += 8; | 1166 d += 8; |
1167 if (d[0] != 0x28) SetError(); | 1167 if (d[0] != 0x28) SetError(); |
1168 else { // 文字変数の内容の表示 | 1168 else { // 絖紊違絎鴻茵腓 |
1169 d++; | 1169 d++; |
1170 dprintf("Print."); | 1170 dprintf("Print."); |
1171 VarInfo info; | 1171 VarInfo info; |
1172 GetLeftToken(d, info); | 1172 GetLeftToken(d, info); |
1173 if (d[0] != 0x29 || info.type == -1) SetError(); | 1173 if (d[0] != 0x29 || info.type == -1) SetError(); |
1174 d++; | 1174 d++; |
1175 dprintf(";");/* | 1175 dprintf(";");/* |
1176 // 数値を全角文字に変換して登録 | 1176 // 医ゃ茹絖紊脂 |
1177 char str[10], str2[20]; // itoa | 1177 char str[10], str2[20]; // itoa |
1178 sprintf(str, "%d", info.value); | 1178 sprintf(str, "%d", info.value); |
1179 int i; for (i=0; str[i] != 0; i++) { | 1179 int i; for (i=0; str[i] != 0; i++) { |
1180 str2[i*2] = 0xa3; | 1180 str2[i*2] = 0xa3; |
1181 str2[i*2+1] = 0xb0 + str[i]-'0'; | 1181 str2[i*2+1] = 0xb0 + str[i]-'0'; |
1185 } | 1185 } |
1186 } else { SetError(); break;} | 1186 } else { SetError(); break;} |
1187 } | 1187 } |
1188 d++; | 1188 d++; |
1189 /* @@@ */ | 1189 /* @@@ */ |
1190 /* 一致しない場合があるのでコメントアウト */ | 1190 /* 筝眼翫с潟<潟≪ */ |
1191 // if (arg_count != argc) SetError(); | 1191 // if (arg_count != argc) SetError(); |
1192 dprintf("\n}\n"); | 1192 dprintf("\n}\n"); |
1193 } | 1193 } |
1194 | 1194 |
1195 void Cmd::GetCmd(Flags& flags_orig, const char*& d ) { | 1195 void Cmd::GetCmd(Flags& flags_orig, const char*& d ) { |
1196 if (d == NULL) { SetError(); return;} | 1196 if (d == NULL) { SetError(); return;} |
1197 if (cmd_type != CMD_NOP) return; | 1197 if (cmd_type != CMD_NOP) return; |
1198 | 1198 |
1199 cmdstr[0] = 0; | 1199 cmdstr[0] = 0; |
1200 rawdata = d; | 1200 rawdata = d; |
1201 if (*d == 0x23) { /* コマンド */ | 1201 if (*d == 0x23) { /* 潟潟 */ |
1202 cmd_type = CMD_OTHER; | 1202 cmd_type = CMD_OTHER; |
1203 cmd1 = *(unsigned const char*)(d+1); | 1203 cmd1 = *(unsigned const char*)(d+1); |
1204 cmd2 = *(unsigned const char*)(d+2); | 1204 cmd2 = *(unsigned const char*)(d+2); |
1205 cmd3 = read_little_endian_short(d+3); | 1205 cmd3 = read_little_endian_short(d+3); |
1206 argc = read_little_endian_short(d+5); | 1206 argc = read_little_endian_short(d+5); |
1207 cmd4 = *(unsigned const char*)(d+7); | 1207 cmd4 = *(unsigned const char*)(d+7); |
1208 d += 8; | 1208 d += 8; |
1209 /* verbose */ | 1209 /* verbose */ |
1210 // dprintf(" 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n",cmd1,cmd2,cmd3,cmd4,argc); | 1210 // dprintf(" 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n",cmd1,cmd2,cmd3,cmd4,argc); |
1211 sprintf(cmdstr, "%02x-%02x:%04x:%02x : %s",cmd1,cmd2,cmd3,cmd4, CmdDescr(cmd1,cmd2,cmd3,cmd4)); | 1211 sprintf(cmdstr, "%02x-%02x:%04x:%02x : %s",cmd1,cmd2,cmd3,cmd4, CmdDescr(cmd1,cmd2,cmd3,cmd4)); |
1212 /* 引数を得る */ | 1212 /* 綣違緇 */ |
1213 /* 特殊引数のもの */ | 1213 /* 号綣違 */ |
1214 int is_special = 0; | 1214 int is_special = 0; |
1215 if (cmd1 == 0) { | 1215 if (cmd1 == 0) { |
1216 if (cmd2 == 1) { | 1216 if (cmd2 == 1) { |
1217 int jump_arg = -1; | 1217 int jump_arg = -1; |
1218 if (cmd3 == 0 || cmd3 == 5) { | 1218 if (cmd3 == 0 || cmd3 == 5) { |
1227 } else if (cmd3 == 1 || cmd3 == 2) { | 1227 } else if (cmd3 == 1 || cmd3 == 2) { |
1228 /* conditional jump (if / unless) */ | 1228 /* conditional jump (if / unless) */ |
1229 if (*d++ != 0x28) { SetError(); return;} | 1229 if (*d++ != 0x28) { SetError(); return;} |
1230 dprintf("\t"); | 1230 dprintf("\t"); |
1231 int cond = GetExpressionCond(d); | 1231 int cond = GetExpressionCond(d); |
1232 if (cmd3 == 1) cond = !cond; // 逆になる | 1232 if (cmd3 == 1) cond = !cond; // |
1233 if (*d++ != 0x29) { SetError(); return; } | 1233 if (*d++ != 0x29) { SetError(); return; } |
1234 int jumpto = read_little_endian_int(d); | 1234 int jumpto = read_little_endian_int(d); |
1235 d += 4; | 1235 d += 4; |
1236 dprintf("-> %d\n", jumpto); | 1236 dprintf("-> %d\n", jumpto); |
1237 if (! cond) jump_arg = jumpto; /* condition が満たされない場合、ジャンプ */ | 1237 if (! cond) jump_arg = jumpto; /* condition 羣翫吾c潟 */ |
1238 is_special = 1; | 1238 is_special = 1; |
1239 } else if (cmd3 == 4) { | 1239 } else if (cmd3 == 4) { |
1240 /* switch to */ | 1240 /* switch to */ |
1241 jump_arg = GetSwitch(d); | 1241 jump_arg = GetSwitch(d); |
1242 is_special = 1; | 1242 is_special = 1; |
1262 GetSelection(d); | 1262 GetSelection(d); |
1263 is_special = 1; | 1263 is_special = 1; |
1264 } | 1264 } |
1265 } | 1265 } |
1266 retry: | 1266 retry: |
1267 /* 一般引数のもの */ | 1267 /* 筝綣違 */ |
1268 if (!is_special) { | 1268 if (!is_special) { |
1269 dprintf(" 0x23 - cmd %02x-%02x:%04x:%02x[%2d] : %s\n",cmd1,cmd2,cmd3,cmd4,argc,CmdDescr(cmd1,cmd2,cmd3,cmd4)); | 1269 dprintf(" 0x23 - cmd %02x-%02x:%04x:%02x[%2d] : %s\n",cmd1,cmd2,cmd3,cmd4,argc,CmdDescr(cmd1,cmd2,cmd3,cmd4)); |
1270 dprintf("\t"); | 1270 dprintf("\t"); |
1271 if (cmd1 == 1 && cmd2 == 0x22 && (cmd3 == 0xc1c || cmd3 == 0x835)) GetArgsSpecial(3, d); | 1271 if (cmd1 == 1 && cmd2 == 0x22 && (cmd3 == 0xc1c || cmd3 == 0x835)) GetArgsSpecial(3, d); |
1272 else if (cmd1 == 1 && cmd2 == 0x0b && cmd3 == 0x65) GetArgsSpecial(0, d); | 1272 else if (cmd1 == 1 && cmd2 == 0x0b && cmd3 == 0x65) GetArgsSpecial(0, d); |
1276 else if (cmd1 == 1 && ((cmd2 == 0x21 && cmd3 == 0x4b) || (cmd2 == 0x28 && cmd3 == 0x64))) GetArgsSpecial(2,d); | 1276 else if (cmd1 == 1 && ((cmd2 == 0x21 && cmd3 == 0x4b) || (cmd2 == 0x28 && cmd3 == 0x64))) GetArgsSpecial(2,d); |
1277 else GetArgs(d); | 1277 else GetArgs(d); |
1278 dprintf("\n"); | 1278 dprintf("\n"); |
1279 | 1279 |
1280 } | 1280 } |
1281 } else if (*d == 0x24) { /* 代入演算 */ | 1281 } else if (*d == 0x24) { /* 篁eユ膊 */ |
1282 if (d[1] == 0x12 || d[2] != 0x5b) SetError(); | 1282 if (d[1] == 0x12 || d[2] != 0x5b) SetError(); |
1283 dprintf("expr: "); | 1283 dprintf("expr: "); |
1284 sprintf(cmdstr, "expr"); | 1284 sprintf(cmdstr, "expr"); |
1285 | 1285 |
1286 VarInfo info; | 1286 VarInfo info; |
1289 int type = d[1]; | 1289 int type = d[1]; |
1290 if (type < 20 || type > 30) SetError(); | 1290 if (type < 20 || type > 30) SetError(); |
1291 else dprintf("%s",op_str[type]); | 1291 else dprintf("%s",op_str[type]); |
1292 d += 2; | 1292 d += 2; |
1293 int value2 = GetExpression(d); | 1293 int value2 = GetExpression(d); |
1294 // 代入情報を埋め込む | 1294 // 篁eユ宴莨若 |
1295 if (type != 30) value2 = eval(value, type-20, value2); | 1295 if (type != 30) value2 = eval(value, type-20, value2); |
1296 cmd_type = CMD_FLAGS; | 1296 cmd_type = CMD_FLAGS; |
1297 args.push_back(info); | 1297 args.push_back(info); |
1298 args.push_back(value2); | 1298 args.push_back(value2); |
1299 dprintf("\n"); | 1299 dprintf("\n"); |
1300 } else if (StrType(d)) { /* 文字出力 */ | 1300 } else if (StrType(d)) { /* 絖阪 */ |
1301 VarInfo info; | 1301 VarInfo info; |
1302 info.type = TYPE_STR; | 1302 info.type = TYPE_STR; |
1303 info.value = GetString(d); | 1303 info.value = GetString(d); |
1304 args.push_back(info); | 1304 args.push_back(info); |
1305 cmd_type = CMD_TEXT; | 1305 cmd_type = CMD_TEXT; |
1306 dprintf("\n"); | 1306 dprintf("\n"); |
1307 } else if (*d == 0x0a || *d == 0x40 || *d == 0x21) { /* デバッグ用データと既読フラグ */ | 1307 } else if (*d == 0x0a || *d == 0x40 || *d == 0x21) { /* 亥若帥∵ */ |
1308 cmd_type = CMD_NOP; | 1308 cmd_type = CMD_NOP; |
1309 if (*d == 0x0a) { | 1309 if (*d == 0x0a) { |
1310 dprintf("line "); | 1310 dprintf("line "); |
1311 d++; | 1311 d++; |
1312 int l; | 1312 int l; |
1317 l = read_little_endian_short(d); | 1317 l = read_little_endian_short(d); |
1318 d += 2; | 1318 d += 2; |
1319 } | 1319 } |
1320 dprintf("%d\n", l); | 1320 dprintf("%d\n", l); |
1321 } else { /* 0x40, 0x21 */ | 1321 } else { /* 0x40, 0x21 */ |
1322 // 既読マーカーらしい。エントリーポイントとセーブポイントも使われる。 | 1322 // ∵若若潟若ゃ潟祉若ゃ潟篏帥 |
1323 // RealLive 1.2.5から、0x40はセーブポイント、0x21はエントリーポイント。 | 1323 // RealLive 1.2.50x40祉若ゃ潟0x21潟若ゃ潟 |
1324 // 1.2.5以前、どちらも0x40が使われる。 | 1324 // 1.2.5篁ュ<0x40篏帥 |
1325 int kidoku_index; | 1325 int kidoku_index; |
1326 d++; | 1326 d++; |
1327 if (system_version == 0) { | 1327 if (system_version == 0) { |
1328 kidoku_index = read_little_endian_int(d); | 1328 kidoku_index = read_little_endian_int(d); |
1329 d += 4; | 1329 d += 4; |
1330 } else { | 1330 } else { |
1331 kidoku_index = read_little_endian_short(d); | 1331 kidoku_index = read_little_endian_short(d); |
1332 d += 2; | 1332 d += 2; |
1333 } | 1333 } |
1334 dprintf("kidoku marker %d\n", kidoku_index); | 1334 dprintf("kidoku marker %d\n", kidoku_index); |
1335 // text_readflagは、このkidoku_indexを使ったら良いかな。 | 1335 // text_readflagkidoku_index篏帥c |
1336 } | 1336 } |
1337 } else if (*d == 0x2c) { /* ??? */ | 1337 } else if (*d == 0x2c) { /* ??? */ |
1338 dprintf("commd;0x2c\n"); // conditional jump の行き先によくあるらしい(常に、かはわからない) | 1338 dprintf("commd;0x2c\n"); // conditional jump 茵鐚絽吾鐚 |
1339 d++; | 1339 d++; |
1340 } else { | 1340 } else { |
1341 SetError(); | 1341 SetError(); |
1342 } | 1342 } |
1343 } | 1343 } |
1454 if (pt < 0 || pt >= STRHEAP_SIZE) return ""; | 1454 if (pt < 0 || pt >= STRHEAP_SIZE) return ""; |
1455 return strheap + pt; | 1455 return strheap + pt; |
1456 } | 1456 } |
1457 | 1457 |
1458 int Cmd::AddStr(char* s) { | 1458 int Cmd::AddStr(char* s) { |
1459 // 1-0a-0064 はこういうものが必要らしい | 1459 // 1-0a-0064 綽荀 |
1460 int start = strend; | 1460 int start = strend; |
1461 while (*s) strheap[strend++] = *s++; | 1461 while (*s) strheap[strend++] = *s++; |
1462 strheap[strend++] = 0; | 1462 strheap[strend++] = 0; |
1463 return start; | 1463 return start; |
1464 } | 1464 } |
1472 cmd1 = from.cmd1; | 1472 cmd1 = from.cmd1; |
1473 cmd2 = from.cmd2; | 1473 cmd2 = from.cmd2; |
1474 cmd3 = from.cmd3; | 1474 cmd3 = from.cmd3; |
1475 cmd4 = from.cmd4; | 1475 cmd4 = from.cmd4; |
1476 argc = from.argc; | 1476 argc = from.argc; |
1477 /* args の読み込み */ | 1477 /* args 茯粋昭 */ |
1478 args.clear(); | 1478 args.clear(); |
1479 char* d = from.args; | 1479 char* d = from.args; |
1480 if (d == NULL) return; | 1480 if (d == NULL) return; |
1481 while(*d != TYPE_END) { | 1481 while(*d != TYPE_END) { |
1482 VarInfo info; | 1482 VarInfo info; |
1515 to.cmd1 = cmd1; | 1515 to.cmd1 = cmd1; |
1516 to.cmd2 = cmd2; | 1516 to.cmd2 = cmd2; |
1517 to.cmd3 = cmd3; | 1517 to.cmd3 = cmd3; |
1518 to.cmd4 = cmd4; | 1518 to.cmd4 = cmd4; |
1519 to.argc = argc; | 1519 to.argc = argc; |
1520 /* args の書き込み */ | 1520 /* args 吾莨若 */ |
1521 if (args.empty()) { | 1521 if (args.empty()) { |
1522 to.args = NULL; | 1522 to.args = NULL; |
1523 } else { | 1523 } else { |
1524 to.args = buffer; | 1524 to.args = buffer; |
1525 char* d = to.args; | 1525 char* d = to.args; |
1547 | 1547 |
1548 void CmdSimplified::copy(const CmdSimplified& from, char*& args_buffer) { | 1548 void CmdSimplified::copy(const CmdSimplified& from, char*& args_buffer) { |
1549 *this = from; | 1549 *this = from; |
1550 if (args == NULL) return; | 1550 if (args == NULL) return; |
1551 char* args_old = from.args; | 1551 char* args_old = from.args; |
1552 /* args のコピー */ | 1552 /* args 潟 */ |
1553 while(*args_old != TYPE_END) { | 1553 while(*args_old != TYPE_END) { |
1554 if (*args_old == TYPE_VAL) { | 1554 if (*args_old == TYPE_VAL) { |
1555 args_old += 5; | 1555 args_old += 5; |
1556 } else { /* TYPE_STR */ | 1556 } else { /* TYPE_STR */ |
1557 args_old += strlen(args_old)+1; | 1557 args_old += strlen(args_old)+1; |
1567 void CmdSimplified::Save(string& saveret) { | 1567 void CmdSimplified::Save(string& saveret) { |
1568 char buf[1024]; | 1568 char buf[1024]; |
1569 sprintf(buf, "%02x-%02x:%04x:%02x(%02d),", cmd1, cmd2, cmd3, cmd4, argc); | 1569 sprintf(buf, "%02x-%02x:%04x:%02x(%02d),", cmd1, cmd2, cmd3, cmd4, argc); |
1570 saveret += buf; | 1570 saveret += buf; |
1571 | 1571 |
1572 /* args のコピー */ | 1572 /* args 潟 */ |
1573 char* d = args; | 1573 char* d = args; |
1574 while(d && *d != TYPE_END) { | 1574 while(d && *d != TYPE_END) { |
1575 if (*d == TYPE_VAL) { | 1575 if (*d == TYPE_VAL) { |
1576 d++; | 1576 d++; |
1577 sprintf(buf, "%d,", read_little_endian_int(d)); | 1577 sprintf(buf, "%d,", read_little_endian_int(d)); |
1578 d += 4; | 1578 d += 4; |
1579 } else { /* TYPE_STR と仮定 */ | 1579 } else { /* TYPE_STR 篁絎 */ |
1580 d++; | 1580 d++; |
1581 if (strlen(d) > 1000) d[1000] = 0; // ありえない・・・ | 1581 if (strlen(d) > 1000) d[1000] = 0; // 祉祉 |
1582 int i; int cnt = 0; | 1582 int i; int cnt = 0; |
1583 buf[cnt++] = '"'; | 1583 buf[cnt++] = '"'; |
1584 for (i=0; d[i] != 0; i++) { | 1584 for (i=0; d[i] != 0; i++) { |
1585 if (d[i] == '"') buf[cnt++] = '"'; | 1585 if (d[i] == '"') buf[cnt++] = '"'; |
1586 buf[cnt++] = d[i]; | 1586 buf[cnt++] = d[i]; |
1679 ARCINFO* info = archive.Find(fname,""); | 1679 ARCINFO* info = archive.Find(fname,""); |
1680 if (info == NULL) continue; | 1680 if (info == NULL) continue; |
1681 char* data = info->CopyRead(); | 1681 char* data = info->CopyRead(); |
1682 char* d = data; | 1682 char* d = data; |
1683 char* dend = d + info->Size(); | 1683 char* dend = d + info->Size(); |
1684 /* version 確認 */ | 1684 /* version 腆肴 */ |
1685 if (read_little_endian_int(d) == 0x1cc) { | 1685 if (read_little_endian_int(d) == 0x1cc) { |
1686 system_version = 0; | 1686 system_version = 0; |
1687 } else if (read_little_endian_int(d) == 0x1d0) { | 1687 } else if (read_little_endian_int(d) == 0x1d0) { |
1688 system_version = 1; | 1688 system_version = 1; |
1689 } else { | 1689 } else { |
1701 | 1701 |
1702 const char* dcur = d; | 1702 const char* dcur = d; |
1703 const char* dstart = d; | 1703 const char* dstart = d; |
1704 fprintf(stderr,"Dumping %s\n",fname); | 1704 fprintf(stderr,"Dumping %s\n",fname); |
1705 Flags flags; | 1705 Flags flags; |
1706 /* 最初から最後までコマンド取得 -> 出力を繰り返す */ | 1706 /* 緇障с潟潟緇 -> 阪膵違菴 */ |
1707 while(dcur<dend) { | 1707 while(dcur<dend) { |
1708 const char* dprev = dcur; | 1708 const char* dprev = dcur; |
1709 Cmd cmd(flags, system_version); cmd.ClearError(); | 1709 Cmd cmd(flags, system_version); cmd.ClearError(); |
1710 | 1710 |
1711 /* end? */ | 1711 /* end? */ |