2464 | | // TODO - correctly implement this function (see also bug #558245) |
2465 | | // |
2466 | | // There are two known places (both in FOA) where this function is being |
2467 | | // called. The fist is during the FOA extro, to change the color to match |
2468 | | // the sinking sun. The following three calls (with some pauses between them) |
2469 | | // are issued: |
2470 | | // |
2471 | | // palManipulateInit(16, 190, 32, 180, 1) |
2472 | | // palManipulateInit(16, 190, 32, 1, 1) |
2473 | | // palManipulateInit(16, 190, 32, 800, 1) |
2474 | | // |
2475 | | // The second place is in the Inner Sanctum after you used the stone discs, |
2476 | | // here it is used to give the scene a "lava glow". |
2477 | | // |
2478 | | // palManipulateInit(32, 65, 46, 20, 1): not implemented! |
2479 | | // |
2480 | | // The first two parameters seem to specify a palette range (as the colors |
2481 | | // from 16 to 190 are the ones that make up water & sky). |
2482 | | // |
2483 | | // Maybe the change has to be done over a period of time, possibly specified |
2484 | | // by the second last parameter - between call 1 and 2, about 17-18 seconds |
2485 | | // seem to pass (well using get_msecs, I measured 17155 ms, 17613 ms, 17815 ms). |
2486 | | // |
2487 | | // No clue about the third and fifth parameter right now, they just always |
2488 | | // are 32 and 1 - possibly finding another example of this function being |
2489 | | // used would help a lot. Also, I can't currently compare it with the original, |
2490 | | // doing that (and possibly, taking screenshots of it for analysis!) would |
2491 | | // help a lot. |
2492 | | |
2493 | | warning("palManipulateInit(%d, %d, %d, %d, %d): not implemented", start, end, d, time, e); |
2494 | | |
2495 | | // FIXME - is this right? |
2496 | | // It seems we already have had this "palManipulate" and "moveMemInPalRes" |
2497 | | // functions, only they were never used (somebody disassembled them and |
2498 | | // didn't disassmble the functions using them?). |
2499 | | // |
2500 | | // I |
| 2464 | byte *srcptr, *destptr, *curptr; |
| 2465 | byte *string1ptr, *string2ptr, *string3ptr; |
| 2466 | int i; |
| 2467 | |
2503 | | //_palManipCounter = ? |
2504 | | |
2505 | | { |
2506 | | int redScale = 0xFF; |
2507 | | int greenScale = 0xFF - d; |
2508 | | int blueScale = 0xFF - d; |
2509 | | byte *cptr; |
2510 | | byte *cur; |
2511 | | int num; |
2512 | | int color; |
2513 | | |
2514 | | cptr = _currentPalette + start * 3; |
2515 | | cur = _currentPalette + start * 3; |
2516 | | num = end - start + 1; |
2517 | | |
2518 | | do { |
2519 | | color = *cptr++; |
2520 | | if (redScale != 0xFF) |
2521 | | color = color * redScale / 0xFF; |
2522 | | if (color > 255) |
2523 | | color = 255; |
2524 | | *cur++ = color; |
2525 | | |
2526 | | color = *cptr++; |
2527 | | if (greenScale != 0xFF) |
2528 | | color = color * greenScale / 0xFF; |
2529 | | if (color > 255) |
2530 | | color = 255; |
2531 | | *cur++ = color; |
2532 | | |
2533 | | color = *cptr++; |
2534 | | if (blueScale != 0xFF) |
2535 | | color = color * blueScale / 0xFF; |
2536 | | if (color > 255) |
2537 | | color = 255; |
2538 | | *cur++ = color; |
2539 | | } while (--num); |
2540 | | setDirtyColors(start, end); |
| 2470 | _palManipCounter = 0; |
| 2471 | |
| 2472 | srcptr = getResourceAddress(rtTemp, 4); |
| 2473 | if (srcptr) |
| 2474 | nukeResource(rtTemp, 4); |
| 2475 | srcptr = createResource(rtTemp, 4, 256 * 6); |
| 2476 | if (!srcptr) { |
| 2477 | warning("palManipulateInit(%d,%d,%d,%d): Cannot create rtTemp resource index 4\n", start, end, string_id, time); |
| 2478 | return; |
| 2480 | srcptr += _palManipStart * 6; |
| 2481 | |
| 2482 | destptr = getResourceAddress(rtTemp, 5); |
| 2483 | if (destptr) |
| 2484 | nukeResource(rtTemp, 5); |
| 2485 | destptr = createResource(rtTemp, 5, 256 * 6); |
| 2486 | if (!destptr) { |
| 2487 | warning("palManipulateInit(%d,%d,%d,%d): Cannot create rtTemp resource index 5\n", start, end, string_id, time); |
| 2488 | return; |
| 2489 | } |
| 2490 | destptr += _palManipStart * 6; |
| 2491 | |
| 2492 | curptr = _currentPalette + _palManipStart * 3; |
| 2493 | string1ptr = getStringAddress(string_id++) + _palManipStart; |
| 2494 | string2ptr = getStringAddress(string_id++) + _palManipStart; |
| 2495 | string3ptr = getStringAddress(string_id) + _palManipStart; |
| 2496 | if (!string1ptr || !string2ptr || !string3ptr) { |
| 2497 | warning("palManipulateInit(%d,%d,%d,%d): Cannot obtain string resources %d, %d and %d\n", |
| 2498 | start, end, string_id, time, string_id - 2, string_id - 1, string_id); |
| 2499 | return; |
| 2500 | } |
| 2501 | |
| 2502 | for (i = _palManipStart; i <= _palManipEnd; ++i) { |
| 2503 | *((uint16 *)srcptr) = ((uint16) *curptr) << 8; |
| 2504 | *((uint16 *)destptr) = (((uint16) *string1ptr++ - (uint16) *curptr++) << 8) / time; |
| 2505 | srcptr += 2; |
| 2506 | destptr += 2; |
| 2507 | *((uint16 *)srcptr) = ((uint16) *curptr) << 8; |
| 2508 | *((uint16 *)destptr) = (((uint16) *string2ptr++ - (uint16) *curptr++) << 8) / time; |
| 2509 | srcptr += 2; |
| 2510 | destptr += 2; |
| 2511 | *((uint16 *)srcptr) = ((uint16) *curptr) << 8; |
| 2512 | *((uint16 *)destptr) = (((uint16) *string3ptr++ - (uint16) *curptr++) << 8) / time; |
| 2513 | srcptr += 2; |
| 2514 | destptr += 2; |
| 2515 | } |
| 2516 | |
| 2517 | _palManipCounter = time; |