From a2fe28e6df10af23e1459fad28f66db78474e0c1 Mon Sep 17 00:00:00 2001 From: Toni Riikonen Date: Mon, 3 Nov 2025 21:48:11 +0200 Subject: [PATCH] Limit audio profile selection to the identical tracks. 40 track audio profiles for 40 track drives, 80 track profiles to 80 track drives. --- src/floppy/fdd.c | 9 ++++++ src/include/86box/fdd.h | 1 + src/qt/qt_settingsfloppycdrom.cpp | 50 +++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/floppy/fdd.c b/src/floppy/fdd.c index bde431d69..2b5765e41 100644 --- a/src/floppy/fdd.c +++ b/src/floppy/fdd.c @@ -430,6 +430,15 @@ fdd_track0(int drive) return !fdd[drive].track; } +int +fdd_get_type_max_track(int type) +{ + if (type < 0 || type >= (sizeof(drive_types) / sizeof(drive_types[0]))) + return 0; + + return drive_types[type].max_track; +} + int fdd_current_track(int drive) { diff --git a/src/include/86box/fdd.h b/src/include/86box/fdd.h index 81ab4dd15..b10c34854 100644 --- a/src/include/86box/fdd.h +++ b/src/include/86box/fdd.h @@ -36,6 +36,7 @@ extern void fdd_do_seek(int drive, int track); extern void fdd_forced_seek(int drive, int track_diff); extern void fdd_seek(int drive, int track_diff); extern int fdd_track0(int drive); +extern int fdd_get_type_max_track(int type); extern int fdd_getrpm(int drive); extern void fdd_set_densel(int densel); extern int fdd_can_read_medium(int drive); diff --git a/src/qt/qt_settingsfloppycdrom.cpp b/src/qt/qt_settingsfloppycdrom.cpp index 8ba860e0f..4b7b86b49 100644 --- a/src/qt/qt_settingsfloppycdrom.cpp +++ b/src/qt/qt_settingsfloppycdrom.cpp @@ -309,8 +309,51 @@ SettingsFloppyCDROM::onFloppyRowChanged(const QModelIndex ¤t) ui->checkBoxCheckBPB->setChecked(current.siblingAtColumn(2).data() == tr("On")); int prof = current.siblingAtColumn(3).data(Qt::UserRole).toInt(); + +#ifndef DISABLE_FDD_AUDIO + // Rebuild audio profile combo box based on drive type + int row = current.row(); + ui->comboBoxFloppyAudio->clear(); + + // Get drive type's track count to determine 40-track vs 80-track + int drive_max_tracks = fdd_get_type_max_track(type); + bool is_40_track = (drive_max_tracks <= 43); + + int profile_count = fdd_audio_get_profile_count(); + int currentProfileIndex = -1; + int comboIndex = 0; + + for (int i = 0; i < profile_count; i++) { + const char *name = fdd_audio_get_profile_name(i); + if (name) { + const fdd_audio_profile_config_t *profile = fdd_audio_get_profile(i); + if (profile) { + // Only show profiles that match the drive type's track count + if ((is_40_track && profile->total_tracks == 40) || (!is_40_track && profile->total_tracks == 80) || profile->total_tracks == 0) { // Profile ID 0 is "None" + ui->comboBoxFloppyAudio->addItem(name, i); + if (i == prof) { + currentProfileIndex = comboIndex; + } + comboIndex++; + } + } + } + } + + // If current profile is not compatible, select "None" (profile 0) + if (currentProfileIndex == -1) { + currentProfileIndex = ui->comboBoxFloppyAudio->findData(0); + // Update the model to reflect "None" profile + auto audioIdx = current.siblingAtColumn(3); + ui->tableViewFloppy->model()->setData(audioIdx, tr("None")); + ui->tableViewFloppy->model()->setData(audioIdx, 0, Qt::UserRole); + } + + ui->comboBoxFloppyAudio->setCurrentIndex(currentProfileIndex); +#else int comboIndex = ui->comboBoxFloppyAudio->findData(prof); ui->comboBoxFloppyAudio->setCurrentIndex(comboIndex); +#endif } void @@ -386,8 +429,11 @@ SettingsFloppyCDROM::on_checkBoxCheckBPB_stateChanged(int arg1) void SettingsFloppyCDROM::on_comboBoxFloppyType_activated(int index) { - setFloppyType(ui->tableViewFloppy->model(), - ui->tableViewFloppy->selectionModel()->currentIndex(), index); + auto currentIndex = ui->tableViewFloppy->selectionModel()->currentIndex(); + setFloppyType(ui->tableViewFloppy->model(), currentIndex, index); + + // Trigger row changed to rebuild audio profile list + onFloppyRowChanged(currentIndex); } void