Play CDDA track

This commit is contained in:
jaby 2024-05-05 22:12:23 +02:00
parent 01622fd5d6
commit f91a7b470c
9 changed files with 80 additions and 3 deletions

View File

@ -1,4 +1,5 @@
#include "include/menu.hpp"
#include <PSX/Audio/CDDA.hpp>
#include <PSX/Periphery/periphery.hpp>
namespace Menu {
@ -41,6 +42,9 @@ namespace Menu {
}
void BackMenu :: setup(JabyEngine::FontWriter* font_writer) {
const auto [first_track, last_track] = CDDA::get_tracks();
CDDA::play(first_track);
this->font_writer = font_writer;
this->timeout.reset();
this->waiting = false;

View File

@ -33,4 +33,5 @@
</Directory>
</Track>
<CD_Audio>../assets/audio/Evacuation_cdda.wav</CD_Audio>
<CD_Audio>../assets/audio/Evacuation_cdda.wav</CD_Audio>
</ISO_Project>

View File

@ -0,0 +1,20 @@
#pragma once
#include "../jabyengine_defines.hpp"
namespace JabyEngine {
namespace CDDA {
struct TrackList {
uint8_t first_track;
uint8_t last_track;
static constexpr TrackList empty() {
return TrackList{.first_track = 0, .last_track = 0};
}
};
TrackList get_tracks();
void play(uint8_t track);
void stop();
}
}

View File

@ -153,10 +153,12 @@ namespace JabyEngine {
static constexpr Desc GetStat{0x01, Interrupt::Type::Acknowledge};
static constexpr Desc SetLoc{0x02, Interrupt::Type::Acknowledge};
static constexpr Desc Play{0x03, Interrupt::Type::Acknowledge};
static constexpr Desc ReadN{0x06, Interrupt::Type::DataReady};
static constexpr Desc Pause{0x09, Interrupt::Type::Complete};
static constexpr Desc Init{0x0A, Interrupt::Type::Complete};
static constexpr Desc SetMode{0x0E, Interrupt::Type::Acknowledge};
static constexpr Desc GetTN{0x13, Interrupt::Type::Acknowledge};
};
static constexpr auto IORegister1Adr = 0x1F801801;

View File

@ -1,5 +1,6 @@
#pragma once
#include "ioport.hpp"
#include <limits.hpp>
namespace JabyEngine {
namespace SPU_IO {
@ -156,6 +157,10 @@ namespace JabyEngine {
__declare_io_port_w_type(inline, Adr, WorkAreaAdr, 0x1F801DA2);
};
static constexpr SimpleVolume operator""_vol(long double fraction) {
return {static_cast<int16_t>(static_cast<long double>(I16_MAX)*fraction)};
}
__declare_io_port(, ControlRegister, 0x1F801DAA);
__declare_io_port(, DataTransferControl, 0x1F801DAC);
__declare_io_port(, PMON, 0x1F801D90);

View File

@ -45,6 +45,8 @@ namespace JabyEngine {
void read_file(AutoLBAEntry file_info, const SectorBufferAllocator& buffer_allocator);
void continue_reading();
void enable_CDDA();
}
}
}

View File

@ -0,0 +1,36 @@
#include "../../internal-include/CD/cd_internal.hpp"
#include <PSX/Audio/CDDA.hpp>
#include <stdio.hpp>
namespace JabyEngine {
namespace CDDA {
namespace CD = JabyEngine::CD::internal;
TrackList get_tracks() {
CD::Command::wait_completed();
CD_IO::PortIndex0::change_to();
CD::Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::GetTN);
const auto stat = CD_IO::PortIndex0::ResponseFifo.read();
const auto first = CD_IO::PortIndex0::ResponseFifo.read().raw;
const auto end = CD_IO::PortIndex0::ResponseFifo.read().raw;
const auto last_track = (end - first) + 1;
if(last_track == 1) {
return TrackList::empty();
}
return TrackList{.first_track = 2, .last_track = static_cast<uint8_t>(last_track)};
}
void play(uint8_t track) {
CD::enable_CDDA(); // < Command waits
CD::Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play, track);
}
void stop() {
}
}
}

View File

@ -15,8 +15,8 @@ namespace JabyEngine {
}
static void clear_cd_and_ext_audio_volume() {
CDVolume::Left.write({0});
CDVolume::Right.write({0});
CDVolume::Left.write(0.5_vol);
CDVolume::Right.write(0.5_vol);
ExternalAudioInputVolume::Left.write({0});
ExternalAudioInputVolume::Right.write({0});

View File

@ -6,6 +6,7 @@
namespace JabyEngine {
namespace CD {
namespace internal {
static constexpr auto AudioSectorMode = CD_IO::Mode::from(CD_IO::Mode::SingleSpeed, CD_IO::Mode::CDDA);
static constexpr auto DataSectorMode = CD_IO::Mode::from(CD_IO::Mode::DoubleSpeed, CD_IO::Mode::DataSector);
static SysCall::InterruptVerifierResult interrupt_verifier();
@ -136,6 +137,12 @@ namespace JabyEngine {
read_cd(cur_lba);
}
}
void enable_CDDA() {
Command::wait_completed();
CD_IO::PortIndex0::change_to();
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, AudioSectorMode);
}
}
}
}