diff --git a/Makefile b/Makefile index 2db2a1f..903138e 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 @@ -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) @@ -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..9be3acc 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). @@ -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. 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..b8a0578 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" @@ -41,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)); } } @@ -156,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); @@ -167,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){ @@ -196,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; } @@ -226,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; } @@ -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 +} diff --git a/test/gl20/gl20_renderer.c b/test/gl20/gl20_renderer.c index d9de645..d50da28 100644 --- a/test/gl20/gl20_renderer.c +++ b/test/gl20/gl20_renderer.c @@ -1,5 +1,9 @@ #include "gl20_renderer.h" +#ifdef __APPLE__ +#include +#endif + #include #include "../../src/libsm64.h"