c64.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2023 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2007-2010 Antti Lankila
* Copyright 2000 Simon White
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef C64_H
#define C64_H
#include <stdint.h>
#include <cstdio>
#include <map>
#include "Banks/IOBank.h"
#include "Banks/ColorRAMBank.h"
#include "Banks/DisconnectedBusBank.h"
#include "Banks/SidBank.h"
#include "Banks/ExtraSidBank.h"
#include "EventScheduler.h"
#include "c64/c64env.h"
#include "c64/c64cpu.h"
#include "c64/c64cia.h"
#include "c64/c64vic.h"
#include "c64/mmu.h"
#include "sidcxx11.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
namespace libsidplayfp
{
class c64sid;
class sidmemory;
class c64 final : private c64env
{
public:
using model_t = enum
{
PAL_B = 0
,NTSC_M
,OLD_NTSC_M
,PAL_N
,PAL_M
};
using cia_model_t = enum
{
OLD = 0
,NEW
,OLD_4485
};
private:
using sidBankMap_t = std::map<int, ExtraSidBank*>;
private:
double cpuFrequency;
int irqCount;
bool oldBAState;
EventScheduler eventScheduler;
c64cia1 cia1;
c64cia2 cia2;
c64vic vic;
ColorRAMBank colorRAMBank;
SidBank sidBank;
sidBankMap_t extraSidBanks;
DisconnectedBusBank disconnectedBusBank;
IOBank ioBank;
MMU mmu;
c64cpubus cpubus;
MOS6510 cpu;
private:
static double getCpuFreq(model_t model);
private:
inline void interruptIRQ(bool state) override;
inline void interruptNMI() override { cpu.triggerNMI(); }
inline void interruptRST() override { cpu.triggerRST(); }
inline void setBA(bool state) override;
inline void lightpen(bool state) override;
void resetIoBank();
public:
c64();
~c64();
EventScheduler *getEventScheduler() { return &eventScheduler; }
uint_least32_t getTimeMs() const
{
return static_cast<uint_least32_t>((eventScheduler.getTime(EVENT_CLOCK_PHI1) * 1000) / cpuFrequency);
}
void clock() { eventScheduler.clock(); }
void debug(bool enable, FILE *out) { cpu.debug(enable, out); }
void reset();
void resetCpu() { cpu.reset(); }
void setModel(model_t model);
void setCiaModel(cia_model_t model);
double getMainCpuSpeed() const { return cpuFrequency; }
void setBaseSid(c64sid *s);
bool addExtraSid(c64sid *s, int address);
void clearSids();
const char* cpuCredits() const { return cpu.credits(); }
const char* ciaCredits() const { return cia1.credits(); }
const char* vicCredits() const { return vic.credits(); }
sidmemory& getMemInterface() { return mmu; }
uint_least16_t getCia1TimerA() const { return cia1.getTimerA(); }
};
void c64::interruptIRQ(bool state)
{
if (state)
{
if (irqCount == 0)
cpu.triggerIRQ();
irqCount ++;
}
else
{
irqCount --;
if (irqCount == 0)
cpu.clearIRQ();
}
}
void c64::setBA(bool state)
{
// only react to changes in state
if (state == oldBAState)
return;
oldBAState = state;
// Signal changes in BA to interested parties
cpu.setRDY(state);
}
void c64::lightpen(bool state)
{
if (!state)
vic.triggerLightpen();
else
vic.clearLightpen();
}
}
#endif // C64_H
libsidplayfp::ColorRAMBank
Definition ColorRAMBank.h:44
libsidplayfp::DisconnectedBusBank
Definition DisconnectedBusBank.h:43
libsidplayfp::EventScheduler
Definition EventScheduler.h:62
libsidplayfp::EventScheduler::getTime
event_clock_t getTime(event_phase_t phase) const
Definition EventScheduler.h:158
libsidplayfp::EventScheduler::clock
void clock()
Definition EventScheduler.h:136
libsidplayfp::IOBank
Definition IOBank.h:40
libsidplayfp::MMU
Definition mmu.h:51
libsidplayfp::MOS6510
Definition mos6510.h:71
libsidplayfp::MOS6510::setRDY
void setRDY(bool newRDY)
Definition mos6510.cpp:128
libsidplayfp::MOS6510::triggerNMI
void triggerNMI()
Definition mos6510.cpp:193
libsidplayfp::MOS6510::credits
static const char * credits()
Definition mos6510.cpp:2203
libsidplayfp::MOS6510::triggerRST
void triggerRST()
Definition mos6510.cpp:179
libsidplayfp::MOS6510::reset
void reset()
Definition mos6510.cpp:2184
libsidplayfp::MOS6510::triggerIRQ
void triggerIRQ()
Definition mos6510.cpp:209
libsidplayfp::MOS6510::clearIRQ
void clearIRQ()
Definition mos6510.cpp:225
libsidplayfp::MOS652X::credits
static const char * credits()
Definition mos652x.cpp:112
libsidplayfp::MOS656X::clearLightpen
void clearLightpen()
Definition mos656x.cpp:700
libsidplayfp::MOS656X::triggerLightpen
void triggerLightpen()
Definition mos656x.cpp:693
libsidplayfp::SidBank
Definition SidBank.h:41
libsidplayfp::c64
Definition c64.h:73
libsidplayfp::c64::addExtraSid
bool addExtraSid(c64sid *s, int address)
Definition c64.cpp:154
libsidplayfp::c64::setCiaModel
void setCiaModel(cia_model_t model)
Definition c64.cpp:143
libsidplayfp::c64::cpuCredits
const char * cpuCredits() const
Definition c64.h:253
libsidplayfp::c64::setBaseSid
void setBaseSid(c64sid *s)
Definition c64.cpp:149
libsidplayfp::c64::getMainCpuSpeed
double getMainCpuSpeed() const
Definition c64.h:224
libsidplayfp::c64::setModel
void setModel(model_t model)
Definition c64.cpp:133
libsidplayfp::c64::clearSids
void clearSids()
Definition c64.cpp:193
libsidplayfp::c64::clock
void clock()
Definition c64.h:202
libsidplayfp::c64::getEventScheduler
EventScheduler * getEventScheduler()
Definition c64.h:190
libsidplayfp::c64cia1
Definition c64cia.h:47
libsidplayfp::c64cia2
Definition c64cia.h:106
libsidplayfp::c64cpubus
Definition c64cpu.h:69
libsidplayfp::c64env
Definition c64env.h:41
libsidplayfp::c64sid
Definition c64sid.h:40
libsidplayfp::c64vic
Definition c64vic.h:45