c64cia.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 2001 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 C64CIA_H
#define C64CIA_H
// The CIA emulations are very generic and here we need to effectively
// wire them into the computer (like adding a chip to a PCB).
#include "Banks/Bank.h"
#include "c64/c64env.h"
#include "sidendian.h"
#include "CIA/mos6526.h"
class c64cia1: public MOS6526, public Bank
{
private:
c64env &m_env;
uint_least16_t last_ta;
protected:
void interrupt(bool state)
{
m_env.interruptIRQ (state);
}
void portB()
{
m_env.lightpen((prb | ~ddrb) & 0x10);
}
public:
c64cia1(c64env *env) :
MOS6526(&(env->context ())),
m_env(*env) {}
void poke(uint_least16_t address, uint8_t value)
{
write(endian_16lo8(address), value);
// Save the value written to Timer A
if (address == 0xDC04 || address == 0xDC05)
{
if (timerA.getTimer() != 0)
last_ta = timerA.getTimer();
}
}
uint8_t peek(uint_least16_t address)
{
return read(endian_16lo8(address));
}
void reset()
{
last_ta = 0;
MOS6526::reset ();
}
uint_least16_t getTimerA() const { return last_ta; }
};
class c64cia2: public MOS6526, public Bank
{
private:
c64env &m_env;
protected:
void interrupt(bool state)
{
if (state)
m_env.interruptNMI ();
}
public:
c64cia2(c64env *env) :
MOS6526(&(env->context ())),
m_env(*env) {}
void poke(uint_least16_t address, uint8_t value)
{
write(address, value);
}
uint8_t peek(uint_least16_t address)
{
return read(address);
}
};
#endif // C64CIA_H
c64cia2::poke
void poke(uint_least16_t address, uint8_t value)
Definition: c64cia.h:113
MOS6526::ddrb
uint8_t & ddrb
Ports.
Definition: mos6526.h:118
c64cia1
Definition: c64cia.h:41
MOS6526
Definition: mos6526.h:103
c64cia1::interrupt
void interrupt(bool state)
Definition: c64cia.h:48
MOS6526::timerA
TimerA timerA
Timers A and B.
Definition: mos6526.h:123
c64cia2::peek
uint8_t peek(uint_least16_t address)
Definition: c64cia.h:118
c64env
Definition: c64env.h:37
MOS6526::read
uint8_t read(uint_least8_t addr)
Definition: mos6526.cpp:154
c64cia1::reset
void reset()
Definition: c64cia.h:80
Bank
Definition: Bank.h:32
Timer::getTimer
uint_least16_t getTimer() const
Definition: timer.h:208
c64cia1::poke
void poke(uint_least16_t address, uint8_t value)
Definition: c64cia.h:63
MOS6526::prb
uint8_t & prb
Ports.
Definition: mos6526.h:118
MOS6526::write
void write(uint_least8_t addr, uint8_t data)
Definition: mos6526.cpp:216
MOS6526::MOS6526
MOS6526(EventContext *context)
Definition: mos6526.cpp:86
MOS6526::reset
virtual void reset()
Definition: mos6526.cpp:131
c64cia2::interrupt
void interrupt(bool state)
Definition: c64cia.h:102
c64cia2
Definition: c64cia.h:96
c64cia1::peek
uint8_t peek(uint_least16_t address)
Definition: c64cia.h:75