Alchemy
Loading...
Searching...
No Matches

kolima_palette.h

Go to the documentation of this file.
1#include "battle.h"
2#include "debug.h"
3#include "field.h"
4#include "game.h"
5#include "graphics.h"
6#include "menu.h"
7#include "minigame.h"
8#include "sound.h"
9#include "system.h"
10#include "dma.h"
11#include "field_event.h"
12#include "io_reg.h"
14
15// Kolima's forest, while Tret's curse lasts (FLAG_KOLIMA_CURSE_LIFTED clear):
16// the forest's colours turned redder and darker, and both sets of colours kept
17// for the scene where the curse lifts.
18
19// Forward declarations.
21static void KolimaPalette_SaveFirst(void);
22static void KolimaPalette_SaveSecond(void);
23static void KolimaPalette_Capture(void);
24
25/// Keeps the healthy colours, curses the background palettes 0 to 13 (all but
26/// colours 1 to 7 of palette 1 and 1 to 8 of palette 12) by strength, keeps
27/// the cursed colours too, and shows them.
28void KolimaPalette_Curse(s32 strength) {
29 u16 i;
30
32 for (i = 0; i < 224; i++) {
33 if ((i < 17 || i > 23) && (i < 193 || i > 200)) {
34 u16 *pal = (u16 *)(0x5000000 + i * 2);
35 *pal = SceneEffect_AdjustColorChannels(*pal, strength);
36 }
37 }
41}
42
43/// One cursed colour: red gains a 4 * adj'th of itself (up to 31), and green
44/// and blue lose an adj'th.
46 s16 green = ((color >> 5) & 31);
47 s16 red = (color & 31);
48 s16 blue = ((color >> 10) & 31);
49 u32 packed;
50
51 red = (red + Math_Divide(red, (adj << 2)));
52 green = (green - Math_Divide(green, adj));
53 blue = (blue - Math_Divide(blue, adj));
54
55 if (red > 31)
56 red = 31;
57
58 packed = red;
59 packed |= (blue << 10) | (green << 5);
60 return packed;
61}
62
63/// Keeps the healthy colours: the colour buffer into gKolimaPalette_First.
64static void KolimaPalette_SaveFirst(void) {
66 (DMA_ENABLE | DMA_32BIT) << 16 | 0xe0, REG_DMA3);
67}
68
69/// Keeps the cursed colours: the colour buffer into gKolimaPalette_Second.
70static void KolimaPalette_SaveSecond(void) {
72 (DMA_ENABLE | DMA_32BIT) << 16 | 0xe0, REG_DMA3);
73}
74
75/// Copies the palettes on the screen, background and sprites, into the colour
76/// buffer as the colours to fade from.
77static void KolimaPalette_Capture(void) {
79
80 Dma_Set((const void *)BG_PLTT, buf, (DMA_ENABLE | DMA_32BIT) << 16 | 0x70,
81 REG_DMA3);
82 Dma_Set((const void *)OBJ_PLTT, buf + 0xe0,
83 (DMA_ENABLE | DMA_32BIT) << 16 | 0x70, REG_DMA3);
85}
86
87/// Makes the healthy colours (second 0) or the cursed ones (second 1) the
88/// colours to fade to; the scene then fades with Engine_ColorBufferInterpolate.
91
92 if (second)
94 REG_DMA3);
95 else
96 Dma_Set(gKolimaPalette_First, buf, (DMA_ENABLE | DMA_32BIT) << 16 | 0xe0,
97 REG_DMA3);
100}
The battle animation state, render objects and effect entries, and the palette buffer work.
struct BattleEffectBuffers * gPaletteBufferWork
The engine calls the debug menus import, and their palette swatch tiles.
DMA channel registers, and the DMA and CPU fills.
static __inline__ void Dma_Set(const volatile void *source, volatile void *destination, u32 control, volatile u32 *channel)
Starts a DMA transfer: stores the source, destination and control words into channel's registers with...
Definition dma.h:62
The scene script layer: the engine services a scene's events call, declared once (Engine_EventBegin,...
static s32 Math_Divide(s32 dividend, s32 divisor)
void Engine_ColorBufferApplyTarget(s32 value, s32 mode)
void Engine_ColorBufferApplySource(s32 value, s32 mode)
The screen blend's globals and the graphics routines.
The hardware's I/O registers and their bits, as pret names them.
#define OBJ_PLTT
Definition io_reg.h:159
#define DMA_32BIT
Definition io_reg.h:210
#define REG_DMA3
Definition io_reg.h:153
#define BG_PLTT
Definition io_reg.h:157
#define DMA_ENABLE
Definition io_reg.h:217
u8 gKolimaPalette_First[1792]
u8 gKolimaPalette_Second[896]
The reel game's title lettering.
static void KolimaPalette_Capture(void)
Copies the palettes on the screen, background and sprites, into the colour buffer as the colours to f...
static void KolimaPalette_SaveFirst(void)
Keeps the healthy colours: the colour buffer into gKolimaPalette_First.
static u16 SceneEffect_AdjustColorChannels(u16 color, s32 adj)
One cursed colour: red gains a 4 * adj'th of itself (up to 31), and green and blue lose an adj'th.
static void KolimaPalette_SaveSecond(void)
Keeps the cursed colours: the colour buffer into gKolimaPalette_Second.
void KolimaPalette_Restore(s32 second)
Makes the healthy colours (second 0) or the cursed ones (second 1) the colours to fade to; the scene ...
void KolimaPalette_Curse(s32 strength)
Keeps the healthy colours, curses the background palettes 0 to 13 (all but colours 1 to 7 of palette ...
u16 palette[0x1c0]
The source palette, RGB555: 224 BG colours, then 224 OBJ colours; palette[0] is the backdrop.
Definition palbuf.h:43
The system's routines and globals: interrupts, BIOS sound bias, random numbers and sleep.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13