diff -ur --exclude=CVS --exclude=Makefile ScummVM/gob/parse.cpp ScummVM+hack/gob/parse.cpp
old
|
new
|
|
21 | 21 | */ |
22 | 22 | #include "gob/gob.h" |
23 | 23 | #include "gob/global.h" |
| 24 | #include "gob/game.h" |
24 | 25 | #include "gob/parse.h" |
25 | 26 | #include "gob/util.h" |
26 | 27 | #include "gob/inter.h" |
27 | 28 | |
28 | 29 | namespace Gob { |
29 | 30 | |
| 31 | enum PointerType { |
| 32 | kExecPtr = 0, |
| 33 | kInterVar = 1, |
| 34 | kResStr = 2 |
| 35 | }; |
| 36 | |
| 37 | int32 encodePtr(char *ptr, int type) { |
| 38 | int32 offset; |
| 39 | |
| 40 | switch (type) { |
| 41 | case kExecPtr: |
| 42 | offset = ptr - game_totFileData; |
| 43 | break; |
| 44 | case kInterVar: |
| 45 | offset = ptr - inter_variables; |
| 46 | break; |
| 47 | case kResStr: |
| 48 | offset = ptr - inter_resStr; |
| 49 | break; |
| 50 | default: |
| 51 | error("encodePtr: Unknown pointer type"); |
| 52 | } |
| 53 | return (type << 28) | offset; |
| 54 | } |
| 55 | |
| 56 | char *decodePtr(int32 n) { |
| 57 | char *ptr; |
30 | 58 | |
| 59 | switch (n >> 28) { |
| 60 | case kExecPtr: |
| 61 | ptr = game_totFileData; |
| 62 | break; |
| 63 | case kInterVar: |
| 64 | ptr = inter_variables; |
| 65 | break; |
| 66 | case kResStr: |
| 67 | ptr = inter_resStr; |
| 68 | break; |
| 69 | default: |
| 70 | error("decodePtr: Unknown pointer type"); |
| 71 | } |
| 72 | return ptr + (n & 0x0FFFFFFF); |
| 73 | } |
31 | 74 | |
32 | 75 | int16 parse_parseExpr(char arg_0, byte *arg_2) { |
33 | 76 | int32 values[20]; |
… |
… |
|
73 | 116 | |
74 | 117 | case 22: |
75 | 118 | *operPtr = 22; |
76 | | *valPtr = (int32)inter_execPtr; |
| 119 | *valPtr = encodePtr(inter_execPtr, kExecPtr); |
77 | 120 | inter_execPtr += strlen(inter_execPtr) + 1; |
78 | 121 | break; |
79 | 122 | |
… |
… |
|
85 | 128 | case 25: |
86 | 129 | *operPtr = 22; |
87 | 130 | temp = inter_load16() * 4; |
88 | | *valPtr = (int32)(inter_variables + temp); |
| 131 | *valPtr = encodePtr(inter_variables + temp, kInterVar); |
89 | 132 | if (*inter_execPtr == 13) { |
90 | 133 | inter_execPtr++; |
91 | 134 | temp += parse_parseValExpr(); |
… |
… |
|
113 | 156 | *valPtr = VAR(temp + offset); |
114 | 157 | break; |
115 | 158 | } |
116 | | *valPtr = (int32)(inter_variables + temp * 4 + offset * inter_animDataSize * 4); |
| 159 | *valPtr = encodePtr(inter_variables + temp * 4 + offset * inter_animDataSize * 4, kInterVar); |
117 | 160 | if (*inter_execPtr == 13) { |
118 | 161 | inter_execPtr++; |
119 | 162 | temp2 = parse_parseValExpr(); |
… |
… |
|
181 | 224 | switch (operPtr[-1]) { |
182 | 225 | case 2: |
183 | 226 | if (operPtr[-2] == 22) { |
184 | | if ((char *)valPtr[-2] != inter_resStr) { |
185 | | strcpy(inter_resStr, (char *)valPtr[-2]); |
186 | | valPtr[-2] = (int32)inter_resStr; |
| 227 | if (decodePtr(valPtr[-2]) != inter_resStr) { |
| 228 | strcpy(inter_resStr, decodePtr(valPtr[-2])); |
| 229 | valPtr[-2] = encodePtr(inter_resStr, kResStr); |
187 | 230 | } |
188 | | strcat(inter_resStr, (char *)valPtr[0]); |
| 231 | strcat(inter_resStr, decodePtr(valPtr[0])); |
189 | 232 | stkPos -= 2; |
190 | 233 | operPtr -= 2; |
191 | 234 | valPtr -= 2; |
… |
… |
|
301 | 344 | if (operStack[brackStart] == 20) { |
302 | 345 | values[brackStart] += valPtr[-1]; |
303 | 346 | } else if (operStack[brackStart] == 22) { |
304 | | if ((char *)values[brackStart] |
305 | | != inter_resStr) { |
306 | | strcpy(inter_resStr, (char *)values[brackStart]); |
307 | | values[brackStart] = (int32)inter_resStr; |
| 347 | if (decodePtr(values[brackStart]) != inter_resStr) { |
| 348 | strcpy(inter_resStr, decodePtr(values[brackStart])); |
| 349 | values[brackStart] = encodePtr(inter_resStr, kResStr); |
308 | 350 | } |
309 | | strcat(inter_resStr, (char *)valPtr[-1]); |
| 351 | strcat(inter_resStr, decodePtr(valPtr[-1])); |
310 | 352 | } |
311 | 353 | stkPos -= 2; |
312 | 354 | operPtr -= 2; |
… |
… |
|
378 | 420 | if (valPtr[-3] < valPtr[-1]) |
379 | 421 | operPtr[-3] = 24; |
380 | 422 | } else if (var_C == 22) { |
381 | | if ((char *)valPtr[-3] != inter_resStr) { |
382 | | strcpy(inter_resStr, (char *)valPtr[-3]); |
383 | | valPtr[-3] = (int32)inter_resStr; |
| 423 | if (decodePtr(valPtr[-3]) != inter_resStr) { |
| 424 | strcpy(inter_resStr, decodePtr(valPtr[-3])); |
| 425 | valPtr[-3] = encodePtr(inter_resStr, kResStr); |
384 | 426 | } |
385 | | if (strcmp(inter_resStr, (char *)valPtr[-1]) < 0) |
| 427 | if (strcmp(inter_resStr, decodePtr(valPtr[-1])) < 0) |
386 | 428 | operPtr[-3] = 24; |
387 | 429 | } |
388 | 430 | stkPos -= 2; |
… |
… |
|
397 | 439 | if (valPtr[-3] <= valPtr[-1]) |
398 | 440 | operPtr[-3] = 24; |
399 | 441 | } else if (var_C == 22) { |
400 | | if ((char *)valPtr[-3] != inter_resStr) { |
401 | | strcpy(inter_resStr, (char *)valPtr[-3]); |
402 | | valPtr[-3] = (int32)inter_resStr; |
| 442 | if (decodePtr(valPtr[-3]) != inter_resStr) { |
| 443 | strcpy(inter_resStr, decodePtr(valPtr[-3])); |
| 444 | valPtr[-3] = encodePtr(inter_resStr, kResStr); |
403 | 445 | } |
404 | | if (strcmp(inter_resStr, (char *)valPtr[-1]) <= 0) |
| 446 | if (strcmp(inter_resStr, decodePtr(valPtr[-1])) <= 0) |
405 | 447 | operPtr[-3] = 24; |
406 | 448 | } |
407 | 449 | stkPos -= 2; |
… |
… |
|
416 | 458 | if (valPtr[-3] > valPtr[-1]) |
417 | 459 | operPtr[-3] = 24; |
418 | 460 | } else if (var_C == 22) { |
419 | | if ((char *)valPtr[-3] != inter_resStr) { |
420 | | strcpy(inter_resStr, (char *)valPtr[-3]); |
421 | | valPtr[-3] = (int32)inter_resStr; |
| 461 | if (decodePtr(valPtr[-3]) != inter_resStr) { |
| 462 | strcpy(inter_resStr, decodePtr(valPtr[-3])); |
| 463 | valPtr[-3] = encodePtr(inter_resStr, kResStr); |
422 | 464 | } |
423 | | if (strcmp(inter_resStr, (char *)valPtr[-1]) > 0) |
| 465 | if (strcmp(inter_resStr, decodePtr(valPtr[-1])) > 0) |
424 | 466 | operPtr[-3] = 24; |
425 | 467 | } |
426 | 468 | stkPos -= 2; |
… |
… |
|
435 | 477 | if (valPtr[-3] >= valPtr[-1]) |
436 | 478 | operPtr[-3] = 24; |
437 | 479 | } else if (var_C == 22) { |
438 | | if ((char *)valPtr[-3] != inter_resStr) { |
439 | | strcpy(inter_resStr, (char *)valPtr[-3]); |
440 | | valPtr[-3] = (int32)inter_resStr; |
| 480 | if (decodePtr(valPtr[-3]) != inter_resStr) { |
| 481 | strcpy(inter_resStr, decodePtr(valPtr[-3])); |
| 482 | valPtr[-3] = encodePtr(inter_resStr, kResStr); |
441 | 483 | } |
442 | | if (strcmp(inter_resStr, (char *)valPtr[-1]) >= 0) |
| 484 | if (strcmp(inter_resStr, decodePtr(valPtr[-1])) >= 0) |
443 | 485 | operPtr[-3] = 24; |
444 | 486 | } |
445 | 487 | stkPos -= 2; |
… |
… |
|
454 | 496 | if (valPtr[-3] == valPtr[-1]) |
455 | 497 | operPtr[-3] = 24; |
456 | 498 | } else if (var_C == 22) { |
457 | | if ((char *)valPtr[-3] != inter_resStr) { |
458 | | strcpy(inter_resStr, (char *)valPtr[-3]); |
459 | | valPtr[-3] = (int32)inter_resStr; |
| 499 | if (decodePtr(valPtr[-3]) != inter_resStr) { |
| 500 | strcpy(inter_resStr, decodePtr(valPtr[-3])); |
| 501 | valPtr[-3] = encodePtr(inter_resStr, kResStr); |
460 | 502 | } |
461 | | if (strcmp(inter_resStr, (char *)valPtr[-1]) == 0) |
| 503 | if (strcmp(inter_resStr, decodePtr(valPtr[-1])) == 0) |
462 | 504 | operPtr[-3] = 24; |
463 | 505 | } |
464 | 506 | stkPos -= 2; |
… |
… |
|
473 | 515 | if (valPtr[-3] != valPtr[-1]) |
474 | 516 | operPtr[-3] = 24; |
475 | 517 | } else if (var_C == 22) { |
476 | | if ((char *)valPtr[-3] != inter_resStr) { |
477 | | strcpy(inter_resStr, (char *)valPtr[-3]); |
478 | | valPtr[-3] = (int32)inter_resStr; |
| 518 | if (decodePtr(valPtr[-3]) != inter_resStr) { |
| 519 | strcpy(inter_resStr, decodePtr(valPtr[-3])); |
| 520 | valPtr[-3] = encodePtr(inter_resStr, kResStr); |
479 | 521 | } |
480 | | if (strcmp(inter_resStr, (char *)valPtr[-1]) != 0) |
| 522 | if (strcmp(inter_resStr, decodePtr(valPtr[-1])) != 0) |
481 | 523 | operPtr[-3] = 24; |
482 | 524 | } |
483 | 525 | stkPos -= 2; |
… |
… |
|
544 | 586 | break; |
545 | 587 | |
546 | 588 | case 22: |
547 | | if ((char *)values[0] != inter_resStr) |
548 | | strcpy(inter_resStr, |
549 | | (char *)values[0]); |
| 589 | if (decodePtr(values[0]) != inter_resStr) |
| 590 | strcpy(inter_resStr, decodePtr(values[0])); |
550 | 591 | break; |
551 | 592 | |
552 | 593 | case 11: |
… |
… |
|
576 | 617 | if (operPtr[-3] == 20) { |
577 | 618 | valPtr[-3] += valPtr[-1]; |
578 | 619 | } else if (operPtr[-3] == 22) { |
579 | | if ((char *)valPtr[-3] != inter_resStr) { |
580 | | strcpy(inter_resStr, (char *)valPtr[-3]); |
581 | | valPtr[-3] = (int32)inter_resStr; |
| 620 | if (decodePtr(valPtr[-3]) != inter_resStr) { |
| 621 | strcpy(inter_resStr, decodePtr(valPtr[-3])); |
| 622 | valPtr[-3] = encodePtr(inter_resStr, kResStr); |
582 | 623 | } |
583 | | strcat(inter_resStr, (char *)valPtr[-1]); |
| 624 | strcat(inter_resStr, decodePtr(valPtr[-1])); |
584 | 625 | } |
585 | 626 | stkPos -= 2; |
586 | 627 | operPtr -= 2; |