Browse Source

and more refractoring, documentation

SBird1337 8 years ago
parent
commit
21b1d2606c

+ 74
- 74
src/battle_engine/battle_test.c View File

8
 #define TEST_AMOUNT 10000
8
 #define TEST_AMOUNT 10000
9
 
9
 
10
 void test_speed() {
10
 void test_speed() {
11
-    print("Initiating Initiative Unit\nTest...\n");
11
+    debug_print("Initiating Initiative Unit\nTest...\n");
12
     u8 pass = true;
12
     u8 pass = true;
13
     battle_participants[0].spd = 10;
13
     battle_participants[0].spd = 10;
14
     battle_participants[1].spd = 11;
14
     battle_participants[1].spd = 11;
15
-    printf("bank_one.spd: %d\n", battle_participants[0].spd);
16
-    printf("bank_two.spd: %d\n", battle_participants[1].spd);
17
-    print("testing (await TWO):");
15
+    debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
16
+    debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
17
+    debug_print("testing (await TWO):");
18
     enum init_enum result = get_first_to_strike(0, 1, 0);
18
     enum init_enum result = get_first_to_strike(0, 1, 0);
19
     if (result == TWO)
19
     if (result == TWO)
20
-        print("\xFE\x1 pass\n\xFE\x0");
20
+        debug_print("\xFE\x1 pass\n\xFE\x0");
21
     else {
21
     else {
22
         pass = false;
22
         pass = false;
23
-        print("\xFE\x2 fail\n\xFE\x0");
23
+        debug_print("\xFE\x2 fail\n\xFE\x0");
24
     }
24
     }
25
     battle_participants[0].spd = 12;
25
     battle_participants[0].spd = 12;
26
-    printf("bank_one.spd: %d\n", battle_participants[0].spd);
27
-    printf("bank_two.spd: %d\n", battle_participants[1].spd);
28
-    print("testing (await ONE):");
26
+    debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
27
+    debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
28
+    debug_print("testing (await ONE):");
29
     result = get_first_to_strike(0, 1, 0);
29
     result = get_first_to_strike(0, 1, 0);
30
     if (result == ONE)
30
     if (result == ONE)
31
-        print("\xFE\x1 pass\n\xFE\x0");
31
+        debug_print("\xFE\x1 pass\n\xFE\x0");
32
     else {
32
     else {
33
         pass = false;
33
         pass = false;
34
-        print("\xFE\x2 fail\n\xFE\x0");
34
+        debug_print("\xFE\x2 fail\n\xFE\x0");
35
     }
35
     }
36
     battle_participants[0].spd = 10;
36
     battle_participants[0].spd = 10;
37
     battle_participants[1].spd = 11;
37
     battle_participants[1].spd = 11;
38
-    printf("bank_one.spd: %d\n", battle_participants[0].spd);
39
-    printf("bank_two.spd: %d\n", battle_participants[1].spd);
38
+    debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
39
+    debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
40
 
40
 
41
     //trick room
41
     //trick room
42
     custom_battle_elements.ptr->field_affecting.trick_room = 1;
42
     custom_battle_elements.ptr->field_affecting.trick_room = 1;
43
-    print("activating trick room...\n");
44
-    print("testing (await ONE):");
43
+    debug_print("activating trick room...\n");
44
+    debug_print("testing (await ONE):");
45
     result = get_first_to_strike(0, 1, 0);
45
     result = get_first_to_strike(0, 1, 0);
46
     if (result == ONE)
46
     if (result == ONE)
47
-        print("\xFE\x1 pass\n\xFE\x0");
47
+        debug_print("\xFE\x1 pass\n\xFE\x0");
48
     else {
48
     else {
49
         pass = false;
49
         pass = false;
50
-        print("\xFE\x2 fail\n\xFE\x0");
50
+        debug_print("\xFE\x2 fail\n\xFE\x0");
51
     }
51
     }
52
 
52
 
53
     battle_participants[0].spd = 12;
53
     battle_participants[0].spd = 12;
54
-    printf("bank_one.spd: %d\n", battle_participants[0].spd);
55
-    printf("bank_two.spd: %d\n", battle_participants[1].spd);
56
-    print("testing (await TWO):");
54
+    debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
55
+    debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
56
+    debug_print("testing (await TWO):");
57
     result = get_first_to_strike(0, 1, 0);
57
     result = get_first_to_strike(0, 1, 0);
58
     if (result == TWO)
58
     if (result == TWO)
59
-        print("\xFE\x1 pass\n\xFE\x0");
59
+        debug_print("\xFE\x1 pass\n\xFE\x0");
60
     else {
60
     else {
61
         pass = false;
61
         pass = false;
62
-        print("\xFE\x2 fail\n\xFE\x0");
62
+        debug_print("\xFE\x2 fail\n\xFE\x0");
63
     }
63
     }
64
 
64
 
65
     battle_participants[1].ability_id = ABILITY_STALL;
65
     battle_participants[1].ability_id = ABILITY_STALL;
66
-    print("stall test (+tr): ");
66
+    debug_print("stall test (+tr): ");
67
     result = get_first_to_strike(0, 1, 0);
67
     result = get_first_to_strike(0, 1, 0);
68
     if (result == ONE)
68
     if (result == ONE)
69
-        print("\xFE\x1 pass\n\xFE\x0");
69
+        debug_print("\xFE\x1 pass\n\xFE\x0");
70
     else {
70
     else {
71
         pass = false;
71
         pass = false;
72
-        print("\xFE\x2 fail\n\xFE\x0");
72
+        debug_print("\xFE\x2 fail\n\xFE\x0");
73
     }
73
     }
74
     custom_battle_elements.ptr->field_affecting.trick_room = 0;
74
     custom_battle_elements.ptr->field_affecting.trick_room = 0;
75
-    print("stall test (-tr): ");
75
+    debug_print("stall test (-tr): ");
76
     
76
     
77
     result = get_first_to_strike(0, 1, 0);
77
     result = get_first_to_strike(0, 1, 0);
78
     if (result == ONE)
78
     if (result == ONE)
79
-        print("\xFE\x1 pass\n\xFE\x0");
79
+        debug_print("\xFE\x1 pass\n\xFE\x0");
80
     else {
80
     else {
81
         pass = false;
81
         pass = false;
82
-        print("\xFE\x2 fail\n\xFE\x0");
82
+        debug_print("\xFE\x2 fail\n\xFE\x0");
83
     }
83
     }
84
 
84
 
85
     battle_participants[1].ability_id = 0;
85
     battle_participants[1].ability_id = 0;
86
 
86
 
87
-    print("\nPRESS A TO CONTINUE...");
88
-    wait_for_btn(1);
87
+    debug_print("\nPRESS A TO CONTINUE...");
88
+    debug_wait_for_btn(1);
89
     debug_clean();
89
     debug_clean();
90
 
90
 
91
-    print("speed value tests...\n");
91
+    debug_print("speed value tests...\n");
92
     battle_participants[0].spd = 75;
92
     battle_participants[0].spd = 75;
93
     battle_participants[1].spd = 60;
93
     battle_participants[1].spd = 60;
94
-    printf("bank_one.spd: %d\n", battle_participants[0].spd);
95
-    printf("bank_two.spd: %d\n", battle_participants[1].spd);
94
+    debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
95
+    debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
96
     u16 speed_one = get_speed(0);
96
     u16 speed_one = get_speed(0);
97
     u16 speed_two = get_speed(1);
97
     u16 speed_two = get_speed(1);
98
-    printf("unaffected speed: %d", speed_one);
99
-    printf(": %d", speed_two);
98
+    debug_printf("unaffected speed: %d", speed_one);
99
+    debug_printf(": %d", speed_two);
100
     if (speed_one == 75 && speed_two == 60) {
100
     if (speed_one == 75 && speed_two == 60) {
101
-        print(" \xFE\x1pass\xFE\x0\n");
101
+        debug_print(" \xFE\x1pass\xFE\x0\n");
102
     } else {
102
     } else {
103
-        print("\xFE\x02 fail\xFE\x0\n");
103
+        debug_print("\xFE\x02 fail\xFE\x0\n");
104
         pass = false;
104
         pass = false;
105
     }
105
     }
106
     battle_participants[0].status.flags.paralysis = 1;
106
     battle_participants[0].status.flags.paralysis = 1;
107
     battle_participants[1].status.flags.paralysis = 1;
107
     battle_participants[1].status.flags.paralysis = 1;
108
     speed_one = get_speed(0);
108
     speed_one = get_speed(0);
109
     speed_two = get_speed(1);
109
     speed_two = get_speed(1);
110
-    printf("para speed: %d", speed_one);
111
-    printf(": %d", speed_two);
110
+    debug_printf("para speed: %d", speed_one);
111
+    debug_printf(": %d", speed_two);
112
 
112
 
113
     if (speed_one == 18 && speed_two == 15) {
113
     if (speed_one == 18 && speed_two == 15) {
114
-        print(" \xFE\x1pass\xFE\x0\n");
114
+        debug_print(" \xFE\x1pass\xFE\x0\n");
115
     } else {
115
     } else {
116
-        print("\xFE\x02 fail\xFE\x0\n");
116
+        debug_print("\xFE\x02 fail\xFE\x0\n");
117
         pass = false;
117
         pass = false;
118
     }
118
     }
119
     battle_participants[0].spd_buff = 12;
119
     battle_participants[0].spd_buff = 12;
121
     speed_one = get_speed(0);
121
     speed_one = get_speed(0);
122
     speed_two = get_speed(1);
122
     speed_two = get_speed(1);
123
 
123
 
124
-    printf("para/speed+6: %d", speed_one);
125
-    printf(": %d", speed_two);
124
+    debug_printf("para/speed+6: %d", speed_one);
125
+    debug_printf(": %d", speed_two);
126
 
126
 
127
     if (speed_one == 75 && speed_two == 60) {
127
     if (speed_one == 75 && speed_two == 60) {
128
-        print(" \xFE\x1pass\xFE\x0\n");
128
+        debug_print(" \xFE\x1pass\xFE\x0\n");
129
     } else {
129
     } else {
130
-        print("\xFE\x02 fail\xFE\x0\n");
130
+        debug_print("\xFE\x02 fail\xFE\x0\n");
131
         pass = false;
131
         pass = false;
132
     }
132
     }
133
     battle_participants[0].status.flags.paralysis = 0;
133
     battle_participants[0].status.flags.paralysis = 0;
135
     speed_one = get_speed(0);
135
     speed_one = get_speed(0);
136
     speed_two = get_speed(1);
136
     speed_two = get_speed(1);
137
 
137
 
138
-    printf("speed+6: %d", speed_one);
139
-    printf(": %d", speed_two);
138
+    debug_printf("speed+6: %d", speed_one);
139
+    debug_printf(": %d", speed_two);
140
 
140
 
141
     if (speed_one == 300 && speed_two == 240) {
141
     if (speed_one == 300 && speed_two == 240) {
142
-        print(" \xFE\x1pass\xFE\x0\n");
142
+        debug_print(" \xFE\x1pass\xFE\x0\n");
143
     } else {
143
     } else {
144
-        print("\xFE\x02 fail\xFE\x0\n");
144
+        debug_print("\xFE\x02 fail\xFE\x0\n");
145
         pass = false;
145
         pass = false;
146
     }
146
     }
147
 
147
 
150
     speed_one = get_speed(0);
150
     speed_one = get_speed(0);
151
     speed_two = get_speed(1);
151
     speed_two = get_speed(1);
152
 
152
 
153
-    printf("speed-3: %d", speed_one);
154
-    printf(": %d", speed_two);
153
+    debug_printf("speed-3: %d", speed_one);
154
+    debug_printf(": %d", speed_two);
155
 
155
 
156
     if (speed_one == 30 && speed_two == 24) {
156
     if (speed_one == 30 && speed_two == 24) {
157
-        print(" \xFE\x1pass\xFE\x0\n");
157
+        debug_print(" \xFE\x1pass\xFE\x0\n");
158
     } else {
158
     } else {
159
-        print("\xFE\x02 fail\xFE\x0\n");
159
+        debug_print("\xFE\x02 fail\xFE\x0\n");
160
         pass = false;
160
         pass = false;
161
     }
161
     }
162
 
162
 
163
     battle_participants[0].spd_buff = 6;
163
     battle_participants[0].spd_buff = 6;
164
     battle_participants[1].spd_buff = 6;
164
     battle_participants[1].spd_buff = 6;
165
-    print("activating chemtrails...\n");
165
+    debug_print("activating chemtrails...\n");
166
     battle_weather.flags.rain = 1;
166
     battle_weather.flags.rain = 1;
167
     battle_weather.flags.sun = 1;
167
     battle_weather.flags.sun = 1;
168
     battle_weather.flags.sandstorm = 1;
168
     battle_weather.flags.sandstorm = 1;
180
     speed_one = get_speed(0);
180
     speed_one = get_speed(0);
181
     if (speed_one != 150)
181
     if (speed_one != 150)
182
         weather_pass = false;
182
         weather_pass = false;
183
-    print("weather test:");
184
-    print(weather_pass ? "\xFE\x1 pass\xFE\x0\n" : "\xFE\x2 fail\xFE\x0\n");
183
+    debug_print("weather test:");
184
+    debug_print(weather_pass ? "\xFE\x1 pass\xFE\x0\n" : "\xFE\x2 fail\xFE\x0\n");
185
     if (!weather_pass)
185
     if (!weather_pass)
186
         pass = false;
186
         pass = false;
187
 
187
 
188
-    print("tailwind + weather: ");
188
+    debug_print("tailwind + weather: ");
189
     custom_battle_elements.ptr->side_affecting[0].tailwind = 1;
189
     custom_battle_elements.ptr->side_affecting[0].tailwind = 1;
190
     custom_battle_elements.ptr->side_affecting[0].tailwind_bank = 0;
190
     custom_battle_elements.ptr->side_affecting[0].tailwind_bank = 0;
191
     custom_battle_elements.ptr->side_affecting[1].tailwind = 1;
191
     custom_battle_elements.ptr->side_affecting[1].tailwind = 1;
194
     speed_two = get_speed(1);
194
     speed_two = get_speed(1);
195
 
195
 
196
     if (speed_one == 300 && speed_two == 240) {
196
     if (speed_one == 300 && speed_two == 240) {
197
-        print(" \xFE\x1pass\xFE\x0\n");
197
+        debug_print(" \xFE\x1pass\xFE\x0\n");
198
     } else {
198
     } else {
199
-        print("\xFE\x02 fail\xFE\x0\n");
199
+        debug_print("\xFE\x02 fail\xFE\x0\n");
200
         pass = false;
200
         pass = false;
201
     }
201
     }
202
     custom_battle_elements.ptr->side_affecting[0].tailwind = 0;
202
     custom_battle_elements.ptr->side_affecting[0].tailwind = 0;
208
     battle_weather.flags.sandstorm = 0;
208
     battle_weather.flags.sandstorm = 0;
209
 
209
 
210
 
210
 
211
-    print("quick feet: ");
211
+    debug_print("quick feet: ");
212
     battle_participants[0].ability_id = ABILITY_QUICK_FEET;
212
     battle_participants[0].ability_id = ABILITY_QUICK_FEET;
213
     battle_participants[1].ability_id = ABILITY_QUICK_FEET;
213
     battle_participants[1].ability_id = ABILITY_QUICK_FEET;
214
     battle_participants[0].status.flags.paralysis = 1;
214
     battle_participants[0].status.flags.paralysis = 1;
230
         quick_feet_pass = false;
230
         quick_feet_pass = false;
231
 
231
 
232
     if (quick_feet_pass) {
232
     if (quick_feet_pass) {
233
-        print(" \xFE\x1pass\xFE\x0\n");
233
+        debug_print(" \xFE\x1pass\xFE\x0\n");
234
     } else {
234
     } else {
235
-        print("\xFE\x02 fail\xFE\x0\n");
235
+        debug_print("\xFE\x02 fail\xFE\x0\n");
236
         pass = false;
236
         pass = false;
237
     }
237
     }
238
     battle_participants[0].status.flags.sleep = 0;
238
     battle_participants[0].status.flags.sleep = 0;
239
     battle_participants[0].ability_id = 0;
239
     battle_participants[0].ability_id = 0;
240
     battle_participants[1].ability_id = 0;
240
     battle_participants[1].ability_id = 0;
241
-    wait_for_btn(8);
241
+    debug_wait_for_btn(8);
242
     debug_clean();
242
     debug_clean();
243
     //stress
243
     //stress
244
     battle_participants[0].spd = 20;
244
     battle_participants[0].spd = 20;
245
     battle_participants[1].spd = 20;
245
     battle_participants[1].spd = 20;
246
-    printf("bank_one.spd: %d\n", battle_participants[0].spd);
247
-    printf("bank_two.spd: %d\n", battle_participants[1].spd);
246
+    debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
247
+    debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
248
     int count_one = 0;
248
     int count_one = 0;
249
     int count_two = 0;
249
     int count_two = 0;
250
     for (int i = 0; i < TEST_AMOUNT; ++i) {
250
     for (int i = 0; i < TEST_AMOUNT; ++i) {
255
             count_two++;
255
             count_two++;
256
     }
256
     }
257
 
257
 
258
-    printf("tie stress test...\ncount \xFE\x1%d\xFE\x0 / ", count_one);
259
-    printf(" \xFE\x2%d\xFE\x0\n", count_two);
258
+    debug_printf("tie stress test...\ncount \xFE\x1%d\xFE\x0 / ", count_one);
259
+    debug_printf(" \xFE\x2%d\xFE\x0\n", count_two);
260
     int ratio_one = (count_one * 100) / TEST_AMOUNT;
260
     int ratio_one = (count_one * 100) / TEST_AMOUNT;
261
     int ratio_two = (count_two * 100) / TEST_AMOUNT;
261
     int ratio_two = (count_two * 100) / TEST_AMOUNT;
262
-    printf("%d%% / ", ratio_one);
263
-    printf("%d%%\n", ratio_two);
264
-    print("\nPRESS A TO CONTINUE...");
262
+    debug_printf("%d%% / ", ratio_one);
263
+    debug_printf("%d%%\n", ratio_two);
264
+    debug_print("\nPRESS A TO CONTINUE...");
265
 
265
 
266
-    wait_for_btn(1);
266
+    debug_wait_for_btn(1);
267
     debug_clean();
267
     debug_clean();
268
 
268
 
269
 
269
 
270
     if (pass)
270
     if (pass)
271
-        set_debug_background(0x3E0);
271
+        debug_set_bg(0x3E0);
272
     else
272
     else
273
-        set_debug_background(0x1F);
274
-    print("test complete\n(entering deadlock)");
273
+        debug_set_bg(0x1F);
274
+    debug_print("test complete\n(entering deadlock)");
275
     while (true) {
275
     while (true) {
276
     }
276
     }
277
     return;
277
     return;

+ 1
- 1
src/battle_engine/scripts/test.S View File

5
 .text
5
 .text
6
 .global bs_test
6
 .global bs_test
7
 bs_test:
7
 bs_test:
8
-    callasm some_test+1
8
+    callasm debug_some_test+1
9
     end
9
     end
10
 
10
 
11
 
11
 

+ 170
- 26
src/debug/debug.c View File

1
-#include <bpre.h>
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 debug.c
25
+ * @author Sturmvogel
26
+ * @date 15 dec 2016
27
+ * @brief Operate with the sots debug engine, very temporary
28
+ */
29
+
30
+/* === INCLUDE === */
31
+
32
+#include <types.h>
33
+#include <callback.h>
34
+#include <lcd.h>
2
 #include <debug.h>
35
 #include <debug.h>
36
+#include <memory.h>
3
 #include <assets/ascii.h>
37
 #include <assets/ascii.h>
4
 #include <battle_test.h>
38
 #include <battle_test.h>
39
+#include <math.h>
40
+#include <fade.h>
41
+
42
+/* === STATICS === */
43
+
44
+static struct print_engine* print_memory = (struct print_engine*)(0x0203FFF0);
45
+
46
+/* === PROTOTYPES === */
47
+
48
+/**
49
+ * @brief set bg color
50
+ * @param color color to set bg to
51
+ */
52
+void debug_set_bg(u16 color);
53
+
54
+/**
55
+ * @brief clean debug screen from any text and reset cursor
56
+ */
57
+void debug_clean();
58
+
59
+/**
60
+ * @brief wait for button press
61
+ * @param field bitfield to specify buttom combination
62
+ */
63
+void debug_wait_for_btn(u16 field);
64
+
65
+/**
66
+ * @brief convert int to char
67
+ * @param i integer
68
+ * @param ref buffer to output to
69
+ */
70
+void debug_int_to_char(u32 i, char* ref);
71
+
72
+/**
73
+ * @get length of integer
74
+ * @param i integer
75
+ * @return length
76
+ */
77
+u32 debug_dec_len(u32 i);
78
+
79
+/**
80
+ * @brief update debug environment
81
+ */
82
+void debug_update();
83
+
84
+/**
85
+ * @brief reset scrolling (from overworld e.g.)
86
+ */
87
+void debug_reset_scrolling();
88
+
89
+/**
90
+ * @brief start a unit test function
91
+ */
92
+void debug_init_unit_test();
93
+
94
+/**
95
+ * @brief handle for the debug scene
96
+ */
97
+void debug_scene();
98
+
99
+/**
100
+ * @brief convert character to byte
101
+ * @param character character
102
+ * @return byte from character
103
+ */
104
+u8 char_to_byte(char character);
105
+
106
+/**
107
+ * @brief print a character on the debug environment
108
+ * @param line line to print to
109
+ * @param row row to print to
110
+ * @param character character to print
111
+ * @param color color to print in
112
+ */
113
+void debug_print_char(u16 line, u16 row, char character, u8 color);
114
+
115
+/**
116
+ * @brief print a string to the debug environment
117
+ * @param line line to print to
118
+ * @param row row to start
119
+ * @param color color to print in
120
+ * @param pBuf string buffer to print (null terminated)
121
+ */
122
+void debug_print_string(u16 line, u16 row, u8 color, char* pBuf);
123
+
124
+/**
125
+ * @brief print string onto debug environment at current position with parsing
126
+ * @param str string to print
127
+ */
128
+void debug_print(char* str);
129
+
130
+/**
131
+ * @brief build power
132
+ * @param n integer to power
133
+ * @param power exponent
134
+ * @return n^power
135
+ */
136
+u32 debug_power(u32 n, u32 power);
137
+
138
+/**
139
+ * @brief print in format to debug environment
140
+ * @param str string with format
141
+ * @param arg argument to print (only one, not an array)
142
+ */
143
+void debug_printf(char* str, int arg);
5
 
144
 
6
-void set_debug_background(u16 color) {
145
+/**
146
+ * @brief set bg color of debug environment
147
+ * @param color color to set to
148
+ */
149
+void debug_set_bg(u16 color) {
7
     u16* bgc = (u16*) 0x020375f8;
150
     u16* bgc = (u16*) 0x020375f8;
8
     *bgc = color;
151
     *bgc = color;
9
     return;
152
     return;
10
 }
153
 }
11
 
154
 
155
+/* === IMPLEMENTATIONS === */
12
 void debug_scene() {
156
 void debug_scene() {
13
     if (superstate.multi_purpose_state_tracker == 0) {
157
     if (superstate.multi_purpose_state_tracker == 0) {
14
         print_memory->row = 0;
158
         print_memory->row = 0;
27
         gpu_bg_show(3);
171
         gpu_bg_show(3);
28
 
172
 
29
         gpu_sync_bg_visibility_and_mode();
173
         gpu_sync_bg_visibility_and_mode();
30
-        reset_scrolling_debug();
174
+        debug_reset_scrolling();
31
         obj_delete_all();
175
         obj_delete_all();
32
         memset((void*) 0x06000000, 0, 0x17fe0);
176
         memset((void*) 0x06000000, 0, 0x17fe0);
33
         memset((void*) 0x020375F8, 0, 0x400);
177
         memset((void*) 0x020375F8, 0, 0x400);
35
     } else if (superstate.multi_purpose_state_tracker == 1) {
179
     } else if (superstate.multi_purpose_state_tracker == 1) {
36
         vram_decompress((void*) asciiTiles, (void*) 0x06000000);
180
         vram_decompress((void*) asciiTiles, (void*) 0x06000000);
37
         memcpy((void*) 0x020375F8, (void*) asciiPal, 0x60);
181
         memcpy((void*) 0x020375F8, (void*) asciiPal, 0x60);
38
-        set_debug_background(0x0000);
182
+        debug_set_bg(0x0000);
39
         superstate.multi_purpose_state_tracker++;
183
         superstate.multi_purpose_state_tracker++;
40
     } else if (superstate.multi_purpose_state_tracker == 2) {
184
     } else if (superstate.multi_purpose_state_tracker == 2) {
41
-        init_unit_test();
185
+        debug_init_unit_test();
42
         superstate.multi_purpose_state_tracker++;
186
         superstate.multi_purpose_state_tracker++;
43
     }
187
     }
44
     return;
188
     return;
45
 }
189
 }
46
 
190
 
47
-u8 some_test() {
191
+u8 debug_some_test() {
48
     set_callback2(debug_scene);
192
     set_callback2(debug_scene);
49
     vblank_handler_set(debug_update);
193
     vblank_handler_set(debug_update);
50
     superstate.multi_purpose_state_tracker = 0;
194
     superstate.multi_purpose_state_tracker = 0;
52
     return 0;
196
     return 0;
53
 }
197
 }
54
 
198
 
55
-void reset_scrolling_debug() {
199
+void debug_reset_scrolling() {
56
     lcd_io_set_func(0x12, 0x0);
200
     lcd_io_set_func(0x12, 0x0);
57
     lcd_io_set_func(0x14, 0x0);
201
     lcd_io_set_func(0x14, 0x0);
58
     lcd_io_set_func(0x16, 0x0);
202
     lcd_io_set_func(0x16, 0x0);
64
     return;
208
     return;
65
 }
209
 }
66
 
210
 
67
-void init_unit_test() {
211
+void debug_init_unit_test() {
68
     test_speed();
212
     test_speed();
69
 }
213
 }
70
 
214
 
71
-void print_string(u16 line, u16 row, u8 color, char* pBuf) {
215
+void debug_print_string(u16 line, u16 row, u8 color, char* pBuf) {
72
     while (*pBuf) {
216
     while (*pBuf) {
73
-        print_character(line, row++, *pBuf++, color);
217
+        debug_print_char(line, row++, *pBuf++, color);
74
     }
218
     }
75
     return;
219
     return;
76
 }
220
 }
77
 
221
 
78
-void print(char* str) {
222
+void debug_print(char* str) {
79
     while (*str) {
223
     while (*str) {
80
         if (*str == '\n') {
224
         if (*str == '\n') {
81
             print_memory->line++;
225
             print_memory->line++;
87
                 c = 0;
231
                 c = 0;
88
             print_memory->color = c;
232
             print_memory->color = c;
89
         } else {
233
         } else {
90
-            print_character(print_memory->line, print_memory->row, *str, print_memory->color);
234
+            debug_print_char(print_memory->line, print_memory->row, *str, print_memory->color);
91
             print_memory->row++;
235
             print_memory->row++;
92
         }
236
         }
93
         str++;
237
         str++;
95
     return;
239
     return;
96
 }
240
 }
97
 
241
 
98
-void printf(char* str, int arg) {
242
+void debug_printf(char* str, int arg) {
99
     while (*str) {
243
     while (*str) {
100
         if (*str == '\n') {
244
         if (*str == '\n') {
101
             print_memory->line++;
245
             print_memory->line++;
109
         } else if (*str == '%') {
253
         } else if (*str == '%') {
110
             str++;
254
             str++;
111
             if (*str == '%') {
255
             if (*str == '%') {
112
-                print_character(print_memory->line, print_memory->row, *str, print_memory->color);
256
+                debug_print_char(print_memory->line, print_memory->row, *str, print_memory->color);
113
                 print_memory->row++;
257
                 print_memory->row++;
114
             } else if (*str == 'd') {
258
             } else if (*str == 'd') {
115
-                u32 len = dec_len(arg);
116
-                char temp[dec_len(len + 1)];
259
+                u32 len = debug_dec_len(arg);
260
+                char temp[debug_dec_len(len + 1)];
117
                 temp[len] = 0;
261
                 temp[len] = 0;
118
-                int_to_char(arg, temp);
119
-                print(temp);
262
+                debug_int_to_char(arg, temp);
263
+                debug_print(temp);
120
             } else if (*str == 'c') {
264
             } else if (*str == 'c') {
121
                 char print_char = (char) (arg);
265
                 char print_char = (char) (arg);
122
-                print_character(print_memory->line, print_memory->row, print_char, print_memory->color);
266
+                debug_print_char(print_memory->line, print_memory->row, print_char, print_memory->color);
123
                 print_memory->row++;
267
                 print_memory->row++;
124
             }
268
             }
125
         } else {
269
         } else {
126
-            print_character(print_memory->line, print_memory->row, *str, print_memory->color);
270
+            debug_print_char(print_memory->line, print_memory->row, *str, print_memory->color);
127
             print_memory->row++;
271
             print_memory->row++;
128
         }
272
         }
129
         str++;
273
         str++;
138
     return;
282
     return;
139
 }
283
 }
140
 
284
 
141
-void wait_for_btn(u16 field) {
285
+void debug_wait_for_btn(u16 field) {
142
     volatile u16* control_io = (volatile u16*) (0x04000130);
286
     volatile u16* control_io = (volatile u16*) (0x04000130);
143
     while (*control_io & field) {
287
     while (*control_io & field) {
144
     }
288
     }
145
     return;
289
     return;
146
 }
290
 }
147
 
291
 
148
-void print_character(u16 line, u16 row, char character, u8 color) {
292
+void debug_print_char(u16 line, u16 row, char character, u8 color) {
149
     if (color > 2)
293
     if (color > 2)
150
         color = 0;
294
         color = 0;
151
     u16 position = (32 * line) + row;
295
     u16 position = (32 * line) + row;
173
     obj_gpu_sprites_upload();
317
     obj_gpu_sprites_upload();
174
 }
318
 }
175
 
319
 
176
-void int_to_char(u32 i, char* ref) {
320
+void debug_int_to_char(u32 i, char* ref) {
177
     if (i == 0) {
321
     if (i == 0) {
178
         ref[0] = '0';
322
         ref[0] = '0';
179
         return;
323
         return;
180
     }
324
     }
181
-    u32 len = dec_len(i);
325
+    u32 len = debug_dec_len(i);
182
     while (i > 0) {
326
     while (i > 0) {
183
 
327
 
184
         ref[len - 1] = '0' + (__aeabi_uidivmod(i, 10));
328
         ref[len - 1] = '0' + (__aeabi_uidivmod(i, 10));
189
     return;
333
     return;
190
 }
334
 }
191
 
335
 
192
-u32 power(u32 n, u32 power) {
336
+u32 debug_power(u32 n, u32 power) {
193
     u32 out = 1;
337
     u32 out = 1;
194
     for (int i = 0; i < power; ++i) {
338
     for (int i = 0; i < power; ++i) {
195
         out = out * n;
339
         out = out * n;
197
     return out;
341
     return out;
198
 }
342
 }
199
 
343
 
200
-u32 dec_len(u32 i) {
344
+u32 debug_dec_len(u32 i) {
201
     u32 len = 1;
345
     u32 len = 1;
202
     while ((i /= 10) > 0) {
346
     while ((i /= 10) > 0) {
203
         len++;
347
         len++;

+ 1
- 18
src/include/debug.h View File

7
     u8 color;
7
     u8 color;
8
 };
8
 };
9
 
9
 
10
-static struct print_engine* print_memory = (struct print_engine*)(0x0203FFF0);
11
-
12
-void set_debug_background(u16 color);
13
-void debug_clean();
14
-void wait_for_btn(u16 field);
15
-void int_to_char(u32 i, char* ref);
16
-u32 dec_len(u32 i);
17
-void debug_update();
18
-u8 some_test();
19
-void reset_scrolling_debug();
20
-void init_unit_test();
21
-void debug_scene();
22
-u8 char_to_byte(char character);
23
-void print_character(u16 line, u16 row, char character, u8 color);
24
-void print_string(u16 line, u16 row, u8 color, char* pBuf);
25
-void print(char* str);
26
-u32 power(u32 n, u32 power);
27
-void printf(char* str, int arg);
10
+u8 debug_some_test();
28
 
11
 
29
 #endif /* DEBUG_H */
12
 #endif /* DEBUG_H */
30
 
13
 

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

22
 	met_play,
22
 	met_play,
23
 	sp_move_camera,
23
 	sp_move_camera,
24
 	init_script,
24
 	init_script,
25
-        some_test,
25
+        debug_some_test,
26
         dns_switch,
26
         dns_switch,
27
 };
27
 };
28
 
28