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 #ifndef NST_IMAGE_H
26 #define NST_IMAGE_H
27 
28 #ifdef NST_PRAGMA_ONCE
29 #pragma once
30 #endif
31 
32 #include <iosfwd>
33 
34 namespace Nes
35 {
36 	namespace Core
37 	{
38 		namespace State
39 		{
40 			class Loader;
41 			class Saver;
42 		}
43 
44 		class ImageDatabase;
45 		class Cpu;
46 		class Apu;
47 		class Ppu;
48 
49 		class NST_NO_VTABLE Image
50 		{
51 		public:
52 
53 			enum Type
54 			{
55 				UNKNOWN   = 0x0,
56 				CARTRIDGE = 0x1,
57 				DISK      = 0x2,
58 				SOUND     = 0x4
59 			};
60 
61 			typedef void* ExternalDevice;
62 
63 			enum ExternalDeviceType
64 			{
65 				EXT_DIP_SWITCHES = 1,
66 				EXT_BARCODE_READER
67 			};
68 
69 			struct Context
70 			{
71 				const Type type;
72 				Cpu& cpu;
73 				Apu& apu;
74 				Ppu& ppu;
75 				std::istream& stream;
76 				std::istream* const patch;
77 				const bool patchBypassChecksum;
78 				Result* const patchResult;
79 				const FavoredSystem favoredSystem;
80 				const bool askProfile;
81 				const ImageDatabase* const database;
82 				Result result;
83 
ContextNes::Core::Image::Context84 				Context(Type t,Cpu& c,Apu& a,Ppu& p,std::istream& s,std::istream* h,bool k,Result* r,FavoredSystem f,bool b,const ImageDatabase* d)
85 				: type(t), cpu(c), apu(a), ppu(p), stream(s), patch(h), patchBypassChecksum(k), patchResult(r), favoredSystem(f), askProfile(b), database(d), result(RESULT_OK) {}
86 			};
87 
88 			static Image* Load(Context&);
89 			static void Unload(Image*);
90 
91 			virtual void Reset(bool) = 0;
92 
PowerOff()93 			virtual bool PowerOff()
94 			{
95 				return true;
96 			}
97 
VSync()98 			virtual void VSync() {}
99 
LoadState(State::Loader &)100 			virtual void LoadState(State::Loader&) {}
SaveState(State::Saver &,dword) const101 			virtual void SaveState(State::Saver&,dword) const {}
102 
103 			virtual uint GetDesiredController(uint) const;
104 			virtual uint GetDesiredAdapter() const;
105 			virtual Region GetDesiredRegion() const = 0;
106 			virtual System GetDesiredSystem(Region,CpuModel* = NULL,PpuModel* = NULL) const;
107 
GetPrgCrc() const108 			virtual dword GetPrgCrc() const
109 			{
110 				return 0;
111 			}
112 
QueryExternalDevice(ExternalDeviceType)113 			virtual ExternalDevice QueryExternalDevice(ExternalDeviceType)
114 			{
115 				return NULL;
116 			}
117 
118 		protected:
119 
120 			explicit Image(Type);
~Image()121 			virtual ~Image() {}
122 
123 			enum
124 			{
125 				INES_ID    = AsciiId<'N','E','S'>::V | 0x1AUL << 24,
126 				UNIF_ID    = AsciiId<'U','N','I','F'>::V,
127 				FDS_ID     = AsciiId<'F','D','S'>::V | 0x1AUL << 24,
128 				FDS_RAW_ID = 0x494E2A01,
129 				NSF_ID     = AsciiId<'N','E','S','M'>::V
130 			};
131 
132 		private:
133 
134 			const Type type;
135 
136 		public:
137 
GetType() const138 			Type GetType() const
139 			{
140 				return type;
141 			}
142 		};
143 	}
144 }
145 
146 #endif
147