From f907b7817b7573be1ea30a7f479866f065fbcd6e Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 4 May 2024 17:01:29 +0600 Subject: [PATCH 01/16] Microtouch support (working at least for MS-DOS, Windows 95 and Windows NT 3.5) --- src/device/CMakeLists.txt | 3 +- src/device/mouse.c | 1 + src/device/mouse_microtouch_touchscreen.c | 279 ++++++++++++++++++++++ src/include/86box/mouse.h | 1 + src/qt/qt_rendererstack.cpp | 2 +- 5 files changed, 284 insertions(+), 2 deletions(-) create mode 100644 src/device/mouse_microtouch_touchscreen.c diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt index c0719af2a1..e48f30d0f9 100644 --- a/src/device/CMakeLists.txt +++ b/src/device/CMakeLists.txt @@ -23,7 +23,8 @@ add_library(dev OBJECT bugger.c cassette.c cartridge.c hasp.c hwm.c hwm_lm75.c h keyboard_at.c mouse.c mouse_bus.c mouse_serial.c mouse_ps2.c nec_mate_unk.c phoenix_486_jumper.c serial_passthrough.c - novell_cardkey.c) + novell_cardkey.c + mouse_microtouch_touchscreen.c) if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") target_link_libraries(86Box atomic) diff --git a/src/device/mouse.c b/src/device/mouse.c index da4ed1c04e..8fd783ee29 100644 --- a/src/device/mouse.c +++ b/src/device/mouse.c @@ -98,6 +98,7 @@ static mouse_t mouse_devices[] = { { &mouse_wacom_device }, { &mouse_wacom_artpad_device }, #endif + { &mouse_mtouch_device }, { NULL } // clang-format on }; diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c new file mode 100644 index 0000000000..50323210a1 --- /dev/null +++ b/src/device/mouse_microtouch_touchscreen.c @@ -0,0 +1,279 @@ + +/* TODO: + MN, SS, SF commands (sensitivity-related). + GP/SP commands (formats are not documented at all). + GF, FQF, FQP (what are those for?) +*/ +#include +#include +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/timer.h> +#include <86box/mouse.h> +#include <86box/serial.h> +#include <86box/plat.h> +#include <86box/fifo8.h> +#include <86box/fifo.h> + +enum mtouch_modes +{ + MODE_TABLET = 1, + MODE_RAW = 2 +}; + +typedef struct mouse_microtouch_t { + double abs_x; + double abs_y; + int oldb; + int b; + char cmd[512]; + int bits; + int baud_rate_sel; + int cmd_pos; + int mode; + double rate; + bool soh; + bool in_reset; + serial_t *serial; + Fifo8 resp; + pc_timer_t host_to_serial_timer; + pc_timer_t reset_timer; +} mouse_microtouch_t; + +static mouse_microtouch_t* mtouch_inst = NULL; + +void microtouch_reset_complete(void *priv) +{ + mouse_microtouch_t *mtouch = (mouse_microtouch_t*)priv; + + mtouch->in_reset = false; + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); +} + +void microtouch_process_commands(mouse_microtouch_t* mtouch) +{ + int i = 0; + mtouch->cmd[strcspn(mtouch->cmd, "\r")] = '\0'; + mtouch->cmd_pos = 0; + pclog("Command received: %s\n", mtouch->cmd); + for (i = 0; i < strlen(mtouch->cmd); i++) { + mtouch->cmd[i] = toupper(mtouch->cmd[i]); + } + /* Re-enable and finish this if actually needed by TouchPen. */ + if (mtouch->cmd[0] == 'Z' || (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O')) { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + } + if (mtouch->cmd[0] == 'U' && mtouch->cmd[1] == 'T') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "QM****00\r", sizeof("QM****00\r") - 1); + } + if (mtouch->cmd[0] == 'O' && mtouch->cmd[1] == 'I') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "Q10200\r", sizeof("Q10200\r") - 1); + } + if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { + mtouch->mode = MODE_TABLET; + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + } + if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'S') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + } + if (mtouch->cmd[0] == 'R') { + mtouch->in_reset = true; + mtouch->mode = MODE_TABLET; + timer_on_auto(&mtouch->reset_timer, 500. * 1000.); + } + if (mtouch->cmd[0] == 'A' && (mtouch->cmd[1] == 'D' || mtouch->cmd[1] == 'E')) { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + } + if (mtouch->cmd[0] == 'N' && mtouch->cmd[1] == 'M') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); + } + if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'Q') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); + } + if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'F') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); + } +} + +void mtouch_write_to_host(void *priv) +{ + mouse_microtouch_t *dev = (mouse_microtouch_t*)priv; + if ((dev->serial->type >= SERIAL_16550) && dev->serial->fifo_enabled) { + if (fifo_get_full(dev->serial->rcvr_fifo)) { + goto no_write_to_machine; + } + } else { + if (dev->serial->lsr & 1) { + goto no_write_to_machine; + } + } + + if (dev->in_reset) + goto no_write_to_machine; + + if (fifo8_num_used(&dev->resp)) { + serial_write_fifo(dev->serial, fifo8_pop(&dev->resp)); + } + +no_write_to_machine: + timer_on_auto(&dev->host_to_serial_timer, (1000000.0 / (double) 9600.0) * (double) (1 + 8 + 1)); +} + +void mtouch_write(serial_t* serial, void* priv, uint8_t data) +{ + mouse_microtouch_t *dev = (mouse_microtouch_t*)priv; + if (!dev->soh && data == 0x11) { + pclog("\n"); + } + if (data == '\x1'){ + dev->soh = 1; + } else if (dev->soh) { + if (data != '\r') { + dev->cmd[dev->cmd_pos++] = data; + } else { + dev->cmd[dev->cmd_pos++] = data; + microtouch_process_commands(dev); + } + } +} + +static int +mtouch_poll(void *priv) +{ + mouse_microtouch_t *dev = (mouse_microtouch_t*)priv; + + if (dev->mode != MODE_RAW && fifo8_num_free(&dev->resp) >= 10) { + unsigned int abs_x_int = 0, abs_y_int = 0; + double abs_x; + double abs_y; + int b = mouse_get_buttons_ex(); + mouse_get_abs_coords(&abs_x, &abs_y); + dev->b |= b & 1; + if (abs_x >= 1.0) + abs_x = 1.0; + if (abs_y >= 1.0) + abs_y = 1.0; + if (abs_x <= 0.0) + abs_x = 0.0; + if (abs_y <= 0.0) + abs_y = 0.0; + if (b & 1) { + dev->abs_x = abs_x; + dev->abs_y = abs_y; + dev->b |= 1; + + abs_x_int = abs_x * 16383; + abs_y_int = 16383 - abs_y * 16383; + + fifo8_push(&dev->resp, 0b11000000); + fifo8_push(&dev->resp, abs_x_int & 0b1111111); + fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); + fifo8_push(&dev->resp, abs_y_int & 0b1111111); + fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111); + } else if ((dev->b & 1) && !(b & 1)) { + dev->b &= ~1; + abs_x_int = dev->abs_x * 16383; + abs_y_int = 16383 - dev->abs_y * 16383; + fifo8_push(&dev->resp, 0b11000000); + fifo8_push(&dev->resp, abs_x_int & 0b1111111); + fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); + fifo8_push(&dev->resp, abs_y_int & 0b1111111); + fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111); + fifo8_push(&dev->resp, 0b10000000); + fifo8_push(&dev->resp, abs_x_int & 0b1111111); + fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); + fifo8_push(&dev->resp, abs_y_int & 0b1111111); + fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111); + } + } + return 0; +} + +static void mtouch_poll_global(void) +{ + mtouch_poll(mtouch_inst); +} + +void* mtouch_init(const device_t* info) +{ + mouse_microtouch_t *dev = calloc(1, sizeof(mouse_microtouch_t)); + + dev->serial = serial_attach(device_get_config_int("port"), NULL, mtouch_write, dev); + fifo8_create(&dev->resp, 512); + timer_add(&dev->host_to_serial_timer, mtouch_write_to_host, dev, 0); + timer_add(&dev->reset_timer, microtouch_reset_complete, dev, 0); + timer_on_auto(&dev->host_to_serial_timer, (1000000. / 9600.) * 10); + dev->mode = MODE_TABLET; + mouse_input_mode = 1; + mouse_set_buttons(2); + mouse_set_poll_ex(mtouch_poll_global); + + mtouch_inst = dev; + + return dev; +} + +void mtouch_close(void* priv) +{ + mouse_microtouch_t *dev = (mouse_microtouch_t *) priv; + + fifo8_destroy(&dev->resp); + /* Detach serial port from the mouse. */ + if (dev && dev->serial && dev->serial->sd) + memset(dev->serial->sd, 0, sizeof(serial_device_t)); + + free(dev); + mtouch_inst = NULL; +} + +static const device_config_t mtouch_config[] = { + // clang-format off + { + .name = "port", + .description = "Serial Port", + .type = CONFIG_SELECTION, + .default_string = "", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .selection = { + { .description = "COM1", .value = 0 }, + { .description = "COM2", .value = 1 }, + { .description = "COM3", .value = 2 }, + { .description = "COM4", .value = 3 }, + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t mouse_mtouch_device = { + .name = "3M MicroTouch SMT3", + .internal_name = "microtouch_touchpen", + .flags = DEVICE_COM, + .local = 0, + .init = mtouch_init, + .close = mtouch_close, + .reset = NULL, + { .poll = mtouch_poll }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = mtouch_config +}; + diff --git a/src/include/86box/mouse.h b/src/include/86box/mouse.h index 786b86f410..e9c1d9b4da 100644 --- a/src/include/86box/mouse.h +++ b/src/include/86box/mouse.h @@ -73,6 +73,7 @@ extern const device_t mouse_ltserial_device; extern const device_t mouse_ps2_device; extern const device_t mouse_wacom_device; extern const device_t mouse_wacom_artpad_device; +extern const device_t mouse_mtouch_device; #endif extern void mouse_clear_x(void); diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index bc4cb9c133..590c025e83 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -250,7 +250,7 @@ RendererStack::enterEvent(QEvent *event) mousedata.mouse_tablet_in_proximity = 1; if (mouse_input_mode == 1) - QApplication::setOverrideCursor(Qt::BlankCursor); + QApplication::setOverrideCursor(Qt::CrossCursor); } void From 7277316c1b7ea38ab5562da0b5a0a4721c5a8532 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 4 May 2024 23:36:09 +0600 Subject: [PATCH 02/16] Cursor override fixes and preparation for overscan checking --- src/qt/qt_mainwindow.cpp | 3 ++- src/qt/qt_rendererstack.cpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index c48dfd052b..112d1cf231 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -205,7 +205,8 @@ MainWindow::MainWindow(QWidget *parent) connect(this, &MainWindow::hardResetCompleted, this, [this]() { ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA)); - QApplication::setOverrideCursor(Qt::ArrowCursor); + while (QApplication::overrideCursor()) + QApplication::restoreOverrideCursor(); #ifdef USE_WACOM ui->menuTablet_tool->menuAction()->setVisible(mouse_input_mode >= 1); #else diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index 590c025e83..d043f823c3 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -114,7 +114,8 @@ RendererStack::RendererStack(QWidget *parent, int monitor_index) RendererStack::~RendererStack() { - QApplication::restoreOverrideCursor(); + while (QApplication::overrideCursor()) + QApplication::restoreOverrideCursor(); delete ui; } @@ -123,7 +124,7 @@ qt_mouse_capture(int on) { if (!on) { mouse_capture = 0; - if (QApplication::overrideCursor()) QApplication::restoreOverrideCursor(); + while (QApplication::overrideCursor()) QApplication::restoreOverrideCursor(); #ifdef __APPLE__ CGAssociateMouseAndMouseCursorPosition(true); #endif @@ -247,7 +248,7 @@ RendererStack::enterEvent(QEnterEvent *event) RendererStack::enterEvent(QEvent *event) #endif { - mousedata.mouse_tablet_in_proximity = 1; + mousedata.mouse_tablet_in_proximity = m_monitor_index + 1; if (mouse_input_mode == 1) QApplication::setOverrideCursor(Qt::CrossCursor); @@ -258,8 +259,10 @@ RendererStack::leaveEvent(QEvent *event) { mousedata.mouse_tablet_in_proximity = 0; - if (mouse_input_mode == 1 && QApplication::overrideCursor()) - QApplication::restoreOverrideCursor(); + if (mouse_input_mode == 1 && QApplication::overrideCursor()) { + while (QApplication::overrideCursor()) + QApplication::restoreOverrideCursor(); + } if (QApplication::platformName().contains("wayland")) { event->accept(); return; From 754f304deb86299f64e284e7db7da1d46806c993 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sun, 5 May 2024 13:06:35 +0600 Subject: [PATCH 03/16] Overscan handling --- src/device/mouse_microtouch_touchscreen.c | 37 ++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 50323210a1..e063260eab 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -19,6 +19,7 @@ #include <86box/plat.h> #include <86box/fifo8.h> #include <86box/fifo.h> +#include <86box/video.h> /* Needed to account for overscan. */ enum mtouch_modes { @@ -65,7 +66,6 @@ void microtouch_process_commands(mouse_microtouch_t* mtouch) for (i = 0; i < strlen(mtouch->cmd); i++) { mtouch->cmd[i] = toupper(mtouch->cmd[i]); } - /* Re-enable and finish this if actually needed by TouchPen. */ if (mtouch->cmd[0] == 'Z' || (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O')) { fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); @@ -87,6 +87,18 @@ void microtouch_process_commands(mouse_microtouch_t* mtouch) fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); } + if (mtouch->cmd[0] == 'P' && mtouch->cmd[1] == 'F') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + } + if (mtouch->cmd[0] == 'P' && mtouch->cmd[1] == 'O') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + } + if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + } if (mtouch->cmd[0] == 'R') { mtouch->in_reset = true; mtouch->mode = MODE_TABLET; @@ -172,6 +184,29 @@ mtouch_poll(void *priv) abs_x = 0.0; if (abs_y <= 0.0) abs_y = 0.0; + if (enable_overscan) { + int index = mouse_tablet_in_proximity - 1; + if (mouse_tablet_in_proximity == -1) + mouse_tablet_in_proximity = 0; + + abs_x *= monitors[index].mon_unscaled_size_x - 1; + abs_y *= monitors[index].mon_efscrnsz_y - 1; + + if (abs_x <= (monitors[index].mon_overscan_x / 2.)) { + abs_x = (monitors[index].mon_overscan_x / 2.); + } + if (abs_y <= (monitors[index].mon_overscan_y / 2.)) { + abs_y = (monitors[index].mon_overscan_y / 2.); + } + abs_x -= (monitors[index].mon_overscan_x / 2.); + abs_y -= (monitors[index].mon_overscan_y / 2.); + abs_x = abs_x / (double)monitors[index].mon_xsize; + abs_y = abs_y / (double)monitors[index].mon_ysize; + if (abs_x >= 1.0) + abs_x = 1.0; + if (abs_y >= 1.0) + abs_y = 1.0; + } if (b & 1) { dev->abs_x = abs_x; dev->abs_y = abs_y; From d9fa8bbb4a1eab05b04ea536f300c6d4fc8bd056 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sun, 5 May 2024 14:25:31 +0600 Subject: [PATCH 04/16] Implement calibration --- src/device/mouse_microtouch_touchscreen.c | 44 +++++++++++++++++------ 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index e063260eab..14d400fbc5 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -37,6 +37,7 @@ typedef struct mouse_microtouch_t { int baud_rate_sel; int cmd_pos; int mode; + uint8_t cal_cntr; double rate; bool soh; bool in_reset; @@ -57,6 +58,17 @@ void microtouch_reset_complete(void *priv) fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); } +void microtouch_calibrate_timer(void *priv) +{ + mouse_microtouch_t *mtouch = (mouse_microtouch_t*)priv; + + if (!fifo8_num_used(&mtouch->resp)) { + mtouch->cal_cntr--; + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); + } +} + void microtouch_process_commands(mouse_microtouch_t* mtouch) { int i = 0; @@ -83,19 +95,13 @@ void microtouch_process_commands(mouse_microtouch_t* mtouch) fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); } - if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'S') { - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); - } - if (mtouch->cmd[0] == 'P' && mtouch->cmd[1] == 'F') { - fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); - } - if (mtouch->cmd[0] == 'P' && mtouch->cmd[1] == 'O') { + if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'R') { + mtouch->mode = MODE_RAW; + mtouch->cal_cntr = 0; fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); } - if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O') { + if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'S') { fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); } @@ -120,6 +126,15 @@ void microtouch_process_commands(mouse_microtouch_t* mtouch) fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); } + if (mtouch->cmd[0] == 'P') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + } + if (mtouch->cmd[0] == 'C' && (mtouch->cmd[1] == 'N' || mtouch->cmd[1] == 'X')) { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + mtouch->cal_cntr = 2; + } } void mtouch_write_to_host(void *priv) @@ -207,6 +222,15 @@ mtouch_poll(void *priv) if (abs_y >= 1.0) abs_y = 1.0; } + if (dev->cal_cntr && (!(dev->b & 1) && (b & 1))) { + dev->b |= 1; + } else if (dev->cal_cntr && ((dev->b & 1) && !(b & 1))) { + dev->b &= ~1; + microtouch_calibrate_timer(dev); + } + if (dev->cal_cntr) { + return 0; + } if (b & 1) { dev->abs_x = abs_x; dev->abs_y = abs_y; From 34ec412bae9694619da6c42a7270f9cbed1a0539 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sun, 5 May 2024 14:36:42 +0600 Subject: [PATCH 05/16] Cleanups and copyright text --- src/device/mouse_microtouch_touchscreen.c | 29 ++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 14d400fbc5..568b6b15b2 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -1,15 +1,28 @@ +/* + * 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. + * + * 3M MicroTouch SMT3 emulation. + * + * + * + * Authors: Cacodemon345 + * + * Copyright 2024 Cacodemon345 + */ /* TODO: - MN, SS, SF commands (sensitivity-related). - GP/SP commands (formats are not documented at all). - GF, FQF, FQP (what are those for?) + GP/SP commands (formats are not documented at all, like anywhere). */ #include #include #include #include #include -#include #include #include <86box/86box.h> #include <86box/device.h> @@ -30,15 +43,11 @@ enum mtouch_modes typedef struct mouse_microtouch_t { double abs_x; double abs_y; - int oldb; int b; char cmd[512]; - int bits; - int baud_rate_sel; int cmd_pos; int mode; uint8_t cal_cntr; - double rate; bool soh; bool in_reset; serial_t *serial; @@ -108,6 +117,7 @@ void microtouch_process_commands(mouse_microtouch_t* mtouch) if (mtouch->cmd[0] == 'R') { mtouch->in_reset = true; mtouch->mode = MODE_TABLET; + mtouch->cal_cntr = 0; timer_on_auto(&mtouch->reset_timer, 500. * 1000.); } if (mtouch->cmd[0] == 'A' && (mtouch->cmd[1] == 'D' || mtouch->cmd[1] == 'E')) { @@ -164,9 +174,6 @@ void mtouch_write_to_host(void *priv) void mtouch_write(serial_t* serial, void* priv, uint8_t data) { mouse_microtouch_t *dev = (mouse_microtouch_t*)priv; - if (!dev->soh && data == 0x11) { - pclog("\n"); - } if (data == '\x1'){ dev->soh = 1; } else if (dev->soh) { From 4fe7090047b47fc83fb540d2023c5a01172411ba Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sun, 5 May 2024 14:55:42 +0600 Subject: [PATCH 06/16] Apply clang-format --- src/device/mouse_microtouch_touchscreen.c | 124 ++++++++++++---------- 1 file changed, 65 insertions(+), 59 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 568b6b15b2..703a372c60 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -15,7 +15,7 @@ * Copyright 2024 Cacodemon345 */ -/* TODO: +/* TODO: GP/SP commands (formats are not documented at all, like anywhere). */ #include @@ -34,122 +34,125 @@ #include <86box/fifo.h> #include <86box/video.h> /* Needed to account for overscan. */ -enum mtouch_modes -{ +enum mtouch_modes { MODE_TABLET = 1, - MODE_RAW = 2 + MODE_RAW = 2 }; typedef struct mouse_microtouch_t { - double abs_x; - double abs_y; - int b; - char cmd[512]; - int cmd_pos; - int mode; - uint8_t cal_cntr; - bool soh; - bool in_reset; - serial_t *serial; - Fifo8 resp; - pc_timer_t host_to_serial_timer; - pc_timer_t reset_timer; + double abs_x; + double abs_y; + int b; + char cmd[512]; + int cmd_pos; + int mode; + uint8_t cal_cntr; + bool soh; + bool in_reset; + serial_t *serial; + Fifo8 resp; + pc_timer_t host_to_serial_timer; + pc_timer_t reset_timer; } mouse_microtouch_t; -static mouse_microtouch_t* mtouch_inst = NULL; +static mouse_microtouch_t *mtouch_inst = NULL; -void microtouch_reset_complete(void *priv) +void +microtouch_reset_complete(void *priv) { - mouse_microtouch_t *mtouch = (mouse_microtouch_t*)priv; + mouse_microtouch_t *mtouch = (mouse_microtouch_t *) priv; - mtouch->in_reset = false; + mtouch->in_reset = false; fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); } -void microtouch_calibrate_timer(void *priv) +void +microtouch_calibrate_timer(void *priv) { - mouse_microtouch_t *mtouch = (mouse_microtouch_t*)priv; + mouse_microtouch_t *mtouch = (mouse_microtouch_t *) priv; if (!fifo8_num_used(&mtouch->resp)) { mtouch->cal_cntr--; fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "1\r", 2); } } -void microtouch_process_commands(mouse_microtouch_t* mtouch) +void +microtouch_process_commands(mouse_microtouch_t *mtouch) { - int i = 0; + int i = 0; mtouch->cmd[strcspn(mtouch->cmd, "\r")] = '\0'; - mtouch->cmd_pos = 0; + mtouch->cmd_pos = 0; pclog("Command received: %s\n", mtouch->cmd); for (i = 0; i < strlen(mtouch->cmd); i++) { mtouch->cmd[i] = toupper(mtouch->cmd[i]); } if (mtouch->cmd[0] == 'Z' || (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O')) { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); } if (mtouch->cmd[0] == 'U' && mtouch->cmd[1] == 'T') { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "QM****00\r", sizeof("QM****00\r") - 1); + fifo8_push_all(&mtouch->resp, (uint8_t *) "QM****00\r", sizeof("QM****00\r") - 1); } if (mtouch->cmd[0] == 'O' && mtouch->cmd[1] == 'I') { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "Q10200\r", sizeof("Q10200\r") - 1); + fifo8_push_all(&mtouch->resp, (uint8_t *) "Q10200\r", sizeof("Q10200\r") - 1); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { mtouch->mode = MODE_TABLET; fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'R') { - mtouch->mode = MODE_RAW; + mtouch->mode = MODE_RAW; mtouch->cal_cntr = 0; fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); } if (mtouch->cmd[0] == 'M' && mtouch->cmd[1] == 'S') { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); } if (mtouch->cmd[0] == 'R') { mtouch->in_reset = true; - mtouch->mode = MODE_TABLET; + mtouch->mode = MODE_TABLET; mtouch->cal_cntr = 0; timer_on_auto(&mtouch->reset_timer, 500. * 1000.); } if (mtouch->cmd[0] == 'A' && (mtouch->cmd[1] == 'D' || mtouch->cmd[1] == 'E')) { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); } if (mtouch->cmd[0] == 'N' && mtouch->cmd[1] == 'M') { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "1\r", 2); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'Q') { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "1\r", 2); } if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'F') { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "1\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "1\r", 2); } if (mtouch->cmd[0] == 'P') { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); } if (mtouch->cmd[0] == 'C' && (mtouch->cmd[1] == 'N' || mtouch->cmd[1] == 'X')) { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t*) "0\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); mtouch->cal_cntr = 2; } } -void mtouch_write_to_host(void *priv) +void +mtouch_write_to_host(void *priv) { - mouse_microtouch_t *dev = (mouse_microtouch_t*)priv; + mouse_microtouch_t *dev = (mouse_microtouch_t *) priv; if ((dev->serial->type >= SERIAL_16550) && dev->serial->fifo_enabled) { if (fifo_get_full(dev->serial->rcvr_fifo)) { goto no_write_to_machine; @@ -171,10 +174,11 @@ void mtouch_write_to_host(void *priv) timer_on_auto(&dev->host_to_serial_timer, (1000000.0 / (double) 9600.0) * (double) (1 + 8 + 1)); } -void mtouch_write(serial_t* serial, void* priv, uint8_t data) +void +mtouch_write(serial_t *serial, void *priv, uint8_t data) { - mouse_microtouch_t *dev = (mouse_microtouch_t*)priv; - if (data == '\x1'){ + mouse_microtouch_t *dev = (mouse_microtouch_t *) priv; + if (data == '\x1') { dev->soh = 1; } else if (dev->soh) { if (data != '\r') { @@ -189,13 +193,13 @@ void mtouch_write(serial_t* serial, void* priv, uint8_t data) static int mtouch_poll(void *priv) { - mouse_microtouch_t *dev = (mouse_microtouch_t*)priv; + mouse_microtouch_t *dev = (mouse_microtouch_t *) priv; if (dev->mode != MODE_RAW && fifo8_num_free(&dev->resp) >= 10) { unsigned int abs_x_int = 0, abs_y_int = 0; - double abs_x; - double abs_y; - int b = mouse_get_buttons_ex(); + double abs_x; + double abs_y; + int b = mouse_get_buttons_ex(); mouse_get_abs_coords(&abs_x, &abs_y); dev->b |= b & 1; if (abs_x >= 1.0) @@ -222,8 +226,8 @@ mtouch_poll(void *priv) } abs_x -= (monitors[index].mon_overscan_x / 2.); abs_y -= (monitors[index].mon_overscan_y / 2.); - abs_x = abs_x / (double)monitors[index].mon_xsize; - abs_y = abs_y / (double)monitors[index].mon_ysize; + abs_x = abs_x / (double) monitors[index].mon_xsize; + abs_y = abs_y / (double) monitors[index].mon_ysize; if (abs_x >= 1.0) abs_x = 1.0; if (abs_y >= 1.0) @@ -242,7 +246,7 @@ mtouch_poll(void *priv) dev->abs_x = abs_x; dev->abs_y = abs_y; dev->b |= 1; - + abs_x_int = abs_x * 16383; abs_y_int = 16383 - abs_y * 16383; @@ -270,12 +274,14 @@ mtouch_poll(void *priv) return 0; } -static void mtouch_poll_global(void) +static void +mtouch_poll_global(void) { mtouch_poll(mtouch_inst); } -void* mtouch_init(const device_t* info) +void * +mtouch_init(const device_t *info) { mouse_microtouch_t *dev = calloc(1, sizeof(mouse_microtouch_t)); @@ -284,7 +290,7 @@ void* mtouch_init(const device_t* info) timer_add(&dev->host_to_serial_timer, mtouch_write_to_host, dev, 0); timer_add(&dev->reset_timer, microtouch_reset_complete, dev, 0); timer_on_auto(&dev->host_to_serial_timer, (1000000. / 9600.) * 10); - dev->mode = MODE_TABLET; + dev->mode = MODE_TABLET; mouse_input_mode = 1; mouse_set_buttons(2); mouse_set_poll_ex(mtouch_poll_global); @@ -294,7 +300,8 @@ void* mtouch_init(const device_t* info) return dev; } -void mtouch_close(void* priv) +void +mtouch_close(void *priv) { mouse_microtouch_t *dev = (mouse_microtouch_t *) priv; @@ -342,4 +349,3 @@ const device_t mouse_mtouch_device = { .force_redraw = NULL, .config = mtouch_config }; - From fe5ce508639ec7c7134d1c6d692a0c638afb1ae2 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 6 May 2024 16:42:42 +0600 Subject: [PATCH 07/16] Stubbed Get Parameter Block command --- src/device/mouse_microtouch_touchscreen.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 703a372c60..954d10ee45 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -147,6 +147,13 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); mtouch->cal_cntr = 2; } + if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t *) "A\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + } } void From 9faf4dc7650ecd8e22b1a36b93b4315966070e53 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 7 May 2024 00:21:52 +0600 Subject: [PATCH 08/16] Stubbed Set Parameter Block command --- src/device/mouse_microtouch_touchscreen.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 954d10ee45..ca0f16dd4e 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -150,10 +150,14 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) if (mtouch->cmd[0] == 'G' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t *) "A\r", 2); - fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0000000000000000000000000\r", sizeof("0000000000000000000000000\r") - 1); fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); } + if (mtouch->cmd[0] == 'S' && mtouch->cmd[1] == 'P' && mtouch->cmd[2] == '1') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t *) "A\r", 2); + } } void From c71ca84d815e8c8d2c319e5128b5789d798d9a94 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 7 May 2024 15:49:28 +0600 Subject: [PATCH 09/16] Emulate a TouchPen instead --- src/device/mouse_microtouch_touchscreen.c | 36 +++++++++++++++-------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index ca0f16dd4e..788413ffcd 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -46,7 +46,7 @@ typedef struct mouse_microtouch_t { char cmd[512]; int cmd_pos; int mode; - uint8_t cal_cntr; + uint8_t cal_cntr, pen_mode; bool soh; bool in_reset; serial_t *serial; @@ -89,17 +89,22 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) for (i = 0; i < strlen(mtouch->cmd); i++) { mtouch->cmd[i] = toupper(mtouch->cmd[i]); } - if (mtouch->cmd[0] == 'Z' || (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O')) { + if (mtouch->cmd[0] == 'Z') { + fifo8_push(&mtouch->resp, 1); + fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); + } + if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'O') { + mtouch->pen_mode = 1; fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); } if (mtouch->cmd[0] == 'U' && mtouch->cmd[1] == 'T') { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "QM****00\r", sizeof("QM****00\r") - 1); + fifo8_push_all(&mtouch->resp, (uint8_t *) "TP****00\r", sizeof("TP****00\r") - 1); } if (mtouch->cmd[0] == 'O' && mtouch->cmd[1] == 'I') { fifo8_push(&mtouch->resp, 1); - fifo8_push_all(&mtouch->resp, (uint8_t *) "Q10200\r", sizeof("Q10200\r") - 1); + fifo8_push_all(&mtouch->resp, (uint8_t *) "P50200\r", sizeof("P50200\r") - 1); } if (mtouch->cmd[0] == 'F' && mtouch->cmd[1] == 'T') { mtouch->mode = MODE_TABLET; @@ -120,6 +125,7 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) mtouch->in_reset = true; mtouch->mode = MODE_TABLET; mtouch->cal_cntr = 0; + mtouch->pen_mode = 3; timer_on_auto(&mtouch->reset_timer, 500. * 1000.); } if (mtouch->cmd[0] == 'A' && (mtouch->cmd[1] == 'D' || mtouch->cmd[1] == 'E')) { @@ -139,6 +145,8 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) fifo8_push_all(&mtouch->resp, (uint8_t *) "1\r", 2); } if (mtouch->cmd[0] == 'P') { + if (mtouch->cmd[1] == 'F') mtouch->pen_mode = 3; + else if (mtouch->cmd[1] == 'O') mtouch->pen_mode = 2; fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t *) "0\r", 2); } @@ -212,7 +220,8 @@ mtouch_poll(void *priv) double abs_y; int b = mouse_get_buttons_ex(); mouse_get_abs_coords(&abs_x, &abs_y); - dev->b |= b & 1; + dev->b |= !!(b & 3); + if (abs_x >= 1.0) abs_x = 1.0; if (abs_y >= 1.0) @@ -244,16 +253,16 @@ mtouch_poll(void *priv) if (abs_y >= 1.0) abs_y = 1.0; } - if (dev->cal_cntr && (!(dev->b & 1) && (b & 1))) { + if (dev->cal_cntr && (!(dev->b & 1) && !!(b & 3))) { dev->b |= 1; - } else if (dev->cal_cntr && ((dev->b & 1) && !(b & 1))) { + } else if (dev->cal_cntr && ((dev->b & 1) && !!(b & 3))) { dev->b &= ~1; microtouch_calibrate_timer(dev); } if (dev->cal_cntr) { return 0; } - if (b & 1) { + if (!!(b & 3)) { dev->abs_x = abs_x; dev->abs_y = abs_y; dev->b |= 1; @@ -261,21 +270,21 @@ mtouch_poll(void *priv) abs_x_int = abs_x * 16383; abs_y_int = 16383 - abs_y * 16383; - fifo8_push(&dev->resp, 0b11000000); + fifo8_push(&dev->resp, 0b11000000 | ((dev->pen_mode & 2) ? ((1 << 5) | ((b & 3))) : 0)); fifo8_push(&dev->resp, abs_x_int & 0b1111111); fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); fifo8_push(&dev->resp, abs_y_int & 0b1111111); fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111); - } else if ((dev->b & 1) && !(b & 1)) { + } else if ((dev->b & 1) && !(b & 3)) { dev->b &= ~1; abs_x_int = dev->abs_x * 16383; abs_y_int = 16383 - dev->abs_y * 16383; - fifo8_push(&dev->resp, 0b11000000); + fifo8_push(&dev->resp, 0b11000000 | ((dev->pen_mode & 2) ? ((1 << 5)) : 0)); fifo8_push(&dev->resp, abs_x_int & 0b1111111); fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); fifo8_push(&dev->resp, abs_y_int & 0b1111111); fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111); - fifo8_push(&dev->resp, 0b10000000); + fifo8_push(&dev->resp, 0b10000000 | ((dev->pen_mode & 2) ? ((1 << 5)) : 0)); fifo8_push(&dev->resp, abs_x_int & 0b1111111); fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); fifo8_push(&dev->resp, abs_y_int & 0b1111111); @@ -302,6 +311,7 @@ mtouch_init(const device_t *info) timer_add(&dev->reset_timer, microtouch_reset_complete, dev, 0); timer_on_auto(&dev->host_to_serial_timer, (1000000. / 9600.) * 10); dev->mode = MODE_TABLET; + dev->pen_mode = 3; mouse_input_mode = 1; mouse_set_buttons(2); mouse_set_poll_ex(mtouch_poll_global); @@ -348,7 +358,7 @@ static const device_config_t mtouch_config[] = { }; const device_t mouse_mtouch_device = { - .name = "3M MicroTouch SMT3", + .name = "3M MicroTouch TouchPen 4", .internal_name = "microtouch_touchpen", .flags = DEVICE_COM, .local = 0, From ef7b4044ef812420b54f29141fdce8f3410fa431 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 20 May 2024 13:05:35 +0600 Subject: [PATCH 10/16] Report finger touches if in Pen or Finger mode --- src/device/mouse_microtouch_touchscreen.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 788413ffcd..db889249e5 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -270,7 +270,7 @@ mtouch_poll(void *priv) abs_x_int = abs_x * 16383; abs_y_int = 16383 - abs_y * 16383; - fifo8_push(&dev->resp, 0b11000000 | ((dev->pen_mode & 2) ? ((1 << 5) | ((b & 3))) : 0)); + fifo8_push(&dev->resp, 0b11000000 | ((dev->pen_mode == 2) ? ((1 << 5) | ((b & 3))) : 0)); fifo8_push(&dev->resp, abs_x_int & 0b1111111); fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); fifo8_push(&dev->resp, abs_y_int & 0b1111111); @@ -279,12 +279,12 @@ mtouch_poll(void *priv) dev->b &= ~1; abs_x_int = dev->abs_x * 16383; abs_y_int = 16383 - dev->abs_y * 16383; - fifo8_push(&dev->resp, 0b11000000 | ((dev->pen_mode & 2) ? ((1 << 5)) : 0)); + fifo8_push(&dev->resp, 0b11000000 | ((dev->pen_mode == 2) ? ((1 << 5)) : 0)); fifo8_push(&dev->resp, abs_x_int & 0b1111111); fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); fifo8_push(&dev->resp, abs_y_int & 0b1111111); fifo8_push(&dev->resp, (abs_y_int >> 7) & 0b1111111); - fifo8_push(&dev->resp, 0b10000000 | ((dev->pen_mode & 2) ? ((1 << 5)) : 0)); + fifo8_push(&dev->resp, 0b10000000 | ((dev->pen_mode == 2) ? ((1 << 5)) : 0)); fifo8_push(&dev->resp, abs_x_int & 0b1111111); fifo8_push(&dev->resp, (abs_x_int >> 7) & 0b1111111); fifo8_push(&dev->resp, abs_y_int & 0b1111111); From 95d7fa828ba719a9abe5fc96c50d62497d433dfd Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 12 Jun 2024 00:24:58 +0600 Subject: [PATCH 11/16] Fixes for calibration and baud rate workaround --- src/device/mouse_microtouch_touchscreen.c | 31 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index db889249e5..af5ef5bf02 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -15,8 +15,11 @@ * Copyright 2024 Cacodemon345 */ +/* Reference: https://www.touchwindow.com/mm5/drivers/mtsctlrm.pdf */ + /* TODO: - GP/SP commands (formats are not documented at all, like anywhere). + Properly implement GP/SP commands (formats are not documented at all, like anywhere; no dumps yet). + - Dynamic baud rate selection from software following this. */ #include #include @@ -42,6 +45,7 @@ enum mtouch_modes { typedef struct mouse_microtouch_t { double abs_x; double abs_y; + double baud_rate; int b; char cmd[512]; int cmd_pos; @@ -83,9 +87,9 @@ void microtouch_process_commands(mouse_microtouch_t *mtouch) { int i = 0; + int fifo_used = fifo8_num_used(&mtouch->resp); mtouch->cmd[strcspn(mtouch->cmd, "\r")] = '\0'; mtouch->cmd_pos = 0; - pclog("Command received: %s\n", mtouch->cmd); for (i = 0; i < strlen(mtouch->cmd); i++) { mtouch->cmd[i] = toupper(mtouch->cmd[i]); } @@ -166,6 +170,8 @@ microtouch_process_commands(mouse_microtouch_t *mtouch) fifo8_push(&mtouch->resp, 1); fifo8_push_all(&mtouch->resp, (uint8_t *) "A\r", 2); } + if (fifo8_num_used(&mtouch->resp) != fifo_used) + pclog("Command received: %s\n", mtouch->cmd); } void @@ -255,7 +261,7 @@ mtouch_poll(void *priv) } if (dev->cal_cntr && (!(dev->b & 1) && !!(b & 3))) { dev->b |= 1; - } else if (dev->cal_cntr && ((dev->b & 1) && !!(b & 3))) { + } else if (dev->cal_cntr && ((dev->b & 1) && !(b & 3))) { dev->b &= ~1; microtouch_calibrate_timer(dev); } @@ -306,10 +312,11 @@ mtouch_init(const device_t *info) mouse_microtouch_t *dev = calloc(1, sizeof(mouse_microtouch_t)); dev->serial = serial_attach(device_get_config_int("port"), NULL, mtouch_write, dev); + dev->baud_rate = device_get_config_int("baudrate"); fifo8_create(&dev->resp, 512); timer_add(&dev->host_to_serial_timer, mtouch_write_to_host, dev, 0); timer_add(&dev->reset_timer, microtouch_reset_complete, dev, 0); - timer_on_auto(&dev->host_to_serial_timer, (1000000. / 9600.) * 10); + timer_on_auto(&dev->host_to_serial_timer, (1000000. / dev->baud_rate) * 10); dev->mode = MODE_TABLET; dev->pen_mode = 3; mouse_input_mode = 1; @@ -353,6 +360,22 @@ static const device_config_t mtouch_config[] = { { .description = "" } } }, + { + .name = "baudrate", + .description = "Baud Rate", + .type = CONFIG_SELECTION, + .default_string = "", + .default_int = 9600, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "19200", .value = 19200 }, + { .description = "9600", .value = 9600 }, + { .description = "4800", .value = 4800 }, + { .description = "2400", .value = 2400 }, + { .description = "1200", .value = 1200 } + } + }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; From 969830ad8372aad57de7266fd8330d8c59eb1621 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 12 Jun 2024 01:58:44 +0200 Subject: [PATCH 12/16] New recompiler: Add a sanity check, fixes crash with RapidCAD, fixes #4487 . --- src/cpu/386_dynarec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index 8e94038998..a7dbd34a43 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -414,7 +414,8 @@ exec386_dynarec_dyn(void) int byte_offset = (phys_addr >> PAGE_BYTE_MASK_SHIFT) & PAGE_BYTE_MASK_OFFSET_MASK; uint64_t byte_mask = 1ULL << (PAGE_BYTE_MASK_MASK & 0x3f); - if ((page->code_present_mask & mask) || (page->byte_code_present_mask[byte_offset] & byte_mask)) + if ((page->code_present_mask & mask) || + ((page->mem != page_ff) && (page->byte_code_present_mask[byte_offset] & byte_mask))) # else if (page->code_present_mask[(phys_addr >> PAGE_MASK_INDEX_SHIFT) & PAGE_MASK_INDEX_MASK] & mask) # endif From 193838b7c2f2bf0b0b3d5f901fb699c6d73b835a Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Tue, 11 Jun 2024 20:06:04 -0400 Subject: [PATCH 13/16] Fix several uninitialized variables --- src/cdrom/cdrom_image_backend.c | 6 +++--- src/ini.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cdrom/cdrom_image_backend.c b/src/cdrom/cdrom_image_backend.c index 482769799d..fdfa4a4abc 100644 --- a/src/cdrom/cdrom_image_backend.c +++ b/src/cdrom/cdrom_image_backend.c @@ -696,9 +696,9 @@ static int cdi_cue_get_frame(uint64_t *frames, char **line) { char temp[128]; - int min; - int sec; - int fr; + int min = 0; + int sec = 0; + int fr = 0; int success; success = cdi_cue_get_buffer(temp, line, 0); diff --git a/src/ini.c b/src/ini.c index a792d356bb..6162457864 100644 --- a/src/ini.c +++ b/src/ini.c @@ -546,7 +546,7 @@ ini_section_get_int(ini_section_t self, const char *name, int def) { section_t *section = (section_t *) self; const entry_t *entry; - int value; + int value = 0; if (section == NULL) return def; @@ -565,7 +565,7 @@ ini_section_get_uint(ini_section_t self, const char *name, uint32_t def) { section_t *section = (section_t *) self; const entry_t *entry; - uint32_t value; + uint32_t value = 0; if (section == NULL) return def; @@ -585,7 +585,7 @@ ini_section_get_float(ini_section_t self, const char *name, float def) { section_t *section = (section_t *) self; const entry_t *entry; - float value; + float value = 0; if (section == NULL) return def; @@ -605,7 +605,7 @@ ini_section_get_double(ini_section_t self, const char *name, double def) { section_t *section = (section_t *) self; const entry_t *entry; - double value; + double value = 0; if (section == NULL) return def; @@ -624,7 +624,7 @@ ini_section_get_hex16(ini_section_t self, const char *name, int def) { section_t *section = (section_t *) self; const entry_t *entry; - unsigned int value; + unsigned int value = 0; if (section == NULL) return def; @@ -643,7 +643,7 @@ ini_section_get_hex20(ini_section_t self, const char *name, int def) { section_t *section = (section_t *) self; const entry_t *entry; - unsigned int value; + unsigned int value = 0; if (section == NULL) return def; From 9a9d73c1595a848ea543eb5c8aa069f29da2306e Mon Sep 17 00:00:00 2001 From: TC1995 Date: Wed, 12 Jun 2024 20:06:29 +0200 Subject: [PATCH 14/16] More fixes to the Paradise/WD VGA cards Banking no longer goes beyond 0xfffff thanks to masking, fixes possible and in-coming glitches on said cards. --- src/video/vid_paradise.c | 186 +++++++++++---------------------------- 1 file changed, 50 insertions(+), 136 deletions(-) diff --git a/src/video/vid_paradise.c b/src/video/vid_paradise.c index 30666e82cc..2e4802fe5f 100644 --- a/src/video/vid_paradise.c +++ b/src/video/vid_paradise.c @@ -38,8 +38,6 @@ typedef struct paradise_t { rom_t bios_rom; - uint8_t bank_mask; - enum { PVGA1A = 0, WD90C11, @@ -51,7 +49,6 @@ typedef struct paradise_t { uint32_t read_bank[4], write_bank[4]; int interlace; - int check; struct { uint8_t reg_block_ptr; @@ -109,16 +106,6 @@ paradise_in(uint16_t addr, void *priv) return 0xff; } switch (svga->gdcaddr) { - case 0x0b: - temp = svga->gdcreg[0x0b]; - if (paradise->type == WD90C30) { - if (paradise->vram_mask == ((512 << 10) - 1)) { - temp &= ~0x40; - temp |= 0xc0; - } - } - return temp; - case 0x0f: return (svga->gdcreg[0x0f] & 0x17) | 0x80; @@ -149,11 +136,6 @@ paradise_out(uint16_t addr, uint8_t val, void *priv) svga_t *svga = ¶dise->svga; uint8_t old; - if (paradise->vram_mask <= ((512 << 10) - 1)) - paradise->bank_mask = 0x7f; - else - paradise->bank_mask = 0xff; - if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) addr ^= 0x60; @@ -189,21 +171,22 @@ paradise_out(uint16_t addr, uint8_t val, void *priv) old = svga->gdcreg[svga->gdcaddr]; switch (svga->gdcaddr) { case 6: - if (old ^ (val & 0x0c)) { - switch (val & 0x0c) { - case 0x00: /*128k at A0000*/ + if ((val & 0xc) != (old & 0xc)) { + svga->gdcreg[6] = val; + switch (svga->gdcreg[6] & 0xc) { + case 0x0: /*128k at A0000*/ mem_mapping_set_addr(&svga->mapping, 0xa0000, 0x20000); svga->banked_mask = 0xffff; break; - case 0x04: /*64k at A0000*/ + case 0x4: /*64k at A0000*/ mem_mapping_set_addr(&svga->mapping, 0xa0000, 0x10000); svga->banked_mask = 0xffff; break; - case 0x08: /*32k at B0000*/ + case 0x8: /*32k at B0000*/ mem_mapping_set_addr(&svga->mapping, 0xb0000, 0x08000); svga->banked_mask = 0x7fff; break; - case 0x0c: /*32k at B8000*/ + case 0xC: /*32k at B8000*/ mem_mapping_set_addr(&svga->mapping, 0xb8000, 0x08000); svga->banked_mask = 0x7fff; break; @@ -211,14 +194,13 @@ paradise_out(uint16_t addr, uint8_t val, void *priv) default: break; } - svga->gdcreg[6] = val; paradise_remap(paradise); } return; case 9: case 0x0a: - svga->gdcreg[svga->gdcaddr] = val & paradise->bank_mask; + svga->gdcreg[svga->gdcaddr] = val; paradise_remap(paradise); return; case 0x0b: @@ -277,8 +259,6 @@ paradise_remap(paradise_t *paradise) { svga_t *svga = ¶dise->svga; - paradise->check = 0; - if (svga->seqregs[0x11] & 0x80) { paradise->read_bank[0] = paradise->read_bank[2] = svga->gdcreg[9] << 12; paradise->read_bank[1] = paradise->read_bank[3] = (svga->gdcreg[9] << 12) + ((svga->gdcreg[6] & 0x08) ? 0 : 0x8000); @@ -303,12 +283,12 @@ paradise_remap(paradise_t *paradise) paradise->write_bank[1] = paradise->write_bank[3] = (svga->gdcreg[9] << 12) + ((svga->gdcreg[6] & 0x08) ? 0 : 0x8000); } - if (((svga->gdcreg[0x0b] & 0xc0) == 0xc0) && !svga->chain4 && (svga->crtc[0x14] & 0x40) && ((svga->gdcreg[6] >> 2) & 3) == 1) - paradise->check = 1; - - if (paradise->bank_mask == 0x7f) { + if ((svga->gdcreg[0x0b] & 0xc0) < 0xc0) { paradise->read_bank[1] &= 0x7ffff; paradise->write_bank[1] &= 0x7ffff; + } else { + paradise->read_bank[1] &= 0xfffff; + paradise->write_bank[1] &= 0xfffff; } } @@ -386,36 +366,20 @@ paradise_write(uint32_t addr, uint8_t val, void *priv) /*Could be done in a better way but it works.*/ if (svga->gdcreg[0x0e] & 0x01) { - if (paradise->check) { + if (((svga->gdcreg[6] & 0x0c) == 0x04) && (svga->crtc[0x14] & 0x40) && ((svga->gdcreg[0x0b] & 0xc0) == 0xc0) && !svga->chain4) { prev_addr = addr & 3; prev_addr2 = addr & 0xfffc; - if ((addr & 3) == 3) { - if ((addr & 0x30000) == 0x20000) + if (prev_addr == 3) { + if ((addr & 0x30000) != 0x30000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) + } else if (prev_addr == 2) { + if ((addr & 0x30000) != 0x20000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) + } else if (prev_addr == 1) { + if ((addr & 0x30000) != 0x10000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 2) { - if ((addr & 0x30000) == 0x30000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 1) { - if ((addr & 0x30000) == 0x30000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x20000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 0) { - if ((addr & 0x30000) == 0x30000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x20000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) + } else { + if (addr & 0x30000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; } } @@ -439,36 +403,20 @@ paradise_writew(uint32_t addr, uint16_t val, void *priv) /*Could be done in a better way but it works.*/ if (svga->gdcreg[0x0e] & 0x01) { - if (paradise->check) { + if (((svga->gdcreg[6] & 0x0c) == 0x04) && (svga->crtc[0x14] & 0x40) && ((svga->gdcreg[0x0b] & 0xc0) == 0xc0) && !svga->chain4) { prev_addr = addr & 3; prev_addr2 = addr & 0xfffc; - if ((addr & 3) == 3) { - if ((addr & 0x30000) == 0x20000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 2) { - if ((addr & 0x30000) == 0x30000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) + if (prev_addr == 3) { + if ((addr & 0x30000) != 0x30000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) + } else if (prev_addr == 2) { + if ((addr & 0x30000) != 0x20000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 1) { - if ((addr & 0x30000) == 0x30000) + } else if (prev_addr == 1) { + if ((addr & 0x30000) != 0x10000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x20000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 0) { - if ((addr & 0x30000) == 0x30000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x20000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) + } else { + if (addr & 0x30000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; } } @@ -484,44 +432,27 @@ paradise_read(uint32_t addr, void *priv) uint32_t prev_addr; uint32_t prev_addr2; - if (!(svga->gdcreg[5] & 0x40)) { + if (!(svga->gdcreg[5] & 0x40)) return svga_read(addr, svga); - } addr = (addr & 0x7fff) + paradise->read_bank[(addr >> 15) & 3]; /*Could be done in a better way but it works.*/ if (svga->gdcreg[0x0e] & 0x01) { - if (paradise->check) { + if (((svga->gdcreg[6] & 0x0c) == 0x04) && (svga->crtc[0x14] & 0x40) && ((svga->gdcreg[0x0b] & 0xc0) == 0xc0) && !svga->chain4) { prev_addr = addr & 3; prev_addr2 = addr & 0xfffc; - if ((addr & 3) == 3) { - if ((addr & 0x30000) == 0x20000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 2) { - if ((addr & 0x30000) == 0x30000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 1) { - if ((addr & 0x30000) == 0x30000) + if (prev_addr == 3) { + if ((addr & 0x30000) != 0x30000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x20000) + } else if (prev_addr == 2) { + if ((addr & 0x30000) != 0x20000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) + } else if (prev_addr == 1) { + if ((addr & 0x30000) != 0x10000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 0) { - if ((addr & 0x30000) == 0x30000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x20000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) + } else { + if (addr & 0x30000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; } } @@ -536,44 +467,27 @@ paradise_readw(uint32_t addr, void *priv) uint32_t prev_addr; uint32_t prev_addr2; - if (!(svga->gdcreg[5] & 0x40)) { + if (!(svga->gdcreg[5] & 0x40)) return svga_readw(addr, svga); - } addr = (addr & 0x7fff) + paradise->read_bank[(addr >> 15) & 3]; /*Could be done in a better way but it works.*/ if (svga->gdcreg[0x0e] & 0x01) { - if (paradise->check) { + if (((svga->gdcreg[6] & 0x0c) == 0x04) && (svga->crtc[0x14] & 0x40) && ((svga->gdcreg[0x0b] & 0xc0) == 0xc0) && !svga->chain4) { prev_addr = addr & 3; prev_addr2 = addr & 0xfffc; - if ((addr & 3) == 3) { - if ((addr & 0x30000) == 0x20000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 2) { - if ((addr & 0x30000) == 0x30000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 1) { - if ((addr & 0x30000) == 0x30000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x20000) - addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x00000) + if (prev_addr == 3) { + if ((addr & 0x30000) != 0x30000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - } else if ((addr & 3) == 0) { - if ((addr & 0x30000) == 0x30000) + } else if (prev_addr == 2) { + if ((addr & 0x30000) != 0x20000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x20000) + } else if (prev_addr == 1) { + if ((addr & 0x30000) != 0x10000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; - else if ((addr & 0x30000) == 0x10000) + } else { + if (addr & 0x30000) addr = (addr >> 16) | (prev_addr << 16) | prev_addr2; } } From a369bc2d05b38a0211884b53d7839e658d54cc56 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 12 Jun 2024 20:46:27 +0200 Subject: [PATCH 15/16] Reimplement S3 ViRGE reset and move PCI TRC CPU reset to outside the recompiled block, fixes #2903. --- src/cpu/386_common.c | 2 + src/cpu/386_dynarec.c | 14 ++++ src/cpu/cpu.c | 4 +- src/cpu/x86.h | 2 + src/pci.c | 8 +++ src/video/vid_s3_virge.c | 136 +++++++++++---------------------------- 6 files changed, 68 insertions(+), 98 deletions(-) diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index 5e80ef4c31..d1d38006b2 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -51,6 +51,8 @@ uint32_t dr[8]; uint32_t use32; int stack32; +int cpu_init = 0; + uint32_t *eal_r; uint32_t *eal_w; diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index a7dbd34a43..d8a33a6240 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -350,6 +350,9 @@ exec386_dynarec_int(void) CPU_BLOCK_END(); } + if (cpu_init) + CPU_BLOCK_END(); + if (cpu_state.abrt) CPU_BLOCK_END(); if (smi_line) @@ -592,6 +595,9 @@ exec386_dynarec_dyn(void) # endif CPU_BLOCK_END(); + if (cpu_init) + CPU_BLOCK_END(); + if ((cpu_state.flags & T_FLAG) || (trap == 2)) CPU_BLOCK_END(); if (smi_line) @@ -689,6 +695,9 @@ exec386_dynarec_dyn(void) # endif CPU_BLOCK_END(); + if (cpu_init) + CPU_BLOCK_END(); + if (cpu_state.flags & T_FLAG) CPU_BLOCK_END(); if (smi_line) @@ -768,6 +777,11 @@ exec386_dynarec(int32_t cycs) exec386_dynarec_dyn(); } + if (cpu_init) { + cpu_init = 0; + resetx86(); + } + if (cpu_state.abrt) { flags_rebuild(); tempi = cpu_state.abrt & ABRT_MASK; diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index e1e0e913de..20476eec9e 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -29,6 +29,7 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" +#include "x86.h" #include "x87_sf.h" #include <86box/device.h> #include <86box/machine.h> @@ -504,7 +505,8 @@ cpu_set(void) acycs = 0; #endif - soft_reset_pci = 0; + soft_reset_pci = 0; + cpu_init = 0; cpu_alt_reset = 0; unmask_a20_in_smm = 0; diff --git a/src/cpu/x86.h b/src/cpu/x86.h index f52e430ac6..327af89640 100644 --- a/src/cpu/x86.h +++ b/src/cpu/x86.h @@ -59,6 +59,8 @@ extern int nmi_enable; extern int oddeven; extern int inttype; +extern int cpu_init; + extern uint32_t use32; extern uint32_t rmdat; extern uint32_t easeg; diff --git a/src/pci.c b/src/pci.c index 6475efe908..b4f5eafe5a 100644 --- a/src/pci.c +++ b/src/pci.c @@ -23,6 +23,7 @@ #include <86box/86box.h> #include <86box/machine.h> #include "cpu.h" +#include "x86.h" #include <86box/io.h> #include <86box/pic.h> #include <86box/mem.h> @@ -420,7 +421,14 @@ pci_trc_reset(uint8_t val) flushmmucache(); } +#ifdef USE_DYNAREC + if (cpu_use_dynarec) + cpu_init = 1; + else + resetx86(); +#else resetx86(); +#endif } void diff --git a/src/video/vid_s3_virge.c b/src/video/vid_s3_virge.c index 7982f816e5..d62ebbbab4 100644 --- a/src/video/vid_s3_virge.c +++ b/src/video/vid_s3_virge.c @@ -299,6 +299,8 @@ typedef struct virge_t { int onboard; } virge_t; +static virge_t *reset_state = NULL; + static video_timings_t timing_diamond_stealth3d_2000_pci = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 3, .read_b = 28, .read_w = 28, .read_l = 45 }; static video_timings_t timing_diamond_stealth3d_3000_pci = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 4, .read_b = 26, .read_w = 26, .read_l = 42 }; static video_timings_t timing_virge_dx_pci = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 3, .read_b = 28, .read_w = 28, .read_l = 45 }; @@ -4248,114 +4250,49 @@ s3_virge_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) } static void -s3_virge_reset(void *priv) +s3_virge_disable_handlers(virge_t *dev) { - virge_t *virge = (virge_t *) priv; - svga_t *svga = &virge->svga; - - memset(svga->crtc, 0x00, sizeof(svga->crtc)); - svga->crtc[0] = 63; - svga->crtc[6] = 255; - svga->dispontime = 1000ULL << 32; - svga->dispofftime = 1000ULL << 32; - svga->bpp = 8; - - io_removehandler(0x03c0, 0x0020, s3_virge_in, NULL, NULL, s3_virge_out, NULL, NULL, virge); - io_sethandler(0x03c0, 0x0020, s3_virge_in, NULL, NULL, s3_virge_out, NULL, NULL, virge); - - memset(virge->pci_regs, 0x00, 256); - - virge->pci_regs[PCI_REG_COMMAND] = 3; - virge->pci_regs[0x05] = 0; - virge->pci_regs[0x06] = 0; - virge->pci_regs[0x07] = 2; - virge->pci_regs[0x32] = 0x0c; - virge->pci_regs[0x3d] = 1; - virge->pci_regs[0x3e] = 4; - virge->pci_regs[0x3f] = 0xff; - - switch (virge->local) { - case S3_VIRGE_325: - case S3_DIAMOND_STEALTH3D_2000: - virge->fifo_slots_num = 8; - virge->svga.crtc[0x59] = 0x70; - break; - case S3_DIAMOND_STEALTH3D_3000: - case S3_STB_VELOCITY_3D: - virge->fifo_slots_num = 8; - virge->svga.crtc[0x59] = 0x70; - break; - case S3_VIRGE_GX2: - case S3_DIAMOND_STEALTH3D_4000: - virge->fifo_slots_num = 16; - virge->svga.crtc[0x6c] = 1; - virge->svga.crtc[0x59] = 0x70; - break; - - case S3_TRIO_3D2X: - virge->fifo_slots_num = 16; - virge->svga.crtc[0x6c] = 1; - virge->svga.crtc[0x59] = 0x70; - break; + io_removehandler(0x03c0, 0x0020, s3_virge_in, NULL, NULL, + s3_virge_out, NULL, NULL, dev); + + mem_mapping_disable(&dev->linear_mapping); + mem_mapping_disable(&dev->mmio_mapping); + mem_mapping_disable(&dev->new_mmio_mapping); + mem_mapping_disable(&dev->svga.mapping); + mem_mapping_disable(&dev->bios_rom.mapping); + + /* Save all the mappings and the timers because they are part of linked lists. */ + reset_state->linear_mapping = dev->linear_mapping; + reset_state->mmio_mapping = dev->mmio_mapping; + reset_state->new_mmio_mapping = dev->new_mmio_mapping; + reset_state->svga.mapping = dev->svga.mapping; + reset_state->bios_rom.mapping = dev->bios_rom.mapping; + + reset_state->svga.timer = dev->svga.timer; + reset_state->svga.timer8514 = dev->svga.timer8514; + + reset_state->tri_timer = dev->tri_timer; +} - default: - virge->fifo_slots_num = 8; - virge->svga.crtc[0x6c] = 1; - virge->svga.crtc[0x59] = 0x70; - break; - } +static void +s3_virge_reset(void *priv) +{ + virge_t *dev = (virge_t *) priv; - if (virge->chip == S3_VIRGEGX2) - virge->svga.crtc[0x36] = 2 | (2 << 2) | (1 << 4) | (1 << 5); - else { - switch (virge->memory_size) { - case 2: - if (virge->chip == S3_VIRGEVX) { - virge->svga.crtc[0x36] = (0 << 5); - } else - virge->svga.crtc[0x36] = 2 | (0 << 2) | (1 << 4) | (4 << 5); - break; - case 8: - if (virge->chip == S3_TRIO3D2X) - virge->svga.crtc[0x36] = 2 | (2 << 2) | (1 << 4) | (0 << 5); - else - virge->svga.crtc[0x36] = (3 << 5); - break; - case 4: - if (virge->chip == S3_VIRGEVX) - virge->svga.crtc[0x36] = (1 << 5); - else if (virge->chip == S3_TRIO3D2X) - virge->svga.crtc[0x36] = 2 | (2 << 2) | (1 << 4) | (2 << 5); - else - virge->svga.crtc[0x36] = 2 | (0 << 2) | (1 << 4) | (0 << 5); - break; + if (reset_state != NULL) { + s3_virge_disable_handlers(dev); + reset_state->pci_slot = dev->pci_slot; - default: - break; - } - if (virge->local == S3_VIRGE_GX) - virge->svga.crtc[0x36] |= (1 << 2); + *dev = *reset_state; } - - virge->svga.crtc[0x37] = 1 | (7 << 5); - virge->svga.crtc[0x53] = 8; - - if (!virge->onboard) - mem_mapping_disable(&virge->bios_rom.mapping); - - s3_virge_updatemapping(virge); - - mem_mapping_disable(&virge->mmio_mapping); - mem_mapping_disable(&virge->new_mmio_mapping); } static void * s3_virge_init(const device_t *info) { const char *bios_fn; - virge_t *virge = malloc(sizeof(virge_t)); - - memset(virge, 0, sizeof(virge_t)); + virge_t *virge = calloc(1, sizeof(virge_t)); + reset_state = calloc(1, sizeof(virge_t)); virge->bilinear_enabled = device_get_config_int("bilinear"); virge->dithering_enabled = device_get_config_int("dithering"); @@ -4595,6 +4532,8 @@ s3_virge_init(const device_t *info) virge->local = info->local; + *reset_state = *virge; + return virge; } @@ -4615,6 +4554,9 @@ s3_virge_close(void *priv) ddc_close(virge->ddc); i2c_gpio_close(virge->i2c); + free(reset_state); + reset_state = NULL; + free(virge); } From df8830c219ccbb5ff2c151b797cffefd37edba27 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Wed, 12 Jun 2024 20:57:39 +0200 Subject: [PATCH 16/16] Fix warning. --- src/video/vid_paradise.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/video/vid_paradise.c b/src/video/vid_paradise.c index 2e4802fe5f..f572521f23 100644 --- a/src/video/vid_paradise.c +++ b/src/video/vid_paradise.c @@ -76,7 +76,6 @@ paradise_in(uint16_t addr, void *priv) { paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; - uint8_t temp = 0; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) addr ^= 0x60;