Palette fade: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 11:
== Details ==
 
The process used to fade between the palettes is as follows. The palette fade starts at palette 0, and on each iteration will update all 16 colors in the background and sprite palettes at the current index. After each iteration, the current palette index is incremented. When all 8 palettes have been updated, the palette fade will complete if there were no colors updated during the last 8 iterations. If there were updated colors, then current palette is reset to 0 and the process repeats. Background palette 7 is skipped during this process, but sprite palette 7 is updated as normal.
 
Before each iteration, there is a delay. The delay starts at 64 frames, and this value is decremented between each iteration. The delay will never go below 1 frame.
 
To update a color, compare each of the red, green, and blue components of the current color and the target color. If the current value is less than the target value, increment it, if it is greater, decrement it, and if the values are the same, do not alter it. This process means that the number of iterations required to complete the fade depends on the largest difference between starting and target color components. See [[#Timing Data|timing data]] for details.
 
== Additional data format ==
 
The format for the additional data in the level is:
 
{| class="wikitable"
|-
! Offset !! Length !! [[Data types|Type]] !! Name !! Description
|-
| 0x00 || 4 || pointer32 || targetBGPalette || Pointer to target background palette
|-
| 0x04 || 4 || pointer32 || targetSpritePalette || Pointer to target sprite palette
|}
 
== RAM map ==
 
=== Entity arguments ===
 
{| class="wikitable"
|-
! Address !! Length !! [[Data types|Type]] !! Name !! Description
|-
| $00 || 4 || pointer32 || additionalData || Pointer to [[#Additional data format|additional data]]
|}
 
=== Entity memory ===
 
{| class="wikitable"
|-
! Address !! Length !! [[Data types|Type]] !! Name !! Description
|-
| $0A || 2 || boolean || updated || Any palette has been updated in current 8-palette cycle
|-
| $0C || 2 || uint16 || curIndex || Index of current palette (in bytes)
|-
| $0E || 2 || uint16 || curDelay || Current delay between iterations
|-
| $10 || 4 || pointer32 || targetBGPalette || Pointer to target background palette
|-
| $14 || 4 || pointer32 || targetSpritePalette || Pointer to target sprite palette
|}
 
== Bugs ==
 
If the high bit is set on any of the colors in the target palettes, then the palette fade will never be considered complete. This happens because the color update logic checks if the color values are exactly equal when determining if the fade is complete, but will never set this bit on the updated colors. Since the high bit is unused in SNES colors, this can be completely avoided by simply leaving the bit unset on all colors. None of the colors in the base game ever have this bit set, so this bug can only occur in modified ROMs.
 
== Timing Data ==
 
{| class="wikitable"
Line 86 ⟶ 133:
|}
 
Highlighted rows in the table below are palette combinations that occur in the original game.
== Additional data format ==
 
The format for the additional data in the level is:
 
{| class="wikitable"
|-
! Tileset !! Palette 1 !! Palette 2 !! Largest component<br/>difference !! Duration (seconds)
! Offset !! Length !! Type !! Description
|-
| rowspan="6"|Grass || Autumn || Night || 24 || 36.87261642
| 0x00 || 4 || pointer32 || Pointer to target background palette
|-
| 0x04Autumn || 4Normal || pointer3218 || Pointer to target sprite palette36.07393159
|}
 
== RAM map ==
 
=== Entity arguments ===
 
{| class="wikitable"
|-
| Autumn || Winter || 28 || 37.40507298
! Address !! Length !! Type !! Description
|- class="highlightrow"
| Night || Normal || 30 || 37.67130126
|-
| Night || Winter || 30 || 37.67130126
| $00 || 4 || pointer32 || Pointer to [[#Additional data format|additional data]]
|}
 
=== Entity memory ===
 
{| class="wikitable"
|-
| Normal || Winter || 23 || 36.73950229
! Address !! Length !! Type !! Description
|-
| rowspan="6"|Castle || Bright || Dark || 24 || 36.87261642
| $0A || 2 || boolean || Any palette has been updated in current 8-palette cycle
|- class="highlightrow"
| Bright || Night || 24 || 36.87261642
|-
| $0CBright || 2Normal || uint1624 || Index of current palette (in bytes)36.87261642
|-
| $0EDark || 2Night || uint1617 || Current delay between iterations35.94081745
|-
| $10Dark || 4Normal || pointer3214 || Pointer to target background palette35.54147504
|- class="highlightrow"
| Night || Normal || 21 || 36.47327401
|-
| $14Mall+Factory || 4Factory || pointer32Mall || Pointer27 to target sprite|| palette37.27195884
|-
| rowspan="10"|Office+Cave || Dark Fire Cave || Dark || 31 || 37.8044154
|-
| Dark Fire Cave || Fire Cave || 31 || 37.8044154
|-
| Dark Fire Cave || Light || 31 || 37.8044154
|-
| Dark Fire Cave || Normal || 31 || 37.8044154
|-
| Dark || Fire Cave || 31 || 37.8044154
|- class="highlightrow"
| Dark || Light || 24 || 36.87261642
|-
| Dark || Normal || 31 || 37.8044154
|-
| Fire Cave || Light || 31 || 37.8044154
|-
| Fire Cave || Normal || 18 || 36.07393159
|- class="highlightrow"
| Light || Normal || 31 || 37.8044154
|-
| rowspan="6"|Sand || Beach || Dark Beach || 23 || 36.73950229
|-
| Beach || Mines || 22 || 36.60638815
|-
| Beach || Pyramid || 22 || 36.60638815
|-
| Dark Beach || Mines || 18 || 36.07393159
|-
| Dark Beach || Pyramid || 23 || 36.73950229
|-
| Mines || Pyramid || 22 || 36.60638815
|}
 
{{Pseudocode header}}
=== Bugs ===
updateColor(targetColor, currentColor) { // $82:AAB7
 
if (currentColor == targetColor) {
If the high bit is set on any of the colors in the target palettes, then the palette fade will never be considered complete. This happens because the color update logic checks if the color values are exactly equal when determining if the fade is complete, but will never set this bit on the updated colors. Since the high bit is unused in SNES colors, this can be completely avoided by simply leaving the bit unset on all colors.
return false
}
targetB = targetColor & 0x7C00
targetG = targetColor & 0x03E0
targetR = targetColor & 0x001F
newB = currentColor & 0x7C00
if (newB > targetB) {
newB -= 0x400
} else if (newB < targetB) {
newB += 0x400
}
newG = currentColor & 0x03E0
if (newG > targetG) {
newG -= 0x20
} else if (newG < targetG) {
newG += 0x20
}
newR = currentColor & 0x001F
if (newR > targetR) {
newR -= 1
} else if (newR < targetR) {
newR += 1
}
newColor = newR | newG | newB
return true, newColor
}
updateBGPalette(targetPalette, index) { // $82:AB19
if (index >= 0x70) {
return false
}
colorUpdated = false
for (i = index; i < index + 0x10; i += 1) {
updated, newColor = updateColor(targetPalette[i], {{RAM name|$7E:5428}}[i])
if (updated) {
colorUpdated = true
{{RAM name|$7E:5428}}[i] = newColor
{{RAM name|$7E:5628}}[i] = newColor
}
}
return colorUpdated
}
updateSpritePalette(targetPalette, index) { // $82:AB5B
colorUpdated = false
for (i = index; i < index + 0x10; i += 1) {
updated, newColor = updateColor(targetPalette[i], {{RAM name|$7E:5528}}[i])
if (updated) {
colorUpdated = true
{{RAM name|$7E:5528}}[i] = newColor
}
}
return colorUpdated
}
main() { // $82:AB95
this.targetBGPalette = args.additionalData.targetBGPalette
this.targetSpritePalette = args.additionalData.targetSpritePalette
this.curIndex = 0
this.updated = false
this.curDelay = 64
while (true) {
{{ROM name|$80:8353}}(this.curDelay)
if (updateBGPalette(this.targetBGPalette, this.curIndex)) {
this.updated = true
}
if (updateSpritePalette(this.targetSpritePalette, this.curIndex)) {
this.updated = true
}
this.curIndex += 0x10
if (this.curIndex >= 0x80) {
if (!this.updated) {
{{RAM name|$7E:1F94}} = true
return
}
{{ROM name|$80:83AE}}({{ROM name|$80:9FDF}}) // Transfer palette to CG-RAM
this.updated = false
this.curIndex = 0
if (this.curDelay >= 2) {
this.curDelay -= 1
}
}
}
}
{{Pseudocode footer}}
 
[[Category:Boss monster]]
[[Category:MonsterBug]]
[[Category:Entity]]