VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
PIA.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 PIA6821 : public SubComponent {
20
21 friend class Drive;
22 friend class ParCable;
23
24 Descriptions descriptions = {{
25
26 .name = "PIA",
27 .description = "PIA 6821"
28 }};
29
30protected:
31
32 // Owner of this PIA
33 Drive &drive;
34
35 // Peripheral ports (pin values)
36 u8 pa;
37 u8 pb;
38
39 // Output registers
40 u8 ora;
41 u8 orb;
42
43 // Data direction registers
44 u8 ddra;
45 u8 ddrb;
46
47 // Control registers
48 u8 cra;
49 u8 crb;
50
51 // Interrupt control lines
52 bool ca1;
53 bool ca2;
54 bool cb1;
55 bool cb2;
56
57
58 //
59 // Methods
60 //
61
62public:
63
64 PIA6821(C64 &ref, Drive &drvref);
65
66 PIA6821& operator= (const PIA6821& other) {
67
68 CLONE(pa)
69 CLONE(pb)
70 CLONE(ora)
71 CLONE(orb)
72 CLONE(ddra)
73 CLONE(ddrb)
74 CLONE(cra)
75 CLONE(crb)
76 CLONE(ca1)
77 CLONE(ca2)
78 CLONE(cb1)
79 CLONE(cb2)
80
81 return *this;
82 }
83
84
85 //
86 // Methods from Serializable
87 //
88
89public:
90
91 template <class T>
92 void serialize(T& worker)
93 {
94 worker
95
96 << pa
97 << pb
98 << ora
99 << orb
100 << ddra
101 << ddrb
102 << cra
103 << crb
104 << ca1
105 << ca2
106 << cb1
107 << cb2;
108
109 } SERIALIZERS(serialize);
110
111
112 //
113 // Methods from CoreComponent
114 //
115
116public:
117
118 const Descriptions &getDescriptions() const override { return descriptions; }
119
120
121 //
122 // Managing interrupts
123 //
124
125public:
126
127 void setCA1External(bool value);
128 void setCA2External(bool value);
129 void setCB1External(bool value);
130 void setCB2External(bool value);
131
132 void toggleCA1External() { setCA1External(!ca1); }
133 void toggleCA2External() { setCA1External(!ca2); }
134 void toggleCB1External() { setCA1External(!cb1); }
135 void toggleCB2External() { setCA1External(!cb2); }
136
137 void pulseCA1External() { toggleCA1External(); toggleCA1External(); }
138
139private:
140
141 void setCA2Internal(bool value);
142 void setCB2Internal(bool value);
143
144 u8 ca2Control() const { return (cra >> 3) & 0b111; }
145 u8 cb2Control() const { return (crb >> 3) & 0b111; }
146 bool ca2IsInput() const { return GET_BIT(cra, 5); }
147 bool cb2IsInput() const { return GET_BIT(crb, 5); }
148
149 bool isActiveTransitionCA1(bool oldValue, bool newValue) const;
150 bool isActiveTransitionCA2(bool oldValue, bool newValue) const;
151 bool isActiveTransitionCB1(bool oldValue, bool newValue) const;
152 bool isActiveTransitionCB2(bool oldValue, bool newValue) const;
153
154 // Callbacks (delegation methods)
155 virtual void ca2HasChangedTo(bool value) { };
156 virtual void cb2HasChangedTo(bool value) { };
157 virtual void irqAHasOccurred() const { };
158 virtual void irqBHasOccurred() const { };
159
160
161 //
162 // Accessing registers
163 //
164
165public:
166
167 // Reads the data bus
168 u8 peek(bool rs1, bool rs0);
169 u8 spypeek(bool rs1, bool rs0) const { return 0; } // TODO
170
171 // Writes the data bus
172 void poke(bool rs1, bool rs0, u8 value);
173
174protected:
175
176 // Gets the port values up-to-date
177 virtual u8 updatePA();
178 virtual u8 updatePB();
179};
180
181//
182// PIA (DolphinDOS 3)
183//
184
185class PiaDolphin final : public PIA6821 {
186
187public:
188
189 using PIA6821::PIA6821;
190
191private:
192
193 void ca2HasChangedTo(bool value) override;
194 void cb2HasChangedTo(bool value) override;
195 void irqAHasOccurred() const override;
196 void irqBHasOccurred() const override;
197 u8 updatePA() override;
198 u8 updatePB() override;
199
200public:
201
202 u8 peek(u16 addr);
203 u8 spypeek(u16 addr) const;
204 void poke(u16 addr, u8 value);
205};
206
207}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16