scaffolding for framebuffer functions

This commit is contained in:
Lukas Höppner
2026-08-12 22:44:54 +02:00
parent 84ba0a609a
commit 7c87a38a6a
9 changed files with 384 additions and 113 deletions
+35 -15
View File
@@ -13,9 +13,9 @@ internal static class Program
return SdRoot / $"slot{slotIdx}" / normalizedPath;
}
private static readonly Nova64Core.DisplayFlushDelegate DisplayFlush = (buffer, width, height) => { };
private static readonly Nova64Core.AudioOutputDelegate AudioOutput = (samples, count) => { };
private static readonly Nova64Core.SdReadFileDelegate SdReadFile = (slotIdx, filePath, destinationBuffer, destinationLength) =>
private static readonly Nova64.DisplayFlushDelegate DisplayFlush = (buffer, width, height) => { };
private static readonly Nova64.AudioOutputDelegate AudioOutput = (samples, count) => { };
private static readonly Nova64.SdReadFileDelegate SdReadFile = (slotIdx, filePath, destinationBuffer, destinationLength) =>
{
var path = GetSlotFilePath(slotIdx, filePath);
Console.WriteLine($"[Core] SD read request: slot {slotIdx}, file '{filePath}', resolved path '{path}' destination length {destinationLength}");
@@ -47,7 +47,7 @@ internal static class Program
return -1;
}
};
private static readonly Nova64Core.SdGetFileSizeDelegate SdGetFileSize = (slotIdx, filePath) =>
private static readonly Nova64.SdGetFileSizeDelegate SdGetFileSize = (slotIdx, filePath) =>
{
var path = GetSlotFilePath(slotIdx, filePath);
Console.WriteLine($"[Core] SD get file size request: slot {slotIdx}, file '{filePath}', resolved path '{path}'");
@@ -69,14 +69,15 @@ internal static class Program
return -1;
}
};
private static readonly Nova64Core.CartridgeStatusDelegate CartridgeStatus = (slotIdx, isInserted) => { };
private static readonly Nova64Core.LogMessageDelegate LogMessage = (message) =>
private static readonly Nova64.CartridgeStatusDelegate CartridgeStatus = (slotIdx, isInserted) => { };
private static readonly Nova64.LogMessageDelegate LogMessage = (message) =>
{
Console.Write($"[Core] {message}");
Console.Out.Flush();
};
private static GCHandle? _ioHandle;
private static GCHandle? _ppuHandle;
private static Thread? _coreThread;
private static readonly ManualResetEventSlim _coreStartedEvent = new(false);
@@ -87,8 +88,13 @@ internal static class Program
Console.WriteLine("[Sim] Core thread failed: IO handle missing.");
return;
}
if (_ppuHandle == null)
{
Console.WriteLine("[Sim] Core thread failed: PPU handle missing.");
return;
}
if (!Nova64Core.nova64_init(_ioHandle.Value.AddrOfPinnedObject()))
if (!Nova64.nova64_init(_ioHandle.Value.AddrOfPinnedObject(), _ppuHandle.Value.AddrOfPinnedObject()))
{
Console.WriteLine("[Sim] nova64_init failed in core thread.");
_coreStartedEvent.Set();
@@ -97,7 +103,7 @@ internal static class Program
_coreStartedEvent.Set();
var result = Nova64Core.nova64_main();
var result = Nova64.nova64_main();
Console.WriteLine($"[Sim] nova64_main returned: {result}");
}
@@ -107,12 +113,11 @@ internal static class Program
try
{
var version = Nova64Core.nova64_get_version();
var version = Nova64.nova64_get_version();
Console.WriteLine($"[Sim] Loaded nova64_core native library. Version: 0x{version:X}");
var ioInterface = new Nova64Core.Nova64IoInterface
var ioInterface = new Nova64.Nova64IoInterface
{
display_flush = Marshal.GetFunctionPointerForDelegate(DisplayFlush),
audio_output = Marshal.GetFunctionPointerForDelegate(AudioOutput),
sd_read_file = Marshal.GetFunctionPointerForDelegate(SdReadFile),
sd_get_file_size = Marshal.GetFunctionPointerForDelegate(SdGetFileSize),
@@ -121,6 +126,14 @@ internal static class Program
};
_ioHandle = GCHandle.Alloc(ioInterface, GCHandleType.Pinned);
var ppuInterface = new Nova64.Nova64PpuInterface
{
};
_ppuHandle = GCHandle.Alloc(ppuInterface, GCHandleType.Pinned);
_coreThread = new Thread(CoreThreadProc)
{
IsBackground = true,
@@ -143,10 +156,10 @@ internal static class Program
if (_coreThread != null && _coreThread.IsAlive)
{
Console.WriteLine("[Sim] Requesting core shutdown...");
if (Nova64Core.nova64_shutdown())
if (Nova64.nova64_shutdown())
{
int timeoutMs = 1000;
while (!Nova64Core.nova64_is_finalized() && timeoutMs > 0)
while (!Nova64.nova64_is_finalized() && timeoutMs > 0)
{
Thread.Sleep(10);
timeoutMs -= 10;
@@ -178,9 +191,16 @@ internal static class Program
{
Console.WriteLine("Core thread still running; leaving native handle pinned until process exit.");
}
else if (_ioHandle.HasValue && _ioHandle.Value.IsAllocated)
else
{
_ioHandle.Value.Free();
if (_ioHandle.HasValue && _ioHandle.Value.IsAllocated)
{
_ioHandle.Value.Free();
}
if (_ppuHandle.HasValue && _ppuHandle.Value.IsAllocated)
{
_ppuHandle.Value.Free();
}
}
}
}