Skip to content

Commit 7e0a17f

Browse files
authored
Merge pull request #1911 from johnbaumann/psyqo-test-command
Adding command buffer and test command
2 parents 6e9b83f + 04a955c commit 7e0a17f

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

src/mips/psyqo/cdrom-commandbuffer.hh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2025 PCSX-Redux authors
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
#pragma once
28+
29+
#include <stdint.h>
30+
31+
#include <concepts>
32+
#include <type_traits>
33+
34+
namespace psyqo::Hardware::CDRom {
35+
36+
template <typename T>
37+
concept CDRomArgumentType = std::is_integral<T>::value;
38+
39+
struct CDRomCommandBuffer {
40+
template <CDRomArgumentType... T>
41+
void set(T... values) {
42+
size = sizeof...(values);
43+
recursiveSet(0, values...);
44+
}
45+
46+
uint8_t buffer[16];
47+
uint8_t size = 0;
48+
49+
private:
50+
void recursiveSet(uint8_t pos, uint8_t arg) { buffer[pos] = arg; }
51+
52+
template <CDRomArgumentType... T>
53+
void recursiveSet(uint8_t pos, uint8_t arg, T... args) {
54+
buffer[pos] = arg;
55+
recursiveSet(pos + 1, args...);
56+
}
57+
};
58+
} // namespace psyqo::Hardware::CDRom

src/mips/psyqo/cdrom-device.hh

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ SOFTWARE.
3535
#include <cstdint>
3636
#include <type_traits>
3737

38+
#include "psyqo/cdrom-commandbuffer.hh"
3839
#include "psyqo/cdrom.hh"
3940
#include "psyqo/msf.hh"
4041
#include "psyqo/task.hh"
@@ -412,6 +413,15 @@ class CDRomDevice final : public CDRom {
412413
*/
413414
void setVolume(uint8_t leftToLeft, uint8_t rightToLeft, uint8_t leftToRight, uint8_t rightToRight);
414415

416+
/**
417+
* @brief Sends a test command to the CDRom mech
418+
*
419+
* @param callback The callback to call when the command operation is complete.
420+
*/
421+
void test(const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer, eastl::function<void(bool)> &&callback);
422+
TaskQueue::Task scheduleTest(const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer);
423+
void testBlocking(GPU &, const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer);
424+
415425
/**
416426
* @brief The action base class for the internal state machine.
417427
*

src/mips/psyqo/hardware/cdrom.hh

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ SOFTWARE.
2626

2727
#pragma once
2828

29+
#include <stdint.h>
30+
31+
#include <concepts>
32+
#include <type_traits>
33+
34+
#include "psyqo/cdrom-commandbuffer.hh"
2935
#include "psyqo/hardware/hwregs.hh"
3036

3137
namespace psyqo::Hardware::CDRom {
@@ -78,6 +84,13 @@ struct Access {
7884
};
7985

8086
struct CommandFifo {
87+
void send(CDL cmd, const CDRomCommandBuffer& commandBuffer) {
88+
Ctrl = 0;
89+
for (unsigned i = 0; i < commandBuffer.size; i++) {
90+
Fifo = commandBuffer.buffer[i];
91+
}
92+
Response = static_cast<uint8_t>(cmd);
93+
}
8194
void send(CDL cmd) {
8295
Ctrl = 0;
8396
Response = static_cast<uint8_t>(cmd);
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2025 PCSX-Redux authors
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
#include "psyqo/cdrom-device.hh"
28+
29+
#include <EASTL/atomic.h>
30+
31+
#include "psyqo/cdrom-commandbuffer.hh"
32+
#include "psyqo/hardware/cdrom.hh"
33+
#include "psyqo/kernel.hh"
34+
35+
namespace {
36+
37+
enum class TestActionState : uint8_t {
38+
IDLE,
39+
TEST,
40+
};
41+
42+
class TestAction : public psyqo::CDRomDevice::Action<TestActionState> {
43+
public:
44+
TestAction() : Action("TestAction") {}
45+
46+
void start(psyqo::CDRomDevice *device, const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer,
47+
eastl::function<void(bool)> &&callback) {
48+
psyqo::Kernel::assert(device->isIdle(), "CDRomDevice::test() called while another action is in progress");
49+
registerMe(device);
50+
setCallback(eastl::move(callback));
51+
setState(TestActionState::TEST);
52+
eastl::atomic_signal_fence(eastl::memory_order_release);
53+
psyqo::Hardware::CDRom::Command.send(psyqo::Hardware::CDRom::CDL::TEST, commandBuffer);
54+
}
55+
void start(psyqo::CDRomDevice *device, eastl::function<void(bool)> &&callback) {
56+
start(device, m_commandBuffer, eastl::move(callback));
57+
}
58+
bool complete(const psyqo::CDRomDevice::Response &) override {
59+
setSuccess(true);
60+
return true;
61+
}
62+
bool acknowledge(const psyqo::CDRomDevice::Response &response) override {
63+
setSuccess(true);
64+
return true;
65+
}
66+
67+
psyqo::Hardware::CDRom::CDRomCommandBuffer m_commandBuffer;
68+
};
69+
70+
TestAction s_testAction;
71+
72+
} // namespace
73+
74+
void psyqo::CDRomDevice::test(const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer,
75+
eastl::function<void(bool)> &&callback) {
76+
Kernel::assert(m_callback == nullptr, "CDRomDevice::test called with pending action");
77+
s_testAction.start(this, commandBuffer, eastl::move(callback));
78+
}
79+
80+
psyqo::TaskQueue::Task psyqo::CDRomDevice::scheduleTest(
81+
const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer) {
82+
s_testAction.m_commandBuffer = commandBuffer;
83+
84+
return TaskQueue::Task(
85+
[this](auto task) { s_testAction.start(this, [task](bool success) { task->complete(success); }); });
86+
}
87+
88+
void psyqo::CDRomDevice::testBlocking(GPU &gpu, const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer) {
89+
Kernel::assert(m_callback == nullptr, "CDRomDevice::testBlocking called with pending action");
90+
bool success = false;
91+
{
92+
BlockingAction blocking(this, gpu);
93+
s_testAction.start(this, commandBuffer, [&success](bool success_) { success = success_; });
94+
}
95+
}

0 commit comments

Comments
 (0)