diff -u frotz-2.42/Makefile frotz-2.42nbsd/Makefile --- frotz-2.42/Makefile Sat Mar 9 16:24:16 2002 +++ frotz-2.42nbsd/Makefile Fri Jun 28 17:17:13 2002 @@ -36,17 +36,24 @@ # Uncomment this if you have an OSS soundcard driver and want classical # Infocom sound support. Currently this works only for Linux. # -#SOUND_DEFS = -DOSS_SOUND +SOUND_DEFS = -DOSS_SOUND # Also uncomment this if you want sound through the OSS driver. # -#SOUND_LIB = -lossaudio +SOUND_LIB = -lossaudio + +# Define your sound device +# This should probably be a command-line/config-file option. +# +SOUND_DEV = /dev/sound +#SOUND_DEV = /dev/dsp +#SOUND_DEV = /dev/audio # This should point to the location of your curses.h or ncurses.h include # file if your compiler doesn't know about it. # -INCL = -I/usr/local/include -#INCL = -I/usr/pkg/include +#INCL = -I/usr/local/include +INCL = -I/usr/pkg/include #INCL = -I/usr/freeware/include #INCL = -I/5usr/include #INCL = @@ -55,8 +62,8 @@ # linking with. Usually, this isn't necessary if /etc/ld.so.conf is set # up correctly. # -LIB = -L/usr/local/lib -#LIB = -L/usr/pkg/lib +#LIB = -L/usr/local/lib +LIB = -L/usr/pkg/lib #LIB = -L/usr/freeware/lib #LIB = -L/5usr/lib #LIB = @@ -86,7 +93,7 @@ # Nothing under this line should need to be changed. ##################################################### -VERSION = 2.42 +VERSION = 2.42nbsd BINNAME = frotz @@ -103,7 +110,7 @@ ux_audio_none.o ux_audio_oss.o OPT_DEFS = -DCONFIG_DIR="\"$(CONFIG_DIR)\"" $(CURSES_DEF) \ - -DVERSION="\"$(VERSION)\"" + -DVERSION="\"$(VERSION)\"" -DSOUND_DEV="\"$(SOUND_DEV)\"" COMP_DEFS = $(OPT_DEFS) $(COLOR_DEFS) $(SOUND_DEFS) $(SOUNDCARD) \ Common subdirectories: frotz-2.42/bugtest and frotz-2.42nbsd/bugtest Only in frotz-2.42nbsd: frotz Only in frotz-2.42nbsd: soundcard.h diff -u frotz-2.42/ux_audio_oss.c frotz-2.42nbsd/ux_audio_oss.c --- frotz-2.42/ux_audio_oss.c Tue Nov 21 22:31:17 2000 +++ frotz-2.42nbsd/ux_audio_oss.c Fri Jun 28 17:13:25 2002 @@ -85,13 +85,38 @@ } static void play_sound(int volume, int repeats) { - struct sigaction sa; + struct sigaction sa; + int format = AFMT_U8; + int channels = 1; - dsp_fd = open("/dev/dsp", O_WRONLY); + dsp_fd = open(SOUND_DEV, O_WRONLY); if (dsp_fd < 0) { - perror("/dev/dsp"); + perror(SOUND_DEV); _exit(1); } + + /* This section of code fixes the nasty problem of samples + * being played with pops and scratches when used with a + * non-Linux system implementing OSS sound. + */ + if (ioctl(dsp_fd, SNDCTL_DSP_SETFMT, &format) == -1) { + perror(SOUND_DEV); + exit(1); + } + if (format != AFMT_U8) { + fprintf(stderr, "bad sound format\n"); + exit(1); + } + if (ioctl(dsp_fd, SNDCTL_DSP_CHANNELS, &channels) == -1) { + perror(SOUND_DEV); + exit(1); + } + if (channels != 1) { + fprintf(stderr, "bad channels\n"); + exit(1); + } + /* End sound fix from Torbjorn Andersson */ + ioctl(dsp_fd, SNDCTL_DSP_SPEED, &sample_rate); if (volume != 255) { @@ -177,6 +202,7 @@ char *filename; const char *basename, *dotpos; int namelen; + int read_length; if (sound_buffer != NULL && current_num == number) return; @@ -211,27 +237,38 @@ fgetc(samples); fgetc(samples); sound_length = fgetc(samples) << 8; sound_length |= fgetc(samples); + sound_buffer = NULL; - sound_buffer = malloc(sound_length); - if (! sound_buffer) { - perror("malloc"); - return; - } - - if (sound_length < 0 || - fread(sound_buffer, 1, sound_length, samples) < sound_length) { - if (feof(samples)) - fprintf(stderr, "%s: premature EOF\n", filename); - else { - errno = ferror(samples); - perror(filename); + if (sound_length > 0) { + sound_buffer = malloc(sound_length); + if (!sound_buffer) { + perror("malloc"); + return; + } + read_length = fread(sound_buffer, 1, sound_length, samples); + if (read_length < sound_length) { + if (feof(samples)) { + /* + * One of the Sherlock samples trigger this for me, so let's make it + * a non-fatal error. + */ + sound_buffer = realloc(sound_buffer, read_length); + if (! sound_buffer) { + perror("realloc"); + return; + } + sound_length = read_length; + } else { + errno = ferror(samples); + perror(filename); + free(sound_buffer); + sound_buffer = NULL; + } } - free(sound_buffer); - sound_buffer = NULL; } - current_num = number; }/* os_prepare_sample */ + static void sigchld_handler(int signal) { int status; diff -u frotz-2.42/ux_init.c frotz-2.42nbsd/ux_init.c --- frotz-2.42/ux_init.c Tue Feb 19 20:26:21 2002 +++ frotz-2.42nbsd/ux_init.c Fri Jun 28 17:16:42 2002 @@ -51,6 +51,7 @@ #define INFORMATION "\ - An interpreter for all Infocom and other Z-Machine games.\n\ Complies with standard 1.0 of Graham Nelson's specification.\n\ +Special NetBSD version. Patched so that sound works with the OSS driver.\n\ \n\ Syntax: frotz [options] story-file\n\ \n\