Browse Source

added unit test for initiatibve (normal + trickroom)

tied to bs_test
SBird1337 8 years ago
parent
commit
77e945f856

+ 4
- 1
bpre.sym View File

115
 m4aSongNumStart = 0x081DD0F5;
115
 m4aSongNumStart = 0x081DD0F5;
116
 MPlayStart_rev01 = 0x081DD859;
116
 MPlayStart_rev01 = 0x081DD859;
117
 MPlayContinue = 0x081DCFF9;
117
 MPlayContinue = 0x081DCFF9;
118
-__aeabi_idiv = 0x081E460C|1;
118
+__aeabi_idiv = 0x081E4018|1;
119
+__aeabi_idivmod = 0x081E40F4|1;
120
+__aeabi_uidiv = 0x081E460C|1;
121
+__aeabi_uidivmod = 0x081E4684|1;

+ 2
- 1
data/moves/effect_table.S View File

4
 
4
 
5
 .global m_effect_table
5
 .global m_effect_table
6
 m_effect_table:
6
 m_effect_table:
7
-	@.word bs_power_trick    @for testing
7
+	@.word bs_test           @for unit tests
8
+        @.word bs_power_trick    @for testing
8
         .word 0x081D6900 @0
9
         .word 0x081D6900 @0
9
 	.word 0x081D696D @1
10
 	.word 0x081D696D @1
10
 	.word 0x081D69DC @2
11
 	.word 0x081D69DC @2

+ 2
- 1
linker.ld View File

14
                 *(.text)
14
                 *(.text)
15
                 *(.ctors)
15
                 *(.ctors)
16
                 *(.dtors)
16
                 *(.dtors)
17
-                *(.rodata)
18
                 *(.fini)
17
                 *(.fini)
19
                 *(COMMON)
18
                 *(COMMON)
20
                 __text_end  = . ;
19
                 __text_end  = . ;
20
+                *(.rodata*)
21
+                *(.rdata)
21
                 *(.data)
22
                 *(.data)
22
                 __bss_start__ = . ;
23
                 __bss_start__ = . ;
23
                 *(.bss)
24
                 *(.bss)

+ 2
- 2
makefile View File

13
 
13
 
14
 DEFINES   := -DBPRE -DSOFTWARE_VERSION=0
14
 DEFINES   := -DBPRE -DSOFTWARE_VERSION=0
15
 ASFLAGS   := -mthumb
15
 ASFLAGS   := -mthumb
16
-CFLAGS    := -g -mthumb -mno-thumb-interwork -mcpu=arm7tdmi -fno-inline -mlong-calls -march=armv4t -O3 -std=gnu99 -Isrc/include $(DEFINES)
16
+CFLAGS    := -g -mthumb -mno-thumb-interwork -mcpu=arm7tdmi -fno-inline -mlong-calls -march=armv4t -O3 -std=c99 -Wall -Isrc/include $(DEFINES)
17
 GRITFLAGS := -ftc -fa
17
 GRITFLAGS := -ftc -fa
18
 LDFLAGS   := -z muldefs
18
 LDFLAGS   := -z muldefs
19
 BLDPATH   := object
19
 BLDPATH   := object
73
 .PHONY: rom
73
 .PHONY: rom
74
 rom: main.asm $(MAIN_OBJ)
74
 rom: main.asm $(MAIN_OBJ)
75
 	$(ARS) $<
75
 	$(ARS) $<
76
-	$(NM) $(BLDPATH)/linked.o -n -g --defined-only | \
76
+	$(NM) $(BLDPATH)/linked.o -l -n -g --defined-only | \
77
 		sed -e '{s/^/0x/g};{/.*\sA\s.*/d};{s/\sT\s/ /g}' > $(OUTPATH)/__symbols.sym
77
 		sed -e '{s/^/0x/g};{/.*\sA\s.*/d};{s/\sT\s/ /g}' > $(OUTPATH)/__symbols.sym
78
 	@echo "*** SUCCESSFULLY BUILT PROJECT ***"
78
 	@echo "*** SUCCESSFULLY BUILT PROJECT ***"
79
 	
79
 	

+ 12
- 6
nbproject/configurations.xml View File

4592
         <df name="battle_engine">
4592
         <df name="battle_engine">
4593
           <df name="scripts">
4593
           <df name="scripts">
4594
             <in>hazards.S</in>
4594
             <in>hazards.S</in>
4595
+            <in>test.S</in>
4595
           </df>
4596
           </df>
4596
           <in>battle_abilities.c</in>
4597
           <in>battle_abilities.c</in>
4597
           <in>battle_help.c</in>
4598
           <in>battle_help.c</in>
4598
           <in>battle_initiative.c</in>
4599
           <in>battle_initiative.c</in>
4599
-          <in>battle_initiative.h</in>
4600
           <in>battle_switch_in_hook.S</in>
4600
           <in>battle_switch_in_hook.S</in>
4601
+          <in>battle_test.c</in>
4601
           <in>custom_structs_malloc.c</in>
4602
           <in>custom_structs_malloc.c</in>
4602
           <in>custom_structs_malloc_hook.S</in>
4603
           <in>custom_structs_malloc_hook.S</in>
4603
           <in>entry_hazards.c</in>
4604
           <in>entry_hazards.c</in>
4612
         </df>
4613
         </df>
4613
         <df name="include">
4614
         <df name="include">
4614
           <in>battle_abilities.h</in>
4615
           <in>battle_abilities.h</in>
4616
+          <in>battle_initiative.h</in>
4617
+          <in>battle_test.h</in>
4615
           <in>debug.h</in>
4618
           <in>debug.h</in>
4616
           <in>item_effects.h</in>
4619
           <in>item_effects.h</in>
4617
           <in>items.h</in>
4620
           <in>items.h</in>
27181
             tool="0"
27184
             tool="0"
27182
             flavor2="0">
27185
             flavor2="0">
27183
       </item>
27186
       </item>
27184
-      <item path="src/battle_engine/battle_initiative.h"
27185
-            ex="false"
27186
-            tool="3"
27187
-            flavor2="0">
27188
-      </item>
27189
       <item path="src/battle_engine/battle_switch_in_hook.S"
27187
       <item path="src/battle_engine/battle_switch_in_hook.S"
27190
             ex="false"
27188
             ex="false"
27191
             tool="4"
27189
             tool="4"
27192
             flavor2="0">
27190
             flavor2="0">
27193
       </item>
27191
       </item>
27192
+      <item path="src/battle_engine/battle_test.c" ex="false" tool="0" flavor2="0">
27193
+      </item>
27194
       <item path="src/battle_engine/custom_structs_malloc.c"
27194
       <item path="src/battle_engine/custom_structs_malloc.c"
27195
             ex="false"
27195
             ex="false"
27196
             tool="0"
27196
             tool="0"
27215
             tool="4"
27215
             tool="4"
27216
             flavor2="0">
27216
             flavor2="0">
27217
       </item>
27217
       </item>
27218
+      <item path="src/battle_engine/scripts/test.S" ex="false" tool="4" flavor2="0">
27219
+      </item>
27218
       <item path="src/debug/debug.c" ex="false" tool="0" flavor2="0">
27220
       <item path="src/debug/debug.c" ex="false" tool="0" flavor2="0">
27219
       </item>
27221
       </item>
27220
       <item path="src/encode/crc32.c" ex="false" tool="0" flavor2="0">
27222
       <item path="src/encode/crc32.c" ex="false" tool="0" flavor2="0">
27221
       </item>
27223
       </item>
27222
       <item path="src/include/battle_abilities.h" ex="false" tool="3" flavor2="0">
27224
       <item path="src/include/battle_abilities.h" ex="false" tool="3" flavor2="0">
27223
       </item>
27225
       </item>
27226
+      <item path="src/include/battle_initiative.h" ex="false" tool="3" flavor2="0">
27227
+      </item>
27228
+      <item path="src/include/battle_test.h" ex="false" tool="3" flavor2="0">
27229
+      </item>
27224
       <item path="src/include/debug.h" ex="false" tool="3" flavor2="0">
27230
       <item path="src/include/debug.h" ex="false" tool="3" flavor2="0">
27225
       </item>
27231
       </item>
27226
       <item path="src/include/item_effects.h" ex="false" tool="3" flavor2="0">
27232
       <item path="src/include/item_effects.h" ex="false" tool="3" flavor2="0">

+ 5
- 4
nbproject/private/configurations.xml View File

5467
         <df name="battle_engine">
5467
         <df name="battle_engine">
5468
           <df name="scripts">
5468
           <df name="scripts">
5469
             <in>hazards.S</in>
5469
             <in>hazards.S</in>
5470
+            <in>test.S</in>
5470
           </df>
5471
           </df>
5471
           <in>battle_abilities.c</in>
5472
           <in>battle_abilities.c</in>
5472
           <in>battle_help.c</in>
5473
           <in>battle_help.c</in>
5473
-          <in>battle_help.h</in>
5474
           <in>battle_initiative.c</in>
5474
           <in>battle_initiative.c</in>
5475
-          <in>battle_initiative.h</in>
5476
           <in>battle_switch_in_hook.S</in>
5475
           <in>battle_switch_in_hook.S</in>
5476
+          <in>battle_test.c</in>
5477
           <in>custom_structs_malloc.c</in>
5477
           <in>custom_structs_malloc.c</in>
5478
           <in>custom_structs_malloc.h</in>
5478
           <in>custom_structs_malloc.h</in>
5479
           <in>custom_structs_malloc_hook.S</in>
5479
           <in>custom_structs_malloc_hook.S</in>
5496
           <in>attack_names.h</in>
5496
           <in>attack_names.h</in>
5497
           <in>battle.h</in>
5497
           <in>battle.h</in>
5498
           <in>battle_abilities.h</in>
5498
           <in>battle_abilities.h</in>
5499
+          <in>battle_help.h</in>
5500
+          <in>battle_initiative.h</in>
5499
           <in>battle_locations.h</in>
5501
           <in>battle_locations.h</in>
5500
           <in>battle_script.h</in>
5502
           <in>battle_script.h</in>
5501
           <in>battle_structs.h</in>
5503
           <in>battle_structs.h</in>
5504
+          <in>battle_test.h</in>
5502
           <in>bpre.h</in>
5505
           <in>bpre.h</in>
5503
           <in>callback.h</in>
5506
           <in>callback.h</in>
5504
           <in>config.h</in>
5507
           <in>config.h</in>
5612
         <gdb_interceptlist>
5615
         <gdb_interceptlist>
5613
           <gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/>
5616
           <gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/>
5614
         </gdb_interceptlist>
5617
         </gdb_interceptlist>
5615
-        <gdb_signals>
5616
-        </gdb_signals>
5617
         <gdb_options>
5618
         <gdb_options>
5618
           <DebugOptions>
5619
           <DebugOptions>
5619
             <option name="gdb_init_file"
5620
             <option name="gdb_init_file"

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

1
-#include "battle_help.h"
1
+#include <battle_help.h>
2
 
2
 
3
 //from kds emerald battle engine upgrade
3
 //from kds emerald battle engine upgrade
4
 
4
 

+ 21
- 22
src/battle_engine/battle_initiative.c View File

1
-#include "battle_initiative.h"
1
+#include <battle_initiative.h>
2
+#include <battle.h>
3
+#include <battle_help.h>
4
+#include <bpre.h>
2
 struct move_info move_table[1024];
5
 struct move_info move_table[1024];
3
 
6
 
4
 u16 get_speed(u8 bank) {
7
 u16 get_speed(u8 bank) {
15
                 speed <<= 1;
18
                 speed <<= 1;
16
             break;
19
             break;
17
     }
20
     }
18
-    if(has_ability_effect(bank, 0, 1))
19
-    {
21
+    if (has_ability_effect(bank, 0, 1)) {
20
         u8 weather_effects = weather_abilities_effect();
22
         u8 weather_effects = weather_abilities_effect();
21
-        switch (battle_participants[bank].ability_id)
22
-        {
23
+        switch (battle_participants[bank].ability_id) {
23
             case ABILITY_CHLOROPHYLL:
24
             case ABILITY_CHLOROPHYLL:
24
-                if(weather_effects && (battle_weather.flags.harsh_sun || battle_weather.flags.permament_sun || battle_weather.flags.sun))
25
-                    speed *=2;
25
+                if (weather_effects && (battle_weather.flags.harsh_sun || battle_weather.flags.permament_sun || battle_weather.flags.sun))
26
+                    speed *= 2;
26
                 break;
27
                 break;
27
             case ABILITY_SWIFT_SWIM:
28
             case ABILITY_SWIFT_SWIM:
28
-                if(weather_effects && (battle_weather.flags.rain || battle_weather.flags.downpour || battle_weather.flags.permament_rain || battle_weather.flags.heavy_rain))
29
-                    speed *=2;
29
+                if (weather_effects && (battle_weather.flags.rain || battle_weather.flags.downpour || battle_weather.flags.permament_rain || battle_weather.flags.heavy_rain))
30
+                    speed *= 2;
30
                 break;
31
                 break;
31
             case ABILITY_SAND_RUSH:
32
             case ABILITY_SAND_RUSH:
32
-                if(weather_effects && (battle_weather.flags.sandstorm || battle_weather.flags.permament_sandstorm))
33
+                if (weather_effects && (battle_weather.flags.sandstorm || battle_weather.flags.permament_sandstorm))
33
                     speed *= 2;
34
                     speed *= 2;
34
                 break;
35
                 break;
35
             case ABILITY_QUICK_FEET:
36
             case ABILITY_QUICK_FEET:
36
-                if(battle_participants[bank].status.flags.burn || battle_participants[bank].status.flags.poison || battle_participants[bank].status.flags.toxic_poison)
37
+                if (battle_participants[bank].status.flags.burn || battle_participants[bank].status.flags.poison || battle_participants[bank].status.flags.toxic_poison)
37
                     speed *= 2;
38
                     speed *= 2;
38
-                else if(battle_participants[bank].status.flags.paralysis)
39
+                else if (battle_participants[bank].status.flags.paralysis)
39
                     speed *= 4;
40
                     speed *= 4;
40
                 break;
41
                 break;
41
         }
42
         }
42
     }
43
     }
43
-    if(battle_participants[bank].status.flags.paralysis)
44
+    if (battle_participants[bank].status.flags.paralysis)
44
         speed >= 2;
45
         speed >= 2;
45
-    if(custom_battle_elements.ptr->side_affecting[get_side_from_bank(bank)].tailwind)
46
+    if (custom_battle_elements.ptr->side_affecting[get_side_from_bank(bank)].tailwind)
46
         speed *= 2;
47
         speed *= 2;
47
     //TODO: unburden
48
     //TODO: unburden
48
     speed = (speed * stat_buffs[battle_participants[bank].spd_buff].dividend) / (stat_buffs[battle_participants[bank].spd_buff].divisor);
49
     speed = (speed * stat_buffs[battle_participants[bank].spd_buff].dividend) / (stat_buffs[battle_participants[bank].spd_buff].divisor);
73
         //TODO: calculate speed
74
         //TODO: calculate speed
74
         u8 stall_one = has_ability(bank_one, ABILITY_STALL);
75
         u8 stall_one = has_ability(bank_one, ABILITY_STALL);
75
         u8 stall_two = has_ability(bank_two, ABILITY_STALL);
76
         u8 stall_two = has_ability(bank_two, ABILITY_STALL);
76
-        if(stall_one && !stall_two)
77
+        if (stall_one && !stall_two)
77
             result = TWO;
78
             result = TWO;
78
-        else if(stall_two && !stall_one)
79
+        else if (stall_two && !stall_one)
79
             result = ONE;
80
             result = ONE;
80
-        else
81
-        {
81
+        else {
82
             u16 speed_one = get_speed(bank_one);
82
             u16 speed_one = get_speed(bank_one);
83
             u16 speed_two = get_speed(bank_two);
83
             u16 speed_two = get_speed(bank_two);
84
-            if(custom_battle_elements.ptr->field_affecting.trick_room || (stall_one && stall_two))
85
-            {
84
+            if (custom_battle_elements.ptr->field_affecting.trick_room || (stall_one && stall_two)) {
86
                 u16 swap_speed = speed_one;
85
                 u16 swap_speed = speed_one;
87
                 speed_one = speed_two;
86
                 speed_one = speed_two;
88
                 speed_two = swap_speed;
87
                 speed_two = swap_speed;
89
             }
88
             }
90
-            if(speed_one > speed_two)
89
+            if (speed_one > speed_two)
91
                 result = ONE;
90
                 result = ONE;
92
-            else if(speed_two > speed_one)
91
+            else if (speed_two > speed_one)
93
                 result = TWO;
92
                 result = TWO;
94
             else if (random() & 1)
93
             else if (random() & 1)
95
                 result = ONE;
94
                 result = ONE;

+ 91
- 0
src/battle_engine/battle_test.c View File

1
+#include <battle_test.h>
2
+#include <battle.h>
3
+#include <bpre.h>
4
+#include <debug.h>
5
+#include <battle_initiative.h>
6
+
7
+void test_battle() {
8
+    print("Initiating Initiative Unit\nTest...\n");
9
+    u8 pass = true;
10
+    battle_participants[0].spd = 10;
11
+    battle_participants[1].spd = 11;
12
+    printf("bank_one.spd: %d\n", battle_participants[0].spd);
13
+    printf("bank_two.spd: %d\n", battle_participants[1].spd);
14
+    print("testing (await TWO):");
15
+    enum init_enum result = get_first_to_strike(0, 1, 0);
16
+    if (result == TWO)
17
+        print("\xFE\x1 pass\n\xFE\x0");
18
+    else {
19
+        pass = false;
20
+        print("\xFE\x2 fail\n\xFE\x0");
21
+    }
22
+    battle_participants[0].spd = 12;
23
+    printf("bank_one.spd: %d\n", battle_participants[0].spd);
24
+    printf("bank_two.spd: %d\n", battle_participants[1].spd);
25
+    print("testing (await ONE):");
26
+    result = get_first_to_strike(0, 1, 0);
27
+    if (result == ONE)
28
+        print("\xFE\x1 pass\n\xFE\x0");
29
+    else {
30
+        pass = false;
31
+        print("\xFE\x2 fail\n\xFE\x0");
32
+    }
33
+    battle_participants[0].spd = 10;
34
+    battle_participants[1].spd = 11;
35
+    printf("bank_one.spd: %d\n", battle_participants[0].spd);
36
+    printf("bank_two.spd: %d\n", battle_participants[1].spd);
37
+
38
+    //trick room
39
+    custom_battle_elements.ptr->field_affecting.trick_room = 1;
40
+    print("activating trick room...\n");
41
+    print("testing (await ONE):");
42
+    result = get_first_to_strike(0, 1, 0);
43
+    if (result == ONE)
44
+        print("\xFE\x1 pass\n\xFE\x0");
45
+    else {
46
+        pass = false;
47
+        print("\xFE\x2 fail\n\xFE\x0");
48
+    }
49
+
50
+    battle_participants[0].spd = 12;
51
+    printf("bank_one.spd: %d\n", battle_participants[0].spd);
52
+    printf("bank_two.spd: %d\n", battle_participants[1].spd);
53
+    print("testing (await TWO):");
54
+    result = get_first_to_strike(0, 1, 0);
55
+    if (result == TWO)
56
+        print("\xFE\x1 pass\n\xFE\x0");
57
+    else {
58
+        pass = false;
59
+        print("\xFE\x2 fail\n\xFE\x0");
60
+    }
61
+    
62
+    wait_for_btn(1);
63
+    debug_clean();
64
+    
65
+    //stress
66
+    battle_participants[0].spd = 20;
67
+    battle_participants[1].spd = 20;
68
+    printf("bank_one.spd: %d\n", battle_participants[0].spd);
69
+    printf("bank_two.spd: %d\n", battle_participants[1].spd);
70
+    int count_one = 0;
71
+    int count_two = 0;
72
+    for (int i = 0; i < 5000; ++i) {
73
+        result = get_first_to_strike(0, 1, 0);
74
+        if (result == ONE)
75
+            count_one++;
76
+        else
77
+            count_two++;
78
+    }
79
+    printf("tie stress test...\ncount \xFE\x1%d\xFE\x0 / ", count_one);
80
+    printf(" \xFE\x2%d\xFE\x0\n", count_two);
81
+    wait_for_btn(1);
82
+    debug_clean();
83
+    if(pass)
84
+        set_debug_background(0x3E0);
85
+    else
86
+        set_debug_background(0x31);
87
+    print("test complete\n(entering deadlock)");
88
+    while(true)
89
+    {}
90
+    return;
91
+}

+ 2
- 0
src/battle_engine/custom_structs_malloc.c View File

2
 #include <battle.h>
2
 #include <battle.h>
3
 #include "custom_structs.h"
3
 #include "custom_structs.h"
4
 #include "custom_structs_malloc.h"
4
 #include "custom_structs_malloc.h"
5
+#include <debug.h>
5
 
6
 
6
 void malloc_battle_structs()
7
 void malloc_battle_structs()
7
 {
8
 {
8
 	custom_battle_elements.ptr=(struct custom_battle_struct*)malloc(sizeof(struct custom_battle_struct));
9
 	custom_battle_elements.ptr=(struct custom_battle_struct*)malloc(sizeof(struct custom_battle_struct));
10
+        some_test();
9
 }
11
 }
10
 
12
 
11
 void free_battle_structs()
13
 void free_battle_structs()

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

1
-#include "battle_help.h"
1
+#include <battle_help.h>
2
 #include <bpre.h>
2
 #include <bpre.h>
3
 
3
 
4
 extern void* bs_stealth_rock;
4
 extern void* bs_stealth_rock;

+ 11
- 0
src/battle_engine/scripts/test.S View File

1
+#include <battle_script.h>
2
+
3
+.align 2
4
+.thumb
5
+.text
6
+.global bs_test
7
+bs_test:
8
+    callasm some_test+1
9
+    end
10
+
11
+

+ 105
- 17
src/debug/debug.c View File

1
 #include <bpre.h>
1
 #include <bpre.h>
2
 #include <debug.h>
2
 #include <debug.h>
3
 #include <assets/ascii.h>
3
 #include <assets/ascii.h>
4
+#include <battle_test.h>
4
 
5
 
5
-void set_background(u16 color) {
6
+void set_debug_background(u16 color) {
6
     u16* bgc = (u16*) 0x020375f8;
7
     u16* bgc = (u16*) 0x020375f8;
7
     *bgc = color;
8
     *bgc = color;
8
     return;
9
     return;
34
     } else if (superstate.multi_purpose_state_tracker == 1) {
35
     } else if (superstate.multi_purpose_state_tracker == 1) {
35
         vram_decompress((void*) asciiTiles, (void*) 0x06000000);
36
         vram_decompress((void*) asciiTiles, (void*) 0x06000000);
36
         memcpy((void*) 0x020375F8, (void*) asciiPal, 0x60);
37
         memcpy((void*) 0x020375F8, (void*) asciiPal, 0x60);
37
-        set_background(0x0000);
38
+        set_debug_background(0x0000);
38
         superstate.multi_purpose_state_tracker++;
39
         superstate.multi_purpose_state_tracker++;
39
     } else if (superstate.multi_purpose_state_tracker == 2) {
40
     } else if (superstate.multi_purpose_state_tracker == 2) {
40
         init_unit_test();
41
         init_unit_test();
43
     return;
44
     return;
44
 }
45
 }
45
 
46
 
46
-void some_test() {
47
+u8 some_test() {
47
     set_callback2(debug_scene);
48
     set_callback2(debug_scene);
49
+    vblank_handler_set(debug_update);
48
     superstate.multi_purpose_state_tracker = 0;
50
     superstate.multi_purpose_state_tracker = 0;
49
 
51
 
50
-    return;
52
+    return 0;
51
 }
53
 }
52
 
54
 
53
 void reset_scrolling_debug() {
55
 void reset_scrolling_debug() {
56
+    lcd_io_set_func(0x12, 0x0);
54
     lcd_io_set_func(0x14, 0x0);
57
     lcd_io_set_func(0x14, 0x0);
55
     lcd_io_set_func(0x16, 0x0);
58
     lcd_io_set_func(0x16, 0x0);
56
     lcd_io_set_func(0x18, 0x0);
59
     lcd_io_set_func(0x18, 0x0);
62
 }
65
 }
63
 
66
 
64
 void init_unit_test() {
67
 void init_unit_test() {
65
-    print("Hello\nWorld!\xFE\x2\nHello\nWorld!");
68
+    test_battle();
66
 }
69
 }
67
 
70
 
68
 void print_string(u16 line, u16 row, u8 color, char* pBuf) {
71
 void print_string(u16 line, u16 row, u8 color, char* pBuf) {
73
 }
76
 }
74
 
77
 
75
 void print(char* str) {
78
 void print(char* str) {
76
-    while(*str)
77
-    {
78
-        if(*str== '\n')
79
-        {
79
+    while (*str) {
80
+        if (*str == '\n') {
80
             print_memory->line++;
81
             print_memory->line++;
81
             print_memory->row = 0;
82
             print_memory->row = 0;
82
-        }
83
-        else if(*str == '\xFE')
84
-        {
83
+        } else if (*str == '\xFE') {
85
             str++;
84
             str++;
86
             u8 c = *str;
85
             u8 c = *str;
87
-            if(c > 2)
86
+            if (c > 2)
88
                 c = 0;
87
                 c = 0;
89
-            print_memory->color=c;
88
+            print_memory->color = c;
89
+        } else {
90
+            print_character(print_memory->line, print_memory->row, *str, print_memory->color);
91
+            print_memory->row++;
90
         }
92
         }
91
-        else
92
-        {
93
+        str++;
94
+    }
95
+    return;
96
+}
97
+
98
+void printf(char* str, int arg) {
99
+    while (*str) {
100
+        if (*str == '\n') {
101
+            print_memory->line++;
102
+            print_memory->row = 0;
103
+        } else if (*str == '\xFE') {
104
+            str++;
105
+            u8 c = *str;
106
+            if (c > 2)
107
+                c = 0;
108
+            print_memory->color = c;
109
+        } else if (*str == '%') {
110
+            str++;
111
+            if (*str == '%') {
112
+                print_character(print_memory->line, print_memory->row, *str, print_memory->color);
113
+                print_memory->row++;
114
+            } else if (*str == 'd') {
115
+                u32 len = dec_len(arg);
116
+                char temp[dec_len(len + 1)];
117
+                temp[len] = 0;
118
+                int_to_char(arg, temp);
119
+                print(temp);
120
+            } else if (*str == 'c') {
121
+                char print_char = (char) (arg);
122
+                print_character(print_memory->line, print_memory->row, print_char, print_memory->color);
123
+                print_memory->row++;
124
+            }
125
+        } else {
93
             print_character(print_memory->line, print_memory->row, *str, print_memory->color);
126
             print_character(print_memory->line, print_memory->row, *str, print_memory->color);
94
             print_memory->row++;
127
             print_memory->row++;
95
         }
128
         }
96
         str++;
129
         str++;
97
     }
130
     }
131
+}
132
+
133
+void debug_clean() {
134
+    memset((void*) 0x0600C800, 0, 0x800);
135
+    print_memory->row = 0;
136
+    print_memory->line = 0;
137
+    print_memory->color = 0;
138
+    return;
139
+}
140
+
141
+void wait_for_btn(u16 field) {
142
+    volatile u16* control_io = (volatile u16*) (0x04000130);
143
+    while (*control_io & field) {
144
+    }
98
     return;
145
     return;
99
 }
146
 }
100
 
147
 
105
     union t_map_entry map_entry;
152
     union t_map_entry map_entry;
106
     map_entry.entry.tile = char_to_byte(character);
153
     map_entry.entry.tile = char_to_byte(character);
107
     map_entry.entry.pal = color;
154
     map_entry.entry.pal = color;
108
-    u16* ptr = (u16*) (0x0600C800 + (position * 2));
155
+    u16* ptr = (u16*) (0x0600c800 + (position * 2));
109
     *ptr = map_entry.short_map;
156
     *ptr = map_entry.short_map;
110
     return;
157
     return;
111
 }
158
 }
115
         return character - 0x20;
162
         return character - 0x20;
116
     else
163
     else
117
         return 3;
164
         return 3;
165
+}
166
+
167
+void debug_update() {
168
+    fade_update();
169
+    task_exec();
170
+    objc_exec();
171
+    obj_sync();
172
+    gpu_pal_upload();
173
+    gpu_sprites_upload();
174
+}
175
+
176
+void int_to_char(u32 i, char* ref) {
177
+    if (i == 0) {
178
+        ref[0] = '0';
179
+        return;
180
+    }
181
+    u32 len = dec_len(i);
182
+    while (i > 0) {
183
+
184
+        ref[len - 1] = '0' + (__aeabi_uidivmod(i, 10));
185
+        i /= 10;
186
+        len--;
187
+    }
188
+
189
+    return;
190
+}
191
+
192
+u32 power(u32 n, u32 power) {
193
+    u32 out = 1;
194
+    for (int i = 0; i < power; ++i) {
195
+        out = out * n;
196
+    }
197
+    return out;
198
+}
199
+
200
+u32 dec_len(u32 i) {
201
+    u32 len = 1;
202
+    while ((i /= 10) > 0) {
203
+        len++;
204
+    }
205
+    return len;
118
 }
206
 }

src/battle_engine/battle_help.h → src/include/battle_help.h View File


src/battle_engine/battle_initiative.h → src/include/battle_initiative.h View File

1
 #ifndef BATTLE_INITIATIVE_H
1
 #ifndef BATTLE_INITIATIVE_H
2
 #define BATTLE_INITIATIVE_H
2
 #define BATTLE_INITIATIVE_H
3
 
3
 
4
-#include <battle.h>
5
-#include "battle_help.h"
6
-#include <bpre.h>
4
+#include <types.h>
7
 
5
 
8
 enum init_enum {ONE, TWO, TIE};
6
 enum init_enum {ONE, TWO, TIE};
9
 
7
 

+ 7
- 0
src/include/battle_test.h View File

1
+#ifndef BATTLE_TEST_H
2
+#define BATTLE_TEST_H
3
+
4
+void test_battle();
5
+
6
+#endif /* BATTLE_TEST_H */
7
+

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

8
 #include <callback.h>
8
 #include <callback.h>
9
 #include <config.h>
9
 #include <config.h>
10
 
10
 
11
+u32 __aeabi_uidivmod(u32 a, u32 b);
11
 u16 *var_access(int index);
12
 u16 *var_access(int index);
12
 u8 flag_check(int flag);
13
 u8 flag_check(int flag);
13
 void clear_flag(u16 flag);
14
 void clear_flag(u16 flag);
14
 u16 random();
15
 u16 random();
15
 void* malloc(int size);
16
 void* malloc(int size);
16
 void free(void* address);
17
 void free(void* address);
17
-void* memcpy (void * destination, const void* source, u32 num);
18
+void* memcpy (void * destination, const void* source, size_t num);
19
+void* memset (void* dst, int value, size_t size);
18
 
20
 
19
 //debug
21
 //debug
20
 void agbprintf(const char* pBuf, ...);
22
 void agbprintf(const char* pBuf, ...);

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

9
 
9
 
10
 static struct print_engine* print_memory = (struct print_engine*)(0x0203FFF0);
10
 static struct print_engine* print_memory = (struct print_engine*)(0x0203FFF0);
11
 
11
 
12
-void some_test();
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();
13
 void reset_scrolling_debug();
19
 void reset_scrolling_debug();
14
 void init_unit_test();
20
 void init_unit_test();
15
 void debug_scene();
21
 void debug_scene();
16
 u8 char_to_byte(char character);
22
 u8 char_to_byte(char character);
17
 void print_character(u16 line, u16 row, char character, u8 color);
23
 void print_character(u16 line, u16 row, char character, u8 color);
18
 void print_string(u16 line, u16 row, u8 color, char* pBuf);
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);
19
 
28
 
20
 #endif /* DEBUG_H */
29
 #endif /* DEBUG_H */
21
 
30
 

+ 2
- 0
src/include/types.h View File

14
 typedef     float                   f32;
14
 typedef     float                   f32;
15
 typedef     double                  f64;
15
 typedef     double                  f64;
16
 
16
 
17
+typedef     unsigned int            size_t;
18
+
17
 #define true 1
19
 #define true 1
18
 #define false 0
20
 #define false 0
19
 
21