From 62c247f432539c475fabd391159afa9815f8d440 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 18 Jun 2024 18:21:51 -0400 Subject: [PATCH 1/7] Makefile: Fix cc command not having include path Fixes one set of build errors on macOS (clang vs. gcc difference?) --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2db2a1f..c97de5e 100644 --- a/Makefile +++ b/Makefile @@ -45,11 +45,11 @@ src/decomp/mario/geo.inc.c: ./import-mario-geo.py ./import-mario-geo.py $(BUILD_DIR)/%.o: %.c $(IMPORTED) - @$(CC) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $< + @$(CC) $(CFLAGS) -I src/decomp/include -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $< $(CC) -c $(CFLAGS) -I src/decomp/include -o $@ $< $(BUILD_DIR)/%.o: %.cpp $(IMPORTED) - @$(CXX) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $< + @$(CXX) $(CFLAGS) -I src/decomp/include -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $< $(CXX) -c $(CFLAGS) -I src/decomp/include -o $@ $< $(LIB_FILE): $(O_FILES) From 6e1c2cfedc4b63d8f2ea0a7bad72735f63d12d97 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 18 Jun 2024 18:31:27 -0400 Subject: [PATCH 2/7] Fixup some includes for macOS --- src/decomp/game/mario.c | 2 +- src/decomp/game/sound_init.c | 1 + src/decomp/include/PR/os_libc.h | 5 +++++ src/decomp/tools/convUtils.c | 3 ++- src/load_audio_data.c | 5 ++++- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/decomp/game/mario.c b/src/decomp/game/mario.c index d1b2871..250215f 100644 --- a/src/decomp/game/mario.c +++ b/src/decomp/game/mario.c @@ -35,7 +35,7 @@ // #include "object_list_processor.h" // #include "print.h" #include "save_file.h" -// #include "sound_init.h" +#include "sound_init.h" // #include "thread6.h" #include "../../load_anim_data.h" diff --git a/src/decomp/game/sound_init.c b/src/decomp/game/sound_init.c index fe62b7f..985fac8 100644 --- a/src/decomp/game/sound_init.c +++ b/src/decomp/game/sound_init.c @@ -14,6 +14,7 @@ #include #include #include "sound_init.h" +#include "../../play_sound.h" //#include "rumble_init.h" #define MUSIC_NONE 0xFFFF diff --git a/src/decomp/include/PR/os_libc.h b/src/decomp/include/PR/os_libc.h index 94111c0..444ec17 100644 --- a/src/decomp/include/PR/os_libc.h +++ b/src/decomp/include/PR/os_libc.h @@ -3,8 +3,13 @@ #include "ultratypes.h" +// These are defined in macOS (BSD?), so we want to def them out. +#ifndef __APPLE__ + // Old deprecated functions from strings.h, replaced by memcpy/memset. extern void bcopy(const void *, void *, size_t); extern void bzero(void *, size_t); +#endif + #endif /* !_OS_LIBC_H_ */ diff --git a/src/decomp/tools/convUtils.c b/src/decomp/tools/convUtils.c index fa67888..959c923 100644 --- a/src/decomp/tools/convUtils.c +++ b/src/decomp/tools/convUtils.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "convUtils.h" #include "convTypes.h" @@ -371,4 +372,4 @@ struct CTL* parse_ctl_data(unsigned char* ctlData, uintptr_t* pos){ // return ctl; -} \ No newline at end of file +} diff --git a/src/load_audio_data.c b/src/load_audio_data.c index 3fc5ef5..ef88a7b 100644 --- a/src/load_audio_data.c +++ b/src/load_audio_data.c @@ -1,9 +1,12 @@ #include "load_audio_data.h" #include "decomp/tools/convUtils.h" +#include "decomp/audio/external.h" #include "decomp/audio/load.h" #include "decomp/audio/load_dat.h" +#include + bool g_is_audio_initialized = false; extern void load_audio_banks( const uint8_t *rom ) { @@ -25,4 +28,4 @@ extern void load_audio_banks( const uint8_t *rom ) { sound_reset( 0 ); g_is_audio_initialized = true; -} \ No newline at end of file +} From d5d0b5409e890550318da3d12665e01068d6ad15 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 18 Jun 2024 18:31:38 -0400 Subject: [PATCH 3/7] Makefile: Fixup DUMMY shell assignment for macOS make --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c97de5e..f177c96 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ ifeq ($(OS),Windows_NT) TEST_FILE := $(DIST_DIR)/run-test.exe endif -DUMMY != mkdir -p $(ALL_DIRS) build/test build/test/gl33core build/test/gl20 src/decomp/mario $(DIST_DIR)/include +DUMMY := $(shell mkdir -p $(ALL_DIRS) build/test build/test/gl33core build/test/gl20 src/decomp/mario $(DIST_DIR)/include) $(filter-out src/decomp/mario/geo.inc.c,$(IMPORTED)): src/decomp/mario/geo.inc.c From fd247e625aa60f35bcea0eddd258916a62608ed4 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 18 Jun 2024 18:42:25 -0400 Subject: [PATCH 4/7] Fix casts so `emmake make CC=emcc` works! --- src/decomp/tools/convUtils.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/decomp/tools/convUtils.c b/src/decomp/tools/convUtils.c index 959c923..b8a0578 100644 --- a/src/decomp/tools/convUtils.c +++ b/src/decomp/tools/convUtils.c @@ -42,18 +42,18 @@ struct seqFile* parse_seqfile(unsigned char* seq){ /* Read SeqFile data */ for (int i = 0; i < bankCount; i++){ uintptr_t start = pos; struct CTL* ptr = parse_ctl_data(seq+(seqFile->seqArray[i].offset), &pos); - seqFile->seqArray[i].offset = ptr; + seqFile->seqArray[i].offset = (uintptr_t)ptr; seqFile->seqArray[i].len = (unsigned int)(pos - start); } }else if (revision == TYPE_TBL){ // TBL file, contains raw audio data for (int i = 0; i < bankCount; i++){ - seqFile->seqArray[i].offset = seq+(seqFile->seqArray[i].offset); + seqFile->seqArray[i].offset = (uintptr_t)(seq+(seqFile->seqArray[i].offset)); } }else if (revision == TYPE_SEQ){ // SEQ file, contains music files (*.m64) for (int i = 0; i < bankCount; i++){ - seqFile->seqArray[i].offset = seq+(seqFile->seqArray[i].offset); + seqFile->seqArray[i].offset = (uintptr_t)(seq+(seqFile->seqArray[i].offset)); } } @@ -157,8 +157,8 @@ struct CSample* parse_sample(unsigned char* sample,unsigned char* ctl, uintptr_t *pos = ALIGN16(*pos); samp->zero=read_u32_be(sample); samp->addr=read_u32_be(sample+4); - samp->loop=read_u32_be(sample+8);// loop address - samp->book=read_u32_be(sample+12);// book address + samp->loop=(struct CLoop*)read_u32_be(sample+8);// loop address + samp->book=(struct CBook*)read_u32_be(sample+12);// book address samp->sample_size=read_u32_be(sample+16); samp->book=parse_book(ctl+((uintptr_t)samp->book), pos); @@ -168,7 +168,7 @@ struct CSample* parse_sample(unsigned char* sample,unsigned char* ctl, uintptr_t struct CSound* parse_sound(unsigned char* sound,unsigned char* ctl, uintptr_t* pos, uintptr_t sndPos, struct SampleList* samples){ struct CSound* snd = (struct CSound*)(sndPos); - snd->sample_addr=read_u32_be(sound); + snd->sample_addr=(struct CSample*)read_u32_be(sound); snd->tuning = (float)read_f32_be(sound+4); // if sample_addr is 0 then the sound is null if (snd->sample_addr!=0){ @@ -197,8 +197,8 @@ struct CDrum* parse_drum(unsigned char* drum,unsigned char* ctl, uintptr_t* pos, drumData->pan = drum[1]; drumData->loaded = drum[2]; drumData->pad = drum[3]; - drumData->snd=*parse_sound(drum+4,ctl, pos, &drumData->snd, samples); - drumData->env_addr=read_u32_be(drum+12); + drumData->snd=*parse_sound(drum+4,ctl, pos, (uintptr_t)&drumData->snd, samples); + drumData->env_addr=(struct CEnvelope*)read_u32_be(drum+12); return drumData; } @@ -227,10 +227,10 @@ struct CInstrument* parse_instrument(unsigned char* instrument,unsigned char* ct inst->normal_range_lo = instrument[1]; inst->normal_range_hi = instrument[2]; inst->release_rate = instrument[3]; - inst->env_addr=read_u32_be(instrument+4); - inst->sound_lo=*parse_sound(instrument+8,ctl, pos, &(inst->sound_lo), samples); - inst->sound_med=*parse_sound(instrument+16,ctl, pos, &(inst->sound_med), samples); - inst->sound_hi=*parse_sound(instrument+24,ctl, pos, &(inst->sound_hi), samples); + inst->env_addr=(struct CEnvelope*)read_u32_be(instrument+4); + inst->sound_lo=*parse_sound(instrument+8,ctl, pos, (uintptr_t)&(inst->sound_lo), samples); + inst->sound_med=*parse_sound(instrument+16,ctl, pos, (uintptr_t)&(inst->sound_med), samples); + inst->sound_hi=*parse_sound(instrument+24,ctl, pos, (uintptr_t)&(inst->sound_hi), samples); return inst; } From 7790f7a444cd9a6c62745bcfc8566e5ba794b16d Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 18 Jun 2024 22:18:49 -0400 Subject: [PATCH 5/7] Fix test build on Mac --- Makefile | 2 ++ README.md | 2 +- test/gl20/gl20_renderer.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f177c96..903138e 100644 --- a/Makefile +++ b/Makefile @@ -70,6 +70,8 @@ $(BUILD_DIR)/test/%.o: test/%.c $(TEST_FILE): $(LIB_FILE) $(TEST_OBJS) ifeq ($(OS),Windows_NT) $(CC) -o $@ $(TEST_OBJS) $(LIB_FILE) -lglew32 -lopengl32 -lSDL2 -lSDL2main -lm +else ifeq ($(shell uname -s),Darwin) + $(CC) -o $@ $(TEST_OBJS) $(LIB_FILE) -framework OpenGL -lGLEW -lSDL2 -lSDL2main -lm -lpthread else $(CC) -o $@ $(TEST_OBJS) $(LIB_FILE) -lGLEW -lGL -lSDL2 -lSDL2main -lm -lpthread endif diff --git a/README.md b/README.md index 2aa3865..312d4f4 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ project under the `test` directory as well, demonstrating usage of the library. - [Godot add-on](https://github.com/Brawmario/libsm64-godot) - [Game Maker 8 extension](https://github.com/headshot2017/libsm64-gm8) -## Building on Linux +## Building on Mac and Linux - Ensure python3 is installed. - Ensure the SDL2 and GLEW libraries are installed if you're building the test program (on Ubuntu: libsdl2-dev, libglew-dev). diff --git a/test/gl20/gl20_renderer.c b/test/gl20/gl20_renderer.c index d9de645..3838aa9 100644 --- a/test/gl20/gl20_renderer.c +++ b/test/gl20/gl20_renderer.c @@ -1,5 +1,6 @@ #include "gl20_renderer.h" +#include #include #include "../../src/libsm64.h" From 4e9ca300c64c29a5a96a553c967e6948038ece7a Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Wed, 19 Jun 2024 13:29:33 -0400 Subject: [PATCH 6/7] Fix test build on Linux --- test/gl20/gl20_renderer.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/gl20/gl20_renderer.c b/test/gl20/gl20_renderer.c index 3838aa9..d50da28 100644 --- a/test/gl20/gl20_renderer.c +++ b/test/gl20/gl20_renderer.c @@ -1,6 +1,9 @@ #include "gl20_renderer.h" +#ifdef __APPLE__ #include +#endif + #include #include "../../src/libsm64.h" From 52868a82fa240f18d10b4a507fd51351d184fcbe Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Wed, 19 Jun 2024 13:33:17 -0400 Subject: [PATCH 7/7] Add Emscripten instructions --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 312d4f4..9be3acc 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,17 @@ project under the `test` directory as well, demonstrating usage of the library. - Run `make` to build - To run the test program you'll need a SM64 US ROM in the root of the repository with the name `baserom.us.z64`. +## Building for Emscripten (Web) (WIP) + +Run `emmake make CC=emcc`. + +If you want libsm64 standalone to call from JS (may not be that +useful?), then run `emcc dist/libsm64.so -o libsm64.js` afterward to +emit `libsm64.wasm` and `libsm64.js`. + +Otherwise, `dist/libsm64.so` should be a compiled WebAssembly object +that you can link into your own C project. + ## Make targets (all platforms) - `make lib`: (Default) Build the `dist` directory, containing the shared object or DLL and public-facing header.