Display BIOS date correctly

This commit is contained in:
Jaby 2024-03-30 12:36:23 -05:00 committed by Jaby
parent 5e78816b4e
commit 723875a79c
4 changed files with 35 additions and 4 deletions

View File

@ -59,7 +59,7 @@ namespace BIOSInfo {
font_sliders[0] = FontSlider::create_for(FontWriter::BIOSFont::Info, result.kernel_maker); font_sliders[0] = FontSlider::create_for(FontWriter::BIOSFont::Info, result.kernel_maker);
font_sliders[1] = FontSlider::create_for(FontWriter::BIOSFont::Info, result.gui_version); font_sliders[1] = FontSlider::create_for(FontWriter::BIOSFont::Info, result.gui_version);
border_tiles[0].concat(border_tiles[1]); border_tiles[0].concat(border_tiles[1]);
return SysCall::get_bios_version(); return result;
} }
static bool update_or_exit(const SysCall::BIOSVersion& bios_version) { static bool update_or_exit(const SysCall::BIOSVersion& bios_version) {
@ -78,7 +78,7 @@ namespace BIOSInfo {
} }
auto cursor = FontWriter::update(TextOffset); auto cursor = FontWriter::update(TextOffset);
FontWriter::bios_font_writer.write(cursor, "BIOS INFORMATION\n----------------\nDate:\n%X\nKernel-Maker:\n", bios_version.date_bcd); FontWriter::bios_font_writer.write(cursor, "BIOS INFORMATION\n----------------\nDate (day/month/year):\n%i/%i/%i\nKernel-Maker:\n", bios_version.date.day, bios_version.date.month, bios_version.date.year);
const auto old_pos_x = cursor.pos.x; 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, font_sliders[0].count, old_pos_x), "%s\n", bios_version.kernel_maker);

View File

@ -1,7 +1,18 @@
#pragma once #pragma once
#include "types.hpp" #include "types.hpp"
#include <stddef.h>
namespace JabyEngine { namespace JabyEngine {
template<typename T>
static constexpr T pow(T base, T power) {
T result = base;
while(power > 1) {
result = result*base;
power--;
}
return result;
}
template<typename T> template<typename T>
static constexpr pair<T, T> div_and_mod(T value, T div) { static constexpr pair<T, T> div_and_mod(T value, T div) {
const auto result = value/div; const auto result = value/div;
@ -12,4 +23,15 @@ namespace JabyEngine {
const auto [tenth, rest] = div_and_mod(value, static_cast<uint8_t>(10)); const auto [tenth, rest] = div_and_mod(value, static_cast<uint8_t>(10));
return (tenth << 4 | rest); return (tenth << 4 | rest);
} }
template<typename T>
static constexpr T from_bcd(T value) {
T result = 0;
for(size_t n = 1; n < pow(10u, sizeof(T)*2); n *= 10) {
result += (value & 0b1111)*n;
value = value >> 4;
}
return result;
}
} }

View File

@ -56,7 +56,11 @@ namespace JabyEngine {
#pragma pack(pop) #pragma pack(pop)
struct BIOSVersion { struct BIOSVersion {
uint32_t date_bcd; struct {
uint8_t day;
uint8_t month;
uint16_t year;
} date;
const char* kernel_maker; const char* kernel_maker;
const char* gui_version; const char* gui_version;
}; };

View File

@ -1,3 +1,4 @@
#include <PSX/Auxiliary/math_helper.hpp>
#include <PSX/System/syscalls.hpp> #include <PSX/System/syscalls.hpp>
namespace JabyEngine { namespace JabyEngine {
@ -5,7 +6,11 @@ namespace JabyEngine {
BIOSVersion get_bios_version() { BIOSVersion get_bios_version() {
BIOSVersion version; BIOSVersion version;
version.date_bcd = *reinterpret_cast<uint32_t*>(0xBFC00100); const auto date_bcd = *reinterpret_cast<uint32_t*>(0xBFC00100);
version.date.day = from_bcd(static_cast<uint8_t>(date_bcd & 0xFF));
version.date.month = from_bcd(static_cast<uint8_t>((date_bcd >> 8) & 0xFF));
version.date.year = from_bcd(static_cast<uint16_t>(date_bcd >> 16));
version.kernel_maker = reinterpret_cast<const char*>(0xBFC00108); version.kernel_maker = reinterpret_cast<const char*>(0xBFC00108);
version.gui_version = reinterpret_cast<const char*>(0xBFC7FF32); version.gui_version = reinterpret_cast<const char*>(0xBFC7FF32);
return version; return version;