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 "NstBoardBmcSuperBig7in1.hpp"
28 
29 namespace Nes
30 {
31 	namespace Core
32 	{
33 		namespace Boards
34 		{
35 			namespace Bmc
36 			{
37 				#ifdef NST_MSVC_OPTIMIZE
38 				#pragma optimize("s", on)
39 				#endif
40 
SubReset(const bool hard)41 				void SuperBig7in1::SubReset(const bool hard)
42 				{
43 					if (hard)
44 						exReg = 0;
45 
46 					Mmc3::SubReset( hard );
47 
48 					for (uint i=0xA001; i < 0xC000; i += 0x2)
49 						Map( i, &SuperBig7in1::Poke_A001 );
50 				}
51 
SubLoad(State::Loader & state,const dword baseChunk)52 				void SuperBig7in1::SubLoad(State::Loader& state,const dword baseChunk)
53 				{
54 					if (baseChunk == AsciiId<'B','S','B'>::V)
55 					{
56 						while (const dword chunk = state.Begin())
57 						{
58 							if (chunk == AsciiId<'R','E','G'>::V)
59 							{
60 								exReg = state.Read8();
61 								exReg = NST_MIN(exReg & 7,6);
62 							}
63 
64 							state.End();
65 						}
66 					}
67 					else
68 					{
69 						Mmc3::SubLoad( state, baseChunk );
70 					}
71 				}
72 
SubSave(State::Saver & state) const73 				void SuperBig7in1::SubSave(State::Saver& state) const
74 				{
75 					Mmc3::SubSave( state );
76 					state.Begin( AsciiId<'B','S','B'>::V ).Begin( AsciiId<'R','E','G'>::V ).Write8( exReg ).End().End();
77 				}
78 
79 				#ifdef NST_MSVC_OPTIMIZE
80 				#pragma optimize("", on)
81 				#endif
82 
NES_POKE_D(SuperBig7in1,A001)83 				NES_POKE_D(SuperBig7in1,A001)
84 				{
85 					data &= 0x7;
86 
87 					if (exReg != data)
88 					{
89 						exReg = data;
90 						Mmc3::UpdatePrg();
91 						Mmc3::UpdateChr();
92 					}
93 				}
94 
UpdatePrg(uint address,uint bank)95 				void NST_FASTCALL SuperBig7in1::UpdatePrg(uint address,uint bank)
96 				{
97 					prg.SwapBank<SIZE_8K>( address, (exReg << 4) | (bank & (exReg >= 6 ? 0x1F : 0x0F)) );
98 				}
99 
UpdateChr(uint address,uint bank) const100 				void NST_FASTCALL SuperBig7in1::UpdateChr(uint address,uint bank) const
101 				{
102 					chr.SwapBank<SIZE_1K>( address, (exReg << 7) | (bank & (exReg >= 6 ? 0xFF : 0x7F)) );
103 				}
104 			}
105 		}
106 	}
107 }
108