From 386299d1f401cb939e6fe3ea16d0ca57731b2648 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Fri, 9 Jul 2021 17:35:12 -0700 Subject: [PATCH] Makefile and Install.md Revamp (#41) * Makefile: move over to gcc for preproc and ditch cpp * INSTALL: rewrite INSTALL * README: add CI badge * Makefile: make tools build before anything else --- INSTALL.md | 307 +++++++++++++++++++++++++++++++++++-- Makefile | 37 +++-- README.md | 6 +- asm/friend_list_menu.s | 8 +- asm/kangaskhan_storage_2.s | 45 ------ asm/kecleon_items.s | 8 +- include/trade_items_menu.h | 10 +- ld_script.txt | 6 +- make_tools.mk | 11 ++ src/felicity_bank_1.c | 2 +- src/gulpin_shop.c | 2 +- src/kangaskhan_storage.c | 2 +- src/kangaskhan_storage_2.c | 31 +++- src/kecleon_items.c | 2 +- src/kecleon_items_1.c | 10 +- src/post_office_guide.c | 4 +- src/trade_items_menu.c | 59 ++++--- 17 files changed, 413 insertions(+), 137 deletions(-) create mode 100644 make_tools.mk diff --git a/INSTALL.md b/INSTALL.md index bb01ff1c..0800e971 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,25 +1,304 @@ -First, you must put a Pokémon Mystery Dungeon Red Rescue Team 1.0 (US) ROM in the root directory of the repository and name it `baserom.gba`. It should have a SHA1 checksum of `9f4cfc5b5f4859d17169a485462e977c7aac2b89`. Then, follow the OS-specific instructions below. -# Linux +# Instructions -Install [**devkitARM**](http://devkitpro.org/wiki/Getting_Started/devkitARM). +These instructions explain how to set up the tools required to build **pmd-red**, which assembles the source files into a ROM. -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". +These instructions come with notes which can be expanded by clicking the "Note..." text. +In general, you should not need to open these unless if you get an error or if you need additional clarification. -Then get the compiler from https://github.com/pret/agbcc and run the following commands. +If you run into trouble, ask for help on Discord or IRC (see [README.md](README.md)). - build.sh - install.sh PATH_OF_PMD-RED_DIRECTORY - ${DEVKITARM}/bin/arm-none-eabi/ranlib PATH_OF_PMD-RED_DIRECTORY/tools/agbcc/lib/libgcc.a lib/libc.a +## Prerequisites -Finally, in the pmd-red directory, build the rom. +First, you must put a Pokémon Mystery Dungeon Red Rescue Team 1.0 (US) ROM in the root directory of the repository and name it `baserom.gba`. It should have a SHA1 checksum of `9f4cfc5b5f4859d17169a485462e977c7aac2b89`. Then, follow the OS-specific instructions below: - make +- [Windows](#windows) +- [macOS](#macos) +- [Linux](#linux) -# Windows +## Windows +- [Windows 10 (WSL1)](#windows-10-wsl1) (**Fastest, highly recommended**, Windows 10 only) -Install [**devkitARM**](http://devkitpro.org/wiki/Getting_Started/devkitARM). +
+ Note for advanced users: WSL2... -Then get the compiled tools from https://github.com/pret/pokeruby-tools. Copy the `tools/` folder over the `tools/` folder in your pmd-red directory. +> WSL2 is an option and is even faster than WSL1 if files are stored on the WSL2 file system, but some tools may have trouble interacting +> with the WSL2 file system over the network drive. For example, tools which use Qt versions before 5.15.2 such as porymap +> may have problems with parsing the \\wsl$ network drive path. +
-You can then build pmd-red using `make` in the MSYS environment provided with devkitARM. +All of the Windows instructions assume that the default drive is C:\\. If this differs to your actual drive letter, then replace C with the correct drive letter when reading the instructions. + +**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. + +## Windows 10 (WSL1) +WSL1 is the preferred terminal to build **pmd-red**. The following instructions will explain how to install WSL1 (referred to interchangeably as WSL). +- If WSL (Debian or Ubuntu) is **not installed**, then go to [Installing WSL1](#installing-wsl1). +- 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). +- Otherwise, **open WSL** and go to [Choosing where to store pmd-red (WSL1)](#choosing-where-to-store-pmd-red-wsl1). + +### Installing WSL1 +1. Open [Windows Powershell **as Administrator**](https://i.imgur.com/QKmVbP9.png), and run the following command (Right Click or Shift+Insert is paste in the Powershell). + + ```powershell + dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart + ``` + +2. Once the process finishes, restart your machine. + +3. The next step is to choose and install a Linux distribution from the Microsoft Store. The following instructions will assume Ubuntu as the Linux distribution of choice. +
+ Note for advanced users... + + > You can pick a preferred Linux distribution, but setup instructions may differ. Debian should work with the given instructions, but has not been tested. +
+ +4. Open the [Microsoft Store Linux Selection](https://aka.ms/wslstore), click Ubuntu, then click Get, which will install the Ubuntu distribution. +
+ Notes... + + > Note 1: If a dialog pops up asking for you to sign into a Microsoft Account, then just close the dialog. + > Note 2: If the link does not work, then open the Microsoft Store manually, and search for the Ubuntu app (choose the one with no version number). +
+ +### Setting up WSL1 +Some tips before proceeding: +- In WSL, Copy and Paste is either done via + - **right-click** (selection + right click to Copy, right click with no selection to Paste) + - **Ctrl+Shift+C/Ctrl+Shift+V** (enabled by right-clicking the title bar, going to Properties, then checking the checkbox next to "Use Ctrl+Shift+C/V as Copy/Paste"). +- Some of the commands that you'll run will ask for your WSL password and/or confirmation to perform the stated action. This is to be expected, just enter your WSL password and/or the yes action when necessary. + +1. Open **Ubuntu** (e.g. using Search). +2. WSL/Ubuntu will set up its own installation when it runs for the first time. Once WSL/Ubuntu finishes installing, it will ask for a username and password (to be input in). +
+ Note... + + > When typing in the password, there will be no visible response, but the terminal will still read in input. +
+ +3. Update WSL/Ubuntu before continuing. Do this by running the following command. These commands will likely take a long time to finish: + + ```bash + sudo apt update && sudo apt upgrade + ``` + +> Note: If the repository you plan to build has an **[older revision of the INSTALL.md](https://github.com/pret/pokeemerald/blob/571c598/INSTALL.md)**, then follow the [legacy WSL1 instructions](docs/legacy_WSL1_INSTALL.md) from here. + +4. Certain packages are required to build pmd-red. Install these packages by running the following command: + + ```bash + sudo apt install build-essential binutils-arm-none-eabi git libpng-dev + ``` +
+ Note... + + > If the above command does not work, try the above command but replacing `apt` with `apt-get`. +
+ +### Choosing where to store pmd-red (WSL1) +WSL has its own file system that's not natively accessible from Windows, but Windows files *are* accessible from WSL. So you're going to want to store pmd-red within Windows. + +For example, say you want to store pmd-red (and agbcc) in **C:\Users\\_\_\Desktop\decomps**. First, ensure that the folder already exists. Then, enter this command to **change directory** to said folder, where *\* is your **Windows** username: + +```bash +cd /mnt/c/Users//Desktop/decomps +``` + +
+ Notes... + +> Note 1: The Windows C:\ drive is called /mnt/c/ in WSL. +> Note 2: If the path has spaces, then the path must be wrapped with quotations, e.g. `cd "/mnt/c/users//Desktop/decomp folder"`. +> Note 3: Windows path names are case-insensitive so adhering to capitalization isn't needed +
+ +If this works, then proceed to [Installation](#installation). + +## macOS +1. If the Xcode Command Line Tools are not installed, download the tools [here](https://developer.apple.com/xcode/resources/), open your Terminal, and run the following command: + + ```bash + xcode-select --install + ``` + +2. - If libpng is **not installed**, then go to [Installing libpng (macOS)](#installing-libpng-macos). + - Otherwise, **open the Terminal** and go to [Choosing where to store pmd-red (macOS)](#choosing-where-to-store-pmd-red-macos) + +### Installing libpng (macOS) +
+ Note for advanced users... + +> 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. +
+ +1. Open the Terminal. +2. If Homebrew is not installed, then install [Homebrew](https://brew.sh/) by following the instructions on the website. +3. Run the following command to install libpng. + + ```bash + brew install libpng + ``` + libpng is now installed. + +### Choosing where to store pmd-red (macOS) +At this point, you can choose a folder to store pmd-red into. If you're okay with storing pmd-red in the user folder, then proceed to [Installation](#installation). Otherwise, you'll need to account for where pmd-red is stored when changing directory to the pmd-red folder. + +For example, if you want to store pmd-red (and agbcc) in **~/Desktop/decomps**, enter this command to **change directory** to the desired folder: +```bash +cd Desktop/decomps +``` +Note that the directory **must exist** in the folder system. If you want to store pmd-red in a dedicated folder that doesn't exist (e.g. the example provided above), then create the folder (e.g. using Finder) before executing the `cd` command. + +
+ Note... + +> Note: If the path has spaces, then the path must be wrapped with quotations, e.g. `cd "Desktop/decomp folder"` +
+ +If this works, then proceed to [Installation](#installation). Otherwise, ask for help on Discord or IRC (see [README.md](README.md)). + +## Linux +Open Terminal and enter the following commands, depending on which distro you're using. + +### Debian/Ubuntu-based distributions +Run the following command to install the necessary packages: +```bash +sudo apt install build-essential binutils-arm-none-eabi git libpng-dev +``` +Then proceed to [Choosing where to store pmd-red (Linux)](#choosing-where-to-store-pmd-red-(linux)). + +### Other distributions +_(Specific instructions for other distributions would be greatly appreciated!)_ + +1. Try to find the required software in its repositories: + - `gcc` + - `g++` + - `make` + - `git` + - `libpng-dev` + +### Choosing where to store pmd-red (Linux) +At this point, you can choose a folder to store pmd-red (and agbcc) into. If so, you'll have to account for the modified folder path when changing directory to the pmd-red folder. + +If this works, then proceed to [Installation](#installation). Otherwise, ask for help on Discord or IRC (see [README.md](README.md)). + +## Installation + +
+ Note for Windows users... + +> Consider adding an exception for the `pmd-red` and/or `decomps` folder in Windows Security using +> [these instructions](https://support.microsoft.com/help/4028485). This prevents Microsoft Defender from +> scanning them which might improve performance while building. +
+ +1. If pmd-red is not already downloaded (some users may prefer to download pmd-red via a git client like GitHub Desktop), run: + + ```bash + git clone https://github.com/pret/pmd-red + ``` + +
+ Note for WSL1... + + > If you get an error stating `fatal: could not set 'core.filemode' to 'false'`, then run the following commands: + > ```bash + > cd + > sudo umount /mnt/c + > sudo mount -t drvfs C: /mnt/c -o metadata,noatime + > cd + > ``` + > Where *\* is the path of the folder [where you chose to store pmd-red](#Choosing-where-to-store-pmd-red-WSL1). Then run the `git clone` command again. +
+ +2. Install agbcc into pmd-red. The commands to run depend on certain conditions. **You should only follow one of the listed instructions**: +- If agbcc has **not been built before** in the folder where you chose to store pmd-red, run the following commands to build and install it into pmd-red: + + ```bash + git clone https://github.com/pret/agbcc + cd agbcc + ./build.sh + ./install.sh ../pmd-red + ``` + +- **Otherwise**, if agbcc has been built before (e.g. if the git clone above fails), but was **last built on a different terminal** than the one currently used (only relevant to Windows, e.g. switching from msys2 to WSL1), then run the following commands to build and install it into pmd-red: + + ```bash + cd agbcc + git clean -fX + ./build.sh + ./install.sh ../pmd-red + ``` + +- **Otherwise**, if agbcc has been built before on the same terminal, run the following commands to install agbcc into pmd-red: + + ```bash + cd agbcc + ./install.sh ../pmd-red + ``` + +
+ Note... + + > If building agbcc or pmd-red results in an error, try deleting the agbcc folder and re-installing agbcc as if it has not been built before. +
+ +3. Once agbcc is installed, change directory back to the base directory where pmd-red and agbcc are stored: + + ```bash + cd .. + ``` + +Now you're ready to [build **pmd-red**](#build-pmd-red) +## Build pmd-red +If you aren't in the pmd-red directory already, then **change directory** to the pmd-red folder: +```bash +cd pmd-red +``` +To build **pmd-red.gba** for the first time and confirm it matches the official ROM image (Note: to speed up builds, see [Parallel builds](#parallel-builds)): +```bash +make compare +``` +If an OK is returned, then the installation went smoothly. +
+Note for Windows... +> 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. +
+ +To build **pmd-red.gba** with your changes: +```bash +make +``` + +# Building guidance + +## Parallel builds + +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. + +To speed up building, first get the value of `nproc` by running the following command: +```bash +nproc +``` +Builds can then be sped up by running the following command: +```bash +make -j +``` +Replace `` with the number that the `nproc` command returned. + +`nproc` is not available on macOS. The alternative is `sysctl -n hw.ncpu` ([relevant Stack Overflow thread](https://stackoverflow.com/questions/1715580)). + +## Other toolchains + +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`. +```bash +make TOOLCHAIN="/path/to/toolchain/here" +``` +The following is an example: +```bash +make TOOLCHAIN="/usr/local/arm-none-eabi" +``` +To compile the `modern` target with this toolchain, the subdirectories `lib`, `include`, and `arm-none-eabi` must also be present. + +# Useful additional tools +* [Tilemap Studio](https://github.com/Rangi42/tilemap-studio) for viewing and editing tilemaps diff --git a/Makefile b/Makefile index 17a1eb71..555b7bce 100755 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ OBJCOPY := $(PREFIX)objcopy export CC := $(PREFIX)gcc export AS := $(PREFIX)as endif -export CPP := $(PREFIX)cpp +export CPP := $(CC) -E export LD := $(PREFIX)ld ifeq ($(OS),Windows_NT) @@ -114,12 +114,6 @@ $(C_BUILDDIR)/m4a.o: CC1 := tools/agbcc/bin/old_agbcc #### Main Rules #### -# Disable dependency scanning when NODEP is used for quick building -ifeq ($(NODEP),1) -$(C_BUILDDIR)/%.o: C_DEP := -else -$(C_BUILDDIR)/%.o: C_DEP = $(shell [[ -f $(C_SUBDIR)/$*.c ]] && $(SCANINC) -I include -I tools/agbcc/include -I gflib $(C_SUBDIR)/$*.c) -endif ALL_BUILDS := red @@ -137,9 +131,29 @@ MAKEFLAGS += --no-print-directory # Delete files that weren't built properly .DELETE_ON_ERROR: +infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line)))) + +# Build tools when building the rom +# Disable dependency scanning for clean/tidy/tools +# Use a separate minimal makefile for speed +# Since we don't need to reload most of this makefile +ifeq (,$(filter-out all rom compare libagbsyscall syms,$(MAKECMDGOALS))) +$(call infoshell, $(MAKE) -f make_tools.mk) +else +NODEP ?= 1 +endif + .PRECIOUS: %.1bpp %.4bpp %.8bpp %.gbapal %.lz %.rl %.pcm %.bin +# Disable dependency scanning when NODEP is used for quick building +ifeq ($(NODEP),1) +$(C_BUILDDIR)/%.o: C_DEP := +else +$(C_BUILDDIR)/%.o: C_DEP = $(shell [[ -f $(C_SUBDIR)/$*.c ]] && $(SCANINC) -I include -I tools/agbcc/include -I gflib $(C_SUBDIR)/$*.c) +endif + + # Create build subdirectories $(shell mkdir -p $(SUBDIRS)) @@ -175,7 +189,7 @@ $(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.c $$(C_DEP) $(AS) $(ASFLAGS) -o $@ $(C_BUILDDIR)/$*.s $(DATA_ASM_BUILDDIR)/%.o: $(DATA_ASM_SUBDIR)/%.s $$(ASM_DEP) dungeon_pokemon dungeon_floor - $(PREPROC) $< charmap.txt | $(CPP) -I include | $(AS) $(ASFLAGS) -o $@ + $(PREPROC) $< charmap.txt | $(CPP) -I include - | $(AS) $(ASFLAGS) -o $@ $(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s $$(ASM_DEP) $(AS) $(ASFLAGS) $< -o $@ @@ -183,10 +197,11 @@ $(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s $$(ASM_DEP) libagbsyscall: @$(MAKE) -C libagbsyscall TOOLCHAIN=$(TOOLCHAIN) -$(LD_SCRIPT): ld_script.txt $(BUILD_DIR)/sym_ewram.ld $(BUILD_DIR)/sym_ewram2.ld $(BUILD_DIR)/sym_iwram.ld +$(BUILD_DIR)/sym_%.txt: sym_%.txt + cp $< $(BUILD_DIR) + +$(LD_SCRIPT): ld_script.txt $(BUILD_DIR)/sym_ewram.txt $(BUILD_DIR)/sym_ewram2.txt $(BUILD_DIR)/sym_iwram.txt cd $(BUILD_DIR) && sed -e "s#tools/#../../tools/#g" ../../ld_script.txt >ld_script.ld -$(BUILD_DIR)/sym_%.ld: sym_%.txt - $(CPP) -P $(CPPFLAGS) $< | sed -e "s#tools/#../../tools/#g" > $@ $(ELF): $(LD_SCRIPT) $(ALL_OBJECTS) $(LIBC) libagbsyscall tools cd $(BUILD_DIR) && $(LD) -T ld_script.ld -Map ../../$(MAP) -o ../../$@ $(LIB) diff --git a/README.md b/README.md index 8db019d0..81b17624 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Pokémon Mystery Dungeon: Red Rescue Team +[![build](https://github.com/pret/pmd-red/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/pret/pmd-red/actions/workflows/build.yml) + This is a disassembly of Pokémon Mystery Dungeon: Red Rescue Team. It builds the following rom: @@ -16,9 +18,10 @@ To set up the repository, see [INSTALL.md](INSTALL.md). * Disassembly of [**Pokémon Crystal**][pokecrystal] * Disassembly of [**Pokémon Pinball**][pokepinball] * Disassembly of [**Pokémon TCG**][poketcg] -* Disassembly of [**Pokémon Fire Red**][pokefirered] +* Disassembly of [**Pokémon Fire Red**/**Leaf Green**][pokefirered] * Disassembly of [**Pokémon Ruby/Sapphire**][pokeruby] * Disassembly of [**Pokémon Emerald**][pokeemerald] +* Disassembly of [**Pokémon Diamond/Pearl**][pokediamond] * Discord: [**pret**][Discord] * irc: **irc.freenode.net** [**#pret**][irc] @@ -31,5 +34,6 @@ To set up the repository, see [INSTALL.md](INSTALL.md). [pokefirered]: https://github.com/pret/pokefirered [pokeruby]: https://github.com/pret/pokeruby [pokeemerald]: https://github.com/pret/pokeemerald +[pokediamond]: https://github.com/pret/pokediamond [Discord]: https://discord.gg/d5dubZ3 [irc]: https://kiwiirc.com/client/irc.freenode.net/?#pret diff --git a/asm/friend_list_menu.s b/asm/friend_list_menu.s index a8603b80..46903a6b 100644 --- a/asm/friend_list_menu.s +++ b/asm/friend_list_menu.s @@ -2272,7 +2272,7 @@ _0802005C: .4byte gUnknown_203B27C _08020060: .4byte gGulpinDialogue _08020064: movs r0, 0x3 - bl sub_8016C40 + bl DrawTeamMoneyBox b _08020562 _0802006C: ldr r2, [r5] @@ -6233,12 +6233,12 @@ _08021FE2: bl sub_8021354 _08021FE8: movs r0, 0x1 - bl sub_8016C40 + bl DrawTeamMoneyBox b _080222B6 _08021FF0: bl sub_8021494 movs r0, 0x1 - bl sub_8016C40 + bl DrawTeamMoneyBox bl sub_8022380 ldr r0, _08022020 ldr r2, [r0] @@ -6976,7 +6976,7 @@ _080225B0: b _080225C2 _080225BC: movs r0, 0x1 - bl sub_8016C40 + bl DrawTeamMoneyBox _080225C2: pop {r4} pop {r0} diff --git a/asm/kangaskhan_storage_2.s b/asm/kangaskhan_storage_2.s index 24a5a3c8..efdac5f6 100644 --- a/asm/kangaskhan_storage_2.s +++ b/asm/kangaskhan_storage_2.s @@ -5,51 +5,6 @@ .text - thumb_func_start sub_8018280 -sub_8018280: - push {r4,lr} - sub sp, 0x4 - ldr r4, _080182DC - ldr r0, [r4] - adds r0, 0xD4 - ldr r0, [r0] - bl sub_8008C54 - ldr r0, [r4] - adds r0, 0xD4 - ldr r0, [r0] - bl sub_80073B8 - ldr r2, _080182E0 - ldr r0, [r4] - adds r0, 0xD4 - ldr r3, [r0] - movs r0, 0 - str r0, [sp] - movs r0, 0x4 - movs r1, 0 - bl xxx_call_draw_string - ldr r0, [r4] - adds r0, 0xC0 - bl sub_8013C68 - ldr r0, [r4] - adds r0, 0xD4 - ldr r0, [r0] - bl sub_80073E0 - bl sub_801CCD8 - movs r0, 0 - bl sub_801AD34 - ldr r0, [r4] - adds r0, 0x70 - movs r1, 0 - bl sub_8012EA4 - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_080182DC: .4byte gUnknown_203B20C -_080182E0: .4byte gUnknown_80DB830 - thumb_func_end sub_8018280 - thumb_func_start sub_80182E4 sub_80182E4: push {r4-r7,lr} diff --git a/asm/kecleon_items.s b/asm/kecleon_items.s index 72a16f2d..19023458 100644 --- a/asm/kecleon_items.s +++ b/asm/kecleon_items.s @@ -426,7 +426,7 @@ _0801922A: movs r0, 0 bl sub_801AD34 movs r0, 0x1 - bl sub_8016C40 + bl DrawTeamMoneyBox bl sub_80195C0 ldr r0, _08019250 ldr r2, [r0] @@ -579,12 +579,12 @@ _08019372: bl sub_801A8D0 _08019378: movs r0, 0x1 - bl sub_8016C40 + bl DrawTeamMoneyBox b _080194E8 _08019380: bl sub_801A9E0 movs r0, 0x1 - bl sub_8016C40 + bl DrawTeamMoneyBox bl sub_8019660 ldr r0, _080193B0 ldr r2, [r0] @@ -1520,7 +1520,7 @@ _08019AF4: movs r0, 0 bl sub_801AD34 movs r0, 0x1 - bl sub_8016C40 + bl DrawTeamMoneyBox _08019B00: pop {r4,r5} pop {r0} diff --git a/include/trade_items_menu.h b/include/trade_items_menu.h index 31eac25c..52cb733c 100644 --- a/include/trade_items_menu.h +++ b/include/trade_items_menu.h @@ -2,6 +2,7 @@ #define GUARD_TRADE_ITEMS_MENU_H #include "text.h" +#include "item.h" struct TradeSubStruct { @@ -41,12 +42,11 @@ struct TradeItemsMenu struct TradeSubStruct unk24C; - struct TradeSubStruct unk254; + /* 0x254 */ struct TradeSubStruct sentItem; - u8 unk25C; - u8 chosenNum; - u8 chosenItem; - u8 fill25F[0x3A0 - 0x25F]; + /* 0x25C */ struct ItemStruct_203B460 itemToSend; + + u8 fill25F[0x3A0 - 0x260]; }; diff --git a/ld_script.txt b/ld_script.txt index 38fe51b3..b8e8e75c 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -10,13 +10,13 @@ SECTIONS { ALIGN(4) { ewram_start = .; - INCLUDE "sym_ewram.ld" + INCLUDE "sym_ewram.txt" src/agb_flash.o(.bss); *libgcc.a:fp-bit.o(.bss); *libgcc.a:dp-bit.o(.bss); *libc.a:syscalls.o(.bss); . = ALIGN(16); - INCLUDE "sym_ewram2.ld" + INCLUDE "sym_ewram2.txt" *libc.a:impure.o(.data); *libc.a:locale.o(.data); *libc.a:mallocr.o(.data); @@ -30,7 +30,7 @@ SECTIONS { ALIGN(4) { iwram_start = .; - INCLUDE "sym_iwram.ld" + INCLUDE "sym_iwram.txt" . = 0x8000; } diff --git a/make_tools.mk b/make_tools.mk new file mode 100644 index 00000000..697897a6 --- /dev/null +++ b/make_tools.mk @@ -0,0 +1,11 @@ + +MAKEFLAGS += --no-print-directory + +TOOLDIRS := $(filter-out tools/agbcc tools/binutils,$(wildcard tools/*)) + +.PHONY: all $(TOOLDIRS) + +all: $(TOOLDIRS) + +$(TOOLDIRS): + @$(MAKE) -C $@ diff --git a/src/felicity_bank_1.c b/src/felicity_bank_1.c index be46eb15..fc769cbf 100644 --- a/src/felicity_bank_1.c +++ b/src/felicity_bank_1.c @@ -140,7 +140,7 @@ void CreateFelicityMoneySavingsHeader(u32 param_1) sub_80073E0(param_1); } -void sub_8016C40(u32 param_1) +void DrawTeamMoneyBox(u32 param_1) { sub_8008C54(param_1); sub_80073B8(param_1); diff --git a/src/gulpin_shop.c b/src/gulpin_shop.c index 43dc94ba..0600befc 100644 --- a/src/gulpin_shop.c +++ b/src/gulpin_shop.c @@ -57,7 +57,7 @@ u32 DisplayGulpinDialogueSprite(s32 param_1,s16 param_2,struct unkStruct_Gulpin param2_32 = param_2; // dumb cast needed to get lsr/asr combo - gUnknown_203B26C = MemoryAlloc(0x18c,8); + gUnknown_203B26C = MemoryAlloc(sizeof(struct unkStruct_203B26C),8); gUnknown_203B26C->unk0 = param_1; gUnknown_203B26C->unkC = param2_32; gUnknown_203B26C->unk10 = param_3; diff --git a/src/kangaskhan_storage.c b/src/kangaskhan_storage.c index 28ab5c99..33f609a1 100644 --- a/src/kangaskhan_storage.c +++ b/src/kangaskhan_storage.c @@ -40,7 +40,7 @@ u32 DisplayKangaskhanDialogueSprite(s32 param_1) ResetUnusedInputStruct(); sub_800641C(0,1,1); - gUnknown_203B208 = MemoryAlloc(0x14c,8); + gUnknown_203B208 = MemoryAlloc(sizeof(struct unkStruct_203B208),8); gUnknown_203B208->unk18 = 0; gUnknown_203B208->unk1C = 0; gUnknown_203B208->unk20 = 0; diff --git a/src/kangaskhan_storage_2.c b/src/kangaskhan_storage_2.c index 6b308824..02059d14 100644 --- a/src/kangaskhan_storage_2.c +++ b/src/kangaskhan_storage_2.c @@ -21,8 +21,7 @@ struct unkStruct_203B20C u32 unk1C; u32 unk20; u8 fill24[0x60 - 0x24]; - u32 unk60; - u8 fill64[0x70 - 0x64]; + u16 unk60[8]; u32 unk70; u8 fill74[0xC0 - 0x74]; u32 unkC0; @@ -77,6 +76,13 @@ extern u32 sub_801A8AC(void); extern void sub_801A928(void); extern void sub_8012CAC(struct UnkTextStruct2 *, u32 *); extern void sub_80182E4(void); +extern void sub_8008C54(u32); +extern void sub_80073B8(u32); +extern void sub_8013C68(u32 *); +extern void sub_80073E0(u32); +extern void sub_8012EA4(u32 *, u32); +extern void xxx_call_draw_string(u32 x, u32 y, u8 *, u32, u32); + extern void sub_801A9E0(); extern void sub_801841C(); @@ -87,7 +93,7 @@ extern void sub_8013AA0(u32 *); extern void sub_801B3C0(struct ItemStruct_203B460 *); extern void sub_801A5D8(u32, u32, u32, u32); extern void sub_801C8C4(u32, u32, u32, u32); -extern void sub_8012D60(u32 *, u32 *, u32, u32 *, u32, u32); +extern void sub_8012D60(u32 *, u32 *, u32, u16 *, u32, u32); extern void sub_801CB5C(u32); extern void sub_801A8D0(u32); @@ -96,6 +102,7 @@ extern struct UnkTextStruct2 gUnknown_80DB7E8; extern struct UnkTextStruct2 gUnknown_80DB7D0; extern struct UnkTextStruct2 gUnknown_80DB800; extern struct UnkTextStruct2 gUnknown_80DB818; +extern u8 gUnknown_80DB830[]; void sub_8017AF8(void) { @@ -410,7 +417,7 @@ void sub_8018100(void) switch(gUnknown_203B20C->state) { case 1: - sub_8012D60(&gUnknown_203B20C->unk70, &gUnknown_203B20C->unk20, 0, &gUnknown_203B20C->unk60, gUnknown_203B20C->unk14, 2); + sub_8012D60(&gUnknown_203B20C->unk70, &gUnknown_203B20C->unk20, 0, gUnknown_203B20C->unk60, gUnknown_203B20C->unk14, 2); break; case 4: sub_801A5D8(3, 3, 0, 0xA); @@ -421,7 +428,7 @@ void sub_8018100(void) case 6: sub_801A9E0(); sub_801841C(); - sub_8012D60(&gUnknown_203B20C->unk70, &gUnknown_203B20C->unk20, 0, &gUnknown_203B20C->unk60, gUnknown_203B20C->unk18, 2); + sub_8012D60(&gUnknown_203B20C->unk70, &gUnknown_203B20C->unk20, 0, gUnknown_203B20C->unk60, gUnknown_203B20C->unk18, 2); break; case 7: sub_801B3C0(&gUnknown_203B20C->unk8); @@ -453,7 +460,7 @@ void sub_8018100(void) sub_801CCD8(); sub_801AD34(0); sub_80184D4(); - sub_8012D60(&gUnknown_203B20C->unk70, &gUnknown_203B20C->unk20, 0, &gUnknown_203B20C->unk60, gUnknown_203B20C->unk1C, 2); + sub_8012D60(&gUnknown_203B20C->unk70, &gUnknown_203B20C->unk20, 0, gUnknown_203B20C->unk60, gUnknown_203B20C->unk1C, 2); break; case 14: sub_801B3C0(&gUnknown_203B20C->unk8); @@ -463,3 +470,15 @@ void sub_8018100(void) break; } } + +void sub_8018280(void) +{ + sub_8008C54(gUnknown_203B20C->unkD4); + sub_80073B8(gUnknown_203B20C->unkD4); + xxx_call_draw_string(4, 0, gUnknown_80DB830, gUnknown_203B20C->unkD4, 0); // Number? + sub_8013C68(&gUnknown_203B20C->unkC0); + sub_80073E0(gUnknown_203B20C->unkD4); + sub_801CCD8(); + sub_801AD34(0); + sub_8012EA4(&gUnknown_203B20C->unk70,0); +} diff --git a/src/kecleon_items.c b/src/kecleon_items.c index 58fead3a..967d1485 100644 --- a/src/kecleon_items.c +++ b/src/kecleon_items.c @@ -35,7 +35,7 @@ u32 DisplayKeckleonDialogueSprite(u32 param_1) char *monName; struct OpenedFile *faceFile; - gUnknown_203B210 = MemoryAlloc(0x148,8); + gUnknown_203B210 = MemoryAlloc(sizeof(struct unkStruct_203B210),8); gUnknown_203B210->unk28 = 0; gUnknown_203B210->unk2C = 0; gUnknown_203B210->unk30 = 0; diff --git a/src/kecleon_items_1.c b/src/kecleon_items_1.c index c05e8b9f..faa8c6bd 100644 --- a/src/kecleon_items_1.c +++ b/src/kecleon_items_1.c @@ -26,7 +26,7 @@ extern void sub_801A2A8(u32); extern s32 sub_801A8AC(void); extern u32 sub_801A6E8(u32); extern void sub_801A928(void); -extern void sub_8016C40(u32); +extern void DrawTeamMoneyBox(u32); void sub_8019B08(void) { @@ -53,7 +53,7 @@ void sub_8019B08(void) break; case 1: default: - sub_8016C40(1); + DrawTeamMoneyBox(1); break; } } @@ -168,13 +168,9 @@ void sub_8019D68(void) u32 sub_8019D8C(void) { if(gUnknown_203B210->unk4) - { return sub_8091814(); - } else - { return sub_8091A48(); - } } void sub_8019DAC(void) @@ -195,7 +191,7 @@ void sub_8019DAC(void) } } -void sub_8019E04(int param_1) +void sub_8019E04(s32 param_1) { if (gUnknown_203B210->unk4) { diff --git a/src/post_office_guide.c b/src/post_office_guide.c index 8fbfe567..063d0fad 100644 --- a/src/post_office_guide.c +++ b/src/post_office_guide.c @@ -33,7 +33,7 @@ struct unkStruct_203B330 u8 fillE[2]; u32 unk10; struct UnkTextStruct2 *unk14; - struct UnkTextStruct2 unk18[3]; + struct UnkTextStruct2 unk18[4]; }; extern struct unkStruct_203B330 *gUnknown_203B330; @@ -536,7 +536,7 @@ void ReturnToGetHelpMenu(void) u32 sub_80319A4(u8 param_1,u8 param_2,int param_3) { - gUnknown_203B330 = MemoryAlloc(0x78,8); + gUnknown_203B330 = MemoryAlloc(sizeof(struct unkStruct_203B330),8); gUnknown_203B330->unkC = param_1; gUnknown_203B330->unkD = param_2; sub_801317C(&gUnknown_203B330->unk0); diff --git a/src/trade_items_menu.c b/src/trade_items_menu.c index 8d20d6ce..57dd99f8 100644 --- a/src/trade_items_menu.c +++ b/src/trade_items_menu.c @@ -1,7 +1,7 @@ #include "global.h" #include "input.h" -#include "trade_items_menu.h" #include "item.h" +#include "trade_items_menu.h" #include "gUnknown_203B460.h" #include "memory.h" #include "save.h" @@ -44,7 +44,7 @@ extern s32 sub_80144A4(s32 *); extern u32 sub_801CA08(u32); extern void sub_801CBB8(); extern u8 sub_801CB24(); -extern void sub_801B3C0(u8 *); +extern void sub_801B3C0(struct ItemStruct_203B460 *); extern u8 sub_8012FD8(u32 *); extern void sub_8013114(u32 *, s32 *); extern void sub_8035CC0(struct UnkTextStruct2 *, u32); @@ -54,8 +54,6 @@ extern void sub_801B450(); extern void sub_801CB5C(u32); extern void sub_8035CF4(u32 *, u32, u32); extern u32 sub_8013BBC(u32 *); -void sub_8036F30(); -extern void TradeItem_AddItem(); extern void sub_80141B4(u32 *, u32, u32, u32); extern void sub_8008C54(u32); @@ -68,9 +66,8 @@ extern u32 sub_801D008(); extern void sub_8090DC4(u32 *, u8, u32); extern void sub_801C8C4(u32, u32, s32 *, u32); - - - +void sub_8036F30(); +void TradeItem_AddItem(); void SetTradeItemMenu(u32); void PrintTradeItemsLinkError(u32); void TradeItem_MainMenu(); @@ -230,9 +227,9 @@ void sub_8036590(void) void sub_80365AC(void) { - gTradeItemsMenu->chosenItem = 0; - gTradeItemsMenu->chosenNum = 1; - gTradeItemsMenu->unk25C = 0; + gTradeItemsMenu->itemToSend.itemIndex = 0; + gTradeItemsMenu->itemToSend.numItems = 1; + gTradeItemsMenu->itemToSend.unk0 = 0; switch(sub_801CA08(1)){ case 2: // Cancel @@ -241,18 +238,18 @@ void sub_80365AC(void) break; case 3: // Pop up menu with Confirm, Info, Cancel - gTradeItemsMenu->chosenItem = sub_801CB24(); - gTradeItemsMenu->chosenNum = 1; + gTradeItemsMenu->itemToSend.itemIndex = sub_801CB24(); + gTradeItemsMenu->itemToSend.numItems = 1; SetTradeItemMenu(TRADE_ITEMS_SEND_ITEM_POPUP_MENU); break; case 4: gTradeItemsMenu->unk4 = 2; - gTradeItemsMenu->chosenItem = sub_801CB24(); - gTradeItemsMenu->chosenNum = 1; + gTradeItemsMenu->itemToSend.itemIndex = sub_801CB24(); + gTradeItemsMenu->itemToSend.numItems = 1; sub_8006518(gTradeItemsMenu->unk1E4); ResetUnusedInputStruct(); sub_800641C(0,1,1); - sub_801B3C0(&gTradeItemsMenu->unk25C); + sub_801B3C0(&gTradeItemsMenu->itemToSend); SetTradeItemMenu(TRADE_ITEMS_ITEM_INFO); break; } @@ -276,7 +273,7 @@ void sub_8036674(void) sub_8006518(gTradeItemsMenu->unk1E4); ResetUnusedInputStruct(); sub_800641C(0,1,1); - sub_801B3C0(&gTradeItemsMenu->unk25C); + sub_801B3C0(&gTradeItemsMenu->itemToSend); SetTradeItemMenu(TRADE_ITEMS_ITEM_INFO); break; case 7: @@ -332,9 +329,9 @@ void sub_8036788(void) break; case 3: // Confirm # of item - gTradeItemsMenu->chosenNum = gTradeItemsMenu->numItemsToSend; - gTradeItemsMenu->unk254.itemIndex = gTradeItemsMenu->chosenItem; - gTradeItemsMenu->unk254.numItems = gTradeItemsMenu->numItemsToSend; + gTradeItemsMenu->itemToSend.numItems = gTradeItemsMenu->numItemsToSend; + gTradeItemsMenu->sentItem.itemIndex = gTradeItemsMenu->itemToSend.itemIndex; + gTradeItemsMenu->sentItem.numItems = gTradeItemsMenu->numItemsToSend; sub_801CBB8(); SetTradeItemMenu(TRADE_ITEMS_SEND_ITEM_CONFIRM); break; @@ -354,9 +351,9 @@ void TradeItem_SendItemConfirm(void) case 5: sub_801CBB8(); // Used temp var to get correct statements - load = gUnknown_203B460->unk50[gTradeItemsMenu->chosenItem]; + load = gUnknown_203B460->unk50[gTradeItemsMenu->itemToSend.itemIndex]; load -= gTradeItemsMenu->numItemsToSend; - gUnknown_203B460->unk50[gTradeItemsMenu->chosenItem] = load; + gUnknown_203B460->unk50[gTradeItemsMenu->itemToSend.itemIndex] = load; SetTradeItemMenu(TRADE_ITEMS_PREPARE_TRADE_SAVING); PrepareSavePakWrite(SPECIES_NONE); break; @@ -396,7 +393,7 @@ void sub_80368D4(void) break; case 7: case 0: - if ((gTradeItemsMenu->unk254.itemIndex != 0) && (gTradeItemsMenu->unk254.numItems != 0)) + if ((gTradeItemsMenu->sentItem.itemIndex != 0) && (gTradeItemsMenu->sentItem.numItems != 0)) { TradeItem_AddItem(); SetTradeItemMenu(0x11); @@ -434,8 +431,8 @@ void sub_8036950(void) } } else { - if (((gTradeItemsMenu->itemMode == TRADE_ITEMS_SEND_ITEM_MODE) && (gTradeItemsMenu->unk254.itemIndex != 0)) - && (gTradeItemsMenu->unk254.numItems != 0)) { + if (((gTradeItemsMenu->itemMode == TRADE_ITEMS_SEND_ITEM_MODE) && (gTradeItemsMenu->sentItem.itemIndex != 0)) + && (gTradeItemsMenu->sentItem.numItems != 0)) { // Link Failure TradeItem_AddItem(); // Add back the item SetTradeItemMenu(0xb); @@ -453,9 +450,9 @@ void TradeItem_AddItem(void) { // Use temp var to get correct statements u16 load; - load = gUnknown_203B460->unk50[gTradeItemsMenu->unk254.itemIndex]; - load += gTradeItemsMenu->unk254.numItems; - gUnknown_203B460->unk50[gTradeItemsMenu->unk254.itemIndex] = load; + load = gUnknown_203B460->unk50[gTradeItemsMenu->sentItem.itemIndex]; + load += gTradeItemsMenu->sentItem.numItems; + gUnknown_203B460->unk50[gTradeItemsMenu->sentItem.itemIndex] = load; } void sub_80369FC(void) @@ -597,7 +594,7 @@ void sub_8036B28(void) break; case 6: gUnknown_202DE30 = gTradeItemsMenu->numItemsToSend; - sub_8090DC4(&gUnknown_202DE58,gTradeItemsMenu->chosenItem,0); + sub_8090DC4(&gUnknown_202DE58,gTradeItemsMenu->itemToSend.itemIndex,0); sub_8014248(&gUnknown_80E61E4,0,5, &gUnknown_80E6154,0,4,0,0,0x101); break; case 7: @@ -634,7 +631,7 @@ void sub_8036B28(void) // Fallthrough needed on each case case TRADE_ITEMS_SEND_ITEM_MODE: temp = &gTradeItemsMenu->unk244; - temp2 = &gTradeItemsMenu->unk254; + temp2 = &gTradeItemsMenu->sentItem; load_2 = temp2->numItems; temp->itemIndex = temp2->itemIndex; temp->numItems = load_2; @@ -665,7 +662,7 @@ void sub_8036B28(void) break; case 0xd: gUnknown_202DE30 = gTradeItemsMenu->numItemsToSend; - sub_8090DC4(&gUnknown_202DE58,gTradeItemsMenu->chosenItem,0); + sub_8090DC4(&gUnknown_202DE58,gTradeItemsMenu->itemToSend.itemIndex,0); sub_80141B4(&gUnknown_80E6358,0,0,0x101); break; case 0xB: @@ -1085,7 +1082,7 @@ void sub_8036F30(void) void sub_8036F74(void) { sub_8006518(gTradeItemsMenu->unk184); - sub_8036ECC(2, gUnknown_203B460->unk50[gTradeItemsMenu->chosenItem]); + sub_8036ECC(2, gUnknown_203B460->unk50[gTradeItemsMenu->itemToSend.itemIndex]); sub_801CCD8(); sub_8035CF4(&gTradeItemsMenu->unk44, 3, 0); sub_8036F30();