From 25fc43064a3f092a175afa6766bc6d257442d784 Mon Sep 17 00:00:00 2001 From: Jaby Date: Thu, 12 Jan 2023 22:02:11 +0100 Subject: [PATCH] Add boot namespace and adjust names --- .../include/BootLoader/boot_loader.hpp | 41 ++--- .../src/BootLoader/boot_file/main_boot.cpp | 10 +- .../src/BootLoader/boot_file/overlay_boot.cpp | 10 +- src/Library/src/BootLoader/cd_boot.cpp | 8 +- src/Library/src/BootLoader/gpu_boot.cpp | 66 +++---- src/Library/src/BootLoader/spu_boot.cpp | 166 +++++++++--------- src/Library/src/BootLoader/start_boot.cpp | 38 ++-- src/Library/src/BootLoader/timer_boot.cpp | 33 ++-- src/Library/src/startup.cpp | 2 +- 9 files changed, 199 insertions(+), 175 deletions(-) diff --git a/src/Library/include/BootLoader/boot_loader.hpp b/src/Library/include/BootLoader/boot_loader.hpp index e4c75c08..8153adc8 100644 --- a/src/Library/include/BootLoader/boot_loader.hpp +++ b/src/Library/include/BootLoader/boot_loader.hpp @@ -4,31 +4,32 @@ namespace JabyEngine { //boot namespace? - - namespace CD { - void setup(); - } + namespace boot { + namespace BootFile { + JabyEngine::NextRoutine setup(); + } - namespace GPU { - void display_logo(); - void setup(); - } + namespace CD { + void setup(); + } - namespace SPU { - void stop_voices(); - void setup(); - } + namespace GPU { + void display_logo(); + void setup(); + } - namespace Setup { - JabyEngine::NextRoutine start(); - } + namespace SPU { + void stop_voices(); + void setup(); + } - namespace BootFile { - JabyEngine::NextRoutine setup(); - } + namespace Start { + JabyEngine::NextRoutine setup(); + } - namespace Timer { - void setup(); + namespace Timer { + void setup(); + } } } #endif //!BOOT_LOADER_HPP \ No newline at end of file diff --git a/src/Library/src/BootLoader/boot_file/main_boot.cpp b/src/Library/src/BootLoader/boot_file/main_boot.cpp index b13f64b2..119b0aec 100644 --- a/src/Library/src/BootLoader/boot_file/main_boot.cpp +++ b/src/Library/src/BootLoader/boot_file/main_boot.cpp @@ -4,10 +4,12 @@ extern JabyEngine::NextRoutine main(); namespace JabyEngine { - namespace BootFile { - JabyEngine::NextRoutine setup() { - printf("Running main!\n"); - return JabyEngine::NextRoutine::from(main); + namespace boot { + namespace BootFile { + JabyEngine::NextRoutine setup() { + printf("Running main!\n"); + return JabyEngine::NextRoutine::from(main); + } } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/boot_file/overlay_boot.cpp b/src/Library/src/BootLoader/boot_file/overlay_boot.cpp index 9276b5e6..0bd5e969 100644 --- a/src/Library/src/BootLoader/boot_file/overlay_boot.cpp +++ b/src/Library/src/BootLoader/boot_file/overlay_boot.cpp @@ -2,10 +2,12 @@ #include namespace JabyEngine { - namespace BootFile { - JabyEngine::NextRoutine setup() { - printf("Overlay boot not implemented!\n"); - return JabyEngine::NextRoutine::null(); + namespace boot { + namespace BootFile { + JabyEngine::NextRoutine setup() { + printf("Overlay boot not implemented!\n"); + return JabyEngine::NextRoutine::null(); + } } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/cd_boot.cpp b/src/Library/src/BootLoader/cd_boot.cpp index 4c2df577..1fe899d6 100644 --- a/src/Library/src/BootLoader/cd_boot.cpp +++ b/src/Library/src/BootLoader/cd_boot.cpp @@ -2,9 +2,11 @@ #include namespace JabyEngine { - namespace CD { - void setup() { - CD_IO::change_to_index0(); + namespace boot { + namespace CD { + void setup() { + CD_IO::change_to_index0(); + } } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index 1e90358d..9f4eca69 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -13,45 +13,49 @@ extern "C" uint32_t __boot_loader_end; namespace JabyEngine { - namespace GPU { - static size_t decompress_logo() { - LZ4Decompressor lz4_decomp(reinterpret_cast(&__boot_loader_end)); + namespace boot { + namespace GPU { + using namespace JabyEngine::GPU; + + static size_t decompress_logo() { + LZ4Decompressor lz4_decomp(reinterpret_cast(&__boot_loader_end)); - const auto [progress, bytes_ready] = lz4_decomp.process(ArrayRange(SplashScreen, sizeof(SplashScreen)), true); - switch(progress) { - case Progress::InProgress: - printf("Decompressing still in progress... %llu\n", bytes_ready); - break; + const auto [progress, bytes_ready] = lz4_decomp.process(ArrayRange(SplashScreen, sizeof(SplashScreen)), true); + switch(progress) { + case Progress::InProgress: + printf("Decompressing still in progress... %llu\n", bytes_ready); + break; - case Progress::Error: - printf("Error decompressing!!!\n"); - break; + case Progress::Error: + printf("Error decompressing!!!\n"); + break; - case Progress::Done: - printf("Done decompressing: %llu Bytes ready\n", bytes_ready); - break; + case Progress::Done: + printf("Done decompressing: %llu Bytes ready\n", bytes_ready); + break; + } + + return bytes_ready; } - return bytes_ready; - } + void display_logo() { + const auto bytes_ready = decompress_logo(); - void display_logo() { - const auto bytes_ready = decompress_logo(); + // Upload SplashScreen picture + auto state = FileProcessor::create(&__boot_loader_end, SimpleTIM(32, 0, 0, 0)); + while(state.process((bytes_ready/sizeof(uint32_t))) == Progress::InProgress); - // Upload SplashScreen picture - auto state = FileProcessor::create(&__boot_loader_end, SimpleTIM(32, 0, 0, 0)); - while(state.process((bytes_ready/sizeof(uint32_t))) == Progress::InProgress); + Display::enable(); + } - Display::enable(); - } - - void setup() { - GPU_IO::GP1.write(GPU_IO::Command::GP1::Reset()); - internal::Screen::configurate(); - internal::Screen::exchange_buffer_and_display(); - - GPU::internal::wait_ready_for_CMD(); - GPU::internal::quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height)); + void setup() { + GPU_IO::GP1.write(GPU_IO::Command::GP1::Reset()); + internal::Screen::configurate(); + internal::Screen::exchange_buffer_and_display(); + + GPU::internal::wait_ready_for_CMD(); + GPU::internal::quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height)); + } } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/spu_boot.cpp b/src/Library/src/BootLoader/spu_boot.cpp index 7b5d8fcf..e24f8e75 100644 --- a/src/Library/src/BootLoader/spu_boot.cpp +++ b/src/Library/src/BootLoader/spu_boot.cpp @@ -3,97 +3,99 @@ #include namespace JabyEngine { - namespace SPU { - using namespace JabyEngine; - - static void clear_main_volume() { - static constexpr auto StartVol = SPU_IO::SweepVolume::with(SPU_IO::SweepVolume::VolumeEnable, SPU_IO::SweepVolume::Volume.with(I16_MAX >> 2)); - - SPU_IO::MainVolume::Left.write(StartVol); - SPU_IO::MainVolume::Right.write(StartVol); - } - - static void clear_cd_and_ext_audio_volume() { - SPU_IO::CDVolume::Left.write(0); - SPU_IO::CDVolume::Right.write(0); - - SPU_IO::ExternalAudioInputVolume::Left.write(0); - SPU_IO::ExternalAudioInputVolume::Right.write(0); - } - - static void clear_control_register() { - SPU_IO::Control.write(SPU_IO::ControlRegister()); - } - - static void clear_voice() { - for(auto& voice : SPU_IO::Voice) { - voice.volumeLeft.write(SPU_IO::SweepVolume()); - voice.volumeRight.write(SPU_IO::SweepVolume()); - voice.sampleRate.write(SPU_IO::SampleRate()); - voice.ad.write(SPU_IO::AD()); - voice.sr.write(SPU_IO::SR()); - voice.currentVolume.write(SPU_IO::SimpleVolume(0)); - - voice.adr.write(0x200); - voice.repeatAdr.write(0x200); - } - } - - static void clear_pmon() { - SPU_IO::PMON.write(SPU_IO::PitchModFlags()); - } - - static void clear_noise_and_echo() { - SPU_IO::NON.write(SPU_IO::NoiseGenerator()); - SPU_IO::EON.write(SPU_IO::EchoOn()); - } - - static void clear_reverb() { - SPU_IO::Reverb::Volume::Left.write(0); - SPU_IO::Reverb::Volume::Right.write(0); - SPU_IO::Reverb::WorkAreaAdr.write(0); - } - - static void setup_control_register() { - static constexpr auto SetupValue = SPU_IO::ControlRegister::with(SPU_IO::ControlRegister::Enable, SPU_IO::ControlRegister::Unmute, SPU_IO::ControlRegister::CDAudioEnable); - - SPU_IO::Control.write(SetupValue); - } - - static void setup_data_transfer_control() { - static constexpr uint16_t RequiredValue = (2 << 1); + namespace boot { + namespace SPU { + using namespace JabyEngine; - SPU_IO::DataTransferControl.write(RequiredValue); - } + static void clear_main_volume() { + static constexpr auto StartVol = SPU_IO::SweepVolume::with(SPU_IO::SweepVolume::VolumeEnable, SPU_IO::SweepVolume::Volume.with(I16_MAX >> 2)); - static void wait_voices() { - static constexpr int16_t Treshhold = (I16_MAX*0.03); + SPU_IO::MainVolume::Left.write(StartVol); + SPU_IO::MainVolume::Right.write(StartVol); + } - try_again: - for(const auto& voice : SPU_IO::Voice) { - if(voice.currentVolume.read() > Treshhold) { - goto try_again; + static void clear_cd_and_ext_audio_volume() { + SPU_IO::CDVolume::Left.write(0); + SPU_IO::CDVolume::Right.write(0); + + SPU_IO::ExternalAudioInputVolume::Left.write(0); + SPU_IO::ExternalAudioInputVolume::Right.write(0); + } + + static void clear_control_register() { + SPU_IO::Control.write(SPU_IO::ControlRegister()); + } + + static void clear_voice() { + for(auto& voice : SPU_IO::Voice) { + voice.volumeLeft.write(SPU_IO::SweepVolume()); + voice.volumeRight.write(SPU_IO::SweepVolume()); + voice.sampleRate.write(SPU_IO::SampleRate()); + voice.ad.write(SPU_IO::AD()); + voice.sr.write(SPU_IO::SR()); + voice.currentVolume.write(SPU_IO::SimpleVolume(0)); + + voice.adr.write(0x200); + voice.repeatAdr.write(0x200); } } - } - void stop_voices() { - SPU_IO::Key::Off.write(UI32_MAX); - } + static void clear_pmon() { + SPU_IO::PMON.write(SPU_IO::PitchModFlags()); + } - void setup() { - wait_voices(); + static void clear_noise_and_echo() { + SPU_IO::NON.write(SPU_IO::NoiseGenerator()); + SPU_IO::EON.write(SPU_IO::EchoOn()); + } - clear_main_volume(); - clear_cd_and_ext_audio_volume(); - clear_control_register(); - clear_voice(); - clear_pmon(); - clear_noise_and_echo(); - clear_reverb(); + static void clear_reverb() { + SPU_IO::Reverb::Volume::Left.write(0); + SPU_IO::Reverb::Volume::Right.write(0); + SPU_IO::Reverb::WorkAreaAdr.write(0); + } - setup_data_transfer_control(); - setup_control_register(); + static void setup_control_register() { + static constexpr auto SetupValue = SPU_IO::ControlRegister::with(SPU_IO::ControlRegister::Enable, SPU_IO::ControlRegister::Unmute, SPU_IO::ControlRegister::CDAudioEnable); + + SPU_IO::Control.write(SetupValue); + } + + static void setup_data_transfer_control() { + static constexpr uint16_t RequiredValue = (2 << 1); + + SPU_IO::DataTransferControl.write(RequiredValue); + } + + static void wait_voices() { + static constexpr int16_t Treshhold = (I16_MAX*0.03); + + try_again: + for(const auto& voice : SPU_IO::Voice) { + if(voice.currentVolume.read() > Treshhold) { + goto try_again; + } + } + } + + void stop_voices() { + SPU_IO::Key::Off.write(UI32_MAX); + } + + void setup() { + wait_voices(); + + clear_main_volume(); + clear_cd_and_ext_audio_volume(); + clear_control_register(); + clear_voice(); + clear_pmon(); + clear_noise_and_echo(); + clear_reverb(); + + setup_data_transfer_control(); + setup_control_register(); + } } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/start_boot.cpp b/src/Library/src/BootLoader/start_boot.cpp index f5864a3b..820e16f5 100644 --- a/src/Library/src/BootLoader/start_boot.cpp +++ b/src/Library/src/BootLoader/start_boot.cpp @@ -5,28 +5,30 @@ #include namespace JabyEngine { - namespace Setup { - static void enable_DMA() { - DMA_IO::DPCR.write(DMA_IO::DPCR.read() | DMA_IO::DMAControlRegister::SPUEnable | DMA_IO::DMAControlRegister::GPUEnable); - } + namespace boot { + namespace Start { + static void enable_DMA() { + DMA_IO::DPCR.write(DMA_IO::DPCR.read() | DMA_IO::DMAControlRegister::SPUEnable | DMA_IO::DMAControlRegister::GPUEnable); + } - JabyEngine::NextRoutine start() { - enable_DMA(); + JabyEngine::NextRoutine setup() { + enable_DMA(); - SPU::stop_voices(); - Timer::setup(); + SPU::stop_voices(); + Timer::setup(); - const auto start = HighResTime::get_time_stamp(); - printf("Start...\n"); - GPU::setup(); - GPU::display_logo(); - const auto end = HighResTime::get_time_stamp(); - printf("GPU setup took %ims %ius\n", start.milliseconds_to(end), start.microseconds_to(end)); - - //Pause?? + const auto start = HighResTime::get_time_stamp(); + printf("Start...\n"); + GPU::setup(); + GPU::display_logo(); + const auto end = HighResTime::get_time_stamp(); + printf("GPU setup took %ims %ius\n", start.milliseconds_to(end), start.microseconds_to(end)); + + //Pause?? - SPU::setup(); - return BootFile::setup(); + SPU::setup(); + return BootFile::setup(); + } } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/timer_boot.cpp b/src/Library/src/BootLoader/timer_boot.cpp index 4259ab65..b7da662c 100644 --- a/src/Library/src/BootLoader/timer_boot.cpp +++ b/src/Library/src/BootLoader/timer_boot.cpp @@ -9,28 +9,37 @@ namespace JabyEngine { namespace Timer { extern InterrupCallback IRQCallback; - void setup() { - using namespace Timer_IO; + } - static constexpr auto Mode = CounterMode::with(CounterMode::FreeRun, Counter2::SyncMode::Freerun, CounterMode::ResetAfterTarget, CounterMode::IRQAtTarget, CounterMode::IRQEveryTime, CounterMode::IRQPulse, Counter2::Source::System_Clock_Div_8); + namespace boot { + namespace Timer { + using namespace JabyEngine::Timer; + + void setup() { + using namespace Timer_IO; - Interrupt::disable_irq(Interrupt::Timer2); + static constexpr auto Mode = CounterMode::with(CounterMode::FreeRun, Counter2::SyncMode::Freerun, CounterMode::ResetAfterTarget, CounterMode::IRQAtTarget, CounterMode::IRQEveryTime, CounterMode::IRQPulse, Counter2::Source::System_Clock_Div_8); - __syscall_EnterCriticalSection(); - __syscall_SysEnqIntRP(Timer2Irq, &IRQCallback); - __syscall_ExitCriticalSection(); + Interrupt::disable_irq(Interrupt::Timer2); - Counter2.target.write(CounterTarget::CounterTargetValue.with(HighResTime::TicksFor10ms)); - Counter2.mode.write(Mode); + __syscall_EnterCriticalSection(); + __syscall_SysEnqIntRP(Timer2Irq, &IRQCallback); + __syscall_ExitCriticalSection(); - Interrupt::enable_irq(Interrupt::Timer2); + Counter2.target.write(CounterTarget::CounterTargetValue.with(HighResTime::TicksFor10ms)); + Counter2.mode.write(Mode); + + Interrupt::enable_irq(Interrupt::Timer2); + } } } } #else namespace JabyEngine { - namespace Timer { - void setup() { + namespace boot { + namespace Timer { + void setup() { + } } } } diff --git a/src/Library/src/startup.cpp b/src/Library/src/startup.cpp index cfd0d651..e2c5912b 100644 --- a/src/Library/src/startup.cpp +++ b/src/Library/src/startup.cpp @@ -8,7 +8,7 @@ namespace JabyEngine { } void start() { - NextRoutine next_routine = JabyEngine::NextRoutine::from(Setup::start); + NextRoutine next_routine = JabyEngine::NextRoutine::from(boot::Start::setup); printf("Starting Planschbecken 0x%p\n", next_routine.value); while(true) {