From fd9f8c90a5b868644aa56bb31cebaf6e847ea82c Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Wed, 26 Jul 2023 04:39:19 +0200 Subject: [PATCH] Basic ADB mouse device emulation. For now, it solely handles the basic ADB commands. --- devices/common/adb/adbmouse.cpp | 69 +++++++++++++++++++++++++++++++++ devices/common/adb/adbmouse.h | 47 ++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 devices/common/adb/adbmouse.cpp create mode 100644 devices/common/adb/adbmouse.h diff --git a/devices/common/adb/adbmouse.cpp b/devices/common/adb/adbmouse.cpp new file mode 100644 index 0000000..3cfc871 --- /dev/null +++ b/devices/common/adb/adbmouse.cpp @@ -0,0 +1,69 @@ +/* +DingusPPC - The Experimental PowerPC Macintosh emulator +Copyright (C) 2018-23 divingkatae and maximum + (theweirdo) spatium + +(Contact divingkatae#1017 or powermax#2286 on Discord for more info) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/** @file Apple Desktop Bus Mouse emulation. */ + +#include +#include + +AdbMouse::AdbMouse(std::string name) : AdbDevice(name) { + this->reset(); +} + +void AdbMouse::reset() { + this->my_addr = ADB_ADDR_RELPOS; + this->dev_handler_id = 1; + this->exc_event_flag = 1; + this->srq_flag = 1; // enable service requests +} + +void AdbMouse::set_register_3() { + if (this->host_obj->get_input_count() < 2) // ensure we got enough data + return; + + const uint8_t* in_data = this->host_obj->get_input_buf(); + + switch (in_data[1]) { + case 0: + this->my_addr = in_data[0] & 0xF; + this->srq_flag = !!(in_data[0] & 0x20); + break; + case 1: + case 2: + this->dev_handler_id = in_data[1]; + break; + case 4: // extended mouse protocol isn't supported yet + break; + case 0xFE: // move to a new address if there was no collision + if (!this->got_collision) { + this->my_addr = in_data[0] & 0xF; + } + break; + default: + LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]); + } +} + +static const DeviceDescription AdbMouse_Descriptor = { + AdbMouse::create, {}, {} +}; + +REGISTER_DEVICE(AdbMouse, AdbMouse_Descriptor); diff --git a/devices/common/adb/adbmouse.h b/devices/common/adb/adbmouse.h new file mode 100644 index 0000000..0e36529 --- /dev/null +++ b/devices/common/adb/adbmouse.h @@ -0,0 +1,47 @@ +/* +DingusPPC - The Experimental PowerPC Macintosh emulator +Copyright (C) 2018-23 divingkatae and maximum + (theweirdo) spatium + +(Contact divingkatae#1017 or powermax#2286 on Discord for more info) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/** @file Apple Desktop Bus Mouse definitions. */ + +#ifndef ADB_MOUSE_H +#define ADB_MOUSE_H + +#include +#include + +#include +#include + +class AdbMouse : public AdbDevice { +public: + AdbMouse(std::string name); + ~AdbMouse() = default; + + static std::unique_ptr create() { + return std::unique_ptr(new AdbMouse("ADB-MOUSE")); + } + + void reset() override; + + void set_register_3() override; +}; + +#endif // ADB_MOUSE_H