1 ////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // Nestopia - NES/Famicom emulator written in C++
4 //
5 // Copyright (C) 2003-2008 Martin Freij
6 // Copyright (C) 2021 Rupert Carmichael
7 //
8 // This file is part of Nestopia.
9 //
10 // Nestopia is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
14 //
15 // Nestopia is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Nestopia; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 //
24 ////////////////////////////////////////////////////////////////////////////////////////
25 
26 #include "NstBoard.hpp"
27 #include "NstBoardNamcot340.hpp"
28 
29 namespace Nes
30 {
31 	namespace Core
32 	{
33 		namespace Boards
34 		{
35 			namespace Namcot
36 			{
37 				#ifdef NST_MSVC_OPTIMIZE
38 				#pragma optimize("s", on)
39 				#endif
40 
N340(const Context & c)41 				N340::N340(const Context& c)
42 				:
43 				Board (c)
44 				{
45 				}
46 
SubReset(const bool hard)47 				void N340::SubReset(const bool hard)
48 				{
49 					Map( 0x8000U, 0x87FFU, CHR_SWAP_1K_0 );
50 					Map( 0x8800U, 0x8FFFU, CHR_SWAP_1K_1 );
51 					Map( 0x9000U, 0x97FFU, CHR_SWAP_1K_2 );
52 					Map( 0x9800U, 0x9FFFU, CHR_SWAP_1K_3 );
53 					Map( 0xA000U, 0xA7FFU, CHR_SWAP_1K_4 );
54 					Map( 0xA800U, 0xAFFFU, CHR_SWAP_1K_5 );
55 					Map( 0xB000U, 0xB7FFU, CHR_SWAP_1K_6 );
56 					Map( 0xB800U, 0xBFFFU, CHR_SWAP_1K_7 );
57 					Map( 0xE000U, 0xE7FFU, &N340::Poke_E000 );
58 					Map( 0xE800U, 0xEFFFU, PRG_SWAP_8K_1 );
59 					Map( 0xF000U, 0xF7FFU, PRG_SWAP_8K_2 );
60 				}
61 
62 				#ifdef NST_MSVC_OPTIMIZE
63 				#pragma optimize("", on)
64 				#endif
65 
NES_POKE_D(N340,E000)66 				NES_POKE_D(N340,E000)
67 				{
68 					prg.SwapBank<SIZE_8K>( 0, data & 0x3FU );
69 
70 					switch ((data >> 6) & 0x3U)
71 					{
72 						case 0x0U: // One-screen A
73 							ppu.SetMirroring( Ppu::NMT_0 );
74 							break;
75 						case 0x1U: // Vertical
76 							ppu.SetMirroring( Ppu::NMT_V );
77 							break;
78 						case 0x2U: // One-screen B
79 							ppu.SetMirroring( Ppu::NMT_1 );
80 							break;
81 						case 0x3U: // Horizontal
82 							ppu.SetMirroring( Ppu::NMT_H );
83 							break;
84 					}
85 				}
86 			}
87 		}
88 	}
89 }
90