ref: 093ab2c4c0a3eab435f3d366d24cedc2e95022c2
parent: ac2d1210a30b8302c48a675124cc0c6b606f7f75
author: Snesrev <snesrev@protonmail.com>
date: Mon Oct 3 12:52:55 EDT 2022
Remove an #ifdef from main.c and make it work with TCC again
--- a/main.c
+++ b/main.c
@@ -5,8 +5,8 @@
#include <stdbool.h>
#include <SDL.h>
#ifdef _WIN32
+#include "platform/win32/volume_control.h"
#include <direct.h>
-#define SYSTEM_VOLUME_MIXER_AVAILABLE
#else
#include <sys/stat.h>
#include <sys/types.h>
@@ -13,13 +13,6 @@
#include <unistd.h>
#endif
-#ifdef SYSTEM_VOLUME_MIXER_AVAILABLE
-#define VOLUME_INCREMENT 5
-#include "platform/win32/volume_control.h"
-#else
-#define VOLUME_INCREMENT (SDL_MIX_MAXVOLUME >> 4)
-#endif
-
#include "snes/ppu.h"
#include "types.h"
@@ -188,7 +181,7 @@
g_audiobuffer_end = g_audiobuffer + g_frames_per_block * g_audio_channels * sizeof(int16);
}
int n = IntMin(len, g_audiobuffer_end - g_audiobuffer_cur);
-#ifdef SYSTEM_VOLUME_MIXER_AVAILABLE
+#if SYSTEM_VOLUME_MIXER_AVAILABLE
memcpy(stream, g_audiobuffer_cur, n);
#else
// Ensure destination audio stream is empty/silence.
@@ -594,11 +587,7 @@
case kKeys_DisplayPerf: g_display_perf ^= 1; break;
case kKeys_ToggleRenderer: g_ppu_render_flags ^= kPpuRenderFlags_NewRenderer; break;
case kKeys_VolumeUp:
- HandleVolumeAdjustment(VOLUME_INCREMENT);
- break;
- case kKeys_VolumeDown:
- HandleVolumeAdjustment(-VOLUME_INCREMENT);
- break;
+ case kKeys_VolumeDown: HandleVolumeAdjustment(j == kKeys_VolumeUp ? 1 : -1); break;
default: assert(0);
}
}
@@ -636,13 +625,13 @@
}
static void HandleVolumeAdjustment(int volume_adjustment) {
-#ifdef SYSTEM_VOLUME_MIXER_AVAILABLE
+#if SYSTEM_VOLUME_MIXER_AVAILABLE
int current_volume = GetApplicationVolume();
- int new_volume = IntMin(IntMax(0, current_volume + volume_adjustment), 100);
+ int new_volume = IntMin(IntMax(0, current_volume + volume_adjustment * 5), 100);
SetApplicationVolume(new_volume);
printf("[System Volume]=%i\n", new_volume);
#else
- g_sdl_audio_mixer_volume = IntMin(IntMax(0, g_sdl_audio_mixer_volume + volume_adjustment), SDL_MIX_MAXVOLUME);
+ g_sdl_audio_mixer_volume = IntMin(IntMax(0, g_sdl_audio_mixer_volume + volume_adjustment * (SDL_MIX_MAXVOLUME >> 4)), SDL_MIX_MAXVOLUME);
printf("[SDL mixer volume]=%i\n", g_sdl_audio_mixer_volume);
#endif
}
--- a/platform/win32/volume_control.h
+++ b/platform/win32/volume_control.h
@@ -1,10 +1,14 @@
-#ifndef VOLUME_CONTROL_H
-#define VOLUME_CONTROL_H
+#ifndef ZELDA3_PLATFORM_WIN32_VOLUME_CONTROL_H_
+#define ZELDA3_PLATFORM_WIN32_VOLUME_CONTROL_H_
#include <stdbool.h>
+#ifndef SYSTEM_VOLUME_MIXER_AVAILABLE
+#define SYSTEM_VOLUME_MIXER_AVAILABLE 1
+#endif // SYSTEM_VOLUME_MIXER_AVAILABLE
+
int GetApplicationVolume();
bool SetApplicationVolume(int volume_level);
bool SetApplicationMuted(bool muted);
-#endif // VOLUME_CONTROL_H
+#endif // ZELDA3_PLATFORM_WIN32_VOLUME_CONTROL_H_
--- a/run_with_tcc.bat
+++ b/run_with_tcc.bat
@@ -38,7 +38,7 @@
echo Building with TCC...
-third_party\tcc\tcc.exe -ozelda3.exe -DHAVE_STDINT_H=1 -D_HAVE_STDINT_H=1 -I%SDL2%/include -L%SDL2%/lib/x64 -lSDL2 *.c snes/*.c
+third_party\tcc\tcc.exe -ozelda3.exe -DHAVE_STDINT_H=1 -D_HAVE_STDINT_H=1 -DSYSTEM_VOLUME_MIXER_AVAILABLE=0 -I%SDL2%/include -L%SDL2%/lib/x64 -lSDL2 *.c snes/*.c
IF ERRORLEVEL 1 goto GETOUT
copy %SDL2%\lib\x64\SDL2.dll .