Support Overlays #2

Merged
jaby merged 48 commits from Overlay-The-Beginning_CDDrive into main 2023-04-22 09:38:32 +00:00
3 changed files with 36 additions and 21 deletions
Showing only changes of commit 864ecf4412 - Show all commits

View File

@ -47,6 +47,7 @@ namespace JabyEngine {
};
void read_file(FileInfo file_info, const SectorBufferAllocator& buffer_allocator);
bool continue_reading();
}
}
}

View File

@ -25,6 +25,11 @@ namespace JabyEngine {
static SectorBufferAllocator sector_allocator;
static uint16_t sectors_left;
static void pause_cd() {
CD_IO::PortIndex0::change_to();
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
}
static void read_sector_dma(CD_IO::DataSector& sector) {
static const auto WaitSectorReady = []() {
while(!CD_IO::IndexStatus.is_set(CD_IO::IndexStatus_t::HasDataFifoData));
@ -55,12 +60,24 @@ namespace JabyEngine {
// Doesn't seem to important when we can use DMA
}
static InterruptVerifierResult interrupt_verifier() {
static const auto pause = []() {
CD_IO::PortIndex0::change_to();
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
};
static bool try_read_sector() {
// Obtain sector content here
auto* sector = sector_allocator.allocate_sector();
if(sector) {
//Now obtain sector
read_sector_to(*sector);
sectors_left--;
if(sectors_left == 0) {
current_state = State::Done;
pause_cd();
}
return true;
}
return false;
}
static InterruptVerifierResult interrupt_verifier() {
if(Interrupt::is_irq(Interrupt::CDROM)) {
const uint8_t old_status = CD_IO::IndexStatus;
@ -71,21 +88,9 @@ namespace JabyEngine {
if(cur_irq == CD_IO::Interrupt::DataReady) {
//Obtain sector content here
auto* sector = sector_allocator.allocate_sector();
if(sector) {
//Now obtain sector
read_sector_to(*sector);
sectors_left--;
if(sectors_left == 0) {
current_state = State::Done;
pause();
}
}
else {
if(!try_read_sector()) {
current_state = State::BufferFull;
pause();
pause_cd();
}
}
@ -131,6 +136,15 @@ namespace JabyEngine {
printf("Now reading: %i(%i:%i:%i)\n", file_info.lba, loc.get_min_cd(), loc.get_sec_cd(), loc.get_sector_cd());
}
bool continue_reading() {
if(current_state != State::BufferFull) {
return true;
}
CD_IO::PortIndex1::change_to();
return try_read_sector();
}
}
}
}

View File

@ -87,8 +87,8 @@ namespace JabyEngine {
case CD::internal::State::BufferFull:
// We have to process data and unpause the CD drive
// Error case for now
return Progress::Error;
CDFileProcessor::reading_state(cur_job);
return CD::internal::continue_reading() ? CDFileProcessor::process() : Progress::Error;
case CD::internal::State::Reading:
// Do we have data? Use it!