1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-23 04:12:02 +00:00

fatal: Add fake monospace for hex output

This commit is contained in:
Michael Scire 2018-11-13 19:30:40 -08:00
parent d4ee772714
commit 98bdb2a7a3
4 changed files with 67 additions and 28 deletions

View file

@ -62,7 +62,7 @@ static void SetupConfigLanguages() {
u8"unable to restart the console, hold the POWER Button for 12 seconds\n"
u8"to turn the console off.\n\n"
u8"If the problem persists, refer to the Nintendo Support Website.\n"
u8"nintendo.com/switch/error\n";
u8"support.nintendo.com/switch/error\n";
}
/* TODO: Try to load dynamically. */

View file

@ -34,6 +34,8 @@ static u16 g_font_color = 0xFFFF;
static float g_font_sz = 16.0f;
static u32 g_line_x = 0, g_cur_x = 0, g_cur_y = 0;
static u32 g_mono_adv = 0;
static PlFontData g_font;
static PlFontData g_fonts[PlSharedFontType_Total];
static FT_Library g_library;
@ -70,7 +72,7 @@ static void DrawGlyph(FT_Bitmap *bitmap, u32 x, u32 y) {
}
}
static void DrawString(const char *str, bool add_line) {
static void DrawString(const char *str, bool add_line, bool mono = false) {
FT_UInt glyph_index;
FT_GlyphSlot slot = g_face->glyph;
@ -112,9 +114,9 @@ static void DrawString(const char *str, bool add_line) {
return;
}
DrawGlyph(&slot->bitmap, cur_x + slot->bitmap_left, cur_y - slot->bitmap_top);
DrawGlyph(&slot->bitmap, cur_x + slot->bitmap_left + ((mono && g_mono_adv > slot->advance.x) ? ((g_mono_adv - slot->advance.x) >> 7) : 0), cur_y - slot->bitmap_top);
cur_x += slot->advance.x >> 6;
cur_x += (mono ? g_mono_adv : slot->advance.x) >> 6;
cur_y += slot->advance.y >> 6;
}
}
@ -147,6 +149,20 @@ void FontManager::PrintFormat(const char *format, ...) {
Print(char_buf);
}
void FontManager::PrintMonospaceU64(u64 x) {
char char_buf[0x400];
snprintf(char_buf, sizeof(char_buf), "%016lX", x);
DrawString(char_buf, false, true);
}
void FontManager::PrintMonospaceU32(u32 x) {
char char_buf[0x400];
snprintf(char_buf, sizeof(char_buf), "%08X", x);
DrawString(char_buf, false, true);
}
void FontManager::SetFontColor(u16 color) {
g_font_color = color;
@ -169,6 +185,15 @@ u32 FontManager::GetY() {
void FontManager::SetFontSize(float fsz) {
g_font_sz = fsz;
g_ft_err = FT_Set_Char_Size(g_face, 0, static_cast<u32>(g_font_sz * 64.0f), 96, 96);
g_ft_err = FT_Load_Glyph(g_face, FT_Get_Char_Index(g_face, 'A'), FT_LOAD_DEFAULT);
if (g_ft_err == 0) {
g_ft_err = FT_Render_Glyph(g_face->glyph, FT_RENDER_MODE_NORMAL);
}
if (g_ft_err == 0) {
g_mono_adv = g_face->glyph->advance.x;
}
}
void FontManager::AddSpacingLines(float num_lines) {
@ -199,6 +224,6 @@ Result FontManager::InitializeSharedFont() {
g_ft_err = FT_New_Memory_Face(g_library, reinterpret_cast<const FT_Byte *>(g_font.address), g_font.size, 0, &g_face);
if (g_ft_err) return g_ft_err;
g_ft_err = FT_Set_Char_Size(g_face, 0, static_cast<u32>(g_font_sz * 64.0f), 96, 96);
SetFontSize(g_font_sz);
return g_ft_err;
}

View file

@ -39,4 +39,6 @@ class FontManager {
static void PrintFormatLine(const char *format, ...);
static void Print(const char *str);
static void PrintFormat(const char *format, ...);
static void PrintMonospaceU64(u64 x);
static void PrintMonospaceU32(u32 x);
};

View file

@ -206,7 +206,7 @@ Result ShowFatalTask::ShowFatal() {
FontManager::SetFontSize(16.0f);
FontManager::PrintFormat(config->error_msg, R_MODULE(this->ctx->error_code), R_DESCRIPTION(this->ctx->error_code), this->ctx->error_code);
FontManager::AddSpacingLines(0.5f);
FontManager::PrintFormatLine("Title: %016lx", this->title_id);
FontManager::PrintFormatLine("Title: %016lX", this->title_id);
FontManager::AddSpacingLines(0.5f);
FontManager::PrintFormatLine(u8"Firmware: %s (Atmosphère %u.%u.%u-%s)", GetFatalConfig()->firmware_version.display_version, CURRENT_ATMOSPHERE_VERSION, GetAtmosphereGitRevision());
FontManager::AddSpacingLines(1.5f);
@ -232,12 +232,19 @@ Result ShowFatalTask::ShowFatal() {
u32 x = FontManager::GetX();
FontManager::PrintFormat("%s:", Aarch32GprNames[i]);
FontManager::SetPosition(x + 47, FontManager::GetY());
FontManager::PrintFormat("0x%08x ", this->ctx->cpu_ctx.aarch32_ctx.r[i]);
FontManager::Print("0x");
FontManager::PrintMonospaceU32(this->ctx->cpu_ctx.aarch32_ctx.r[i]);
FontManager::Print(" ");
x = FontManager::GetX();
FontManager::PrintFormat("%s:", Aarch32GprNames[i + (NumAarch32Gprs / 2)]);
FontManager::SetPosition(x + 47, FontManager::GetY());
FontManager::PrintFormat("0x%08x ", this->ctx->cpu_ctx.aarch32_ctx.r[i]);
FontManager::Print("0x");
FontManager::PrintMonospaceU32(this->ctx->cpu_ctx.aarch32_ctx.r[i + (NumAarch32Gprs / 2)]);
if (i == (NumAarch32Gprs / 2) - 1) {
FontManager::Print(" ");
backtrace_x = FontManager::GetX();
}
FontManager::PrintLine("");
FontManager::SetPosition(32, FontManager::GetY());
@ -247,11 +254,12 @@ Result ShowFatalTask::ShowFatal() {
u32 x = FontManager::GetX();
FontManager::PrintFormat("%s:", Aarch64GprNames[i]);
FontManager::SetPosition(x + 47, FontManager::GetY());
FontManager::PrintFormat("0x%016lx ", this->ctx->cpu_ctx.aarch64_ctx.x[i]);
FontManager::PrintMonospaceU64(this->ctx->cpu_ctx.aarch64_ctx.x[i]);
FontManager::Print(" ");
x = FontManager::GetX();
FontManager::PrintFormat("%s:", Aarch64GprNames[i + (NumAarch64Gprs / 2)]);
FontManager::SetPosition(x + 47, FontManager::GetY());
FontManager::PrintFormat("0x%016lx ", this->ctx->cpu_ctx.aarch64_ctx.x[i]);
FontManager::PrintMonospaceU64(this->ctx->cpu_ctx.aarch64_ctx.x[i + (NumAarch64Gprs / 2)]);
if (i == (NumAarch64Gprs / 2) - 1) {
FontManager::Print(" ");
@ -271,16 +279,17 @@ Result ShowFatalTask::ShowFatal() {
bt_size = this->ctx->cpu_ctx.aarch64_ctx.stack_trace_size;
}
FontManager::SetPosition(backtrace_x, backtrace_y);
if (bt_size == 0) {
if (this->ctx->cpu_ctx.is_aarch32) {
FontManager::PrintFormatLine("Start Address: 0x%08x", this->ctx->cpu_ctx.aarch32_ctx.start_address);
FontManager::PrintFormatLine("Start Address: 0x%08X", this->ctx->cpu_ctx.aarch32_ctx.start_address);
} else {
FontManager::PrintFormatLine("Start Address: 0x%016lx", this->ctx->cpu_ctx.aarch64_ctx.start_address);
FontManager::PrintFormatLine("Start Address: 0x%016lX", this->ctx->cpu_ctx.aarch64_ctx.start_address);
}
} else {
FontManager::SetPosition(backtrace_x, backtrace_y);
if (this->ctx->cpu_ctx.is_aarch32) {
FontManager::PrintFormatLine("Backtrace (Start Address = 0x%08x)", this->ctx->cpu_ctx.aarch32_ctx.start_address);
FontManager::PrintFormatLine("Backtrace - Start Address: 0x%08X", this->ctx->cpu_ctx.aarch32_ctx.start_address);
FontManager::AddSpacingLines(0.5f);
for (u32 i = 0; i < Aarch32CpuContext::MaxStackTraceDepth / 2; i++) {
u32 bt_cur = 0, bt_next = 0;
@ -293,23 +302,25 @@ Result ShowFatalTask::ShowFatal() {
if (i < this->ctx->cpu_ctx.aarch32_ctx.stack_trace_size) {
u32 x = FontManager::GetX();
FontManager::PrintFormat("BT[%02X]: ", i);
FontManager::SetPosition(x + 76, FontManager::GetY());
FontManager::PrintFormat("0x%08x ", bt_cur);
FontManager::PrintFormat("BT[%02d]: ", i);
FontManager::SetPosition(x + 72, FontManager::GetY());
FontManager::PrintMonospaceU32(bt_cur);
FontManager::Print(" ");
}
if (i + Aarch32CpuContext::MaxStackTraceDepth / 2 < this->ctx->cpu_ctx.aarch32_ctx.stack_trace_size) {
u32 x = FontManager::GetX();
FontManager::PrintFormat("BT[%02X]: ", i + Aarch32CpuContext::MaxStackTraceDepth / 2);
FontManager::SetPosition(x + 76, FontManager::GetY());
FontManager::PrintFormat("0x%08x ", bt_next);
FontManager::PrintFormat("BT[%02d]: ", i + Aarch32CpuContext::MaxStackTraceDepth / 2);
FontManager::SetPosition(x + 72, FontManager::GetY());
FontManager::PrintMonospaceU32(bt_next);
}
FontManager::PrintLine("");
FontManager::SetPosition(backtrace_x, FontManager::GetY());
}
} else {
FontManager::PrintFormatLine("Backtrace (Start Address = 0x%016lx)", this->ctx->cpu_ctx.aarch64_ctx.start_address);
} else {
FontManager::PrintFormatLine("Backtrace - Start Address: 0x%016lX", this->ctx->cpu_ctx.aarch64_ctx.start_address);
FontManager::AddSpacingLines(0.5f);
for (u32 i = 0; i < Aarch64CpuContext::MaxStackTraceDepth / 2; i++) {
u64 bt_cur = 0, bt_next = 0;
@ -322,16 +333,17 @@ Result ShowFatalTask::ShowFatal() {
if (i < this->ctx->cpu_ctx.aarch64_ctx.stack_trace_size) {
u32 x = FontManager::GetX();
FontManager::PrintFormat("BT[%02X]: ", i);
FontManager::SetPosition(x + 76, FontManager::GetY());
FontManager::PrintFormat("0x%016lx ", bt_cur);
FontManager::PrintFormat("BT[%02d]: ", i);
FontManager::SetPosition(x + 72, FontManager::GetY());
FontManager::PrintMonospaceU64(bt_cur);
FontManager::Print(" ");
}
if (i + Aarch64CpuContext::MaxStackTraceDepth / 2 < this->ctx->cpu_ctx.aarch64_ctx.stack_trace_size) {
u32 x = FontManager::GetX();
FontManager::PrintFormat("BT[%02X]: ", i + Aarch64CpuContext::MaxStackTraceDepth / 2);
FontManager::SetPosition(x + 76, FontManager::GetY());
FontManager::PrintFormat("0x%016lx ", bt_next);
FontManager::PrintFormat("BT[%02d]: ", i + Aarch64CpuContext::MaxStackTraceDepth / 2);
FontManager::SetPosition(x + 72, FontManager::GetY());
FontManager::PrintMonospaceU64(bt_next);
}
FontManager::PrintLine("");