From 560d899a9b57641970c47a08ac7ad9ecdcf84204 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 13 Nov 2018 13:11:41 -0800 Subject: [PATCH] Improve text rendering API, add ams version. --- stratosphere/fatal/source/fatal_font.cpp | 21 ++++++++++++++----- stratosphere/fatal/source/fatal_font.hpp | 5 +++-- .../fatal/source/fatal_task_screen.cpp | 9 +++++++- stratosphere/libstratosphere | 2 +- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/stratosphere/fatal/source/fatal_font.cpp b/stratosphere/fatal/source/fatal_font.cpp index b81c65126..e2fd4b3b2 100644 --- a/stratosphere/fatal/source/fatal_font.cpp +++ b/stratosphere/fatal/source/fatal_font.cpp @@ -31,6 +31,7 @@ static u16 *g_fb = nullptr; static u32 (*g_unswizzle_func)(u32, u32) = nullptr; static u16 g_font_color = 0xFFFF; +static u32 g_cur_x = 0, g_cur_y = 0; static PlFontData g_font; static PlFontData g_fonts[PlSharedFontType_Total]; @@ -68,13 +69,18 @@ static void DrawGlyph(FT_Bitmap *bitmap, u32 x, u32 y) { } } -void FontManager::DrawString(u32 x, u32 y, const char *str) { +void FontManager::PrintLine(const char *str) { FT_UInt glyph_index; FT_GlyphSlot slot = g_face->glyph; const size_t len = strlen(str); - u32 cur_x = x, cur_y = y; + u32 cur_x = g_cur_x, cur_y = g_cur_y; + ON_SCOPE_EXIT { + /* Advance to next line. */ + /* g_cur_x = g_cur_x; */ + g_cur_y = cur_y + (g_face->size->metrics.height >> 6); + }; for (u32 i = 0; i < len; ) { u32 cur_char; @@ -83,7 +89,7 @@ void FontManager::DrawString(u32 x, u32 y, const char *str) { i += unit_count; if (cur_char == '\n') { - cur_x = x; + cur_x = g_cur_x; cur_y += g_face->size->metrics.height >> 6; continue; } @@ -107,20 +113,25 @@ void FontManager::DrawString(u32 x, u32 y, const char *str) { } } -void FontManager::DrawFormat(u32 x, u32 y, const char *format, ...) { +void FontManager::PrintFormatLine(const char *format, ...) { va_list va_arg; va_start(va_arg, format); char char_buf[0x400]; vsnprintf(char_buf, sizeof(char_buf), format, va_arg); - DrawString(x, y, char_buf); + PrintLine(char_buf); } void FontManager::SetFontColor(u16 color) { g_font_color = color; } +void FontManager::SetPosition(u32 x, u32 y) { + g_cur_x = x; + g_cur_y = y; +} + void FontManager::ConfigureFontFramebuffer(u16 *fb, u32 (*unswizzle_func)(u32, u32)) { g_fb = fb; g_unswizzle_func = unswizzle_func; diff --git a/stratosphere/fatal/source/fatal_font.hpp b/stratosphere/fatal/source/fatal_font.hpp index ab553a28a..c72921065 100644 --- a/stratosphere/fatal/source/fatal_font.hpp +++ b/stratosphere/fatal/source/fatal_font.hpp @@ -30,6 +30,7 @@ class FontManager { static void ConfigureFontFramebuffer(u16 *fb, u32 (*unswizzle_func)(u32, u32)); static void SetFontColor(u16 color); - static void DrawString(u32 x, u32 y, const char *str); - static void DrawFormat(u32 x, u32 y, const char *format, ...); + static void SetPosition(u32 x, u32 y); + static void PrintLine(const char *str); + static void PrintFormatLine(const char *format, ...); }; \ No newline at end of file diff --git a/stratosphere/fatal/source/fatal_task_screen.cpp b/stratosphere/fatal/source/fatal_task_screen.cpp index b651c7ef9..81d4b143b 100644 --- a/stratosphere/fatal/source/fatal_task_screen.cpp +++ b/stratosphere/fatal/source/fatal_task_screen.cpp @@ -15,6 +15,9 @@ */ #include + +#include + #include "fatal_task_screen.hpp" #include "fatal_config.hpp" #include "fatal_font.hpp" @@ -198,7 +201,11 @@ Result ShowFatalTask::ShowFatal() { } /* TODO: Actually draw meaningful shit here. */ - FontManager::DrawFormat(32, 64, u8"A fatal error occurred: 2%03d-%04d\n", R_MODULE(this->ctx->error_code), R_DESCRIPTION(this->ctx->error_code)); + FontManager::SetPosition(32, 64); + FontManager::PrintFormatLine(u8"A fatal error occurred: 2%03d-%04d", R_MODULE(this->ctx->error_code), R_DESCRIPTION(this->ctx->error_code)); + FontManager::PrintFormatLine(u8"Firmware: %s (AMS %u.%u.%u-%s)", GetFatalConfig()->firmware_version.display_version, + CURRENT_ATMOSPHERE_VERSION, GetAtmosphereGitRevision()); + /* Enqueue the buffer. */ framebufferEnd(&fb); diff --git a/stratosphere/libstratosphere b/stratosphere/libstratosphere index 6a6eedeac..0fb33e9c0 160000 --- a/stratosphere/libstratosphere +++ b/stratosphere/libstratosphere @@ -1 +1 @@ -Subproject commit 6a6eedeacd69a4bddb1e43e31a642a1249a8eb88 +Subproject commit 0fb33e9c094bffde737c7a73cd5ccce4d7cbae33