Skip to content

Commit

Permalink
Merge pull request #2 from xdanieldzd/restructure
Browse files Browse the repository at this point in the history
Merging restructure branch
  • Loading branch information
xdanieldzd authored May 24, 2022
2 parents a03ec4a + e47b1ae commit 54fa0e5
Show file tree
Hide file tree
Showing 194 changed files with 7,466 additions and 3,728 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[*.cs]

# CA1822: Member als statisch markieren
dotnet_diagnostic.CA1822.severity = silent
#dotnet_diagnostic.CA1822.severity = silent
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build
on: [push]

jobs:
build:
runs-on: windows-latest
strategy:
matrix:
project: ['StoicGoose', 'StoicGoose.GLWindow']
include:
- project: StoicGoose
csproj: StoicGoose\StoicGoose.csproj
artifacts: StoicGoose-artifacts
- project: StoicGoose.GLWindow
csproj: StoicGoose.GLWindow\StoicGoose.GLWindow.csproj
artifacts: StoicGoose.GLWindow-artifacts
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Publish
run: dotnet publish ${{ matrix.csproj }} -c Release -o release --nologo
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.artifacts }}
path: D:\a\StoicGoose\StoicGoose\release\*
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# StoicGoose
StoicGoose is a work-in-progress Bandai WonderSwan and WonderSwan Color emulator. It is written in C# via Visual Studio Community 2019 under Windows 10 Pro 21H2, and uses .NET Framework 5.0 along with the following NuGet packages:
StoicGoose is a work-in-progress Bandai WonderSwan and WonderSwan Color emulator. It is written in C# via Visual Studio Community 2022 under Windows 10 Pro 21H2, and uses .NET Framework 6.0 along with the following NuGet packages:

* [OpenTK](https://www.nuget.org/packages/OpenTK) 4.7.1 (for OpenGL rendering, OpenAL sound, etc.)
* [OpenTK](https://www.nuget.org/packages/OpenTK) 4.7.2 (for OpenGL rendering, OpenAL sound, etc.)
* [OpenTK.WinForms](https://www.nuget.org/packages/OpenTK.WinForms) 4.0.0-pre.6 (for WinForms OpenGL control)
* [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json) 13.0.1 (for configuration, cheats and breakpoint storage)
* [ImGui.NET](https://www.nuget.org/packages/ImGui.NET) 1.87.3 (for debugging UI)
* [GitInfo](https://www.nuget.org/packages/GitInfo) 2.2.0 (for versioning information)
* [Microsoft.CodeAnalysis.CSharp.Scripting](https://www.nuget.org/packages/Microsoft.CodeAnalysis.CSharp.Scripting) 4.1.0 (for breakpoint support)
* [Gee.External.Capstone](https://www.nuget.org/packages/Gee.External.Capstone) 2.0.2 (for x86 disassembly)
* [Microsoft.CodeAnalysis.CSharp.Scripting](https://www.nuget.org/packages/Microsoft.CodeAnalysis.CSharp.Scripting) 4.2.0 (for breakpoint support)
* [Iced](https://www.nuget.org/packages/Iced) 1.17.0 (for x86 disassembly)

## Screenshots
WonderSwan and WonderSwan Color Bootstraps, using Dot-Matrix and Dot-Matrix Color shaders:
Expand All @@ -29,5 +29,4 @@ Various debugging features:
## Acknowledgements & Attribution
* The XML data files in `Assets\No-Intro` were created by the [No-Intro](http://www.no-intro.org) project; see the [DAT-o-MATIC website](https://datomatic.no-intro.org) for official downloads.
* The file `WS-Icon.ico` is derived from "[WonderSwan-Black-Left.jpg](https://en.wikipedia.org/wiki/File:WonderSwan-Black-Left.jpg)" on [Wikipedia](https://en.wikipedia.org), in revision from 25 May 2014 by [Evan-Amos](https://commons.wikimedia.org/wiki/User:Evan-Amos), used as public domain.
* The file `Goose.png` is derived from "[Goose vectorized](https://openclipart.org/detail/282727/goose-vectorized)" on [Openclipart](https://openclipart.org/), uploaded on 7 July 2017 by [Firkin](https://openclipart.org/artist/Firkin), and used under [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/).
* My personal thanks and gratitude to the late Near, who has always been encouraging and inspiring on my amateur emulator developer journey. They are sorely missed.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;

namespace StoicGoose.Interface.Attributes
namespace StoicGoose.Common.Attributes
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class ImGuiBitDescriptionAttribute : Attribute
public class BitDescriptionAttribute : Attribute
{
public string Description { get; set; } = string.Empty;
public int LowBit { get; set; } = -1;
public int HighBit { get; set; } = -1;

public string BitString => LowBit != -1 ? $"B{LowBit}{(HighBit > LowBit ? $"-{HighBit}" : string.Empty)}: " : string.Empty;

public ImGuiBitDescriptionAttribute(string desc, int low = -1, int high = -1)
public BitDescriptionAttribute(string desc, int low = -1, int high = -1)
{
Description = desc;
LowBit = low;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;

namespace StoicGoose.Interface.Attributes
namespace StoicGoose.Common.Attributes
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class ImGuiFormatAttribute : Attribute
public class FormatAttribute : Attribute
{
public string Format { get; set; } = string.Empty;
public int Shift { get; set; } = 0;

public ImGuiFormatAttribute(string format, int shift = 0)
public FormatAttribute(string format, int shift = 0)
{
Format = format;
Shift = shift;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;

namespace StoicGoose.Interface.Attributes
namespace StoicGoose.Common.Attributes
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class ImGuiRegisterAttribute : Attribute
public class PortAttribute : Attribute
{
public string Name { get; set; } = string.Empty;
public List<ushort> Numbers { get; set; } = new();

public ImGuiRegisterAttribute(string name, params ushort[] numbers)
public PortAttribute(string name, params ushort[] numbers)
{
Name = name;
Numbers.AddRange(numbers);
Expand Down
2 changes: 1 addition & 1 deletion StoicGoose/Ansi.cs → StoicGoose.Common/Console/Ansi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace StoicGoose
namespace StoicGoose.Common.Console
{
public static class Ansi
{
Expand Down
145 changes: 145 additions & 0 deletions StoicGoose.Common/Console/ConsoleHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using System;
using System.Collections.Generic;

namespace StoicGoose.Common.Console
{
public enum ConsoleLogSeverity { Success, Information, Warning, Error }

public static class ConsoleHelpers
{
readonly static Dictionary<ConsoleLogSeverity, string> logSeverityAnsiColors = new()
{
{ ConsoleLogSeverity.Success, Ansi.Green },
{ ConsoleLogSeverity.Information, Ansi.Cyan },
{ ConsoleLogSeverity.Warning, Ansi.Yellow },
{ ConsoleLogSeverity.Error, Ansi.Red }
};

public static void WriteLog(ConsoleLogSeverity severity, object source, string message)
{
System.Console.WriteLine($"{logSeverityAnsiColors[severity]}[{source.GetType().Name}]{Ansi.Reset}: {message}");
}

// Such a stupid gimmick... but hey, I like stupid gimmicks and I especially like making them, so whatever~
public static void WriteGradientLine(string text, bool useHsl, params (byte r, byte g, byte b)[] colors)
{
var stepsPerColor = (int)Math.Round(text.Length / (colors.Length - 1f), MidpointRounding.AwayFromZero);
var steps = Math.Max(stepsPerColor * (colors.Length - 1), text.Length);

List<(byte r, byte g, byte b)> gradient = new();

for (int i = 0, c = 0; i < steps; i += stepsPerColor, c++)
{
if (useHsl)
{
var (h1, s1, l1) = RgbToHsl(colors[c + 0].r, colors[c + 0].g, colors[c + 0].b);
var (h2, s2, l2) = RgbToHsl(colors[c + 1].r, colors[c + 1].g, colors[c + 1].b);

for (var j = 0; j < stepsPerColor; j++)
{
var by = Math.Clamp((j / 1f) / ((stepsPerColor - 1) / 1f), 0f, 1f);
var (h, s, l) = Lerp(h1, s1, l1, h2, s2, l2, by);
gradient.Add(HslToRgb(h, s, l));
}
}
else
{
var (r1, g1, b1) = (colors[c + 0].r / 255f, colors[c + 0].g / 255f, colors[c + 0].b / 255f);
var (r2, g2, b2) = (colors[c + 1].r / 255f, colors[c + 1].g / 255f, colors[c + 1].b / 255f);

for (var j = 0; j < stepsPerColor; j++)
{
var by = Math.Clamp((j / 1f) / ((stepsPerColor - 1) / 1f), 0f, 1f);
gradient.Add(((byte)(Lerp(r1, r2, by) * 255), (byte)(Lerp(g1, g2, by) * 255), (byte)(Lerp(b1, b2, by) * 255)));
}
}
}

for (var i = 0; i < Math.Min(gradient.Count, text.Length); i++)
System.Console.Write($"{Ansi.RGB(gradient[i].r, gradient[i].g, gradient[i].b)}{text[i]}");
System.Console.Write(Environment.NewLine);
}

private static float Lerp(float v1, float v2, float by) => v1 * (1f - by) + v2 * by;
private static (float h, float s, float l) Lerp(float h1, float s1, float l1, float h2, float s2, float l2, float by) => (Lerp(h1, h2, by) % 360f, Math.Clamp(Lerp(s1, s2, by), 0f, 1f), Math.Clamp(Lerp(l1, l2, by), 0f, 1f));

// http://www.easyrgb.com/en/math.php
private static (float h, float s, float l) RgbToHsl(byte red, byte green, byte blue)
{
float h = 0f, s, l;

var r = red / 255f;
var g = green / 255f;
var b = blue / 255f;

var min = Math.Min(Math.Min(r, g), b);
var max = Math.Max(Math.Max(r, g), b);
var deltaMax = max - min;

l = (max + min) / 2f;

if (deltaMax == 0)
{
h = 0;
s = 0;
}
else
{
if (l < 0.5f) s = deltaMax / (max + min);
else s = deltaMax / (2f - max - min);

var deltaR = (((max - r) / 6f) + (deltaMax / 2f)) / deltaMax;
var deltaG = (((max - g) / 6f) + (deltaMax / 2f)) / deltaMax;
var deltaB = (((max - b) / 6f) + (deltaMax / 2f)) / deltaMax;

if (r == max) h = deltaB - deltaG;
else if (g == max) h = (1f / 3f) + deltaR - deltaB;
else if (b == max) h = (2f / 3f) + deltaG - deltaR;

if (h < 0f) h++;
if (h > 1f) h--;
}

return (h, s, l);
}

// http://www.easyrgb.com/en/math.php
private static (byte r, byte g, byte b) HslToRgb(float hue, float saturation, float lightness)
{
byte r, g, b;

if (saturation == 0f)
{
r = (byte)(lightness * 255);
g = (byte)(lightness * 255);
b = (byte)(lightness * 255);
}
else
{
float v1, v2;

if (lightness < 0.5f) v2 = lightness * (1f + saturation);
else v2 = (lightness + saturation) - (saturation * lightness);

v1 = 2f * lightness - v2;

r = (byte)(255 * HueToRgb(v1, v2, hue + (1f / 3f)));
g = (byte)(255 * HueToRgb(v1, v2, hue));
b = (byte)(255 * HueToRgb(v1, v2, hue - (1f / 3f)));
}

return (r, g, b);
}

private static float HueToRgb(float v1, float v2, float vh)
{
if (vh < 0f) vh++;
if (vh > 1) vh--;

if ((6f * vh) < 1f) return v1 + (v2 - v1) * 6f * vh;
if ((2f * vh) < 1f) return v2;
if ((3f * vh) < 2f) return v1 + (v2 - v1) * ((2f / 3f) - vh) * 6f;
return v1;
}
}
}
55 changes: 55 additions & 0 deletions StoicGoose.Common/Drawing/RgbaFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.IO;
using System.Linq;

namespace StoicGoose.Common.Drawing
{
/* RGBA bitmap file format -- https://github.com/bzotto/rgba_bitmap
* ".rgba is the dumbest possible image interchange format, now available for your programming pleasure."
*/

public class RgbaFile
{
const string expectedMagic = "RGBA";

public string MagicNumber { get; protected set; }
public uint Width { get; protected set; }
public uint Height { get; protected set; }
public byte[] PixelData { get; protected set; }

public RgbaFile(string filename) : this(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { }

public RgbaFile(Stream stream)
{
MagicNumber = ReadString(stream, 4);
Width = ReadUInt32(stream);
Height = ReadUInt32(stream);
PixelData = new byte[Width * Height * 4];
stream.Read(PixelData);
}

public RgbaFile(uint width, uint height, byte[] pixelData)
{
MagicNumber = expectedMagic;
Width = width;
Height = height;
PixelData = pixelData;
}

public void Save(string filename) => Save(new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite));

public void Save(Stream stream)
{
WriteString(stream, MagicNumber);
WriteUInt32(stream, Width);
WriteUInt32(stream, Height);
stream.Write(PixelData);
}

private static string ReadString(Stream stream, int length) => new(Enumerable.Range(0, length).Select(_ => (char)stream.ReadByte()).ToArray());
private static uint ReadUInt32(Stream stream) => (uint)(((stream.ReadByte() & 0xFF) << 24) | ((stream.ReadByte() & 0xFF) << 16) | ((stream.ReadByte() & 0xFF) << 8) | ((stream.ReadByte() & 0xFF) << 0));

private static void WriteString(Stream stream, string str) => Array.ForEach(str.ToCharArray(), (x) => stream.WriteByte((byte)x));
private static void WriteUInt32(Stream stream, uint val) { stream.WriteByte((byte)((val >> 24) & 0xFF)); stream.WriteByte((byte)((val >> 16) & 0xFF)); stream.WriteByte((byte)((val >> 8) & 0xFF)); stream.WriteByte((byte)((val >> 0) & 0xFF)); }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json;

namespace StoicGoose.Extensions
namespace StoicGoose.Common.Extensions
{
public static class ObjectExtensionMethods
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

using Newtonsoft.Json;

namespace StoicGoose.Extensions
namespace StoicGoose.Common.Extensions
{
public static class SerializationExtensionMethods
{
public static void SerializeToFile(this object obj, string jsonFileName)
{
SerializeToFile(obj, jsonFileName, new JsonSerializerSettings());
SerializeToFile(obj, jsonFileName, new JsonSerializerSettings() { Formatting = Formatting.Indented });
}

public static void SerializeToFile(this object obj, string jsonFileName, JsonSerializerSettings serializerSettings)
{
using var writer = new StreamWriter(jsonFileName);
writer.Write(JsonConvert.SerializeObject(obj, Formatting.Indented, serializerSettings));
writer.Write(JsonConvert.SerializeObject(obj, serializerSettings));
}

public static T DeserializeFromFile<T>(this string jsonFileName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace StoicGoose.Extensions
namespace StoicGoose.Common.Extensions
{
public static class StringExtensionMethods
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

using OpenTK.Graphics.OpenGL4;

using StoicGoose.OpenGL.Vertices;
using StoicGoose.Common.OpenGL.Vertices;

namespace StoicGoose.OpenGL
namespace StoicGoose.Common.OpenGL
{
public sealed class Buffer : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using OpenTK.Graphics.OpenGL4;

namespace StoicGoose.OpenGL
namespace StoicGoose.Common.OpenGL
{
public static class ContextInfo
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace StoicGoose.OpenGL.Shaders.Bundles
namespace StoicGoose.Common.OpenGL.Shaders.Bundles
{
public enum FilterMode { Linear, Nearest }

Expand Down
Loading

0 comments on commit 54fa0e5

Please sign in to comment.