|
| 1 | +//////////////////////////////////////////////////////////////////////////////// |
| 2 | +// Copyright 2015 by Joseph Forgione |
| 3 | +// This file is part of VCC (Virtual Color Computer). |
| 4 | +// |
| 5 | +// VCC (Virtual Color Computer) is free software: you can redistribute itand/or |
| 6 | +// modify it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or (at your |
| 8 | +// option) any later version. |
| 9 | +// |
| 10 | +// VCC (Virtual Color Computer) is distributed in the hope that it will be |
| 11 | +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 13 | +// Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License along with |
| 16 | +// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>. |
| 17 | +//////////////////////////////////////////////////////////////////////////////// |
| 18 | +#pragma once |
| 19 | +#include "host_cartridge_context.h" |
| 20 | +#include <vcc/core/cartridge.h> |
| 21 | +#include <vcc/core/cartridge_loader.h> |
| 22 | +#include "../CartridgeMenu.h" |
| 23 | + |
| 24 | + |
| 25 | +namespace vcc { namespace modules { namespace mpi |
| 26 | +{ |
| 27 | + |
| 28 | + class cartridge_slot |
| 29 | + { |
| 30 | + public: |
| 31 | + |
| 32 | + using name_type = ::vcc::core::cartridge::name_type; |
| 33 | + using catalog_id_type = ::vcc::core::cartridge::catalog_id_type; |
| 34 | + using path_type = ::std::string; |
| 35 | + using label_type = ::std::string; |
| 36 | + using handle_type = ::vcc::core::cartridge_loader_result::handle_type; |
| 37 | + using cartridge_ptr_type = ::std::unique_ptr<::vcc::core::cartridge>; |
| 38 | + using menu_item_type = CartMenuItem; |
| 39 | + using menu_item_collection_type = std::vector<menu_item_type>; |
| 40 | + using context_type = host_cartridge_context;// ::vcc::core::cartridge_context; |
| 41 | + |
| 42 | + |
| 43 | + public: |
| 44 | + |
| 45 | + cartridge_slot(); |
| 46 | + cartridge_slot(path_type path, handle_type handle, cartridge_ptr_type cartridge); |
| 47 | + cartridge_slot(const cartridge_slot&) = delete; |
| 48 | + cartridge_slot(cartridge_slot&&) = delete; |
| 49 | + |
| 50 | + cartridge_slot& operator=(const cartridge_slot& other) = delete; |
| 51 | + cartridge_slot& operator=(cartridge_slot&& other) noexcept; |
| 52 | + |
| 53 | + bool empty() const |
| 54 | + { |
| 55 | + return path_.empty(); |
| 56 | + } |
| 57 | + |
| 58 | + const path_type& path() const |
| 59 | + { |
| 60 | + return path_; |
| 61 | + } |
| 62 | + |
| 63 | + name_type name() const |
| 64 | + { |
| 65 | + return cartridge_->name(); |
| 66 | + } |
| 67 | + |
| 68 | + catalog_id_type catalog_id() const |
| 69 | + { |
| 70 | + return cartridge_->catalog_id(); |
| 71 | + } |
| 72 | + |
| 73 | + label_type label() const; |
| 74 | + |
| 75 | + void start() const |
| 76 | + { |
| 77 | + cartridge_->start(); |
| 78 | + } |
| 79 | + |
| 80 | + void reset() const |
| 81 | + { |
| 82 | + cartridge_->reset(); |
| 83 | + } |
| 84 | + |
| 85 | + void heartbeat() const |
| 86 | + { |
| 87 | + cartridge_->heartbeat(); |
| 88 | + } |
| 89 | + |
| 90 | + void write_port(unsigned char port_id, unsigned char value) const |
| 91 | + { |
| 92 | + cartridge_->write_port(port_id, value); |
| 93 | + } |
| 94 | + |
| 95 | + unsigned char read_port(unsigned char port_id) const |
| 96 | + { |
| 97 | + return cartridge_->read_port(port_id); |
| 98 | + } |
| 99 | + |
| 100 | + unsigned char read_memory_byte(unsigned short memory_address) const |
| 101 | + { |
| 102 | + return cartridge_->read_memory_byte(memory_address); |
| 103 | + } |
| 104 | + |
| 105 | + void status(char* status) const |
| 106 | + { |
| 107 | + cartridge_->status(status); |
| 108 | + } |
| 109 | + |
| 110 | + unsigned short sample_audio() const |
| 111 | + { |
| 112 | + return cartridge_->sample_audio(); |
| 113 | + } |
| 114 | + |
| 115 | + void menu_item_clicked(unsigned char item_id) const |
| 116 | + { |
| 117 | + return cartridge_->menu_item_clicked(item_id); |
| 118 | + } |
| 119 | + |
| 120 | + void line_state(bool state) |
| 121 | + { |
| 122 | + line_state_ = state; |
| 123 | + } |
| 124 | + |
| 125 | + bool line_state() const |
| 126 | + { |
| 127 | + return line_state_; |
| 128 | + } |
| 129 | + |
| 130 | + void reset_menu() |
| 131 | + { |
| 132 | + menu_items_.clear(); |
| 133 | + } |
| 134 | + |
| 135 | + void append_menu_item(const menu_item_type& item) |
| 136 | + { |
| 137 | + menu_items_.push_back(item); |
| 138 | + } |
| 139 | + |
| 140 | + void enumerate_menu_items(context_type& context) const |
| 141 | + { |
| 142 | + for (const auto& item : menu_items_) |
| 143 | + { |
| 144 | + context.add_menu_item(item.name.c_str(), item.menu_id, item.type); |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + |
| 149 | + private: |
| 150 | + |
| 151 | + path_type path_; |
| 152 | + handle_type handle_; |
| 153 | + cartridge_ptr_type cartridge_; |
| 154 | + menu_item_collection_type menu_items_; |
| 155 | + bool line_state_ = false; |
| 156 | + }; |
| 157 | + |
| 158 | +} } } |
0 commit comments