libsidplayfp 1.8.8
c64cia.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2011-2014 Leandro Nini <drfiemost@users.sourceforge.net>
5 * Copyright 2007-2010 Antti Lankila
6 * Copyright 2001 Simon White
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22
23#ifndef C64CIA_H
24#define C64CIA_H
25
26// The CIA emulations are very generic and here we need to effectively
27// wire them into the computer (like adding a chip to a PCB).
28
29#include "Banks/Bank.h"
30#include "c64/c64env.h"
31#include "sidendian.h"
32#include "CIA/mos6526.h"
33
41class c64cia1: public MOS6526, public Bank
42{
43private:
44 c64env &m_env;
45 uint_least16_t last_ta;
46
47protected:
48 void interrupt(bool state)
49 {
50 m_env.interruptIRQ (state);
51 }
52
53 void portB()
54 {
55 m_env.lightpen((prb | ~ddrb) & 0x10);
56 }
57
58public:
59 c64cia1(c64env *env) :
60 MOS6526(&(env->context ())),
61 m_env(*env) {}
62
63 void poke(uint_least16_t address, uint8_t value)
64 {
65 write(endian_16lo8(address), value);
66
67 // Save the value written to Timer A
68 if (address == 0xDC04 || address == 0xDC05)
69 {
70 if (timerA.getTimer() != 0)
71 last_ta = timerA.getTimer();
72 }
73 }
74
75 uint8_t peek(uint_least16_t address)
76 {
77 return read(endian_16lo8(address));
78 }
79
80 void reset()
81 {
82 last_ta = 0;
84 }
85
86 uint_least16_t getTimerA() const { return last_ta; }
87};
88
96class c64cia2: public MOS6526, public Bank
97{
98private:
99 c64env &m_env;
100
101protected:
102 void interrupt(bool state)
103 {
104 if (state)
105 m_env.interruptNMI ();
106 }
107
108public:
109 c64cia2(c64env *env) :
110 MOS6526(&(env->context ())),
111 m_env(*env) {}
112
113 void poke(uint_least16_t address, uint8_t value)
114 {
115 write(address, value);
116 }
117
118 uint8_t peek(uint_least16_t address)
119 {
120 return read(address);
121 }
122};
123
124#endif // C64CIA_H
Definition: Bank.h:33
Definition: mos6526.h:104
uint8_t read(uint_least8_t addr)
Definition: mos6526.cpp:158
virtual void reset()
Definition: mos6526.cpp:134
void write(uint_least8_t addr, uint8_t data)
Definition: mos6526.cpp:229
TimerA timerA
Timers A and B.
Definition: mos6526.h:129
uint_least16_t getTimer() const
Definition: timer.h:208
Definition: c64cia.h:42
void poke(uint_least16_t address, uint8_t value)
Definition: c64cia.h:63
void reset()
Definition: c64cia.h:80
uint8_t peek(uint_least16_t address)
Definition: c64cia.h:75
void interrupt(bool state)
Definition: c64cia.h:48
Definition: c64cia.h:97
uint8_t peek(uint_least16_t address)
Definition: c64cia.h:118
void interrupt(bool state)
Definition: c64cia.h:102
void poke(uint_least16_t address, uint8_t value)
Definition: c64cia.h:113
Definition: c64env.h:38