Skip to content

Commit 27905a8

Browse files
remutroLukeUsher
authored andcommitted
Add ability to change disc for ldrom2 titles
1 parent 2f2704b commit 27905a8

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

ares/pce/pcd/pcd.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ auto PCD::load(Node::Object parent) -> void {
2626
tray->setType("Compact Disc");
2727
}
2828
tray->setHotSwappable(true);
29-
tray->setAllocate([&](auto name) { return allocate(tray); });
29+
tray->setAllocate([&](auto name) { return allocate(tray, name); });
3030
tray->setConnect([&] { return connect(); });
3131
tray->setDisconnect([&] { return disconnect(); });
3232

@@ -99,9 +99,11 @@ auto PCD::unload() -> void {
9999
node.reset();
100100
}
101101

102-
auto PCD::allocate(Node::Port parent) -> Node::Peripheral {
102+
auto PCD::allocate(Node::Port parent, string name) -> Node::Peripheral {
103103
if (Model::LaserActive()) {
104-
return disc = parent->append<Node::Peripheral>("Laserdisc");
104+
disc = parent->append<Node::Peripheral>("Laserdisc");
105+
disc->setAttribute("media", name);
106+
return disc;
105107
}
106108
return disc = parent->append<Node::Peripheral>("PC Engine CD Disc");
107109
}
@@ -142,6 +144,9 @@ auto PCD::disconnect() -> void {
142144
fd.reset();
143145
pak.reset();
144146
disc.reset();
147+
if(Model::LaserActive()) {
148+
ld.notifyDiscEjected();
149+
}
145150
}
146151

147152
auto PCD::save() -> void {

ares/pce/pcd/pcd.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct PCD : Thread {
3434
auto load(Node::Object) -> void;
3535
auto unload() -> void;
3636

37-
auto allocate(Node::Port) -> Node::Peripheral;
37+
auto allocate(Node::Port, string name) -> Node::Peripheral;
3838
auto connect() -> void;
3939
auto disconnect() -> void;
4040

desktop-ui/emulator/pc-engine-ld.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
struct PCEngineLD : PCEngine {
22
PCEngineLD();
33
auto load() -> LoadResult override;
4+
auto load(Menu) -> void override;
5+
auto unload() -> void override;
46
auto save() -> bool override;
57
auto pak(ares::Node::Object) -> std::shared_ptr<vfs::directory> override;
8+
auto changeDiskState(const string state) -> void;
69

710
std::shared_ptr<mia::Pak> hucard;
811
u32 internalBiosId = 0;
912
maybe<u32> hucardBiosId;
13+
sTimer discTrayTimer;
1014
};
1115

1216
PCEngineLD::PCEngineLD() {
@@ -89,10 +93,56 @@ auto PCEngineLD::load() -> LoadResult {
8993
}
9094

9195
connectPorts();
96+
discTrayTimer = Timer{};
9297

9398
return successful;
9499
}
95100

101+
auto PCEngineLD::load(Menu menu) -> void {
102+
Group group;
103+
Menu changeSideMenu{&menu};
104+
changeSideMenu.setIcon(Icon::Device::Optical);
105+
changeSideMenu.setText("Change Side");
106+
auto medium = game->pak->attribute("medium");
107+
auto sides = nall::split_and_strip(medium, ",");
108+
109+
MenuRadioItem noDiscItem{&changeSideMenu};
110+
noDiscItem.setText("No Disc").onActivate([&] {
111+
changeDiskState("No Disc");
112+
});
113+
group.append(noDiscItem);
114+
115+
auto checkedItemIndex = group.objectCount();
116+
for(auto side : sides) {
117+
MenuRadioItem item{&changeSideMenu};
118+
group.append(item);
119+
item.setText(side).onActivate([this, side] {changeDiskState(side);});
120+
}
121+
group.objects<MenuRadioItem>()[checkedItemIndex].setChecked();
122+
}
123+
124+
auto PCEngineLD::changeDiskState(const string state) -> void {
125+
Program::Guard guard;
126+
discTrayTimer->setEnabled(false);
127+
save();
128+
auto tray = root->find<ares::Node::Port>("PC Engine LD/Disc Tray");
129+
tray->disconnect();
130+
131+
if(state == "No Disc") return;
132+
133+
discTrayTimer->onActivate([&, state] {
134+
discTrayTimer->setEnabled(false);
135+
auto tray = root->find<ares::Node::Port>("PC Engine LD/Disc Tray");
136+
tray->allocate(state);
137+
tray->connect();
138+
}).setInterval(3000).setEnabled();
139+
}
140+
141+
auto PCEngineLD::unload() -> void {
142+
Emulator::unload();
143+
discTrayTimer.reset();
144+
}
145+
96146
auto PCEngineLD::save() -> bool {
97147
root->save();
98148
system->save(game->location);

0 commit comments

Comments
 (0)