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 "NstBoardAveD1012.hpp" 27 28 namespace Nes 29 { 30 namespace Core 31 { 32 namespace Boards 33 { 34 namespace Ave 35 { 36 #ifdef NST_MSVC_OPTIMIZE 37 #pragma optimize("s", on) 38 #endif 39 SubReset(const bool hard)40 void D1012::SubReset(const bool hard) 41 { 42 Map( 0xFF80U, 0xFF9FU, &D1012::Peek_FF80, &D1012::Poke_FF80 ); 43 Map( 0xFFE8U, 0xFFF7U, &D1012::Peek_FFE8, &D1012::Poke_FFE8 ); 44 45 if (hard) 46 { 47 regs[0] = 0; 48 regs[1] = 0; 49 50 Update(); 51 } 52 } 53 SubLoad(State::Loader & state,const dword baseChunk)54 void D1012::SubLoad(State::Loader& state,const dword baseChunk) 55 { 56 if (baseChunk == AsciiId<'A','D','1'>::V) 57 { 58 while (const dword chunk = state.Begin()) 59 { 60 if (chunk == AsciiId<'R','E','G'>::V) 61 { 62 State::Loader::Data<2> data( state ); 63 64 regs[0] = data[0]; 65 regs[1] = data[1]; 66 } 67 68 state.End(); 69 } 70 } 71 } 72 SubSave(State::Saver & state) const73 void D1012::SubSave(State::Saver& state) const 74 { 75 state.Begin( AsciiId<'A','D','1'>::V ).Begin( AsciiId<'R','E','G'>::V ).Write16( regs[0] | uint(regs[1]) << 8 ).End().End(); 76 } 77 78 #ifdef NST_MSVC_OPTIMIZE 79 #pragma optimize("", on) 80 #endif 81 Update()82 void D1012::Update() 83 { 84 prg.SwapBank<SIZE_32K,0x0000>( (regs[0] & 0xE) | (regs[regs[0] >> 6 & 0x1] & 0x1) ); 85 chr.SwapBank<SIZE_8K,0x0000>( (regs[0] << 2 & ((regs[0] >> 4 & 0x4) ^ 0x3C)) | (regs[1] >> 4 & ((regs[0] >> 4 & 0x4) | 0x3)) ); 86 } 87 NES_POKE_D(D1012,FF80)88 NES_POKE_D(D1012,FF80) 89 { 90 if (!(regs[0] & 0x3F)) 91 { 92 regs[0] = data; 93 ppu.SetMirroring( (data & 0x80) ? Ppu::NMT_H : Ppu::NMT_V ); 94 Update(); 95 } 96 } 97 NES_PEEK_A(D1012,FF80)98 NES_PEEK_A(D1012,FF80) 99 { 100 const uint data = prg[3][address - 0xE000]; 101 NES_DO_POKE(FF80,address,data); 102 return data; 103 } 104 NES_POKE_D(D1012,FFE8)105 NES_POKE_D(D1012,FFE8) 106 { 107 regs[1] = data; 108 ppu.Update(); 109 Update(); 110 } 111 NES_PEEK_A(D1012,FFE8)112 NES_PEEK_A(D1012,FFE8) 113 { 114 const uint data = prg[3][address - 0xE000]; 115 NES_DO_POKE(FFE8,address,data); 116 return data; 117 } 118 } 119 } 120 } 121 } 122