diff --git a/src/86box.c b/src/86box.c index fba67ca55..32724802c 100644 --- a/src/86box.c +++ b/src/86box.c @@ -97,6 +97,8 @@ #include <86box/version.h> #include <86box/gdbstub.h> #include <86box/machine_status.h> +#include <86box/apm.h> +#include <86box/acpi.h> // Disable c99-designator to avoid the warnings about int ng #ifdef __clang__ @@ -1016,6 +1018,9 @@ pc_reset_hard_init(void) * modules that are. */ + /* Mark ACPI as unavailable */ + acpi_enabled = 0; + /* Reset the general machine support modules. */ io_init(); diff --git a/src/acpi.c b/src/acpi.c index 5f9db8d05..2c5f2ff90 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -40,7 +40,9 @@ #include <86box/i2c.h> #include <86box/video.h> -int acpi_rtc_status = 0; +int acpi_rtc_status = 0; +atomic_int acpi_pwrbut_pressed = 0; +int acpi_enabled = 0; static double cpu_to_acpi; @@ -1516,6 +1518,21 @@ acpi_ali_soft_smi_status_write(acpi_t *dev, uint8_t soft_smi) dev->regs.ali_soft_smi = soft_smi; } +void +acpi_pwrbtn_timer(void* priv) +{ + acpi_t *dev = (acpi_t *) priv; + + timer_on_auto(&dev->pwrbtn_timer, 16. * 1000.); + if (acpi_pwrbut_pressed) { + acpi_pwrbut_pressed = 0; + if (dev->regs.pmen & PWRBTN_EN) { + dev->regs.pmsts |= PWRBTN_STS; + acpi_update_irq(dev); + } + } +} + static void acpi_apm_out(uint16_t port, uint8_t val, void *p) { @@ -1707,9 +1724,13 @@ acpi_init(const device_t *info) timer_add(&dev->timer, acpi_timer_overflow, dev, 0); timer_add(&dev->resume_timer, acpi_timer_resume, dev, 0); + timer_add(&dev->pwrbtn_timer, acpi_pwrbtn_timer, dev, 0); + + timer_on_auto(&dev->pwrbtn_timer, 16. * 1000.); acpi_reset(dev); + acpi_enabled = 1; return dev; } diff --git a/src/include/86box/acpi.h b/src/include/86box/acpi.h index 4d2f2ac0d..18f40d874 100644 --- a/src/include/86box/acpi.h +++ b/src/include/86box/acpi.h @@ -18,7 +18,11 @@ #define ACPI_H #ifdef __cplusplus +#include +using atomic_int = std::atomic_int; extern "C" { +#else +#include #endif #define ACPI_TIMER_FREQ 3579545 @@ -90,7 +94,7 @@ typedef struct slot, irq_mode, irq_pin, irq_line, mirq_is_level; - pc_timer_t timer, resume_timer; + pc_timer_t timer, resume_timer, pwrbtn_timer; nvr_t *nvr; apm_t *apm; void *i2c, @@ -98,7 +102,9 @@ typedef struct } acpi_t; /* Global variables. */ -extern int acpi_rtc_status; +extern int acpi_rtc_status; +extern atomic_int acpi_pwrbut_pressed; +extern int acpi_enabled; extern const device_t acpi_ali_device; extern const device_t acpi_intel_device; diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 0af5626f3..013650673 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -47,6 +47,9 @@ extern "C" { #include <86box/machine.h> #include <86box/vid_ega.h> #include <86box/version.h> +//#include <86box/acpi.h> /* Requires timer.h include, which conflicts with Qt headers */ +extern atomic_int acpi_pwrbut_pressed; +extern int acpi_enabled; #ifdef USE_VNC # include <86box/vnc.h> @@ -1679,6 +1682,7 @@ MainWindow::refreshMediaMenu() mm->refresh(ui->menuMedia); status->refresh(ui->statusbar); ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA)); + ui->actionACPI_Shutdown->setEnabled(!!acpi_enabled); } void @@ -2430,3 +2434,9 @@ MainWindow::on_actionApply_fullscreen_stretch_mode_when_maximized_triggered(bool device_force_redraw(); config_save(); } + +void MainWindow::on_actionACPI_Shutdown_triggered() +{ + acpi_pwrbut_pressed = 1; +} + diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 6ad4c9beb..9668ecbbb 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -134,6 +134,9 @@ protected: void closeEvent(QCloseEvent *event) override; void changeEvent(QEvent *event) override; +private slots: + void on_actionACPI_Shutdown_triggered(); + private slots: void on_actionShow_non_primary_monitors_triggered(); diff --git a/src/qt/qt_mainwindow.ui b/src/qt/qt_mainwindow.ui index 6a86b632e..eb921899b 100644 --- a/src/qt/qt_mainwindow.ui +++ b/src/qt/qt_mainwindow.ui @@ -743,7 +743,7 @@ - false + true @@ -756,7 +756,7 @@ ACPI Shutdown - false + true