summaryrefslogtreecommitdiff
path: root/RegionVisualiser
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-27 21:22:55 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-27 21:22:55 +1000
commit634681ce2bb36cd686943102a0f071cd6a09049f (patch)
tree6710047aa231d50f57114bdd54a27c559fb20a73 /RegionVisualiser
parent94ddc02e03ab942d0c881e29053e8df3d2940c30 (diff)
fixed bugs and revolutionized the universe
Diffstat (limited to 'RegionVisualiser')
-rw-r--r--RegionVisualiser/BoxDrawer.cs49
-rw-r--r--RegionVisualiser/Program.cs74
-rw-r--r--RegionVisualiser/Region.cs10
-rw-r--r--RegionVisualiser/RegionVisualiser.csproj14
-rw-r--r--RegionVisualiser/SizeFormatter.cs25
-rw-r--r--RegionVisualiser/output.txt18
6 files changed, 190 insertions, 0 deletions
diff --git a/RegionVisualiser/BoxDrawer.cs b/RegionVisualiser/BoxDrawer.cs
new file mode 100644
index 0000000..77d0fc7
--- /dev/null
+++ b/RegionVisualiser/BoxDrawer.cs
@@ -0,0 +1,49 @@
+namespace RegionVisualiser;
+
+public static class BoxDrawer
+{
+ public static void DrawBox(string title, string body, int width = 0, string head = "", string tail = "")
+ {
+ int leftPad = Math.Max(head.Length, tail.Length);
+ var lines = body.Split('\n');
+ int maxWidth = Math.Max(Math.Max(title.Length + 2, BoxDrawer.GetMaxWidth(lines) + 1), width);
+
+ // Top border with centered title
+ string top = "┌" + BoxDrawer.CenterText($" {title} ", maxWidth, '─') + "┐";
+ Console.Write(head);
+ Console.CursorLeft = leftPad;
+ Console.WriteLine(top);
+
+ // Body lines, left aligned
+ foreach (var line in lines)
+ {
+ Console.CursorLeft = leftPad;
+ Console.WriteLine("│ " + line.PadRight(maxWidth - 1) + "│");
+ }
+
+ // Bottom border
+ string bottom = "└" + new string('─', maxWidth) + "┘";
+ Console.Write(tail);
+ Console.CursorLeft = leftPad;
+ Console.WriteLine(bottom);
+ }
+
+ private static int GetMaxWidth(string[] lines)
+ {
+ int width = 0;
+ foreach (var l in lines)
+ if (l.Length + 1 > width) width = l.Length + 1;
+ return width;
+ }
+
+ private static string CenterText(string text, int width, char fill)
+ {
+ int totalPad = width - text.Length;
+ if (totalPad <= 0) return text;
+
+ int left = totalPad / 2;
+ int right = totalPad - left;
+
+ return new string(fill, left) + text + new string(fill, right);
+ }
+} \ No newline at end of file
diff --git a/RegionVisualiser/Program.cs b/RegionVisualiser/Program.cs
new file mode 100644
index 0000000..029f324
--- /dev/null
+++ b/RegionVisualiser/Program.cs
@@ -0,0 +1,74 @@
+namespace RegionVisualiser;
+
+using Q1.Emulator;
+
+class Program
+{
+ static void Main(string[] args)
+ {
+ Region[] regions =
+ [
+ new Region
+ {
+ Name = "ROM",
+ Info = $"ProgramStart: 0x{Q1Layout.ProgramStart:X4}",
+ Start = Q1Layout.Rom.start,
+ Size = Q1Layout.Rom.size
+ },
+ new Region
+ {
+ Name = "Memory",
+ Info =
+ $"Stack: 0x{Q1Layout.StackStart:X4}-0x{Q1Layout.StackStart + Q1Layout.StackLength:X4}"
+ + $" ({Q1Layout.StackLength}b)\n"
+ + $"Free : 0x{Q1Layout.FreeMemoryStart:X4}",
+ Start = Q1Layout.Memory.start,
+ Size = Q1Layout.Memory.size
+ },
+ new Region
+ {
+ Name = "Display",
+ Info = $"Palette : {Q1Layout.DisplayPaletteSize} colors\n"
+ + $"Offset : 0x{Q1Layout.Display.start + Q1Layout.DisplayPaletteSize * 3:X4}\n"
+ + $"Dimensions: {Q1Layout.DisplayWidth}x{Q1Layout.DisplayHeight}",
+ Start = Q1Layout.Display.start,
+ Size = Q1Layout.Display.size
+ },
+ new Region
+ {
+ Name = "HID Module",
+ Info = $"Mouse IDX : 0x{Q1Layout.Hid.start:X4}\n"
+ + $"Mouse state: 0x{Q1Layout.Hid.start + 2:X4}\n"
+ + $"Keyboard SK: 0x{Q1Layout.Hid.start + 4:X4}",
+ Start = Q1Layout.Hid.start,
+ Size = Q1Layout.Hid.size
+ },
+ ];
+
+ regions = regions.OrderBy(x => x.Start).ToArray();
+
+ int lastRegionEnd = -1;
+ for (int i = 0; i < regions.Length; i++)
+ {
+ Region r = regions[i];
+ if (r.Start != lastRegionEnd + 1)
+ {
+ Console.WriteLine($" 0x{lastRegionEnd + 1:X4} ────" + new string('─', 50));
+ Console.WriteLine($" [ Unmapped / Reserved ({SizeFormatter.HumanReadable(r.Start - lastRegionEnd)}) ]");
+ }
+ BoxDrawer.DrawBox(
+ $"{r.Name} ({SizeFormatter.HumanReadable(r.Size)})",
+ r.Info,
+ width: 50,
+ head: $" 0x{r.Start:X4} ── ");
+
+ lastRegionEnd = r.End;
+ }
+
+ if (lastRegionEnd + 1 != UInt16.MaxValue)
+ {
+ Console.WriteLine($" 0x{lastRegionEnd + 1:X4} ────" + new string('─', 50));
+ Console.WriteLine($" [ Unmapped / Reserved ({SizeFormatter.HumanReadable(UInt16.MaxValue - lastRegionEnd)}) ]");
+ }
+ }
+} \ No newline at end of file
diff --git a/RegionVisualiser/Region.cs b/RegionVisualiser/Region.cs
new file mode 100644
index 0000000..bee39f5
--- /dev/null
+++ b/RegionVisualiser/Region.cs
@@ -0,0 +1,10 @@
+namespace RegionVisualiser;
+
+public class Region
+{
+ public string Name;
+ public int Start;
+ public int Size;
+ public int End => this.Start + this.Size -1;
+ public string Info;
+} \ No newline at end of file
diff --git a/RegionVisualiser/RegionVisualiser.csproj b/RegionVisualiser/RegionVisualiser.csproj
new file mode 100644
index 0000000..d7bfae3
--- /dev/null
+++ b/RegionVisualiser/RegionVisualiser.csproj
@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net9.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\Emulator\Emulator.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/RegionVisualiser/SizeFormatter.cs b/RegionVisualiser/SizeFormatter.cs
new file mode 100644
index 0000000..3479bd8
--- /dev/null
+++ b/RegionVisualiser/SizeFormatter.cs
@@ -0,0 +1,25 @@
+namespace RegionVisualiser;
+
+public static class SizeFormatter
+{
+ private static readonly string[] Units = ["bytes", "KB", "MB", "GB", "TB"];
+
+ public static string HumanReadable(long bytes)
+ {
+ if (bytes < 1024) return $"{bytes} {SizeFormatter.Units[0]}";
+
+ double value = bytes;
+ int unit = 0;
+
+ while (value >= 1024 && unit < SizeFormatter.Units.Length - 1)
+ {
+ value /= 1024;
+ unit++;
+ }
+
+ // Show up to 2 decimal places if not whole
+ return value % 1 == 0
+ ? $"{value:0} {SizeFormatter.Units[unit]}"
+ : $"{value:0.##} {SizeFormatter.Units[unit]}";
+ }
+} \ No newline at end of file
diff --git a/RegionVisualiser/output.txt b/RegionVisualiser/output.txt
new file mode 100644
index 0000000..ecf83cc
--- /dev/null
+++ b/RegionVisualiser/output.txt
@@ -0,0 +1,18 @@
+ 0x0000 ──────────────────────────────────────────────────────
+ [ Unmapped / Reserved (8 KB) ]
+ 0x1FFF ── ┌─────────────────── ROM (8 KB) ───────────────────┐
+ │ ProgramStart: 0x1FFF │
+ └──────────────────────────────────────────────────┘
+ 0x3FFF ── ┌─────────────── Display (8.05 KB) ────────────────┐
+ │ Palette: 16 colors │
+ │ Offset: 0x402F │
+ │ Dimensions: 128x64 │
+ └──────────────────────────────────────────────────┘
+ 0x602F ──────────────────────────────────────────────────────
+ [ Unmapped / Reserved (3.95 KB) ]
+ 0x6FFF ── ┌───────────────── Memory (16 KB) ─────────────────┐
+ │ Stack: 0x6FFF-0x71FF (512b) │
+ │ Free : 0x71FF │
+ └──────────────────────────────────────────────────┘
+ 0xAFFF ──────────────────────────────────────────────────────
+ [ Unmapped / Reserved (20 KB) ] \ No newline at end of file