Skip to content

Commit

Permalink
Expose mute channel functionality to WASM build (#57)
Browse files Browse the repository at this point in the history
* Remove unsupported flag

Update CMakeList to remove unsupported flag --memory-init-file

* Add functionality for GB Studio

Add a GBSTUDIO compile flag, that exposes the following functionality:

* Set audio channel mute
* Functions exposes with the RGBDS_LIVE flag
  • Loading branch information
pau-tomas authored Jun 4, 2024
1 parent 1e67a75 commit 38f2c2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
option(WERROR "Build with warnings as errors" OFF)
option(WASM "Build for WebAssembly" OFF)
option(RGBDS_LIVE "Build for rgbds-live (Wasm only)" OFF)
option(GBSTUDIO "Build for GB Studio (Wasm only. Sets rgbds-live.)" OFF)

if (MSVC)
add_definitions(-W3 -D_CRT_SECURE_NO_WARNINGS)
Expand Down Expand Up @@ -152,8 +153,12 @@ else (EMSCRIPTEN)
target_compile_definitions(binjgb PUBLIC RGBDS_LIVE)
endif ()

if (GBSTUDIO)
# If GBSTUDIO is set, set RGBDS_LIVE too
target_compile_definitions(binjgb PUBLIC GBSTUDIO RGBDS_LIVE)
endif ()

set(LINK_FLAGS
--memory-init-file 0
-s EXPORTED_FUNCTIONS=\"@${EXPORTED_JSON}\"
-s MALLOC=emmalloc
-s ASSERTIONS=0
Expand Down
3 changes: 2 additions & 1 deletion src/emscripten/exported.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
"_emulator_get_wram_ptr",
"_emulator_get_hram_ptr",
"_emulator_read_mem",
"_emulator_write_mem"
"_emulator_write_mem",
"_set_audio_channel_mute"
]
16 changes: 16 additions & 0 deletions src/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -5258,3 +5258,19 @@ void emulator_render_vram(Emulator* e, u32* buffer) {}
void emulator_render_background(Emulator* e, u32* buffer, int type) {}

#endif

#ifdef GBSTUDIO
Bool set_audio_channel_mute(Emulator *e, int channel, Bool muted) {
EmulatorConfig emu_config = emulator_get_config(e);
emu_config.disable_sound[channel] = muted;
emulator_set_config(e, &emu_config);
return emu_config.disable_sound[channel];
}

#else // !GBSTUDIO

Bool set_audio_channel_mute(Emulator *e, int channel, Bool muted) {
return FALSE;
}

#endif

0 comments on commit 38f2c2f

Please sign in to comment.