File: NstNsf.hpp

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 (355 lines) | stat: -rw-r--r-- 7,304 bytes parent folder | download | duplicates (6)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
////////////////////////////////////////////////////////////////////////////////////////
//
// 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
//
////////////////////////////////////////////////////////////////////////////////////////

#ifndef NST_NSF_H
#define NST_NSF_H

#include "NstImage.hpp"

#ifdef NST_PRAGMA_ONCE
#pragma once
#endif

namespace Nes
{
	namespace Core
	{
		class Nsf : public Image
		{
		public:

			explicit Nsf(Context&);

			void BeginFrame();
			uint GetChips() const;

			Result SelectSong(uint);
			Result PlaySong();
			Result StopSong();

		private:

			~Nsf();

			void Reset(bool);
			bool PowerOff();
			void InitSong();
			Region GetDesiredRegion() const;
			System GetDesiredSystem(Region,CpuModel*,PpuModel*) const;

			inline uint FetchLast(uint) const;

			typedef Memory<SIZE_32K,SIZE_4K> Prg;

			enum
			{
				JAM = 0x02,
				JMP = 0x4C,
				JSR = 0x20,
				SEI = 0x78,
				LDA = 0xA9,
				LDX = 0xA2,
				TXS = 0x9A
			};

			NES_DECL_PEEK( 38EC );
			NES_DECL_PEEK( 38ED );
			NES_DECL_PEEK( 38EE );
			NES_DECL_PEEK( 38EF );
			NES_DECL_PEEK( 38F0 );
			NES_DECL_PEEK( 38F1 );
			NES_DECL_PEEK( 38F2 );
			NES_DECL_PEEK( 38F3 );
			NES_DECL_PEEK( 38F4 );
			NES_DECL_PEEK( 38F5 );
			NES_DECL_PEEK( 38F6 );
			NES_DECL_PEEK( 38F7 );
			NES_DECL_PEEK( 38F8 );
			NES_DECL_PEEK( 38F9 );
			NES_DECL_PEEK( 38FA );
			NES_DECL_PEEK( 38FB );
			NES_DECL_PEEK( 38FC );
			NES_DECL_PEEK( 38FD );
			NES_DECL_PEEK( 38FE );
			NES_DECL_PEEK( 38FF );

			NES_DECL_POKE( 4017 );

			NES_DECL_POKE( 5FF8 );
			NES_DECL_POKE( 5FF9 );
			NES_DECL_POKE( 5FFA );
			NES_DECL_POKE( 5FFB );
			NES_DECL_POKE( 5FFC );
			NES_DECL_POKE( 5FFD );
			NES_DECL_POKE( 5FFE );
			NES_DECL_POKE( 5FFF );

			NES_DECL_PEEK( Prg_8 );
			NES_DECL_PEEK( Prg_9 );
			NES_DECL_PEEK( Prg_A );
			NES_DECL_PEEK( Prg_B );
			NES_DECL_PEEK( Prg_C );
			NES_DECL_PEEK( Prg_D );
			NES_DECL_PEEK( Prg_E );
			NES_DECL_PEEK( Prg_F );

			NES_DECL_PEEK( Wrk );
			NES_DECL_POKE( Wrk );

			NES_DECL_PEEK( Fds_4040 );
			NES_DECL_POKE( Fds_4040 );
			NES_DECL_POKE( Fds_4080 );
			NES_DECL_POKE( Fds_4082 );
			NES_DECL_POKE( Fds_4083 );
			NES_DECL_POKE( Fds_4084 );
			NES_DECL_POKE( Fds_4085 );
			NES_DECL_POKE( Fds_4086 );
			NES_DECL_POKE( Fds_4087 );
			NES_DECL_POKE( Fds_4088 );
			NES_DECL_POKE( Fds_4089 );
			NES_DECL_POKE( Fds_408A );
			NES_DECL_PEEK( Fds_4090 );
			NES_DECL_PEEK( Fds_4092 );
			NES_DECL_POKE( Fds_5FF6 );
			NES_DECL_POKE( Fds_5FF7 );
			NES_DECL_POKE( Fds_5FF8 );
			NES_DECL_POKE( Fds_5FF9 );
			NES_DECL_POKE( Fds_5FFA );
			NES_DECL_POKE( Fds_5FFB );
			NES_DECL_POKE( Fds_5FFC );
			NES_DECL_POKE( Fds_5FFD );
			NES_DECL_POKE( Fds_5FFE );
			NES_DECL_POKE( Fds_5FFF );
			NES_DECL_PEEK( Fds_Ram  );
			NES_DECL_POKE( Fds_Ram  );

			NES_DECL_POKE( Mmc5_5000 );
			NES_DECL_POKE( Mmc5_5002 );
			NES_DECL_POKE( Mmc5_5003 );
			NES_DECL_POKE( Mmc5_5004 );
			NES_DECL_POKE( Mmc5_5006 );
			NES_DECL_POKE( Mmc5_5007 );
			NES_DECL_POKE( Mmc5_5010 );
			NES_DECL_POKE( Mmc5_5011 );
			NES_DECL_POKE( Mmc5_5015 );
			NES_DECL_PEEK( Mmc5_5015 );
			NES_DECL_PEEK( Mmc5_5205 );
			NES_DECL_PEEK( Mmc5_5206 );
			NES_DECL_POKE( Mmc5_5205 );
			NES_DECL_POKE( Mmc5_5206 );
			NES_DECL_PEEK( Mmc5_5C00 );
			NES_DECL_POKE( Mmc5_5C00 );

			NES_DECL_POKE( Vrc6_9000 );
			NES_DECL_POKE( Vrc6_9001 );
			NES_DECL_POKE( Vrc6_9002 );
			NES_DECL_POKE( Vrc6_A000 );
			NES_DECL_POKE( Vrc6_A001 );
			NES_DECL_POKE( Vrc6_A002 );
			NES_DECL_POKE( Vrc6_B000 );
			NES_DECL_POKE( Vrc6_B001 );
			NES_DECL_POKE( Vrc6_B002 );

			NES_DECL_POKE( Vrc7_9010 );
			NES_DECL_POKE( Vrc7_9030 );

			NES_DECL_PEEK( N163_48 );
			NES_DECL_POKE( N163_48 );
			NES_DECL_POKE( N163_F8 );

			NES_DECL_POKE( S5b_C );
			NES_DECL_POKE( S5b_E );

			NES_DECL_PEEK( FFFA );
			NES_DECL_PEEK( FFFB );
			NES_DECL_PEEK( FFFC );
			NES_DECL_PEEK( FFFD );

			NES_DECL_PEEK( Nop );
			NES_DECL_POKE( Nop );

			enum Header
			{
				HEADER_SIZE = 128,
				HEADER_RESERVED_LENGTH = 4
			};

			class Chips;

			struct Songs
			{
				byte start;
				byte current;
				byte count;
				const byte padding;

				struct
				{
					char name[32];
					char artist[32];
					char copyright[32];
				}   info;

				Songs()
				:
				start    (0),
				current  (0),
				count    (0),
				padding  (0)
				{}
			};

			struct Speed
			{
				word ntsc;
				word pal;

				Speed()
				:
				ntsc (0),
				pal  (0)
				{}
			};

			struct Addressing
			{
				word play;
				word init;
				word load;
				word bankSwitched;

				Addressing()
				:
				play         (0x0000),
				init         (0x0000),
				load         (0x0000),
				bankSwitched (false)
				{}
			};

			struct Routine
			{
				enum
				{
					RESET_A = 0x1,
					RESET_B = 0x2,
					RESET   = RESET_A|RESET_B,
					NMI_A   = 0x1,
					NMI_B   = 0x2,
					NMI     = NMI_A|NMI_B
				};

				bool playing;
				byte nmi;
				byte reset;
				byte jmp;

				Routine()
				:
				playing (false),
				nmi     (0),
				reset   (0),
				jmp     (0x00)
				{}
			};

			Prg           prg;
			Routine       routine;
			Cpu&          cpu;
			Apu&          apu;
			Chips*        chips;
			FavoredSystem favoredSystem;
			Songs         songs;
			Addressing    addressing;
			Speed         speed;
			uint          tuneMode;
			byte          banks[8];
			byte          wrk[SIZE_8K];

		public:

			cstring GetName() const
			{
				return songs.info.name;
			}

			cstring GetArtist() const
			{
				return songs.info.artist;
			}

			cstring GetCopyright() const
			{
				return songs.info.copyright;
			}

			uint GetTuneMode() const
			{
				return tuneMode;
			}

			uint NumSongs() const
			{
				return songs.count;
			}

			uint CurrentSong() const
			{
				return songs.current;
			}

			uint StartingSong() const
			{
				return songs.start;
			}

			bool UsesBankSwitching() const
			{
				return addressing.bankSwitched;
			}

			bool IsPlaying() const
			{
				return routine.playing;
			}

			uint GetInitAddress() const
			{
				return addressing.init;
			}

			uint GetLoadAddress() const
			{
				return addressing.load;
			}

			uint GetPlayAddress() const
			{
				return addressing.play;
			}
		};
	}
}

#endif