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 "NstBoardTxc.hpp"
27 
28 namespace Nes
29 {
30 	namespace Core
31 	{
32 		namespace Boards
33 		{
34 			namespace Txc
35 			{
36 				#ifdef NST_MSVC_OPTIMIZE
37 				#pragma optimize("s", on)
38 				#endif
39 
SubReset(const bool hard)40 				void T22211A::SubReset(const bool hard)
41 				{
42 					Map( 0x4100U,          &T22211A::Peek_4100 );
43 					Map( 0x4100U, 0x4103U, &T22211A::Poke_4100 );
44 					Map( 0x8000U, 0xFFFFU, &T22211A::Poke_8000 );
45 
46 					if (hard)
47 					{
48 						for (uint i=0; i < 4; ++i)
49 							regs[i] = 0;
50 
51 						prg.SwapBank<SIZE_32K,0x0000>(0);
52 					}
53 				}
54 
SubReset(const bool hard)55 				void T22211B::SubReset(const bool hard)
56 				{
57 					T22211A::SubReset( hard );
58 
59 					Map( 0x8000U, 0xFFFFU, &T22211B::Poke_8000 );
60 				}
61 
SubReset(const bool hard)62 				void T22211C::SubReset(const bool hard)
63 				{
64 					T22211A::SubReset( hard );
65 
66 					Map( 0x4100U, &T22211C::Peek_4100 );
67 				}
68 
SubLoad(State::Loader & state,const dword baseChunk)69 				void T22211A::SubLoad(State::Loader& state,const dword baseChunk)
70 				{
71 					NST_VERIFY( baseChunk == (AsciiId<'T','2','1'>::V) );
72 
73 					if (baseChunk == AsciiId<'T','2','1'>::V)
74 					{
75 						while (const dword chunk = state.Begin())
76 						{
77 							if (chunk == AsciiId<'R','E','G'>::V)
78 								state.Read( regs );
79 
80 							state.End();
81 						}
82 					}
83 				}
84 
SubSave(State::Saver & state) const85 				void T22211A::SubSave(State::Saver& state) const
86 				{
87 					state.Begin( AsciiId<'T','2','1'>::V ).Begin( AsciiId<'R','E','G'>::V ).Write( regs ).End().End();
88 				}
89 
90 				#ifdef NST_MSVC_OPTIMIZE
91 				#pragma optimize("", on)
92 				#endif
93 
94 				NES_PEEK(T22211A,4100)
95 				{
96 					return (uint(regs[1]) ^ regs[2]) | 0x40;
97 				}
98 
99 				NES_PEEK(T22211C,4100)
100 				{
101 					return (uint(regs[1]) ^ regs[2]) | 0x41;
102 				}
103 
104 				NES_POKE_AD(T22211A,4100)
105 				{
106 					regs[address & 0x3] = data;
107 				}
108 
109 				NES_POKE(T22211A,8000)
110 				{
111 					ppu.Update();
112 					prg.SwapBank<SIZE_32K,0x0000>( regs[2] >> 2 );
113 					chr.SwapBank<SIZE_8K,0x0000>( regs[2] );
114 				}
115 
116 				NES_POKE_D(T22211B,8000)
117 				{
118 					ppu.Update();
119 					prg.SwapBank<SIZE_32K,0x0000>( regs[2] >> 2 );
120 					chr.SwapBank<SIZE_8K,0x0000>( ((data^regs[2]) >> 3 & 0x2) | ((data^regs[2]) >> 5 & 0x1) );
121 				}
122 			}
123 		}
124 	}
125 }
126