libsidplayfp 2.12.0
c64.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2023 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 <map>
30
31#include "Banks/IOBank.h"
32#include "Banks/ColorRAMBank.h"
33#include "Banks/DisconnectedBusBank.h"
34#include "Banks/SidBank.h"
35#include "Banks/ExtraSidBank.h"
36
37#include "EventScheduler.h"
38
39#include "c64/c64env.h"
40#include "c64/c64cpu.h"
41#include "c64/c64cia.h"
42#include "c64/c64vic.h"
43#include "c64/mmu.h"
44
45#include "sidcxx11.h"
46
47#ifdef HAVE_CONFIG_H
48# include "config.h"
49#endif
50
51namespace libsidplayfp
52{
53
54class c64sid;
55class sidmemory;
56
72class c64 final : private c64env
73{
74public:
75 using model_t = enum
76 {
77 PAL_B = 0
78 ,NTSC_M
79 ,OLD_NTSC_M
80 ,PAL_N
81 ,PAL_M
82 };
83
84 using cia_model_t = enum
85 {
86 OLD = 0
87 ,NEW
88 ,OLD_4485
89 };
90
91private:
92 using sidBankMap_t = std::map<int, ExtraSidBank*>;
93
94private:
96 double cpuFrequency;
97
99 int irqCount;
100
102 bool oldBAState;
103
105 EventScheduler eventScheduler;
106
108 c64cia1 cia1;
109
111 c64cia2 cia2;
112
114 c64vic vic;
115
117 ColorRAMBank colorRAMBank;
118
120 SidBank sidBank;
121
123 sidBankMap_t extraSidBanks;
124
126 DisconnectedBusBank disconnectedBusBank;
127
129 IOBank ioBank;
130
132 MMU mmu;
133
135 c64cpubus cpubus;
136
138 MOS6510 cpu;
139
140private:
141 static double getCpuFreq(model_t model);
142
143private:
151 inline void interruptIRQ(bool state) override;
152
158 inline void interruptNMI() override { cpu.triggerNMI(); }
159
163 inline void interruptRST() override { cpu.triggerRST(); }
164
172 inline void setBA(bool state) override;
173
177 inline void lightpen(bool state) override;
178
179 void resetIoBank();
180
181public:
182 c64();
183 ~c64();
184
190 EventScheduler *getEventScheduler() { return &eventScheduler; }
191
192 uint_least32_t getTimeMs() const
193 {
194 return static_cast<uint_least32_t>((eventScheduler.getTime(EVENT_CLOCK_PHI1) * 1000) / cpuFrequency);
195 }
196
202 void clock() { eventScheduler.clock(); }
203
204 void debug(bool enable, FILE *out) { cpu.debug(enable, out); }
205
206 void reset();
207 void resetCpu() { cpu.reset(); }
208
212 void setModel(model_t model);
213
217 void setCiaModel(cia_model_t model);
218
224 double getMainCpuSpeed() const { return cpuFrequency; }
225
231 void setBaseSid(c64sid *s);
232
242 bool addExtraSid(c64sid *s, int address);
243
247 void clearSids();
248
253 const char* cpuCredits() const { return cpu.credits(); }
254 const char* ciaCredits() const { return cia1.credits(); }
255 const char* vicCredits() const { return vic.credits(); }
257
258 sidmemory& getMemInterface() { return mmu; }
259
260 uint_least16_t getCia1TimerA() const { return cia1.getTimerA(); }
261};
262
263void c64::interruptIRQ(bool state)
264{
265 if (state)
266 {
267 if (irqCount == 0)
268 cpu.triggerIRQ();
269
270 irqCount ++;
271 }
272 else
273 {
274 irqCount --;
275 if (irqCount == 0)
276 cpu.clearIRQ();
277 }
278}
279
280void c64::setBA(bool state)
281{
282 // only react to changes in state
283 if (state == oldBAState)
284 return;
285
286 oldBAState = state;
287
288 // Signal changes in BA to interested parties
289 cpu.setRDY(state);
290}
291
292void c64::lightpen(bool state)
293{
294 if (!state)
295 vic.triggerLightpen();
296 else
297 vic.clearLightpen();
298}
299
300}
301
302#endif // C64_H
Definition ColorRAMBank.h:44
Definition DisconnectedBusBank.h:43
Definition EventScheduler.h:62
event_clock_t getTime(event_phase_t phase) const
Definition EventScheduler.h:158
Definition IOBank.h:40
Definition mmu.h:51
Definition mos6510.h:71
void reset()
Definition mos6510.cpp:2184
static const char * credits()
Definition mos652x.cpp:112
Definition SidBank.h:41
bool addExtraSid(c64sid *s, int address)
Definition c64.cpp:154
void setCiaModel(cia_model_t model)
Definition c64.cpp:143
const char * cpuCredits() const
Definition c64.h:253
void setBaseSid(c64sid *s)
Definition c64.cpp:149
double getMainCpuSpeed() const
Definition c64.h:224
void setModel(model_t model)
Definition c64.cpp:133
void clearSids()
Definition c64.cpp:193
void clock()
Definition c64.h:202
EventScheduler * getEventScheduler()
Definition c64.h:190
Definition c64cia.h:47
Definition c64cia.h:106
Definition c64cpu.h:69
Definition c64sid.h:40
Definition c64vic.h:45
Definition sidmemory.h:34