Skip to content

Commit dafc98d

Browse files
committed
system: added fastboot
1 parent 98c23b0 commit dafc98d

File tree

8 files changed

+128
-25
lines changed

8 files changed

+128
-25
lines changed

Diff for: README.md

+4-12
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,12 @@ Currently Avocado requires OpenGL 3.2. In the future this limitation will be lif
6969

7070
## Running
7171

72-
Avocado requires the BIOS from real console in the data/bios directory.
73-
Selection of a BIOS rom will be required on the first run. The rom can be changed under Options->BIOS or by modifying the **config.json** file.
72+
Avocado requires the BIOS from real console in the `data/bios` directory. (use `File->Open Avocado directory` to locate the directory on your system)
73+
Selection of a BIOS rom will be required on the first run. The rom can be changed under `Options->BIOS` or by modifying the **config.json** file.
7474

75-
Avocado doesn't support fast booting. [UniROM](http://www.psxdev.net/forum/viewtopic.php?t=722) can be used as a work around. Place the .rom file in the data/bios directory and modify **config.json**:
76-
```
77-
"extension": "data/bios/unirom_caetlaNTSC_plugin.rom"
78-
```
79-
80-
Press the **Start** button (Enter by default) to fastboot, or **R2** (keypad *) to slowboot a game.
81-
You can run the included Playstation firmware replacement *Caetla* with the **Select** button (Right shift) then run the .exe directly from the disk.
82-
83-
To load a .cue/.bin/.img/.chd file just drag and drop it.
75+
To load a `.cue/.bin/.img/.chd` or `.exe/.psexe/.psf/.minipsf` file just drag and drop it.
8476

85-
PAL games with LibCrypt protection need additional subchannel info - download proper file .SBI or .LSD file from [Redump](http://redump.org/discs/system/psx/), place it in the same folder as game image and make sure has identical name as .cue/.bin/... file.
77+
PAL games with LibCrypt protection need additional subchannel info - download proper file `.SBI` or `.LSD` file from [Redump](http://redump.org/discs/system/psx/), place it in the same folder as game image and make sure has identical name as `.cue/.bin/...` file.
8678

8779
## Controls
8880

Diff for: src/disc/load.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
#include "load.h"
2+
#include <array>
23
#include "disc/format/chd_format.h"
34
#include "disc/format/cue_parser.h"
45
#include "utils/file.h"
56

67
namespace disc {
8+
const std::array<std::string, 5> discFormats = {
9+
"chd", "cue", "iso", "bin", "img",
10+
};
11+
12+
bool isDiscImage(const std::string& path) {
13+
std::string ext = getExtension(path);
14+
transform(ext.begin(), ext.end(), ext.begin(), tolower);
15+
16+
return std::find(discFormats.begin(), discFormats.end(), ext) != discFormats.end();
17+
}
18+
719
std::unique_ptr<disc::Disc> load(const std::string& path) {
820
std::string ext = getExtension(path);
921
transform(ext.begin(), ext.end(), ext.begin(), tolower);

Diff for: src/disc/load.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
#include "disc.h"
55

66
namespace disc {
7+
bool isDiscImage(const std::string& path);
78
std::unique_ptr<disc::Disc> load(const std::string& path);
8-
}
9+
} // namespace disc

Diff for: src/platform/windows/gui/file/open.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool Open::onFileSelected(const gui::helper::File& f) {
2424
auto path = f.entry.path();
2525
config.gui.lastPath = path.parent_path().string();
2626

27-
bus.notify(Event::File::Load{path.string(), true});
27+
bus.notify(Event::File::Load{path.string()});
2828
return true;
2929
}
3030

Diff for: src/platform/windows/gui/gui.cpp

+49-4
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,22 @@ void GUI::render(std::unique_ptr<System>& sys) {
292292
aboutHelp.displayWindows();
293293
}
294294

295+
toasts.display();
296+
295297
if (!config.isEmulatorConfigured() && !notInitializedWindowShown) {
296298
notInitializedWindowShown = true;
297299
ImGui::OpenPopup("Avocado");
300+
} else if (droppedItem) {
301+
if (!droppedItemDialogShown) {
302+
droppedItemDialogShown = true;
303+
ImGui::OpenPopup("Disc");
304+
}
305+
} else {
306+
drawControls(sys);
298307
}
299308

300-
toasts.display();
301-
302-
if (config.isEmulatorConfigured()) {
303-
drawControls(sys);
309+
if (droppedItem) {
310+
discDialog();
304311
}
305312

306313
// Work in progress
@@ -310,6 +317,44 @@ void GUI::render(std::unique_ptr<System>& sys) {
310317
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
311318
}
312319

320+
void GUI::discDialog() {
321+
if (!ImGui::BeginPopupModal("Disc", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize)) {
322+
return;
323+
}
324+
325+
ImGui::Text("%s", getFilenameExt(*droppedItem).c_str());
326+
if (ImGui::Button("Boot")) {
327+
bus.notify(Event::File::Load{*droppedItem, Event::File::Load::Action::slowboot});
328+
ImGui::CloseCurrentPopup();
329+
}
330+
if (ImGui::IsItemHovered()) ImGui::SetTooltip("Restart console and boot the CD");
331+
332+
ImGui::SameLine();
333+
if (ImGui::Button("Fast boot")) {
334+
bus.notify(Event::File::Load{*droppedItem, Event::File::Load::Action::fastboot});
335+
ImGui::CloseCurrentPopup();
336+
}
337+
if (ImGui::IsItemHovered()) ImGui::SetTooltip("Restart console and boot the CD (skipping BIOS intro)");
338+
339+
ImGui::SameLine();
340+
if (ImGui::Button("Swap disc")) {
341+
bus.notify(Event::File::Load{*droppedItem, Event::File::Load::Action::swap});
342+
ImGui::CloseCurrentPopup();
343+
}
344+
if (ImGui::IsItemHovered()) ImGui::SetTooltip("Swap currently inserted disc");
345+
ImGui::SameLine();
346+
347+
if (ImGui::Button("Cancel")) {
348+
ImGui::CloseCurrentPopup();
349+
}
350+
ImGui::EndPopup();
351+
352+
if (!ImGui::IsPopupOpen("Disc")) {
353+
droppedItem = {};
354+
droppedItemDialogShown = false;
355+
}
356+
}
357+
313358
void GUI::drawControls(std::unique_ptr<System>& sys) {
314359
auto symbolButton = [](const char* hint, const char* symbol, ImVec4 bg = ImVec4(1, 1, 1, 0.08f)) -> bool {
315360
auto padding = ImGui::GetStyle().FramePadding;

Diff for: src/platform/windows/gui/gui.h

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <SDL.h>
3+
#include <optional>
34
#include "file/open.h"
45
#include "debug/cdrom.h"
56
#include "debug/cpu.h"
@@ -40,6 +41,7 @@ class GUI {
4041
gui::Toasts toasts;
4142

4243
void mainMenu(std::unique_ptr<System>& sys);
44+
void discDialog();
4345
void drawControls(std::unique_ptr<System>& sys);
4446
void renderController();
4547

@@ -55,6 +57,10 @@ class GUI {
5557
bool statusFramelimitter = true;
5658
bool statusMouseLocked = false;
5759

60+
// Drag&drop
61+
std::optional<std::string> droppedItem;
62+
bool droppedItemDialogShown = false;
63+
5864
GUI(SDL_Window* window, void* glContext);
5965
~GUI();
6066

Diff for: src/platform/windows/main.cpp

+47-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string>
88
#include "config.h"
99
#include "config_parser.h"
10+
#include "disc/load.h"
1011
#include "gui/filesystem.h"
1112
#include "gui/gui.h"
1213
#include "input/sdl_input_manager.h"
@@ -191,15 +192,56 @@ int main(int argc, char** argv) {
191192
return 1;
192193
}
193194

195+
auto gui = std::make_unique<GUI>(window, glContext);
194196
Sound::init();
195197

196198
std::unique_ptr<System> sys = system_tools::hardReset();
197199

198200
int busToken = bus.listen<Event::File::Load>([&](auto e) {
199-
bool isPaused = sys->state == System::State::pause;
200-
if (e.reset) {
201-
sys = system_tools::hardReset();
201+
if (disc::isDiscImage(e.file)) {
202+
if (e.action == Event::File::Load::Action::ask) {
203+
// Show dialog and decide what to do
204+
gui->droppedItem = e.file;
205+
return;
206+
}
207+
208+
std::unique_ptr<disc::Disc> disc = disc::load(e.file);
209+
if (!disc) {
210+
toast(fmt::format("Cannot load {}", getFilenameExt(e.file)));
211+
return;
212+
}
213+
214+
if (e.action == Event::File::Load::Action::slowboot) {
215+
system_tools::bootstrap(sys);
216+
sys->cdrom->disc = std::move(disc);
217+
sys->cdrom->setShell(false);
218+
sys->state = System::State::run;
219+
220+
toast("System restarted");
221+
return;
222+
} else if (e.action == Event::File::Load::Action::fastboot) {
223+
system_tools::bootstrap(sys);
224+
sys->cdrom->disc = std::move(disc);
225+
sys->cdrom->setShell(false);
226+
227+
// BIOS is at 0x80030000 after bootstrap, forcing CPU to return
228+
// will skip the boot animation and go straight to the CD boot
229+
230+
sys->cpu->setPC(sys->cpu->reg[31]);
231+
sys->state = System::State::run;
232+
233+
toast("Fastboot");
234+
return;
235+
} else if (e.action == Event::File::Load::Action::swap) {
236+
sys->cdrom->disc = std::move(disc);
237+
sys->cdrom->setShell(false);
238+
239+
toast("Disc swapped");
240+
return;
241+
}
202242
}
243+
244+
bool isPaused = sys->state == System::State::pause;
203245
system_tools::loadFile(sys, e.file);
204246
sys->state = isPaused ? System::State::pause : System::State::run;
205247
});
@@ -238,8 +280,6 @@ int main(int argc, char** argv) {
238280
auto inputManager = std::make_unique<SdlInputManager>();
239281
InputManager::setInstance(inputManager.get());
240282

241-
auto gui = std::make_unique<GUI>(window, glContext);
242-
243283
if (!sys->isSystemReady()) {
244284
sys->state = System::State::stop;
245285
} else {
@@ -335,7 +375,8 @@ int main(int argc, char** argv) {
335375
if (event.type == SDL_DROPFILE) {
336376
std::string path = event.drop.file;
337377
SDL_free(event.drop.file);
338-
system_tools::loadFile(sys, path);
378+
379+
bus.notify(Event::File::Load{path});
339380
}
340381
if (event.type == SDL_WINDOWEVENT
341382
&& (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED || event.window.event == SDL_WINDOWEVENT_RESIZED)) {

Diff for: src/utils/event.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ struct Spu {};
1414

1515
namespace File {
1616
struct Load {
17+
enum class Action {
18+
ask,
19+
slowboot,
20+
fastboot,
21+
swap,
22+
};
1723
std::string file;
18-
bool reset;
24+
Action action = Action::ask;
1925
};
2026
struct Exit {};
2127
}; // namespace File

0 commit comments

Comments
 (0)