libsidplayfp
1.0.3
|
00001 /* 00002 * This file is part of libsidplayfp, a SID player engine. 00003 * 00004 * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net> 00005 * Copyright 2007-2010 Antti Lankila 00006 * Copyright 2001 Simon White 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef C64CIA_H 00024 #define C64CIA_H 00025 00026 // The CIA emulations are very generic and here we need to effectively 00027 // wire them into the computer (like adding a chip to a PCB). 00028 00029 #include "Banks/Bank.h" 00030 #include "sidplayfp/c64/c64env.h" 00031 #include "sidplayfp/sidendian.h" 00032 #include "CIA/mos6526.h" 00033 00039 class c64cia1: public MOS6526, public Bank 00040 { 00041 private: 00042 c64env &m_env; 00043 uint_least16_t last_ta; 00044 uint8_t lp; 00045 00046 protected: 00047 void interrupt(bool state) 00048 { 00049 m_env.interruptIRQ (state); 00050 } 00051 00052 void portB() 00053 { 00054 const uint8_t lp = (prb | ~ddrb) & 0x10; 00055 if (lp != this->lp) 00056 { 00057 m_env.lightpen(); 00058 this->lp = lp; 00059 } 00060 } 00061 00062 public: 00063 c64cia1(c64env *env) : 00064 MOS6526(&(env->context ())), 00065 m_env(*env) {} 00066 00067 void poke(uint_least16_t address, uint8_t value) 00068 { 00069 write(endian_16lo8(address), value); 00070 00071 // Save the value written to Timer A 00072 if (address == 0xDC04 || address == 0xDC05) 00073 { 00074 if (timerA.getTimer() != 0) 00075 last_ta = timerA.getTimer(); 00076 } 00077 } 00078 00079 uint8_t peek(uint_least16_t address) 00080 { 00081 return read(endian_16lo8(address)); 00082 } 00083 00084 const char *error() const { return ""; } 00085 00086 void reset() 00087 { 00088 last_ta = 0; 00089 lp = 0x10; 00090 MOS6526::reset (); 00091 } 00092 00093 uint_least16_t getTimerA() const { return last_ta; } 00094 }; 00095 00101 class c64cia2: public MOS6526, public Bank 00102 { 00103 private: 00104 c64env &m_env; 00105 00106 protected: 00107 void interrupt(bool state) 00108 { 00109 if (state) 00110 m_env.interruptNMI (); 00111 } 00112 00113 public: 00114 c64cia2(c64env *env) : 00115 MOS6526(&(env->context ())), 00116 m_env(*env) {} 00117 00118 void poke(uint_least16_t address, uint8_t value) 00119 { 00120 write(address, value); 00121 } 00122 00123 uint8_t peek(uint_least16_t address) 00124 { 00125 return read(address); 00126 } 00127 00128 const char *error() const { return ""; } 00129 }; 00130 00131 #endif // C64CIA_H