|
@@ -0,0 +1,137 @@
|
|
1
|
+#include <pokeagb/pokeagb.h>
|
|
2
|
+#include <agb_debug.h>
|
|
3
|
+#include <dns.h>
|
|
4
|
+
|
|
5
|
+#define DNS_BUF_SIZE 256
|
|
6
|
+#define DNS_SEC_PAL_START 224
|
|
7
|
+#define DNS_SEC_PAL_START_C (DNS_SEC_PAL_START / 2)
|
|
8
|
+
|
|
9
|
+#define crgb5(r,g,b) (union Color)(((u16)(((b) << 10) | ((g)<<5) | ((r)))))
|
|
10
|
+#define rgb82rgb5(r,g,b) (crgb5(r/8, g/8, b/8))
|
|
11
|
+
|
|
12
|
+const union Color dns_color_times[5] = {
|
|
13
|
+ rgb82rgb5(70, 70, 196),
|
|
14
|
+ rgb82rgb5(70, 70, 196),
|
|
15
|
+ rgb82rgb5(70, 70, 196),
|
|
16
|
+ rgb82rgb5(70, 70, 196),
|
|
17
|
+ rgb82rgb5(70, 70, 196)
|
|
18
|
+};
|
|
19
|
+
|
|
20
|
+union Color dns_color_multiply(union Color a, union Color b);
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+void dns_blockset_load_palette(struct MapBlockset* blockset, u16 offset, u16 size){
|
|
24
|
+ dprintf("loading blocset 0x%x\n", blockset);
|
|
25
|
+ if(blockset != NULL){
|
|
26
|
+ union Color *dns_buffer = malloc(DNS_BUF_SIZE*2);
|
|
27
|
+ if(blockset->secondary > 0)
|
|
28
|
+ {
|
|
29
|
+ if(blockset->secondary == 1)
|
|
30
|
+ {
|
|
31
|
+ //load secondary palette uncompressed
|
|
32
|
+ memcpy(dns_buffer, blockset->palettes+DNS_SEC_PAL_START, size);
|
|
33
|
+ dns_modify_palette(dns_buffer, size/2);
|
|
34
|
+ gpu_pal_apply(dns_buffer, offset,size);
|
|
35
|
+ load_palette3(offset, size/2);
|
|
36
|
+ }
|
|
37
|
+ else
|
|
38
|
+ {
|
|
39
|
+ //load secondary palette compressed
|
|
40
|
+ LZ77UnCompWram(blockset->palettes, dns_buffer);
|
|
41
|
+
|
|
42
|
+ dns_modify_palette(&dns_buffer[DNS_SEC_PAL_START_C], size/2);
|
|
43
|
+
|
|
44
|
+ gpu_pal_apply(&dns_buffer[DNS_SEC_PAL_START_C], offset, size);
|
|
45
|
+ load_palette3(offset,size/2);
|
|
46
|
+
|
|
47
|
+ }
|
|
48
|
+ }
|
|
49
|
+ else
|
|
50
|
+ {
|
|
51
|
+ union Color black;
|
|
52
|
+ black.packed = 0x0000;
|
|
53
|
+ gpu_pal_apply(&black, 0, 2);
|
|
54
|
+ memcpy(dns_buffer, blockset->palettes, size);
|
|
55
|
+ dns_modify_palette(dns_buffer, size/2);
|
|
56
|
+ gpu_pal_apply(&dns_buffer[1], offset+1, size-2);
|
|
57
|
+ load_palette3(offset+1, (size-2)/2);
|
|
58
|
+ //load primary palette
|
|
59
|
+
|
|
60
|
+ }
|
|
61
|
+ free(dns_buffer);
|
|
62
|
+ }
|
|
63
|
+}
|
|
64
|
+
|
|
65
|
+void dns_oec01_load_pal_impl(u32 *oe_script) {
|
|
66
|
+ struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
|
|
67
|
+ struct SpritePalette palToApply = {
|
|
68
|
+ .data = NULL,
|
|
69
|
+ .tag = pal->tag
|
|
70
|
+ };
|
|
71
|
+ u8 idx = gpu_pal_tags_index_of(palToApply.tag);
|
|
72
|
+
|
|
73
|
+ union Color *buffer = malloc(32);
|
|
74
|
+ memcpy(buffer, pal->data, 32);
|
|
75
|
+ dns_modify_palette(buffer, 16);
|
|
76
|
+ palToApply.data = buffer;
|
|
77
|
+
|
|
78
|
+ gpu_pal_obj_alloc_tag_and_apply(&palToApply);
|
|
79
|
+ if(idx == 0xFF) {
|
|
80
|
+ u8 idx = gpu_pal_tags_index_of(palToApply.tag);
|
|
81
|
+ tint_palette_switch(idx);
|
|
82
|
+ }
|
|
83
|
+ idx = gpu_pal_tags_index_of(palToApply.tag);
|
|
84
|
+ free(buffer);
|
|
85
|
+ palette_obj_807AA8C(idx);
|
|
86
|
+ *oe_script += 4;
|
|
87
|
+}
|
|
88
|
+
|
|
89
|
+void dns_oec02_load_pal_impl(u32 *oe_script) {
|
|
90
|
+ struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
|
|
91
|
+ struct SpritePalette palToApply = {
|
|
92
|
+ .data = NULL,
|
|
93
|
+ .tag = pal->tag
|
|
94
|
+ };
|
|
95
|
+ u8 idx = gpu_pal_tags_index_of(palToApply.tag);
|
|
96
|
+
|
|
97
|
+ union Color *buffer = malloc(32);
|
|
98
|
+ memcpy(buffer, pal->data, 32);
|
|
99
|
+ dns_modify_palette(buffer, 16);
|
|
100
|
+ palToApply.data = buffer;
|
|
101
|
+
|
|
102
|
+ gpu_pal_obj_alloc_tag_and_apply(&palToApply);
|
|
103
|
+ if(idx == 0xFF) {
|
|
104
|
+ u8 idx = gpu_pal_tags_index_of(palToApply.tag);
|
|
105
|
+ tint_palette_switch(idx);
|
|
106
|
+ }
|
|
107
|
+ free(buffer);
|
|
108
|
+ *oe_script += 4;
|
|
109
|
+}
|
|
110
|
+
|
|
111
|
+void dns_pal_patch_for_npc(u16 tag, u8 idx)
|
|
112
|
+{
|
|
113
|
+ extern struct SpritePalette ow_pal_table[1100];
|
|
114
|
+ u16 npcPalIdx = hacked_npc_pal_idx_for_given_tag(tag);
|
|
115
|
+ union Color *buffer = malloc(32);
|
|
116
|
+ memcpy(buffer, ow_pal_table[npcPalIdx].data,32);
|
|
117
|
+ dns_modify_palette(buffer,16);
|
|
118
|
+ gpu_pal_apply(buffer, 256 + 16*idx, 32);
|
|
119
|
+
|
|
120
|
+ free(buffer);
|
|
121
|
+ tint_palette_switch(idx);
|
|
122
|
+}
|
|
123
|
+
|
|
124
|
+void dns_modify_palette(union Color* buffer, u16 size){
|
|
125
|
+ if(current_map_header.light == 8)
|
|
126
|
+ return;
|
|
127
|
+ for(u16 i = 0; i < size; ++i) {
|
|
128
|
+ buffer[i] = dns_color_multiply(dns_color_times[0], buffer[i]);
|
|
129
|
+ }
|
|
130
|
+}
|
|
131
|
+
|
|
132
|
+union Color dns_color_multiply(union Color a, union Color b) {
|
|
133
|
+ u32 red = (a.components.r * b.components.r) / 31;
|
|
134
|
+ u32 green = (a.components.g * b.components.g) / 31;
|
|
135
|
+ u32 blue = (a.components.b * b.components.b) / 31;
|
|
136
|
+ return crgb5(red,green,blue);
|
|
137
|
+}
|