Merge branch 'master' into pokenav_unk_2

This commit is contained in:
PikalaxALT 2019-08-05 08:33:45 -04:00
commit 51d5ee771d
8 changed files with 905 additions and 1205 deletions

2
.gitattributes vendored
View File

@ -1,5 +1,5 @@
*.pal text eol=crlf
*.sh text eol=lf
*.s text eol=lf
*.txt text eol=lf
Makefile text eol=lf

View File

@ -1,116 +1,90 @@
Follow the OS-specific instructions below.
# Prerequisites
# Linux
| Linux | macOS | Windows 10 (build 18917+) | Windows 10 (1709+) | Windows Vista, 7, 8, 8.1, and 10 (1507, 1511, 1607, and 1703)
| ----- | ----- | ------------------------- | ------------------ | ---------------------------------------------------------
| none | [Xcode Command Line Tools package][xcode] | [Windows Subsystem for Linux 2][wsl2] | [Windows Subsystem for Linux][wsl] | MSYS2 (see below)
Install [**devkitARM**](http://devkitpro.org/wiki/Getting_Started/devkitARM).
[xcode]: https://developer.apple.com/library/archive/technotes/tn2339/_index.html#//apple_ref/doc/uid/DTS40014588-CH1-DOWNLOADING_COMMAND_LINE_TOOLS_IS_NOT_AVAILABLE_IN_XCODE_FOR_MACOS_10_9__HOW_CAN_I_INSTALL_THEM_ON_MY_MACHINE_
[wsl2]: https://docs.microsoft.com/windows/wsl/wsl2-install
[wsl]: https://docs.microsoft.com/windows/wsl/install-win10
Make sure that there is an environment variable called DEVKITARM with the path of the directory before the "bin" directory containing "arm-none-eabi-as", "arm-none-eabi-cpp", "arm-none-eabi-ld" and "arm-none-eabi-objcopy".
The [prerelease version of the Linux subsystem](https://docs.microsoft.com/windows/wsl/install-legacy) available in the 1607 and 1703 releases of Windows 10 is obsolete so consider uninstalling it.
Then get the compiler from https://github.com/pret/agbcc and run the following commands.
Make sure that the `build-essential`, `git`, and `libpng-dev` packages are installed. The `build-essential` package includes the `make`, `gcc-core`, and `g++` packages so they do not have to be obtained separately. MSYS2 does not include `libpng-dev` so it must be built from source.
```
./build.sh
./install.sh PATH_OF_POKEEMERALD_DIRECTORY
```
Install the **devkitARM** toolchain of [devkitPro](https://devkitpro.org/wiki/Getting_Started) and add its environment variables. For Windows versions without the Linux subsystem, the devkitPro [graphical installer](https://github.com/devkitPro/installer/releases) includes a preconfigured MSYS2 environment, thus the steps below are not required.
Finally, build the rom.
```
make
```
# Windows
Install [**devkitARM**](http://devkitpro.org/wiki/Getting_Started/devkitARM).
Then get the compiled tools from https://github.com/pret/pokeruby-tools. Copy the `tools/` folder over the `tools/` folder in your pokeemerald directory.
You can then build pokeemerald using `make` in the MSYS environment provided with devkitARM.
# Mac
Installing pokeemerald on a Mac requires macOS >= 10.12 (Sierra or higher).
Download a [devkitPRO pacman](https://github.com/devkitPro/pacman/releases/tag/v1.0.0)
Run the following commands in Terminal:
export DEVKITPRO=/opt/devkitpro
echo "export DEVKITPRO=$DEVKITPRO" >> ~/.bashrc
export DEVKITARM=$DEVKITPRO/devkitARM
echo "export DEVKITARM=$DEVKITARM" >> ~/.bashrc
```
xcode-select --install
# Installation
sudo dkp-pacman -S devkitARM
To set up the repository:
export DEVKITPRO=/opt/devkitpro
echo "export DEVKITPRO=$DEVKITPRO" >> ~/.bashrc
export DEVKITARM=$DEVKITPRO/devkitARM
echo "export DEVKITARM=$DEVKITARM" >> ~/.bashrc
echo "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi" >> ~/.bash_profile
git clone https://github.com/pret/pokeemerald
git clone https://github.com/pret/agbcc
git clone https://github.com/pret/pokeemerald
git clone https://github.com/pret/agbcc
cd ./agbcc
./build.sh
./install.sh ../pokeemerald
cd agbcc/
./build.sh
./install.sh ../pokeemerald
cd ../pokeemerald
cd ../pokeemerald
./build_tools.sh
```
To build **pokeemerald.gba** and confirm it matches the official ROM image:
And build the ROM with `make`.
make compare
If the step `./build.sh` in the above list of commands fails with the error `Makefile:1: /opt/devkitpro/devkitARM/base_tools: No such file or directory`, then try installing the pacman package `devkitarm-rules` by executing the command
## Notes
```
sudo dkp-pacman -S devkitarm-rules
```
* If the base tools are not found on macOS in new Terminal sessions after the first successful build, run `echo "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi" >> ~/.bash_profile` once to prevent the issue from occurring again. Verify that the `devkitarm-rules` package is installed as well; if not, install it by running `sudo dkp-pacman -S devkitarm-rules`.
Executing `./build.sh` again should now succeed.
* If the repository was previously set up using Cygwin, delete the `.exe` files in the subfolders of the `tools` folder except for `agbcc` and try building again. [Learn the differences between MSYS2 and Cygwin.](https://github.com/msys2/msys2/wiki/How-does-MSYS2-differ-from-Cygwin)
# Faster builds
# Guidance
After the first build, subsequent builds are faster. You can further speed up the build:
To build **pokeemerald.gba** with your changes:
## Parallel build
make
This significantly speeds up the build on modern machines.
## Parallel builds
By default `make` only runs a single thread. You can tell `make` to run on multiple threads with `make -j`. See the manfile for usage (`man make`).
See [the GNU docs](https://www.gnu.org/software/make/manual/html_node/Parallel.html) and [this Stack Exchange thread](https://unix.stackexchange.com/questions/208568) for more information.
The optimal value for `-j` is the number of logical cores on your machine. You can run `nproc` to see the exact number.
To speed up building, run:
```
$ nproc
8
```
make -j$(nproc)
If you have 8 cores, run: `make -j8`
`nproc` is not available on macOS. The alternative is `sysctl -n hw.ncpu` ([relevant Stack Overflow thread](https://stackoverflow.com/questions/1715580)).
`-j` on its own will spawn a new thread for each job. A clean build will have thousands of jobs, which will be slower than not using -j at all.
## Building without dependency scanning
## Disable the dependency scanning
If only `.c` or `.s` files were changed, turn off the dependency scanning temporarily. Changes to any other files will be ignored and the build will either fail or not reflect those changes.
If you've only changed `.c` or `.s` files, you can turn off the dependency scanning temporarily. Changes to any other files will be ignored, and the build will either fail or not reflect those changes.
make NODEP=1
`make NODEP=1`
## Building with devkitARM's C compiler
# Building with devkitARM's C compiler
This project supports the `arm-none-eabi-gcc` compiler included with devkitARM r52. To build this target, simply run:
This project supports the `arm-none-eabi-gcc` compiler which ships with devkitARM r52. To build this target, simply run:
make modern
make modern
## Building with other toolchains
# Building with your own toolchain
To build using a toolchain other than devkitARM, override the `TOOLCHAIN` environment variable with the path to your toolchain, which must contain the subdirectory `bin`.
To build Pokemon Emerald with a toolchain other than devkitARM, override the `TOOLCHAIN` environment variable with the path to your toolchain. Example:
make TOOLCHAIN="/path/to/toolchain/here"
make compare TOOLCHAIN=/usr/local/arm-none-eabi
The following is an example:
The path you pass to the `TOOLCHAIN` variable must contain the subdirectory `bin`. If you compile the `modern` target with this toolchain, the subdirectories `lib`, `include`, and `arm-none-eabi` must also be present.
make TOOLCHAIN="/usr/local/arm-none-eabi"
# Building with debug info
To compile the `modern` target with this toolchain, the subdirectories `lib`, `include`, and `arm-none-eabi` must also be present.
To build the ELF file with enhanced debug info, use the `DINFO` variable:
## Building with debug info
make compare DINFO=1
To build **pokeemerald.elf** with enhanced debug info, use the `DINFO` variable.
make DINFO=1

View File

@ -2,37 +2,35 @@
[![Build Status][travis-badge]][travis]
This is a disassembly of Pokémon Emerald.
[travis]: https://travis-ci.org/pret/pokeemerald
[travis-badge]: https://travis-ci.org/pret/pokeemerald.svg?branch=master
It builds the following rom:
This is a decompilation of Pokémon Emerald.
* pokeemerald.gba `sha1: f3ae088181bf583e55daf962a92bb46f4f1d07b7`
It builds the following ROM:
* [**pokeemerald.gba**](https://datomatic.no-intro.org/index.php?page=show_record&s=23&n=1961) `sha1: f3ae088181bf583e55daf962a92bb46f4f1d07b7`
To set up the repository, see [INSTALL.md](INSTALL.md).
## See also
* Disassembly of [**Pokémon Red/Blue**][pokered]
* Disassembly of [**Pokémon Yellow**][pokeyellow]
* Disassembly of [**Pokémon Gold**][pokegold]
* Disassembly of [**Pokémon Crystal**][pokecrystal]
* Disassembly of [**Pokémon Pinball**][pokepinball]
* Disassembly of [**Pokémon TCG**][poketcg]
* Disassembly of [**Pokémon Ruby**][pokeruby]
* Disassembly of [**Pokémon Fire Red**][pokefirered]
* Discord: [**pret**][Discord]
* irc: **irc.freenode.net** [**#pret**][irc]
Other disassembly and/or decompilation projects:
* [**Pokémon Red and Blue**](https://github.com/pret/pokered)
* [**Pokémon Gold and Silver (Space World '97 demo)**](https://github.com/pret/pokegold-spaceworld)
* [**Pokémon Yellow**](https://github.com/pret/pokeyellow)
* [**Pokémon Trading Card Game**](https://github.com/pret/poketcg)
* [**Pokémon Pinball**](https://github.com/pret/pokepinball)
* [**Pokémon Stadium**](https://github.com/pret/pokestadium)
* [**Pokémon Gold and Silver**](https://github.com/pret/pokegold)
* [**Pokémon Crystal**](https://github.com/pret/pokecrystal)
* [**Pokémon Ruby and Sapphire**](https://github.com/pret/pokeruby)
* [**Pokémon Pinball: Ruby & Sapphire**](https://github.com/pret/pokepinballrs)
* [**Pokémon FireRed and LeafGreen**](https://github.com/pret/pokefirered)
* [**Pokémon Mystery Dungeon: Red Rescue Team**](https://github.com/pret/pmd-red)
[pokered]: https://github.com/pret/pokered
[pokeyellow]: https://github.com/pret/pokeyellow
[pokegold]: https://github.com/pret/pokegold
[pokecrystal]: https://github.com/pret/pokecrystal
[pokepinball]: https://github.com/pret/pokepinball
[poketcg]: https://github.com/pret/poketcg
[pokeruby]: https://github.com/pret/pokeruby
[pokefirered]: https://github.com/pret/pokefirered
[Discord]: https://discord.gg/6EuWgX9
[irc]: https://kiwiirc.com/client/irc.freenode.net/?#pret
[travis]: https://travis-ci.org/pret/pokeemerald
[travis-badge]: https://travis-ci.org/pret/pokeemerald.svg?branch=master
## Contacts
You can find us on [Discord](https://discord.gg/6EuWgX9) and [IRC](https://kiwiirc.com/client/irc.freenode.net/?#pret).

View File

@ -5,206 +5,7 @@
@ File centered around AllocSubstruct(9)
thumb_func_start sub_81CF9BC
sub_81CF9BC: @ 81CF9BC
push {r4,lr}
movs r0, 0x9
movs r1, 0x20
bl AllocSubstruct
adds r4, r0, 0
cmp r4, 0
beq _081CF9FC
ldr r1, =0x000006ac
movs r0, 0x12
bl AllocSubstruct
str r0, [r4, 0x1C]
cmp r0, 0
beq _081CF9FC
ldr r0, =sub_81CFA68
str r0, [r4]
ldr r0, =sub_81CFB74
movs r1, 0x1
bl CreateLoopedTask
str r0, [r4, 0x4]
movs r0, 0
str r0, [r4, 0x14]
movs r0, 0x1
b _081CF9FE
.pool
_081CF9FC:
movs r0, 0
_081CF9FE:
pop {r4}
pop {r1}
bx r1
thumb_func_end sub_81CF9BC
thumb_func_start sub_81CFA04
sub_81CFA04: @ 81CFA04
push {r4,lr}
movs r0, 0x9
movs r1, 0x20
bl AllocSubstruct
adds r4, r0, 0
cmp r4, 0
beq _081CFA2C
movs r0, 0x12
bl GetSubstructPtr
str r0, [r4, 0x1C]
ldr r0, =sub_81CFA88
str r0, [r4]
movs r0, 0x1
str r0, [r4, 0x14]
b _081CFA2E
.pool
_081CFA2C:
movs r0, 0
_081CFA2E:
pop {r4}
pop {r1}
bx r1
thumb_func_end sub_81CFA04
thumb_func_start sub_81CFA34
sub_81CFA34: @ 81CFA34
push {lr}
movs r0, 0x9
bl GetSubstructPtr
ldr r1, [r0]
bl _call_via_r1
pop {r1}
bx r1
thumb_func_end sub_81CFA34
thumb_func_start sub_81CFA48
sub_81CFA48: @ 81CFA48
push {lr}
movs r0, 0x9
bl GetSubstructPtr
ldr r0, [r0, 0x18]
cmp r0, 0
bne _081CFA5C
movs r0, 0x12
bl FreePokenavSubstruct
_081CFA5C:
movs r0, 0x9
bl FreePokenavSubstruct
pop {r0}
bx r0
thumb_func_end sub_81CFA48
thumb_func_start sub_81CFA68
sub_81CFA68: @ 81CFA68
push {r4,lr}
adds r4, r0, 0
ldr r0, [r4, 0x4]
bl IsLoopedTaskActive
cmp r0, 0
bne _081CFA7A
ldr r0, =sub_81CFA88
str r0, [r4]
_081CFA7A:
movs r0, 0
pop {r4}
pop {r1}
bx r1
.pool
thumb_func_end sub_81CFA68
thumb_func_start sub_81CFA88
sub_81CFA88: @ 81CFA88
push {r4,r5,lr}
adds r4, r0, 0
ldr r2, =gMain
ldrh r1, [r2, 0x30]
movs r0, 0x40
ands r0, r1
cmp r0, 0
beq _081CFAA0
movs r0, 0x1
b _081CFAFE
.pool
_081CFAA0:
movs r0, 0x80
ands r0, r1
cmp r0, 0
beq _081CFAAC
movs r0, 0x2
b _081CFAFE
_081CFAAC:
ldrh r1, [r2, 0x2E]
movs r0, 0x20
ands r0, r1
cmp r0, 0
beq _081CFABA
movs r0, 0x3
b _081CFAFE
_081CFABA:
movs r0, 0x10
ands r0, r1
lsls r0, 16
lsrs r2, r0, 16
cmp r2, 0
beq _081CFACA
movs r0, 0x4
b _081CFAFE
_081CFACA:
movs r0, 0x2
ands r0, r1
cmp r0, 0
beq _081CFAE0
str r2, [r4, 0x18]
ldr r0, =sub_81CFB08
str r0, [r4]
movs r0, 0x5
b _081CFAFE
.pool
_081CFAE0:
movs r5, 0x1
adds r0, r5, 0
ands r0, r1
cmp r0, 0
bne _081CFAEE
movs r0, 0
b _081CFAFE
_081CFAEE:
bl GetSelectedMatchCall
ldr r1, [r4, 0x1C]
strh r0, [r1, 0x2]
str r5, [r4, 0x18]
ldr r0, =sub_81CFB10
str r0, [r4]
movs r0, 0x6
_081CFAFE:
pop {r4,r5}
pop {r1}
bx r1
.pool
thumb_func_end sub_81CFA88
thumb_func_start sub_81CFB08
sub_81CFB08: @ 81CFB08
ldr r0, =0x000186a5
bx lr
.pool
thumb_func_end sub_81CFB08
thumb_func_start sub_81CFB10
sub_81CFB10: @ 81CFB10
ldr r0, =0x000186ad
bx lr
.pool
thumb_func_end sub_81CFB10
thumb_func_start sub_81CFB18
sub_81CFB18: @ 81CFB18
push {lr}
movs r0, 0x9
bl GetSubstructPtr
ldr r0, [r0, 0x14]
pop {r1}
bx r1
thumb_func_end sub_81CFB18
thumb_func_start sub_81CFB28
sub_81CFB28: @ 81CFB28

View File

@ -27,13 +27,13 @@ enum
struct BgTemplate
{
u32 bg:2; // 0x1, 0x2 -> 0x3
u32 charBaseIndex:2; // 0x4, 0x8 -> 0xC
u32 mapBaseIndex:5; // 0x10, 0x20, 0x40, 0x80, 0x100 -> 0x1F0
u32 screenSize:2; // 0x200, 0x400 -> 0x600
u32 paletteMode:1; // 0x800
u32 priority:2; // 0x1000, 0x2000 > 0x3000
u32 baseTile:10;
u16 bg:2; // 0x1, 0x2 -> 0x3
u16 charBaseIndex:2; // 0x4, 0x8 -> 0xC
u16 mapBaseIndex:5; // 0x10, 0x20, 0x40, 0x80, 0x100 -> 0x1F0
u16 screenSize:2; // 0x200, 0x400 -> 0x600
u16 paletteMode:1; // 0x800
u16 priority:2; // 0x1000, 0x2000 > 0x3000
u16 baseTile:10;
};
void ResetBgs(void);

View File

@ -317,6 +317,7 @@ SECTIONS {
src/pokenav_unk_7.o(.text);
src/pokenav_unk_8.o(.text);
asm/pokenav_unk_8.o(.text);
src/pokenav_unk_9.o(.text);
asm/pokenav_unk_9.o(.text);
src/pokenav_unk_10.o(.text);
src/pokenav_match_call_data.o(.text);

File diff suppressed because it is too large Load Diff

View File

@ -3,15 +3,30 @@
#include "bg.h"
#include "window.h"
struct PokenavSub9
{
u32 (*unk0)(struct PokenavSub9*);
u32 loopedTaskId;
u8 filler[0xC];
u32 unk14;
u32 unk18;
struct PokenavSub18 *unk1C;
};
u32 sub_81CFA68(struct PokenavSub9 *structPtr);
u32 sub_81CFA88(struct PokenavSub9 *structPtr);
u32 sub_81CFB08(struct PokenavSub9 *structPtr);
u32 sub_81CFB10(struct PokenavSub9 *structPtr);
u32 sub_81CFB8C(void);
u32 sub_81CFC2C(void);
u32 sub_81CFC40(void);
u32 sub_81CFFFC(s32);
u32 sub_81D0074(s32);
u32 sub_81D00EC(s32);
u32 sub_81D0164(s32);
u32 sub_81D01DC(s32);
u32 sub_81D021C(s32);
u32 sub_81CFB74(s32 state);
u32 sub_81CFFFC(s32 state);
u32 sub_81D0074(s32 state);
u32 sub_81D00EC(s32 state);
u32 sub_81D0164(s32 state);
u32 sub_81D01DC(s32 state);
u32 sub_81D021C(s32 state);
u32 (*const gUnknown_086235D8[])(void) =
{
@ -72,3 +87,94 @@ const struct WindowTemplate gUnknown_086237D4 =
const u8 gUnknown_086237DC[] = _("{COLOR_HIGHLIGHT_SHADOW}{LIGHT_RED}{WHITE}{GREEN}♂{COLOR_HIGHLIGHT_SHADOW}{DARK_GREY}{WHITE}{LIGHT_GREY}");
const u8 gUnknown_086237E8[] = _("{COLOR_HIGHLIGHT_SHADOW}{LIGHT_GREEN}{WHITE}{BLUE}♀{COLOR_HIGHLIGHT_SHADOW}{DARK_GREY}{WHITE}{LIGHT_GREY}");
const u8 gUnknown_086237F4[] = _("{UNK_SPACER}");
bool32 sub_81CF9BC(void)
{
struct PokenavSub9 *structPtr = AllocSubstruct(9, sizeof(struct PokenavSub9));
if (structPtr == NULL)
return FALSE;
structPtr->unk1C = AllocSubstruct(18, sizeof(struct PokenavSub18));
if (structPtr->unk1C == NULL)
return FALSE;
structPtr->unk0 = sub_81CFA68;
structPtr->loopedTaskId = CreateLoopedTask(sub_81CFB74, 1);
structPtr->unk14 = 0;
return TRUE;
}
bool32 sub_81CFA04(void)
{
struct PokenavSub9 *structPtr = AllocSubstruct(9, sizeof(struct PokenavSub9));
if (structPtr == NULL)
return FALSE;
structPtr->unk1C = GetSubstructPtr(18);
structPtr->unk0 = sub_81CFA88;
structPtr->unk14 = 1;
return TRUE;
}
u32 sub_81CFA34(void)
{
struct PokenavSub9 *structPtr = GetSubstructPtr(9);
return structPtr->unk0(structPtr);
}
void sub_81CFA48(void)
{
struct PokenavSub9 *structPtr = GetSubstructPtr(9);
if (!structPtr->unk18)
FreePokenavSubstruct(18);
FreePokenavSubstruct(9);
}
u32 sub_81CFA68(struct PokenavSub9 *structPtr)
{
if (!IsLoopedTaskActive(structPtr->loopedTaskId))
structPtr->unk0 = sub_81CFA88;
return 0;
}
u32 sub_81CFA88(struct PokenavSub9 *structPtr)
{
if (gMain.newAndRepeatedKeys & DPAD_UP)
return 1;
if (gMain.newAndRepeatedKeys & DPAD_DOWN)
return 2;
if (gMain.newKeys & DPAD_LEFT)
return 3;
if (gMain.newKeys & DPAD_RIGHT)
return 4;
if (gMain.newKeys & B_BUTTON)
{
structPtr->unk18 = 0;
structPtr->unk0 = sub_81CFB08;
return 5;
}
if (gMain.newKeys & A_BUTTON)
{
structPtr->unk1C->unk2 = GetSelectedMatchCall();
structPtr->unk18 = 1;
structPtr->unk0 = sub_81CFB10;
return 6;
}
return 0;
}
u32 sub_81CFB08(struct PokenavSub9 *structPtr)
{
return 0x186a5;
}
u32 sub_81CFB10(struct PokenavSub9 *structPtr)
{
return 0x186ad;
}
u32 sub_81CFB18(void)
{
struct PokenavSub9 *structPtr = GetSubstructPtr(9);
return structPtr->unk14;
}