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 |
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); |
| 2466 | _palManipCounter = 0; |
| 2467 | |
| 2468 | byte *startptr = getResourceAddress(rtTemp, 4); |
| 2469 | if (startptr) |
| 2470 | nukeResource(rtTemp, 4); |
| 2471 | startptr = createResource(rtTemp, 4, 256 * 6); |
| 2472 | if (!startptr) { |
| 2473 | warning("palManipulateInit(%d,%d,%d,%d): Cannot create rtTemp resource index 4\n", start, end, string_id, time); |
| 2474 | return; |
| 2476 | startptr += _palManipStart * 6; |
| 2477 | |
| 2478 | byte *endptr = getResourceAddress(rtTemp, 5); |
| 2479 | if (endptr) |
| 2480 | nukeResource(rtTemp, 5); |
| 2481 | endptr = createResource(rtTemp, 5, 256 * 6); |
| 2482 | if (!endptr) { |
| 2483 | warning("palManipulateInit(%d,%d,%d,%d): Cannot create rtTemp resource index 5\n", start, end, string_id, time); |
| 2484 | return; |
| 2485 | } |
| 2486 | endptr += _palManipStart * 6; |
| 2487 | |
| 2488 | byte *curptr = _currentPalette + _palManipStart * 3; |
| 2489 | byte *string1ptr = getStringAddress(string_id) + _palManipStart; |
| 2490 | byte *string2ptr = getStringAddress(string_id + 1) + _palManipStart; |
| 2491 | byte *string3ptr = getStringAddress(string_id + 2) + _palManipStart; |
| 2492 | if (!string1ptr || !string2ptr || !string3ptr) { |
| 2493 | warning("palManipulateInit(%d,%d,%d,%d): Cannot obtain string resources %d, %d and %d\n", |
| 2494 | start, end, string_id, time, string_id, string_id + 1, string_id + 2); |
| 2495 | return; |
| 2496 | } |
| 2497 | |
| 2498 | int i; |
| 2499 | for (i = _palManipStart; i <= _palManipEnd; ++i) { |
| 2500 | *((uint16 *)startptr) = ((uint16) *curptr++) << 8; |
| 2501 | *((uint16 *)endptr) = ((uint16) *string1ptr++) << 8; |
| 2502 | startptr += 2; |
| 2503 | endptr += 2; |
| 2504 | *((uint16 *)startptr) = ((uint16) *curptr++) << 8; |
| 2505 | *((uint16 *)endptr) = ((uint16) *string2ptr++) << 8; |
| 2506 | startptr += 2; |
| 2507 | endptr += 2; |
| 2508 | *((uint16 *)startptr) = ((uint16) *curptr++) << 8; |
| 2509 | *((uint16 *)endptr) = ((uint16) *string3ptr++) << 8; |
| 2510 | startptr += 2; |
| 2511 | endptr += 2; |
| 2512 | } |
| 2513 | |
| 2514 | _palManipCounter = time; |