EarthBound/ASM/Palette Routines: Difference between revisions

From Data Crystal
Jump to navigation Jump to search
m (Fixup pointer font)
Line 7: Line 7:
==<tt>$C0030F-$C0035A</tt>: Iterate map palette animation frame<span class="anchor" id="$C0030F"></span>==
==<tt>$C0030F-$C0035A</tt>: Iterate map palette animation frame<span class="anchor" id="$C0030F"></span>==


Decrements [[EarthBound:Palette_Memory#$7E445C|Animation Palette Remaining Frames]], and if zero, updates WRAM ([[EarthBound:Palette_Memory#$7E445E|Animation Palette Number]] and Animation Palette Remaining Frames) for the next animation palette and calls the subroutine at [[#$C0A1F2|$C0A1F2]] to load the next palette.
Decrements [[EarthBound:Palette_Memory#$7E445C|Animation Palette Remaining Frames]], and if zero, updates WRAM ([[EarthBound:Palette_Memory#$7E445E|Animation Palette Number]] and Animation Palette Remaining Frames) for the next animation palette and calls the subroutine at [[#$C0A1F2|<tt>$C0A1F2</tt>]] to load the next palette.


==<tt>$C00391-$C00433</tt>: Calculate color averages for map palette<span class="anchor" id="$C00391"></span>==
==<tt>$C00391-$C00433</tt>: Calculate color averages for map palette<span class="anchor" id="$C00391"></span>==


For the given map palette, averages out all the non-zero red values, all the non-zero green values, and all the non-zero blue values from all colors in all 6 subpalettes of the map palette. Stores the results to WRAM at [[EarthBound:Palette_Memory#$7E43D0|$7E43D0]], [[EarthBound:Palette_Memory#$7E43D2|$7E43D2]], and [[EarthBound:Palette_Memory#$7E43D4|$7E43D4]] respectively.
For the given map palette, averages out all the non-zero red values, all the non-zero green values, and all the non-zero blue values from all colors in all 6 subpalettes of the map palette. Stores the results to WRAM at [[EarthBound:Palette_Memory#$7E43D0|<tt>$7E43D0</tt>]], [[EarthBound:Palette_Memory#$7E43D2|<tt>$7E43D2</tt>]], and [[EarthBound:Palette_Memory#$7E43D4|<tt>$7E43D4</tt>]] respectively.


===Inputs===
===Inputs===
Line 19: Line 19:
==<tt>$C00434-$C0047F</tt>: Cap palette color adjustment<span class="anchor" id="$C00434"></span>==
==<tt>$C00434-$C0047F</tt>: Cap palette color adjustment<span class="anchor" id="$C00434"></span>==


For the given unadjusted and adjusted color values (single red, green, or blue value), determines a new adjusted color value that is at most 6 different from the unadjusted. Used by the subroutine at [[#$C00480|$C00480]] to limit the difference made by sprite palette adjustements.
For the given unadjusted and adjusted color values (single red, green, or blue value), determines a new adjusted color value that is at most 6 different from the unadjusted. Used by the subroutine at [[#$C00480|<tt>$C00480</tt>]] to limit the difference made by sprite palette adjustements.


===Inputs===
===Inputs===

Revision as of 19:58, 17 July 2023

This is a sub-page of EarthBound/ASM.

$C0023F-$C0030E: Load map palette animation

First checks if the currently loaded map palette is animated, as indicated by a non-zero Palette Animation Index and a non-zero Animation Number of Palettes for that animation index, and sets the Animation Palette Active Flag accordingly in WRAM. If the palette is animated, loads Decompressed Map Animation Palettes, Animation Palette Frame Durations, Animation Palette Remaining Frames, and Animation Palette Number to WRAM.

$C0030F-$C0035A: Iterate map palette animation frame

Decrements Animation Palette Remaining Frames, and if zero, updates WRAM (Animation Palette Number and Animation Palette Remaining Frames) for the next animation palette and calls the subroutine at $C0A1F2 to load the next palette.

$C00391-$C00433: Calculate color averages for map palette

For the given map palette, averages out all the non-zero red values, all the non-zero green values, and all the non-zero blue values from all colors in all 6 subpalettes of the map palette. Stores the results to WRAM at $7E43D0, $7E43D2, and $7E43D4 respectively.

Inputs

  • accumulator: Map palette data pointer

$C00434-$C0047F: Cap palette color adjustment

For the given unadjusted and adjusted color values (single red, green, or blue value), determines a new adjusted color value that is at most 6 different from the unadjusted. Used by the subroutine at $C00480 to limit the difference made by sprite palette adjustements.

Inputs

  • accumulator: Original unadjusted color value (red, green, or blue)
  • x: Adjusted color value

Outputs

  • accumulator: Capped adjusted color value

$C00480-$C005E6: Adjust sprite palette colors for map palette

Adjusts all sprite palettes based on the color differences between the current map palette and the default map (Onett daytime) palette.

Calculates color averages for the current map palette at $7E0240 using the subroutine at $C00391. Then compares the averages with the default map palette averages stored at $7E43D6, $7E43D8, and $7E43DA, and computes a comparison ratio using the formula ratio = current_color_average * 8 / default_color_average.

Then for every single color in the sprite palettes ($7E0300-$7E03FF), individually multiplies each of red, green, and blue by the comparison ratio for that color component (or if red, green, and blue components are all equal, multiplies them by the average of the comparison ratios) to calculate an adjusted color component. Finally caps the adjustment to each color component using the subroutine at $C00434, and writes the adjusted color components back to the sprite palette.

$C005E7-$C00629: Calculate color averages for default map palette

$C0A1F2-$C0A20B: Load map palette animation palette

Loads a palette from Decompressed Map Animation Palettes and replaces the current map palette.

Inputs

  • accumulator: Map animation palette number
So very stubbly.
This page is rather stubbly and could use some expansion.
Are you a bad enough dude to rescue this article?