libsidplayfp  2.0.5
c64cia.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2020 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2001 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 C64CIA_H
24 #define C64CIA_H
25 
26 // The CIA emulations are very generic and here we need to effectively
27 // wire them into the computer (like adding a chip to a PCB).
28 
29 #include "Banks/Bank.h"
30 #include "c64/c64env.h"
31 #include "sidendian.h"
32 #include "CIA/mos6526.h"
33 
34 #include "sidcxx11.h"
35 
36 namespace libsidplayfp
37 {
38 
46 class c64cia1 final : public MOS6526, public Bank
47 {
48 private:
49  c64env &m_env;
50  uint_least16_t last_ta;
51 
52 protected:
53  void interrupt(bool state) override
54  {
55  m_env.interruptIRQ(state);
56  }
57 
58  void portB() override
59  {
60  const uint8_t pb = prb | ~ddrb;
61  // We should call adjustDataPort here
62  // but we're only interested in bit 4
63  m_env.lightpen(pb & 0x10);
64  }
65 
66 public:
67  c64cia1(c64env &env) :
68  MOS6526(env.scheduler()),
69  m_env(env) {}
70 
71  void poke(uint_least16_t address, uint8_t value) override
72  {
73  const uint8_t addr = endian_16lo8(address);
74  write(addr, value);
75 
76  // Save the value written to Timer A
77  if ((addr == 0x04) || (addr == 0x05))
78  {
79  if (timerA.getTimer() != 0)
80  last_ta = timerA.getTimer();
81  }
82  }
83 
84  uint8_t peek(uint_least16_t address) override
85  {
86  return read(endian_16lo8(address));
87  }
88 
89  void reset() override
90  {
91  last_ta = 0;
93  }
94 
95  uint_least16_t getTimerA() const { return last_ta; }
96 };
97 
105 class c64cia2 : public MOS6526, public Bank
106 {
107 private:
108  c64env &m_env;
109 
110 protected:
111  void interrupt(bool state) override
112  {
113  if (state)
114  m_env.interruptNMI();
115  }
116 
117 public:
118  c64cia2(c64env &env) :
119  MOS6526(env.scheduler()),
120  m_env(env) {}
121 
122  void poke(uint_least16_t address, uint8_t value) override
123  {
124  write(endian_16lo8(address), value);
125  }
126 
127  uint8_t peek(uint_least16_t address) override
128  {
129  return read(endian_16lo8(address));
130  }
131 };
132 
133 }
134 
135 #endif // C64CIA_H
libsidplayfp::MOS6526::write
void write(uint_least8_t addr, uint8_t data)
Definition: mos6526.cpp:269
libsidplayfp::MOS6526::read
uint8_t read(uint_least8_t addr)
Definition: mos6526.cpp:230
libsidplayfp::c64cia2
Definition: c64cia.h:106
libsidplayfp::Bank
Definition: Bank.h:36
libsidplayfp::MOS6526
Definition: mos6526.h:153
libsidplayfp::MOS6526::timerA
TimerA timerA
Timers A and B.
Definition: mos6526.h:177
libsidplayfp::c64cia2::poke
void poke(uint_least16_t address, uint8_t value) override
Definition: c64cia.h:122
libsidplayfp::c64cia1::poke
void poke(uint_least16_t address, uint8_t value) override
Definition: c64cia.h:71
libsidplayfp::Timer::getTimer
uint_least16_t getTimer() const
Definition: timer.h:212
libsidplayfp::c64cia1::peek
uint8_t peek(uint_least16_t address) override
Definition: c64cia.h:84
libsidplayfp::c64cia2::peek
uint8_t peek(uint_least16_t address) override
Definition: c64cia.h:127
libsidplayfp::c64cia2::interrupt
void interrupt(bool state) override
Definition: c64cia.h:111
libsidplayfp::c64cia1::interrupt
void interrupt(bool state) override
Definition: c64cia.h:53
libsidplayfp::MOS6526::reset
virtual void reset()
Definition: mos6526.cpp:194
libsidplayfp::c64env
Definition: c64env.h:41
libsidplayfp::c64cia1
Definition: c64cia.h:47
libsidplayfp::MOS6526::MOS6526
MOS6526(EventScheduler &scheduler)
Definition: mos6526.cpp:170
libsidplayfp::c64cia1::reset
void reset() override
Definition: c64cia.h:89