libsidplayfp  1.1.0
c64.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 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 C64_H
24 #define C64_H
25 
26 #include "Banks/Bank.h"
27 #include "Banks/IOBank.h"
28 #include "Banks/ColorRAMBank.h"
29 #include "Banks/DisconnectedBusBank.h"
30 #include "Banks/SidBank.h"
31 #include "Banks/ExtraSidBank.h"
32 
33 #include "sidplayfp/c64/c64env.h"
34 #include "sidplayfp/c64/c64cpu.h"
35 #include "sidplayfp/c64/c64cia.h"
36 #include "sidplayfp/c64/c64vic.h"
37 #include "sidplayfp/c64/mmu.h"
38 
39 
40 #ifdef HAVE_CONFIG_H
41 # include "config.h"
42 #endif
43 
44 
45 #ifdef PC64_TESTSUITE
46 class testEnv
47 {
48 public:
49  virtual ~testEnv() {}
50  virtual void load(const char *) =0;
51 };
52 #endif
53 
65 class c64: private c64env
66 {
67 public:
69  static const unsigned int MAX_SIDS = 2;
70 
71 public:
72  typedef enum
73  {
74  PAL_B = 0
78  } model_t;
79 
80 private:
82  double m_cpuFreq;
83 
85  int irqCount;
86 
88  bool oldBAState;
89 
91  EventScheduler m_scheduler;
92 
94  c64cpu cpu;
95 
97  c64cia1 cia1;
98 
100  c64cia2 cia2;
101 
103  c64vic vic;
104 
106  ColorRAMBank colorRAMBank;
107 
109  SidBank sidBank;
110 
112  ExtraSidBank extraSidBank;
113 
115  DisconnectedBusBank disconnectedBusBank;
116 
118  IOBank ioBank;
119 
121  MMU mmu;
122 
123 private:
124  static double getCpuFreq(model_t model);
125 
126 private:
133  uint8_t cpuRead(uint_least16_t addr) { return mmu.cpuRead(addr); }
134 
141  void cpuWrite(uint_least16_t addr, uint8_t data) { mmu.cpuWrite(addr, data); }
142 
150  inline void interruptIRQ(bool state);
151 
157  inline void interruptNMI() { cpu.triggerNMI (); }
158 
162  inline void interruptRST() { cpu.triggerRST (); }
163 
171  inline void setBA(bool state);
172 
173  inline void lightpen() { vic.lightpen (); }
174 
175 #ifdef PC64_TESTSUITE
176  testEnv *m_env;
177 
178  void loadFile(const char *file)
179  {
180  m_env->load(file);
181  }
182 #endif
183 
184  void resetIoBank();
185 
186 public:
187  c64();
188  ~c64() {}
189 
190 #ifdef PC64_TESTSUITE
191  void setTestEnv(testEnv *env)
192  {
193  m_env = env;
194  }
195 #endif
196 
203  EventScheduler *getEventScheduler() { return &m_scheduler; }
204  const EventScheduler &getEventScheduler() const { return m_scheduler; }
206 
207  void debug(bool enable, FILE *out) { cpu.debug (enable, out); }
208 
209  void reset();
210  void resetCpu() { cpu.reset(); }
211 
215  void setModel(model_t model);
216 
217  void setRoms(const uint8_t* kernal, const uint8_t* basic, const uint8_t* character)
218  {
219  mmu.setRoms(kernal, basic, character);
220  }
221 
227  double getMainCpuSpeed() const { return m_cpuFreq; }
228 
235  void setSid(unsigned int i, sidemu *s);
236 
243  sidemu *getSid(unsigned int i) const;
244 
254  void setSecondSIDAddress(int sidChipBase2);
255 
260  const char* cpuCredits () const { return cpu.credits(); }
261  const char* ciaCredits () const { return cia1.credits(); }
262  const char* vicCredits () const { return vic.credits(); }
264 
265  sidmemory *getMemInterface() { return &mmu; }
266 
267  uint_least16_t getCia1TimerA() const { return cia1.getTimerA(); }
268 };
269 
270 void c64::interruptIRQ (bool state)
271 {
272  if (state)
273  {
274  if (irqCount == 0)
275  cpu.triggerIRQ ();
276 
277  irqCount ++;
278  }
279  else
280  {
281  irqCount --;
282  if (irqCount == 0)
283  cpu.clearIRQ ();
284  }
285 }
286 
287 void c64::setBA (bool state)
288 {
289  /* only react to changes in state */
290  if (state == oldBAState)
291  return;
292 
293  oldBAState = state;
294 
295  /* Signal changes in BA to interested parties */
296  cpu.setRDY (state);
297 }
298 
299 #endif // C64_H
const char * cpuCredits() const
Definition: c64.h:260
Definition: EventScheduler.h:57
Definition: SidBank.h:32
const char * vicCredits() const
Definition: c64.h:262
Definition: c64vic.h:38
Definition: c64cia.h:39
Definition: ColorRAMBank.h:35
void setRDY(bool newRDY)
Definition: mos6510.cpp:154
virtual void reset()
Definition: mos6510.cpp:2209
Definition: DisconnectedBusBank.h:33
const EventScheduler & getEventScheduler() const
Definition: c64.h:204
Definition: sidemu.h:45
double getMainCpuSpeed() const
Definition: c64.h:227
uint8_t cpuRead(uint_least16_t addr) const
Definition: mmu.h:120
Old NTSC C64.
Definition: c64.h:76
static const unsigned int MAX_SIDS
Definition: c64.h:69
Definition: c64env.h:37
model_t
Definition: c64.h:72
void cpuWrite(uint_least16_t addr, uint8_t data)
Definition: mmu.h:128
Definition: c64.h:65
void setSid(unsigned int i, sidemu *s)
Definition: c64.cpp:104
PAL C64.
Definition: c64.h:74
const char * ciaCredits() const
Definition: c64.h:261
sidemu * getSid(unsigned int i) const
Definition: c64.cpp:119
void setModel(model_t model)
Definition: c64.cpp:94
void triggerNMI()
Definition: mos6510.cpp:223
Definition: mmu.h:41
NTSC C64.
Definition: c64.h:75
void triggerIRQ()
Definition: mos6510.cpp:237
void clearIRQ()
Definition: mos6510.cpp:251
Definition: ExtraSidBank.h:30
Definition: c64cia.h:99
Definition: sidmemory.h:30
void triggerRST()
Definition: mos6510.cpp:209
void setSecondSIDAddress(int sidChipBase2)
Definition: c64.cpp:134
Definition: IOBank.h:35
const char * credits() const
Definition: mos6526.h:256
EventScheduler * getEventScheduler()
Definition: c64.h:203
C64 Drean.
Definition: c64.h:77
Definition: c64cpu.h:31