Skip to content

Commit 979e559

Browse files
committed
Merge branch 'master' of https://github.com/pret/pokefirered
2 parents d31a2a2 + 0c17a3b commit 979e559

File tree

1,825 files changed

+79022
-77234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,825 files changed

+79022
-77234
lines changed

.github/calcrom/calcrom.pl

+15-13
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
}
6969

7070
my @sorted = sort { $a->[1] <=> $b->[1] } @pairs;
71+
(my $elffname = $ARGV[0]) =~ s/\.map/.elf/;
7172

7273
# Note that the grep filters out all branch labels. It also requires a minimum
7374
# line length of 5, to filter out a ton of generated symbols (like AcCn). No
@@ -78,16 +79,17 @@
7879
#
7980
# You'd expect this to take a while, because of uniq. It runs in under a second,
8081
# though. Uniq is pretty fast!
81-
my $base_cmd = "nm pokefirered.elf | awk '{print \$3}' | grep '^[^_].\\{4\\}' | uniq";
82+
my $base_cmd = "nm $elffname | awk '{print \$3}' | grep '^[^_].\\{4\\}' | uniq";
8283

83-
# This looks for Unknown_, Unknown_, or sub_, followed by just numbers. Note that
84+
# This looks for Unknown_, Unknown_, or sub_, followed by an address. Note that
8485
# it matches even if stuff precedes the unknown, like sUnknown/gUnknown.
85-
my $undoc_cmd = "grep '[Uu]nknown_[0-9a-fA-F]*\\|sub_[0-9a-fA-F]*'";
86+
my $undoc_regex = "'[Uu]nknown_[0-9a-fA-F]\\{5,7\\}\\|sub_[0-9a-fA-F]\\{5,7\\}'";
8687

8788
# This looks for every symbol with an address at the end of it. Some things are
8889
# given a name based on their type / location, but still have an unknown purpose.
8990
# For example, FooMap_EventScript_FFFFFFF.
90-
my $partial_doc_cmd = "grep '_[0-38][0-9a-fA-F]\\{5,6\\}'";
91+
# The above may be double counted here, and will need to be filtered out.
92+
my $partial_doc_regex = "'_[0-28][0-9a-fA-F]\\{5,7\\}'";
9193

9294
my $count_cmd = "wc -l";
9395

@@ -104,15 +106,15 @@
104106

105107
my $undocumented_as_string;
106108
(run (
107-
command => "$base_cmd | $undoc_cmd | $count_cmd",
109+
command => "$base_cmd | grep $undoc_regex | $count_cmd",
108110
buffer => \$undocumented_as_string,
109111
timeout => 60
110112
))
111113
or die "ERROR: Error while filtering for undocumented symbols: $?";
112114

113115
my $partial_documented_as_string;
114116
(run (
115-
command => "$base_cmd | $partial_doc_cmd | $count_cmd",
117+
command => "$base_cmd | grep $partial_doc_regex | grep -v $undoc_regex | $count_cmd",
116118
buffer => \$partial_documented_as_string,
117119
timeout => 60
118120
))
@@ -121,16 +123,19 @@
121123
# Performing addition on a string converts it to a number. Any string that fails
122124
# to convert to a number becomes 0. So if our converted number is 0, but our string
123125
# is nonzero, then the conversion was an error.
126+
$undocumented_as_string =~ s/^\s+|\s+$//g;
124127
my $undocumented = $undocumented_as_string + 0;
125-
(($undocumented != 0) and ($undocumented_as_string ne "0"))
128+
(($undocumented != 0) or (($undocumented == 0) and ($undocumented_as_string eq "0")))
126129
or die "ERROR: Cannot convert string to num: '$undocumented_as_string'";
127130

131+
$partial_documented_as_string =~ s/^\s+|\s+$//g;
128132
my $partial_documented = $partial_documented_as_string + 0;
129-
(($partial_documented != 0) and ($partial_documented_as_string ne "0"))
130-
or die "ERROR: Cannot convert string to num: '$partial_documented_as_string'";
133+
(($partial_documented != 0) or (($partial_documented == 0) and ($partial_documented_as_string eq "0")))
134+
or die "ERROR: Cannot convert string to num: '$partial_documented_as_string'";
131135

136+
$total_syms_as_string =~ s/^\s+|\s+$//g;
132137
my $total_syms = $total_syms_as_string + 0;
133-
(($total_syms != 0) and ($total_syms_as_string ne "0"))
138+
(($total_syms != 0) or (($total_syms == 0) and ($total_syms_as_string eq "0")))
134139
or die "ERROR: Cannot convert string to num: '$total_syms_as_string'";
135140

136141
($total_syms != 0)
@@ -140,9 +145,6 @@
140145
my $srcPct = sprintf("%.4f", 100 * $src / $total);
141146
my $asmPct = sprintf("%.4f", 100 * $asm / $total);
142147

143-
# partial_documented is double-counting the unknown_* and sub_* symbols.
144-
$partial_documented = $partial_documented - $undocumented;
145-
146148
my $documented = $total_syms - ($undocumented + $partial_documented);
147149
my $docPct = sprintf("%.4f", 100 * $documented / $total_syms);
148150
my $partialPct = sprintf("%.4f", 100 * $partial_documented / $total_syms);

.github/workflows/build.yml

-8
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ jobs:
7373
run: |
7474
make -j${nproc} all
7575
76-
- name: Webhook
77-
if: ${{ github.event_name == 'push' && github.repository_owner == 'pret' }}
78-
env:
79-
CALCROM_DISCORD_WEBHOOK_USERNAME: OK
80-
CALCROM_DISCORD_WEBHOOK_AVATAR_URL: https://i.imgur.com/38BQHdd.png
81-
CALCROM_DISCORD_WEBHOOK_URL: ${{ secrets.CALCROM_DISCORD_WEBHOOK_URL }}
82-
run: sh .github/calcrom/webhook.sh pokefirered
83-
8476
- name: Move symfiles
8577
if: ${{ github.event_name == 'push' }}
8678
run: |

.gitignore

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*.id1
2323
*.id2
2424
*.latfont
25-
*.ld
2625
*.lz
2726
*.map
2827
*.nam
@@ -46,14 +45,18 @@ ld_script_sapphire.txt
4645
sound/**/*.bin
4746
sound/songs/midi/*.s
4847
src/data/items.h
48+
src/data/region_map/region_map_entries.h
49+
src/data/region_map/region_map_entry_strings.h
50+
src/data/region_map/porymap_config.json
4951
tags
5052
tools/agbcc
5153
tools/binutils
5254
types_*.taghl
5355
!.github/calcrom/calcrom.pl
5456
!sound/programmable_wave_samples/*.pcm
5557
_Deparsed_XSubs.pm
56-
porymap.project.cfg
58+
porymap.*.cfg
59+
prefabs.json
5760
.vscode/*.*
5861
*.ss1
5962
*.ss2

INSTALL.md

+66-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you run into trouble, ask for help on Discord or IRC (see [README.md](README.
99

1010
## Windows
1111
Windows has instructions for building with three possible terminals, providing 3 different options in case the user stumbles upon unexpected errors.
12-
- [Windows 10 (WSL1)](#windows-10-wsl1) (**Fastest, highly recommended**, Windows 10 only)
12+
- [Windows 10/11 (WSL1)](#windows-1011-wsl1) (**Fastest, highly recommended**, Windows 10 and 11 only)
1313
- [Windows (msys2)](#windows-msys2) (Second fastest)
1414
- [Windows (Cygwin)](#windows-cygwin) (Slowest)
1515

@@ -26,7 +26,7 @@ All of the Windows instructions assume that the default drive is C:\\. If this d
2626

2727
**A note of caution**: As Windows 7 is officially unsupported by Microsoft and Windows 8 has very little usage, some maintainers are unwilling to maintain the Windows 7/8 instructions. Thus, these instructions may break in the future with fixes taking longer than fixes to the Windows 10 instructions.
2828

29-
## Windows 10 (WSL1)
29+
## Windows 10/11 (WSL1)
3030
WSL1 is the preferred terminal to build **pokefirered**. The following instructions will explain how to install WSL1 (referred to interchangeably as WSL).
3131
- If WSL (Debian or Ubuntu) is **not installed**, then go to [Installing WSL1](#Installing-WSL1).
3232
- Otherwise, if WSL is installed, but it **hasn't previously been set up for another decompilation project**, then go to [Setting up WSL1](#Setting-up-WSL1).
@@ -125,19 +125,52 @@ Otherwise, ask for help on Discord or IRC (see [README.md](README.md)), or conti
125125

126126
Note that in msys2, Copy is Ctrl+Insert and Paste is Shift+Insert.
127127

128-
1. Open msys2 at C:\devkitPro\msys2\mingw64.exe or run `C:\devkitPro\msys2\msys2_shell.bat -mingw64`.
128+
1. Open msys2 at C:\devkitPro\msys2\msys2_shell.bat.
129129

130130
2. Certain packages are required to build pokefirered. Install these by running the following command:
131131

132132
```bash
133-
pacman -S make zlib-devel git mingw-w64-x86_64-gcc mingw-w64-x86_64-libpng
133+
pacman -S make gcc zlib-devel git
134134
```
135135
<details>
136136
<summary><i>Note...</i></summary>
137137

138138
> This command will ask for confirmation, just enter the yes action when prompted.
139139
</details>
140140

141+
3. Download [libpng](https://sourceforge.net/projects/libpng/files/libpng16/1.6.37/libpng-1.6.37.tar.xz/download).
142+
143+
4. Change directory to where libpng was downloaded. By default, msys2 will start in the current user's profile folder, located at **C:\Users\\&#8288;_\<user>_**, where *\<user>* is your Windows username. In most cases, libpng should be saved within a subfolder of the profile folder. For example, if libpng was saved to **C:\Users\\_\<user>_\Downloads** (the Downloads location for most users), enter this command:
144+
145+
```bash
146+
cd Downloads
147+
```
148+
149+
<details>
150+
<summary><i>Notes...</i></summary>
151+
152+
> Note 1: While not shown, msys uses forward slashes `/` instead of backwards slashes `\` as the directory separator.
153+
> Note 2: If the path has spaces, then the path must be wrapped with quotations, e.g. `cd "Downloads/My Downloads"`.
154+
> Note 3: Windows path names are case-insensitive so adhering to capitalization isn’t needed.
155+
> Note 4: If libpng was saved elsewhere, you will need to specify the full path to where libpng was downloaded, e.g. `cd c:/devkitpro/msys2` if it was saved there.
156+
</details>
157+
158+
5. Run the following commands to uncompress and install libpng.
159+
160+
```bash
161+
tar xf libpng-1.6.37.tar.xz
162+
cd libpng-1.6.37
163+
./configure --prefix=/usr
164+
make check
165+
make install
166+
```
167+
168+
6. Then finally, run the following command to change back to the user profile folder.
169+
170+
```bash
171+
cd
172+
```
173+
141174
### Choosing where to store pokefirered (msys2)
142175
At this point, you can choose a folder to store pokefirered into. If you're okay with storing pokefirered in the user profile folder, then proceed to [Installation](#installation). Otherwise, you'll need to account for where pokefirered is stored when changing directory to the pokefirered folder.
143176

@@ -236,13 +269,19 @@ If this works, then proceed to [Installation](#installation). Otherwise, ask for
236269
237270
> This guide installs libpng via Homebrew as it is the easiest method, however advanced users can install libpng through other means if they so desire.
238271
</details>
272+
<details>
273+
<summary><i><strong>Note for Apple Silicon (M1) Mac users...</strong></i></summary>
274+
275+
> Currently, Homebrew and libng must be installed via Rosetta on Apple Silicon Macs. Before continuing, create a [Terminal shell profile with Rosetta](https://www.astroworldcreations.com/blog/apple-silicon-and-legacy-command-line-software). Be sure to run the commands corresponding to Apple Silicon (M1).
276+
</details>
239277
240278
1. Open the Terminal.
241279
2. If Homebrew is not installed, then install [Homebrew](https://brew.sh/) by following the instructions on the website.
242280
3. Run the following command to install libpng.
243281
244282
```bash
245-
brew install libpng
283+
brew install libpng # Intel Macs
284+
/usr/local/bin/brew install libpng # Apple Silicon (M1) Macs
246285
```
247286
libpng is now installed.
248287
@@ -265,11 +304,14 @@ If this works, then proceed to [Installation](#installation). Otherwise, ask for
265304
266305
```bash
267306
export DEVKITPRO=/opt/devkitpro
268-
echo "export DEVKITPRO=$DEVKITPRO" >> ~/.bashrc
307+
echo "export DEVKITPRO=$DEVKITPRO" >> ~/.bashrc # Intel Macs
308+
echo "export DEVKITPRO=$DEVKITPRO" >> ~/.zshrc # Apple Silicon (M1) Macs
269309
export DEVKITARM=$DEVKITPRO/devkitARM
270-
echo "export DEVKITARM=$DEVKITARM" >> ~/.bashrc
310+
echo "export DEVKITARM=$DEVKITARM" >> ~/.bashrc # Intel Macs
311+
echo "export DEVKITARM=$DEVKITARM" >> ~/.zshrc # Apple Silicon (M1) Macs
271312
272-
echo "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi" >> ~/.bash_profile
313+
echo "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi" >> ~/.bash_profile # Intel Macs
314+
echo "if [ -f ~/.zshrc ]; then . ~/.zshrc; fi" >> ~/.zprofile # Apple Silicon (M1) Macs
273315
```
274316
275317
### Choosing where to store pokefirered (macOS)
@@ -404,21 +446,16 @@ If you aren't in the pokefirered directory already, then **change directory** to
404446
```bash
405447
cd pokefirered
406448
```
407-
To build **pokefirered.gba** for the first time and confirm it matches the official ROM image (Note: to speed up builds, see [Parallel builds](#parallel-builds)):
449+
To build **pokefirered.gba** (Note: to speed up builds, see [Parallel builds](#parallel-builds)):
408450
```bash
409-
make compare
451+
make
410452
```
411-
If an OK is returned, then the installation went smoothly.
453+
If it has built successfully you will have the output file **pokefirered.gba** in your project folder.
412454
<details>
413455
<summary>Note for Windows...</summary>
414456
> If you switched terminals since the last build (e.g. from msys2 to WSL1), you must run `make clean-tools` once before any subsequent `make` commands.
415457
</details>
416458

417-
To build **pokefirered.gba** with your changes:
418-
```bash
419-
make
420-
```
421-
422459
## Build pokeleafgreen and REV1
423460
Pokemon FireRed and LeafGreen were both released together. As such, this project is capable of building both ROMs. To do so, simply run
424461
```bash
@@ -449,11 +486,20 @@ Replace `<output of nproc>` with the number that the `nproc` command returned.
449486

450487
`nproc` is not available on macOS. The alternative is `sysctl -n hw.ncpu` ([relevant Stack Overflow thread](https://stackoverflow.com/questions/1715580)).
451488

452-
## Debug info
489+
## Compare ROM to the original
453490

454-
To build **pokefirered.elf** with enhanced debug info:
491+
For contributing, or if you'd simply like to verify that your ROM is identical to the original game, run:
492+
```bash
493+
make compare # or compare_leafgreen, compare_firered_rev1, compare_leafgreen_rev1
494+
```
495+
If it matches, you will see the following at the end of the output:
496+
```bash
497+
pokefirered.gba: OK
498+
```
499+
If there are any changes from the original game, you will instead see:
455500
```bash
456-
make DINFO=1
501+
pokefirered.gba: FAILED
502+
shasum: WARNING: 1 computed checksum did NOT match
457503
```
458504
459505
## devkitARM's C compiler
@@ -548,4 +594,4 @@ To compile the `modern` target with this toolchain, the subdirectories `lib`, `i
548594

549595
* [porymap](https://github.com/huderlem/porymap) for viewing and editing maps
550596
* [poryscript](https://github.com/huderlem/poryscript) for scripting ([VS Code extension](https://marketplace.visualstudio.com/items?itemName=karathan.poryscript))
551-
* [Tilemap Studio](https://github.com/Rangi42/tilemap-studio) for viewing and editing tilemaps
597+
* [Tilemap Studio](https://github.com/Rangi42/tilemap-studio) for viewing and editing tilemaps

Makefile

+7-10
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ ASM_SUBDIR = asm
8181
DATA_ASM_SUBDIR = data
8282
SONG_SUBDIR = sound/songs
8383
MID_SUBDIR = sound/songs/midi
84+
SAMPLE_SUBDIR = sound/direct_sound_samples
8485
CRY_SUBDIR = sound/direct_sound_samples/cries
8586

8687
C_BUILDDIR = $(OBJ_DIR)/$(C_SUBDIR)
@@ -194,7 +195,7 @@ compare:
194195
@$(MAKE) COMPARE=1
195196

196197
mostlyclean: tidy
197-
$(RM) sound/direct_sound_samples/*.bin
198+
rm -f $(SAMPLE_SUBDIR)/*.bin
198199
rm -f $(CRY_SUBDIR)/*.bin
199200
$(RM) $(SONG_OBJS) $(MID_SUBDIR)/*.s
200201
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.latfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} +
@@ -247,7 +248,7 @@ $(C_BUILDDIR)/isagbprn.o: CC1 := tools/agbcc/bin/old_agbcc$(EXE)
247248
$(C_BUILDDIR)/isagbprn.o: CFLAGS := -mthumb-interwork
248249

249250
$(C_BUILDDIR)/trainer_tower.o: CFLAGS += -ffreestanding
250-
$(C_BUILDDIR)/flying.o: CFLAGS += -ffreestanding
251+
$(C_BUILDDIR)/battle_anim_flying.o: CFLAGS += -ffreestanding
251252

252253
$(C_BUILDDIR)/librfu_intr.o: CC1 := tools/agbcc/bin/agbcc_arm$(EXE)
253254
$(C_BUILDDIR)/librfu_intr.o: CFLAGS := -O2 -mthumb-interwork -quiet
@@ -326,19 +327,15 @@ $(OBJ_DIR)/sym_ewram.ld: sym_ewram.txt
326327
$(RAMSCRGEN) ewram_data $< ENGLISH > $@
327328

328329
ifeq ($(MODERN),0)
329-
LD_SCRIPT := ld_script.txt
330+
LD_SCRIPT := ld_script.ld
330331
LD_SCRIPT_DEPS := $(OBJ_DIR)/sym_bss.ld $(OBJ_DIR)/sym_common.ld $(OBJ_DIR)/sym_ewram.ld
331332
else
332-
LD_SCRIPT := ld_script_modern.txt
333+
LD_SCRIPT := ld_script_modern.ld
333334
LD_SCRIPT_DEPS :=
334335
endif
335336

336-
$(OBJ_DIR)/ld_script.ld: $(LD_SCRIPT) $(LD_SCRIPT_DEPS)
337-
cd $(OBJ_DIR) && sed -f ../../ld_script.sed ../../$< | sed "s#tools/#../../tools/#g" > ld_script.ld
338-
339-
$(ELF): $(OBJ_DIR)/ld_script.ld $(OBJS)
340-
@echo "cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ <objects> <lib>"
341-
@cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ $(OBJS_REL) $(LIB)
337+
$(ELF): $(LD_SCRIPT) $(LD_SCRIPT_DEPS) $(OBJS)
338+
@cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ../../$< -o ../../$@ $(OBJS_REL) $(LIB)
342339
$(FIX) $@ -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(GAME_REVISION) --silent
343340

344341
$(ROM): $(ELF)

README.md

+1-15
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,7 @@ This is the repository for the Pokémon FireRed and LeafGreen+ hack, based on [p
1111

1212
## See also
1313

14-
Other pret disassembly and/or decompilation projects:
15-
* [**Pokémon Red and Blue**](https://github.com/pret/pokered)
16-
* [**Pokémon Gold and Silver (Space World '97 demo)**](https://github.com/pret/pokegold-spaceworld)
17-
* [**Pokémon Yellow**](https://github.com/pret/pokeyellow)
18-
* [**Pokémon Trading Card Game**](https://github.com/pret/poketcg)
19-
* [**Pokémon Pinball**](https://github.com/pret/pokepinball)
20-
* [**Pokémon Stadium**](https://github.com/pret/pokestadium)
21-
* [**Pokémon Gold and Silver**](https://github.com/pret/pokegold)
22-
* [**Pokémon Crystal**](https://github.com/pret/pokecrystal)
23-
* [**Pokémon Ruby and Sapphire**](https://github.com/pret/pokeruby)
24-
* [**Pokémon FireRed and LeafGreen**](https://github.com/pret/pokefirered)
25-
* [**Pokémon Pinball: Ruby & Sapphire**](https://github.com/pret/pokepinballrs)
26-
* [**Pokémon Emerald**](https://github.com/pret/pokeemerald)
27-
* [**Pokémon Mystery Dungeon: Red Rescue Team**](https://github.com/pret/pmd-red)
28-
14+
For other pret projects, see [pret.github.io](https://pret.github.io/).
2915

3016
## Discord server for pret
3117

asm/macros.inc

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.include "asm/macros/asm.inc"
22
.include "asm/macros/function.inc"
33
.include "asm/macros/movement.inc"
4-
.include "asm/macros/pokemon_data.inc"
54
.include "asm/macros/ec.inc"
65
.include "asm/macros/map.inc"
76
.include "asm/macros/m4a.inc"

0 commit comments

Comments
 (0)