Delay committing fullscreen until seeing window size change
[lsnes.git] / include / core / rom.hpp
blob37e399b4dcd0d52eafd47004b5f4ca9977afcec6
1 #ifndef _rom__hpp__included__
2 #define _rom__hpp__included__
4 #include <string>
5 #include <map>
6 #include <vector>
7 #include <stdexcept>
8 #include "core/misc.hpp"
9 #include "core/rom-small.hpp"
10 #include "core/romimage.hpp"
11 #include "interface/romtype.hpp"
12 #include "library/fileimage.hpp"
14 /**
15 * ROM loaded into memory.
17 struct loaded_rom
19 /**
20 * Create blank ROM
22 loaded_rom() throw();
23 /**
24 * Create ROM from image.
26 * parameter _image: The image to use load
27 * throws std::bad_alloc: Not enough memory.
28 * throws std::runtime_error: Loading ROM file failed.
30 loaded_rom(rom_image_handle _image) throw(std::bad_alloc, std::runtime_error);
31 /**
32 * Switches the active cartridge to this cartridge. The compatiblity between selected region and original region
33 * is checked. Region is updated after cartridge has been loaded.
35 * throws std::bad_alloc: Not enough memory
36 * throws std::runtime_error: Switching cartridges failed.
38 void load(std::map<std::string, std::string>& settings, uint64_t rtc_sec, uint64_t rtc_subsec)
39 throw(std::bad_alloc, std::runtime_error);
40 /**
41 * Reset the emulation state to state just before last load.
43 void reset_to_load() { return rtype().reset_to_load(); }
44 /**
45 * Saves core state into buffer. WARNING: This takes emulated time.
47 * returns: The saved state.
48 * throws std::bad_alloc: Not enough memory.
50 std::vector<char> save_core_state(bool nochecksum = false) throw(std::bad_alloc, std::runtime_error);
52 /**
53 * Loads core state from buffer.
55 * parameter buf: The buffer containing the state.
56 * throws std::runtime_error: Loading state failed.
58 void load_core_state(const std::vector<char>& buf, bool nochecksum = false) throw(std::runtime_error);
60 /**
61 * Get internal type representation.
63 core_type& get_internal_rom_type() { return rtype(); }
64 /**
65 * Get internal region representation.
67 core_region& get_internal_region() { return *region; }
68 /**
69 * Is same ROM type?
71 bool is_of_type(core_type& type) { return image->is_of_type(type); }
72 /**
73 * Get gametype of this ROM.
75 core_sysregion& get_sysregion() { return rtype().combine_region(*region); }
76 /**
77 * Set internal region representation.
79 void set_internal_region(core_region& reg) { region = &reg; }
80 /**
81 * Access main ROM image.
83 * parameter index: The index of ROM slot to access.
84 * returns: The ROM image (NULL image if index is out of range).
86 fileimage::image& get_rom(size_t index) { return image->get_image(index, false); }
87 /**
88 * Access ROM markup image.
90 * parameter index: The index of ROM slot to access.
91 * returns: The ROM markup image (NULL image if index is out of range).
93 fileimage::image& get_markup(size_t index) { return image->get_image(index, true); }
94 /**
95 * Get filename of ROM pack, if any.
97 const std::string& get_pack_filename() { return image->get_pack_filename(); }
98 /**
99 * Get MSU-1 base fileaname.
101 const std::string& get_msu1_base() { return image->get_msu1_base(); }
102 //ROM methods.
103 std::string get_core_identifier() { return rtype().get_core_identifier(); }
104 std::pair<uint32_t, uint32_t> get_scale_factors(uint32_t width, uint32_t height)
106 return rtype().get_scale_factors(width, height);
108 const std::string& get_hname() { return image->get_hname(); }
109 core_sysregion& combine_region(core_region& reg) { return rtype().combine_region(reg); }
110 bool isnull() { return rtype().isnull(); }
111 std::vector<std::string> get_trace_cpus() { return rtype().get_trace_cpus(); }
112 controller_set controllerconfig(std::map<std::string, std::string>& settings)
114 return rtype().controllerconfig(settings);
116 core_setting_group& get_settings() { return rtype().get_settings(); }
117 std::set<std::string> srams() { return rtype().srams(); }
118 double get_PAR() { return rtype().get_PAR(); }
119 std::string get_systemmenu_name() { return rtype().get_systemmenu_name(); }
120 unsigned action_flags(unsigned id) { return rtype().action_flags(id); }
121 std::set<const interface_action*> get_actions() { return rtype().get_actions(); }
122 void execute_action(unsigned id, const std::vector<interface_action_paramval>& p)
124 return rtype().execute_action(id, p);
126 std::pair<unsigned, unsigned> lightgun_scale() { return rtype().lightgun_scale(); }
127 const interface_device_reg* get_registers() { return rtype().get_registers(); }
128 bool get_pflag() { return rtype().get_pflag(); }
129 void set_pflag(bool pflag) { rtype().set_pflag(pflag); }
130 std::pair<uint64_t, uint64_t> get_bus_map() { return rtype().get_bus_map(); }
131 std::list<core_region*> get_regions() { return image->get_regions(); }
132 const std::string& get_iname() { return rtype().get_iname(); }
133 std::map<std::string, std::vector<char>> save_sram() throw(std::bad_alloc) { return rtype().save_sram(); }
134 void load_sram(std::map<std::string, std::vector<char>>& sram) throw(std::bad_alloc)
136 rtype().load_sram(sram);
138 std::list<core_vma_info> vma_list() { return rtype().vma_list(); }
139 framebuffer::raw& draw_cover() { return rtype().draw_cover(); }
140 int reset_action(bool hard) { return rtype().reset_action(hard); }
141 void pre_emulate_frame(portctrl::frame& cf) { return rtype().pre_emulate_frame(cf); }
142 void emulate() { rtype().emulate(); }
143 void runtosave() { rtype().runtosave(); }
144 std::pair<uint32_t, uint32_t> get_audio_rate() { return rtype().get_audio_rate(); }
145 void set_debug_flags(uint64_t addr, unsigned flags_set, unsigned flags_clear)
147 return rtype().set_debug_flags(addr, flags_set, flags_clear);
149 void set_cheat(uint64_t addr, uint64_t value, bool set)
151 return rtype().set_cheat(addr, value, set);
153 void debug_reset()
155 rtype().debug_reset();
157 //Region methods.
158 const std::string& orig_region_get_iname() { return image->get_region().get_iname(); }
159 const std::string& orig_region_get_hname() { return image->get_region().get_hname(); }
160 const std::string& region_get_iname() { return region->get_iname(); }
161 const std::string& region_get_hname() { return region->get_hname(); }
162 double region_approx_framerate() { return region->approx_framerate(); }
163 void region_fill_framerate_magic(uint64_t* magic) { region->fill_framerate_magic(magic); }
164 bool region_compatible_with(core_region& run)
166 return image->get_region().compatible_with(run);
168 private:
169 core_type& rtype() { return image->get_type(); }
170 //The internal ROM image.
171 rom_image_handle image;
172 //ROM region.
173 core_region* region;
177 * Get major type and region of loaded ROM.
179 * returns: Tuple (ROM type, ROM region) of currently loaded ROM.
181 std::pair<core_type*, core_region*> get_current_rom_info() throw();
184 * Read SRAMs from command-line and and load the files.
186 * parameter cmdline: Command line
187 * returns: The loaded SRAM contents.
188 * throws std::bad_alloc: Out of memory.
189 * throws std::runtime_error: Failed to load.
191 std::map<std::string, std::vector<char>> load_sram_commandline(const std::vector<std::string>& cmdline)
192 throw(std::bad_alloc, std::runtime_error);
194 struct romload_request
196 //Pack file to load. Overrides everything else.
197 std::string packfile;
198 //Single file to load to default slot.
199 std::string singlefile;
200 //Core and system. May be blank.
201 std::string core;
202 std::string system;
203 std::string region;
204 //Files to load.
205 std::string files[ROM_SLOT_COUNT];
208 bool load_null_rom();
209 bool _load_new_rom(const romload_request& req);
210 bool reload_active_rom();
211 regex_results get_argument(const std::vector<std::string>& cmdline, const std::string& regexp);
212 std::string get_requested_core(const std::vector<std::string>& cmdline);
213 void try_guess_roms(rom_request& req);
214 std::string try_to_guess_rom(const std::string& hint, const std::string& hash, const std::string& xhash,
215 core_type& type, unsigned i);
219 #endif