Get rough shape of CD file processing code

This commit is contained in:
Jaby
2023-02-18 09:35:15 +01:00
committed by Jaby
parent c1b8b54eb5
commit 672ad04c83
7 changed files with 121 additions and 24 deletions

View File

@@ -5,7 +5,61 @@
namespace JabyEngine {
namespace CD {
namespace internal {
enum struct State {
Free = 0,
Done = 0,
Reading,
BufferFull,
Error,
};
extern VolatilePOD<CD_IO::Interrupt::Type> last_interrupt;
extern VolatilePOD<State> state;
struct Sector {
uint32_t data[512];
};
struct FileInfo {
uint16_t lba;
uint16_t sectors;
constexpr FileInfo(uint16_t lba, uint16_t sectors) : lba(lba), sectors(sectors) {
}
};
class SectorBufferAllocator {
private:
struct Dummy {
};
typedef Sector* (*SimpleAllocator)();
typedef Sector* (Dummy::*ComplexAllocator)();
private:
Dummy* this_ctx = nullptr;
union {
SimpleAllocator allocate;
ComplexAllocator this_allocate;
};
SectorBufferAllocator(SimpleAllocator allocate) : this_ctx(nullptr), allocate(allocate) {
}
SectorBufferAllocator(Dummy* ctx, ComplexAllocator this_allocate) : this_ctx(ctx), this_allocate(this_allocate) {
}
public:
static SectorBufferAllocator create(SimpleAllocator allocate) {
return SectorBufferAllocator(allocate);
}
template<typename T>
static SectorBufferAllocator create(T &obj, Sector* (T::*obj_allocate)()) {
return SectorBufferAllocator(reinterpret_cast<Dummy*>(&obj), reinterpret_cast<ComplexAllocator>(obj_allocate));
}
};
struct Command {
static void wait_until(CD_IO::Interrupt::Type irq) {
@@ -26,6 +80,8 @@ namespace JabyEngine {
wait_until(cmd.complete_irq);
}
};
State start_reading(FileInfo file_info, const SectorBufferAllocator& buffer_allocator);
}
}
}