diff --git a/examples/PoolBox/application/src/Overlay/BIOSInfo/bios_info.cpp b/examples/PoolBox/application/src/Overlay/BIOSInfo/bios_info.cpp index f0aff8bf..9d5c58ab 100644 --- a/examples/PoolBox/application/src/Overlay/BIOSInfo/bios_info.cpp +++ b/examples/PoolBox/application/src/Overlay/BIOSInfo/bios_info.cpp @@ -1,34 +1,104 @@ #include "../../../include/asset_mgr.hpp" #include "../../../include/shared.hpp" +#include #include +#include +#include #include +#include namespace BIOSInfo { using namespace JabyEngine; + static constexpr auto TextOffset = Make::PositionI16(16, 16); + + struct FontSlider { + static constexpr auto MoveTimeout = static_cast(300_ms); + static constexpr auto WaitTimeout = static_cast(1000_ms); + + int16_t count; + int16_t max; + int8_t delta; + IntervalTimer wait_timer; + + static FontSlider create_for(const FontWriter::FontInfo& font_info, const char* str) { + return FontSlider{ + .count = 0, + .max = static_cast((strlen(str)*font_info.get_kern_size().width) - GPU::Display::Width + (TextOffset.x << 1)), + .delta = static_cast(font_info.get_kern_size().width/2), + .wait_timer = IntervalTimer::create(FontSlider::MoveTimeout) + }; + } + + void advance() { + if(this->wait_timer.is_expired()) { + this->wait_timer.reset(); + this->count += delta; + + if(this->count <= 0 || this->count >= this->max) { + this->delta *= -1; + this->wait_timer.set_interval(FontSlider::WaitTimeout); + } + + else { + this->wait_timer.set_interval(FontSlider::MoveTimeout); + } + } + } + }; + + static FontSlider font_sliders[2]; + static GPU::TILE::Linked border_tiles[2] = { + Make::TILE(Make::AreaI16(0, 0, TextOffset.x, GPU::Display::Height), GPU::Color24::Black()).linked(), + Make::TILE(Make::AreaI16(GPU::Display::Width - TextOffset.x, 0, TextOffset.x, GPU::Display::Height), GPU::Color24::Black()).linked() + }; + + static SysCall::BIOSVersion setup() { + const auto result = SysCall::get_bios_version(); - static void setup() { Shared::back_menu.reset(); - printf("Planschbecken!\n"); + font_sliders[0] = FontSlider::create_for(FontWriter::BIOSFont::Info, result.kernel_maker); + font_sliders[1] = FontSlider::create_for(FontWriter::BIOSFont::Info, result.gui_version); + border_tiles[0].concat(border_tiles[1]); + return SysCall::get_bios_version(); } - static bool update_or_exit() { + static bool update_or_exit(const SysCall::BIOSVersion& bios_version) { + static const auto move_cursor = [](JabyEngine::Cursor& cursor, int16_t dx, int16_t old_x) -> JabyEngine::Cursor& { + cursor.pos.x = (old_x - dx); + return cursor; + }; + Periphery::query_controller(); if(Shared::back_menu.update(Make::PositionI16(0, GPU::Display::Height - 32))) { return true; } + for(auto& font_slider : font_sliders) { + font_slider.advance(); + } + + auto cursor = FontWriter::update(TextOffset); + FontWriter::bios_font_writer.write(cursor, "BIOS INFORMATION\n----------------\nDate:\n%X\nKernel-Maker:\n", bios_version.date_bcd); + + const auto old_pos_x = cursor.pos.x; + FontWriter::bios_font_writer.write(move_cursor(cursor, font_sliders[0].count, old_pos_x), "%s\n", bios_version.kernel_maker); + FontWriter::bios_font_writer.write(move_cursor(cursor, 0, old_pos_x), "GUI-Version:\n"); + FontWriter::bios_font_writer.write(move_cursor(cursor, font_sliders[1].count, old_pos_x), "%s\n", bios_version.gui_version); + FontWriter::bios_font_writer.write(move_cursor(cursor, 0, old_pos_x), "----------------\n"); + return false; } static void render() { Shared::back_menu.render(); + FontWriter::bios_font_writer.render(); + GPU::render(border_tiles[0]); } void main() { - setup(); - + const auto bios_version = setup(); while(true) { - if(update_or_exit()) { + if(update_or_exit(bios_version)) { break; } GPU::swap_buffers_vsync(1); diff --git a/include/PSX/System/syscalls.hpp b/include/PSX/System/syscalls.hpp index 00234cdd..ff4951fe 100644 --- a/include/PSX/System/syscalls.hpp +++ b/include/PSX/System/syscalls.hpp @@ -55,6 +55,14 @@ namespace JabyEngine { }; #pragma pack(pop) + struct BIOSVersion { + uint32_t date_bcd; + const char* kernel_maker; + const char* gui_version; + }; + + BIOSVersion get_bios_version(); + #define __syscall_function_cast(table, ...) reinterpret_cast<__VA_ARGS__>(table) static __always_inline void* memcpy(void *dst, const void *src, size_t len) { diff --git a/include/PSX/Timer/frame_timer.hpp b/include/PSX/Timer/frame_timer.hpp index b665215e..45f2e6dd 100644 --- a/include/PSX/Timer/frame_timer.hpp +++ b/include/PSX/Timer/frame_timer.hpp @@ -27,6 +27,13 @@ namespace JabyEngine { public: constexpr SimpleTimer() = default; + static SimpleTimer create() { + SimpleTimer timer; + + timer.reset(); + return timer; + } + bool is_expired_for(T time) const { return static_cast((MasterTime::read_as() - this->value)) >= time; } @@ -46,6 +53,14 @@ namespace JabyEngine { constexpr IntervalTimer(T interval) : SimpleTimer(), interval(interval) { } + static constexpr IntervalTimer create(T interval) { + IntervalTimer timer; + + static_cast&>(timer) = SimpleTimer::create(); + timer.interval = interval; + return timer; + } + void set_interval(T interval) { this->interval = interval; } diff --git a/include/string.h b/include/string.h new file mode 100644 index 00000000..0d1fa71d --- /dev/null +++ b/include/string.h @@ -0,0 +1,9 @@ +#ifndef __STRING__H +#define __STRING__H +#include "PSX/jabyengine_defines.h" + +START_C_FUNCTIONS + size_t strlen(const char* str); +END_C_FUNCTIONS + +#endif // !__STRING__H \ No newline at end of file diff --git a/src/Library/src/System/string.cpp b/src/Library/src/System/string.cpp new file mode 100644 index 00000000..89f4a35f --- /dev/null +++ b/src/Library/src/System/string.cpp @@ -0,0 +1,10 @@ +#include + +START_C_FUNCTIONS + size_t strlen(const char *str) { + const char* end = str; + + for(; *end; ++end); + return(end - str); + } +END_C_FUNCTIONS \ No newline at end of file diff --git a/src/Library/src/System/syscall.cpp b/src/Library/src/System/syscall.cpp new file mode 100644 index 00000000..917a2174 --- /dev/null +++ b/src/Library/src/System/syscall.cpp @@ -0,0 +1,14 @@ +#include + +namespace JabyEngine { + namespace SysCall { + BIOSVersion get_bios_version() { + BIOSVersion version; + + version.date_bcd = *reinterpret_cast(0xBFC00100); + version.kernel_maker = reinterpret_cast(0xBFC00108); + version.gui_version = reinterpret_cast(0xBFC7FF32); + return version; + } + } +} \ No newline at end of file