1 #ifndef _rom__hpp__included__
2 #define _rom__hpp__included__
8 #include "core/misc.hpp"
9 #include "core/rom-small.hpp"
10 #include "interface/romtype.hpp"
11 #include "library/fileimage.hpp"
17 std::vector
<core_type
*> cores
;
18 //Selected core (default core on call).
21 //Filename selected (on entry, filename hint).
22 bool has_slot
[ROM_SLOT_COUNT
];
23 bool guessed
[ROM_SLOT_COUNT
];
24 std::string filename
[ROM_SLOT_COUNT
];
25 std::string hash
[ROM_SLOT_COUNT
];
26 std::string hashxml
[ROM_SLOT_COUNT
];
32 * ROM loaded into memory.
41 * Take in ROM filename (or a bundle) and load it to memory.
43 * parameter file: The file to load
44 * parameter tmpprefer: The core name to prefer.
45 * throws std::bad_alloc: Not enough memory.
46 * throws std::runtime_error: Loading ROM file failed.
48 loaded_rom(const std::string
& file
, const std::string
& tmpprefer
= "") throw(std::bad_alloc
,
51 * Take a ROM and load it.
53 loaded_rom(const std::string
& file
, const std::string
& core
, const std::string
& type
,
54 const std::string
& region
);
56 * Load a multi-file ROM.
58 loaded_rom(const std::string file
[ROM_SLOT_COUNT
], const std::string
& core
, const std::string
& type
,
59 const std::string
& region
);
61 * Take in ROM filename and load it to memory with specified type.
63 * parameter file: The file to load
64 * parameter ctype: The core type to use.
65 * throws std::bad_alloc: Not enough memory.
66 * throws std::runtime_error: Loading ROM file failed.
68 loaded_rom(const std::string
& file
, core_type
& ctype
) throw(std::bad_alloc
, std::runtime_error
);
72 fileimage::image romimg
[ROM_SLOT_COUNT
];
76 fileimage::image romxml
[ROM_SLOT_COUNT
];
80 std::string msu1_base
;
84 std::string load_filename
;
86 * Switches the active cartridge to this cartridge. The compatiblity between selected region and original region
87 * is checked. Region is updated after cartridge has been loaded.
89 * throws std::bad_alloc: Not enough memory
90 * throws std::runtime_error: Switching cartridges failed.
92 void load(std::map
<std::string
, std::string
>& settings
, uint64_t rtc_sec
, uint64_t rtc_subsec
)
93 throw(std::bad_alloc
, std::runtime_error
);
95 * Saves core state into buffer. WARNING: This takes emulated time.
97 * returns: The saved state.
98 * throws std::bad_alloc: Not enough memory.
100 std::vector
<char> save_core_state(bool nochecksum
= false) throw(std::bad_alloc
, std::runtime_error
);
103 * Loads core state from buffer.
105 * parameter buf: The buffer containing the state.
106 * throws std::runtime_error: Loading state failed.
108 void load_core_state(const std::vector
<char>& buf
, bool nochecksum
= false) throw(std::runtime_error
);
113 * parameter filename: The file to probe.
114 * retruns: True if gamepak, false if not.
115 * throws std::runtime_error: No such file.
117 static bool is_gamepak(const std::string
& filename
) throw(std::bad_alloc
, std::runtime_error
);
120 * Get internal type representation.
122 core_type
& get_internal_rom_type() { return *rtype
; }
124 * Get internal region representation.
126 core_region
& get_internal_region() { return *region
; }
130 bool is_of_type(core_type
& type
) { return (rtype
== &type
); }
132 * Get gametype of this ROM.
134 core_sysregion
& get_sysregion() { return rtype
->combine_region(*region
); }
136 * Set internal region representation.
138 void set_internal_region(core_region
& reg
) { region
= ®
; }
141 std::string
get_core_identifier() { return rtype
->get_core_identifier(); }
142 std::pair
<uint32_t, uint32_t> get_scale_factors(uint32_t width
, uint32_t height
)
144 return rtype
->get_scale_factors(width
, height
);
146 const std::string
& get_hname() { return rtype
->get_hname(); }
147 core_sysregion
& combine_region(core_region
& reg
) { return rtype
->combine_region(reg
); }
148 bool isnull() { return !rtype
|| rtype
->isnull(); }
149 std::vector
<std::string
> get_trace_cpus() { return rtype
->get_trace_cpus(); }
150 controller_set
controllerconfig(std::map
<std::string
, std::string
>& settings
)
152 return rtype
->controllerconfig(settings
);
154 core_setting_group
& get_settings() { return rtype
->get_settings(); }
155 std::set
<std::string
> srams() { return rtype
->srams(); }
156 double get_PAR() { return rtype
->get_PAR(); }
157 std::string
get_systemmenu_name() { return rtype
->get_systemmenu_name(); }
158 unsigned action_flags(unsigned id
) { return rtype
->action_flags(id
); }
159 std::set
<const interface_action
*> get_actions() { return rtype
->get_actions(); }
160 void execute_action(unsigned id
, const std::vector
<interface_action_paramval
>& p
)
162 return rtype
->execute_action(id
, p
);
164 std::pair
<unsigned, unsigned> lightgun_scale() { return rtype
->lightgun_scale(); }
165 const interface_device_reg
* get_registers() { return rtype
->get_registers(); }
166 bool get_pflag() { return rtype
->get_pflag(); }
167 void set_pflag(bool pflag
) { rtype
->set_pflag(pflag
); }
168 std::pair
<uint64_t, uint64_t> get_bus_map() { return rtype
->get_bus_map(); }
169 std::list
<core_region
*> get_regions() { return rtype
->get_regions(); }
170 const std::string
& get_iname() { return rtype
->get_iname(); }
171 std::map
<std::string
, std::vector
<char>> save_sram() throw(std::bad_alloc
) { return rtype
->save_sram(); }
172 void load_sram(std::map
<std::string
, std::vector
<char>>& sram
) throw(std::bad_alloc
)
174 rtype
->load_sram(sram
);
176 std::list
<core_vma_info
> vma_list() { return rtype
->vma_list(); }
177 framebuffer::raw
& draw_cover() { return rtype
->draw_cover(); }
178 int reset_action(bool hard
) { return rtype
->reset_action(hard
); }
179 void pre_emulate_frame(portctrl::frame
& cf
) { return rtype
->pre_emulate_frame(cf
); }
180 void emulate() { rtype
->emulate(); }
181 void runtosave() { rtype
->runtosave(); }
182 std::pair
<uint32_t, uint32_t> get_audio_rate() { return rtype
->get_audio_rate(); }
183 void set_debug_flags(uint64_t addr
, unsigned flags_set
, unsigned flags_clear
)
185 return rtype
->set_debug_flags(addr
, flags_set
, flags_clear
);
187 void set_cheat(uint64_t addr
, uint64_t value
, bool set
)
189 return rtype
->set_cheat(addr
, value
, set
);
193 rtype
->debug_reset();
196 const std::string
& orig_region_get_iname() { return orig_region
->get_iname(); }
197 const std::string
& orig_region_get_hname() { return orig_region
->get_hname(); }
198 const std::string
& region_get_iname() { return region
->get_iname(); }
199 const std::string
& region_get_hname() { return region
->get_hname(); }
200 double region_approx_framerate() { return region
->approx_framerate(); }
201 void region_fill_framerate_magic(uint64_t* magic
) { region
->fill_framerate_magic(magic
); }
202 bool region_compatible_with(core_region
& run
)
204 return orig_region
&& orig_region
->compatible_with(run
);
212 * ROM region (this is the currently active region).
216 * ROM original region (this is the region ROM is loaded as).
218 core_region
* orig_region
;
222 * Get major type and region of loaded ROM.
224 * returns: Tuple (ROM type, ROM region) of currently loaded ROM.
226 std::pair
<core_type
*, core_region
*> get_current_rom_info() throw();
229 * Read SRAMs from command-line and and load the files.
231 * parameter cmdline: Command line
232 * returns: The loaded SRAM contents.
233 * throws std::bad_alloc: Out of memory.
234 * throws std::runtime_error: Failed to load.
236 std::map
<std::string
, std::vector
<char>> load_sram_commandline(const std::vector
<std::string
>& cmdline
)
237 throw(std::bad_alloc
, std::runtime_error
);
240 * Set the hasher callback.
242 void set_hasher_callback(std::function
<void(uint64_t, uint64_t)> cb
);
244 struct romload_request
246 //Pack file to load. Overrides everything else.
247 std::string packfile
;
248 //Single file to load to default slot.
249 std::string singlefile
;
250 //Core and system. May be blank.
255 std::string files
[ROM_SLOT_COUNT
];
258 bool load_null_rom();
259 bool _load_new_rom(const romload_request
& req
);
260 bool reload_active_rom();
261 regex_results
get_argument(const std::vector
<std::string
>& cmdline
, const std::string
& regexp
);
262 std::string
get_requested_core(const std::vector
<std::string
>& cmdline
);
263 loaded_rom
construct_rom(const std::string
& movie_filename
, const std::vector
<std::string
>& cmdline
);
264 void try_guess_roms(rom_request
& req
);
265 void record_filehash(const std::string
& file
, uint64_t prefix
, const std::string
& hash
);
266 std::string
try_to_guess_rom(const std::string
& hint
, const std::string
& hash
, const std::string
& xhash
,
267 core_type
& type
, unsigned i
);
270 //Map of preferred cores for each extension and type.
271 extern std::map
<std::string
, core_type
*> preferred_core
;
273 extern fileimage::hash lsnes_image_hasher
;