VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
ControlPort.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 "ControlPortTypes.h"
16#include "CmdQueueTypes.h"
17#include "SubComponent.h"
18#include "Joystick.h"
19#include "Mouse.h"
20#include "Paddle.h"
21
22namespace vc64 {
23
24class ControlPort final : public SubComponent {
25
26 friend class Mouse;
27 friend class Joystick;
28 friend class Paddle;
29
30 Descriptions descriptions = {
31 {
32 .name = "Port1",
33 .description = "Control Port 1"
34 },
35 {
36 .name = "Port2",
37 .description = "Control Port 2"
38 }
39 };
40
41 // The connected device
42 ControlPortDevice device = CPDEVICE_NONE;
43
44
45 //
46 // Sub components
47 //
48
49public:
50
51 Mouse mouse = Mouse(c64, *this);
52 Joystick joystick = Joystick(c64, *this);
53 Paddle paddle = Paddle(c64, *this);
54
55
56 //
57 // Methods
58 //
59
60public:
61
62 ControlPort(C64 &ref, isize id);
63
64 ControlPort& operator= (const ControlPort& other) {
65
66 CLONE(mouse)
67 CLONE(joystick)
68 CLONE(paddle)
69 CLONE(device)
70
71 return *this;
72 }
73
74
75 //
76 // Methods from Serializable
77 //
78
79public:
80
81 template <class T> void serialize(T& worker) {
82
83 worker
84
85 << mouse
86 << joystick
87 << paddle;
88
89 } SERIALIZERS(serialize);
90
91
92 //
93 // Methods from CoreComponent
94 //
95
96public:
97
98 const Descriptions &getDescriptions() const override { return descriptions; }
99
100private:
101
102 void _dump(Category category, std::ostream& os) const override;
103
104
105 //
106 // Emulating
107 //
108
109public:
110
111 // Invoked at the end of each frame
112 void execute();
113
114 // Updates the control port bits (must be called before reading)
115 void updateControlPort();
116
117 // Returns the control port bits as set by the mouse
118 u8 getControlPort() const;
119
120 // Updates the pot bits (must be called before reading)
121 void updatePotX();
122 void updatePotY();
123
124 // Reads the pot bits that show up in the SID registers
125 u8 readPotX() const;
126 u8 readPotY() const;
127
128
129 //
130 // Processing commands and events
131 //
132
133public:
134
135 // Processes a datasette command
136 void processCommand(const Cmd &cmd);
137};
138
139}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16
@ CPDEVICE_NONE
No device.
Definition ControlPortTypes.h:35