From 4e3a9e3e1d568befd0aa5680ac59daa5b75cc884 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Wed, 4 Dec 2024 11:33:54 -0800 Subject: [PATCH 01/14] Switch to using DSP mixer instead of creating a new audio interface in Tiny SoundFont --- src/i_oplmusic.cpp | 1 + src/mpualsa.cpp | 1 + src/mpucorea.cpp | 3 +- src/mpucorem.cpp | 3 +- src/mputsf.cpp | 100 ++++++++++++++++++++------------------------- src/mpuwinmm.cpp | 1 + src/musapi.cpp | 17 +++++--- src/musapi.h | 1 + 8 files changed, 64 insertions(+), 63 deletions(-) diff --git a/src/i_oplmusic.cpp b/src/i_oplmusic.cpp index 6d731ec..de84ba6 100644 --- a/src/i_oplmusic.cpp +++ b/src/i_oplmusic.cpp @@ -1370,4 +1370,5 @@ musdevice_t mus_device_opl = { PitchBendEvent, ProgramChgEvent, AllOffEvent, + 0 }; diff --git a/src/mpualsa.cpp b/src/mpualsa.cpp index e86f93c..c7cf054 100644 --- a/src/mpualsa.cpp +++ b/src/mpualsa.cpp @@ -256,5 +256,6 @@ musdevice_t mus_device_alsa = { PitchBendEvent, ProgramEvent, AllNotesOffEvent, + 0 }; #endif diff --git a/src/mpucorea.cpp b/src/mpucorea.cpp index dda47f6..f797090 100644 --- a/src/mpucorea.cpp +++ b/src/mpucorea.cpp @@ -544,6 +544,7 @@ musdevice_t mus_device_corea = { ControllerEvent, PitchBendEvent, ProgramEvent, - AllNotesOffEvent + AllNotesOffEvent, + 0 }; #endif diff --git a/src/mpucorem.cpp b/src/mpucorem.cpp index 1a1d248..37e782d 100644 --- a/src/mpucorem.cpp +++ b/src/mpucorem.cpp @@ -266,6 +266,7 @@ musdevice_t mus_device_corem = { ControllerEvent, PitchBendEvent, ProgramEvent, - AllNotesOffEvent + AllNotesOffEvent, + 0 }; #endif diff --git a/src/mputsf.cpp b/src/mputsf.cpp index bae61ad..2158d13 100644 --- a/src/mputsf.cpp +++ b/src/mputsf.cpp @@ -7,6 +7,8 @@ #define TSF_IMPLEMENTATION #include "tsf.h" +#include "fx.h" + #include "musapi.h" #include "prefapi.h" @@ -17,14 +19,11 @@ AudioCallback() - ***************************************************************************/ void AudioCallback( - void* data, - uint8_t* stream, + int16_t *stream, int len ) { - int SampleCount = (len / (2 * sizeof(short))); //2 output channels - - tsf_render_short(g_TinySoundFont, (short*)stream, SampleCount, 0); + tsf_render_short(g_TinySoundFont, (short*)stream, len, 0); } /*************************************************************************** @@ -35,41 +34,31 @@ TSF_Init( int option ) { - SDL_AudioSpec OutputAudioSpec; - OutputAudioSpec.freq = 44100; - OutputAudioSpec.format = AUDIO_S16SYS; - OutputAudioSpec.channels = 2; - OutputAudioSpec.samples = 512; - OutputAudioSpec.callback = AudioCallback; - char fn[128]; - INI_GetPreference("Setup", "SoundFont", fn, 127, "SoundFont.sf2"); + #ifdef __SWITCH__ + strcpy(fn, RAP_SD_DIR "TimGM6mb.sf2"); + #else + INI_GetPreference("Setup", "SoundFont", fn, 127, "TimGM6mb.sf2"); + // Load the SoundFont from a file + #endif - // Load the SoundFont from a file g_TinySoundFont = tsf_load_filename(fn); - + if (!g_TinySoundFont) { char errmsg[255]; fprintf(stderr, "Could not load %s\n", fn); sprintf(errmsg,"Could not load %s\n", fn); + #ifndef SDL12 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Raptor", errmsg, NULL); + #endif EXIT_Error("Could not load SoundFont."); return 0; } - - // Set the SoundFont rendering output mode - tsf_set_output(g_TinySoundFont, TSF_STEREO_INTERLEAVED, OutputAudioSpec.freq, 0.0f); - - // Request the desired audio output format - if (SDL_OpenAudio(&OutputAudioSpec, NULL) < 0) - { - fprintf(stderr, "Could not open the audio hardware or the desired audio output format\n"); - EXIT_Error("Could not open the audio hardware or the desired audio output format."); - return 0; - } + // Set the SoundFont rendering output mode + tsf_set_output(g_TinySoundFont, TSF_STEREO_INTERLEAVED, fx_freq, 0.0f); return 1; } @@ -166,36 +155,36 @@ AllNotesOffEvent( tsf_note_off_all(g_TinySoundFont); } -/*************************************************************************** -SetChannelVolume() - - ***************************************************************************/ -static void -SetChannelVolume( - unsigned int chan, - unsigned int param -) -{ - float volume = (float)param; - volume /= 127; +// /*************************************************************************** +// SetChannelVolume() - +// ***************************************************************************/ +// static void +// SetChannelVolume( +// unsigned int chan, +// unsigned int param +// ) +// { +// float volume = (float)param; +// volume /= 127; - tsf_channel_set_volume(g_TinySoundFont, MPU_MapChannel(chan), volume); -} - -/*************************************************************************** -SetChannelPan() - - ***************************************************************************/ -static void -SetChannelPan( - unsigned int chan, - unsigned int param -) -{ - - float pan = (float)param; - pan /= 127; +// tsf_channel_set_volume(g_TinySoundFont, MPU_MapChannel(chan), volume); +// } + +// /*************************************************************************** +// SetChannelPan() - +// ***************************************************************************/ +// static void +// SetChannelPan( +// unsigned int chan, +// unsigned int param +// ) +// { + +// float pan = (float)param; +// pan /= 127; - tsf_channel_set_pan(g_TinySoundFont, MPU_MapChannel(chan), pan); -} +// tsf_channel_set_pan(g_TinySoundFont, MPU_MapChannel(chan), pan); +// } /*************************************************************************** ControllerEvent() - @@ -218,7 +207,7 @@ ControllerEvent( musdevice_t mus_device_tsf = { TSF_Init, TSF_DeInit, - NULL, + AudioCallback, KeyOffEvent, KeyOnEvent, @@ -226,4 +215,5 @@ musdevice_t mus_device_tsf = { PitchBendEvent, ProgramEvent, AllNotesOffEvent, + 1 }; \ No newline at end of file diff --git a/src/mpuwinmm.cpp b/src/mpuwinmm.cpp index c2a2169..e9ae184 100644 --- a/src/mpuwinmm.cpp +++ b/src/mpuwinmm.cpp @@ -224,5 +224,6 @@ musdevice_t mus_device_winmm = { PitchBendEvent, ProgramEvent, AllNotesOffEvent, + 0 }; #endif // _WIN32 diff --git a/src/musapi.cpp b/src/musapi.cpp index 93c6ba7..dbb8454 100644 --- a/src/musapi.cpp +++ b/src/musapi.cpp @@ -237,8 +237,9 @@ MUS_Reset( music_device->ControllerEvent(i, 3, newvol); } - if (music_device && music_device->AllNotesOffEvent) - music_device->AllNotesOffEvent(i,0); + + if (music_device && music_device->AllNotesOffEvent) + music_device->AllNotesOffEvent(i,0); } } @@ -359,7 +360,6 @@ MUS_Service( param = music_vol; if (music_device && music_device->ControllerEvent) music_device->ControllerEvent(chan, 3, param); - break; default: break; @@ -595,10 +595,14 @@ MUS_Mix( if (!music_init || !music_device || !music_device->Mix) return; - + if(music_device->sampleDirect) + music_device->Mix(stream, len); + for (i = 0; i < len; i++) { - music_device->Mix(stream, 1); + if(!music_device->sampleDirect) + music_device->Mix(stream, 1); + music_cnt += musrate; while (music_cnt >= fx_freq) @@ -624,7 +628,8 @@ MUS_Mix( GSS_Service(); } } - stream += 2; + if(!music_device->sampleDirect) + stream += 2; } } diff --git a/src/musapi.h b/src/musapi.h index 9a94540..9164d4b 100644 --- a/src/musapi.h +++ b/src/musapi.h @@ -13,6 +13,7 @@ struct musdevice_t { void (*PitchBendEvent)(unsigned int chan, int bend); void (*ProgramEvent)(unsigned int chan, unsigned int param); void (*AllNotesOffEvent)(unsigned int chan, unsigned int param); + int sampleDirect; }; extern musdevice_t mus_device_opl, mus_device_winmm, mus_device_tsf, mus_device_alsa, mus_device_corea, mus_device_corem; From c6f69ef6752d2f54b075371b5029057884c6e5eb Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 6 Dec 2024 09:59:47 -0800 Subject: [PATCH 02/14] Refactored music sampling engine for improved performance. --- src/fx.cpp | 5 ++++- src/i_oplmusic.cpp | 3 +-- src/mpualsa.cpp | 3 +-- src/mpucorea.cpp | 3 +-- src/mpucorem.cpp | 3 +-- src/mputsf.cpp | 12 ++++-------- src/mpuwinmm.cpp | 3 +-- src/musapi.cpp | 26 +++++++++++++++----------- src/musapi.h | 2 +- 9 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/fx.cpp b/src/fx.cpp index 753f9c2..79a3e9d 100644 --- a/src/fx.cpp +++ b/src/fx.cpp @@ -116,7 +116,6 @@ SND_InitSound( dig_flag = 0; fx_device = SND_NONE; - music_volume = INI_GetPreferenceLong("Music", "Volume", 127); music_card = INI_GetPreferenceLong("Music", "CardType", M_NONE); sys_midi = INI_GetPreferenceLong("Setup", "sys_midi", 0); @@ -125,6 +124,10 @@ SND_InitSound( core_midi_port = INI_GetPreferenceLong("Setup", "core_midi_port", 0); alsaclient = INI_GetPreferenceLong("Setup", "alsa_output_client", 128); alsaport = INI_GetPreferenceLong("Setup", "alsa_output_port", 0); + music_samplesperloop = INI_GetPreferenceLong("Music", "SamplesPerLoop", 16); + + if(music_samplesperloop < 1 || music_samplesperloop > spec.samples) + music_samplesperloop = 16; switch (music_card) { diff --git a/src/i_oplmusic.cpp b/src/i_oplmusic.cpp index de84ba6..99804f6 100644 --- a/src/i_oplmusic.cpp +++ b/src/i_oplmusic.cpp @@ -1369,6 +1369,5 @@ musdevice_t mus_device_opl = { ControllerEvent, PitchBendEvent, ProgramChgEvent, - AllOffEvent, - 0 + AllOffEvent }; diff --git a/src/mpualsa.cpp b/src/mpualsa.cpp index c7cf054..cb82ff8 100644 --- a/src/mpualsa.cpp +++ b/src/mpualsa.cpp @@ -255,7 +255,6 @@ musdevice_t mus_device_alsa = { ControllerEvent, PitchBendEvent, ProgramEvent, - AllNotesOffEvent, - 0 + AllNotesOffEvent }; #endif diff --git a/src/mpucorea.cpp b/src/mpucorea.cpp index f797090..dda47f6 100644 --- a/src/mpucorea.cpp +++ b/src/mpucorea.cpp @@ -544,7 +544,6 @@ musdevice_t mus_device_corea = { ControllerEvent, PitchBendEvent, ProgramEvent, - AllNotesOffEvent, - 0 + AllNotesOffEvent }; #endif diff --git a/src/mpucorem.cpp b/src/mpucorem.cpp index 37e782d..1a1d248 100644 --- a/src/mpucorem.cpp +++ b/src/mpucorem.cpp @@ -266,7 +266,6 @@ musdevice_t mus_device_corem = { ControllerEvent, PitchBendEvent, ProgramEvent, - AllNotesOffEvent, - 0 + AllNotesOffEvent }; #endif diff --git a/src/mputsf.cpp b/src/mputsf.cpp index 2158d13..928976e 100644 --- a/src/mputsf.cpp +++ b/src/mputsf.cpp @@ -35,12 +35,9 @@ TSF_Init( ) { char fn[128]; - #ifdef __SWITCH__ - strcpy(fn, RAP_SD_DIR "TimGM6mb.sf2"); - #else - INI_GetPreference("Setup", "SoundFont", fn, 127, "TimGM6mb.sf2"); - // Load the SoundFont from a file - #endif + + INI_GetPreference("Setup", "SoundFont", fn, 127, "TimGM6mb.sf2"); + // Load the SoundFont from a file g_TinySoundFont = tsf_load_filename(fn); @@ -214,6 +211,5 @@ musdevice_t mus_device_tsf = { ControllerEvent, PitchBendEvent, ProgramEvent, - AllNotesOffEvent, - 1 + AllNotesOffEvent }; \ No newline at end of file diff --git a/src/mpuwinmm.cpp b/src/mpuwinmm.cpp index e9ae184..54b39ba 100644 --- a/src/mpuwinmm.cpp +++ b/src/mpuwinmm.cpp @@ -223,7 +223,6 @@ musdevice_t mus_device_winmm = { ControllerEvent, PitchBendEvent, ProgramEvent, - AllNotesOffEvent, - 0 + AllNotesOffEvent }; #endif // _WIN32 diff --git a/src/musapi.cpp b/src/musapi.cpp index dbb8454..3a18a50 100644 --- a/src/musapi.cpp +++ b/src/musapi.cpp @@ -8,6 +8,8 @@ static int musrate = 70; static int musfaderate = 50; + +int music_samplesperloop = 1; int music_init; int music_startoffset; int music_len; @@ -592,25 +594,27 @@ MUS_Mix( ) { int i; - + int mRate = musrate * music_samplesperloop; + int fRate = musfaderate * music_samplesperloop; + int gRate = gssrate * music_samplesperloop; + int SPLx2 = music_samplesperloop * 2; + if (!music_init || !music_device || !music_device->Mix) return; - if(music_device->sampleDirect) - music_device->Mix(stream, len); - for (i = 0; i < len; i++) + for (i = 0; i < len; i+=music_samplesperloop) { - if(!music_device->sampleDirect) - music_device->Mix(stream, 1); - music_cnt += musrate; + music_device->Mix(stream, music_samplesperloop); + + music_cnt += mRate; while (music_cnt >= fx_freq) { music_cnt -= fx_freq; MUS_Service(); } - music_cnt2 += musfaderate; + music_cnt2 += fRate; while (music_cnt2 >= fx_freq) { @@ -620,7 +624,7 @@ MUS_Mix( if (gsshack) { - music_cnt3 += gssrate; + music_cnt3 += gRate; while (music_cnt3 >= fx_freq) { @@ -628,8 +632,8 @@ MUS_Mix( GSS_Service(); } } - if(!music_device->sampleDirect) - stream += 2; + + stream += SPLx2; } } diff --git a/src/musapi.h b/src/musapi.h index 9164d4b..81a3b8e 100644 --- a/src/musapi.h +++ b/src/musapi.h @@ -13,9 +13,9 @@ struct musdevice_t { void (*PitchBendEvent)(unsigned int chan, int bend); void (*ProgramEvent)(unsigned int chan, unsigned int param); void (*AllNotesOffEvent)(unsigned int chan, unsigned int param); - int sampleDirect; }; +extern int music_samplesperloop; extern musdevice_t mus_device_opl, mus_device_winmm, mus_device_tsf, mus_device_alsa, mus_device_corea, mus_device_corem; extern musdevice_t *music_device; From 2123472c8d138523abaf7fd6a16b258cbd16cfd9 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Thu, 19 Dec 2024 18:44:11 -0800 Subject: [PATCH 03/14] Fixed some warnings in the text screen lib. --- include/textscreen/include/txt_fileselect.c | 2 +- include/textscreen/include/txt_gui.c | 1 - include/textscreen/include/txt_window.c | 5 ++--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/textscreen/include/txt_fileselect.c b/include/textscreen/include/txt_fileselect.c index d9c754f..b273edc 100644 --- a/include/textscreen/include/txt_fileselect.c +++ b/include/textscreen/include/txt_fileselect.c @@ -603,7 +603,7 @@ static char *ExpandExtension(const char *orig) c = newext; for (i = 0; i < oldlen; ++i) { - if (isalpha(orig[i])) + if (isalpha((int)orig[i])) { *c++ = '['; *c++ = tolower(orig[i]); diff --git a/include/textscreen/include/txt_gui.c b/include/textscreen/include/txt_gui.c index d7f4362..ed4f84e 100644 --- a/include/textscreen/include/txt_gui.c +++ b/include/textscreen/include/txt_gui.c @@ -204,7 +204,6 @@ void TXT_DrawSpecialSeparator(int x, int y, int w, int h, int sepcolor, int cust int bx; int x1; - int b; TXT_SaveColors(&colors); diff --git a/include/textscreen/include/txt_window.c b/include/textscreen/include/txt_window.c index 9cfaab4..c1cd6fd 100644 --- a/include/textscreen/include/txt_window.c +++ b/include/textscreen/include/txt_window.c @@ -625,12 +625,11 @@ void TXT_OpenURL(const char *url) #endif retval = system(cmd); - free(cmd); if (retval != 0) { - fprintf(stderr, "TXT_OpenURL: error executing '%s'; return code %d\n", - cmd, retval); + fprintf(stderr, "TXT_OpenURL: error executing '%s'; return code %d\n", cmd, retval); } + free(cmd); } #endif /* #ifndef _WIN32 */ From ec9d43ff39e03eac30911d84c8ef517bafdc8324 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 08:23:35 -0800 Subject: [PATCH 04/14] Fixed some warnings, and added a function for finding file path --- src/glbapi.cpp | 97 +++++++++++++++++++++++++++++++++++++------------- src/glbapi.h | 1 + 2 files changed, 74 insertions(+), 24 deletions(-) diff --git a/src/glbapi.cpp b/src/glbapi.cpp index 45b00f3..2802307 100644 --- a/src/glbapi.cpp +++ b/src/glbapi.cpp @@ -35,10 +35,16 @@ char* strupr(char* s) static const char* serial = "32768GLB"; static char exePath[PATH_MAX]; static int num_glbs; -static KEYFILE g_key; static char prefix[5] = "FILE"; static bool fVmem = 0; +//This is the list of loctions to look for files in. +static const char *lookNdirs[] = { + "", + exePath, + "soundfonts/", + NULL +}; /* * define file descriptor used to access file. */ @@ -153,8 +159,7 @@ GLB_FindFile( const char *permissions // INPUT : file access permissions ) { - const char* routine = "GLB_FindFile"; - char filename[PATH_MAX]; + char *filename; FILE *handle; FILEDESC* fd; @@ -173,22 +178,23 @@ GLB_FindFile( * create a file name and attempt to open it local first, then if it * fails use the exe path and try again. */ - sprintf(filename, "%s%04u.GLB", prefix, filenum); - if ((handle = fopen(filename, permissions)) == NULL) - { - sprintf(filename, "%s%s%04u.GLB", exePath, prefix, filenum); - - if ((handle = fopen(filename, permissions)) == NULL) - { - if (return_on_failure) - return NULL; - - sprintf(filename, "%s%04u.GLB", prefix, filenum); - EXIT_Error("GLB_FindFile: %s, Error #%d,%s", - filename, errno, strerror(errno)); + int lookat = 0; + char *name = (char*)malloc((strlen(prefix)+9) * sizeof(char)); + sprintf(name, "%s%04u.GLB", prefix, filenum); + filename = GLB_FindFilePath(name); + + if(filename == NULL){ + if (return_on_failure){ + free(name); + return NULL; } + + EXIT_Error("GLB_FindFile: %s, Error #%d,%s", name, errno, strerror(errno)); } - + free(name); + + handle = fopen(filename, permissions); + /* * Keep file handle */ @@ -198,9 +204,12 @@ GLB_FindFile( fd->permissions = permissions; fd->handle = handle; + free(filename); + return handle; } + /*------------------------------------------------------------------------ GLB_OpenFile() - Opens & Caches file handle ------------------------------------------------------------------------*/ @@ -243,7 +252,7 @@ GLB_OpenFile( /*------------------------------------------------------------------------ GLB_CloseFiles() - Closes all cached files. ------------------------------------------------------------------------*/ -static void +void GLB_CloseFiles( void ) @@ -304,6 +313,7 @@ GLB_LoadIDT( int j; int k; int n; + size_t flen; KEYFILE key[10]; ITEMINFO* ii; @@ -316,10 +326,10 @@ GLB_LoadIDT( { k = fd->items - j; - if (k > ASIZE(key)) + if (k > (int)ASIZE(key)) k = ASIZE(key); - fread(key, sizeof(KEYFILE), k, handle); + flen = fread(key, sizeof(KEYFILE), k, handle); for (n = 0; n < k; n++) { @@ -429,7 +439,7 @@ GLB_Load( { FILE *handle; ITEMINFO* ii; - + size_t flen; ASSERT(filenum >= 0 && filenum < num_glbs); handle = filedesc[filenum].handle; @@ -449,11 +459,11 @@ GLB_Load( else { fseek(handle, ii->offset, SEEK_SET); - fread(inmem, ii->size, 1, handle); + flen = fread(inmem, ii->size, 1, handle); #ifdef _SCOTTGAME if (ii->flags & ITF_ENCODED) { - GLB_DeCrypt(serial, inmem, ii->size); + GLB_DeCrypt(serial, inmem, flen); } #endif } @@ -475,7 +485,7 @@ GLB_FetchItem( ITEM_H itm; ITEMINFO* ii; - if (handle == ~0) + if (handle == ((uint32_t)~0)) { EXIT_Error("GLB_FetchItem: empty handle."); return NULL; @@ -899,4 +909,43 @@ GLB_SaveFile( } fclose(handle); +} + +/*************************************************************************** + * GLB_FindFilePath() - Finds the path to a filename by searching in multiple directories. + * + * This function iterates through the 'lookNdirs' array and tries to open each file path. + * The first path that is successfully opened is returned as a dynamically allocated string. + ***************************************************************************/ +char * +GLB_FindFilePath( + char *file +) +{ + char filename[PATH_MAX]; + + FILE *handle; + + int lookat = 0; + + while(lookNdirs[lookat] != NULL){ + sprintf(filename, "%s%s", lookNdirs[lookat], file); + lookat++; + if ((handle = fopen(filename, "r")) == NULL) + { + if(lookNdirs[lookat] == NULL) + return NULL; + + } else { + fclose(handle); + break; + } + } + + char * retChar = (char*)malloc(strlen(filename)+1 * sizeof(char)); + strcpy(retChar, filename); + + printf("Found: %s\n", filename); + + return retChar; } \ No newline at end of file diff --git a/src/glbapi.h b/src/glbapi.h index eea35ab..2e17852 100644 --- a/src/glbapi.h +++ b/src/glbapi.h @@ -38,6 +38,7 @@ void GLB_SaveFile(char *name, char *buffer, int length); int GLB_Load(char *inmem, int filenum, int itemnum); int GLB_IsLabel(int handle); void GLB_ReadItem(int handle, char *mem); +char * GLB_FindFilePath(char *file); //char *GLB_GetPtr(int handle); //void GLB_SetItemPointer(int a1, char* a2); //void GLB_SetItemSize(int a1, int a2); \ No newline at end of file From a74940190df8f53e85495227bb3ed136076231fd Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 08:25:47 -0800 Subject: [PATCH 05/14] Added a mixer for GSS. --- src/gssapi.cpp | 175 +++++++++++++++++++++++++++---------------------- 1 file changed, 96 insertions(+), 79 deletions(-) diff --git a/src/gssapi.cpp b/src/gssapi.cpp index 596917f..b921a0a 100644 --- a/src/gssapi.cpp +++ b/src/gssapi.cpp @@ -25,37 +25,50 @@ int gss_type; int gss_lastnote, gss_lastsmp; /*************************************************************************** -GSS_Init () - +GSS_Init () - ***************************************************************************/ -void -GSS_Init( - int device, - int option -) +void GSS_Init( + int device, + int option) { if (gss_init) return; - + switch (device) { case M_NONE: gss_device = NULL; break; - + case M_ADLIB: case M_PAS: case M_SB: gss_device = &mus_device_opl; break; - + case M_WAVE: case M_CANVAS: case M_GMIDI: default: - - #ifdef _WIN32 - gss_device = &mus_device_winmm; - #endif // _WIN32 + if (sys_midi) + { + #ifdef _WIN32 + gss_device = &mus_device_winmm; + #endif // _WIN32 + + #ifdef __linux__ + gss_device = &mus_device_alsa; + #endif // __linux__ + + #ifdef __APPLE__ + if (core_dls_synth) + gss_device = &mus_device_corea; + else + gss_device = &mus_device_corem; + #endif // __APPLE__ + } + else + gss_device = &mus_device_tsf; break; } @@ -75,17 +88,15 @@ GSS_Init( /*************************************************************************** GSS_DeInit () - ***************************************************************************/ -void -GSS_DeInit( - void -) +void GSS_DeInit( + void) { if (!gss_init) return; if (gss_device && gss_device->DeInit) gss_device->DeInit(); - + gsshack = 0; gss_device = NULL; gss_init = 0; @@ -94,21 +105,19 @@ GSS_DeInit( /*************************************************************************** GSS_Service () - ***************************************************************************/ -void -GSS_Service( - void -) +void GSS_Service( + void) { if (!gss_init) return; - + switch (gss_type) { case 1: { - gss1_t *gss = (gss1_t*)gss_ptr; + gss1_t *gss = (gss1_t *)gss_ptr; int smp, note, bend; - + if (gss_currentptr == 0) { // setup playback @@ -116,7 +125,7 @@ GSS_Service( { if (gss_device && gss_device->KeyOffEvent) gss_device->KeyOffEvent(14, gss_lastnote); - + gss_lastnote = 0; } if (gss_device && gss_device->ControllerEvent) @@ -134,7 +143,7 @@ GSS_Service( { if (gss_device && gss_device->KeyOffEvent) gss_device->KeyOffEvent(14, gss_lastnote); - + gss_lastnote = 0; } gss_type = 0; @@ -142,32 +151,32 @@ GSS_Service( break; } smp = gss->data[gss_currentptr++]; - + if (gss_lastsmp != smp) { if (smp == 0 && gss_lastnote) { if (gss_device && gss_device->KeyOffEvent) gss_device->KeyOffEvent(14, gss_lastnote); - + gss_lastnote = 0; } else { note = 29 + ((smp - 1) >> 1); bend = (smp & 1) ? 127 : 159; - + if (note != gss_lastnote) { if (gss_device && gss_device->KeyOffEvent) gss_device->KeyOffEvent(14, gss_lastnote); - + if (gss_device && gss_device->PitchBendEvent) gss_device->PitchBendEvent(14, bend); - + if (gss_device && gss_device->KeyOnEvent) gss_device->KeyOnEvent(14, note, gss_volume); - + gss_lastnote = note; } else @@ -186,14 +195,14 @@ GSS_Service( /*************************************************************************** GSS_Mix () - ***************************************************************************/ -void -GSS_Mix( - int16_t *stream, - int len -) +void GSS_Mix( + int16_t *stream, + int len) { + int32_t L, R; int i; - + int16_t GSSsample[2]; + if (!gss_init) return; @@ -202,9 +211,25 @@ GSS_Mix( for (i = 0; i < len; i++) { - gss_device->Mix(stream, 1); + gss_device->Mix(GSSsample, 1); gss_cnt += gssrate; - + + L = (GSSsample[0] + stream[0]) >> 2; + R = (GSSsample[1] + stream[1]) >> 2; + + if (L < INT16_MIN) + L = INT16_MIN; + else if (L > INT16_MAX) + L = INT16_MAX; + + if (R < INT16_MIN) + R = INT16_MIN; + else if (R > INT16_MAX) + R = INT16_MAX; + + stream[0] = L; + stream[1] = R; + while (gss_cnt >= fx_freq) { gss_cnt -= fx_freq; @@ -217,20 +242,18 @@ GSS_Mix( /*************************************************************************** GSS_Poll () - ***************************************************************************/ -void -GSS_Poll( - void -) +void GSS_Poll( + void) { if (!gss_init || !gss_device || gss_device->Mix) return; int now = SDL_GetTicks(); - + while (gss_timer < now) { gss_cnt += gssrate; - + if (gss_cnt >= 1000) { gss_cnt -= 1000; @@ -243,18 +266,16 @@ GSS_Poll( /*************************************************************************** GSS_PlayPatch () - ***************************************************************************/ -int -GSS_PlayPatch( - void *gss, - int sep, - int pitch, - int volume, - int priority -) +int GSS_PlayPatch( + void *gss, + int sep, + int pitch, + int volume, + int priority) { - int format = *(int16_t*)gss; + int format = *(int16_t *)gss; int handle = (gss_handcnt++) & FXHAND_MASK; - + if (format != 1 && format != 2) return -1; @@ -268,14 +289,14 @@ GSS_PlayPatch( if (gss_type == 0) gss_lastnote = 0; - + gss_type = 0; gss_ptr = 0; gss_priority = priority; gss_sep = sep; gss_volume = volume; - + switch (format) { case 1: @@ -286,7 +307,7 @@ GSS_PlayPatch( gss_type = 1; break; } - + case 2: gss_currentptr = 0; gss_ptr = gss; @@ -296,32 +317,30 @@ GSS_PlayPatch( gss_handle = handle; SND_Unlock(); - + return handle | FXHAND_GSS1; } /*************************************************************************** GSS_StopPatch () - ***************************************************************************/ -void -GSS_StopPatch( - int handle -) +void GSS_StopPatch( + int handle) { if (!gss_init) return; - + handle &= FXHAND_MASK; - + SND_Lock(); - + if (handle == gss_handle) { switch (gss_type) { case 1: { - gss1_t *gss = (gss1_t*)gss_ptr; + gss1_t *gss = (gss1_t *)gss_ptr; gss_currentptr = gss->len; } } @@ -332,24 +351,22 @@ GSS_StopPatch( /*************************************************************************** GSS_PatchIsPlaying () - ***************************************************************************/ -int -GSS_PatchIsPlaying( - int handle -) +int GSS_PatchIsPlaying( + int handle) { int stat = 0; - + if (!gss_init) return 0; - + handle &= FXHAND_MASK; - + SND_Lock(); - + if (handle == gss_handle && gss_type != 0) stat = 1; - + SND_Unlock(); - + return stat; } From a65e67350e3916f21ec638ee4435b6e71c2f8cc1 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 08:30:39 -0800 Subject: [PATCH 06/14] change how tsf looks for sound fonts. --- src/mputsf.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mputsf.cpp b/src/mputsf.cpp index 928976e..84069a6 100644 --- a/src/mputsf.cpp +++ b/src/mputsf.cpp @@ -11,6 +11,7 @@ #include "musapi.h" #include "prefapi.h" +#include "glbapi.h" static tsf* g_TinySoundFont; @@ -34,13 +35,19 @@ TSF_Init( int option ) { - char fn[128]; + char NameOfFile[127]; - INI_GetPreference("Setup", "SoundFont", fn, 127, "TimGM6mb.sf2"); - // Load the SoundFont from a file + INI_GetPreference("Setup", "SoundFont", NameOfFile, 127, "TimGM6mb.sf2"); + //Get the path to the file. + char* fn = GLB_FindFilePath(NameOfFile); + + //Load the SoundFont from a file g_TinySoundFont = tsf_load_filename(fn); + if(fn) + free(fn); + if (!g_TinySoundFont) { char errmsg[255]; From 505034a05989081207d62d4c48b78f0c5e83d85f Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 08:33:30 -0800 Subject: [PATCH 07/14] Fixed undefine values, type mismatches. --- src/gfxapi.cpp | 8 ++++---- src/prefapi.cpp | 4 ++-- src/swdapi.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gfxapi.cpp b/src/gfxapi.cpp index 2bec0e7..2affd83 100644 --- a/src/gfxapi.cpp +++ b/src/gfxapi.cpp @@ -639,7 +639,7 @@ GFX_ShadeArea( ) { int loop; - char *buf, *cur_table; + char *buf, *cur_table = ltable; if (!GFX_ClipLines(NULL, &x, &y, &lx, &ly)) return; @@ -682,7 +682,7 @@ GFX_ShadeShape( GFX_PIC* h = (GFX_PIC*)inmem; GFX_SPRITE* ah; char rval; - char *cur_table; + char *cur_table = ltable; char *dest; int ox = x; int oy = y; @@ -753,7 +753,7 @@ GFX_VShadeLine( int ly // INPUT : length of line ) { - char *cur_table; + char *cur_table = ltable; char *outbuf; int lx = 1; @@ -798,7 +798,7 @@ GFX_HShadeLine( int lx // INPUT : length of line ) { - char *cur_table; + char *cur_table = ltable; char *outbuf; int ly = 1; diff --git a/src/prefapi.cpp b/src/prefapi.cpp index faab246..f9b8016 100644 --- a/src/prefapi.cpp +++ b/src/prefapi.cpp @@ -107,7 +107,7 @@ WritePrivateProfileString( FILE* fptr; short found = 0; short len; - int pos1, pos2, pos3; + int pos1, pos2 = 0, pos3; int exist_len, new_len, delta; int size; int cnt; @@ -260,7 +260,7 @@ WritePrivateProfileString( chsize(fileno(fptr), pos1); #endif #ifdef __GNUC__ - ftruncate(fileno(fptr), pos1); + int flen = ftruncate(fileno(fptr), pos1); #endif } else if (delta > 0) // Expand file, starting at the end diff --git a/src/swdapi.cpp b/src/swdapi.cpp index e5171cf..53045eb 100644 --- a/src/swdapi.cpp +++ b/src/swdapi.cpp @@ -1605,7 +1605,7 @@ SWD_ReformatFieldData( SFIELD32* swdfield32 = (SFIELD32*)((char*)header + header->fldofs); SFIELD* swdfield = (SFIELD*)((char*)swdNewData + swdNewData->fldofs); - for (size_t loop = 0; loop < header->numflds; loop++) + for (size_t loop = 0; loop < (size_t)header->numflds; loop++) { swdfield[loop].opt = swdfield32[loop].opt; swdfield[loop].id = swdfield32[loop].id; From 76fa71487e43d13ea303cfb5eb214a0ef4d8ad73 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 08:34:36 -0800 Subject: [PATCH 08/14] Fixed gun sounds overriding other GGS Sounds --- src/fx.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fx.cpp b/src/fx.cpp index 79a3e9d..8824cbe 100644 --- a/src/fx.cpp +++ b/src/fx.cpp @@ -209,7 +209,10 @@ SND_InitSound( fx_channels = 1; if (fx_card == M_ADLIB || fx_card == M_WAVE || fx_card == M_CANVAS || fx_card == M_GMIDI) + { + fx_gus = 1; GSS_Init(fx_card, 0); + } SDL_PauseAudioDevice(fx_dev, 0); From 12d6ad3d9b7a6a8f8b386ff16f811c27e6aec696 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 11:04:08 -0800 Subject: [PATCH 09/14] Making the code more understandable --- src/fileids.h | 4 ++-- src/glbapi.cpp | 17 +++++++++-------- src/opl3.cpp | 6 +++--- src/vmemapi.cpp | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/fileids.h b/src/fileids.h index 04f0474..b649346 100644 --- a/src/fileids.h +++ b/src/fileids.h @@ -1,7 +1,7 @@ #pragma once +#define FILE_NULL UINT32_MAX //FILE0000.GLB Items - #define FILE000_ATENTION_TXT 0x00000 #define FILE001_LASTSCR1_TXT 0x00001 #define FILE002_LASTSCR2_TXT 0x00002 @@ -1730,4 +1730,4 @@ #define FILE4d3_EBOSS11_PIC 0x400d3 #define FILE4d4_STARTG4TILES 0x400d4 #define FILE415_ENDG4TILES 0x40615 -#define FILE416_BOGUS4 0x40616 +#define FILE416_BOGUS4 0x40616 \ No newline at end of file diff --git a/src/glbapi.cpp b/src/glbapi.cpp index 2802307..88e51d5 100644 --- a/src/glbapi.cpp +++ b/src/glbapi.cpp @@ -8,6 +8,7 @@ #include "common.h" #include "glbapi.h" #include "vmemapi.h" +#include "fileids.h" #ifdef _WIN32 #include @@ -485,7 +486,7 @@ GLB_FetchItem( ITEM_H itm; ITEMINFO* ii; - if (handle == ((uint32_t)~0)) + if (handle == FILE_NULL) { EXIT_Error("GLB_FetchItem: empty handle."); return NULL; @@ -593,7 +594,7 @@ GLB_UnlockItem( ITEM_H itm; ITEMINFO* ii; - if (handle == ~0) + if (handle == FILE_NULL) return; itm.handle = handle; @@ -633,7 +634,7 @@ GLB_IsLabel( ITEM_H itm; ITEMINFO* ii; - if (handle == ~0) + if (handle == FILE_NULL) return 0; itm.handle = handle; @@ -659,7 +660,7 @@ GLB_ReadItem( ITEM_H itm; ITEMINFO* ii; - if (handle == ~0) + if (handle == FILE_NULL) return; ASSERT(mem != NULL); @@ -694,7 +695,7 @@ GLB_GetItemID( ASSERT(in_name != NULL); - itm.handle = ~0; + itm.handle = FILE_NULL; if (*in_name != ' ' && *in_name != '\0') { for (filenum = 0; filenum < num_glbs; filenum++) @@ -730,7 +731,7 @@ GLB_GetPtr( ITEM_H itm; ITEMINFO* ii; - if (handle == ~0) + if (handle == FILE_NULL) return NULL; itm.handle = handle; @@ -756,7 +757,7 @@ GLB_FreeItem( ITEM_H itm; ITEMINFO* ii; - if (handle == ~0) + if (handle == FILE_NULL) return; itm.handle = handle; @@ -829,7 +830,7 @@ GLB_ItemSize( ITEM_H itm; ITEMINFO* ii; - if (handle == ~0) + if (handle == FILE_NULL) return 0; itm.handle = handle; diff --git a/src/opl3.cpp b/src/opl3.cpp index 56dcce5..1a57297 100644 --- a/src/opl3.cpp +++ b/src/opl3.cpp @@ -954,12 +954,12 @@ static void OPL3_ChannelWriteC0(opl3_channel *channel, Bit8u data) } if (channel->chip->newm) { - channel->cha = ((data >> 4) & 0x01) ? ~0 : 0; - channel->chb = ((data >> 5) & 0x01) ? ~0 : 0; + channel->cha = ((data >> 4) & 0x01) ? UINT16_MAX : 0; + channel->chb = ((data >> 5) & 0x01) ? UINT16_MAX : 0; } else { - channel->cha = channel->chb = (Bit16u)~0; + channel->cha = channel->chb = UINT16_MAX; } } diff --git a/src/vmemapi.cpp b/src/vmemapi.cpp index 1af950b..2b7ddd5 100644 --- a/src/vmemapi.cpp +++ b/src/vmemapi.cpp @@ -123,7 +123,7 @@ vm_DiscardMem( do { - oldage = lowsize = lowcnt = (uint32_t)~0; + oldage = lowsize = lowcnt = UINT32_MAX; low_mcb = NULL; mcb = (MCBL*)(pool.blk[0]); mem_freed = 0; From f641cfa0589f3e6d3d12a92ed5317067b7227cf9 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 11:07:20 -0800 Subject: [PATCH 10/14] Fixed warnings in loadsave due to string buffers not fitting into eachother due to size being equal. --- src/loadsave.cpp | 63 ++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/src/loadsave.cpp b/src/loadsave.cpp index 2146985..efe5f1b 100644 --- a/src/loadsave.cpp +++ b/src/loadsave.cpp @@ -36,7 +36,7 @@ #define MAX_SAVE 10 -char cdpath[PATH_MAX]; +char cdpath[PATH_MAX>>2]; char g_setup_ini[PATH_MAX]; int cdflag = 0; @@ -46,8 +46,8 @@ int map_item = -1; int curplr_diff = 2; int srwpos = 0; -static const char *fmt = "CHAR%04u.FIL"; -static const char *cdfmt = "%sCHAR%04u.FIL"; +#define FMT "CHAR%04u.FIL" +#define CDFMT "%sCHAR%04u.FIL" MAZELEVEL *mapmem; CSPRITE *csprite; @@ -369,9 +369,9 @@ RAP_AreSavedFiles( for (loop = 0; loop < MAX_SAVE; loop++) { if (cdflag) - sprintf(temp, cdfmt, cdpath, loop); + snprintf(temp, sizeof(temp), CDFMT, cdpath, loop); else - sprintf(temp, fmt, loop); + snprintf(temp, sizeof(temp), FMT, loop); if (!access(temp, 0)) return 1; @@ -392,7 +392,8 @@ RAP_ReadFile( { FILE *handle; handle = fopen(name, "rb"); - + size_t flen; + if (!handle) { WIN_Msg("File open Error"); @@ -400,16 +401,16 @@ RAP_ReadFile( } savebuffer = (char*)malloc(sizerec); - fread(savebuffer, 1, sizerec, handle); + flen = fread(savebuffer, 1, sizerec, handle); - GLB_DeCrypt(gdmodestr, savebuffer, sizerec); + GLB_DeCrypt(gdmodestr, savebuffer, flen); ReadPlayer((PLAYEROBJ*)buffer); fclose(handle); free(savebuffer); SaveResetReadWritePosition(); - return sizerec; + return flen; } /*************************************************************************** @@ -429,9 +430,9 @@ RAP_FFSaveFile( for (loop = 0; loop < MAX_SAVE; loop++) { if (cdflag) - sprintf(temp, cdfmt, cdpath, loop); + snprintf(temp, sizeof(temp), CDFMT, cdpath, loop); else - sprintf(temp, fmt, loop); + snprintf(temp, sizeof(temp), FMT, loop); if (access(temp, 0) != 0) { @@ -457,22 +458,28 @@ RAP_IsSaveFile( char temp[PATH_MAX]; int rval, loop; FILE *handle; + size_t flen; + rval = 0; for (loop = 0; loop < MAX_SAVE; loop++) { if (cdflag) - sprintf(temp, cdfmt, cdpath, loop); + snprintf(temp, sizeof(temp), CDFMT, cdpath, loop); else - sprintf(temp, fmt, loop); + snprintf(temp, sizeof(temp), FMT, loop); handle = fopen(temp, "rb"); if (handle) { savebuffer = (char*)malloc(sizeof(tp)); - fread(savebuffer, 1, sizeof(tp), handle); + flen = fread(savebuffer, 1, sizeof(tp), handle); + if(flen != sizeof(tp)) + { + EXIT_Error("Error reading save file.\n"); + } //GLB_DeCrypt(gdmodestr, savebuffer, sizeof(tp)); //missing in v1.2 ReadPlayer(&tp); @@ -505,6 +512,7 @@ RAP_LoadPlayer( char *dchrobj; int size; int rval, loop; + size_t flen; FILE *handle; OBJ inobj; @@ -518,9 +526,9 @@ RAP_LoadPlayer( memset(&plr, 0, sizeof(plr)); if (cdflag) - sprintf(filename, cdfmt, cdpath, filepos); + snprintf(filename, sizeof(filename), CDFMT, cdpath, loop); else - sprintf(filename, fmt, filepos); + snprintf(filename, sizeof(filename), FMT, loop); handle = fopen(filename, "rb"); @@ -538,13 +546,22 @@ RAP_LoadPlayer( savebuffer = (char*)malloc(size); dchrobj = (char*)malloc(size - sizeof(plr)); - fread(dchrplr, 1, sizeof(plr), handle); + flen = fread(dchrplr, 1, sizeof(plr), handle); + if(flen != sizeof(plr)) + { + EXIT_Error("Error reading save file.\n"); + } fseek(handle, sizeof(plr), SEEK_SET); GLB_DeCrypt(gdmodestr, dchrplr, sizeof(plr)); memcpy(savebuffer, dchrplr, sizeof(plr)); - fread(dchrobj, 1, size - sizeof(plr), handle); + flen = fread(dchrobj, 1, size - sizeof(plr), handle); + + if(flen != (size - sizeof(plr))) + { + EXIT_Error("Error reading save file.\n"); + } GLB_DeCrypt(gdmodestr, dchrobj, size - sizeof(plr)); @@ -609,9 +626,9 @@ RAP_SavePlayer( EXIT_Error("RAP_Save() ERR: Try to save Dead player"); if (cdflag) - sprintf(filename, cdfmt, cdpath, filepos); + snprintf(filename, sizeof(filename), CDFMT, cdpath, filepos); else - sprintf(filename, fmt, filepos); + snprintf(filename, sizeof(filename), FMT, filepos); handle = fopen(filename, "wb"); @@ -761,15 +778,15 @@ RAP_LoadWin( for (loop = 0; loop < MAX_SAVE; loop++) { if (cdflag) - sprintf(temp, cdfmt, cdpath, loop); + snprintf(temp, sizeof(temp), CDFMT, cdpath, loop); else - sprintf(temp, fmt, loop); + snprintf(temp, sizeof(temp), FMT, loop); if (!access(temp, 0)) { if (pos == -1) pos = loop; - strncpy(filenames[loop], temp, PATH_MAX); + strncpy(filenames[loop], temp, sizeof(temp)); } } From a995506fdf65eef5665f1151e3860e57816c83ad Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 11:28:24 -0800 Subject: [PATCH 11/14] Fixed a bug I made by using the len of the fread to drive GLB_DeCrypt --- src/glbapi.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/glbapi.cpp b/src/glbapi.cpp index 88e51d5..da6e4b3 100644 --- a/src/glbapi.cpp +++ b/src/glbapi.cpp @@ -291,9 +291,8 @@ GLB_NumItems( fseek(handle, 0L, SEEK_SET); if (!fread(&key, sizeof(KEYFILE), 1, handle)) - { EXIT_Error("GLB_NumItems: Read failed!"); - } + #ifdef _SCOTTGAME GLB_DeCrypt(serial, (uint8_t*)&key, sizeof(KEYFILE)); @@ -314,7 +313,6 @@ GLB_LoadIDT( int j; int k; int n; - size_t flen; KEYFILE key[10]; ITEMINFO* ii; @@ -330,7 +328,8 @@ GLB_LoadIDT( if (k > (int)ASIZE(key)) k = ASIZE(key); - flen = fread(key, sizeof(KEYFILE), k, handle); + if (!fread(key, sizeof(KEYFILE), k, handle)) + EXIT_Error("GLB_NumItems: Read failed!"); for (n = 0; n < k; n++) { @@ -440,7 +439,6 @@ GLB_Load( { FILE *handle; ITEMINFO* ii; - size_t flen; ASSERT(filenum >= 0 && filenum < num_glbs); handle = filedesc[filenum].handle; @@ -460,11 +458,13 @@ GLB_Load( else { fseek(handle, ii->offset, SEEK_SET); - flen = fread(inmem, ii->size, 1, handle); + if(!fread(inmem, ii->size, 1, handle)) + EXIT_Error("GLB_Load: Failed to read data\n"); + #ifdef _SCOTTGAME if (ii->flags & ITF_ENCODED) { - GLB_DeCrypt(serial, inmem, flen); + GLB_DeCrypt(serial, inmem, ii->size); } #endif } From a320b18d12e61d3f3c1559447fb3e7fa0a4e009a Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 11:41:57 -0800 Subject: [PATCH 12/14] Fixed a were loadsave should have been using filepos --- src/loadsave.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/loadsave.cpp b/src/loadsave.cpp index efe5f1b..9878b61 100644 --- a/src/loadsave.cpp +++ b/src/loadsave.cpp @@ -526,9 +526,9 @@ RAP_LoadPlayer( memset(&plr, 0, sizeof(plr)); if (cdflag) - snprintf(filename, sizeof(filename), CDFMT, cdpath, loop); + snprintf(filename, sizeof(filename), CDFMT, cdpath, filepos); else - snprintf(filename, sizeof(filename), FMT, loop); + snprintf(filename, sizeof(filename), FMT, filepos); handle = fopen(filename, "rb"); From b8eefff0e74649fb3f2537b038f1d15b088e0255 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 11:46:56 -0800 Subject: [PATCH 13/14] Fixed error handling of ftruncate. --- src/prefapi.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/prefapi.cpp b/src/prefapi.cpp index f9b8016..e64b03f 100644 --- a/src/prefapi.cpp +++ b/src/prefapi.cpp @@ -260,7 +260,8 @@ WritePrivateProfileString( chsize(fileno(fptr), pos1); #endif #ifdef __GNUC__ - int flen = ftruncate(fileno(fptr), pos1); + if(ftruncate(fileno(fptr), pos1)) + EXIT_Error("WritePrivateProfileString: ftruncate Failed.\n"); #endif } else if (delta > 0) // Expand file, starting at the end From ade17425ba02dad50614d650a1acf3e8ecbeca12 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Fri, 20 Dec 2024 11:55:27 -0800 Subject: [PATCH 14/14] Fixed some type mismatches and removed unused vars. All handles now use Uint32_t in all function in glbapi.cpp --- src/demo.cpp | 4 +--- src/gfxapi.cpp | 2 +- src/glbapi.cpp | 19 +++++++++---------- src/glbapi.h | 18 +++++++++--------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/demo.cpp b/src/demo.cpp index 51177a2..ba60d7e 100644 --- a/src/demo.cpp +++ b/src/demo.cpp @@ -184,9 +184,7 @@ DEMO_LoadFile( void ) { - int filesize; - - filesize = GLB_ReadFile(demo_name, 0); + GLB_ReadFile(demo_name, 0); GLB_ReadFile(demo_name, (char*)playback); cur_play = 1; diff --git a/src/gfxapi.cpp b/src/gfxapi.cpp index 2affd83..1424d81 100644 --- a/src/gfxapi.cpp +++ b/src/gfxapi.cpp @@ -1522,7 +1522,7 @@ GFX_StrPixelLen( for (loop = 0; loop < maxloop; loop++) { - outlen += infont->width[instr[loop]] + fontspacing; + outlen += infont->width[(int)instr[loop]] + fontspacing; } return outlen; diff --git a/src/glbapi.cpp b/src/glbapi.cpp index da6e4b3..12be3b7 100644 --- a/src/glbapi.cpp +++ b/src/glbapi.cpp @@ -179,7 +179,6 @@ GLB_FindFile( * create a file name and attempt to open it local first, then if it * fails use the exe path and try again. */ - int lookat = 0; char *name = (char*)malloc((strlen(prefix)+9) * sizeof(char)); sprintf(name, "%s%04u.GLB", prefix, filenum); filename = GLB_FindFilePath(name); @@ -555,7 +554,7 @@ GLB_FetchItem( ***************************************************************************/ char* GLB_CacheItem( - int handle + uint32_t handle ) { return GLB_FetchItem(handle, FI_CACHE); @@ -566,7 +565,7 @@ GLB_CacheItem( ***************************************************************************/ char* GLB_GetItem( - int handle // INPUT : handle of item + uint32_t handle // INPUT : handle of item ) { return GLB_FetchItem(handle, FI_DISCARD); @@ -577,7 +576,7 @@ GLB_GetItem( ***************************************************************************/ char* GLB_LockItem( - int handle + uint32_t handle ) { return GLB_FetchItem(handle, FI_LOCK); @@ -588,7 +587,7 @@ GLB_LockItem( ***************************************************************************/ void GLB_UnlockItem( - int handle + uint32_t handle ) { ITEM_H itm; @@ -628,7 +627,7 @@ GLB_UnlockItem( ***************************************************************************/ int // RETURN: TRUE = Label GLB_IsLabel( - int handle // INPUT : handle of item + uint32_t handle // INPUT : handle of item ) { ITEM_H itm; @@ -653,7 +652,7 @@ GLB_IsLabel( ***************************************************************************/ void GLB_ReadItem( - int handle, // INPUT : handle of item + uint32_t handle, // INPUT : handle of item char* mem // INPUT : pointer to memory ) { @@ -725,7 +724,7 @@ GLB_GetItemID( ***************************************************************************/ char* // RETURN: pointer to item GLB_GetPtr( - int handle // INPUT : handle of item + uint32_t handle // INPUT : handle of item ) { ITEM_H itm; @@ -751,7 +750,7 @@ GLB_GetPtr( ***************************************************************************/ void GLB_FreeItem( - int handle // INPUT : handle of item + uint32_t handle // INPUT : handle of item ) { ITEM_H itm; @@ -824,7 +823,7 @@ GLB_FreeAll( ***************************************************************************/ int // RETURN: sizeof ITEM GLB_ItemSize( - int handle // INPUT : handle of item + uint32_t handle // INPUT : handle of item ) { ITEM_H itm; diff --git a/src/glbapi.h b/src/glbapi.h index 2e17852..4c8e7e1 100644 --- a/src/glbapi.h +++ b/src/glbapi.h @@ -23,22 +23,22 @@ typedef struct void GLB_UseVM(void); int GLB_InitSystem(const char *exepath, int innum, const char *iprefix); -char *GLB_LockItem(int handle); -void GLB_UnlockItem(int handle); -char *GLB_GetItem(int handle); -char *GLB_CacheItem(int handle); -void GLB_FreeItem(int handle); +char *GLB_LockItem(uint32_t handle); +void GLB_UnlockItem(uint32_t handle); +char *GLB_GetItem(uint32_t handle); +char *GLB_CacheItem(uint32_t handle); +void GLB_FreeItem(uint32_t handle); void GLB_FreeAll(void); int GLB_GetItemID(const char *in_name); -int GLB_ItemSize(int handle); +int GLB_ItemSize(uint32_t handle); void GLB_EnCrypt(const char *key, void *buf, int length); void GLB_DeCrypt(const char *key, void *buf, int length); int GLB_ReadFile(const char *name, char *buffer); void GLB_SaveFile(char *name, char *buffer, int length); int GLB_Load(char *inmem, int filenum, int itemnum); -int GLB_IsLabel(int handle); -void GLB_ReadItem(int handle, char *mem); +int GLB_IsLabel(uint32_t handle); +void GLB_ReadItem(uint32_t handle, char *mem); char * GLB_FindFilePath(char *file); -//char *GLB_GetPtr(int handle); +//char *GLB_GetPtr(uint32_t handle); //void GLB_SetItemPointer(int a1, char* a2); //void GLB_SetItemSize(int a1, int a2); \ No newline at end of file