c64.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2013 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 "Banks/IOBank.h"
#include "Banks/ColorRAMBank.h"
#include "Banks/DisconnectedBusBank.h"
#include "Banks/SidBank.h"
#include "Banks/ExtraSidBank.h"
#include "sidplayfp/EventScheduler.h"
#include "sidplayfp/c64/c64env.h"
#include "sidplayfp/c64/c64cpu.h"
#include "sidplayfp/c64/c64cia.h"
#include "sidplayfp/c64/c64vic.h"
#include "sidplayfp/c64/mmu.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
class c64sid;
class sidmemory;
#ifdef PC64_TESTSUITE
class testEnv
{
public:
virtual ~testEnv() {}
virtual void load(const char *) =0;
};
#endif
class c64: private c64env
{
public:
static const unsigned int MAX_SIDS = 2;
public:
typedef enum
{
PAL_B = 0
,NTSC_M
,OLD_NTSC_M
,PAL_N
} model_t;
private:
double m_cpuFreq;
int irqCount;
bool oldBAState;
EventScheduler m_scheduler;
c64cpu cpu;
c64cia1 cia1;
c64cia2 cia2;
c64vic vic;
ColorRAMBank colorRAMBank;
SidBank sidBank;
ExtraSidBank extraSidBank;
DisconnectedBusBank disconnectedBusBank;
IOBank ioBank;
MMU mmu;
private:
static double getCpuFreq(model_t model);
private:
uint8_t cpuRead(uint_least16_t addr) { return mmu.cpuRead(addr); }
void cpuWrite(uint_least16_t addr, uint8_t data) { mmu.cpuWrite(addr, data); }
inline void interruptIRQ(bool state);
inline void interruptNMI() { cpu.triggerNMI (); }
inline void interruptRST() { cpu.triggerRST (); }
inline void setBA(bool state);
inline void lightpen() { vic.lightpen (); }
#ifdef PC64_TESTSUITE
testEnv *m_env;
void loadFile(const char *file)
{
m_env->load(file);
}
#endif
void resetIoBank();
public:
c64();
~c64() {}
#ifdef PC64_TESTSUITE
void setTestEnv(testEnv *env)
{
m_env = env;
}
#endif
EventScheduler *getEventScheduler() { return &m_scheduler; }
const EventScheduler &getEventScheduler() const { return m_scheduler; }
void debug(bool enable, FILE *out) { cpu.debug(enable, out); }
void reset();
void resetCpu() { cpu.reset(); }
void setModel(model_t model);
void setRoms(const uint8_t* kernal, const uint8_t* basic, const uint8_t* character)
{
mmu.setRoms(kernal, basic, character);
}
double getMainCpuSpeed() const { return m_cpuFreq; }
void setSid(unsigned int i, c64sid *s);
void setSecondSIDAddress(int sidChipBase2);
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);
}
#endif // C64_H
c64::cpuCredits
const char * cpuCredits() const
Definition: c64.h:258
EventScheduler
Definition: EventScheduler.h:55
SidBank
Definition: SidBank.h:34
c64::vicCredits
const char * vicCredits() const
Definition: c64.h:260
c64vic
Definition: c64vic.h:38
c64::setSid
void setSid(unsigned int i, c64sid *s)
Definition: c64.cpp:121
c64cia1
Definition: c64cia.h:39
ColorRAMBank
Definition: ColorRAMBank.h:35
MOS6510::setRDY
void setRDY(bool newRDY)
Definition: mos6510.cpp:156
MOS6510::reset
virtual void reset()
Definition: mos6510.cpp:2215
DisconnectedBusBank
Definition: DisconnectedBusBank.h:33
c64::getEventScheduler
const EventScheduler & getEventScheduler() const
Definition: c64.h:210
c64::getMainCpuSpeed
double getMainCpuSpeed() const
Definition: c64.h:233
MMU::cpuRead
uint8_t cpuRead(uint_least16_t addr) const
Definition: mmu.h:121
c64sid
Definition: c64sid.h:31
c64::OLD_NTSC_M
Old NTSC C64.
Definition: c64.h:82
c64::MAX_SIDS
static const unsigned int MAX_SIDS
Definition: c64.h:75
c64env
Definition: c64env.h:37
c64::model_t
model_t
Definition: c64.h:78
MMU::cpuWrite
void cpuWrite(uint_least16_t addr, uint8_t data)
Definition: mmu.h:129
c64
Definition: c64.h:71
c64::PAL_B
PAL C64.
Definition: c64.h:80
c64::ciaCredits
const char * ciaCredits() const
Definition: c64.h:259
c64::setModel
void setModel(model_t model)
Definition: c64.cpp:111
MOS6510::triggerNMI
void triggerNMI()
Definition: mos6510.cpp:225
MMU
Definition: mmu.h:42
c64::NTSC_M
NTSC C64.
Definition: c64.h:81
MOS6510::triggerIRQ
void triggerIRQ()
Definition: mos6510.cpp:239
MOS6510::clearIRQ
void clearIRQ()
Definition: mos6510.cpp:253
ExtraSidBank
Definition: ExtraSidBank.h:32
c64cia2
Definition: c64cia.h:99
sidmemory
Definition: sidmemory.h:30
MOS6510::triggerRST
void triggerRST()
Definition: mos6510.cpp:211
c64::setSecondSIDAddress
void setSecondSIDAddress(int sidChipBase2)
Definition: c64.cpp:136
IOBank
Definition: IOBank.h:35
MOS6526::credits
const char * credits() const
Definition: mos6526.h:260
c64::getEventScheduler
EventScheduler * getEventScheduler()
Definition: c64.h:209
c64::PAL_N
C64 Drean.
Definition: c64.h:83
c64cpu
Definition: c64cpu.h:31