From c56bd0cdcf9a24dd485be14b7dcfb780e4bfe559 Mon Sep 17 00:00:00 2001 From: sonicspiral <> Date: Sat, 5 Sep 2020 11:39:03 -0700 Subject: [PATCH 1/6] add starter windows terminal --- tools/windows_terminal.ps1 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tools/windows_terminal.ps1 diff --git a/tools/windows_terminal.ps1 b/tools/windows_terminal.ps1 new file mode 100644 index 0000000000..599794a966 --- /dev/null +++ b/tools/windows_terminal.ps1 @@ -0,0 +1,27 @@ +<# +.SYNOPSIS +Opens and sets up a few helpful starter tabs in Windows Terminal using the default distro. + +.DESCRIPTION +You can can set your default distro using: wsl --set-default . + +To register mips_to_c.py as a global command in your bash PATH: +sudo apt update +sudo apt install python3-pip +sudo git clone https://github.com/matt-kempster/mips_to_c.git /usr/local/bin/mips_to_c + +Then add PATH="$PATH:/usr/local/bin/mips_to_c" to the end of your ~/.bashrc file. +Any editor should work to do this: +vim ~/.bashrc +joe ~/.bashrc +code ~/.bashrc +Apply the changes using: source ~/.bashrc. + +You should be able to run mips_to_c.py now. + +.LINK +https://docs.microsoft.com/en-us/windows/wsl/reference +https://github.com/matt-kempster/mips_to_c.git +#> + +wt -d "../" `; split-pane -d "../" -V --title "diff.py" `; new-tab -d "../" --title "mips_to_c.py" `; focus-tab -t 0 From 58bcaf586f87e94c9f91573ec3a24567b92d4a8e Mon Sep 17 00:00:00 2001 From: sonicspiral <> Date: Sat, 5 Sep 2020 12:06:51 -0700 Subject: [PATCH 2/6] add mips_to_c.py local setup --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 3299ce49ac..c0bc1b07d4 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,17 @@ Decide on a function to match. These can be found in the subdirectories of `asm/ Take the relevant `.s` file and pass it to [mips_to_c](https://github.com/matt-kempster/mips_to_c) ([web version](https://simonsoftware.se/other/mips_to_c.py)). +You can also use mips_to_c locally by registering `mips_to_c.py` as a global command in your bash PATH: +``` +sudo apt update +sudo apt install python3-pip +sudo git clone https://github.com/matt-kempster/mips_to_c.git /usr/local/bin/mips_to_c +``` + +Then add `PATH="$PATH:/usr/local/bin/mips_to_c"` to the end of your `~/.bashrc` file. +You should be able to run `mips_to_c.py` now for any file in `asm/nonmatchings/`. Here's an example `mips_to_c.py ./asm/nonmatchings/code_13870_len_6980/func_8003B3D0.s func_8003B3D0`. +`. + If mips_to_c gives you an error about branch-likely instructions, edit the `.s` file and rename any branch-likely instructions to their unlikely equivalent (i.e. remove the `l` suffix). Add a `nop` after the branches and move the instruction that was originally in the delay slot (directly after the branch instruction) to the start of the target label. Don't commit the edited assembly. Open up the relevant `.c` file and replace the function's `INCLUDE_ASM` macro with the output from mips_to_c. Run the following command to attempt to compile, replacing `function_name` with the name of the function you're working with: From 39d8a13f73046ebd237a2c1604344f42b3ed1d19 Mon Sep 17 00:00:00 2001 From: sonicspiral <> Date: Sat, 5 Sep 2020 12:10:35 -0700 Subject: [PATCH 3/6] convert starter windows terminal to bat * note the requirement to run wsl --set-default first --- tools/windows_terminal.bat | 2 ++ tools/windows_terminal.ps1 | 27 --------------------------- 2 files changed, 2 insertions(+), 27 deletions(-) create mode 100644 tools/windows_terminal.bat delete mode 100644 tools/windows_terminal.ps1 diff --git a/tools/windows_terminal.bat b/tools/windows_terminal.bat new file mode 100644 index 0000000000..0402031eb1 --- /dev/null +++ b/tools/windows_terminal.bat @@ -0,0 +1,2 @@ +REM first set your default distro using: wsl --set-default +wt --title "diff.py" -d "../" ; split-pane -d "../" -V ; new-tab --title "mips_to_c.py" -d "../" ; focus-tab -t 0 diff --git a/tools/windows_terminal.ps1 b/tools/windows_terminal.ps1 deleted file mode 100644 index 599794a966..0000000000 --- a/tools/windows_terminal.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -<# -.SYNOPSIS -Opens and sets up a few helpful starter tabs in Windows Terminal using the default distro. - -.DESCRIPTION -You can can set your default distro using: wsl --set-default . - -To register mips_to_c.py as a global command in your bash PATH: -sudo apt update -sudo apt install python3-pip -sudo git clone https://github.com/matt-kempster/mips_to_c.git /usr/local/bin/mips_to_c - -Then add PATH="$PATH:/usr/local/bin/mips_to_c" to the end of your ~/.bashrc file. -Any editor should work to do this: -vim ~/.bashrc -joe ~/.bashrc -code ~/.bashrc -Apply the changes using: source ~/.bashrc. - -You should be able to run mips_to_c.py now. - -.LINK -https://docs.microsoft.com/en-us/windows/wsl/reference -https://github.com/matt-kempster/mips_to_c.git -#> - -wt -d "../" `; split-pane -d "../" -V --title "diff.py" `; new-tab -d "../" --title "mips_to_c.py" `; focus-tab -t 0 From ab484954190b837390558e5ac614b60b71febd90 Mon Sep 17 00:00:00 2001 From: sonicspiral <> Date: Tue, 29 Sep 2020 23:38:30 -0700 Subject: [PATCH 4/6] add comment for `wsl --set-default ` in bat file --- tools/windows_terminal.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/windows_terminal.bat b/tools/windows_terminal.bat index 0402031eb1..9dd5cda1cc 100644 --- a/tools/windows_terminal.bat +++ b/tools/windows_terminal.bat @@ -1,2 +1,3 @@ REM first set your default distro using: wsl --set-default +ehco "first set your default distro using: wsl --set-default " wt --title "diff.py" -d "../" ; split-pane -d "../" -V ; new-tab --title "mips_to_c.py" -d "../" ; focus-tab -t 0 From 4949824769ca4fbccc2d9999776fa718c0744735 Mon Sep 17 00:00:00 2001 From: sonicspiral <> Date: Tue, 29 Sep 2020 23:43:49 -0700 Subject: [PATCH 5/6] updated mipstoc guidnace for local use --- README.md | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c0bc1b07d4..76cd845197 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Discord: [Paper Mario Modding](https://discord.gg/urUm3VG) ## Setup -You'll need Linux, a Linux VM, or Windows 10 (WSL) to work on this project. +You'll need Linux, a Linux VM, or Windows 10 (WSL) to work on this project. For WSL, we've included `windows_termainl.bat` under tools that you can use to quickly spin up a terminal for your default distro set using `wsl --set-default `. #### Clone the repository @@ -76,16 +76,32 @@ Decide on a function to match. These can be found in the subdirectories of `asm/ Take the relevant `.s` file and pass it to [mips_to_c](https://github.com/matt-kempster/mips_to_c) ([web version](https://simonsoftware.se/other/mips_to_c.py)). -You can also use mips_to_c locally by registering `mips_to_c.py` as a global command in your bash PATH: +You can also use mips_to_c locally installed to a destination of your choice. Then register a function in `~/.bashrc` that calls `path/to/mips_to_c.py (with args)`: ``` sudo apt update sudo apt install python3-pip -sudo git clone https://github.com/matt-kempster/mips_to_c.git /usr/local/bin/mips_to_c +sudo git clone https://github.com/matt-kempster/mips_to_c.git path/to/mips_to_c ``` -Then add `PATH="$PATH:/usr/local/bin/mips_to_c"` to the end of your `~/.bashrc` file. -You should be able to run `mips_to_c.py` now for any file in `asm/nonmatchings/`. Here's an example `mips_to_c.py ./asm/nonmatchings/code_13870_len_6980/func_8003B3D0.s func_8003B3D0`. -`. +Here's a starter function you can use: +```sh +# don't forget to replace /path/to/mips_to_c with you're path +function mipstoc() { + if [ "$#" -eq 2 ]; then + echo "running mips_to_c on file $1 for func $2"; + /path/to/mips_to_c/mips_to_c.py $1 $2; + elif [ "$#" -gt 2 ]; then + echo "running mips_to_c on file $1 for func $2 with flags"; + /path/to/mips_to_c/mips_to_c.py $@; + else + printf "Please call mipstoc using this format and make sure you're at the repo root:"; + printf "\nmipstoc\t\033[0;31marg1 - the nonmatching asm file\033[0m \t\t\t\033[0;34marg2 - the target function\033[0m \033[0;33margN - any of the optional mips_to_c.py flags\033[0m"; + printf "\nmipstoc \033[0;31m./asm/nonmatchings/code_13870_len_6980/func_8003B3D0.s\033[0m \t\033[0;34mfunc_8003B3D0\033[0m \033[0;33m--flag1 --flag2 --flag3\033[0m\n"; + /path/to/mips_to_c/mips_to_c.py; + fi +} +export -f mipstoc +``` If mips_to_c gives you an error about branch-likely instructions, edit the `.s` file and rename any branch-likely instructions to their unlikely equivalent (i.e. remove the `l` suffix). Add a `nop` after the branches and move the instruction that was originally in the delay slot (directly after the branch instruction) to the start of the target label. Don't commit the edited assembly. From f478d476c6cf660d601bd9d93f7529ed2b2e9a85 Mon Sep 17 00:00:00 2001 From: sonicspiral <> Date: Thu, 1 Oct 2020 00:24:29 -0700 Subject: [PATCH 6/6] optimize sample mipstoc script and readme cleanup --- README.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 76cd845197..f1aa3786ce 100644 --- a/README.md +++ b/README.md @@ -85,26 +85,20 @@ sudo git clone https://github.com/matt-kempster/mips_to_c.git path/to/mips_to_c Here's a starter function you can use: ```sh -# don't forget to replace /path/to/mips_to_c with you're path +# don't forget to replace /path/to/mips_to_c with your path function mipstoc() { - if [ "$#" -eq 2 ]; then - echo "running mips_to_c on file $1 for func $2"; - /path/to/mips_to_c/mips_to_c.py $1 $2; - elif [ "$#" -gt 2 ]; then - echo "running mips_to_c on file $1 for func $2 with flags"; + if [ "$#" -gt 1 ]; then /path/to/mips_to_c/mips_to_c.py $@; else printf "Please call mipstoc using this format and make sure you're at the repo root:"; - printf "\nmipstoc\t\033[0;31marg1 - the nonmatching asm file\033[0m \t\t\t\033[0;34marg2 - the target function\033[0m \033[0;33margN - any of the optional mips_to_c.py flags\033[0m"; - printf "\nmipstoc \033[0;31m./asm/nonmatchings/code_13870_len_6980/func_8003B3D0.s\033[0m \t\033[0;34mfunc_8003B3D0\033[0m \033[0;33m--flag1 --flag2 --flag3\033[0m\n"; + printf "\nmipstoc \033[0;31marg1 - the nonmatching asm file\033[0m \033[0;34marg2 - the target function\033[0m \033[0;33margN - any of the optional mips_to_c.py flags\033[0m"; + printf "\nmipstoc \033[0;31m./asm/nonmatchings/code_13870_len_6980/func_8003B3D0.s\033[0m \033[0;34mfunc_8003B3D0\033[0m \033[0;33m--flag1 --flag2 --flagN\033[0m\n"; /path/to/mips_to_c/mips_to_c.py; fi } export -f mipstoc ``` -If mips_to_c gives you an error about branch-likely instructions, edit the `.s` file and rename any branch-likely instructions to their unlikely equivalent (i.e. remove the `l` suffix). Add a `nop` after the branches and move the instruction that was originally in the delay slot (directly after the branch instruction) to the start of the target label. Don't commit the edited assembly. - Open up the relevant `.c` file and replace the function's `INCLUDE_ASM` macro with the output from mips_to_c. Run the following command to attempt to compile, replacing `function_name` with the name of the function you're working with: ```sh