diff --git a/Dockerfile b/Dockerfile index ca63fa0f2..302a75fc4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,13 +14,6 @@ RUN apt-get update && \ zlib1g-dev && \ rm -rf /var/lib/apt/lists/* -RUN wget \ - https://github.com/n64decomp/qemu-irix/releases/download/v2.11-deb/qemu-irix-2.11.0-2169-g32ab296eef_amd64.deb \ - -O qemu.deb && \ - echo 8170f37cf03a08cc2d7c1c58f10d650ea0d158f711f6916da9364f6d8c85f741 qemu.deb | sha256sum --check && \ - dpkg -i qemu.deb && \ - rm qemu.deb - RUN git clone --depth 1 https://github.com/emscripten-core/emsdk.git && \ ./emsdk/emsdk install latest && \ ./emsdk/emsdk activate latest diff --git a/Doxyfile b/Doxyfile index f73f4c637..8087a237b 100644 --- a/Doxyfile +++ b/Doxyfile @@ -2089,7 +2089,7 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = NON_MATCHING AVOID_UB +PREDEFINED = AVOID_UB # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The diff --git a/Jenkinsfile b/Jenkinsfile index eee93a9fc..1d0410026 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -41,7 +41,7 @@ pipeline { git clean -fd . git checkout -- . echo 'y' | tools/apply_patch.sh "$f" - make -j4 VERSION=us COMPARE=0 + make -j4 VERSION=us done ''' } diff --git a/Makefile b/Makefile index 56404185f..02f864c54 100644 --- a/Makefile +++ b/Makefile @@ -14,10 +14,8 @@ default: all VERSION ?= us # Graphics microcode used GRUCODE ?= f3d_old -# If COMPARE is 1, check the output sha1sum when building 'all' -COMPARE ?= 1 -# If NON_MATCHING is 1, define the NON_MATCHING and AVOID_UB macros when building (recommended) -NON_MATCHING ?= 1 + +# define AVOID_UB macros when building (recommended) # Build and optimize for Raspberry Pi(s) TARGET_RPI ?= 0 @@ -28,25 +26,32 @@ TARGET_WEB ?= 0 # Makeflag to enable OSX fixes OSX_BUILD ?= 0 +# Makeflag to enable Windows fixes +WINDOWS_BUILD ?= 0 + # Specify the target you are building for, TARGET_BITS=0 means native TARGET_ARCH ?= native TARGET_BITS ?= 0 # Disable better camera by default BETTERCAMERA ?= 0 + # Disable no drawing distance by default NODRAWINGDISTANCE ?= 0 + # Disable texture fixes by default (helps with them purists) TEXTURE_FIX ?= 0 + # Enable extended options menu by default EXT_OPTIONS_MENU ?= 1 + # Disable text-based save-files by default TEXTSAVES ?= 0 + # Load textures from external PNG files EXTERNAL_TEXTURES ?= 0 # Various workarounds for weird toolchains - NO_BZERO_BCOPY ?= 0 NO_LDIV ?= 0 @@ -56,9 +61,7 @@ LEGACY_GL ?= 0 # Automatic settings for PC port(s) -NON_MATCHING := 1 GRUCODE := f3dex2e -WINDOWS_BUILD ?= 0 ifeq ($(TARGET_WEB),0) ifeq ($(OS),Windows_NT) @@ -139,31 +142,26 @@ ifeq ($(GRUCODE),f3dex) # Fast3DEX GRUCODE_CFLAGS := -DF3DEX_GBI GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1 --defsym F3DEX_GBI=1 TARGET := $(TARGET).f3dex - COMPARE := 0 else ifeq ($(GRUCODE), f3dex2) # Fast3DEX2 GRUCODE_CFLAGS := -DF3DEX_GBI_2 GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1 --defsym F3DEX_GBI_2=1 TARGET := $(TARGET).f3dex2 - COMPARE := 0 else ifeq ($(GRUCODE), f3dex2e) # Fast3DEX2 Extended (PC default) GRUCODE_CFLAGS := -DF3DEX_GBI_2E TARGET := $(TARGET).f3dex2e - COMPARE := 0 else ifeq ($(GRUCODE),f3d_new) # Fast3D 2.0H (Shindou) GRUCODE_CFLAGS := -DF3D_NEW GRUCODE_ASFLAGS := --defsym F3D_NEW=1 TARGET := $(TARGET).f3d_new - COMPARE := 0 else ifeq ($(GRUCODE),f3dzex) # Fast3DZEX (2.0J / Animal Forest - Dōbutsu no Mori) $(warning Fast3DZEX is experimental. Try at your own risk.) GRUCODE_CFLAGS := -DF3DEX_GBI_2 GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1 --defsym F3DZEX_GBI=1 TARGET := $(TARGET).f3dzex - COMPARE := 0 endif endif endif @@ -182,7 +180,6 @@ ifeq ($(OSX_BUILD),1) # Modify GFX & SDL2 for OSX GL endif VERSION_ASFLAGS := --defsym AVOID_UB=1 -COMPARE := 0 ifeq ($(TARGET_WEB),1) VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_WEB @@ -593,7 +590,6 @@ export LANG := C # N64 conversion tools TOOLS_DIR = tools MIO0TOOL = $(TOOLS_DIR)/mio0 -N64CKSUM = $(TOOLS_DIR)/n64cksum N64GRAPHICS = $(TOOLS_DIR)/n64graphics N64GRAPHICS_CI = $(TOOLS_DIR)/n64graphics_ci TEXTCONV = $(TOOLS_DIR)/textconv @@ -640,12 +636,6 @@ distclean: $(RM) -r $(BUILD_DIR_BASE) ./extract_assets.py --clean -test: $(ROM) - $(EMULATOR) $(EMU_FLAGS) $< - -load: $(ROM) - $(LOADER) $(LOADER_FLAGS) $< - libultra: $(BUILD_DIR)/libultra.a asm/boot.s: $(BUILD_DIR)/lib/bin/ipl3_font.bin @@ -861,9 +851,9 @@ $(BUILD_DIR)/src/audio/%.copt: $(BUILD_DIR)/src/audio/%.acpp $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/lib/copt -signed -I=$< -CMP=$@ -cp=i -scalaroptimize=1 endif -# Rebuild files with 'GLOBAL_ASM' if the NON_MATCHING flag changes. -$(GLOBAL_ASM_O_FILES): $(GLOBAL_ASM_DEP).$(NON_MATCHING) -$(GLOBAL_ASM_DEP).$(NON_MATCHING): +# Rebuild files with 'GLOBAL_ASM' if something happens? +$(GLOBAL_ASM_O_FILES): $(GLOBAL_ASM_DEP) +$(GLOBAL_ASM_DEP): @rm -f $(GLOBAL_ASM_DEP).* touch $@ diff --git a/asm/rom_header.s b/asm/rom_header.s deleted file mode 100644 index 88ac440fd..000000000 --- a/asm/rom_header.s +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Super Mario 64 ROM header - * Only the first 0x18 bytes matter to the console. - */ - -.byte 0x80, 0x37, 0x12, 0x40 /* PI BSD Domain 1 register */ -.word 0x0000000F /* Clockrate setting*/ -.word entry_point /* Entrypoint */ - -/* Revision */ -.if VERSION_SH == 1 - .word 0x00001448 -.elseif VERSION_EU == 1 - .word 0x00001446 -.else /* NTSC-U and NTSC-J 1.0 */ - .word 0x00001444 -.endif - -.word 0x4EAA3D0E /* Checksum 1 */ -.word 0x74757C24 /* Checksum 2 */ -.word 0x00000000 /* Unknown */ -.word 0x00000000 /* Unknown */ -.if VERSION_SH == 1 -.ascii "SUPERMARIO64 " /* Internal ROM name */ -.else -.ascii "SUPER MARIO 64 " /* Internal ROM name */ -.endif -.word 0x00000000 /* Unknown */ -.word 0x0000004E /* Cartridge */ -.ascii "SM" /* Cartridge ID */ - -/* Region */ -.if VERSION_US == 1 - .ascii "E" /* NTSC-U (North America) */ -.elseif (VERSION_JP == 1 || VERSION_SH == 1) - .ascii "J" /* NTSC-J (Japan) */ -.else - .ascii "P" /* PAL (Europe) */ -.endif - -.if VERSION_SH == 1 - .byte 0x03 /* Version (Shindou) */ -.else - .byte 0x00 /* Version */ -.endif - diff --git a/include/macros.h b/include/macros.h index f93642fb8..1a252b69e 100644 --- a/include/macros.h +++ b/include/macros.h @@ -7,12 +7,6 @@ #define GLOBAL_ASM(...) #endif -#if !defined(__sgi) && (!defined(NON_MATCHING) || !defined(AVOID_UB)) -// asm-process isn't supported outside of IDO, and undefined behavior causes -// crashes. -#error Matching build is only possible on IDO; please build with NON_MATCHING=1. -#endif - #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) #define GLUE(a, b) a ## b diff --git a/pisetup.sh b/pisetup.sh old mode 100755 new mode 100644 index 5b34c233b..ce432c351 --- a/pisetup.sh +++ b/pisetup.sh @@ -1,14 +1,15 @@ #!/bin/bash # Super Mario 64 PC on Raspberry Pi -# Find latest updates and code on https://www.github.com/sm64pc/sm64pc +# Find latest updates and code on https://www.github.com/sm64pc/sm64pc # ToDo: Test on more Pi models with fresh Raspbian and allow existing src folders to be updated. # clear echo "This script will assist with compiling Super Mario 64 on Raspbian 10" echo "Note that accelerated OpenGL (vc4_drm) is required for maximum performance" echo "Checking Raspberry Pi model..." +origdir=$PWD lowmem=0 -pi=0 +pi=1 pimodel=$(uname -m 2>/dev/null || echo unknown) pitype=$(tr -d '\0' < /sys/firmware/devicetree/base/model) @@ -22,28 +23,36 @@ then exp=1; fi -if [[ $pimodel =~ "armv7" ]] +if [[ $pimodel =~ "armv7" && $pitype =~ "Pi 2" || $pitype =~ "Pi 3" ]] then - echo + echo "" echo "Raspberry Pi Model 2/3 detected (32bit)" pi=2; lowmem=0; fi -if [[ $pimodel =~ "aarch64" && $pitype =~ "4" ]] +if [[ $pimodel =~ "aarch64" ]] +then +pi=4; +exp=1; +lowmem=0; +echo "" +echo "64bit Raspbian / Pi detected. Pi model defaulted to Pi 4" +fi + +if [[ $pitype =~ "Model 4" ]] then - echo + echo "" echo "Raspberry Pi Model 4 detected" - echo "Audio errors reported" - echo "Fixing audio config, reboot after compilation completes to activate" - sudo sed -i 's/load-module module-udev-detect/load-module module-udev-detect tsched=0/' /etc/pulse/default.pa - #load-module module-udev-detect tsched=0 + echo "Audio errors reported for Pulseaudio users. Fix by adding tsched=0 to module-udev-detect in /etc/pulse/default.pa" + #echo "Fixing audio config. If no errors are reported, reboot after compilation completes to activate." + #sudo sed -i 's/load-module module-udev-detect/load-module module-udev-detect tsched=0/' /etc/pulse/default.pa + #load-module module-udev-detect tsched=0 pi=4; lowmem=0; exp=1; fi - if [[ $exp == 1 ]] then echo "" @@ -55,6 +64,7 @@ then then echo "" else + echo "Y not entered. Exiting." exit fi @@ -67,12 +77,9 @@ fi #////////////////////////////////////////////////////////////////////////////////////////////////////////// clear echo "Super Mario 64 RPi Initial Setup" +# On Pi Pi4 only enable FKMS. -if [[ $pi != 4 ]] -then #Dumb idea, but quick hack. - #We CANNOT enable VC4 for Pi4 as it uses VC6 - -inxinf=$(inxi -Gx) +inxinf=$(inxi -Gx 2>&1) echo "Checking for pre-enabled VC4 acceleration (inxi -Gx)" if [[ $inxinf =~ "not found" ]] @@ -80,12 +87,15 @@ then echo "Error: inxi not installed. Installing..." sudo apt-get update sudo apt-get install inxi -inxi=$(inxi -Gx) +sync +sleep 1 +inxi=$(bash inxi -Gx 2>&1) +sleep 1 if [[ $inxinf =~ "not found" ]] then - echo "Warning: Setup will not continue unless inxi is installed" - echo "Please ensure your Pi is in a state to download and install packages" + echo "" + echo "Please reload the script to detect installed inxi" sleep 3 exit fi @@ -100,15 +110,27 @@ sleep 4 else echo "" echo "OpenGL driver not found. opening Raspi-Config..." - echo "Please enable raspi-config -> ADV Opt -> OpenGL -> Enable FullKMS Renderer" + if [[ $pi == 4 ]] + then + echo "Please enable raspi-config -> ADV Opt -> OpenGL -> Enable FAKE KMS Renderer" + else + echo "Please enable raspi-config -> ADV Opt -> OpenGL -> Enable Full KMS Renderer" + fi echo "" sleep 5 sudo raspi-config + sync + if [[ $pi == 4 ]] + then + vc4add=$(cat /boot/config.txt | grep -e "dtoverlay=vc4-fkms-v3d") + else vc4add=$(cat /boot/config.txt | grep -e "dtoverlay=vc4-kms-v3d") - + fi if [[ $vc4add =~ "vc4" ]] then echo "OGL driver now enabled on reboot" + else + echo "OGL driver not detected / enabled in /boot/config.txt" fi fi @@ -158,7 +180,7 @@ read -p "Reboot to enable changes? (Y/N): " fixstart sleep 4 sudo reboot fi - fi + fi # "Should never run on a Pi 4" part ends here #-------------------------------------------------------------------------------- @@ -198,9 +220,12 @@ then echo "" echo "Installing dependencies for SDL2 compilation" -sudo sed -i '/^#\sdeb-src /s/^#//' "/etc/apt/sources.list" -sudo apt build-dep libsdl2 -sudo apt install libdrm-dev libgbm-dev +sudo sed -i -- 's/#deb-src/deb-src/g' /etc/apt/sources.list && sudo sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list +sync +sudo apt-get update +sync +sudo apt-get build-dep libsdl2 +sudo apt-get install libdrm-dev libgbm-dev sync echo "" @@ -211,20 +236,22 @@ mkdir $HOME/src cd $HOME/src mkdir $HOME/src/sdl2 cd $HOME/src/sdl2 -sleep 2 +sleep 1 echo "Downloading SDL2 from libsdl.org and unzipping to HOME/src/sdl2/SDL2" -wget https://www.libsdl.org/release/SDL2-2.0.10.tar.gz +wget https://www.libsdl.org/release/SDL2-2.0.12.tar.gz -O sdl2.tar.gz sync -tar xzf ./SDL2*.gz +tar xzf ./sdl2.tar.gz sync -cd ./SDL2* +cd SDL2*/ echo "Configuring SDL2 library to enable KMSDRM (Xorg free rendering)" ./configure --enable-video-kmsdrm echo "Compiling modified SDL2 and installing." -make +make -j$pi sudo make install +sync +cd $origdir fi #---------------------------------------------------------------------- @@ -239,13 +266,25 @@ echo "" sm64dircur=$(ls ./Makefile) sm64dir=$(ls $HOME/src/sm64pi/sm64pc/Makefile) +if [[ $sm64dircur =~ "access" ]] +then +echo "" +sm64dircur=0; +else if [[ $sm64dircur =~ "Makefile" ]] #If current directory has a makefile then sm64dir=$sm64dircur curdir=1; #If current directory has a Makefile or is git zip fi +fi -if [[ $sm64dir =~ "Makefile" ]]; +if [[ $sm64dir =~ "access" ]] +then +echo "" +sm64dir=0; +curdir=0; +else +if [[ $sm64dir =~ "Makefile" ]] then echo "Existing Super Mario 64 PC port files found!" echo "Redownload files (fresh compile)?" @@ -254,17 +293,18 @@ then if [[ $sm64git =~ "N" ]] # Do NOT redownload, USE current directory for compile then sm64dir=1; # Don't redownload files , use current directory (has sm64 files) - curdir=1 + curdir=1; fi else #Do a fresh compile in HOME/src/sm64pi/sm64pc/ sm64dir=0; curdir=0; fi +fi #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ - +echo "" if [[ $sm64git =~ "Y" || $sm64dir == 0 || $curdir == 0 ]] #If user wants to redownload or NOT git-zip execution then echo "Step 2. Super Mario 64 PC-Port will now be downloaded from github" @@ -299,7 +339,7 @@ echo "" echo "Step 3. Compiling Super Mario 64 for the Raspberry Pi" echo "" echo "Warning: Super Mario 64 assets are required in order to compile" -if [[ $curdir ==1 ]] +if [[ $curdir == 1 ]] then echo "Assets will be extracted from "$PWD" " else @@ -308,7 +348,7 @@ fi if [[ $curdir == 1 ]] then -sm64z64=$(find ./* | grep baserom) #See if current directory is prepped +sm64z64=$(find ./* -maxdepth 1 | grep baserom) #See if current directory is prepped else sm64z64=$(find $HOME/src/sm64pi/sm64pc/* | grep baserom) #see if fresh compile directory is prepped fi @@ -358,7 +398,7 @@ echo "At least 300MB of free storage AND RAM is recommended" echo "" make clean sync -make TARGET_RPI=1 +make -j$pi TARGET_RPI=1 sync @@ -367,7 +407,7 @@ sync if [[ $curdir == 1 ]] then -sm64done=$(find ./build/*/* | grep .arm) +sm64done=$(find $PWD/build/*/* | grep .arm) else sm64done=$(find $HOME/src/sm64pi/sm64pc/build/*/* | grep .arm) fi @@ -380,7 +420,7 @@ echo "You may find it in" if [[ $curdir == 1 ]] then -$sm64loc=$(ls ./build/*pc/*.arm) +$sm64loc=$(ls $PWD/build/*pc/*.arm) else $sm64loc=$(ls $HOME/src/sm64pi/sm64pc/build/*pc/*.arm) fi diff --git a/src/audio/external.c b/src/audio/external.c index a059c0b5a..bd181170c 100644 --- a/src/audio/external.c +++ b/src/audio/external.c @@ -1622,8 +1622,6 @@ void func_8031F96C(u8 player) { } } -#ifdef NON_MATCHING - void process_level_music_dynamics(void) { s32 conditionBits; // s0 u32 tempBits; // v1 @@ -1758,9 +1756,6 @@ void process_level_music_dynamics(void) { } } -#else -GLOBAL_ASM("asm/non_matchings/process_level_music_dynamics.s") -#endif void unused_8031FED0(u8 player, u32 bits, s8 arg2) { u8 i; diff --git a/src/audio/seqplayer.c b/src/audio/seqplayer.c index 7e66a220c..d31cace0e 100644 --- a/src/audio/seqplayer.c +++ b/src/audio/seqplayer.c @@ -378,7 +378,6 @@ u16 m64_read_compressed_u16(struct M64ScriptState *state) { return ret; } -#ifdef NON_MATCHING void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) { struct SequencePlayer *seqPlayer; // sp5C, t4 struct SequenceChannel *seqChannel; // sp58, t5 @@ -1046,14 +1045,6 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) { } } -#elif defined(VERSION_EU) -GLOBAL_ASM("asm/non_matchings/eu/audio/seq_channel_layer_process_script.s") -#elif defined(VERSION_JP) -GLOBAL_ASM("asm/non_matchings/seq_channel_layer_process_script_jp.s") -#else -GLOBAL_ASM("asm/non_matchings/seq_channel_layer_process_script_us.s") -#endif - u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut, struct AdsrSettings *adsr) { @@ -1141,7 +1132,6 @@ void sequence_channel_set_volume(struct SequenceChannel *seqChannel, u8 volume) seqChannel->volume = FLOAT_CAST(volume) / US_FLOAT(127.0); } -#ifdef NON_MATCHING void sequence_channel_process_script(struct SequenceChannel *seqChannel) { u16 sp5A; s8 value; // sp53 @@ -1678,14 +1668,6 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { } } -#elif defined(VERSION_EU) -GLOBAL_ASM("asm/non_matchings/eu/audio/sequence_channel_process_script.s") -#elif defined(VERSION_JP) -GLOBAL_ASM("asm/non_matchings/sequence_channel_process_script_jp.s") -#else -GLOBAL_ASM("asm/non_matchings/sequence_channel_process_script_us.s") -#endif - void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) { u8 cmd; u8 loBits; diff --git a/tools/Makefile b/tools/Makefile index 28ff49bff..ff0084a4f 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -5,7 +5,7 @@ endif CC := gcc CFLAGS := -Llib -Iinclude -I../include -I . -Wall -Wextra -Wno-unused-parameter $(OSX_BUILD) -pedantic -std=c99 -O3 -s -PROGRAMS := n64graphics n64graphics_ci mio0 n64cksum textconv patch_libultra_math iplfontutil aifc_decode aiff_extract_codebook vadpcm_enc tabledesign extract_data_for_mio skyconv +PROGRAMS := n64graphics n64graphics_ci mio0 textconv patch_libultra_math iplfontutil aifc_decode aiff_extract_codebook vadpcm_enc tabledesign extract_data_for_mio skyconv n64graphics_SOURCES := n64graphics.c utils.c n64graphics_CFLAGS := -DN64GRAPHICS_STANDALONE @@ -16,8 +16,6 @@ n64graphics_ci_CFLAGS := -O2 # 3s faster compile time mio0_SOURCES := libmio0.c mio0_CFLAGS := -DMIO0_STANDALONE -n64cksum_SOURCES := n64cksum.c libmio0.c libsm64.c utils.c - textconv_SOURCES := textconv.c utf8.c hashtable.c patch_libultra_math_SOURCES := patch_libultra_math.c diff --git a/tools/n64cksum.c b/tools/n64cksum.c deleted file mode 100644 index f377f9a30..000000000 --- a/tools/n64cksum.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -#include "libsm64.h" -#include "utils.h" - -#define N64CKSUM_VERSION "0.1" - -static void print_usage(void) -{ - ERROR("Usage: n64cksum ROM [ROM_OUT]\n" - "\n" - "n64cksum v" N64CKSUM_VERSION ": N64 ROM checksum calculator\n" - "\n" - "File arguments:\n" - " ROM input ROM file\n" - " ROM_OUT output ROM file (default: overwrites input ROM)\n"); -} - -int main(int argc, char *argv[]) -{ - unsigned char *rom_data; - char *file_in; - char *file_out; - long length; - long write_length; - if (argc < 2) { - print_usage(); - return EXIT_FAILURE; - } - - file_in = argv[1]; - if (argc > 2) { - file_out = argv[2]; - } else { - file_out = argv[1]; - } - - length = read_file(file_in, &rom_data); - if (length < 0) { - ERROR("Error reading input file \"%s\"\n", file_in); - return EXIT_FAILURE; - } - - sm64_update_checksums(rom_data); - - write_length = write_file(file_out, rom_data, length); - - free(rom_data); - - if (write_length != length) { - ERROR("Error writing to output file \"%s\"\n", file_out); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -}