From 07756fd18040c00bae8860fe7aff3bd459684009 Mon Sep 17 00:00:00 2001 From: jaby Date: Mon, 1 Jul 2024 23:01:41 +0200 Subject: [PATCH] Fixup CD freeze? --- mkfile/psexe.ld | 5 +++++ src/Library/src/CD/cd.cpp | 28 +++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/mkfile/psexe.ld b/mkfile/psexe.ld index d1fef6ec..d02aff2f 100644 --- a/mkfile/psexe.ld +++ b/mkfile/psexe.ld @@ -31,6 +31,7 @@ ENTRY(_ZN10JabyEngine5startEv) TLOAD_ADDR = DEFINED(TLOAD_ADDR) ? TLOAD_ADDR : 0x80010000; MEMORY { + zero : ORIGIN = 0x0 LENGTH = 0x100 bios : ORIGIN = 0x100, LENGTH = 0x500 loader : ORIGIN = (TLOAD_ADDR - 0x800), LENGTH = 2048 ram(rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 @@ -53,6 +54,10 @@ __stack_start = ORIGIN(ram) + LENGTH(ram); SECTIONS { + .zero (NOLOAD) : { + _ZN10JabyEngine2CD4zeroE = .; + } > zero + .bios (NOLOAD) : { _ZN10JabyEngine15table_of_tablesE = .; } > bios diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index ac8fbc00..ba2f7f59 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -40,11 +40,13 @@ namespace JabyEngine { static File cur_file; State current_state = State::Ready; + auto irq_callback = SysCall::InterruptCallback::from(IRQ::verifier, IRQ::handler); static BCDTimeStamp send_read_cmd0(uint32_t lba, CD_IO::Command::Desc cmd) { const auto loc = BCDTimeStamp::from(lba); + printf("!!2-%X %X %X\n", loc.min, loc.sec, loc.sector); NewCommand::send(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector); NewCommand::send(cmd); return loc; @@ -67,6 +69,7 @@ namespace JabyEngine { DMA_IO::CDROM.channel_ctrl.write(DMA_IO::CHCHR::StartCDROM()); DMA_IO::CDROM.wait(); + CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::Request.write(CD_IO::Request::reset()); }; @@ -84,6 +87,7 @@ namespace JabyEngine { } void resume_at0(const BCDTimeStamp& cd_time) { + printf("!!3-%X %X %X\n", cd_time.min, cd_time.sec, cd_time.sector); NewCommand::send(CD_IO::Command::SetLoc, cd_time.min, cd_time.sec, cd_time.sector); } @@ -104,15 +108,20 @@ namespace JabyEngine { const auto old_status = CD_IO::IndexStatus.read(); CD_IO::PortIndex1::change_to(); - const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); - if(cur_irq == CD_IO::Interrupt::DataReady) { + const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); + const auto is_data_rdy = cur_irq == CD_IO::Interrupt::DataReady; + if(is_data_rdy) { CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::Request.write(CD_IO::Request::want_data()); } CD_IO::PortIndex1::change_to(); CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag); - CD_IO::PortIndex0::change_to(); + CD_IO::Interrupt::reset_parameter_fifo(CD_IO::PortIndex1::InterruptFlag); + zero = 0; + zero = 1; + zero = 2; + zero = 3; // No masking required because we can only write bit 0 - 2 CD_IO::IndexStatus.write(old_status); @@ -128,6 +137,9 @@ namespace JabyEngine { if(sector) { //Now obtain sector read_sector_to0(sector->data, CD_IO::DataSector::SizeBytes); + + const auto time = get_locL(); + printf("%X %X %X\n", time.min, time.sec, time.sector); if(cur_file.done_processing()) { current_state = State::Done; @@ -194,6 +206,16 @@ namespace JabyEngine { return BCDTimeStamp{min, sec, sectors}; } + BCDTimeStamp get_locL() { + NewCommand::send_wait_response(CD_IO::Command::GetLocL); + + const auto min = CD_IO::PortIndex0::ResponseFifo.read().raw; + const auto sec = CD_IO::PortIndex0::ResponseFifo.read().raw; + const auto sector = CD_IO::PortIndex0::ResponseFifo.read().raw; + + return BCDTimeStamp{min, sec, sector}; + } + void enable_CD() { NewCommand::send(CD_IO::Command::SetMode, DataSectorMode); }