From 165346127916f6d810231151e18dc8982550a4b0 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 1 Apr 2024 16:43:54 -0500 Subject: [PATCH] Finish detecting BIOS type --- .../src/Overlay/BIOSInfo/bios_info.cpp | 71 +++++++-------- include/PSX/GPU/gpu_types.hpp | 8 ++ include/PSX/System/syscalls.hpp | 26 +++--- .../BootLoader/boot_loader.hpp | 6 +- src/Library/src/BootLoader/start_boot.cpp | 12 +-- src/Library/src/BootLoader/syscall_boot.cpp | 88 +++++++++++++++++++ src/Library/src/System/syscall.cpp | 81 +---------------- 7 files changed, 150 insertions(+), 142 deletions(-) create mode 100644 src/Library/src/BootLoader/syscall_boot.cpp diff --git a/examples/PoolBox/application/src/Overlay/BIOSInfo/bios_info.cpp b/examples/PoolBox/application/src/Overlay/BIOSInfo/bios_info.cpp index 7c94562e..23d1f516 100644 --- a/examples/PoolBox/application/src/Overlay/BIOSInfo/bios_info.cpp +++ b/examples/PoolBox/application/src/Overlay/BIOSInfo/bios_info.cpp @@ -1,9 +1,10 @@ #include "../../../include/asset_mgr.hpp" #include "../../../include/shared.hpp" -#include +#include #include #include #include +#include #include #include @@ -11,6 +12,8 @@ namespace BIOSInfo { using namespace JabyEngine; static constexpr auto TextOffset = Make::PositionI16(16, 16); + using NameColorPair = pair; + struct FontSlider { static constexpr auto MoveTimeout = static_cast(300_ms); static constexpr auto WaitTimeout = static_cast(1000_ms); @@ -60,52 +63,46 @@ namespace BIOSInfo { {.bios_str_offset = &BIOS::Version::copyright, .display_str = "Copyright"}, }; - static GPU::TILE::Linked border_tiles[2] = { + static GPU::TILE::Linked border_tiles[2] = { Make::TILE(Make::AreaI16(0, 0, TextOffset.x, GPU::Display::Height - 32), GPU::Color24::Black()).linked(), Make::TILE(Make::AreaI16(GPU::Display::Width - TextOffset.x, 0, TextOffset.x, GPU::Display::Height - 32), GPU::Color24::Black()).linked() }; - static const char* bios_name = nullptr; - static FontSlider bios_name_slider; + static NameColorPair bios_name; + static FontSlider bios_name_slider; - static const char* get_bios_name() { - switch(BIOS::type) { - case BIOS::Type::Devboard: - return "DevBoard"; - case BIOS::Type::PS1: - return "PS1"; - case BIOS::Type::PS2: - return "PS2"; - case BIOS::Type::PS3: - return "PS3"; - case BIOS::Type::PSCompatible: - return "Unkown PS compatible BIOS"; - case BIOS::Type::No$psx: - return "NO$PSX"; - case BIOS::Type::XEBRA: - return "XEBRA"; + static NameColorPair get_bios_name() { + switch(BIOS::version.type) { + case BIOS::Version::Devboard: + return {"DevBoard", GPU::Color24::Green()}; + case BIOS::Version::PS1: + return {"PS1", GPU::Color24::Red()}; + case BIOS::Version::PS2: + return {"PS2", GPU::Color24::Blue()}; + case BIOS::Version::PS3: + return {"PS3", GPU::Color24::Yellow()}; + case BIOS::Version::PSCompatible: + return {"Unkown PS compatible BIOS", GPU::Color24::Grey()}; + case BIOS::Version::No$psx: + return {"NO$PSX", GPU::Color24::Purple()}; + case BIOS::Version::XEBRA: + return {"XEBRA", GPU::Color24::Turquoise()}; default: - return "Unkown"; + return {"Unkown", GPU::Color24::White()}; } } - static BIOS::Version setup() { - const auto result = BIOS::get_bios_version(); - - if(!bios_name) { - bios_name = get_bios_name(); - } - + static void setup() { + bios_name = get_bios_name(); Shared::back_menu.reset(); for(auto& bios_str_info : BIOSStringInfo) { - bios_str_info.font_slider = FontSlider::create_for(FontWriter::BIOSFont::Info, result.*(bios_str_info.bios_str_offset)); + bios_str_info.font_slider = FontSlider::create_for(FontWriter::BIOSFont::Info, BIOS::version.*(bios_str_info.bios_str_offset)); } - bios_name_slider = FontSlider::create_for(FontWriter::BIOSFont::Info, bios_name); + bios_name_slider = FontSlider::create_for(FontWriter::BIOSFont::Info, bios_name.first); border_tiles[0].concat(border_tiles[1]); - return result; } - static bool update_or_exit(const BIOS::Version& bios_version) { + static bool update_or_exit() { 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; @@ -117,17 +114,17 @@ namespace BIOSInfo { } auto cursor = FontWriter::update(TextOffset); - FontWriter::bios_font_writer.write(cursor, "BIOS INFORMATION\n----------------\nDate (day/month/year):\n%i/%i/%i\n", bios_version.date.day, bios_version.date.month, bios_version.date.year); + FontWriter::bios_font_writer.write(cursor, "BIOS INFORMATION\n----------------\nDate (day/month/year):\n%i/%i/%i\n", BIOS::version.date.day, BIOS::version.date.month, BIOS::version.date.year); const auto old_pos_x = cursor.pos.x; for(auto& bios_str_info : BIOSStringInfo) { bios_str_info.font_slider.advance(); FontWriter::bios_font_writer.write(move_cursor(cursor, 0, old_pos_x), "%s:\n", bios_str_info.display_str); - FontWriter::bios_font_writer.write(move_cursor(cursor, bios_str_info.font_slider.count, old_pos_x), "%s\n", bios_version.*(bios_str_info.bios_str_offset)); + FontWriter::bios_font_writer.write(move_cursor(cursor, bios_str_info.font_slider.count, old_pos_x), "%s\n", BIOS::version.*(bios_str_info.bios_str_offset)); } FontWriter::bios_font_writer.write(move_cursor(cursor, 0, old_pos_x), "BIOS Type:\n"); - FontWriter::bios_font_writer.write(move_cursor(cursor, bios_name_slider.count, old_pos_x), "%s\n", bios_name); + FontWriter::bios_font_writer.write(move_cursor(cursor, bios_name_slider.count, old_pos_x), "%s\n", bios_name.second, bios_name.first); FontWriter::bios_font_writer.write(move_cursor(cursor, 0, old_pos_x), "----------------\n"); return false; @@ -140,9 +137,9 @@ namespace BIOSInfo { } void main() { - const auto bios_version = setup(); + setup(); while(true) { - if(update_or_exit(bios_version)) { + if(update_or_exit()) { break; } GPU::swap_buffers_vsync(1); diff --git a/include/PSX/GPU/gpu_types.hpp b/include/PSX/GPU/gpu_types.hpp index 596d3a87..7d1a41b1 100644 --- a/include/PSX/GPU/gpu_types.hpp +++ b/include/PSX/GPU/gpu_types.hpp @@ -83,6 +83,14 @@ namespace JabyEngine { static constexpr T Yellow(uint8_t base = 0xFF) { return T::from_rgb(base, base, 0x0); } + + static constexpr T Purple(uint8_t base = 0xFF) { + return T::from_rgb(base, 0x0, base); + } + + static constexpr T Turquoise(uint8_t base = 0xFF) { + return T::from_rgb(0x0, base, base); + } }; } diff --git a/include/PSX/System/syscalls.hpp b/include/PSX/System/syscalls.hpp index ca181155..28ba8aa5 100644 --- a/include/PSX/System/syscalls.hpp +++ b/include/PSX/System/syscalls.hpp @@ -19,30 +19,30 @@ R31 ra Return address (set by function call) namespace JabyEngine { namespace BIOS { struct Version { + enum Type { + Unkown, + Devboard, + PS1, + PS2, + PS3, + PSCompatible, // internal usage only + No$psx, + XEBRA + }; + struct { uint8_t day; uint8_t month; uint16_t year; } date; + Type type; const char* kernel_maker; const char* version_str; const char* gui_version; const char* copyright; }; - enum struct Type { - Devboard, - PS1, - PS2, - PS3, - PSCompatible, // internal usage only - No$psx, - XEBRA, - Unkown - }; - - Version get_bios_version(); - extern Type type; + extern const Version version; } namespace SysCall { diff --git a/src/Library/internal-include/BootLoader/boot_loader.hpp b/src/Library/internal-include/BootLoader/boot_loader.hpp index 829e38d2..38b3ac0f 100644 --- a/src/Library/internal-include/BootLoader/boot_loader.hpp +++ b/src/Library/internal-include/BootLoader/boot_loader.hpp @@ -4,6 +4,10 @@ namespace JabyEngine { namespace boot { + namespace BIOS { + void identify(); + } + namespace CD { void setup(); } @@ -35,5 +39,5 @@ namespace JabyEngine { } } - void __no_return run(); + void __no_return run(); } \ No newline at end of file diff --git a/src/Library/src/BootLoader/start_boot.cpp b/src/Library/src/BootLoader/start_boot.cpp index dcf0cb3b..16c77941 100644 --- a/src/Library/src/BootLoader/start_boot.cpp +++ b/src/Library/src/BootLoader/start_boot.cpp @@ -99,25 +99,15 @@ namespace JabyEngine { printf("---\n"); } } - - namespace BIOS { - namespace internal { - Type get_bios_type(); - } - } namespace boot { namespace Start { - static void identify_bios() { - BIOS::type = BIOS::internal::get_bios_type(); - } - static void setup() { static constexpr auto DebugX = 1; static constexpr auto DebugY = 0; static constexpr auto DebugScale = 1.0; - identify_bios(); + BIOS::identify(); __debug_boot_color_at(::JabyEngine::GPU::Color24::Grey(), DebugX, DebugY, DebugScale); DMA::setup(); diff --git a/src/Library/src/BootLoader/syscall_boot.cpp b/src/Library/src/BootLoader/syscall_boot.cpp new file mode 100644 index 00000000..364532fd --- /dev/null +++ b/src/Library/src/BootLoader/syscall_boot.cpp @@ -0,0 +1,88 @@ +#include +#include +#include + +namespace JabyEngine { + namespace boot { + namespace BIOS { + using Version = JabyEngine::BIOS::Version; + + static uint32_t get_bcd_version() { + return *reinterpret_cast(0xBFC00100); + } + + static const char* get_kernel_maker_str() { + return reinterpret_cast(0xBFC00108); + } + + static const char* get_version_str() { + const char* kernel_maker = get_kernel_maker_str(); + const char* ver_start = kernel_maker + (strlen(kernel_maker) + 1); + + while(*ver_start == 0) { + ver_start++; + } + return ver_start; + } + + static Version::Type get_raw_bios_type(const char* version_str) { + static const auto str_length = [](const char (&name)[N]) -> size_t { + return N - 1; + }; + const char dev_str[] = "DTL-"; + const char ps1_str[] = "CEX-"; + const char ps_compatible_str[] = "PS compatible mode"; + const char no$psx_str[] = "no$psx"; + const char xebra_str[] = "XEBRA"; + + const struct { + const char* name; + size_t name_length; + Version::Type type; + } bioses[] = { + // Sorted by likeliness + {.name = ps1_str, .name_length = str_length(ps1_str), .type = Version::Type::PS1}, + {.name = ps_compatible_str, .name_length = str_length(ps_compatible_str), .type = Version::Type::PSCompatible}, + {.name = no$psx_str, .name_length = str_length(no$psx_str), .type = Version::Type::No$psx}, + {.name = xebra_str, .name_length = str_length(xebra_str), .type = Version::Type::XEBRA}, + {.name = dev_str, .name_length = str_length(dev_str), .type = Version::Type::Devboard} + }; + + for(const auto& bios : bioses) { + if(strncmp(version_str, bios.name, bios.name_length) == 0) { + return bios.type; + } + } + return Version::Type::Unkown; + } + + static Version::Type refine_bios_type(Version::Type type) { + if(type == Version::Type::PSCompatible) { + const auto bios_year_bcd = get_bcd_version() >> 16; + return bios_year_bcd == 0x2011 ? Version::Type::PS3 : Version::Type::PS2; + } + return type; + } + + static Version get_bios_version() { + Version version; + const auto date_bcd = get_bcd_version(); + const char*const version_str = get_version_str(); + + version.date.day = from_bcd(static_cast(date_bcd & 0xFF)); + version.date.month = from_bcd(static_cast((date_bcd >> 8) & 0xFF)); + version.date.year = from_bcd(static_cast(date_bcd >> 16)); + version.type = refine_bios_type(get_raw_bios_type(version_str)); + version.kernel_maker = get_kernel_maker_str(); + version.version_str = version_str; + version.gui_version = reinterpret_cast(0xBFC7FF32); + version.copyright = version.gui_version + (strlen(version.gui_version) + 1); + return version; + } + + void identify() { + const_cast(JabyEngine::BIOS::version) = get_bios_version(); + } + } + } +} \ No newline at end of file diff --git a/src/Library/src/System/syscall.cpp b/src/Library/src/System/syscall.cpp index a98f0b04..11ec3291 100644 --- a/src/Library/src/System/syscall.cpp +++ b/src/Library/src/System/syscall.cpp @@ -4,85 +4,6 @@ namespace JabyEngine { namespace BIOS { - static uint32_t get_bcd_version() { - return *reinterpret_cast(0xBFC00100); - } - - static const char* get_kernel_maker_str() { - return reinterpret_cast(0xBFC00108); - } - - static const char* get_version_str() { - const char* kernel_maker = get_kernel_maker_str(); - const char* ver_start = kernel_maker + (strlen(kernel_maker) + 1); - - while(*ver_start == 0) { - ver_start++; - } - return ver_start; - } - - // TODO: Move these to boot up code!! - static Type get_raw_bios_type() { - static const auto str_length = [](const char (&name)[N]) -> size_t { - return N - 1; - }; - const char dev_str[] = "DTL-"; - const char ps1_str[] = "CEX-"; - const char ps_compatible_str[] = "PS compatible mode"; - const char no$psx_str[] = "no$psx"; - const char xebra_str[] = "XEBRA"; - - const struct { - const char* name; - size_t name_length; - Type type; - } bioses[] = { - // Sorted by likeliness - {.name = ps1_str, .name_length = str_length(ps1_str), .type = Type::PS1}, - {.name = ps_compatible_str, .name_length = str_length(ps_compatible_str), .type = Type::PSCompatible}, - {.name = no$psx_str, .name_length = str_length(no$psx_str), .type = Type::No$psx}, - {.name = xebra_str, .name_length = str_length(xebra_str), .type = Type::XEBRA}, - {.name = dev_str, .name_length = str_length(dev_str), .type = Type::Devboard} - }; - - const char*const version_str = get_version_str(); - for(const auto& bios : bioses) { - if(strncmp(version_str, bios.name, bios.name_length) == 0) { - return bios.type; - } - } - return Type::Unkown; - } - - static Type refine_bios_type(Type type) { - if(type == Type::PSCompatible) { - const auto bios_year_bcd = get_bcd_version() >> 16; - return bios_year_bcd == 0x2011 ? Type::PS3 : Type::PS2; - } - return type; - } - - namespace internal { - Type get_bios_type() { - return refine_bios_type(get_raw_bios_type()); - } - } - - Version get_bios_version() { - Version version; - const auto date_bcd = get_bcd_version(); - - version.date.day = from_bcd(static_cast(date_bcd & 0xFF)); - version.date.month = from_bcd(static_cast((date_bcd >> 8) & 0xFF)); - version.date.year = from_bcd(static_cast(date_bcd >> 16)); - version.kernel_maker = get_kernel_maker_str(); - version.version_str = get_version_str(); - version.gui_version = reinterpret_cast(0xBFC7FF32); - version.copyright = version.gui_version + (strlen(version.gui_version) + 1); - return version; - } - - Type type = Type::Unkown; + const Version version = {0}; } } \ No newline at end of file