Browse Source

even more refractoring and documentation

SBird1337 8 years ago
parent
commit
e87d4f3444

+ 8
- 8
bpre.sym View File

10
 memcpy = 0x081E5E78|1;
10
 memcpy = 0x081E5E78|1;
11
 obj_template_instanciate_forward_search = 0x08006F8D;
11
 obj_template_instanciate_forward_search = 0x08006F8D;
12
 gpu_copy_to_vram_by_bgid = 0x08001298|1;
12
 gpu_copy_to_vram_by_bgid = 0x08001298|1;
13
-bg_set_tilemap = 0x08001FA0|1;
14
-bg_nullify_tilemap = 0x08001FD4|1;
15
-bg_get_tilemap = 0x08002008|1;
16
-bg_send_tilemap = 0x080020BC|1;
13
+virtual_bg_set_tilemap = 0x08001FA0|1;
14
+virtual_bg_nullify_tilemap = 0x08001FD4|1;
15
+virtual_bg_get_tilemap = 0x08002008|1;
16
+virtual_bg_send_tilemap = 0x080020BC|1;
17
 gpu_init_bgs = 0x08001028|1;
17
 gpu_init_bgs = 0x08001028|1;
18
 gpu_tile_bg_drop_all_sets = 0x08001618|1;
18
 gpu_tile_bg_drop_all_sets = 0x08001618|1;
19
-bg_vram_setup = 0x08001658|1;
19
+gpu_bg_vram_setup = 0x08001658|1;
20
 gpu_bg_show = 0x08001320|1;
20
 gpu_bg_show = 0x08001320|1;
21
 gpu_bg_hide = 0x0800139C|1;
21
 gpu_bg_hide = 0x0800139C|1;
22
 gpu_sync_bg_visibility_and_mode = 0x080013D0|1;
22
 gpu_sync_bg_visibility_and_mode = 0x080013D0|1;
85
 objc_exec = 0x08006B5D;
85
 objc_exec = 0x08006B5D;
86
 obj_sync = 0x08006BA9;
86
 obj_sync = 0x08006BA9;
87
 
87
 
88
-clear_flag = 0x0806E6A9;
88
+flag_clear = 0x0806E6A9;
89
 
89
 
90
 divide = 0x081E4018;
90
 divide = 0x081E4018;
91
 
91
 
141
 party_player = 0x02024284;
141
 party_player = 0x02024284;
142
 party_opponent = 0x0202402C;
142
 party_opponent = 0x0202402C;
143
 
143
 
144
-get_attributes = 0x0803FBE8|1;
145
-set_attributes = 0x0804037C|1;
144
+pokemon_get_attribute = 0x0803FBE8|1;
145
+pokemon_set_attribute = 0x0804037C|1;
146
 
146
 
147
 
147
 
148
 battle_status3_bits_pbs = 0x02023DFC;
148
 battle_status3_bits_pbs = 0x02023DFC;

+ 6
- 0
nbproject/configurations.xml View File

4632
           <in>battle_test.h</in>
4632
           <in>battle_test.h</in>
4633
           <in>debug.h</in>
4633
           <in>debug.h</in>
4634
           <in>dns_core.h</in>
4634
           <in>dns_core.h</in>
4635
+          <in>game_engine.h</in>
4635
           <in>item_effects.h</in>
4636
           <in>item_effects.h</in>
4636
           <in>items.h</in>
4637
           <in>items.h</in>
4638
+          <in>math.h</in>
4637
           <in>memory.h</in>
4639
           <in>memory.h</in>
4638
           <in>oe_animation.h</in>
4640
           <in>oe_animation.h</in>
4639
           <in>pkmn_attributes.h</in>
4641
           <in>pkmn_attributes.h</in>
27380
       </item>
27382
       </item>
27381
       <item path="src/include/dns_core.h" ex="false" tool="3" flavor2="0">
27383
       <item path="src/include/dns_core.h" ex="false" tool="3" flavor2="0">
27382
       </item>
27384
       </item>
27385
+      <item path="src/include/game_engine.h" ex="false" tool="3" flavor2="0">
27386
+      </item>
27383
       <item path="src/include/item_effects.h" ex="false" tool="3" flavor2="0">
27387
       <item path="src/include/item_effects.h" ex="false" tool="3" flavor2="0">
27384
       </item>
27388
       </item>
27385
       <item path="src/include/items.h" ex="false" tool="3" flavor2="0">
27389
       <item path="src/include/items.h" ex="false" tool="3" flavor2="0">
27386
       </item>
27390
       </item>
27391
+      <item path="src/include/math.h" ex="false" tool="3" flavor2="0">
27392
+      </item>
27387
       <item path="src/include/memory.h" ex="false" tool="3" flavor2="0">
27393
       <item path="src/include/memory.h" ex="false" tool="3" flavor2="0">
27388
       </item>
27394
       </item>
27389
       <item path="src/include/oe_animation.h" ex="false" tool="3" flavor2="0">
27395
       <item path="src/include/oe_animation.h" ex="false" tool="3" flavor2="0">

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

6063
           <in>debug.h</in>
6063
           <in>debug.h</in>
6064
           <in>dns_core.h</in>
6064
           <in>dns_core.h</in>
6065
           <in>fade.h</in>
6065
           <in>fade.h</in>
6066
+          <in>game_engine.h</in>
6066
           <in>item_effects.h</in>
6067
           <in>item_effects.h</in>
6067
           <in>items.h</in>
6068
           <in>items.h</in>
6068
           <in>lcd.h</in>
6069
           <in>lcd.h</in>
6070
+          <in>math.h</in>
6069
           <in>memory.h</in>
6071
           <in>memory.h</in>
6070
           <in>moves.h</in>
6072
           <in>moves.h</in>
6071
           <in>objects.h</in>
6073
           <in>objects.h</in>

+ 1
- 1
src/battle_engine/battle_help.c View File

131
     u8 usable_pokes = 0;
131
     u8 usable_pokes = 0;
132
     for (u8 i = 0; i < 6; i ++)
132
     for (u8 i = 0; i < 6; i ++)
133
     {
133
     {
134
-        if (get_attributes(&poke[i], ATTR_CURRENT_HP, 0) != 0 && get_attributes(&poke[i], ATTR_IS_EGG, 0) != 1 && get_attributes(&poke[i], ATTR_SPECIES, 0) != 0)
134
+        if (pokemon_get_attribute(&poke[i], ATTR_CURRENT_HP, 0) != 0 && pokemon_get_attribute(&poke[i], ATTR_IS_EGG, 0) != 1 && pokemon_get_attribute(&poke[i], ATTR_SPECIES, 0) != 0)
135
             usable_pokes++;
135
             usable_pokes++;
136
     }
136
     }
137
     return usable_pokes;
137
     return usable_pokes;

+ 1
- 1
src/debug/debug.c View File

19
         gpu_tile_bg_drop_all_sets(2);
19
         gpu_tile_bg_drop_all_sets(2);
20
         gpu_tile_bg_drop_all_sets(3);
20
         gpu_tile_bg_drop_all_sets(3);
21
 
21
 
22
-        bg_vram_setup(0, standard_bg, 4);
22
+        gpu_bg_vram_setup(0, standard_bg, 4);
23
 
23
 
24
         gpu_bg_show(0);
24
         gpu_bg_show(0);
25
         gpu_bg_show(1);
25
         gpu_bg_show(1);

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

10
 #include <pkmn_attributes.h>
10
 #include <pkmn_attributes.h>
11
 #include <battle_structs.h>
11
 #include <battle_structs.h>
12
 
12
 
13
-u32 __aeabi_uidivmod(u32 a, u32 b);
14
-u16 *var_access(int index);
15
-u8 flag_check(int flag);
16
-void clear_flag(u16 flag);
17
-u16 random();
18
-void* malloc(int size);
19
-void free(void* address);
20
-void* memcpy (void * destination, const void* source, size_t num);
21
-void* memset (void* dst, int value, size_t size);
22
-
23
 //debug
13
 //debug
24
 /*void agbprintf(const char* pBuf, ...);
14
 /*void agbprintf(const char* pBuf, ...);
25
 void agbprint_flush();
15
 void agbprint_flush();
37
 
27
 
38
 
28
 
39
 //attribute setter and getter
29
 //attribute setter and getter
40
-u8 get_attributes(struct pokemon* poke_address, u8 request, void* destination);
41
-void set_attributes(struct pokemon* poke_address, u8 request, void* new_value);
30
+
42
 
31
 
43
 #endif
32
 #endif

+ 80
- 0
src/include/game_engine.h View File

1
+/****************************************************************************
2
+ * Copyright (C) 2015-2016 by the SotS Team                                 *
3
+ *                                                                          *
4
+ * This file is part of Sovereign of the Skies.                             *
5
+ *                                                                          *
6
+ *   Sovereign of the Skies is free software: you can redistribute it       *
7
+ *   and/or modify it                                                       *
8
+ *   under the terms of the GNU Lesser General Public License as published  *
9
+ *   by the Free Software Foundation, either version 3 of the License, or   *
10
+ *   (at your option) any later version provided you include a copy of the  *
11
+ *   licence and this header.                                               *
12
+ *                                                                          *
13
+ *   Sovereign of the Skies is distributed in the hope that it will be      *
14
+ *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
16
+ *   GNU Lesser General Public License for more details.                    *
17
+ *                                                                          *
18
+ *   You should have received a copy of the GNU Lesser General Public       *
19
+ *   License along with Sovereign of the Skies.                             *
20
+ *   If not, see <http://www.gnu.org/licenses/>.                            *
21
+ ****************************************************************************/
22
+
23
+/**
24
+ * @file game_engine.h
25
+ * @author Sturmvogel
26
+ * @date 15 dec 2016
27
+ * @brief Game Environment
28
+ * 
29
+ * This header file contains methods to interact with the game environment,
30
+ * misc. functions i.e. access to flags / variables and (encrypted) pokémon
31
+ * data.
32
+ */
33
+
34
+#ifndef GAME_ENGINE_H
35
+#define GAME_ENGINE_H
36
+
37
+/* === INCLUDE === */
38
+#include <types.h>
39
+
40
+/* === EXTERN METHODS === */
41
+
42
+/**
43
+ * @brief get pointer of var
44
+ * @param index variable to access
45
+ * @return pointer to given variable storage
46
+ */
47
+extern u16 *var_access(u32 index);
48
+
49
+/**
50
+ * @brief checks if flag is set
51
+ * @param flag index of flag to check
52
+ * @return flag status (bool)
53
+ */
54
+extern u8 flag_check(u32 flag);
55
+
56
+/**
57
+ * @brief clears a flag
58
+ * @param flag flag index to clear
59
+ */
60
+extern void flag_clear(u16 flag);
61
+
62
+/**
63
+ * @brief gets attribute of pokémon
64
+ * @param poke_address address to pokémon structure
65
+ * @param request request from the attribute request table
66
+ * @param destination destination to write to (if not returned directly)
67
+ * @return requested value (if not too big)
68
+ */
69
+extern u32 pokemon_get_attribute(struct pokemon* poke_address, u8 request, void* destination);
70
+
71
+/**
72
+ * @brief sets attribute of pokémon
73
+ * @param poke_address address to pokémon structure
74
+ * @param request request from the attribute request table
75
+ * @param new_value pointer to new value
76
+ */
77
+void pokemon_set_attribute(struct pokemon* poke_address, u8 request, void* new_value);
78
+
79
+#endif /* GAME_ENGINE_H */
80
+

+ 139
- 11
src/include/lcd.h View File

1
+/****************************************************************************
2
+ * Copyright (C) 2015-2016 by the SotS Team                                 *
3
+ *                                                                          *
4
+ * This file is part of Sovereign of the Skies.                             *
5
+ *                                                                          *
6
+ *   Sovereign of the Skies is free software: you can redistribute it       *
7
+ *   and/or modify it                                                       *
8
+ *   under the terms of the GNU Lesser General Public License as published  *
9
+ *   by the Free Software Foundation, either version 3 of the License, or   *
10
+ *   (at your option) any later version provided you include a copy of the  *
11
+ *   licence and this header.                                               *
12
+ *                                                                          *
13
+ *   Sovereign of the Skies is distributed in the hope that it will be      *
14
+ *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
16
+ *   GNU Lesser General Public License for more details.                    *
17
+ *                                                                          *
18
+ *   You should have received a copy of the GNU Lesser General Public       *
19
+ *   License along with Sovereign of the Skies.                             *
20
+ *   If not, see <http://www.gnu.org/licenses/>.                            *
21
+ ****************************************************************************/
22
+
23
+/**
24
+ * @file lcd.h
25
+ * @author Sturmvogel
26
+ * @date 15 dec 2016
27
+ * @brief Operations on the GBA Screen
28
+ * 
29
+ * This header contains methods to manipulate and update the lcd screen,
30
+ * for interacting with the object entity engine
31
+ * @see objects.h
32
+ */
33
+
34
+
1
 #ifndef LCD_H_
35
 #ifndef LCD_H_
2
 #define LCD_H_
36
 #define LCD_H_
3
 
37
 
4
-#include "objects.h"
38
+/* === STRUCTURES === */
5
 
39
 
6
 struct bg_config {
40
 struct bg_config {
7
     u32 id : 2;
41
     u32 id : 2;
30
     u16 b : 5;
64
     u16 b : 5;
31
 };
65
 };
32
 
66
 
67
+/* === STATIC STRUCTURES === */
68
+
33
 static struct bg_config standard_bg[4] = {
69
 static struct bg_config standard_bg[4] = {
34
     {0, 0, 0x19, 0, 0, 0},
70
     {0, 0, 0x19, 0, 0, 0},
35
     {1, 1, 0x1A, 0, 0, 1},
71
     {1, 1, 0x1A, 0, 0, 1},
37
     {3, 3, 0x1C, 0, 0, 3}
73
     {3, 3, 0x1C, 0, 0, 3}
38
 };
74
 };
39
 
75
 
40
-u8 gpu_copy_to_vram_by_bgid(u8 bg_id, void* source, u16 byte_size, u16 start_tile, u8 mode);
41
-void gpu_init_bgs();
42
-void gpu_tile_bg_drop_all_sets(u8 bg);
43
-void bg_vram_setup(u8 mirror, struct bg_config* configs, u8 count);
44
-void bg_set_tilemap(u8 bg_id, void* tilemap);
45
-void bg_nullify_tilemap(u8 bg_id);
46
-void* bg_get_tilemap(u8 bg_id);
47
-void bg_send_tilemap(u8 bg_id);
48
-void wram_decompress(void* src, void* dst);
49
-void vram_decompress(void* src, void* dst);
76
+/* === EXTERN METHODS === */
77
+
78
+/**
79
+ * @brief copy tileset or tilemap to bg
80
+ * @param bg_id bg id to copy tileset to
81
+ * @param source tileset source
82
+ * @param byte_size tileset size
83
+ * @param start_tile start tile to copy to
84
+ * @param mode 1 = copy tileset 2 = copy tilemap
85
+ * @return 
86
+ */
87
+extern u8 gpu_copy_to_vram_by_bgid(u8 bg_id, void* source, u16 byte_size, u16 start_tile, u8 mode);
88
+
89
+/**
90
+ * @brief reset bg configs and init bgs
91
+ */
92
+extern void gpu_init_bgs();
93
+
94
+/**
95
+ * @brief drop all tilesets from bg ( ? )
96
+ * @param bg background to drop tilesets from
97
+ */
98
+extern void gpu_tile_bg_drop_all_sets(u8 bg);
99
+
100
+/**
101
+ * @setup bg vram
102
+ * @param mirror not so sure about that
103
+ * @param configs pointer to config array (4 entries)
104
+ * @param count number of entries
105
+ */
106
+extern void gpu_bg_vram_setup(u8 mirror, struct bg_config* configs, u8 count);
107
+
108
+/**
109
+ * @brief set tilemap of bg in the bg structure
110
+ * @param bg_id bg to set tilemap for
111
+ * @param tilemap pointer to tilemap
112
+ */
113
+extern void virtual_bg_set_tilemap(u8 bg_id, void* tilemap);
114
+
115
+/**
116
+ * @brief set tilemap of bg to NULL in bg structure
117
+ * @param bg_id bg to set tilemap for
118
+ */
119
+extern void virtual_bg_nullify_tilemap(u8 bg_id);
120
+
121
+/**
122
+ * @brief get tilemap of bg in bg structure
123
+ * @param bg_id bg to get tilemap for
124
+ * @return pointer to tilemap, might be null
125
+ */
126
+extern void* virtual_bg_get_tilemap(u8 bg_id);
127
+
128
+/**
129
+ * @brief sends virtual tilemap to vram
130
+ * @param bg_id bg id to send tilemap for
131
+ */
132
+extern void virtual_bg_send_tilemap(u8 bg_id);
133
+
134
+
135
+/**
136
+ * @brief decompress palette and copy to f/u buffers
137
+ * @param src palette source (lz compressed)
138
+ * @param start palette start (in bytes)
139
+ * @param end palette count (in entries, I think)
140
+ */
50
 void pal_decompress_slice_to_faded_and_unfaded(void* src, u16 start, u16 end);
141
 void pal_decompress_slice_to_faded_and_unfaded(void* src, u16 start, u16 end);
142
+
143
+/**
144
+ * @brief show bg
145
+ * @param id bg id
146
+ */
51
 void gpu_bg_show(u8 id);
147
 void gpu_bg_show(u8 id);
148
+
149
+/**
150
+ * @brief hide bg
151
+ * @param id bg id
152
+ */
52
 void gpu_bg_hide(u8 id);
153
 void gpu_bg_hide(u8 id);
154
+
155
+/**
156
+ * @brief sync bg visibility and mode, execute during vblank to avoid artifacts
157
+ */
53
 void gpu_sync_bg_visibility_and_mode();
158
 void gpu_sync_bg_visibility_and_mode();
159
+
160
+/**
161
+ * @brief set I/O
162
+ * @param id device ID
163
+ * @param value value to set I/O device to
164
+ */
54
 void lcd_io_set_func(u8 id, u16 value);
165
 void lcd_io_set_func(u8 id, u16 value);
166
+
167
+/**
168
+ * @brief upload palettes from buffer to palette memory
169
+ */
55
 void gpu_pal_upload();
170
 void gpu_pal_upload();
171
+
172
+/**
173
+ * @brief free pal tag
174
+ * @param tag tag to free
175
+ */
56
 void gpu_pal_free_by_tag(u16 tag);
176
 void gpu_pal_free_by_tag(u16 tag);
57
 
177
 
178
+/**
179
+ * @brief get from I/O
180
+ * @param id device ID
181
+ * @return I/O value
182
+ */
58
 u16 lcd_io_get(u8 id);
183
 u16 lcd_io_get(u8 id);
59
 
184
 
185
+/* === MACROS AND DEFINES === */
186
+
187
+/* TODO: Implement without macros */
60
 #define palette_faded_buffer ((struct color*) 0x020375F8)
188
 #define palette_faded_buffer ((struct color*) 0x020375F8)
61
 #define palette_unfaded_buffer ((struct color*) 0x020371F8)
189
 #define palette_unfaded_buffer ((struct color*) 0x020371F8)
62
 
190
 

+ 53
- 0
src/include/math.h View File

1
+/****************************************************************************
2
+ * Copyright (C) 2015-2016 by the SotS Team                                 *
3
+ *                                                                          *
4
+ * This file is part of Sovereign of the Skies.                             *
5
+ *                                                                          *
6
+ *   Sovereign of the Skies is free software: you can redistribute it       *
7
+ *   and/or modify it                                                       *
8
+ *   under the terms of the GNU Lesser General Public License as published  *
9
+ *   by the Free Software Foundation, either version 3 of the License, or   *
10
+ *   (at your option) any later version provided you include a copy of the  *
11
+ *   licence and this header.                                               *
12
+ *                                                                          *
13
+ *   Sovereign of the Skies is distributed in the hope that it will be      *
14
+ *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
16
+ *   GNU Lesser General Public License for more details.                    *
17
+ *                                                                          *
18
+ *   You should have received a copy of the GNU Lesser General Public       *
19
+ *   License along with Sovereign of the Skies.                             *
20
+ *   If not, see <http://www.gnu.org/licenses/>.                            *
21
+ ****************************************************************************/
22
+
23
+/**
24
+ * @file math.h
25
+ * @author Sturmvogel
26
+ * @date 15 dec 2016
27
+ * @brief Math Environment
28
+ * 
29
+ * This header file contains methods to interact with the math engine,
30
+ * i.e. the division / mod methods and the PRNG
31
+ */
32
+
33
+#ifndef MATH_H
34
+#define MATH_H
35
+
36
+/* === INCLUDE === */
37
+
38
+#include <types.h>
39
+
40
+/* === EXTERN METHODS === */
41
+
42
+/**
43
+ * @brief gets the a mod b
44
+ * @param a dividend
45
+ * @param b divisor
46
+ * @return a % b
47
+ */
48
+u32 __aeabi_uidivmod(u32 a, u32 b);
49
+
50
+u16 random();
51
+
52
+#endif /* MATH_H */
53
+

+ 14
- 0
src/include/memory.h View File

70
  */
70
  */
71
 extern void* memset (void* dst, int value, size_t size);
71
 extern void* memset (void* dst, int value, size_t size);
72
 
72
 
73
+/**
74
+ * @brief decompress data into wram using interrupt
75
+ * @param src data source
76
+ * @param dst data destination (must be in wram)
77
+ */
78
+extern void wram_decompress(void* src, void* dst);
79
+
80
+/**
81
+ * @brief decompress data into vram using interrupt
82
+ * @param src data source
83
+ * @param dst data destination (must be in vram)
84
+ */
85
+extern void vram_decompress(void* src, void* dst);
86
+
73
 #endif /* MEMORY_H */
87
 #endif /* MEMORY_H */
74
 
88
 

+ 1
- 1
src/include/types.h View File

23
 
23
 
24
 #define NULL 0
24
 #define NULL 0
25
 
25
 
26
-#define		rgb5(r,g,b)				(u16)( r | ( g << 5) | ( b << 10) )
26
+#define rgb5(r,g,b)                 (u16)( r | ( g << 5) | ( b << 10) )
27
 
27
 
28
 #endif
28
 #endif

+ 1
- 1
src/specials/custom_specials.c View File

14
 {
14
 {
15
   for(u16 i = 0x1000; i < 0x1800; ++i)
15
   for(u16 i = 0x1000; i < 0x1800; ++i)
16
   {
16
   {
17
-    clear_flag(i);
17
+    flag_clear(i);
18
   }
18
   }
19
 }
19
 }
20
 
20
 

+ 1
- 1
src/specials/cutscene_meteor.c View File

274
 	gpu_tile_bg_drop_all_sets(2);
274
 	gpu_tile_bg_drop_all_sets(2);
275
 	gpu_tile_bg_drop_all_sets(3);
275
 	gpu_tile_bg_drop_all_sets(3);
276
 
276
 
277
-	bg_vram_setup(0, standard_bg, 4);
277
+	gpu_bg_vram_setup(0, standard_bg, 4);
278
 
278
 
279
 	gpu_bg_show(0);
279
 	gpu_bg_show(0);
280
 	gpu_bg_show(1);
280
 	gpu_bg_show(1);