Skip to content

Commit

Permalink
Adding blocking reset and reads + adding reset in example.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasnoble committed Oct 1, 2024
1 parent 5d9e150 commit a0a2774
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mips/psyqo/cdrom-device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class CDRomDevice final : public CDRom {
*/
void reset(eastl::function<void(bool)> &&callback);
TaskQueue::Task scheduleReset();
bool resetBlocking(GPU &);

/**
* @brief Reads sectors from the CDRom.
Expand All @@ -151,6 +152,7 @@ class CDRomDevice final : public CDRom {
*/
void readSectors(uint32_t sector, uint32_t count, void *buffer, eastl::function<void(bool)> &&callback) override;
TaskQueue::Task scheduleReadSectors(uint32_t sector, uint32_t count, void *buffer);
bool readSectorsBlocking(uint32_t sector, uint32_t count, void *buffer, GPU &);

/**
* @brief Gets the size of the Table of Contents from the CDRom. Note that
Expand Down
3 changes: 3 additions & 0 deletions src/mips/psyqo/examples/cdda/cdda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ void CDDA::loopPlaybackTrack(unsigned track) {
void CDDA::createScene() {
m_font.uploadSystemFont(gpu());
pushScene(&cddaScene);
syscall_puts("CD-Rom device reset...\n");
m_cdrom.resetBlocking(gpu());
syscall_puts("CD-Rom device ready, getting TOC size...\n");
auto tocSize = m_cdrom.getTOCSizeBlocking(gpu());
ramsyscall_printf("CD-Rom track count: %d\n", tocSize);
// Start playback of track 2, which is a good
Expand Down
10 changes: 10 additions & 0 deletions src/mips/psyqo/src/cdrom-device-readsectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,13 @@ psyqo::TaskQueue::Task psyqo::CDRomDevice::scheduleReadSectors(uint32_t sector,
readSectors(sector, count, buffer, [task](bool success) { task->complete(success); });
});
}

bool psyqo::CDRomDevice::readSectorsBlocking(uint32_t sector, uint32_t count, void *buffer, GPU &gpu) {
Kernel::assert(m_callback == nullptr, "CDRomDevice::readSectorsBlocking called with pending action");
bool success = false;
{
BlockingAction blocking(this, gpu);
s_readSectorsAction.start(this, sector, count, buffer, [&success](bool success_) { success = success_; });
}
return success;
}
11 changes: 11 additions & 0 deletions src/mips/psyqo/src/cdrom-device-reset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,14 @@ void psyqo::CDRomDevice::reset(eastl::function<void(bool)> &&callback) {
psyqo::TaskQueue::Task psyqo::CDRomDevice::scheduleReset() {
return TaskQueue::Task([this](auto task) { reset([task](bool success) { task->complete(success); }); });
}

bool psyqo::CDRomDevice::resetBlocking(GPU &gpu) {
Kernel::assert(m_callback == nullptr, "CDRomDevice::resetBlocking called with pending action");
unsigned size = 0;
bool success = false;
{
BlockingAction blocking(this, gpu);
s_resetAction.start(this, [&success](bool success_) { success = success_; });
}
return success;
}

0 comments on commit a0a2774

Please sign in to comment.