chore(cli): scaffold CLI project with option parsing

This commit is contained in:
dualfroz committed 2026-08-27 13:30:28 +02:00
1 parent de89553bb0
commit 99458b9d0b
2 files changed
+138

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Chip8.Cli</RootNamespace>
<AssemblyName>Chip8.Cli</AssemblyName>
<LangVersion>10</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Raylib-cs" Version="4.5.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Chip8.Core\Chip8.Core.csproj" />
</ItemGroup>
</Project>
+116
View File
@@ -0,0 +1,116 @@
using System;
using Chip8.Core;
namespace Chip8.Cli;
sealed class Options
{
public string romPath = "";
public bool headless;
public int cycles = 2000;
public int scale = 14;
public int instructionsPerFrame = 11;
public int? seed;
public string quirksProfile = "auto";
public string platformName = "chip8";
public string paletteName = "octo";
public int maxFrames;
public string? screenshotPath;
public string? dumpPpmPath;
public string? dumpWavPath;
public Platform buildPlatform() => platformName.ToLowerInvariant() switch
{
"superchip" or "schip" => Platform.SuperChip,
"xochip" or "xo" => Platform.XoChip,
_ => Platform.Chip8,
};
public Quirks? buildQuirks() => quirksProfile.ToLowerInvariant() switch
{
"auto" => null,
"cosmac" => Quirks.cosmacVip(),
"superchip" => Quirks.superChip(),
"xochip" => Quirks.xoChip(),
_ => Quirks.modern(),
};
public Palette buildPalette() => Palette.byName(paletteName);
public static Options parse(string[] args)
{
var options = new Options();
int index = 0;
while (index < args.Length)
{
string token = args[index];
switch (token)
{
case "--headless":
options.headless = true;
index++;
break;
case "--cycles":
options.cycles = int.Parse(args[++index]);
index++;
break;
case "--scale":
options.scale = int.Parse(args[++index]);
index++;
break;
case "--ipf":
options.instructionsPerFrame = int.Parse(args[++index]);
index++;
break;
case "--seed":
options.seed = int.Parse(args[++index]);
index++;
break;
case "--quirks":
options.quirksProfile = args[++index];
index++;
break;
case "--platform":
options.platformName = args[++index];
index++;
break;
case "--palette":
options.paletteName = args[++index];
index++;
break;
case "--frames":
options.maxFrames = int.Parse(args[++index]);
index++;
break;
case "--shot":
options.screenshotPath = args[++index];
index++;
break;
case "--ppm":
options.dumpPpmPath = args[++index];
index++;
break;
case "--wav":
options.dumpWavPath = args[++index];
index++;
break;
default:
if (token.StartsWith("--"))
{
throw new ArgumentException($"Unknown option: {token}");
}
options.romPath = token;
index++;
break;
}
}
if (options.romPath.Length == 0)
{
throw new ArgumentException("No ROM path given.");
}
return options;
}
}