File: NstBoardOpenCorp.cpp

package info (click to toggle)
libretro-nestopia 1.52.0%2B20230102.gitcb1e24e-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,960 kB
  • sloc: cpp: 107,513; xml: 27,221; python: 1,329; ansic: 772; makefile: 634
file content (183 lines) | stat: -rw-r--r-- 4,677 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
////////////////////////////////////////////////////////////////////////////////////////
//
// Nestopia - NES/Famicom emulator written in C++
//
// Copyright (C) 2003-2008 Martin Freij
//
// This file is part of Nestopia.
//
// Nestopia is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Nestopia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Nestopia; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
////////////////////////////////////////////////////////////////////////////////////////

// Reference: https://github.com/TASVideos/fceux/blob/master/src/boards/156.cpp

#include "NstBoard.hpp"
#include "NstBoardOpenCorp.hpp"

namespace Nes
{
	namespace Core
	{
		namespace Boards
		{
			namespace OpenCorp
			{
				#ifdef NST_MSVC_OPTIMIZE
				#pragma optimize("s", on)
				#endif

				void Daou306::RemapChr()
				{
					chr.SwapBank<SIZE_1K>( 0x0000, (chrHigh[0] << 8) | chrLow[0] );
					chr.SwapBank<SIZE_1K>( 0x0400, (chrHigh[1] << 8) | chrLow[1] );
					chr.SwapBank<SIZE_1K>( 0x0800, (chrHigh[2] << 8) | chrLow[2] );
					chr.SwapBank<SIZE_1K>( 0x0C00, (chrHigh[3] << 8) | chrLow[3] );
					chr.SwapBank<SIZE_1K>( 0x1000, (chrHigh[4] << 8) | chrLow[4] );
					chr.SwapBank<SIZE_1K>( 0x1400, (chrHigh[5] << 8) | chrLow[5] );
					chr.SwapBank<SIZE_1K>( 0x1800, (chrHigh[6] << 8) | chrLow[6] );
					chr.SwapBank<SIZE_1K>( 0x1C00, (chrHigh[7] << 8) | chrLow[7] );

					if (mirrorUsed) {
						ppu.SetMirroring( mirror ^ 0x1 ? Ppu::NMT_V : Ppu::NMT_H );
					}
					else
					{
						ppu.SetMirroring( Ppu::NMT_0 );
					}
				}

				void Daou306::SubReset(bool)
				{
					for (uint i = 0; i < 8; i++)
					{
						chrLow[i] = chrHigh[i] = 0;
					}

					Map( 0xC000U, 0xC00FU, &Daou306::Poke_C000 );
					Map( 0xC010U, PRG_SWAP_16K_0 );
					Map( 0xC014U, &Daou306::Poke_C014 );
				}

				NES_POKE_AD(Daou306,C000)
				{
					switch (address)
					{
						case 0xC000:
						case 0xC001:
						case 0xC002:
						case 0xC003:
							chrLow[address & 0x03] = data;
							break;
						case 0xC004:
						case 0xC005:
						case 0xC006:
						case 0xC007:
							chrHigh[address & 0x03] = data;
							break;
						case 0xC008:
						case 0xC009:
						case 0xC00A:
						case 0xC00B:
							chrLow[4 + (address & 0x03)] = data;
							break;
						case 0xC00C:
						case 0xC00D:
						case 0xC00E:
						case 0xC00F:
							chrHigh[4 + (address & 0x03)] = data;
							break;
					}
					RemapChr();
				}

				NES_POKE_D(Daou306,C014)
				{
					mirror = data;
					mirrorUsed = 1;
				}

				void Daou306::SubLoad(State::Loader& state,const dword baseChunk)
				{
					NST_VERIFY( baseChunk == (AsciiId<'O','P','C'>::V) );

					if (baseChunk == AsciiId<'O','P','C'>::V)
					{
						state.Begin();

						State::Loader::Data<18> data( state );
						chrLow[0] = data[0];
						chrLow[1] = data[1];
						chrLow[2] = data[2];
						chrLow[3] = data[3];
						chrLow[4] = data[4];
						chrLow[5] = data[5];
						chrLow[6] = data[6];
						chrLow[7] = data[7];
						chrHigh[0] = data[8];
						chrHigh[1] = data[9];
						chrHigh[2] = data[10];
						chrHigh[3] = data[11];
						chrHigh[4] = data[12];
						chrHigh[5] = data[13];
						chrHigh[6] = data[14];
						chrHigh[7] = data[15];
						mirror = data[16];
						mirrorUsed = data[17];

						state.End();

						RemapChr();
					}
				}

				void Daou306::SubSave(State::Saver& state) const
				{
					state.Begin( AsciiId<'O','P','C'>::V );

					const byte data[18] =
						{
							chrLow[0],
							chrLow[1],
							chrLow[2],
							chrLow[3],
							chrLow[4],
							chrLow[5],
							chrLow[6],
							chrLow[7],
							chrHigh[0],
							chrHigh[1],
							chrHigh[2],
							chrHigh[3],
							chrHigh[4],
							chrHigh[5],
							chrHigh[6],
							chrHigh[7],
							mirror,
							mirrorUsed,
						};

					state.Begin( AsciiId<'C','H','R'>::V ).Write( data ).End();

					state.End();
				}

				#ifdef NST_MSVC_OPTIMIZE
				#pragma optimize("", on)
				#endif
			}
		}
	}
}