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 "NstBoardBmcSuper40in1.hpp"
27 
28 namespace Nes
29 {
30 	namespace Core
31 	{
32 		namespace Boards
33 		{
34 			namespace Bmc
35 			{
36 				#ifdef NST_MSVC_OPTIMIZE
37 				#pragma optimize("s", on)
38 				#endif
39 
SubReset(const bool hard)40 				void Super40in1::SubReset(const bool hard)
41 				{
42 					reg = 0x00;
43 
44 					for (uint i=0x6000; i < 0x7000; i += 0x2)
45 					{
46 						Map( i + 0x0, &Super40in1::Poke_6000 );
47 						Map( i + 0x1, &Super40in1::Poke_6001 );
48 					}
49 
50 					if (hard)
51 						NES_DO_POKE(6000,0x6000,0x00);
52 				}
53 
SubLoad(State::Loader & state,const dword baseChunk)54 				void Super40in1::SubLoad(State::Loader& state,const dword baseChunk)
55 				{
56 					NST_VERIFY( baseChunk == (AsciiId<'B','S','4'>::V) );
57 
58 					if (baseChunk == AsciiId<'B','S','4'>::V)
59 					{
60 						while (const dword chunk = state.Begin())
61 						{
62 							if (chunk == AsciiId<'R','E','G'>::V)
63 								reg = state.Read8() & 0x20;
64 
65 							state.End();
66 						}
67 					}
68 				}
69 
SubSave(State::Saver & state) const70 				void Super40in1::SubSave(State::Saver& state) const
71 				{
72 					state.Begin( AsciiId<'B','S','4'>::V ).Begin( AsciiId<'R','E','G'>::V ).Write8( reg ).End().End();
73 				}
74 
75 				#ifdef NST_MSVC_OPTIMIZE
76 				#pragma optimize("", on)
77 				#endif
78 
79 				NES_POKE_D(Super40in1,6000)
80 				{
81 					if (!reg)
82 					{
83 						reg = data & 0x20;
84 						prg.SwapBanks<SIZE_16K,0x0000>( data & ~(~data >> 3 & 0x1), data | (~data >> 3 & 0x1) );
85 						ppu.SetMirroring( (data & 0x10) ? Ppu::NMT_H : Ppu::NMT_V );
86 					}
87 				}
88 
89 				NES_POKE_D(Super40in1,6001)
90 				{
91 					if (!reg)
92 					{
93 						ppu.Update();
94 						chr.SwapBank<SIZE_8K,0x0000>( data );
95 					}
96 				}
97 			}
98 		}
99 	}
100 }
101