From f8ed3c635b4f3629b39d34a588c286bcb5edb662 Mon Sep 17 00:00:00 2001 From: Jaby Date: Tue, 2 Jul 2024 20:05:02 +0200 Subject: [PATCH] Save state before change --- include/PSX/System/IOPorts/cd_io.hpp | 17 +++++++++++++---- src/Library/internal-include/CD/cd_internal.hpp | 3 +++ src/Library/src/Audio/CDXA.cpp | 6 +++--- .../src/File/Processor/cd_file_processor.cpp | 4 ++-- .../src/File/Processor/tim_processor.cpp | 2 +- src/Library/src/System/callbacks.cpp | 2 ++ 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/PSX/System/IOPorts/cd_io.hpp b/include/PSX/System/IOPorts/cd_io.hpp index fbf95f37..36249085 100644 --- a/include/PSX/System/IOPorts/cd_io.hpp +++ b/include/PSX/System/IOPorts/cd_io.hpp @@ -13,6 +13,15 @@ namespace JabyEngine { static constexpr T words_to_sectors(T size) { return (size + static_cast(DataSector::SizeWords - 1))/static_cast(DataSector::SizeWords); } + + constexpr size_t hash() const { + uint32_t value = 0; + + for(const auto word : this->data) { + value += word; + } + return value; + } }; enum Index { @@ -142,10 +151,10 @@ namespace JabyEngine { static void ack_extended(IOPort& port) { port.write(InterruptFlag::from(InterruptFlag::InterruptTypValue.range_max(), InterruptEnable::UnknownIRQ, InterruptEnable::CommandStartIRQ)); -// *reinterpret_cast(0x0) = 0; -// *reinterpret_cast(0x0) = 0; -// *reinterpret_cast(0x0) = 0; -// *reinterpret_cast(0x0) = 0; + } + + static void reset_parameter_fifo(IOPort& port) { + port.write(InterruptFlag{0x40}); } }; diff --git a/src/Library/internal-include/CD/cd_internal.hpp b/src/Library/internal-include/CD/cd_internal.hpp index f60ea8c1..9c9d2938 100644 --- a/src/Library/internal-include/CD/cd_internal.hpp +++ b/src/Library/internal-include/CD/cd_internal.hpp @@ -7,6 +7,8 @@ namespace JabyEngine { namespace CD { + extern volatile uint8_t zero; + namespace internal { enum struct State { Ready = 0, @@ -84,6 +86,7 @@ namespace JabyEngine { void continue_reading(); BCDTimeStamp get_loc(); + BCDTimeStamp get_locL(); void enable_CD(); void enable_CDDA(); diff --git a/src/Library/src/Audio/CDXA.cpp b/src/Library/src/Audio/CDXA.cpp index 30e21450..e524ce2a 100644 --- a/src/Library/src/Audio/CDXA.cpp +++ b/src/Library/src/Audio/CDXA.cpp @@ -48,7 +48,7 @@ namespace JabyEngine { setting.get_loc_functional = !CD::get_loc().is_zero(); CD::enable_CDXA(double_speed); //< Activates PortIndex0 - set_channel(channel); + set_channel(channel);printf("!!0-%X %X %X\n", setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector); CD::NewCommand::send(CD_IO::Command::SetLoc, setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector); CD::NewCommand::send(CD_IO::Command::ReadS); } @@ -75,8 +75,8 @@ namespace JabyEngine { void pop_play() { CD::enable_CDXA(setting.double_speed); //< Activates PortIndex0 - set_channel(setting.channel); - CD::NewCommand::send(CD_IO::Command::SetLoc, setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector); + set_channel(setting.channel);printf("!!1-%X %X %X\n", setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector); + CD::NewCommand::send_wait_response(CD_IO::Command::SetLoc, setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector); CD::NewCommand::send(CD_IO::Command::ReadS); } } diff --git a/src/Library/src/File/Processor/cd_file_processor.cpp b/src/Library/src/File/Processor/cd_file_processor.cpp index 2046df53..a99df151 100644 --- a/src/Library/src/File/Processor/cd_file_processor.cpp +++ b/src/Library/src/File/Processor/cd_file_processor.cpp @@ -56,8 +56,8 @@ namespace JabyEngine { return self.circular_buffer.allocate(); })); - printf(">>> 0x%p\n", this->jobs.files); - printf(">>> %i.) CD needs to load LBA: %i -> %i (is LZ4: [%s])\n", cur_job.rel_lba_idx, cur_lba.get_lba(), cur_lba.get_size_in_sectors(), cur_lba.is_lz4() ? "Yes" : "No"); + //printf(">>> 0x%p\n", this->jobs.files); + //printf(">>> %i.) CD needs to load LBA: %i -> %i (is LZ4: [%s])\n", cur_job.rel_lba_idx, cur_lba.get_lba(), cur_lba.get_size_in_sectors(), cur_lba.is_lz4() ? "Yes" : "No"); } bool CDFileProcessor :: process_data() { diff --git a/src/Library/src/File/Processor/tim_processor.cpp b/src/Library/src/File/Processor/tim_processor.cpp index eab980aa..74016215 100644 --- a/src/Library/src/File/Processor/tim_processor.cpp +++ b/src/Library/src/File/Processor/tim_processor.cpp @@ -104,7 +104,7 @@ namespace JabyEngine { } static Progress switch_state_parse_data(State::Configuration& config, SimpleTIMState& state) { - state.words_left = set_gpu_receive_data(reinterpret_cast(config.data_adr), {state.dst_info.get_texture_position(), state.size_info.get_texture_size()}); + state.words_left = set_gpu_receive_data(reinterpret_cast(config.data_adr), {state.dst_info.get_texture_position(), state.size_info.get_texture_size()}); return Helper::exchange_and_execute_process_function(parse_data, config, state); } diff --git a/src/Library/src/System/callbacks.cpp b/src/Library/src/System/callbacks.cpp index 3b5ac341..5a8f7f4a 100644 --- a/src/Library/src/System/callbacks.cpp +++ b/src/Library/src/System/callbacks.cpp @@ -32,7 +32,9 @@ namespace JabyEngine { void routine(uint32_t irq) { while(true) { + const auto old_status = CD_IO::IndexStatus.read(); CD_IRQ::process(irq); + CD_IO::IndexStatus.write(old_status); irq = Callback::internal::CD::resume(); } }