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 
132 
134 
135  uint8_t sdr_out;
139 
141  uint8_t icr;
142 
144  uint8_t idr;
145 
148 
151 
154 
156 
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
Definition: mos6526.h:66
Definition: mos6526.h:103
void reset()
Definition: timer.cpp:128
EventCallback< MOS6526 > spEvent
Events.
Definition: mos6526.h:159
uint8_t idr
Interrupt data register.
Definition: mos6526.h:144
TimerB(EventContext *context, MOS6526 *parent)
Definition: mos6526.h:75
TimerA timerA
Timers A and B.
Definition: mos6526.h:129
int sdr_count
Serial Data Registers.
Definition: mos6526.h:137
uint8_t sdr_out
Serial Data Registers.
Definition: mos6526.h:135
Definition: mos6526.h:42
uint8_t read(uint_least8_t reg)
Definition: tod.cpp:46
void cascade()
Definition: mos6526.h:81
Definition: event.h:107
void setPeriod(event_clock_t clock)
Definition: tod.h:114
static const char * credits()
Definition: mos6526.h:266
EventCallback< MOS6526 > bTickEvent
Events.
Definition: mos6526.h:157
MOS6526 *const parent
Pointer to the MOS6526 which this Timer belongs to.
Definition: timer.h:88
EventCallback< MOS6526 > triggerEvent
Events.
Definition: mos6526.h:158
Tod tod
TOD.
Definition: mos6526.h:150
Definition: component.h:28
bool triggerScheduled
Have we already scheduled CIA->CPU interrupt transition?
Definition: mos6526.h:153
int_least32_t state
CRA/CRB control register / state.
Definition: timer.h:91
uint8_t & prb
Ports.
Definition: mos6526.h:124
void write(uint_least8_t reg, uint8_t data)
Definition: tod.cpp:63
bool sdr_buffered
Serial Data Registers.
Definition: mos6526.h:136
uint8_t icr
Interrupt control register.
Definition: mos6526.h:141
void syncWithCpu()
Definition: timer.cpp:34
void wakeUpAfterSyncWithCpu()
Definition: timer.cpp:57
TimerA(EventContext *context, MOS6526 *parent)
Definition: mos6526.h:56
EventContext & event_context
Event context.
Definition: mos6526.h:147
Definition: timer.h:38
void setDayOfTimeRate(unsigned int clock)
Definition: mos6526.h:273
Definition: tod.h:36
bool started() const
Definition: mos6526.h:94
TimerB timerB
Timers A and B.
Definition: mos6526.h:130