1 #ifndef _rom__hpp__included__
2 #define _rom__hpp__included__
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"
15 * ROM loaded into memory.
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
);
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
);
41 * Saves core state into buffer. WARNING: This takes emulated time.
43 * returns: The saved state.
44 * throws std::bad_alloc: Not enough memory.
46 std::vector
<char> save_core_state(bool nochecksum
= false) throw(std::bad_alloc
, std::runtime_error
);
49 * Loads core state from buffer.
51 * parameter buf: The buffer containing the state.
52 * throws std::runtime_error: Loading state failed.
54 void load_core_state(const std::vector
<char>& buf
, bool nochecksum
= false) throw(std::runtime_error
);
57 * Get internal type representation.
59 core_type
& get_internal_rom_type() { return rtype(); }
61 * Get internal region representation.
63 core_region
& get_internal_region() { return *region
; }
67 bool is_of_type(core_type
& type
) { return image
->is_of_type(type
); }
69 * Get gametype of this ROM.
71 core_sysregion
& get_sysregion() { return rtype().combine_region(*region
); }
73 * Set internal region representation.
75 void set_internal_region(core_region
& reg
) { region
= ®
; }
77 * Access main ROM image.
79 * parameter index: The index of ROM slot to access.
80 * returns: The ROM image (NULL image if index is out of range).
82 fileimage::image
& get_rom(size_t index
) { return image
->get_image(index
, false); }
84 * Access ROM markup image.
86 * parameter index: The index of ROM slot to access.
87 * returns: The ROM markup image (NULL image if index is out of range).
89 fileimage::image
& get_markup(size_t index
) { return image
->get_image(index
, true); }
91 * Get filename of ROM pack, if any.
93 const std::string
& get_pack_filename() { return image
->get_pack_filename(); }
95 * Get MSU-1 base fileaname.
97 const std::string
& get_msu1_base() { return image
->get_msu1_base(); }
99 std::string
get_core_identifier() { return rtype().get_core_identifier(); }
100 std::pair
<uint32_t, uint32_t> get_scale_factors(uint32_t width
, uint32_t height
)
102 return rtype().get_scale_factors(width
, height
);
104 const std::string
& get_hname() { return image
->get_hname(); }
105 core_sysregion
& combine_region(core_region
& reg
) { return rtype().combine_region(reg
); }
106 bool isnull() { return rtype().isnull(); }
107 std::vector
<std::string
> get_trace_cpus() { return rtype().get_trace_cpus(); }
108 controller_set
controllerconfig(std::map
<std::string
, std::string
>& settings
)
110 return rtype().controllerconfig(settings
);
112 core_setting_group
& get_settings() { return rtype().get_settings(); }
113 std::set
<std::string
> srams() { return rtype().srams(); }
114 double get_PAR() { return rtype().get_PAR(); }
115 std::string
get_systemmenu_name() { return rtype().get_systemmenu_name(); }
116 unsigned action_flags(unsigned id
) { return rtype().action_flags(id
); }
117 std::set
<const interface_action
*> get_actions() { return rtype().get_actions(); }
118 void execute_action(unsigned id
, const std::vector
<interface_action_paramval
>& p
)
120 return rtype().execute_action(id
, p
);
122 std::pair
<unsigned, unsigned> lightgun_scale() { return rtype().lightgun_scale(); }
123 const interface_device_reg
* get_registers() { return rtype().get_registers(); }
124 bool get_pflag() { return rtype().get_pflag(); }
125 void set_pflag(bool pflag
) { rtype().set_pflag(pflag
); }
126 std::pair
<uint64_t, uint64_t> get_bus_map() { return rtype().get_bus_map(); }
127 std::list
<core_region
*> get_regions() { return image
->get_regions(); }
128 const std::string
& get_iname() { return rtype().get_iname(); }
129 std::map
<std::string
, std::vector
<char>> save_sram() throw(std::bad_alloc
) { return rtype().save_sram(); }
130 void load_sram(std::map
<std::string
, std::vector
<char>>& sram
) throw(std::bad_alloc
)
132 rtype().load_sram(sram
);
134 std::list
<core_vma_info
> vma_list() { return rtype().vma_list(); }
135 framebuffer::raw
& draw_cover() { return rtype().draw_cover(); }
136 int reset_action(bool hard
) { return rtype().reset_action(hard
); }
137 void pre_emulate_frame(portctrl::frame
& cf
) { return rtype().pre_emulate_frame(cf
); }
138 void emulate() { rtype().emulate(); }
139 void runtosave() { rtype().runtosave(); }
140 std::pair
<uint32_t, uint32_t> get_audio_rate() { return rtype().get_audio_rate(); }
141 void set_debug_flags(uint64_t addr
, unsigned flags_set
, unsigned flags_clear
)
143 return rtype().set_debug_flags(addr
, flags_set
, flags_clear
);
145 void set_cheat(uint64_t addr
, uint64_t value
, bool set
)
147 return rtype().set_cheat(addr
, value
, set
);
151 rtype().debug_reset();
154 const std::string
& orig_region_get_iname() { return image
->get_region().get_iname(); }
155 const std::string
& orig_region_get_hname() { return image
->get_region().get_hname(); }
156 const std::string
& region_get_iname() { return region
->get_iname(); }
157 const std::string
& region_get_hname() { return region
->get_hname(); }
158 double region_approx_framerate() { return region
->approx_framerate(); }
159 void region_fill_framerate_magic(uint64_t* magic
) { region
->fill_framerate_magic(magic
); }
160 bool region_compatible_with(core_region
& run
)
162 return image
->get_region().compatible_with(run
);
165 core_type
& rtype() { return image
->get_type(); }
166 //The internal ROM image.
167 rom_image_handle image
;
173 * Get major type and region of loaded ROM.
175 * returns: Tuple (ROM type, ROM region) of currently loaded ROM.
177 std::pair
<core_type
*, core_region
*> get_current_rom_info() throw();
180 * Read SRAMs from command-line and and load the files.
182 * parameter cmdline: Command line
183 * returns: The loaded SRAM contents.
184 * throws std::bad_alloc: Out of memory.
185 * throws std::runtime_error: Failed to load.
187 std::map
<std::string
, std::vector
<char>> load_sram_commandline(const std::vector
<std::string
>& cmdline
)
188 throw(std::bad_alloc
, std::runtime_error
);
190 struct romload_request
192 //Pack file to load. Overrides everything else.
193 std::string packfile
;
194 //Single file to load to default slot.
195 std::string singlefile
;
196 //Core and system. May be blank.
201 std::string files
[ROM_SLOT_COUNT
];
204 bool load_null_rom();
205 bool _load_new_rom(const romload_request
& req
);
206 bool reload_active_rom();
207 regex_results
get_argument(const std::vector
<std::string
>& cmdline
, const std::string
& regexp
);
208 std::string
get_requested_core(const std::vector
<std::string
>& cmdline
);
209 void try_guess_roms(rom_request
& req
);
210 std::string
try_to_guess_rom(const std::string
& hint
, const std::string
& hash
, const std::string
& xhash
,
211 core_type
& type
, unsigned i
);