1 //////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // Nestopia - NES/Famicom emulator written in C++ 4 // 5 // Copyright (C) 2003-2008 Martin Freij 6 // 7 // This file is part of Nestopia. 8 // 9 // Nestopia is free software; you can redistribute it and/or modify 10 // it under the terms of the GNU General Public License as published by 11 // the Free Software Foundation; either version 2 of the License, or 12 // (at your option) any later version. 13 // 14 // Nestopia is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // You should have received a copy of the GNU General Public License 20 // along with Nestopia; if not, write to the Free Software 21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 // 23 //////////////////////////////////////////////////////////////////////////////////////// 24 25 #ifndef NST_BOARD_KONAMI_VRC4_H 26 #define NST_BOARD_KONAMI_VRC4_H 27 28 #ifdef NST_PRAGMA_ONCE 29 #pragma once 30 #endif 31 32 namespace Nes 33 { 34 namespace Core 35 { 36 namespace Boards 37 { 38 namespace Konami 39 { 40 class Vrc4 : public Board 41 { 42 public: 43 44 explicit Vrc4(const Context&); 45 46 protected: 47 48 void SubReset(bool); 49 50 private: 51 52 struct BaseIrq 53 { 54 void Reset(bool); 55 bool Clock(); 56 57 enum 58 { 59 ENABLE_0 = 0x2, 60 ENABLE_1 = 0x1, 61 NO_PPU_SYNC = 0x4, 62 CTRL = 0x1U|0x2U|0x4U 63 }; 64 65 uint ctrl; 66 uint count[2]; 67 uint latch; 68 }; 69 70 public: 71 72 struct Irq : Timer::M2<BaseIrq> 73 { 74 void WriteLatch0(uint); 75 void WriteLatch1(uint); 76 void Toggle(uint); 77 void Toggle(); 78 void LoadState(State::Loader&); 79 void SaveState(State::Saver&,dword) const; 80 IrqNes::Core::Boards::Konami::Vrc4::Irq81 explicit Irq(Cpu& c) 82 : Timer::M2<BaseIrq>(c) {} 83 }; 84 85 private: 86 87 static uint GetPrgLineShift(const Context&,uint,uint); 88 89 void SubSave(State::Saver&) const; 90 void SubLoad(State::Loader&,dword); 91 void Sync(Event,Input::Controllers*); 92 93 template<uint OFFSET> 94 void SwapChr(uint,uint) const; 95 96 NES_DECL_PEEK( 6000 ); 97 NES_DECL_POKE( 6000 ); 98 NES_DECL_POKE( 8000 ); 99 NES_DECL_POKE( 9000 ); 100 NES_DECL_POKE( B000 ); 101 NES_DECL_POKE( B001 ); 102 NES_DECL_POKE( B002 ); 103 NES_DECL_POKE( B003 ); 104 NES_DECL_POKE( C000 ); 105 NES_DECL_POKE( C001 ); 106 NES_DECL_POKE( C002 ); 107 NES_DECL_POKE( C003 ); 108 NES_DECL_POKE( D000 ); 109 NES_DECL_POKE( D001 ); 110 NES_DECL_POKE( D002 ); 111 NES_DECL_POKE( D003 ); 112 NES_DECL_POKE( E000 ); 113 NES_DECL_POKE( E001 ); 114 NES_DECL_POKE( E002 ); 115 NES_DECL_POKE( E003 ); 116 NES_DECL_POKE( F000 ); 117 NES_DECL_POKE( F001 ); 118 NES_DECL_POKE( F002 ); 119 NES_DECL_POKE( F003 ); 120 121 Irq irq; 122 const uint prgLineA; 123 const uint prgLineB; 124 125 protected: 126 127 uint prgSwap; 128 }; 129 } 130 } 131 } 132 } 133 134 #endif 135