Skip to content

Commit 7bee4a2

Browse files
committedJan 26, 2019
Merge branch 'master' of https://github.com/Sagiri/wonder-trade
2 parents 3f0098e + 2cb79f5 commit 7bee4a2

File tree

8 files changed

+69
-31
lines changed

8 files changed

+69
-31
lines changed
 

‎main.asm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.gba
22
.thumb
33

4-
.open "test.gba", 0x08000000
4+
.open "rom.gba", "test.gba", 0x08000000
55

66
.org allocation
77

‎scripts/makinoa/__main__.py

+35-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os, sys, argparse, configparser, shutil, subprocess, fnmatch, itertools
44
import os.path
55
import kewensis
6+
from orderedset import OrderedSet
7+
from collections import OrderedDict
68

79
src = "src"
810
build = "build"
@@ -28,9 +30,9 @@
2830
free_space = iniparser.get("main", "free-space", fallback="0x08800000")
2931
optimization_level = iniparser.get("main", "optimization-level", fallback="-O2")
3032
reserve = iniparser.get("main", "reserve", fallback="0")
31-
static_objects = set() if "static" not in iniparser else set(iniparser["static"])
32-
defines = {} if "defines" not in iniparser else dict(iniparser["defines"])
33-
libgcc = set() if "libgcc" not in iniparser else set(iniparser["libgcc"])
33+
static_objects = OrderedSet() if "static" not in iniparser else OrderedSet(iniparser["static"])
34+
defines = OrderedDict() if "defines" not in iniparser else OrderedDict(iniparser["defines"])
35+
libgcc = OrderedSet() if "libgcc" not in iniparser else OrderedSet(iniparser["libgcc"])
3436

3537
try:
3638
free_space = int(free_space, 16)
@@ -64,6 +66,7 @@
6466

6567
CC = os.path.join(DEVKITARM, "bin", "arm-none-eabi-gcc")
6668
LD = os.path.join(DEVKITARM, "bin", "arm-none-eabi-ld")
69+
SIZE = os.path.join(DEVKITARM, "bin", "arm-none-eabi-size")
6770

6871
CFLAGS = [
6972
optimization_level,
@@ -85,7 +88,12 @@
8588
"--relocatable"
8689
]
8790

88-
relocatable_objects = set()
91+
SIZEFLAGS = [
92+
"-d",
93+
"-B"
94+
]
95+
96+
relocatable_objects = OrderedSet()
8997

9098
if os.path.exists(src):
9199
for srcfile in (path for path in os.listdir(src) if fnmatch.fnmatch(path, "*.c")):
@@ -126,6 +134,14 @@
126134
if not libgcc:
127135
break
128136

137+
needed_words = 0
138+
139+
def round_up_to_4(x):
140+
if x & 0x3 == 0:
141+
return x
142+
else:
143+
return round_up_to_4(x + 1)
144+
129145
if relocatable_objects:
130146
exit_code = subprocess.run([
131147
LD,
@@ -138,17 +154,24 @@
138154
if exit_code != 0:
139155
print("Error :: Linking failed.")
140156
sys.exit(exit_code)
141-
142-
def round_up_to_4(x):
143-
if x & 0x3 == 0:
144-
return x
145-
else:
146-
return round_up_to_4(x + 1)
157+
158+
rslt = subprocess.run([
159+
SIZE,
160+
*SIZEFLAGS,
161+
relocatable
162+
], stdout=subprocess.PIPE)
163+
164+
if rslt.returncode != 0:
165+
print("Error :: Size calculation failed.")
166+
sys.exit(rslt.returncode)
167+
168+
sz = int(rslt.stdout.decode("UTF-8").split("\n")[1].split()[3])
169+
170+
needed_words = round_up_to_4(sz + reserve) >> 2
147171

148172
offset_mask = 0x08000000
149173
free_space |= offset_mask
150174

151-
needed_words = round_up_to_4(os.stat(relocatable).st_size + reserve) >> 2
152175
free_space = round_up_to_4(free_space)
153176

154177
def find_needed_words(needed_words, free_space):
@@ -176,7 +199,7 @@ def find_needed_words(needed_words, free_space):
176199

177200
return start ^ offset_mask
178201

179-
shutil.copy("rom.gba", "test.gba")
202+
# shutil.copy("rom.gba", "test.gba")
180203

181204
if "ARMIPS" in os.environ:
182205
ARMIPS = os.environ["ARMIPS"]

‎scripts/makinoa/orderedset.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import collections
2+
3+
class OrderedSet():
4+
def __init__(self, things=()):
5+
self._dict = collections.OrderedDict()
6+
for thing in things:
7+
self._dict[thing] = None
8+
9+
def __iter__(self):
10+
return iter(self._dict)
11+
12+
def add(self, thing):
13+
self._dict[thing] = None
14+
15+
def remove(self, thing):
16+
self._dict.pop(thing)
17+
18+
def __bool__(self):
19+
return bool(self._dict)

‎src/functions.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include "types.h"
33

44
u8 b_trainer_build_party(struct pokemon* party, u16 tid);
5-
u32 strnlen(u8*, u32);
5+
u32 strnlen(const char*, u32);
66
u16 rand();
77
u32 umod(u32, u32);
8-
void memcpy(void *dst, void *src, u32 size);
9-
void pokemon_setattr(struct pokemon*, u8, void*);
8+
void memcpy(void* dst, const void* src, u32 size);
9+
void pokemon_setattr(struct pokemon*, u8, const void*);

‎src/gen_random_pokemon.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "defines.h"
1+
#include "global.h"
22

33
void gen_random_pokemon() {
44
u16 tid;
@@ -23,7 +23,7 @@ void gen_random_pokemon() {
2323
pokemon_setattr(&party_trader[0], REQ_METLOC, &location);
2424
}
2525

26-
u32 strnlen(u8* str, u32 max) {
26+
u32 strnlen(const char* str, u32 max) {
2727
u32 len = 0;
2828
while(*str != 0xFF && len < max) {
2929
++len;

‎src/defines.h ‎src/global.h

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#pragma once
22
#include "types.h"
33

4+
#define PARTY_SIZE 6
5+
#define NUM_TRAINERS 743
6+
47
#include "structs.h"
58
#include "functions.h"
69
#include "locations.h"

‎src/locations.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#pragma once
22
#include "types.h"
33

4-
extern u32 battle_type_flags;
4+
extern u32 battle_type_flags;
5+
6+
extern struct pokemon party_opponent[PARTY_SIZE];
7+
extern const struct trainer trainers[NUM_TRAINERS];

‎src/structs.h

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
#pragma once
22
#include "types.h"
33

4-
#define PARTY_SIZE 6
5-
64
struct pokemon {
75
u8 _[100];
86
};
97

10-
extern struct pokemon party_opponent[PARTY_SIZE];
11-
12-
// -----------------------------------------------------------------------------
13-
14-
#define NUM_TRAINERS 743
15-
168
struct trainer {
179
u8 custom_moveset_flag : 1;
1810
u8 held_item_flag : 1;
@@ -21,12 +13,10 @@ struct trainer {
2113
u8 music : 7;
2214
u8 gender : 1;
2315
u8 sprite;
24-
u8 name[12];
16+
char name[12];
2517
u8 data[8];
2618
u8 double_flag;
2719
u8 data2[7];
2820
u32 party_size;
2921
void* party_data;
30-
};
31-
32-
extern struct trainer trainers[NUM_TRAINERS];
22+
};

0 commit comments

Comments
 (0)
Please sign in to comment.