Actually call on_reset callback
[lsnes.git] / include / core / rom.hpp
blobd03ba8b4940b186e6030efedab9d35d870ea62f5
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);
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 /**
40 * Reset the emulation state to state just before last load.
42 void reset_to_load() { return rtype().reset_to_load(); }
43 /**
44 * Saves core state into buffer. WARNING: This takes emulated time.
46 * returns: The saved state.
47 * throws std::bad_alloc: Not enough memory.
49 std::vector<char> save_core_state(bool nochecksum = false);
51 /**
52 * Loads core state from buffer.
54 * parameter buf: The buffer containing the state.
55 * throws std::runtime_error: Loading state failed.
57 void load_core_state(const std::vector<char>& buf, bool nochecksum = false);
59 /**
60 * Get internal type representation.
62 core_type& get_internal_rom_type() { return rtype(); }
63 /**
64 * Get internal region representation.
66 core_region& get_internal_region() { return *region; }
67 /**
68 * Is same ROM type?
70 bool is_of_type(core_type& type) { return image->is_of_type(type); }
71 /**
72 * Get gametype of this ROM.
74 core_sysregion& get_sysregion() { return rtype().combine_region(*region); }
75 /**
76 * Set internal region representation.
78 void set_internal_region(core_region& reg) { region = &reg; }
79 /**
80 * Access main ROM image.
82 * parameter index: The index of ROM slot to access.
83 * returns: The ROM image (NULL image if index is out of range).
85 fileimage::image& get_rom(size_t index) { return image->get_image(index, false); }
86 /**
87 * Access ROM markup image.
89 * parameter index: The index of ROM slot to access.
90 * returns: The ROM markup image (NULL image if index is out of range).
92 fileimage::image& get_markup(size_t index) { return image->get_image(index, true); }
93 /**
94 * Get filename of ROM pack, if any.
96 const std::string& get_pack_filename() { return image->get_pack_filename(); }
97 /**
98 * Get MSU-1 base fileaname.
100 const std::string& get_msu1_base() { return image->get_msu1_base(); }
101 //ROM methods.
102 std::string get_core_identifier() { return rtype().get_core_identifier(); }
103 std::pair<uint32_t, uint32_t> get_scale_factors(uint32_t width, uint32_t height)
105 return rtype().get_scale_factors(width, height);
107 const std::string& get_hname() { return image->get_hname(); }
108 core_sysregion& combine_region(core_region& reg) { return rtype().combine_region(reg); }
109 bool isnull() { return rtype().isnull(); }
110 std::vector<std::string> get_trace_cpus() { return rtype().get_trace_cpus(); }
111 controller_set controllerconfig(std::map<std::string, std::string>& settings)
113 return rtype().controllerconfig(settings);
115 core_setting_group& get_settings() { return rtype().get_settings(); }
116 std::set<std::string> srams() { return rtype().srams(); }
117 double get_PAR() { return rtype().get_PAR(); }
118 std::string get_systemmenu_name() { return rtype().get_systemmenu_name(); }
119 unsigned action_flags(unsigned id) { return rtype().action_flags(id); }
120 std::set<const interface_action*> get_actions() { return rtype().get_actions(); }
121 void execute_action(unsigned id, const std::vector<interface_action_paramval>& p)
123 return rtype().execute_action(id, p);
125 std::pair<unsigned, unsigned> lightgun_scale() { return rtype().lightgun_scale(); }
126 const interface_device_reg* get_registers() { return rtype().get_registers(); }
127 bool get_pflag() { return rtype().get_pflag(); }
128 void set_pflag(bool pflag) { rtype().set_pflag(pflag); }
129 std::pair<uint64_t, uint64_t> get_bus_map() { return rtype().get_bus_map(); }
130 std::list<core_region*> get_regions() { return image->get_regions(); }
131 const std::string& get_iname() { return rtype().get_iname(); }
132 std::map<std::string, std::vector<char>> save_sram() { return rtype().save_sram(); }
133 void load_sram(std::map<std::string, std::vector<char>>& sram)
135 rtype().load_sram(sram);
137 std::list<core_vma_info> vma_list() { return rtype().vma_list(); }
138 framebuffer::raw& draw_cover() { return rtype().draw_cover(); }
139 int reset_action(bool hard) { return rtype().reset_action(hard); }
140 void pre_emulate_frame(portctrl::frame& cf) { return rtype().pre_emulate_frame(cf); }
141 void emulate() { rtype().emulate(); }
142 void runtosave() { rtype().runtosave(); }
143 std::pair<uint32_t, uint32_t> get_audio_rate() { return rtype().get_audio_rate(); }
144 void set_debug_flags(uint64_t addr, unsigned flags_set, unsigned flags_clear)
146 return rtype().set_debug_flags(addr, flags_set, flags_clear);
148 void set_cheat(uint64_t addr, uint64_t value, bool set)
150 return rtype().set_cheat(addr, value, set);
152 void debug_reset()
154 rtype().debug_reset();
156 //Region methods.
157 const std::string& orig_region_get_iname() { return image->get_region().get_iname(); }
158 const std::string& orig_region_get_hname() { return image->get_region().get_hname(); }
159 const std::string& region_get_iname() { return region->get_iname(); }
160 const std::string& region_get_hname() { return region->get_hname(); }
161 double region_approx_framerate() { return region->approx_framerate(); }
162 void region_fill_framerate_magic(uint64_t* magic) { region->fill_framerate_magic(magic); }
163 bool region_compatible_with(core_region& run)
165 return image->get_region().compatible_with(run);
167 private:
168 core_type& rtype() { return image->get_type(); }
169 //The internal ROM image.
170 rom_image_handle image;
171 //ROM region.
172 core_region* region;
176 * Get major type and region of loaded ROM.
178 * returns: Tuple (ROM type, ROM region) of currently loaded ROM.
180 std::pair<core_type*, core_region*> get_current_rom_info() throw();
183 * Read SRAMs from command-line and and load the files.
185 * parameter cmdline: Command line
186 * returns: The loaded SRAM contents.
187 * throws std::bad_alloc: Out of memory.
188 * throws std::runtime_error: Failed to load.
190 std::map<std::string, std::vector<char>> load_sram_commandline(const std::vector<std::string>& cmdline);
192 struct romload_request
194 //Pack file to load. Overrides everything else.
195 std::string packfile;
196 //Single file to load to default slot.
197 std::string singlefile;
198 //Core and system. May be blank.
199 std::string core;
200 std::string system;
201 std::string region;
202 //Files to load.
203 std::string files[ROM_SLOT_COUNT];
206 bool load_null_rom();
207 bool _load_new_rom(const romload_request& req);
208 bool reload_active_rom();
209 regex_results get_argument(const std::vector<std::string>& cmdline, const std::string& regexp);
210 std::string get_requested_core(const std::vector<std::string>& cmdline);
211 void try_guess_roms(rom_request& req);
212 std::string try_to_guess_rom(const std::string& hint, const std::string& hash, const std::string& xhash,
213 core_type& type, unsigned i);
217 #endif