From 71ea73292eae78e5620a6610c2eadc3c6db80453 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 30 Jul 2025 13:08:23 +0200 Subject: [PATCH 1/9] MKE CD-ROM: Memset ver with 0x00's before calling cdrom_generate_name_mke(), should avoid garbage at the end of the name. --- src/cdrom/cdrom_mke.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cdrom/cdrom_mke.c b/src/cdrom/cdrom_mke.c index b156f173f..5203af9e9 100644 --- a/src/cdrom/cdrom_mke.c +++ b/src/cdrom/cdrom_mke.c @@ -903,6 +903,7 @@ mke_init(const device_t *info) mke->present = 1; + memset(ver, 0x00, 512); cdrom_generate_name_mke(dev->type, mke->ver); fifo8_create(&mke->info_fifo, 128); From 8d7e185ba58485e42f75f2b3a05252dffe2d9062 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 30 Jul 2025 13:09:13 +0200 Subject: [PATCH 2/9] Fix a compile-breaking mistake. --- src/cdrom/cdrom_mke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cdrom/cdrom_mke.c b/src/cdrom/cdrom_mke.c index 5203af9e9..24e9849e8 100644 --- a/src/cdrom/cdrom_mke.c +++ b/src/cdrom/cdrom_mke.c @@ -903,7 +903,7 @@ mke_init(const device_t *info) mke->present = 1; - memset(ver, 0x00, 512); + memset(mke->ver, 0x00, 512); cdrom_generate_name_mke(dev->type, mke->ver); fifo8_create(&mke->info_fifo, 128); From 9cb99ed47678bf009c8ed15adf85b5faacb7f6c7 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 30 Jul 2025 13:11:41 +0200 Subject: [PATCH 3/9] Also set an explicit 0x00 after the 10 bytes of ver. --- src/cdrom/cdrom_mke.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cdrom/cdrom_mke.c b/src/cdrom/cdrom_mke.c index 24e9849e8..2a57df588 100644 --- a/src/cdrom/cdrom_mke.c +++ b/src/cdrom/cdrom_mke.c @@ -905,6 +905,7 @@ mke_init(const device_t *info) memset(mke->ver, 0x00, 512); cdrom_generate_name_mke(dev->type, mke->ver); + mke->ver[10] = 0x00; fifo8_create(&mke->info_fifo, 128); fifo8_create(&mke->data_fifo, 624240 * 2); From 81ac0d786e0caa469a26f9f64d1a8e68ec397333 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Wed, 30 Jul 2025 16:22:26 +0500 Subject: [PATCH 4/9] Fix MKE bus channels 2 and 3 not being usable --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index ba02760ad..6801670d2 100644 --- a/src/config.c +++ b/src/config.c @@ -1396,7 +1396,7 @@ load_floppy_and_cdrom_drives(void) cdrom_set_type(c, cdrom_get_from_internal_name("cr563_075")); sprintf(temp, "cdrom_%02i_mke_channel", c + 1); - cdrom[c].mke_channel = !!ini_section_get_int(cat, temp, c & 3); + cdrom[c].mke_channel = ini_section_get_int(cat, temp, c & 3); if (cdrom[c].mke_channel > 3) cdrom[c].mke_channel = 3; From 9204c1b6d87f72e720eea99c0ea4e1a20fa555a1 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Wed, 30 Jul 2025 16:23:53 +0500 Subject: [PATCH 5/9] Qt: Explicitly set CD-ROM speed on a bus change --- src/qt/qt_settingsfloppycdrom.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/qt/qt_settingsfloppycdrom.cpp b/src/qt/qt_settingsfloppycdrom.cpp index cb8b15018..c47d6f772 100644 --- a/src/qt/qt_settingsfloppycdrom.cpp +++ b/src/qt/qt_settingsfloppycdrom.cpp @@ -414,6 +414,20 @@ SettingsFloppyCDROM::on_comboBoxBus_activated(int) setCDROMType(ui->tableViewCDROM->model(), ui->tableViewCDROM->selectionModel()->currentIndex(), ui->comboBoxCDROMType->currentData().toUInt()); + + int speed = cdrom_get_speed(ui->comboBoxCDROMType->currentData().toUInt()); + if ((speed == -1) && (bus_type != CDROM_BUS_MITSUMI)) { + speed = ui->comboBoxSpeed->currentData().toUInt(); + ui->comboBoxSpeed->setEnabled(bus_type != CDROM_BUS_DISABLED); + } else { + ui->comboBoxSpeed->setEnabled(false); + if (bus_type == CDROM_BUS_MITSUMI) // temp hack + speed = 0; + } + ui->comboBoxSpeed->setCurrentIndex(speed == 0 ? 7 : speed - 1); + setCDROMSpeed(ui->tableViewCDROM->model(), + ui->tableViewCDROM->selectionModel()->currentIndex(), + speed); emit cdromChannelChanged(); } From 72a5c0add48cd513cf344978236ef9c5ccc97bbd Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Wed, 30 Jul 2025 16:24:19 +0500 Subject: [PATCH 6/9] Qt: Disable the CD-ROM speed dropdown on disabled entries --- src/qt/qt_settingsfloppycdrom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qt_settingsfloppycdrom.cpp b/src/qt/qt_settingsfloppycdrom.cpp index c47d6f772..f597aebe6 100644 --- a/src/qt/qt_settingsfloppycdrom.cpp +++ b/src/qt/qt_settingsfloppycdrom.cpp @@ -277,7 +277,7 @@ SettingsFloppyCDROM::onCDROMRowChanged(const QModelIndex ¤t) int speed = cdrom_get_speed(type); if (speed == -1) { speed = current.siblingAtColumn(1).data(Qt::UserRole).toUInt(); - ui->comboBoxSpeed->setEnabled(true); + ui->comboBoxSpeed->setEnabled((bus == CDROM_BUS_DISABLED) ? false : true); } else ui->comboBoxSpeed->setEnabled(false); ui->comboBoxSpeed->setCurrentIndex(speed == 0 ? 7 : speed - 1); From 4537db483045e090a66db262752b988898f1abf7 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 30 Jul 2025 15:04:30 +0200 Subject: [PATCH 7/9] PIC: Ignore IRQ raise or lower then the PIC is not yet properly set up. --- src/pic.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pic.c b/src/pic.c index 4b8993322..446ea1361 100644 --- a/src/pic.c +++ b/src/pic.c @@ -693,6 +693,13 @@ picint_common(uint16_t num, int level, int set, uint8_t *irq_state) uint16_t lines = level ? 0x0000 : num; pic_t *dev; + /* + Do this because some emulated cards will, for whatever reason, attempt to + raise an IRQ at init when the PIC has not yet been properly initialized. + */ + if (update_pending == NULL) + return; + /* Make sure to ignore all slave IRQ's, and in case of AT+, translate IRQ 2 to IRQ 9. */ for (uint8_t i = 0; i < 8; i++) { From 325887a5671e831bcfc164aa6a0066c71c6dd39b Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 30 Jul 2025 16:31:11 +0200 Subject: [PATCH 8/9] MKE CD-ROM: Fix TOC and multi-session reading, fixes the Windows 95 built-in driver with the non-Creative interface. --- src/cdrom/cdrom_mke.c | 123 +++++++++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 31 deletions(-) diff --git a/src/cdrom/cdrom_mke.c b/src/cdrom/cdrom_mke.c index 2a57df588..495d3d103 100644 --- a/src/cdrom/cdrom_mke.c +++ b/src/cdrom/cdrom_mke.c @@ -326,8 +326,8 @@ mke_get_subq(mke_t *mke, uint8_t *b) } /* Lifted from FreeBSD */ - -static void blk_to_msf(int blk, unsigned char *msf) +static void +blk_to_msf(int blk, unsigned char *msf) { blk = blk + 150; /* 2 seconds skip required to reach ISO data */ @@ -339,28 +339,50 @@ static void blk_to_msf(int blk, unsigned char *msf) return; } -uint8_t mke_read_toc(mke_t *mke, unsigned char *b, uint8_t track) { - cdrom_t *dev = mke->cdrom_dev; +uint8_t +mke_read_toc(mke_t *mke, unsigned char *b, uint8_t track) { + cdrom_t *dev = mke->cdrom_dev; +#if 0 track_info_t ti; int last_track; +#endif + const raw_track_info_t *trti = (raw_track_info_t *) mke->temp_buf; + int num = 0; + int ret = 0; - cdrom_read_toc(dev, mke->temp_buf, CD_TOC_NORMAL, 0, 0, 65536); - last_track = mke->temp_buf[3]; - /* Should we allow +1 here? */ - if (track > last_track) - return 0; - dev->ops->get_track_info(dev->local, track, 0, &ti); - b[0]=0; - b[1]=ti.attr; - b[2]=ti.number; - b[3]=0; - b[4]=ti.m; - b[5]=ti.s; - b[6]=ti.f; - b[7]=0; - mke_log("mke_read_toc: 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n", - b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]); - return 1; + dev->ops->get_raw_track_info(dev->local, &num, mke->temp_buf); + + if (num > 0) { + if (track == 0xaa) + track = 0xa2; + + int trk = - 1; + + for (int i = (num - 1); i >= 0; i--) { + if (trti[i].point == track) { + trk = i; + break; + } + } + + if (trk != -1) { + b[0] = 0; + b[1] = trti[trk].adr_ctl; + b[2] = (trti[trk].point == 0xa2) ? 0xaa : trti[trk].point; + b[3] = 0; + b[4] = trti[trk].pm; + b[5] = trti[trk].ps; + b[6] = trti[trk].pf; + b[7] = 0; + + ret = 1; + } + + mke_log("mke_read_toc: 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n", + b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]); + } + + return ret; } @@ -407,17 +429,56 @@ mke_disc_capacity(cdrom_t *dev, unsigned char *b) void mke_read_multisess(mke_t *mke) { - if ((mke->temp_buf[9] != 0) || (mke->temp_buf[10] != 0) || (mke->temp_buf[11] != 0)) { - /* Multi-session disc. */ - fifo8_push(&mke->info_fifo, 0x80); - fifo8_push(&mke->info_fifo, mke->temp_buf[9]); - fifo8_push(&mke->info_fifo, mke->temp_buf[10]); - fifo8_push(&mke->info_fifo, mke->temp_buf[11]); - fifo8_push(&mke->info_fifo, 0); - fifo8_push(&mke->info_fifo, 0); + cdrom_t *dev = mke->cdrom_dev; + uint8_t *b = (uint8_t *) &(mke->temp_buf[32768]); + const raw_track_info_t *trti = (raw_track_info_t *) mke->temp_buf; + int num = 0; + int first_sess = 0; + int last_sess = 0; + + dev->ops->get_raw_track_info(dev->local, &num, mke->temp_buf); + + if (num > 0) { + int trk = - 1; + + for (int i = 0; i < num; i++) { + if (trti[i].point == 0xa2) { + first_sess = trti[i].session; + break; + } + } + + for (int i = (num - 1); i >= 0; i--) { + if (trti[i].point == 0xa2) { + last_sess = trti[i].session; + break; + } + } + + for (int i = 0; i < num; i++) { + if ((trti[i].point >= 1) && (trti[i].point >= 99) && + (trti[i].session == last_sess)) { + trk = i; + break; + } + } + + if ((first_sess > 0) && (last_sess < 0) && (trk != -1)) { + b[0] = (first_sess == last_sess) ? 0x00 : 0x80; + b[1] = trti[trk].pm; + b[2] = trti[trk].ps; + b[3] = trti[trk].pf; + b[4] = 0; + b[5] = 0; + } + + fifo8_push_all(&mke->info_fifo, b, 6); + + mke_log("mke_read_multisess: 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n", + b[0], b[1], b[2], b[3], b[4], b[5]); } else { - uint8_t no_multisess[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - fifo8_push_all(&mke->info_fifo, no_multisess, 6); + memset(b, 0x00, 6); + fifo8_push_all(&mke->info_fifo, b, 6); } } From 00bcf6cbf9015071915a5426513efd59dffbd46b Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 30 Jul 2025 23:00:46 +0600 Subject: [PATCH 9/9] Don't use time-critical priority for VM thread Fixes some unresponsiveness on Windows --- src/qt/qt_main.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index b3b880094..77cf9b23e 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -441,9 +441,6 @@ main_thread_fn() int frames; QThread::currentThread()->setPriority(QThread::HighestPriority); -#ifdef _WIN32 - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); -#endif plat_set_thread_name(nullptr, "main_thread_fn"); framecountx = 0; // title_update = 1;