From 5626e8ecb1e3026dbd14407561fad8a88714385e Mon Sep 17 00:00:00 2001 From: jaby Date: Wed, 11 Jan 2023 20:45:17 +0100 Subject: [PATCH] Add internal namespace to easily tell header apart --- src/Library/include/CD/cd.hpp | 19 --- src/Library/include/CD/cd_internal.hpp | 10 ++ src/Library/include/GPU/gpu.hpp | 118 ----------------- src/Library/include/GPU/gpu_internal.hpp | 120 ++++++++++++++++++ src/Library/src/BootLoader/gpu_boot.cpp | 10 +- .../src/File/Processor/tim_processor.cpp | 20 +-- src/Library/src/GPU/gpu.cpp | 24 ++-- 7 files changed, 159 insertions(+), 162 deletions(-) delete mode 100644 src/Library/include/CD/cd.hpp create mode 100644 src/Library/include/CD/cd_internal.hpp delete mode 100644 src/Library/include/GPU/gpu.hpp create mode 100644 src/Library/include/GPU/gpu_internal.hpp diff --git a/src/Library/include/CD/cd.hpp b/src/Library/include/CD/cd.hpp deleted file mode 100644 index 57868489..00000000 --- a/src/Library/include/CD/cd.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __JABYENGINE_CD_HPP__ -#define __JABYENGINE_CD_HPP__ -#include - -namespace JabyEngine { - namespace CD { - namespace CircularBuffer { - extern uint8_t* write_ptr; - extern uint8_t* read_ptr; - extern uint8_t* end_ptr; - } - - enum struct State { - }; - - extern State state; - } -} -#endif //!__JABYENGINE_CD_HPP__ \ No newline at end of file diff --git a/src/Library/include/CD/cd_internal.hpp b/src/Library/include/CD/cd_internal.hpp new file mode 100644 index 00000000..5c08fd09 --- /dev/null +++ b/src/Library/include/CD/cd_internal.hpp @@ -0,0 +1,10 @@ +#ifndef __JABYENGINE_CD_HPP__ +#define __JABYENGINE_CD_HPP__ +#include + +namespace JabyEngine { + namespace CD { + namespace internal {} + } +} +#endif //!__JABYENGINE_CD_HPP__ \ No newline at end of file diff --git a/src/Library/include/GPU/gpu.hpp b/src/Library/include/GPU/gpu.hpp deleted file mode 100644 index 0466a586..00000000 --- a/src/Library/include/GPU/gpu.hpp +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef __JABYENGINE_INTERNAL_GPU_HPP__ -#define __JABYENGINE_INTERNAL_GPU_HPP__ -#include -#include -#include - -namespace JabyEngine { - namespace GPU { - struct ScreenHelper { - struct Mode { - enum struct TVEncoding { - NTSC = 0, - PAL = 1, - }; - - static constexpr auto HorizontalResolution368 = Bit(6); - static constexpr auto VerticalInterlace = Bit(5); - static constexpr auto DisplayAreaColorDepth = BitRange::from_to(4, 4); - static constexpr auto VideoMode = BitRange::from_to(3, 3); - static constexpr auto VerticalResolution = BitRange::from_to(2, 2); - static constexpr auto HorizontalResolution = BitRange::from_to(0, 1); - - static constexpr uint32_t PAL() { - return ComplexBitMap::with( - Mode::HorizontalResolution.with(GPU_IO::HorizontalResolution::$320), - Mode::VerticalResolution.with(GPU_IO::VerticalResolution::$240), - Mode::VideoMode.with(TVEncoding::PAL), - Mode::DisplayAreaColorDepth.with(GPU_IO::DisplayAreaColorDepth::$15bit) - ).raw; - } - - static constexpr uint32_t NTSC() { - return ComplexBitMap::with( - Mode::HorizontalResolution.with(GPU_IO::HorizontalResolution::$320), - Mode::VerticalResolution.with(GPU_IO::VerticalResolution::$240), - Mode::VideoMode.with(TVEncoding::NTSC), - Mode::DisplayAreaColorDepth.with(GPU_IO::DisplayAreaColorDepth::$15bit) - ).raw; - } - }; - - static void configurate() { - static constexpr uint16_t FirstVisiblePixelH = 0x260; - - #ifdef JABYENGINE_PAL - static constexpr uint16_t FirstVisiblePixelV = 0xA3; - - GPU_IO::GP1.write(GPU_IO::Command::GP1::DisplayMode(Mode::PAL())); - GPU::Screen::set_offset(0, 0); - #else - static constexpr uint16_t FirstVisiblePixelV = 0x88; - - GPU_IO::GP1.write(GPU_IO::Command::GP1::DisplayMode(Mode::NTSC())); - GPU::Screen::set_offset(0, 5); //< Random values - #endif - } - - static void exchange_buffer_and_display(); - }; - - static void set_draw_area(uint16_t x, uint16_t y) { - GPU_IO::GP0.write(GPU_IO::Command::GP0::DrawAreaTopLeft(x, y)); - GPU_IO::GP0.write(GPU_IO::Command::GP0::DrawAreaBottomRight((x + Display::Width), (y + Display::Height))); - } - - static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) { - GPU_IO::GP0.write(GPU_IO::Command::GP0::QuickFill(color)); - GPU_IO::GP0.write(GPU_IO::Command::GP0::TopLeftPosition(pos.x, pos.y)); - GPU_IO::GP0.write(GPU_IO::Command::GP0::WidthHeight(size.width, size.height)); - } - - static void reset_cmd_buffer() { - GPU_IO::GP1.write(GPU_IO::Command::GP1::ResetCMDBufer()); - } - - static void wait_ready_for_CMD() { - while(!GPU_IO::GPUSTAT.read().is(GPU_IO::GPUStatusRegister::GP0ReadyForCMD)); - } - - namespace DMA { - static void wait() { - while(::JabyEngine::DMA_IO::GPU.channel_ctrl.read().is(::JabyEngine::DMA_IO::CHCHR::Busy)); - } - - static void end() { - reset_cmd_buffer(); - } - - namespace Receive { - static void prepare() - { - GPU_IO::GP1.write(GPU_IO::Command::GP1::DMADirection(GPU_IO::DMADirection::CPU2GPU)); - reset_cmd_buffer(); - } - - static void set_src(uintptr_t adr) { - DMA_IO::GPU.adr.write(DMA_IO::MADR::MemoryAdr.with(static_cast(adr))); - } - - static void set_dst(const PositionU16& position, const SizeU16& size) { - wait_ready_for_CMD(); - GPU_IO::GP0.write(GPU_IO::Command::GP0::CPU2VRAM_Blitting()); - GPU_IO::GP0.write(GPU_IO::Command::GP0::TopLeftPosition(position.x, position.y)); - GPU_IO::GP0.write(GPU_IO::Command::GP0::WidthHeight(size.width, size.height)); - } - - static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) { - typedef DMA_IO::BCR::SyncMode1 SyncMode1; - - DMA_IO::GPU.block_ctrl.write(SyncMode1::with(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount))); - DMA_IO::GPU.channel_ctrl.write(DMA_IO::CHCHR::StartGPUReceive()); - } - } - } - } -} - -#endif //!__JABYENGINE_INTERNAL_GPU_HPP__ \ No newline at end of file diff --git a/src/Library/include/GPU/gpu_internal.hpp b/src/Library/include/GPU/gpu_internal.hpp new file mode 100644 index 00000000..c4a9d432 --- /dev/null +++ b/src/Library/include/GPU/gpu_internal.hpp @@ -0,0 +1,120 @@ +#ifndef __JABYENGINE_INTERNAL_GPU_HPP__ +#define __JABYENGINE_INTERNAL_GPU_HPP__ +#include +#include +#include + +namespace JabyEngine { + namespace GPU { + namespace internal { + struct Screen { + struct Mode { + enum struct TVEncoding { + NTSC = 0, + PAL = 1, + }; + + static constexpr auto HorizontalResolution368 = Bit(6); + static constexpr auto VerticalInterlace = Bit(5); + static constexpr auto DisplayAreaColorDepth = BitRange::from_to(4, 4); + static constexpr auto VideoMode = BitRange::from_to(3, 3); + static constexpr auto VerticalResolution = BitRange::from_to(2, 2); + static constexpr auto HorizontalResolution = BitRange::from_to(0, 1); + + static constexpr uint32_t PAL() { + return ComplexBitMap::with( + Mode::HorizontalResolution.with(GPU_IO::HorizontalResolution::$320), + Mode::VerticalResolution.with(GPU_IO::VerticalResolution::$240), + Mode::VideoMode.with(TVEncoding::PAL), + Mode::DisplayAreaColorDepth.with(GPU_IO::DisplayAreaColorDepth::$15bit) + ).raw; + } + + static constexpr uint32_t NTSC() { + return ComplexBitMap::with( + Mode::HorizontalResolution.with(GPU_IO::HorizontalResolution::$320), + Mode::VerticalResolution.with(GPU_IO::VerticalResolution::$240), + Mode::VideoMode.with(TVEncoding::NTSC), + Mode::DisplayAreaColorDepth.with(GPU_IO::DisplayAreaColorDepth::$15bit) + ).raw; + } + }; + + static void configurate() { + static constexpr uint16_t FirstVisiblePixelH = 0x260; + + #ifdef JABYENGINE_PAL + static constexpr uint16_t FirstVisiblePixelV = 0xA3; + + GPU_IO::GP1.write(GPU_IO::Command::GP1::DisplayMode(Mode::PAL())); + GPU::Screen::set_offset(0, 0); + #else + static constexpr uint16_t FirstVisiblePixelV = 0x88; + + GPU_IO::GP1.write(GPU_IO::Command::GP1::DisplayMode(Mode::NTSC())); + GPU::Screen::set_offset(0, 5); //< Random values + #endif + } + + static void exchange_buffer_and_display(); + }; + + static void set_draw_area(uint16_t x, uint16_t y) { + GPU_IO::GP0.write(GPU_IO::Command::GP0::DrawAreaTopLeft(x, y)); + GPU_IO::GP0.write(GPU_IO::Command::GP0::DrawAreaBottomRight((x + Display::Width), (y + Display::Height))); + } + + static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) { + GPU_IO::GP0.write(GPU_IO::Command::GP0::QuickFill(color)); + GPU_IO::GP0.write(GPU_IO::Command::GP0::TopLeftPosition(pos.x, pos.y)); + GPU_IO::GP0.write(GPU_IO::Command::GP0::WidthHeight(size.width, size.height)); + } + + static void reset_cmd_buffer() { + GPU_IO::GP1.write(GPU_IO::Command::GP1::ResetCMDBufer()); + } + + static void wait_ready_for_CMD() { + while(!GPU_IO::GPUSTAT.read().is(GPU_IO::GPUStatusRegister::GP0ReadyForCMD)); + } + + namespace DMA { + static void wait() { + while(::JabyEngine::DMA_IO::GPU.channel_ctrl.read().is(::JabyEngine::DMA_IO::CHCHR::Busy)); + } + + static void end() { + reset_cmd_buffer(); + } + + namespace Receive { + static void prepare() + { + GPU_IO::GP1.write(GPU_IO::Command::GP1::DMADirection(GPU_IO::DMADirection::CPU2GPU)); + reset_cmd_buffer(); + } + + static void set_src(uintptr_t adr) { + DMA_IO::GPU.adr.write(DMA_IO::MADR::MemoryAdr.with(static_cast(adr))); + } + + static void set_dst(const PositionU16& position, const SizeU16& size) { + wait_ready_for_CMD(); + GPU_IO::GP0.write(GPU_IO::Command::GP0::CPU2VRAM_Blitting()); + GPU_IO::GP0.write(GPU_IO::Command::GP0::TopLeftPosition(position.x, position.y)); + GPU_IO::GP0.write(GPU_IO::Command::GP0::WidthHeight(size.width, size.height)); + } + + static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) { + typedef DMA_IO::BCR::SyncMode1 SyncMode1; + + DMA_IO::GPU.block_ctrl.write(SyncMode1::with(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount))); + DMA_IO::GPU.channel_ctrl.write(DMA_IO::CHCHR::StartGPUReceive()); + } + } + } + } + } +} + +#endif //!__JABYENGINE_INTERNAL_GPU_HPP__ \ 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 d1b84d47..1e90358d 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -1,4 +1,4 @@ -#include "../../include/GPU/gpu.hpp" +#include "../../include/GPU/gpu_internal.hpp" #include #include #include @@ -47,11 +47,11 @@ namespace JabyEngine { void setup() { GPU_IO::GP1.write(GPU_IO::Command::GP1::Reset()); - ScreenHelper::configurate(); - ScreenHelper::exchange_buffer_and_display(); + internal::Screen::configurate(); + internal::Screen::exchange_buffer_and_display(); - GPU::wait_ready_for_CMD(); - quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height)); + 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/File/Processor/tim_processor.cpp b/src/Library/src/File/Processor/tim_processor.cpp index b5faee68..636a00eb 100644 --- a/src/Library/src/File/Processor/tim_processor.cpp +++ b/src/Library/src/File/Processor/tim_processor.cpp @@ -1,4 +1,4 @@ -#include "../../../include/GPU/gpu.hpp" +#include "../../../include/GPU/gpu_internal.hpp" #include "simplehelper.hpp" #include #include @@ -39,9 +39,9 @@ namespace JabyEngine { }; static void set_gpu_receive(const uint32_t* src, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { - GPU::DMA::Receive::prepare(); - GPU::DMA::Receive::set_dst(PositionU16(x, y), SizeU16(w, h)); - GPU::DMA::Receive::set_src(reinterpret_cast(src)); + GPU::internal::DMA::Receive::prepare(); + GPU::internal::DMA::Receive::set_dst(PositionU16(x, y), SizeU16(w, h)); + GPU::internal::DMA::Receive::set_src(reinterpret_cast(src)); } static void set_gpu_receive_data(const uint32_t* src, SimpleTIMState& state, uint16_t width, uint16_t height) { @@ -58,8 +58,8 @@ namespace JabyEngine { const auto block_send = (block_count > UI16_MAX) ? UI16_MAX : block_count; // Send data! - GPU::DMA::wait(); - GPU::DMA::Receive::start(block_send); + GPU::internal::DMA::wait(); + GPU::internal::DMA::Receive::start(block_send); block_count -= block_send; } @@ -67,12 +67,12 @@ namespace JabyEngine { // Send words const auto last_words = (words_to_use & 0b1111); if(last_words > 0) { - GPU::DMA::wait(); - GPU::DMA::Receive::start(1, last_words); + GPU::internal::DMA::wait(); + GPU::internal::DMA::Receive::start(1, last_words); } - GPU::DMA::wait(); - GPU::DMA::end(); + GPU::internal::DMA::wait(); + GPU::internal::DMA::end(); state.words_left = 0; config.processed(words_to_use); diff --git a/src/Library/src/GPU/gpu.cpp b/src/Library/src/GPU/gpu.cpp index 27aa069a..31a1cc91 100644 --- a/src/Library/src/GPU/gpu.cpp +++ b/src/Library/src/GPU/gpu.cpp @@ -1,19 +1,23 @@ -#include "../include/GPU/gpu.hpp" +#include "../include/GPU/gpu_internal.hpp" namespace JabyEngine { namespace GPU { uint8_t Screen :: CurrentDisplayAreaID = 1; //< Setup will call exchange and set it to 0 - #ifdef JABYENGINE_PAL - static constexpr uint16_t ScanlinesV = 288; - #else - static constexpr uint16_t ScanlinesV = 240; - #endif //JABYENGINE_PAL + namespace internal { + typedef ::JabyEngine::GPU::Screen PublicScreenClass; - void ScreenHelper :: exchange_buffer_and_display() { - GPU::set_draw_area(0, (Display::Height*Screen::CurrentDisplayAreaID)); - Screen::CurrentDisplayAreaID ^= 1; - GPU_IO::GP1.write(GPU_IO::Command::GP1::DisplayArea(0, (Display::Height*Screen::CurrentDisplayAreaID))); + #ifdef JABYENGINE_PAL + static constexpr uint16_t ScanlinesV = 288; + #else + static constexpr uint16_t ScanlinesV = 240; + #endif //JABYENGINE_PAL + + void Screen :: exchange_buffer_and_display() { + GPU::internal::set_draw_area(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID)); + PublicScreenClass::CurrentDisplayAreaID ^= 1; + GPU_IO::GP1.write(GPU_IO::Command::GP1::DisplayArea(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID))); + } } #ifndef USE_NO$PSX