From c95424b8d9b15f7e3faa16e82e78eceedf2b4a41 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 18 Apr 2023 15:03:26 -0300 Subject: [PATCH 1/4] config: Migrate standalone SSI-2001, CMS and GUS from v3.11 and older --- src/config.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 6399c91ab..4b94fb2ac 100644 --- a/src/config.c +++ b/src/config.c @@ -718,6 +718,20 @@ load_sound(void) mpu401_standalone_enable = !!ini_section_get_int(cat, "mpu401_standalone", 0); + /* Backwards compatibility for standalone SSI-2001, CMS and GUS from v3.11 and older. */ + char *legacy_cards[][2] = {{"ssi2001", "ssi2001"}, {"gameblaster", "cms"}, {"gus", "gus"}}; + for (int i = 0, j = 0; i < (sizeof(legacy_cards) / sizeof(legacy_cards[0])); i++) { + if (ini_section_get_int(cat, legacy_cards[i][0], 0) == 1) { + /* Migrate to the first available sound card slot. */ + for (; j < (sizeof(sound_card_current) / sizeof(sound_card_current[0])); j++) { + if (!sound_card_current[j]) { + sound_card_current[j] = sound_card_get_from_internal_name(legacy_cards[i][1]); + break; + } + } + } + } + memset(temp, '\0', sizeof(temp)); p = ini_section_get_string(cat, "sound_type", "float"); if (strlen(p) > 511) @@ -2159,7 +2173,7 @@ save_machine(void) else ini_section_delete_var(cat, "cpu_override"); - /* Forwards compatibility with the previous CPU model system. */ + /* Downgrade compatibility with the previous CPU model system. */ ini_section_delete_var(cat, "cpu_manufacturer"); ini_section_delete_var(cat, "cpu"); @@ -2390,6 +2404,23 @@ save_sound(void) else ini_section_set_int(cat, "mpu401_standalone", mpu401_standalone_enable); + /* Downgrade compatibility for standalone SSI-2001, CMS and GUS from v3.11 and older. */ + char *legacy_cards[][2] = {{"ssi2001", "ssi2001"}, {"gameblaster", "cms"}, {"gus", "gus"}}; + for (int i = 0; i < (sizeof(legacy_cards) / sizeof(legacy_cards[0])); i++) { + int card_id = sound_card_get_from_internal_name(legacy_cards[i][1]); + for (int j = 0; j < (sizeof(sound_card_current) / sizeof(sound_card_current[0])); j++) { + if (sound_card_current[j] == card_id) { + /* A special value of 2 still enables the cards on older versions, + but lets newer versions know that they've already been migrated. */ + ini_section_set_int(cat, legacy_cards[i][0], 2); + card_id = 0; /* mark as found */ + break; + } + } + if (card_id > 0) /* not found */ + ini_section_delete_var(cat, legacy_cards[i][0]); + } + if (sound_is_float == 1) ini_section_delete_var(cat, "sound_type"); else From fb8ef3e40c6819b9d5624fb85e1d2d97ddf6331f Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 18 Apr 2023 16:14:44 -0300 Subject: [PATCH 2/4] ini: Constify parameters to optimize execution --- src/config.c | 4 ++-- src/include/86box/ini.h | 40 +++++++++++++++++----------------- src/include/86box/sound.h | 2 +- src/ini.c | 46 +++++++++++++++++++-------------------- src/sound/sound.c | 2 +- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/config.c b/src/config.c index 4b94fb2ac..96f9374ef 100644 --- a/src/config.c +++ b/src/config.c @@ -719,7 +719,7 @@ load_sound(void) mpu401_standalone_enable = !!ini_section_get_int(cat, "mpu401_standalone", 0); /* Backwards compatibility for standalone SSI-2001, CMS and GUS from v3.11 and older. */ - char *legacy_cards[][2] = {{"ssi2001", "ssi2001"}, {"gameblaster", "cms"}, {"gus", "gus"}}; + const char *legacy_cards[][2] = {{"ssi2001", "ssi2001"}, {"gameblaster", "cms"}, {"gus", "gus"}}; for (int i = 0, j = 0; i < (sizeof(legacy_cards) / sizeof(legacy_cards[0])); i++) { if (ini_section_get_int(cat, legacy_cards[i][0], 0) == 1) { /* Migrate to the first available sound card slot. */ @@ -2405,7 +2405,7 @@ save_sound(void) ini_section_set_int(cat, "mpu401_standalone", mpu401_standalone_enable); /* Downgrade compatibility for standalone SSI-2001, CMS and GUS from v3.11 and older. */ - char *legacy_cards[][2] = {{"ssi2001", "ssi2001"}, {"gameblaster", "cms"}, {"gus", "gus"}}; + const char *legacy_cards[][2] = {{"ssi2001", "ssi2001"}, {"gameblaster", "cms"}, {"gus", "gus"}}; for (int i = 0; i < (sizeof(legacy_cards) / sizeof(legacy_cards[0])); i++) { int card_id = sound_card_get_from_internal_name(legacy_cards[i][1]); for (int j = 0; j < (sizeof(sound_card_current) / sizeof(sound_card_current[0])); j++) { diff --git a/src/include/86box/ini.h b/src/include/86box/ini.h index 5eca9ab8c..866787352 100644 --- a/src/include/86box/ini.h +++ b/src/include/86box/ini.h @@ -30,26 +30,26 @@ typedef void *ini_t; typedef void *ini_section_t; extern ini_t ini_new(void); -extern ini_t ini_read(char *fn); -extern void ini_write(ini_t ini, char *fn); +extern ini_t ini_read(const char *fn); +extern void ini_write(ini_t ini, const char *fn); extern void ini_dump(ini_t ini); extern void ini_close(ini_t ini); -extern void ini_section_delete_var(ini_section_t section, char *name); -extern int ini_section_get_int(ini_section_t section, char *name, int def); -extern double ini_section_get_double(ini_section_t section, char *name, double def); -extern int ini_section_get_hex16(ini_section_t section, char *name, int def); -extern int ini_section_get_hex20(ini_section_t section, char *name, int def); -extern int ini_section_get_mac(ini_section_t section, char *name, int def); -extern char *ini_section_get_string(ini_section_t section, char *name, char *def); -extern wchar_t *ini_section_get_wstring(ini_section_t section, char *name, wchar_t *def); -extern void ini_section_set_int(ini_section_t section, char *name, int val); -extern void ini_section_set_double(ini_section_t section, char *name, double val); -extern void ini_section_set_hex16(ini_section_t section, char *name, int val); -extern void ini_section_set_hex20(ini_section_t section, char *name, int val); -extern void ini_section_set_mac(ini_section_t section, char *name, int val); +extern void ini_section_delete_var(ini_section_t section, const char *name); +extern int ini_section_get_int(ini_section_t section, const char *name, int def); +extern double ini_section_get_double(ini_section_t section, const char *name, double def); +extern int ini_section_get_hex16(ini_section_t section, const char *name, int def); +extern int ini_section_get_hex20(ini_section_t section, const char *name, int def); +extern int ini_section_get_mac(ini_section_t section, const char *name, int def); +extern char *ini_section_get_string(ini_section_t section, const char *name, char *def); +extern wchar_t *ini_section_get_wstring(ini_section_t section, const char *name, wchar_t *def); +extern void ini_section_set_int(ini_section_t section, const char *name, int val); +extern void ini_section_set_double(ini_section_t section, const char *name, double val); +extern void ini_section_set_hex16(ini_section_t section, const char *name, int val); +extern void ini_section_set_hex20(ini_section_t section, const char *name, int val); +extern void ini_section_set_mac(ini_section_t section, const char *name, int val); extern void ini_section_set_string(ini_section_t section, const char *name, const char *val); -extern void ini_section_set_wstring(ini_section_t section, char *name, wchar_t *val); +extern void ini_section_set_wstring(ini_section_t section, const char *name, wchar_t *val); #define ini_delete_var(ini, head, name) ini_section_delete_var(ini_find_section(ini, head), name) @@ -69,13 +69,13 @@ extern void ini_section_set_wstring(ini_section_t section, char *name, wchar #define ini_set_string(ini, head, name, val) ini_section_set_string(ini_find_or_create_section(ini, head), name, val) #define ini_set_wstring(ini, head, name, val) ini_section_set_wstring(ini_find_or_create_section(ini, head), name, val) -extern ini_section_t ini_find_section(ini_t ini, char *name); -extern ini_section_t ini_find_or_create_section(ini_t ini, char *name); -extern void ini_rename_section(ini_section_t section, char *name); +extern ini_section_t ini_find_section(ini_t ini, const char *name); +extern ini_section_t ini_find_or_create_section(ini_t ini, const char *name); +extern void ini_rename_section(ini_section_t section, const char *name); extern void ini_delete_section_if_empty(ini_t ini, ini_section_t section); #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif diff --git a/src/include/86box/sound.h b/src/include/86box/sound.h index dada9e164..1cb9357a6 100644 --- a/src/include/86box/sound.h +++ b/src/include/86box/sound.h @@ -62,7 +62,7 @@ extern const device_t *sound_card_getdevice(int card); #endif extern int sound_card_has_config(int card); extern char *sound_card_get_internal_name(int card); -extern int sound_card_get_from_internal_name(char *s); +extern int sound_card_get_from_internal_name(const char *s); extern void sound_card_init(void); extern void sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r); diff --git a/src/ini.c b/src/ini.c index 009d21c0b..d41573bed 100644 --- a/src/ini.c +++ b/src/ini.c @@ -101,10 +101,10 @@ ini_log(const char *fmt, ...) #endif static section_t * -find_section(list_t *head, char *name) +find_section(list_t *head, const char *name) { section_t *sec = (section_t *) head->next; - char blank[] = ""; + const char blank[] = ""; if (name == NULL) name = blank; @@ -120,7 +120,7 @@ find_section(list_t *head, char *name) } ini_section_t -ini_find_section(ini_t ini, char *name) +ini_find_section(ini_t ini, const char *name) { if (ini == NULL) return NULL; @@ -129,7 +129,7 @@ ini_find_section(ini_t ini, char *name) } void -ini_rename_section(ini_section_t section, char *name) +ini_rename_section(ini_section_t section, const char *name) { section_t *sec = (section_t *) section; @@ -197,7 +197,7 @@ ini_delete_section_if_empty(ini_t ini, ini_section_t section) } static section_t * -create_section(list_t *head, char *name) +create_section(list_t *head, const char *name) { section_t *ns = malloc(sizeof(section_t)); @@ -209,7 +209,7 @@ create_section(list_t *head, char *name) } ini_section_t -ini_find_or_create_section(ini_t ini, char *name) +ini_find_or_create_section(ini_t ini, const char *name) { if (ini == NULL) return NULL; @@ -263,7 +263,7 @@ ini_close(ini_t ini) } static int -ini_detect_bom(char *fn) +ini_detect_bom(const char *fn) { FILE *f; unsigned char bom[4] = { 0, 0, 0, 0 }; @@ -311,7 +311,7 @@ ini_fgetws(wchar_t *str, int count, FILE *stream) /* Read and parse the configuration file into memory. */ ini_t -ini_read(char *fn) +ini_read(const char *fn) { char sname[128], ename[128]; wchar_t buff[1024]; @@ -438,7 +438,7 @@ ini_read(char *fn) /* Write the in-memory configuration to disk. */ void -ini_write(ini_t ini, char *fn) +ini_write(ini_t ini, const char *fn) { wchar_t wtemp[512]; list_t *list = (list_t *) ini; @@ -521,7 +521,7 @@ ini_dump(ini_t ini) } void -ini_section_delete_var(ini_section_t self, char *name) +ini_section_delete_var(ini_section_t self, const char *name) { section_t *section = (section_t *) self; entry_t *entry; @@ -537,7 +537,7 @@ ini_section_delete_var(ini_section_t self, char *name) } int -ini_section_get_int(ini_section_t self, char *name, int def) +ini_section_get_int(ini_section_t self, const char *name, int def) { section_t *section = (section_t *) self; entry_t *entry; @@ -556,7 +556,7 @@ ini_section_get_int(ini_section_t self, char *name, int def) } double -ini_section_get_double(ini_section_t self, char *name, double def) +ini_section_get_double(ini_section_t self, const char *name, double def) { section_t *section = (section_t *) self; entry_t *entry; @@ -575,7 +575,7 @@ ini_section_get_double(ini_section_t self, char *name, double def) } int -ini_section_get_hex16(ini_section_t self, char *name, int def) +ini_section_get_hex16(ini_section_t self, const char *name, int def) { section_t *section = (section_t *) self; entry_t *entry; @@ -594,7 +594,7 @@ ini_section_get_hex16(ini_section_t self, char *name, int def) } int -ini_section_get_hex20(ini_section_t self, char *name, int def) +ini_section_get_hex20(ini_section_t self, const char *name, int def) { section_t *section = (section_t *) self; entry_t *entry; @@ -613,7 +613,7 @@ ini_section_get_hex20(ini_section_t self, char *name, int def) } int -ini_section_get_mac(ini_section_t self, char *name, int def) +ini_section_get_mac(ini_section_t self, const char *name, int def) { section_t *section = (section_t *) self; entry_t *entry; @@ -632,7 +632,7 @@ ini_section_get_mac(ini_section_t self, char *name, int def) } char * -ini_section_get_string(ini_section_t self, char *name, char *def) +ini_section_get_string(ini_section_t self, const char *name, char *def) { section_t *section = (section_t *) self; entry_t *entry; @@ -648,7 +648,7 @@ ini_section_get_string(ini_section_t self, char *name, char *def) } wchar_t * -ini_section_get_wstring(ini_section_t self, char *name, wchar_t *def) +ini_section_get_wstring(ini_section_t self, const char *name, wchar_t *def) { section_t *section = (section_t *) self; entry_t *entry; @@ -664,7 +664,7 @@ ini_section_get_wstring(ini_section_t self, char *name, wchar_t *def) } void -ini_section_set_int(ini_section_t self, char *name, int val) +ini_section_set_int(ini_section_t self, const char *name, int val) { section_t *section = (section_t *) self; entry_t *ent; @@ -681,7 +681,7 @@ ini_section_set_int(ini_section_t self, char *name, int val) } void -ini_section_set_double(ini_section_t self, char *name, double val) +ini_section_set_double(ini_section_t self, const char *name, double val) { section_t *section = (section_t *) self; entry_t *ent; @@ -698,7 +698,7 @@ ini_section_set_double(ini_section_t self, char *name, double val) } void -ini_section_set_hex16(ini_section_t self, char *name, int val) +ini_section_set_hex16(ini_section_t self, const char *name, int val) { section_t *section = (section_t *) self; entry_t *ent; @@ -715,7 +715,7 @@ ini_section_set_hex16(ini_section_t self, char *name, int val) } void -ini_section_set_hex20(ini_section_t self, char *name, int val) +ini_section_set_hex20(ini_section_t self, const char *name, int val) { section_t *section = (section_t *) self; entry_t *ent; @@ -732,7 +732,7 @@ ini_section_set_hex20(ini_section_t self, char *name, int val) } void -ini_section_set_mac(ini_section_t self, char *name, int val) +ini_section_set_mac(ini_section_t self, const char *name, int val) { section_t *section = (section_t *) self; entry_t *ent; @@ -774,7 +774,7 @@ ini_section_set_string(ini_section_t self, const char *name, const char *val) } void -ini_section_set_wstring(ini_section_t self, char *name, wchar_t *val) +ini_section_set_wstring(ini_section_t self, const char *name, wchar_t *val) { section_t *section = (section_t *) self; entry_t *ent; diff --git a/src/sound/sound.c b/src/sound/sound.c index dbfaf0fdb..d8791d0cf 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -202,7 +202,7 @@ sound_card_get_internal_name(int card) } int -sound_card_get_from_internal_name(char *s) +sound_card_get_from_internal_name(const char *s) { int c = 0; From 5813d425e95a78831df6f36f9a252e9f342794ae Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 18 Apr 2023 16:16:42 -0300 Subject: [PATCH 3/4] clang-format my previous commits --- src/config.c | 12 ++++++++++-- src/include/86box/sound.h | 12 ++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/config.c b/src/config.c index 96f9374ef..7641c637c 100644 --- a/src/config.c +++ b/src/config.c @@ -719,7 +719,11 @@ load_sound(void) mpu401_standalone_enable = !!ini_section_get_int(cat, "mpu401_standalone", 0); /* Backwards compatibility for standalone SSI-2001, CMS and GUS from v3.11 and older. */ - const char *legacy_cards[][2] = {{"ssi2001", "ssi2001"}, {"gameblaster", "cms"}, {"gus", "gus"}}; + const char *legacy_cards[][2] = { + {"ssi2001", "ssi2001"}, + { "gameblaster", "cms" }, + { "gus", "gus" } + }; for (int i = 0, j = 0; i < (sizeof(legacy_cards) / sizeof(legacy_cards[0])); i++) { if (ini_section_get_int(cat, legacy_cards[i][0], 0) == 1) { /* Migrate to the first available sound card slot. */ @@ -2405,7 +2409,11 @@ save_sound(void) ini_section_set_int(cat, "mpu401_standalone", mpu401_standalone_enable); /* Downgrade compatibility for standalone SSI-2001, CMS and GUS from v3.11 and older. */ - const char *legacy_cards[][2] = {{"ssi2001", "ssi2001"}, {"gameblaster", "cms"}, {"gus", "gus"}}; + const char *legacy_cards[][2] = { + {"ssi2001", "ssi2001"}, + { "gameblaster", "cms" }, + { "gus", "gus" } + }; for (int i = 0; i < (sizeof(legacy_cards) / sizeof(legacy_cards[0])); i++) { int card_id = sound_card_get_from_internal_name(legacy_cards[i][1]); for (int j = 0; j < (sizeof(sound_card_current) / sizeof(sound_card_current[0])); j++) { diff --git a/src/include/86box/sound.h b/src/include/86box/sound.h index 1cb9357a6..9f36a70b6 100644 --- a/src/include/86box/sound.h +++ b/src/include/86box/sound.h @@ -24,13 +24,13 @@ extern int sound_gain; -#define FREQ_44100 44100 -#define FREQ_48000 48000 -#define FREQ_49716 49716 -#define FREQ_88200 88200 -#define FREQ_96000 96000 +#define FREQ_44100 44100 +#define FREQ_48000 48000 +#define FREQ_49716 49716 +#define FREQ_88200 88200 +#define FREQ_96000 96000 -#define SOUND_FREQ FREQ_48000 +#define SOUND_FREQ FREQ_48000 #define SOUNDBUFLEN (SOUND_FREQ / 50) #define CD_FREQ FREQ_44100 From beb1df4f5cb9f0f9931389f80d60210bb2558401 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 18 Apr 2023 20:28:03 -0300 Subject: [PATCH 4/4] qt: Hide unused CD-ROM controller selector --- src/qt/qt_settingsstoragecontrollers.ui | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/qt/qt_settingsstoragecontrollers.ui b/src/qt/qt_settingsstoragecontrollers.ui index 558d4c441..9fc0ea519 100644 --- a/src/qt/qt_settingsstoragecontrollers.ui +++ b/src/qt/qt_settingsstoragecontrollers.ui @@ -54,16 +54,26 @@ CD-ROM Controller: + + false + - + + + false + + Configure + + false +