From e609d2b406e3c9ea5098e3e419c05631e5c6af2b Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 29 Jul 2024 13:36:06 -0500 Subject: [PATCH] Increase PoolBox to Version 0.9.0 --- .../PoolBox/application/include/asset_mgr.hpp | 1 + .../src/Overlay/GPUTest/gpu_test_assets.cpp | 24 +++++- .../application/src/Overlay/Overlays.hpp | 3 +- .../PoolBox/application/src/application.cpp | 83 +++++++++++++------ .../PoolBox/application/src/asset_mgr.cpp | 4 + examples/PoolBox/iso/Config.xml | 3 +- include/PSX/Auxiliary/literals.hpp | 40 +++++---- include/PSX/GPU/make_gpu_primitives.hpp | 3 - include/PSX/Periphery/controller.hpp | 4 + include/PSX/jabyengine_defines.hpp | 1 + src/Library/src/Audio/CDDA.cpp | 5 +- src/Library/src/CD/cd.cpp | 2 + 12 files changed, 119 insertions(+), 54 deletions(-) diff --git a/examples/PoolBox/application/include/asset_mgr.hpp b/examples/PoolBox/application/include/asset_mgr.hpp index 8997a262..0a49790a 100644 --- a/examples/PoolBox/application/include/asset_mgr.hpp +++ b/examples/PoolBox/application/include/asset_mgr.hpp @@ -23,6 +23,7 @@ namespace Assets { void load_bios_info(); void load_controller_test(); void load_gpu_test(); + void load_large_gpu_test(); void load_gte_test(); void load_font_cycler(); void load_screen_center(); diff --git a/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test_assets.cpp b/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test_assets.cpp index fb57f977..a2cf1e07 100644 --- a/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test_assets.cpp +++ b/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test_assets.cpp @@ -13,10 +13,32 @@ namespace GPUTest { }; __declare_lba_header(LBA); - CDFile Assets[18] = { + CDFile Assets[2] = { CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), CDFileBuilder::simple_tim(LBA::ICON, IconTIM), + }; + CDFile LargeAssets[36] = { + CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), + CDFileBuilder::simple_tim(LBA::ICON, IconTIM), + CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), + CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), + CDFileBuilder::simple_tim(LBA::ICON, IconTIM), + CDFileBuilder::simple_tim(LBA::ICON, IconTIM), + CDFileBuilder::simple_tim(LBA::ICON, IconTIM), + CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), + CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), + CDFileBuilder::simple_tim(LBA::ICON, IconTIM), + CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), + CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), + CDFileBuilder::simple_tim(LBA::ICON, IconTIM), + CDFileBuilder::simple_tim(LBA::ICON, IconTIM), + CDFileBuilder::simple_tim(LBA::ICON, IconTIM), + CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), + CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), + CDFileBuilder::simple_tim(LBA::ICON, IconTIM), + CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), + CDFileBuilder::simple_tim(LBA::ICON, IconTIM), CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), CDFileBuilder::simple_tim(LBA::TEX, TexPageTIM), CDFileBuilder::simple_tim(LBA::ICON, IconTIM), diff --git a/examples/PoolBox/application/src/Overlay/Overlays.hpp b/examples/PoolBox/application/src/Overlay/Overlays.hpp index 18186482..d4dcd7d7 100644 --- a/examples/PoolBox/application/src/Overlay/Overlays.hpp +++ b/examples/PoolBox/application/src/Overlay/Overlays.hpp @@ -14,7 +14,8 @@ namespace ControllerTest { namespace GPUTest { extern const volatile JabyEngine::AutoLBAEntry lba[]; - extern JabyEngine::CDFile Assets[18]; + extern JabyEngine::CDFile Assets[2]; + extern JabyEngine::CDFile LargeAssets[36]; void main(); } diff --git a/examples/PoolBox/application/src/application.cpp b/examples/PoolBox/application/src/application.cpp index feaeece8..4d6cf550 100644 --- a/examples/PoolBox/application/src/application.cpp +++ b/examples/PoolBox/application/src/application.cpp @@ -5,7 +5,7 @@ #include "Overlay/Overlays.hpp" #include #include -//#include +#include #include #include #include @@ -13,35 +13,68 @@ using namespace JabyEngine; using DigitalButton = Periphery::GenericController::Button; -struct XAPlayer { +struct CDPlayer { static constexpr auto MaxChannels = 2; uint8_t channel; + bool is_xa; - static XAPlayer create() { - return XAPlayer{0}; + static constexpr CDPlayer create() { + return CDPlayer{.channel = 0, .is_xa = true}; } void play() { - this->channel = 0; - Assets::XAAudio::play_fox(); + if(this->is_xa) { + Assets::XAAudio::play_fox(); + } + + else { + const auto [first_track, last_track] = CDDA::get_tracks(); + CDDA::play(first_track); + } } void stop() { - CDXA::stop(); + if(this->is_xa) { + CDXA::stop(); + } + + else { + CDDA::stop(); + } } void change_channel(int8_t step) { - this->channel = static_cast((this->channel + step))%MaxChannels; - CDXA::set_channel(this->channel); + if(this->is_xa) { + this->channel = static_cast((this->channel + step))%MaxChannels; + CDXA::set_channel(this->channel); + } + } + + void change_audio() { + CDPlayer::stop(); + this->is_xa = !this->is_xa; + CDPlayer::play(); } void push() { - CDXA::push_play(); + if(this->is_xa) { + CDXA::push_play(); + } + + else { + CDDA::push_play(); + } } void pop() { - CDXA::pop_play(); + if(this->is_xa) { + CDXA::pop_play(); + } + + else { + CDDA::pop_play(); + } } }; @@ -80,7 +113,7 @@ static const auto doener_fish = Make::SPRT( GPU::Color24::Grey() ); -static XAPlayer xa = XAPlayer::create(); +static CDPlayer cd_player = CDPlayer::create(); static object::Paco paco; static Menu::SimpleMenu menu; static StateChange state_changer; @@ -101,8 +134,9 @@ static void setup() { const auto& controller = Periphery::get_primary_controller_as(); // With this approach we can default load_test to true for debugging reasons - if(controller.button.is_down(DigitalButton::R2) && controller.button.is_down(DigitalButton::L2)) { - Shared::load_test = true; + if(controller.is_connected()) { + // TODO: Make this work on the PS3 + Shared::load_test = controller.button.is_down(DigitalButton::R2) && controller.button.is_down(DigitalButton::L2); } Assets::Main::load(); @@ -144,11 +178,7 @@ static void setup() { } },MenuEntries); - // TODO: CDDA? - // const auto [first_track, last_track] = CDDA::get_tracks(); - // CDDA::play(first_track); - - xa.play(); + cd_player.play(); } namespace NormalScene { @@ -161,12 +191,16 @@ namespace NormalScene { Periphery::query_controller(); const auto& controller = Periphery::get_primary_controller_as(); + if(controller.button.went_down(DigitalButton::SEL)) { + cd_player.change_audio(); + } + if(controller.button.went_down(DigitalButton::R1)) { - xa.change_channel(1); + cd_player.change_channel(1); } if(controller.button.went_down(DigitalButton::L1)) { - xa.change_channel(-1); + cd_player.change_channel(-1); } auto cursor = FontWriter::update(Make::PositionI16((GPU::Display::Width-TitleLength)/2, 16)); @@ -176,10 +210,9 @@ namespace NormalScene { FontWriter::new_font_writer.write(cursor.change_position(Make::PositionI16((GPU::Display::Width-VersionLength)/2, 16 + DefaultFont::Info.get_kern_size().height)), Version, GPU::Color24::Green(0xD0), &FontWriter::wiggle); menu.update(FontWriter::bios_font_writer, cursor, Make::PositionI16(8, 64)); - if(Shared::load_test) { // Force state change if we are in the load_test state - state_changer.asset_load = Assets::Overlay::load_gpu_test; + state_changer.asset_load = Assets::Overlay::load_large_gpu_test; state_changer.main = GPUTest::main; } @@ -220,10 +253,10 @@ namespace LoadingScene { render(); GPU::swap_buffers_vsync(1); - xa.push(); + cd_player.push(); state_changer.asset_load(); old_state_changer = state_changer; - xa.pop(); + cd_player.pop(); } state_changer.main(); diff --git a/examples/PoolBox/application/src/asset_mgr.cpp b/examples/PoolBox/application/src/asset_mgr.cpp index 2fefab3b..009d0f74 100644 --- a/examples/PoolBox/application/src/asset_mgr.cpp +++ b/examples/PoolBox/application/src/asset_mgr.cpp @@ -96,6 +96,10 @@ namespace Assets { load(CDFileBuilder::overlay(LBA::GPU_TEST_OVL, &__gpu_tests_start), GPUTest::lba, GPUTest::Assets); } + void load_large_gpu_test() { + load(CDFileBuilder::overlay(LBA::GPU_TEST_OVL, &__gpu_tests_start), GPUTest::lba, GPUTest::LargeAssets); + } + void load_gte_test() { load(CDFileBuilder::overlay(LBA::GTE_TEST_OVL, &__gpu_tests_start), GTETest::lba, GTETest::Assets); } diff --git a/examples/PoolBox/iso/Config.xml b/examples/PoolBox/iso/Config.xml index d8d2c032..04d443fd 100644 --- a/examples/PoolBox/iso/Config.xml +++ b/examples/PoolBox/iso/Config.xml @@ -4,14 +4,13 @@ --> Jaby %PSX_LICENSE_PATH%/%PSX_LICENSE%.DAT - System.cnf.subst
../application/bin/%PSX_TV_FORMAT%/PSX-release/PoolBox.psexe
diff --git a/include/PSX/Auxiliary/literals.hpp b/include/PSX/Auxiliary/literals.hpp index 0bd57ce1..e328aff7 100644 --- a/include/PSX/Auxiliary/literals.hpp +++ b/include/PSX/Auxiliary/literals.hpp @@ -1,32 +1,30 @@ #pragma once #include "../../stdint.hpp" -namespace JabyEngine { - static constexpr int8_t operator""_i8(unsigned long long int value) { - return static_cast(value); - } +static constexpr int8_t operator""_i8(unsigned long long int value) { + return static_cast(value); +} - static constexpr uint8_t operator""_u8(unsigned long long int value) { - return static_cast(value); - } +static constexpr uint8_t operator""_u8(unsigned long long int value) { + return static_cast(value); +} - // ################################################################### +// ################################################################### - static constexpr int16_t operator""_i16(unsigned long long int value) { - return static_cast(value); - } +static constexpr int16_t operator""_i16(unsigned long long int value) { + return static_cast(value); +} - static constexpr uint16_t operator""_u16(unsigned long long int value) { - return static_cast(value); - } +static constexpr uint16_t operator""_u16(unsigned long long int value) { + return static_cast(value); +} - // ################################################################### +// ################################################################### - static constexpr int32_t operator""_i32(unsigned long long int value) { - return static_cast(value); - } +static constexpr int32_t operator""_i32(unsigned long long int value) { + return static_cast(value); +} - static constexpr uint32_t operator""_u32(unsigned long long int value) { - return static_cast(value); - } +static constexpr uint32_t operator""_u32(unsigned long long int value) { + return static_cast(value); } \ No newline at end of file diff --git a/include/PSX/GPU/make_gpu_primitives.hpp b/include/PSX/GPU/make_gpu_primitives.hpp index 06a15390..ebd456f8 100644 --- a/include/PSX/GPU/make_gpu_primitives.hpp +++ b/include/PSX/GPU/make_gpu_primitives.hpp @@ -3,9 +3,6 @@ namespace JabyEngine { namespace Make { - using JabyEngine::operator""_i16; - using JabyEngine::operator""_u16; - template static constexpr T creator_template(const ARGS&...args) { return T::create(args...); diff --git a/include/PSX/Periphery/controller.hpp b/include/PSX/Periphery/controller.hpp index da676359..80e25207 100644 --- a/include/PSX/Periphery/controller.hpp +++ b/include/PSX/Periphery/controller.hpp @@ -50,6 +50,10 @@ namespace JabyEngine { return RawController::header.rumble1; } + bool is_connected() const { + return RawController::header.state != RawController::State::Disconnected; + } + bool is_useable() const { const auto type = RawController::get_type(); return ((RawController::header.state == RawController::State::Stable) && (type == ControllerType::Controller || type == ControllerType::DualShock)); diff --git a/include/PSX/jabyengine_defines.hpp b/include/PSX/jabyengine_defines.hpp index 4faaca3f..bd0bb37d 100644 --- a/include/PSX/jabyengine_defines.hpp +++ b/include/PSX/jabyengine_defines.hpp @@ -1,4 +1,5 @@ #pragma once +#include "Auxiliary/literals.hpp" #include #define __used __attribute__((used)) diff --git a/src/Library/src/Audio/CDDA.cpp b/src/Library/src/Audio/CDDA.cpp index 6ef3cd24..a40f4788 100644 --- a/src/Library/src/Audio/CDDA.cpp +++ b/src/Library/src/Audio/CDDA.cpp @@ -30,7 +30,10 @@ namespace JabyEngine { playing_track.min = CD_IO::PortIndex0::ResponseFifo.read().raw; playing_track.sec = CD_IO::PortIndex0::ResponseFifo.read().raw; - CD::Command::send(CD_IO::Command::Play, track); + CD::Command::send(CD_IO::Command::SetLoc, playing_track.min, playing_track.sec, 0x0_u8); + CD::Command::send(CD_IO::Command::Play); + // The PS3 does not support playing a track by track id + //CD::Command::send(CD_IO::Command::Play, track); } void stop() { diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index 7cbee843..84f6b1d5 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -5,6 +5,8 @@ #include #include +// TODO: Outsource the interrupt handler to new source file? +// TODO: Do not spawn a new thread for handling the CD interrupt but use that thread for loading files or something? namespace JabyEngine { namespace CDDA { extern CD::internal::BCDTimeStamp playing_track;