Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dosbox-staging/dosbox-staging.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeralChild64 <>2022-10-12 13:45:03 +0300
committerFeralChild64 <>2022-10-13 14:00:04 +0300
commit7f5d6f09909c8afb9c01ad364eec0fe9da1ff77e (patch)
treee969d1a71833cfcd59623d6c6e6a959a7235da9b
parent4a6a54027e2335875981798b72d5a42fc63045c1 (diff)
Handle code review remarks (WIP)fc/mouse-mapper-1
-rw-r--r--include/math_utils.h16
-rw-r--r--include/mouse.h16
-rw-r--r--meson.build14
-rw-r--r--src/dos/program_mousectl.cpp67
-rw-r--r--src/dos/program_mousectl.h2
-rw-r--r--src/hardware/mouse/mouse.cpp122
-rw-r--r--src/hardware/mouse/mouse_common.cpp28
-rw-r--r--src/hardware/mouse/mouse_common.h5
-rw-r--r--src/hardware/mouse/mouse_config.cpp8
-rw-r--r--src/hardware/mouse/mouse_config.h2
-rw-r--r--src/hardware/mouse/mouse_interfaces.cpp2
-rw-r--r--src/hardware/mouse/mouse_interfaces.h2
-rw-r--r--src/hardware/mouse/mouse_manymouse.cpp19
-rw-r--r--src/hardware/mouse/mouse_manymouse.h2
-rw-r--r--src/hardware/mouse/mouse_queue.cpp2
-rw-r--r--src/hardware/mouse/mouse_queue.h2
-rw-r--r--src/hardware/mouse/mouseif_dos_driver.cpp11
-rw-r--r--src/hardware/mouse/mouseif_ps2_bios.cpp5
-rw-r--r--src/hardware/mouse/mouseif_virtual_machines.cpp9
-rw-r--r--src/hardware/serialport/serialmouse.cpp9
-rw-r--r--src/hardware/serialport/serialmouse.h2
21 files changed, 167 insertions, 178 deletions
diff --git a/include/math_utils.h b/include/math_utils.h
index 849921cde..4d7cab1dc 100644
--- a/include/math_utils.h
+++ b/include/math_utils.h
@@ -127,6 +127,22 @@ constexpr T1 left_shift_signed(T1 value, T2 amount)
return static_cast<T1>(shifted);
}
+inline int8_t clamp_to_int8(const int32_t val)
+{
+ const auto tmp = std::clamp(val,
+ static_cast<int32_t>(INT8_MIN),
+ static_cast<int32_t>(INT8_MAX));
+ return static_cast<int8_t>(tmp);
+}
+
+inline int16_t clamp_to_int16(const int32_t val)
+{
+ const auto tmp = std::clamp(val,
+ static_cast<int32_t>(INT16_MIN),
+ static_cast<int32_t>(INT16_MAX));
+ return static_cast<int16_t>(tmp);
+}
+
inline double decibel_to_gain(const double decibel)
{
return pow(10.0, decibel / 20.0);
diff --git a/include/mouse.h b/include/mouse.h
index 7f0bb4260..70a7c7624 100644
--- a/include/mouse.h
+++ b/include/mouse.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
* Copyright (C) 2002-2021 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
@@ -168,15 +168,15 @@ private:
const MousePhysical &Physical() const;
};
-class MouseConfigAPI final {
+class MouseControlAPI final {
public:
// Always destroy the object once it is not needed anymore
// (configuration tool finishes it's job) and we are returning
// to normal code execution!
- MouseConfigAPI();
- ~MouseConfigAPI();
+ MouseControlAPI();
+ ~MouseControlAPI();
// Empty list = performs operation on all emulated interfaces
typedef std::vector<MouseInterfaceId> ListIDs;
@@ -213,13 +213,13 @@ public:
static const std::vector<uint16_t> &GetValidMinRateList();
static const std::string &GetValidMinRateStr();
- bool SetMinRate(const MouseConfigAPI::ListIDs &list_ids,
+ bool SetMinRate(const MouseControlAPI::ListIDs &list_ids,
const uint16_t value_hz);
- bool ResetMinRate(const MouseConfigAPI::ListIDs &list_ids);
+ bool ResetMinRate(const MouseControlAPI::ListIDs &list_ids);
private:
- MouseConfigAPI(const MouseConfigAPI &) = delete;
- MouseConfigAPI &operator=(const MouseConfigAPI &) = delete;
+ MouseControlAPI(const MouseControlAPI &) = delete;
+ MouseControlAPI &operator=(const MouseControlAPI &) = delete;
};
#endif // DOSBOX_MOUSE_H
diff --git a/meson.build b/meson.build
index e611814c5..dddd33f18 100644
--- a/meson.build
+++ b/meson.build
@@ -528,13 +528,6 @@ coreaudio_dep = optional_dep
coremidi_dep = optional_dep
corefoundation_dep = optional_dep
iokit_dep = optional_dep
-iokit_code = '''
-#include <IOKit/hid/IOHIDLib.h>
-int main() {
- dispatch_block_t test_var;
- return 0;
-}
-'''
if host_machine.system() == 'darwin'
# ObjectiveC parsing, if possible
@@ -584,6 +577,13 @@ if host_machine.system() == 'darwin'
)
if iokit_dep.found()
if cxx.check_header('IOKit/IOKitLib.h')
+ iokit_code = '''
+ #include <IOKit/hid/IOHIDLib.h>
+ int main() {
+ dispatch_block_t test_var;
+ return 0;
+ }
+ '''
is_iokit_compilable = cxx.links(
iokit_code,
name: 'compiler is capable of compiling IOKit',
diff --git a/src/dos/program_mousectl.cpp b/src/dos/program_mousectl.cpp
index 7f529321b..19cc10e7c 100644
--- a/src/dos/program_mousectl.cpp
+++ b/src/dos/program_mousectl.cpp
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: GPL-2.0-or-later
*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
@@ -56,7 +56,7 @@ bool MOUSECTL::ParseAndRun()
{
if (idx >= params.size())
return false;
- return (0 == strcasecmp(params[idx].c_str(), string));
+ return iequals(params[idx].c_str(), string);
};
// CmdShow
@@ -129,11 +129,12 @@ bool MOUSECTL::ParseInterfaces(std::vector<std::string> &params)
MouseInterfaceId::COM3,
MouseInterfaceId::COM4,
}) {
- const auto is_interface = string_iequals(param, GetInterfaceStr(id));
+ const auto is_interface = iequals(param, GetInterfaceStr(id));
if (is_interface)
list_ids.push_back(id);
return is_interface;
}
+ return false;
};
while (!params.empty() && add_if_is_interface(params.front()))
params.erase(params.begin()); // pop
@@ -150,16 +151,15 @@ bool MOUSECTL::ParseInterfaces(std::vector<std::string> &params)
bool MOUSECTL::CheckInterfaces()
{
- if (!MouseConfigAPI::CheckInterfaces(list_ids))
- {
- if (list_ids.empty())
- WriteOut(MSG_Get("SHELL_CMD_MOUSECTL_NO_INTERFACES"));
- else
- WriteOut(MSG_Get("SHELL_CMD_MOUSECTL_MISSING_INTERFACES"));
- return false;
- }
+ if (MouseControlAPI::CheckInterfaces(list_ids))
+ return true;
- return true;
+ if (list_ids.empty())
+ WriteOut(MSG_Get("SHELL_CMD_MOUSECTL_NO_INTERFACES"));
+ else
+ WriteOut(MSG_Get("SHELL_CMD_MOUSECTL_MISSING_INTERFACES"));
+
+ return false;
}
const char *MOUSECTL::GetInterfaceStr(const MouseInterfaceId interface_id) const
@@ -197,7 +197,7 @@ const char *MOUSECTL::GetMapStatusStr(const MouseMapStatus map_status) const
bool MOUSECTL::CmdShow(const bool show_all)
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
const auto info_interfaces = mouse_config_api.GetInfoInterfaces();
bool show_mapped = false;
@@ -213,8 +213,9 @@ bool MOUSECTL::CmdShow(const bool show_all)
continue;
const auto interface_id = entry.GetInterfaceId();
const auto rate_hz = entry.GetRate();
+ const bool rate_enforced = entry.GetMinRate();
- if (entry.GetMinRate())
+ if (rate_enforced)
hint_rate_min = true;
if (interface_id == MouseInterfaceId::COM1 ||
@@ -227,7 +228,7 @@ bool MOUSECTL::CmdShow(const bool show_all)
GetInterfaceStr(interface_id),
entry.GetSensitivityX(),
entry.GetSensitivityY(),
- hint_rate_min ? "*" : "",
+ rate_enforced ? "*" : "",
rate_hz ? std::to_string(rate_hz).c_str() : "-",
convert_ansi_markup(GetMapStatusStr(entry.GetMapStatus())).c_str());
WriteOut("\n");
@@ -304,17 +305,17 @@ void MOUSECTL::FinalizeMapping()
bool MOUSECTL::CmdMap(const MouseInterfaceId interface_id, const std::string &pattern)
{
std::regex regex;
- if (!MouseConfigAPI::PatternToRegex(pattern, regex)) {
+ if (!MouseControlAPI::PatternToRegex(pattern, regex)) {
WriteOut(MSG_Get("SHELL_CMD_MOUSECTL_SYNTAX_PATTERN"));
return false;
}
- if (MouseConfigAPI::IsNoMouseMode()) {
+ if (MouseControlAPI::IsNoMouseMode()) {
WriteOut(MSG_Get("SHELL_CMD_MOUSECTL_MAPPING_NO_MOUSE"));
return false;
}
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
if (!mouse_config_api.Map(interface_id, regex)) {
WriteOut(MSG_Get("SHELL_CMD_MOUSECTL_NO_MATCH"));
return false;
@@ -328,12 +329,12 @@ bool MOUSECTL::CmdMap()
{
assert(list_ids.size() >= 1);
- if (MouseConfigAPI::IsNoMouseMode()) {
+ if (MouseControlAPI::IsNoMouseMode()) {
WriteOut(MSG_Get("SHELL_CMD_MOUSECTL_MAPPING_NO_MOUSE"));
return false;
}
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
const auto info_physical = mouse_config_api.GetInfoPhysical();
if (info_physical.empty()) {
@@ -375,71 +376,71 @@ bool MOUSECTL::CmdMap()
bool MOUSECTL::CmdUnMap()
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.UnMap(list_ids);
return true;
}
bool MOUSECTL::CmdOnOff(const bool enable)
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.OnOff(list_ids, enable);
return true;
}
bool MOUSECTL::CmdReset()
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.Reset(list_ids);
return true;
}
bool MOUSECTL::CmdSensitivity(const int8_t value)
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.SetSensitivity(list_ids, value, value);
return true;
}
bool MOUSECTL::CmdSensitivityX(const int8_t value)
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.SetSensitivityX(list_ids, value);
return true;
}
bool MOUSECTL::CmdSensitivityY(const int8_t value)
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.SetSensitivityY(list_ids, value);
return true;
}
bool MOUSECTL::CmdSensitivity()
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.ResetSensitivity(list_ids);
return true;
}
bool MOUSECTL::CmdSensitivityX()
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.ResetSensitivityX(list_ids);
return true;
}
bool MOUSECTL::CmdSensitivityY()
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.ResetSensitivityY(list_ids);
return true;
}
bool MOUSECTL::CmdMinRate(const std::string &param)
{
- const auto &valid_list = MouseConfigAPI::GetValidMinRateList();
- const auto &valid_str = MouseConfigAPI::GetValidMinRateStr();
+ const auto &valid_list = MouseControlAPI::GetValidMinRateList();
+ const auto &valid_str = MouseControlAPI::GetValidMinRateStr();
const auto tmp = std::atoi(param.c_str());
if (tmp < 0 || tmp > UINT16_MAX) {
@@ -455,14 +456,14 @@ bool MOUSECTL::CmdMinRate(const std::string &param)
return false;
}
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.SetMinRate(list_ids, value_hz);
return true;
}
bool MOUSECTL::CmdMinRate()
{
- MouseConfigAPI mouse_config_api;
+ MouseControlAPI mouse_config_api;
mouse_config_api.ResetMinRate(list_ids);
return true;
}
diff --git a/src/dos/program_mousectl.h b/src/dos/program_mousectl.h
index d59b9dcd0..6156001a3 100644
--- a/src/dos/program_mousectl.h
+++ b/src/dos/program_mousectl.h
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: GPL-2.0-or-later
*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
diff --git a/src/hardware/mouse/mouse.cpp b/src/hardware/mouse/mouse.cpp
index 1f7b4ea68..6e4bbfeaa 100644
--- a/src/hardware/mouse/mouse.cpp
+++ b/src/hardware/mouse/mouse.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
* Copyright (C) 2002-2021 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
@@ -179,7 +179,7 @@ void MOUSE_NotifyDisconnect(const MouseInterfaceId interface_id)
void MOUSE_NotifyFakePS2()
{
- auto interface = MouseInterface::GetPS2();
+ const auto interface = MouseInterface::GetPS2();
if (interface && interface->IsUsingEvents()) {
MouseEvent ev;
@@ -289,11 +289,9 @@ void MOUSE_EventWheel(const int16_t w_rel,
// MOUSECTL.COM / GUI configurator interface
// ***************************************************************************
-void get_relevant_interfaces(std::vector<MouseInterface *> &list_out,
- const std::vector<MouseInterfaceId> &list_ids)
+static std::vector<MouseInterface *> get_relevant_interfaces(const std::vector<MouseInterfaceId> &list_ids)
{
- list_out.clear();
- auto list_tmp = list_out;
+ std::vector<MouseInterface *> list_tmp = {};
if (list_ids.empty())
// If command does not specify interfaces,
@@ -307,42 +305,44 @@ void get_relevant_interfaces(std::vector<MouseInterface *> &list_out,
}
// Filter out not emulated ones
+ std::vector<MouseInterface *> list_out = {};
for (const auto &interface : list_tmp)
if (interface->IsEmulated())
list_out.push_back(interface);
+
+ return list_out;
}
-MouseConfigAPI::MouseConfigAPI()
+MouseControlAPI::MouseControlAPI()
{
manymouse.StartConfigAPI();
}
-MouseConfigAPI::~MouseConfigAPI()
+MouseControlAPI::~MouseControlAPI()
{
manymouse.StopConfigAPI();
MOUSE_NotifyStateChanged();
}
-bool MouseConfigAPI::IsNoMouseMode()
+bool MouseControlAPI::IsNoMouseMode()
{
return mouse_config.no_mouse;
}
-const std::vector<MouseInterfaceInfoEntry> &MouseConfigAPI::GetInfoInterfaces() const
+const std::vector<MouseInterfaceInfoEntry> &MouseControlAPI::GetInfoInterfaces() const
{
return mouse_info.interfaces;
}
-const std::vector<MousePhysicalInfoEntry> &MouseConfigAPI::GetInfoPhysical()
+const std::vector<MousePhysicalInfoEntry> &MouseControlAPI::GetInfoPhysical()
{
manymouse.RescanIfSafe();
return mouse_info.physical;
}
-bool MouseConfigAPI::CheckInterfaces(const MouseConfigAPI::ListIDs &list_ids)
+bool MouseControlAPI::CheckInterfaces(const MouseControlAPI::ListIDs &list_ids)
{
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
+ const auto list = get_relevant_interfaces(list_ids);
if (list_ids.empty() && list.empty())
return false; // no emulated mouse interfaces
@@ -354,8 +354,8 @@ bool MouseConfigAPI::CheckInterfaces(const MouseConfigAPI::ListIDs &list_ids)
return true;
}
-bool MouseConfigAPI::PatternToRegex(const std::string &pattern,
- std::regex &regex)
+bool MouseControlAPI::PatternToRegex(const std::string &pattern,
+ std::regex &regex)
{
// Convert DOS wildcard pattern to a regular expression
std::stringstream pattern_regex;
@@ -381,7 +381,7 @@ bool MouseConfigAPI::PatternToRegex(const std::string &pattern,
return true;
}
-bool MouseConfigAPI::ProbeForMapping(uint8_t &device_id)
+bool MouseControlAPI::ProbeForMapping(uint8_t &device_id)
{
if (mouse_config.no_mouse)
return false;
@@ -390,7 +390,7 @@ bool MouseConfigAPI::ProbeForMapping(uint8_t &device_id)
return manymouse.ProbeForMapping(device_id);
}
-bool MouseConfigAPI::Map(const MouseInterfaceId interface_id,
+bool MouseControlAPI::Map(const MouseInterfaceId interface_id,
const uint8_t device_idx)
{
if (mouse_config.no_mouse)
@@ -403,8 +403,8 @@ bool MouseConfigAPI::Map(const MouseInterfaceId interface_id,
return mouse_interface->ConfigMap(device_idx);
}
-bool MouseConfigAPI::Map(const MouseInterfaceId interface_id,
- const std::regex &regex)
+bool MouseControlAPI::Map(const MouseInterfaceId interface_id,
+ const std::regex &regex)
{
if (mouse_config.no_mouse)
return false;
@@ -417,43 +417,37 @@ bool MouseConfigAPI::Map(const MouseInterfaceId interface_id,
return Map(interface_id, idx);
}
-bool MouseConfigAPI::UnMap(const MouseConfigAPI::ListIDs &list_ids)
+bool MouseControlAPI::UnMap(const MouseControlAPI::ListIDs &list_ids)
{
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigUnMap();
return !list.empty();
}
-bool MouseConfigAPI::OnOff(const MouseConfigAPI::ListIDs &list_ids,
- const bool enable)
+bool MouseControlAPI::OnOff(const MouseControlAPI::ListIDs &list_ids,
+ const bool enable)
{
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigOnOff(enable);
return !list.empty();
}
-bool MouseConfigAPI::Reset(const MouseConfigAPI::ListIDs &list_ids)
+bool MouseControlAPI::Reset(const MouseControlAPI::ListIDs &list_ids)
{
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigReset();
return !list.empty();
}
-bool MouseConfigAPI::SetSensitivity(const MouseConfigAPI::ListIDs &list_ids,
- const int8_t sensitivity_x,
- const int8_t sensitivity_y)
+bool MouseControlAPI::SetSensitivity(const MouseControlAPI::ListIDs &list_ids,
+ const int8_t sensitivity_x,
+ const int8_t sensitivity_y)
{
if (sensitivity_x > mouse_predefined.sensitivity_user_max ||
sensitivity_x < -mouse_predefined.sensitivity_user_max ||
@@ -461,86 +455,74 @@ bool MouseConfigAPI::SetSensitivity(const MouseConfigAPI::ListIDs &list_ids,
sensitivity_y < -mouse_predefined.sensitivity_user_max)
return false;
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigSetSensitivity(sensitivity_x, sensitivity_y);
return !list.empty();
}
-bool MouseConfigAPI::SetSensitivityX(const MouseConfigAPI::ListIDs &list_ids,
- const int8_t sensitivity_x)
+bool MouseControlAPI::SetSensitivityX(const MouseControlAPI::ListIDs &list_ids,
+ const int8_t sensitivity_x)
{
if (sensitivity_x > mouse_predefined.sensitivity_user_max ||
sensitivity_x < -mouse_predefined.sensitivity_user_max)
return false;
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigSetSensitivityX(sensitivity_x);
return !list.empty();
}
-bool MouseConfigAPI::SetSensitivityY(const MouseConfigAPI::ListIDs &list_ids,
- const int8_t sensitivity_y)
+bool MouseControlAPI::SetSensitivityY(const MouseControlAPI::ListIDs &list_ids,
+ const int8_t sensitivity_y)
{
if (sensitivity_y > mouse_predefined.sensitivity_user_max ||
sensitivity_y < -mouse_predefined.sensitivity_user_max)
return false;
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigSetSensitivityY(sensitivity_y);
return !list.empty();
}
-bool MouseConfigAPI::ResetSensitivity(const MouseConfigAPI::ListIDs &list_ids)
+bool MouseControlAPI::ResetSensitivity(const MouseControlAPI::ListIDs &list_ids)
{
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigResetSensitivity();
return !list.empty();
}
-bool MouseConfigAPI::ResetSensitivityX(const MouseConfigAPI::ListIDs &list_ids)
+bool MouseControlAPI::ResetSensitivityX(const MouseControlAPI::ListIDs &list_ids)
{
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigResetSensitivityX();
return !list.empty();
}
-bool MouseConfigAPI::ResetSensitivityY(const MouseConfigAPI::ListIDs &list_ids)
+bool MouseControlAPI::ResetSensitivityY(const MouseControlAPI::ListIDs &list_ids)
{
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigResetSensitivityY();
return !list.empty();
}
-const std::vector<uint16_t> &MouseConfigAPI::GetValidMinRateList()
+const std::vector<uint16_t> &MouseControlAPI::GetValidMinRateList()
{
return MouseConfig::GetValidMinRateList();
}
-const std::string &MouseConfigAPI::GetValidMinRateStr()
+const std::string &MouseControlAPI::GetValidMinRateStr()
{
static std::string out_str = "";
@@ -560,27 +542,23 @@ const std::string &MouseConfigAPI::GetValidMinRateStr()
return out_str;
}
-bool MouseConfigAPI::SetMinRate(const MouseConfigAPI::ListIDs &list_ids,
- const uint16_t value_hz)
+bool MouseControlAPI::SetMinRate(const MouseControlAPI::ListIDs &list_ids,
+ const uint16_t value_hz)
{
const auto &valid_list = GetValidMinRateList();
if (std::find(valid_list.begin(), valid_list.end(), value_hz) == valid_list.end())
return false; // invalid value
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigSetMinRate(value_hz);
return !list.empty();
}
-bool MouseConfigAPI::ResetMinRate(const MouseConfigAPI::ListIDs &list_ids)
+bool MouseControlAPI::ResetMinRate(const MouseControlAPI::ListIDs &list_ids)
{
- std::vector<MouseInterface *> list;
- get_relevant_interfaces(list, list_ids);
-
+ auto list = get_relevant_interfaces(list_ids);
for (auto &interface : list)
interface->ConfigResetMinRate();
diff --git a/src/hardware/mouse/mouse_common.cpp b/src/hardware/mouse/mouse_common.cpp
index 75e2f5d08..fcebf5a0b 100644
--- a/src/hardware/mouse/mouse_common.cpp
+++ b/src/hardware/mouse/mouse_common.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
@@ -42,7 +42,9 @@ float MOUSE_GetBallisticsCoeff(const float speed)
// This routine provides a function for mouse ballistics
// (cursor acceleration), to be reused by various mouse interfaces.
// Since this is a DOS emulator, the acceleration model is
- // based on a historic PS/2 mouse specification.
+ // based on a historic PS/2 mouse scaling specification, desribed
+ // for exampel here:
+ // - https://wiki.osdev.org/Mouse_Input
// Input: mouse speed
// Output: acceleration coefficient (1.0f for speed >= 6.0f)
@@ -93,30 +95,12 @@ float MOUSE_ClampRelativeMovement(const float rel)
uint16_t MOUSE_ClampRateHz(const uint16_t rate_hz)
{
- constexpr auto rate_min = static_cast<uint16_t>(10);
- constexpr auto rate_max = static_cast<uint16_t>(500);
+ constexpr uint16_t rate_min = 10;
+ constexpr uint16_t rate_max = 500;
return std::clamp(rate_hz, rate_min, rate_max);
}
-int8_t MOUSE_ClampToInt8(const int32_t val)
-{
- const auto tmp = std::clamp(val,
- static_cast<int32_t>(INT8_MIN),
- static_cast<int32_t>(INT8_MAX));
-
- return static_cast<int8_t>(tmp);
-}
-
-int16_t MOUSE_ClampToInt16(const int32_t val)
-{
- const auto tmp = std::clamp(val,
- static_cast<int32_t>(INT16_MIN),
- static_cast<int32_t>(INT16_MAX));
-
- return static_cast<int16_t>(tmp);
-}
-
// ***************************************************************************
// Mouse speed calculation
// ***************************************************************************
diff --git a/src/hardware/mouse/mouse_common.h b/src/hardware/mouse/mouse_common.h
index 5c54b26d1..86230e179 100644
--- a/src/hardware/mouse/mouse_common.h
+++ b/src/hardware/mouse/mouse_common.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
@@ -79,9 +79,6 @@ uint8_t MOUSE_GetDelayFromRateHz(const uint16_t rate_hz);
float MOUSE_ClampRelativeMovement(const float rel);
uint16_t MOUSE_ClampRateHz(const uint16_t rate_hz);
-int8_t MOUSE_ClampToInt8(const int32_t val);
-int16_t MOUSE_ClampToInt16(const int32_t val);
-
// ***************************************************************************
// Mouse speed calculation
// ***************************************************************************
diff --git a/src/hardware/mouse/mouse_config.cpp b/src/hardware/mouse/mouse_config.cpp
index 87efb66b2..a329e899f 100644
--- a/src/hardware/mouse/mouse_config.cpp
+++ b/src/hardware/mouse/mouse_config.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
@@ -40,7 +40,7 @@ CHECK_NARROWING();
MouseConfig mouse_config;
MousePredefined mouse_predefined;
-static std::vector<std::string> list_models_ps2 = {
+static const std::vector<std::string> list_models_ps2 = {
"standard",
"intellimouse",
#ifdef ENABLE_EXPLORER_MOUSE
@@ -48,7 +48,7 @@ static std::vector<std::string> list_models_ps2 = {
#endif
};
-static std::vector<std::string> list_models_com = {
+static const std::vector<std::string> list_models_com = {
"2button",
"3button",
"wheel",
@@ -58,7 +58,7 @@ static std::vector<std::string> list_models_com = {
"wheel+msm",
};
-static std::vector<uint16_t> list_rates = {
+static const std::vector<uint16_t> list_rates = {
// Commented out values are probably not interesting
// for the end user as "boosted" sampling rate
// 10", // PS/2 mouse
diff --git a/src/hardware/mouse/mouse_config.h b/src/hardware/mouse/mouse_config.h
index 0d41cfc39..04a3e404d 100644
--- a/src/hardware/mouse/mouse_config.h
+++ b/src/hardware/mouse/mouse_config.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
diff --git a/src/hardware/mouse/mouse_interfaces.cpp b/src/hardware/mouse/mouse_interfaces.cpp
index 067b4c6cf..09eb7efe4 100644
--- a/src/hardware/mouse/mouse_interfaces.cpp
+++ b/src/hardware/mouse/mouse_interfaces.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
diff --git a/src/hardware/mouse/mouse_interfaces.h b/src/hardware/mouse/mouse_interfaces.h
index dec05244e..4eddf1bc4 100644
--- a/src/hardware/mouse/mouse_interfaces.h
+++ b/src/hardware/mouse/mouse_interfaces.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
diff --git a/src/hardware/mouse/mouse_manymouse.cpp b/src/hardware/mouse/mouse_manymouse.cpp
index cc71216e1..8fbba5ce9 100644
--- a/src/hardware/mouse/mouse_manymouse.cpp
+++ b/src/hardware/mouse/mouse_manymouse.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
@@ -22,6 +22,7 @@
#include "callback.h"
#include "checks.h"
+#include "math_utils.h"
#include "pic.h"
#include "string_utils.h"
@@ -163,12 +164,16 @@ void ManyMouseGlue::Rescan()
std::string name;
UTF8_RenderForDos(name_utf8, name);
+ const char character_nbsp = 0x7f; // non-breaking space
+ const char character_space = 0x20;
+
for (auto pos = name.size(); pos > 0; pos--) {
// Replace non-breaking space with a regular space
- if (name[pos - 1] == 0x7f)
- name[pos - 1] = 0x20;
+ if (name[pos - 1] == character_nbsp)
+ name[pos - 1] = character_space;
// Remove non-ASCII and control characters
- if (name[pos - 1] < 0x20 || name[pos - 1] > 0x7e)
+ if (name[pos - 1] < character_space ||
+ name[pos - 1] > character_nbsp)
name.erase(pos - 1, 1);
}
@@ -248,7 +253,7 @@ bool ManyMouseGlue::ProbeForMapping(uint8_t &device_id)
// Do not accept already mapped devices
bool already_mapped = false;
- for (auto &interface : mouse_interfaces)
+ for (const auto &interface : mouse_interfaces)
if (interface->IsMapped(device_id))
already_mapped = true;
if (already_mapped)
@@ -282,7 +287,7 @@ uint8_t ManyMouseGlue::GetIdx(const std::regex &regex)
return static_cast<uint8_t>(i);
}
- return max_mice;
+ return max_mice; // return value which will be considered out of range
}
void ManyMouseGlue::Map(const uint8_t physical_idx,
@@ -386,7 +391,7 @@ void ManyMouseGlue::HandleEvent(const ManyMouseEvent &event,
// LOG_INFO("MANYMOUSE #%u WHEEL #%u %d", event.device, event.item, event.value);
if (no_interface || critical_only || (event.item != 0))
break; // only the 1st wheel is supported
- MOUSE_EventWheel(MOUSE_ClampToInt16(-event.value), interface_id);
+ MOUSE_EventWheel(clamp_to_int16(-event.value), interface_id);
break;
case MANYMOUSE_EVENT_DISCONNECT:
diff --git a/src/hardware/mouse/mouse_manymouse.h b/src/hardware/mouse/mouse_manymouse.h
index d8cb9b65f..4853982c3 100644
--- a/src/hardware/mouse/mouse_manymouse.h
+++ b/src/hardware/mouse/mouse_manymouse.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
diff --git a/src/hardware/mouse/mouse_queue.cpp b/src/hardware/mouse/mouse_queue.cpp
index e793b41e0..095013fe4 100644
--- a/src/hardware/mouse/mouse_queue.cpp
+++ b/src/hardware/mouse/mouse_queue.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
diff --git a/src/hardware/mouse/mouse_queue.h b/src/hardware/mouse/mouse_queue.h
index 7286b0826..7268cc4d1 100644
--- a/src/hardware/mouse/mouse_queue.h
+++ b/src/hardware/mouse/mouse_queue.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
diff --git a/src/hardware/mouse/mouseif_dos_driver.cpp b/src/hardware/mouse/mouseif_dos_driver.cpp
index 31ac9e361..fea52df11 100644
--- a/src/hardware/mouse/mouseif_dos_driver.cpp
+++ b/src/hardware/mouse/mouseif_dos_driver.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
* Copyright (C) 2002-2021 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
@@ -30,6 +30,7 @@
#include "checks.h"
#include "cpu.h"
#include "dos_inc.h"
+#include "math_utils.h"
#include "pic.h"
#include "regs.h"
@@ -104,7 +105,9 @@ static struct {
// Multiply by 6.0f to compensate for 'MOUSE_GetBallisticsCoeff', which uses
// 6 as intersection point (just like 2:1 scaling model from PS/2 specification)
-static MouseSpeedCalculator speed_mickeys(mouse_predefined.acceleration_dos * 6.0f);
+constexpr float acceleration_multiplier = 6.0f;
+static MouseSpeedCalculator speed_mickeys(acceleration_multiplier *
+ mouse_predefined.acceleration_dos);
static struct { // DOS driver state
@@ -1046,7 +1049,7 @@ uint8_t MOUSEDOS_UpdateButtons(const MouseButtons12S new_buttons_12S)
static uint8_t move_wheel()
{
- counter_w = MOUSE_ClampToInt8(static_cast<int32_t>(counter_w + pending.w_rel));
+ counter_w = clamp_to_int8(static_cast<int32_t>(counter_w + pending.w_rel));
// Pending wheel scroll is now consummed
pending.w_rel = 0;
@@ -1121,7 +1124,7 @@ bool MOUSEDOS_NotifyWheel(const int16_t w_rel)
// wheel counter in 16-bit format, scrolling hundreds of lines in one
// go would be insane - thus, limit the wheel counter to 8 bits and
// reuse the code written for other mouse modules
- pending.w_rel = MOUSE_ClampToInt8(pending.w_rel + w_rel);
+ pending.w_rel = clamp_to_int8(pending.w_rel + w_rel);
if (pending.w_rel == 0)
return 0;
diff --git a/src/hardware/mouse/mouseif_ps2_bios.cpp b/src/hardware/mouse/mouseif_ps2_bios.cpp
index 461c59b99..210ecfaf1 100644
--- a/src/hardware/mouse/mouseif_ps2_bios.cpp
+++ b/src/hardware/mouse/mouseif_ps2_bios.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
* Copyright (C) 2002-2021 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
@@ -29,6 +29,7 @@
#include "callback.h"
#include "checks.h"
#include "cpu.h"
+#include "math_utils.h"
#include "pic.h"
#include "regs.h"
@@ -342,7 +343,7 @@ bool MOUSEPS2_NotifyWheel(const int16_t w_rel)
return false;
auto old_counter_w = counter_w;
- counter_w = MOUSE_ClampToInt8(static_cast<int32_t>(counter_w + w_rel));
+ counter_w = clamp_to_int8(static_cast<int32_t>(counter_w + w_rel));
return (old_counter_w != counter_w);
}
diff --git a/src/hardware/mouse/mouseif_virtual_machines.cpp b/src/hardware/mouse/mouseif_virtual_machines.cpp
index db65f34a1..32f4a5fca 100644
--- a/src/hardware/mouse/mouseif_virtual_machines.cpp
+++ b/src/hardware/mouse/mouseif_virtual_machines.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
*
* 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
@@ -24,6 +24,7 @@
#include "checks.h"
#include "inout.h"
+#include "math_utils.h"
#include "pic.h"
#include "regs.h"
@@ -83,7 +84,9 @@ static float pos_y = 0.0f;
// Multiply scale by 0.02f to put acceleration_vmm in a reasonable
// range, similar to sensitivity_dos or sensitivity_vmm)
-static MouseSpeedCalculator speed_xy(0.02f * mouse_predefined.acceleration_vmm);
+constexpr float acceleration_multiplier = 0.02f;
+static MouseSpeedCalculator speed_xy(acceleration_multiplier *
+ mouse_predefined.acceleration_vmm);
// ***************************************************************************
// VMware interface implementation
@@ -269,7 +272,7 @@ bool MOUSEVMM_NotifyWheel(const int16_t w_rel)
return false;
const auto old_counter_w = counter_w;
- counter_w = MOUSE_ClampToInt8(static_cast<int32_t>(counter_w + w_rel));
+ counter_w = clamp_to_int8(static_cast<int32_t>(counter_w + w_rel));
if (GCC_UNLIKELY(old_counter_w == counter_w))
return false;
diff --git a/src/hardware/serialport/serialmouse.cpp b/src/hardware/serialport/serialmouse.cpp
index bcdaf5ecf..14b8883f8 100644
--- a/src/hardware/serialport/serialmouse.cpp
+++ b/src/hardware/serialport/serialmouse.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
* Copyright (C) 2002-2021 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
@@ -28,6 +28,7 @@
#include "serialmouse.h"
#include "checks.h"
+#include "math_utils.h"
#include "../mouse/mouse_interfaces.h"
@@ -244,8 +245,8 @@ void CSerialMouse::NotifyMoved(const float x_rel, const float y_rel)
if (dx == 0 && dy == 0)
return; // movement not significant enough
- counter_x = MOUSE_ClampToInt8(counter_x + dx);
- counter_y = MOUSE_ClampToInt8(counter_y + dy);
+ counter_x = clamp_to_int8(counter_x + dx);
+ counter_y = clamp_to_int8(counter_y + dy);
delta_x -= dx;
delta_y -= dy;
@@ -278,7 +279,7 @@ void CSerialMouse::NotifyWheel(const int16_t w_rel)
if (!has_wheel)
return;
- counter_w = MOUSE_ClampToInt8(static_cast<int32_t>(counter_w + w_rel));
+ counter_w = clamp_to_int8(static_cast<int32_t>(counter_w + w_rel));
if (xmit_idx >= packet_len)
StartPacketData(true);
diff --git a/src/hardware/serialport/serialmouse.h b/src/hardware/serialport/serialmouse.h
index 1cf05eb19..b9185e949 100644
--- a/src/hardware/serialport/serialmouse.h
+++ b/src/hardware/serialport/serialmouse.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The DOSBox Staging Team
+ * Copyright (C) 2022-2022 The DOSBox Staging Team
* Copyright (C) 2002-2021 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify