EarthBound/ASM/Palette Routines: Difference between revisions

From Data Crystal
Jump to navigation Jump to search
m (Xkeeper moved page EarthBound:ASM:Palette Routines to EarthBound/ASM/Palette Routines: normalize subpages and titles)
 
(3 intermediate revisions by one other user not shown)
Line 41: Line 41:


Calculates color averages for the default map palette (the [[EarthBound:Map_Data:Global_Tileset/Palette_Table#Onett|Onett daytime palette]]). Loads the palette as the current map palette, calculates averages using the subroutine at [[#$C00391|<tt>$C00391</tt>]], and then copies the red, green, and blue averages to [[EarthBound:Palette_Memory#$7E43D6|<tt>$7E43D6</tt>]], [[EarthBound:Palette_Memory#$7E43D8|<tt>$7E43D8</tt>]], and [[EarthBound:Palette_Memory#$7E43DA|<tt>$7E43DA</tt>]] respectively.
Calculates color averages for the default map palette (the [[EarthBound:Map_Data:Global_Tileset/Palette_Table#Onett|Onett daytime palette]]). Loads the palette as the current map palette, calculates averages using the subroutine at [[#$C00391|<tt>$C00391</tt>]], and then copies the red, green, and blue averages to [[EarthBound:Palette_Memory#$7E43D6|<tt>$7E43D6</tt>]], [[EarthBound:Palette_Memory#$7E43D8|<tt>$7E43D8</tt>]], and [[EarthBound:Palette_Memory#$7E43DA|<tt>$7E43DA</tt>]] respectively.
==<tt>$C00778-$C007B5</tt>: Load sprite replacement palette from map<span class="anchor" id="$C00778"></span>==
If the current map palette's [[EarthBound:Map_Data:Palettes#Sprite_Palette_Replacement_Index|Sprite Palette Replacement Index]] is non-zero, replace sprite subpalette 3 (loaded into RAM at <tt>$7E0380-$7E039F</tt>) with the subpalette designated by the replacement index.
Used to bring a map subpalette into sprite subpalettes for the occasions where a map element needs to be created using sprites, e.g. to animate [https://earthbound.fandom.com/wiki/Lost_Underworld Lost Underworld] geysers.
==<tt>$C007B6-$C008C2</tt>: Load map palette<span class="anchor" id="$C007B6"></span>==
For the given tileset number and map palette number, loads the relevant map palette as the current map palette (in RAM at <tt>$7E0240-$7E02FF</tt>). Implemented by looking up the relevant palette location using the [[EarthBound:Map_Data:Palette_Pointer_Table|Map Palette Pointer Table]] and then doing a simple copy.
If the [[EarthBound:Map_Data:Palettes#Alternate_Palette_Flag|Alternate Palette Flag]] from the newly-loaded palette is non-zero, checks the relevant [[EarthBound:Flags|Flag]], and on match, replaces the newly-loaded palette with the one found at the [[EarthBound:Map_Data:Palettes#Alternate_Palette_Pointer|Alternate Palette Pointer]] of the newly-loaded palette. To allow chaining alternate palettes, this check repeats until the Alternate Palette Flag is zero or the relevant flag does not match.
If the [[EarthBound:Photographer_Flags#$7EB4EF|End Credits Display Photos flag]] is non-zero, instead of loading the normal map palette, loads a palette for photo display. Decompresses all the photo display palettes from <tt>$E1374A-$E1413E</tt> to <tt>$7F0000</tt>. Then looks up the [[EarthBound:Photographer_Flags#$7EB4F1|Current Photographer Photo]] in the [[EarthBound:Wandering_Photographer_Configuration_Table|Wandering Photographer Configuration Table]] to get the relevant pointer in the decompressed palettes, and loads that palette as the current map palette.
===Inputs===
* <tt>accumulator</tt>: Tileset number
* <tt>x</tt>: Map palette number


==<tt>$C0A1F2-$C0A20B</tt>: Load map palette animation palette<span class="anchor" id="$C0A1F2"></span>==
==<tt>$C0A1F2-$C0A20B</tt>: Load map palette animation palette<span class="anchor" id="$C0A1F2"></span>==
Line 48: Line 66:
===Inputs===
===Inputs===
* <tt>accumulator</tt>: Map animation palette number
* <tt>accumulator</tt>: Map animation palette number
==<tt>$C47F87-$C4800A</tt>: Load text/window palette<span class="anchor" id="$C47F87"></span>==
First checks player data in RAM to determine if any characters are  unconscious or diamondized. If so, loads the red text/window palette used in such situations as the current text/window palette.
Otherwise, loads the appropriate palette for the player-selected [[EarthBound:Palette_Memory#$7E99CD|Current Window Flavor]] as the current text/window palette.
==<tt>$C496F9-$C4973F</tt>: Copy current palettes<span class="anchor" id="$C496F9"></span>==
Copies all current text/window/map/sprite palettes (at <tt>$7E0200-$7E03FF</tt>) to $7F0000-$7F01FF.


[[Category:EarthBound:ASM|Palette Routines]]
[[Category:EarthBound:ASM|Palette Routines]]
{{Internal Data|game=EarthBound}}
{{Internal Data|game=EarthBound}}
{{stub}}

Latest revision as of 02:41, 24 January 2024

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 palette (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

Calculates color averages for the default map palette (the Onett daytime palette). Loads the palette as the current map palette, calculates averages using the subroutine at $C00391, and then copies the red, green, and blue averages to $7E43D6, $7E43D8, and $7E43DA respectively.

$C00778-$C007B5: Load sprite replacement palette from map

If the current map palette's Sprite Palette Replacement Index is non-zero, replace sprite subpalette 3 (loaded into RAM at $7E0380-$7E039F) with the subpalette designated by the replacement index.

Used to bring a map subpalette into sprite subpalettes for the occasions where a map element needs to be created using sprites, e.g. to animate Lost Underworld geysers.

$C007B6-$C008C2: Load map palette

For the given tileset number and map palette number, loads the relevant map palette as the current map palette (in RAM at $7E0240-$7E02FF). Implemented by looking up the relevant palette location using the Map Palette Pointer Table and then doing a simple copy.

If the Alternate Palette Flag from the newly-loaded palette is non-zero, checks the relevant Flag, and on match, replaces the newly-loaded palette with the one found at the Alternate Palette Pointer of the newly-loaded palette. To allow chaining alternate palettes, this check repeats until the Alternate Palette Flag is zero or the relevant flag does not match.

If the End Credits Display Photos flag is non-zero, instead of loading the normal map palette, loads a palette for photo display. Decompresses all the photo display palettes from $E1374A-$E1413E to $7F0000. Then looks up the Current Photographer Photo in the Wandering Photographer Configuration Table to get the relevant pointer in the decompressed palettes, and loads that palette as the current map palette.

Inputs

  • accumulator: Tileset number
  • x: Map palette number

$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

$C47F87-$C4800A: Load text/window palette

First checks player data in RAM to determine if any characters are unconscious or diamondized. If so, loads the red text/window palette used in such situations as the current text/window palette.

Otherwise, loads the appropriate palette for the player-selected Current Window Flavor as the current text/window palette.

$C496F9-$C4973F: Copy current palettes

Copies all current text/window/map/sprite palettes (at $7E0200-$7E03FF) to $7F0000-$7F01FF.