libsidplayfp  1.5.3
c64.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2014 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 <stdint.h>
27 #include <cstdio>
28 
29 #include "Banks/IOBank.h"
30 #include "Banks/ColorRAMBank.h"
31 #include "Banks/DisconnectedBusBank.h"
32 #include "Banks/SidBank.h"
33 #include "Banks/ExtraSidBank.h"
34 
35 #include "sidplayfp/EventScheduler.h"
36 
37 #include "sidplayfp/c64/c64env.h"
38 #include "sidplayfp/c64/c64cpu.h"
39 #include "sidplayfp/c64/c64cia.h"
40 #include "sidplayfp/c64/c64vic.h"
41 #include "sidplayfp/c64/mmu.h"
42 
43 #ifdef HAVE_CONFIG_H
44 # include "config.h"
45 #endif
46 
47 class c64sid;
48 class sidmemory;
49 
50 
51 #ifdef PC64_TESTSUITE
52 class testEnv
53 {
54 public:
55  virtual ~testEnv() {}
56  virtual void load(const char *) =0;
57 };
58 #endif
59 
75 class c64: private c64env
76 {
77 public:
79  static const unsigned int MAX_SIDS = 2;
80 
81 public:
82  typedef enum
83  {
84  PAL_B = 0
88  } model_t;
89 
90 private:
92  double m_cpuFreq;
93 
95  int irqCount;
96 
98  bool oldBAState;
99 
101  EventScheduler m_scheduler;
102 
104  c64cpu cpu;
105 
107  c64cia1 cia1;
108 
110  c64cia2 cia2;
111 
113  c64vic vic;
114 
116  ColorRAMBank colorRAMBank;
117 
119  SidBank sidBank;
120 
122  ExtraSidBank extraSidBank;
123 
125  DisconnectedBusBank disconnectedBusBank;
126 
128  IOBank ioBank;
129 
131  MMU mmu;
132 
133 private:
134  static double getCpuFreq(model_t model);
135 
136 private:
143  uint8_t cpuRead(uint_least16_t addr) { return mmu.cpuRead(addr); }
144 
151  void cpuWrite(uint_least16_t addr, uint8_t data) { mmu.cpuWrite(addr, data); }
152 
160  inline void interruptIRQ(bool state);
161 
167  inline void interruptNMI() { cpu.triggerNMI (); }
168 
172  inline void interruptRST() { cpu.triggerRST (); }
173 
181  inline void setBA(bool state);
182 
183  inline void lightpen() { vic.lightpen (); }
184 
185 #ifdef PC64_TESTSUITE
186  testEnv *m_env;
187 
188  void loadFile(const char *file)
189  {
190  m_env->load(file);
191  }
192 #endif
193 
194  void resetIoBank();
195 
196 public:
197  c64();
198  ~c64() {}
199 
200 #ifdef PC64_TESTSUITE
201  void setTestEnv(testEnv *env)
202  {
203  m_env = env;
204  }
205 #endif
206 
213  EventScheduler *getEventScheduler() { return &m_scheduler; }
214  const EventScheduler &getEventScheduler() const { return m_scheduler; }
216 
217  void debug(bool enable, FILE *out) { cpu.debug(enable, out); }
218 
219  void reset();
220  void resetCpu() { cpu.reset(); }
221 
225  void setModel(model_t model);
226 
227  void setRoms(const uint8_t* kernal, const uint8_t* basic, const uint8_t* character)
228  {
229  mmu.setRoms(kernal, basic, character);
230  }
231 
237  double getMainCpuSpeed() const { return m_cpuFreq; }
238 
245  void setSid(unsigned int i, c64sid *s);
246 
256  void setSecondSIDAddress(int sidChipBase2);
257 
262  const char* cpuCredits () const { return cpu.credits(); }
263  const char* ciaCredits () const { return cia1.credits(); }
264  const char* vicCredits () const { return vic.credits(); }
266 
267  sidmemory *getMemInterface() { return &mmu; }
268 
269  uint_least16_t getCia1TimerA() const { return cia1.getTimerA(); }
270 };
271 
272 void c64::interruptIRQ(bool state)
273 {
274  if (state)
275  {
276  if (irqCount == 0)
277  cpu.triggerIRQ ();
278 
279  irqCount ++;
280  }
281  else
282  {
283  irqCount --;
284  if (irqCount == 0)
285  cpu.clearIRQ ();
286  }
287 }
288 
289 void c64::setBA(bool state)
290 {
291  // only react to changes in state
292  if (state == oldBAState)
293  return;
294 
295  oldBAState = state;
296 
297  // Signal changes in BA to interested parties
298  cpu.setRDY (state);
299 }
300 
301 #endif // C64_H
const char * cpuCredits() const
Definition: c64.h:262
Definition: EventScheduler.h:55
Definition: SidBank.h:34
const char * vicCredits() const
Definition: c64.h:264
Definition: c64vic.h:38
void setSid(unsigned int i, c64sid *s)
Definition: c64.cpp:126
Definition: c64cia.h:39
Definition: ColorRAMBank.h:35
void setRDY(bool newRDY)
Definition: mos6510.cpp:156
virtual void reset()
Definition: mos6510.cpp:2215
Definition: DisconnectedBusBank.h:33
const EventScheduler & getEventScheduler() const
Definition: c64.h:214
double getMainCpuSpeed() const
Definition: c64.h:237
uint8_t cpuRead(uint_least16_t addr) const
Definition: mmu.h:122
Definition: c64sid.h:31
Old NTSC C64.
Definition: c64.h:86
static const unsigned int MAX_SIDS
Maximum number of supported SIDs (mono and stereo)
Definition: c64.h:79
Definition: c64env.h:37
model_t
Definition: c64.h:82
void cpuWrite(uint_least16_t addr, uint8_t data)
Definition: mmu.h:130
Definition: c64.h:75
PAL C64.
Definition: c64.h:84
const char * ciaCredits() const
Definition: c64.h:263
void setModel(model_t model)
Definition: c64.cpp:116
void triggerNMI()
Definition: mos6510.cpp:225
Definition: mmu.h:42
NTSC C64.
Definition: c64.h:85
void triggerIRQ()
Definition: mos6510.cpp:239
void clearIRQ()
Definition: mos6510.cpp:253
Definition: ExtraSidBank.h:32
Definition: c64cia.h:99
Definition: sidmemory.h:30
void triggerRST()
Definition: mos6510.cpp:211
void setSecondSIDAddress(int sidChipBase2)
Definition: c64.cpp:141
Definition: IOBank.h:35
const char * credits() const
Definition: mos6526.h:264
EventScheduler * getEventScheduler()
Definition: c64.h:213
C64 Drean.
Definition: c64.h:87
Definition: c64cpu.h:31