Fix all warnings -Wall spews
[lsnes.git] / rom.hpp
blobac008ff1174a69bd418363026c6a7de5f6bc45c3
1 #ifndef _rom__hpp__included__
2 #define _rom__hpp__included__
4 #include <string>
5 #include "window.hpp"
6 #include <map>
7 #include <vector>
8 #include <stdexcept>
9 #include "misc.hpp"
11 /**
12 * \brief Region of ROM.
14 enum rom_region
16 /**
17 * \brief Autodetect region
19 REGION_AUTO = 0,
20 /**
21 * \brief (force) PAL region
23 REGION_PAL,
24 /**
25 * \brief (force) NTSC region
27 REGION_NTSC
30 /**
31 * \brief Major type of ROM
33 enum rom_type
35 /**
36 * \brief Ordinary SNES ROM
38 ROMTYPE_SNES, //ROM is Ordinary SNES ROM.
39 /**
40 * \brief BS-X Slotted ROM.
42 ROMTYPE_BSXSLOTTED,
43 /**
44 * \brief BS-X (non-slotted) ROM.
46 ROMTYPE_BSX,
47 /**
48 * \brief Sufami Turbo ROM.
50 ROMTYPE_SUFAMITURBO,
51 /**
52 * \brief Super Game Boy ROM.
54 ROMTYPE_SGB,
55 /**
56 * \brief No ROM.
58 ROMTYPE_NONE
61 /**
62 * \brief Type of ROM and region
64 * This enumeration enumerates possible ROM types and regions for those.
66 enum gametype_t
68 /**
69 * \brief NTSC-region SNES game
71 GT_SNES_NTSC = 0,
72 /**
73 * \brief PAL-region SNES game
75 GT_SNES_PAL = 1,
76 /**
77 * \brief NTSC-region BSX slotted game
79 GT_BSX_SLOTTED = 2,
80 /**
81 * \brief NTSC-region BSX (non-slotted) game
83 GT_BSX = 3,
84 /**
85 * \brief NTSC-region sufami turbo game
87 GT_SUFAMITURBO = 4,
88 /**
89 * \brief NTSC-region Super Game Boy game
91 GT_SGB_NTSC = 5,
92 /**
93 * \brief PAL-region Super Game Boy game
95 GT_SGB_PAL = 6,
96 /**
97 * \brief Invalid game type
99 GT_INVALID = 7
103 * \brief Translations between diffrent representations of type.
105 class gtype
107 public:
108 static std::string tostring(rom_type rtype, rom_region region) throw(std::bad_alloc, std::runtime_error);
109 static std::string tostring(gametype_t gametype) throw(std::bad_alloc, std::runtime_error);
110 static gametype_t togametype(rom_type rtype, rom_region region) throw(std::bad_alloc, std::runtime_error);
111 static gametype_t togametype(const std::string& gametype) throw(std::bad_alloc, std::runtime_error);
112 static rom_type toromtype(const std::string& gametype) throw(std::bad_alloc, std::runtime_error);
113 static rom_type toromtype(gametype_t gametype) throw();
114 static rom_region toromregion(const std::string& gametype) throw(std::bad_alloc, std::runtime_error);
115 static rom_region toromregion(gametype_t gametype) throw();
119 * \brief Filenames associated with ROM.
121 * This structure gives all files associated with given ROM image.
123 struct rom_files
126 * \brief Construct defaults
128 rom_files() throw();
131 * \brief Read files from command line arguments.
133 * Reads the filenames out of command line arguments given. Also supports bundle files.
135 * \param cmdline The commmand line
136 * \throws std::bad_alloc Not enough memory
137 * \throws std::runtime_error Failed to load ROM filenames.
139 rom_files(const std::vector<std::string>& cmdline, window* win) throw(std::bad_alloc, std::runtime_error);
142 * \brief Resolve relative references.
144 void resolve_relative() throw(std::bad_alloc, std::runtime_error);
147 * \brief Base ROM image
149 * The file to look other ROM files relative to. May be blank.
151 std::string base_file;
153 * \brief Major ROM type.
155 enum rom_type rtype;
157 * \brief Game region
159 enum rom_region region;
161 * \brief Relative filename of main ROM file.
163 std::string rom;
165 * \brief Relative filename of main ROM XML file.
167 std::string rom_xml;
169 * \brief Relative filename of slot A ROM file (non-SNES only).
171 std::string slota;
173 * \brief Relative filename of slot A XML file (non-SNES only).
175 std::string slota_xml;
177 * \brief Relative filename of slot B ROM file (Sufami Turbo only).
179 std::string slotb;
181 * \brief Relative filename of slot B XML file (Sufami Turbo only).
183 std::string slotb_xml;
187 * \brief Loaded data
189 * Some loaded data or indication of no data.
191 struct loaded_slot
194 * \brief Construct empty slot.
195 * \throws std::bad_alloc Not enough memory.
197 loaded_slot() throw(std::bad_alloc);
200 * \brief Read a slot
202 * This constructor construct slot by reading data from file. If filename is "", constructs an empty slot.
204 * \param filename The filename to read. If "", empty slot is constructed.
205 * \param base Base filename to interpret the filename against. If "", no base filename is used.
206 * \param xml_flag If set, always keep trailing NUL.
207 * \throws std::bad_alloc Not enough memory.
208 * \throws std::runtime_error Can't load the data.
210 loaded_slot(const std::string& filename, const std::string& base, bool xml_flag = false) throw(std::bad_alloc,
211 std::runtime_error);
214 * \brief IPS-patch a slot
216 * This method patches this slot using specified IPS patch.
218 * \param patch The patch to apply
219 * \param offset The amount to add to the offsets in the IPS file. Parts with offsets below zero are not patched.
220 * \throws std::bad_alloc Not enough memory.
221 * \throws std::runtime_error Bad IPS patch.
223 void patch(const std::vector<char>& patch, int32_t offset) throw(std::bad_alloc, std::runtime_error);
226 * \brief Is this slot XML slot?
228 bool xml;
230 * \brief True if this slot has valid data
232 * If this slot is blank, this is set to false, data is undefined and sha256 is "". Otherwise this is set to true,
233 * data to apporiate data, and sha256 to hash of data.
235 bool valid;
237 * \brief The actual data for this slot.
239 std::vector<char> data;
241 * \brief SHA-256 for the data in this slot.
243 * SHA-256 for the data in this slot if data is valid. If no valid data, this field is "".
245 std::string sha256;
247 * \brief Get pointer to loaded data
248 * \return Pointer to loaded data, or NULL if slot is blank.
250 operator const char*() const throw()
252 return valid ? reinterpret_cast<const char*>(&data[0]) : NULL;
255 * \brief Get pointer to loaded data
256 * \return Pointer to loaded data, or NULL if slot is blank.
258 operator const uint8_t*() const throw()
260 return valid ? reinterpret_cast<const uint8_t*>(&data[0]) : NULL;
263 * \brief Get size of slot
264 * \return The number of bytes in slot, or 0 if slot is blank.
266 operator unsigned() const throw()
268 return valid ? data.size() : 0;
273 * \brief ROM loaded into memory.
275 struct loaded_rom
278 * \brief Create blank ROM
280 loaded_rom() throw();
282 * \brief Load specified ROM files into memory.
284 * Takes in collection of ROM filenames and loads them into memory.
286 * \throws std::bad_alloc Not enough memory.
287 * \throws std::runtime_error Loading ROM files failed.
289 loaded_rom(const rom_files& files, window* win) throw(std::bad_alloc, std::runtime_error);
291 * \brief ROM type
293 enum rom_type rtype;
295 * \brief ROM region
297 enum rom_region region;
299 * \brief ROM original region
301 enum rom_region orig_region;
303 * \brief Loaded main ROM
305 loaded_slot rom;
307 * \brief Loaded main ROM XML
309 loaded_slot rom_xml;
311 * \brief Loaded slot A ROM
313 loaded_slot slota;
315 * \brief Loaded slot A XML
317 loaded_slot slota_xml;
319 * \brief Loaded slot B ROM
321 loaded_slot slotb;
323 * \brief Loaded slot B XML
325 loaded_slot slotb_xml;
328 * \brief Patch the ROM.
330 void do_patch(const std::vector<std::string>& cmdline, window* win) throw(std::bad_alloc, std::runtime_error);
333 * \brief Load this ROM into "SNES".
335 * Switches the active cartridge to this cartridge. The compatiblity between selected region and original region
336 * is checked. Region is updated after cartridge has been loaded.
338 * \throw std::bad_alloc Not enough memory
339 * \throw std::runtime_error Switching cartridges failed.
341 void load() throw(std::bad_alloc, std::runtime_error);
344 int recognize_commandline_rom(enum rom_type major, const std::string& romname) throw(std::bad_alloc);
345 rom_type recognize_platform(unsigned long flags) throw(std::bad_alloc, std::runtime_error);
348 * \brief Name a sub-ROM.
350 std::string name_subrom(enum rom_type major, unsigned romnumber) throw(std::bad_alloc);
353 * \brief Get major type and region of loaded ROM.
354 * \return rom type and region of current ROM.
356 std::pair<enum rom_type, enum rom_region> get_current_rom_info() throw();
359 * \brief Save all SRAMs
361 * Take current values of all SRAMs in current system and save their contents.
363 * \return Saved SRAM contents.
364 * \throws std::bad_alloc Out of memory.
366 std::map<std::string, std::vector<char>> save_sram() throw(std::bad_alloc);
369 * \brief Load all SRAMs
371 * Write contents of saved SRAMs into current system SRAMs.
373 * \param sram Saved SRAM contents.
374 * \throws std::bad_alloc Out of memory.
376 void load_sram(std::map<std::string, std::vector<char>>& sram, window* win) throw(std::bad_alloc);
379 * \brief Load SRAMs specified on command-line
381 * Read SRAMs from command-line and and load the files.
383 * \param cmdline Command line
384 * \return The loaded SRAM contents.
385 * \throws std::bad_alloc Out of memory.
386 * \throws std::runtime_error Failed to load.
388 std::map<std::string, std::vector<char>> load_sram_commandline(const std::vector<std::string>& cmdline)
389 throw(std::bad_alloc, std::runtime_error);
392 * \brief Emulate a frame
394 void emulate_frame() throw();
397 * \brief Reset the SNES
399 void reset_snes() throw();
402 * \brief Save core state into buffer
404 * Saves core state into buffer. WARNING: This takes emulated time.
406 * \return The saved state.
407 * \throws std::bad_alloc Not enough memory.
409 std::vector<char> save_core_state() throw(std::bad_alloc);
412 * \brief Restore core state from buffer.
414 * Loads core state from buffer.
416 * \param buf The buffer containing the state.
417 * \throws std::runtime_error Loading state failed.
419 void load_core_state(const std::vector<char>& buf) throw(std::runtime_error);
422 * \brief Read index file.
424 * Read index of ROMs and add ROMs found to content-searchable storage.
426 * \param filename The filename of index file.
427 * \throws std::bad_alloc Not enough memory.
428 * \throws std::runtime_error Loading index failed.
430 void load_index_file(const std::string& filename) throw(std::bad_alloc, std::runtime_error);
433 * \brief Lookup absolute filename by hash.
435 * Search all indices, looking for file with specified SHA-256 (specifying hash of "" results "").
437 * \param hash The hash of file.
438 * \return Absolute filename.
439 * \throws std::bad_alloc Not enough memory.
440 * \throws std::runtime_error Not found.
442 std::string lookup_file_by_sha256(const std::string& hash) throw(std::bad_alloc, std::runtime_error);
444 #endif