CDXA not working

This commit is contained in:
jaby 2024-05-26 09:33:23 +02:00
parent 4f06d39e43
commit 43c534cf9b
10 changed files with 135 additions and 51 deletions

View File

@ -27,4 +27,8 @@ namespace Assets {
void load_font_cycler(); void load_font_cycler();
void load_screen_center(); void load_screen_center();
} }
namespace XAAudio {
void play_fox();
}
} }

View File

@ -5,7 +5,7 @@
#include "Overlay/Overlays.hpp" #include "Overlay/Overlays.hpp"
#include <FontWriter/fonts.hpp> #include <FontWriter/fonts.hpp>
#include <FontWriter/font_writer.hpp> #include <FontWriter/font_writer.hpp>
#include <PSX/Audio/CDDA.hpp> //#include <PSX/Audio/CDDA.hpp>
#include <PSX/Periphery/periphery.hpp> #include <PSX/Periphery/periphery.hpp>
#include <PSX/System/callbacks.hpp> #include <PSX/System/callbacks.hpp>
#include <stdio.hpp> #include <stdio.hpp>
@ -105,8 +105,11 @@ static void setup() {
} }
},MenuEntries); },MenuEntries);
const auto [first_track, last_track] = CDDA::get_tracks(); // TODO: CDDA?
CDDA::play(first_track); // const auto [first_track, last_track] = CDDA::get_tracks();
// CDDA::play(first_track);
Assets::XAAudio::play_fox();
} }
namespace NormalScene { namespace NormalScene {
@ -158,6 +161,7 @@ namespace LoadingScene {
printf("Loading new state...\n"); printf("Loading new state...\n");
Callback::VSyncCallback::install([]() { Callback::VSyncCallback::install([]() {
// TODO: Use it or remove it!!
printf("Still loading...\n"); printf("Still loading...\n");
}); });
@ -166,10 +170,11 @@ namespace LoadingScene {
render(); render();
GPU::swap_buffers_vsync(1); GPU::swap_buffers_vsync(1);
CDDA::push_play(); // TODO: Enable push and pop
//CDDA::push_play();
state_changer.asset_load(); state_changer.asset_load();
old_state_changer = state_changer; old_state_changer = state_changer;
CDDA::pop_play(); //CDDA::pop_play();
Callback::VSyncCallback::uninstall(); Callback::VSyncCallback::uninstall();
} }

View File

@ -1,8 +1,9 @@
#include "../include/asset_mgr.hpp" #include "../include/asset_mgr.hpp"
#include "Overlay/Overlays.hpp" #include "Overlay/Overlays.hpp"
#include <PSX/File/Processor/cd_file_processor.hpp> #include <PSX/Audio/CDXA.hpp>
#include <PSX/AutoLBA/auto_lba.hpp> #include <PSX/AutoLBA/auto_lba.hpp>
#include <PSX/AutoLBA/auto_lba_declaration.hpp> #include <PSX/AutoLBA/auto_lba_declaration.hpp>
#include <PSX/File/Processor/cd_file_processor.hpp>
#include <stdio.hpp> #include <stdio.hpp>
extern "C" uint32_t __bios_info_start; extern "C" uint32_t __bios_info_start;
@ -15,6 +16,7 @@ namespace Assets {
__jabyengine_start_lba_request __jabyengine_start_lba_request
__jabyengine_request_lba_for(PACO, "ASSETS/MAIN/PACO.BIN"), __jabyengine_request_lba_for(PACO, "ASSETS/MAIN/PACO.BIN"),
__jabyengine_request_lba_for(DFISH, "ASSETS/MAIN/DFISH.BIN"), __jabyengine_request_lba_for(DFISH, "ASSETS/MAIN/DFISH.BIN"),
__jabyengine_request_lba_for(FOX_XA, "XAAUDIO/FOX.XA"),
__jabyengine_request_lba_for(BIOS_INFO_OVL, "BIO.BIN"), __jabyengine_request_lba_for(BIOS_INFO_OVL, "BIO.BIN"),
__jabyengine_request_lba_for(GPU_TEST_OVL, "GTO.BIN"), __jabyengine_request_lba_for(GPU_TEST_OVL, "GTO.BIN"),
__jabyengine_request_lba_for(GTE_TEST_OVL, "GTE.BIN"), __jabyengine_request_lba_for(GTE_TEST_OVL, "GTE.BIN"),
@ -106,4 +108,10 @@ namespace Assets {
load(CDFileBuilder::overlay(LBA::SCREEN_CENT_OVL, &__screen_center_start)); load(CDFileBuilder::overlay(LBA::SCREEN_CENT_OVL, &__screen_center_start));
} }
} }
namespace XAAudio {
void play_fox() {
CDXA::play(lba, CDXA::CDFile{FOX_XA}, 0);
}
}
} }

View File

@ -0,0 +1,13 @@
#pragma once
#include "../AutoLBA/auto_lba.hpp"
namespace JabyEngine {
namespace CDXA {
struct CDFile {
uint8_t rel_lba_idx;
};
void play(const volatile AutoLBAEntry* lba, const CDFile& file, uint8_t channel);
void stop();
}
}

View File

@ -157,10 +157,12 @@ namespace JabyEngine {
static constexpr Desc ReadN{0x06, Interrupt::Type::DataReady}; static constexpr Desc ReadN{0x06, Interrupt::Type::DataReady};
static constexpr Desc Pause{0x09, Interrupt::Type::Complete}; static constexpr Desc Pause{0x09, Interrupt::Type::Complete};
static constexpr Desc Init{0x0A, Interrupt::Type::Complete}; static constexpr Desc Init{0x0A, Interrupt::Type::Complete};
static constexpr Desc Filter{0x0D, Interrupt::Type::Acknowledge};
static constexpr Desc SetMode{0x0E, Interrupt::Type::Acknowledge}; static constexpr Desc SetMode{0x0E, Interrupt::Type::Acknowledge};
static constexpr Desc GetLocP{0x11, Interrupt::Type::Acknowledge}; static constexpr Desc GetLocP{0x11, Interrupt::Type::Acknowledge};
static constexpr Desc GetTN{0x13, Interrupt::Type::Acknowledge}; static constexpr Desc GetTN{0x13, Interrupt::Type::Acknowledge};
static constexpr Desc GetTD{0x14, Interrupt::Type::Acknowledge}; static constexpr Desc GetTD{0x14, Interrupt::Type::Acknowledge};
static constexpr Desc ReadS{0x1B, Interrupt::Type::DataReady};
}; };
static constexpr auto IORegister1Adr = 0x1F801801; static constexpr auto IORegister1Adr = 0x1F801801;

View File

@ -45,7 +45,16 @@ namespace JabyEngine {
void read_file(AutoLBAEntry file_info, const SectorBufferAllocator& buffer_allocator); void read_file(AutoLBAEntry file_info, const SectorBufferAllocator& buffer_allocator);
void continue_reading(); void continue_reading();
void read_n(uint32_t lba);
void read_s(uint32_t lba);
void enable_CDDA(); void enable_CDDA();
void enable_CDXA(bool double_speed);
static void pause() {
CD_IO::PortIndex0::change_to();
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
}
} }
} }
} }

View File

@ -8,8 +8,8 @@ namespace JabyEngine {
namespace CD { namespace CD {
namespace internal { namespace internal {
enum struct State { enum struct State {
Free = 0, Ready = 0,
Done = 0, Done = 0,
Reading, Reading,
BufferFull, BufferFull,

View File

@ -38,8 +38,7 @@ namespace JabyEngine {
} }
void stop() { void stop() {
CD::Command::wait_completed(); CD::pause();
CD::Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
} }
void push_play() { void push_play() {

View File

@ -0,0 +1,20 @@
#include "../../internal-include/CD/cd_internal.hpp"
#include <PSX/Audio/CDXA.hpp>
namespace JabyEngine {
namespace CDXA {
namespace CD = JabyEngine::CD::internal;
void play(const volatile AutoLBAEntry* lba, const CDFile& file, uint8_t channel) {
static constexpr uint8_t File = 0;
CD::enable_CDXA(false);
CD::Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::Filter, File, channel);
CD::read_s(lba[file.rel_lba_idx].get_lba());
}
void stop() {
CD::pause();
}
}
}

View File

@ -7,8 +7,9 @@
namespace JabyEngine { namespace JabyEngine {
namespace CD { namespace CD {
namespace internal { namespace internal {
static constexpr auto AudioSectorMode = CD_IO::Mode::from(CD_IO::Mode::SingleSpeed, CD_IO::Mode::AutoPauseTrack, CD_IO::Mode::CDDA); static constexpr auto AudioSectorMode = CD_IO::Mode::from(CD_IO::Mode::SingleSpeed, CD_IO::Mode::AutoPauseTrack, CD_IO::Mode::CDDA);
static constexpr auto DataSectorMode = CD_IO::Mode::from(CD_IO::Mode::DoubleSpeed, CD_IO::Mode::DataSector); static constexpr auto DataSectorMode = CD_IO::Mode::from(CD_IO::Mode::DoubleSpeed, CD_IO::Mode::DataSector);
static constexpr auto XAAudioSectorMode = CD_IO::Mode::from(CD_IO::Mode::SingleSpeed, CD_IO::Mode::XADPCM, CD_IO::Mode::WholeSector, CD_IO::Mode::UseXAFilter);
static SysCall::InterruptVerifierResult interrupt_verifier(); static SysCall::InterruptVerifierResult interrupt_verifier();
static uint32_t interrupt_handler(uint32_t); static uint32_t interrupt_handler(uint32_t);
@ -18,25 +19,21 @@ namespace JabyEngine {
static uint32_t dst_lba; static uint32_t dst_lba;
uint8_t cmd_interrupt_bit = 0; uint8_t cmd_interrupt_bit = 0;
State current_state = State::Free; State current_state = State::Ready;
SysCall::InterrupCallback callback = { SysCall::InterrupCallback callback = {
.next = nullptr, .next = nullptr,
.handler_function = interrupt_handler, .handler_function = interrupt_handler,
.verifier_function = interrupt_verifier .verifier_function = interrupt_verifier
}; };
static void pause_cd() {
CD_IO::PortIndex0::change_to();
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
}
// Requires Index0 // Requires Index0
static void read_cd(uint32_t lba) { static void read_cd(uint32_t lba, CD_IO::Command::Desc desc) {
const auto loc = CDTimeStamp::from(lba); const auto loc = CDTimeStamp::from(lba);
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, loc.get_min_cd(), loc.get_sec_cd(), loc.get_sector_cd()); Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, loc.get_min_cd(), loc.get_sec_cd(), loc.get_sector_cd());
Command::send<CD_IO::PortIndex0>(CD_IO::Command::ReadN); Command::send<CD_IO::PortIndex0>(desc);
current_state = State::Reading; current_state = State::Reading;
printf("Done??\n");
} }
static void read_sector_dma(CD_IO::DataSector& sector) { static void read_sector_dma(CD_IO::DataSector& sector) {
@ -87,42 +84,49 @@ namespace JabyEngine {
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag); CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
cmd_interrupt_bit = bit::clear(cmd_interrupt_bit, cur_irq); cmd_interrupt_bit = bit::clear(cmd_interrupt_bit, cur_irq);
switch(cur_irq) {
case CD_IO::Interrupt::DataReady: {
// Obtain sector content here
auto* sector = sector_allocator.allocate_sector();
if(sector) {
//Now obtain sector
read_sector_to(*sector);
cur_lba++; if(!CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::HasXAFifoData)) {
if(cur_lba == dst_lba) { switch(cur_irq) {
current_state = State::Done; case CD_IO::Interrupt::DataReady: {
pause_cd(); // Obtain sector content here
auto* sector = sector_allocator.allocate_sector();
if(sector) {
//Now obtain sector
read_sector_to(*sector);
cur_lba++;
if(cur_lba == dst_lba) {
current_state = State::Done;
pause();
}
} }
}
else { else {
current_state = State::BufferFull; current_state = State::BufferFull;
pause_cd(); pause();
} }
} break; } break;
case CD_IO::Interrupt::DataEnd: { case CD_IO::Interrupt::DataEnd: {
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
Command::send<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, static_cast<uint8_t>(0x0), static_cast<uint8_t>(0x09), static_cast<uint8_t>(0x0)); Command::send<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, static_cast<uint8_t>(0x0), static_cast<uint8_t>(0x09), static_cast<uint8_t>(0x0));
CD_IO::PortIndex1::change_to(); CD_IO::PortIndex1::change_to();
while(CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag) != CD_IO::Interrupt::Acknowledge); while(CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag) != CD_IO::Interrupt::Acknowledge);
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag); CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play); Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play);
} break; } break;
case CD_IO::Interrupt::DiskError: { case CD_IO::Interrupt::DiskError: {
current_state = State::Error; current_state = State::Error;
} break; } break;
}
}
else {
printf("Playing CDXA\n");
} }
// No masking required because we can only write bit 0 - 2 // No masking required because we can only write bit 0 - 2
@ -141,21 +145,41 @@ namespace JabyEngine {
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, DataSectorMode); Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, DataSectorMode);
read_cd(cur_lba); read_n(cur_lba);
} }
void continue_reading() { void continue_reading() {
if(current_state == State::BufferFull) { if(current_state == State::BufferFull) {
Command::wait_completed(); Command::wait_completed();
read_cd(cur_lba); read_n(cur_lba);
} }
} }
void read_n(uint32_t lba) {
read_cd(lba, CD_IO::Command::ReadN);
}
void read_s(uint32_t lba) {
printf("Now ReadS %i\n", lba);
read_cd(lba, CD_IO::Command::ReadS);
}
void enable_CDDA() { void enable_CDDA() {
Command::wait_completed(); Command::wait_completed();
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, AudioSectorMode); Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, AudioSectorMode);
} }
void enable_CDXA(bool double_speed) {
static constexpr uint8_t SingleSpeedBit = 0x0;
static constexpr uint8_t DoubleSpeedBit = static_cast<uint8_t>(CD_IO::Mode::DoubleSpeed);
const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit);
Command::wait_completed();
CD_IO::PortIndex0::change_to();
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, mode);
}
} }
} }
} }