mos6526.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2014 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 MOS6526_H
#define MOS6526_H
#include <stdint.h>
#include "timer.h"
#include "tod.h"
#include "EventScheduler.h"
#include "c64/component.h"
class EventContext;
class MOS6526;
class TimerA : public Timer
{
private:
void underFlow();
void serialPort();
public:
TimerA(EventContext *context, MOS6526* parent) :
Timer("CIA Timer A", context, parent) {}
};
class TimerB : public Timer
{
private:
void underFlow();
public:
TimerB(EventContext *context, MOS6526* parent) :
Timer("CIA Timer B", context, parent) {}
void cascade()
{
/* we pretend that we are CPU doing a write to ctrl register */
syncWithCpu();
state |= CIAT_STEP;
wakeUpAfterSyncWithCpu();
}
bool started() const { return (state & CIAT_CR_START) != 0; }
};
class MOS6526: public component
{
friend class TimerA;
friend class TimerB;
friend class Tod;
private:
static const char *credit;
protected:
uint8_t regs[0x10];
uint8_t &pra, &prb, &ddra, &ddrb;
TimerA timerA;
TimerB timerB;
uint8_t sdr_out;
bool sdr_buffered;
int sdr_count;
uint8_t icr;
uint8_t idr;
EventContext &event_context;
Tod tod;
bool triggerScheduled;
EventCallback<MOS6526> bTickEvent;
EventCallback<MOS6526> triggerEvent;
protected:
MOS6526(EventContext *context);
~MOS6526() {}
void bTick();
void trigger();
void underflowA();
void underflowB();
void trigger(uint8_t interruptMask);
void clear();
void serialPort();
virtual void interrupt(bool state) = 0;
virtual void portA() {}
virtual void portB() {}
uint8_t read(uint_least8_t addr);
void write(uint_least8_t addr, uint8_t data);
private:
void todInterrupt();
public:
virtual void reset();
static const char *credits() { return credit; }
void setDayOfTimeRate(unsigned int clock) { tod.setPeriod(clock); }
};
#endif // MOS6526_H
MOS6526::bTick
void bTick()
Definition: mos6526.cpp:312
MOS6526::regs
uint8_t regs[0x10]
These are all CIA registers.
Definition: mos6526.h:114
MOS6526::ddrb
uint8_t & ddrb
Ports.
Definition: mos6526.h:118
TimerB
Definition: mos6526.h:66
MOS6526
Definition: mos6526.h:103
MOS6526::idr
uint8_t idr
Interrupt data register.
Definition: mos6526.h:138
TimerB::TimerB
TimerB(EventContext *context, MOS6526 *parent)
Definition: mos6526.h:75
MOS6526::timerA
TimerA timerA
Timers A and B.
Definition: mos6526.h:123
MOS6526::sdr_count
int sdr_count
Serial Data Registers.
Definition: mos6526.h:131
MOS6526::sdr_out
uint8_t sdr_out
Serial Data Registers.
Definition: mos6526.h:129
TimerA
Definition: mos6526.h:42
TimerB::started
bool started() const
Definition: mos6526.h:94
TimerB::cascade
void cascade()
Definition: mos6526.h:81
MOS6526::read
uint8_t read(uint_least8_t addr)
Definition: mos6526.cpp:154
EventContext
Definition: event.h:107
MOS6526::trigger
void trigger()
Definition: mos6526.cpp:291
Tod::setPeriod
void setPeriod(event_clock_t clock)
Definition: tod.h:109
MOS6526::credits
static const char * credits()
Definition: mos6526.h:252
MOS6526::bTickEvent
EventCallback< MOS6526 > bTickEvent
Events.
Definition: mos6526.h:151
EventCallback< MOS6526 >
MOS6526::clear
void clear()
Definition: mos6526.cpp:123
Timer::parent
MOS6526 *const parent
Pointer to the MOS6526 which this Timer belongs to.
Definition: timer.h:88
MOS6526::ddra
uint8_t & ddra
Ports.
Definition: mos6526.h:118
MOS6526::underflowA
void underflowA()
Definition: mos6526.cpp:317
MOS6526::triggerEvent
EventCallback< MOS6526 > triggerEvent
Events.
Definition: mos6526.h:152
MOS6526::tod
Tod tod
TOD.
Definition: mos6526.h:144
component
Definition: component.h:28
MOS6526::triggerScheduled
bool triggerScheduled
Have we already scheduled CIA->CPU interrupt transition?
Definition: mos6526.h:147
MOS6526::serialPort
void serialPort()
Definition: mos6526.cpp:102
Timer::state
int_least32_t state
CRA/CRB control register / state.
Definition: timer.h:91
MOS6526::underflowB
void underflowB()
Definition: mos6526.cpp:329
MOS6526::prb
uint8_t & prb
Ports.
Definition: mos6526.h:118
MOS6526::sdr_buffered
bool sdr_buffered
Serial Data Registers.
Definition: mos6526.h:130
MOS6526::write
void write(uint_least8_t addr, uint8_t data)
Definition: mos6526.cpp:216
MOS6526::icr
uint8_t icr
Interrupt control register.
Definition: mos6526.h:135
MOS6526::MOS6526
MOS6526(EventContext *context)
Definition: mos6526.cpp:86
MOS6526::reset
virtual void reset()
Definition: mos6526.cpp:131
MOS6526::interrupt
virtual void interrupt(bool state)=0
Timer::syncWithCpu
void syncWithCpu()
Definition: timer.cpp:34
Timer::wakeUpAfterSyncWithCpu
void wakeUpAfterSyncWithCpu()
Definition: timer.cpp:57
TimerA::TimerA
TimerA(EventContext *context, MOS6526 *parent)
Definition: mos6526.h:56
MOS6526::event_context
EventContext & event_context
Event context.
Definition: mos6526.h:141
MOS6526::pra
uint8_t & pra
Ports.
Definition: mos6526.h:118
Timer
Definition: timer.h:38
MOS6526::setDayOfTimeRate
void setDayOfTimeRate(unsigned int clock)
Definition: mos6526.h:259
Tod
Definition: tod.h:36
MOS6526::timerB
TimerB timerB
Timers A and B.
Definition: mos6526.h:124