From b8f67643dca74f333092ca28f2db86c9b81cabac Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 10 Jul 2018 02:00:31 -0400 Subject: [PATCH] Make DosBeep volume configurable. --- lib2ine.c | 16 ++++++++++++++++ lib2ine.h | 1 + native/doscalls.c | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib2ine.c b/lib2ine.c index 3aac15d..439a821 100644 --- a/lib2ine.c +++ b/lib2ine.c @@ -384,6 +384,17 @@ static void cfgProcessBoolString(const char *fname, const int lineno, int *outpu cfgWarn(fname, lineno, "\"%s\" is not valid for this setting. Try 1 or 0.", val); } +static void cfgProcessFloatString(const char *fname, const int lineno, float *output, const char *val) +{ + errno = 0; + const float converted = strtof(val, NULL); + if (!errno) { + *output = converted; + } else { + cfgWarn(fname, lineno, "\"%s\" is not valid for this setting. Try a number.", val); + } +} + static void cfgProcessMountPoint(const char *fname, const int lineno, const char *var, const char *val) { char letter = var[0]; @@ -426,6 +437,8 @@ static void cfgProcessSystem(const char *fname, const int lineno, const char *va cfgProcessBoolString(fname, lineno, &GLoaderState.trace_native, val); } else if (strcmp(var, "trace_events") == 0) { cfgProcessBoolString(fname, lineno, &GLoaderState.trace_events, val); + } else if (strcmp(var, "beep_volume") == 0) { + cfgProcessFloatString(fname, lineno, &GLoaderState.beep_volume, val); } else { cfgWarn(fname, lineno, "Unknown variable system.%s", var); } @@ -818,6 +831,9 @@ LX_NATIVE_CONSTRUCTOR(lib2ine) GLoaderState.registerAudioGenerator = registerAudioGenerator_lib2ine; GLoaderState.lib2ine_shutdown = lib2ine_shutdown; + // VMware emulates the PC Speaker on a sound card _really_ quietly. + GLoaderState.beep_volume = 0.05f; + cfgLoadFiles(); prepOs2Drives(); diff --git a/lib2ine.h b/lib2ine.h index c702550..09e49cd 100644 --- a/lib2ine.h +++ b/lib2ine.h @@ -299,6 +299,7 @@ typedef struct LxLoaderState char *current_dir[26]; // current directory, per-disk, A: through Z: ... NULL if unmounted. int current_disk; // 1==A:\\, 2==B:\\, etc. uint32 diskmap; // 1<<0==drive A mounted, 1<<1==drive B mounted, etc. + float beep_volume; uint8 main_tib_selector; uint32 mainstacksize; uint16 original_cs; diff --git a/native/doscalls.c b/native/doscalls.c index 8c3b176..4115b6f 100644 --- a/native/doscalls.c +++ b/native/doscalls.c @@ -3151,6 +3151,7 @@ static DosBeepGeneratorInfo dos_beep_info; static int DosBeepGenerator(void *userdata, float *stream, int samples, int freq) { + const float beep_volume = GLoaderState.beep_volume; DosBeepGeneratorInfo *info = &dos_beep_info; assert(userdata == &dos_beep_info); @@ -3177,7 +3178,7 @@ static int DosBeepGenerator(void *userdata, float *stream, int samples, int freq } } else { // still generating the current piece of the square wave, mix it into the stream. // VMware emulates the PC Speaker on a sound card _really_ quietly. - const float val = info->positive ? 0.05f : -0.05f; + const float val = info->positive ? beep_volume : -beep_volume; int total = info->square_remaining; if (info->samples_remaining < total) total = info->samples_remaining; if (samples < total) total = samples;