Skip to content

Commit 11e22b2

Browse files
committed
Update color remap tools for new palette layout (WIP)
1 parent c4ef399 commit 11e22b2

File tree

2 files changed

+156
-101
lines changed

2 files changed

+156
-101
lines changed

utils/palremap.c

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,53 @@
1+
/* palremap
2+
========
3+
4+
This tool takes a raw 256 color bitmap with up to 126 used colors
5+
(contiguously from index 0!) and changes each pixel's color index
6+
so it falls into a usable logo palette slot for the sd2snes/fxpak
7+
palette.
8+
9+
Its complement is palreorder which does the same for the palette
10+
itself. */
11+
112
#include <stdio.h>
213
#include <stdint.h>
314

415
/* Mapping table. This table specifies the target index in the
516
output file. */
6-
int map_idx [120] = {
7-
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
8-
0x2c, 0x2d, 0x2e, 0x2f, 0x34, 0x35, 0x36, 0x37,
9-
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
10-
0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
11-
0x4c, 0x4d, 0x4e, 0x4f, 0x54, 0x55, 0x56, 0x57,
12-
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
13-
0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
14-
0x6c, 0x6d, 0x6e, 0x6f, 0x74, 0x75, 0x76, 0x77,
17+
int map_idx [126] = {
18+
0x04,
19+
0x08, 0x0c,
20+
0x10, 0x14,
21+
0x18, 0x1c,
22+
0x20, 0x24, 0x25, 0x26, 0x27,
23+
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
24+
0x30, 0x34, 0x35, 0x36, 0x37,
25+
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
26+
0x40,
27+
28+
0x50, 0x54, 0x55, 0x56, 0x57,
29+
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
30+
0x60, 0x64, 0x65, 0x66, 0x67,
31+
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
32+
0x70, 0x74, 0x75, 0x76, 0x77,
1533
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
1634
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
1735
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
1836
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
1937
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
2038
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
21-
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf
22-
};
39+
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
40+
0xb0,
2341

42+
0xc0,
43+
44+
0xd0,
45+
46+
0xe0,
47+
48+
0xf0
49+
};
2450

25-
/* remap colors in a 256 color bitmap */
2651
int main(int argc, char **argv) {
2752
if(argc<3) {
2853
fprintf(stderr, "Usage: %s <infile> <outfile>\n", argv[0]);
@@ -40,28 +65,12 @@ int main(int argc, char **argv) {
4065
while(1) {
4166
uint8_t c=fgetc(in);
4267
if(feof(in))break;
43-
/* new palette mapping:
44-
0-31: fonts, tile stuff
45-
32-35: 4bit palette 2
46-
36-47: logo
47-
48-51: 4bit palette 3
48-
52-63: logo
49-
64-67: 4bit palette 4
50-
68-79: logo
51-
80-83: 4bit palette 5
52-
84-95: logo
53-
96-99: 4bit palette 6
54-
100-111: logo
55-
112-115: 4bit palette 7
56-
116-175: logo
57-
176-191: sprites (misc overlays, cursor, etc.)
58-
192-255: sprites (logo gfx overlays)
59-
*/
60-
if(c < 120) {
68+
69+
if(c < 126) {
6170
c = map_idx[c];
6271
} else {
6372
c = 0;
64-
}
73+
}
6574
fputc(c, out);
6675
}
6776
fclose(out);

utils/palreorder.c

Lines changed: 116 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,71 @@
11
#include <stdio.h>
22
#include <stdint.h>
33
/* reorder entries in a palette file */
4+
45
/* map action types:
6+
This type decides which source palette (if any) will be used to fill in
7+
each respective slot of the target palette:
8+
59
MA_NONE: do not map anything to this entry (constant 0000)
610
MA_LOC: map indexed entry of local palette to this entry
711
MA_SRC: map indexed entry of input palette to this entry
12+
MA_BTN: map indexed entry of buttons palette to this entry
13+
- palette may be switched between EU/JP and US via command line
14+
The index of each corresponding source palette entry is determined
15+
by a second table, map_idx, which for each target palette entry contains
16+
the index of the respective palette chosen by map_action.
817
*/
9-
enum map_action_type { MA_NONE = 0, MA_LOC, MA_SRC };
18+
enum map_action_type { MA_NONE = 0, MA_LOC, MA_SRC, MA_BTN };
1019

1120
int map_action [256] = {
12-
/* 0-3: local entries (2-bit text palette 0 + 4-bit text palette 0)
13-
4-7: local entries (2-bit text palette 1)
14-
8-11: local entries (2-bit text palette 2)
15-
12-15: local entries (2-bit text palette 3)
16-
16-19: local entries (4-bit text palette 1 - 2-bit palette 4 not used)
17-
20-23: local entries (2-bit text palette 5)
18-
24-27: local entries (2-bit text palette 6)
19-
28-31: local entries (2-bit text palette 7) */
20-
MA_NONE, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC,
21-
MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC,
22-
MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC,
23-
MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_LOC,
24-
/* 32-35: local entries (4-bit text palette 2)
25-
36-47: logo gfx */
26-
MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
27-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
28-
/* 48-51: local entries (4-bit text palette 3)
29-
52-63: logo */
30-
MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
31-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
32-
/* 64-67: local entries (4-bit text palette 4 - 4-bit only spare palette)
33-
68-79: logo */
34-
MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
35-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
36-
/* 80-83: local entries (4-bit text palette 5)
37-
84-95: logo */
38-
MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
39-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
40-
/* 96-99: local entries (4-bit text palette 6)
41-
100-111: logo */
42-
MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
43-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
44-
/* 112-115: local entries (4-bit text palette 7)
45-
116-175: logo */
46-
MA_LOC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
47-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
48-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
49-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
50-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
51-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
52-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
53-
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
54-
/* 176-191: sprites (reserved) */
55-
MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE,
21+
/* 0: unused (backdrop color)
22+
1-3: local entries (2-bit text palette 0 + 4-bit text palette 0)
23+
5-7: local entries (2-bit text palette 1)
24+
9-11: local entries (2-bit text palette 2)
25+
13-15: local entries (2-bit text palette 3)
26+
17-19: local entries (4-bit text palette 1 - 2-bit palette 4 not used)
27+
21-23: local entries (2-bit text palette 5)
28+
25-27: local entries (2-bit text palette 6)
29+
29-31: local entries (2-bit text palette 7)
30+
4,8,12,16,20,24,28: logo */
31+
MA_NONE, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_LOC, MA_LOC, MA_LOC,
32+
MA_SRC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_LOC, MA_LOC, MA_LOC,
33+
MA_SRC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_LOC, MA_LOC, MA_LOC,
34+
MA_SRC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_LOC, MA_LOC, MA_LOC,
35+
/* 33-35: local entries (4-bit text palette 2)
36+
32, 36-47: logo */
37+
MA_SRC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
38+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
39+
/* 49-51: local entries (4-bit text palette 3)
40+
48, 52-63: logo */
41+
MA_SRC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
42+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
43+
/* 64: logo
44+
65-79: local entries (4-bit palette 4 - for button graphics) */
45+
MA_SRC, MA_BTN, MA_BTN, MA_BTN, MA_BTN, MA_BTN, MA_BTN, MA_BTN,
46+
MA_BTN, MA_BTN, MA_BTN, MA_BTN, MA_BTN, MA_BTN, MA_BTN, MA_BTN,
47+
/* 81-83: local entries (4-bit text palette 5)
48+
80, 84-95: logo */
49+
MA_SRC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
50+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
51+
/* 97-99: local entries (4-bit text palette 6)
52+
96, 100-111: logo */
53+
MA_SRC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
54+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
55+
/* 113-115: local entries (4-bit text palette 7)
56+
112, 116-127: logo */
57+
MA_SRC, MA_LOC, MA_LOC, MA_LOC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
58+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
59+
/* 128-175: logo */
60+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
61+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
62+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
63+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
64+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
65+
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
66+
/* 176: logo
67+
177-191: sprites (reserved) */
68+
MA_SRC, MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE,
5669
MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE, MA_NONE,
5770
/* 192-255: sprites (logo gfx overlays) */
5871
MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC, MA_SRC,
@@ -69,37 +82,53 @@ int map_action [256] = {
6982
source palette file or the local palette, depending on the action
7083
specified in the table above. */
7184
int map_idx [256] = {
72-
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
85+
/* 0-15 */
86+
0x00, 0x01, 0x02, 0x03, 0x00, 0x05, 0x06, 0x07,
87+
0x01, 0x09, 0x0a, 0x0b, 0x02, 0x0d, 0x0e, 0x0f,
88+
/* 16-31 */
89+
0x03, 0x05, 0x06, 0x07, 0x04, 0x15, 0x16, 0x17,
90+
0x05, 0x19, 0x1a, 0x1b, 0x06, 0x1d, 0x1e, 0x1f,
91+
/* 32-47 */
92+
0x07, 0x09, 0x0a, 0x0b, 0x08, 0x09, 0x0a, 0x0b,
93+
0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
94+
/* 48-63 */
95+
0x14, 0x0d, 0x0e, 0x0f, 0x15, 0x16, 0x17, 0x18,
96+
0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
97+
/* 64-79 */
98+
0x21, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
7399
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
74-
0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17,
75-
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
76-
0x08, 0x09, 0x0a, 0x0b, 0x00, 0x01, 0x02, 0x03,
77-
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
78-
0x0c, 0x0d, 0x0e, 0x0f, 0x0c, 0x0d, 0x0e, 0x0f,
79-
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
80-
0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1a, 0x1b,
81-
0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
82-
0x14, 0x15, 0x16, 0x17, 0x24, 0x25, 0x26, 0x27,
83-
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
84-
0x18, 0x19, 0x1a, 0x1b, 0x30, 0x31, 0x32, 0x33,
100+
/* 80-95 */
101+
0x22, 0x15, 0x16, 0x17, 0x23, 0x24, 0x25, 0x26,
102+
0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
103+
/* 96-111 */
104+
0x2f, 0x19, 0x1a, 0x1b, 0x30, 0x31, 0x32, 0x33,
85105
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
86-
0x1c, 0x1d, 0x1e, 0x1f, 0x3c, 0x3d, 0x3e, 0x3f,
87-
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
88-
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
89-
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
90-
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
91-
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
92-
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
93-
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
106+
/* 112-127 */
107+
0x3c, 0x1d, 0x1e, 0x1f, 0x3d, 0x3e, 0x3f, 0x40,
108+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
109+
/* 128-143 */
110+
0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
111+
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
112+
/* 144-159 */
113+
0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60,
114+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
115+
/* 160-175 */
116+
0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
117+
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
118+
/* 176-191 */
119+
0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94120
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96-
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
121+
/* 192-207 */
122+
0x7a, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
97123
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
98-
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
124+
/* 208-223 */
125+
0x7b, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
99126
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
100-
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
127+
/* 224-239 */
128+
0x7c, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
101129
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
102-
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
130+
/* 240-255 */
131+
0x7d, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
103132
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
104133
};
105134

@@ -112,6 +141,17 @@ uint16_t local_palette [32] = {
112141
0x0000, 0x5294, 0x18c6, 0x39ce, 0x0000, 0x32ff, 0x10a7, 0x2a38
113142
};
114143

144+
/* local palettes for buttons. */
145+
uint16_t buttons_palette_eujp[16] = {
146+
0x0000, 0x03e0, 0x0683, 0x0144, 0x181f, 0x0016, 0x040c, 0x075f,
147+
0x0213, 0x7ee8, 0x7cc5, 0x5820, 0x14a5, 0x318c, 0x6318, 0x7fff
148+
};
149+
150+
uint16_t buttons_palette_us[16] = {
151+
0x0000, 0x646a, 0x4806, 0x7f1a, 0x7df4, 0x7cf3, 0x03e0, 0x03e0,
152+
0x03e0, 0x03e0, 0x03e0, 0x03e0, 0x14a5, 0x318c, 0x6318, 0x7fff
153+
};
154+
115155
int main(int argc, char **argv) {
116156
if(argc<3) {
117157
fprintf(stderr, "Usage: %s <infile> <outfile>\n", argv[0]);
@@ -129,6 +169,9 @@ int main(int argc, char **argv) {
129169
uint16_t palette_src[256];
130170
uint16_t palette_tgt[256];
131171
uint16_t palette_val;
172+
173+
uint16_t *buttons_palette = buttons_palette_eujp;
174+
132175
int tgt_index;
133176
fread(palette_src, 2, 256, in);
134177
for(tgt_index=0; tgt_index<256; tgt_index++) {
@@ -139,6 +182,9 @@ int main(int argc, char **argv) {
139182
case MA_SRC:
140183
palette_val = palette_src[map_idx[tgt_index]];
141184
break;
185+
case MA_BTN:
186+
palette_val = buttons_palette[map_idx[tgt_index]];
187+
break;
142188
case MA_NONE:
143189
default:
144190
palette_val = 0x7c1f;

0 commit comments

Comments
 (0)