From 833837adf252b467d2e653cdd02e70a846450d15 Mon Sep 17 00:00:00 2001 From: indigoparadox Date: Mon, 12 Aug 2024 22:50:49 -0400 Subject: [PATCH] Shoring up issues with sound in various places. Starting NDS sound. --- api/dosbios/retapid.h | 11 ++- api/dosbios/retapif.h | 2 +- api/nds/retapid.h | 1 + api/nds/retapif.h | 15 ++- make/Makece.inc | 2 +- src/retroflt.h | 214 +++++++++++++++++++++--------------------- 6 files changed, 129 insertions(+), 116 deletions(-) diff --git a/api/dosbios/retapid.h b/api/dosbios/retapid.h index c517ae80..e13dcd3c 100644 --- a/api/dosbios/retapid.h +++ b/api/dosbios/retapid.h @@ -196,8 +196,13 @@ struct RETROFLAT_PLATFORM { #ifndef NO_RETROSND -# define RETROSND_MPU_FLAG_OUTPUT 0x40 -# define RETROSND_MPU_TIMEOUT 30 +#define RETROSND_PC_BIOS_SPKR 0x01 +#define RETROSND_PC_BIOS_MPU 0x02 +#define RETROSND_PC_BIOS_GUS 0x04 +#define RETROSND_PC_BIOS_ADLIB 0x08 + +#define RETROSND_MPU_FLAG_OUTPUT 0x40 +#define RETROSND_MPU_TIMEOUT 30 struct RETROFLAT_SOUND { uint8_t flags; @@ -205,7 +210,7 @@ struct RETROFLAT_SOUND { uint8_t io_timeout; uint8_t driver; struct RETROSND_ADLIB_VOICE* adlib_voices; - char sf_bank_filename[SF_BANK_FILENAME_SZ_MAX + 1]; + char sf_bank_filename[RETROFLAT_PATH_MAX + 1]; }; #endif /* !NO_RETROSND */ diff --git a/api/dosbios/retapif.h b/api/dosbios/retapif.h index f54d17e9..07eb7016 100644 --- a/api/dosbios/retapif.h +++ b/api/dosbios/retapif.h @@ -968,7 +968,7 @@ MERROR_RETVAL retrosnd_init( struct RETROFLAT_ARGS* args ) { cleanup: - return retval;' + return retval; } /* === */ diff --git a/api/nds/retapid.h b/api/nds/retapid.h index 3588d7a1..1a1ae236 100644 --- a/api/nds/retapid.h +++ b/api/nds/retapid.h @@ -261,6 +261,7 @@ uint8_t retroflat_viewport_focus( struct RETROFLAT_SOUND { uint8_t flags; + uint8_t channels[RETROSND_CHANNEL_CT]; }; #endif /* !NO_RETROSND */ diff --git a/api/nds/retapif.h b/api/nds/retapif.h index f463eb58..ce34cc2d 100644 --- a/api/nds/retapif.h +++ b/api/nds/retapif.h @@ -776,7 +776,9 @@ MERROR_RETVAL retrosnd_init( struct RETROFLAT_ARGS* args ) { assert( 2 <= sizeof( MERROR_RETVAL ) ); -# pragma message( "warning: init not implemented" ) + soundEnable(); + + g_retroflat_state->sound.flags |= RETROSND_FLAG_INIT; return retval; } @@ -826,7 +828,11 @@ void retrosnd_midi_note_on( uint8_t channel, uint8_t pitch, uint8_t vel ) { return; } -# pragma message( "warning: note_on not implemented" ) + g_retroflat_state->sound.channels[channel] = + soundPlayPSG( 100, 2620, 32, 64 ); + + debug_printf( 1, "playing channel %u on DS channel: %u", + channel, g_retroflat_state->sound.channels[channel] ); } @@ -841,7 +847,7 @@ void retrosnd_midi_note_off( uint8_t channel, uint8_t pitch, uint8_t vel ) { return; } -# pragma message( "warning: note_off not implemented" ) + soundKill( g_retroflat_state->sound.channels[channel] ); } @@ -873,7 +879,8 @@ void retrosnd_shutdown() { return; } -# pragma message( "warning: shutdown not implemented" ) + soundDisable(); + } #endif /* !NO_RETROSND */ diff --git a/make/Makece.inc b/make/Makece.inc index 4c7037d1..80806712 100644 --- a/make/Makece.inc +++ b/make/Makece.inc @@ -15,7 +15,7 @@ OBJDIR_CECL_WINCE_MIPS := obj/cecl-wince-mips OBJDIR_CECL_WINCE_X86 := obj/cecl-wince-x86 -CFLAGS_CECL_WINCE += /nologo /GX- /D "_WIN32_WCE" /D "UNICODE" /I "$(WCE20DEV)/INCLUDE" /I "$(MAUG_ROOT)/api/win" /D "RETROFLAT_OS_WIN" /D "RETROFLAT_API_WINCE" /D "MAUG_ANCIENT_C" /D "RETROFLAT_NO_CLI" /D "RETROFLAT_NO_STRING" /D "MAUG_NO_STDLIB" /D "MAUG_WCHAR" $(INCLUDES_VS) +CFLAGS_CECL_WINCE += /nologo /GX- /D "_WIN32_WCE" /D "UNICODE" /I "$(WCE20DEV)/INCLUDE" /I "$(MAUG_ROOT)/api/win" /D "RETROFLAT_OS_WIN" /D "RETROFLAT_API_WINCE" /D "MAUG_ANCIENT_C" /D "RETROFLAT_NO_CLI" /D "RETROFLAT_NO_STRING" /D "MAUG_NO_STDLIB" /D "MAUG_WCHAR" /D "NO_RETROSND" $(INCLUDES_VS) LDFLAGS_CECL_WINCE += commctrl.lib coredll.lib /nologo /subsystem:windowsce diff --git a/src/retroflt.h b/src/retroflt.h index b5a6bc9d..de057341 100644 --- a/src/retroflt.h +++ b/src/retroflt.h @@ -875,6 +875,113 @@ struct RETROFLAT_GLTEX { }; #endif /* RETROFLAT_OPENGL */ +struct RETROFLAT_ARGS; + +#ifndef NO_RETROSND + +/** + * \addtogroup maug_retrosnd RetroSound API + * \brief Abstraction layer header for sound on retro systems. + * \{ + * + * \file retrosnd.h + * \brief Abstraction layer header for sound on retro systems. + * + * RetroSound is a compatibility layer for making sound + * on various platforms, including Windows, MS-DOS or Linux. + * + * To use, define RETROSND_C before including this header from your main.c. + * + * You may include this header in other .c files, as well, but RETROSND_C + * should \b ONLY be declared \b ONCE in the entire program. + * + * It is *highly* advised to use this in conjunction with retroflt.h. + * + * maug.h should also be included before this header. + * + * Special thanks to: "Programming the Adlib/Sound Blaster FM Music Chips" + * by Jeffrey S. Lee (https://bochs.sourceforge.io/techspec/adlib_sb.txt) + * and "The Gravis Ultrasound" by neuraldk + * (http://neuraldk.org/document.php?gus) for DOS platform-specific stuff. + * + * And the MPU-401 interface for being so darn simple! + */ + +#ifndef RETROSND_TRACE_LVL +# define RETROSND_TRACE_LVL 0 +#endif /* !RETROSND_TRACE_LVL */ + +#ifndef RETROSND_REG_TRACE_LVL +# define RETROSND_REG_TRACE_LVL 0 +#endif /* !RETROSND_REG_TRACE_LVL */ + +/** + * \addtogroup maug_retrosnd_flags RetroSound State Flags + * \brief Flags indicating global state for the RETROSND_STATE::flags field. + * \{ + */ + +/** + * \brief Flag in RETROSND_STATE::flags indicating initialization was + * successful. + */ +#define RETROSND_FLAG_INIT 0x01 + +/*! \} */ /* maug_retrosnd_flags */ + +#define RETROSND_VOICE_BREATH 122 + +#define RETROSND_VOICE_SEASHORE 123 + +#define RETROSND_VOICE_BIRD_TWEET 124 + +#define RETROSND_VOICE_PHONE_RING 125 + +#define RETROSND_VOICE_HELICOPTER 126 + +#define RETROSND_VOICE_APPLAUSE 127 + +/** + * \brief Parameter for retrosnd_midi_set_voice() indicating a gunshot + * sound effect. + */ +#define RETROSND_VOICE_GUNSHOT 128 + +#define RETROSND_CHANNEL_CT 8 + +/** + * \brief Initialize retrosnd engine. + * \param args A pointer to the RETROSND_ARGS struct initialized by + * the calling program. + * + * The RETROSND_ARGS::snd_io_base field must be initialized with the address + * or other platform-specific indicator of the MIDI device to use. + */ +MERROR_RETVAL retrosnd_init( struct RETROFLAT_ARGS* args ); + +/** + * \brief Set the name of the voice bank filename to use. + */ +void retrosnd_set_sf_bank( const char* filename_in ); + +void retrosnd_midi_set_voice( uint8_t channel, uint8_t voice ); + +void retrosnd_midi_set_control( uint8_t channel, uint8_t key, uint8_t val ); + +void retrosnd_midi_note_on( uint8_t channel, uint8_t pitch, uint8_t vel ); + +void retrosnd_midi_note_off( uint8_t channel, uint8_t pitch, uint8_t vel ); + +MERROR_RETVAL retrosnd_midi_play_smf( const char* filename ); + +uint8_t retrosnd_midi_is_playing_smf(); + +void retrosnd_shutdown(); + +/*! \} */ /* maug_retrosnd */ + +#endif /* !NO_RETROSND */ + /* === OS-Specific Includes and Defines === */ #if defined( RETROFLAT_OS_WIN ) && !defined( MAUG_WINDOWS_H ) @@ -1523,112 +1630,6 @@ RETROFLAT_IN_KEY retroflat_poll_input( struct RETROFLAT_INPUT* input ); /*! \} */ /* maug_retroflt_input */ -/** - * \addtogroup maug_retrosnd RetroSound API - * \brief Abstraction layer header for sound on retro systems. - * \{ - * - * \file retrosnd.h - * \brief Abstraction layer header for sound on retro systems. - * - * RetroSound is a compatibility layer for making sound - * on various platforms, including Windows, MS-DOS or Linux. - * - * To use, define RETROSND_C before including this header from your main.c. - * - * You may include this header in other .c files, as well, but RETROSND_C - * should \b ONLY be declared \b ONCE in the entire program. - * - * It is *highly* advised to use this in conjunction with retroflt.h. - * - * maug.h should also be included before this header. - * - * Special thanks to: "Programming the Adlib/Sound Blaster FM Music Chips" - * by Jeffrey S. Lee (https://bochs.sourceforge.io/techspec/adlib_sb.txt) - * and "The Gravis Ultrasound" by neuraldk - * (http://neuraldk.org/document.php?gus) for DOS platform-specific stuff. - * - * And the MPU-401 interface for being so darn simple! - */ - -#ifndef RETROSND_TRACE_LVL -# define RETROSND_TRACE_LVL 0 -#endif /* !RETROSND_TRACE_LVL */ - -#ifndef RETROSND_REG_TRACE_LVL -# define RETROSND_REG_TRACE_LVL 0 -#endif /* !RETROSND_REG_TRACE_LVL */ - -#define SF_BANK_FILENAME_SZ_MAX 30 - -/** - * \addtogroup maug_retrosnd_flags RetroSound State Flags - * \brief Flags indicating global state for the RETROSND_STATE::flags field. - * \{ - */ - -/** - * \brief Flag in RETROSND_STATE::flags indicating initialization was - * successful. - */ -#define RETROSND_FLAG_INIT 0x01 - -/*! \} */ /* maug_retrosnd_flags */ - -#define RETROSND_VOICE_BREATH 122 - -#define RETROSND_VOICE_SEASHORE 123 - -#define RETROSND_VOICE_BIRD_TWEET 124 - -#define RETROSND_VOICE_PHONE_RING 125 - -#define RETROSND_VOICE_HELICOPTER 126 - -#define RETROSND_VOICE_APPLAUSE 127 - -#define RETROSND_PC_BIOS_SPKR 0x01 -#define RETROSND_PC_BIOS_MPU 0x02 -#define RETROSND_PC_BIOS_GUS 0x04 -#define RETROSND_PC_BIOS_ADLIB 0x08 - -/** - * \brief Parameter for retrosnd_midi_set_voice() indicating a gunshot - * sound effect. - */ -#define RETROSND_VOICE_GUNSHOT 128 - -/** - * \brief Initialize retrosnd engine. - * \param args A pointer to the RETROSND_ARGS struct initialized by - * the calling program. - * - * The RETROSND_ARGS::snd_io_base field must be initialized with the address - * or other platform-specific indicator of the MIDI device to use. - */ -MERROR_RETVAL retrosnd_init( struct RETROFLAT_ARGS* args ); - -/** - * \brief Set the name of the voice bank filename to use. - */ -void retrosnd_set_sf_bank( const char* filename_in ); - -void retrosnd_midi_set_voice( uint8_t channel, uint8_t voice ); - -void retrosnd_midi_set_control( uint8_t channel, uint8_t key, uint8_t val ); - -void retrosnd_midi_note_on( uint8_t channel, uint8_t pitch, uint8_t vel ); - -void retrosnd_midi_note_off( uint8_t channel, uint8_t pitch, uint8_t vel ); - -MERROR_RETVAL retrosnd_midi_play_smf( const char* filename ); - -uint8_t retrosnd_midi_is_playing_smf(); - -void retrosnd_shutdown(); - -/*! \} */ /* maug_retrosnd */ - #ifdef RETROFLT_C MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_x[8] = @@ -2404,7 +2405,6 @@ void retroflat_shutdown( int retval ) { maug_mfree( g_retroflat_state->viewport.refresh_grid_h ); } - # if defined( RETROFLAT_VDP ) if( NULL != g_retroflat_state->vdp_exe ) { retroflat_vdp_call( "retroflat_vdp_shutdown" );