VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
NeosMouse.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 NeosMouse final : public SubComponent {
20
21 Descriptions descriptions = {{
22
23 .name = "NeosMouse",
24 .description = "Neos Mouse"
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 = 512;
37 int dividerY = 256;
38
39 // Mouse movement in pixels per execution step
40 i64 shiftX = 127;
41 i64 shiftY = 127;
42
43 // Mouse state. When the mouse switches to state 0, the current mouse
44 // position is latched and the deltaX and deltaY are computed. After that,
45 // the mouse cycles through the other states and writes the delta values
46 // onto the control port, nibble by nibble.
47 u8 state;
48
49 // CPU cycle of the most recent trigger event
50 i64 triggerCycle;
51
52 // Latched mouse position
53 i64 latchedX;
54 i64 latchedY;
55
56 // Value transmitted to the C64
57 i8 deltaX;
58 i8 deltaY;
59
60
61 //
62 // Methods
63 //
64
65public:
66
67 NeosMouse(C64 &ref) : SubComponent(ref) { }
68
69 NeosMouse& operator= (const NeosMouse& other) {
70
71 CLONE(mouseX)
72 CLONE(mouseY)
73 CLONE(leftButton)
74 CLONE(rightButton)
75 CLONE(dividerX)
76 CLONE(dividerY)
77 CLONE(shiftX)
78 CLONE(shiftY)
79 CLONE(state)
80 CLONE(triggerCycle)
81 CLONE(latchedX)
82 CLONE(latchedY)
83 CLONE(deltaX)
84 CLONE(deltaY)
85
86 return *this;
87 }
88
89
90 //
91 // Methods from Serializable
92 //
93
94public:
95
96 template <class T> void serialize(T& worker) { } SERIALIZERS(serialize);
97 void _reset(bool hard) override;
98
99
100 //
101 // Methods from CoreComponent
102 //
103
104public:
105
106 const Descriptions &getDescriptions() const override { return descriptions; }
107
108
109 //
110 // Accessing
111 //
112
113public:
114
115 // Updates the button state
116 void setLeftMouseButton(bool value) { leftButton = value; }
117 void setRightMouseButton(bool value) { rightButton = value; }
118
119 // Returns the pot bits as set by the mouse
120 u8 readPotX() const;
121 u8 readPotY() const;
122
123 // Updates the control port bits (must be called before reading)
124 void updateControlPort(i64 targetX, i64 targetY);
125
126 // Returns the control port bits triggered by the mouse
127 u8 readControlPort() const;
128
129 // Triggers a state change
130 void risingStrobe(i64 targetX, i64 targetY);
131 void fallingStrobe(i64 targetX, i64 targetY);
132
133private:
134
135 // Latches the current mouse position and computed the transmission deltas
136 void latchPosition(i64 targetX, i64 targetY);
137};
138
139}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16