VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
Paddle.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 "PaddleTypes.h"
16#include "JoystickTypes.h"
17#include "C64Types.h"
18#include "SubComponent.h"
19
20namespace vc64 {
21
22class Paddle final : public SubComponent, public Inspectable<PaddleInfo> {
23
24 Descriptions descriptions = {
25 {
26 .name = "Paddle1",
27 .description = "Paddle in Port 1"
28 },
29 {
30 .name = "Paddle2",
31 .description = "Paddle in Port 2"
32 }
33 };
34
35 ConfigOptions options = {
36
38 };
39
40 // Reference to the control port this device belongs to
41 ControlPort &port;
42
43 // Current configuration
44 PaddleConfig config = { };
45
46 // Paddle positions in the range [-1...1]
47 double pos[2] = { };
48
49 // Button states
50 bool button[2] = { };
51
52
53 //
54 // Methods
55 //
56
57public:
58
59 Paddle(C64 &ref, ControlPort& pref);
60
61 Paddle& operator= (const Paddle& other) {
62
63 CLONE(config)
64
65 return *this;
66 }
67
68
69 //
70 // Methods from Serializable
71 //
72
73public:
74
75 template <class T> void serialize(T& worker) {
76
77 if (isResetter(worker)) return;
78 }
79 void operator << (SerChecker &worker) override { serialize(worker); }
80 void operator << (SerCounter &worker) override { serialize(worker); }
81 void operator << (SerResetter &worker) override;
82 void operator << (SerReader &worker) override;
83 void operator << (SerWriter &worker) override { serialize(worker); }
84
85
86 //
87 // Methods from CoreComponent
88 //
89
90public:
91
92 const Descriptions &getDescriptions() const override { return descriptions; }
93
94private:
95
96 void _dump(Category category, std::ostream& os) const override;
97 void _reset(bool hard) override;
98
99
100 //
101 // Methods from Inspectable
102 //
103
104private:
105
106 void cacheInfo(PaddleInfo &result) const override;
107
108
109 //
110 // Methods from Configurable
111 //
112
113public:
114
115 const PaddleConfig &getConfig() const { return config; }
116 const ConfigOptions &getOptions() const override { return options; }
117 i64 getOption(Option opt) const override;
118 void checkOption(Option opt, i64 value) override;
119 void setOption(Option opt, i64 value) override;
120
121
122 //
123 // Using the device
124 //
125
126public:
127
128 // Sets the button state
129 void setButton(isize nr, bool value);
130
131 // Sets the paddle position
132 void setPosXY(isize nr, double x, double y);
133 void setPosDxDy(isize nr, double x, double y);
134
135 // Reads the port bits that show up in the CIA's data port registers
136 u8 readControlPort() const;
137
138 // Reads the pot bits that show up in the SID registers
139 u8 readPotX() const;
140 u8 readPotY() const;
141
142};
143
144}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16
@ OPT_PADDLE_ORIENTATION
Paddle value mapping scheme.
Definition OptionTypes.h:167