VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
SerialPort.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 "SerialPortTypes.h"
16#include "SubComponent.h"
17
18namespace vc64 {
19
20class SerialPort final : public SubComponent, public Inspectable<Void, SerialPortStats> {
21
22 Descriptions descriptions = {{
23
24 .name = "Serial",
25 .description = "Serial Port (IEC Bus)"
26 }};
27
28public:
29
30 // Current values of the IEC bus lines
31 bool atnLine;
32 bool clockLine;
33 bool dataLine;
34
35 // Bus driving values from drive 1
36 bool device1Atn;
37 bool device1Clock;
38 bool device1Data;
39
40 // Bus driving values from drive 2
41 bool device2Atn;
42 bool device2Clock;
43 bool device2Data;
44
45 // Bus driving values from the CIA
46 bool ciaAtn;
47 bool ciaClock;
48 bool ciaData;
49
50private:
51
52 // Indicates whether data is being transferred from or to a drive
53 bool transferring = false;
54
55
56 //
57 // Methods
58 //
59
60public:
61
62 SerialPort(C64 &ref) : SubComponent(ref) { };
63
64public:
65
66 SerialPort& operator= (const SerialPort& other) {
67
68 CLONE(atnLine)
69 CLONE(clockLine)
70 CLONE(dataLine)
71 CLONE(device1Atn)
72 CLONE(device1Clock)
73 CLONE(device1Data)
74 CLONE(device2Atn)
75 CLONE(device2Clock)
76 CLONE(device2Data)
77 CLONE(ciaAtn)
78 CLONE(ciaClock)
79 CLONE(ciaData)
80 CLONE(stats)
81
82 return *this;
83 }
84
85
86 //
87 // Methods from Serializable
88 //
89
90public:
91
92 template <class T>
93 void serialize(T& worker)
94 {
95 worker
96
97 << atnLine
98 << clockLine
99 << dataLine
100 << device1Atn
101 << device1Clock
102 << device1Data
103 << device2Atn
104 << device2Clock
105 << device2Data
106 << ciaAtn
107 << ciaClock
108 << ciaData
109 << stats.idle;
110
111 } SERIALIZERS(serialize);
112
113
114 //
115 // Methods from CoreComponent
116 //
117
118public:
119
120 const Descriptions &getDescriptions() const override { return descriptions; }
121
122private:
123
124 void _dump(Category category, std::ostream& os) const override;
125 void _reset(bool hard) override;
126
127
128 //
129 // Accessing
130 //
131
132public:
133
134 // Schedules an update event for the serial port (IEC bus)
135 void setNeedsUpdate();
136
137 /* Updates all three bus lines. The new values are determined by VIA1
138 * (drive side) and CIA2 (C64 side).
139 */
140 void update();
141
142 /* Execution function for observing the bus activity. This method is
143 * invoked periodically. It's purpose is to determines if data is
144 * transmitted on the bus.
145 */
146 void execute();
147
148 // Returns true if data is currently transferred over the bus
149 bool isTransferring() const { return transferring; }
150
151 // Updates variable transferring
152 void updateTransferStatus();
153
154private:
155
156 void updateIecLines();
157
158 /* Work horse for method updateIecLines. It returns true if at least one
159 * line changed it's value.
160 */
161 bool _updateIecLines();
162};
163
164}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16