libsidplayfp 2.15.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
143 static void deleteSids(sidBankMap_t &extraSidBanks);
144
145private:
153 inline void interruptIRQ(bool state) override;
154
160 inline void interruptNMI() override { cpu.triggerNMI(); }
161
165 inline void interruptRST() override { cpu.triggerRST(); }
166
174 inline void setBA(bool state) override;
175
179 inline void lightpen(bool state) override;
180
181 void resetIoBank();
182
183public:
184 c64();
185 ~c64();
186
192 EventScheduler *getEventScheduler() { return &eventScheduler; }
193
194 uint_least32_t getTimeMs() const
195 {
196 return static_cast<uint_least32_t>((eventScheduler.getTime(EVENT_CLOCK_PHI1) * 1000) / cpuFrequency);
197 }
198
204 void clock() { eventScheduler.clock(); }
205
206 void debug(bool enable, FILE *out) { cpu.debug(enable, out); }
207
208 void reset();
209 void resetCpu() { cpu.reset(); }
210
214 void setModel(model_t model);
215
219 void setCiaModel(cia_model_t model);
220
226 double getMainCpuSpeed() const { return cpuFrequency; }
227
233 void setBaseSid(c64sid *s);
234
244 bool addExtraSid(c64sid *s, int address);
245
249 void clearSids();
250
255 const char* cpuCredits() const { return cpu.credits(); }
256 const char* ciaCredits() const { return cia1.credits(); }
257 const char* vicCredits() const { return vic.credits(); }
259
260 sidmemory& getMemInterface() { return mmu; }
261
262 uint_least16_t getCia1TimerA() const { return cia1.getTimerA(); }
263
264 unsigned int installedSIDs() const;
265};
266
267void c64::interruptIRQ(bool state)
268{
269 if (state)
270 {
271 if (irqCount == 0)
272 cpu.triggerIRQ();
273
274 irqCount ++;
275 }
276 else
277 {
278 irqCount --;
279 if (irqCount == 0)
280 cpu.clearIRQ();
281 }
282}
283
284void c64::setBA(bool state)
285{
286 // only react to changes in state
287 if (state == oldBAState)
288 return;
289
290 oldBAState = state;
291
292 // Signal changes in BA to interested parties
293 cpu.setRDY(state);
294}
295
296void c64::lightpen(bool state)
297{
298 if (!state)
299 vic.triggerLightpen();
300 else
301 vic.clearLightpen();
302}
303
304}
305
306#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
void clock()
Definition EventScheduler.h:136
Definition IOBank.h:40
Definition mmu.h:51
Definition mos6510.h:71
void setRDY(bool newRDY)
Definition mos6510.cpp:128
void triggerNMI()
Definition mos6510.cpp:193
static const char * credits()
Definition mos6510.cpp:2203
void triggerRST()
Definition mos6510.cpp:179
void reset()
Definition mos6510.cpp:2184
void triggerIRQ()
Definition mos6510.cpp:209
void clearIRQ()
Definition mos6510.cpp:225
static const char * credits()
Definition mos652x.cpp:112
void clearLightpen()
Definition mos656x.cpp:700
void triggerLightpen()
Definition mos656x.cpp:693
Definition SidBank.h:41
Definition c64.h:73
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:255
void setBaseSid(c64sid *s)
Definition c64.cpp:149
double getMainCpuSpeed() const
Definition c64.h:226
void setModel(model_t model)
Definition c64.cpp:133
void clearSids()
Definition c64.cpp:206
void clock()
Definition c64.h:204
EventScheduler * getEventScheduler()
Definition c64.h:192
Definition c64cia.h:47
Definition c64cia.h:106
Definition c64cpu.h:69
Definition c64env.h:41
Definition c64sid.h:40
Definition c64vic.h:45