diff options
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | CONTRIBUTING.md | 8 | ||||
-rw-r--r-- | INSTALL.md | 12 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | arm7/Makefile | 1 | ||||
-rw-r--r-- | arm9/Makefile | 1 | ||||
-rw-r--r-- | arm9/lib/syscall/_svc_mw.s | 76 | ||||
-rw-r--r-- | arm9/src/pokemon.c | 2 | ||||
-rw-r--r-- | arm9/src/waza.c | 46 | ||||
-rw-r--r-- | explode_incbins.py | 21 | ||||
-rw-r--r-- | include/move_data.h | 33 | ||||
-rw-r--r-- | tools/csv2bin/Makefile | 8 |
12 files changed, 98 insertions, 113 deletions
diff --git a/.travis.yml b/.travis.yml index 9c60702e..32b091c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,6 @@ cache: install: # These files are only accessible from Travis CI IP Addresses to prevent piracy. - wget http://private.martmists.com/mwccarm.zip - - wget http://private.martmists.com/baserom.nds - wget http://private.martmists.com/nitro.zip - unzip mwccarm.zip - mv mwccarm tools diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 397bdf95..d8e2b89c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -105,11 +105,11 @@ OBJDUMP_MODE="${OBJDUMP_MODE:-force-thumb}" OBJDUMP_VMA="${OBJDUMP_VMA:-0x02000000}" OBJDUMP="arm-none-eabi-objdump -Drz -bbinary -m${OBJDUMP_ARCH} -M${OBJDUMP_MODE}" OPTIONS="--start-address=$(($1 + OBJDUMP_VMA)) --stop-address=$(($1 + $2 + OBJDUMP_VMA))" -$OBJDUMP $OPTIONS baserom.sbin > baserom.dump || exit 1 -$OBJDUMP $OPTIONS build/arm9.sbin > arm9.dump -diff -u baserom.dump arm9.dump +$OBJDUMP $OPTIONS $(dirname $0)/baserom.sbin > $(dirname $0)/baserom.dump || exit 1 +$OBJDUMP $OPTIONS $(dirname $0)/build/arm9.sbin > $(dirname $0)/arm9.dump +diff -u $(dirname $0)/baserom.dump $(dirname $0)/arm9.dump ``` -Place a clean version of the ARM9 binary as arm9/baserom.sbin. In your terminal, navigate to the arm9 directory and run `./asmdiff.sh 0 $(wc -c baserom.sbin) | less`, then scroll through to where the grievances begin. Fix any obvious problems in your code/tree, and rerun. If the differences are extensive, you may have induced a shift in the binary either by writing incorrect code or placing it incorrectly into the LCF. *Tip: you can specify a start address and size to only compare the portion of the ROM you are working on.* +Place a clean version of the ARM9 binary as arm9/baserom.sbin (arm9/build/arm9.bin from a successful build should suffice). In your terminal, navigate to the arm9 directory and run `./asmdiff.sh 0 $(wc -c baserom.sbin) | less`, then scroll through to where the grievances begin. Fix any obvious problems in your code/tree, and rerun. If the differences are extensive, you may have induced a shift in the binary either by writing incorrect code or placing it incorrectly into the LCF. *Tip: you can specify a start address and size to only compare the portion of the ROM you are working on.* ## Decompiling data @@ -1,18 +1,14 @@ -### 1. Copy baserom(s) into root folder - -Put a clean copy of Pokemon Diamond (US) nds rom at `./baserom.nds`. - -### 2. Install MWCC compiler +### 1. Install MWCC compiler The build system requires the use of the Metrowerk C Compiler 2.0/base to compile matching files. We cannot distribute the correct compiler here so join the PRET discord and download the pinned mwccarm.zip zip in #pokediamond and extract it to tools/. Run each of the executables so they ask for a license.dat and provide the one in the rar (it may also ask for it when compiling). This only needs to be done once. In the future, a GCC option will be available so MWCC is not required to build, however it is required for a matching ROM. -### 3. Install Nitro SDK +### 2. Install Nitro SDK As with the compiler, the Nitro SDK is proprietary and cannot be distributed here. Opened the pinned Mega folder in the PRET discord and download "NITRO SDK v3.0.zip" and "NITRO SDK V3.0 Plus 2.zip" from the "SDK System Libraries" folder. Extract v3.0.zip into a separate folder, then extract v3.0 Plus 2.zip into the same folder, overwriting when prompted. Copy the contents of tools/bin from the Nitro SDK to tools/bin in your pokediamond clone. Finally, copy include/nitro/specfiles/ARM7-TS.lcf.template into the arm7 subdirectory, and include/nitro/specfiles/ARM9-TS.lcf.template into the arm9 subdirectory. -### 4. Dependencies +### 3. Dependencies #### Linux @@ -48,7 +44,7 @@ You will still require the following packages: Install them using either the Cygwin package manager or using pacman on Msys2. -### 5. Build ROM +### 4. Build ROM Run `make` to build the ROM. @@ -8,6 +8,8 @@ It builds the following ROM: To set up the repository, see [INSTALL.md](INSTALL.md). +For contributor instructions, see [CONTRIBUTING.md](CONTRIBUTING.md). + ## See also Other disassembly and/or decompilation projects: diff --git a/arm7/Makefile b/arm7/Makefile index 1ade0ed4..1b0cd3c3 100644 --- a/arm7/Makefile +++ b/arm7/Makefile @@ -196,7 +196,6 @@ DUMMY != mkdir -p $(ALL_DIRS) %.pal: ; # Included files -baserom.%: ; %.h: ; %.inc: ; diff --git a/arm9/Makefile b/arm9/Makefile index 9c1d4f9a..cb8eba06 100644 --- a/arm9/Makefile +++ b/arm9/Makefile @@ -305,7 +305,6 @@ DUMMY != mkdir -p $(ALL_DIRS) %.pal: ; # Included files -baserom.%: ; %.h: ; %.inc: ; diff --git a/arm9/lib/syscall/_svc_mw.s b/arm9/lib/syscall/_svc_mw.s index c1e36b4b..d449ee58 100644 --- a/arm9/lib/syscall/_svc_mw.s +++ b/arm9/lib/syscall/_svc_mw.s @@ -7,115 +7,115 @@ ; Secure area .space 0x800 - non_word_aligned_thumb_func_start SVC_SoftReset + .global SVC_SoftReset + .thumb SVC_SoftReset: swi 0 bx lr - thumb_func_end SVC_SoftReset - non_word_aligned_thumb_func_start SVC_WaitByLoop + .global SVC_WaitByLoop + .thumb SVC_WaitByLoop: swi 3 bx lr - thumb_func_end SVC_WaitByLoop - non_word_aligned_thumb_func_start SVC_WaitIntr + .global SVC_WaitIntr + .thumb SVC_WaitIntr: mov r2, #0 swi 4 bx lr - thumb_func_end SVC_WaitIntr - non_word_aligned_thumb_func_start SVC_WaitVBlankIntr + .global SVC_WaitVBlankIntr + .thumb SVC_WaitVBlankIntr: mov r2, #0 swi 5 bx lr - thumb_func_end SVC_WaitVBlankIntr - non_word_aligned_thumb_func_start SVC_Halt + .global SVC_Halt + .thumb SVC_Halt: swi 6 bx lr - thumb_func_end SVC_Halt - non_word_aligned_thumb_func_start SVC_Div + .global SVC_Div + .thumb SVC_Div: swi 9 bx lr - thumb_func_end SVC_Div - non_word_aligned_thumb_func_start SVC_DimRem + .global SVC_DivRem + .thumb SVC_DivRem: swi 9 add r0, r1, #0 bx lr - thumb_func_end SVC_DivRem - non_word_aligned_thumb_func_start SVC_CpuSet + .global SVC_CpuSet + .thumb SVC_CpuSet: swi 11 bx lr - thumb_func_end SVC_CpuSet - non_word_aligned_thumb_func_start SVC_CpuFastSet -SVC_CpuFastSet: + .global SVC_CpuSetFast + .thumb +SVC_CpuSetFast: swi 12 bx lr - thumb_func_end SVC_CpuFastSet - non_word_aligned_thumb_func_start SVC_Sqrt + .global SVC_Sqrt + .thumb SVC_Sqrt: swi 13 bx lr - thumb_func_end SVC_Sqrt - non_word_aligned_thumb_func_start SVC_GetCRC16 + .global SVC_GetCRC16 + .thumb SVC_GetCRC16: swi 14 bx lr - thumb_func_end SVC_GetCRC16 - non_word_aligned_thumb_func_start IsMemExpanded -IsMemExpanded: + .global IsMmemExpanded + .thumb +IsMmemExpanded: swi 15 bx lr - thumb_func_end IsMemExpanded - non_word_aligned_thumb_func_start SVC_UnpackBits + .global SVC_UnpackBits + .thumb SVC_UnpackBits: swi 16 bx lr - thumb_func_end SVC_UnpackBits - non_word_aligned_thumb_func_start SVC_UncompressLZ8 + .global SVC_UncompressLZ8 + .thumb SVC_UncompressLZ8: swi 17 bx lr - thumb_func_end SVC_UncompressLZ8 - non_word_aligned_thumb_func_start SVC_UncompressLZ16FromDevice + .global SVC_UncompressLZ16FromDevice + .thumb SVC_UncompressLZ16FromDevice: swi 18 bx lr - thumb_func_end SVC_UncompressLZ16FromDevice - non_word_aligned_thumb_func_start SVC_UncompressHuffmanFromDevice + .global SVC_UncompressHuffmanFromDevice + .thumb SVC_UncompressHuffmanFromDevice: swi 19 bx lr - thumb_func_end SVC_UncompressHuffmanFromDevice - non_word_aligned_thumb_func_start SVC_UncompressRL8 + .global SVC_UncompressRL8 + .thumb SVC_UncompressRL8: swi 20 bx lr - thumb_func_end SVC_UncompressRL8 - non_word_aligned_thumb_func_start SVC_UncompressRL16FromDevice + .global SVC_UncompressRL16FromDevice + .thumb SVC_UncompressRL16FromDevice: swi 21 bx lr - thumb_func_end SVC_UncompressRL16FromDevice .balign 4, 0 ; Don't pad with nop diff --git a/arm9/src/pokemon.c b/arm9/src/pokemon.c index 9bd9764d..8df597a6 100644 --- a/arm9/src/pokemon.c +++ b/arm9/src/pokemon.c @@ -2859,7 +2859,7 @@ void FUN_02069718(struct BoxPokemon * boxmon, u16 move) } moves[3] = move; - pp[3] = (u8)GetWazaAttr(move, 5); + pp[3] = (u8)GetWazaAttr(move, MOVEATTR_PP); ppUp[3] = 0; for (i = 0; i < 4; i++) diff --git a/arm9/src/waza.c b/arm9/src/waza.c index 4b505482..f394fedd 100644 --- a/arm9/src/waza.c +++ b/arm9/src/waza.c @@ -15,7 +15,7 @@ void LoadAllWazaTbl(struct WazaTbl * dest) ReadFromNarcMemberByIdPair(dest, NARC_POKETOOL_WAZA_WAZA_TBL, 0, 0, (NUM_MOVES + 1) * sizeof(struct WazaTbl)); } -u32 GetWazaAttr(u16 waza, u32 attr) +u32 GetWazaAttr(u16 waza, MoveAttr attr) { struct WazaTbl wazaTbl; LoadWazaEntry(waza, &wazaTbl); @@ -27,38 +27,40 @@ u8 WazaGetMaxPp(u16 waza, u8 ppUp) u8 pp; if (ppUp > 3) ppUp = 3; - pp = (u8)GetWazaAttr(waza, 5); + pp = (u8)GetWazaAttr(waza, MOVEATTR_PP); return (u8)(pp + (pp * 20 * ppUp) / 100); } -u32 GetAttrFromWazaTbl(struct WazaTbl * wazaTbl, u32 attr) +u32 GetAttrFromWazaTbl(struct WazaTbl * wazaTbl, MoveAttr attr) { switch (attr) { - case 0: - return wazaTbl->unk0; - case 1: + case MOVEATTR_EFFECT: + return wazaTbl->effect; + case MOVEATTR_UNK1: return wazaTbl->unk2; - case 2: - return wazaTbl->unk3; - case 3: - return wazaTbl->unk4; - case 4: - return wazaTbl->unk5; - case 5: + case MOVEATTR_POWER: + return wazaTbl->power; + case MOVEATTR_TYPE: + return wazaTbl->type; + case MOVEATTR_ACCURACY: + return wazaTbl->accuracy; + case MOVEATTR_PP: return wazaTbl->pp; - case 6: - return wazaTbl->unk7; - case 7: + case MOVEATTR_EFFECT_CHANCE: + return wazaTbl->effectChance; + case MOVEATTR_UNK7: return wazaTbl->unk8; - case 8: - return wazaTbl->unkA; - case 9: + case MOVEATTR_PRIORTY: + return wazaTbl->priority; + case MOVEATTR_UNK9: return wazaTbl->unkB; - case 10: + case MOVEATTR_UNK10: return wazaTbl->unkC; - case 11: - return wazaTbl->unkD; + case MOVEATTR_CONTEST_TYPE: + return wazaTbl->contestType; + default: + return (u32)wazaTbl; } } diff --git a/explode_incbins.py b/explode_incbins.py deleted file mode 100644 index 4e1af1b5..00000000 --- a/explode_incbins.py +++ /dev/null @@ -1,21 +0,0 @@ -import sys -import re - -with open(sys.argv[1], 'rb') as rom: - for fname in sys.argv[2:]: - with open(fname, 'r+') as fp: - lines = [] - for line in fp: - m = re.search(r'\.incbin "baserom.nds", (0x\w+), (0x\w+)', line) - if m is not None: - addr = int(m[1], 16) - size = int(m[2], 16) - rom.seek(addr) - for i in range(0, size, 16): - data = rom.read(min(size - i, 16)) - lines.append('\t.byte ' + ', '.join(f'0x{k:02X}' for k in data) + '\n') - else: - lines.append(line) - fp.seek(0) - fp.truncate() - fp.write(''.join(lines)) diff --git a/include/move_data.h b/include/move_data.h index 5267bfb1..a970e1bf 100644 --- a/include/move_data.h +++ b/include/move_data.h @@ -3,24 +3,39 @@ struct WazaTbl { - u16 unk0; + u16 effect; u8 unk2; - u8 unk3; - u8 unk4; - u8 unk5; + u8 power; + u8 type; + u8 accuracy; u8 pp; - u8 unk7; + u8 effectChance; u16 unk8; - s8 unkA; + s8 priority; u8 unkB; u8 unkC; - u8 unkD; + u8 contestType; u8 padding[2]; }; +typedef enum MoveAttr { + MOVEATTR_EFFECT = 0, + MOVEATTR_UNK1, + MOVEATTR_POWER, + MOVEATTR_TYPE, + MOVEATTR_ACCURACY, + MOVEATTR_PP, + MOVEATTR_EFFECT_CHANCE, + MOVEATTR_UNK7, + MOVEATTR_PRIORTY, + MOVEATTR_UNK9, + MOVEATTR_UNK10, + MOVEATTR_CONTEST_TYPE, +} MoveAttr; + void LoadAllWazaTbl(struct WazaTbl * dest); u8 WazaGetMaxPp(u16 move, u8 ppUp); -u32 GetWazaAttr(u16 move, u32 attr); -u32 GetAttrFromWazaTbl(struct WazaTbl * wazaTbl, u32 attr); +u32 GetWazaAttr(u16 move, MoveAttr attr); +u32 GetAttrFromWazaTbl(struct WazaTbl * wazaTbl, MoveAttr attr); #endif //POKEDIAMOND_MOVE_DATA_H diff --git a/tools/csv2bin/Makefile b/tools/csv2bin/Makefile index 949ec4e4..818e6579 100644 --- a/tools/csv2bin/Makefile +++ b/tools/csv2bin/Makefile @@ -1,19 +1,13 @@ CC = gcc CFLAGS = -O3 -growth_rates_txt = $(wildcard *.txt) -growth_rates_bin = $(growth_rates_txt:%.txt=%.bin) - .PHONY: all clean all: csv2bin $(growth_rates_bin) @: clean: - $(RM) csv2bin $(growth_rates_bin) + $(RM) csv2bin csv2bin: csv2bin.c $(CC) $(CFLAGS) -o $@ $^ - -%.bin: %.txt - ./csv2bin $< |