libsidplayfp  0.3.5
c64cia.h
1 /***************************************************************************
2  c64cia.h - C64 CIAs
3  -------------------
4  begin : Fri Apr 4 2001
5  copyright : (C) 2001 by Simon White
6  email : s_a_white@email.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef _c64cia_h_
19 #define _c64cia_h_
20 
21 // The CIA emulations are very generic and here we need to effectively
22 // wire them into the computer (like adding a chip to a PCB).
23 
24 #include "sidplayfp/c64env.h"
25 #include "../mos6526/mos6526.h"
26 
27 /* CIA 1 specifics:
28  Generates IRQs
29 */
30 class c64cia1: public MOS6526
31 {
32 private:
33  c64env &m_env;
34  uint8_t lp;
35 
36 protected:
37  void interrupt (bool state)
38  {
39  m_env.interruptIRQ (state);
40  }
41 
42  void portB ()
43  {
44  const uint8_t lp = (prb | ~ddrb) & 0x10;
45  if (lp != this->lp)
46  {
47  m_env.lightpen();
48  this->lp = lp;
49  }
50  }
51 
52 public:
53  c64cia1 (c64env *env)
54  :MOS6526(&(env->context ())),
55  m_env(*env) {}
56  const char *error (void) {return "";}
57 
58  void reset ()
59  {
60  lp = 0x10;
61  MOS6526::reset ();
62  }
63 };
64 
65 /* CIA 2 specifics:
66  Generates NMIs
67 */
68 class c64cia2: public MOS6526
69 {
70 private:
71  c64env &m_env;
72 
73 protected:
74  void interrupt (bool state)
75  {
76  if (state)
77  m_env.interruptNMI ();
78  }
79 
80 public:
81  c64cia2 (c64env *env)
82  :MOS6526(&(env->context ())),
83  m_env(*env) {}
84  const char *error (void) {return "";}
85 };
86 
87 #endif // _c64cia_h_