Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
cdcheck.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2026 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <stdint.h>
30
31#include "psyqo/cdrom-device.hh"
32#include "psyqo/coroutine.hh"
34
35namespace psyqo {
36class GPU;
37}
38
39namespace shello {
40
41// Replaces the original shell's hand-rolled CD-ROM state machine (cdrom.c).
42// The original walked the controller protocol by hand each frame: reset, get
43// TOC/ID, read the PVD, validate the "CD001" signature, read the root
44// directory and scan it for PSX.EXE;1 / SYSTEM.CNF;1. psyqo's CDRomDevice and
45// ISO9660Parser do all of that, so this is a coroutine that loops the same
46// decision and publishes an observable state for the scene to react to.
47//
48// Note: like the original, audio-CD detection is not implemented (the original
49// defined CD_SUCCESS_AUDIO but never reached it, so isCDAudio() was always
50// false). isAudio() is kept as a faithful stub.
51class CDChecker {
52 public:
53 enum class State {
54 Checking, // probe in progress, no verdict yet
55 Error, // no recognizable PlayStation disc (sticky across retries)
56 Success, // a bootable data disc was found
57 };
58
59 // Must be called from the Application's prepare() (after gpu().initialize()).
60 void prepare(psyqo::GPU &gpu);
61 // Kicks off the probe coroutine; call once from createScene().
62 void start();
63
64 State state() const { return m_state; }
65 bool isError() const { return m_state == State::Error; }
66 bool isSuccess() const { return m_state == State::Success; }
67 bool isAudio() const { return false; }
68
69 private:
70 psyqo::Coroutine<> probe();
71
72 psyqo::GPU *m_gpu = nullptr;
73 psyqo::CDRomDevice m_cdrom;
74 psyqo::ISO9660Parser m_isoParser = psyqo::ISO9660Parser(&m_cdrom);
75 psyqo::Coroutine<> m_coroutine;
76 State m_state = State::Checking;
77};
78
79} // namespace shello
A specialization of the CDRom interface.
Definition cdrom-device.hh:80
The singleton GPU class.
Definition gpu.hh:79
An ISO9660 parser.
Definition iso9660-parser.hh:48
Definition cdcheck.hh:51
State
Definition cdcheck.hh:53
bool isAudio() const
Definition cdcheck.hh:67
bool isError() const
Definition cdcheck.hh:65
bool isSuccess() const
Definition cdcheck.hh:66
State state() const
Definition cdcheck.hh:64
void prepare(psyqo::GPU &gpu)
Definition cdcheck.cpp:33
void start()
Definition cdcheck.cpp:38
Definition lua.hh:38
Definition cdcheck.cpp:31
A suitable type to hold and return a C++20 coroutine.
Definition coroutine.hh:54