libsidplayfp 1.8.8
mos6526.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2018 Leandro Nini <drfiemost@users.sourceforge.net>
5 * Copyright 2007-2010 Antti Lankila
6 * Copyright 2000 Simon White
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22
23#ifndef MOS6526_H
24#define MOS6526_H
25
26#include <stdint.h>
27
28#include "timer.h"
29#include "tod.h"
30#include "EventScheduler.h"
31#include "c64/component.h"
32
33class EventContext;
34class MOS6526;
35
42class TimerA : public Timer
43{
44private:
48 void underFlow();
49
50 void serialPort();
51
52public:
57 Timer("CIA Timer A", context, parent) {}
58};
59
66class TimerB : public Timer
67{
68private:
69 void underFlow();
70
71public:
76 Timer("CIA Timer B", context, parent) {}
77
81 void cascade()
82 {
83 /* we pretend that we are CPU doing a write to ctrl register */
85 state |= CIAT_STEP;
87 }
88
94 bool started() const { return (state & CIAT_CR_START) != 0; }
95};
96
103class MOS6526: public component
104{
105 friend class TimerA;
106 friend class TimerB;
107 friend class Tod;
108
109private:
110 static const char *credit;
111
113 event_clock_t last_clear;
114
116 bool tbBug;
117
118protected:
120 uint8_t regs[0x10];
121
123
124 uint8_t &pra, &prb, &ddra, &ddrb;
126
128
130 TimerB timerB;
132
134
135 uint8_t sdr_out;
136 bool sdr_buffered;
137 int sdr_count;
139
141 uint8_t icr;
142
144 uint8_t idr;
145
148
151
154
156
158 EventCallback<MOS6526> triggerEvent;
161
162protected:
168 MOS6526(EventContext *context);
169 ~MOS6526() {}
170
183 void bTick();
184
188 void trigger();
189
193 void underflowA();
194
196 void underflowB();
197
203 void trigger(uint8_t interruptMask);
204
208 void clear();
209
213 void serialPort();
214
221 virtual void interrupt(bool state) = 0;
222
223 virtual void portA() {}
224 virtual void portB() {}
225
232 uint8_t read(uint_least8_t addr);
233
242 void write(uint_least8_t addr, uint8_t data);
243
244private:
245 void todInterrupt();
246
250 void spInterrupt();
251
252 void triggerBug();
253
254public:
258 virtual void reset();
259
266 static const char *credits() { return credit; }
267
273 void setDayOfTimeRate(unsigned int clock) { tod.setPeriod(clock); }
274};
275
276#endif // MOS6526_H
Definition: EventScheduler.h:31
Definition: event.h:108
Definition: mos6526.h:104
uint8_t read(uint_least8_t addr)
Definition: mos6526.cpp:158
void bTick()
Definition: mos6526.cpp:346
uint8_t sdr_out
Serial Data Registers.
Definition: mos6526.h:135
virtual void reset()
Definition: mos6526.cpp:134
void trigger()
Definition: mos6526.cpp:304
uint8_t & pra
Ports.
Definition: mos6526.h:124
void serialPort()
Definition: mos6526.cpp:105
Tod tod
TOD.
Definition: mos6526.h:150
static const char * credits()
Definition: mos6526.h:266
bool triggerScheduled
Have we already scheduled CIA->CPU interrupt transition?
Definition: mos6526.h:153
void clear()
Definition: mos6526.cpp:126
void write(uint_least8_t addr, uint8_t data)
Definition: mos6526.cpp:229
uint8_t regs[0x10]
These are all CIA registers.
Definition: mos6526.h:120
virtual void interrupt(bool state)=0
uint8_t idr
Interrupt data register.
Definition: mos6526.h:144
uint8_t icr
Interrupt control register.
Definition: mos6526.h:141
EventCallback< MOS6526 > bTickEvent
Events.
Definition: mos6526.h:157
TimerA timerA
Timers A and B.
Definition: mos6526.h:129
void underflowB()
Definition: mos6526.cpp:363
void setDayOfTimeRate(unsigned int clock)
Definition: mos6526.h:273
EventContext & event_context
Event context.
Definition: mos6526.h:147
void underflowA()
Definition: mos6526.cpp:351
Definition: mos6526.h:43
TimerA(EventContext *context, MOS6526 *parent)
Definition: mos6526.h:56
Definition: mos6526.h:67
bool started() const
Definition: mos6526.h:94
void cascade()
Definition: mos6526.h:81
TimerB(EventContext *context, MOS6526 *parent)
Definition: mos6526.h:75
Definition: timer.h:39
void syncWithCpu()
Definition: timer.cpp:34
void wakeUpAfterSyncWithCpu()
Definition: timer.cpp:57
int_least32_t state
CRA/CRB control register / state.
Definition: timer.h:91
MOS6526 *const parent
Pointer to the MOS6526 which this Timer belongs to.
Definition: timer.h:88
Definition: tod.h:37
void setPeriod(event_clock_t clock)
Definition: tod.h:114
Definition: component.h:29