pcsx-redux/tools/vscode-extension/templates/psyqo/hello/main.cpp
2024-01-04 04:43:14 -08:00

72 lines
1.8 KiB
C++

{{=<% %>=}}#include <stdint.h>
#include "third_party/nugget/common/syscalls/syscalls.h"
#include "third_party/nugget/psyqo/application.hh"
#include "third_party/nugget/psyqo/font.hh"
#include "third_party/nugget/psyqo/gpu.hh"
#include "third_party/nugget/psyqo/scene.hh"
namespace {
// A PSYQo software needs to declare one \`Application\` object.
// This is the one we're going to do for our hello world.
class Hello final : public psyqo::Application {
void prepare() override;
void createScene() override;
public:
psyqo::Font<> m_font;
};
// And we need at least one scene to be created.
// This is the one we're going to do for our hello world.
class HelloScene final : public psyqo::Scene {
void frame() override;
// We'll have some simple animation going on, so we
// need to keep track of our state here.
uint8_t m_anim = 0;
bool m_direction = true;
};
// We're instantiating the two objects above right now.
Hello hello;
HelloScene helloScene;
} // namespace
void Hello::prepare() {
psyqo::GPU::Configuration config;
config.set(psyqo::GPU::Resolution::W320)
.set(psyqo::GPU::VideoMode::AUTO)
.set(psyqo::GPU::ColorMode::C15BITS)
.set(psyqo::GPU::Interlace::PROGRESSIVE);
gpu().initialize(config);
}
void Hello::createScene() {
m_font.uploadSystemFont(gpu());
pushScene(&helloScene);
}
void HelloScene::frame() {
if (m_anim == 0) {
m_direction = true;
} else if (m_anim == 255) {
m_direction = false;
}
psyqo::Color bg{{.r = 0, .g = 64, .b = 91}};
bg.r = m_anim;
hello.gpu().clear(bg);
if (m_direction) {
m_anim++;
} else {
m_anim--;
}
psyqo::Color c = {{.r = 255, .g = 255, .b = uint8_t(255 - m_anim)}};
hello.m_font.print(hello.gpu(), "Hello World!", {{.x = 16, .y = 32}}, c);
}
int main() { return hello.run(); }