Alchemy
Loading...
Searching...
No Matches

palette_editor.c

Go to the documentation of this file.
1/// @file
2/// The debug palette editor.
3/// Part of object.c, the field object, compiled only through it.
4
6
7// The palettes, as plain halfwords, and where the editor draws: from column
8// 13 of row 1 of screen block 4.
9#define EDITOR_PALETTE ((u16 *)0x05000000)
10#define EDITOR_MAP ((u16 *)0x0600205a)
11#define EDITOR_HEX_DIGIT 0xf0e0 ///< the tile of digit 0, in BG palette 15
12
13/// The debug palette editor (L on the pause menu in debug mode). Shows colours
14/// 1 to 15 of a palette with their red, green and blue values in hex. Left and
15/// right choose the colour, up and down the channel, L and R the palette (0 to
16/// 13); A raises the channel and B lowers it, Start makes the colour blink
17/// while held, and Select leaves. Called by Field_RunScene for the pause
18/// request when L is held in debug mode. Writes the edited colours straight to
19/// BG palette RAM and draws over screen block 4; on leaving it reloads the
20/// window graphics and clears the debug text.
22 s32 palette = 0;
23 s32 channel = 1;
24 s32 color = 1;
25 u16 *swatchColumn;
26 u16 *tileEntry;
27 u16 *paletteColor;
28 u32 tile;
29 u32 rgb555;
30 u32 red;
31 u32 green;
32 u32 blue;
33 u32 i;
34
35 // The swatch tiles go to tile 0xd0 of character block 0; colour n is drawn
36 // with tile 0xd0 + n.
38redraw:
39 // Column 0 shows the palette number and R, G, B; columns 1 to 15 show each
40 // colour's swatch, drawn in the palette being edited, and its three
41 // channels. The letters are tiles at their ASCII codes in BG palette 15.
42 tile = (palette << 12) + 0xd1;
43 paletteColor = &EDITOR_PALETTE[palette * 16 + 1];
44 swatchColumn = EDITOR_MAP;
45 tileEntry = swatchColumn;
46 *tileEntry = EDITOR_HEX_DIGIT + palette;
47 tileEntry += 32;
48 *tileEntry = 0xf000 | 'R';
49 tileEntry += 32;
50 *tileEntry = 0xf000 | 'G';
51 tileEntry += 32;
52 *tileEntry = 0xf000 | 'B';
53 swatchColumn++;
54 for (i = 1; i < 16; i++) {
55 tileEntry = swatchColumn;
56 *tileEntry = tile++;
57 rgb555 = *paletteColor++;
58 tileEntry += 32;
59 *tileEntry = (rgb555 & 31) + EDITOR_HEX_DIGIT;
60 tileEntry += 32;
61 *tileEntry = ((rgb555 >> 5) & 31) + EDITOR_HEX_DIGIT;
62 tileEntry += 32;
63 *tileEntry = ((rgb555 >> 10) & 31) + EDITOR_HEX_DIGIT;
64 swatchColumn++;
65 }
66 WaitFrames(1);
67 for (;;) {
68 if (gKeysRepeat & KEY_UP) {
69 channel--;
70 if (channel <= 0)
71 channel = 3;
72 }
73 if (gKeysRepeat & KEY_DOWN) {
74 channel++;
75 if (channel > 3)
76 channel = 1;
77 }
78 if (gKeysRepeat & KEY_LEFT) {
79 color--;
80 if (color <= 0)
81 color = 15;
82 }
83 if (gKeysRepeat & KEY_RIGHT) {
84 color++;
85 if (color > 15)
86 color = 1;
87 }
88 if (gKeysRepeat & KEY_L) {
89 palette--;
90 if (palette < 0)
91 palette = 13;
92 goto redraw;
93 }
94 if (gKeysRepeat & KEY_R) {
95 palette++;
96 if (palette > 13)
97 palette = 0;
98 goto redraw;
99 }
100 if (gKeysRepeat & KEY_A) {
101 paletteColor = &EDITOR_PALETTE[palette * 16 + color];
102 rgb555 = *paletteColor;
103 red = rgb555 & 31;
104 green = (rgb555 >> 5) & 31;
105 blue = (rgb555 >> 10) & 31;
106 if (channel == 1 && red < 31)
107 red++;
108 if (channel == 2 && green < 31)
109 green++;
110 if (channel == 3 && blue < 31)
111 blue++;
112 *paletteColor = RGB(red, green, blue);
113 goto redraw;
114 }
115 if (gKeysRepeat & KEY_B) {
116 paletteColor = &EDITOR_PALETTE[palette * 16 + color];
117 rgb555 = *paletteColor;
118 red = rgb555 & 31;
119 green = (rgb555 >> 5) & 31;
120 blue = (rgb555 >> 10) & 31;
121 if (channel == 1 && red != 0)
122 red--;
123 if (channel == 2 && green != 0)
124 green--;
125 if (channel == 3 && blue != 0)
126 blue--;
127 *paletteColor = RGB(red, green, blue);
128 goto redraw;
129 }
130 if (gKeysRepeat & KEY_START) {
131 // Blink white, the colour, black, the colour, every 10 frames; red
132 // counts the frames here.
133 paletteColor = &EDITOR_PALETTE[palette * 16 + color];
134 rgb555 = *paletteColor;
135 red = 0;
136 for (;;) {
137 WaitFrames(1);
138 if (!(gKeysHeld & KEY_START))
139 break;
140 if (red == 0)
141 *paletteColor = 0x7fff;
142 if (red == 10)
143 *paletteColor = rgb555;
144 if (red == 20)
145 *paletteColor = 0;
146 if (red == 30)
147 *paletteColor = rgb555;
148 if (++red >= 40)
149 red = 0;
150 }
151 *paletteColor = rgb555;
152 }
154 break;
155 gFrameCount; // a read whose value is not used
156 WaitFrames(1);
157 }
160}
161
162#undef EDITOR_PALETTE
163#undef EDITOR_MAP
164#undef EDITOR_HEX_DIGIT
const u8 gDebug_PaletteSwatchTiles[]
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
volatile u32 gFrameCount
Frames WaitFrames has finished.
#define RGB(r, g, b)
A 15-bit colour from its red, green and blue levels (0 to 31 each), as the palette stores it: blue in...
Definition io_reg.h:164
@ KEY_UP
Definition io_reg.h:249
@ KEY_B
Definition io_reg.h:244
@ KEY_SELECT
Definition io_reg.h:245
@ KEY_LEFT
Definition io_reg.h:248
@ KEY_START
Definition io_reg.h:246
@ KEY_RIGHT
Definition io_reg.h:247
@ KEY_R
Definition io_reg.h:251
@ KEY_A
Definition io_reg.h:243
@ KEY_DOWN
Definition io_reg.h:250
@ KEY_L
Definition io_reg.h:252
volatile u32 gKeysHeld
Keys down now.
volatile u32 gKeysRepeat
Pressed keys, repeating while held: after 19 frames, then every 6.
What every part of object.c shares: its includes and the macros and types more than one part uses.
#define EDITOR_PALETTE
#define EDITOR_HEX_DIGIT
the tile of digit 0, in BG palette 15
#define EDITOR_MAP
void Debug_RunPaletteEditor(void)
The debug palette editor (L on the pause menu in debug mode).
void Resource_DecompressHalfwords(const void *source, void *destination)
Decompresses the halfword LZ stream at source to destination, with a copy of the ARM decoder on the s...
Definition decompress.c:9
void Ui_LoadWindowGraphics(void)
Loads the window font and frame tiles into BG character block 0, the window palette into BG palette 1...
Definition text.c:180
void DebugText_Clear(void)
Blanks the debug text screen, homes the cursor and points BG0 at it.
Definition text.c:170
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13