Browse Source

day and night core

SBird1337 8 years ago
parent
commit
7bdcda9b9e

+ 12
- 0
bpre.sym View File

5
 vblank_handler_set = 0x080006F5;
5
 vblank_handler_set = 0x080006F5;
6
 malloc = 0x08002BB0|1;
6
 malloc = 0x08002BB0|1;
7
 free = 0x08002BC4|1;
7
 free = 0x08002BC4|1;
8
+memmove = 0x081E8E60|1;
8
 memset = 0x081E5ED8|1;
9
 memset = 0x081E5ED8|1;
9
 memcpy = 0x081E5E78|1;
10
 memcpy = 0x081E5E78|1;
10
 template_instanciate_forward_search = 0x08006F8D;
11
 template_instanciate_forward_search = 0x08006F8D;
26
 calc_circle = 0x0807EE2C|1;
27
 calc_circle = 0x0807EE2C|1;
27
 random = 0x08044EC8|1;
28
 random = 0x08044EC8|1;
28
 
29
 
30
+palette_unfaded_buffer = 0x020371F8;
31
+palette_faded_buffer = 0x020375F8;
32
+current_mapheader = 0x02036DFC;
33
+
34
+blockset_load_palette_to_gpu = 0x080599C8|1;
35
+npc_pal_idx_for_given_tag = 0x0805F5A0|1;
36
+gpu_pal_apply = 0x080703EC|1;
37
+tint_palette = 0x08083598|1;
38
+tint_filter = 0x02036E28;
39
+gpu_pal_tags_index_of = 0x080089E8|1;
40
+
29
 vram_decompress = 0x081E3B6C|1;
41
 vram_decompress = 0x081E3B6C|1;
30
 pal_decompress_slice_to_faded_and_unfaded = 0x080703A8|1;
42
 pal_decompress_slice_to_faded_and_unfaded = 0x080703A8|1;
31
 gpu_tile_obj_decompress_alloc_tag_and_upload = 0x0800F035;
43
 gpu_tile_obj_decompress_alloc_tag_and_upload = 0x0800F035;

+ 5
- 1
data/overworld/overworld_pal_table.S View File

1539
 .word ow_00000Pal
1539
 .word ow_00000Pal
1540
 .byte 254, 19, 0, 0
1540
 .byte 254, 19, 0, 0
1541
 .word ow_00000Pal
1541
 .word ow_00000Pal
1542
-.byte 255, 19, 0, 0
1542
+.byte 255, 19, 0, 0
1543
+
1544
+.global npc_palettes
1545
+npc_palettes:
1546
+    .word ow_pal_table

+ 2
- 0
main.asm View File

32
 .include "patches/pokemon_data/pokemon_icons.asm"
32
 .include "patches/pokemon_data/pokemon_icons.asm"
33
 .include "patches/pokemon_data/pokemon_habitats.asm"
33
 .include "patches/pokemon_data/pokemon_habitats.asm"
34
 
34
 
35
+.include "patches/dns/core.asm"
36
+
35
 .include "patches/overworlds/overworld.asm"
37
 .include "patches/overworlds/overworld.asm"
36
 
38
 
37
 .include "patches/battle_engine/malloc.asm"
39
 .include "patches/battle_engine/malloc.asm"

+ 10
- 0
nbproject/configurations.xml View File

3767
           <in>battle_engine.asm</in>
3767
           <in>battle_engine.asm</in>
3768
           <in>malloc.asm</in>
3768
           <in>malloc.asm</in>
3769
         </df>
3769
         </df>
3770
+        <df name="dns">
3771
+          <in>core.asm</in>
3772
+        </df>
3770
         <df name="items">
3773
         <df name="items">
3771
           <in>item_limits.asm</in>
3774
           <in>item_limits.asm</in>
3772
           <in>item_routines.asm</in>
3775
           <in>item_routines.asm</in>
4617
         <df name="debug">
4620
         <df name="debug">
4618
           <in>debug.c</in>
4621
           <in>debug.c</in>
4619
         </df>
4622
         </df>
4623
+        <df name="dns">
4624
+          <in>dns_core.c</in>
4625
+        </df>
4620
         <df name="encode">
4626
         <df name="encode">
4621
           <in>crc32.c</in>
4627
           <in>crc32.c</in>
4622
         </df>
4628
         </df>
23509
       </item>
23515
       </item>
23510
       <item path="patches/disable_cry_table_blocks.s" ex="false" tool="4" flavor2="0">
23516
       <item path="patches/disable_cry_table_blocks.s" ex="false" tool="4" flavor2="0">
23511
       </item>
23517
       </item>
23518
+      <item path="patches/dns/core.asm" ex="false" tool="4" flavor2="0">
23519
+      </item>
23512
       <item path="patches/dynamic_overworld_hooks.asm"
23520
       <item path="patches/dynamic_overworld_hooks.asm"
23513
             ex="false"
23521
             ex="false"
23514
             tool="4"
23522
             tool="4"
27354
       </item>
27362
       </item>
27355
       <item path="src/debug/debug.c" ex="false" tool="0" flavor2="0">
27363
       <item path="src/debug/debug.c" ex="false" tool="0" flavor2="0">
27356
       </item>
27364
       </item>
27365
+      <item path="src/dns/dns_core.c" ex="false" tool="0" flavor2="0">
27366
+      </item>
27357
       <item path="src/encode/crc32.c" ex="false" tool="0" flavor2="0">
27367
       <item path="src/encode/crc32.c" ex="false" tool="0" flavor2="0">
27358
       </item>
27368
       </item>
27359
       <item path="src/include/battle_abilities.h" ex="false" tool="3" flavor2="0">
27369
       <item path="src/include/battle_abilities.h" ex="false" tool="3" flavor2="0">

+ 8
- 0
nbproject/private/configurations.xml View File

4279
           </df>
4279
           </df>
4280
           <df name="debug">
4280
           <df name="debug">
4281
           </df>
4281
           </df>
4282
+          <df name="dns">
4283
+          </df>
4282
           <df name="encode">
4284
           <df name="encode">
4283
           </df>
4285
           </df>
4284
           <df name="include">
4286
           <df name="include">
4370
           <in>battle_engine.asm</in>
4372
           <in>battle_engine.asm</in>
4371
           <in>malloc.asm</in>
4373
           <in>malloc.asm</in>
4372
         </df>
4374
         </df>
4375
+        <df name="dns">
4376
+          <in>core.asm</in>
4377
+        </df>
4373
         <df name="items">
4378
         <df name="items">
4374
           <in>item_limits.asm</in>
4379
           <in>item_limits.asm</in>
4375
           <in>item_routines.asm</in>
4380
           <in>item_routines.asm</in>
6027
         <df name="debug">
6032
         <df name="debug">
6028
           <in>debug.c</in>
6033
           <in>debug.c</in>
6029
         </df>
6034
         </df>
6035
+        <df name="dns">
6036
+          <in>dns_core.c</in>
6037
+        </df>
6030
         <df name="encode">
6038
         <df name="encode">
6031
           <in>crc32.c</in>
6039
           <in>crc32.c</in>
6032
         </df>
6040
         </df>

+ 14
- 0
patches/dns/core.asm View File

1
+.org 0x08059A90
2
+    ldr r3, =mapdata_load_palette_one+1
3
+    bx r3
4
+    .pool
5
+
6
+.org 0x08059AA0
7
+    ldr r3, =mapdata_load_palette_two+1
8
+    bx r3
9
+    .pool
10
+
11
+.org 0x0805F538
12
+    ldr r2, =pal_patch_for_npc+1
13
+    bx r2
14
+    .pool

+ 190
- 0
src/dns/dns_core.c View File

1
+#include <bpre.h>
2
+
3
+enum time_type {
4
+    DAY,
5
+    NIGHT
6
+};
7
+
8
+enum map_type {
9
+    UNK_00,
10
+    VILLAGE,
11
+    CITY,
12
+    ROUTE,
13
+    CELLAR,
14
+    UNDERWATER,
15
+    UNK_07,
16
+    UNK_08,
17
+    INSIDE,
18
+    SECRET_BASE
19
+};
20
+
21
+struct mapdata_header {
22
+    u32 width;
23
+    u32 height;
24
+    void* border;
25
+    void* data;
26
+    void* blockset_one;
27
+    void* blockset_two;
28
+    u8 border_width;
29
+    u8 border_height;
30
+    u16 unknown;
31
+};
32
+
33
+struct mapheader {
34
+    struct mapdata_header* data_header;
35
+    void* events;
36
+    void* scripts;
37
+    void* connections;
38
+    u16 music;
39
+    u16 mapindex;
40
+    u8 name;
41
+    u8 cave;
42
+    u8 weather;
43
+    enum map_type maptype;
44
+    u8 field18;
45
+    u8 escape_rope;
46
+    u8 showname;
47
+    u8 battletype;
48
+};
49
+
50
+extern struct mapheader current_mapheader;
51
+
52
+struct color_shade {
53
+    struct color color;
54
+    u8 alpha;
55
+};
56
+
57
+struct npc_palette {
58
+    struct color* palette;
59
+    u16 tag;
60
+    u16 fill;
61
+};
62
+
63
+struct pal_replace {
64
+    void* blockset;
65
+    u8 pal;
66
+    u8 index;
67
+    struct color color;
68
+};
69
+
70
+extern struct npc_palette* npc_palettes;
71
+extern volatile u8 tint_filter;
72
+void apply_shaders(u8 pal, u8 fade_copy);
73
+struct color alpha_blend(struct color a, struct color b, u8 alpha);
74
+extern void blockset_load_palette_to_gpu(void* blockset, u16 start, u16 len);
75
+extern void gpu_pal_apply(struct color* src, u16 dst, u16 len);
76
+extern void tint_palette(u8 pal_slot);
77
+extern u8 gpu_pal_tags_index_of(u16 pal_tag);
78
+void copy_unfaded(u8 slot);
79
+u8 is_current_map_dn_valid(enum map_type current_type);
80
+//care, this has to be manually patched to be u16
81
+extern u16 npc_pal_idx_for_given_tag(u16 tag);
82
+struct color_shade get_color_from_time(enum time_type current_time);
83
+enum time_type get_time_of_day();
84
+void apply_lighting(void* blockset, u8 copy);
85
+
86
+enum time_type get_time_of_day() {
87
+    return NIGHT;
88
+}
89
+
90
+static struct pal_replace lightmap[] = {
91
+    {(void*) 0x082D4AAC, 9, 10, {31, 31, 0}},
92
+    {(void*) 0x082D4AAC, 9, 9, {31, 31, 0}},
93
+    {(void*) 0x082D4AAC, 9, 8, {31, 31, 0}}
94
+};
95
+
96
+static struct color_shade color_shade_day = {
97
+    {0, 0, 0}, 255
98
+};
99
+static struct color_shade color_shade_night = {
100
+    {0, 6, 16}, 120
101
+};
102
+
103
+void mapdata_load_palette_two(struct mapdata_header* data_header) {
104
+    blockset_load_palette_to_gpu(data_header->blockset_two, 0x70, 0xC0);
105
+    for (u8 i = 7; i < 7 + 6; ++i)
106
+        apply_shaders(i, 0);
107
+    apply_lighting(data_header->blockset_two, 0);
108
+    return;
109
+}
110
+
111
+void mapdata_load_palette_one(struct mapdata_header* data_header) {
112
+    blockset_load_palette_to_gpu(data_header->blockset_one, 0x0, 0xE0);
113
+    for (u8 i = 0; i < 7; ++i)
114
+        apply_shaders(i, 0);
115
+    apply_lighting(data_header->blockset_one, 0);
116
+    return;
117
+}
118
+
119
+void apply_lighting(void* blockset, u8 copy) 
120
+{
121
+    for (int i = 0; i < (sizeof (lightmap) / sizeof (lightmap[0])); ++i) {
122
+        if (blockset == lightmap[i].blockset) {
123
+            palette_unfaded_buffer[lightmap[i].pal * 16 + lightmap[i].index] = lightmap[i].color;
124
+        }
125
+    }
126
+    return;
127
+}
128
+
129
+void apply_shaders(u8 pal, u8 fade_copy) {
130
+    if (tint_filter != 0)
131
+        return;
132
+    if (!is_current_map_dn_valid(current_mapheader.maptype))
133
+        return;
134
+    for (int i = pal * 16; i < (pal * 16) + 16; ++i) {
135
+        struct color_shade current_shade = get_color_from_time(get_time_of_day());
136
+        palette_unfaded_buffer[i] = alpha_blend(palette_unfaded_buffer[i], current_shade.color, current_shade.alpha);
137
+    }
138
+    if (fade_copy)
139
+        copy_unfaded(pal);
140
+}
141
+
142
+void copy_unfaded(u8 slot) {
143
+    for (int i = slot * 16; i < (slot * 16) + 16; ++i) {
144
+        palette_faded_buffer[i] = palette_unfaded_buffer[i];
145
+    }
146
+}
147
+
148
+u8 is_current_map_dn_valid(enum map_type current_type) {
149
+    switch (current_type) {
150
+        case VILLAGE:
151
+        case CITY:
152
+        case ROUTE:
153
+            return 1;
154
+        default:
155
+            return 0;
156
+    }
157
+    return 0;
158
+}
159
+
160
+struct color_shade get_color_from_time(enum time_type current_time) {
161
+    switch (current_time) {
162
+        case NIGHT:
163
+            return color_shade_night;
164
+        case DAY:
165
+        default:
166
+            return color_shade_day;
167
+    }
168
+}
169
+
170
+struct color alpha_blend(struct color a, struct color b, u8 alpha) {
171
+    if (alpha == 255)
172
+        return a;
173
+    if (alpha == 0)
174
+        return b;
175
+    struct color output;
176
+    u8 inverted_alpha = 255 - alpha;
177
+
178
+    output.r = ((a.r * alpha + b.r * inverted_alpha) / 255);
179
+    output.b = ((a.b * alpha + b.b * inverted_alpha) / 255);
180
+    output.g = ((a.g * alpha + b.g * inverted_alpha) / 255);
181
+    return output;
182
+}
183
+
184
+void pal_patch_for_npc(u16 tag, u8 pal_slot) {
185
+    u16 npc_map_entry = npc_pal_idx_for_given_tag(tag);
186
+    gpu_pal_apply(npc_palettes[npc_map_entry].palette, (pal_slot + 16) * 16, 32);
187
+    tint_palette(pal_slot);
188
+    apply_shaders(pal_slot + 16, 1);
189
+}
190
+/*use fade in animation, load palettes according to current fade state*/

+ 1
- 0
src/include/bpre.h View File

8
 #include <callback.h>
8
 #include <callback.h>
9
 #include <config.h>
9
 #include <config.h>
10
 #include <pkmn_attributes.h>
10
 #include <pkmn_attributes.h>
11
+#include <battle_structs.h>
11
 
12
 
12
 u32 __aeabi_uidivmod(u32 a, u32 b);
13
 u32 __aeabi_uidivmod(u32 a, u32 b);
13
 u16 *var_access(int index);
14
 u16 *var_access(int index);

+ 10
- 4
src/include/lcd.h View File

19
     u16 pal : 4;
19
     u16 pal : 4;
20
 };
20
 };
21
 
21
 
22
-union t_map_entry{
22
+union t_map_entry {
23
     u16 short_map;
23
     u16 short_map;
24
     struct map_entry entry;
24
     struct map_entry entry;
25
 };
25
 };
26
 
26
 
27
+struct color {
28
+    u16 r : 5;
29
+    u16 g : 5;
30
+    u16 b : 5;
31
+};
32
+
27
 static struct bg_config standard_bg[4] = {
33
 static struct bg_config standard_bg[4] = {
28
     {0, 0, 0x19, 0, 0, 0},
34
     {0, 0, 0x19, 0, 0, 0},
29
     {1, 1, 0x1A, 0, 0, 1},
35
     {1, 1, 0x1A, 0, 0, 1},
49
 void gpu_pal_upload();
55
 void gpu_pal_upload();
50
 void gpu_sprites_upload();
56
 void gpu_sprites_upload();
51
 
57
 
52
-void gpu_pal_obj_alloc_tag_and_apply(resource *pal);
58
+u8 gpu_pal_obj_alloc_tag_and_apply(resource *pal);
53
 void gpu_pal_free_by_tag(u16 tag);
59
 void gpu_pal_free_by_tag(u16 tag);
54
 void gpu_tile_obj_free_by_tag(u16 tag);
60
 void gpu_tile_obj_free_by_tag(u16 tag);
55
 void obj_delete_and_free_tiles(object *obj);
61
 void obj_delete_and_free_tiles(object *obj);
57
 
63
 
58
 u16 lcd_io_get(u8 id);
64
 u16 lcd_io_get(u8 id);
59
 
65
 
60
-#define palette_unfaded_buffer ((void*)0x020371F8)
61
-#define palette_faded_buffer ((void*)0x020375F8)
66
+#define palette_faded_buffer ((struct color*) 0x020375F8)
67
+#define palette_unfaded_buffer ((struct color*) 0x020371F8)
62
 
68
 
63
 #endif
69
 #endif