Skip to content

Commit 5f2aa81

Browse files
ChetSimpsonejaquay
authored andcommitted
refactor mpi to use cartride and cartridge loader
- move mpi cartridge code into multipak_cartridge - separate ui from multipak cartridge implementation
1 parent 9503224 commit 5f2aa81

13 files changed

+1279
-778
lines changed

mpi/cartridge_slot.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
#include "cartridge_slot.h"
19+
#include <vcc/core/cartridges/null_cartridge.h>
20+
21+
22+
namespace vcc { namespace modules { namespace mpi
23+
{
24+
25+
cartridge_slot::cartridge_slot()
26+
: cartridge_(std::make_unique<::vcc::core::cartridges::null_cartridge>())
27+
{}
28+
29+
cartridge_slot::cartridge_slot(path_type path, handle_type handle, cartridge_ptr_type cartridge)
30+
:
31+
path_(move(path)),
32+
handle_(move(handle)),
33+
cartridge_(move(cartridge))
34+
{}
35+
36+
cartridge_slot& cartridge_slot::operator=(cartridge_slot&& other) noexcept
37+
{
38+
if (this != &other)
39+
{
40+
// Destroy the cartrige first before the handle is released
41+
// in case this is the last reference to the shared library
42+
cartridge_.reset();
43+
handle_.reset();
44+
45+
path_ = move(other.path_);
46+
handle_ = move(other.handle_);
47+
cartridge_ = move(other.cartridge_);
48+
menu_items_ = move(other.menu_items_);
49+
line_state_ = other.line_state_;
50+
51+
other.line_state_ = false;
52+
}
53+
54+
return *this;
55+
}
56+
57+
58+
cartridge_slot::label_type cartridge_slot::label() const
59+
{
60+
std::string text;
61+
62+
text += cartridge_->name();
63+
text += " ";
64+
text += cartridge_->catalog_id();
65+
66+
return text;
67+
}
68+
69+
} } }

mpi/cartridge_slot.h

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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

Comments
 (0)