Save ROM name hints
[lsnes.git] / include / core / rom.hpp
bloba27f6da7f0ef176603cc8cdcb3d178bbae659bf6
1 #ifndef _rom__hpp__included__
2 #define _rom__hpp__included__
4 #define ROM_SLOT_COUNT 27
6 #include <string>
7 #include <map>
8 #include <vector>
9 #include <stdexcept>
10 #include "core/misc.hpp"
11 #include "core/moviefile.hpp"
12 #include "core/romtype.hpp"
14 /**
15 * Some loaded data or indication of no data.
17 struct loaded_slot
19 /**
20 * Construct empty slot.
22 * throws std::bad_alloc: Not enough memory.
24 loaded_slot() throw(std::bad_alloc);
26 /**
27 * This constructor construct slot by reading data from file. If filename is "", constructs an empty slot.
29 * parameter filename: The filename to read. If "", empty slot is constructed.
30 * parameter base: Base filename to interpret the filename against. If "", no base filename is used.
31 * parameter imginfo: Image information.
32 * parameter xml_flag: If set, always keep trailing NUL.
33 * throws std::bad_alloc: Not enough memory.
34 * throws std::runtime_error: Can't load the data.
36 loaded_slot(const std::string& filename, const std::string& base, const struct core_romimage_info& imginfo,
37 bool xml_flag = false) throw(std::bad_alloc, std::runtime_error);
39 /**
40 * This method patches this slot using specified IPS patch.
42 * parameter patch: The patch to apply
43 * parameter offset: The amount to add to the offsets in the IPS file. Parts with offsets below zero are not patched.
44 * throws std::bad_alloc: Not enough memory.
45 * throws std::runtime_error: Bad IPS patch.
47 void patch(const std::vector<char>& patch, int32_t offset) throw(std::bad_alloc, std::runtime_error);
49 /**
50 * Is this slot XML slot?
52 bool xml;
53 /**
54 * If this slot is blank, this is set to false, data is undefined and sha256 is "". Otherwise this is set to true,
55 * data to apporiate data, and sha256 to hash of data.
57 bool valid;
58 /**
59 * The actual data for this slot.
61 std::vector<char> data;
62 /**
63 * SHA-256 for the data in this slot if data is valid. If no valid data, this field is "".
65 std::string sha256;
66 /**
67 * Name hint. Only for non-XML slots.
69 std::string namehint;
70 /**
71 * Get pointer to loaded data
73 * returns: Pointer to loaded data, or NULL if slot is blank.
75 operator const char*() const throw()
77 return valid ? reinterpret_cast<const char*>(&data[0]) : NULL;
79 /**
80 * Get pointer to loaded data
82 * returns: Pointer to loaded data, or NULL if slot is blank.
84 operator const uint8_t*() const throw()
86 return valid ? reinterpret_cast<const uint8_t*>(&data[0]) : NULL;
88 /**
89 * Get size of slot
91 * returns: The number of bytes in slot, or 0 if slot is blank.
93 operator unsigned() const throw()
95 return valid ? data.size() : 0;
99 /**
100 * ROM loaded into memory.
102 struct loaded_rom
105 * Create blank ROM
107 loaded_rom() throw();
109 * Take in ROM filename (or a bundle) and load it to memory.
111 * parameter file: The file to load
112 * throws std::bad_alloc: Not enough memory.
113 * throws std::runtime_error: Loading ROM file failed.
115 loaded_rom(const std::string& file) throw(std::bad_alloc, std::runtime_error);
117 * ROM type
119 core_type* rtype;
121 * ROM region (this is the currently active region).
123 core_region* region;
125 * ROM original region (this is the region ROM is loaded as).
127 core_region* orig_region;
129 * Loaded main ROM
131 loaded_slot romimg[ROM_SLOT_COUNT];
133 * Loaded main ROM XML
135 loaded_slot romxml[ROM_SLOT_COUNT];
137 * MSU-1 base.
139 std::string msu1_base;
141 * Load filename.
143 std::string load_filename;
145 * Switches the active cartridge to this cartridge. The compatiblity between selected region and original region
146 * is checked. Region is updated after cartridge has been loaded.
148 * throws std::bad_alloc: Not enough memory
149 * throws std::runtime_error: Switching cartridges failed.
151 void load(uint64_t rtc_sec, uint64_t rtc_subsec) throw(std::bad_alloc, std::runtime_error);
155 * Get major type and region of loaded ROM.
157 * returns: Tuple (ROM type, ROM region) of currently loaded ROM.
159 std::pair<core_type*, core_region*> get_current_rom_info() throw();
162 * Take current values of all SRAMs in current system and save their contents.
164 * returns: Saved SRAM contents.
165 * throws std::bad_alloc: Out of memory.
167 std::map<std::string, std::vector<char>> save_sram() throw(std::bad_alloc);
170 * Write contents of saved SRAMs into current system SRAMs.
172 * parameter sram: Saved SRAM contents.
173 * throws std::bad_alloc: Out of memory.
175 void load_sram(std::map<std::string, std::vector<char>>& sram) throw(std::bad_alloc);
178 * Read SRAMs from command-line and and load the files.
180 * parameter cmdline: Command line
181 * returns: The loaded SRAM contents.
182 * throws std::bad_alloc: Out of memory.
183 * throws std::runtime_error: Failed to load.
185 std::map<std::string, std::vector<char>> load_sram_commandline(const std::vector<std::string>& cmdline)
186 throw(std::bad_alloc, std::runtime_error);
189 * Saves core state into buffer. WARNING: This takes emulated time.
191 * returns: The saved state.
192 * throws std::bad_alloc: Not enough memory.
194 std::vector<char> save_core_state(bool nochecksum = false) throw(std::bad_alloc);
197 * Loads core state from buffer.
199 * parameter buf: The buffer containing the state.
200 * throws std::runtime_error: Loading state failed.
202 void load_core_state(const std::vector<char>& buf, bool nochecksum = false) throw(std::runtime_error);
204 #endif