Homebrew Question Mario 64 port?

Gonax

Member
Newcomer
Joined
Oct 14, 2019
Messages
7
Trophies
0
Age
19
XP
98
Country
Peru
Hi, I hope the next steps help to somebody, first forgive my bad English, is no my native language.

Switch Compilation Process

If you read the guide:

https://github.com/fgsfdsfgs/sm64pc/wiki/Compiling-for-Nintendo-Switch

The steps are loosely explained, but they don’t work well for me, so I decided read a lot of documentation and this thread completely.

When you want to compile by yourself the code for Nintendo Switch, you will need have a functional MSYS2 shell, for installing it you need:

Download the latest version from: https://github.com/msys2/msys2-installer/releases

Install the version corresponding to your Operating System (64 or 32 bits).

Accept the defaults in installation program of MSYS2 once you finish the installation you will have shortcuts for MSYS2, MinGW32 and MinGW64. MSYS2 is used to compiling POSIX binaries for Linux from Windows.

MinGW32 & MinGW64 compile Native Windows binaries using a linux toolchain (gcc, bash, etc.)

Launch MSYS2 shell and execute the command: pacman -Syuu several times until you get the message: "there is nothing to do".

In order to compile the Switch binary you must first confirm all works fine compiling a binary for Windows. So do the next steps:

Install prerequisites

In a MinGW64 shell (or MinGW32 if you have a Windows 32 bit edition, why?). Be sure the prompt shows MINGW64 or MINGW32 if not you started the wrong shell, close it and open the right one.

Please execute the next command, several times until you get the message "there is nothing to do", you can be asked to restarts the MINGW64 environment few times:
pacman -Syuu

Then execute the next command:

pacman -Sy --noconfirm base-devel git make mercurial python3 subversion unzip autoconf automake libtool pkg-config autoconf-wrapper mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc mingw-w64-x86_64-glew mingw-w64-x86_64-SDL2 mingw-w64-x86_64-toolchain mingw-w64-x86_64-SDL

Once the installation end, verify the MSYS2 database again:

pacman -Syuu

Clone the repository, using the --recursive option in order to clone all the trees.

git clone --recursive https://github.com/fgsfdsfgs/sm64ex

The repository is cloned to a subfolder of the "Home" directory of MinGWXX Shell, on the prompt "~" means your home directory.

You need copy a legal copy of the original ROM in the cloned directory, it must be in "Big Endian" formatted and called:

./baserom.us.z64

copy the file to the path c:\msys64\home\USERNAME\sm64ex

If your ROM isn't on Big Endian format, use https://hack64.net/tools/swapper.php to convert it.

You should set the $PATH variable. For Windows 64 bits use the command:

export PATH=/mingw64/bin:/mingw32/bin:$PATH

And for Windows 32 bits use:

export PATH=/mingw32/bin:/mingw64/bin:$PATH

The repository needs you to compile the AudioFile library, so you need to run these commands:

Code:
cd sm64ex/tools/audiofile-0.3.6/
autoreconf -i
LIBS=-lstdc++ ; ./configure --disable-docs
make
mkdir ../lib
cp libaudiofile/.libs/libaudiofile.a ../lib/
cp libaudiofile/.libs/libaudiofile.la ../lib/

Then you need to edit the sm64ex\tools\Makefile file using a decent Text Editor and change the line:

tabledesign_CFLAGS := -Wno-uninitialized -laudiofile

By:

tabledesign_CFLAGS := -Wno-uninitialized -laudiofile -lstdc++

Pay attention to the space before " -lstdc++". then run the commands:

Code:
cd ..
make

Last, you can compile the Widows executable using make and the build options you choose, by example:

Code:
cd ..
make BETTERCAMERA=1 NODRAWINGDISTANCE=1 TEXTURE_FIX=1 EXT_OPTIONS_MENU=1 -j9

If all go through you get an .exe file on build subfolder of sm64ex.

Troubleshooting
  • If you get the error gcc: command not found or make: gcc: No such file or directory you do not install all needed packages or run the wrong Shell, be sure of running «MINGW32» or «MINGW64» and what that is pointed on the prompt in purple.
  • If the ROM is missing or wrong format/version you get the error Failed to open baserom.us.z64! Verify the correct ROM at the c:\msys64\home\<username>\sm64ex.folder.
  • If you get the error make: *** No targets specified and no makefile found. Stop. You are on the wrong folder the last make command should be run from c:\msys64\home\<username>\sm64ex folder.
  • Be sure of get the responses Target: i686-w64-mingw32 or Target: x86_64-w64-mingw32 when you run the command gcc -v if else other is shown on screen you install the wrong gcc package or run MSYS shell, remember the process should be run on «MINGW32» or «MINGW64» shells.
Nintendo Switch compilation.

After all works fine and a Windows binary is created, you can run extra steps for make a Switch NRO file

First you need to install DevKitPro.

You need to edit the pacman.conf on c:\msys64\etc\

And add the next lines at end of it:

Code:
[dkp-libs]
Server = https://downloads.devkitpro.org/packages

[dkp-windows]
Server = https://downloads.devkitpro.org/packages/windows

Import the cypher keys of DevKitPro

Code:
pacman-key --recv BC26F752D25B92CE272E0F44F7FD5492264BB9D0 --keyserver keyserver.ubuntu.com
pacman-key --recv F7FD5492264BB9D0

In my case the command fail because the server didn’t send the correct file:
Code:
gpg: keyserver receive failed: General error
==> ERROR: Remote key not fetched correctly from keyserver.

So, I did save the next content on a file called pubring.gpg: ()




Then import it manually:

Code:
pacman-key --import "FULL_PATH_TO_FOLDER_CONTAINING_pubring_gpg"

By example:

Code:
pacman-key --import "C:\downloads\DevKitPro"


Next sign locally the key:

Code:
pacman-key --lsign BC26F752D25B92CE272E0F44F7FD5492264BB9D0
pacman-key --lsign F7FD5492264BB9D0

Then verify the key is working well:

Code:
pacman-key -l BC26F752D25B92CE272E0F44F7FD5492264BB9D0
pacman-key -l F7FD5492264BB9D0

You should get a response just like:

Code:
pub  rsa4096 2018-02-28 [SC]
      BC26F752D25B92CE272E0F44F7FD5492264BB9D0
uid          [  full  ] Dave Murphy (WinterMute) <[email protected]>
sub  rsa4096 2018-02-28 [E]

Install DevKitPro Keyring

Code:
pacman -U https://downloads.devkitpro.org/devkitpro-keyring.pkg.tar.xz

Now verify MSYS2 database:

Code:
pacman -Sy
pacman -Syu

Install DevKitPro packages:

Code:
pacman -S --noconfirm switch-dev devkitA64 dkp-toolchain-vars libnx switch-tools switch-mesa switch-libdrm_nouveau switch-sdl2

Set needed variables

Code:
export DEVKITPRO=/opt/devkitpro
export DEVKITARM=/opt/devkitpro/devkitARM
export DEVKITPPC=/opt/devkitpro/devkitPPC

By last run the next commands in order to make the NRO file, PLEASE DO NOT FORGET TO COPY THE EXE FILE GENERATED FOR WINDOWS TO OTHER PATH, it will be deleted on the next step.

Code:
git stash
git checkout master
git pull
git checkout -f switch
make clean
(optional)
Code:
source $DEVKITPRO/switchvars.sh

You can use any build options you want, one example:

Code:
make TARGET_SWITCH=1 BETTERCAMERA=1 NODRAWINGDISTANCE=1 TEXTURE_FIX=1 -j9

BUILD OPTIONS
Build optionDefaultPossible valuesDescription
VERSIONusus, eu, jp, shWhich ROM to use. The selected ROM has to be in the repo folder with the name baserom.$VERSION.z64. sh is currently broken.
TARGET_BITS32, 64,TARGET_BITS=n appends some compiler flags for an n-bit build. If the value is empty, the option does nothing, assuming your native toolchain will set everything up by itself. Use this only if you're having trouble otherwise.
TARGET_RPI00, 1If 1, select optimal settings for Raspberry PI hardware. See the main article (https://github.com/sm64pc/sm64pc/wiki/Helper-compiling-script-for-Raspberry-Pi) on that.
TARGET_WEB00, 1If 1, build Emscripten version. See the main article (https://github.com/sm64pc/sm64pc/wiki/Compiling-for-the-web) on that.
WINDOWS_BUILD0, 1If 1, build for Windows. Usually set automatically if building on Windows.
OSX_BUILD00, 1If 1, build for OSX.
WINDOWS_CONSOLE00, 1If 1, append -mconsole to Windows CFLAGS, making a console window appear while the game is running. Can be useful for debugging purposes.
DEBUG00, 1If 1, build with debug symbols and default optimization level. Otherwise build with -O2.
RENDER_APIGLGL, GL_LEGACY, D3D11, D3D12Select rendering backend to use.
GL corresponds to OpenGL 2.1 (gfx_opengl.c),
GL_LEGACY corresponds to OpenGL 1.3 (gfx_opengl_legacy.c).
Direct3D backends will also force WINDOW_API to DXGI.
WINDOW_APISDL2SDL2, DXGISelect windowing backend. GL renderers force SDL2 and D3D renderers force DXGI for now, so you don't need to specify this.
AUDIO_APISDL2SDL2Select audio backend. There's only one right now.
CONTROLLER_APISDL2SDL2Specify list of controller backends to use. There's only one right now.
BETTERCAMERA00, 1If 1, build with analog camera support (uses Puppycam).
NODRAWINGDISTANCE00, 1If 1, build with disabled draw distance (every object is active at all times). May affect gameplay.
TEXTURE_FIX00, 1If 1, enable various texture-related bugfixes (e.g. fixes the smoke texture).
EXT_OPTIONS_MENU10, 1If 1, enable Options menu. Accessed from the Pause menu by pressing R.
EXTERNAL_DATA00, 1If 1, load textures and soundbanks from external files. Allows you to use texture packs. The default data is copied to a res folder next to the produced executable. (En Switch va en la carpeta raíz), para PC no lo genera
DISCORDRPC00, 1If 1, enable Discord Rich Presence support. Only works on x86_64.
TEXTSAVES00, 1If 1, use INI-based save format instead of binary EEPROM dumps. Experimental.





Optional Steps
If you want a Banner for the NRO file, you need to put a file called nx_icon.jpg on the sm64ex folder and BEFORE run the last make command you edit the Makefile file and replace the next lines

Code:
# add `--icon=$(APP_ICON)` to this when we get a suitable icon
%.nro: %.stripped %.nacp
      @elf2nro $< [email protected] --nacp=$*.nacp
      @echo built ... $(notdir [email protected])

By these:

Code:
# add `--icon=$(APP_ICON)` to this when we get a suitable icon
%.nro: %.stripped %.nacp
      @elf2nro $< [email protected] --nacp=$*.nacp --icon=$(APP_ICON)
      @echo built ... $(notdir [email protected])

After the NRO file is created, you can use SAK Switch Army Knife to make a NSP forwarder installable on the HOS.


-edited to update the new packages dependencies-

--edited to correct some typos and code errors--

I manage to build the switch version following you instructions, thank you.
May I ask if there exist a way to play it at 60 fps
 
  • Love
Reactions: impeeza

impeeza

¡Kabito!
Member
Joined
Apr 5, 2011
Messages
3,517
Trophies
3
Age
45
Location
At my chair.
XP
9,007
Country
Colombia
I manage to build the switch version following you instructions, thank you.
May I ask if there exist a way to play it at 60 fps
Yes there is a patch, will post tomorrow
Post automatically merged:

Before build you can apply 60 fps patch, execute the next commands BEFORE make:

Bash:
tools/apply_patch.sh enhancements/60fps_ex.patch
git apply enhancements/60fps_ex.patch

that applies the patch to the source code.

is on the official wiki.
 
Last edited by impeeza,
General chit-chat
Help Users
  • No one is chatting at the moment.
    K3N1 @ K3N1: https://youtube.com/shorts/PArWUK0WyDQ?feature=share