Skip to content

Commit 38f2c2f

Browse files
authored
Expose mute channel functionality to WASM build (#57)
* 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
1 parent 1e67a75 commit 38f2c2f

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

CMakeLists.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
99
option(WERROR "Build with warnings as errors" OFF)
1010
option(WASM "Build for WebAssembly" OFF)
1111
option(RGBDS_LIVE "Build for rgbds-live (Wasm only)" OFF)
12+
option(GBSTUDIO "Build for GB Studio (Wasm only. Sets rgbds-live.)" OFF)
1213

1314
if (MSVC)
1415
add_definitions(-W3 -D_CRT_SECURE_NO_WARNINGS)
@@ -152,8 +153,12 @@ else (EMSCRIPTEN)
152153
target_compile_definitions(binjgb PUBLIC RGBDS_LIVE)
153154
endif ()
154155

156+
if (GBSTUDIO)
157+
# If GBSTUDIO is set, set RGBDS_LIVE too
158+
target_compile_definitions(binjgb PUBLIC GBSTUDIO RGBDS_LIVE)
159+
endif ()
160+
155161
set(LINK_FLAGS
156-
--memory-init-file 0
157162
-s EXPORTED_FUNCTIONS=\"@${EXPORTED_JSON}\"
158163
-s MALLOC=emmalloc
159164
-s ASSERTIONS=0

src/emscripten/exported.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@
5959
"_emulator_get_wram_ptr",
6060
"_emulator_get_hram_ptr",
6161
"_emulator_read_mem",
62-
"_emulator_write_mem"
62+
"_emulator_write_mem",
63+
"_set_audio_channel_mute"
6364
]

src/emulator.c

+16
Original file line numberDiff line numberDiff line change
@@ -5258,3 +5258,19 @@ void emulator_render_vram(Emulator* e, u32* buffer) {}
52585258
void emulator_render_background(Emulator* e, u32* buffer, int type) {}
52595259

52605260
#endif
5261+
5262+
#ifdef GBSTUDIO
5263+
Bool set_audio_channel_mute(Emulator *e, int channel, Bool muted) {
5264+
EmulatorConfig emu_config = emulator_get_config(e);
5265+
emu_config.disable_sound[channel] = muted;
5266+
emulator_set_config(e, &emu_config);
5267+
return emu_config.disable_sound[channel];
5268+
}
5269+
5270+
#else // !GBSTUDIO
5271+
5272+
Bool set_audio_channel_mute(Emulator *e, int channel, Bool muted) {
5273+
return FALSE;
5274+
}
5275+
5276+
#endif

0 commit comments

Comments
 (0)