Files
palladium/tests/gfx/source/os/horizon-ctr.cpp
T

91 lines
2.4 KiB
C++
Raw Normal View History

2026-03-21 14:43:16 +01:00
#include <os/horizon-ctr.hpp>
#if defined(__3DS__)
#include <3ds.h>
#include <citro3d.h>
const u32 DisplayTransferFlags =
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |
GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |
GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO));
#include <pdsystem>
namespace PD {
struct HorizonCtr::Impl {
C3D_RenderTarget* Top = nullptr;
C3D_RenderTarget* Bottom = nullptr;
2026-03-22 21:50:53 +01:00
uint32_t* pSocBuf = nullptr;
2026-09-13 14:10:07 +02:00
int CurrentScreen = 0;
2026-03-21 14:43:16 +01:00
};
void HorizonCtr::Init() {
if (impl) return;
impl = new Impl();
2026-03-22 21:50:53 +01:00
impl->pSocBuf = (uint32_t*)std::aligned_alloc(0x1000, 0x100000);
if (impl->pSocBuf) {
Result ret = socInit(impl->pSocBuf, 0x100000);
if (R_FAILED(ret)) {
free(impl->pSocBuf);
impl->pSocBuf = nullptr;
}
}
link3dsStdio();
2026-03-21 14:43:16 +01:00
romfsInit();
2026-09-05 11:56:26 +02:00
osSetSpeedupEnable(true);
2026-03-21 14:43:16 +01:00
gfxInitDefault();
2026-09-05 22:52:59 +02:00
// consoleInit(GFX_BOTTOM, nullptr);
2026-03-21 14:43:16 +01:00
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
impl->Top =
C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
impl->Bottom =
C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetOutput(impl->Top, GFX_TOP, GFX_LEFT, DisplayTransferFlags);
C3D_RenderTargetSetOutput(impl->Bottom, GFX_BOTTOM, GFX_LEFT,
DisplayTransferFlags);
PD::Gfx::UseDriver<PD::GfxCitro3D>();
2026-09-06 14:21:30 +02:00
PD::Hid::UseDriver<PD::Hid3DS>();
2026-03-21 14:43:16 +01:00
}
void HorizonCtr::Deinit() {
if (impl) {
C3D_RenderTargetDelete(impl->Top);
C3D_RenderTargetDelete(impl->Bottom);
C3D_Fini();
gfxExit();
romfsExit();
2026-03-22 21:50:53 +01:00
socExit();
2026-03-21 14:43:16 +01:00
delete impl;
impl = nullptr;
}
}
bool HorizonCtr::Mainloop() {
pViewPort = ivec2(400, 240);
2026-03-22 21:50:53 +01:00
bool _kill = hidKeysUp() & KEY_START;
2026-09-05 22:52:59 +02:00
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
2026-09-13 14:10:07 +02:00
impl->CurrentScreen = 0;
2026-03-22 21:50:53 +01:00
return aptMainLoop() && !_kill;
2026-03-21 14:43:16 +01:00
}
void HorizonCtr::ClearViewPort() {
2026-09-13 14:10:07 +02:00
C3D_RenderTargetClear(impl->CurrentScreen ? impl->Bottom : impl->Top,
C3D_CLEAR_ALL, PD::Color(25, 25, 25, 25), 0);
}
void HorizonCtr::DrawOnScreen(int s) {
impl->CurrentScreen = s;
if (s == 0) {
C3D_FrameDrawOn(impl->Top);
pViewPort = PD::ivec2(400, 240);
} else if (s == 1) {
C3D_FrameDrawOn(impl->Bottom);
pViewPort = PD::ivec2(320, 240);
}
2026-03-21 14:43:16 +01:00
PD::Gfx::SetViewPort(pViewPort);
}
void HorizonCtr::SwapBuffers() { C3D_FrameEnd(0); }
} // namespace PD
#endif