mos6526.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 MOS6526_H
#define MOS6526_H
#include <stdint.h>
#include "timer.h"
#include "sidplayfp/EventScheduler.h"
#include "sidplayfp/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;
private:
static const char *credit;
protected:
uint8_t regs[0x10];
// Ports
uint8_t &pra, &prb, &ddra, &ddrb;
TimerA timerA;
TimerB timerB;
// Serial Data Registers
uint8_t sdr_out;
bool sdr_buffered;
int sdr_count;
uint8_t icr;
uint8_t idr;
EventContext &event_context;
// TOD
bool m_todlatched;
bool m_todstopped;
uint8_t m_todclock[4], m_todalarm[4], m_todlatch[4];
event_clock_t m_todCycles, m_todPeriod;
bool triggerScheduled;
// Events
EventCallback<MOS6526> bTickEvent;
EventCallback<MOS6526> todEvent;
EventCallback<MOS6526> triggerEvent;
protected:
MOS6526(EventContext *context);
~MOS6526() {}
void bTick();
void tod();
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:
// TOD implementation taken from Vice
static uint8_t byte2bcd(uint8_t byte) { return (((byte / 10) << 4) + (byte % 10)) & 0xff; }
static uint8_t bcd2byte(uint8_t bcd) { return ((10*((bcd & 0xf0) >> 4)) + (bcd & 0xf)) & 0xff; }
public:
virtual void reset();
const char *credits() const { return credit; }
void setDayOfTimeRate(unsigned int clock);
};
#endif // MOS6526_H
MOS6526::bTick
void bTick()
Definition: mos6526.cpp:360
MOS6526::regs
uint8_t regs[0x10]
Definition: mos6526.h:114
TimerB
Definition: mos6526.h:65
MOS6526
Definition: mos6526.h:102
MOS6526::idr
uint8_t idr
Definition: mos6526.h:134
TimerB::TimerB
TimerB(EventContext *context, MOS6526 *parent)
Definition: mos6526.h:74
MOS6526::timerA
TimerA timerA
Definition: mos6526.h:122
TimerA
Definition: mos6526.h:41
TimerB::started
bool started() const
Definition: mos6526.h:93
TimerB::cascade
void cascade()
Definition: mos6526.h:80
MOS6526::read
uint8_t read(uint_least8_t addr)
Definition: mos6526.cpp:166
EventContext
Definition: event.h:101
MOS6526::trigger
void trigger()
Definition: mos6526.cpp:339
EventCallback< MOS6526 >
MOS6526::clear
void clear()
Definition: mos6526.cpp:123
Timer::parent
MOS6526 *const parent
Definition: timer.h:100
MOS6526::underflowA
void underflowA()
Definition: mos6526.cpp:365
component
Definition: component.h:28
MOS6526::triggerScheduled
bool triggerScheduled
Definition: mos6526.h:148
MOS6526::serialPort
void serialPort()
Definition: mos6526.cpp:102
Timer::state
int_least32_t state
Definition: timer.h:105
MOS6526::underflowB
void underflowB()
Definition: mos6526.cpp:377
MOS6526::write
void write(uint_least8_t addr, uint8_t data)
Definition: mos6526.cpp:240
MOS6526::icr
uint8_t icr
Definition: mos6526.h:131
MOS6526::MOS6526
MOS6526(EventContext *context)
Definition: mos6526.cpp:85
MOS6526::tod
void tod()
Definition: mos6526.cpp:382
MOS6526::reset
virtual void reset()
Definition: mos6526.cpp:136
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:55
MOS6526::event_context
EventContext & event_context
Definition: mos6526.h:139
Timer
Definition: timer.h:38
MOS6526::setDayOfTimeRate
void setDayOfTimeRate(unsigned int clock)
Definition: mos6526.cpp:131
MOS6526::credits
const char * credits() const
Definition: mos6526.h:260