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 #include "NstBoard.hpp" 26 #include "NstBoardMmc3.hpp" 27 #include "NstBoardGouder.hpp" 28 29 namespace Nes 30 { 31 namespace Core 32 { 33 namespace Boards 34 { 35 namespace Gouder 36 { 37 #ifdef NST_MSVC_OPTIMIZE 38 #pragma optimize("s", on) 39 #endif 40 SubReset(const bool hard)41 void G37017::SubReset(const bool hard) 42 { 43 if (hard) 44 { 45 regs.select = 0; 46 47 for (uint i=0; i < 4; ++i) 48 regs.buffer[i] = 0; 49 } 50 51 Mmc3::SubReset( hard ); 52 53 Map( 0x4800U, 0x4FFFU, &G37017::Poke_4800 ); 54 Map( 0x5000U, 0x57FFU, &G37017::Poke_5000 ); 55 Map( 0x5800U, 0x5FFFU, &G37017::Peek_5800, &G37017::Poke_5800 ); 56 } 57 SubLoad(State::Loader & state,const dword baseChunk)58 void G37017::SubLoad(State::Loader& state,const dword baseChunk) 59 { 60 if (baseChunk == AsciiId<'G','D','R'>::V) 61 { 62 while (const dword chunk = state.Begin()) 63 { 64 if (chunk == AsciiId<'R','E','G'>::V) 65 { 66 state.Read( regs.buffer ); 67 regs.select = state.Read8(); 68 } 69 70 state.End(); 71 } 72 } 73 } 74 SubSave(State::Saver & state) const75 void G37017::SubSave(State::Saver& state) const 76 { 77 state.Begin( AsciiId<'G','D','R'>::V ).Begin( AsciiId<'R','E','G'>::V ).Write( regs.buffer ).Write8( regs.select ).End().End(); 78 } 79 80 #ifdef NST_MSVC_OPTIMIZE 81 #pragma optimize("", on) 82 #endif 83 UpdatePrg(uint,uint)84 void NST_FASTCALL G37017::UpdatePrg(uint,uint) 85 { 86 // controlled by $4800..$4FFF 87 } 88 89 NES_POKE_D(G37017,4800) 90 { 91 prg.SwapBank<SIZE_32K,0x0000>( (data & 0x1) | (data >> 3 & 0x2) ); 92 } 93 94 NES_POKE_D(G37017,5000) 95 { 96 regs.select = data; 97 } 98 99 NES_POKE_AD(G37017,5800) 100 { 101 static const byte lut[256] = 102 { 103 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x49,0x19,0x09,0x59,0x49,0x19,0x09, 104 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x51,0x41,0x11,0x01,0x51,0x41,0x11,0x01, 105 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x49,0x19,0x09,0x59,0x49,0x19,0x09, 106 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x51,0x41,0x11,0x01,0x51,0x41,0x11,0x01, 107 0x00,0x10,0x40,0x50,0x00,0x10,0x40,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 108 0x08,0x18,0x48,0x58,0x08,0x18,0x48,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 109 0x00,0x10,0x40,0x50,0x00,0x10,0x40,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 110 0x08,0x18,0x48,0x58,0x08,0x18,0x48,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 111 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x58,0x48,0x18,0x08,0x58,0x48,0x18,0x08, 112 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x50,0x40,0x10,0x00,0x50,0x40,0x10,0x00, 113 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x58,0x48,0x18,0x08,0x58,0x48,0x18,0x08, 114 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x50,0x40,0x10,0x00,0x50,0x40,0x10,0x00, 115 0x01,0x11,0x41,0x51,0x01,0x11,0x41,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 116 0x09,0x19,0x49,0x59,0x09,0x19,0x49,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 117 0x01,0x11,0x41,0x51,0x01,0x11,0x41,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 118 0x09,0x19,0x49,0x59,0x09,0x19,0x49,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 119 }; 120 121 regs.buffer[address & 0x3] = data ^ lut[regs.select]; 122 } 123 124 NES_PEEK_A(G37017,5800) 125 { 126 return regs.buffer[address & 0x3]; 127 } 128 } 129 } 130 } 131 } 132