diff options
Diffstat (limited to 'src/devices/bus/ti99/gromport/cartridges.h')
-rw-r--r-- | src/devices/bus/ti99/gromport/cartridges.h | 105 |
1 files changed, 16 insertions, 89 deletions
diff --git a/src/devices/bus/ti99/gromport/cartridges.h b/src/devices/bus/ti99/gromport/cartridges.h index df94321a5f9..ccf8773c79b 100644 --- a/src/devices/bus/ti99/gromport/cartridges.h +++ b/src/devices/bus/ti99/gromport/cartridges.h @@ -11,6 +11,7 @@ #include "gromport.h" #include "machine/tmc0430.h" +#include "formats/rpk.h" #include "emuopts.h" #include "softlist_dev.h" @@ -22,46 +23,6 @@ namespace bus::ti99::gromport { class ti99_cartridge_pcb; -enum rpk_open_error -{ - RPK_OK, - RPK_NOT_ZIP_FORMAT, - RPK_CORRUPT, - RPK_OUT_OF_MEMORY, - RPK_XML_ERROR, - RPK_INVALID_FILE_REF, - RPK_ZIP_ERROR, - RPK_ZIP_UNSUPPORTED, - RPK_MISSING_RAM_LENGTH, - RPK_INVALID_RAM_SPEC, - RPK_UNKNOWN_RESOURCE_TYPE, - RPK_INVALID_RESOURCE_REF, - RPK_INVALID_LAYOUT, - RPK_MISSING_LAYOUT, - RPK_NO_PCB_OR_RESOURCES, - RPK_UNKNOWN_PCB_TYPE -}; - -const char *const error_text[16] = -{ - "No error", - "Not a RPK (zip) file", - "Module definition corrupt", - "Out of memory", - "XML format error", - "Invalid file reference", - "Zip file error", - "Unsupported zip version", - "Missing RAM length", - "Invalid RAM specification", - "Unknown resource type", - "Invalid resource reference", - "layout.xml not valid", - "Missing layout", - "No pcb or resource found", - "Unknown pcb type" -}; - class ti99_cartridge_device : public device_t, public device_image_interface { public: @@ -108,50 +69,16 @@ protected: private: - /***************** RPK support ******************** - Actually deprecated, and to be removed as soon as - softlists allow for homebrew cartridges - ***************************************************/ - - class rpk_socket; + class ti99_rpk_socket; class rpk; - class rpk_exception - { - public: - rpk_exception(rpk_open_error value): m_err(value), m_detail(nullptr) { } - rpk_exception(rpk_open_error value, const char* detail) : m_err(value), m_detail(detail) { } - - std::string to_string() - { - std::string errmsg(error_text[(int)m_err]); - if (m_detail==nullptr) - return errmsg; - return errmsg.append(": ").append(m_detail); - } - - private: - rpk_open_error m_err; - const char* m_detail; - }; - - class rpk_reader - { - public: - rpk_reader(const pcb_type *types) : m_types(types) { } - - rpk *open(emu_options &options, util::core_file &file, const char *system_name); - - private: - int find_file(util::archive_file &zip, const char *filename, uint32_t crc); - std::unique_ptr<rpk_socket> load_rom_resource(util::archive_file &zip, util::xml::data_node const* rom_resource_node, const char* socketname); - std::unique_ptr<rpk_socket> load_ram_resource(emu_options &options, util::xml::data_node const* ram_resource_node, const char* socketname, const char* system_name); - const pcb_type* m_types; - }; + static std::error_condition rpk_open(emu_options &options, std::unique_ptr<util::random_read> &&stream, const char *system_name, std::unique_ptr<rpk> &result); + static std::error_condition rpk_load_rom_resource(const rpk_socket &socket, std::unique_ptr<ti99_rpk_socket> &result); + static std::unique_ptr<ti99_rpk_socket> rpk_load_ram_resource(emu_options &options, const rpk_socket &socket, const char *system_name); class rpk { - friend class rpk_reader; + friend class ti99_cartridge_device; public: rpk(emu_options& options, const char* sysname); ~rpk(); @@ -165,29 +92,29 @@ private: emu_options& m_options; // need this to find the path to the nvram files int m_type; //const char* m_system_name; // need this to find the path to the nvram files - std::unordered_map<std::string,std::unique_ptr<rpk_socket>> m_sockets; + std::unordered_map<std::string,std::unique_ptr<ti99_rpk_socket>> m_sockets; - void add_socket(const char* id, std::unique_ptr<rpk_socket> newsock); + void add_socket(const char* id, std::unique_ptr<ti99_rpk_socket> &&newsock); }; - class rpk_socket + class ti99_rpk_socket { public: - rpk_socket(const char *id, int length, std::unique_ptr<uint8_t []> &&contents); - rpk_socket(const char *id, int length, std::unique_ptr<uint8_t []> &&contents, std::string &&pathname); - ~rpk_socket() {} + ti99_rpk_socket(const char *id, int length, std::vector<uint8_t> &&contents); + ti99_rpk_socket(const char *id, int length, std::vector<uint8_t> &&contents, std::string &&pathname); + ~ti99_rpk_socket() {} const char* id() { return m_id; } int get_content_length() { return m_length; } - uint8_t* get_contents() { return m_contents.get(); } + uint8_t* get_contents() { return &m_contents[0]; } bool persistent_ram() { return !m_pathname.empty(); } const char* get_pathname() { return m_pathname.c_str(); } - void cleanup() { m_contents.reset(); } + void cleanup() { m_contents.clear(); } private: const char* m_id; uint32_t m_length; - std::unique_ptr<uint8_t []> m_contents; + std::vector<uint8_t> m_contents; const std::string m_pathname; }; @@ -201,7 +128,7 @@ private: // RPK which is associated to this cartridge // When we close it, the contents are saved to NVRAM if available - rpk *m_rpk; + std::unique_ptr<rpk> m_rpk; }; /****************************************************************************/ |