libsidplayfp  1.0.3
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  const char *error() const { return ""; }
85 
86  void reset()
87  {
88  last_ta = 0;
89  lp = 0x10;
90  MOS6526::reset ();
91  }
92 
93  uint_least16_t getTimerA() const { return last_ta; }
94 };
95 
101 class c64cia2: public MOS6526, public Bank
102 {
103 private:
104  c64env &m_env;
105 
106 protected:
107  void interrupt(bool state)
108  {
109  if (state)
110  m_env.interruptNMI ();
111  }
112 
113 public:
114  c64cia2(c64env *env) :
115  MOS6526(&(env->context ())),
116  m_env(*env) {}
117 
118  void poke(uint_least16_t address, uint8_t value)
119  {
120  write(address, value);
121  }
122 
123  uint8_t peek(uint_least16_t address)
124  {
125  return read(address);
126  }
127 
128  const char *error() const { return ""; }
129 };
130 
131 #endif // C64CIA_H