Bus fixes: Reading of CPU MMIO registers does not update MDR
[lsnes.git] / bsnes-patches / v084 / 0007-Fix-mouse-polling.patch
blobd38d054c3e5ac61cc73ba54d4c7f0cd4ce4ce2ce
1 From 4f6981592e29038ad9f818399c0d5a48750cf28a Mon Sep 17 00:00:00 2001
2 From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
3 Date: Wed, 7 Mar 2012 16:57:18 +0200
4 Subject: [PATCH 07/10] Fix mouse polling
6 Don't poll for mouse motion excessive number of times (no need to poll it for
7 each bit!)
8 ---
9 snes/controller/mouse/mouse.cpp | 14 ++++++++++++--
10 snes/controller/mouse/mouse.hpp | 2 ++
11 2 files changed, 14 insertions(+), 2 deletions(-)
13 diff --git a/snes/controller/mouse/mouse.cpp b/snes/controller/mouse/mouse.cpp
14 index 6b26fae..1a066b9 100755
15 --- a/snes/controller/mouse/mouse.cpp
16 +++ b/snes/controller/mouse/mouse.cpp
17 @@ -3,9 +3,13 @@
18 uint2 Mouse::data() {
19 if(counter >= 32) return 1;
21 - int position_x = interface->inputPoll(port, Input::Device::Mouse, 0, (unsigned)Input::MouseID::X); //-n = left, 0 = center, +n = right
22 - int position_y = interface->inputPoll(port, Input::Device::Mouse, 0, (unsigned)Input::MouseID::Y); //-n = up, 0 = center, +n = down
23 + if(counter == 0) {
24 + _position_x = interface->inputPoll(port, Input::Device::Mouse, 0, (unsigned)Input::MouseID::X); //-n = left, 0 = center, +n = right
25 + _position_y = interface->inputPoll(port, Input::Device::Mouse, 0, (unsigned)Input::MouseID::Y); //-n = up, 0 = center, +n = down
26 + }
28 + int position_x = _position_x;
29 + int position_y = _position_y;
30 bool direction_x = position_x < 0; //0 = right, 1 = left
31 bool direction_y = position_y < 0; //0 = down, 1 = up
33 @@ -67,10 +71,16 @@ void Mouse::serialize(serializer& s) {
34 unsigned char block[Controller::SaveSize] = {0};
35 block[0] = latched ? 1 : 0;
36 block[1] = counter;
37 + block[2] = (unsigned short)_position_x >> 8;
38 + block[3] = (unsigned short)_position_x;
39 + block[4] = (unsigned short)_position_y >> 8;
40 + block[5] = (unsigned short)_position_y;
41 s.array(block, Controller::SaveSize);
42 if(s.mode() == nall::serializer::Load) {
43 latched = (block[0] != 0);
44 counter = block[1];
45 + _position_x = (short)(((unsigned short)block[2] << 8) | (unsigned short)block[3]);
46 + _position_y = (short)(((unsigned short)block[4] << 8) | (unsigned short)block[5]);
50 diff --git a/snes/controller/mouse/mouse.hpp b/snes/controller/mouse/mouse.hpp
51 index b66ea51..b07c8ab 100755
52 --- a/snes/controller/mouse/mouse.hpp
53 +++ b/snes/controller/mouse/mouse.hpp
54 @@ -6,4 +6,6 @@ struct Mouse : Controller {
55 private:
56 bool latched;
57 unsigned counter;
58 + int _position_x;
59 + int _position_y;
61 --
62 1.8.4.4