Skip to content

Adding command buffer and test command #1911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/mips/psyqo/cdrom-commandbuffer.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*

MIT License

Copyright (c) 2025 PCSX-Redux authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

#pragma once

#include <stdint.h>

#include <concepts>
#include <type_traits>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're missing a namespace here. Probably psyqo::Hardware::CDRom

namespace psyqo::Hardware::CDRom {

template <typename T>
concept CDRomArgumentType = std::is_integral<T>::value;

struct CDRomCommandBuffer {
template <CDRomArgumentType... T>
void set(T... values) {
size = sizeof...(values);
recursiveSet(0, values...);
}

uint8_t buffer[16];
uint8_t size = 0;

private:
void recursiveSet(uint8_t pos, uint8_t arg) { buffer[pos] = arg; }

template <CDRomArgumentType... T>
void recursiveSet(uint8_t pos, uint8_t arg, T... args) {
buffer[pos] = arg;
recursiveSet(pos + 1, args...);
}
};
} // namespace psyqo::Hardware::CDRom
10 changes: 10 additions & 0 deletions src/mips/psyqo/cdrom-device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SOFTWARE.
#include <cstdint>
#include <type_traits>

#include "psyqo/cdrom-commandbuffer.hh"
#include "psyqo/cdrom.hh"
#include "psyqo/msf.hh"
#include "psyqo/task.hh"
Expand Down Expand Up @@ -412,6 +413,15 @@ class CDRomDevice final : public CDRom {
*/
void setVolume(uint8_t leftToLeft, uint8_t rightToLeft, uint8_t leftToRight, uint8_t rightToRight);

/**
* @brief Sends a test command to the CDRom mech
*
* @param callback The callback to call when the command operation is complete.
*/
void test(const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer, eastl::function<void(bool)> &&callback);
TaskQueue::Task scheduleTest(const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer);
void testBlocking(GPU &, const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer);

/**
* @brief The action base class for the internal state machine.
*
Expand Down
13 changes: 13 additions & 0 deletions src/mips/psyqo/hardware/cdrom.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ SOFTWARE.

#pragma once

#include <stdint.h>

#include <concepts>
#include <type_traits>

#include "psyqo/cdrom-commandbuffer.hh"
#include "psyqo/hardware/hwregs.hh"

namespace psyqo::Hardware::CDRom {
Expand Down Expand Up @@ -78,6 +84,13 @@ struct Access {
};

struct CommandFifo {
void send(CDL cmd, const CDRomCommandBuffer& commandBuffer) {
Ctrl = 0;
for (unsigned i = 0; i < commandBuffer.size; i++) {
Fifo = commandBuffer.buffer[i];
}
Response = static_cast<uint8_t>(cmd);
}
void send(CDL cmd) {
Ctrl = 0;
Response = static_cast<uint8_t>(cmd);
Expand Down
95 changes: 95 additions & 0 deletions src/mips/psyqo/src/cdrom-device-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*

MIT License

Copyright (c) 2025 PCSX-Redux authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

#include "psyqo/cdrom-device.hh"

#include <EASTL/atomic.h>

#include "psyqo/cdrom-commandbuffer.hh"
#include "psyqo/hardware/cdrom.hh"
#include "psyqo/kernel.hh"

namespace {

enum class TestActionState : uint8_t {
IDLE,
TEST,
};

class TestAction : public psyqo::CDRomDevice::Action<TestActionState> {
public:
TestAction() : Action("TestAction") {}

void start(psyqo::CDRomDevice *device, const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer,
eastl::function<void(bool)> &&callback) {
psyqo::Kernel::assert(device->isIdle(), "CDRomDevice::test() called while another action is in progress");
registerMe(device);
setCallback(eastl::move(callback));
setState(TestActionState::TEST);
eastl::atomic_signal_fence(eastl::memory_order_release);
psyqo::Hardware::CDRom::Command.send(psyqo::Hardware::CDRom::CDL::TEST, commandBuffer);
}
void start(psyqo::CDRomDevice *device, eastl::function<void(bool)> &&callback) {
start(device, m_commandBuffer, eastl::move(callback));
}
bool complete(const psyqo::CDRomDevice::Response &) override {
setSuccess(true);
return true;
}
bool acknowledge(const psyqo::CDRomDevice::Response &response) override {
setSuccess(true);
return true;
}

psyqo::Hardware::CDRom::CDRomCommandBuffer m_commandBuffer;
};

TestAction s_testAction;

} // namespace

void psyqo::CDRomDevice::test(const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer,
eastl::function<void(bool)> &&callback) {
Kernel::assert(m_callback == nullptr, "CDRomDevice::test called with pending action");
s_testAction.start(this, commandBuffer, eastl::move(callback));
}

psyqo::TaskQueue::Task psyqo::CDRomDevice::scheduleTest(
const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer) {
s_testAction.m_commandBuffer = commandBuffer;

return TaskQueue::Task(
[this](auto task) { s_testAction.start(this, [task](bool success) { task->complete(success); }); });
}

void psyqo::CDRomDevice::testBlocking(GPU &gpu, const psyqo::Hardware::CDRom::CDRomCommandBuffer &commandBuffer) {
Kernel::assert(m_callback == nullptr, "CDRomDevice::testBlocking called with pending action");
bool success = false;
{
BlockingAction blocking(this, gpu);
s_testAction.start(this, commandBuffer, [&success](bool success_) { success = success_; });
}
}
Loading