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 
33 class EventContext;
34 class MOS6526;
35 
42 class TimerA : public Timer
43 {
44 private:
48  void underFlow();
49 
50  void serialPort();
51 
52 public:
57  Timer("CIA Timer A", context, parent) {}
58 };
59 
66 class TimerB : public Timer
67 {
68 private:
69  void underFlow();
70 
71 public:
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 */
84  syncWithCpu();
85  state |= CIAT_STEP;
87  }
88 
94  bool started() const { return (state & CIAT_CR_START) != 0; }
95 };
96 
103 class MOS6526: public component
104 {
105  friend class TimerA;
106  friend class TimerB;
107  friend class Tod;
108 
109 private:
110  static const char *credit;
111 
113  event_clock_t last_clear;
114 
116  bool tbBug;
117 
118 protected:
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;
159  EventCallback<MOS6526> spEvent;
161 
162 protected:
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 
244 private:
245  void todInterrupt();
246 
250  void spInterrupt();
251 
252  void triggerBug();
253 
254 public:
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
MOS6526::idr
uint8_t idr
Interrupt data register.
Definition: mos6526.h:144
TimerA
Definition: mos6526.h:42
TimerB::cascade
void cascade()
Definition: mos6526.h:81
MOS6526::triggerScheduled
bool triggerScheduled
Have we already scheduled CIA->CPU interrupt transition?
Definition: mos6526.h:153
MOS6526::underflowA
void underflowA()
Definition: mos6526.cpp:351
MOS6526::MOS6526
MOS6526(EventContext *context)
Definition: mos6526.cpp:86
component
Definition: component.h:28
MOS6526::underflowB
void underflowB()
Definition: mos6526.cpp:363
MOS6526::interrupt
virtual void interrupt(bool state)=0
MOS6526::regs
uint8_t regs[0x10]
These are all CIA registers.
Definition: mos6526.h:120
EventCallback< MOS6526 >
Timer
Definition: timer.h:38
MOS6526::tod
Tod tod
TOD.
Definition: mos6526.h:150
Timer::parent
MOS6526 *const parent
Pointer to the MOS6526 which this Timer belongs to.
Definition: timer.h:88
MOS6526::reset
virtual void reset()
Definition: mos6526.cpp:134
MOS6526::sdr_out
uint8_t sdr_out
Serial Data Registers.
Definition: mos6526.h:135
MOS6526::timerA
TimerA timerA
Timers A and B.
Definition: mos6526.h:129
MOS6526::bTickEvent
EventCallback< MOS6526 > bTickEvent
Events.
Definition: mos6526.h:157
Tod::setPeriod
void setPeriod(event_clock_t clock)
Definition: tod.h:114
MOS6526::trigger
void trigger()
Definition: mos6526.cpp:304
EventContext
Definition: event.h:107
TimerB::TimerB
TimerB(EventContext *context, MOS6526 *parent)
Definition: mos6526.h:75
Timer::state
int_least32_t state
CRA/CRB control register / state.
Definition: timer.h:91
Timer::syncWithCpu
void syncWithCpu()
Definition: timer.cpp:34
MOS6526::pra
uint8_t & pra
Ports.
Definition: mos6526.h:124
MOS6526::event_context
EventContext & event_context
Event context.
Definition: mos6526.h:147
MOS6526::setDayOfTimeRate
void setDayOfTimeRate(unsigned int clock)
Definition: mos6526.h:273
TimerA::TimerA
TimerA(EventContext *context, MOS6526 *parent)
Definition: mos6526.h:56
TimerB::started
bool started() const
Definition: mos6526.h:94
MOS6526::read
uint8_t read(uint_least8_t addr)
Definition: mos6526.cpp:158
Timer::wakeUpAfterSyncWithCpu
void wakeUpAfterSyncWithCpu()
Definition: timer.cpp:57
MOS6526::clear
void clear()
Definition: mos6526.cpp:126
MOS6526::credits
static const char * credits()
Definition: mos6526.h:266
TimerB
Definition: mos6526.h:66
MOS6526::bTick
void bTick()
Definition: mos6526.cpp:346
MOS6526
Definition: mos6526.h:103
MOS6526::serialPort
void serialPort()
Definition: mos6526.cpp:105
MOS6526::write
void write(uint_least8_t addr, uint8_t data)
Definition: mos6526.cpp:229
MOS6526::icr
uint8_t icr
Interrupt control register.
Definition: mos6526.h:141
Tod
Definition: tod.h:36