2011-09-13 17:50:18 +03:00
|
|
|
#ifndef _rom__hpp__included__
|
|
|
|
#define _rom__hpp__included__
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <stdexcept>
|
2012-07-09 18:11:32 +03:00
|
|
|
#include "core/misc.hpp"
|
|
|
|
#include "core/romtype.hpp"
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Some loaded data or indication of no data.
|
|
|
|
*/
|
|
|
|
struct loaded_slot
|
|
|
|
{
|
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* Construct empty slot.
|
|
|
|
*
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
loaded_slot() throw(std::bad_alloc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This constructor construct slot by reading data from file. If filename is "", constructs an empty slot.
|
|
|
|
*
|
2011-09-16 21:09:22 +03:00
|
|
|
* parameter filename: The filename to read. If "", empty slot is constructed.
|
|
|
|
* parameter base: Base filename to interpret the filename against. If "", no base filename is used.
|
2012-08-24 20:24:18 +03:00
|
|
|
* parameter imginfo: Image information.
|
2011-09-16 21:09:22 +03:00
|
|
|
* parameter xml_flag: If set, always keep trailing NUL.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
* throws std::runtime_error: Can't load the data.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-08-24 20:24:18 +03:00
|
|
|
loaded_slot(const std::string& filename, const std::string& base, const struct core_romimage_info& imginfo,
|
|
|
|
bool xml_flag = false) throw(std::bad_alloc, std::runtime_error);
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method patches this slot using specified IPS patch.
|
|
|
|
*
|
2011-09-16 21:09:22 +03:00
|
|
|
* parameter patch: The patch to apply
|
|
|
|
* parameter offset: The amount to add to the offsets in the IPS file. Parts with offsets below zero are not patched.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
|
|
|
* throws std::runtime_error: Bad IPS patch.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
void patch(const std::vector<char>& patch, int32_t offset) throw(std::bad_alloc, std::runtime_error);
|
|
|
|
|
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* Is this slot XML slot?
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
bool xml;
|
|
|
|
/**
|
|
|
|
* If this slot is blank, this is set to false, data is undefined and sha256 is "". Otherwise this is set to true,
|
|
|
|
* data to apporiate data, and sha256 to hash of data.
|
|
|
|
*/
|
|
|
|
bool valid;
|
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* The actual data for this slot.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
std::vector<char> data;
|
|
|
|
/**
|
|
|
|
* SHA-256 for the data in this slot if data is valid. If no valid data, this field is "".
|
|
|
|
*/
|
|
|
|
std::string sha256;
|
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* Get pointer to loaded data
|
|
|
|
*
|
|
|
|
* returns: Pointer to loaded data, or NULL if slot is blank.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
operator const char*() const throw()
|
|
|
|
{
|
|
|
|
return valid ? reinterpret_cast<const char*>(&data[0]) : NULL;
|
|
|
|
}
|
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* Get pointer to loaded data
|
|
|
|
*
|
|
|
|
* returns: Pointer to loaded data, or NULL if slot is blank.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
operator const uint8_t*() const throw()
|
|
|
|
{
|
|
|
|
return valid ? reinterpret_cast<const uint8_t*>(&data[0]) : NULL;
|
|
|
|
}
|
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* Get size of slot
|
|
|
|
*
|
|
|
|
* returns: The number of bytes in slot, or 0 if slot is blank.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
operator unsigned() const throw()
|
|
|
|
{
|
|
|
|
return valid ? data.size() : 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* ROM loaded into memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
struct loaded_rom
|
|
|
|
{
|
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* Create blank ROM
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
loaded_rom() throw();
|
|
|
|
/**
|
2012-08-24 20:24:18 +03:00
|
|
|
* Take in ROM filename (or a bundle) and load it to memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*
|
2012-08-24 20:24:18 +03:00
|
|
|
* parameter file: The file to load
|
2011-09-16 21:09:22 +03:00
|
|
|
* throws std::bad_alloc: Not enough memory.
|
2012-08-24 20:24:18 +03:00
|
|
|
* throws std::runtime_error: Loading ROM file failed.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-08-24 20:24:18 +03:00
|
|
|
loaded_rom(const std::string& file) throw(std::bad_alloc, std::runtime_error);
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* ROM type
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-07-09 18:11:32 +03:00
|
|
|
core_type* rtype;
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* ROM region (this is the currently active region).
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-07-09 18:11:32 +03:00
|
|
|
core_region* region;
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* ROM original region (this is the region ROM is loaded as).
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-07-09 18:11:32 +03:00
|
|
|
core_region* orig_region;
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* Loaded main ROM
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-07-09 18:11:32 +03:00
|
|
|
loaded_slot romimg[27];
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* Loaded main ROM XML
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-07-09 18:11:32 +03:00
|
|
|
loaded_slot romxml[27];
|
2012-05-18 19:03:32 +03:00
|
|
|
/**
|
|
|
|
* MSU-1 base.
|
|
|
|
*/
|
|
|
|
std::string msu1_base;
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2012-08-24 20:24:18 +03:00
|
|
|
* Load filename.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-08-24 20:24:18 +03:00
|
|
|
std::string load_filename;
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
|
|
|
* Switches the active cartridge to this cartridge. The compatiblity between selected region and original region
|
|
|
|
* is checked. Region is updated after cartridge has been loaded.
|
|
|
|
*
|
2011-09-16 21:09:22 +03:00
|
|
|
* throws std::bad_alloc: Not enough memory
|
|
|
|
* throws std::runtime_error: Switching cartridges failed.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-07-14 09:17:26 +03:00
|
|
|
void load(uint64_t rtc_sec, uint64_t rtc_subsec) throw(std::bad_alloc, std::runtime_error);
|
2011-09-13 17:50:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2011-09-16 21:09:22 +03:00
|
|
|
* Get major type and region of loaded ROM.
|
|
|
|
*
|
|
|
|
* returns: Tuple (ROM type, ROM region) of currently loaded ROM.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-07-09 18:11:32 +03:00
|
|
|
std::pair<core_type*, core_region*> get_current_rom_info() throw();
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Take current values of all SRAMs in current system and save their contents.
|
|
|
|
*
|
2011-09-16 21:09:22 +03:00
|
|
|
* returns: Saved SRAM contents.
|
|
|
|
* throws std::bad_alloc: Out of memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
std::map<std::string, std::vector<char>> save_sram() throw(std::bad_alloc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write contents of saved SRAMs into current system SRAMs.
|
|
|
|
*
|
2011-09-16 21:09:22 +03:00
|
|
|
* parameter sram: Saved SRAM contents.
|
|
|
|
* throws std::bad_alloc: Out of memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-09-17 01:05:41 +03:00
|
|
|
void load_sram(std::map<std::string, std::vector<char>>& sram) throw(std::bad_alloc);
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read SRAMs from command-line and and load the files.
|
|
|
|
*
|
2011-09-16 21:09:22 +03:00
|
|
|
* parameter cmdline: Command line
|
|
|
|
* returns: The loaded SRAM contents.
|
|
|
|
* throws std::bad_alloc: Out of memory.
|
|
|
|
* throws std::runtime_error: Failed to load.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
|
|
|
std::map<std::string, std::vector<char>> load_sram_commandline(const std::vector<std::string>& cmdline)
|
|
|
|
throw(std::bad_alloc, std::runtime_error);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves core state into buffer. WARNING: This takes emulated time.
|
|
|
|
*
|
2011-09-16 21:09:22 +03:00
|
|
|
* returns: The saved state.
|
|
|
|
* throws std::bad_alloc: Not enough memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-05-19 14:37:49 +03:00
|
|
|
std::vector<char> save_core_state(bool nochecksum = false) throw(std::bad_alloc);
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads core state from buffer.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-09-16 21:09:22 +03:00
|
|
|
* parameter buf: The buffer containing the state.
|
|
|
|
* throws std::runtime_error: Loading state failed.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-05-19 14:37:49 +03:00
|
|
|
void load_core_state(const std::vector<char>& buf, bool nochecksum = false) throw(std::runtime_error);
|
2011-09-13 17:50:18 +03:00
|
|
|
|
|
|
|
#endif
|