Nugget
Loading...
Searching...
No Matches
cdrom.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2022 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 <EASTL/functional.h>
30#include <stdint.h>
31
32#include <coroutine>
33
34#include "psyqo/task.hh"
35
36namespace psyqo {
37
46class CDRom {
47 struct ReadSectorsAwaiter {
48 ReadSectorsAwaiter(uint32_t sector, uint32_t count, void *buffer, CDRom &cdrom)
49 : m_sector(sector), m_count(count), m_buffer(buffer), m_cdrom(cdrom) {}
50 ~ReadSectorsAwaiter() {}
51 constexpr bool await_ready() const { return false; }
52 template <typename U>
53 void await_suspend(std::coroutine_handle<U> handle) {
54 m_cdrom.readSectors(m_sector, m_count, m_buffer, [handle, this](bool result) {
55 m_result = result;
56 handle.resume();
57 });
58 }
59 bool await_resume() { return m_result; }
60
61 private:
62 uint32_t m_sector;
63 uint32_t m_count;
64 void *m_buffer;
65 CDRom &m_cdrom;
66 bool m_result;
67 };
68
69 public:
70 virtual ~CDRom() {}
78 struct ReadRequest {
81 void *buffer = nullptr;
82 };
83
99 virtual void readSectors(uint32_t sector, uint32_t count, void *buffer, eastl::function<void(bool)> &&callback) = 0;
100
113
126
140 return {sector, count, buffer, *this};
141 }
142
143 private:
144 ReadRequest m_readRequest;
145};
146
147} // namespace psyqo
The base CDRom class.
Definition cdrom.hh:46
TaskQueue::Task scheduleReadRequest(ReadRequest *request)
Schedule a read operation.
Definition cdrom.cpp:39
virtual void readSectors(uint32_t sector, uint32_t count, void *buffer, eastl::function< void(bool)> &&callback)=0
Read a sector from the CDRom.
virtual ~CDRom()
Definition cdrom.hh:70
ReadSectorsAwaiter readSectorsForCoroutine(uint32_t sector, uint32_t count, void *buffer)
Wrapper around the readSectors method for coroutines.
Definition cdrom.hh:139
TaskQueue::Task scheduleReadSectors(uint32_t sector, uint32_t count, void *buffer)
Schedule a read operation.
Definition cdrom.cpp:29
The Task class.
Definition task.hh:140
void * result
Definition memcpy.c:47
Definition cdrom-loader.hh:39
An asynchronous read request.
Definition cdrom.hh:78
void * buffer
Definition cdrom.hh:81
uint32_t LBA
Definition cdrom.hh:79
uint32_t count
Definition cdrom.hh:80
static void * buffer
Definition syscalls.h:230
static const void size_t count
Definition syscalls.h:145
static int sector
Definition syscalls.h:467
void uint32_t(classId, spec)