libsidplayfp  1.2.2
c64cia.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 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 "sidplayfp/c64/c64env.h"
31 #include "sidplayfp/sidendian.h"
32 #include "CIA/mos6526.h"
33 
39 class c64cia1: public MOS6526, public Bank
40 {
41 private:
42  c64env &m_env;
43  uint_least16_t last_ta;
44  uint8_t lp;
45 
46 protected:
47  void interrupt(bool state)
48  {
49  m_env.interruptIRQ (state);
50  }
51 
52  void portB()
53  {
54  const uint8_t lp = (prb | ~ddrb) & 0x10;
55  if (lp != this->lp)
56  {
57  m_env.lightpen();
58  this->lp = lp;
59  }
60  }
61 
62 public:
63  c64cia1(c64env *env) :
64  MOS6526(&(env->context ())),
65  m_env(*env) {}
66 
67  void poke(uint_least16_t address, uint8_t value)
68  {
69  write(endian_16lo8(address), value);
70 
71  // Save the value written to Timer A
72  if (address == 0xDC04 || address == 0xDC05)
73  {
74  if (timerA.getTimer() != 0)
75  last_ta = timerA.getTimer();
76  }
77  }
78 
79  uint8_t peek(uint_least16_t address)
80  {
81  return read(endian_16lo8(address));
82  }
83 
84  void reset()
85  {
86  last_ta = 0;
87  lp = 0x10;
88  MOS6526::reset ();
89  }
90 
91  uint_least16_t getTimerA() const { return last_ta; }
92 };
93 
99 class c64cia2: public MOS6526, public Bank
100 {
101 private:
102  c64env &m_env;
103 
104 protected:
105  void interrupt(bool state)
106  {
107  if (state)
108  m_env.interruptNMI ();
109  }
110 
111 public:
112  c64cia2(c64env *env) :
113  MOS6526(&(env->context ())),
114  m_env(*env) {}
115 
116  void poke(uint_least16_t address, uint8_t value)
117  {
118  write(address, value);
119  }
120 
121  uint8_t peek(uint_least16_t address)
122  {
123  return read(address);
124  }
125 };
126 
127 #endif // C64CIA_H
void poke(uint_least16_t address, uint8_t value)
Definition: c64cia.h:116
Definition: c64cia.h:39
Definition: mos6526.h:102
void interrupt(bool state)
Definition: c64cia.h:47
TimerA timerA
Definition: mos6526.h:122
uint8_t peek(uint_least16_t address)
Definition: c64cia.h:121
Definition: c64env.h:37
uint8_t read(uint_least8_t addr)
Definition: mos6526.cpp:166
void reset()
Definition: c64cia.h:84
Definition: Bank.h:32
uint_least16_t getTimer() const
Definition: timer.h:223
void poke(uint_least16_t address, uint8_t value)
Definition: c64cia.h:67
void write(uint_least8_t addr, uint8_t data)
Definition: mos6526.cpp:240
virtual void reset()
Definition: mos6526.cpp:136
void interrupt(bool state)
Definition: c64cia.h:105
Definition: c64cia.h:99
uint8_t peek(uint_least16_t address)
Definition: c64cia.h:79