mirror of
https://github.com/pret/pmd-sky.git
synced 2026-04-25 07:24:42 -05:00
Updated Decompiling a function (markdown)
parent
c600f55ec0
commit
a884d73ae8
|
|
@ -310,4 +310,38 @@ Note that the permuter only makes changes that are functionally equivalent to th
|
|||
## Asking for help
|
||||
If you have trouble matching a function, you can ask for help on the pret Discord's #asm2c channel. Post the link to your decomp.me scratch on the channel, and other people can fork the scratch to experiment on their own. You'll see a notification on decomp.me if anyone successfully matches your function. You can also browse through previously matched functions for inspiration on tricks used by others to produce matching assembly. As you continue to decompile more, you can try helping others in the channel, which in turn will help you practice and gain exposure to the nuances of the decompilation process.
|
||||
|
||||
If all else fails, leave the function in assembly within the decomp project and add a comment linking to your decomp.me scratch. This provides others with a starting point to try matching the function later on.
|
||||
If all else fails, leave the function in assembly within the decomp project and add a comment linking to your decomp.me scratch. This provides others with a starting point to try matching the function later on.
|
||||
|
||||
## NONMATCHING
|
||||
If you are unable to matching the ASM exactly, but are confident that your C code is functionally equivalent to the ASM, you can add your C code to the decomp using the `NONMATCHING` flag. The raw ASM for the function remains in the project and is used when building the project normally, but the nonmatching code can be used for a build with the command `make <language>-nonmatching` (e.g., `make us-nonmatching`). In addition, functionally equivalent C code is still useful for documentation and research even if it doesn't match the ASM exactly.
|
||||
|
||||
`extract_function` offers a `-n` (or `--nonmatching`) argument to automatically set up a nonmatching function.
|
||||
|
||||
### Manually inserting a nonmatching function
|
||||
Alternatively, to set up a nonmatching function up manually, follow similar steps to manually inserting a matching function, except with the following differences:
|
||||
1. If the function is in the middle of the `.s` file, split it just like with a matching function, but leave the target function in the old `.s` file.
|
||||
2. Surround the function's raw ASM with `#ifndef NONMATCHING`
|
||||
```
|
||||
; https://decomp.me/scratch/jVfou
|
||||
#ifndef NONMATCHING
|
||||
arm_func_start AiConsiderMove
|
||||
AiConsiderMove: ; 0x02319880
|
||||
...
|
||||
arm_func_end AiConsiderMove
|
||||
#endif
|
||||
```
|
||||
3. In the `.c` file, surround the function with `#ifdef NONMATCHING`
|
||||
```
|
||||
// https://decomp.me/scratch/jVfou
|
||||
#ifdef NONMATCHING
|
||||
u32 AiConsiderMove(struct ai_possible_move *ai_possible_move, struct entity *monster, struct move *move)
|
||||
{
|
||||
...
|
||||
}
|
||||
#endif
|
||||
```
|
||||
|
||||
### Validating a nonmatching function
|
||||
To validate that a nonmatching function builds, first run `make tidy` to clean up the build files. Then, run `make us-nonmatching` (or one of the other languages if the function has EU/JP-specific code), and make sure the build runs to completion. The built binary will not match the original ROM hash, but if you make it to the point where it compares hashes, then you know the ROM can build successfully.
|
||||
|
||||
Whenever you switch between a nonmatching and a matching build, remember to run `make tidy`. Otherwise, stale build files will remain that do not respect the current `NONMATCHING` setting.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user