VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
Mouse1351.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "SubComponent.h"
16
17namespace vc64 {
18
19class Mouse1351 final : public SubComponent {
20
21 Descriptions descriptions = {{
22
23 .name = "Mouse1351",
24 .description = "Mouse 1351"
25 }};
26
27 // Mouse position
28 i64 mouseX;
29 i64 mouseY;
30
31 // Mouse button states
32 bool leftButton;
33 bool rightButton;
34
35 // Dividers applied to raw coordinates in setXY()
36 int dividerX = 256;
37 int dividerY = 256;
38
39 // Mouse movement in pixels per execution step
40 i64 shiftX = 31;
41 i64 shiftY = 31;
42
43 //
44 // Methods
45 //
46
47public:
48
49 Mouse1351(C64 &ref) : SubComponent(ref) { }
50
51 Mouse1351& operator= (const Mouse1351& other) {
52
53 CLONE(mouseX)
54 CLONE(mouseY)
55 CLONE(leftButton)
56 CLONE(rightButton)
57 CLONE(dividerX)
58 CLONE(dividerY)
59 CLONE(shiftX)
60 CLONE(shiftY)
61
62 return *this;
63 }
64
65
66 //
67 // Methods from Serializable
68 //
69
70public:
71
72 template <class T> void serialize(T& worker) { } SERIALIZERS(serialize);
73 void _reset(bool hard) override;
74
75
76 //
77 // Methods from CoreComponent
78 //
79
80public:
81
82 const Descriptions &getDescriptions() const override { return descriptions; }
83
84
85 //
86 // Accessing
87 //
88
89public:
90
91 // Updates the button state
92 void setLeftMouseButton(bool value) { leftButton = value; }
93 void setRightMouseButton(bool value) { rightButton = value; }
94
95 // Returns the pot bits as set by the mouse
96 u8 readPotX() const;
97 u8 readPotY() const;
98
99 // Returns the control port bits triggered by the mouse
100 u8 readControlPort() const;
101
102 // Execution function (Smoothly moves the mouse to the target position)
103 void executeX(i64 targetX);
104 void executeY(i64 targetY);
105
106 // Returns the mouse bits as they show up in the SID register
107 u8 mouseXBits() const { return (u8)((mouseX & 0x3F) << 1); }
108 u8 mouseYBits() const { return (u8)((mouseY & 0x3F) << 1); }
109};
110
111}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16