Support pushing and poping a playing CDDA track

This commit is contained in:
Jaby 2024-05-06 17:16:43 +02:00
parent 6301eb211f
commit 7877cb5b2d
7 changed files with 36 additions and 7 deletions

View File

@ -5,6 +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/Periphery/periphery.hpp> #include <PSX/Periphery/periphery.hpp>
#include <stdio.hpp> #include <stdio.hpp>
@ -102,6 +103,9 @@ static void setup() {
break; break;
} }
},MenuEntries); },MenuEntries);
const auto [first_track, last_track] = CDDA::get_tracks();
CDDA::play(first_track);
} }
namespace NormalScene { namespace NormalScene {
@ -157,8 +161,10 @@ namespace LoadingScene {
render(); render();
GPU::swap_buffers_vsync(1); GPU::swap_buffers_vsync(1);
CDDA::push_play();
state_changer.asset_load(); state_changer.asset_load();
old_state_changer = state_changer; old_state_changer = state_changer;
CDDA::pop_play();
} }
state_changer.main(); state_changer.main();

View File

@ -1,5 +1,4 @@
#include "include/menu.hpp" #include "include/menu.hpp"
#include <PSX/Audio/CDDA.hpp>
#include <PSX/Periphery/periphery.hpp> #include <PSX/Periphery/periphery.hpp>
namespace Menu { namespace Menu {
@ -42,9 +41,6 @@ namespace Menu {
} }
void BackMenu :: setup(JabyEngine::FontWriter* font_writer) { 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->font_writer = font_writer;
this->timeout.reset(); this->timeout.reset();
this->waiting = false; this->waiting = false;

View File

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

View File

@ -16,5 +16,8 @@ namespace JabyEngine {
void play(uint8_t track); void play(uint8_t track);
void pause(); void pause();
void push_play();
void pop_play();
} }
} }

View File

@ -158,6 +158,7 @@ namespace JabyEngine {
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 SetMode{0x0E, Interrupt::Type::Acknowledge}; static constexpr Desc SetMode{0x0E, 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};
}; };

View File

@ -6,6 +6,8 @@ namespace JabyEngine {
namespace CDDA { namespace CDDA {
namespace CD = JabyEngine::CD::internal; namespace CD = JabyEngine::CD::internal;
static CD::CDTimeStamp last_track;
TrackList get_tracks() { TrackList get_tracks() {
CD::Command::wait_completed(); CD::Command::wait_completed();
@ -33,5 +35,27 @@ namespace JabyEngine {
CD::Command::wait_completed(); CD::Command::wait_completed();
CD::Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause); CD::Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
} }
void push_play() {
pause();
CD::Command::wait_completed();
CD::Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::GetLocP);
const auto track = CD_IO::PortIndex0::ResponseFifo.read().raw; // track number (AAh=Lead-out area) (FFh=unknown, toc, none?)
const auto index = CD_IO::PortIndex0::ResponseFifo.read().raw; // index number (Usually 01h)
const auto mm = CD_IO::PortIndex0::ResponseFifo.read().raw; // minute number within track (00h and up)
const auto ss = CD_IO::PortIndex0::ResponseFifo.read().raw; // second number within track (00h to 59h)
const auto sect = CD_IO::PortIndex0::ResponseFifo.read().raw; // sector number within track (00h to 74h)
last_track.min = CD_IO::PortIndex0::ResponseFifo.read().raw; // minute number on entire disk (00h and up)
last_track.sec = CD_IO::PortIndex0::ResponseFifo.read().raw; // second number on entire disk (00h to 59h)
last_track.sector = CD_IO::PortIndex0::ResponseFifo.read().raw; // sector number on entire disk (00h to 74h)
}
void pop_play() {
CD::Command::wait_completed();
CD::Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, last_track.min, last_track.sec, last_track.sector);
CD::enable_CDDA(); // < Command waits
CD::Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play);
}
} }
} }

View File

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