#ifndef INCLUDED_GAME_H #define INCLUDED_GAME_H #include "Util/NewConfig.h" #include "Pkgs/unzip.h" #include #include struct Game { std::string title; std::string version; std::string manufacturer; int year; std::string stepping; // Holds a ROM region struct ROM { std::shared_ptr data; size_t size = 0; }; std::map roms; }; //TODO: move to separate GameLoader.cpp class GameLoader { private: // Describes a file node in the game XML struct File { typedef std::shared_ptr Ptr_t; uint32_t offset; std::string filename; uint32_t crc32; bool has_crc32; static Ptr_t Create(const GameLoader &loader, const Util::Config::Node &file_node); bool Matches(const std::string &filename, uint32_t crc32) const; }; // Describes a region node in the game XML struct Region { typedef std::shared_ptr Ptr_t; std::string region_name; size_t stride; size_t chunk_size; bool byte_swap; typedef std::map FilesByOffset_t; FilesByOffset_t files_by_offset; static Ptr_t Create(const GameLoader &loader, const Util::Config::Node ®ion_node); }; std::map m_game_info_by_game; // ROMs not loaded here typedef std::map RegionsByName_t; std::map m_regions_by_game; std::string m_xml_filename; std::string m_zipfilename; unzFile m_zf; std::map m_filename_by_crc32; std::map m_zip_info_by_filename; std::map m_zip_info_by_crc32; static bool MissingAttrib(const GameLoader &loader, const Util::Config::Node &node, const std::string &attribute); bool ParseXML(const Util::Config::Node::ConstPtr_t &xml); std::set IdentifyGamesFileBelongsTo(const std::string &filename, uint32_t crc32) const; const unz_file_info *LookupZippedFile(const File::Ptr_t &file) const; bool ComputeRegionSize(uint32_t *region_size, const Region::Ptr_t ®ion) const; bool LoadZippedFile(std::shared_ptr *buffer, size_t *file_size, const GameLoader::File::Ptr_t &file); bool LoadRegion(Game::ROM *buffer, const GameLoader::Region::Ptr_t ®ion); bool LoadROMs(std::map *roms, const std::string &game_name); public: GameLoader() { } bool LoadDefinitionXML(const std::string &filename); bool Load(Game *game, const std::string &zipfilename); }; #endif // INCLUDED_GAME_H