From 24ee676b1397dad534f37c891c65d6e64a77a9d1 Mon Sep 17 00:00:00 2001 From: Adrien Moulin Date: Wed, 13 Jul 2022 01:04:01 +0200 Subject: [PATCH 001/386] qt: switch to polling for status bar updating --- src/86box.c | 3 + src/CMakeLists.txt | 2 +- src/include/86box/machine_status.h | 32 ++++++ src/include/86box/plat.h | 2 + src/include/86box/ui.h | 4 +- src/machine_status.c | 52 ++++++++++ src/qt/qt_machinestatus.cpp | 159 ++++++++++++++--------------- src/qt/qt_machinestatus.hpp | 4 +- src/qt/qt_mainwindow.cpp | 2 - src/qt/qt_progsettings.cpp | 2 - src/qt/qt_ui.cpp | 79 +++++++++++++- 11 files changed, 242 insertions(+), 99 deletions(-) create mode 100644 src/include/86box/machine_status.h create mode 100644 src/machine_status.c diff --git a/src/86box.c b/src/86box.c index 24f74b04a..449588c5d 100644 --- a/src/86box.c +++ b/src/86box.c @@ -96,6 +96,7 @@ #include <86box/thread.h> #include <86box/version.h> #include <86box/gdbstub.h> +#include <86box/machine_status.h> // Disable c99-designator to avoid the warnings about int ng #ifdef __clang__ @@ -891,6 +892,8 @@ pc_init_modules(void) video_reset_close(); + machine_status_init(); + return(1); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 36df54404..d1da45172 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,7 +17,7 @@ add_executable(86Box 86box.c config.c log.c random.c timer.c io.c acpi.c apm.c dma.c ddma.c discord.c nmi.c pic.c pit.c port_6x.c port_92.c ppi.c pci.c - mca.c usb.c fifo8.c device.c nvr.c nvr_at.c nvr_ps2.c) + mca.c usb.c fifo8.c device.c nvr.c nvr_at.c nvr_ps2.c machine_status.c) if(CMAKE_SYSTEM_NAME MATCHES "Linux") add_compile_definitions(_FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE=1 _LARGEFILE64_SOURCE=1) diff --git a/src/include/86box/machine_status.h b/src/include/86box/machine_status.h new file mode 100644 index 000000000..2afed078e --- /dev/null +++ b/src/include/86box/machine_status.h @@ -0,0 +1,32 @@ +#ifndef EMU_MACHINE_STATUS_H +#define EMU_MACHINE_STATUS_H + +typedef struct { + atomic_bool_t empty; + atomic_bool_t active; +} dev_status_empty_active_t; + +typedef struct { + atomic_bool_t active; +} dev_status_active_t; + +typedef struct { + atomic_bool_t empty; +} dev_status_empty_t; + +typedef struct { + dev_status_empty_active_t fdd[FDD_NUM]; + dev_status_empty_active_t cdrom[CDROM_NUM]; + dev_status_empty_active_t zip[ZIP_NUM]; + dev_status_empty_active_t mo[MO_NUM]; + dev_status_empty_active_t cassette; + dev_status_active_t hdd[HDD_BUS_USB]; + dev_status_active_t net; + dev_status_empty_t cartridge[2]; +} machine_status_t; + +extern machine_status_t machine_status; + +extern void machine_status_init(); + +#endif /*EMU_MACHINE_STATUS_H*/ \ No newline at end of file diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 5b810ed22..d4b50e0a5 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -68,10 +68,12 @@ extern int strnicmp(const char* s1, const char* s2, size_t n); #ifdef __cplusplus #include #define atomic_flag_t std::atomic_flag +#define atomic_bool_t std::atomic_bool extern "C" { #else #include #define atomic_flag_t atomic_flag +#define atomic_bool_t atomic_bool #endif /* Global variables residing in the platform module. */ diff --git a/src/include/86box/ui.h b/src/include/86box/ui.h index 847b8c706..adfb84581 100644 --- a/src/include/86box/ui.h +++ b/src/include/86box/ui.h @@ -70,8 +70,8 @@ extern void ui_sb_update_panes(void); extern void ui_sb_update_text(void); extern void ui_sb_update_tip(int meaning); extern void ui_sb_timer_callback(int pane); -extern void ui_sb_update_icon(int tag, int val); -extern void ui_sb_update_icon_state(int tag, int active); +extern void ui_sb_update_icon(int tag, int active); +extern void ui_sb_update_icon_state(int tag, int state); extern void ui_sb_set_text_w(wchar_t *wstr); extern void ui_sb_set_text(char *str); extern void ui_sb_bugui(char *str); diff --git a/src/machine_status.c b/src/machine_status.c new file mode 100644 index 000000000..258c16821 --- /dev/null +++ b/src/machine_status.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include + +#include <86box/86box.h> +#include <86box/plat.h> +#include <86box/ui.h> +#include <86box/timer.h> +#include <86box/device.h> +#include <86box/fdd.h> +#include <86box/hdc.h> +#include <86box/scsi.h> +#include <86box/scsi_device.h> +#include <86box/cartridge.h> +#include <86box/cassette.h> +#include <86box/cdrom.h> +#include <86box/zip.h> +#include <86box/mo.h> +#include <86box/hdd.h> +#include <86box/machine_status.h> + +machine_status_t machine_status; + +void +machine_status_init() { + for (size_t i = 0; i < FDD_NUM; ++i) { + machine_status.fdd[i].empty = (strlen(floppyfns[i]) == 0); + machine_status.fdd[i].active = false; + } + for (size_t i = 0; i < CDROM_NUM; ++i) { + machine_status.cdrom[i].empty = cdrom[i].host_drive != 200 || (strlen(cdrom[i].image_path) == 0); + machine_status.cdrom[i].active = false; + } + for (size_t i = 0; i < ZIP_NUM; i++) { + machine_status.zip[i].empty = (strlen(zip_drives[i].image_path) == 0); + machine_status.zip[i].active = false; + } + for (size_t i = 0; i < MO_NUM; i++) { + machine_status.mo[i].empty = (strlen(mo_drives[i].image_path) == 0); + machine_status.mo[i].active = false; + } + + machine_status.cassette.empty = (strlen(cassette_fname) == 0); + + for (size_t i = 0; i < HDD_BUS_USB; i++) { + machine_status.hdd[i].active = false; + } + + machine_status.net.active = false; +} \ No newline at end of file diff --git a/src/qt/qt_machinestatus.cpp b/src/qt/qt_machinestatus.cpp index bd0e491f1..773566319 100644 --- a/src/qt/qt_machinestatus.cpp +++ b/src/qt/qt_machinestatus.cpp @@ -39,6 +39,7 @@ extern uint64_t tsc; #include <86box/machine.h> #include <86box/network.h> #include <86box/ui.h> +#include <86box/machine_status.h> }; #include @@ -92,17 +93,21 @@ namespace { struct StateActive { std::unique_ptr label; - QTimer timer; PixmapSetActive* pixmaps = nullptr; bool active = false; void setActive(bool b) { - active = b; - if (! label) { + if (!label || b == active) + return; + active = b; + + refresh(); + } + + void refresh() { + if (!label) return; - } label->setPixmap(active ? pixmaps->active : pixmaps->normal); - timer.start(75); } }; struct StateEmpty { @@ -111,33 +116,42 @@ namespace { bool empty = false; void setEmpty(bool e) { - empty = e; - if (! label) { + if (!label || e == empty) + return; + empty = e; + + refresh(); + } + + void refresh() { + if (!label) return; - } label->setPixmap(empty ? pixmaps->empty : pixmaps->normal); } }; struct StateEmptyActive { std::unique_ptr label; - QTimer timer; PixmapSetEmptyActive* pixmaps = nullptr; bool empty = false; bool active = false; void setActive(bool b) { + if (!label || b == active) + return; + active = b; refresh(); - timer.start(75); } void setEmpty(bool b) { + if (!label || b == empty) + return; + empty = b; refresh(); } void refresh() { - if (! label) { + if (!label) return; - } if (empty) { label->setPixmap(active ? pixmaps->empty_active : pixmaps->empty); } else { @@ -190,26 +204,20 @@ struct MachineStatus::States { cartridge[0].pixmaps = &pixmaps.cartridge; cartridge[1].pixmaps = &pixmaps.cartridge; cassette.pixmaps = &pixmaps.cassette; - QObject::connect(&cassette.timer, &QTimer::timeout, parent, [&]{ cassette.setActive(false); }); for (auto& f : fdd) { f.pixmaps = &pixmaps.floppy_disabled; - QObject::connect(&f.timer, &QTimer::timeout, parent, [&]{ f.setActive(false); }); } for (auto& c : cdrom) { c.pixmaps = &pixmaps.cdrom; - QObject::connect(&c.timer, &QTimer::timeout, parent, [&]{ c.setActive(false); }); } for (auto& z : zip) { z.pixmaps = &pixmaps.zip; - QObject::connect(&z.timer, &QTimer::timeout, parent, [&]{ z.setActive(false); }); } for (auto& m : mo) { m.pixmaps = &pixmaps.mo; - QObject::connect(&m.timer, &QTimer::timeout, parent, [&]{ m.setActive(false); }); } for (auto& h : hdds) { h.pixmaps = &pixmaps.hd; - QObject::connect(&h.timer, &QTimer::timeout, parent, [&]{ h.setActive(false); }); } net.pixmaps = &pixmaps.net; } @@ -227,9 +235,12 @@ struct MachineStatus::States { }; MachineStatus::MachineStatus(QObject *parent) : - QObject(parent) + QObject(parent), + refreshTimer(new QTimer(this)) { d = std::make_unique(this); + connect(refreshTimer, &QTimer::timeout, this, &MachineStatus::refreshIcons); + refreshTimer->start(75); } MachineStatus::~MachineStatus() = default; @@ -321,6 +332,38 @@ static int hdd_count(int bus) { return(c); } +void MachineStatus::refreshIcons() { + for (size_t i = 0; i < FDD_NUM; ++i) { + d->fdd[i].setActive(machine_status.fdd[i].active); + d->fdd[i].setEmpty(machine_status.fdd[i].empty); + } + for (size_t i = 0; i < CDROM_NUM; ++i) { + d->cdrom[i].setActive(machine_status.cdrom[i].active); + d->cdrom[i].setEmpty(machine_status.cdrom[i].empty); + } + for (size_t i = 0; i < ZIP_NUM; i++) { + d->zip[i].setActive(machine_status.zip[i].active); + d->zip[i].setEmpty(machine_status.zip[i].empty); + } + for (size_t i = 0; i < MO_NUM; i++) { + d->mo[i].setActive(machine_status.mo[i].active); + d->mo[i].setEmpty(machine_status.mo[i].empty); + } + + d->cassette.setEmpty(machine_status.cassette.empty); + + for (size_t i = 0; i < HDD_BUS_USB; i++) { + d->hdds[i].setActive(machine_status.hdd[i].active); + } + + d->net.setActive(machine_status.net.active); + + for (int i = 0; i < 2; ++i) { + d->cartridge[i].setEmpty(machine_status.cartridge[i].empty); + } + +} + void MachineStatus::refresh(QStatusBar* sbar) { bool has_mfm = machine_has_flags(machine, MACHINE_MFM) > 0; bool has_xta = machine_has_flags(machine, MACHINE_XTA) > 0; @@ -358,6 +401,7 @@ void MachineStatus::refresh(QStatusBar* sbar) { if (cassette_enable) { d->cassette.label = std::make_unique(); d->cassette.setEmpty(QString(cassette_fname).isEmpty()); + d->cassette.refresh(); connect((ClickableLabel*)d->cassette.label.get(), &ClickableLabel::clicked, [](QPoint pos) { MediaMenu::ptr->cassetteMenu->popup(pos - QPoint(0, MediaMenu::ptr->cassetteMenu->sizeHint().height())); }); @@ -373,6 +417,7 @@ void MachineStatus::refresh(QStatusBar* sbar) { for (int i = 0; i < 2; ++i) { d->cartridge[i].label = std::make_unique(); d->cartridge[i].setEmpty(QString(cart_fns[i]).isEmpty()); + d->cartridge[i].refresh(); connect((ClickableLabel*)d->cartridge[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { MediaMenu::ptr->cartridgeMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->cartridgeMenus[i]->sizeHint().height())); }); @@ -397,6 +442,7 @@ void MachineStatus::refresh(QStatusBar* sbar) { d->fdd[i].label = std::make_unique(); d->fdd[i].setEmpty(QString(floppyfns[i]).isEmpty()); d->fdd[i].setActive(false); + d->fdd[i].refresh(); connect((ClickableLabel*)d->fdd[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { MediaMenu::ptr->floppyMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->floppyMenus[i]->sizeHint().height())); }); @@ -412,6 +458,7 @@ void MachineStatus::refresh(QStatusBar* sbar) { d->cdrom[i].label = std::make_unique(); d->cdrom[i].setEmpty(cdrom[i].host_drive != 200 || QString(cdrom[i].image_path).isEmpty()); d->cdrom[i].setActive(false); + d->cdrom[i].refresh(); connect((ClickableLabel*)d->cdrom[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { MediaMenu::ptr->cdromMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->cdromMenus[i]->sizeHint().height())); }); @@ -427,6 +474,7 @@ void MachineStatus::refresh(QStatusBar* sbar) { d->zip[i].label = std::make_unique(); d->zip[i].setEmpty(QString(zip_drives[i].image_path).isEmpty()); d->zip[i].setActive(false); + d->zip[i].refresh(); connect((ClickableLabel*)d->zip[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { MediaMenu::ptr->zipMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->zipMenus[i]->sizeHint().height())); }); @@ -442,6 +490,7 @@ void MachineStatus::refresh(QStatusBar* sbar) { d->mo[i].label = std::make_unique(); d->mo[i].setEmpty(QString(mo_drives[i].image_path).isEmpty()); d->mo[i].setActive(false); + d->mo[i].refresh(); connect((ClickableLabel*)d->mo[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { MediaMenu::ptr->moMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->moMenus[i]->sizeHint().height())); }); @@ -457,24 +506,28 @@ void MachineStatus::refresh(QStatusBar* sbar) { if ((has_mfm || hdc_name.left(5) == QStringLiteral("st506")) && c_mfm > 0) { d->hdds[HDD_BUS_MFM].label = std::make_unique(); d->hdds[HDD_BUS_MFM].setActive(false); + d->hdds[HDD_BUS_MFM].refresh(); d->hdds[HDD_BUS_MFM].label->setToolTip(tr("Hard disk (%s)").replace("%s", "MFM/RLL")); sbar->addWidget(d->hdds[HDD_BUS_MFM].label.get()); } if ((has_esdi || hdc_name.left(4) == QStringLiteral("esdi")) && c_esdi > 0) { d->hdds[HDD_BUS_ESDI].label = std::make_unique(); d->hdds[HDD_BUS_ESDI].setActive(false); + d->hdds[HDD_BUS_ESDI].refresh(); d->hdds[HDD_BUS_ESDI].label->setToolTip(tr("Hard disk (%s)").replace("%s", "ESDI")); sbar->addWidget(d->hdds[HDD_BUS_ESDI].label.get()); } if ((has_xta || hdc_name.left(3) == QStringLiteral("xta")) && c_xta > 0) { d->hdds[HDD_BUS_XTA].label = std::make_unique(); d->hdds[HDD_BUS_XTA].setActive(false); + d->hdds[HDD_BUS_XTA].refresh(); d->hdds[HDD_BUS_XTA].label->setToolTip(tr("Hard disk (%s)").replace("%s", "XTA")); sbar->addWidget(d->hdds[HDD_BUS_XTA].label.get()); } if ((hasIDE() || hdc_name.left(5) == QStringLiteral("xtide") || hdc_name.left(3) == QStringLiteral("ide")) && c_ide > 0) { d->hdds[HDD_BUS_IDE].label = std::make_unique(); d->hdds[HDD_BUS_IDE].setActive(false); + d->hdds[HDD_BUS_IDE].refresh(); d->hdds[HDD_BUS_IDE].label->setToolTip(tr("Hard disk (%s)").replace("%s", "IDE")); sbar->addWidget(d->hdds[HDD_BUS_IDE].label.get()); } @@ -482,6 +535,7 @@ void MachineStatus::refresh(QStatusBar* sbar) { (scsi_card_current[2] != 0) || (scsi_card_current[3] != 0)) && c_scsi > 0) { d->hdds[HDD_BUS_SCSI].label = std::make_unique(); d->hdds[HDD_BUS_SCSI].setActive(false); + d->hdds[HDD_BUS_SCSI].refresh(); d->hdds[HDD_BUS_SCSI].label->setToolTip(tr("Hard disk (%s)").replace("%s", "SCSI")); sbar->addWidget(d->hdds[HDD_BUS_SCSI].label.get()); } @@ -489,6 +543,7 @@ void MachineStatus::refresh(QStatusBar* sbar) { if (do_net) { d->net.label = std::make_unique(); d->net.setActive(false); + d->net.refresh(); d->net.label->setToolTip(tr("Network")); sbar->addWidget(d->net.label.get()); } @@ -505,72 +560,6 @@ void MachineStatus::refresh(QStatusBar* sbar) { sbar->addWidget(d->text.get()); } -void MachineStatus::setActivity(int tag, bool active) { - int category = tag & 0xfffffff0; - int item = tag & 0xf; - switch (category) { - case SB_CASSETTE: - break; - case SB_CARTRIDGE: - break; - case SB_FLOPPY: - d->fdd[item].setActive(active); - break; - case SB_CDROM: - d->cdrom[item].setActive(active); - break; - case SB_ZIP: - d->zip[item].setActive(active); - break; - case SB_MO: - d->mo[item].setActive(active); - break; - case SB_HDD: - d->hdds[item].setActive(active); - break; - case SB_NETWORK: - d->net.setActive(active); - break; - case SB_SOUND: - break; - case SB_TEXT: - break; - } -} - -void MachineStatus::setEmpty(int tag, bool empty) { - int category = tag & 0xfffffff0; - int item = tag & 0xf; - switch (category) { - case SB_CASSETTE: - d->cassette.setEmpty(empty); - break; - case SB_CARTRIDGE: - d->cartridge[item].setEmpty(empty); - break; - case SB_FLOPPY: - d->fdd[item].setEmpty(empty); - break; - case SB_CDROM: - d->cdrom[item].setEmpty(empty); - break; - case SB_ZIP: - d->zip[item].setEmpty(empty); - break; - case SB_MO: - d->mo[item].setEmpty(empty); - break; - case SB_HDD: - break; - case SB_NETWORK: - break; - case SB_SOUND: - break; - case SB_TEXT: - break; - } -} - void MachineStatus::message(const QString &msg) { d->text->setText(msg); } diff --git a/src/qt/qt_machinestatus.hpp b/src/qt/qt_machinestatus.hpp index ba30d36f2..8c31dd238 100644 --- a/src/qt/qt_machinestatus.hpp +++ b/src/qt/qt_machinestatus.hpp @@ -70,14 +70,14 @@ public: QString getMessage(); public slots: void refresh(QStatusBar* sbar); - void setActivity(int tag, bool active); - void setEmpty(int tag, bool active); void message(const QString& msg); void updateTip(int tag); + void refreshIcons(); private: struct States; std::unique_ptr d; + QTimer *refreshTimer; }; #endif // QT_MACHINESTATUS_HPP diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 31ab4886b..d0549311b 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -266,8 +266,6 @@ MainWindow::MainWindow(QWidget *parent) : }); connect(this, &MainWindow::updateStatusBarPanes, this, &MainWindow::refreshMediaMenu); connect(this, &MainWindow::updateStatusBarTip, status.get(), &MachineStatus::updateTip); - connect(this, &MainWindow::updateStatusBarActivity, status.get(), &MachineStatus::setActivity); - connect(this, &MainWindow::updateStatusBarEmpty, status.get(), &MachineStatus::setEmpty); connect(this, &MainWindow::statusBarMessage, status.get(), &MachineStatus::message, Qt::QueuedConnection); ui->actionKeyboard_requires_capture->setChecked(kbd_req_capture); diff --git a/src/qt/qt_progsettings.cpp b/src/qt/qt_progsettings.cpp index 803fddc24..b11466c08 100644 --- a/src/qt/qt_progsettings.cpp +++ b/src/qt/qt_progsettings.cpp @@ -132,8 +132,6 @@ void ProgSettings::accept() main_window->refreshMediaMenu(); main_window->status->message(msg); connect(main_window, &MainWindow::updateStatusBarTip, main_window->status.get(), &MachineStatus::updateTip); - connect(main_window, &MainWindow::updateStatusBarActivity, main_window->status.get(), &MachineStatus::setActivity); - connect(main_window, &MainWindow::updateStatusBarEmpty, main_window->status.get(), &MachineStatus::setEmpty); connect(main_window, &MainWindow::statusBarMessage, main_window->status.get(), &MachineStatus::message, Qt::QueuedConnection); mouse_sensitivity = mouseSensitivity; QDialog::accept(); diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index 128631282..74cc88ebf 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -25,6 +25,7 @@ #include #include "qt_mainwindow.hpp" +#include "qt_machinestatus.hpp" MainWindow* main_window = nullptr; @@ -35,6 +36,20 @@ extern "C" { #include <86box/plat.h> #include <86box/ui.h> #include <86box/mouse.h> +#include <86box/timer.h> +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/fdd.h> +#include <86box/hdc.h> +#include <86box/scsi.h> +#include <86box/scsi_device.h> +#include <86box/cartridge.h> +#include <86box/cassette.h> +#include <86box/cdrom.h> +#include <86box/zip.h> +#include <86box/mo.h> +#include <86box/hdd.h> +#include <86box/machine_status.h> void plat_delay_ms(uint32_t count) @@ -161,16 +176,70 @@ void ui_sb_set_ready(int ready) { void ui_sb_update_icon_state(int tag, int state) { - if (main_window == nullptr) { - return; + int category = tag & 0xfffffff0; + int item = tag & 0xf; + switch (category) { + case SB_CASSETTE: + machine_status.cassette.empty = state > 0 ? true : false; + break; + case SB_CARTRIDGE: + machine_status.cartridge[item].empty = state > 0 ? true : false; + break; + case SB_FLOPPY: + machine_status.fdd[item].empty = state > 0 ? true : false; + break; + case SB_CDROM: + machine_status.cdrom[item].empty = state > 0 ? true : false; + break; + case SB_ZIP: + machine_status.zip[item].empty = state > 0 ? true : false; + break; + case SB_MO: + machine_status.mo[item].empty = state > 0 ? true : false; + break; + case SB_HDD: + break; + case SB_NETWORK: + break; + case SB_SOUND: + break; + case SB_TEXT: + break; } - main_window->updateStatusBarEmpty(tag, state > 0 ? true : false); } void ui_sb_update_icon(int tag, int active) { - if (!update_icons) return; - main_window->updateStatusBarActivity(tag, active > 0 ? true : false); + int category = tag & 0xfffffff0; + int item = tag & 0xf; + switch (category) { + case SB_CASSETTE: + break; + case SB_CARTRIDGE: + break; + case SB_FLOPPY: + machine_status.fdd[item].active = active > 0 ? true : false; + break; + case SB_CDROM: + machine_status.cdrom[item].active = active > 0 ? true : false; + break; + case SB_ZIP: + machine_status.zip[item].active = active > 0 ? true : false; + break; + case SB_MO: + machine_status.mo[item].active = active > 0 ? true : false; + break; + case SB_HDD: + machine_status.hdd[item].active = active > 0 ? true : false; + break; + case SB_NETWORK: + machine_status.net.active = active > 0 ? true : false; + break; + case SB_SOUND: + break; + case SB_TEXT: + break; + } } } From 2f9597d13a760f39c401cad7b65e68cbea365d5f Mon Sep 17 00:00:00 2001 From: Adrien Moulin Date: Wed, 13 Jul 2022 01:04:40 +0200 Subject: [PATCH 002/386] Fix IDE activity status updating --- src/disk/hdc_ide.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index a4a9f2ddc..b005cbd6d 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -1642,9 +1642,6 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) disabled, the Read Multiple operation is rejected with an Aborted Com- mand error. */ ide->blockcount = 0; - /* Turn on the activity indicator *here* so that it gets turned on - less times. */ - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); /*FALLTHROUGH*/ case WIN_READ: @@ -1658,6 +1655,7 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) ide->atastat = BSY_STAT; if (ide->type == IDE_HDD) { + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); uint32_t sec_count; double wait_time; if ((val == WIN_READ_DMA) || (val == WIN_READ_DMA_ALT)) { @@ -1908,7 +1906,7 @@ ide_read_data(ide_t *ide, int length) double xfer_time = ide_get_xfer_time(ide, 512); ide_set_callback(ide, seek_time + xfer_time); } - } else if (ide->command != WIN_READ_MULTIPLE) + } else ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); } } From aa9fc2d44a21cac19ec70d624597938b24058725 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Tue, 12 Jul 2022 19:41:44 -0400 Subject: [PATCH 003/386] Fix accidental removal of rtmidi --- .github/workflows/cmake.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index c6ac100f7..5606f1342 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -77,6 +77,7 @@ jobs: ${{ matrix.environment.prefix }}-libpng ${{ matrix.environment.prefix }}-libvncserver ${{ matrix.environment.prefix }}-openal + ${{ matrix.environment.prefix }}-rtmidi - uses: actions/checkout@v2 - name: Configure CMake run: >- From 7430df2cc30258e4244576ed8a97beaa33e3883b Mon Sep 17 00:00:00 2001 From: richardg867 Date: Tue, 12 Jul 2022 22:22:00 -0300 Subject: [PATCH 004/386] Add incomplete (and standalone for now) 8042 emulator --- src/upi42.c | 903 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 903 insertions(+) create mode 100644 src/upi42.c diff --git a/src/upi42.c b/src/upi42.c new file mode 100644 index 000000000..e98af5496 --- /dev/null +++ b/src/upi42.c @@ -0,0 +1,903 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Intel UPI-42/MCS-48 microcontroller emulation. + * + * + * + * Authors: RichardG, + * + * Copyright 2022 RichardG. + */ +#include +#include +#include +#include +#define fatal printf +#define pclog printf + +enum { + UPI42_8042 = 0, + UPI42_80C42 +}; + +typedef struct _upi42_ { + int (*ops[256])(struct _upi42_ *upi42, uint32_t fetchdat); + uint8_t ram[256], rom[4096], /* memory */ + ports[7], /* I/O ports */ + dbb_in, dbb_out; /* UPI-42 data buffer */ + + uint8_t rammask, + a, /* accumulator */ + t, /* timer counter */ + psw, /* program status word */ + sts; /* UPI-42 status */ + + uint16_t pc; /* program counter */ + + unsigned int prescaler : 5, tf : 1, tcnti : 1, run_timer : 1, run_counter : 1, skip_timer_inc : 1, /* timer/counter */ + i : 1, i_asserted : 1, tcnti_asserted : 1, irq_mask : 1, /* interrupts */ + dbf : 1, /* ROM bank */ + t0 : 1, t1 : 1, /* T0/T1 signals */ + flags : 1, /* buffer flag pins */ + suspend : 1; /* 80C42 suspend flag */ + + int cycs; /* cycle counter */ +} upi42_t; + +#define UPI42_REG_READ(upi42, r) ((upi42->psw & 0x10) ? (upi42->ram[24 + ((r) &7)]) : (upi42->ram[(r) &7])) +#define UPI42_REG_WRITE(upi42, r, op) ((upi42->psw & 0x10) ? (upi42->ram[24 + ((r) &7)] op) : (upi42->ram[(r) &7] op)) + +static inline void +upi42_mirror_f0(upi42_t *upi42) +{ + /* Update status register F0 flag to match PSW F0 flag. */ + upi42->sts = ((upi42->psw & 0x20) >> 3) | (upi42->sts & ~0x04); +} + +static int +upi42_op_MOV_A_Rr(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = UPI42_REG_READ(upi42, fetchdat); + return 1; +} + +static int +upi42_op_MOV_Rr_A(upi42_t *upi42, uint32_t fetchdat) +{ + UPI42_REG_WRITE(upi42, fetchdat, = upi42->a); + return 1; +} + +static int +upi42_op_MOV_A_indRr(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = upi42->ram[upi42->ram[fetchdat & 1] & upi42->rammask]; + return 1; +} + +static int +upi42_op_MOV_indRr_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->ram[upi42->ram[fetchdat & 1] & upi42->rammask] = upi42->a; + return 1; +} + +static int +upi42_op_MOV_Rr_imm(upi42_t *upi42, uint32_t fetchdat) +{ + UPI42_REG_WRITE(upi42, fetchdat, = fetchdat >> 8); + upi42->cycs--; + return 2; +} + +static int +upi42_op_MOV_indRr_imm(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->ram[upi42->ram[fetchdat & 1] & upi42->rammask] = fetchdat >> 8; + upi42->cycs--; + return 2; +} + +static int +upi42_op_MOV_A_imm(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = fetchdat >> 8; + upi42->cycs--; + return 2; +} + +static int +upi42_op_MOV_A_PSW(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = upi42->psw; + upi42_mirror_f0(upi42); + return 1; +} + +static int +upi42_op_MOV_PSW_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->psw = upi42->a; + upi42_mirror_f0(upi42); + return 1; +} + +static int +upi42_op_MOV_A_T(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = upi42->t; + return 1; +} + +static int +upi42_op_MOV_T_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->t = upi42->a; + return 1; +} + +static int +upi42_op_MOV_STS_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->sts = (upi42->a & 0xf0) | (upi42->sts & 0x0f); + return 1; +} + +static int +upi42_op_MOVP_A_indA(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = upi42->rom[(upi42->pc & 0xff00) | upi42->a]; + upi42->cycs--; + return 1; +} + +static int +upi42_op_MOVP3_A_indA(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = upi42->rom[0x300 | upi42->a]; + upi42->cycs--; + return 1; +} + +static int +upi42_op_XCH_A_Rr(upi42_t *upi42, uint32_t fetchdat) +{ + uint8_t temp = upi42->a; + upi42->a = UPI42_REG_READ(upi42, fetchdat); + UPI42_REG_WRITE(upi42, fetchdat, = temp); + return 1; +} + +static int +upi42_op_XCH_A_indRr(upi42_t *upi42, uint32_t fetchdat) +{ + uint8_t temp = upi42->a, addr = upi42->ram[fetchdat & 1] & upi42->rammask; + upi42->a = upi42->ram[addr]; + upi42->ram[addr] = temp; + return 1; +} + +static int +upi42_op_XCHD_A_indRr(upi42_t *upi42, uint32_t fetchdat) +{ + uint8_t temp = upi42->a, addr = upi42->ram[fetchdat & 1] & upi42->rammask; + upi42->a = (upi42->a & 0xf0) | (upi42->ram[addr] & 0x0f); + upi42->ram[addr] = (upi42->ram[addr] & 0xf0) | (temp & 0x0f); + return 1; +} + +static int +upi42_op_SWAP_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = (upi42->a << 4) | (upi42->a >> 4); + return 1; +} + +static int +upi42_op_IN_A_Pp(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = upi42->ports[fetchdat & 3]; + upi42->cycs--; + return 1; +} + +static int +upi42_op_IN_A_DBB(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = upi42->dbb_in; + return 1; +} + +static int +upi42_op_OUTL_Pp_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->ports[fetchdat & 3] = upi42->a; + upi42->cycs--; + return 1; +} + +static int +upi42_op_OUT_DBB_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->dbb_out = upi42->a; + upi42->sts |= 0x01; + return 1; +} + +static int +upi42_op_MOVD_A_Pp(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = upi42->ports[4 | (fetchdat & 3)] & 0x0f; + upi42->cycs--; + return 1; +} + +static int +upi42_op_MOVD_Pp_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->ports[4 | (fetchdat & 3)] = upi42->a & 0x0f; + upi42->cycs--; + return 1; +} + +static int +upi42_op_ANL_A_Rr(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a &= UPI42_REG_READ(upi42, fetchdat); + return 1; +} + +static int +upi42_op_ORL_A_Rr(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a |= UPI42_REG_READ(upi42, fetchdat); + return 1; +} + +static int +upi42_op_XRL_A_Rr(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a ^= UPI42_REG_READ(upi42, fetchdat); + return 1; +} + +static int +upi42_op_ANL_A_indRr(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a &= upi42->ram[upi42->ram[fetchdat & 1] & upi42->rammask]; + return 1; +} + +static int +upi42_op_ORL_A_indRr(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a |= upi42->ram[upi42->ram[fetchdat & 1] & upi42->rammask]; + return 1; +} + +static int +upi42_op_XRL_A_indRr(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a ^= upi42->ram[upi42->ram[fetchdat & 1] & upi42->rammask]; + return 1; +} + +static int +upi42_op_ANL_A_imm(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a &= fetchdat >> 8; + upi42->cycs--; + return 2; +} + +static int +upi42_op_ORL_A_imm(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a |= fetchdat >> 8; + upi42->cycs--; + return 2; +} + +static int +upi42_op_XRL_A_imm(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a ^= fetchdat >> 8; + upi42->cycs--; + return 2; +} + +static int +upi42_op_ANL_Pp_imm(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->ports[fetchdat & 3] &= fetchdat >> 8; + upi42->cycs--; + return 2; +} + +static int +upi42_op_ORL_Pp_imm(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->ports[fetchdat & 3] |= fetchdat >> 8; + upi42->cycs--; + return 2; +} + +static int +upi42_op_ANLD_Pp_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->ports[4 | (fetchdat & 3)] &= upi42->a; + upi42->cycs--; + return 1; +} + +static int +upi42_op_ORLD_Pp_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->ports[4 | (fetchdat & 3)] |= upi42->a; + upi42->cycs--; + return 1; +} + +static int +upi42_op_RR_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = (upi42->a << 7) | (upi42->a >> 1); + return 1; +} + +static int +upi42_op_RL_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = (upi42->a >> 7) | (upi42->a << 1); + return 1; +} + +static int +upi42_op_RRC_A(upi42_t *upi42, uint32_t fetchdat) +{ + uint8_t temp = upi42->a; + upi42->a = (upi42->psw & 0x80) | (temp >> 1); + upi42->psw = (temp << 7) | (upi42->psw & ~0x80); + return 1; +} + +static int +upi42_op_RLC_A(upi42_t *upi42, uint32_t fetchdat) +{ + uint8_t temp = upi42->a; + upi42->a = (temp << 1) | (upi42->psw >> 7); + upi42->psw = (temp & 0x80) | (upi42->psw & ~0x80); + return 1; +} + +static int +upi42_op_INC_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a++; + return 1; +} + +static int +upi42_op_INC_Rr(upi42_t *upi42, uint32_t fetchdat) +{ + UPI42_REG_WRITE(upi42, fetchdat, ++); + return 1; +} + +static int +upi42_op_INC_indRr(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->ram[upi42->ram[fetchdat & 1] & upi42->rammask]++; + return 1; +} + +static int +upi42_op_DEC_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a--; + return 1; +} + +static int +upi42_op_DEC_Rr(upi42_t *upi42, uint32_t fetchdat) +{ + UPI42_REG_WRITE(upi42, fetchdat, --); + return 1; +} + +static int +upi42_op_DJNZ_Rr_imm(upi42_t *upi42, uint32_t fetchdat) +{ + UPI42_REG_WRITE(upi42, fetchdat, --); + if (UPI42_REG_READ(upi42, fetchdat)) { + upi42->pc = (upi42->pc & 0xff00) | ((fetchdat >> 8) & 0xff); + return 0; + } else { + return 2; + } +} + +static int +upi42_op_ADD_A_Rr(upi42_t *upi42, uint32_t fetchdat) +{ + int res = upi42->a + UPI42_REG_READ(upi42, fetchdat); + upi42->a = res; + upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); + return 1; +} + +static int +upi42_op_ADDC_A_Rr(upi42_t *upi42, uint32_t fetchdat) +{ + int res = upi42->a + (upi42->psw >> 7) + UPI42_REG_READ(upi42, fetchdat); + upi42->a = res; + upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); + return 1; +} + +static int +upi42_op_ADD_A_indRr(upi42_t *upi42, uint32_t fetchdat) +{ + int res = upi42->a + upi42->ram[UPI42_REG_READ(upi42, fetchdat) & upi42->rammask]; + upi42->a = res; + upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); + return 1; +} + +static int +upi42_op_ADDC_A_indRr(upi42_t *upi42, uint32_t fetchdat) +{ + int res = upi42->a + (upi42->psw >> 7) + upi42->ram[UPI42_REG_READ(upi42, fetchdat) & upi42->rammask]; + upi42->a = res; + upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); + return 1; +} + +static int +upi42_op_ADD_A_imm(upi42_t *upi42, uint32_t fetchdat) +{ + int res = upi42->a + (fetchdat >> 8); + upi42->a = res; + upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); + upi42->cycs--; + return 2; +} + +static int +upi42_op_ADDC_A_imm(upi42_t *upi42, uint32_t fetchdat) +{ + int res = upi42->a + (upi42->psw >> 7) + (fetchdat >> 8); + upi42->a = res; + upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); + upi42->cycs--; + return 2; +} + +static int +upi42_op_CLR_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = 0; + return 1; +} + +static int +upi42_op_CPL_A(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->a = ~upi42->a; + return 1; +} + +static int +upi42_op_DA_A(upi42_t *upi42, uint32_t fetchdat) +{ + if (((upi42->a & 0x0f) > 9) || (upi42->psw & 0x40)) + upi42->a += 6; + if (((upi42->a >> 4) > 9) || (upi42->psw & 0x80)) { + int res = upi42->a + (6 << 4); + upi42->a = res; + upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); + } + return 1; +} + +static int +upi42_op_CLR_C(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->psw &= ~0x80; + return 1; +} + +static int +upi42_op_CPL_C(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->psw ^= 0x80; + return 1; +} + +static int +upi42_op_CLR_F0(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->psw &= ~0x20; + upi42_mirror_f0(upi42); + return 1; +} + +static int +upi42_op_CPL_F0(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->psw ^= 0x20; + upi42_mirror_f0(upi42); + return 1; +} + +static int +upi42_op_CLR_F1(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->sts &= ~0x08; + return 1; +} + +static int +upi42_op_CPL_F1(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->sts ^= 0x08; + return 1; +} + +static int +upi42_op_EN_I(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->i = 1; + upi42->skip_timer_inc = 1; + return 1; +} + +static int +upi42_op_DIS_I(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->i = 0; + upi42->skip_timer_inc = 1; + return 1; +} + +static int +upi42_op_EN_TCNTI(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->tcnti = 1; + return 1; +} + +static int +upi42_op_DIS_TCNTI(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->tcnti = upi42->tcnti_asserted = 0; + return 1; +} + +static int +upi42_op_STRT_T(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->run_timer = 1; + upi42->prescaler = 0; + upi42->skip_timer_inc = 1; + return 1; +} + +static int +upi42_op_STRT_CNT(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->run_counter = 1; + upi42->skip_timer_inc = 1; + return 1; +} + +static int +upi42_op_STOP_TCNT(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->run_timer = upi42->run_counter = 0; + upi42->skip_timer_inc = 1; + return 1; +} + +static int +upi42_op_SEL_PMB0(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->dbf = 0; + return 1; +} + +static int +upi42_op_SEL_PMB1(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->dbf = 1; + return 1; +} + +static int +upi42_op_SEL_RB0(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->psw &= ~0x10; + return 1; +} + +static int +upi42_op_SEL_RB1(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->psw |= 0x10; + return 1; +} + +static int +upi42_op_NOP(upi42_t *upi42, uint32_t fetchdat) +{ + return 1; +} + +static int +upi42_op_CALL_imm(upi42_t *upi42, uint32_t fetchdat) +{ + /* Push new frame onto stack. */ + uint8_t sp = (upi42->psw & 0x07) << 1; + upi42->ram[8 + sp++] = upi42->pc; /* stack frame format is undocumented! */ + upi42->ram[8 + sp++] = (upi42->psw & 0xf0) | ((upi42->pc >> 8) & 0x07); + upi42->psw = (upi42->psw & 0xf8) | (sp >> 1); + + /* Load new program counter. */ + upi42->pc = (upi42->dbf << 11) | ((fetchdat << 3) & 0x0700) | ((fetchdat >> 8) & 0x00ff); + + /* Don't decrease cycle counter if this is an interrupt call. */ + if (fetchdat & 0xff) + upi42->cycs--; + return 0; +} + +static int +upi42_op_RET(upi42_t *upi42, uint32_t fetchdat) +{ + /* Pop frame off the stack. */ + uint8_t sp = (upi42->psw & 0x07) << 1; + uint8_t frame1 = upi42->ram[8 + --sp]; + uint8_t frame0 = upi42->ram[8 + --sp]; + upi42->psw = (upi42->psw & 0xf8) | (sp >> 1); + + /* Load new program counter. */ + upi42->pc = ((frame1 & 0x0f) << 8) | frame0; + + /* Load new Program Status Word and unmask interrupts if this is RETR. */ + if (fetchdat & 0x10) { + upi42->psw = (frame1 & 0xf0) | (upi42->psw & 0x0f); + upi42_mirror_f0(upi42); + + upi42->irq_mask = 0; + } + + upi42->cycs--; + return 0; +} + +static int +upi42_op_JMP_imm(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->pc = (upi42->dbf << 11) | ((fetchdat << 3) & 0x0700) | ((fetchdat >> 8) & 0x00ff); + upi42->cycs--; + return 0; +} + +static int +upi42_op_JMPP_indA(upi42_t *upi42, uint32_t fetchdat) +{ + upi42->pc = (upi42->pc & 0xff00) | upi42->a; + upi42->cycs--; + return 0; +} + +#define UPI42_COND_JMP_IMM(insn, cond, post) \ + static int \ + upi42_op_##insn##_imm(upi42_t *upi42, uint32_t fetchdat) \ + { \ + if (cond) \ + upi42->pc = (upi42->pc & 0xff00) | ((fetchdat >> 8) & 0x00ff); \ + post \ + upi42->cycs--; \ + return 2 * !(cond); \ + } +UPI42_COND_JMP_IMM(JC, upi42->psw & 0x80, ;) +UPI42_COND_JMP_IMM(JNC, !(upi42->psw & 0x80), ;) +UPI42_COND_JMP_IMM(JZ, !upi42->a, ;) +UPI42_COND_JMP_IMM(JNZ, upi42->a, ;) +UPI42_COND_JMP_IMM(JT0, upi42->t0, ;) +UPI42_COND_JMP_IMM(JNT0, !upi42->t0, ;) +UPI42_COND_JMP_IMM(JT1, upi42->t1, ;) +UPI42_COND_JMP_IMM(JNT1, !upi42->t1, ;) +UPI42_COND_JMP_IMM(JF0, upi42->psw & 0x20, ;) +UPI42_COND_JMP_IMM(JF1, upi42->sts & 0x08, ;) +UPI42_COND_JMP_IMM(JTF, !upi42->tf, upi42->tf = 0;) +UPI42_COND_JMP_IMM(JBb, upi42->a &(1 << ((fetchdat >> 5) & 7)), ;) +UPI42_COND_JMP_IMM(JNIBF, !(upi42->sts & 0x02), ;) +UPI42_COND_JMP_IMM(JOBF, upi42->sts & 0x01, ;) + +static int +upi42_op_EN_A20(upi42_t *upi42, uint32_t fetchdat) +{ + /* Enable fast A20 until reset. */ + return 1; +} + +static int +upi42_op_EN_DMA(upi42_t *upi42, uint32_t fetchdat) +{ + return 1; +} + +static int +upi42_op_EN_FLAGS(upi42_t *upi42, uint32_t fetchdat) +{ + return 1; +} + +static int +upi42_op_SUSPEND(upi42_t *upi42, uint32_t fetchdatr) +{ + /* Inhibit execution until reset. */ + upi42->suspend = 1; + return 1; +} + +static void +upi42_exec(void *priv) +{ + upi42_t *upi42 = (upi42_t *) priv; + + /* Skip interrupt handling and code execution if we're suspended or in a multi-cycle instruction. */ + if (upi42->suspend || ++upi42->cycs < 0) + return; + + /* Trigger interrupt if requested. */ + if (upi42->irq_mask) { + /* Masked, we're currently in an ISR. */ + } else if (upi42->i_asserted) { + /* External interrupt. Higher priority than the timer interrupt. */ + upi42->irq_mask = 1; + upi42->i_asserted = 0; + upi42_op_CALL_imm(upi42, 3 << 8); + return; + } else if (upi42->tcnti_asserted) { + /* Timer interrupt. */ + upi42->irq_mask = 1; + upi42->tcnti_asserted = 0; + upi42_op_CALL_imm(upi42, 7 << 8); + return; + } + + /* Fetch instruction. */ + uint32_t fetchdat = *((uint32_t *) &upi42->rom[upi42->pc]); + pclog("%04X @ %04X R0=%02X", fetchdat & 0xffff, upi42->pc, upi42->ram[0]); + + /* Decode instruction. */ + uint8_t insn = fetchdat & 0xff; + if (upi42->ops[insn]) { + /* Execute instruction and increment program counter. */ + upi42->pc += upi42->ops[insn](upi42, fetchdat); + + /* Decrement cycle counter. Multi-cycle instructions also decrement within their code. */ + upi42->cycs--; + } else { + fatal("UPI42: Unknown opcode %02X (%08X)\n", insn, fetchdat); + return; + } + + /* Some instructions don't increment the timer. */ + if (upi42->skip_timer_inc) { + upi42->skip_timer_inc = 0; + } else { + /* Increment counter once the prescaler overflows, + and set timer flag once the main value overflows. */ + if ((++upi42->prescaler == 0) && (++upi42->t == 0)) { + upi42->tf = 1; + + /* Fire counter interrupt if enabled. */ + if (upi42->tcnti) + upi42->tcnti_asserted = 1; + } + } +} + +static const int (*ops_80c42[256])(upi42_t *upi42, uint32_t fetchdat) = { + // clang-format off + /* 0 / 8 */ /* 1 / 9 */ /* 2 / a */ /* 3 / b */ /* 4 / c */ /* 5 / d */ /* 6 / e */ /* 7 / f */ + /* 00 */ upi42_op_NOP, NULL, upi42_op_OUT_DBB_A, upi42_op_ADD_A_imm, upi42_op_JMP_imm, upi42_op_EN_I, NULL, upi42_op_DEC_A, + /* 08 */ upi42_op_IN_A_Pp, upi42_op_IN_A_Pp, upi42_op_IN_A_Pp, NULL, upi42_op_MOVD_A_Pp, upi42_op_MOVD_A_Pp, upi42_op_MOVD_A_Pp, upi42_op_MOVD_A_Pp, + /* 10 */ upi42_op_INC_indRr, upi42_op_INC_indRr, upi42_op_JBb_imm, upi42_op_ADDC_A_imm, upi42_op_CALL_imm, upi42_op_DIS_I, upi42_op_JTF_imm, upi42_op_INC_A, + /* 18 */ upi42_op_INC_Rr, upi42_op_INC_Rr, upi42_op_INC_Rr, upi42_op_INC_Rr, upi42_op_INC_Rr, upi42_op_INC_Rr, upi42_op_INC_Rr, upi42_op_INC_Rr, + /* 20 */ upi42_op_XCH_A_indRr, upi42_op_XCH_A_indRr, upi42_op_IN_A_DBB, upi42_op_MOV_A_imm, upi42_op_JMP_imm, upi42_op_EN_TCNTI, upi42_op_JNT0_imm, upi42_op_CLR_A, + /* 28 */ upi42_op_XCH_A_Rr, upi42_op_XCH_A_Rr, upi42_op_XCH_A_Rr, upi42_op_XCH_A_Rr, upi42_op_XCH_A_Rr, upi42_op_XCH_A_Rr, upi42_op_XCH_A_Rr, upi42_op_XCH_A_Rr, + /* 30 */ upi42_op_XCHD_A_indRr, upi42_op_XCHD_A_indRr, upi42_op_JBb_imm, upi42_op_EN_A20, upi42_op_CALL_imm, upi42_op_DIS_TCNTI, upi42_op_JT0_imm, upi42_op_CPL_A, + /* 38 */ upi42_op_OUTL_Pp_A, upi42_op_OUTL_Pp_A, upi42_op_OUTL_Pp_A, upi42_op_OUTL_Pp_A, upi42_op_MOVD_Pp_A, upi42_op_MOVD_Pp_A, upi42_op_MOVD_Pp_A, upi42_op_MOVD_Pp_A, + /* 40 */ upi42_op_ORL_A_indRr, upi42_op_ORL_A_indRr, upi42_op_MOV_A_T, upi42_op_ORL_A_imm, upi42_op_JMP_imm, upi42_op_STRT_CNT, upi42_op_JNT1_imm, upi42_op_SWAP_A, + /* 48 */ upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, + /* 50 */ upi42_op_ANL_A_indRr, upi42_op_ANL_A_indRr, upi42_op_JBb_imm, upi42_op_ANL_A_imm, upi42_op_CALL_imm, upi42_op_STRT_T, upi42_op_JT1_imm, upi42_op_DA_A, + /* 58 */ upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, + /* 60 */ upi42_op_ADD_A_indRr, upi42_op_ADD_A_indRr, upi42_op_MOV_T_A, NULL, upi42_op_JMP_imm, upi42_op_STOP_TCNT, NULL, upi42_op_RRC_A, + /* 68 */ upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, + /* 70 */ upi42_op_ADDC_A_indRr, upi42_op_ADDC_A_indRr, upi42_op_JBb_imm, NULL, upi42_op_CALL_imm, NULL, upi42_op_JF1_imm, upi42_op_RR_A, + /* 78 */ upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, + /* 80 */ NULL, NULL, upi42_op_SUSPEND, upi42_op_RET, upi42_op_JMP_imm, upi42_op_CLR_F0, upi42_op_JOBF_imm, NULL, + /* 88 */ upi42_op_ORL_Pp_imm, upi42_op_ORL_Pp_imm, upi42_op_ORL_Pp_imm, upi42_op_ORL_Pp_imm, upi42_op_ORLD_Pp_A, upi42_op_ORLD_Pp_A, upi42_op_ORLD_Pp_A, upi42_op_ORLD_Pp_A, + /* 90 */ upi42_op_MOV_STS_A, NULL, upi42_op_JBb_imm, upi42_op_RET, upi42_op_CALL_imm, upi42_op_CPL_F0, upi42_op_JNZ_imm, upi42_op_CLR_C, + /* 98 */ upi42_op_ANL_Pp_imm, upi42_op_ANL_Pp_imm, upi42_op_ANL_Pp_imm, upi42_op_ANL_Pp_imm, upi42_op_ANLD_Pp_A, upi42_op_ANLD_Pp_A, upi42_op_ANLD_Pp_A, upi42_op_ANLD_Pp_A, + /* a0 */ upi42_op_MOV_indRr_A, upi42_op_MOV_indRr_A, NULL, upi42_op_MOVP_A_indA, upi42_op_JMP_imm, upi42_op_CLR_F1, NULL, upi42_op_CPL_C, + /* a8 */ upi42_op_MOV_Rr_A, upi42_op_MOV_Rr_A, upi42_op_MOV_Rr_A, upi42_op_MOV_Rr_A, upi42_op_MOV_Rr_A, upi42_op_MOV_Rr_A, upi42_op_MOV_Rr_A, upi42_op_MOV_Rr_A, + /* b0 */ upi42_op_MOV_indRr_imm,upi42_op_MOV_indRr_imm,upi42_op_JBb_imm, upi42_op_JMPP_indA, upi42_op_CALL_imm, upi42_op_CPL_F1, upi42_op_JF0_imm, NULL, + /* b8 */ upi42_op_MOV_Rr_imm, upi42_op_MOV_Rr_imm, upi42_op_MOV_Rr_imm, upi42_op_MOV_Rr_imm, upi42_op_MOV_Rr_imm, upi42_op_MOV_Rr_imm, upi42_op_MOV_Rr_imm, upi42_op_MOV_Rr_imm, + /* c0 */ NULL, NULL, NULL, NULL, upi42_op_JMP_imm, NULL, upi42_op_JZ_imm, upi42_op_MOV_A_PSW, + /* c8 */ upi42_op_DEC_Rr, upi42_op_DEC_Rr, upi42_op_DEC_Rr, upi42_op_DEC_Rr, upi42_op_DEC_Rr, upi42_op_DEC_Rr, upi42_op_DEC_Rr, upi42_op_DEC_Rr, + /* d0 */ upi42_op_XRL_A_indRr, upi42_op_XRL_A_indRr, upi42_op_JBb_imm, upi42_op_XRL_A_imm, upi42_op_CALL_imm, NULL, upi42_op_JNIBF_imm, upi42_op_MOV_PSW_A, + /* d8 */ upi42_op_XRL_A_Rr, upi42_op_XRL_A_Rr, upi42_op_XRL_A_Rr, upi42_op_XRL_A_Rr, upi42_op_XRL_A_Rr, upi42_op_XRL_A_Rr, upi42_op_XRL_A_Rr, upi42_op_XRL_A_Rr, + /* e0 */ NULL, NULL, upi42_op_SUSPEND, upi42_op_MOVP3_A_indA, upi42_op_JMP_imm, upi42_op_EN_DMA, upi42_op_JNC_imm, upi42_op_RL_A, + /* e8 */ upi42_op_DJNZ_Rr_imm, upi42_op_DJNZ_Rr_imm, upi42_op_DJNZ_Rr_imm, upi42_op_DJNZ_Rr_imm, upi42_op_DJNZ_Rr_imm, upi42_op_DJNZ_Rr_imm, upi42_op_DJNZ_Rr_imm, upi42_op_DJNZ_Rr_imm, + /* f0 */ upi42_op_MOV_A_indRr, upi42_op_MOV_A_indRr, upi42_op_JBb_imm, NULL, upi42_op_CALL_imm, upi42_op_EN_FLAGS, upi42_op_JC_imm, upi42_op_RLC_A, + /* f8 */ upi42_op_MOV_A_Rr, upi42_op_MOV_A_Rr, upi42_op_MOV_A_Rr, upi42_op_MOV_A_Rr, upi42_op_MOV_A_Rr, upi42_op_MOV_A_Rr, upi42_op_MOV_A_Rr, upi42_op_MOV_A_Rr + // clang-format on +}; + +static void +upi42_reset(upi42_t *upi42) +{ + upi42->pc = 0; /* program counter */ + upi42->psw = 0; /* stack pointer, register bank and F0 */ + upi42->dbf = 0; /* memory bank */ + upi42->i = upi42->tcnti = 0; /* both interrupts */ + upi42->tf = 0; /* timer flag */ + upi42->sts = 0; /* F1 */ + upi42->suspend = 0; /* 80C42 suspend flag */ +} + +static upi42_t * +upi42_init(int type) +{ + /* Allocate state structure. */ + upi42_t *upi42 = (upi42_t *) malloc(sizeof(upi42_t)); + memset(upi42, 0, sizeof(upi42_t)); + + /* Build instruction table. */ + memcpy(upi42->ops, ops_80c42, sizeof(ops_80c42)); + if (type < UPI42_80C42) { + /* Remove 80C42-only instructions. */ + upi42->ops[0x33] = NULL; /* EN A20 */ + upi42->ops[0x63] = NULL; /* SEL PMB0 */ + upi42->ops[0x73] = NULL; /* SEL PMB1 */ + upi42->ops[0x42] = NULL; /* SUSPEND */ + upi42->ops[0xe2] = NULL; /* SUSPEND */ + } + + return upi42; +} + +int +main(int argc, char **argv) +{ + upi42_t *upi42 = upi42_init(UPI42_8042); + + /* Load ROM. */ + FILE *f = fopen("1503033.bin", "rb"); + fread(upi42->rom, 1, sizeof(upi42->rom), f); + fclose(f); + + /* Start execution. */ + char buf[256]; + while (1) { + upi42->sts |= 0x02; + upi42->sts |= 0x08; + upi42->dbb_in = 0xaa; + upi42->cycs = 0; + + upi42_exec(upi42); + fgets(buf, 256, stdin); + } +} From f47b20a82405d157b5148805b8ac951304ae7604 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 13 Jul 2022 03:32:42 +0200 Subject: [PATCH 005/386] Attempt to optimize hard disk timings by reducing if's. --- src/disk/hdd.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/disk/hdd.c b/src/disk/hdd.c index 1b63a83e9..b66474098 100644 --- a/src/disk/hdd.c +++ b/src/disk/hdd.c @@ -165,6 +165,12 @@ hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_ break; } +#ifndef OLD_CODE + double continuous_times[2][2] = { { hdd->head_switch_usec, hdd->cyl_switch_usec }, + { zone->sector_time_usec, zone->sector_time_usec } }; + double times[2] = { 50.0, hdd->avg_rotation_lat_usec }; +#endif + uint32_t new_track = zone->start_track + ((dst_addr - zone->start_sector) / zone->sectors_per_track); uint32_t new_cylinder = new_track / hdd->phy_heads; uint32_t cylinder_diff = abs((int)hdd->cur_cylinder - (int)new_cylinder); @@ -174,6 +180,7 @@ hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_ double seek_time = 0.0; if (continuous) { +#ifdef OLD_CODE if (new_track == hdd->cur_track) { // Same track seek_time = zone->sector_time_usec; @@ -184,19 +191,31 @@ hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_ // Sequential cylinder seek_time = hdd->cyl_switch_usec; } +#else + seek_time = continuous_times[new_track == hdd->cur_track][!!cylinder_diff]; +#endif } else { if (!cylinder_diff) { +#ifdef OLD_CODE if (operation != HDD_OP_SEEK) { seek_time = hdd->avg_rotation_lat_usec; } else { //seek_time = hdd->cyl_switch_usec; seek_time = 50.0; } +#else + seek_time = times[operation != HDD_OP_SEEK]; +#endif } else { +#ifdef OLD_CODE seek_time = hdd->cyl_switch_usec + (hdd->full_stroke_usec * (double)cylinder_diff / (double)hdd->phy_cyl); if (operation != HDD_OP_SEEK) { seek_time += hdd->avg_rotation_lat_usec; } +#else + seek_time = hdd->cyl_switch_usec + (hdd->full_stroke_usec * (double)cylinder_diff / (double)hdd->phy_cyl) + + ((operation != HDD_OP_SEEK) * hdd->avg_rotation_lat_usec); +#endif } } From b164db81feebfb3f8680a420cf73499ef0e33471 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 13 Jul 2022 04:04:36 +0200 Subject: [PATCH 006/386] Added machine_status.o to Makefile.mingw. --- src/win/Makefile.mingw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index c7c3df7d6..b4b802bbb 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -526,7 +526,7 @@ CXXFLAGS := $(CFLAGS) ######################################################################### MAINOBJ := 86box.o config.o log.o random.o timer.o io.o acpi.o apm.o dma.o ddma.o \ nmi.o pic.o pit.o port_6x.o port_92.o ppi.o pci.o mca.o fifo8.o \ - usb.o device.o nvr.o nvr_at.o nvr_ps2.o \ + usb.o device.o nvr.o nvr_at.o nvr_ps2.o machine_status.o \ $(VNCOBJ) MEMOBJ := catalyst_flash.o i2c_eeprom.o intel_flash.o mem.o rom.o smram.o spd.o sst_flash.o From d1bc26c3ae63f2f86da7c76bd9b311fcda9760db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Wed, 13 Jul 2022 15:56:12 +0200 Subject: [PATCH 007/386] vcpkg: fix OpenAL discovery --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b78e4efe4..f9e856faf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ if(NOT DEFINED QT OR QT) list(APPEND VCPKG_MANIFEST_FEATURES "qt-ui") endif() -if(OPENAL) +if(NOT DEFINED OPENAL OR OPENAL) list(APPEND VCPKG_MANIFEST_FEATURES "openal") endif() From 6821c03d0a314131ea0b9715c50b0e957774725f Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 13 Jul 2022 20:39:29 +0600 Subject: [PATCH 008/386] qt: restore fixed window size property --- src/qt/qt_mainwindow.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 17c91c9a0..72876c61c 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -1437,12 +1437,7 @@ void MainWindow::on_actionFullscreen_triggered() { if (!hide_tool_bar) ui->toolBar->show(); video_fullscreen = 0; if (vid_resize != 1) { - if (vid_resize == 2) setFixedSize(fixed_size_x, fixed_size_y - + menuBar()->height() - + (!hide_status_bar ? statusBar()->height() : 0) - + (!hide_tool_bar ? ui->toolBar->height() : 0)); - - emit resizeContents(monitors[0].mon_scrnsz_x, monitors[0].mon_scrnsz_y); + emit resizeContents(vid_resize == 2 ? fixed_size_x : monitors[0].mon_scrnsz_x, vid_resize == 2 ? fixed_size_y : monitors[0].mon_scrnsz_y); } } else { if (video_fullscreen_first) From a61f10fe55cb1eee2dfbd37b5ff89d598ac1df93 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 13 Jul 2022 23:55:37 +0600 Subject: [PATCH 009/386] qt: Fix double free when multi-monitor is enabled and evdev is used --- src/qt/evdev_mouse.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/qt/evdev_mouse.cpp b/src/qt/evdev_mouse.cpp index 8d708d3a1..120f4572c 100644 --- a/src/qt/evdev_mouse.cpp +++ b/src/qt/evdev_mouse.cpp @@ -70,6 +70,7 @@ void evdev_thread_func() for (unsigned int i = 0; i < evdev_mice.size(); i++) { libevdev_free(evdev_mice[i].second); + evdev_mice[i].second = nullptr; close(evdev_mice[i].first); } evdev_mice.clear(); @@ -77,12 +78,16 @@ void evdev_thread_func() void evdev_stop() { - stopped = true; - evdev_thread->wait(); + if (evdev_thread) { + stopped = true; + evdev_thread->wait(); + evdev_thread = nullptr; + } } void evdev_init() { + if (evdev_thread) return; for (int i = 0; i < 256; i++) { std::string evdev_device_path = "/dev/input/event" + std::to_string(i); From 16690b520330ccb65b8d4cef15af2070ef47bee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Wed, 13 Jul 2022 17:03:21 +0200 Subject: [PATCH 010/386] Actions: Fix macOS build --- .github/workflows/cmake.yml | 7 ++++--- src/sound/CMakeLists.txt | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5606f1342..475a5bc35 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -275,11 +275,12 @@ jobs: run: brew install freetype sdl2 libpng rtmidi qt@5 openal-soft ninja - name: Configure CMake run: >- - PATH=/usr/local/opt/qt@5/bin:$PATH cmake -G Ninja -S . -B build --preset ${{ matrix.build.preset }} - --toolchain cmake/flags-gcc-x86_64.cmake + --toolchain cmake/flags-gcc-x86_64.cmake --debug-find -D NEW_DYNAREC=${{ matrix.build.new-dynarec }} - -D CMAKE_FIND_ROOT_PATH=/usr/local/opt/qt@5 + -D Qt5_ROOT=$(brew --prefix qt@5) + -D Qt5LinguistTools_ROOT=$(brew --prefix qt@5) + -D OpenAL_ROOT=$(brew --prefix openal-soft) - name: Build run: cmake --build build - name: Generate package diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index 087f62cb1..c0aaa2790 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -31,10 +31,11 @@ if(OPENAL) if(TARGET OpenAL::OpenAL) target_link_libraries(86Box OpenAL::OpenAL) else() - include_directories(${OPENAL_INCLUDE_DIR}) target_link_libraries(86Box ${OPENAL_LIBRARY}) endif() + include_directories(${OPENAL_INCLUDE_DIR}) + target_sources(snd PRIVATE openal.c) else() if(WIN32) @@ -49,16 +50,16 @@ else() # Use FAudio, a reimplementation of XAudio2 pkg_check_modules(FAUDIO IMPORTED_TARGET FAudio) if(FAUDIO_FOUND) - include_directories(${FAUDIO_INCLUDE_DIRS}) target_link_libraries(86Box PkgConfig::FAUDIO) else() find_path(FAUDIO_INCLUDE_DIR NAMES "FAudio.h") find_library(FAUDIO_LIBRARY FAudio) - include_directories(${FAUDIO_INCLUDE_DIR}) target_link_libraries(86Box ${FAUDIO_LIBRARY}) endif() + include_directories(${FAUDIO_INCLUDE_DIRS}) + set_property(SOURCE xaudio2.c PROPERTY COMPILE_DEFINITIONS USE_FAUDIO) endif() endif() From d4e22bcedb1180d409c524f7067a74d7c9bedc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Wed, 13 Jul 2022 21:53:21 +0200 Subject: [PATCH 011/386] Actions: Remove a leftover debug parameter --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 475a5bc35..a1b9b4d5b 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -276,7 +276,7 @@ jobs: - name: Configure CMake run: >- cmake -G Ninja -S . -B build --preset ${{ matrix.build.preset }} - --toolchain cmake/flags-gcc-x86_64.cmake --debug-find + --toolchain cmake/flags-gcc-x86_64.cmake -D NEW_DYNAREC=${{ matrix.build.new-dynarec }} -D Qt5_ROOT=$(brew --prefix qt@5) -D Qt5LinguistTools_ROOT=$(brew --prefix qt@5) From cddd0302a5844be51db652f6b921915decd28dfa Mon Sep 17 00:00:00 2001 From: richardg867 Date: Wed, 13 Jul 2022 19:06:52 -0300 Subject: [PATCH 012/386] Another day of work on the 8042 emulator --- src/upi42.c | 528 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 374 insertions(+), 154 deletions(-) diff --git a/src/upi42.c b/src/upi42.c index e98af5496..216f87c73 100644 --- a/src/upi42.c +++ b/src/upi42.c @@ -18,41 +18,52 @@ #include #include #include -#define fatal printf -#define pclog printf -enum { - UPI42_8042 = 0, - UPI42_80C42 -}; +#ifdef UPI42_STANDALONE +# define fatal(...) \ + upi42_log(__VA_ARGS__); \ + abort(); +# define upi42_log printf +#endif + +#define UPI42_REG(upi42, r, op) ((upi42->psw & 0x10) ? (upi42->ram[24 + ((r) &7)] op) : (upi42->ram[(r) &7] op)) + +#define UPI42_ROM_SHIFT 0 /* actually the mask */ +#define UPI42_RAM_SHIFT 16 /* actually the mask */ +#define UPI42_TYPE_MCS (0 << 24) +#define UPI42_TYPE_UPI (1 << 24) +#define UPI42_EXT_C42 (1 << 25) + +#define UPI42_8048 ((1023 << UPI42_ROM_SHIFT) | (63 << UPI42_RAM_SHIFT) | UPI42_TYPE_MCS) +#define UPI42_8049 ((2047 << UPI42_ROM_SHIFT) | (127 << UPI42_RAM_SHIFT) | UPI42_TYPE_MCS) +#define UPI42_8041 ((1023 << UPI42_ROM_SHIFT) | (127 << UPI42_RAM_SHIFT) | UPI42_TYPE_UPI) +#define UPI42_8042 ((2047 << UPI42_ROM_SHIFT) | (255 << UPI42_RAM_SHIFT) | UPI42_TYPE_UPI) +#define UPI42_80C42 ((4095 << UPI42_ROM_SHIFT) | (255 << UPI42_RAM_SHIFT) | UPI42_TYPE_UPI | UPI42_EXT_C42) typedef struct _upi42_ { int (*ops[256])(struct _upi42_ *upi42, uint32_t fetchdat); - uint8_t ram[256], rom[4096], /* memory */ - ports[7], /* I/O ports */ - dbb_in, dbb_out; /* UPI-42 data buffer */ + uint32_t type; + uint8_t ram[256], *rom, /* memory */ + ports_in[8], ports_out[8], /* I/O ports */ + dbb_in, dbb_out; /* UPI-42 data buffer */ - uint8_t rammask, - a, /* accumulator */ - t, /* timer counter */ - psw, /* program status word */ - sts; /* UPI-42 status */ + uint8_t rammask, /* RAM mask */ + a, /* accumulator */ + t, /* timer counter */ + psw, /* program status word */ + sts; /* UPI-42 status */ - uint16_t pc; /* program counter */ + uint16_t pc, rommask; /* program counter and ROM mask */ - unsigned int prescaler : 5, tf : 1, tcnti : 1, run_timer : 1, run_counter : 1, skip_timer_inc : 1, /* timer/counter */ - i : 1, i_asserted : 1, tcnti_asserted : 1, irq_mask : 1, /* interrupts */ - dbf : 1, /* ROM bank */ - t0 : 1, t1 : 1, /* T0/T1 signals */ - flags : 1, /* buffer flag pins */ - suspend : 1; /* 80C42 suspend flag */ + unsigned int prescaler : 5, tf : 1, skip_timer_inc : 1, /* timer/counter */ + run_timer : 1, run_counter : 1, tcnti : 1, /* timer/counter enables */ + i : 1, i_raise : 1, tcnti_raise : 1, irq_mask : 1, /* interrupts */ + t0 : 1, t1 : 1, /* T0/T1 signals */ + flags : 1, dbf : 1, suspend : 1; /* UPI-42 flags */ int cycs; /* cycle counter */ } upi42_t; -#define UPI42_REG_READ(upi42, r) ((upi42->psw & 0x10) ? (upi42->ram[24 + ((r) &7)]) : (upi42->ram[(r) &7])) -#define UPI42_REG_WRITE(upi42, r, op) ((upi42->psw & 0x10) ? (upi42->ram[24 + ((r) &7)] op) : (upi42->ram[(r) &7] op)) - static inline void upi42_mirror_f0(upi42_t *upi42) { @@ -63,14 +74,14 @@ upi42_mirror_f0(upi42_t *upi42) static int upi42_op_MOV_A_Rr(upi42_t *upi42, uint32_t fetchdat) { - upi42->a = UPI42_REG_READ(upi42, fetchdat); + upi42->a = UPI42_REG(upi42, fetchdat, ); return 1; } static int upi42_op_MOV_Rr_A(upi42_t *upi42, uint32_t fetchdat) { - UPI42_REG_WRITE(upi42, fetchdat, = upi42->a); + UPI42_REG(upi42, fetchdat, = upi42->a); return 1; } @@ -91,7 +102,7 @@ upi42_op_MOV_indRr_A(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_MOV_Rr_imm(upi42_t *upi42, uint32_t fetchdat) { - UPI42_REG_WRITE(upi42, fetchdat, = fetchdat >> 8); + UPI42_REG(upi42, fetchdat, = fetchdat >> 8); upi42->cycs--; return 2; } @@ -169,8 +180,8 @@ static int upi42_op_XCH_A_Rr(upi42_t *upi42, uint32_t fetchdat) { uint8_t temp = upi42->a; - upi42->a = UPI42_REG_READ(upi42, fetchdat); - UPI42_REG_WRITE(upi42, fetchdat, = temp); + upi42->a = UPI42_REG(upi42, fetchdat, ); + UPI42_REG(upi42, fetchdat, = temp); return 1; } @@ -202,7 +213,8 @@ upi42_op_SWAP_A(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_IN_A_Pp(upi42_t *upi42, uint32_t fetchdat) { - upi42->a = upi42->ports[fetchdat & 3]; + int port = fetchdat & 3; + upi42->a = upi42->ports_in[port] & upi42->ports_out[port]; upi42->cycs--; return 1; } @@ -211,13 +223,14 @@ static int upi42_op_IN_A_DBB(upi42_t *upi42, uint32_t fetchdat) { upi42->a = upi42->dbb_in; + upi42->sts &= ~0x02; /* clear IBF */ return 1; } static int upi42_op_OUTL_Pp_A(upi42_t *upi42, uint32_t fetchdat) { - upi42->ports[fetchdat & 3] = upi42->a; + upi42->ports_out[fetchdat & 3] = upi42->a; upi42->cycs--; return 1; } @@ -226,14 +239,15 @@ static int upi42_op_OUT_DBB_A(upi42_t *upi42, uint32_t fetchdat) { upi42->dbb_out = upi42->a; - upi42->sts |= 0x01; + upi42->sts |= 0x01; /* set OBF */ return 1; } static int upi42_op_MOVD_A_Pp(upi42_t *upi42, uint32_t fetchdat) { - upi42->a = upi42->ports[4 | (fetchdat & 3)] & 0x0f; + int port = 4 | (fetchdat & 3); + upi42->a = (upi42->ports_in[port] & upi42->ports_out[port]) & 0x0f; upi42->cycs--; return 1; } @@ -241,7 +255,7 @@ upi42_op_MOVD_A_Pp(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_MOVD_Pp_A(upi42_t *upi42, uint32_t fetchdat) { - upi42->ports[4 | (fetchdat & 3)] = upi42->a & 0x0f; + upi42->ports_out[4 | (fetchdat & 3)] = upi42->a & 0x0f; upi42->cycs--; return 1; } @@ -249,21 +263,21 @@ upi42_op_MOVD_Pp_A(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_ANL_A_Rr(upi42_t *upi42, uint32_t fetchdat) { - upi42->a &= UPI42_REG_READ(upi42, fetchdat); + upi42->a &= UPI42_REG(upi42, fetchdat, ); return 1; } static int upi42_op_ORL_A_Rr(upi42_t *upi42, uint32_t fetchdat) { - upi42->a |= UPI42_REG_READ(upi42, fetchdat); + upi42->a |= UPI42_REG(upi42, fetchdat, ); return 1; } static int upi42_op_XRL_A_Rr(upi42_t *upi42, uint32_t fetchdat) { - upi42->a ^= UPI42_REG_READ(upi42, fetchdat); + upi42->a ^= UPI42_REG(upi42, fetchdat, ); return 1; } @@ -315,7 +329,7 @@ upi42_op_XRL_A_imm(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_ANL_Pp_imm(upi42_t *upi42, uint32_t fetchdat) { - upi42->ports[fetchdat & 3] &= fetchdat >> 8; + upi42->ports_out[fetchdat & 3] &= fetchdat >> 8; upi42->cycs--; return 2; } @@ -323,7 +337,7 @@ upi42_op_ANL_Pp_imm(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_ORL_Pp_imm(upi42_t *upi42, uint32_t fetchdat) { - upi42->ports[fetchdat & 3] |= fetchdat >> 8; + upi42->ports_out[fetchdat & 3] |= fetchdat >> 8; upi42->cycs--; return 2; } @@ -331,7 +345,7 @@ upi42_op_ORL_Pp_imm(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_ANLD_Pp_A(upi42_t *upi42, uint32_t fetchdat) { - upi42->ports[4 | (fetchdat & 3)] &= upi42->a; + upi42->ports_out[4 | (fetchdat & 3)] &= upi42->a; upi42->cycs--; return 1; } @@ -339,7 +353,7 @@ upi42_op_ANLD_Pp_A(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_ORLD_Pp_A(upi42_t *upi42, uint32_t fetchdat) { - upi42->ports[4 | (fetchdat & 3)] |= upi42->a; + upi42->ports_out[4 | (fetchdat & 3)] |= upi42->a; upi42->cycs--; return 1; } @@ -386,7 +400,7 @@ upi42_op_INC_A(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_INC_Rr(upi42_t *upi42, uint32_t fetchdat) { - UPI42_REG_WRITE(upi42, fetchdat, ++); + UPI42_REG(upi42, fetchdat, ++); return 1; } @@ -407,15 +421,16 @@ upi42_op_DEC_A(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_DEC_Rr(upi42_t *upi42, uint32_t fetchdat) { - UPI42_REG_WRITE(upi42, fetchdat, --); + UPI42_REG(upi42, fetchdat, --); return 1; } static int upi42_op_DJNZ_Rr_imm(upi42_t *upi42, uint32_t fetchdat) { - UPI42_REG_WRITE(upi42, fetchdat, --); - if (UPI42_REG_READ(upi42, fetchdat)) { + upi42->cycs--; + UPI42_REG(upi42, fetchdat, --); + if (UPI42_REG(upi42, fetchdat, )) { upi42->pc = (upi42->pc & 0xff00) | ((fetchdat >> 8) & 0xff); return 0; } else { @@ -426,7 +441,7 @@ upi42_op_DJNZ_Rr_imm(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_ADD_A_Rr(upi42_t *upi42, uint32_t fetchdat) { - int res = upi42->a + UPI42_REG_READ(upi42, fetchdat); + int res = upi42->a + UPI42_REG(upi42, fetchdat, ); upi42->a = res; upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); return 1; @@ -435,7 +450,7 @@ upi42_op_ADD_A_Rr(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_ADDC_A_Rr(upi42_t *upi42, uint32_t fetchdat) { - int res = upi42->a + (upi42->psw >> 7) + UPI42_REG_READ(upi42, fetchdat); + int res = upi42->a + (upi42->psw >> 7) + UPI42_REG(upi42, fetchdat, ); upi42->a = res; upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); return 1; @@ -444,7 +459,7 @@ upi42_op_ADDC_A_Rr(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_ADD_A_indRr(upi42_t *upi42, uint32_t fetchdat) { - int res = upi42->a + upi42->ram[UPI42_REG_READ(upi42, fetchdat) & upi42->rammask]; + int res = upi42->a + upi42->ram[UPI42_REG(upi42, fetchdat, ) & upi42->rammask]; upi42->a = res; upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); return 1; @@ -453,7 +468,7 @@ upi42_op_ADD_A_indRr(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_ADDC_A_indRr(upi42_t *upi42, uint32_t fetchdat) { - int res = upi42->a + (upi42->psw >> 7) + upi42->ram[UPI42_REG_READ(upi42, fetchdat) & upi42->rammask]; + int res = upi42->a + (upi42->psw >> 7) + upi42->ram[UPI42_REG(upi42, fetchdat, ) & upi42->rammask]; upi42->a = res; upi42->psw = ((res >> 1) & 0x80) | (upi42->psw & ~0x80); return 1; @@ -576,7 +591,7 @@ upi42_op_EN_TCNTI(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_DIS_TCNTI(upi42_t *upi42, uint32_t fetchdat) { - upi42->tcnti = upi42->tcnti_asserted = 0; + upi42->tcnti = upi42->tcnti_raise = 0; return 1; } @@ -644,16 +659,14 @@ upi42_op_CALL_imm(upi42_t *upi42, uint32_t fetchdat) { /* Push new frame onto stack. */ uint8_t sp = (upi42->psw & 0x07) << 1; - upi42->ram[8 + sp++] = upi42->pc; /* stack frame format is undocumented! */ + upi42->ram[8 + sp++] = upi42->pc + 2; /* stack frame format is undocumented! */ upi42->ram[8 + sp++] = (upi42->psw & 0xf0) | ((upi42->pc >> 8) & 0x07); upi42->psw = (upi42->psw & 0xf8) | (sp >> 1); /* Load new program counter. */ upi42->pc = (upi42->dbf << 11) | ((fetchdat << 3) & 0x0700) | ((fetchdat >> 8) & 0x00ff); - /* Don't decrease cycle counter if this is an interrupt call. */ - if (fetchdat & 0xff) - upi42->cycs--; + upi42->cycs--; return 0; } @@ -703,24 +716,24 @@ upi42_op_JMPP_indA(upi42_t *upi42, uint32_t fetchdat) { \ if (cond) \ upi42->pc = (upi42->pc & 0xff00) | ((fetchdat >> 8) & 0x00ff); \ - post \ - upi42->cycs--; \ + post; \ + upi42->cycs--; \ return 2 * !(cond); \ } -UPI42_COND_JMP_IMM(JC, upi42->psw & 0x80, ;) -UPI42_COND_JMP_IMM(JNC, !(upi42->psw & 0x80), ;) -UPI42_COND_JMP_IMM(JZ, !upi42->a, ;) -UPI42_COND_JMP_IMM(JNZ, upi42->a, ;) -UPI42_COND_JMP_IMM(JT0, upi42->t0, ;) -UPI42_COND_JMP_IMM(JNT0, !upi42->t0, ;) -UPI42_COND_JMP_IMM(JT1, upi42->t1, ;) -UPI42_COND_JMP_IMM(JNT1, !upi42->t1, ;) -UPI42_COND_JMP_IMM(JF0, upi42->psw & 0x20, ;) -UPI42_COND_JMP_IMM(JF1, upi42->sts & 0x08, ;) -UPI42_COND_JMP_IMM(JTF, !upi42->tf, upi42->tf = 0;) -UPI42_COND_JMP_IMM(JBb, upi42->a &(1 << ((fetchdat >> 5) & 7)), ;) -UPI42_COND_JMP_IMM(JNIBF, !(upi42->sts & 0x02), ;) -UPI42_COND_JMP_IMM(JOBF, upi42->sts & 0x01, ;) +UPI42_COND_JMP_IMM(JC, upi42->psw & 0x80, ) +UPI42_COND_JMP_IMM(JNC, !(upi42->psw & 0x80), ) +UPI42_COND_JMP_IMM(JZ, !upi42->a, ) +UPI42_COND_JMP_IMM(JNZ, upi42->a, ) +UPI42_COND_JMP_IMM(JT0, upi42->t0, ) +UPI42_COND_JMP_IMM(JNT0, !upi42->t0, ) +UPI42_COND_JMP_IMM(JT1, upi42->t1, ) +UPI42_COND_JMP_IMM(JNT1, !upi42->t1, ) +UPI42_COND_JMP_IMM(JF0, upi42->psw & 0x20, ) +UPI42_COND_JMP_IMM(JF1, upi42->sts & 0x08, ) +UPI42_COND_JMP_IMM(JTF, !upi42->tf, upi42->tf = 0) +UPI42_COND_JMP_IMM(JBb, upi42->a &(1 << ((fetchdat >> 5) & 7)), ) +UPI42_COND_JMP_IMM(JNIBF, !(upi42->sts & 0x02), ) +UPI42_COND_JMP_IMM(JOBF, upi42->sts & 0x01, ) static int upi42_op_EN_A20(upi42_t *upi42, uint32_t fetchdat) @@ -738,6 +751,7 @@ upi42_op_EN_DMA(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_EN_FLAGS(upi42_t *upi42, uint32_t fetchdat) { + upi42->flags = 1; return 1; } @@ -749,65 +763,6 @@ upi42_op_SUSPEND(upi42_t *upi42, uint32_t fetchdatr) return 1; } -static void -upi42_exec(void *priv) -{ - upi42_t *upi42 = (upi42_t *) priv; - - /* Skip interrupt handling and code execution if we're suspended or in a multi-cycle instruction. */ - if (upi42->suspend || ++upi42->cycs < 0) - return; - - /* Trigger interrupt if requested. */ - if (upi42->irq_mask) { - /* Masked, we're currently in an ISR. */ - } else if (upi42->i_asserted) { - /* External interrupt. Higher priority than the timer interrupt. */ - upi42->irq_mask = 1; - upi42->i_asserted = 0; - upi42_op_CALL_imm(upi42, 3 << 8); - return; - } else if (upi42->tcnti_asserted) { - /* Timer interrupt. */ - upi42->irq_mask = 1; - upi42->tcnti_asserted = 0; - upi42_op_CALL_imm(upi42, 7 << 8); - return; - } - - /* Fetch instruction. */ - uint32_t fetchdat = *((uint32_t *) &upi42->rom[upi42->pc]); - pclog("%04X @ %04X R0=%02X", fetchdat & 0xffff, upi42->pc, upi42->ram[0]); - - /* Decode instruction. */ - uint8_t insn = fetchdat & 0xff; - if (upi42->ops[insn]) { - /* Execute instruction and increment program counter. */ - upi42->pc += upi42->ops[insn](upi42, fetchdat); - - /* Decrement cycle counter. Multi-cycle instructions also decrement within their code. */ - upi42->cycs--; - } else { - fatal("UPI42: Unknown opcode %02X (%08X)\n", insn, fetchdat); - return; - } - - /* Some instructions don't increment the timer. */ - if (upi42->skip_timer_inc) { - upi42->skip_timer_inc = 0; - } else { - /* Increment counter once the prescaler overflows, - and set timer flag once the main value overflows. */ - if ((++upi42->prescaler == 0) && (++upi42->t == 0)) { - upi42->tf = 1; - - /* Fire counter interrupt if enabled. */ - if (upi42->tcnti) - upi42->tcnti_asserted = 1; - } - } -} - static const int (*ops_80c42[256])(upi42_t *upi42, uint32_t fetchdat) = { // clang-format off /* 0 / 8 */ /* 1 / 9 */ /* 2 / a */ /* 3 / b */ /* 4 / c */ /* 5 / d */ /* 6 / e */ /* 7 / f */ @@ -823,9 +778,9 @@ static const int (*ops_80c42[256])(upi42_t *upi42, uint32_t fetchdat) = { /* 48 */ upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, upi42_op_ORL_A_Rr, /* 50 */ upi42_op_ANL_A_indRr, upi42_op_ANL_A_indRr, upi42_op_JBb_imm, upi42_op_ANL_A_imm, upi42_op_CALL_imm, upi42_op_STRT_T, upi42_op_JT1_imm, upi42_op_DA_A, /* 58 */ upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, upi42_op_ANL_A_Rr, - /* 60 */ upi42_op_ADD_A_indRr, upi42_op_ADD_A_indRr, upi42_op_MOV_T_A, NULL, upi42_op_JMP_imm, upi42_op_STOP_TCNT, NULL, upi42_op_RRC_A, + /* 60 */ upi42_op_ADD_A_indRr, upi42_op_ADD_A_indRr, upi42_op_MOV_T_A, upi42_op_SEL_PMB0, upi42_op_JMP_imm, upi42_op_STOP_TCNT, NULL, upi42_op_RRC_A, /* 68 */ upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, upi42_op_ADD_A_Rr, - /* 70 */ upi42_op_ADDC_A_indRr, upi42_op_ADDC_A_indRr, upi42_op_JBb_imm, NULL, upi42_op_CALL_imm, NULL, upi42_op_JF1_imm, upi42_op_RR_A, + /* 70 */ upi42_op_ADDC_A_indRr, upi42_op_ADDC_A_indRr, upi42_op_JBb_imm, upi42_op_SEL_PMB1, upi42_op_CALL_imm, NULL, upi42_op_JF1_imm, upi42_op_RR_A, /* 78 */ upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, upi42_op_ADDC_A_Rr, /* 80 */ NULL, NULL, upi42_op_SUSPEND, upi42_op_RET, upi42_op_JMP_imm, upi42_op_CLR_F0, upi42_op_JOBF_imm, NULL, /* 88 */ upi42_op_ORL_Pp_imm, upi42_op_ORL_Pp_imm, upi42_op_ORL_Pp_imm, upi42_op_ORL_Pp_imm, upi42_op_ORLD_Pp_A, upi42_op_ORLD_Pp_A, upi42_op_ORLD_Pp_A, upi42_op_ORLD_Pp_A, @@ -847,27 +802,184 @@ static const int (*ops_80c42[256])(upi42_t *upi42, uint32_t fetchdat) = { }; static void -upi42_reset(upi42_t *upi42) +upi42_exec(void *priv) { - upi42->pc = 0; /* program counter */ - upi42->psw = 0; /* stack pointer, register bank and F0 */ - upi42->dbf = 0; /* memory bank */ - upi42->i = upi42->tcnti = 0; /* both interrupts */ - upi42->tf = 0; /* timer flag */ - upi42->sts = 0; /* F1 */ - upi42->suspend = 0; /* 80C42 suspend flag */ + upi42_t *upi42 = (upi42_t *) priv; + + /* Skip everything if we're suspended, or just process timer if we're in a multi-cycle instruction. */ + if (upi42->suspend) + return; + else if (++upi42->cycs < 0) + goto timer; + + /* Trigger interrupt if requested. */ + if (upi42->irq_mask) { + /* Masked, we're currently in an ISR. */ + } else if (upi42->i_raise) { + /* External interrupt. Higher priority than the timer interrupt. */ + upi42->irq_mask = 1; + upi42->i_raise = 0; + + upi42->pc -= 2; + upi42->cycs++; + upi42_op_CALL_imm(upi42, 3 << 8); + return; + } else if (upi42->tcnti_raise) { + /* Timer interrupt. */ + upi42->irq_mask = 1; + upi42->tcnti_raise = 0; + + upi42->pc -= 2; + upi42->cycs++; + upi42_op_CALL_imm(upi42, 7 << 8); + return; + } + + /* Fetch instruction. */ + uint32_t fetchdat = *((uint32_t *) &upi42->rom[upi42->pc]); + + /* Decode instruction. */ + uint8_t insn = fetchdat & 0xff; + if (upi42->ops[insn]) { + /* Execute instruction. */ + int pc_inc = upi42->ops[insn](upi42, fetchdat); + + /* Increment lower 11 bits of the program counter. */ + upi42->pc = (upi42->pc & 0xf800) | ((upi42->pc + pc_inc) & 0x07ff); + + /* Decrement cycle counter. Multi-cycle instructions also decrement within their code. */ + upi42->cycs--; + } else { + fatal("UPI42: Unknown opcode %02X (%08X)\n", insn, fetchdat); + return; + } + +timer: + /* Process timer. */ + if (!upi42->run_timer) { + /* Timer disabled. */ + } else if (upi42->skip_timer_inc) { + /* Some instructions don't increment the timer. */ + upi42->skip_timer_inc = 0; + } else { + /* Increment counter once the prescaler overflows, + and set timer flag once the main value overflows. */ + if ((++upi42->prescaler == 0) && (++upi42->t == 0)) { + upi42->tf = 1; + + /* Fire counter interrupt if enabled. */ + if (upi42->tcnti) + upi42->tcnti_raise = 1; + } + } } -static upi42_t * -upi42_init(int type) +uint8_t +upi42_port_read(void *priv, int port) +{ + upi42_t *upi42 = (upi42_t *) priv; + + /* Read base port value. */ + port &= 7; + uint8_t ret = upi42->ports_in[port] & upi42->ports_out[port]; + + /* Apply special meanings. */ + switch (port) { + } + + upi42_log("UPI42: port_read(%d) = %02X\n", port, ret); + return ret; +} + +void +upi42_port_write(void *priv, int port, uint8_t val) +{ + upi42_t *upi42 = (upi42_t *) priv; + + port &= 7; + upi42_log("UPI42: port_write(%d, %02X)\n", port, val); + + /* Set input level. */ + upi42->ports_in[port] = val; +} + +/* NOTE: The dbb/sts/cmd functions use I/O handler signatures; port is ignored. */ + +uint8_t +upi42_dbb_read(uint16_t port, void *priv) +{ + upi42_t *upi42 = (upi42_t *) priv; + + uint8_t ret = upi42->dbb_out; + upi42_log("UPI42: dbb_read(%04X) = %02X\n", port, ret); + upi42->sts &= ~0x01; /* clear OBF */ + return ret; +} + +void +upi42_dbb_write(uint16_t port, uint8_t val, void *priv) +{ + upi42_t *upi42 = (upi42_t *) priv; + + upi42_log("UPI42: dbb_write(%04X, %02X)\n", port, val); + upi42->dbb_in = val; + upi42->sts = (upi42->sts & ~0x08) | 0x02; /* clear F1 and set IBF */ + if (upi42->i) /* fire IBF interrupt if enabled */ + upi42->i_raise = 1; +} + +uint8_t +upi42_sts_read(uint16_t port, void *priv) +{ + upi42_t *upi42 = (upi42_t *) priv; + + uint8_t ret = upi42->sts; + upi42_log("UPI42: sts_read(%04X) = %02X\n", port, ret); + return ret; +} + +void +upi42_cmd_write(uint16_t port, uint8_t val, void *priv) +{ + upi42_t *upi42 = (upi42_t *) priv; + + upi42_log("UPI42: cmd_write(%04X, %02X)\n", port, val); + upi42->dbb_in = val; + upi42->sts |= 0x0a; /* set F1 and IBF */ + if (upi42->i) /* fire IBF interrupt if enabled */ + upi42->i_raise = 1; +} + +void +upi42_reset(upi42_t *upi42) +{ + upi42->pc = 0; /* program counter */ + upi42->psw = 0; /* stack pointer, register bank and F0 */ + upi42->dbf = 0; /* ROM bank */ + upi42->i = 0; /* external interrupt */ + upi42->tcnti = 0; /* timer/counter interrupt */ + upi42->tf = 0; /* timer flag */ + upi42->sts = 0; /* F1 */ + upi42->flags = 0; /* UPI-42 buffer interrupts */ + upi42->suspend = 0; /* 80C42 suspend flag */ +} + +void * +upi42_init(uint32_t type, uint8_t *rom) { /* Allocate state structure. */ upi42_t *upi42 = (upi42_t *) malloc(sizeof(upi42_t)); memset(upi42, 0, sizeof(upi42_t)); + upi42->rom = rom; + + /* Set chip type. */ + upi42->type = type; + upi42->rommask = type >> UPI42_ROM_SHIFT; + upi42->rammask = type >> UPI42_RAM_SHIFT; /* Build instruction table. */ memcpy(upi42->ops, ops_80c42, sizeof(ops_80c42)); - if (type < UPI42_80C42) { + if (!(type & UPI42_EXT_C42)) { /* Remove 80C42-only instructions. */ upi42->ops[0x33] = NULL; /* EN A20 */ upi42->ops[0x63] = NULL; /* SEL PMB0 */ @@ -879,25 +991,133 @@ upi42_init(int type) return upi42; } +#ifdef UPI42_STANDALONE +static const char *flags_8042[] = { "OBF", "IBF", "F0", "F1", "ST4", "ST5", "ST6", "ST7" }; + int main(int argc, char **argv) { - upi42_t *upi42 = upi42_init(UPI42_8042); + /* Check arguments. */ + if (argc < 2) { + upi42_log("Specify a ROM file to execute.\n"); + return 1; + } /* Load ROM. */ - FILE *f = fopen("1503033.bin", "rb"); - fread(upi42->rom, 1, sizeof(upi42->rom), f); + uint8_t rom[4096] = { 0 }; + FILE *f = fopen(argv[1], "rb"); + if (!f) { + upi42_log("Could not read ROM file.\n"); + return 2; + } + size_t rom_size = fread(rom, sizeof(rom[0]), sizeof(rom), f); fclose(f); - /* Start execution. */ - char buf[256]; - while (1) { - upi42->sts |= 0x02; - upi42->sts |= 0x08; - upi42->dbb_in = 0xaa; - upi42->cycs = 0; + /* Determine chip type from ROM. */ + upi42_log("%d-byte ROM, ", rom_size); + uint32_t type; + switch (rom_size) { + case 0 ... 1024: + upi42_log("emulating 8041"); + type = UPI42_8041; + break; - upi42_exec(upi42); - fgets(buf, 256, stdin); + case 1025 ... 2048: + upi42_log("emulating 8042"); + type = UPI42_8042; + break; + + case 2049 ... 4096: + upi42_log("emulating 80C42"); + type = UPI42_80C42; + break; + + default: + upi42_log("unknown!\n"); + return 3; } + upi42_log(".\n"); + + /* Initialize emulator. */ + upi42_t *upi42 = (upi42_t *) upi42_init(type, rom); + + /* Start execution. */ + char cmd, cmd_buf[256]; + int val, go_until = -1; + while (1) { + /* Output status. */ + upi42_log("PC=%04X I=%02X(%02X) A=%02X", upi42->pc, upi42->rom[upi42->pc], upi42->rom[upi42->pc + 1], upi42->a); + for (val = 0; val < 8; val++) + upi42_log(" R%d=%02X", val, UPI42_REG(upi42, val, )); + upi42_log(" T=%02X PSW=%02X TF=%d I=%d TCNTI=%d", upi42->t, upi42->psw, upi42->tf, upi42->i, upi42->tcnti); + if (type & UPI42_TYPE_UPI) { + upi42_log(" STS=%02X", upi42->sts); + for (val = 0; val < 8; val++) { + if (upi42->sts & (1 << val)) + upi42_log(" [%s]", flags_8042[val]); + else + upi42_log(" %s ", flags_8042[val]); + } + } + upi42_log("\n"); + + /* Break for command only if stepping. */ + if ((go_until < 0) || (upi42->pc == go_until)) { +retry: + go_until = -1; + upi42_log("> "); + + /* Read command. */ + cmd = '\0'; + scanf("%c", &cmd); + + /* Execute command. */ + switch (cmd) { + case 'c': /* write command */ + if (scanf("%X%*c", &val, &cmd_buf)) + upi42_cmd_write(0, val, upi42); + goto retry; + + case 'd': /* write data */ + if (scanf("%X%*c", &val, &cmd_buf)) + upi42_dbb_write(0, val, upi42); + goto retry; + + case 'g': /* go until */ + if (!scanf("%X%*c", &go_until, &cmd_buf)) + go_until = -1; + break; + + case 'r': /* read data */ + upi42_dbb_read(0, upi42); /* return value will be logged */ + goto skip_and_retry; + + case 'q': /* exit */ + return 0; + + case '\r': /* step */ + case '\n': + case '\0': + break; + + default: + upi42_log("Monitor commands:\n"); + upi42_log("- Return (no command) - Step execution\n"); + upi42_log("- q (or Ctrl+C) - Exit\n"); + upi42_log("- gXXXX - Execute until PC is hex value XXXX\n"); + upi42_log("- dXX - Write hex value XX to data port\n"); + upi42_log("- cXX - Write hex value XX to command port\n"); + upi42_log("- r - Read from data port and reset OBF\n"); +skip_and_retry: + scanf("%*c", &cmd_buf); + goto retry; + } + } + + /* Execute a cycle. */ + upi42_exec(upi42); + } + + return 0; } +#endif From ebca2da32a3ea34f8d19b5652761d72f76a87fe9 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Wed, 13 Jul 2022 19:10:56 -0300 Subject: [PATCH 013/386] Fix 8042 emulator under MSYS2 --- src/upi42.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/upi42.c b/src/upi42.c index 216f87c73..77d580004 100644 --- a/src/upi42.c +++ b/src/upi42.c @@ -20,10 +20,16 @@ #include #ifdef UPI42_STANDALONE -# define fatal(...) \ - upi42_log(__VA_ARGS__); \ - abort(); -# define upi42_log printf +# define fatal(...) \ + { \ + upi42_log(__VA_ARGS__); \ + abort(); \ + } +# define upi42_log(...) \ + { \ + printf(__VA_ARGS__); \ + fflush(stdout); \ + } #endif #define UPI42_REG(upi42, r, op) ((upi42->psw & 0x10) ? (upi42->ram[24 + ((r) &7)] op) : (upi42->ram[(r) &7] op)) @@ -1053,10 +1059,11 @@ main(int argc, char **argv) if (type & UPI42_TYPE_UPI) { upi42_log(" STS=%02X", upi42->sts); for (val = 0; val < 8; val++) { - if (upi42->sts & (1 << val)) + if (upi42->sts & (1 << val)) { upi42_log(" [%s]", flags_8042[val]); - else + } else { upi42_log(" %s ", flags_8042[val]); + } } } upi42_log("\n"); From 6b63feb6ac7d4c5f721bbdcefb8053f8e2ebbf70 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 14 Jul 2022 02:31:59 +0200 Subject: [PATCH 014/386] Preliminary code for UPI42 integration into 86Box. --- src/upi42.c | 332 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 328 insertions(+), 4 deletions(-) diff --git a/src/upi42.c b/src/upi42.c index 77d580004..8b8e4b72e 100644 --- a/src/upi42.c +++ b/src/upi42.c @@ -30,6 +30,33 @@ printf(__VA_ARGS__); \ fflush(stdout); \ } +#else +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/timer.h> + + +#ifdef ENABLE_UPI42_LOG +int upi42_do_log = ENABLE_UPI42_LOG; + + +void +upi42_log(const char *fmt, ...) +{ + va_list ap; + + if (upi42_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +#define upi42_log(fmt, ...) +#endif #endif #define UPI42_REG(upi42, r, op) ((upi42->psw & 0x10) ? (upi42->ram[24 + ((r) &7)] op) : (upi42->ram[(r) &7] op)) @@ -68,6 +95,11 @@ typedef struct _upi42_ { flags : 1, dbf : 1, suspend : 1; /* UPI-42 flags */ int cycs; /* cycle counter */ + +#ifndef UPI42_STANDALONE + uint8_t ram_index; + uint16_t rom_index; +#endif } upi42_t; static inline void @@ -970,11 +1002,9 @@ upi42_reset(upi42_t *upi42) upi42->suspend = 0; /* 80C42 suspend flag */ } -void * -upi42_init(uint32_t type, uint8_t *rom) +void +upi42_do_init(upi32_t type, uint8_t *rom) { - /* Allocate state structure. */ - upi42_t *upi42 = (upi42_t *) malloc(sizeof(upi42_t)); memset(upi42, 0, sizeof(upi42_t)); upi42->rom = rom; @@ -994,6 +1024,18 @@ upi42_init(uint32_t type, uint8_t *rom) upi42->ops[0xe2] = NULL; /* SUSPEND */ } + memset(upi42_t->ports_in, 0xff, 0x08); + upi42_t->t0 = 1; + upi42_t->t1 = 1; +} + +void * +upi42_init(uint32_t type, uint8_t *rom) +{ + /* Allocate state structure. */ + upi42_t *upi42 = (upi42_t *) malloc(sizeof(upi42_t)); + upi42_do_init(type, rom); + return upi42; } @@ -1127,4 +1169,286 @@ skip_and_retry: return 0; } +#else +static void +upi42_write(uint16_t port, uint8_t val, void *priv) +{ + upi42_t *upi42 = (upi42_t *) priv; + uint32_t temp_type, uint8_t *temp_rom; + int i; + + switch (port) { + /* Write to data port. */ + case 0x0060: + case 0x0160: + upi42_dbb_write(0, val, upi42); + break; + + /* RAM Index. */ + case 0x0162: + upi42->ram_index = val & upi42->rammask; + break; + + /* RAM. */ + case 0x0163: + upi42->ram[upi42->ram_index & upi42->rammask] = val; + break; + + /* Write to command port. */ + case 0x0064: + case 0x0164: + upi42_cmd_write(0, val, upi42); + break; + + /* Input ports. */ + case 0x0180 ... 0x0187: + upi42->ports_in[addr & 0x0007] = val; + break; + + /* Output ports. */ + case 0x0188 ... 0x018f: + upi42->ports_out[addr & 0x0007] = val; + break; + + /* 4 = T0, 5 = T1. */ + case 0x0194: + upi42->t0 = (val >> 4) & 0x01; + upi42->t1 = (val >> 5) & 0x01; + break; + + /* Program counter. */ + case 0x0196: + upi42->pc = (upi42->pc & 0xff00) | val; + break; + case 0x0197: + upi42->pc = (upi42->pc & 0x00ff) | (val << 8); + break; + + /* Input data buffer. */ + case 0x019a: + upi42->dbb_in = val; + break; + + /* Output data buffer. */ + case 0x019b: + upi42->dbb_out = val; + break; + + /* ROM Index. */ + case 0x01a0: + upi42->rom_index = (upi42->rom_index & 0xff00) | val; + break; + case 0x01a1: + upi42->rom_index = (upi42->rom_index & 0x00ff) | (val << 8); + break; + + /* Hard reset. */ + case 0x01a2: + temp_type = upi42->type; + temp_rom = upi42->rom; + upi42_do_init(temp_type, temp_rom); + break; + + /* Soft reset. */ + case 0x01a3: + upi42_reset(upi42); + break; + + /* ROM. */ + case 0x01a4: + upi42->rom[upi42->rom_index & upi42->rommask] = val; + break; + case 0x01a5: + upi42->rom[(upi42->rom_index + 1) & upi42->rommask] = val; + break; + case 0x01a6: + upi42->rom[(upi42->rom_index + 2) & upi42->rommask] = val; + break; + case 0x01a7: + upi42->rom[(upi42->rom_index + 3) & upi42->rommask] = val; + break; + + /* Pause. */ + case 0x01a8: + break; + + /* Resume. */ + case 0x01a9: + break; + + /* Bus master ROM: 0 = direction (0 = to memory, 1 = from memory). */ + case 0x01aa: + if (val & 0x01) { + for (i = 0; i <= upi42->rommask; i += 4) + *(uint32_t *) &(upi42->rom[i]) = mem_readl_phys(upi42->ram_addr + i); + } else { + for (i = 0; i <= upi42->rommask; i += 4) + mem_writel_phys(upi42->ram_addr + i, *(uint32_t *) &(upi42->rom[i])); + } + upi42->bm_stat = (val & 0x01) | 0x02; + break; + } +} + + +static uint8_t +upi42_read(uint16_t port, void *priv) +{ + upi42_t *upi42 = (upi42_t *) priv; + uint8_t ret = 0xff; + + switch (port) { + /* Type. */ + case 0x015c: + ret = upi42->type & 0xff; + break; + case 0x015d: + ret = upi42->type >> 8; + break; + case 0x015e: + ret = upi42->type >> 16; + break; + case 0x015f: + ret = upi42->type >> 24; + break; + + /* Read from data port and reset OBF. */ + case 0x0060: + case 0x0160: + ret = upi42->dbb_out; + upi42->sts &= ~0x01; /* clear OBF */ + break; + + /* RAM Mask. */ + case 0x0161: + ret = upi42->rammask; + break; + + /* RAM Index. */ + case 0x0162: + ret = upi42->ram_index; + break; + + /* RAM. */ + case 0x0163: + ret = upi42->ram[upi42->ram_index & upi42->rammask]; + break; + + /* Read status. */ + case 0x0064: + case 0x0164: + ret = upi42->sts; + break; + + /* Input ports. */ + case 0x0180 ... 0x0187: + ret = upi42->ports_in[addr & 0x0007]; + break; + + /* Output ports. */ + case 0x0188 ... 0x018f: + ret = upi42->ports_out[addr & 0x0007]; + break; + + /* Accumulator. */ + case 0x0190: + ret = upi42->a; + break; + + /* Timer counter. */ + case 0x0191: + ret = upi42->t; + break; + + /* Program status word. */ + case 0x0192: + ret = upi42->psw; + break; + + /* 0-4 = Prescaler, 5 = TF, 6 = Skip Timer Inc, 7 = Run Timer. */ + case 0x0193: + ret = (upi42->prescaler & 0x1f) || ((upi42->tf & 0x01) << 5) || ((upi42->skip_timer_inc & 0x01) << 6) || ((upi42->run_timer & 0x01) << 7); + break; + + /* 0 = I, 1 = I Raise, 2 = TCNTI Raise, 3 = IRQ Mask, 4 = T0, 5 = T1, 6 = Flags, 7 = DBF. */ + case 0x0194: + ret = (upi42->i & 0x01) || ((upi42->i_raise & 0x01) << 1) || ((upi42->tcnti_raise & 0x01) << 2) || ((upi42->irq_mask & 0x01) << 3) || + ((upi42->t0 & 0x01) << 4) || ((upi42->t1 & 0x01) << 5) || ((upi42->flags & 0x01) << 6) || ((upi42->dbf & 0x01) << 7); + break; + + /* 0 = Suspend. */ + case 0x0195: + ret = (upi42->suspend & 0x01); + break; + + /* Program counter. */ + case 0x0196: + ret = upi42->pc & 0xff; + break; + case 0x0197: + ret = upi42->pc >> 8; + break; + + /* ROM Mask. */ + case 0x0198: + ret = upi42->rommask & 0xff; + break; + case 0x0199: + ret = upi42->rommask >> 8; + break; + + /* Input data buffer. */ + case 0x019a: + ret = upi42->dbb_in; + break; + + /* Output data buffer. */ + case 0x019b: + ret = upi42->dbb_out; + break; + + /* Cycle counter. */ + case 0x019c: + ret = upi42->cycs & 0xff; + break; + case 0x019d: + ret = upi42->cycs >> 8; + break; + case 0x019e: + ret = upi42->cycs >> 16; + break; + case 0x019f: + ret = upi42->cycs >> 24; + break; + + /* ROM Index. */ + case 0x01a0: + ret = upi42->rom_index & 0xff; + break; + case 0x01a1: + ret = upi42->rom_index >> 8; + break; + + /* ROM. */ + case 0x01a4: + ret = upi42->rom[upi42->rom_index & upi42->rommask]; + break; + case 0x01a5: + ret = upi42->rom[(upi42->rom_index + 1) & upi42->rommask]; + break; + case 0x01a6: + ret = upi42->rom[(upi42->rom_index + 2) & upi42->rommask]; + break; + case 0x01a7: + ret = upi42->rom[(upi42->rom_index + 3) & upi42->rommask]; + break; + + /* Bus master status: 0 = direction, 1 = finished. */ + case 0x01ab: + ret = upi42->bm_stat; + break; + } + + return ret; +} #endif From a10e010a93dfb704addc9adb6d2caaeba9854237 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 14 Jul 2022 22:16:53 -0400 Subject: [PATCH 015/386] Don't shut down when second display is closed --- src/qt/qt_rendererstack.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index ae451db6c..795c31fe7 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -447,7 +447,11 @@ RendererStack::blitCommon(int x, int y, int w, int h) void RendererStack::closeEvent(QCloseEvent* event) { - if (cpu_thread_run == 0 || is_quit == 1) { event->accept(); return; } + if (cpu_thread_run == 0 || is_quit == 0) { + event->accept(); + show_second_monitors = 0; // TODO: This isn't actually the right fix, so fix this properly. + return; + } event->ignore(); main_window->close(); } From b80fda4280318ac3d54524cb7998b190db84a567 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Fri, 15 Jul 2022 12:34:41 +0200 Subject: [PATCH 016/386] The IBM 386/486 cpu's are based on modified Intel 386 designs and, as such, should behave like the them on the x86 flag ops. --- src/cpu/x86_ops_flag.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpu/x86_ops_flag.h b/src/cpu/x86_ops_flag.h index 24c97339e..ce0cb4cd6 100644 --- a/src/cpu/x86_ops_flag.h +++ b/src/cpu/x86_ops_flag.h @@ -266,11 +266,11 @@ static int opPOPFD(uint32_t fetchdat) else if (IOPLp) cpu_state.flags = (cpu_state.flags & 0x3000) | (templ & 0x4fd5) | 2; else cpu_state.flags = (cpu_state.flags & 0x3200) | (templ & 0x4dd5) | 2; - templ &= (is486 || isibm486) ? 0x3c0000 : 0; + templ &= (is486) ? 0x3c0000 : 0; templ |= ((cpu_state.eflags&3) << 16); if (cpu_CR4_mask & CR4_VME) cpu_state.eflags = (templ >> 16) & 0x3f; else if (CPUID) cpu_state.eflags = (templ >> 16) & 0x27; - else if (is486 || isibm486) cpu_state.eflags = (templ >> 16) & 7; + else if (is486) cpu_state.eflags = (templ >> 16) & 7; else cpu_state.eflags = (templ >> 16) & 3; flags_extract(); From 5f8d5dbe9039a61ddbba7a798a9c942aa0fe5a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 15 Jul 2022 16:01:24 +0200 Subject: [PATCH 017/386] Discord: Target the latest SDK, fixes #2455 --- src/discord.c | 127 +++++------ src/include/discord_game_sdk.h | 399 ++++++++++++++++++++------------- 2 files changed, 300 insertions(+), 226 deletions(-) diff --git a/src/discord.c b/src/discord.c index 27b8c6fdf..d1966a93d 100644 --- a/src/discord.c +++ b/src/discord.c @@ -15,69 +15,68 @@ * Copyright 2019 David Hrdlička. */ #include -#include #include +#include #include #include #include #define HAVE_STDARG_H -#include <86box/86box.h> #include "cpu/cpu.h" +#include <86box/86box.h> +#include <86box/discord.h> #include <86box/machine.h> #include <86box/plat.h> #include <86box/plat_dynld.h> -#include <86box/discord.h> #include #ifdef _WIN32 -#define PATH_DISCORD_DLL "discord_game_sdk.dll" +# define PATH_DISCORD_DLL "discord_game_sdk.dll" #elif defined __APPLE__ -#define PATH_DISCORD_DLL "discord_game_sdk.dylib" +# define PATH_DISCORD_DLL "discord_game_sdk.dylib" #else -#define PATH_DISCORD_DLL "discord_game_sdk.so" +# define PATH_DISCORD_DLL "discord_game_sdk.so" #endif -int discord_loaded = 0; +int discord_loaded = 0; -static void *discord_handle = NULL; -static struct IDiscordCore *discord_core = NULL; -static struct IDiscordActivityManager *discord_activities = NULL; +static void *discord_handle = NULL; +static struct IDiscordCore *discord_core = NULL; +static struct IDiscordActivityManager *discord_activities = NULL; -static enum EDiscordResult (*discord_create)(DiscordVersion version, struct DiscordCreateParams* params, struct IDiscordCore** result); +static enum EDiscordResult(DISCORD_API *discord_create)(DiscordVersion version, struct DiscordCreateParams *params, struct IDiscordCore **result); static dllimp_t discord_imports[] = { - { "DiscordCreate", &discord_create }, - { NULL, NULL } + {"DiscordCreate", &discord_create}, + { NULL, NULL } }; #ifdef ENABLE_DISCORD_LOG int discord_do_log = 1; - static void discord_log(const char *fmt, ...) { va_list ap; if (discord_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); } } #else -#define discord_log(fmt, ...) +# define discord_log(fmt, ...) #endif void discord_update_activity(int paused) { struct DiscordActivity activity; - char cpufamily[1024]; - char *paren; + char cpufamily[1024]; + char *paren; - if(discord_activities == NULL) - return; + if (discord_activities == NULL) + return; discord_log("discord: discord_update_activity(paused=%d)\n", paused); @@ -86,53 +85,47 @@ discord_update_activity(int paused) strncpy(cpufamily, cpu_f->name, sizeof(cpufamily) - 1); paren = strchr(cpufamily, '('); if (paren) - *(paren - 1) = '\0'; + *(paren - 1) = '\0'; #pragma GCC diagnostic push #if defined(__GNUC__) -#pragma GCC diagnostic ignored "-Wformat-truncation" +# pragma GCC diagnostic ignored "-Wformat-truncation" #endif - if (strlen(vm_name) < 100) - { - snprintf(activity.details, sizeof(activity.details), "Running \"%s\"", vm_name); - snprintf(activity.state, sizeof(activity.state), "%s (%s/%s)", strchr(machine_getname(), ']') + 2, cpufamily, cpu_s->name); - } - else - { - strncpy(activity.details, strchr(machine_getname(), ']') + 2, sizeof(activity.details) - 1); - snprintf(activity.state, sizeof(activity.state), "%s/%s", cpufamily, cpu_s->name); + if (strlen(vm_name) < 100) { + snprintf(activity.details, sizeof(activity.details), "Running \"%s\"", vm_name); + snprintf(activity.state, sizeof(activity.state), "%s (%s/%s)", strchr(machine_getname(), ']') + 2, cpufamily, cpu_s->name); + } else { + strncpy(activity.details, strchr(machine_getname(), ']') + 2, sizeof(activity.details) - 1); + snprintf(activity.state, sizeof(activity.state), "%s/%s", cpufamily, cpu_s->name); } #pragma GCC diagnostic pop activity.timestamps.start = time(NULL); -/* Icon choosing for Discord based on 86Box.rc */ + /* Icon choosing for Discord based on 86Box.rc */ #ifdef RELEASE_BUILD -/* Icon by OBattler and laciba96 (green for release builds)*/ + /* Icon by OBattler and laciba96 (green for release builds)*/ strcpy(activity.assets.large_image, "86box-green"); #elif BETA_BUILD -/* Icon by OBattler and laciba96 (yellow for beta builds done by Jenkins)*/ + /* Icon by OBattler and laciba96 (yellow for beta builds done by Jenkins)*/ strcpy(activity.assets.large_image, "86box-yellow"); #elif ALPHA_BUILD -/* Icon by OBattler and laciba96 (red for alpha builds done by Jenkins)*/ + /* Icon by OBattler and laciba96 (red for alpha builds done by Jenkins)*/ strcpy(activity.assets.large_image, "86box-red"); #else -/* Icon by OBattler and laciba96 (gray for builds of branches and from the git master)*/ + /* Icon by OBattler and laciba96 (gray for builds of branches and from the git master)*/ strcpy(activity.assets.large_image, "86box"); #endif -/* End of icon choosing */ + /* End of icon choosing */ - if (paused) - { - strcpy(activity.assets.small_image, "status-paused"); - strcpy(activity.assets.small_text, "Paused"); - } - else - { - strcpy(activity.assets.small_image, "status-running"); - strcpy(activity.assets.small_text, "Running"); + if (paused) { + strcpy(activity.assets.small_image, "status-paused"); + strcpy(activity.assets.small_text, "Paused"); + } else { + strcpy(activity.assets.small_image, "status-running"); + strcpy(activity.assets.small_text, "Running"); } discord_activities->update_activity(discord_activities, &activity, NULL, NULL); @@ -142,42 +135,40 @@ int discord_load() { if (discord_handle != NULL) - return(1); + return (1); // Try to load the DLL discord_handle = dynld_module(PATH_DISCORD_DLL, discord_imports); - if (discord_handle == NULL) - { - discord_log("discord: couldn't load " PATH_DISCORD_DLL "\n"); - discord_close(); + if (discord_handle == NULL) { + discord_log("discord: couldn't load " PATH_DISCORD_DLL "\n"); + discord_close(); - return(0); + return (0); } discord_loaded = 1; - return(1); + return (1); } void discord_init() { - enum EDiscordResult result; + enum EDiscordResult result; struct DiscordCreateParams params; - if(discord_handle == NULL) - return; + if (discord_handle == NULL) + return; DiscordCreateParamsSetDefault(¶ms); params.client_id = 906956844956782613; - params.flags = DiscordCreateFlags_NoRequireDiscord; + params.flags = DiscordCreateFlags_NoRequireDiscord; result = discord_create(DISCORD_VERSION, ¶ms, &discord_core); - if (result != DiscordResult_Ok) - { - discord_log("discord: DiscordCreate returned %d\n", result); - discord_close(); - return; + if (result != DiscordResult_Ok) { + discord_log("discord: DiscordCreate returned %d\n", result); + discord_close(); + return; } discord_activities = discord_core->get_activity_manager(discord_core); @@ -189,17 +180,17 @@ void discord_close() { if (discord_core != NULL) - discord_core->destroy(discord_core); + discord_core->destroy(discord_core); - discord_core = NULL; + discord_core = NULL; discord_activities = NULL; } void discord_run_callbacks() { - if(discord_core == NULL) - return; + if (discord_core == NULL) + return; discord_core->run_callbacks(discord_core); } diff --git a/src/include/discord_game_sdk.h b/src/include/discord_game_sdk.h index e3779a7cc..62ea8418e 100644 --- a/src/include/discord_game_sdk.h +++ b/src/include/discord_game_sdk.h @@ -8,6 +8,23 @@ #ifndef _DISCORD_GAME_SDK_H_ #define _DISCORD_GAME_SDK_H_ +#ifdef _WIN32 +#include +#include +#endif + +#ifdef _WIN32 +# ifdef _WIN64 +# define DISCORD_API +# else +# define DISCORD_API __stdcall +# endif +#else +# define DISCORD_API +#endif + +#define DISCORD_CALLBACK DISCORD_API + #ifdef __cplusplus extern "C" { #endif @@ -18,7 +35,7 @@ extern "C" { #include #endif -#define DISCORD_VERSION 2 +#define DISCORD_VERSION 3 #define DISCORD_APPLICATION_MANAGER_VERSION 1 #define DISCORD_USER_MANAGER_VERSION 1 #define DISCORD_IMAGE_MANAGER_VERSION 1 @@ -26,7 +43,7 @@ extern "C" { #define DISCORD_RELATIONSHIP_MANAGER_VERSION 1 #define DISCORD_LOBBY_MANAGER_VERSION 1 #define DISCORD_NETWORK_MANAGER_VERSION 1 -#define DISCORD_OVERLAY_MANAGER_VERSION 1 +#define DISCORD_OVERLAY_MANAGER_VERSION 2 #define DISCORD_STORAGE_MANAGER_VERSION 1 #define DISCORD_STORE_MANAGER_VERSION 1 #define DISCORD_VOICE_MANAGER_VERSION 1 @@ -77,6 +94,7 @@ enum EDiscordResult { DiscordResult_InvalidGiftCode = 41, DiscordResult_PurchaseError = 42, DiscordResult_TransactionAborted = 43, + DiscordResult_DrawingInitFailed = 44, }; enum EDiscordCreateFlags { @@ -109,6 +127,11 @@ enum EDiscordImageType { DiscordImageType_User, }; +enum EDiscordActivityPartyPrivacy { + DiscordActivityPartyPrivacy_Private = 0, + DiscordActivityPartyPrivacy_Public = 1, +}; + enum EDiscordActivityType { DiscordActivityType_Playing, DiscordActivityType_Streaming, @@ -121,6 +144,12 @@ enum EDiscordActivityActionType { DiscordActivityActionType_Spectate, }; +enum EDiscordActivitySupportedPlatformFlags { + DiscordActivitySupportedPlatformFlags_Desktop = 1, + DiscordActivitySupportedPlatformFlags_Android = 2, + DiscordActivitySupportedPlatformFlags_iOS = 4, +}; + enum EDiscordActivityJoinRequestReply { DiscordActivityJoinRequestReply_No, DiscordActivityJoinRequestReply_Yes, @@ -169,6 +198,18 @@ enum EDiscordLobbySearchDistance { DiscordLobbySearchDistance_Global, }; +enum EDiscordKeyVariant { + DiscordKeyVariant_Normal, + DiscordKeyVariant_Right, + DiscordKeyVariant_Left, +}; + +enum EDiscordMouseButton { + DiscordMouseButton_Left, + DiscordMouseButton_Middle, + DiscordMouseButton_Right, +}; + enum EDiscordEntitlementType { DiscordEntitlementType_Purchase = 1, DiscordEntitlementType_PremiumSubscription, @@ -204,6 +245,18 @@ typedef char DiscordMetadataKey[256]; typedef char DiscordMetadataValue[4096]; typedef uint64_t DiscordNetworkPeerId; typedef uint8_t DiscordNetworkChannelId; +#ifdef __APPLE__ +typedef void IDXGISwapChain; +#endif +#ifdef __linux__ +typedef void IDXGISwapChain; +#endif +#ifdef __APPLE__ +typedef void MSG; +#endif +#ifdef __linux__ +typedef void MSG; +#endif typedef char DiscordPath[4096]; typedef char DiscordDateTime[64]; @@ -252,6 +305,7 @@ struct DiscordPartySize { struct DiscordActivityParty { char id[128]; struct DiscordPartySize size; + enum EDiscordActivityPartyPrivacy privacy; }; struct DiscordActivitySecrets { @@ -271,6 +325,7 @@ struct DiscordActivity { struct DiscordActivityParty party; struct DiscordActivitySecrets secrets; bool instance; + uint32_t supported_platforms; }; struct DiscordPresence { @@ -293,6 +348,21 @@ struct DiscordLobby { bool locked; }; +struct DiscordImeUnderline { + int32_t from; + int32_t to; + uint32_t color; + uint32_t background_color; + bool thick; +}; + +struct DiscordRect { + int32_t left; + int32_t top; + int32_t right; + int32_t bottom; +}; + struct DiscordFileStat { char filename[260]; uint64_t size; @@ -330,265 +400,278 @@ struct DiscordUserAchievement { }; struct IDiscordLobbyTransaction { - enum EDiscordResult (*set_type)(struct IDiscordLobbyTransaction* lobby_transaction, enum EDiscordLobbyType type); - enum EDiscordResult (*set_owner)(struct IDiscordLobbyTransaction* lobby_transaction, DiscordUserId owner_id); - enum EDiscordResult (*set_capacity)(struct IDiscordLobbyTransaction* lobby_transaction, uint32_t capacity); - enum EDiscordResult (*set_metadata)(struct IDiscordLobbyTransaction* lobby_transaction, DiscordMetadataKey key, DiscordMetadataValue value); - enum EDiscordResult (*delete_metadata)(struct IDiscordLobbyTransaction* lobby_transaction, DiscordMetadataKey key); - enum EDiscordResult (*set_locked)(struct IDiscordLobbyTransaction* lobby_transaction, bool locked); + enum EDiscordResult (DISCORD_API *set_type)(struct IDiscordLobbyTransaction* lobby_transaction, enum EDiscordLobbyType type); + enum EDiscordResult (DISCORD_API *set_owner)(struct IDiscordLobbyTransaction* lobby_transaction, DiscordUserId owner_id); + enum EDiscordResult (DISCORD_API *set_capacity)(struct IDiscordLobbyTransaction* lobby_transaction, uint32_t capacity); + enum EDiscordResult (DISCORD_API *set_metadata)(struct IDiscordLobbyTransaction* lobby_transaction, DiscordMetadataKey key, DiscordMetadataValue value); + enum EDiscordResult (DISCORD_API *delete_metadata)(struct IDiscordLobbyTransaction* lobby_transaction, DiscordMetadataKey key); + enum EDiscordResult (DISCORD_API *set_locked)(struct IDiscordLobbyTransaction* lobby_transaction, bool locked); }; struct IDiscordLobbyMemberTransaction { - enum EDiscordResult (*set_metadata)(struct IDiscordLobbyMemberTransaction* lobby_member_transaction, DiscordMetadataKey key, DiscordMetadataValue value); - enum EDiscordResult (*delete_metadata)(struct IDiscordLobbyMemberTransaction* lobby_member_transaction, DiscordMetadataKey key); + enum EDiscordResult (DISCORD_API *set_metadata)(struct IDiscordLobbyMemberTransaction* lobby_member_transaction, DiscordMetadataKey key, DiscordMetadataValue value); + enum EDiscordResult (DISCORD_API *delete_metadata)(struct IDiscordLobbyMemberTransaction* lobby_member_transaction, DiscordMetadataKey key); }; struct IDiscordLobbySearchQuery { - enum EDiscordResult (*filter)(struct IDiscordLobbySearchQuery* lobby_search_query, DiscordMetadataKey key, enum EDiscordLobbySearchComparison comparison, enum EDiscordLobbySearchCast cast, DiscordMetadataValue value); - enum EDiscordResult (*sort)(struct IDiscordLobbySearchQuery* lobby_search_query, DiscordMetadataKey key, enum EDiscordLobbySearchCast cast, DiscordMetadataValue value); - enum EDiscordResult (*limit)(struct IDiscordLobbySearchQuery* lobby_search_query, uint32_t limit); - enum EDiscordResult (*distance)(struct IDiscordLobbySearchQuery* lobby_search_query, enum EDiscordLobbySearchDistance distance); + enum EDiscordResult (DISCORD_API *filter)(struct IDiscordLobbySearchQuery* lobby_search_query, DiscordMetadataKey key, enum EDiscordLobbySearchComparison comparison, enum EDiscordLobbySearchCast cast, DiscordMetadataValue value); + enum EDiscordResult (DISCORD_API *sort)(struct IDiscordLobbySearchQuery* lobby_search_query, DiscordMetadataKey key, enum EDiscordLobbySearchCast cast, DiscordMetadataValue value); + enum EDiscordResult (DISCORD_API *limit)(struct IDiscordLobbySearchQuery* lobby_search_query, uint32_t limit); + enum EDiscordResult (DISCORD_API *distance)(struct IDiscordLobbySearchQuery* lobby_search_query, enum EDiscordLobbySearchDistance distance); }; typedef void* IDiscordApplicationEvents; struct IDiscordApplicationManager { - void (*validate_or_exit)(struct IDiscordApplicationManager* manager, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*get_current_locale)(struct IDiscordApplicationManager* manager, DiscordLocale* locale); - void (*get_current_branch)(struct IDiscordApplicationManager* manager, DiscordBranch* branch); - void (*get_oauth2_token)(struct IDiscordApplicationManager* manager, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result, struct DiscordOAuth2Token* oauth2_token)); - void (*get_ticket)(struct IDiscordApplicationManager* manager, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result, const char* data)); + void (DISCORD_API *validate_or_exit)(struct IDiscordApplicationManager* manager, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *get_current_locale)(struct IDiscordApplicationManager* manager, DiscordLocale* locale); + void (DISCORD_API *get_current_branch)(struct IDiscordApplicationManager* manager, DiscordBranch* branch); + void (DISCORD_API *get_oauth2_token)(struct IDiscordApplicationManager* manager, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result, struct DiscordOAuth2Token* oauth2_token)); + void (DISCORD_API *get_ticket)(struct IDiscordApplicationManager* manager, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result, const char* data)); }; struct IDiscordUserEvents { - void (*on_current_user_update)(void* event_data); + void (DISCORD_API *on_current_user_update)(void* event_data); }; struct IDiscordUserManager { - enum EDiscordResult (*get_current_user)(struct IDiscordUserManager* manager, struct DiscordUser* current_user); - void (*get_user)(struct IDiscordUserManager* manager, DiscordUserId user_id, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result, struct DiscordUser* user)); - enum EDiscordResult (*get_current_user_premium_type)(struct IDiscordUserManager* manager, enum EDiscordPremiumType* premium_type); - enum EDiscordResult (*current_user_has_flag)(struct IDiscordUserManager* manager, enum EDiscordUserFlag flag, bool* has_flag); + enum EDiscordResult (DISCORD_API *get_current_user)(struct IDiscordUserManager* manager, struct DiscordUser* current_user); + void (DISCORD_API *get_user)(struct IDiscordUserManager* manager, DiscordUserId user_id, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result, struct DiscordUser* user)); + enum EDiscordResult (DISCORD_API *get_current_user_premium_type)(struct IDiscordUserManager* manager, enum EDiscordPremiumType* premium_type); + enum EDiscordResult (DISCORD_API *current_user_has_flag)(struct IDiscordUserManager* manager, enum EDiscordUserFlag flag, bool* has_flag); }; typedef void* IDiscordImageEvents; struct IDiscordImageManager { - void (*fetch)(struct IDiscordImageManager* manager, struct DiscordImageHandle handle, bool refresh, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result, struct DiscordImageHandle handle_result)); - enum EDiscordResult (*get_dimensions)(struct IDiscordImageManager* manager, struct DiscordImageHandle handle, struct DiscordImageDimensions* dimensions); - enum EDiscordResult (*get_data)(struct IDiscordImageManager* manager, struct DiscordImageHandle handle, uint8_t* data, uint32_t data_length); + void (DISCORD_API *fetch)(struct IDiscordImageManager* manager, struct DiscordImageHandle handle, bool refresh, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result, struct DiscordImageHandle handle_result)); + enum EDiscordResult (DISCORD_API *get_dimensions)(struct IDiscordImageManager* manager, struct DiscordImageHandle handle, struct DiscordImageDimensions* dimensions); + enum EDiscordResult (DISCORD_API *get_data)(struct IDiscordImageManager* manager, struct DiscordImageHandle handle, uint8_t* data, uint32_t data_length); }; struct IDiscordActivityEvents { - void (*on_activity_join)(void* event_data, const char* secret); - void (*on_activity_spectate)(void* event_data, const char* secret); - void (*on_activity_join_request)(void* event_data, struct DiscordUser* user); - void (*on_activity_invite)(void* event_data, enum EDiscordActivityActionType type, struct DiscordUser* user, struct DiscordActivity* activity); + void (DISCORD_API *on_activity_join)(void* event_data, const char* secret); + void (DISCORD_API *on_activity_spectate)(void* event_data, const char* secret); + void (DISCORD_API *on_activity_join_request)(void* event_data, struct DiscordUser* user); + void (DISCORD_API *on_activity_invite)(void* event_data, enum EDiscordActivityActionType type, struct DiscordUser* user, struct DiscordActivity* activity); }; struct IDiscordActivityManager { - enum EDiscordResult (*register_command)(struct IDiscordActivityManager* manager, const char* command); - enum EDiscordResult (*register_steam)(struct IDiscordActivityManager* manager, uint32_t steam_id); - void (*update_activity)(struct IDiscordActivityManager* manager, struct DiscordActivity* activity, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*clear_activity)(struct IDiscordActivityManager* manager, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*send_request_reply)(struct IDiscordActivityManager* manager, DiscordUserId user_id, enum EDiscordActivityJoinRequestReply reply, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*send_invite)(struct IDiscordActivityManager* manager, DiscordUserId user_id, enum EDiscordActivityActionType type, const char* content, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*accept_invite)(struct IDiscordActivityManager* manager, DiscordUserId user_id, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); + enum EDiscordResult (DISCORD_API *register_command)(struct IDiscordActivityManager* manager, const char* command); + enum EDiscordResult (DISCORD_API *register_steam)(struct IDiscordActivityManager* manager, uint32_t steam_id); + void (DISCORD_API *update_activity)(struct IDiscordActivityManager* manager, struct DiscordActivity* activity, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *clear_activity)(struct IDiscordActivityManager* manager, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *send_request_reply)(struct IDiscordActivityManager* manager, DiscordUserId user_id, enum EDiscordActivityJoinRequestReply reply, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *send_invite)(struct IDiscordActivityManager* manager, DiscordUserId user_id, enum EDiscordActivityActionType type, const char* content, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *accept_invite)(struct IDiscordActivityManager* manager, DiscordUserId user_id, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); }; struct IDiscordRelationshipEvents { - void (*on_refresh)(void* event_data); - void (*on_relationship_update)(void* event_data, struct DiscordRelationship* relationship); + void (DISCORD_API *on_refresh)(void* event_data); + void (DISCORD_API *on_relationship_update)(void* event_data, struct DiscordRelationship* relationship); }; struct IDiscordRelationshipManager { - void (*filter)(struct IDiscordRelationshipManager* manager, void* filter_data, bool (*filter)(void* filter_data, struct DiscordRelationship* relationship)); - enum EDiscordResult (*count)(struct IDiscordRelationshipManager* manager, int32_t* count); - enum EDiscordResult (*get)(struct IDiscordRelationshipManager* manager, DiscordUserId user_id, struct DiscordRelationship* relationship); - enum EDiscordResult (*get_at)(struct IDiscordRelationshipManager* manager, uint32_t index, struct DiscordRelationship* relationship); + void (DISCORD_API *filter)(struct IDiscordRelationshipManager* manager, void* filter_data, bool (DISCORD_API *filter)(void* filter_data, struct DiscordRelationship* relationship)); + enum EDiscordResult (DISCORD_API *count)(struct IDiscordRelationshipManager* manager, int32_t* count); + enum EDiscordResult (DISCORD_API *get)(struct IDiscordRelationshipManager* manager, DiscordUserId user_id, struct DiscordRelationship* relationship); + enum EDiscordResult (DISCORD_API *get_at)(struct IDiscordRelationshipManager* manager, uint32_t index, struct DiscordRelationship* relationship); }; struct IDiscordLobbyEvents { - void (*on_lobby_update)(void* event_data, int64_t lobby_id); - void (*on_lobby_delete)(void* event_data, int64_t lobby_id, uint32_t reason); - void (*on_member_connect)(void* event_data, int64_t lobby_id, int64_t user_id); - void (*on_member_update)(void* event_data, int64_t lobby_id, int64_t user_id); - void (*on_member_disconnect)(void* event_data, int64_t lobby_id, int64_t user_id); - void (*on_lobby_message)(void* event_data, int64_t lobby_id, int64_t user_id, uint8_t* data, uint32_t data_length); - void (*on_speaking)(void* event_data, int64_t lobby_id, int64_t user_id, bool speaking); - void (*on_network_message)(void* event_data, int64_t lobby_id, int64_t user_id, uint8_t channel_id, uint8_t* data, uint32_t data_length); + void (DISCORD_API *on_lobby_update)(void* event_data, int64_t lobby_id); + void (DISCORD_API *on_lobby_delete)(void* event_data, int64_t lobby_id, uint32_t reason); + void (DISCORD_API *on_member_connect)(void* event_data, int64_t lobby_id, int64_t user_id); + void (DISCORD_API *on_member_update)(void* event_data, int64_t lobby_id, int64_t user_id); + void (DISCORD_API *on_member_disconnect)(void* event_data, int64_t lobby_id, int64_t user_id); + void (DISCORD_API *on_lobby_message)(void* event_data, int64_t lobby_id, int64_t user_id, uint8_t* data, uint32_t data_length); + void (DISCORD_API *on_speaking)(void* event_data, int64_t lobby_id, int64_t user_id, bool speaking); + void (DISCORD_API *on_network_message)(void* event_data, int64_t lobby_id, int64_t user_id, uint8_t channel_id, uint8_t* data, uint32_t data_length); }; struct IDiscordLobbyManager { - enum EDiscordResult (*get_lobby_create_transaction)(struct IDiscordLobbyManager* manager, struct IDiscordLobbyTransaction** transaction); - enum EDiscordResult (*get_lobby_update_transaction)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, struct IDiscordLobbyTransaction** transaction); - enum EDiscordResult (*get_member_update_transaction)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, struct IDiscordLobbyMemberTransaction** transaction); - void (*create_lobby)(struct IDiscordLobbyManager* manager, struct IDiscordLobbyTransaction* transaction, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result, struct DiscordLobby* lobby)); - void (*update_lobby)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, struct IDiscordLobbyTransaction* transaction, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*delete_lobby)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*connect_lobby)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordLobbySecret secret, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result, struct DiscordLobby* lobby)); - void (*connect_lobby_with_activity_secret)(struct IDiscordLobbyManager* manager, DiscordLobbySecret activity_secret, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result, struct DiscordLobby* lobby)); - void (*disconnect_lobby)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - enum EDiscordResult (*get_lobby)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, struct DiscordLobby* lobby); - enum EDiscordResult (*get_lobby_activity_secret)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordLobbySecret* secret); - enum EDiscordResult (*get_lobby_metadata_value)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordMetadataKey key, DiscordMetadataValue* value); - enum EDiscordResult (*get_lobby_metadata_key)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, int32_t index, DiscordMetadataKey* key); - enum EDiscordResult (*lobby_metadata_count)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, int32_t* count); - enum EDiscordResult (*member_count)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, int32_t* count); - enum EDiscordResult (*get_member_user_id)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, int32_t index, DiscordUserId* user_id); - enum EDiscordResult (*get_member_user)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, struct DiscordUser* user); - enum EDiscordResult (*get_member_metadata_value)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, DiscordMetadataKey key, DiscordMetadataValue* value); - enum EDiscordResult (*get_member_metadata_key)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, int32_t index, DiscordMetadataKey* key); - enum EDiscordResult (*member_metadata_count)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, int32_t* count); - void (*update_member)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, struct IDiscordLobbyMemberTransaction* transaction, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*send_lobby_message)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, uint8_t* data, uint32_t data_length, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - enum EDiscordResult (*get_search_query)(struct IDiscordLobbyManager* manager, struct IDiscordLobbySearchQuery** query); - void (*search)(struct IDiscordLobbyManager* manager, struct IDiscordLobbySearchQuery* query, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*lobby_count)(struct IDiscordLobbyManager* manager, int32_t* count); - enum EDiscordResult (*get_lobby_id)(struct IDiscordLobbyManager* manager, int32_t index, DiscordLobbyId* lobby_id); - void (*connect_voice)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*disconnect_voice)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - enum EDiscordResult (*connect_network)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id); - enum EDiscordResult (*disconnect_network)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id); - enum EDiscordResult (*flush_network)(struct IDiscordLobbyManager* manager); - enum EDiscordResult (*open_network_channel)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, uint8_t channel_id, bool reliable); - enum EDiscordResult (*send_network_message)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, uint8_t channel_id, uint8_t* data, uint32_t data_length); + enum EDiscordResult (DISCORD_API *get_lobby_create_transaction)(struct IDiscordLobbyManager* manager, struct IDiscordLobbyTransaction** transaction); + enum EDiscordResult (DISCORD_API *get_lobby_update_transaction)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, struct IDiscordLobbyTransaction** transaction); + enum EDiscordResult (DISCORD_API *get_member_update_transaction)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, struct IDiscordLobbyMemberTransaction** transaction); + void (DISCORD_API *create_lobby)(struct IDiscordLobbyManager* manager, struct IDiscordLobbyTransaction* transaction, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result, struct DiscordLobby* lobby)); + void (DISCORD_API *update_lobby)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, struct IDiscordLobbyTransaction* transaction, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *delete_lobby)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *connect_lobby)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordLobbySecret secret, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result, struct DiscordLobby* lobby)); + void (DISCORD_API *connect_lobby_with_activity_secret)(struct IDiscordLobbyManager* manager, DiscordLobbySecret activity_secret, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result, struct DiscordLobby* lobby)); + void (DISCORD_API *disconnect_lobby)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + enum EDiscordResult (DISCORD_API *get_lobby)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, struct DiscordLobby* lobby); + enum EDiscordResult (DISCORD_API *get_lobby_activity_secret)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordLobbySecret* secret); + enum EDiscordResult (DISCORD_API *get_lobby_metadata_value)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordMetadataKey key, DiscordMetadataValue* value); + enum EDiscordResult (DISCORD_API *get_lobby_metadata_key)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, int32_t index, DiscordMetadataKey* key); + enum EDiscordResult (DISCORD_API *lobby_metadata_count)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, int32_t* count); + enum EDiscordResult (DISCORD_API *member_count)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, int32_t* count); + enum EDiscordResult (DISCORD_API *get_member_user_id)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, int32_t index, DiscordUserId* user_id); + enum EDiscordResult (DISCORD_API *get_member_user)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, struct DiscordUser* user); + enum EDiscordResult (DISCORD_API *get_member_metadata_value)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, DiscordMetadataKey key, DiscordMetadataValue* value); + enum EDiscordResult (DISCORD_API *get_member_metadata_key)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, int32_t index, DiscordMetadataKey* key); + enum EDiscordResult (DISCORD_API *member_metadata_count)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, int32_t* count); + void (DISCORD_API *update_member)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, struct IDiscordLobbyMemberTransaction* transaction, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *send_lobby_message)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, uint8_t* data, uint32_t data_length, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + enum EDiscordResult (DISCORD_API *get_search_query)(struct IDiscordLobbyManager* manager, struct IDiscordLobbySearchQuery** query); + void (DISCORD_API *search)(struct IDiscordLobbyManager* manager, struct IDiscordLobbySearchQuery* query, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *lobby_count)(struct IDiscordLobbyManager* manager, int32_t* count); + enum EDiscordResult (DISCORD_API *get_lobby_id)(struct IDiscordLobbyManager* manager, int32_t index, DiscordLobbyId* lobby_id); + void (DISCORD_API *connect_voice)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *disconnect_voice)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + enum EDiscordResult (DISCORD_API *connect_network)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id); + enum EDiscordResult (DISCORD_API *disconnect_network)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id); + enum EDiscordResult (DISCORD_API *flush_network)(struct IDiscordLobbyManager* manager); + enum EDiscordResult (DISCORD_API *open_network_channel)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, uint8_t channel_id, bool reliable); + enum EDiscordResult (DISCORD_API *send_network_message)(struct IDiscordLobbyManager* manager, DiscordLobbyId lobby_id, DiscordUserId user_id, uint8_t channel_id, uint8_t* data, uint32_t data_length); }; struct IDiscordNetworkEvents { - void (*on_message)(void* event_data, DiscordNetworkPeerId peer_id, DiscordNetworkChannelId channel_id, uint8_t* data, uint32_t data_length); - void (*on_route_update)(void* event_data, const char* route_data); + void (DISCORD_API *on_message)(void* event_data, DiscordNetworkPeerId peer_id, DiscordNetworkChannelId channel_id, uint8_t* data, uint32_t data_length); + void (DISCORD_API *on_route_update)(void* event_data, const char* route_data); }; struct IDiscordNetworkManager { /** * Get the local peer ID for this process. */ - void (*get_peer_id)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId* peer_id); + void (DISCORD_API *get_peer_id)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId* peer_id); /** * Send pending network messages. */ - enum EDiscordResult (*flush)(struct IDiscordNetworkManager* manager); + enum EDiscordResult (DISCORD_API *flush)(struct IDiscordNetworkManager* manager); /** * Open a connection to a remote peer. */ - enum EDiscordResult (*open_peer)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id, const char* route_data); + enum EDiscordResult (DISCORD_API *open_peer)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id, const char* route_data); /** * Update the route data for a connected peer. */ - enum EDiscordResult (*update_peer)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id, const char* route_data); + enum EDiscordResult (DISCORD_API *update_peer)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id, const char* route_data); /** * Close the connection to a remote peer. */ - enum EDiscordResult (*close_peer)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id); + enum EDiscordResult (DISCORD_API *close_peer)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id); /** * Open a message channel to a connected peer. */ - enum EDiscordResult (*open_channel)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id, DiscordNetworkChannelId channel_id, bool reliable); + enum EDiscordResult (DISCORD_API *open_channel)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id, DiscordNetworkChannelId channel_id, bool reliable); /** * Close a message channel to a connected peer. */ - enum EDiscordResult (*close_channel)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id, DiscordNetworkChannelId channel_id); + enum EDiscordResult (DISCORD_API *close_channel)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id, DiscordNetworkChannelId channel_id); /** * Send a message to a connected peer over an opened message channel. */ - enum EDiscordResult (*send_message)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id, DiscordNetworkChannelId channel_id, uint8_t* data, uint32_t data_length); + enum EDiscordResult (DISCORD_API *send_message)(struct IDiscordNetworkManager* manager, DiscordNetworkPeerId peer_id, DiscordNetworkChannelId channel_id, uint8_t* data, uint32_t data_length); }; struct IDiscordOverlayEvents { - void (*on_toggle)(void* event_data, bool locked); + void (DISCORD_API *on_toggle)(void* event_data, bool locked); }; struct IDiscordOverlayManager { - void (*is_enabled)(struct IDiscordOverlayManager* manager, bool* enabled); - void (*is_locked)(struct IDiscordOverlayManager* manager, bool* locked); - void (*set_locked)(struct IDiscordOverlayManager* manager, bool locked, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*open_activity_invite)(struct IDiscordOverlayManager* manager, enum EDiscordActivityActionType type, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*open_guild_invite)(struct IDiscordOverlayManager* manager, const char* code, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*open_voice_settings)(struct IDiscordOverlayManager* manager, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *is_enabled)(struct IDiscordOverlayManager* manager, bool* enabled); + void (DISCORD_API *is_locked)(struct IDiscordOverlayManager* manager, bool* locked); + void (DISCORD_API *set_locked)(struct IDiscordOverlayManager* manager, bool locked, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *open_activity_invite)(struct IDiscordOverlayManager* manager, enum EDiscordActivityActionType type, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *open_guild_invite)(struct IDiscordOverlayManager* manager, const char* code, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *open_voice_settings)(struct IDiscordOverlayManager* manager, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + enum EDiscordResult (DISCORD_API *init_drawing_dxgi)(struct IDiscordOverlayManager* manager, IDXGISwapChain* swapchain, bool use_message_forwarding); + void (DISCORD_API *on_present)(struct IDiscordOverlayManager* manager); + void (DISCORD_API *forward_message)(struct IDiscordOverlayManager* manager, MSG* message); + void (DISCORD_API *key_event)(struct IDiscordOverlayManager* manager, bool down, const char* key_code, enum EDiscordKeyVariant variant); + void (DISCORD_API *char_event)(struct IDiscordOverlayManager* manager, const char* character); + void (DISCORD_API *mouse_button_event)(struct IDiscordOverlayManager* manager, uint8_t down, int32_t click_count, enum EDiscordMouseButton which, int32_t x, int32_t y); + void (DISCORD_API *mouse_motion_event)(struct IDiscordOverlayManager* manager, int32_t x, int32_t y); + void (DISCORD_API *ime_commit_text)(struct IDiscordOverlayManager* manager, const char* text); + void (DISCORD_API *ime_set_composition)(struct IDiscordOverlayManager* manager, const char* text, struct DiscordImeUnderline* underlines, uint32_t underlines_length, int32_t from, int32_t to); + void (DISCORD_API *ime_cancel_composition)(struct IDiscordOverlayManager* manager); + void (DISCORD_API *set_ime_composition_range_callback)(struct IDiscordOverlayManager* manager, void* on_ime_composition_range_changed_data, void (DISCORD_API *on_ime_composition_range_changed)(void* on_ime_composition_range_changed_data, int32_t from, int32_t to, struct DiscordRect* bounds, uint32_t bounds_length)); + void (DISCORD_API *set_ime_selection_bounds_callback)(struct IDiscordOverlayManager* manager, void* on_ime_selection_bounds_changed_data, void (DISCORD_API *on_ime_selection_bounds_changed)(void* on_ime_selection_bounds_changed_data, struct DiscordRect anchor, struct DiscordRect focus, bool is_anchor_first)); + bool (DISCORD_API *is_point_inside_click_zone)(struct IDiscordOverlayManager* manager, int32_t x, int32_t y); }; typedef void* IDiscordStorageEvents; struct IDiscordStorageManager { - enum EDiscordResult (*read)(struct IDiscordStorageManager* manager, const char* name, uint8_t* data, uint32_t data_length, uint32_t* read); - void (*read_async)(struct IDiscordStorageManager* manager, const char* name, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result, uint8_t* data, uint32_t data_length)); - void (*read_async_partial)(struct IDiscordStorageManager* manager, const char* name, uint64_t offset, uint64_t length, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result, uint8_t* data, uint32_t data_length)); - enum EDiscordResult (*write)(struct IDiscordStorageManager* manager, const char* name, uint8_t* data, uint32_t data_length); - void (*write_async)(struct IDiscordStorageManager* manager, const char* name, uint8_t* data, uint32_t data_length, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - enum EDiscordResult (*delete_)(struct IDiscordStorageManager* manager, const char* name); - enum EDiscordResult (*exists)(struct IDiscordStorageManager* manager, const char* name, bool* exists); - void (*count)(struct IDiscordStorageManager* manager, int32_t* count); - enum EDiscordResult (*stat)(struct IDiscordStorageManager* manager, const char* name, struct DiscordFileStat* stat); - enum EDiscordResult (*stat_at)(struct IDiscordStorageManager* manager, int32_t index, struct DiscordFileStat* stat); - enum EDiscordResult (*get_path)(struct IDiscordStorageManager* manager, DiscordPath* path); + enum EDiscordResult (DISCORD_API *read)(struct IDiscordStorageManager* manager, const char* name, uint8_t* data, uint32_t data_length, uint32_t* read); + void (DISCORD_API *read_async)(struct IDiscordStorageManager* manager, const char* name, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result, uint8_t* data, uint32_t data_length)); + void (DISCORD_API *read_async_partial)(struct IDiscordStorageManager* manager, const char* name, uint64_t offset, uint64_t length, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result, uint8_t* data, uint32_t data_length)); + enum EDiscordResult (DISCORD_API *write)(struct IDiscordStorageManager* manager, const char* name, uint8_t* data, uint32_t data_length); + void (DISCORD_API *write_async)(struct IDiscordStorageManager* manager, const char* name, uint8_t* data, uint32_t data_length, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + enum EDiscordResult (DISCORD_API *delete_)(struct IDiscordStorageManager* manager, const char* name); + enum EDiscordResult (DISCORD_API *exists)(struct IDiscordStorageManager* manager, const char* name, bool* exists); + void (DISCORD_API *count)(struct IDiscordStorageManager* manager, int32_t* count); + enum EDiscordResult (DISCORD_API *stat)(struct IDiscordStorageManager* manager, const char* name, struct DiscordFileStat* stat); + enum EDiscordResult (DISCORD_API *stat_at)(struct IDiscordStorageManager* manager, int32_t index, struct DiscordFileStat* stat); + enum EDiscordResult (DISCORD_API *get_path)(struct IDiscordStorageManager* manager, DiscordPath* path); }; struct IDiscordStoreEvents { - void (*on_entitlement_create)(void* event_data, struct DiscordEntitlement* entitlement); - void (*on_entitlement_delete)(void* event_data, struct DiscordEntitlement* entitlement); + void (DISCORD_API *on_entitlement_create)(void* event_data, struct DiscordEntitlement* entitlement); + void (DISCORD_API *on_entitlement_delete)(void* event_data, struct DiscordEntitlement* entitlement); }; struct IDiscordStoreManager { - void (*fetch_skus)(struct IDiscordStoreManager* manager, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*count_skus)(struct IDiscordStoreManager* manager, int32_t* count); - enum EDiscordResult (*get_sku)(struct IDiscordStoreManager* manager, DiscordSnowflake sku_id, struct DiscordSku* sku); - enum EDiscordResult (*get_sku_at)(struct IDiscordStoreManager* manager, int32_t index, struct DiscordSku* sku); - void (*fetch_entitlements)(struct IDiscordStoreManager* manager, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*count_entitlements)(struct IDiscordStoreManager* manager, int32_t* count); - enum EDiscordResult (*get_entitlement)(struct IDiscordStoreManager* manager, DiscordSnowflake entitlement_id, struct DiscordEntitlement* entitlement); - enum EDiscordResult (*get_entitlement_at)(struct IDiscordStoreManager* manager, int32_t index, struct DiscordEntitlement* entitlement); - enum EDiscordResult (*has_sku_entitlement)(struct IDiscordStoreManager* manager, DiscordSnowflake sku_id, bool* has_entitlement); - void (*start_purchase)(struct IDiscordStoreManager* manager, DiscordSnowflake sku_id, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *fetch_skus)(struct IDiscordStoreManager* manager, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *count_skus)(struct IDiscordStoreManager* manager, int32_t* count); + enum EDiscordResult (DISCORD_API *get_sku)(struct IDiscordStoreManager* manager, DiscordSnowflake sku_id, struct DiscordSku* sku); + enum EDiscordResult (DISCORD_API *get_sku_at)(struct IDiscordStoreManager* manager, int32_t index, struct DiscordSku* sku); + void (DISCORD_API *fetch_entitlements)(struct IDiscordStoreManager* manager, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *count_entitlements)(struct IDiscordStoreManager* manager, int32_t* count); + enum EDiscordResult (DISCORD_API *get_entitlement)(struct IDiscordStoreManager* manager, DiscordSnowflake entitlement_id, struct DiscordEntitlement* entitlement); + enum EDiscordResult (DISCORD_API *get_entitlement_at)(struct IDiscordStoreManager* manager, int32_t index, struct DiscordEntitlement* entitlement); + enum EDiscordResult (DISCORD_API *has_sku_entitlement)(struct IDiscordStoreManager* manager, DiscordSnowflake sku_id, bool* has_entitlement); + void (DISCORD_API *start_purchase)(struct IDiscordStoreManager* manager, DiscordSnowflake sku_id, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); }; struct IDiscordVoiceEvents { - void (*on_settings_update)(void* event_data); + void (DISCORD_API *on_settings_update)(void* event_data); }; struct IDiscordVoiceManager { - enum EDiscordResult (*get_input_mode)(struct IDiscordVoiceManager* manager, struct DiscordInputMode* input_mode); - void (*set_input_mode)(struct IDiscordVoiceManager* manager, struct DiscordInputMode input_mode, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - enum EDiscordResult (*is_self_mute)(struct IDiscordVoiceManager* manager, bool* mute); - enum EDiscordResult (*set_self_mute)(struct IDiscordVoiceManager* manager, bool mute); - enum EDiscordResult (*is_self_deaf)(struct IDiscordVoiceManager* manager, bool* deaf); - enum EDiscordResult (*set_self_deaf)(struct IDiscordVoiceManager* manager, bool deaf); - enum EDiscordResult (*is_local_mute)(struct IDiscordVoiceManager* manager, DiscordSnowflake user_id, bool* mute); - enum EDiscordResult (*set_local_mute)(struct IDiscordVoiceManager* manager, DiscordSnowflake user_id, bool mute); - enum EDiscordResult (*get_local_volume)(struct IDiscordVoiceManager* manager, DiscordSnowflake user_id, uint8_t* volume); - enum EDiscordResult (*set_local_volume)(struct IDiscordVoiceManager* manager, DiscordSnowflake user_id, uint8_t volume); + enum EDiscordResult (DISCORD_API *get_input_mode)(struct IDiscordVoiceManager* manager, struct DiscordInputMode* input_mode); + void (DISCORD_API *set_input_mode)(struct IDiscordVoiceManager* manager, struct DiscordInputMode input_mode, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + enum EDiscordResult (DISCORD_API *is_self_mute)(struct IDiscordVoiceManager* manager, bool* mute); + enum EDiscordResult (DISCORD_API *set_self_mute)(struct IDiscordVoiceManager* manager, bool mute); + enum EDiscordResult (DISCORD_API *is_self_deaf)(struct IDiscordVoiceManager* manager, bool* deaf); + enum EDiscordResult (DISCORD_API *set_self_deaf)(struct IDiscordVoiceManager* manager, bool deaf); + enum EDiscordResult (DISCORD_API *is_local_mute)(struct IDiscordVoiceManager* manager, DiscordSnowflake user_id, bool* mute); + enum EDiscordResult (DISCORD_API *set_local_mute)(struct IDiscordVoiceManager* manager, DiscordSnowflake user_id, bool mute); + enum EDiscordResult (DISCORD_API *get_local_volume)(struct IDiscordVoiceManager* manager, DiscordSnowflake user_id, uint8_t* volume); + enum EDiscordResult (DISCORD_API *set_local_volume)(struct IDiscordVoiceManager* manager, DiscordSnowflake user_id, uint8_t volume); }; struct IDiscordAchievementEvents { - void (*on_user_achievement_update)(void* event_data, struct DiscordUserAchievement* user_achievement); + void (DISCORD_API *on_user_achievement_update)(void* event_data, struct DiscordUserAchievement* user_achievement); }; struct IDiscordAchievementManager { - void (*set_user_achievement)(struct IDiscordAchievementManager* manager, DiscordSnowflake achievement_id, uint8_t percent_complete, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*fetch_user_achievements)(struct IDiscordAchievementManager* manager, void* callback_data, void (*callback)(void* callback_data, enum EDiscordResult result)); - void (*count_user_achievements)(struct IDiscordAchievementManager* manager, int32_t* count); - enum EDiscordResult (*get_user_achievement)(struct IDiscordAchievementManager* manager, DiscordSnowflake user_achievement_id, struct DiscordUserAchievement* user_achievement); - enum EDiscordResult (*get_user_achievement_at)(struct IDiscordAchievementManager* manager, int32_t index, struct DiscordUserAchievement* user_achievement); + void (DISCORD_API *set_user_achievement)(struct IDiscordAchievementManager* manager, DiscordSnowflake achievement_id, uint8_t percent_complete, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *fetch_user_achievements)(struct IDiscordAchievementManager* manager, void* callback_data, void (DISCORD_API *callback)(void* callback_data, enum EDiscordResult result)); + void (DISCORD_API *count_user_achievements)(struct IDiscordAchievementManager* manager, int32_t* count); + enum EDiscordResult (DISCORD_API *get_user_achievement)(struct IDiscordAchievementManager* manager, DiscordSnowflake user_achievement_id, struct DiscordUserAchievement* user_achievement); + enum EDiscordResult (DISCORD_API *get_user_achievement_at)(struct IDiscordAchievementManager* manager, int32_t index, struct DiscordUserAchievement* user_achievement); }; typedef void* IDiscordCoreEvents; struct IDiscordCore { - void (*destroy)(struct IDiscordCore* core); - enum EDiscordResult (*run_callbacks)(struct IDiscordCore* core); - void (*set_log_hook)(struct IDiscordCore* core, enum EDiscordLogLevel min_level, void* hook_data, void (*hook)(void* hook_data, enum EDiscordLogLevel level, const char* message)); - struct IDiscordApplicationManager* (*get_application_manager)(struct IDiscordCore* core); - struct IDiscordUserManager* (*get_user_manager)(struct IDiscordCore* core); - struct IDiscordImageManager* (*get_image_manager)(struct IDiscordCore* core); - struct IDiscordActivityManager* (*get_activity_manager)(struct IDiscordCore* core); - struct IDiscordRelationshipManager* (*get_relationship_manager)(struct IDiscordCore* core); - struct IDiscordLobbyManager* (*get_lobby_manager)(struct IDiscordCore* core); - struct IDiscordNetworkManager* (*get_network_manager)(struct IDiscordCore* core); - struct IDiscordOverlayManager* (*get_overlay_manager)(struct IDiscordCore* core); - struct IDiscordStorageManager* (*get_storage_manager)(struct IDiscordCore* core); - struct IDiscordStoreManager* (*get_store_manager)(struct IDiscordCore* core); - struct IDiscordVoiceManager* (*get_voice_manager)(struct IDiscordCore* core); - struct IDiscordAchievementManager* (*get_achievement_manager)(struct IDiscordCore* core); + void (DISCORD_API *destroy)(struct IDiscordCore* core); + enum EDiscordResult (DISCORD_API *run_callbacks)(struct IDiscordCore* core); + void (DISCORD_API *set_log_hook)(struct IDiscordCore* core, enum EDiscordLogLevel min_level, void* hook_data, void (DISCORD_API *hook)(void* hook_data, enum EDiscordLogLevel level, const char* message)); + struct IDiscordApplicationManager* (DISCORD_API *get_application_manager)(struct IDiscordCore* core); + struct IDiscordUserManager* (DISCORD_API *get_user_manager)(struct IDiscordCore* core); + struct IDiscordImageManager* (DISCORD_API *get_image_manager)(struct IDiscordCore* core); + struct IDiscordActivityManager* (DISCORD_API *get_activity_manager)(struct IDiscordCore* core); + struct IDiscordRelationshipManager* (DISCORD_API *get_relationship_manager)(struct IDiscordCore* core); + struct IDiscordLobbyManager* (DISCORD_API *get_lobby_manager)(struct IDiscordCore* core); + struct IDiscordNetworkManager* (DISCORD_API *get_network_manager)(struct IDiscordCore* core); + struct IDiscordOverlayManager* (DISCORD_API *get_overlay_manager)(struct IDiscordCore* core); + struct IDiscordStorageManager* (DISCORD_API *get_storage_manager)(struct IDiscordCore* core); + struct IDiscordStoreManager* (DISCORD_API *get_store_manager)(struct IDiscordCore* core); + struct IDiscordVoiceManager* (DISCORD_API *get_voice_manager)(struct IDiscordCore* core); + struct IDiscordAchievementManager* (DISCORD_API *get_achievement_manager)(struct IDiscordCore* core); }; struct DiscordCreateParams { @@ -644,7 +727,7 @@ void DiscordCreateParamsSetDefault(struct DiscordCreateParams* params) params->achievement_version = DISCORD_ACHIEVEMENT_MANAGER_VERSION; } -enum EDiscordResult DiscordCreate(DiscordVersion version, struct DiscordCreateParams* params, struct IDiscordCore** result); +enum EDiscordResult DISCORD_API DiscordCreate(DiscordVersion version, struct DiscordCreateParams* params, struct IDiscordCore** result); #ifdef __cplusplus } From 121a11f132465c1640eb4a9aeac5531fdda40724 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Fri, 15 Jul 2022 17:36:06 +0200 Subject: [PATCH 018/386] Revert to the IBM ESDI MCA roms to prevent a hang into booting some operating systems such as NT. Remove horrible status hack. --- src/disk/hdc_esdi_mca.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/disk/hdc_esdi_mca.c b/src/disk/hdc_esdi_mca.c index 9d2881294..e0859697f 100644 --- a/src/disk/hdc_esdi_mca.c +++ b/src/disk/hdc_esdi_mca.c @@ -86,8 +86,8 @@ #define ESDI_IOADDR_SEC 0x3518 #define ESDI_IRQCHAN 14 -#define BIOS_FILE_L "roms/hdd/esdi/62-000193-036.BIN" -#define BIOS_FILE_H "roms/hdd/esdi/62-000194-036.BIN" +#define BIOS_FILE_L "roms/hdd/esdi/90x8969.bin" +#define BIOS_FILE_H "roms/hdd/esdi/90x8970.bin" #define ESDI_TIME 512 @@ -133,7 +133,7 @@ typedef struct esdi_t { int command; int cmd_state; - int in_reset, in_reset2; + int in_reset; uint64_t callback; pc_timer_t timer; @@ -825,13 +825,6 @@ esdi_read(uint16_t port, void *priv) switch (port & 7) { case 2: /*Basic status register*/ - if (!dev->status) { - if (((dev->command == CMD_WRITE) || dev->in_reset2) && !dev->cmd_dev) { - dev->in_reset2 = 0; - dev->status |= STATUS_STATUS_OUT_FULL; - } else if (dev->command && (dev->cmd_dev == ATTN_HOST_ADAPTER)) - dev->status |= STATUS_STATUS_OUT_FULL; - } ret = dev->status; break; @@ -859,7 +852,6 @@ esdi_write(uint16_t port, uint8_t val, void *priv) case 2: /*Basic control register*/ if ((dev->basic_ctrl & CTRL_RESET) && !(val & CTRL_RESET)) { dev->in_reset = 1; - dev->in_reset2 = 1; esdi_mca_set_callback(dev, ESDI_TIME * 50); dev->status = STATUS_BUSY; } @@ -891,7 +883,6 @@ esdi_write(uint16_t port, uint8_t val, void *priv) case ATTN_RESET: dev->in_reset = 1; - dev->in_reset2 = 1; esdi_mca_set_callback(dev, ESDI_TIME * 50); dev->status = STATUS_BUSY; break; @@ -1152,7 +1143,6 @@ esdi_init(const device_t *info) /* Mark for a reset. */ dev->in_reset = 1; - dev->in_reset2 = 1; esdi_mca_set_callback(dev, ESDI_TIME * 50); dev->status = STATUS_BUSY; From 0ba7c3c025c62b9a8352230a2e80d5a8f5a41eb5 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Fri, 15 Jul 2022 18:27:30 +0200 Subject: [PATCH 019/386] Fix warnings on the XGA, 8514/A and EGA Render map files. Revert initial XGA rom length back to 0x2000 to prevent error 114 in the MCA bioses. --- src/include/86box/vid_ega_render_remap.h | 30 ++++---- src/video/vid_8514a.c | 89 ++---------------------- src/video/vid_xga.c | 58 ++++++++------- 3 files changed, 51 insertions(+), 126 deletions(-) diff --git a/src/include/86box/vid_ega_render_remap.h b/src/include/86box/vid_ega_render_remap.h index 4ad64466c..b21233fbd 100644 --- a/src/include/86box/vid_ega_render_remap.h +++ b/src/include/86box/vid_ega_render_remap.h @@ -88,24 +88,24 @@ static uint32_t (*address_remap_funcs[16])(ega_t *ega, uint32_t in_addr) = void ega_recalc_remap_func(ega_t *ega) { - int func_nr; + int func_nr; - if (ega->crtc[0x14] & 0x40) - func_nr = VAR_DWORD_MODE; - else if (ega->crtc[0x17] & 0x40) - func_nr = VAR_BYTE_MODE; - else if (ega->crtc[0x17] & 0x20) - func_nr = VAR_WORD_MODE_MA15; - else - func_nr = VAR_WORD_MODE_MA13; + if (ega->crtc[0x14] & 0x40) + func_nr = VAR_DWORD_MODE; + else if (ega->crtc[0x17] & 0x40) + func_nr = VAR_BYTE_MODE; + else if (ega->crtc[0x17] & 0x20) + func_nr = VAR_WORD_MODE_MA15; + else + func_nr = VAR_WORD_MODE_MA13; - if (!(ega->crtc[0x17] & 0x01)) - func_nr |= VAR_ROW0_MA13; - if (!(ega->crtc[0x17] & 0x02)) - func_nr |= VAR_ROW1_MA14; + if (!(ega->crtc[0x17] & 0x01)) + func_nr |= VAR_ROW0_MA13; + if (!(ega->crtc[0x17] & 0x02)) + func_nr |= VAR_ROW1_MA14; - ega->remap_required = (func_nr != 0); - ega->remap_func = address_remap_funcs[func_nr]; + ega->remap_required = (func_nr != 0); + ega->remap_func = address_remap_funcs[func_nr]; } #endif /*VIDEO_RENDER_REMAP_H*/ diff --git a/src/video/vid_8514a.c b/src/video/vid_8514a.c index 7f1c7d770..0d28be612 100644 --- a/src/video/vid_8514a.c +++ b/src/video/vid_8514a.c @@ -37,22 +37,6 @@ #include <86box/vid_svga_render.h> #include "cpu.h" -#define INT_VSY (1 << 0) -#define INT_GE_BSY (1 << 1) -#define INT_FIFO_OVR (1 << 2) -#define INT_FIFO_EMP (1 << 3) -#define INT_MASK 0xf - -#define FIFO_MASK (FIFO_SIZE - 1) -#define FIFO_ENTRY_SIZE (1 << 31) - -#define FIFO_ENTRIES_8514 (dev->fifo_write_idx - dev->fifo_read_idx) -#define FIFO_FULL_8514 ((dev->fifo_write_idx - dev->fifo_read_idx) >= FIFO_SIZE) -#define FIFO_EMPTY_8514 (dev->fifo_read_idx == dev->fifo_write_idx) - -#define FIFO_TYPE_8514 0xff000000 -#define FIFO_ADDR_8514 0x00ffffff - static void ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len); static void ibm8514_accel_outb(uint16_t port, uint8_t val, void *p); static void ibm8514_accel_outw(uint16_t port, uint16_t val, void *p); @@ -368,17 +352,14 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) case 0x82e8: case 0xc2e8: if (len == 1) { - dev->accel.cur_y_bit12 = (dev->accel.cur_y_bit12 & 0xf00) | val; dev->accel.cur_y = (dev->accel.cur_y & 0x700) | val; } else { - dev->accel.cur_y_bit12 = val & 0xfff; dev->accel.cur_y = val & 0x7ff; } break; case 0x82e9: case 0xc2e9: if (len == 1) { - dev->accel.cur_y_bit12 = (dev->accel.cur_y_bit12 & 0xff) | ((val & 0x0f) << 8); dev->accel.cur_y = (dev->accel.cur_y & 0xff) | ((val & 0x07) << 8); } break; @@ -386,17 +367,14 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) case 0x86e8: case 0xc6e8: if (len == 1) { - dev->accel.cur_x_bit12 = (dev->accel.cur_x_bit12 & 0xf00) | val; dev->accel.cur_x = (dev->accel.cur_x & 0x700) | val; } else { - dev->accel.cur_x_bit12 = val & 0xfff; dev->accel.cur_x = val & 0x7ff; } break; case 0x86e9: case 0xc6e9: if (len == 1) { - dev->accel.cur_x_bit12 = (dev->accel.cur_x_bit12 & 0xff) | ((val & 0x0f) << 8); dev->accel.cur_x = (dev->accel.cur_x & 0xff) | ((val & 0x07) << 8); } break; @@ -448,7 +426,7 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) else { dev->accel.err_term = val & 0x3fff; if (val & 0x2000) - dev->accel.err_term |= ~0x3fff; + dev->accel.err_term |= ~0x1fff; } break; case 0x92e9: @@ -456,7 +434,7 @@ ibm8514_accel_out_fifo(ibm8514_t *dev, uint16_t port, uint32_t val, int len) if (len == 1) { dev->accel.err_term = (dev->accel.err_term & 0xff) | ((val & 0x3f) << 8); if (val & 0x20) - dev->accel.err_term |= ~0x3fff; + dev->accel.err_term |= ~0x1fff; } break; @@ -707,7 +685,6 @@ ibm8514_ramdac_in(uint16_t port, void *p) { svga_t *svga = (svga_t *)p; uint8_t ret = 0xff; - uint8_t index; switch (port) { case 0x2ea: @@ -727,62 +704,6 @@ ibm8514_ramdac_in(uint16_t port, void *p) return ret; } -static void -ibm8514_io_remove(svga_t *svga) -{ - io_removehandler(0x2e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x2ea, 0x0004, ibm8514_ramdac_in, NULL, NULL, ibm8514_ramdac_out, NULL, NULL, svga); - io_removehandler(0x6e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x12e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x16e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x1ae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x1ee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x22e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x26e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x2ee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x42e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x4ae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x52e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x56e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x5ae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x5ee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x82e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x86e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x8ae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x8ee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x92e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x96e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x9ae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0x9ee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xa2e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xa6e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xaae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xaee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xb2e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xb6e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xbae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xbee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xe2e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - - io_removehandler(0xc2e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xc6e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xcae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xcee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xd2e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xd6e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xdae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xdee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xe6e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xeae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xeee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xf2e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xf6e8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xfae8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); - io_removehandler(0xfee8, 0x0002, ibm8514_accel_inb, ibm8514_accel_inw, NULL, ibm8514_accel_outb, ibm8514_accel_outw, NULL, svga); -} - static void ibm8514_io_set(svga_t *svga) { @@ -1139,7 +1060,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat uint32_t old_mix_dat; int and3 = dev->accel.cur_x & 3; uint8_t poly_src = 0; - int16_t tmpswap; + int16_t tmpswap = 0; if (dev->accel.cmd & 0x100) { dev->force_busy = 1; @@ -2717,7 +2638,7 @@ bitblt_pix: break; } - READ(dev->accel.dest + dev->accel.cx, dest_dat); + READ(dev->accel.dest + dev->accel.dx, dest_dat); if ((compare_mode == 0) || ((compare_mode == 0x10) && (dest_dat >= compare)) || @@ -2729,7 +2650,7 @@ bitblt_pix: old_dest_dat = dest_dat; MIX(mix_dat & mix_mask, dest_dat, src_dat); dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); - WRITE(dev->accel.dest + dev->accel.cx, dest_dat); + WRITE(dev->accel.dest + dev->accel.dx, dest_dat); } } diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index 60e6f3d67..970834386 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -445,7 +445,6 @@ xga_ext_inb(uint16_t addr, void *p) svga_t *svga = (svga_t *)p; xga_t *xga = &svga->xga; uint8_t ret, index; - uint16_t sprite_idx; switch (addr & 0x0f) { case 0: @@ -898,7 +897,7 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; int y = ssv & 0x0f; int x = 0; - int dx, dy, dirx, diry; + int dx, dy, dirx = 0, diry = 0; dx = xga->accel.dst_map_x & 0x1fff; if (xga->accel.dst_map_x & 0x1800) @@ -1916,7 +1915,7 @@ xga_memio_writel(uint32_t addr, uint32_t val, void *p) static uint8_t xga_mem_read(uint32_t addr, xga_t *xga, svga_t *svga) { - uint8_t temp; + uint8_t temp = 0xff; addr &= 0x1fff; @@ -2031,19 +2030,16 @@ static void xga_hwcursor_draw(svga_t *svga, int displine) { xga_t *xga = &svga->xga; - uint8_t dat; + uint8_t dat = 0; int offset = xga->hwcursor_latch.x - xga->hwcursor_latch.xoff; int x, x_pos, y_pos; - int comb; + int comb = 0; uint32_t *p; - uint8_t *cd; int idx = (xga->cursor_data_on) ? 32 : 0; if (xga->interlace && xga->hwcursor_oddeven) xga->hwcursor_latch.addr += 16; - cd = (uint8_t *) xga->sprite_data; - y_pos = displine; x_pos = offset + svga->x_add; p = buffer32->line[y_pos]; @@ -2155,7 +2151,6 @@ xga_render_16bpp(xga_t *xga, svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t addr; if ((xga->displine + svga->y_add) < 0) return; @@ -2169,7 +2164,7 @@ xga_render_16bpp(xga_t *xga, svga_t *svga) for (x = 0; x <= (xga->h_disp); x += 8) { dat = *(uint32_t *)(&xga->vram[(xga->ma + (x << 1)) & xga->vram_mask]); - p[x] = video_16to32[dat & 0xffff]; + p[x] = video_16to32[dat & 0xffff]; p[x + 1] = video_16to32[dat >> 16]; dat = *(uint32_t *)(&xga->vram[(xga->ma + (x << 1) + 4) & xga->vram_mask]); @@ -2216,7 +2211,6 @@ static void xga_writeb(uint32_t addr, uint8_t val, void *p) { svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; //pclog("[%04X:%08X]: WriteB\n", CS, cpu_state.pc); xga_write(addr, val, p); @@ -2226,7 +2220,6 @@ static void xga_writew(uint32_t addr, uint16_t val, void *p) { svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; //pclog("[%04X:%08X]: WriteW\n", CS, cpu_state.pc); xga_write(addr, val, p); @@ -2237,7 +2230,6 @@ static void xga_writel(uint32_t addr, uint32_t val, void *p) { svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; //pclog("[%04X:%08X]: WriteL\n", CS, cpu_state.pc); xga_write(addr, val, p); @@ -2345,7 +2337,6 @@ static uint8_t xga_readb(uint32_t addr, void *p) { svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; uint8_t ret; ret = xga_read(addr, p); @@ -2357,7 +2348,6 @@ static uint16_t xga_readw(uint32_t addr, void *p) { svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; uint16_t ret; ret = xga_read(addr, p); @@ -2370,7 +2360,6 @@ static uint32_t xga_readl(uint32_t addr, void *p) { svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; uint32_t ret; ret = xga_read(addr, p); @@ -2665,16 +2654,11 @@ xga_mca_feedb(void *priv) } static void -xga_pos_out(uint16_t addr, uint8_t val, void *priv) +xga_mca_reset(void *p) { - svga_t *svga = (svga_t *)priv; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; - mem_mapping_disable(&svga->mapping); - if (val & 0x08) { - mem_mapping_enable(&svga->mapping); - xga_updatemapping(svga); - } + xga_mca_write(0x102, 0, svga); } static uint8_t @@ -2692,6 +2676,7 @@ static void xga_t *xga = &svga->xga; FILE *f; uint32_t temp; + uint32_t initial_bios_addr = device_get_config_hex20("init_bios_addr"); uint8_t *rom = NULL; xga->type = device_get_config_int("type"); @@ -2704,7 +2689,7 @@ static void xga->on = 0; xga->hwcursor.cur_xsize = 64; xga->hwcursor.cur_ysize = 64; - xga->bios_rom.sz = 0x8000; + xga->bios_rom.sz = 0x2000; f = rom_fopen(xga->type ? XGA2_BIOS_PATH : XGA_BIOS_PATH, "rb"); (void)fseek(f, 0L, SEEK_END); @@ -2729,7 +2714,7 @@ static void xga->instance = 0; xga->rom_addr = 0; mem_mapping_add(&xga->bios_rom.mapping, - 0xd8000, xga->bios_rom.sz, + initial_bios_addr, xga->bios_rom.sz, rom_read, rom_readw, rom_readl, NULL, NULL, NULL, xga->bios_rom.rom, MEM_MAPPING_EXTERNAL, &xga->bios_rom); @@ -2759,7 +2744,7 @@ static void xga->pos_regs[1] = 0x8f; if (xga->bus & DEVICE_MCA) { - mca_add(xga_mca_read, xga_mca_write, xga_mca_feedb, NULL, svga); + mca_add(xga_mca_read, xga_mca_write, xga_mca_feedb, xga_mca_reset, svga); } else { io_sethandler(0x0100, 0x0008, xga_pos_in, NULL, NULL, NULL, NULL, NULL, svga); io_sethandler(0x2100 + (xga->instance << 4), 0x0010, xga_ext_inb, NULL, NULL, xga_ext_outb, NULL, NULL, svga); @@ -2805,6 +2790,25 @@ xga_force_redraw(void *p) static const device_config_t xga_configuration[] = { // clang-format off + { + .name = "init_bios_addr", + .description = "Initial MCA BIOS Address (before POS configuration)", + .type = CONFIG_HEX20, + .default_string = "", + .default_int = 0xc0000, + .file_filter = "", + .spinner = { 0 }, + .selection = { + { .description = "C000H", .value = 0xc0000 }, + { .description = "C800H", .value = 0xc8000 }, + { .description = "CC00H", .value = 0xcc000 }, + { .description = "D000H", .value = 0xd0000 }, + { .description = "D400H", .value = 0xd4000 }, + { .description = "D800H", .value = 0xd8000 }, + { .description = "DC00H", .value = 0xdc000 }, + { .description = "" } + }, + }, { .name = "type", .description = "XGA type", From 3cc3bb339ad6c98a696deabd6d413769af2af598 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Fri, 15 Jul 2022 18:36:47 +0200 Subject: [PATCH 020/386] Fix the fix. --- src/video/vid_8514a.c | 4 ---- src/video/vid_xga.c | 9 --------- 2 files changed, 13 deletions(-) diff --git a/src/video/vid_8514a.c b/src/video/vid_8514a.c index 0d28be612..1cb0a5407 100644 --- a/src/video/vid_8514a.c +++ b/src/video/vid_8514a.c @@ -662,7 +662,6 @@ static void ibm8514_ramdac_out(uint16_t port, uint8_t val, void *p) { svga_t *svga = (svga_t *)p; - uint8_t index; switch (port) { case 0x2ea: @@ -1038,8 +1037,6 @@ ibm8514_short_stroke_start(int count, int cpu_input, uint32_t mix_dat, uint32_t ibm8514_accel_start(count, cpu_input, mix_dat, cpu_dat, dev, len); } -#define SWAP(a,b) { tmpswap = a; a = b; b = tmpswap; } - static void ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, ibm8514_t *dev, int len) { @@ -1060,7 +1057,6 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat uint32_t old_mix_dat; int and3 = dev->accel.cur_x & 3; uint8_t poly_src = 0; - int16_t tmpswap = 0; if (dev->accel.cmd & 0x100) { dev->force_busy = 1; diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index 970834386..40f0aa6aa 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -2210,8 +2210,6 @@ xga_write(uint32_t addr, uint8_t val, void *p) static void xga_writeb(uint32_t addr, uint8_t val, void *p) { - svga_t *svga = (svga_t *)p; - //pclog("[%04X:%08X]: WriteB\n", CS, cpu_state.pc); xga_write(addr, val, p); } @@ -2219,8 +2217,6 @@ xga_writeb(uint32_t addr, uint8_t val, void *p) static void xga_writew(uint32_t addr, uint16_t val, void *p) { - svga_t *svga = (svga_t *)p; - //pclog("[%04X:%08X]: WriteW\n", CS, cpu_state.pc); xga_write(addr, val, p); xga_write(addr + 1, val >> 8, p); @@ -2229,8 +2225,6 @@ xga_writew(uint32_t addr, uint16_t val, void *p) static void xga_writel(uint32_t addr, uint32_t val, void *p) { - svga_t *svga = (svga_t *)p; - //pclog("[%04X:%08X]: WriteL\n", CS, cpu_state.pc); xga_write(addr, val, p); xga_write(addr + 1, val >> 8, p); @@ -2336,7 +2330,6 @@ xga_read(uint32_t addr, void *p) static uint8_t xga_readb(uint32_t addr, void *p) { - svga_t *svga = (svga_t *)p; uint8_t ret; ret = xga_read(addr, p); @@ -2347,7 +2340,6 @@ xga_readb(uint32_t addr, void *p) static uint16_t xga_readw(uint32_t addr, void *p) { - svga_t *svga = (svga_t *)p; uint16_t ret; ret = xga_read(addr, p); @@ -2359,7 +2351,6 @@ xga_readw(uint32_t addr, void *p) static uint32_t xga_readl(uint32_t addr, void *p) { - svga_t *svga = (svga_t *)p; uint32_t ret; ret = xga_read(addr, p); From 3b2b0b984aeaa34ab08b2ee59ca46382a3c12a00 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 15:36:00 -0300 Subject: [PATCH 021/386] Jenkins: Expand nodes which can perform the initial clone --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index fbcb51c04..fbb7fd081 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -194,7 +194,7 @@ pipeline { /* Adding to the above, run a git clone as soon as possible on any node to further avoid race conditions caused by busy node executor delays. */ retry(10) { - node('citadel && !Windows') { + node('!Windows') { /* Run git clone. */ gitClone(repository[buildBranch], branch[buildBranch]) From 2ed8ad907c27cc8248fd94819b146150fa50db46 Mon Sep 17 00:00:00 2001 From: Adrien Moulin Date: Fri, 15 Jul 2022 23:42:40 +0200 Subject: [PATCH 022/386] ACPI: replace 3.58MHz timer with an overflow timer --- src/acpi.c | 95 ++++++++++++++++++++++++---------------- src/include/86box/acpi.h | 3 +- src/include/86box/pit.h | 2 +- src/pit.c | 1 - 4 files changed, 60 insertions(+), 41 deletions(-) diff --git a/src/acpi.c b/src/acpi.c index 11d991f63..c73440fa5 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -20,6 +20,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" @@ -37,10 +38,11 @@ #include <86box/acpi.h> #include <86box/machine.h> #include <86box/i2c.h> - +#include <86box/video.h> int acpi_rtc_status = 0; +static double cpu_to_acpi; #ifdef ENABLE_ACPI_LOG int acpi_do_log = ENABLE_ACPI_LOG; @@ -61,6 +63,50 @@ acpi_log(const char *fmt, ...) #define acpi_log(fmt, ...) #endif +static uint64_t acpi_clock_get() { + return tsc * cpu_to_acpi; +} + +static uint32_t acpi_timer_get(acpi_t *dev) { + uint64_t clock = acpi_clock_get(); + if (dev->regs.timer32) + return clock & 0xffffffff; + else + return clock & 0xffffff; +} + +static double acpi_get_overflow_period(acpi_t *dev) { + uint64_t timer = acpi_clock_get(); + uint64_t overflow_time; + + if (dev->regs.timer32) { + overflow_time = (timer + 0x80000000LL) & ~0x7fffffffLL; + } else { + overflow_time = (timer + 0x800000LL) & ~0x7fffffLL; + } + + uint64_t time_to_overflow = overflow_time - timer; + + return ((double)time_to_overflow / (double)ACPI_TIMER_FREQ) * 1000000.0; +} + +static void +acpi_timer_overflow(void *priv) +{ + acpi_t *dev = (acpi_t *) priv; + dev->regs.pmsts |= TMROF_STS; + acpi_update_irq(dev); +} + +static void +acpi_timer_update(acpi_t *dev, bool enable) +{ + if (enable) { + timer_on_auto(&dev->timer, acpi_get_overflow_period(dev)); + } else { + timer_stop(&dev->timer); + } +} void acpi_update_irq(acpi_t *dev) @@ -84,6 +130,8 @@ acpi_update_irq(acpi_t *dev) else pci_clear_mirq(0xf0 | dev->irq_line, 1); } + + acpi_timer_update(dev, (dev->regs.pmen & TMROF_EN) && !(dev->regs.pmsts & TMROF_STS)); } @@ -145,7 +193,7 @@ acpi_reg_read_common_regs(int size, uint16_t addr, void *p) break; case 0x08: case 0x09: case 0x0a: case 0x0b: /* PMTMR - Power Management Timer Register (IO) */ - ret = (dev->regs.timer_val >> shift32) & 0xff; + ret = (acpi_timer_get(dev) >> shift32) & 0xff; #ifdef USE_DYNAREC if (cpu_use_dynarec) update_tsc(); @@ -1282,33 +1330,6 @@ acpi_update_aux_io_mapping(acpi_t *dev, uint32_t base, int chipset_en) } } - -static void -acpi_timer_count(void *priv) -{ - acpi_t *dev = (acpi_t *) priv; - int overflow; - uint32_t old; - - old = dev->regs.timer_val; - dev->regs.timer_val++; - - if (dev->regs.timer32) - overflow = (old ^ dev->regs.timer_val) & 0x80000000; - else { - dev->regs.timer_val &= 0x00ffffff; - overflow = (old ^ dev->regs.timer_val) & 0x00800000; - } - - if (overflow) { - dev->regs.pmsts |= TMROF_EN; - acpi_update_irq(dev); - } - - timer_advance_u64(&dev->timer, ACPICONST); -} - - static void acpi_timer_resume(void *priv) { @@ -1338,9 +1359,6 @@ void acpi_set_timer32(acpi_t *dev, uint8_t timer32) { dev->regs.timer32 = timer32; - - if (!dev->regs.timer32) - dev->regs.timer_val &= 0x00ffffff; } @@ -1524,9 +1542,12 @@ static void acpi_speed_changed(void *priv) { acpi_t *dev = (acpi_t *) priv; + cpu_to_acpi = ACPI_TIMER_FREQ / cpuclock; + bool timer_enabled = timer_is_enabled(&dev->timer); + timer_stop(&dev->timer); - timer_disable(&dev->timer); - timer_set_delay_u64(&dev->timer, ACPICONST); + if (timer_enabled) + timer_on_auto(&dev->timer, acpi_get_overflow_period(dev)); } @@ -1541,7 +1562,7 @@ acpi_close(void *priv) i2c_gpio_close(dev->i2c); } - timer_disable(&dev->timer); + timer_stop(&dev->timer); free(dev); } @@ -1556,6 +1577,7 @@ acpi_init(const device_t *info) if (dev == NULL) return(NULL); memset(dev, 0x00, sizeof(acpi_t)); + cpu_to_acpi = ACPI_TIMER_FREQ / cpuclock; dev->vendor = info->local; dev->irq_line = 9; @@ -1604,8 +1626,7 @@ acpi_init(const device_t *info) break; } - timer_add(&dev->timer, acpi_timer_count, dev, 0); - timer_set_delay_u64(&dev->timer, ACPICONST); + timer_add(&dev->timer, acpi_timer_overflow, dev, 0); timer_add(&dev->resume_timer, acpi_timer_resume, dev, 0); acpi_reset(dev); diff --git a/src/include/86box/acpi.h b/src/include/86box/acpi.h index 999909f1d..d12b45507 100644 --- a/src/include/86box/acpi.h +++ b/src/include/86box/acpi.h @@ -76,10 +76,9 @@ typedef struct devsts, glben, glbctl, devctl, padsts, paden, - gptren, gptimer, timer_val, + gptren, gptimer, gpo_val, gpi_val, extsmi_val, pad0; - uint64_t tmr_overflow_time; } acpi_regs_t; diff --git a/src/include/86box/pit.h b/src/include/86box/pit.h index c560fae12..e823794df 100644 --- a/src/include/86box/pit.h +++ b/src/include/86box/pit.h @@ -70,7 +70,7 @@ extern uint64_t PITCONST, ISACONST, HERCCONST, VGACONST1, VGACONST2, - RTCCONST, ACPICONST; + RTCCONST; extern int refresh_at_enable; diff --git a/src/pit.c b/src/pit.c index 28fc9b3c2..f19a1acf7 100644 --- a/src/pit.c +++ b/src/pit.c @@ -1039,7 +1039,6 @@ pit_set_clock(int clock) VGACONST1 = (uint64_t) (cpuclock / 25175000.0 * (double)(1ull << 32)); VGACONST2 = (uint64_t) (cpuclock / 28322000.0 * (double)(1ull << 32)); RTCCONST = (uint64_t) (cpuclock / 32768.0 * (double)(1ull << 32)); - ACPICONST = (uint64_t) (cpuclock / 3579545.0 * (double)(1ull << 32)); TIMER_USEC = (uint64_t)((cpuclock / 1000000.0) * (double)(1ull << 32)); From a8be5d1f188768bf7e09afc120a8a764345237e8 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 20:39:06 -0300 Subject: [PATCH 023/386] Jenkins: Dummy commit to test new webhook flow --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index fbb7fd081..55c2c254e 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -137,7 +137,7 @@ def removeDir(dir) { def runBuild(args) { if (isUnix()) - return sh(returnStatus: true, script: "chmod u+x \"$WORKSPACE/.ci/build.sh\" && exec \"$WORKSPACE/.ci/build.sh\" $args") + return sh(returnStatus: true, script: "chmod u+x '$WORKSPACE/.ci/build.sh' && exec '$WORKSPACE/.ci/build.sh' $args") else return bat(returnStatus: true, script: "C:\\msys64\\msys2_shell.cmd -msys2 -defterm -here -no-start -c 'exec \"\$(cygpath -u \\'%WORKSPACE%\\')/.ci/build.sh\" $args'") } From e9af11d9d9c439e9e0af049aeaac46ce89f6fa37 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 20:39:18 -0300 Subject: [PATCH 024/386] Jenkins: Second dummy commit to test new webhook flow --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 55c2c254e..cb58e1fd8 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -130,7 +130,7 @@ def gitClone(repository, branch) { def removeDir(dir) { if (isUnix()) - return sh(returnStatus: true, script: "rm -rf \"$dir\"") + return sh(returnStatus: true, script: "rm -rf '$dir'") else return bat(returnStatus: true, script: "rd /s /q \"$dir\"") } From da5d45138684dcec616086a96a7b7e3c4ed536ba Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:45:46 +0200 Subject: [PATCH 025/386] Preparation for SMI# and NMI# changes. --- src/cpu/386.c | 3 --- src/cpu/386_common.c | 21 ++++++++++++++++++--- src/cpu/386_dynarec.c | 3 --- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/cpu/386.c b/src/cpu/386.c index 2484cbb66..5f30e1199 100644 --- a/src/cpu/386.c +++ b/src/cpu/386.c @@ -210,9 +210,6 @@ exec386(int cycs) loadcs(readmemw(0, addr + 2)); } } else if (nmi && nmi_enable && nmi_mask) { - if (is486 && (cpu_fast_off_flags & 0x20000000)) - cpu_fast_off_count = cpu_fast_off_val + 1; - cpu_state.oldpc = cpu_state.pc; x86_int(2); nmi_enable = 0; diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index 73a06f553..a88f892e1 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -1183,9 +1183,6 @@ enter_smm(int in_hlt) void enter_smm_check(int in_hlt) { - if (smi_line && (cpu_fast_off_flags & 0x80000000)) - cpu_fast_off_count = cpu_fast_off_val + 1; - if ((in_smm == 0) && smi_line) { #ifdef ENABLE_386_COMMON_LOG x386_common_log("SMI while not in SMM\n"); @@ -1840,6 +1837,24 @@ sysret(uint32_t fetchdat) } +void +raise_smi(void) +{ + if (is486 && (cpu_fast_off_flags & 0x80000000)) + cpu_fast_off_count = cpu_fast_off_val + 1; + + smi_line = 1; +} + + +void +raise_nmi(void) +{ + if (is486 && (cpu_fast_off_flags & 0x20000000)) + cpu_fast_off_count = cpu_fast_off_val + 1; +} + + #ifndef USE_DYNAREC /* This is for compatibility with new x87 code. */ void codegen_set_rounding_mode(int mode) diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index 46674fbc6..3e4d91ed2 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -819,9 +819,6 @@ exec386_dynarec(int cycs) if (smi_line) enter_smm_check(0); else if (nmi && nmi_enable && nmi_mask) { - if (is486 && (cpu_fast_off_flags & 0x20000000)) - cpu_fast_off_count = cpu_fast_off_val + 1; - #ifndef USE_NEW_DYNAREC oldcs = CS; #endif From 2c9bfa979ffb235e4f9cf858c1fb5776be823c13 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:47:39 +0200 Subject: [PATCH 026/386] ALi M1489 and a CPU fix. --- src/chipset/ali1489.c | 2 +- src/cpu/386_common.c | 4 ++-- src/cpu/cpu.h | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index 5ba53f34c..c8e07c657 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -319,7 +319,7 @@ ali1489_write(uint16_t addr, uint8_t val, void *priv) smi_line = 1; break; case 0x10: - nmi = 1; + nmi_raise(); break; case 0x20: picint(1 << 15); diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index a88f892e1..1f5bfe3b5 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -1838,7 +1838,7 @@ sysret(uint32_t fetchdat) void -raise_smi(void) +smi_raise(void) { if (is486 && (cpu_fast_off_flags & 0x80000000)) cpu_fast_off_count = cpu_fast_off_val + 1; @@ -1848,7 +1848,7 @@ raise_smi(void) void -raise_nmi(void) +nmi_raise(void) { if (is486 && (cpu_fast_off_flags & 0x20000000)) cpu_fast_off_count = cpu_fast_off_val + 1; diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index c140cb7db..136a6c834 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -733,4 +733,7 @@ extern uint8_t do_translate, do_translate2; extern void reset_808x(int hard); +extern void smi_raise(); +extern void nmi_raise(); + #endif /*EMU_CPU_H*/ From 0cea9de7df0debeecdfc0473796e912578ce9fc4 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:48:59 +0200 Subject: [PATCH 027/386] VIA PIPC and ALi M1489 fix. --- src/chipset/ali1489.c | 2 ++ src/chipset/via_pipc.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index c8e07c657..9738baed3 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -197,7 +197,9 @@ ali1489_defaults(ali1489_t *dev) picintc(1 << 10); picintc(1 << 15); +#ifdef OLD_NMI_BEHAVIOR nmi = 0; +#endif smi_line = 0; in_smm = 0; diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 076328a00..a415daa6f 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -728,8 +728,10 @@ pipc_fmnmi_read(uint16_t addr, void *priv) if (dev->ac97_regs[0][0x48] & 0x01) { if (dev->ac97_regs[0][0x48] & 0x04) smi_line = 0; +#ifdef OLD_NMI_BEHAVIOR else nmi = 0; +#endif } #endif @@ -790,7 +792,7 @@ pipc_fm_write(uint16_t addr, uint8_t val, void *priv) if (dev->ac97_regs[0][0x48] & 0x04) smi_line = 1; else - nmi = 1; + nmi_raise(); } } #else From 22a856634c398d7f1b38982343d5d33a1327e638 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:50:53 +0200 Subject: [PATCH 028/386] Amstrad. --- src/machine/m_amstrad.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/machine/m_amstrad.c b/src/machine/m_amstrad.c index 27244189d..cac5a29d2 100644 --- a/src/machine/m_amstrad.c +++ b/src/machine/m_amstrad.c @@ -1068,7 +1068,9 @@ vid_in_200(uint16_t addr, void *priv) case 0x03dd: ret = vid->crtc_index; /* Read NMI reason */ vid->crtc_index &= 0x1f; /* Reset NMI reason */ +#ifdef OLD_NMI_BEHAVIOR nmi = 0; /* And reset NMI flag */ +#endif return(ret); case 0x03de: @@ -1106,7 +1108,7 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) if (!(vid->operation_ctrl & 0x40) && mda->crtcreg <= 11) { vid->crtc_index = 0x20 | (mda->crtcreg & 0x1f); if (vid->operation_ctrl & 0x80) - nmi = 1; + nmi_raise(); vid->reg_3df = val; return; } @@ -1127,7 +1129,7 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) vid->crtc_index &= 0x1F; vid->crtc_index |= 0x80; if (vid->operation_ctrl & 0x80) - nmi = 1; + nmi_raise(); return; /* CGA writes ============================================================== */ @@ -1138,7 +1140,7 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) if (!(vid->operation_ctrl & 0x40) && cga->crtcreg <= 11) { vid->crtc_index = 0x20 | (cga->crtcreg & 0x1f); if (vid->operation_ctrl & 0x80) - nmi = 1; + nmi_raise(); vid->reg_3df = val; return; } @@ -1160,7 +1162,7 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) vid->crtc_index &= 0x1f; vid->crtc_index |= 0x80; if (vid->operation_ctrl & 0x80) - nmi = 1; + nmi_raise(); else set_lcd_cols(val); return; @@ -1174,7 +1176,7 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) if (val & 0x80) { vid->operation_ctrl = val; vid->crtc_index |= 0x40; - nmi = 1; + nmi_raise(); return; } timer_disable(&vid->cga.timer); From 49f4b2c8fb2c263f6863d27e0d2497c28134859b Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:52:50 +0200 Subject: [PATCH 029/386] AudioPCI and GUS. --- src/sound/snd_audiopci.c | 4 +++- src/sound/snd_gus.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index 251fda72f..fe00038c7 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -306,7 +306,9 @@ es1371_reset(void *p) es1371_t *dev = (es1371_t *) p; int i; +#ifdef OLD_NMI_BEHAVIOR nmi = 0; +#endif /* Interrupt/Chip Select Control Register, Address 00H Addressable as byte, word, longword */ @@ -1240,7 +1242,7 @@ capture_event(es1371_t *dev, int type, int rw, uint16_t port) dev->legacy_ctrl &= ~LEGACY_EVENT_TYPE_RW; dev->legacy_ctrl |= ((port << LEGACY_EVENT_ADDR_SHIFT) & LEGACY_EVENT_ADDR_MASK); dev->legacy_ctrl &= ~LEGACY_INT; - nmi = 1; + nmi_raise(); } static void diff --git a/src/sound/snd_gus.c b/src/sound/snd_gus.c index 293be8915..2bef7edac 100644 --- a/src/sound/snd_gus.c +++ b/src/sound/snd_gus.c @@ -452,11 +452,15 @@ writegus(uint16_t addr, uint8_t val, void *p) gus->irqstatus &= ~8; if (!(val & 0x20)) { gus->ad_status &= ~0x18; +#ifdef OLD_NMI_BEHAVIOR nmi = 0; +#endif } if (!(val & 0x02)) { gus->ad_status &= ~0x01; +#ifdef OLD_NMI_BEHAVIOR nmi = 0; +#endif } gus->tctrl = val; gus->sb_ctrl = val; @@ -492,7 +496,7 @@ writegus(uint16_t addr, uint8_t val, void *p) gus->ad_status |= 0x01; if (gus->sb_ctrl & 0x02) { if (gus->sb_nmi) - nmi = 1; + nmi_raise(); else if (gus->irq != -1) picint(1 << gus->irq); } @@ -568,7 +572,7 @@ writegus(uint16_t addr, uint8_t val, void *p) gus->ad_status |= 0x08; if (gus->sb_ctrl & 0x20) { if (gus->sb_nmi) - nmi = 1; + nmi_raise(); else if (gus->irq != -1) picint(1 << gus->irq); } @@ -580,7 +584,7 @@ writegus(uint16_t addr, uint8_t val, void *p) gus->ad_status |= 0x10; if (gus->sb_ctrl & 0x20) { if (gus->sb_nmi) - nmi = 1; + nmi_raise(); else if (gus->irq != -1) picint(1 << gus->irq); } @@ -832,7 +836,9 @@ readgus(uint16_t addr, void *p) case 0x209: gus->ad_status &= ~0x01; +#ifdef OLD_NMI_BEHAVIOR nmi = 0; +#endif /*FALLTHROUGH*/ case 0x389: val = gus->ad_data; From d12b8b8c30a3c25539f5f09a44c8351c8004a0ea Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:53:26 +0200 Subject: [PATCH 030/386] Sigma. --- src/video/vid_sigma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/video/vid_sigma.c b/src/video/vid_sigma.c index 9c5474de9..e340a7c52 100644 --- a/src/video/vid_sigma.c +++ b/src/video/vid_sigma.c @@ -208,7 +208,7 @@ sigma_out(uint16_t addr, uint8_t val, void *p) /* If set to NMI on video I/O... */ if (sigma->enable_nmi && (sigma->sigma_ctl & CTL_NMI)) { sigma->lastport |= 0x80; /* Card raised NMI */ - nmi = 1; + nmi_raise(); } /* For CRTC emulation, the card BIOS sets the value to be * read from port 0x3D1 like this */ @@ -245,7 +245,9 @@ sigma_out(uint16_t addr, uint8_t val, void *p) sigma->lastport &= 0x7F; return; case 0x2DC: /* Reset NMI */ +#idef OLD_NMI_BEHAVIOR nmi = 0; +#endif sigma->lastport &= 0x7F; return; case 0x2DD: /* Page in RAM at 0xC1800 */ From d68121ae898ae0d9d168d250efc5f77f04248242 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:54:49 +0200 Subject: [PATCH 031/386] ACPI, APM, PIC, and USB. --- src/acpi.c | 8 ++++---- src/apm.c | 2 +- src/pic.c | 2 +- src/usb.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/acpi.c b/src/acpi.c index c73440fa5..470e24c41 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -144,12 +144,12 @@ acpi_raise_smi(void *priv, int do_smi) if ((dev->vendor == VEN_VIA) || (dev->vendor == VEN_VIA_596B)) { if ((!dev->regs.smi_lock || !dev->regs.smi_active)) { if (do_smi) - smi_line = 1; + smi_raise(); dev->regs.smi_active = 1; } } else if ((dev->vendor == VEN_INTEL) || (dev->vendor == VEN_ALI)) { if (do_smi) - smi_line = 1; + smi_raise(); /* Clear bit 16 of GLBCTL. */ if (dev->vendor == VEN_INTEL) dev->regs.glbctl &= ~0x00010000; @@ -157,7 +157,7 @@ acpi_raise_smi(void *priv, int do_smi) dev->regs.ali_soft_smi = 1; } else if (dev->vendor == VEN_SMC) { if (do_smi) - smi_line = 1; + smi_raise(); } } } @@ -1449,7 +1449,7 @@ acpi_apm_out(uint16_t port, uint8_t val, void *p) dev->apm->cmd = val; // acpi_raise_smi(dev, dev->apm->do_smi); if (dev->apm->do_smi) - smi_line = 1; + smi_raise(); dev->regs.ali_soft_smi = 1; } else if (port == 0x0003) dev->apm->stat = val; diff --git a/src/apm.c b/src/apm.c index 9bee70e78..3fe8d54c6 100644 --- a/src/apm.c +++ b/src/apm.c @@ -67,7 +67,7 @@ apm_out(uint16_t port, uint8_t val, void *p) if (port == 0x0000) { dev->cmd = val; if (dev->do_smi) - smi_line = 1; + smi_raise(); } else dev->stat = val; } diff --git a/src/pic.c b/src/pic.c index efe81f470..23f99945e 100644 --- a/src/pic.c +++ b/src/pic.c @@ -608,7 +608,7 @@ picint_common(uint16_t num, int level, int set) if (set) { if (smi_irq_mask & num) { - smi_line = 1; + smi_raise(); smi_irq_status |= num; } diff --git a/src/usb.c b/src/usb.c index 2f8f957b5..c70fc2d63 100644 --- a/src/usb.c +++ b/src/usb.c @@ -173,7 +173,7 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p) if (val & 0x08) { dev->ohci_mmio[0x0f] = 0x40; if ((dev->ohci_mmio[0x13] & 0xc0) == 0xc0) - smi_line = 1; + smi_raise(); } /* bit HostControllerReset must be cleared for the controller to be seen as initialized */ From f6fef765d71cecda7362d9d85bf7d917f78465d3 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:58:37 +0200 Subject: [PATCH 032/386] Chipsets. --- src/chipset/ali1489.c | 2 +- src/chipset/contaq_82c59x.c | 2 +- src/chipset/ims8848.c | 2 +- src/chipset/intel_420ex.c | 2 +- src/chipset/intel_piix.c | 2 +- src/chipset/intel_sio.c | 2 +- src/chipset/opti895.c | 2 +- src/chipset/sis_5511.c | 2 +- src/chipset/sis_5571.c | 2 +- src/chipset/sis_85c496.c | 2 +- src/chipset/sis_85c4xx.c | 2 +- src/chipset/sis_85c50x.c | 2 +- src/chipset/umc_8886.c | 2 +- src/chipset/via_pipc.c | 2 +- src/chipset/via_vt82c49x.c | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index 9738baed3..921c7d082 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -318,7 +318,7 @@ ali1489_write(uint16_t addr, uint8_t val, void *priv) if (((val & 0x14) == 0x14) && !(old & 0x08) && (val & 0x08)) { switch (dev->regs[0x35] & 0x30) { case 0x00: - smi_line = 1; + smi_raise(); break; case 0x10: nmi_raise(); diff --git a/src/chipset/contaq_82c59x.c b/src/chipset/contaq_82c59x.c index 6763202d0..97c8716eb 100644 --- a/src/chipset/contaq_82c59x.c +++ b/src/chipset/contaq_82c59x.c @@ -242,7 +242,7 @@ contaq_82c59x_write(uint16_t addr, uint8_t val, void *priv) dev->regs[dev->index] = val; if (val & 0x80) { if (dev->regs[0x65] & 0x80) - smi_line = 1; + smi_raise(); dev->smi_status[0] |= 0x10; } break; diff --git a/src/chipset/ims8848.c b/src/chipset/ims8848.c index 10e87b530..35b1ef62b 100644 --- a/src/chipset/ims8848.c +++ b/src/chipset/ims8848.c @@ -230,7 +230,7 @@ ims8848_write(uint16_t addr, uint8_t val, void *priv) if (dev->idx == 0x1b) { ims8848_smram(dev); if (!(old & 0x10) && (val & 0x10)) - smi_line = 1; + smi_raise(); } else if (dev->idx == 0x1c) pci_set_irq_routing(PCI_INTA, (val >> 4) ? (val >> 4) : PCI_IRQ_DISABLED); break; diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 187e6f636..8c8603efc 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -423,7 +423,7 @@ i420ex_fast_off_count(void *priv) cpu_fast_off_count--; if (cpu_fast_off_count == 0) { - smi_line = 1; + smi_raise(); dev->regs[0xaa] |= 0x20; cpu_fast_off_count = dev->regs[0xa8] + 1; } diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index 025862c44..55002405f 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -1334,7 +1334,7 @@ piix_fast_off_count(void *priv) cpu_fast_off_count--; if (cpu_fast_off_count == 0) { - smi_line = 1; + smi_raise(); dev->regs[0][0xaa] |= 0x20; cpu_fast_off_count = dev->regs[0][0xa8] + 1; } diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index ab535cb65..75aef516c 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -432,7 +432,7 @@ sio_fast_off_count(void *priv) cpu_fast_off_count--; if (cpu_fast_off_count == 0) { - smi_line = 1; + smi_raise(); dev->regs[0xaa] |= 0x20; cpu_fast_off_count = dev->regs[0xa8] + 1; } diff --git a/src/chipset/opti895.c b/src/chipset/opti895.c index 8efddb96d..9eb360e02 100644 --- a/src/chipset/opti895.c +++ b/src/chipset/opti895.c @@ -175,7 +175,7 @@ opti895_write(uint16_t addr, uint8_t val, void *priv) case 0xe1: if ((val & 0x08) && (dev->regs[0xe0] & 0x01)) { - smi_line = 1; + smi_raise(); dev->forced_green = 1; break; } diff --git a/src/chipset/sis_5511.c b/src/chipset/sis_5511.c index 63950d47a..d0900629d 100644 --- a/src/chipset/sis_5511.c +++ b/src/chipset/sis_5511.c @@ -225,7 +225,7 @@ sis_5511_write(int func, int addr, uint8_t val, void *priv) case 0x60: dev->pci_conf[addr] = val & 0x3e; if ((dev->pci_conf[0x68] & 1) && (val & 2)) { - smi_line = 1; + smi_raise(); dev->pci_conf[0x69] |= 1; } break; diff --git a/src/chipset/sis_5571.c b/src/chipset/sis_5571.c index 3f678d87b..2d9d92c8d 100644 --- a/src/chipset/sis_5571.c +++ b/src/chipset/sis_5571.c @@ -288,7 +288,7 @@ memory_pci_bridge_write(int func, int addr, uint8_t val, void *priv) if ((dev->pci_conf[0x9b] & 1) && !!(val & 2)) { - smi_line = 1; + smi_raise(); dev->pci_conf[0x9d] |= 1; } break; diff --git a/src/chipset/sis_85c496.c b/src/chipset/sis_85c496.c index b900d4443..36d1f2030 100644 --- a/src/chipset/sis_85c496.c +++ b/src/chipset/sis_85c496.c @@ -390,7 +390,7 @@ sis_85c49x_pci_write(int func, int addr, uint8_t val, void *priv) if (dev->pci_conf[0x80] & 0x10) picint(1 << smm_irq[dev->pci_conf[0x81] & 0x03]); else - smi_line = 1; + smi_raise(); smi_block = 1; dev->pci_conf[0xa0] |= 0x10; } diff --git a/src/chipset/sis_85c4xx.c b/src/chipset/sis_85c4xx.c index b705eb32e..508f653e2 100644 --- a/src/chipset/sis_85c4xx.c +++ b/src/chipset/sis_85c4xx.c @@ -104,7 +104,7 @@ sis_85c4xx_sw_smi_out(uint16_t port, uint8_t val, void *priv) if (dev->regs[0x18] & 0x02) { if (dev->regs[0x0b] & 0x10) - smi_line = 1; + smi_raise(); else picint(1 << ((dev->regs[0x0b] & 0x08) ? 15 : 12)); soft_reset_mask = 1; diff --git a/src/chipset/sis_85c50x.c b/src/chipset/sis_85c50x.c index 9d5dddebd..1c46074b1 100644 --- a/src/chipset/sis_85c50x.c +++ b/src/chipset/sis_85c50x.c @@ -176,7 +176,7 @@ sis_85c50x_write(int func, int addr, uint8_t val, void *priv) case 0x60: /* SMI */ if ((dev->pci_conf[0x68] & 0x01) && !(dev->pci_conf[addr] & 0x02) && (val & 0x02)) { dev->pci_conf[0x69] |= 0x01; - smi_line = 1; + smi_raise(); } dev->pci_conf[addr] = val & 0x3e; break; diff --git a/src/chipset/umc_8886.c b/src/chipset/umc_8886.c index 72dc8778b..ba11ba829 100644 --- a/src/chipset/umc_8886.c +++ b/src/chipset/umc_8886.c @@ -232,7 +232,7 @@ umc_8886_write(int func, int addr, uint8_t val, void *priv) if (dev->pci_conf_sb[0][0x46] & 0x40) picint(1 << ((dev->pci_conf_sb[0][0x46] & 0x80) ? 15 : 10)); else - smi_line = 1; + smi_raise(); dev->pci_conf_sb[0][0xa3] |= 0x04; } diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index a415daa6f..720ad7561 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -790,7 +790,7 @@ pipc_fm_write(uint16_t addr, uint8_t val, void *priv) /* Fire NMI/SMI if enabled. */ if (dev->ac97_regs[0][0x48] & 0x01) { if (dev->ac97_regs[0][0x48] & 0x04) - smi_line = 1; + smi_raise(); else nmi_raise(); } diff --git a/src/chipset/via_vt82c49x.c b/src/chipset/via_vt82c49x.c index 7efa76d01..f951741e7 100644 --- a/src/chipset/via_vt82c49x.c +++ b/src/chipset/via_vt82c49x.c @@ -234,7 +234,7 @@ vt82c49x_write(uint16_t addr, uint8_t val, void *priv) case 0x54: if ((dev->regs[0x5b] & 0x80) && (valxor & 0x01) && (val & 0x01)) { if (dev->regs[0x5b] & 0x20) - smi_line = 1; + smi_raise(); else picint(1 << 15); dev->regs[0x55] = 0x01; From e83d1e7ea376383573028111beb6dc03abdcb2c6 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:59:15 +0200 Subject: [PATCH 033/386] OPTi 611. --- src/disk/hdc_ide_opti611.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/disk/hdc_ide_opti611.c b/src/disk/hdc_ide_opti611.c index 2cbf8e1a2..9a6bd9cd4 100644 --- a/src/disk/hdc_ide_opti611.c +++ b/src/disk/hdc_ide_opti611.c @@ -152,7 +152,7 @@ opti611_ide_write(uint16_t addr, uint8_t val, void *priv) uint8_t smibe = (addr & 0x0003); if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | smibe; dev->regs[0x04] = val; } @@ -169,7 +169,7 @@ opti611_ide_writew(uint16_t addr, uint16_t val, void *priv) uint8_t smibe = (addr & 0x0002) | 0x0001; if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | smibe; dev->regs[0x04] = 0x00; } @@ -185,7 +185,7 @@ opti611_ide_writel(uint16_t addr, uint32_t val, void *priv) uint8_t smia2 = (!!(addr & 0x0004)) << 4; if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | 0x0003; dev->regs[0x04] = 0x00; } @@ -202,7 +202,7 @@ opti611_ide_read(uint16_t addr, void *priv) uint8_t smibe = (addr & 0x0003); if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | smibe; dev->regs[0x04] = 0x00; } @@ -229,7 +229,7 @@ opti611_ide_readw(uint16_t addr, void *priv) } if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | smibe; dev->regs[0x04] = 0x00; } @@ -247,7 +247,7 @@ opti611_ide_readl(uint16_t addr, void *priv) uint8_t smia2 = (!!(addr & 0x0004)) << 4; if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | 0x0003; dev->regs[0x04] = 0x00; } From 2fd712d092465aaae7c25ec8734a75e8af87c470 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:12:24 +0200 Subject: [PATCH 034/386] CPU changes. --- src/cpu/386_common.c | 34 ++++++++++++++++++++++++++++++++-- src/cpu/cpu.h | 4 ++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index 1f5bfe3b5..d7544b351 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -22,6 +22,7 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/keyboard.h> +#include <86box/timer.h> #include "386_common.h" #include "x86_flags.h" #include "x86seg.h" @@ -71,6 +72,9 @@ int smm_in_hlt = 0, smi_block = 0; uint32_t addr64, addr64_2; uint32_t addr64a[8], addr64a_2[8]; +static timer_t *cpu_fast_off_timer = NULL; +static double *cpu_fast_off_period = NULL; + #define AMD_SYSCALL_EIP (msr.star & 0xFFFFFFFF) #define AMD_SYSCALL_SB ((msr.star >> 32) & 0xFFFF) @@ -1837,11 +1841,37 @@ sysret(uint32_t fetchdat) } +void +cpu_register_fast_off_handler(void *timer, double *period) +{ + cpu_fast_off_timer = (timer_t *) timer; + cpu_fast_off_period = period; +} + + +void +cpu_fast_off_advance(void) +{ + if (cpu_fast_off_period && (*cpu_fast_off_period != 0.0)) + timer_on_auto(cpu_fast_off_timer, *cpu_fast_off_period); +} + + +void +cpu_fast_off_period_set(uint16_t val, double period) +{ + if (cpu_fast_off_period) { + *cpu_fast_off_period = ((double) (val + 1)) * period; + cpu_fast_off_advance(); + } +} + + void smi_raise(void) { if (is486 && (cpu_fast_off_flags & 0x80000000)) - cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_advance(); smi_line = 1; } @@ -1851,7 +1881,7 @@ void nmi_raise(void) { if (is486 && (cpu_fast_off_flags & 0x20000000)) - cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_advance(); } diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 136a6c834..61fd700d9 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -733,6 +733,10 @@ extern uint8_t do_translate, do_translate2; extern void reset_808x(int hard); +extern void cpu_register_fast_off_handler(void *timer, double *period); +extern void cpu_fast_off_advance(void); +extern void cpu_fast_off_period_set(uint16_t vla, double period); + extern void smi_raise(); extern void nmi_raise(); From c58360df3e3bf779ec47325c15000c62a70c3188 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:21:09 +0200 Subject: [PATCH 035/386] Chipsets. --- src/chipset/intel_420ex.c | 21 +++++++-------------- src/chipset/intel_piix.c | 24 +++++++----------------- src/chipset/intel_sio.c | 23 +++++++---------------- 3 files changed, 21 insertions(+), 47 deletions(-) diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 8c8603efc..1590bc34c 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -316,10 +316,8 @@ i420ex_write(int func, int addr, uint8_t val, void *priv) dev->fast_off_period = PCICLK * 32768.0; break; } - cpu_fast_off_count = dev->regs[0xa8] + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); break; case 0xa2: dev->regs[addr] = val & 0xff; @@ -347,9 +345,7 @@ i420ex_write(int func, int addr, uint8_t val, void *priv) dev->regs[addr] = val & 0xff; cpu_fast_off_val = val; cpu_fast_off_count = val + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); break; } } @@ -422,13 +418,8 @@ i420ex_fast_off_count(void *priv) cpu_fast_off_count--; - if (cpu_fast_off_count == 0) { - smi_raise(); - dev->regs[0xaa] |= 0x20; - cpu_fast_off_count = dev->regs[0xa8] + 1; - } - - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + smi_raise(); + dev->regs[0xaa] |= 0x20; } @@ -513,6 +504,8 @@ i420ex_init(const device_t *info) cpu_fast_off_val = dev->regs[0xa8]; cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_register_fast_off_handler(&dev->fast_off_timer); + dev->apm = device_add(&apm_pci_device); /* APM intercept handler to update 82420EX SMI status on APM SMI. */ io_sethandler(0x00b2, 0x0001, NULL, NULL, NULL, i420ex_apm_out, NULL, NULL, dev); diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index 55002405f..c0f28914b 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -628,10 +628,8 @@ piix_write(int func, int addr, uint8_t val, void *priv) dev->fast_off_period = PCICLK * 32768.0; break; } - cpu_fast_off_count = fregs[0xa8] + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); } break; case 0xa2: @@ -679,9 +677,7 @@ piix_write(int func, int addr, uint8_t val, void *priv) fregs[addr] = val & 0xff; cpu_fast_off_val = val; cpu_fast_off_count = val + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); } break; case 0xaa: @@ -1331,15 +1327,8 @@ piix_fast_off_count(void *priv) { piix_t *dev = (piix_t *) priv; - cpu_fast_off_count--; - - if (cpu_fast_off_count == 0) { - smi_raise(); - dev->regs[0][0xaa] |= 0x20; - cpu_fast_off_count = dev->regs[0][0xa8] + 1; - } - - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + smi_raise(); + dev->regs[0][0xaa] |= 0x20; } @@ -1446,7 +1435,7 @@ piix_speed_changed(void *priv) timer_stop(&dev->fast_off_timer); if (te) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + timer_on_auto(&dev->fast_off_timer, ((double) cpu_fast_off_val + 1) * dev->fast_off_period); } @@ -1510,6 +1499,7 @@ static void if (dev->type < 4) { cpu_fast_off_val = dev->regs[0][0xa8]; cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_register(&dev->fast_off_timer); } else cpu_fast_off_val = cpu_fast_off_count = 0; diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index 75aef516c..8c75e88c2 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -264,10 +264,8 @@ sio_write(int func, int addr, uint8_t val, void *priv) dev->fast_off_period = PCICLK * 32768.0; break; } - cpu_fast_off_count = dev->regs[0xa8] + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); } break; case 0xa2: @@ -306,9 +304,7 @@ sio_write(int func, int addr, uint8_t val, void *priv) dev->regs[addr] = val & 0xff; cpu_fast_off_val = val; cpu_fast_off_count = val + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); break; } } @@ -429,15 +425,8 @@ sio_fast_off_count(void *priv) { sio_t *dev = (sio_t *) priv; - cpu_fast_off_count--; - - if (cpu_fast_off_count == 0) { - smi_raise(); - dev->regs[0xaa] |= 0x20; - cpu_fast_off_count = dev->regs[0xa8] + 1; - } - - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + smi_raise(); + dev->regs[0xaa] |= 0x20; } @@ -513,6 +502,8 @@ sio_init(const device_t *info) if (dev->id == 0x03) { cpu_fast_off_val = dev->regs[0xa8]; cpu_fast_off_count = cpu_fast_off_val + 1; + + cpu_fast_off_register(&dev->fast_off_timer); } else cpu_fast_off_val = cpu_fast_off_count = 0; From a35c4aa67466e464c7ad9bc834c583f473a3fd2e Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:21:21 +0200 Subject: [PATCH 036/386] CPU changes. --- src/cpu/386_common.c | 25 ++++++++++++++++--------- src/cpu/cpu.h | 3 ++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index d7544b351..aa5a813b8 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -73,7 +73,7 @@ uint32_t addr64, addr64_2; uint32_t addr64a[8], addr64a_2[8]; static timer_t *cpu_fast_off_timer = NULL; -static double *cpu_fast_off_period = NULL; +static double cpu_fast_off_period = 0.0; #define AMD_SYSCALL_EIP (msr.star & 0xFFFFFFFF) @@ -1842,28 +1842,35 @@ sysret(uint32_t fetchdat) void -cpu_register_fast_off_handler(void *timer, double *period) +cpu_register_fast_off_handler(void *timer) { cpu_fast_off_timer = (timer_t *) timer; - cpu_fast_off_period = period; } void cpu_fast_off_advance(void) { - if (cpu_fast_off_period && (*cpu_fast_off_period != 0.0)) - timer_on_auto(cpu_fast_off_timer, *cpu_fast_off_period); + timer_disable(cpu_fast_off_timer); + if (cpu_fast_off_period != 0.0) + timer_on_auto(cpu_fast_off_timer, cpu_fast_off_period); } void cpu_fast_off_period_set(uint16_t val, double period) { - if (cpu_fast_off_period) { - *cpu_fast_off_period = ((double) (val + 1)) * period; - cpu_fast_off_advance(); - } + cpu_fast_off_period = ((double) (val + 1)) * period; + cpu_fast_off_advance(); +} + + +void +cpu_fast_off_reset(void) +{ + cpu_register_fast_off_handler(NULL); + cpu_fast_off_period = 0.0; + cpu_fast_off_advance(); } diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 61fd700d9..6d66e1531 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -733,9 +733,10 @@ extern uint8_t do_translate, do_translate2; extern void reset_808x(int hard); -extern void cpu_register_fast_off_handler(void *timer, double *period); +extern void cpu_register_fast_off_handler(void *timer); extern void cpu_fast_off_advance(void); extern void cpu_fast_off_period_set(uint16_t vla, double period); +extern void cpu_fast_off_reset(void); extern void smi_raise(); extern void nmi_raise(); From f4ba136b976026f8bfee17366fe2b922619e79a5 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:22:28 +0200 Subject: [PATCH 037/386] Machine. --- src/machine/machine.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/machine/machine.c b/src/machine/machine.c index 1549ce7c6..00516d8fb 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -105,6 +105,9 @@ machine_init_ex(int m) /* Reset any ISA memory cards. */ isamem_reset(); + + /* Reset the fast off stuff. */ + cpu_fast_off_reset(); } /* All good, boot the machine! */ From 27713f6557c99835be544719550aa68cd2fdbaa3 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:22:41 +0200 Subject: [PATCH 038/386] More CPU. --- src/cpu/386_common.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index aa5a813b8..bef9aa59a 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -1868,6 +1868,9 @@ cpu_fast_off_period_set(uint16_t val, double period) void cpu_fast_off_reset(void) { + if (cpu-fast_off_timer) + timer_disable(cpu_fast_off_timer); + cpu_register_fast_off_handler(NULL); cpu_fast_off_period = 0.0; cpu_fast_off_advance(); From 231afcbe11d3c66252a48e439d6f7070ba564009 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:23:21 +0200 Subject: [PATCH 039/386] PIC. --- src/pic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pic.c b/src/pic.c index 23f99945e..13c13d6df 100644 --- a/src/pic.c +++ b/src/pic.c @@ -223,7 +223,7 @@ find_best_interrupt(pic_t *dev) intr += 8; if (cpu_fast_off_flags & (1u << intr)) - cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_advance(); } return ret; From b97338144e253fc4c2cfe17d484e730077fabe82 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 22:59:49 -0300 Subject: [PATCH 040/386] Jenkins: Allow macOS to make source tarballs --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index cb58e1fd8..b0c865083 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -215,7 +215,7 @@ pipeline { /* Create source tarball. */ try { retry(10) { - node('Linux') { + node('Linux || macOS') { /* Run git clone. */ gitClone(repository[buildBranch], branch[buildBranch]) From a1744ddbd209c54bce97deb62e86a4bc617d38e6 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 23:04:36 -0300 Subject: [PATCH 041/386] Jenkins: Install and use gnutar on macOS for source tarballs --- .ci/build.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index eeb22c9c2..da4169516 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -52,8 +52,20 @@ make_tar() { # Install dependencies. if ! which tar xz > /dev/null 2>&1 then - which apt-get > /dev/null 2>&1 && DEBIAN_FRONTEND=noninteractive sudo apt-get install -y tar xz-utils + if which apt-get > /dev/null 2>&1 + then + sudo apt-get update + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y tar xz-utils + sudo apt-get clean + elif which port > /dev/null 2>&1 + then + sudo port install gnutar xz + fi fi + + # Prefer gnutar on macOS. + local tar_cmd=tar + which gnutar > /dev/null 2>&1 && tar_cmd=gnutar # Determine the best supported compression type. local compression_flag= @@ -80,7 +92,7 @@ make_tar() { # --uid/gid (bsdtar) or even none at all (MSYS2 bsdtar). Account for such # flag differences by checking if they're mentioned on the help text. local ownership_flags= - local tar_help=$(tar --help 2>&1) + local tar_help=$("$tar_cmd" --help 2>&1) if echo $tar_help | grep -q -- --owner then local ownership_flags="--owner=0 --group=0" @@ -90,7 +102,7 @@ make_tar() { fi # Run tar. - tar -c $compression_flag -f "$1$compression_ext" $ownership_flags * + "$tar_cmd" -c $compression_flag -f "$1$compression_ext" $ownership_flags * return $? } From 63e52cb8327651d7e717f2ab36faeb47c33ed441 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 04:06:46 +0200 Subject: [PATCH 042/386] Fixes to cpu/386_common.c. --- src/cpu/386_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index bef9aa59a..ca7888502 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -72,7 +72,7 @@ int smm_in_hlt = 0, smi_block = 0; uint32_t addr64, addr64_2; uint32_t addr64a[8], addr64a_2[8]; -static timer_t *cpu_fast_off_timer = NULL; +static pc_timer_t *cpu_fast_off_timer = NULL; static double cpu_fast_off_period = 0.0; @@ -1844,7 +1844,7 @@ sysret(uint32_t fetchdat) void cpu_register_fast_off_handler(void *timer) { - cpu_fast_off_timer = (timer_t *) timer; + cpu_fast_off_timer = (pc_timer_t *) timer; } @@ -1868,7 +1868,7 @@ cpu_fast_off_period_set(uint16_t val, double period) void cpu_fast_off_reset(void) { - if (cpu-fast_off_timer) + if (cpu_fast_off_timer) timer_disable(cpu_fast_off_timer); cpu_register_fast_off_handler(NULL); From 8a8d7857d36c769a4f220e4bf98806e695e55d7e Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 04:08:13 +0200 Subject: [PATCH 043/386] Two chipset .c files. --- src/chipset/intel_420ex.c | 1 + src/chipset/intel_sio.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 1590bc34c..11c66b833 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -19,6 +19,7 @@ #include #include #include <86box/86box.h> +#include "cpu.h" #include <86box/device.h> #include <86box/io.h> #include <86box/apm.h> diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index 8c75e88c2..10b1b7380 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -18,6 +18,7 @@ #include #include #include <86box/86box.h> +#include "cpu.h" #include <86box/device.h> #include <86box/io.h> #include <86box/apm.h> From dcd7cc904742cd38a195b63ee4b1a66aa3b3aead Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 04:09:49 +0200 Subject: [PATCH 044/386] And more. --- src/chipset/intel_piix.c | 2 +- src/chipset/intel_sio.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index c0f28914b..f8302e854 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -1499,7 +1499,7 @@ static void if (dev->type < 4) { cpu_fast_off_val = dev->regs[0][0xa8]; cpu_fast_off_count = cpu_fast_off_val + 1; - cpu_fast_off_register(&dev->fast_off_timer); + cpu_register_fast_off_handler(&dev->fast_off_timer); } else cpu_fast_off_val = cpu_fast_off_count = 0; diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index 10b1b7380..bbc85662d 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -504,7 +504,7 @@ sio_init(const device_t *info) cpu_fast_off_val = dev->regs[0xa8]; cpu_fast_off_count = cpu_fast_off_val + 1; - cpu_fast_off_register(&dev->fast_off_timer); + cpu_register_fast_off_handler(&dev->fast_off_timer); } else cpu_fast_off_val = cpu_fast_off_count = 0; From 1b9c360bbe2ede16b306d1ea96b53c8425d489f3 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 04:10:54 +0200 Subject: [PATCH 045/386] And Sigma. --- src/video/vid_sigma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/vid_sigma.c b/src/video/vid_sigma.c index e340a7c52..154469317 100644 --- a/src/video/vid_sigma.c +++ b/src/video/vid_sigma.c @@ -245,7 +245,7 @@ sigma_out(uint16_t addr, uint8_t val, void *p) sigma->lastport &= 0x7F; return; case 0x2DC: /* Reset NMI */ -#idef OLD_NMI_BEHAVIOR +#ifdef OLD_NMI_BEHAVIOR nmi = 0; #endif sigma->lastport &= 0x7F; From 0ebf0e0ecea6153d2728b9952bbdc8000e4f067a Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 23:12:27 -0300 Subject: [PATCH 046/386] Jenkins: Fix small typo in tarball script --- .ci/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/build.sh b/.ci/build.sh index da4169516..98dbf3e3f 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -65,7 +65,7 @@ make_tar() { # Prefer gnutar on macOS. local tar_cmd=tar - which gnutar > /dev/null 2>&1 && tar_cmd=gnutar + which gnutar > /dev/null 2>&1 && local tar_cmd=gnutar # Determine the best supported compression type. local compression_flag= From 00b63fe9b8777d9875c585980fbc5fef60a0476e Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 23:17:07 -0300 Subject: [PATCH 047/386] Jenkins: More macOS stuff --- .ci/build.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index 98dbf3e3f..278e252d8 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -59,11 +59,12 @@ make_tar() { sudo apt-get clean elif which port > /dev/null 2>&1 then + sudo port selfupdate sudo port install gnutar xz fi fi - - # Prefer gnutar on macOS. + + # Use MacPorts gnutar (if installed) on macOS. local tar_cmd=tar which gnutar > /dev/null 2>&1 && local tar_cmd=gnutar From 549a8544a0a2b7507c7022d43c363d0746a71a74 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 04:29:19 +0200 Subject: [PATCH 048/386] Rewrote the NVR periodic timer for better performance. --- src/nvr_at.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/nvr_at.c b/src/nvr_at.c index b164d948d..2bf8be383 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -496,6 +496,8 @@ timer_load_count(nvr_t *nvr) int c = nvr->regs[RTC_REGA] & REGA_RS; local_t *local = (local_t *) nvr->data; + timer_disable(&local->rtc_timer); + if ((nvr->regs[RTC_REGA] & 0x70) != 0x20) { local->state = 0; return; @@ -509,9 +511,11 @@ timer_load_count(nvr_t *nvr) break; case 1: case 2: local->count = 1 << (c + 6); + timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); break; default: local->count = 1 << (c - 1); + timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); break; } } @@ -523,20 +527,16 @@ timer_intr(void *priv) nvr_t *nvr = (nvr_t *)priv; local_t *local = (local_t *)nvr->data; - timer_advance_u64(&local->rtc_timer, RTCCONST); - if (local->state == 1) { - if (--local->count == 0) { - timer_load_count(nvr); + timer_load_count(nvr); - nvr->regs[RTC_REGC] |= REGC_PF; - if (nvr->regs[RTC_REGB] & REGB_PIE) { - nvr->regs[RTC_REGC] |= REGC_IRQF; + nvr->regs[RTC_REGC] |= REGC_PF; + if (nvr->regs[RTC_REGB] & REGB_PIE) { + nvr->regs[RTC_REGC] |= REGC_IRQF; - /* Generate an interrupt. */ - if (nvr->irq != -1) - picint(1 << nvr->irq); - } + /* Generate an interrupt. */ + if (nvr->irq != -1) + picint(1 << nvr->irq); } } } @@ -809,6 +809,7 @@ nvr_read(uint16_t addr, void *priv) return(ret); } + /* Secondary NVR write - used by SMC. */ static void nvr_sec_write(uint16_t addr, uint8_t val, void *priv) @@ -824,6 +825,7 @@ nvr_sec_read(uint16_t addr, void *priv) return nvr_read(0x72 + (addr & 1), priv); } + /* Reset the RTC state to 1980/01/01 00:00. */ static void nvr_reset(nvr_t *nvr) @@ -883,8 +885,7 @@ nvr_at_speed_changed(void *priv) nvr_t *nvr = (nvr_t *) priv; local_t *local = (local_t *) nvr->data; - timer_disable(&local->rtc_timer); - timer_set_delay_u64(&local->rtc_timer, RTCCONST); + timer_load_count(nvr); timer_disable(&local->update_timer); if (local->ecount > 0ULL) @@ -1081,7 +1082,6 @@ nvr_at_init(const device_t *info) nvr->regs[RTC_REGA] = (nvr->regs[RTC_REGA] & 0x8f) | 0x20; nvr_at_reset(nvr); timer_load_count(nvr); - timer_set_delay_u64(&local->rtc_timer, RTCCONST); /* Set up the I/O handler for this device. */ io_sethandler(0x0070, 2, From efdf003272097719a698e703391d8d8cbad0b877 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 23:43:00 -0300 Subject: [PATCH 049/386] Jenkins: Better document some stuff --- .ci/Jenkinsfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index b0c865083..61330031a 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -113,9 +113,9 @@ def gitClone(repository, branch) { } else if (env.GIT_COMMIT != scmVars.GIT_COMMIT) { /* Checkout the commit read from the polling log. */ if (isUnix()) - sh returnStatus: true, script: "git checkout ${env.GIT_COMMIT}" + sh(returnStatus: true, script: "git checkout ${env.GIT_COMMIT}") else - bat returnStatus: true, script: "git checkout ${env.GIT_COMMIT}" + bat(returnStatus: true, script: "git checkout ${env.GIT_COMMIT}") } println "[-] Using git commit [${env.GIT_COMMIT}]" @@ -173,8 +173,10 @@ pipeline { steps { script { - /* Extract the polled commit from the polling log, so that git checkout can be used - to avoid JENKINS-20518 race conditions caused by two pushes too close together. */ + /* Extract the polled commit from the polling log, so that git checkout + can be used to avoid JENKINS-20518 race conditions caused by the + webhook being triggered more than once in a short period of time. + This is a backup strategy for FilterProxy's webhook queuing. */ node('master') { /* must run on master node to read polling log */ /* Ignore exceptions as this is not really critical. */ try { From 548e8b360abe43bee3169fc21c35b4c2377034b3 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 16 Jul 2022 12:57:35 +0600 Subject: [PATCH 050/386] qt: Make renderer widget resizable only once --- src/qt/qt_mainwindow.cpp | 8 +++++--- src/qt/qt_mainwindow.hpp | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 72876c61c..0725d21a4 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -229,7 +229,10 @@ MainWindow::MainWindow(QWidget *parent) : }); connect(this, &MainWindow::resizeContents, this, [this](int w, int h) { - ui->stackedWidget->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + if (shownonce) { + if (resizableonce == false) ui->stackedWidget->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + resizableonce = true; + } if (!QApplication::platformName().contains("eglfs") && vid_resize != 1) { w = (w / (!dpi_scale ? util::screenOfWidget(this)->devicePixelRatio() : 1.)); @@ -558,7 +561,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { if (renderers[i]) { monitor_settings[i].mon_window_w = renderers[i]->geometry().width(); monitor_settings[i].mon_window_h = renderers[i]->geometry().height(); - if (!QApplication::platformName().contains("wayland")) continue; + if (QApplication::platformName().contains("wayland")) continue; monitor_settings[i].mon_window_x = renderers[i]->geometry().x(); monitor_settings[i].mon_window_y = renderers[i]->geometry().y(); } @@ -582,7 +585,6 @@ void MainWindow::initRendererMonitorSlot(int monitor_index) auto& secondaryRenderer = this->renderers[monitor_index]; secondaryRenderer.reset(new RendererStack(nullptr, monitor_index)); if (secondaryRenderer) { - connect(this, &MainWindow::pollMouse, secondaryRenderer.get(), &RendererStack::mousePoll, Qt::DirectConnection); connect(secondaryRenderer.get(), &RendererStack::rendererChanged, this, [this, monitor_index] { this->renderers[monitor_index]->show(); diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index f0fd3ba6a..49300e72b 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -141,6 +141,7 @@ private: /* If main window should send keyboard input */ bool send_keyboard_input = true; bool shownonce = false; + bool resizableonce = false; friend class SpecifyDimensions; friend class ProgSettings; From 7beec38ed3624c4bf0a00caa8b7bc22b00efa5f1 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 16 Jul 2022 12:57:54 +0600 Subject: [PATCH 051/386] qt: Fix mouse polling --- src/qt/qt_rendererstack.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index 795c31fe7..d93bc802e 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -34,6 +34,7 @@ #include "evdev_mouse.hpp" +#include #include #include @@ -53,8 +54,8 @@ double mouse_sensitivity = 1.0; } struct mouseinputdata { - int deltax, deltay, deltaz; - int mousebuttons; + atomic_int deltax, deltay, deltaz; + atomic_int mousebuttons; }; static mouseinputdata mousedata; @@ -145,7 +146,7 @@ int ignoreNextMouseEvent = 1; void RendererStack::mouseReleaseEvent(QMouseEvent *event) { - if (this->geometry().contains(event->pos()) && event->button() == Qt::LeftButton && !mouse_capture && (isMouseDown & 1)) { + if (this->geometry().contains(event->pos()) && event->button() == Qt::LeftButton && !mouse_capture && (isMouseDown & 1) && mouse_get_buttons() != 0) { plat_mouse_capture(1); this->setCursor(Qt::BlankCursor); if (!ignoreNextMouseEvent) @@ -164,6 +165,7 @@ RendererStack::mouseReleaseEvent(QMouseEvent *event) } isMouseDown &= ~1; } + void RendererStack::mousePressEvent(QMouseEvent *event) { @@ -173,6 +175,7 @@ RendererStack::mousePressEvent(QMouseEvent *event) } event->accept(); } + void RendererStack::wheelEvent(QWheelEvent *event) { From 1b8e50e4da0df10112ab57a50b388a8d69ee3791 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Sat, 16 Jul 2022 20:53:59 +0200 Subject: [PATCH 052/386] Revert to the old NMI way in the AudioPCI code. --- src/sound/snd_audiopci.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index fe00038c7..4791be6a0 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -306,9 +306,7 @@ es1371_reset(void *p) es1371_t *dev = (es1371_t *) p; int i; -#ifdef OLD_NMI_BEHAVIOR nmi = 0; -#endif /* Interrupt/Chip Select Control Register, Address 00H Addressable as byte, word, longword */ From d630bba26e22a6124a6836692314b8360486bd4f Mon Sep 17 00:00:00 2001 From: TC1995 Date: Sat, 16 Jul 2022 22:04:45 +0200 Subject: [PATCH 053/386] Not only AudioPCI, revert the NMI way where applicable (ali1489, viapipc, amstrad and sigma). --- src/chipset/ali1489.c | 2 -- src/chipset/via_pipc.c | 2 -- src/machine/m_amstrad.c | 2 -- src/video/vid_sigma.c | 2 -- 4 files changed, 8 deletions(-) diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index 921c7d082..da6ff39cc 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -197,9 +197,7 @@ ali1489_defaults(ali1489_t *dev) picintc(1 << 10); picintc(1 << 15); -#ifdef OLD_NMI_BEHAVIOR nmi = 0; -#endif smi_line = 0; in_smm = 0; diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 720ad7561..bcb54130f 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -728,10 +728,8 @@ pipc_fmnmi_read(uint16_t addr, void *priv) if (dev->ac97_regs[0][0x48] & 0x01) { if (dev->ac97_regs[0][0x48] & 0x04) smi_line = 0; -#ifdef OLD_NMI_BEHAVIOR else nmi = 0; -#endif } #endif diff --git a/src/machine/m_amstrad.c b/src/machine/m_amstrad.c index cac5a29d2..baf78d071 100644 --- a/src/machine/m_amstrad.c +++ b/src/machine/m_amstrad.c @@ -1068,9 +1068,7 @@ vid_in_200(uint16_t addr, void *priv) case 0x03dd: ret = vid->crtc_index; /* Read NMI reason */ vid->crtc_index &= 0x1f; /* Reset NMI reason */ -#ifdef OLD_NMI_BEHAVIOR nmi = 0; /* And reset NMI flag */ -#endif return(ret); case 0x03de: diff --git a/src/video/vid_sigma.c b/src/video/vid_sigma.c index 154469317..73a9363e8 100644 --- a/src/video/vid_sigma.c +++ b/src/video/vid_sigma.c @@ -245,9 +245,7 @@ sigma_out(uint16_t addr, uint8_t val, void *p) sigma->lastport &= 0x7F; return; case 0x2DC: /* Reset NMI */ -#ifdef OLD_NMI_BEHAVIOR nmi = 0; -#endif sigma->lastport &= 0x7F; return; case 0x2DD: /* Page in RAM at 0xC1800 */ From 39145e7cc660ae53ac394236d421a4a7b2f013b2 Mon Sep 17 00:00:00 2001 From: GetDizzy Date: Sat, 16 Jul 2022 16:50:41 -0400 Subject: [PATCH 054/386] Set default IRQ for NE2000 to 3 Increases compatibility with Windows 9x and other operating systems that have a limited selection of IRQs for this device (usually IRQs <= 9). --- src/network/net_ne2000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/net_ne2000.c b/src/network/net_ne2000.c index 5c0a7ba61..4a8d68393 100644 --- a/src/network/net_ne2000.c +++ b/src/network/net_ne2000.c @@ -1211,7 +1211,7 @@ static const device_config_t ne2000_config[] = { .description = "IRQ", .type = CONFIG_SELECTION, .default_string = "", - .default_int = 10, + .default_int = 3, .file_filter = "", .spinner = { 0 }, .selection = { From c89ce886f9b45582d5cd9de3d5b76be03e2fa405 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 02:17:16 +0200 Subject: [PATCH 055/386] Fixed warnings in config.c. --- src/config.c | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/config.c b/src/config.c index eea247e3f..9d2ad1a63 100644 --- a/src/config.c +++ b/src/config.c @@ -587,11 +587,9 @@ load_general(void) confirm_exit = config_get_int(cat, "confirm_exit", 1); confirm_save = config_get_int(cat, "confirm_save", 1); - p = config_get_string(cat, "language", NULL); - if (p != NULL) - { - lang_id = plat_language_code(p); - } + p = config_get_string(cat, "language", NULL); + if (p != NULL) + lang_id = plat_language_code(p); mouse_sensitivity = config_get_double(cat, "mouse_sensitivity", 1.0); if (mouse_sensitivity < 0.5) @@ -599,11 +597,11 @@ load_general(void) else if (mouse_sensitivity > 2.0) mouse_sensitivity = 2.0; - p = config_get_string(cat, "iconset", NULL); - if (p != NULL) - strcpy(icon_set, p); - else - strcpy(icon_set, ""); + p = config_get_string(cat, "iconset", NULL); + if (p != NULL) + strcpy(icon_set, p); + else + strcpy(icon_set, ""); enable_discord = !!config_get_int(cat, "enable_discord", 0); @@ -2224,7 +2222,7 @@ static void save_general(void) { char *cat = "General"; - char temp[512]; + char temp[512], buffer[512] = {0}; char *va_name; @@ -2233,11 +2231,10 @@ save_general(void) config_delete_var(cat, "vid_resize"); va_name = plat_vidapi_name(vid_api); - if (!strcmp(va_name, "default")) { + if (!strcmp(va_name, "default")) config_delete_var(cat, "vid_renderer"); - } else { + else config_set_string(cat, "vid_renderer", va_name); - } if (video_fullscreen_scale == 0) config_delete_var(cat, "video_fullscreen_scale"); @@ -2304,9 +2301,8 @@ save_general(void) config_set_int(cat, "window_remember", window_remember); else config_delete_var(cat, "window_remember"); - } else { + } else config_delete_var(cat, "window_remember"); - } if (vid_resize & 2) { sprintf(temp, "%ix%i", fixed_size_x, fixed_size_y); @@ -2356,17 +2352,15 @@ save_general(void) if (lang_id == DEFAULT_LANGUAGE) config_delete_var(cat, "language"); - else - { - char buffer[512] = {0}; - plat_language_code_r(lang_id, buffer, 511); - config_set_string(cat, "language", buffer); - } + else { + plat_language_code_r(lang_id, buffer, 511); + config_set_string(cat, "language", buffer); + } - if (!strcmp(icon_set, "")) - config_delete_var(cat, "iconset"); - else - config_set_string(cat, "iconset", icon_set); + if (!strcmp(icon_set, "")) + config_delete_var(cat, "iconset"); + else + config_set_string(cat, "iconset", icon_set); if (enable_discord) config_set_int(cat, "enable_discord", enable_discord); From 8bf4b6c0ce3715821d78be2f41d12b8695855ff2 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 02:26:26 +0200 Subject: [PATCH 056/386] Clean-ups and warning fixes in video/video.c. --- src/video/video.c | 74 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/src/video/video.c b/src/video/video.c index a481a1d86..1bfb148a3 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -76,35 +76,30 @@ #include -volatile int screenshots = 0; -//bitmap_t *buffer32 = NULL; -uint8_t fontdat[2048][8]; /* IBM CGA font */ -uint8_t fontdatm[2048][16]; /* IBM MDA font */ -uint8_t fontdatw[512][32]; /* Wyse700 font */ -uint8_t fontdat8x12[256][16]; /* MDSI Genius font */ -uint8_t fontdat12x18[256][36]; /* IM1024 font */ -dbcs_font_t *fontdatksc5601 = NULL; /* Korean KSC-5601 font */ -dbcs_font_t *fontdatksc5601_user = NULL; /* Korean KSC-5601 user defined font */ -int herc_blend = 0; -uint32_t *video_6to8 = NULL, - *video_8togs = NULL, - *video_8to32 = NULL, - *video_15to32 = NULL, - *video_16to32 = NULL; -int frames = 0; -int fullchange = 0; -uint8_t edatlookup[4][4]; -static int video_force_resize; -int video_grayscale = 0; -int video_graytype = 0; -static int vid_type; -static const video_timings_t *vid_timings; -static uint32_t cga_2_table[16]; -static uint8_t thread_run = 0; -monitor_t monitors[MONITORS_NUM]; -monitor_settings_t monitor_settings[MONITORS_NUM]; -atomic_bool doresize_monitors[MONITORS_NUM]; -int monitor_index_global = 0; +volatile int screenshots = 0; +uint8_t edatlookup[4][4]; +uint8_t fontdat[2048][8]; /* IBM CGA font */ +uint8_t fontdatm[2048][16]; /* IBM MDA font */ +uint8_t fontdatw[512][32]; /* Wyse700 font */ +uint8_t fontdat8x12[256][16]; /* MDSI Genius font */ +uint8_t fontdat12x18[256][36]; /* IM1024 font */ +dbcs_font_t *fontdatksc5601 = NULL; /* Korean KSC-5601 font */ +dbcs_font_t *fontdatksc5601_user = NULL; /* Korean KSC-5601 user defined font */ +int herc_blend = 0; +int frames = 0; +int fullchange = 0; +int video_grayscale = 0; +int video_graytype = 0; +int monitor_index_global = 0; +uint32_t *video_6to8 = NULL, + *video_8togs = NULL, + *video_8to32 = NULL, + *video_15to32 = NULL, + *video_16to32 = NULL; +monitor_t monitors[MONITORS_NUM]; +monitor_settings_t monitor_settings[MONITORS_NUM]; +atomic_bool doresize_monitors[MONITORS_NUM]; + #ifdef _WIN32 void * __cdecl (*video_copy)(void *_Dst, const void *_Src, size_t _Size) = memcpy; @@ -241,18 +236,21 @@ const uint32_t shade[5][256] = }; -static struct blit_data_struct { +typedef struct blit_data_struct { int x, y, w, h; int busy; int buffer_in_use; int thread_run; - int monitor_index; + int monitor_index; thread_t *blit_thread; event_t *wake_blit_thread; event_t *blit_complete; event_t *buffer_not_in_use; -} blit_data; +} blit_data_t; + + +static uint32_t cga_2_table[16]; static void (*blit_func)(int x, int y, int w, int h, int monitor_index); @@ -288,7 +286,7 @@ video_setblit(void(*blit)(int,int,int,int,int)) void video_blit_complete_monitor(int monitor_index) { - struct blit_data_struct* blit_data_ptr = monitors[monitor_index].mon_blit_data_ptr; + blit_data_t* blit_data_ptr = monitors[monitor_index].mon_blit_data_ptr; blit_data_ptr->buffer_in_use = 0; thread_set_event(blit_data_ptr->buffer_not_in_use); @@ -298,7 +296,7 @@ video_blit_complete_monitor(int monitor_index) void video_wait_for_blit_monitor(int monitor_index) { - struct blit_data_struct* blit_data_ptr = monitors[monitor_index].mon_blit_data_ptr; + blit_data_t* blit_data_ptr = monitors[monitor_index].mon_blit_data_ptr; while (blit_data_ptr->busy) thread_wait_event(blit_data_ptr->blit_complete, -1); @@ -309,7 +307,7 @@ video_wait_for_blit_monitor(int monitor_index) void video_wait_for_buffer_monitor(int monitor_index) { - struct blit_data_struct* blit_data_ptr = monitors[monitor_index].mon_blit_data_ptr; + blit_data_t* blit_data_ptr = monitors[monitor_index].mon_blit_data_ptr; while (blit_data_ptr->buffer_in_use) thread_wait_event(blit_data_ptr->buffer_not_in_use, -1); @@ -328,7 +326,7 @@ video_take_screenshot_monitor(const char *fn, uint32_t *buf, int start_x, int st png_bytep *b_rgb = NULL; FILE *fp = NULL; uint32_t temp = 0x00000000; - struct blit_data_struct* blit_data_ptr = monitors[monitor_index].mon_blit_data_ptr; + blit_data_t* blit_data_ptr = monitors[monitor_index].mon_blit_data_ptr; /* create file */ fp = plat_fopen((char *) fn, (char *) "wb"); @@ -460,7 +458,7 @@ video_transform_copy(void *__restrict _Dst, const void *__restrict _Src, size_t static void blit_thread(void *param) { - struct blit_data_struct* data = param; + blit_data_t* data = param; while (data->thread_run) { thread_wait_event(data->wake_blit_thread, -1); thread_reset_event(data->wake_blit_thread); @@ -870,7 +868,7 @@ video_monitor_init(int index) monitors[index].mon_bpp = 8; monitors[index].mon_changeframecount = 2; monitors[index].target_buffer = create_bitmap(2048, 2048); - monitors[index].mon_blit_data_ptr = calloc(1, sizeof(struct blit_data_struct)); + monitors[index].mon_blit_data_ptr = calloc(1, sizeof(blit_data_t)); monitors[index].mon_blit_data_ptr->wake_blit_thread = thread_create_event(); monitors[index].mon_blit_data_ptr->blit_complete = thread_create_event(); monitors[index].mon_blit_data_ptr->buffer_not_in_use = thread_create_event(); From f05ec1f872cefac4bc2c6d6fabc31009dbfff5cd Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 02:32:31 +0200 Subject: [PATCH 057/386] Fixed warnings in 86box.c. --- src/86box.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/86box.c b/src/86box.c index 7565a7af7..805cc60bf 100644 --- a/src/86box.c +++ b/src/86box.c @@ -409,8 +409,10 @@ pc_init(int argc, char *argv[]) char temp[2048]; struct tm *info; time_t now; - int c; - int ng = 0, lvmp = 0; + int c, lvmp = 0; +#ifdef ENABLE_NG + int ng = 0; +#endif #ifdef _WIN32 uint32_t *uid, *shwnd; #endif @@ -492,12 +494,14 @@ usage: !strcasecmp(argv[c], "-D")) { force_debug = 1; #endif +#ifdef ENABLE_NG } else if (!strcasecmp(argv[c], "--nographic") || !strcasecmp(argv[c], "-E")) { /* Currently does nothing, but if/when we implement a built-in manager, it's going to force the manager not to run, allowing the old usage without parameter. */ ng = 1; +#endif } else if (!strcasecmp(argv[c], "--fullscreen") || !strcasecmp(argv[c], "-F")) { start_in_fullscreen = 1; @@ -1263,8 +1267,6 @@ pc_onesec(void) void set_screen_size_monitor(int x, int y, int monitor_index) { - int owsx = monitors[monitor_index].mon_scrnsz_x; - int owsy = monitors[monitor_index].mon_scrnsz_y; int temp_overscan_x = monitors[monitor_index].mon_overscan_x; int temp_overscan_y = monitors[monitor_index].mon_overscan_y; double dx, dy, dtx, dty; From 1b56e118becbd20230275d151b185b6ebe82456f Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 15:12:37 +0200 Subject: [PATCH 058/386] Back to IRQ 10. --- src/network/net_ne2000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/net_ne2000.c b/src/network/net_ne2000.c index 4a8d68393..5c0a7ba61 100644 --- a/src/network/net_ne2000.c +++ b/src/network/net_ne2000.c @@ -1211,7 +1211,7 @@ static const device_config_t ne2000_config[] = { .description = "IRQ", .type = CONFIG_SELECTION, .default_string = "", - .default_int = 3, + .default_int = 10, .file_filter = "", .spinner = { 0 }, .selection = { From 3ce22ca61d27d172e67afded0c39361f77d977d1 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 18 Jul 2022 21:46:22 +0600 Subject: [PATCH 059/386] qt: don't enable blitting too early --- src/qt/qt_rendererstack.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index d93bc802e..fab20b5b7 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -314,7 +314,6 @@ RendererStack::createRenderer(Renderer renderer) connect(hw, &OpenGLRenderer::errorInitializing, [=]() { /* Renderer not could initialize, fallback to software. */ imagebufs = {}; - endblit(); QTimer::singleShot(0, this, [this]() { switchRenderer(Renderer::Software); }); }); current.reset(this->createWindowContainer(hw, this)); @@ -332,7 +331,6 @@ RendererStack::createRenderer(Renderer renderer) msgBox->setAttribute(Qt::WA_DeleteOnClose); msgBox->show(); imagebufs = {}; - endblit(); QTimer::singleShot(0, this, [this]() { switchRenderer(Renderer::Software); }); }); connect(hw, &D3D9Renderer::initialized, this, [this]() @@ -356,7 +354,6 @@ RendererStack::createRenderer(Renderer renderer) msgBox->setAttribute(Qt::WA_DeleteOnClose); msgBox->show(); imagebufs = {}; - endblit(); QTimer::singleShot(0, this, [this]() { switchRenderer(Renderer::Software); }); current.reset(nullptr); break; @@ -375,7 +372,6 @@ RendererStack::createRenderer(Renderer renderer) msgBox->setAttribute(Qt::WA_DeleteOnClose); msgBox->show(); imagebufs = {}; - endblit(); QTimer::singleShot(0, this, [this]() { switchRenderer(Renderer::Software); }); }); current.reset(this->createWindowContainer(hw, this)); From 711e26207ae7002bcd8389359024d3143bdced61 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Mon, 18 Jul 2022 15:22:33 -0400 Subject: [PATCH 060/386] Size the QListView according to minimum width instead of maximum --- src/qt/qt_settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qt_settings.cpp b/src/qt/qt_settings.cpp index ea4a86373..290b95982 100644 --- a/src/qt/qt_settings.cpp +++ b/src/qt/qt_settings.cpp @@ -143,7 +143,7 @@ Settings::Settings(QWidget *parent) : ui->stackedWidget->setCurrentIndex(current.row()); }); - ui->listView->setMaximumWidth(ui->listView->sizeHintForColumn(0) + qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent)); + ui->listView->setMinimumWidth(ui->listView->sizeHintForColumn(0) + qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent)); Settings::settings = this; } From 95cd9b68af4ce94b33c0aa5b9beb8fd5fc0ee9cd Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:32:11 +0200 Subject: [PATCH 061/386] The NVR no longer raises IRQ's if the IRQF flag is set. --- src/nvr_at.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/nvr_at.c b/src/nvr_at.c index 2bf8be383..fc5ae4bde 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -466,11 +466,11 @@ timer_update(void *priv) check_alarm_via(nvr, RTC_MONTH, RTC_ALMONT_SIS)*/) { nvr->regs[RTC_REGC] |= REGC_AF; if (nvr->regs[RTC_REGB] & REGB_AIE) { - nvr->regs[RTC_REGC] |= REGC_IRQF; - /* Generate an interrupt. */ - if (nvr->irq != -1) + if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) picint(1 << nvr->irq); + + nvr->regs[RTC_REGC] |= REGC_IRQF; } } @@ -480,11 +480,11 @@ timer_update(void *priv) */ nvr->regs[RTC_REGC] |= REGC_UF; if (nvr->regs[RTC_REGB] & REGB_UIE) { - nvr->regs[RTC_REGC] |= REGC_IRQF; - /* Generate an interrupt. */ - if (nvr->irq != -1) + if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) picint(1 << nvr->irq); + + nvr->regs[RTC_REGC] |= REGC_IRQF; } } } @@ -532,11 +532,11 @@ timer_intr(void *priv) nvr->regs[RTC_REGC] |= REGC_PF; if (nvr->regs[RTC_REGB] & REGB_PIE) { - nvr->regs[RTC_REGC] |= REGC_IRQF; - /* Generate an interrupt. */ - if (nvr->irq != -1) + if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) picint(1 << nvr->irq); + + nvr->regs[RTC_REGC] |= REGC_IRQF; } } } From 8575947a577b54263fde1f04070020a0b558ff01 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:32:59 +0200 Subject: [PATCH 062/386] Some config.c indentation fixes. --- src/config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index 9d2ad1a63..54cb60f40 100644 --- a/src/config.c +++ b/src/config.c @@ -593,9 +593,9 @@ load_general(void) mouse_sensitivity = config_get_double(cat, "mouse_sensitivity", 1.0); if (mouse_sensitivity < 0.5) - mouse_sensitivity = 0.5; + mouse_sensitivity = 0.5; else if (mouse_sensitivity > 2.0) - mouse_sensitivity = 2.0; + mouse_sensitivity = 2.0; p = config_get_string(cat, "iconset", NULL); if (p != NULL) From 52f8d68fb0aef7f5b42408951ad0e5148a386764 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:36:11 +0200 Subject: [PATCH 063/386] ALi M6117 DRAM sizing implementation. --- src/chipset/ali6117.c | 107 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/src/chipset/ali6117.c b/src/chipset/ali6117.c index 815085ee8..d33387b9f 100644 --- a/src/chipset/ali6117.c +++ b/src/chipset/ali6117.c @@ -41,12 +41,49 @@ typedef struct ali6117_t uint32_t local; /* Main registers (port 22h/23h) */ - uint8_t unlocked; + uint8_t unlocked, mode; uint8_t reg_offset; uint8_t regs[256]; } ali6117_t; +/* Total size, Bank 0 size, Bank 1 size, Bank 2 size, Bank 3 size. */ +static uint32_t ali6117_modes[32][5] = { + { 1024, 512, 512, 0, 0 }, + { 2048, 512, 512, 512, 512 }, + { 3072, 512, 512, 2048, 0 }, + { 5120, 512, 512, 2048, 2048 }, + { 9216, 512, 512, 8192, 0 }, + { 1024, 1024, 0, 0, 0 }, + { 2048, 1024, 1024, 0, 0 }, + { 4096, 1024, 1024, 2048, 0 }, + { 6144, 1024, 1024, 2048, 2048 }, + { 10240, 1024, 1024, 8192, 0 }, + { 18432, 1024, 1024, 8192, 8192 }, + { 3072, 1024, 2048, 0, 0 }, + { 5120, 1024, 2048, 2048, 0 }, + { 9216, 1024, 8192, 0, 0 }, + { 2048, 2048, 0, 0, 0 }, + { 4096, 2048, 2048, 0, 0 }, + { 6144, 2048, 2048, 2048, 0 }, + { 8192, 2048, 2048, 2048, 2048 }, + { 12288, 2048, 2048, 8192, 0 }, + { 20480, 2048, 2048, 8192, 8192 }, + { 10240, 2048, 8192, 0, 0 }, + { 18432, 2048, 8192, 8192, 0 }, + { 26624, 2048, 8192, 8192, 8192 }, + { 4096, 4096, 0, 0, 0 }, + { 8192, 4096, 4096, 0, 0 }, + { 24576, 4096, 4096, 8192, 8192 }, + { 12288, 4096, 8192, 0, 0 }, + { 8192, 8192, 0, 0, 0 }, + { 16384, 8192, 8192, 0, 0 }, + { 24576, 8192, 8192, 8192, 0 }, + { 32768, 8192, 8192, 8192, 8192 }, + { 65536, 32768, 32768, 0, 0 } +}; + + #ifdef ENABLE_ALI6117_LOG int ali6117_do_log = ENABLE_ALI6117_LOG; @@ -113,10 +150,56 @@ ali6117_recalcmapping(ali6117_t *dev) } +static void +ali6117_bank_recalc(ali6117_t *dev) +{ + int i; + uint32_t bank, addr; + + for (i = 0x00000000; i < (mem_size << 10); i += 4096) { + if ((i >= 0x000a0000) && (i < 0x00100000)) + continue; + + if (!is6117 && (i >= 0x00f00000) && (i < 0x01000000)) + continue; + + if (is6117 && (i >= 0x03f00000) && (i < 0x04000000)) + continue; + + switch (dev->regs[0x10] & 0xf8) { + case 0xe8: + bank = (i >> 12) & 3; + addr = (i & 0xfff) | ((i >> 14) << 12); + ali6117_log("E8 (%08X): Bank %i, address %08X vs. bank size %08X\n", i, bank, addr, ali6117_modes[dev->mode][bank + 1] * 1024); + if (addr < (ali6117_modes[dev->mode][bank + 1] * 1024)) + mem_set_mem_state_both(i, 4096, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + else + mem_set_mem_state_both(i, 4096, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + break; + case 0xf8: + bank = (i >> 12) & 1; + addr = (i & 0xfff) | ((i >> 13) << 12); + ali6117_log("F8 (%08X): Bank %i, address %08X vs. bank size %08X\n", i, bank, addr, ali6117_modes[dev->mode][bank + 1] * 1024); + if (addr < (ali6117_modes[dev->mode][bank + 1] * 1024)) + mem_set_mem_state_both(i, 4096, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + else + mem_set_mem_state_both(i, 4096, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + break; + default: + mem_set_mem_state_both(i, 4096, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + break; + } + } + + flushmmucache(); +} + + static void ali6117_reg_write(uint16_t addr, uint8_t val, void *priv) { ali6117_t *dev = (ali6117_t *) priv; + int i; ali6117_log("ALI6117: reg_write(%04X, %02X)\n", addr, val); @@ -135,6 +218,14 @@ ali6117_reg_write(uint16_t addr, uint8_t val, void *priv) case 0x10: refresh_at_enable = !(val & 0x02) || !!(dev->regs[0x20] & 0x80); + dev->regs[dev->reg_offset] = val; + + if (val & 0x04) + mem_set_mem_state_both(0x00f00000, 0x00100000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + else + mem_set_mem_state_both(0x00f00000, 0x00100000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + + ali6117_bank_recalc(dev); break; case 0x12: @@ -326,6 +417,10 @@ ali6117_reset(void *priv) cpu_set_isa_speed(7159091); refresh_at_enable = 1; + + /* On-board memory 15-16M is enabled by default. */ + mem_set_mem_state_both(0x00f00000, 0x00100000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + ali6117_bank_recalc(dev); } @@ -357,6 +452,8 @@ ali6117_close(void *priv) static void * ali6117_init(const device_t *info) { + int i, last_match = 0; + ali6117_log("ALI6117: init()\n"); ali6117_t *dev = (ali6117_t *) malloc(sizeof(ali6117_t)); @@ -367,6 +464,14 @@ ali6117_init(const device_t *info) device_add(&ide_isa_device); ali6117_setup(dev); + + for (i = 31; i >= 0; i--) { + if ((mem_size >= ali6117_modes[i][0]) && (ali6117_modes[i][0] > last_match)) { + last_match = ali6117_modes[i][0]; + dev->mode = i; + } + } + ali6117_reset(dev); if (!(dev->local & 0x08)) From 645c4e69022d6c73aa7a4dc5c9a805d0fb6bb690 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:38:06 +0200 Subject: [PATCH 064/386] ALi M6117-related CPU fixes. --- src/cpu/386_common.c | 2 ++ src/cpu/cpu.c | 4 +++- src/cpu/cpu.h | 2 +- src/cpu/x86.c | 2 ++ src/cpu/x86seg.c | 5 ++++- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index ca7888502..546da2aa3 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -1173,6 +1173,8 @@ enter_smm(int in_hlt) if (unmask_a20_in_smm) { old_rammask = rammask; rammask = cpu_16bitbus ? 0xFFFFFF : 0xFFFFFFFF; + if (is6117) + rammask |= 0x3000000; flushmmucache(); } diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index b416206f6..a880ef1a5 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -114,7 +114,7 @@ int isa_cycles, cpu_inited, cpu_override, cpu_effective, cpu_multi, cpu_16bitbus, cpu_64bitbus, cpu_busspeed, cpu_cyrix_alignment, CPUID, - is286, is386, is486 = 1, + is286, is386, is6117, is486 = 1, cpu_isintel, cpu_iscyrix, hascache, isibm486, israpidcad, is_vpc, is_am486, is_am486dxl, is_pentium, is_k5, is_k6, is_p6, is_cxsmm, hasfpu, @@ -382,6 +382,8 @@ cpu_set(void) is_am486 = (cpu_s->cpu_type == CPU_ENH_Am486DX); is_am486dxl = (cpu_s->cpu_type == CPU_Am486DXL); + is6117 = !strcmp(cpu_f->manufacturer, "ALi"); + cpu_isintel = !strcmp(cpu_f->manufacturer, "Intel"); cpu_iscyrix = !strcmp(cpu_f->manufacturer, "Cyrix") || !strcmp(cpu_f->manufacturer, "ST"); diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 6d66e1531..b6998162f 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -495,7 +495,7 @@ extern double fpu_multi; extern int cpu_cyrix_alignment; /*Cyrix 5x86/6x86 only has data misalignment penalties when crossing 8-byte boundaries*/ -extern int is8086, is286, is386, is486; +extern int is8086, is286, is386, is6117, is486; extern int is_am486, is_am486dxl, is_pentium, is_k5, is_k6, is_p6, is_cxsmm; extern int hascache; extern int isibm486; diff --git a/src/cpu/x86.c b/src/cpu/x86.c index e8370a5b5..bf5b168db 100644 --- a/src/cpu/x86.c +++ b/src/cpu/x86.c @@ -272,6 +272,8 @@ reset_common(int hard) loadcs(0xF000); cpu_state.pc = 0xFFF0; rammask = cpu_16bitbus ? 0xFFFFFF : 0xFFFFFFFF; + if (is6117) + rammask |= 0x03000000; } idt.base = 0; cpu_state.flags = 2; diff --git a/src/cpu/x86seg.c b/src/cpu/x86seg.c index 67cf04222..e103f0247 100644 --- a/src/cpu/x86seg.c +++ b/src/cpu/x86seg.c @@ -83,7 +83,10 @@ seg_reset(x86seg *s) if (s == &cpu_state.seg_cs) { if (!cpu_inited) fatal("seg_reset(&cpu_state.seg.cs) without an initialized CPU\n"); - s->base = is286 ? (cpu_16bitbus ? 0x00ff0000 : 0xffff0000) : 0x000ffff0; + if (is6117) + s->base = 0x03ff0000; + else + s->base = is286 ? (cpu_16bitbus ? 0x00ff0000 : 0xffff0000) : 0x000ffff0; s->seg = is286 ? 0xf000 : 0xffff; } else { s->base = 0; From 37893cd8abd955e85fb5836dba3b5cdaeff4c08d Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:39:40 +0200 Subject: [PATCH 065/386] PnP-related IDE fixes. --- src/disk/hdc_ide.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index b005cbd6d..be799916a 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -2614,7 +2614,7 @@ ide_read_ali_76(void) } -static void +void ide_set_handlers(uint8_t board) { if (ide_boards[board] == NULL) @@ -2636,7 +2636,7 @@ ide_set_handlers(uint8_t board) } -static void +void ide_remove_handlers(uint8_t board) { if (ide_boards[board] == NULL) @@ -2878,11 +2878,11 @@ ide_board_init(int board, int irq, int base_main, int side_main, int type) void ide_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) { + intptr_t board = (intptr_t) priv; + if (ld) return; - intptr_t board = (intptr_t) priv; - if (ide_boards[board]->base_main || ide_boards[board]->side_main) { ide_remove_handlers(board); ide_boards[board]->base_main = ide_boards[board]->side_main = 0; @@ -2891,10 +2891,10 @@ ide_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) ide_boards[board]->irq = -1; if (config->activate) { - ide_boards[board]->base_main = config->io[0].base; - ide_boards[board]->side_main = config->io[1].base; + ide_boards[board]->base_main = (config->io[0].base != ISAPNP_IO_DISABLED) ? config->io[0].base : 0x0000; + ide_boards[board]->side_main = (config->io[1].base != ISAPNP_IO_DISABLED) ? config->io[1].base : 0x0000; - if ((ide_boards[board]->base_main != ISAPNP_IO_DISABLED) && (ide_boards[board]->side_main != ISAPNP_IO_DISABLED)) + if (ide_boards[board]->base_main && ide_boards[board]->side_main) ide_set_handlers(board); if (config->irq[0].irq != ISAPNP_IRQ_DISABLED) From 0e539f4a6a6fcc34c7790c9856a2d5f411eff2af Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:41:03 +0200 Subject: [PATCH 066/386] Header fixes. --- src/include/86box/gameport.h | 1 + src/include/86box/hdc_ide.h | 3 +++ src/include/86box/machine.h | 1 + src/include/86box/mem.h | 6 ++++++ src/include/86box/sio.h | 1 + src/include/86box/snd_sb_dsp.h | 2 +- 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/include/86box/gameport.h b/src/include/86box/gameport.h index 48b07cca6..65fdee996 100644 --- a/src/include/86box/gameport.h +++ b/src/include/86box/gameport.h @@ -121,6 +121,7 @@ extern const device_t gameport_tm_acm_device; extern const device_t gameport_pnp_device; extern const device_t gameport_pnp_6io_device; extern const device_t gameport_sio_device; +extern const device_t gameport_sio_1io_device; extern const device_t *standalone_gameport_type; #endif diff --git a/src/include/86box/hdc_ide.h b/src/include/86box/hdc_ide.h index 840e5daad..9e2539359 100644 --- a/src/include/86box/hdc_ide.h +++ b/src/include/86box/hdc_ide.h @@ -143,6 +143,9 @@ extern void win_cdrom_reload(uint8_t id); extern void ide_set_base(int board, uint16_t port); extern void ide_set_side(int board, uint16_t port); +extern void ide_set_handlers(uint8_t board); +extern void ide_remove_handlers(uint8_t board); + extern void ide_pri_enable(void); extern void ide_pri_disable(void); extern void ide_sec_enable(void); diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 43799d1fe..8456b4dc8 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -658,6 +658,7 @@ extern int machine_at_5emapro_init(const machine_t *); /* m_at_socket8.c */ extern int machine_at_p6rp4_init(const machine_t *); +extern int machine_at_aurora_init(const machine_t *); extern int machine_at_686nx_init(const machine_t *); extern int machine_at_acerv60n_init(const machine_t *); diff --git a/src/include/86box/mem.h b/src/include/86box/mem.h index 79d1963dc..b2ee94d14 100644 --- a/src/include/86box/mem.h +++ b/src/include/86box/mem.h @@ -182,6 +182,8 @@ typedef struct _mem_mapping_ { uint32_t base; uint32_t size; + uint32_t mask; + uint8_t (*read_b)(uint32_t addr, void *priv); uint16_t (*read_w)(uint32_t addr, void *priv); uint32_t (*read_l)(uint32_t addr, void *priv); @@ -270,6 +272,7 @@ extern int writelookup[256]; extern uintptr_t * writelookup2; extern int writelnext; extern uint32_t ram_mapped_addr[64]; +extern uint8_t page_ff[4096]; extern mem_mapping_t ram_low_mapping, #if 1 @@ -298,6 +301,8 @@ extern int memspeed[11]; extern int mmu_perm; extern uint8_t high_page; /* if a high (> 4 gb) page was detected */ +extern uint32_t pages_sz; /* #pages in table */ + extern int mem_a20_state, mem_a20_alt, mem_a20_key; @@ -370,6 +375,7 @@ extern void mem_mapping_set_p(mem_mapping_t *, void *p); extern void mem_mapping_set_addr(mem_mapping_t *, uint32_t base, uint32_t size); extern void mem_mapping_set_exec(mem_mapping_t *, uint8_t *exec); +extern void mem_mapping_set_mask(mem_mapping_t *, uint32_t mask); extern void mem_mapping_disable(mem_mapping_t *); extern void mem_mapping_enable(mem_mapping_t *); extern void mem_mapping_recalc(uint64_t base, uint64_t size); diff --git a/src/include/86box/sio.h b/src/include/86box/sio.h index a9ee018cb..6f9cfa731 100644 --- a/src/include/86box/sio.h +++ b/src/include/86box/sio.h @@ -42,6 +42,7 @@ extern const device_t fdc37m60x_370_device; extern const device_t it8661f_device; extern const device_t i82091aa_device; extern const device_t i82091aa_398_device; +extern const device_t i82091aa_ide_pri_device; extern const device_t i82091aa_ide_device; extern const device_t pc87306_device; extern const device_t pc87307_device; diff --git a/src/include/86box/snd_sb_dsp.h b/src/include/86box/snd_sb_dsp.h index 9dd184ac5..2f3607176 100644 --- a/src/include/86box/snd_sb_dsp.h +++ b/src/include/86box/snd_sb_dsp.h @@ -83,7 +83,7 @@ typedef struct sb_dsp_t { pc_timer_t output_timer, input_timer; - uint64_t sblatcho, sblatchi; + double sblatcho, sblatchi; uint16_t sb_addr; From 8f92f0722afb7f53428af9c429e48c5e3d38f885 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:43:22 +0200 Subject: [PATCH 067/386] Initialize the PS/1 middle ROM file (F80000.BIN) if present. --- src/machine/m_ps1.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/machine/m_ps1.c b/src/machine/m_ps1.c index 0b0182692..101746a03 100644 --- a/src/machine/m_ps1.c +++ b/src/machine/m_ps1.c @@ -68,7 +68,7 @@ typedef struct { int model; - rom_t high_rom; + rom_t mid_rom, high_rom; uint8_t ps1_91, ps1_92, @@ -300,6 +300,11 @@ ps1_setup(int model) io_sethandler(0x00e0, 2, ps1_read, NULL, NULL, ps1_write, NULL, NULL, ps); + if (rom_present("roms/machines/ibmps1_2121/F80000.BIN")) { + rom_init(&ps->mid_rom, + "roms/machines/ibmps1_2121/F80000.BIN", + 0xf80000, 0x40000, 0x3ffff, 0, MEM_MAPPING_EXTERNAL); + } rom_init(&ps->high_rom, "roms/machines/ibmps1_2121/FC0000.BIN", 0xfc0000, 0x40000, 0x3ffff, 0, MEM_MAPPING_EXTERNAL); From b91ab53c0f40797dc14a1dc23c71e79172948270 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:44:21 +0200 Subject: [PATCH 068/386] Marked the DataExpert EXP8551 as having a gameport. --- src/machine/machine_table.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index d671cfabe..ac4a4e9c7 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -633,7 +633,7 @@ const machine_t machines[] = { /* Has AMIKey F KBC firmware. */ { "[i430FX] AMI Apollo", "apollo", MACHINE_TYPE_SOCKET5, MACHINE_CHIPSET_INTEL_430FX, machine_at_apollo_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_SOCKET5_7, CPU_BLOCK_NONE, 50000000, 66666667, 3380, 3520, 1.5, 2.0, MACHINE_PS2_PCI, MACHINE_IDE_DUAL, 8192, 131072, 8192, 127, NULL, NULL }, /* Has AMIKey H KBC firmware. */ - { "[i430FX] DataExpert EXP8551", "exp8551", MACHINE_TYPE_SOCKET5, MACHINE_CHIPSET_INTEL_430FX, machine_at_exp8551_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_SOCKET5_7, CPU_BLOCK_NONE, 50000000, 66666667, 3380, 3520, 1.5, 3.0, MACHINE_PS2_PCI, MACHINE_IDE_DUAL, 8192, 131072, 8192, 127, NULL, NULL }, + { "[i430FX] DataExpert EXP8551", "exp8551", MACHINE_TYPE_SOCKET5, MACHINE_CHIPSET_INTEL_430FX, machine_at_exp8551_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_SOCKET5_7, CPU_BLOCK_NONE, 50000000, 66666667, 3380, 3520, 1.5, 3.0, MACHINE_PS2_PCI, MACHINE_IDE_DUAL | MACHINE_GAMEPORT, 8192, 131072, 8192, 127, NULL, NULL }, /* According to tests from real hardware: This has AMI MegaKey KBC firmware on the PC87306 Super I/O chip, command 0xA1 returns '5'. Command 0xA0 copyright string: (C)1994 AMI . */ @@ -842,6 +842,10 @@ const machine_t machines[] = { /* 450KX */ /* This has an AMIKey-2, which is an updated version of type 'H'. */ { "[i450KX] ASUS P/I-P6RP4", "p6rp4", MACHINE_TYPE_SOCKET8, MACHINE_CHIPSET_INTEL_450KX, machine_at_p6rp4_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_SOCKET8, CPU_BLOCK_NONE, 60000000, 66666667, 2100, 3500, 1.5, 8.0, MACHINE_PS2_PCI, MACHINE_IDE_DUAL, 8192, 524288, 8192, 127, NULL, NULL }, + /* According to tests from real hardware: This has AMI MegaKey KBC firmware on the + PC87306 Super I/O chip, command 0xA1 returns '5'. + Command 0xA0 copyright string: (C)1994 AMI . */ + { "[i450KX] Intel Performance/AU", "aurora", MACHINE_TYPE_SOCKET8, MACHINE_CHIPSET_INTEL_450KX, machine_at_aurora_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_SOCKET8, CPU_BLOCK_NONE, 60000000, 66666667, 2100, 3500, 1.5, 8.0, MACHINE_PS2_PCI, MACHINE_IDE_DUAL, 8192, 524288, 8192, 127, NULL, NULL }, /* 440FX */ /* Has the SMC FDC73C935's on-chip KBC with Phoenix MultiKey firmware. */ From 69d0ff454c7d7c1dab11b70ff548ed514a62299c Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:45:25 +0200 Subject: [PATCH 069/386] A game/gameport.c change. --- src/game/gameport.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/game/gameport.c b/src/game/gameport.c index 20ea51ffa..5f845b485 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -698,3 +698,17 @@ const device_t gameport_sio_device = { .force_redraw = NULL, .config = NULL }; + +const device_t gameport_sio_1io_device = { + .name = "Game port (Super I/O, 1 I/O port)", + .internal_name = "gameport_sio", + .flags = 0, + .local = 0x1010000, + .init = gameport_init, + .close = gameport_close, + .reset = NULL, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; From 25783f137d17c6c57715cb1b02abd56a5ad1806d Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:48:18 +0200 Subject: [PATCH 070/386] ALi M6117-related memory and ROM fixes. --- src/mem/mem.c | 43 ++++++++++++++++++++++++++++--------------- src/mem/rom.c | 13 +++++++++++-- src/mem/sst_flash.c | 15 +++++++++++---- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/mem/mem.c b/src/mem/mem.c index 4a54c72f2..bc4e34691 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -1319,7 +1319,6 @@ writememll(uint32_t addr, uint32_t val) uint32_t readmemll_no_mmut(uint32_t addr, uint32_t *a64) { -#ifndef NO_MMUT mem_mapping_t *map; GDBSTUB_MEM_ACCESS(addr, GDBSTUB_MEM_READ, 4); @@ -1367,9 +1366,6 @@ readmemll_no_mmut(uint32_t addr, uint32_t *a64) ((uint32_t) (map->read_b(addr + 3, map->p)) << 24); return 0xffffffff; -#else - return readmemll(addr); -#endif } @@ -1377,7 +1373,6 @@ readmemll_no_mmut(uint32_t addr, uint32_t *a64) void writememll_no_mmut(uint32_t addr, uint32_t *a64, uint32_t val) { -#ifndef NO_MMUT mem_mapping_t *map; GDBSTUB_MEM_ACCESS(addr, GDBSTUB_MEM_WRITE, 4); @@ -1435,9 +1430,6 @@ writememll_no_mmut(uint32_t addr, uint32_t *a64, uint32_t val) map->write_b(addr + 3, val >> 24, map->p); return; } -#else - writememll(addr, val); -#endif } @@ -1668,7 +1660,7 @@ mem_readb_phys(uint32_t addr) if (map) { if (map->exec) - ret = map->exec[addr - map->base]; + ret = map->exec[(addr - map->base) & map->mask]; else if (map->read_b) ret = map->read_b(addr, map->p); } @@ -1686,7 +1678,7 @@ mem_readw_phys(uint32_t addr) mem_logical_addr = 0xffffffff; if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->exec)) { - p = (uint16_t *) &(map->exec[addr - map->base]); + p = (uint16_t *) &(map->exec[(addr - map->base) & map->mask]); ret = *p; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->read_w)) ret = map->read_w(addr, map->p); @@ -1708,7 +1700,7 @@ mem_readl_phys(uint32_t addr) mem_logical_addr = 0xffffffff; if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->exec)) { - p = (uint32_t *) &(map->exec[addr - map->base]); + p = (uint32_t *) &(map->exec[(addr - map->base) & map->mask]); ret = *p; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->read_l)) ret = map->read_l(addr, map->p); @@ -1750,7 +1742,7 @@ mem_writeb_phys(uint32_t addr, uint8_t val) if (map) { if (map->exec) - map->exec[addr - map->base] = val; + map->exec[(addr - map->base) & map->mask] = val; else if (map->write_b) map->write_b(addr, val, map->p); } @@ -1766,7 +1758,7 @@ mem_writew_phys(uint32_t addr, uint16_t val) mem_logical_addr = 0xffffffff; if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->exec)) { - p = (uint16_t *) &(map->exec[addr - map->base]); + p = (uint16_t *) &(map->exec[(addr - map->base) & map->mask]); *p = val; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->write_w)) map->write_w(addr, val, map->p); @@ -1786,7 +1778,7 @@ mem_writel_phys(uint32_t addr, uint32_t val) mem_logical_addr = 0xffffffff; if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->exec)) { - p = (uint32_t *) &(map->exec[addr - map->base]); + p = (uint32_t *) &(map->exec[(addr - map->base) & map->mask]); *p = val; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->write_l)) map->write_l(addr, val, map->p); @@ -2362,6 +2354,7 @@ mem_mapping_set(mem_mapping_t *map, map->enable = 0; map->base = base; map->size = size; + map->mask = (map->size ? 0xffffffff : 0x00000000); map->read_b = read_b; map->read_w = read_w; map->read_l = read_l; @@ -2479,6 +2472,15 @@ mem_mapping_set_exec(mem_mapping_t *map, uint8_t *exec) } +void +mem_mapping_set_mask(mem_mapping_t *map, uint32_t mask) +{ + map->mask = mask; + + mem_mapping_recalc(map->base, map->size); +} + + void mem_mapping_set_p(mem_mapping_t *map, void *p) { @@ -2560,6 +2562,8 @@ mem_a20_init(void) { if (is286) { rammask = cpu_16bitbus ? 0xefffff : 0xffefffff; + if (is6117) + rammask |= 0x03000000; flushmmucache(); mem_a20_state = mem_a20_key | mem_a20_alt; } else { @@ -2690,6 +2694,9 @@ mem_reset(void) if (cpu_16bitbus) { /* 80286/386SX; maximum address space is 16MB. */ m = 4096; + /* ALi M6117; maximum address space is 64MB. */ + if (is6117) + m <<= 2; } else { /* 80386DX+; maximum address space is 4GB. */ m = 1048576; @@ -2761,8 +2768,10 @@ mem_reset(void) mem_init_ram_mapping(&ram_low_mapping, 0x000000, (mem_size > 640) ? 0xa0000 : mem_size * 1024); if (mem_size > 1024) { - if (cpu_16bitbus && mem_size > 16256) + if (cpu_16bitbus && !is6117 && mem_size > 16256) mem_init_ram_mapping(&ram_high_mapping, 0x100000, (16256 - 1024) * 1024); + else if (cpu_16bitbus && is6117 && mem_size > 65408) + mem_init_ram_mapping(&ram_high_mapping, 0x100000, (65408 - 1024) * 1024); else { if (mem_size > 1048576) { mem_init_ram_mapping(&ram_high_mapping, 0x100000, (1048576 - 1024) * 1024); @@ -2904,9 +2913,13 @@ mem_a20_recalc(void) state = mem_a20_key | mem_a20_alt; if (state && !mem_a20_state) { rammask = (cpu_16bitbus) ? 0xffffff : 0xffffffff; + if (is6117) + rammask |= 0x03000000; flushmmucache(); } else if (!state && mem_a20_state) { rammask = (cpu_16bitbus) ? 0xefffff : 0xffefffff; + if (is6117) + rammask |= 0x03000000; flushmmucache(); } diff --git a/src/mem/rom.c b/src/mem/rom.c index 62b03bc11..eb2b5791b 100644 --- a/src/mem/rom.c +++ b/src/mem/rom.c @@ -451,12 +451,13 @@ static void bios_add(void) { int temp_cpu_type, temp_cpu_16bitbus = 1; - int temp_is286 = 0; + int temp_is286 = 0, temp_is6117 = 0; if (/*AT && */cpu_s) { temp_cpu_type = cpu_s->cpu_type; temp_cpu_16bitbus = (temp_cpu_type == CPU_286 || temp_cpu_type == CPU_386SX || temp_cpu_type == CPU_486SLC || temp_cpu_type == CPU_IBM386SLC || temp_cpu_type == CPU_IBM486SLC ); temp_is286 = (temp_cpu_type >= CPU_286); + temp_is6117 = !strcmp(cpu_f->manufacturer, "ALi"); } if (biosmask > 0x1ffff) { @@ -478,7 +479,15 @@ bios_add(void) MEM_READ_ROMCS | MEM_WRITE_ROMCS); } - if (temp_is286) { + if (temp_is6117) { + mem_mapping_add(&bios_high_mapping, biosaddr | 0x03f00000, biosmask + 1, + bios_read,bios_readw,bios_readl, + NULL,NULL,NULL, + rom, MEM_MAPPING_EXTERNAL|MEM_MAPPING_ROM|MEM_MAPPING_ROMCS, 0); + + mem_set_mem_state_both(biosaddr | 0x03f00000, biosmask + 1, + MEM_READ_ROMCS | MEM_WRITE_ROMCS); + } else if (temp_is286) { mem_mapping_add(&bios_high_mapping, biosaddr | (temp_cpu_16bitbus ? 0x00f00000 : 0xfff00000), biosmask + 1, bios_read,bios_readw,bios_readl, NULL,NULL,NULL, diff --git a/src/mem/sst_flash.c b/src/mem/sst_flash.c index 1fc5b2082..9aa0d4345 100644 --- a/src/mem/sst_flash.c +++ b/src/mem/sst_flash.c @@ -400,10 +400,17 @@ sst_add_mappings(sst_t *dev) sst_write, NULL, NULL, dev->array + fbase, MEM_MAPPING_EXTERNAL|MEM_MAPPING_ROM|MEM_MAPPING_ROMCS, (void *) dev); } - mem_mapping_add(&(dev->mapping_h[i]), (base | (cpu_16bitbus ? 0xf00000 : 0xfff00000)), 0x10000, - sst_read, sst_readw, sst_readl, - sst_write, NULL, NULL, - dev->array + fbase, MEM_MAPPING_EXTERNAL|MEM_MAPPING_ROM|MEM_MAPPING_ROMCS, (void *) dev); + if (is6117) { + mem_mapping_add(&(dev->mapping_h[i]), (base | 0x3f00000), 0x10000, + sst_read, sst_readw, sst_readl, + sst_write, NULL, NULL, + dev->array + fbase, MEM_MAPPING_EXTERNAL|MEM_MAPPING_ROM|MEM_MAPPING_ROMCS, (void *) dev); + } else { + mem_mapping_add(&(dev->mapping_h[i]), (base | (cpu_16bitbus ? 0xf00000 : 0xfff00000)), 0x10000, + sst_read, sst_readw, sst_readl, + sst_write, NULL, NULL, + dev->array + fbase, MEM_MAPPING_EXTERNAL|MEM_MAPPING_ROM|MEM_MAPPING_ROMCS, (void *) dev); + } } } From 5dc9b4a7fca84760fe8d08d741563d4b430c20f4 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:53:05 +0200 Subject: [PATCH 071/386] Super I/O chip fixes. --- src/sio/sio_82091aa.c | 30 +++++++++++++++++++++++------- src/sio/sio_w83787f.c | 24 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/sio/sio_82091aa.c b/src/sio/sio_82091aa.c index e385bcd2d..7a60aa7c4 100644 --- a/src/sio/sio_82091aa.c +++ b/src/sio/sio_82091aa.c @@ -125,11 +125,13 @@ serial_handler(i82091aa_t *dev, int uart) static void ide_handler(i82091aa_t *dev) { - ide_sec_disable(); - ide_set_base(1, (dev->regs[0x50] & 0x02) ? 0x170 : 0x1f0); - ide_set_side(1, (dev->regs[0x50] & 0x02) ? 0x376 : 0x3f6); + int board = dev->has_ide - 1; + + ide_remove_handlers(board); + ide_set_base(board, (dev->regs[0x50] & 0x02) ? 0x170 : 0x1f0); + ide_set_side(board, (dev->regs[0x50] & 0x02) ? 0x376 : 0x3f6); if (dev->regs[0x50] & 0x01) - ide_sec_enable(); + ide_set_handlers(board); } @@ -258,7 +260,7 @@ i82091aa_init(const device_t *info) dev->uart[0] = device_add_inst(&ns16550_device, 1); dev->uart[1] = device_add_inst(&ns16550_device, 2); - dev->has_ide = !!(info->local & 0x200); + dev->has_ide = (info->local >> 9) & 0x03; i82091aa_reset(dev); @@ -303,8 +305,8 @@ const device_t i82091aa_398_device = { .config = NULL }; -const device_t i82091aa_ide_device = { - .name = "Intel 82091AA Super I/O (With IDE)", +const device_t i82091aa_ide_pri_device = { + .name = "Intel 82091AA Super I/O (With Primary IDE)", .internal_name = "i82091aa_ide", .flags = 0, .local = 0x240, @@ -316,3 +318,17 @@ const device_t i82091aa_ide_device = { .force_redraw = NULL, .config = NULL }; + +const device_t i82091aa_ide_device = { + .name = "Intel 82091AA Super I/O (With IDE)", + .internal_name = "i82091aa_ide", + .flags = 0, + .local = 0x440, + .init = i82091aa_init, + .close = i82091aa_close, + .reset = NULL, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/sio/sio_w83787f.c b/src/sio/sio_w83787f.c index fe48f5d79..393ab5fd9 100644 --- a/src/sio/sio_w83787f.c +++ b/src/sio/sio_w83787f.c @@ -34,6 +34,7 @@ #include <86box/fdc.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> +#include <86box/gameport.h> #include <86box/sio.h> #ifdef ENABLE_W83787_LOG @@ -82,6 +83,7 @@ typedef struct { ide_start; fdc_t *fdc; serial_t *uart[2]; + void *gameport; } w83787f_t; @@ -200,6 +202,16 @@ w83787f_lpt_handler(w83787f_t *dev) } +static void +w83787f_gameport_handler(w83787f_t *dev) +{ + if (!(dev->regs[3] & 0x40) && !(dev->regs[4] & 0x40)) + gameport_remap(dev->gameport, 0x201); + else + gameport_remap(dev->gameport, 0); +} + + static void w83787f_fdc_handler(w83787f_t *dev) { @@ -282,6 +294,8 @@ w83787f_write(uint16_t port, uint8_t val, void *priv) case 3: if (valxor & 0x80) w83787f_lpt_handler(dev); + if (valxor & 0x40) + w83787f_gameport_handler(dev); if (valxor & 0x08) w83787f_serial_handler(dev, 0); if (valxor & 0x04) @@ -294,6 +308,8 @@ w83787f_write(uint16_t port, uint8_t val, void *priv) w83787f_serial_handler(dev, 0); if (valxor & 0x80) w83787f_lpt_handler(dev); + if (valxor & 0x40) + w83787f_gameport_handler(dev); break; case 6: if (valxor & 0x08) @@ -392,16 +408,20 @@ w83787f_reset(w83787f_t *dev) fdc_reset(dev->fdc); dev->regs[0x01] = 0x2C; - dev->regs[0x03] = 0x30; + dev->regs[0x03] = 0x70; dev->regs[0x07] = 0xF5; dev->regs[0x09] = dev->reg_init & 0xff; dev->regs[0x0a] = 0x1F; dev->regs[0x0c] = 0x2C; dev->regs[0x0d] = 0xA3; + gameport_remap(dev->gameport, 0); + serial_setup(dev->uart[0], COM1_ADDR, COM1_IRQ); serial_setup(dev->uart[1], COM2_ADDR, COM2_IRQ); + w83787f_lpt_handler(dev); + dev->key = 0x89; w83787f_remap(dev); @@ -433,6 +453,8 @@ w83787f_init(const device_t *info) dev->uart[0] = device_add_inst(&ns16550_device, 1); dev->uart[1] = device_add_inst(&ns16550_device, 2); + dev->gameport = gameport_add(&gameport_sio_1io_device); + if ((dev->ide_function & 0x30) == 0x10) device_add(&ide_isa_device); From 74fd270ee8efee918e7d09ff84620b45843d7639 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:55:30 +0200 Subject: [PATCH 072/386] Assorted SB fixes. --- src/sound/snd_sb.c | 22 ++++++++++++++++++++++ src/sound/snd_sb_dsp.c | 32 ++++++++++++++++---------------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 247455036..aaafd11fa 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -1816,6 +1816,16 @@ sb_16_pnp_init(const device_t *info) isapnp_add_card(sb_16_pnp_rom, sizeof(sb_16_pnp_rom), sb_16_pnp_config_changed, NULL, NULL, NULL, sb); + sb_dsp_setaddr(&sb->dsp, 0); + sb_dsp_setirq(&sb->dsp, 0); + sb_dsp_setdma8(&sb->dsp, ISAPNP_DMA_DISABLED); + sb_dsp_setdma16(&sb->dsp, ISAPNP_DMA_DISABLED); + + mpu401_change_addr(sb->mpu, 0); + ide_remove_handlers(2); + + gameport_remap(sb->gameport, 0); + return sb; } @@ -2017,6 +2027,18 @@ sb_awe32_pnp_init(const device_t *info) break; } + sb_dsp_setaddr(&sb->dsp, 0); + sb_dsp_setirq(&sb->dsp, 0); + sb_dsp_setdma8(&sb->dsp, ISAPNP_DMA_DISABLED); + sb_dsp_setdma16(&sb->dsp, ISAPNP_DMA_DISABLED); + + mpu401_change_addr(sb->mpu, 0); + ide_remove_handlers(2); + + emu8k_change_addr(&sb->emu8k, 0); + + gameport_remap(sb->gameport, 0); + return sb; } diff --git a/src/sound/snd_sb_dsp.c b/src/sound/snd_sb_dsp.c index c87f45e2f..3cbb223f3 100644 --- a/src/sound/snd_sb_dsp.c +++ b/src/sound/snd_sb_dsp.c @@ -326,14 +326,14 @@ void sb_dsp_speed_changed(sb_dsp_t *dsp) { if (dsp->sb_timeo < 256) - dsp->sblatcho = TIMER_USEC * (256 - dsp->sb_timeo); + dsp->sblatcho = (256.0 - (double) dsp->sb_timeo); else - dsp->sblatcho = (uint64_t) (TIMER_USEC * (1000000.0f / (float) (dsp->sb_timeo - 256))); + dsp->sblatcho = ((1000000.0 / ((double) dsp->sb_timeo - 256.0))); if (dsp->sb_timei < 256) - dsp->sblatchi = TIMER_USEC * (256 - dsp->sb_timei); + dsp->sblatchi = (256.0 - (double) dsp->sb_timei); else - dsp->sblatchi = (uint64_t) (TIMER_USEC * (1000000.0f / (float) (dsp->sb_timei - 256))); + dsp->sblatchi = ((1000000.0 / ((double) dsp->sb_timei - 256.0))); } void @@ -359,7 +359,7 @@ sb_start_dma(sb_dsp_t *dsp, int dma8, int autoinit, uint8_t format, int len) dsp->sb_16_enable = 0; dsp->sb_8_output = 1; if (!timer_is_enabled(&dsp->output_timer)) - timer_set_delay_u64(&dsp->output_timer, dsp->sblatcho); + timer_on_auto(&dsp->output_timer, dsp->sblatcho); dsp->sbleftright = dsp->sbleftright_default; dsp->sbdacpos = 0; } else { @@ -372,7 +372,7 @@ sb_start_dma(sb_dsp_t *dsp, int dma8, int autoinit, uint8_t format, int len) dsp->sb_8_enable = 0; dsp->sb_16_output = 1; if (!timer_is_enabled(&dsp->output_timer)) - timer_set_delay_u64(&dsp->output_timer, dsp->sblatcho); + timer_on_auto(&dsp->output_timer, dsp->sblatcho); } } @@ -389,7 +389,7 @@ sb_start_dma_i(sb_dsp_t *dsp, int dma8, int autoinit, uint8_t format, int len) dsp->sb_16_enable = 0; dsp->sb_8_output = 0; if (!timer_is_enabled(&dsp->input_timer)) - timer_set_delay_u64(&dsp->input_timer, dsp->sblatchi); + timer_on_auto(&dsp->input_timer, dsp->sblatchi); } else { dsp->sb_16_length = dsp->sb_16_origlength = len; dsp->sb_16_format = format; @@ -400,7 +400,7 @@ sb_start_dma_i(sb_dsp_t *dsp, int dma8, int autoinit, uint8_t format, int len) dsp->sb_8_enable = 0; dsp->sb_16_output = 0; if (!timer_is_enabled(&dsp->input_timer)) - timer_set_delay_u64(&dsp->input_timer, dsp->sblatchi); + timer_on_auto(&dsp->input_timer, dsp->sblatchi); } memset(dsp->record_buffer, 0, sizeof(dsp->record_buffer)); @@ -508,10 +508,10 @@ sb_exec_command(sb_dsp_t *dsp) mode does not imply such samplerate. Position is increased in sb_poll_i(). */ if (!timer_is_enabled(&dsp->input_timer)) { dsp->sb_timei = 256 - 22; - dsp->sblatchi = TIMER_USEC * 22; + dsp->sblatchi = 22.0; temp = 1000000 / 22; dsp->sb_freq = temp; - timer_set_delay_u64(&dsp->input_timer, dsp->sblatchi); + timer_on_auto(&dsp->input_timer, dsp->sblatchi); } break; case 0x24: /* 8-bit single cycle DMA input */ @@ -561,7 +561,7 @@ sb_exec_command(sb_dsp_t *dsp) break; case 0x40: /* Set time constant */ dsp->sb_timei = dsp->sb_timeo = dsp->sb_data[0]; - dsp->sblatcho = dsp->sblatchi = TIMER_USEC * (256 - dsp->sb_data[0]); + dsp->sblatcho = dsp->sblatchi = (256.0 - (double) dsp->sb_data[0]); temp = 256 - dsp->sb_data[0]; temp = 1000000 / temp; sb_dsp_log("Sample rate - %ihz (%i)\n", temp, dsp->sblatcho); @@ -572,8 +572,8 @@ sb_exec_command(sb_dsp_t *dsp) case 0x41: /* Set output sampling rate */ case 0x42: /* Set input sampling rate */ if (dsp->sb_type >= SB16) { - dsp->sblatcho = (uint64_t) (TIMER_USEC * (1000000.0f / (float) (dsp->sb_data[1] + (dsp->sb_data[0] << 8)))); - sb_dsp_log("Sample rate - %ihz (%i)\n", dsp->sb_data[1] + (dsp->sb_data[0] << 8), dsp->sblatcho); + dsp->sblatcho = ((1000000.0 / (double) (dsp->sb_data[1] + (dsp->sb_data[0] << 8)))); + sb_dsp_log("Sample rate - %ihz (%lf)\n", dsp->sb_data[1] + (dsp->sb_data[0] << 8), dsp->sblatcho); temp = dsp->sb_freq; dsp->sb_freq = dsp->sb_data[1] + (dsp->sb_data[0] << 8); dsp->sb_timeo = 256LL + dsp->sb_freq; @@ -631,7 +631,7 @@ sb_exec_command(sb_dsp_t *dsp) case 0x80: /* Pause DAC */ dsp->sb_pausetime = dsp->sb_data[0] + (dsp->sb_data[1] << 8); if (!timer_is_enabled(&dsp->output_timer)) - timer_set_delay_u64(&dsp->output_timer, dsp->sblatcho); + timer_on_auto(&dsp->output_timer, dsp->sblatcho); break; case 0x90: /* High speed 8-bit autoinit DMA output */ if (dsp->sb_type >= SB2) @@ -1200,7 +1200,7 @@ pollsb(void *p) int tempi, ref; int data[2]; - timer_advance_u64(&dsp->output_timer, dsp->sblatcho); + timer_on_auto(&dsp->output_timer, dsp->sblatcho); if (dsp->sb_8_enable && !dsp->sb_8_pause && dsp->sb_pausetime < 0 && dsp->sb_8_output) { sb_dsp_update(dsp); @@ -1457,7 +1457,7 @@ sb_poll_i(void *p) sb_dsp_t *dsp = (sb_dsp_t *) p; int processed = 0; - timer_advance_u64(&dsp->input_timer, dsp->sblatchi); + timer_on_auto(&dsp->input_timer, dsp->sblatchi); if (dsp->sb_8_enable && !dsp->sb_8_pause && dsp->sb_pausetime < 0 && !dsp->sb_8_output) { switch (dsp->sb_8_format) { From 3bcb9f6310d24ce518f4ee22609eef0e9c0cad5f Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:56:21 +0200 Subject: [PATCH 073/386] Cleaned up the (S)VGA render code of excess CRTC checks. --- src/video/vid_svga.c | 4 +- src/video/vid_svga_render.c | 770 +++++++++++++++--------------------- 2 files changed, 322 insertions(+), 452 deletions(-) diff --git a/src/video/vid_svga.c b/src/video/vid_svga.c index 542ab13e0..d7a122cb4 100644 --- a/src/video/vid_svga.c +++ b/src/video/vid_svga.c @@ -460,7 +460,7 @@ svga_recalctimings(svga_t *svga) svga->hdisp_time = svga->hdisp; svga->render = svga_render_blank; - if (!svga->scrblank && svga->attr_palette_enable) { + if (!svga->scrblank && (svga->crtc[0x17] & 0x80) && svga->attr_palette_enable) { if (!(svga->gdcreg[6] & 1) && !(svga->attrregs[0x10] & 1)) { /*Text mode*/ if (svga->seqregs[1] & 8) /*40 column*/ { svga->render = svga_render_text_40; @@ -658,6 +658,7 @@ svga_poll(void *p) uint32_t x, blink_delay; int wx, wy; int ret, old_ma; + int old_vc; if (!vga_on && ibm8514_enabled && ibm8514_on) { ibm8514_poll(&svga->dev8514, svga); @@ -786,6 +787,7 @@ svga_poll(void *p) return; svga->vc++; + old_vc = svga->vc; svga->vc &= 2047; if (svga->vc == svga->split) { diff --git a/src/video/vid_svga_render.c b/src/video/vid_svga_render.c index ca9c3b3f1..c4b817fd4 100644 --- a/src/video/vid_svga_render.c +++ b/src/video/vid_svga_render.c @@ -136,16 +136,13 @@ svga_render_text_40(svga_t *svga) drawcursor = ((svga->ma == svga->ca) && svga->con && svga->cursoron); - if (svga->crtc[0x17] & 0x80) { - if (svga->force_old_addr) { - chr = svga->vram[(svga->ma << 1) & svga->vram_display_mask]; - attr = svga->vram[((svga->ma << 1) + 1) & svga->vram_display_mask]; - } else { - chr = svga->vram[addr]; - attr = svga->vram[addr+1]; - } - } else - chr = attr = 0; + if (svga->force_old_addr) { + chr = svga->vram[(svga->ma << 1) & svga->vram_display_mask]; + attr = svga->vram[((svga->ma << 1) + 1) & svga->vram_display_mask]; + } else { + chr = svga->vram[addr]; + attr = svga->vram[addr+1]; + } if (attr & 8) charaddr = svga->charsetb + (chr * 128); else charaddr = svga->charseta + (chr * 128); @@ -212,16 +209,13 @@ svga_render_text_80(svga_t *svga) drawcursor = ((svga->ma == svga->ca) && svga->con && svga->cursoron); - if (svga->crtc[0x17] & 0x80) { - if (svga->force_old_addr) { - chr = svga->vram[(svga->ma << 1) & svga->vram_display_mask]; - attr = svga->vram[((svga->ma << 1) + 1) & svga->vram_display_mask]; - } else { - chr = svga->vram[addr]; - attr = svga->vram[addr+1]; - } - } else - chr = attr = 0; + if (svga->force_old_addr) { + chr = svga->vram[(svga->ma << 1) & svga->vram_display_mask]; + attr = svga->vram[((svga->ma << 1) + 1) & svga->vram_display_mask]; + } else { + chr = svga->vram[addr]; + attr = svga->vram[addr+1]; + } if (attr & 8) charaddr = svga->charsetb + (chr * 128); else charaddr = svga->charseta + (chr * 128); @@ -286,10 +280,7 @@ svga_render_text_80_ksc5601(svga_t *svga) drawcursor = ((svga->ma == svga->ca) && svga->con && svga->cursoron); chr = svga->vram[addr]; nextchr = svga->vram[addr + 8]; - if (svga->crtc[0x17] & 0x80) - attr = svga->vram[addr + 1]; - else - attr = 0; + attr = svga->vram[addr + 1]; if (drawcursor) { bg = svga->pallook[svga->egapal[attr & 15]]; @@ -433,17 +424,14 @@ svga_render_2bpp_lowres(svga_t *svga) else svga->ma += 4; svga->ma &= svga->vram_mask; - if (svga->crtc[0x17] & 0x80) { - p[0] = p[1] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3]]; - p[2] = p[3] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3]]; - p[4] = p[5] = svga->pallook[svga->egapal[(dat[0] >> 2) & 3]]; - p[6] = p[7] = svga->pallook[svga->egapal[dat[0] & 3]]; - p[8] = p[9] = svga->pallook[svga->egapal[(dat[1] >> 6) & 3]]; - p[10] = p[11] = svga->pallook[svga->egapal[(dat[1] >> 4) & 3]]; - p[12] = p[13] = svga->pallook[svga->egapal[(dat[1] >> 2) & 3]]; - p[14] = p[15] = svga->pallook[svga->egapal[dat[1] & 3]]; - } else - memset(p, 0x00, 16 * sizeof(uint32_t)); + p[0] = p[1] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3]]; + p[2] = p[3] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3]]; + p[4] = p[5] = svga->pallook[svga->egapal[(dat[0] >> 2) & 3]]; + p[6] = p[7] = svga->pallook[svga->egapal[dat[0] & 3]]; + p[8] = p[9] = svga->pallook[svga->egapal[(dat[1] >> 6) & 3]]; + p[10] = p[11] = svga->pallook[svga->egapal[(dat[1] >> 4) & 3]]; + p[12] = p[13] = svga->pallook[svga->egapal[(dat[1] >> 2) & 3]]; + p[14] = p[15] = svga->pallook[svga->egapal[dat[1] & 3]]; p += 16; } } @@ -469,17 +457,14 @@ svga_render_2bpp_lowres(svga_t *svga) svga->ma &= svga->vram_mask; - if (svga->crtc[0x17] & 0x80) { - p[0] = p[1] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3]]; - p[2] = p[3] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3]]; - p[4] = p[5] = svga->pallook[svga->egapal[(dat[0] >> 2) & 3]]; - p[6] = p[7] = svga->pallook[svga->egapal[dat[0] & 3]]; - p[8] = p[9] = svga->pallook[svga->egapal[(dat[1] >> 6) & 3]]; - p[10] = p[11] = svga->pallook[svga->egapal[(dat[1] >> 4) & 3]]; - p[12] = p[13] = svga->pallook[svga->egapal[(dat[1] >> 2) & 3]]; - p[14] = p[15] = svga->pallook[svga->egapal[dat[1] & 3]]; - } else - memset(p, 0x00, 16 * sizeof(uint32_t)); + p[0] = p[1] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3]]; + p[2] = p[3] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3]]; + p[4] = p[5] = svga->pallook[svga->egapal[(dat[0] >> 2) & 3]]; + p[6] = p[7] = svga->pallook[svga->egapal[dat[0] & 3]]; + p[8] = p[9] = svga->pallook[svga->egapal[(dat[1] >> 6) & 3]]; + p[10] = p[11] = svga->pallook[svga->egapal[(dat[1] >> 4) & 3]]; + p[12] = p[13] = svga->pallook[svga->egapal[(dat[1] >> 2) & 3]]; + p[14] = p[15] = svga->pallook[svga->egapal[dat[1] & 3]]; p += 16; } @@ -537,17 +522,14 @@ svga_render_2bpp_highres(svga_t *svga) else svga->ma += 4; svga->ma &= svga->vram_mask; - if (svga->crtc[0x17] & 0x80) { - p[0] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3]]; - p[1] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3]]; - p[2] = svga->pallook[svga->egapal[(dat[0] >> 2) & 3]]; - p[3] = svga->pallook[svga->egapal[dat[0] & 3]]; - p[4] = svga->pallook[svga->egapal[(dat[1] >> 6) & 3]]; - p[5] = svga->pallook[svga->egapal[(dat[1] >> 4) & 3]]; - p[6] = svga->pallook[svga->egapal[(dat[1] >> 2) & 3]]; - p[7] = svga->pallook[svga->egapal[dat[1] & 3]]; - } else - memset(p, 0x00, 8 * sizeof(uint32_t)); + p[0] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3]]; + p[1] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3]]; + p[2] = svga->pallook[svga->egapal[(dat[0] >> 2) & 3]]; + p[3] = svga->pallook[svga->egapal[dat[0] & 3]]; + p[4] = svga->pallook[svga->egapal[(dat[1] >> 6) & 3]]; + p[5] = svga->pallook[svga->egapal[(dat[1] >> 4) & 3]]; + p[6] = svga->pallook[svga->egapal[(dat[1] >> 2) & 3]]; + p[7] = svga->pallook[svga->egapal[dat[1] & 3]]; p += 8; } } @@ -573,17 +555,14 @@ svga_render_2bpp_highres(svga_t *svga) svga->ma &= svga->vram_mask; - if (svga->crtc[0x17] & 0x80) { - p[0] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3]]; - p[1] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3]]; - p[2] = svga->pallook[svga->egapal[(dat[0] >> 2) & 3]]; - p[3] = svga->pallook[svga->egapal[dat[0] & 3]]; - p[4] = svga->pallook[svga->egapal[(dat[1] >> 6) & 3]]; - p[5] = svga->pallook[svga->egapal[(dat[1] >> 4) & 3]]; - p[6] = svga->pallook[svga->egapal[(dat[1] >> 2) & 3]]; - p[7] = svga->pallook[svga->egapal[dat[1] & 3]]; - } else - memset(p, 0x00, 8 * sizeof(uint32_t)); + p[0] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3]]; + p[1] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3]]; + p[2] = svga->pallook[svga->egapal[(dat[0] >> 2) & 3]]; + p[3] = svga->pallook[svga->egapal[dat[0] & 3]]; + p[4] = svga->pallook[svga->egapal[(dat[1] >> 6) & 3]]; + p[5] = svga->pallook[svga->egapal[(dat[1] >> 4) & 3]]; + p[6] = svga->pallook[svga->egapal[(dat[1] >> 2) & 3]]; + p[7] = svga->pallook[svga->egapal[dat[1] & 3]]; p += 8; } @@ -629,21 +608,18 @@ svga_render_2bpp_headland_highres(svga_t *svga) svga->ma += 4; svga->ma &= svga->vram_mask; - if (svga->crtc[0x17] & 0x80) { - dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); - p[0] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[1] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); - p[2] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[3] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); - p[4] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[5] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); - p[6] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[7] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - } else - memset(p, 0x00, 8 * sizeof(uint32_t)); + dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); + p[0] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[1] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); + p[2] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[3] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); + p[4] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[5] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); + p[6] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[7] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; p += 8; } @@ -704,21 +680,18 @@ svga_render_4bpp_lowres(svga_t *svga) } svga->ma &= svga->vram_mask; - if (svga->crtc[0x17] & 0x80) { - dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); - p[0] = p[1] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[2] = p[3] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); - p[4] = p[5] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[6] = p[7] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); - p[8] = p[9] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[10] = p[11] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); - p[12] = p[13] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[14] = p[15] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - } else - memset(p, 0x00, 16 * sizeof(uint32_t)); + dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); + p[0] = p[1] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[2] = p[3] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); + p[4] = p[5] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[6] = p[7] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); + p[8] = p[9] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[10] = p[11] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); + p[12] = p[13] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[14] = p[15] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; p += 16; } @@ -749,21 +722,18 @@ svga_render_4bpp_lowres(svga_t *svga) } svga->ma &= svga->vram_mask; - if (svga->crtc[0x17] & 0x80) { - dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); - p[0] = p[1] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[2] = p[3] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); - p[4] = p[5] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[6] = p[7] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); - p[8] = p[9] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[10] = p[11] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); - p[12] = p[13] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[14] = p[15] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - } else - memset(p, 0x00, 16 * sizeof(uint32_t)); + dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); + p[0] = p[1] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[2] = p[3] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); + p[4] = p[5] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[6] = p[7] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); + p[8] = p[9] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[10] = p[11] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); + p[12] = p[13] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[14] = p[15] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; p += 16; } @@ -829,21 +799,18 @@ svga_render_4bpp_highres(svga_t *svga) } svga->ma &= svga->vram_mask; - if (svga->crtc[0x17] & 0x80) { - dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); - p[0] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[1] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); - p[2] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[3] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); - p[4] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[5] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); - p[6] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[7] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - } else - memset(p, 0x00, 8 * sizeof(uint32_t)); + dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); + p[0] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[1] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); + p[2] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[3] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); + p[4] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[5] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); + p[6] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[7] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; p += 8; } @@ -874,21 +841,18 @@ svga_render_4bpp_highres(svga_t *svga) } svga->ma &= svga->vram_mask; - if (svga->crtc[0x17] & 0x80) { - dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); - p[0] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[1] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); - p[2] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[3] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); - p[4] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[5] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); - p[6] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; - p[7] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; - } else - memset(p, 0x00, 8 * sizeof(uint32_t)); + dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); + p[0] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[1] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[(edat[0] >> 4) & 3][(edat[1] >> 4) & 3] | (edatlookup[(edat[2] >> 4) & 3][(edat[3] >> 4) & 3] << 2); + p[2] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[3] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[(edat[0] >> 2) & 3][(edat[1] >> 2) & 3] | (edatlookup[(edat[2] >> 2) & 3][(edat[3] >> 2) & 3] << 2); + p[4] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[5] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; + dat = edatlookup[edat[0] & 3][edat[1] & 3] | (edatlookup[edat[2] & 3][edat[3] & 3] << 2); + p[6] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask]]; + p[7] = svga->pallook[svga->egapal[dat & svga->plane_mask]]; p += 8; } @@ -1071,25 +1035,22 @@ svga_render_8bpp_tseng_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[0] = p[1] = svga->map8[dat & 0xff]; - dat >>= 8; - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[2] = p[3] = svga->map8[dat & 0xff]; - dat >>= 8; - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[4] = p[5] = svga->map8[dat & 0xff]; - dat >>= 8; - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[6] = p[7] = svga->map8[dat & 0xff]; - } else - memset(p, 0x00, 8 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[0] = p[1] = svga->map8[dat & 0xff]; + dat >>= 8; + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[2] = p[3] = svga->map8[dat & 0xff]; + dat >>= 8; + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[4] = p[5] = svga->map8[dat & 0xff]; + dat >>= 8; + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[6] = p[7] = svga->map8[dat & 0xff]; svga->ma += 4; p += 8; @@ -1117,42 +1078,39 @@ svga_render_8bpp_tseng_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp/* + svga->scrollcache*/); x += 8) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[0] = svga->map8[dat & 0xff]; - dat >>= 8; - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[1] = svga->map8[dat & 0xff]; - dat >>= 8; - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[2] = svga->map8[dat & 0xff]; - dat >>= 8; - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[3] = svga->map8[dat & 0xff]; + dat = *(uint32_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[0] = svga->map8[dat & 0xff]; + dat >>= 8; + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[1] = svga->map8[dat & 0xff]; + dat >>= 8; + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[2] = svga->map8[dat & 0xff]; + dat >>= 8; + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[3] = svga->map8[dat & 0xff]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[4] = svga->map8[dat & 0xff]; - dat >>= 8; - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[5] = svga->map8[dat & 0xff]; - dat >>= 8; - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[6] = svga->map8[dat & 0xff]; - dat >>= 8; - if (svga->attrregs[0x10] & 0x80) - dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); - p[7] = svga->map8[dat & 0xff]; - } else - memset(p, 0x00, 8 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[4] = svga->map8[dat & 0xff]; + dat >>= 8; + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[5] = svga->map8[dat & 0xff]; + dat >>= 8; + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[6] = svga->map8[dat & 0xff]; + dat >>= 8; + if (svga->attrregs[0x10] & 0x80) + dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); + p[7] = svga->map8[dat & 0xff]; svga->ma += 8; p += 8; @@ -1181,19 +1139,16 @@ svga_render_15bpp_lowres(svga_t *svga) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; - for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + if (svga->crtc[0x17] & 0x80) { + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - p[(x << 1)] = p[(x << 1) + 1] = video_15to32[dat & 0xffff]; - p[(x << 1) + 2] = p[(x << 1) + 3] = video_15to32[dat >> 16]; + p[(x << 1)] = p[(x << 1) + 1] = video_15to32[dat & 0xffff]; + p[(x << 1) + 2] = p[(x << 1) + 3] = video_15to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); - p[(x << 1) + 4] = p[(x << 1) + 5] = video_15to32[dat & 0xffff]; - p[(x << 1) + 6] = p[(x << 1) + 7] = video_15to32[dat >> 16]; - } else - memset(&(p[(x << 1)]), 0x00, 8 * sizeof(uint32_t)); + p[(x << 1) + 4] = p[(x << 1) + 5] = video_15to32[dat & 0xffff]; + p[(x << 1) + 6] = p[(x << 1) + 7] = video_15to32[dat >> 16]; } svga->ma += x << 1; svga->ma &= svga->vram_display_mask; @@ -1210,30 +1165,24 @@ svga_render_15bpp_lowres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - *p++ = video_15to32[dat & 0xffff]; - *p++ = video_15to32[dat >> 16]; + *p++ = video_15to32[dat & 0xffff]; + *p++ = video_15to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); - *p++ = video_15to32[dat & 0xffff]; - *p++ = video_15to32[dat >> 16]; - } else - memset(&(p[(x << 1)]), 0x00, 8 * sizeof(uint32_t)); + *p++ = video_15to32[dat & 0xffff]; + *p++ = video_15to32[dat >> 16]; } svga->ma += x << 1; } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 2) { - if (svga->crtc[0x17] & 0x80) { - addr = svga->remap_func(svga, svga->ma); - dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + addr = svga->remap_func(svga, svga->ma); + dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - *p++ = video_15to32[dat & 0xffff]; - *p++ = video_15to32[dat >> 16]; - } else - memset(&(p[x]), 0x00, 2 * sizeof(uint32_t)); + *p++ = video_15to32[dat & 0xffff]; + *p++ = video_15to32[dat >> 16]; svga->ma += 4; } } @@ -1263,24 +1212,21 @@ svga_render_15bpp_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - p[x] = video_15to32[dat & 0xffff]; - p[x + 1] = video_15to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + p[x] = video_15to32[dat & 0xffff]; + p[x + 1] = video_15to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); - p[x + 2] = video_15to32[dat & 0xffff]; - p[x + 3] = video_15to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + p[x + 2] = video_15to32[dat & 0xffff]; + p[x + 3] = video_15to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); - p[x + 4] = video_15to32[dat & 0xffff]; - p[x + 5] = video_15to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); + p[x + 4] = video_15to32[dat & 0xffff]; + p[x + 5] = video_15to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); - p[x + 6] = video_15to32[dat & 0xffff]; - p[x + 7] = video_15to32[dat >> 16]; - } else - memset(&(p[x]), 0x00, 8 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); + p[x + 6] = video_15to32[dat & 0xffff]; + p[x + 7] = video_15to32[dat >> 16]; } svga->ma += x << 1; svga->ma &= svga->vram_display_mask; @@ -1297,36 +1243,30 @@ svga_render_15bpp_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - *p++ = video_15to32[dat & 0xffff]; - *p++ = video_15to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + *p++ = video_15to32[dat & 0xffff]; + *p++ = video_15to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); - *p++ = video_15to32[dat & 0xffff]; - *p++ = video_15to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + *p++ = video_15to32[dat & 0xffff]; + *p++ = video_15to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); - *p++ = video_15to32[dat & 0xffff]; - *p++ = video_15to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); + *p++ = video_15to32[dat & 0xffff]; + *p++ = video_15to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); - *p++ = video_15to32[dat & 0xffff]; - *p++ = video_15to32[dat >> 16]; - } else - memset(&(p[x]), 0x00, 8 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); + *p++ = video_15to32[dat & 0xffff]; + *p++ = video_15to32[dat >> 16]; } svga->ma += x << 1; } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 2) { - if (svga->crtc[0x17] & 0x80) { - addr = svga->remap_func(svga, svga->ma); - dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + addr = svga->remap_func(svga, svga->ma); + dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - *p++ = video_15to32[dat & 0xffff]; - *p++ = video_15to32[dat >> 16]; - } else - memset(&(p[x]), 0x00, 2 * sizeof(uint32_t)); + *p++ = video_15to32[dat & 0xffff]; + *p++ = video_15to32[dat >> 16]; svga->ma += 4; } } @@ -1354,20 +1294,17 @@ svga_render_15bpp_mix_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - p[(x << 1)] = p[(x << 1) + 1] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + p[(x << 1)] = p[(x << 1) + 1] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - dat >>= 16; - p[(x << 1) + 2] = p[(x << 1) + 3] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat >>= 16; + p[(x << 1) + 2] = p[(x << 1) + 3] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); - p[(x << 1) + 4] = p[(x << 1) + 5] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + p[(x << 1) + 4] = p[(x << 1) + 5] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - dat >>= 16; - p[(x << 1) + 6] = p[(x << 1) + 7] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - } else - memset(&(p[(x << 1)]), 0x00, 8 * sizeof(uint32_t)); + dat >>= 16; + p[(x << 1) + 6] = p[(x << 1) + 7] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; } svga->ma += x << 1; svga->ma &= svga->vram_display_mask; @@ -1393,28 +1330,25 @@ svga_render_15bpp_mix_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - p[x] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - dat >>= 16; - p[x + 1] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + p[x] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat >>= 16; + p[x + 1] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); - p[x + 2] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - dat >>= 16; - p[x + 3] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + p[x + 2] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat >>= 16; + p[x + 3] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); - p[x + 4] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - dat >>= 16; - p[x + 5] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); + p[x + 4] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat >>= 16; + p[x + 5] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); - p[x + 6] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - dat >>= 16; - p[x + 7] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; - } else - memset(&(p[x]), 0x00, 8 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); + p[x + 6] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; + dat >>= 16; + p[x + 7] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; } svga->ma += x << 1; svga->ma &= svga->vram_display_mask; @@ -1442,16 +1376,13 @@ svga_render_16bpp_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - p[(x << 1)] = p[(x << 1) + 1] = video_16to32[dat & 0xffff]; - p[(x << 1) + 2] = p[(x << 1) + 3] = video_16to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + p[(x << 1)] = p[(x << 1) + 1] = video_16to32[dat & 0xffff]; + p[(x << 1) + 2] = p[(x << 1) + 3] = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); - p[(x << 1) + 4] = p[(x << 1) + 5] = video_16to32[dat & 0xffff]; - p[(x << 1) + 6] = p[(x << 1) + 7] = video_16to32[dat >> 16]; - } else - memset(&(p[(x << 1)]), 0x00, 8 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + p[(x << 1) + 4] = p[(x << 1) + 5] = video_16to32[dat & 0xffff]; + p[(x << 1) + 6] = p[(x << 1) + 7] = video_16to32[dat >> 16]; } svga->ma += x << 1; svga->ma &= svga->vram_display_mask; @@ -1468,30 +1399,24 @@ svga_render_16bpp_lowres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - *p++ = video_16to32[dat & 0xffff]; - *p++ = video_16to32[dat >> 16]; + *p++ = video_16to32[dat & 0xffff]; + *p++ = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); - *p++ = video_16to32[dat & 0xffff]; - *p++ = video_16to32[dat >> 16]; - } else - memset(&(p[(x << 1)]), 0x00, 8 * sizeof(uint32_t)); + *p++ = video_16to32[dat & 0xffff]; + *p++ = video_16to32[dat >> 16]; } svga->ma += x << 1; } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 2) { - if (svga->crtc[0x17] & 0x80) { addr = svga->remap_func(svga, svga->ma); dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); *p++ = video_16to32[dat & 0xffff]; *p++ = video_16to32[dat >> 16]; - } else - memset(&(p[x]), 0x00, 2 * sizeof(uint32_t)); } svga->ma += 4; } @@ -1521,24 +1446,21 @@ svga_render_16bpp_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - if (svga->crtc[0x17] & 0x80) { - uint32_t dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - p[x] = video_16to32[dat & 0xffff]; - p[x + 1] = video_16to32[dat >> 16]; + uint32_t dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + p[x] = video_16to32[dat & 0xffff]; + p[x + 1] = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); - p[x + 2] = video_16to32[dat & 0xffff]; - p[x + 3] = video_16to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + p[x + 2] = video_16to32[dat & 0xffff]; + p[x + 3] = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); - p[x + 4] = video_16to32[dat & 0xffff]; - p[x + 5] = video_16to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); + p[x + 4] = video_16to32[dat & 0xffff]; + p[x + 5] = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); - p[x + 6] = video_16to32[dat & 0xffff]; - p[x + 7] = video_16to32[dat >> 16]; - } else - memset(&(p[x]), 0x00, 8 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); + p[x + 6] = video_16to32[dat & 0xffff]; + p[x + 7] = video_16to32[dat >> 16]; } svga->ma += x << 1; svga->ma &= svga->vram_display_mask; @@ -1555,36 +1477,30 @@ svga_render_16bpp_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); - *p++ = video_16to32[dat & 0xffff]; - *p++ = video_16to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + *p++ = video_16to32[dat & 0xffff]; + *p++ = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); - *p++ = video_16to32[dat & 0xffff]; - *p++ = video_16to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + *p++ = video_16to32[dat & 0xffff]; + *p++ = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); - *p++ = video_16to32[dat & 0xffff]; - *p++ = video_16to32[dat >> 16]; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); + *p++ = video_16to32[dat & 0xffff]; + *p++ = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); - *p++ = video_16to32[dat & 0xffff]; - *p++ = video_16to32[dat >> 16]; - } else - memset(&(p[x]), 0x00, 8 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); + *p++ = video_16to32[dat & 0xffff]; + *p++ = video_16to32[dat >> 16]; } svga->ma += x << 1; } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 2) { - if (svga->crtc[0x17] & 0x80) { - addr = svga->remap_func(svga, svga->ma); - dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + addr = svga->remap_func(svga, svga->ma); + dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - *p++ = video_16to32[dat & 0xffff]; - *p++ = video_16to32[dat >> 16]; - } else - memset(&(p[x]), 0x00, 2 * sizeof(uint32_t)); + *p++ = video_16to32[dat & 0xffff]; + *p++ = video_16to32[dat >> 16]; svga->ma += 4; } @@ -1617,10 +1533,7 @@ svga_render_24bpp_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) - fg = svga->vram[svga->ma] | (svga->vram[svga->ma + 1] << 8) | (svga->vram[svga->ma + 2] << 16); - else - fg = 0x00000000; + fg = svga->vram[svga->ma] | (svga->vram[svga->ma + 1] << 8) | (svga->vram[svga->ma + 2] << 16); svga->ma += 3; svga->ma &= svga->vram_display_mask; buffer32->line[svga->displine + svga->y_add][(x << 1) + svga->x_add] = @@ -1639,12 +1552,9 @@ svga_render_24bpp_lowres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - dat0 = *(uint32_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); - dat1 = *(uint32_t *)(&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); - dat2 = *(uint32_t *)(&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); - } else - dat0 = dat1 = dat2 = 0x00000000; + dat0 = *(uint32_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); + dat1 = *(uint32_t *)(&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); + dat2 = *(uint32_t *)(&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); p[0] = p[1] = dat0 & 0xffffff; p[2] = p[3] = (dat0 >> 24) | ((dat1 & 0xffff) << 8); @@ -1655,15 +1565,12 @@ svga_render_24bpp_lowres(svga_t *svga) } } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - if (svga->crtc[0x17] & 0x80) { - addr = svga->remap_func(svga, svga->ma); - dat0 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - addr = svga->remap_func(svga, svga->ma + 4); - dat1 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - addr = svga->remap_func(svga, svga->ma + 8); - dat2 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - } else - dat0 = dat1 = dat2 = 0x00000000; + addr = svga->remap_func(svga, svga->ma); + dat0 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + addr = svga->remap_func(svga, svga->ma + 4); + dat1 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + addr = svga->remap_func(svga, svga->ma + 8); + dat2 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); p[0] = p[1] = dat0 & 0xffffff; p[2] = p[3] = (dat0 >> 24) | ((dat1 & 0xffff) << 8); @@ -1700,20 +1607,17 @@ svga_render_24bpp_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); - p[x] = dat & 0xffffff; + dat = *(uint32_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); + p[x] = dat & 0xffffff; - dat = *(uint32_t *)(&svga->vram[(svga->ma + 3) & svga->vram_display_mask]); - p[x + 1] = dat & 0xffffff; + dat = *(uint32_t *)(&svga->vram[(svga->ma + 3) & svga->vram_display_mask]); + p[x + 1] = dat & 0xffffff; - dat = *(uint32_t *)(&svga->vram[(svga->ma + 6) & svga->vram_display_mask]); - p[x + 2] = dat & 0xffffff; + dat = *(uint32_t *)(&svga->vram[(svga->ma + 6) & svga->vram_display_mask]); + p[x + 2] = dat & 0xffffff; - dat = *(uint32_t *)(&svga->vram[(svga->ma + 9) & svga->vram_display_mask]); - p[x + 3] = dat & 0xffffff; - } else - memset(&(p[x]), 0x0, 4 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + 9) & svga->vram_display_mask]); + p[x + 3] = dat & 0xffffff; svga->ma += 12; } @@ -1731,36 +1635,30 @@ svga_render_24bpp_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - if (svga->crtc[0x17] & 0x80) { - dat0 = *(uint32_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); - dat1 = *(uint32_t *)(&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); - dat2 = *(uint32_t *)(&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); + dat0 = *(uint32_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); + dat1 = *(uint32_t *)(&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); + dat2 = *(uint32_t *)(&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); - *p++ = dat0 & 0xffffff; - *p++ = (dat0 >> 24) | ((dat1 & 0xffff) << 8); - *p++ = (dat1 >> 16) | ((dat2 & 0xff) << 16); - *p++ = dat2 >> 8; - } else - memset(&(p[x]), 0x0, 4 * sizeof(uint32_t)); + *p++ = dat0 & 0xffffff; + *p++ = (dat0 >> 24) | ((dat1 & 0xffff) << 8); + *p++ = (dat1 >> 16) | ((dat2 & 0xff) << 16); + *p++ = dat2 >> 8; svga->ma += 12; } } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - if (svga->crtc[0x17] & 0x80) { - addr = svga->remap_func(svga, svga->ma); - dat0 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - addr = svga->remap_func(svga, svga->ma + 4); - dat1 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - addr = svga->remap_func(svga, svga->ma + 8); - dat2 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + addr = svga->remap_func(svga, svga->ma); + dat0 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + addr = svga->remap_func(svga, svga->ma + 4); + dat1 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + addr = svga->remap_func(svga, svga->ma + 8); + dat2 = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - *p++ = dat0 & 0xffffff; - *p++ = (dat0 >> 24) | ((dat1 & 0xffff) << 8); - *p++ = (dat1 >> 16) | ((dat2 & 0xff) << 16); - *p++ = dat2 >> 8; - } else - memset(&(p[x]), 0x0, 4 * sizeof(uint32_t)); + *p++ = dat0 & 0xffffff; + *p++ = (dat0 >> 24) | ((dat1 & 0xffff) << 8); + *p++ = (dat1 >> 16) | ((dat2 & 0xff) << 16); + *p++ = dat2 >> 8; svga->ma += 12; } @@ -1789,10 +1687,7 @@ svga_render_32bpp_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) - dat = svga->vram[svga->ma] | (svga->vram[svga->ma + 1] << 8) | (svga->vram[svga->ma + 2] << 16); - else - dat = 0x00000000; + dat = svga->vram[svga->ma] | (svga->vram[svga->ma + 1] << 8) | (svga->vram[svga->ma + 2] << 16); svga->ma += 4; svga->ma &= svga->vram_display_mask; buffer32->line[svga->displine + svga->y_add][(x << 1) + svga->x_add] = @@ -1811,21 +1706,15 @@ svga_render_32bpp_lowres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); - else - dat = 0x00000000; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); *p++ = dat & 0xffffff; *p++ = dat & 0xffffff; } svga->ma += (x * 4); } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - addr = svga->remap_func(svga, svga->ma); - dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - } else - dat = 0x00000000; + addr = svga->remap_func(svga, svga->ma); + dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); *p++ = dat & 0xffffff; *p++ = dat & 0xffffff; svga->ma += 4; @@ -1857,10 +1746,7 @@ svga_render_32bpp_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); - else - dat = 0x00000000; + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); p[x] = dat & 0xffffff; } svga->ma += 4; @@ -1878,21 +1764,15 @@ svga_render_32bpp_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); - *p++ = dat & 0xffffff; - } else - memset(&(p[x]), 0x0, 1 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); + *p++ = dat & 0xffffff; } svga->ma += (x * 4); } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - addr = svga->remap_func(svga, svga->ma); - dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - *p++ = dat & 0xffffff; - } else - memset(&(p[x]), 0x0, 1 * sizeof(uint32_t)); + addr = svga->remap_func(svga, svga->ma); + dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + *p++ = dat & 0xffffff; svga->ma += 4; } @@ -1925,21 +1805,15 @@ svga_render_ABGR8888_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); - *p++ = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); - } else - memset(&(p[x]), 0x0, 1 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); + *p++ = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); } svga->ma += x*4; } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - addr = svga->remap_func(svga, svga->ma); - dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - *p++ = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); - } else - memset(&(p[x]), 0x0, 1 * sizeof(uint32_t)); + addr = svga->remap_func(svga, svga->ma); + dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + *p++ = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); svga->ma += 4; } @@ -1971,21 +1845,15 @@ svga_render_RGBA8888_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); - *p++ = dat >> 8; - } else - memset(&(p[x]), 0x0, 1 * sizeof(uint32_t)); + dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); + *p++ = dat >> 8; } svga->ma += (x * 4); } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - addr = svga->remap_func(svga, svga->ma); - dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); - *p++ = dat >> 8; - } else - memset(&(p[x]), 0x0, 1 * sizeof(uint32_t)); + addr = svga->remap_func(svga, svga->ma); + dat = *(uint32_t *)(&svga->vram[addr & svga->vram_display_mask]); + *p++ = dat >> 8; svga->ma += 4; } From a555b9312dc15ad6ef34dfb7df573ea0edee24ee Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 18 Jul 2022 23:58:22 +0200 Subject: [PATCH 074/386] And the IBM RAMDAC renderers as well. --- src/video/vid_ibm_rgb528_ramdac.c | 243 ++++++++++++++---------------- 1 file changed, 114 insertions(+), 129 deletions(-) diff --git a/src/video/vid_ibm_rgb528_ramdac.c b/src/video/vid_ibm_rgb528_ramdac.c index d70732553..f119e722e 100644 --- a/src/video/vid_ibm_rgb528_ramdac.c +++ b/src/video/vid_ibm_rgb528_ramdac.c @@ -101,40 +101,37 @@ ibm_rgb528_render_4bpp(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - if (vram_size == 3) { - if (!(x & 31)) { - dat64 = *(uint64_t *)(&svga->vram[svga->ma]); - dat642 = *(uint64_t *)(&svga->vram[svga->ma + 8]); - if (swap_word) { - dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); - dat642 = (dat642 << 32ULL) | (dat642 >> 32ULL); - } + if (vram_size == 3) { + if (!(x & 31)) { + dat64 = *(uint64_t *)(&svga->vram[svga->ma]); + dat642 = *(uint64_t *)(&svga->vram[svga->ma + 8]); + if (swap_word) { + dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); + dat642 = (dat642 << 32ULL) | (dat642 >> 32ULL); } - if (swap_nib) - dat = (((x & 16) ? dat642 : dat64) >> ((x & 15) << 2)) & 0xf; - else - dat = (((x & 16) ? dat642 : dat64) >> (((x & 15) << 2) ^ 4)) & 0xf; - } else if (vram_size == 1) { - if (!(x & 15)) { - dat64 = *(uint64_t *)(&svga->vram[svga->ma]); - if (swap_word) - dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); - } - if (swap_nib) - dat = (dat64 >> ((x & 15) << 2)) & 0xf; - else - dat = (dat64 >> (((x & 15) << 2) ^ 4)) & 0xf; - } else { - if (!(x & 7)) - dat32 = *(uint32_t *)(&svga->vram[svga->ma]); - if (swap_nib) - dat = (dat32 >> ((x & 7) << 2)) & 0xf; - else - dat = (dat32 >> (((x & 7) << 2) ^ 4)) & 0xf; } - } else - dat = 0x00000000; + if (swap_nib) + dat = (((x & 16) ? dat642 : dat64) >> ((x & 15) << 2)) & 0xf; + else + dat = (((x & 16) ? dat642 : dat64) >> (((x & 15) << 2) ^ 4)) & 0xf; + } else if (vram_size == 1) { + if (!(x & 15)) { + dat64 = *(uint64_t *)(&svga->vram[svga->ma]); + if (swap_word) + dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); + } + if (swap_nib) + dat = (dat64 >> ((x & 15) << 2)) & 0xf; + else + dat = (dat64 >> (((x & 15) << 2) ^ 4)) & 0xf; + } else { + if (!(x & 7)) + dat32 = *(uint32_t *)(&svga->vram[svga->ma]); + if (swap_nib) + dat = (dat32 >> ((x & 7) << 2)) & 0xf; + else + dat = (dat32 >> (((x & 7) << 2) ^ 4)) & 0xf; + } if (b8_dcol == 0x00) { dat_out.a = 0x00; dat_out.r = ramdac->palettes[0][partition | dat]; @@ -184,31 +181,28 @@ ibm_rgb528_render_8bpp(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - if (vram_size == 3) { - if (!(x & 15)) { - dat64 = *(uint64_t *)(&svga->vram[svga->ma]); - dat642 = *(uint64_t *)(&svga->vram[svga->ma + 8]); - if (swap_word) { - dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); - dat642 = (dat642 << 32ULL) | (dat642 >> 32ULL); - } + if (vram_size == 3) { + if (!(x & 15)) { + dat64 = *(uint64_t *)(&svga->vram[svga->ma]); + dat642 = *(uint64_t *)(&svga->vram[svga->ma + 8]); + if (swap_word) { + dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); + dat642 = (dat642 << 32ULL) | (dat642 >> 32ULL); } - dat = (((x & 8) ? dat642 : dat64) >> ((x & 7) << 3)) & 0xff; - } else if (vram_size == 1) { - if (!(x & 7)) { - dat64 = *(uint64_t *)(&svga->vram[svga->ma]); - if (swap_word) - dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); - } - dat = (dat64 >> ((x & 7) << 3)) & 0xff; - } else { - if (!(x & 3)) - dat32 = *(uint32_t *)(&svga->vram[svga->ma]); - dat = (dat32 >> ((x & 3) << 3)) & 0xff; } - } else - dat = 0x00000000; + dat = (((x & 8) ? dat642 : dat64) >> ((x & 7) << 3)) & 0xff; + } else if (vram_size == 1) { + if (!(x & 7)) { + dat64 = *(uint64_t *)(&svga->vram[svga->ma]); + if (swap_word) + dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); + } + dat = (dat64 >> ((x & 7) << 3)) & 0xff; + } else { + if (!(x & 3)) + dat32 = *(uint32_t *)(&svga->vram[svga->ma]); + dat = (dat32 >> ((x & 3) << 3)) & 0xff; + } if (b8_dcol == 0x00) { dat_out.a = 0x00; dat_out.r = ramdac->palettes[0][dat]; @@ -268,31 +262,28 @@ ibm_rgb528_render_15_16bpp(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - if (vram_size == 2) { - if (!(x & 7)) { - dat64 = *(uint64_t *)(&svga->vram[svga->ma]); - dat642 = *(uint64_t *)(&svga->vram[svga->ma + 8]); - if (swap_word) { - dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); - dat642 = (dat64 << 32ULL) | (dat642 >> 32ULL); - } + if (vram_size == 2) { + if (!(x & 7)) { + dat64 = *(uint64_t *)(&svga->vram[svga->ma]); + dat642 = *(uint64_t *)(&svga->vram[svga->ma + 8]); + if (swap_word) { + dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); + dat642 = (dat64 << 32ULL) | (dat642 >> 32ULL); } - dat = (((x & 4) ? dat642 : dat64) >> ((x & 3) << 4)) & 0xffff; - } else if (vram_size == 1) { - if (!(x & 3)) { - dat64 = *(uint64_t *)(&svga->vram[svga->ma]); - if (swap_word) - dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); - } - dat = (dat64 >> ((x & 3) << 4)) & 0xffff; - } else { - if (!(x & 1)) - dat32 = *(uint32_t *)(&svga->vram[svga->ma]); - dat = (dat32 >> ((x & 1) << 4)) & 0xffff; } - } else - dat = 0x00000000; + dat = (((x & 4) ? dat642 : dat64) >> ((x & 3) << 4)) & 0xffff; + } else if (vram_size == 1) { + if (!(x & 3)) { + dat64 = *(uint64_t *)(&svga->vram[svga->ma]); + if (swap_word) + dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); + } + dat = (dat64 >> ((x & 3) << 4)) & 0xffff; + } else { + if (!(x & 1)) + dat32 = *(uint32_t *)(&svga->vram[svga->ma]); + dat = (dat32 >> ((x & 1) << 4)) & 0xffff; + } dat_ex = (ibm_rgb528_pixel16_t *) &dat; if (b555_565 && (b16_dcol != 0x01)) { if (swaprb) { @@ -389,39 +380,36 @@ ibm_rgb528_render_24bpp(svga_t *svga) for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { dat_ex = (ibm_rgb528_pixel32_t *) &dat; - if (svga->crtc[0x17] & 0x80) { - if (vram_size == 3) { - if ((x & 15) == 0) { - dat64[0] = *(uint64_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); - dat64[1] = *(uint64_t *)(&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); - dat64[2] = *(uint64_t *)(&svga->vram[(svga->ma + 16) & svga->vram_display_mask]); - dat64[3] = *(uint64_t *)(&svga->vram[(svga->ma + 24) & svga->vram_display_mask]); - dat64[4] = *(uint64_t *)(&svga->vram[(svga->ma + 32) & svga->vram_display_mask]); - dat64[5] = *(uint64_t *)(&svga->vram[(svga->ma + 40) & svga->vram_display_mask]); - if (swap_word) { - dat64[0] = (dat64[0] << 32ULL) | (dat64[0] >> 32ULL); - dat64[1] = (dat64[1] << 32ULL) | (dat64[1] >> 32ULL); - dat64[2] = (dat64[2] << 32ULL) | (dat64[2] >> 32ULL); - dat64[3] = (dat64[3] << 32ULL) | (dat64[3] >> 32ULL); - dat64[4] = (dat64[4] << 32ULL) | (dat64[4] >> 32ULL); - dat64[5] = (dat64[5] << 32ULL) | (dat64[5] >> 32ULL); - } + if (vram_size == 3) { + if ((x & 15) == 0) { + dat64[0] = *(uint64_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); + dat64[1] = *(uint64_t *)(&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); + dat64[2] = *(uint64_t *)(&svga->vram[(svga->ma + 16) & svga->vram_display_mask]); + dat64[3] = *(uint64_t *)(&svga->vram[(svga->ma + 24) & svga->vram_display_mask]); + dat64[4] = *(uint64_t *)(&svga->vram[(svga->ma + 32) & svga->vram_display_mask]); + dat64[5] = *(uint64_t *)(&svga->vram[(svga->ma + 40) & svga->vram_display_mask]); + if (swap_word) { + dat64[0] = (dat64[0] << 32ULL) | (dat64[0] >> 32ULL); + dat64[1] = (dat64[1] << 32ULL) | (dat64[1] >> 32ULL); + dat64[2] = (dat64[2] << 32ULL) | (dat64[2] >> 32ULL); + dat64[3] = (dat64[3] << 32ULL) | (dat64[3] >> 32ULL); + dat64[4] = (dat64[4] << 32ULL) | (dat64[4] >> 32ULL); + dat64[5] = (dat64[5] << 32ULL) | (dat64[5] >> 32ULL); } - dat_ex = (ibm_rgb528_pixel32_t *) &(dat8[((x & 15) * 3)]); - } else if (vram_size == 1) { - if ((x & 7) == 0) { - dat64[0] = *(uint64_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); - dat64[1] = *(uint64_t *)(&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); - dat64[2] = *(uint64_t *)(&svga->vram[(svga->ma + 16) & svga->vram_display_mask]); - if (swap_word) { - dat64[0] = (dat64[0] << 32ULL) | (dat64[0] >> 32ULL); - dat64[1] = (dat64[1] << 32ULL) | (dat64[1] >> 32ULL); - dat64[2] = (dat64[2] << 32ULL) | (dat64[2] >> 32ULL); - } + } + dat_ex = (ibm_rgb528_pixel32_t *) &(dat8[((x & 15) * 3)]); + } else if (vram_size == 1) { + if ((x & 7) == 0) { + dat64[0] = *(uint64_t *)(&svga->vram[svga->ma & svga->vram_display_mask]); + dat64[1] = *(uint64_t *)(&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); + dat64[2] = *(uint64_t *)(&svga->vram[(svga->ma + 16) & svga->vram_display_mask]); + if (swap_word) { + dat64[0] = (dat64[0] << 32ULL) | (dat64[0] >> 32ULL); + dat64[1] = (dat64[1] << 32ULL) | (dat64[1] >> 32ULL); + dat64[2] = (dat64[2] << 32ULL) | (dat64[2] >> 32ULL); } - dat_ex = (ibm_rgb528_pixel32_t *) &(dat8[((x & 7) * 3)]); - } else - dat = 0x00000000; + } + dat_ex = (ibm_rgb528_pixel32_t *) &(dat8[((x & 7) * 3)]); } else dat = 0x00000000; if (swaprb) { @@ -482,28 +470,25 @@ ibm_rgb528_render_32bpp(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - if (svga->crtc[0x17] & 0x80) { - if (vram_size == 3) { - if (!(x & 3)) { - dat64 = *(uint64_t *)(&svga->vram[svga->ma]); - dat642 = *(uint64_t *)(&svga->vram[svga->ma + 8]); - if (swap_word) { - dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); - dat642 = (dat642 << 32ULL) | (dat642 >> 32ULL); - } + if (vram_size == 3) { + if (!(x & 3)) { + dat64 = *(uint64_t *)(&svga->vram[svga->ma]); + dat642 = *(uint64_t *)(&svga->vram[svga->ma + 8]); + if (swap_word) { + dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); + dat642 = (dat642 << 32ULL) | (dat642 >> 32ULL); } - dat = (((x & 2) ? dat642 : dat64) >> ((x & 1ULL) << 5ULL)) & 0xffffffff; - } else if (vram_size == 1) { - if (!(x & 1)) { - dat64 = *(uint64_t *)(&svga->vram[svga->ma]); - if (swap_word) - dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); - } - dat = (dat64 >> ((x & 1ULL) << 5ULL)) & 0xffffffff; - } else - dat = *(uint32_t *)(&svga->vram[svga->ma]); + } + dat = (((x & 2) ? dat642 : dat64) >> ((x & 1ULL) << 5ULL)) & 0xffffffff; + } else if (vram_size == 1) { + if (!(x & 1)) { + dat64 = *(uint64_t *)(&svga->vram[svga->ma]); + if (swap_word) + dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); + } + dat = (dat64 >> ((x & 1ULL) << 5ULL)) & 0xffffffff; } else - dat = 0x00000000; + dat = *(uint32_t *)(&svga->vram[svga->ma]); dat_ex = (ibm_rgb528_pixel32_t *) &dat; if (swaprb) { temp = dat_ex->r; From 33c5f9397ea3162b5e3901feae34ff3cce5b5789 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 19 Jul 2022 00:14:29 +0200 Subject: [PATCH 075/386] (S)VGA renderer fixes. --- src/video/vid_svga_render.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/video/vid_svga_render.c b/src/video/vid_svga_render.c index c4b817fd4..17b4c4981 100644 --- a/src/video/vid_svga_render.c +++ b/src/video/vid_svga_render.c @@ -1126,20 +1126,20 @@ svga_render_15bpp_lowres(svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t changed_addr, addr; + uint32_t changed_addr, addr; if ((svga->displine + svga->y_add) < 0) - return; + return; - if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->force_old_addr) { + if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { p = &buffer32->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; - if (svga->crtc[0x17] & 0x80) { + for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { dat = *(uint32_t *)(&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); p[(x << 1)] = p[(x << 1) + 1] = video_15to32[dat & 0xffff]; @@ -1152,11 +1152,11 @@ svga_render_15bpp_lowres(svga_t *svga) } svga->ma += x << 1; svga->ma &= svga->vram_display_mask; - } - } else { - changed_addr = svga->remap_func(svga, svga->ma); + } + } else { + changed_addr = svga->remap_func(svga, svga->ma); - if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1187,8 +1187,8 @@ svga_render_15bpp_lowres(svga_t *svga) } } svga->ma &= svga->vram_display_mask; - } } + } } @@ -1198,13 +1198,13 @@ svga_render_15bpp_highres(svga_t *svga) int x; uint32_t *p; uint32_t dat; - uint32_t changed_addr, addr; + uint32_t changed_addr, addr; if ((svga->displine + svga->y_add) < 0) return; - if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->force_old_addr) { + if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { p = &buffer32->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1230,11 +1230,11 @@ svga_render_15bpp_highres(svga_t *svga) } svga->ma += x << 1; svga->ma &= svga->vram_display_mask; - } - } else { - changed_addr = svga->remap_func(svga, svga->ma); + } + } else { + changed_addr = svga->remap_func(svga, svga->ma); - if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1271,8 +1271,8 @@ svga_render_15bpp_highres(svga_t *svga) } } svga->ma &= svga->vram_display_mask; - } } + } } From 1d0177289a8c15652bff48f45143b972ebf416e9 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 19 Jul 2022 00:15:25 +0200 Subject: [PATCH 076/386] PCI graphics cards initialization fixes. --- src/video/vid_ati_mach64.c | 17 ++++++++++------- src/video/vid_cl54xx.c | 11 +++++++++-- src/video/vid_tgui9440.c | 7 +++++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/video/vid_ati_mach64.c b/src/video/vid_ati_mach64.c index a5325e8f7..7f4e2c7c9 100644 --- a/src/video/vid_ati_mach64.c +++ b/src/video/vid_ati_mach64.c @@ -3532,13 +3532,10 @@ static void *mach64_common_init(const device_t *info) mach64_overlay_draw); mach64->svga.dac_hwcursor.cur_ysize = 64; - if (info->flags & DEVICE_PCI) - mem_mapping_disable(&mach64->bios_rom.mapping); - - mem_mapping_add(&mach64->linear_mapping, 0, 0, svga_read_linear, svga_readw_linear, svga_readl_linear, svga_write_linear, svga_writew_linear, svga_writel_linear, NULL, MEM_MAPPING_EXTERNAL, &mach64->svga); - mem_mapping_add(&mach64->mmio_linear_mapping, 0, 0, mach64_ext_readb, mach64_ext_readw, mach64_ext_readl, mach64_ext_writeb, mach64_ext_writew, mach64_ext_writel, NULL, MEM_MAPPING_EXTERNAL, mach64); - mem_mapping_add(&mach64->mmio_linear_mapping_2, 0, 0, mach64_ext_readb, mach64_ext_readw, mach64_ext_readl, mach64_ext_writeb, mach64_ext_writew, mach64_ext_writel, NULL, MEM_MAPPING_EXTERNAL, mach64); - mem_mapping_add(&mach64->mmio_mapping, 0xbc000, 0x04000, mach64_ext_readb, mach64_ext_readw, mach64_ext_readl, mach64_ext_writeb, mach64_ext_writew, mach64_ext_writel, NULL, MEM_MAPPING_EXTERNAL, mach64); + mem_mapping_add(&mach64->linear_mapping, 0, 0, svga_read_linear, svga_readw_linear, svga_readl_linear, svga_write_linear, svga_writew_linear, svga_writel_linear, NULL, MEM_MAPPING_EXTERNAL, &mach64->svga); + mem_mapping_add(&mach64->mmio_linear_mapping, 0, 0, mach64_ext_readb, mach64_ext_readw, mach64_ext_readl, mach64_ext_writeb, mach64_ext_writew, mach64_ext_writel, NULL, MEM_MAPPING_EXTERNAL, mach64); + mem_mapping_add(&mach64->mmio_linear_mapping_2, 0, 0, mach64_ext_readb, mach64_ext_readw, mach64_ext_readl, mach64_ext_writeb, mach64_ext_writew, mach64_ext_writel, NULL, MEM_MAPPING_EXTERNAL, mach64); + mem_mapping_add(&mach64->mmio_mapping, 0xbc000, 0x04000, mach64_ext_readb, mach64_ext_readw, mach64_ext_readl, mach64_ext_writeb, mach64_ext_writew, mach64_ext_writel, NULL, MEM_MAPPING_EXTERNAL, mach64); mem_mapping_disable(&mach64->mmio_mapping); mach64_io_set(mach64); @@ -3604,6 +3601,9 @@ static void *mach64gx_init(const device_t *info) else if (info->flags & DEVICE_ISA) rom_init(&mach64->bios_rom, BIOS_ISA_ROM_PATH, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + if (info->flags & DEVICE_PCI) + mem_mapping_disable(&mach64->bios_rom.mapping); + return mach64; } static void *mach64vt2_init(const device_t *info) @@ -3628,6 +3628,9 @@ static void *mach64vt2_init(const device_t *info) rom_init(&mach64->bios_rom, BIOS_ROMVT2_PATH, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + if (info->flags & DEVICE_PCI) + mem_mapping_disable(&mach64->bios_rom.mapping); + svga->vblank_start = mach64_vblank_start; return mach64; diff --git a/src/video/vid_cl54xx.c b/src/video/vid_cl54xx.c index b4a7057f0..174dc5037 100644 --- a/src/video/vid_cl54xx.c +++ b/src/video/vid_cl54xx.c @@ -3708,6 +3708,11 @@ cl_pci_write(int func, int addr, uint8_t val, void *p) io_sethandler(0x03c0, 0x0020, gd54xx_in, NULL, NULL, gd54xx_out, NULL, NULL, gd54xx); if ((val & PCI_COMMAND_MEM) && (gd54xx->vgablt_base != 0x00000000) && (gd54xx->vgablt_base < 0xfff00000)) mem_mapping_set_addr(&gd54xx->vgablt_mapping, gd54xx->vgablt_base, 0x1000); + if ((gd54xx->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_MEM) && (gd54xx->pci_regs[0x30] & 0x01)) { + uint32_t addr = (gd54xx->pci_regs[0x32] << 16) | (gd54xx->pci_regs[0x33] << 24); + mem_mapping_set_addr(&gd54xx->bios_rom.mapping, addr, 0x8000); + } else + mem_mapping_disable(&gd54xx->bios_rom.mapping); gd543x_recalc_mapping(gd54xx); break; @@ -3735,7 +3740,7 @@ cl_pci_write(int func, int addr, uint8_t val, void *p) case 0x30: case 0x32: case 0x33: gd54xx->pci_regs[addr] = val; - if (gd54xx->pci_regs[0x30] & 0x01) { + if ((gd54xx->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_MEM) && (gd54xx->pci_regs[0x30] & 0x01)) { uint32_t addr = (gd54xx->pci_regs[0x32] << 16) | (gd54xx->pci_regs[0x33] << 24); mem_mapping_set_addr(&gd54xx->bios_rom.mapping, addr, 0x8000); } else @@ -4061,8 +4066,10 @@ static void } io_sethandler(0x03c0, 0x0020, gd54xx_in, NULL, NULL, gd54xx_out, NULL, NULL, gd54xx); - if (gd54xx->pci && id >= CIRRUS_ID_CLGD5430) + if (gd54xx->pci && id >= CIRRUS_ID_CLGD5430) { pci_add_card(PCI_ADD_VIDEO, cl_pci_read, cl_pci_write, gd54xx); + mem_mapping_disable(&gd54xx->bios_rom.mapping); + } mem_mapping_set_p(&svga->mapping, gd54xx); mem_mapping_disable(&gd54xx->mmio_mapping); diff --git a/src/video/vid_tgui9440.c b/src/video/vid_tgui9440.c index 603acccb9..a4fd83a0e 100644 --- a/src/video/vid_tgui9440.c +++ b/src/video/vid_tgui9440.c @@ -3079,8 +3079,11 @@ static void *tgui_init(const device_t *info) tgui->has_bios = (bios_fn != NULL); - if (tgui->has_bios) + if (tgui->has_bios) { rom_init(&tgui->bios_rom, (char *) bios_fn, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); + if (tgui->pci) + mem_mapping_disable(&tgui->bios_rom.mapping); + } if (tgui->pci) video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_tgui_pci); @@ -3107,7 +3110,7 @@ static void *tgui_init(const device_t *info) if (tgui->pci && (tgui->type >= TGUI_9440)) { if (tgui->has_bios) - tgui->card = pci_add_card(PCI_ADD_VIDEO, tgui_pci_read, tgui_pci_write, tgui); + tgui->card = pci_add_card(PCI_ADD_VIDEO, tgui_pci_read, tgui_pci_write, tgui); else tgui->card = pci_add_card(PCI_ADD_VIDEO | PCI_ADD_STRICT, tgui_pci_read, tgui_pci_write, tgui); } From f4f886060610166992fa0d059784cb639d29029b Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 19 Jul 2022 00:16:46 +0200 Subject: [PATCH 077/386] The Performance/EU should *NOT* have been there. --- src/machine/machine_table.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index ac4a4e9c7..7a0873f20 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -842,10 +842,6 @@ const machine_t machines[] = { /* 450KX */ /* This has an AMIKey-2, which is an updated version of type 'H'. */ { "[i450KX] ASUS P/I-P6RP4", "p6rp4", MACHINE_TYPE_SOCKET8, MACHINE_CHIPSET_INTEL_450KX, machine_at_p6rp4_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_SOCKET8, CPU_BLOCK_NONE, 60000000, 66666667, 2100, 3500, 1.5, 8.0, MACHINE_PS2_PCI, MACHINE_IDE_DUAL, 8192, 524288, 8192, 127, NULL, NULL }, - /* According to tests from real hardware: This has AMI MegaKey KBC firmware on the - PC87306 Super I/O chip, command 0xA1 returns '5'. - Command 0xA0 copyright string: (C)1994 AMI . */ - { "[i450KX] Intel Performance/AU", "aurora", MACHINE_TYPE_SOCKET8, MACHINE_CHIPSET_INTEL_450KX, machine_at_aurora_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_SOCKET8, CPU_BLOCK_NONE, 60000000, 66666667, 2100, 3500, 1.5, 8.0, MACHINE_PS2_PCI, MACHINE_IDE_DUAL, 8192, 524288, 8192, 127, NULL, NULL }, /* 440FX */ /* Has the SMC FDC73C935's on-chip KBC with Phoenix MultiKey firmware. */ From 46f65405420ec2a3e9beaa169ce937a67a9bfa8e Mon Sep 17 00:00:00 2001 From: Adrien Moulin Date: Tue, 19 Jul 2022 11:31:06 +0200 Subject: [PATCH 078/386] hdd: make speed preset configurable This includes settings UI for Qt --- src/config.c | 19 ++++ src/disk/hdc_ide.c | 2 +- src/disk/hdd.c | 153 ++++++++++++++++++++------------ src/include/86box/hdd.h | 13 ++- src/qt/qt_harddiskdialog.cpp | 6 ++ src/qt/qt_harddiskdialog.hpp | 1 + src/qt/qt_harddiskdialog.ui | 10 +++ src/qt/qt_harddrive_common.cpp | 21 +++++ src/qt/qt_harddrive_common.hpp | 1 + src/qt/qt_settingsharddisks.cpp | 32 ++++++- src/qt/qt_settingsharddisks.hpp | 1 + src/qt/qt_settingsharddisks.ui | 10 +++ 12 files changed, 206 insertions(+), 63 deletions(-) diff --git a/src/config.c b/src/config.c index eea247e3f..bd2e299a4 100644 --- a/src/config.c +++ b/src/config.c @@ -1378,6 +1378,18 @@ load_hard_disks(void) if (hdd[c].tracks > max_tracks) hdd[c].tracks = max_tracks; + sprintf(temp, "hdd_%02i_speed", c+1); + switch (hdd[c].bus) { + case HDD_BUS_IDE: + sprintf(tmp2, "1997_5400rpm"); + break; + default: + sprintf(tmp2, "ramdisk"); + break; + } + p = config_get_string(cat, temp, tmp2); + hdd[c].speed_preset = hdd_preset_get_from_internal_name(p); + /* MFM/RLL */ sprintf(temp, "hdd_%02i_mfm_channel", c+1); if (hdd[c].bus == HDD_BUS_MFM) @@ -2918,6 +2930,13 @@ save_hard_disks(void) } else config_delete_var(cat, temp); + + sprintf(temp, "hdd_%02i_speed", c+1); + if (!hdd_is_valid(c) || (hdd[c].bus != HDD_BUS_IDE)) + config_delete_var(cat, temp); + else + config_set_string(cat, temp, hdd_preset_get_internal_name(hdd[c].speed_preset)); + } delete_section_if_empty(cat); diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index b005cbd6d..b654c78b4 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -734,7 +734,7 @@ loadhd(ide_t *ide, int d, const char *fn) return; } - hdd_preset_auto(&hdd[d]); + hdd_preset_apply(d); ide->spt = ide->cfg_spt = hdd[d].spt; ide->hpc = ide->cfg_hpc = hdd[d].hpc; diff --git a/src/disk/hdd.c b/src/disk/hdd.c index b66474098..ca434aa61 100644 --- a/src/disk/hdd.c +++ b/src/disk/hdd.c @@ -31,8 +31,9 @@ #include <86box/video.h> #include "cpu.h" -hard_disk_t hdd[HDD_NUM]; +#define HDD_OVERHEAD_TIME 50.0 +hard_disk_t hdd[HDD_NUM]; int hdd_init(void) @@ -158,6 +159,9 @@ hdd_is_valid(int c) double hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_t continuous, double max_seek_time) { + if (!hdd->speed_preset) + return HDD_OVERHEAD_TIME; + hdd_zone_t *zone = NULL; for (int i = 0; i < hdd->num_zones; i++) { zone = &hdd->zones[i]; @@ -168,7 +172,7 @@ hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_ #ifndef OLD_CODE double continuous_times[2][2] = { { hdd->head_switch_usec, hdd->cyl_switch_usec }, { zone->sector_time_usec, zone->sector_time_usec } }; - double times[2] = { 50.0, hdd->avg_rotation_lat_usec }; + double times[2] = { HDD_OVERHEAD_TIME, hdd->avg_rotation_lat_usec }; #endif uint32_t new_track = zone->start_track + ((dst_addr - zone->start_sector) / zone->sectors_per_track); @@ -201,7 +205,7 @@ hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_ seek_time = hdd->avg_rotation_lat_usec; } else { //seek_time = hdd->cyl_switch_usec; - seek_time = 50.0; + seek_time = HDD_OVERHEAD_TIME; } #else seek_time = times[operation != HDD_OP_SEEK]; @@ -292,6 +296,9 @@ hdd_writecache_update(hard_disk_t *hdd) double hdd_timing_write(hard_disk_t *hdd, uint32_t addr, uint32_t len) { + if (!hdd->speed_preset) + return HDD_OVERHEAD_TIME; + hdd_readahead_update(hdd); hdd_writecache_update(hdd); @@ -327,6 +334,9 @@ hdd_timing_write(hard_disk_t *hdd, uint32_t addr, uint32_t len) double hdd_timing_read(hard_disk_t *hdd, uint32_t addr, uint32_t len) { + if (!hdd->speed_preset) + return HDD_OVERHEAD_TIME; + hdd_readahead_update(hdd); hdd_writecache_update(hdd); @@ -388,7 +398,7 @@ update_lru: cache->ra_ongoing = 1; cache->ra_segment = active_seg->id; cache->ra_start_time = tsc + (uint32_t)(seek_time * cpuclock / 1000000.0); - + return seek_time; } @@ -414,7 +424,7 @@ hdd_zones_init(hard_disk_t *hdd) { uint32_t lba = 0; uint32_t track = 0; - + double revolution_usec = 60.0 / (double)hdd->rpm * 1000000.0; for (uint32_t i = 0; i < hdd->num_zones; i++) { hdd_zone_t *zone = &hdd->zones[i]; @@ -428,53 +438,98 @@ hdd_zones_init(hard_disk_t *hdd) } } -hdd_preset_t hdd_presets[] = { - { .target_year = 1989, .match_max_mbyte = 99, .zones = 1, .avg_spt = 35, .heads = 2, .rpm = 3500, .full_stroke_ms = 40, .track_seek_ms = 8, - .rcache_num_seg = 1, .rcache_seg_size = 16, .max_multiple = 8 }, +static hdd_preset_t hdd_speed_presets[] = { + { .name = "RAM Disk (max. speed)", .internal_name = "ramdisk", .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 32 }, - { .target_year = 1992, .match_max_mbyte = 249, .zones = 1, .avg_spt = 45, .heads = 2, .rpm = 3500, .full_stroke_ms = 30, .track_seek_ms = 6, - .rcache_num_seg = 4, .rcache_seg_size = 16, .max_multiple = 8 }, + { .name = "[1989] 3500 RPM", .internal_name = "1989_3500rpm", .zones = 1, .avg_spt = 35, .heads = 2, .rpm = 3500, + .full_stroke_ms = 40, .track_seek_ms = 8, .rcache_num_seg = 1, .rcache_seg_size = 16, .max_multiple = 8 }, - { .target_year = 1994, .match_max_mbyte = 999, .zones = 8, .avg_spt = 80, .heads = 4, .rpm = 4500, .full_stroke_ms = 26, .track_seek_ms = 5, - .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 16 }, + { .name = "[1992] 3600 RPM", .internal_name = "1992_3600rpm", .zones = 1, .avg_spt = 45, .heads = 2, .rpm = 3600, + .full_stroke_ms = 30, .track_seek_ms = 6, .rcache_num_seg = 4, .rcache_seg_size = 16, .max_multiple = 8 }, - { .target_year = 1996, .match_max_mbyte = 1999, .zones = 16, .avg_spt = 135, .heads = 4, .rpm = 5400, .full_stroke_ms = 24, .track_seek_ms = 3, - .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 16 }, + { .name = "[1994] 4500 RPM", .internal_name = "1994_4500rpm", .zones = 8, .avg_spt = 80, .heads = 4, .rpm = 4500, + .full_stroke_ms = 26, .track_seek_ms = 5, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 16 }, - { .target_year = 1997, .match_max_mbyte = 4999, .zones = 16, .avg_spt = 185, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.5, - .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 32 }, + { .name = "[1996] 5400 RPM", .internal_name = "1996_5400rpm", .zones = 16, .avg_spt = 135, .heads = 4, .rpm = 5400, + .full_stroke_ms = 24, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 16 }, - { .target_year = 1998, .match_max_mbyte = 9999, .zones = 16, .avg_spt = 300, .heads = 8, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, - .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 32 }, + { .name = "[1997] 5400 RPM", .internal_name = "1997_5400rpm", .zones = 16, .avg_spt = 185, .heads = 6, .rpm = 5400, + .full_stroke_ms = 20, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 32 }, - { .target_year = 2000, .match_max_mbyte = 99999, .zones = 16, .avg_spt = 350, .heads = 6, .rpm = 7200, .full_stroke_ms = 15, .track_seek_ms = 2, - .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 32 }, + { .name = "[1998] 5400 RPM", .internal_name = "1998_5400rpm", .zones = 16, .avg_spt = 300, .heads = 8, .rpm = 5400, + .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 32 }, + + { .name = "[2000] 7200 RPM", .internal_name = "2000_7200rpm", .zones = 16, .avg_spt = 350, .heads = 6, .rpm = 7200, + .full_stroke_ms = 15, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 32 }, }; -void -hdd_preset_apply(hard_disk_t *hdd, hdd_preset_t *preset) +int +hdd_preset_get_num() { - hdd->phy_heads = preset->heads; - hdd->rpm = preset->rpm; + return sizeof(hdd_speed_presets) / sizeof(hdd_preset_t); +} - double revolution_usec = 60.0 / (double)hdd->rpm * 1000000.0; - hdd->avg_rotation_lat_usec = revolution_usec / 2; - hdd->full_stroke_usec = preset->full_stroke_ms * 1000; - hdd->head_switch_usec = preset->track_seek_ms * 1000; - hdd->cyl_switch_usec = preset->track_seek_ms * 1000; +char * +hdd_preset_getname(int preset) +{ + return (char *)hdd_speed_presets[preset].name; +} - hdd->cache.num_segments = preset->rcache_num_seg; - hdd->cache.segment_size = preset->rcache_seg_size; - hdd->max_multiple_block = preset->max_multiple; +char * +hdd_preset_get_internal_name(int preset) +{ + return (char *)hdd_speed_presets[preset].internal_name; +} - hdd->cache.write_size = 64; +int +hdd_preset_get_from_internal_name(char *s) +{ + int c = 0; - hdd->num_zones = preset->zones; - uint32_t disk_sectors = hdd->tracks * hdd->hpc * hdd->spt; - uint32_t sectors_per_surface = (uint32_t)ceil((double)disk_sectors / (double)hdd->phy_heads); + for (int i = 0; i < (sizeof(hdd_speed_presets) / sizeof(hdd_preset_t)); i++) { + if (!strcmp((char *)hdd_speed_presets[c].internal_name, s)) + return c; + c++; + } + + return 0; +} + +void +hdd_preset_apply(int hdd_id) +{ + hard_disk_t *hd = &hdd[hdd_id]; + + if (hd->speed_preset >= hdd_preset_get_num()) + hd->speed_preset = 0; + + hdd_preset_t *preset = &hdd_speed_presets[hd->speed_preset]; + + hd->cache.num_segments = preset->rcache_num_seg; + hd->cache.segment_size = preset->rcache_seg_size; + hd->max_multiple_block = preset->max_multiple; + + if (!hd->speed_preset) + return; + + hd->phy_heads = preset->heads; + hd->rpm = preset->rpm; + + double revolution_usec = 60.0 / (double)hd->rpm * 1000000.0; + hd->avg_rotation_lat_usec = revolution_usec / 2; + hd->full_stroke_usec = preset->full_stroke_ms * 1000; + hd->head_switch_usec = preset->track_seek_ms * 1000; + hd->cyl_switch_usec = preset->track_seek_ms * 1000; + + hd->cache.write_size = 64; + + hd->num_zones = preset->zones; + + uint32_t disk_sectors = hd->tracks * hd->hpc * hd->spt; + uint32_t sectors_per_surface = (uint32_t)ceil((double)disk_sectors / (double)hd->phy_heads); uint32_t cylinders = (uint32_t)ceil((double)sectors_per_surface / (double)preset->avg_spt); - hdd->phy_cyl = cylinders; + hd->phy_cyl = cylinders; uint32_t cylinders_per_zone = cylinders / preset->zones; uint32_t total_sectors = 0; @@ -493,26 +548,10 @@ hdd_preset_apply(hard_disk_t *hdd, hdd_preset_t *preset) uint32_t zone_sectors = spt * cylinders_per_zone * preset->heads; total_sectors += zone_sectors; - hdd->zones[i].cylinders = cylinders_per_zone; - hdd->zones[i].sectors_per_track = spt; + hd->zones[i].cylinders = cylinders_per_zone; + hd->zones[i].sectors_per_track = spt; } - hdd_zones_init(hdd); - hdd_cache_init(hdd); -} - -void -hdd_preset_auto(hard_disk_t *hdd) -{ - uint32_t disk_sectors = hdd->tracks * hdd->hpc * hdd->spt; - uint32_t disk_size_mb = disk_sectors * 512 / 1024 / 1024; - int i; - for (i = 0; i < (sizeof(hdd_presets) / sizeof(hdd_presets[0])); i++) { - if (hdd_presets[i].match_max_mbyte >= disk_size_mb) - break; - } - - hdd_preset_t *preset = &hdd_presets[i]; - - hdd_preset_apply(hdd, preset); + hdd_zones_init(hd); + hdd_cache_init(hd); } \ No newline at end of file diff --git a/src/include/86box/hdd.h b/src/include/86box/hdd.h index 2a2a16bfc..a1c552e1e 100644 --- a/src/include/86box/hdd.h +++ b/src/include/86box/hdd.h @@ -82,12 +82,12 @@ enum { #define HDD_MAX_CACHE_SEG 16 typedef struct { - uint32_t match_max_mbyte; + const char *name; + const char *internal_name; uint32_t zones; uint32_t avg_spt; uint32_t heads; uint32_t rpm; - uint32_t target_year; uint32_t rcache_num_seg; uint32_t rcache_seg_size; uint32_t max_multiple; @@ -169,6 +169,8 @@ typedef struct { uint32_t cur_track; uint32_t cur_addr; + uint32_t speed_preset; + double avg_rotation_lat_usec; double full_stroke_usec; double head_switch_usec; @@ -207,7 +209,10 @@ extern int image_is_vhd(const char *s, int check_signature); extern double hdd_timing_write(hard_disk_t *hdd, uint32_t addr, uint32_t len); extern double hdd_timing_read(hard_disk_t *hdd, uint32_t addr, uint32_t len); extern double hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_t continuous, double max_seek_time); -extern void hdd_preset_apply(hard_disk_t *hdd, hdd_preset_t *preset); -extern void hdd_preset_auto(hard_disk_t *hdd); +int hdd_preset_get_num(); +char * hdd_preset_getname(int preset); +extern char *hdd_preset_get_internal_name(int preset); +extern int hdd_preset_get_from_internal_name(char *s); +extern void hdd_preset_apply(int hdd_id); #endif /*EMU_HDD_H*/ diff --git a/src/qt/qt_harddiskdialog.cpp b/src/qt/qt_harddiskdialog.cpp index dd598af46..91179cdbc 100644 --- a/src/qt/qt_harddiskdialog.cpp +++ b/src/qt/qt_harddiskdialog.cpp @@ -138,6 +138,10 @@ QString HarddiskDialog::fileName() const { return ui->fileField->fileName(); } +uint32_t HarddiskDialog::speed() const { + return static_cast(ui->comboBoxSpeed->currentData().toUInt()); +} + void HarddiskDialog::on_comboBoxFormat_currentIndexChanged(int index) { bool enabled; if (index == 5) { /* They switched to a diff VHD; disable the geometry fields. */ @@ -700,6 +704,8 @@ void HarddiskDialog::on_comboBoxBus_currentIndexChanged(int index) { ui->lineEditSectors->setValidator(new QIntValidator(1, max_sectors, this)); Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt()); + Harddrives::populateSpeeds(ui->comboBoxSpeed->model(), ui->comboBoxBus->currentData().toInt()); + switch (ui->comboBoxBus->currentData().toInt()) { case HDD_BUS_MFM: diff --git a/src/qt/qt_harddiskdialog.hpp b/src/qt/qt_harddiskdialog.hpp index 321dc4708..408726f63 100644 --- a/src/qt/qt_harddiskdialog.hpp +++ b/src/qt/qt_harddiskdialog.hpp @@ -21,6 +21,7 @@ public: uint32_t cylinders() const { return cylinders_; } uint32_t heads() const { return heads_; } uint32_t sectors() const { return sectors_; } + uint32_t speed() const; signals: void fileProgress(int i); diff --git a/src/qt/qt_harddiskdialog.ui b/src/qt/qt_harddiskdialog.ui index 823652aa6..84c557660 100644 --- a/src/qt/qt_harddiskdialog.ui +++ b/src/qt/qt_harddiskdialog.ui @@ -42,6 +42,16 @@ + + + + Speed: + + + + + + diff --git a/src/qt/qt_harddrive_common.cpp b/src/qt/qt_harddrive_common.cpp index a47e036c7..5ac46dd42 100644 --- a/src/qt/qt_harddrive_common.cpp +++ b/src/qt/qt_harddrive_common.cpp @@ -54,6 +54,27 @@ void Harddrives::populateRemovableBuses(QAbstractItemModel *model) { model->setData(model->index(2, 0), HDD_BUS_SCSI, Qt::UserRole); } +void Harddrives::populateSpeeds(QAbstractItemModel *model, int bus) { + int num_preset; + + switch (bus) { + case HDD_BUS_IDE: + num_preset = hdd_preset_get_num(); + break; + + default: + num_preset = 1; + } + + model->removeRows(0, model->rowCount()); + model->insertRows(0, num_preset); + + for (int i = 0; i < num_preset; i++) { + model->setData(model->index(i, 0), QObject::tr(hdd_preset_getname(i))); + model->setData(model->index(i, 0), i, Qt::UserRole); + } +} + void Harddrives::populateBusChannels(QAbstractItemModel *model, int bus) { model->removeRows(0, model->rowCount()); diff --git a/src/qt/qt_harddrive_common.hpp b/src/qt/qt_harddrive_common.hpp index 5d4bbc9e0..6e133506f 100644 --- a/src/qt/qt_harddrive_common.hpp +++ b/src/qt/qt_harddrive_common.hpp @@ -10,6 +10,7 @@ namespace Harddrives { void populateBuses(QAbstractItemModel* model); void populateRemovableBuses(QAbstractItemModel* model); void populateBusChannels(QAbstractItemModel* model, int bus); + void populateSpeeds(QAbstractItemModel* model, int bus); QString BusChannelName(uint8_t bus, uint8_t channel); inline SettingsBusTracking* busTrackClass = nullptr; }; diff --git a/src/qt/qt_settingsharddisks.cpp b/src/qt/qt_settingsharddisks.cpp index df9c6b1dc..0c3938c91 100644 --- a/src/qt/qt_settingsharddisks.cpp +++ b/src/qt/qt_settingsharddisks.cpp @@ -37,6 +37,7 @@ const int ColumnCylinders = 2; const int ColumnHeads = 3; const int ColumnSectors = 4; const int ColumnSize = 5; +const int ColumnSpeed = 6; const int DataBus = Qt::UserRole; const int DataBusChannel = Qt::UserRole + 1; @@ -94,6 +95,8 @@ static void addRow(QAbstractItemModel* model, hard_disk_t* hd) { model->setData(model->index(row, ColumnHeads), hd->hpc); model->setData(model->index(row, ColumnSectors), hd->spt); model->setData(model->index(row, ColumnSize), (hd->tracks * hd->hpc * hd->spt) >> 11); + model->setData(model->index(row, ColumnSpeed), hdd_preset_getname(hd->speed_preset)); + model->setData(model->index(row, ColumnSpeed), hd->speed_preset, Qt::UserRole); } SettingsHarddisks::SettingsHarddisks(QWidget *parent) : @@ -102,13 +105,14 @@ SettingsHarddisks::SettingsHarddisks(QWidget *parent) : { ui->setupUi(this); - QAbstractItemModel* model = new QStandardItemModel(0, 6, this); + QAbstractItemModel* model = new QStandardItemModel(0, 7, this); model->setHeaderData(ColumnBus, Qt::Horizontal, tr("Bus")); model->setHeaderData(ColumnFilename, Qt::Horizontal, tr("File")); model->setHeaderData(ColumnCylinders, Qt::Horizontal, tr("C")); model->setHeaderData(ColumnHeads, Qt::Horizontal, tr("H")); model->setHeaderData(ColumnSectors, Qt::Horizontal, tr("S")); model->setHeaderData(ColumnSize, Qt::Horizontal, tr("MiB")); + model->setHeaderData(ColumnSpeed, Qt::Horizontal, tr("Speed")); ui->tableView->setModel(model); for (int i = 0; i < HDD_NUM; i++) { @@ -149,6 +153,7 @@ void SettingsHarddisks::save() { hdd[i].tracks = idx.siblingAtColumn(ColumnCylinders).data().toUInt(); hdd[i].hpc = idx.siblingAtColumn(ColumnHeads).data().toUInt(); hdd[i].spt = idx.siblingAtColumn(ColumnSectors).data().toUInt(); + hdd[i].speed_preset = idx.siblingAtColumn(ColumnSpeed).data(Qt::UserRole).toUInt(); QByteArray fileName = idx.siblingAtColumn(ColumnFilename).data(Qt::UserRole).toString().toUtf8(); strncpy(hdd[i].fn, fileName.data(), sizeof(hdd[i].fn) - 1); @@ -173,6 +178,7 @@ void SettingsHarddisks::on_comboBoxBus_currentIndexChanged(int index) { } Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt()); + Harddrives::populateSpeeds(ui->comboBoxSpeed->model(), ui->comboBoxBus->currentData().toInt()); int chanIdx = 0; switch (ui->comboBoxBus->currentData().toInt()) @@ -221,15 +227,32 @@ void SettingsHarddisks::on_comboBoxChannel_currentIndexChanged(int index) { } } +void SettingsHarddisks::on_comboBoxSpeed_currentIndexChanged(int index) { + if (index < 0) { + return; + } + + auto idx = ui->tableView->selectionModel()->currentIndex(); + if (idx.isValid()) { + auto* model = ui->tableView->model(); + auto col = idx.siblingAtColumn(ColumnSpeed); + model->setData(col, ui->comboBoxSpeed->currentData(Qt::UserRole), Qt::UserRole); + model->setData(col, hdd_preset_getname(ui->comboBoxSpeed->currentData(Qt::UserRole).toUInt())); + } +} + void SettingsHarddisks::onTableRowChanged(const QModelIndex ¤t) { bool hidden = !current.isValid(); ui->labelBus->setHidden(hidden); ui->labelChannel->setHidden(hidden); + ui->labelSpeed->setHidden(hidden); ui->comboBoxBus->setHidden(hidden); ui->comboBoxChannel->setHidden(hidden); + ui->comboBoxSpeed->setHidden(hidden); uint32_t bus = current.siblingAtColumn(ColumnBus).data(DataBus).toUInt(); uint32_t busChannel = current.siblingAtColumn(ColumnBus).data(DataBusChannel).toUInt(); + uint32_t speed = current.siblingAtColumn(ColumnSpeed).data(Qt::UserRole).toUInt(); auto* model = ui->comboBoxBus->model(); auto match = model->match(model->index(0, 0), Qt::UserRole, bus); @@ -241,6 +264,12 @@ void SettingsHarddisks::onTableRowChanged(const QModelIndex ¤t) { if (! match.isEmpty()) { ui->comboBoxChannel->setCurrentIndex(match.first().row()); } + + model = ui->comboBoxSpeed->model(); + match = model->match(model->index(0, 0), Qt::UserRole, speed); + if (! match.isEmpty()) { + ui->comboBoxSpeed->setCurrentIndex(match.first().row()); + } } static void addDriveFromDialog(Ui::SettingsHarddisks* ui, const HarddiskDialog& dlg) { @@ -255,6 +284,7 @@ static void addDriveFromDialog(Ui::SettingsHarddisks* ui, const HarddiskDialog& hd.hpc = dlg.heads(); hd.spt = dlg.sectors(); strncpy(hd.fn, fn.data(), sizeof(hd.fn) - 1); + hd.speed_preset = dlg.speed(); addRow(ui->tableView->model(), &hd); ui->tableView->resizeColumnsToContents(); diff --git a/src/qt/qt_settingsharddisks.hpp b/src/qt/qt_settingsharddisks.hpp index b10e79029..a8aebb0bd 100644 --- a/src/qt/qt_settingsharddisks.hpp +++ b/src/qt/qt_settingsharddisks.hpp @@ -19,6 +19,7 @@ public: private slots: void on_comboBoxChannel_currentIndexChanged(int index); + void on_comboBoxSpeed_currentIndexChanged(int index); private slots: void on_pushButtonRemove_clicked(); diff --git a/src/qt/qt_settingsharddisks.ui b/src/qt/qt_settingsharddisks.ui index fa913beea..b5ab110c9 100644 --- a/src/qt/qt_settingsharddisks.ui +++ b/src/qt/qt_settingsharddisks.ui @@ -64,6 +64,16 @@ + + + + Speed: + + + + + + From 301b422816f3a3999c3b5fbe2d9cfb9697fefb23 Mon Sep 17 00:00:00 2001 From: AsciiWolf Date: Tue, 19 Jul 2022 14:20:46 +0200 Subject: [PATCH 079/386] Add missing semicolon to desktop file It should be there according to the desktop file specification --- src/unix/assets/net.86box.86Box.desktop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/assets/net.86box.86Box.desktop b/src/unix/assets/net.86box.86Box.desktop index 3eab58322..83d20b9e7 100644 --- a/src/unix/assets/net.86box.86Box.desktop +++ b/src/unix/assets/net.86box.86Box.desktop @@ -6,4 +6,4 @@ Exec=86Box Icon=net.86box.86Box Terminal=false Type=Application -Categories=System;Emulator +Categories=System;Emulator; From df5c1a1a46a992bece32ef8ce090911324b052cb Mon Sep 17 00:00:00 2001 From: TC1995 Date: Tue, 19 Jul 2022 16:32:23 +0200 Subject: [PATCH 080/386] ISA PS/2: Clean-ups and converted into a typedef struct. MCA PS/2: Added Model 60 (8-slot version of 50 with the same bios) and Model 65sx (essentially the same as 55sx but with a new bios and a secondary nvram a la 70-80 but limited to 2KB of size instead of 8KB). MCA PS/2: Made the i486 cpu selection on only on Type 3 MCA models (70-80) and not Type 2 anymore, therefore the latter is limited to 386DX cpu's only. --- src/include/86box/machine.h | 2 + src/include/86box/nvr_ps2.h | 1 + src/machine/m_ps2_isa.c | 283 +++++++++++++++++++----------------- src/machine/m_ps2_mca.c | 100 ++++++++++--- src/machine/machine_table.c | 14 +- src/nvr_ps2.c | 35 ++++- 6 files changed, 266 insertions(+), 169 deletions(-) diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 8456b4dc8..449942915 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -777,7 +777,9 @@ extern int machine_ps2_m30_286_init(const machine_t *); /* m_ps2_mca.c */ extern int machine_ps2_model_50_init(const machine_t *); +extern int machine_ps2_model_60_init(const machine_t *); extern int machine_ps2_model_55sx_init(const machine_t *); +extern int machine_ps2_model_65sx_init(const machine_t *); extern int machine_ps2_model_70_type3_init(const machine_t *); extern int machine_ps2_model_80_init(const machine_t *); extern int machine_ps2_model_80_axx_init(const machine_t *); diff --git a/src/include/86box/nvr_ps2.h b/src/include/86box/nvr_ps2.h index 7cb37a625..fe3f141e2 100644 --- a/src/include/86box/nvr_ps2.h +++ b/src/include/86box/nvr_ps2.h @@ -40,6 +40,7 @@ extern const device_t ps2_nvr_device; +extern const device_t ps2_nvr_55ls_device; #endif /*EMU_NVRPS2_H*/ diff --git a/src/machine/m_ps2_isa.c b/src/machine/m_ps2_isa.c index c39c4eb92..6e26b159d 100644 --- a/src/machine/m_ps2_isa.c +++ b/src/machine/m_ps2_isa.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include <86box/86box.h> @@ -25,145 +26,175 @@ #include <86box/machine.h> -static uint8_t ps2_91, ps2_94, ps2_102, ps2_103, ps2_104, ps2_105, ps2_190; -static serial_t *ps2_uart; +typedef struct { + int model; + int cpu_type; + + uint8_t ps2_91, + ps2_92, + ps2_94, + ps2_102, + ps2_103, + ps2_104, + ps2_105, + ps2_190; + + serial_t *uart; +} ps2_isa_t; -static struct +static void +ps2_write(uint16_t port, uint8_t val, void *priv) { - uint8_t status, int_status; - uint8_t attention, ctrl; -} ps2_hd; + ps2_isa_t *ps2 = (ps2_isa_t *)priv; + switch (port) { + case 0x0094: + ps2->ps2_94 = val; + break; -static uint8_t ps2_read(uint16_t port, void *p) -{ - uint8_t temp; + case 0x0102: + if (!(ps2->ps2_94 & 0x80)) { + lpt1_remove(); + serial_remove(ps2->uart); + if (val & 0x04) { + if (val & 0x08) + serial_setup(ps2->uart, COM1_ADDR, COM1_IRQ); + else + serial_setup(ps2->uart, COM2_ADDR, COM2_IRQ); + } + if (val & 0x10) { + switch ((val >> 5) & 3) { + case 0: + lpt1_init(LPT_MDA_ADDR); + break; + case 1: + lpt1_init(LPT1_ADDR); + break; + case 2: + lpt1_init(LPT2_ADDR); + break; + } + } + ps2->ps2_102 = val; + } + break; - switch (port) - { - case 0x91: - temp = ps2_91; - ps2_91 = 0; - return temp; - case 0x94: - return ps2_94; - case 0x102: - return ps2_102 | 8; - case 0x103: - return ps2_103; - case 0x104: - return ps2_104; - case 0x105: - return ps2_105; - case 0x190: - return ps2_190; + case 0x0103: + ps2->ps2_103 = val; + break; -#ifdef FIXME - case 0x322: - temp = ps2_hd.status; - break; - case 0x324: - temp = ps2_hd.int_status; - ps2_hd.int_status &= ~0x02; - break; -#endif + case 0x0104: + ps2->ps2_104 = val; + break; - default: - temp = 0xff; - break; - } + case 0x0105: + ps2->ps2_105 = val; + break; - return temp; + case 0x0190: + ps2->ps2_190 = val; + break; + } } -static void ps2_write(uint16_t port, uint8_t val, void *p) +static uint8_t +ps2_read(uint16_t port, void *priv) { - switch (port) - { - case 0x94: - ps2_94 = val; - break; - case 0x102: - if (!(ps2_94 & 0x80)) { - lpt1_remove(); - serial_remove(ps2_uart); - if (val & 0x04) { - if (val & 0x08) - serial_setup(ps2_uart, COM1_ADDR, COM1_IRQ); - else - serial_setup(ps2_uart, COM2_ADDR, COM2_IRQ); - } - if (val & 0x10) { - switch ((val >> 5) & 3) - { - case 0: - lpt1_init(LPT_MDA_ADDR); - break; - case 1: - lpt1_init(LPT1_ADDR); - break; - case 2: - lpt1_init(LPT2_ADDR); - break; - } - } - ps2_102 = val; - } - break; + ps2_isa_t *ps2 = (ps2_isa_t *)priv; + uint8_t temp = 0xff; - case 0x103: - ps2_103 = val; - break; - case 0x104: - ps2_104 = val; - break; - case 0x105: - ps2_105 = val; - break; - case 0x190: - ps2_190 = val; - break; + switch (port) { + case 0x0091: + temp = ps2->ps2_91; + ps2->ps2_91 = 0; + break; -#ifdef FIXME - case 0x322: - ps2_hd.ctrl = val; - if (val & 0x80) - ps2_hd.status |= 0x02; - break; - case 0x324: - ps2_hd.attention = val & 0xf0; - if (ps2_hd.attention) - ps2_hd.status = 0x14; - break; -#endif - } + case 0x0094: + temp = ps2->ps2_94; + break; + + case 0x0102: + temp = ps2->ps2_102 | 0x08; + break; + + case 0x0103: + temp = ps2->ps2_103; + break; + + case 0x0104: + temp = ps2->ps2_104; + break; + + case 0x0105: + temp = ps2->ps2_105; + break; + + case 0x0190: + temp = ps2->ps2_190; + break; + } + + return temp; } - -static void ps2board_init(void) +static void +ps2_isa_setup(int model, int cpu_type) { - io_sethandler(0x0091, 0x0001, ps2_read, NULL, NULL, ps2_write, NULL, NULL, NULL); - io_sethandler(0x0094, 0x0001, ps2_read, NULL, NULL, ps2_write, NULL, NULL, NULL); - io_sethandler(0x0102, 0x0004, ps2_read, NULL, NULL, ps2_write, NULL, NULL, NULL); - io_sethandler(0x0190, 0x0001, ps2_read, NULL, NULL, ps2_write, NULL, NULL, NULL); -#ifdef FIXME - io_sethandler(0x0320, 0x0001, ps2_read, NULL, NULL, ps2_write, NULL, NULL, NULL); - io_sethandler(0x0322, 0x0001, ps2_read, NULL, NULL, ps2_write, NULL, NULL, NULL); - io_sethandler(0x0324, 0x0001, ps2_read, NULL, NULL, ps2_write, NULL, NULL, NULL); -#endif + ps2_isa_t *ps2; + void *priv; + + ps2 = (ps2_isa_t *)malloc(sizeof(ps2_isa_t)); + memset(ps2, 0x00, sizeof(ps2_isa_t)); + ps2->model = model; + ps2->cpu_type = cpu_type; + + + io_sethandler(0x0091, 1, + ps2_read, NULL, NULL, ps2_write, NULL, NULL, ps2); + io_sethandler(0x0094, 1, + ps2_read, NULL, NULL, ps2_write, NULL, NULL, ps2); + io_sethandler(0x0102, 4, + ps2_read, NULL, NULL, ps2_write, NULL, NULL, ps2); + io_sethandler(0x0190, 1, + ps2_read, NULL, NULL, ps2_write, NULL, NULL, ps2); + + ps2->uart = device_add_inst(&ns16450_device, 1); + + lpt1_remove(); + lpt1_init(LPT_MDA_ADDR); device_add(&port_92_device); - ps2_190 = 0; + mem_remap_top(384); - ps2_uart = device_add_inst(&ns16450_device, 1); + device_add(&ps_nvr_device); - lpt1_init(LPT_MDA_ADDR); + device_add(&fdc_at_ps1_device); - memset(&ps2_hd, 0, sizeof(ps2_hd)); + /* Enable the builtin HDC. */ + if (hdc_current == 1) { + priv = device_add(&ps1_hdc_device); + ps1_hdc_inform(priv, &ps2->ps2_91); + } + + device_add(&ps1vga_device); } +static void +ps2_isa_common_init(const machine_t *model) +{ + machine_common_init(model); + + refresh_at_enable = 1; + pit_ctr_set_out_func(&pit->counters[1], pit_refresh_timer_at); + + dma16_init(); + pic2_init(); + + device_add(&keyboard_ps2_device); + device_add(&port_6x_ps2_device); +} int machine_ps2_m30_286_init(const machine_t *model) @@ -178,28 +209,10 @@ machine_ps2_m30_286_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_common_init(model); + ps2_isa_common_init(model); - mem_remap_top(384); - - device_add(&fdc_at_ps1_device); - - refresh_at_enable = 1; - pit_ctr_set_out_func(&pit->counters[1], pit_refresh_timer_at); - dma16_init(); - device_add(&keyboard_ps2_device); - device_add(&port_6x_ps2_device); - device_add(&ps_nvr_device); - pic2_init(); - ps2board_init(); - device_add(&ps1vga_device); - - /* Enable the builtin HDC. */ - if (hdc_current == 1) { - priv = device_add(&ps1_hdc_device); - - ps1_hdc_inform(priv, &ps2_91); - } + ps2_isa_setup(30, 286); return ret; } + diff --git a/src/machine/m_ps2_mca.c b/src/machine/m_ps2_mca.c index 094487d37..c0296fb2a 100644 --- a/src/machine/m_ps2_mca.c +++ b/src/machine/m_ps2_mca.c @@ -253,9 +253,9 @@ static uint8_t model_50_read(uint16_t port) switch (port) { case 0x100: - return 0xff; + return ps2.planar_id & 0xff; case 0x101: - return 0xfb; + return ps2.planar_id >> 8; case 0x102: return ps2.option[0]; case 0x103: @@ -277,9 +277,9 @@ static uint8_t model_55sx_read(uint16_t port) switch (port) { case 0x100: - return 0xff; + return ps2.planar_id & 0xff; case 0x101: - return 0xfb; + return ps2.planar_id >> 8; case 0x102: return ps2.option[0]; case 0x103: @@ -325,9 +325,9 @@ static uint8_t model_80_read(uint16_t port) switch (port) { case 0x100: - return 0xff; + return ps2.planar_id & 0xff; case 0x101: - return 0xfd; + return ps2.planar_id >> 8; case 0x102: return ps2.option[0]; case 0x103: @@ -829,17 +829,17 @@ static void ps2_mca_write(uint16_t port, uint8_t val, void *p) static void ps2_mca_board_common_init() { - io_sethandler(0x0091, 0x0001, ps2_mca_read, NULL, NULL, ps2_mca_write, NULL, NULL, NULL); - io_sethandler(0x0094, 0x0001, ps2_mca_read, NULL, NULL, ps2_mca_write, NULL, NULL, NULL); - io_sethandler(0x0096, 0x0001, ps2_mca_read, NULL, NULL, ps2_mca_write, NULL, NULL, NULL); - io_sethandler(0x0100, 0x0008, ps2_mca_read, NULL, NULL, ps2_mca_write, NULL, NULL, NULL); + io_sethandler(0x0091, 0x0001, ps2_mca_read, NULL, NULL, ps2_mca_write, NULL, NULL, NULL); + io_sethandler(0x0094, 0x0001, ps2_mca_read, NULL, NULL, ps2_mca_write, NULL, NULL, NULL); + io_sethandler(0x0096, 0x0001, ps2_mca_read, NULL, NULL, ps2_mca_write, NULL, NULL, NULL); + io_sethandler(0x0100, 0x0008, ps2_mca_read, NULL, NULL, ps2_mca_write, NULL, NULL, NULL); device_add(&port_6x_ps2_device); - device_add(&port_92_device); + device_add(&port_92_device); - ps2.setup = 0xff; + ps2.setup = 0xff; - lpt1_init(LPT_MDA_ADDR); + lpt1_init(LPT_MDA_ADDR); } static uint8_t ps2_mem_expansion_read(int port, void *p) @@ -951,12 +951,12 @@ static void ps2_mca_mem_d071_init(int start_mb) } -static void ps2_mca_board_model_50_init() +static void ps2_mca_board_model_50_init(int slots) { ps2_mca_board_common_init(); mem_remap_top(384); - mca_init(4); + mca_init(slots); device_add(&keyboard_ps2_mca_2_device); ps2.planar_read = model_50_read; @@ -972,7 +972,7 @@ static void ps2_mca_board_model_50_init() device_add(&ps1vga_mca_device); } -static void ps2_mca_board_model_55sx_init() +static void ps2_mca_board_model_55sx_init(int has_sec_nvram, int slots) { ps2_mca_board_common_init(); @@ -1015,14 +1015,20 @@ static void ps2_mca_board_model_55sx_init() break; } - mca_init(4); + mca_init(slots); device_add(&keyboard_ps2_mca_device); + if (has_sec_nvram == 1) + device_add(&ps2_nvr_55ls_device); + else if (has_sec_nvram == 2) { + device_add(&ps2_nvr_device); + } + ps2.planar_read = model_55sx_read; ps2.planar_write = model_55sx_write; - if (gfxcard == VID_INTERNAL) - device_add(&ps1vga_mca_device); + if (gfxcard == VID_INTERNAL) + device_add(&ps1vga_mca_device); model_55sx_mem_recalc(); } @@ -1383,7 +1389,31 @@ machine_ps2_model_50_init(const machine_t *model) machine_ps2_common_init(model); - ps2_mca_board_model_50_init(); + ps2.planar_id = 0xfbff; + ps2_mca_board_model_50_init(4); + + return ret; +} + +int +machine_ps2_model_60_init(const machine_t *model) +{ + int ret; + + ret = bios_load_interleaved("roms/machines/ibmps2_m50/90x7420.zm13", + "roms/machines/ibmps2_m50/90x7429.zm18", + 0x000f0000, 131072, 0); + ret &= bios_load_aux_interleaved("roms/machines/ibmps2_m50/90x7423.zm14", + "roms/machines/ibmps2_m50/90x7426.zm16", + 0x000e0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_ps2_common_init(model); + + ps2.planar_id = 0xf7ff; + ps2_mca_board_model_50_init(8); return ret; } @@ -1403,12 +1433,33 @@ machine_ps2_model_55sx_init(const machine_t *model) machine_ps2_common_init(model); - ps2_mca_board_model_55sx_init(); + ps2.planar_id = 0xfffb; + ps2_mca_board_model_55sx_init(0, 4); return ret; } +int +machine_ps2_model_65sx_init(const machine_t *model) +{ + int ret; + + ret = bios_load_interleaved("roms/machines/ibmps2_m65sx/64F3608.BIN", + "roms/machines/ibmps2_m65sx/64F3611.BIN", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_ps2_common_init(model); + + ps2.planar_id = 0xe3ff; + ps2_mca_board_model_55sx_init(1, 8); + + return ret; +} + int machine_ps2_model_70_type3_init(const machine_t *model) { @@ -1443,9 +1494,10 @@ machine_ps2_model_80_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_ps2_common_init(model); + machine_ps2_common_init(model); - ps2_mca_board_model_80_type2_init(0); + ps2.planar_id = 0xfdff; + ps2_mca_board_model_80_type2_init(0); return ret; } @@ -1470,3 +1522,5 @@ machine_ps2_model_80_axx_init(const machine_t *model) return ret; } + + diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index 7a0873f20..96f70ee65 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -312,6 +312,8 @@ const machine_t machines[] = { /* 286 machines that utilize the MCA bus */ /* Has IBM PS/2 Type 2 KBC firmware. */ { "[MCA] IBM PS/2 model 50", "ibmps2_m50", MACHINE_TYPE_286, MACHINE_CHIPSET_PROPRIETARY, machine_ps2_model_50_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_286 | CPU_PKG_486SLC_IBM, CPU_BLOCK_NONE, 10000000, 0, 0, 0, 0, 0, MACHINE_PS2_MCA, MACHINE_VIDEO, 1024, 10240, 1024, 63, NULL, NULL }, + /* Has IBM PS/2 Type 2 KBC firmware. */ + { "[MCA] IBM PS/2 model 60", "ibmps2_m60", MACHINE_TYPE_286, MACHINE_CHIPSET_PROPRIETARY, machine_ps2_model_60_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_286 | CPU_PKG_486SLC_IBM, CPU_BLOCK_NONE, 10000000, 0, 0, 0, 0, 0, MACHINE_PS2_MCA, MACHINE_VIDEO, 1024, 10240, 1024, 63, NULL, NULL }, /* 386SX machines */ /* ISA slots available because an official IBM expansion for that existed. */ @@ -373,6 +375,8 @@ const machine_t machines[] = { /* 386SX machines which utilize the MCA bus */ /* Has IBM PS/2 Type 1 KBC firmware. */ { "[MCA] IBM PS/2 model 55SX", "ibmps2_m55sx", MACHINE_TYPE_386SX, MACHINE_CHIPSET_PROPRIETARY, machine_ps2_model_55sx_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_386SX, CPU_BLOCK_NONE, 0, 0, 0, 0, 0, 0, MACHINE_PS2_MCA, MACHINE_VIDEO, 1024, 8192, 1024, 63, NULL, NULL }, + /* Has IBM PS/2 Type 1 KBC firmware. */ + { "[MCA] IBM PS/2 model 65SX", "ibmps2_m65sx", MACHINE_TYPE_386SX, MACHINE_CHIPSET_PROPRIETARY, machine_ps2_model_65sx_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_386SX, CPU_BLOCK_NONE, 0, 0, 0, 0, 0, 0, MACHINE_PS2_MCA, MACHINE_VIDEO, 1024, 8192, 1024, 63, NULL, NULL }, /* 486SLC machines */ /* 486SLC machines with just the ISA slot */ @@ -397,11 +401,7 @@ const machine_t machines[] = { /* 386DX machines which utilize the MCA bus */ /* Has IBM PS/2 Type 1 KBC firmware. */ - { "[MCA] IBM PS/2 model 70 (type 3)", "ibmps2_m70_type3", MACHINE_TYPE_386DX, MACHINE_CHIPSET_PROPRIETARY, machine_ps2_model_70_type3_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_386DX | CPU_PKG_486BL, CPU_BLOCK_NONE, 0, 0, 0, 0, 0, 0, MACHINE_PS2_MCA, MACHINE_VIDEO, 2048, 65536, 2048, 63, NULL, NULL }, - /* Has IBM PS/2 Type 1 KBC firmware. */ - { "[MCA] IBM PS/2 model 80 (type 2)", "ibmps2_m80", MACHINE_TYPE_386DX, MACHINE_CHIPSET_PROPRIETARY, machine_ps2_model_80_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_386DX | CPU_PKG_486BL | CPU_PKG_SOCKET1, CPU_BLOCK_NONE, 0, 0, 0, 0, 0, 0, MACHINE_PS2_MCA, MACHINE_VIDEO, 1024, 65536, 1024, 63, NULL, NULL }, - /* Has IBM PS/2 Type 1 KBC firmware. */ - { "[MCA] IBM PS/2 model 80 (type 3)", "ibmps2_m80_type3", MACHINE_TYPE_386DX, MACHINE_CHIPSET_PROPRIETARY, machine_ps2_model_80_axx_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_386DX | CPU_PKG_486BL | CPU_PKG_SOCKET1, CPU_BLOCK_NONE, 0, 0, 0, 0, 0, 0, MACHINE_PS2_MCA, MACHINE_VIDEO, 2048, 65536, 2048, 63, NULL, NULL }, + { "[MCA] IBM PS/2 model 80 (type 2)", "ibmps2_m80", MACHINE_TYPE_386DX, MACHINE_CHIPSET_PROPRIETARY, machine_ps2_model_80_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_386DX | CPU_PKG_486BL, CPU_BLOCK_NONE, 0, 0, 0, 0, 0, 0, MACHINE_PS2_MCA, MACHINE_VIDEO, 1024, 65536, 1024, 63, NULL, NULL }, /* 386DX/486 machines */ /* The BIOS sends commands C9 without a parameter and D5, both of which are @@ -411,6 +411,10 @@ const machine_t machines[] = { { "[OPTi 495] DataExpert SX495", "ami495", MACHINE_TYPE_386DX_486, MACHINE_CHIPSET_OPTI_495, machine_at_opti495_ami_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_386DX | CPU_PKG_SOCKET1, CPU_BLOCK_NONE, 0, 0, 0, 0, 0, 0, MACHINE_VLB, MACHINE_IDE, 1024, 32768, 1024, 127, NULL, NULL }, /* Has AMIKey F KBC firmware (it's just the MR BIOS for the above machine). */ { "[OPTi 495] DataExpert SX495 (MR BIOS)", "mr495", MACHINE_TYPE_386DX_486, MACHINE_CHIPSET_OPTI_495, machine_at_opti495_mr_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_386DX | CPU_PKG_SOCKET1, CPU_BLOCK_NONE, 0, 0, 0, 0, 0, 0, MACHINE_VLB, MACHINE_IDE, 1024, 32768, 1024, 127, NULL, NULL }, + /* Has IBM PS/2 Type 1 KBC firmware. */ + { "[MCA] IBM PS/2 model 70 (type 3)", "ibmps2_m70_type3", MACHINE_TYPE_386DX_486, MACHINE_CHIPSET_PROPRIETARY, machine_ps2_model_70_type3_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_386DX | CPU_PKG_486BL | CPU_PKG_SOCKET1, CPU_BLOCK_NONE, 0, 0, 0, 0, 0, 0, MACHINE_PS2_MCA, MACHINE_VIDEO, 2048, 65536, 2048, 63, NULL, NULL }, + /* Has IBM PS/2 Type 1 KBC firmware. */ + { "[MCA] IBM PS/2 model 80 (type 3)", "ibmps2_m80_type3", MACHINE_TYPE_386DX_486, MACHINE_CHIPSET_PROPRIETARY, machine_ps2_model_80_axx_init, 0, 0, MACHINE_AVAILABLE, 0 , CPU_PKG_386DX | CPU_PKG_486BL | CPU_PKG_SOCKET1, CPU_BLOCK_NONE, 0, 0, 0, 0, 0, 0, MACHINE_PS2_MCA, MACHINE_VIDEO, 2048, 65536, 2048, 63, NULL, NULL }, /* 486 machines - Socket 1 */ /* Has JetKey 5 KBC Firmware which looks like it is a clone of AMIKey type F. diff --git a/src/nvr_ps2.c b/src/nvr_ps2.c index cd6f47af7..e82eff150 100644 --- a/src/nvr_ps2.c +++ b/src/nvr_ps2.c @@ -53,7 +53,8 @@ typedef struct { int addr; - uint8_t ram[8192]; + uint8_t *ram; + int size; char *fn; } ps2_nvr_t; @@ -114,6 +115,11 @@ ps2_nvr_init(const device_t *info) nvr = (ps2_nvr_t *)malloc(sizeof(ps2_nvr_t)); memset(nvr, 0x00, sizeof(ps2_nvr_t)); + if (info->local) + nvr->size = 2048; + else + nvr->size = 8192; + /* Set up the NVR file's name. */ c = strlen(machine_get_internal_name()) + 9; nvr->fn = (char *)malloc(c + 1); @@ -124,9 +130,10 @@ ps2_nvr_init(const device_t *info) f = nvr_fopen(nvr->fn, "rb"); - memset(nvr->ram, 0xff, 8192); + nvr->ram = (uint8_t *)malloc(nvr->size); + memset(nvr->ram, 0xff, nvr->size); if (f != NULL) { - if (fread(nvr->ram, 1, 8192, f) != 8192) + if (fread(nvr->ram, 1, nvr->size, f) != nvr->size) fatal("ps2_nvr_init(): Error reading EEPROM data\n"); fclose(f); } @@ -144,16 +151,18 @@ ps2_nvr_close(void *priv) f = nvr_fopen(nvr->fn, "wb"); if (f != NULL) { - (void)fwrite(nvr->ram, 8192, 1, f); + (void)fwrite(nvr->ram, nvr->size, 1, f); fclose(f); } + if (nvr->ram != NULL) + free(nvr->ram); + free(nvr); } - const device_t ps2_nvr_device = { - .name = "PS/2 Secondary NVRAM", + .name = "PS/2 Secondary NVRAM for PS/2 Models 70-80", .internal_name = "ps2_nvr", .flags = 0, .local = 0, @@ -165,3 +174,17 @@ const device_t ps2_nvr_device = { .force_redraw = NULL, .config = NULL }; + +const device_t ps2_nvr_55ls_device = { + .name = "PS/2 Secondary NVRAM for PS/2 Models 55LS-65SX", + .internal_name = "ps2_nvr_55ls", + .flags = 0, + .local = 1, + .init = ps2_nvr_init, + .close = ps2_nvr_close, + .reset = NULL, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; From a8c0d30a0a0fd8a96ac02643e1158a44935bdaf5 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Tue, 19 Jul 2022 17:18:46 +0200 Subject: [PATCH 081/386] Apparently a default temp val of 0xff in the read makes XGA-1/2 panic on GUI's... --- src/video/vid_xga.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index 40f0aa6aa..a7ee05ffd 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -1915,7 +1915,7 @@ xga_memio_writel(uint32_t addr, uint32_t val, void *p) static uint8_t xga_mem_read(uint32_t addr, xga_t *xga, svga_t *svga) { - uint8_t temp = 0xff; + uint8_t temp = 0; addr &= 0x1fff; From 8767bb5894fc01d1b3ec59654934cbaf4df433fc Mon Sep 17 00:00:00 2001 From: TC1995 Date: Tue, 19 Jul 2022 17:25:17 +0200 Subject: [PATCH 082/386] Made reg 0x53 (read only) default temp val to 0x70 to satisfy xgaaidos.sys's detection. Apparently MCA Audio cards always want auto-init enabled. --- src/dma.c | 4 ++-- src/video/vid_xga.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dma.c b/src/dma.c index a995660a5..6ab9a12ad 100644 --- a/src/dma.c +++ b/src/dma.c @@ -1448,7 +1448,7 @@ dma_channel_read(int channel) dma_sg_next_addr(dma_c); else { tc = 1; - if (dma_c->mode & 0x10) { /*Auto-init*/ + if ((dma_c->mode & 0x10) || dma_ps2.is_ps2) { /*Auto-init*/ dma_c->cc = dma_c->cb; dma_c->ac = dma_c->ab; } else @@ -1536,7 +1536,7 @@ dma_channel_write(int channel, uint16_t val) if (dma_advanced && (dma_c->sg_status & 1) && !(dma_c->sg_status & 6)) dma_sg_next_addr(dma_c); else { - if (dma_c->mode & 0x10) { /*Auto-init*/ + if ((dma_c->mode & 0x10) || dma_ps2.is_ps2) { /*Auto-init*/ dma_c->cc = dma_c->cb; dma_c->ac = dma_c->ab; } else diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index a7ee05ffd..2941d9cb2 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -577,7 +577,7 @@ xga_ext_inb(uint16_t addr, void *p) ret = 0x0b; break; case 0x53: - ret = 0xb0; + ret = 0x70; break; case 0x54: ret = xga->clk_sel_1; From 2df92dc7f30cd5b9dd7b82d31da179cd519357ea Mon Sep 17 00:00:00 2001 From: TC1995 Date: Tue, 19 Jul 2022 19:21:15 +0200 Subject: [PATCH 083/386] Actually fix the fixed dma. --- src/dma.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/dma.c b/src/dma.c index a995660a5..b5809f9e6 100644 --- a/src/dma.c +++ b/src/dma.c @@ -592,7 +592,7 @@ static uint8_t dma_ps2_read(uint16_t addr, void *priv) { dma_t *dma_c = &dma[dma_ps2.xfr_channel]; - uint8_t temp = 0xff; + uint8_t temp = 0; switch (addr) { case 0x1a: @@ -622,7 +622,7 @@ dma_ps2_read(uint16_t addr, void *priv) else temp = dma_c->cc & 0xff; dma_ps2.byte_ptr = (dma_ps2.byte_ptr + 1) & 1; - break; + break; case 6: /*Read DMA status*/ if (dma_ps2.byte_ptr) { @@ -650,7 +650,6 @@ dma_ps2_read(uint16_t addr, void *priv) } break; } - return(temp); } @@ -719,7 +718,7 @@ dma_ps2_write(uint16_t addr, uint8_t val, void *priv) dma_c->cc = (dma_c->cc & 0xff00) | val; dma_ps2.byte_ptr = (dma_ps2.byte_ptr + 1) & 1; dma_c->cb = dma_c->cc; - break; + break; case 7: /*Mode register*/ mode = 0; @@ -727,9 +726,9 @@ dma_ps2_write(uint16_t addr, uint8_t val, void *priv) mode |= 0x20; if ((val & DMA_PS2_XFER_MASK) == DMA_PS2_XFER_MEM_TO_IO) mode |= 8; - else if ((val & DMA_PS2_XFER_MASK) == DMA_PS2_XFER_IO_TO_MEM) + else if ((val & DMA_PS2_XFER_MASK) == DMA_PS2_XFER_IO_TO_MEM) mode |= 4; - dma_c->mode = (dma_c->mode & ~0x2c) | mode; + dma_c->mode = (dma_c->mode & ~0x2c) | 0x10 | mode; dma_c->ps2_mode = val; dma_c->size = val & DMA_PS2_SIZE16; break; From af1c8982018dbba20efd412e4294ab431a3fd450 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Tue, 19 Jul 2022 19:23:07 +0200 Subject: [PATCH 084/386] (NW) --- src/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dma.c b/src/dma.c index b5809f9e6..e6ab520d3 100644 --- a/src/dma.c +++ b/src/dma.c @@ -592,7 +592,7 @@ static uint8_t dma_ps2_read(uint16_t addr, void *priv) { dma_t *dma_c = &dma[dma_ps2.xfr_channel]; - uint8_t temp = 0; + uint8_t temp = 0xff; switch (addr) { case 0x1a: From e1b44ad064b2d538360781e3fc82cca84fa8578d Mon Sep 17 00:00:00 2001 From: richardg867 Date: Tue, 19 Jul 2022 14:59:29 -0300 Subject: [PATCH 085/386] Jenkins: Allow master node to do IRC notification --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 61330031a..27f7cb855 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -317,7 +317,7 @@ pipeline { scmWebUrl: commitBrowser[buildBranch] /* Notify IRC, which needs a node for whatever reason. */ - node('citadel') { + node('citadel || master') { ircNotify() } } catch (e) { From b7c1e9ad330d090df257bd3a71cbe09f79852644 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Tue, 19 Jul 2022 20:05:34 +0200 Subject: [PATCH 086/386] Revert the DMA auto-init hack on PS/2. --- src/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dma.c b/src/dma.c index 39232fb90..7d6d4b5c3 100644 --- a/src/dma.c +++ b/src/dma.c @@ -728,7 +728,7 @@ dma_ps2_write(uint16_t addr, uint8_t val, void *priv) mode |= 8; else if ((val & DMA_PS2_XFER_MASK) == DMA_PS2_XFER_IO_TO_MEM) mode |= 4; - dma_c->mode = (dma_c->mode & ~0x2c) | 0x10 | mode; + dma_c->mode = (dma_c->mode & ~0x2c) | mode; dma_c->ps2_mode = val; dma_c->size = val & DMA_PS2_SIZE16; break; From 15eced5b557231aa6746bd8763eb4e6420ca3a5e Mon Sep 17 00:00:00 2001 From: richardg867 Date: Tue, 19 Jul 2022 15:07:38 -0300 Subject: [PATCH 087/386] Jenkins: Also allow rg to use IRC over LAN --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 27f7cb855..53e146a64 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -317,7 +317,7 @@ pipeline { scmWebUrl: commitBrowser[buildBranch] /* Notify IRC, which needs a node for whatever reason. */ - node('citadel || master') { + node('citadel || rg || master') { ircNotify() } } catch (e) { From bfc05e7db25d4baa3578795a67ab711aa5012d79 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Tue, 19 Jul 2022 20:44:25 +0200 Subject: [PATCH 088/386] Revert the rest of autoinit on PS/2. --- src/dma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dma.c b/src/dma.c index 7d6d4b5c3..c109f1b8d 100644 --- a/src/dma.c +++ b/src/dma.c @@ -1447,7 +1447,7 @@ dma_channel_read(int channel) dma_sg_next_addr(dma_c); else { tc = 1; - if ((dma_c->mode & 0x10) || dma_ps2.is_ps2) { /*Auto-init*/ + if (dma_c->mode & 0x10) { /*Auto-init*/ dma_c->cc = dma_c->cb; dma_c->ac = dma_c->ab; } else @@ -1535,7 +1535,7 @@ dma_channel_write(int channel, uint16_t val) if (dma_advanced && (dma_c->sg_status & 1) && !(dma_c->sg_status & 6)) dma_sg_next_addr(dma_c); else { - if ((dma_c->mode & 0x10) || dma_ps2.is_ps2) { /*Auto-init*/ + if (dma_c->mode & 0x10) { /*Auto-init*/ dma_c->cc = dma_c->cb; dma_c->ac = dma_c->ab; } else From 3cca314d0cfd5cefcfe83b0ba764a46acd19b7a8 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 19 Jul 2022 23:38:39 +0200 Subject: [PATCH 089/386] Fixed warning in chipset/ali6117.c. --- src/chipset/ali6117.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/chipset/ali6117.c b/src/chipset/ali6117.c index d33387b9f..224d448a2 100644 --- a/src/chipset/ali6117.c +++ b/src/chipset/ali6117.c @@ -199,7 +199,6 @@ static void ali6117_reg_write(uint16_t addr, uint8_t val, void *priv) { ali6117_t *dev = (ali6117_t *) priv; - int i; ali6117_log("ALI6117: reg_write(%04X, %02X)\n", addr, val); From 3c2caca481c1bf4fee1ccd22fdd2e28908dae58e Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 19 Jul 2022 23:40:08 +0200 Subject: [PATCH 090/386] And machine/m_ps2_isa.c. --- src/machine/m_ps2_isa.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/machine/m_ps2_isa.c b/src/machine/m_ps2_isa.c index 6e26b159d..4f98401e7 100644 --- a/src/machine/m_ps2_isa.c +++ b/src/machine/m_ps2_isa.c @@ -98,6 +98,7 @@ ps2_write(uint16_t port, uint8_t val, void *priv) } } + static uint8_t ps2_read(uint16_t port, void *priv) { @@ -138,6 +139,7 @@ ps2_read(uint16_t port, void *priv) return temp; } + static void ps2_isa_setup(int model, int cpu_type) { @@ -181,6 +183,7 @@ ps2_isa_setup(int model, int cpu_type) device_add(&ps1vga_device); } + static void ps2_isa_common_init(const machine_t *model) { @@ -192,27 +195,26 @@ ps2_isa_common_init(const machine_t *model) dma16_init(); pic2_init(); - device_add(&keyboard_ps2_device); - device_add(&port_6x_ps2_device); + device_add(&keyboard_ps2_device); + device_add(&port_6x_ps2_device); } + int machine_ps2_m30_286_init(const machine_t *model) { - void *priv; + int ret; - int ret; + ret = bios_load_linear("roms/machines/ibmps2_m30_286/33f5381a.bin", + 0x000e0000, 131072, 0); - ret = bios_load_linear("roms/machines/ibmps2_m30_286/33f5381a.bin", - 0x000e0000, 131072, 0); - - if (bios_only || !ret) - return ret; + if (bios_only || !ret) + return ret; ps2_isa_common_init(model); ps2_isa_setup(30, 286); - return ret; + return ret; } From fb78071ce98a099d91d2672507e9e5e20855b9a3 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 19 Jul 2022 23:41:09 +0200 Subject: [PATCH 091/386] And machine/m_ps2_mca.c. --- src/machine/m_ps2_mca.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/machine/m_ps2_mca.c b/src/machine/m_ps2_mca.c index c0296fb2a..193840f6b 100644 --- a/src/machine/m_ps2_mca.c +++ b/src/machine/m_ps2_mca.c @@ -1018,17 +1018,16 @@ static void ps2_mca_board_model_55sx_init(int has_sec_nvram, int slots) mca_init(slots); device_add(&keyboard_ps2_mca_device); - if (has_sec_nvram == 1) - device_add(&ps2_nvr_55ls_device); - else if (has_sec_nvram == 2) { - device_add(&ps2_nvr_device); - } + if (has_sec_nvram == 1) + device_add(&ps2_nvr_55ls_device); + else if (has_sec_nvram == 2) + device_add(&ps2_nvr_device); - ps2.planar_read = model_55sx_read; - ps2.planar_write = model_55sx_write; + ps2.planar_read = model_55sx_read; + ps2.planar_write = model_55sx_write; - if (gfxcard == VID_INTERNAL) - device_add(&ps1vga_mca_device); + if (gfxcard == VID_INTERNAL) + device_add(&ps1vga_mca_device); model_55sx_mem_recalc(); } From 97e33097b21977c8ce1ec3e139f43b6f1884dab9 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 19 Jul 2022 23:52:18 +0200 Subject: [PATCH 092/386] And in disk/hdd.c --- src/disk/hdd.c | 486 ++++++++++++++++++++++++------------------------- 1 file changed, 242 insertions(+), 244 deletions(-) diff --git a/src/disk/hdd.c b/src/disk/hdd.c index ca434aa61..d2f77a1ab 100644 --- a/src/disk/hdd.c +++ b/src/disk/hdd.c @@ -31,10 +31,13 @@ #include <86box/video.h> #include "cpu.h" + #define HDD_OVERHEAD_TIME 50.0 + hard_disk_t hdd[HDD_NUM]; + int hdd_init(void) { @@ -156,288 +159,278 @@ hdd_is_valid(int c) return(1); } + double hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_t continuous, double max_seek_time) { if (!hdd->speed_preset) return HDD_OVERHEAD_TIME; - hdd_zone_t *zone = NULL; - for (int i = 0; i < hdd->num_zones; i++) { - zone = &hdd->zones[i]; - if (zone->end_sector >= dst_addr) - break; + hdd_zone_t *zone = NULL; + for (int i = 0; i < hdd->num_zones; i++) { + zone = &hdd->zones[i]; + if (zone->end_sector >= dst_addr) + break; + } + + double continuous_times[2][2] = { { hdd->head_switch_usec, hdd->cyl_switch_usec }, + { zone->sector_time_usec, zone->sector_time_usec } }; + double times[2] = { HDD_OVERHEAD_TIME, hdd->avg_rotation_lat_usec }; + + uint32_t new_track = zone->start_track + ((dst_addr - zone->start_sector) / zone->sectors_per_track); + uint32_t new_cylinder = new_track / hdd->phy_heads; + uint32_t cylinder_diff = abs((int)hdd->cur_cylinder - (int)new_cylinder); + + bool sequential = dst_addr == hdd->cur_addr + 1; + continuous = continuous && sequential; + + double seek_time = 0.0; + if (continuous) + seek_time = continuous_times[new_track == hdd->cur_track][!!cylinder_diff]; + else { + if (!cylinder_diff) + seek_time = times[operation != HDD_OP_SEEK]; + else { + seek_time = hdd->cyl_switch_usec + (hdd->full_stroke_usec * (double)cylinder_diff / (double)hdd->phy_cyl) + + ((operation != HDD_OP_SEEK) * hdd->avg_rotation_lat_usec); } + } -#ifndef OLD_CODE - double continuous_times[2][2] = { { hdd->head_switch_usec, hdd->cyl_switch_usec }, - { zone->sector_time_usec, zone->sector_time_usec } }; - double times[2] = { HDD_OVERHEAD_TIME, hdd->avg_rotation_lat_usec }; -#endif + if (!max_seek_time || seek_time <= max_seek_time) { + hdd->cur_addr = dst_addr; + hdd->cur_track = new_track; + hdd->cur_cylinder = new_cylinder; + } - uint32_t new_track = zone->start_track + ((dst_addr - zone->start_sector) / zone->sectors_per_track); - uint32_t new_cylinder = new_track / hdd->phy_heads; - uint32_t cylinder_diff = abs((int)hdd->cur_cylinder - (int)new_cylinder); - - bool sequential = dst_addr == hdd->cur_addr + 1; - continuous = continuous && sequential; - - double seek_time = 0.0; - if (continuous) { -#ifdef OLD_CODE - if (new_track == hdd->cur_track) { - // Same track - seek_time = zone->sector_time_usec; - } else if (!cylinder_diff) { - // Same cylinder, sequential track - seek_time = hdd->head_switch_usec; - } else { - // Sequential cylinder - seek_time = hdd->cyl_switch_usec; - } -#else - seek_time = continuous_times[new_track == hdd->cur_track][!!cylinder_diff]; -#endif - } else { - if (!cylinder_diff) { -#ifdef OLD_CODE - if (operation != HDD_OP_SEEK) { - seek_time = hdd->avg_rotation_lat_usec; - } else { - //seek_time = hdd->cyl_switch_usec; - seek_time = HDD_OVERHEAD_TIME; - } -#else - seek_time = times[operation != HDD_OP_SEEK]; -#endif - } else { -#ifdef OLD_CODE - seek_time = hdd->cyl_switch_usec + (hdd->full_stroke_usec * (double)cylinder_diff / (double)hdd->phy_cyl); - if (operation != HDD_OP_SEEK) { - seek_time += hdd->avg_rotation_lat_usec; - } -#else - seek_time = hdd->cyl_switch_usec + (hdd->full_stroke_usec * (double)cylinder_diff / (double)hdd->phy_cyl) + - ((operation != HDD_OP_SEEK) * hdd->avg_rotation_lat_usec); -#endif - } - } - - if (!max_seek_time || seek_time <= max_seek_time) { - hdd->cur_addr = dst_addr; - hdd->cur_track = new_track; - hdd->cur_cylinder = new_cylinder; - } - - return seek_time; + return seek_time; } + static void hdd_readahead_update(hard_disk_t *hdd) { - hdd_cache_t *cache = &hdd->cache; - if (cache->ra_ongoing) { - hdd_cache_seg_t *segment = &cache->segments[cache->ra_segment]; + uint64_t elapsed_cycles; + double elapsed_us, seek_time; + uint32_t max_read_ahead, i; + uint32_t space_needed; - uint64_t elapsed_cycles = tsc - cache->ra_start_time; - double elapsed_us = (double)elapsed_cycles / cpuclock * 1000000.0; - // Do not overwrite data not yet read by host - uint32_t max_read_ahead = (segment->host_addr + cache->segment_size) - segment->ra_addr; + hdd_cache_t *cache = &hdd->cache; + if (cache->ra_ongoing) { + hdd_cache_seg_t *segment = &cache->segments[cache->ra_segment]; - double seek_time = 0.0; + elapsed_cycles = tsc - cache->ra_start_time; + elapsed_us = (double)elapsed_cycles / cpuclock * 1000000.0; + /* Do not overwrite data not yet read by host */ + max_read_ahead = (segment->host_addr + cache->segment_size) - segment->ra_addr; - for (uint32_t i = 0; i < max_read_ahead; i++) { - seek_time += hdd_seek_get_time(hdd, segment->ra_addr, HDD_OP_READ, 1, elapsed_us - seek_time); - if (seek_time > elapsed_us) - break; + seek_time = 0.0; - segment->ra_addr++; - } + for (i = 0; i < max_read_ahead; i++) { + seek_time += hdd_seek_get_time(hdd, segment->ra_addr, HDD_OP_READ, 1, elapsed_us - seek_time); + if (seek_time > elapsed_us) + break; - if (segment->ra_addr > segment->lba_addr + cache->segment_size) { - uint32_t space_needed = segment->ra_addr - (segment->lba_addr + cache->segment_size); - segment->lba_addr += space_needed; - } + segment->ra_addr++; } + + if (segment->ra_addr > segment->lba_addr + cache->segment_size) { + space_needed = segment->ra_addr - (segment->lba_addr + cache->segment_size); + segment->lba_addr += space_needed; + } + } } + static double hdd_writecache_flush(hard_disk_t *hdd) { - double seek_time = 0.0; - while (hdd->cache.write_pending) { - seek_time += hdd_seek_get_time(hdd, hdd->cache.write_addr, HDD_OP_WRITE, 1, 0); - hdd->cache.write_addr++; - hdd->cache.write_pending--; - } + double seek_time = 0.0; - return seek_time; + while (hdd->cache.write_pending) { + seek_time += hdd_seek_get_time(hdd, hdd->cache.write_addr, HDD_OP_WRITE, 1, 0); + hdd->cache.write_addr++; + hdd->cache.write_pending--; + } + + return seek_time; } + static void hdd_writecache_update(hard_disk_t *hdd) { - if (hdd->cache.write_pending) { - uint64_t elapsed_cycles = tsc - hdd->cache.write_start_time; - double elapsed_us = (double)elapsed_cycles / cpuclock * 1000000.0; - double seek_time = 0.0; + uint64_t elapsed_cycles; + double elapsed_us, seek_time; - while (hdd->cache.write_pending) { - seek_time += hdd_seek_get_time(hdd, hdd->cache.write_addr, HDD_OP_WRITE, 1, elapsed_us - seek_time); - if (seek_time > elapsed_us) - break; + if (hdd->cache.write_pending) { + elapsed_cycles = tsc - hdd->cache.write_start_time; + elapsed_us = (double)elapsed_cycles / cpuclock * 1000000.0; + seek_time = 0.0; - hdd->cache.write_addr++; - hdd->cache.write_pending--; - } + while (hdd->cache.write_pending) { + seek_time += hdd_seek_get_time(hdd, hdd->cache.write_addr, HDD_OP_WRITE, 1, elapsed_us - seek_time); + if (seek_time > elapsed_us) + break; + + hdd->cache.write_addr++; + hdd->cache.write_pending--; } + } } + double hdd_timing_write(hard_disk_t *hdd, uint32_t addr, uint32_t len) { + double seek_time = 0.0; + uint32_t flush_needed; + if (!hdd->speed_preset) return HDD_OVERHEAD_TIME; - hdd_readahead_update(hdd); - hdd_writecache_update(hdd); + hdd_readahead_update(hdd); + hdd_writecache_update(hdd); - hdd->cache.ra_ongoing = 0; + hdd->cache.ra_ongoing = 0; - double seek_time = 0.0; + if (hdd->cache.write_pending && (addr != (hdd->cache.write_addr + hdd->cache.write_pending))) { + /* New request is not sequential to existing cache, need to flush it */ + seek_time += hdd_writecache_flush(hdd); + } - if (hdd->cache.write_pending && (addr != (hdd->cache.write_addr + hdd->cache.write_pending))) { - // New request is not sequential to existing cache, need to flush it - seek_time += hdd_writecache_flush(hdd); + if (!hdd->cache.write_pending) { + /* Cache is empty */ + hdd->cache.write_addr = addr; + } + + hdd->cache.write_pending += len; + if (hdd->cache.write_pending > hdd->cache.write_size) { + /* If request is bigger than free cache, flush some data first */ + flush_needed = hdd->cache.write_pending - hdd->cache.write_size; + for (uint32_t i = 0; i < flush_needed; i++) { + seek_time += hdd_seek_get_time(hdd, hdd->cache.write_addr, HDD_OP_WRITE, 1, 0); + hdd->cache.write_addr++; } + } - if (!hdd->cache.write_pending) { - // Cache is empty - hdd->cache.write_addr = addr; - } + hdd->cache.write_start_time = tsc + (uint32_t)(seek_time * cpuclock / 1000000.0); - hdd->cache.write_pending += len; - if (hdd->cache.write_pending > hdd->cache.write_size) { - // If request is bigger than free cache, flush some data first - uint32_t flush_needed = hdd->cache.write_pending - hdd->cache.write_size; - for (uint32_t i = 0; i < flush_needed; i++) { - seek_time += hdd_seek_get_time(hdd, hdd->cache.write_addr, HDD_OP_WRITE, 1, 0); - hdd->cache.write_addr++; - } - } - - hdd->cache.write_start_time = tsc + (uint32_t)(seek_time * cpuclock / 1000000.0); - - return seek_time; + return seek_time; } + double hdd_timing_read(hard_disk_t *hdd, uint32_t addr, uint32_t len) { + double seek_time = 0.0; + if (!hdd->speed_preset) return HDD_OVERHEAD_TIME; - hdd_readahead_update(hdd); - hdd_writecache_update(hdd); + hdd_readahead_update(hdd); + hdd_writecache_update(hdd); - double seek_time = 0.0; - seek_time += hdd_writecache_flush(hdd); + seek_time += hdd_writecache_flush(hdd); - hdd_cache_t *cache = &hdd->cache; - hdd_cache_seg_t *active_seg = &cache->segments[0]; + hdd_cache_t *cache = &hdd->cache; + hdd_cache_seg_t *active_seg = &cache->segments[0]; - for (uint32_t i = 0; i < cache->num_segments; i++) { - hdd_cache_seg_t *segment = &cache->segments[i]; - if (!segment->valid) { - active_seg = segment; - continue; - } - - if (segment->lba_addr <= addr && (segment->lba_addr + cache->segment_size) >= addr) { - // Cache HIT - segment->host_addr = addr; - active_seg = segment; - if (addr + len > segment->ra_addr) { - uint32_t need_read = (addr + len) - segment->ra_addr; - for (uint32_t j = 0; j < need_read; j++) { - seek_time += hdd_seek_get_time(hdd, segment->ra_addr, HDD_OP_READ, 1, 0.0); - segment->ra_addr++; - } - } - if (addr + len > segment->lba_addr + cache->segment_size) { - // Need to erase some previously cached data - uint32_t space_needed = (addr + len) - (segment->lba_addr + cache->segment_size); - segment->lba_addr += space_needed; - } - goto update_lru; - } else { - if (segment->lru > active_seg->lru) { - active_seg = segment; - } - } + for (uint32_t i = 0; i < cache->num_segments; i++) { + hdd_cache_seg_t *segment = &cache->segments[i]; + if (!segment->valid) { + active_seg = segment; + continue; } - // Cache MISS - active_seg->lba_addr = addr; - active_seg->valid = 1; - active_seg->host_addr = addr; - active_seg->ra_addr = addr; - - for (uint32_t i = 0; i < len; i++) { - seek_time += hdd_seek_get_time(hdd, active_seg->ra_addr, HDD_OP_READ, i != 0, 0.0); - active_seg->ra_addr++; + if (segment->lba_addr <= addr && (segment->lba_addr + cache->segment_size) >= addr) { + /* Cache HIT */ + segment->host_addr = addr; + active_seg = segment; + if (addr + len > segment->ra_addr) { + uint32_t need_read = (addr + len) - segment->ra_addr; + for (uint32_t j = 0; j < need_read; j++) { + seek_time += hdd_seek_get_time(hdd, segment->ra_addr, HDD_OP_READ, 1, 0.0); + segment->ra_addr++; + } + } + if (addr + len > segment->lba_addr + cache->segment_size) { + /* Need to erase some previously cached data */ + uint32_t space_needed = (addr + len) - (segment->lba_addr + cache->segment_size); + segment->lba_addr += space_needed; + } + goto update_lru; + } else { + if (segment->lru > active_seg->lru) + active_seg = segment; } + } + + /* Cache MISS */ + active_seg->lba_addr = addr; + active_seg->valid = 1; + active_seg->host_addr = addr; + active_seg->ra_addr = addr; + + for (uint32_t i = 0; i < len; i++) { + seek_time += hdd_seek_get_time(hdd, active_seg->ra_addr, HDD_OP_READ, i != 0, 0.0); + active_seg->ra_addr++; + } update_lru: - for (uint32_t i = 0; i < cache->num_segments; i++) { - cache->segments[i].lru++; - } + for (uint32_t i = 0; i < cache->num_segments; i++) + cache->segments[i].lru++; - active_seg->lru = 0; + active_seg->lru = 0; - cache->ra_ongoing = 1; - cache->ra_segment = active_seg->id; - cache->ra_start_time = tsc + (uint32_t)(seek_time * cpuclock / 1000000.0); + cache->ra_ongoing = 1; + cache->ra_segment = active_seg->id; + cache->ra_start_time = tsc + (uint32_t)(seek_time * cpuclock / 1000000.0); - return seek_time; + return seek_time; } + static void hdd_cache_init(hard_disk_t *hdd) { - hdd_cache_t *cache = &hdd->cache; - cache->ra_segment = 0; - cache->ra_ongoing = 0; - cache->ra_start_time = 0; + hdd_cache_t *cache = &hdd->cache; + uint32_t i; - for (uint32_t i = 0; i < cache->num_segments; i++) { - cache->segments[i].valid = 0; - cache->segments[i].lru = 0; - cache->segments[i].id = i; - cache->segments[i].ra_addr = 0; - cache->segments[i].host_addr = 0; - } + cache->ra_segment = 0; + cache->ra_ongoing = 0; + cache->ra_start_time = 0; + + for (i = 0; i < cache->num_segments; i++) { + cache->segments[i].valid = 0; + cache->segments[i].lru = 0; + cache->segments[i].id = i; + cache->segments[i].ra_addr = 0; + cache->segments[i].host_addr = 0; + } } + static void hdd_zones_init(hard_disk_t *hdd) { - uint32_t lba = 0; - uint32_t track = 0; + uint32_t lba = 0, track = 0; + uint32_t i, tracks; + double revolution_usec = 60.0 / (double)hdd->rpm * 1000000.0; + hdd_zone_t *zone; - double revolution_usec = 60.0 / (double)hdd->rpm * 1000000.0; - for (uint32_t i = 0; i < hdd->num_zones; i++) { - hdd_zone_t *zone = &hdd->zones[i]; - zone->start_sector = lba; - zone->start_track = track; - zone->sector_time_usec = revolution_usec / (double)zone->sectors_per_track; - uint32_t tracks = zone->cylinders * hdd->phy_heads; - lba += tracks * zone->sectors_per_track; - zone->end_sector = lba - 1; - track += tracks - 1; - } + for (i = 0; i < hdd->num_zones; i++) { + zone = &hdd->zones[i]; + zone->start_sector = lba; + zone->start_track = track; + zone->sector_time_usec = revolution_usec / (double)zone->sectors_per_track; + tracks = zone->cylinders * hdd->phy_heads; + lba += tracks * zone->sectors_per_track; + zone->end_sector = lba - 1; + track += tracks - 1; + } } + static hdd_preset_t hdd_speed_presets[] = { { .name = "RAM Disk (max. speed)", .internal_name = "ramdisk", .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 32 }, @@ -463,30 +456,33 @@ static hdd_preset_t hdd_speed_presets[] = { .full_stroke_ms = 15, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 32 }, }; + int hdd_preset_get_num() { return sizeof(hdd_speed_presets) / sizeof(hdd_preset_t); } + char * hdd_preset_getname(int preset) { return (char *)hdd_speed_presets[preset].name; } + char * hdd_preset_get_internal_name(int preset) { return (char *)hdd_speed_presets[preset].internal_name; } + int hdd_preset_get_from_internal_name(char *s) { int c = 0; - for (int i = 0; i < (sizeof(hdd_speed_presets) / sizeof(hdd_preset_t)); i++) { if (!strcmp((char *)hdd_speed_presets[c].internal_name, s)) return c; @@ -496,62 +492,64 @@ hdd_preset_get_from_internal_name(char *s) return 0; } + void hdd_preset_apply(int hdd_id) { - hard_disk_t *hd = &hdd[hdd_id]; + hard_disk_t *hd = &hdd[hdd_id]; + double revolution_usec, zone_percent; + uint32_t disk_sectors, sectors_per_surface, cylinders, cylinders_per_zone; + uint32_t total_sectors = 0, i; + uint32_t spt, zone_sectors; - if (hd->speed_preset >= hdd_preset_get_num()) - hd->speed_preset = 0; + if (hd->speed_preset >= hdd_preset_get_num()) + hd->speed_preset = 0; - hdd_preset_t *preset = &hdd_speed_presets[hd->speed_preset]; + hdd_preset_t *preset = &hdd_speed_presets[hd->speed_preset]; - hd->cache.num_segments = preset->rcache_num_seg; - hd->cache.segment_size = preset->rcache_seg_size; - hd->max_multiple_block = preset->max_multiple; + hd->cache.num_segments = preset->rcache_num_seg; + hd->cache.segment_size = preset->rcache_seg_size; + hd->max_multiple_block = preset->max_multiple; - if (!hd->speed_preset) - return; + if (!hd->speed_preset) + return; - hd->phy_heads = preset->heads; - hd->rpm = preset->rpm; + hd->phy_heads = preset->heads; + hd->rpm = preset->rpm; - double revolution_usec = 60.0 / (double)hd->rpm * 1000000.0; - hd->avg_rotation_lat_usec = revolution_usec / 2; - hd->full_stroke_usec = preset->full_stroke_ms * 1000; - hd->head_switch_usec = preset->track_seek_ms * 1000; - hd->cyl_switch_usec = preset->track_seek_ms * 1000; + revolution_usec = 60.0 / (double)hd->rpm * 1000000.0; + hd->avg_rotation_lat_usec = revolution_usec / 2; + hd->full_stroke_usec = preset->full_stroke_ms * 1000; + hd->head_switch_usec = preset->track_seek_ms * 1000; + hd->cyl_switch_usec = preset->track_seek_ms * 1000; - hd->cache.write_size = 64; + hd->cache.write_size = 64; - hd->num_zones = preset->zones; + hd->num_zones = preset->zones; - uint32_t disk_sectors = hd->tracks * hd->hpc * hd->spt; - uint32_t sectors_per_surface = (uint32_t)ceil((double)disk_sectors / (double)hd->phy_heads); - uint32_t cylinders = (uint32_t)ceil((double)sectors_per_surface / (double)preset->avg_spt); - hd->phy_cyl = cylinders; - uint32_t cylinders_per_zone = cylinders / preset->zones; + disk_sectors = hd->tracks * hd->hpc * hd->spt; + sectors_per_surface = (uint32_t)ceil((double)disk_sectors / (double)hd->phy_heads); + cylinders = (uint32_t)ceil((double)sectors_per_surface / (double)preset->avg_spt); + hd->phy_cyl = cylinders; + cylinders_per_zone = cylinders / preset->zones; - uint32_t total_sectors = 0; - for (uint32_t i = 0; i < preset->zones; i++) { - uint32_t spt; - double zone_percent = i * 100 / (double)preset->zones; + for (i = 0; i < preset->zones; i++) { + zone_percent = i * 100 / (double)preset->zones; - if (i < preset->zones - 1) { - // Function for realistic zone sector density - double spt_percent = -0.00341684 * pow(zone_percent, 2) - 0.175811 * zone_percent + 118.48; - spt = (uint32_t)ceil((double)preset->avg_spt * spt_percent / 100); - } else { - spt = (uint32_t)ceil((double)(disk_sectors - total_sectors) / (double)(cylinders_per_zone*preset->heads)); - } + if (i < preset->zones - 1) { + /* Function for realistic zone sector density */ + double spt_percent = -0.00341684 * pow(zone_percent, 2) - 0.175811 * zone_percent + 118.48; + spt = (uint32_t)ceil((double)preset->avg_spt * spt_percent / 100); + } else + spt = (uint32_t)ceil((double)(disk_sectors - total_sectors) / (double)(cylinders_per_zone*preset->heads)); - uint32_t zone_sectors = spt * cylinders_per_zone * preset->heads; - total_sectors += zone_sectors; + zone_sectors = spt * cylinders_per_zone * preset->heads; + total_sectors += zone_sectors; - hd->zones[i].cylinders = cylinders_per_zone; - hd->zones[i].sectors_per_track = spt; - } + hd->zones[i].cylinders = cylinders_per_zone; + hd->zones[i].sectors_per_track = spt; + } - hdd_zones_init(hd); - hdd_cache_init(hd); -} \ No newline at end of file + hdd_zones_init(hd); + hdd_cache_init(hd); +} From 184dc4c5f261fbea2b468324cf25ae7a081037cf Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 19 Jul 2022 23:52:55 +0200 Subject: [PATCH 093/386] And in video/vid_svga.c. --- src/video/vid_svga.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/video/vid_svga.c b/src/video/vid_svga.c index d7a122cb4..ea70248dc 100644 --- a/src/video/vid_svga.c +++ b/src/video/vid_svga.c @@ -658,7 +658,6 @@ svga_poll(void *p) uint32_t x, blink_delay; int wx, wy; int ret, old_ma; - int old_vc; if (!vga_on && ibm8514_enabled && ibm8514_on) { ibm8514_poll(&svga->dev8514, svga); @@ -787,7 +786,6 @@ svga_poll(void *p) return; svga->vc++; - old_vc = svga->vc; svga->vc &= 2047; if (svga->vc == svga->split) { From 307bddda1ea0cbc3ceca0c8ff7a936aa2dc0ecf8 Mon Sep 17 00:00:00 2001 From: AsciiWolf Date: Wed, 20 Jul 2022 00:08:16 +0200 Subject: [PATCH 094/386] Add screenshot to AppStream metainfo file --- src/unix/assets/net.86box.86Box.metainfo.xml | 5 +++++ src/unix/assets/screenshots/86Box.png | Bin 0 -> 14335 bytes 2 files changed, 5 insertions(+) create mode 100644 src/unix/assets/screenshots/86Box.png diff --git a/src/unix/assets/net.86box.86Box.metainfo.xml b/src/unix/assets/net.86box.86Box.metainfo.xml index 71121b708..982ae9b4d 100644 --- a/src/unix/assets/net.86box.86Box.metainfo.xml +++ b/src/unix/assets/net.86box.86Box.metainfo.xml @@ -28,5 +28,10 @@ want to emulate.