#ifndef __JABYENGINE_GPU_INTERNAL_HPP__ #define __JABYENGINE_GPU_INTERNAL_HPP__ #include #include #include namespace JabyEngine { namespace GPU { namespace internal { struct Display { typedef ::JabyEngine::GPU::Display PublicDisplay; static constexpr auto Width = PublicDisplay::Width; static constexpr auto Height = PublicDisplay::Height; #ifdef JABYENGINE_PAL static constexpr auto DisplayMode = GPU_IO::DisplayMode_t::PAL(); static constexpr uint16_t ScanlinesV = 288; #else static constexpr auto DisplayMode = GPU_IO::DisplayMode_t::NTSC(); static constexpr uint16_t ScanlinesV = 240; #endif //JABYENGINE_PAL static uint32_t exchange_buffer_and_display(); }; void wait_vsync(uint8_t syncs); static void wait_ready_for_CMD() { while(!GPU_IO::GPUSTAT.is_set(GPU_IO::GPUSTAT_t::GP0ReadyForCMD)); } static void set_draw_area(uint16_t x, uint16_t y) { const auto top_left = GPU_IO::Command::DrawAreaTopLeft(x, y); const auto bottom_right = GPU_IO::Command::DrawAreaBottomRight((x + Display::Width - 1), (y + Display::Height - 1)); wait_ready_for_CMD(); GPU_IO::GP0 = top_left; wait_ready_for_CMD(); GPU_IO::GP0 = bottom_right; } static void copy_vram_to_vram(const AreaU16& dst, const PositionU16& src) { wait_ready_for_CMD(); GPU_IO::GP0 = GPU_IO::Command::VRAM2VRAM_Blitting(); GPU_IO::GP0 = GPU_IO::Command::TopLeftPosition(src.x, src.y); GPU_IO::GP0 = GPU_IO::Command::TopLeftPosition(dst.position.x, dst.position.y); GPU_IO::GP0 = GPU_IO::Command::WidthHeight(dst.size.width, dst.size.height); } static void quick_fill_fast(const Color24& color, const AreaU16& area) { wait_ready_for_CMD(); GPU_IO::GP0 = GPU_IO::Command::QuickFill(color); GPU_IO::GP0 = GPU_IO::Command::TopLeftPosition(area.position.x, area.position.y); GPU_IO::GP0 = GPU_IO::Command::WidthHeight(area.size.width, area.size.height); } static void set_draw_offset(int16_t x, int16_t y) { wait_ready_for_CMD(); GPU_IO::GP0 = GPU_IO::Command::SetDrawOffset(x, y); } static void reset_cmd_buffer() { GPU_IO::GP1 = GPU_IO::Command::ResetCMDBufer(); } namespace DMA { static void wait() { ::JabyEngine::DMA_IO::GPU.wait(); } static void end() { reset_cmd_buffer(); } namespace Receive { static void prepare() { GPU_IO::GP1 = GPU_IO::Command::DMADirection(GPU_IO::DMADirection::CPU2GPU); reset_cmd_buffer(); } static void set_src(uintptr_t adr) { DMA_IO::GPU.set_adr(adr); } static void set_dst(const PositionU16& position, const SizeU16& size) { wait_ready_for_CMD(); GPU_IO::GP0 = GPU_IO::Command::CPU2VRAM_Blitting(); GPU_IO::GP0 = GPU_IO::Command::TopLeftPosition(position.x, position.y); GPU_IO::GP0 = GPU_IO::Command::WidthHeight(size.width, size.height); } static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) { typedef DMA_IO::BCR_t::SyncMode1 SyncMode1; DMA_IO::GPU.block_ctrl = DMA_IO::BCR_t::from(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount)); DMA_IO::GPU.channel_ctrl = DMA_IO::CHCHR_t::StartGPUReceive(); } } } } } } #endif //!__JABYENGINE_GPU_INTERNAL_HPP__