mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 18:46:43 +00:00
Added panic screen back
This commit is contained in:
parent
2644477847
commit
511515b9fa
4 changed files with 86 additions and 2 deletions
|
@ -75,6 +75,7 @@ internal class InputEmitter
|
|||
if (heldReboot >= rebootDelay)
|
||||
{
|
||||
heldReboot = 0;
|
||||
RuntimeManager.ResetPanic();
|
||||
RuntimeManager.Reboot();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,9 +135,18 @@ public class LuaState : IDisposable
|
|||
string stacktrace = Thread.OptString(-1, null);
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendLine(status switch
|
||||
{
|
||||
LuaStatus.ErrSyntax => "Syntax error",
|
||||
LuaStatus.ErrMem => "Out of memory",
|
||||
LuaStatus.ErrErr => "Error",
|
||||
LuaStatus.ErrRun => "Runtime error",
|
||||
_ => status.ToString()
|
||||
});
|
||||
builder.AppendLine(error);
|
||||
if (!string.IsNullOrWhiteSpace(stacktrace))
|
||||
{
|
||||
builder.AppendLine();
|
||||
builder.Append(stacktrace);
|
||||
}
|
||||
|
||||
|
|
57
Capy64/Runtime/PanicScreen.cs
Normal file
57
Capy64/Runtime/PanicScreen.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using Capy64.Core;
|
||||
using Capy64.Runtime.Libraries;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Capy64.Runtime;
|
||||
|
||||
public class PanicScreen
|
||||
{
|
||||
public static Color ForegroundColor = Color.White;
|
||||
public static Color BackgroundColor = new Color(0, 51, 187);
|
||||
|
||||
public static void Render(string error, string details = null)
|
||||
{
|
||||
Term.ForegroundColor = ForegroundColor;
|
||||
Term.BackgroundColor = BackgroundColor;
|
||||
Term.SetCursorBlink(false);
|
||||
Term.SetSize(51, 19);
|
||||
Term.Clear();
|
||||
|
||||
var title = " Capy64 ";
|
||||
var halfX = (Term.Width / 2) + 1;
|
||||
Term.SetCursorPosition(halfX - (title.Length / 2), 2);
|
||||
Term.ForegroundColor = BackgroundColor;
|
||||
Term.BackgroundColor = ForegroundColor;
|
||||
Term.Write(title);
|
||||
|
||||
Term.ForegroundColor = ForegroundColor;
|
||||
Term.BackgroundColor = BackgroundColor;
|
||||
Term.SetCursorPosition(1, 4);
|
||||
Print(error + '\n');
|
||||
|
||||
if (details is not null)
|
||||
{
|
||||
Print(details);
|
||||
}
|
||||
Term.SetCursorPosition(1, 19);
|
||||
Print("Hold CTRL + ALT + INSERT to reboot.");
|
||||
}
|
||||
|
||||
private static void Print(string txt)
|
||||
{
|
||||
foreach (var ch in txt)
|
||||
{
|
||||
Term.Write(ch.ToString());
|
||||
if (Term.CursorPosition.X >= Term.Width || ch == '\n')
|
||||
{
|
||||
Term.SetCursorPosition(1, (int)Term.CursorPosition.Y + 1);
|
||||
}
|
||||
}
|
||||
Term.SetCursorPosition(1, (int)Term.CursorPosition.Y + 1);
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ internal class RuntimeManager : IPlugin
|
|||
private int step = 0;
|
||||
|
||||
private static bool close = false;
|
||||
private static bool inPanic = false;
|
||||
|
||||
private static IGame _game;
|
||||
public RuntimeManager(IGame game)
|
||||
|
@ -58,12 +59,28 @@ internal class RuntimeManager : IPlugin
|
|||
}
|
||||
|
||||
private void Resume()
|
||||
{
|
||||
if (inPanic) return;
|
||||
try
|
||||
{
|
||||
if (close || !luaState.ProcessQueue())
|
||||
{
|
||||
Start();
|
||||
}
|
||||
}
|
||||
catch (LuaException e)
|
||||
{
|
||||
Console.Error.WriteLine(e);
|
||||
inPanic = true;
|
||||
close = true;
|
||||
PanicScreen.Render(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetPanic()
|
||||
{
|
||||
inPanic = false;
|
||||
}
|
||||
|
||||
private void InitBIOS()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue