Cleanup
This commit is contained in:
+22
-22
@@ -45,13 +45,13 @@ static void nova64_log(const char *format, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool initialize_wasm_runtime(void) {
|
static bool initialize_wasm_runtime(void) {
|
||||||
nova64_log("[Core] Initializing WASM runtime...\n");
|
nova64_log("Initializing WASM runtime...\n");
|
||||||
// TODO: Replace this stub with real WAMR initialization.
|
// TODO: Replace this stub with real WAMR initialization.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool load_launcher_from_internal_storage(void) {
|
static bool load_launcher_from_internal_storage(void) {
|
||||||
nova64_log("[Core] Loading launcher from internal storage (%s)...\n",
|
nova64_log("Loading launcher from internal storage (%s)...\n",
|
||||||
kInternalLauncherPath);
|
kInternalLauncherPath);
|
||||||
// TODO: Implement the actual internal storage filesystem and launcher load.
|
// TODO: Implement the actual internal storage filesystem and launcher load.
|
||||||
return true;
|
return true;
|
||||||
@@ -59,7 +59,7 @@ static bool load_launcher_from_internal_storage(void) {
|
|||||||
|
|
||||||
static void nova64_wasm_launcher_task(void *params) {
|
static void nova64_wasm_launcher_task(void *params) {
|
||||||
(void)params;
|
(void)params;
|
||||||
nova64_log("[Core] WASM launcher task started.\n");
|
nova64_log("WASM launcher task started.\n");
|
||||||
|
|
||||||
// TODO: Execute the loaded WASM launcher module here with the WAMR engine.
|
// TODO: Execute the loaded WASM launcher module here with the WAMR engine.
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -73,21 +73,21 @@ static bool start_launcher_task(void) {
|
|||||||
tskIDLE_PRIORITY + 1, &launcher_task_handle);
|
tskIDLE_PRIORITY + 1, &launcher_task_handle);
|
||||||
|
|
||||||
if (result != pdPASS) {
|
if (result != pdPASS) {
|
||||||
nova64_log("[Core] Failed to create launcher task.\n");
|
nova64_log("Failed to create launcher task.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nova64_log("[Core] Launcher task created successfully.\n");
|
nova64_log("Launcher task created successfully.\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nova64_shutdown_task(void *params) {
|
static void nova64_shutdown_task(void *params) {
|
||||||
(void)params;
|
(void)params;
|
||||||
|
|
||||||
nova64_log("[Core] Shutdown task started.\n");
|
nova64_log("Shutdown task started.\n");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (shutdown_requested) {
|
if (shutdown_requested) {
|
||||||
nova64_log("[Core] Shutdown requested; ending scheduler.\n");
|
nova64_log("Shutdown requested; ending scheduler.\n");
|
||||||
vTaskEndScheduler();
|
vTaskEndScheduler();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -101,37 +101,37 @@ static bool start_shutdown_task(void) {
|
|||||||
tskIDLE_PRIORITY + 2, &shutdown_task_handle);
|
tskIDLE_PRIORITY + 2, &shutdown_task_handle);
|
||||||
|
|
||||||
if (result != pdPASS) {
|
if (result != pdPASS) {
|
||||||
nova64_log("[Core] Failed to create shutdown task.\n");
|
nova64_log("Failed to create shutdown task.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nova64_log("[Core] Shutdown task created successfully.\n");
|
nova64_log("Shutdown task created successfully.\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nova64_boot_task(void *params) {
|
static void nova64_boot_task(void *params) {
|
||||||
(void)params;
|
(void)params;
|
||||||
nova64_log("[Core] Boot task started.\n");
|
nova64_log("Boot task started.\n");
|
||||||
|
|
||||||
if (!initialize_wasm_runtime()) {
|
if (!initialize_wasm_runtime()) {
|
||||||
nova64_log("[Core] WASM runtime initialization failed.\n");
|
nova64_log("WASM runtime initialization failed.\n");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!load_launcher_from_internal_storage()) {
|
if (!load_launcher_from_internal_storage()) {
|
||||||
nova64_log("[Core] Launcher loading failed.\n");
|
nova64_log("Launcher loading failed.\n");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!start_launcher_task()) {
|
if (!start_launcher_task()) {
|
||||||
nova64_log("[Core] Launcher startup failed.\n");
|
nova64_log("Launcher startup failed.\n");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nova64_log("[Core] Boot process completed.\n");
|
nova64_log("Boot process completed.\n");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,11 +144,11 @@ NOVA64_API bool nova64_init(const nova64_io_interface_t *io_interface) {
|
|||||||
g_io_interface = &g_io_interface_storage;
|
g_io_interface = &g_io_interface_storage;
|
||||||
shutdown_requested = false;
|
shutdown_requested = false;
|
||||||
|
|
||||||
nova64_log("[Core] System Initializing...\n");
|
nova64_log("System Initializing...\n");
|
||||||
|
|
||||||
event_queue = xQueueCreate(10, sizeof(uint32_t));
|
event_queue = xQueueCreate(10, sizeof(uint32_t));
|
||||||
if (event_queue == NULL) {
|
if (event_queue == NULL) {
|
||||||
nova64_log("[Core] Failed to create event queue.\n");
|
nova64_log("Failed to create event queue.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,12 +156,12 @@ NOVA64_API bool nova64_init(const nova64_io_interface_t *io_interface) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nova64_log("[Core] Starting boot process...\n");
|
nova64_log("Starting boot process...\n");
|
||||||
BaseType_t created =
|
BaseType_t created =
|
||||||
xTaskCreate(nova64_boot_task, "Nova64Boot", 4096 / sizeof(StackType_t),
|
xTaskCreate(nova64_boot_task, "Nova64Boot", 4096 / sizeof(StackType_t),
|
||||||
NULL, tskIDLE_PRIORITY + 2, &boot_task_handle);
|
NULL, tskIDLE_PRIORITY + 2, &boot_task_handle);
|
||||||
if (created != pdPASS) {
|
if (created != pdPASS) {
|
||||||
nova64_log("[Core] Failed to create boot task.\n");
|
nova64_log("Failed to create boot task.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,14 +175,14 @@ NOVA64_API int32_t nova64_main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nova64_log(
|
nova64_log(
|
||||||
"[Core] Entering main runtime and starting FreeRTOS scheduler...\n");
|
"Entering main runtime and starting FreeRTOS scheduler...\n");
|
||||||
vTaskStartScheduler();
|
vTaskStartScheduler();
|
||||||
|
|
||||||
// vTaskStartScheduler only returns if the scheduler fails to start or if
|
// vTaskStartScheduler only returns if the scheduler fails to start or if
|
||||||
// the scheduler is shut down by vTaskEndScheduler().
|
// the scheduler is shut down by vTaskEndScheduler().
|
||||||
nova64_log("[Core] vTaskStartScheduler returned.\n");
|
nova64_log("vTaskStartScheduler returned.\n");
|
||||||
is_initialized = false;
|
is_initialized = false;
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
NOVA64_API bool nova64_shutdown(void) {
|
NOVA64_API bool nova64_shutdown(void) {
|
||||||
@@ -190,7 +190,7 @@ NOVA64_API bool nova64_shutdown(void) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nova64_log("[Core] Scheduler shutdown requested from host.\n");
|
nova64_log("Scheduler shutdown requested from host.\n");
|
||||||
shutdown_requested = true;
|
shutdown_requested = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
internal static class Nova64Core
|
||||||
|
{
|
||||||
|
private const string LibName = "nova64_core";
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
public delegate void DisplayFlushDelegate(IntPtr buffer, ushort width, ushort height);
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
public delegate void AudioOutputDelegate(IntPtr samples, uint count);
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
public delegate bool SdReadSectorDelegate(uint sectorIdx, IntPtr destinationBuffer, uint sectorCount);
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
public delegate void CartridgeStatusDelegate(uint slotIdx, bool isInserted);
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
|
public delegate void LogMessageDelegate([MarshalAs(UnmanagedType.LPStr)] string message);
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct Nova64IoInterface
|
||||||
|
{
|
||||||
|
public IntPtr display_flush;
|
||||||
|
public IntPtr audio_output;
|
||||||
|
public IntPtr sd_read_sector;
|
||||||
|
public IntPtr cartridge_status;
|
||||||
|
public IntPtr log_message;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern bool nova64_init(IntPtr io_interface);
|
||||||
|
|
||||||
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern int nova64_main();
|
||||||
|
|
||||||
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern bool nova64_shutdown();
|
||||||
|
|
||||||
|
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern uint nova64_get_version();
|
||||||
|
}
|
||||||
+16
-58
@@ -2,48 +2,6 @@ using System;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
internal static class Nova64Core
|
|
||||||
{
|
|
||||||
private const string LibName = "nova64_core";
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
public delegate void DisplayFlushDelegate(IntPtr buffer, ushort width, ushort height);
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
public delegate void AudioOutputDelegate(IntPtr samples, uint count);
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
public delegate bool SdReadSectorDelegate(uint sectorIdx, IntPtr destinationBuffer, uint sectorCount);
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
public delegate void CartridgeStatusDelegate(uint slotIdx, bool isInserted);
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
||||||
public delegate void LogMessageDelegate([MarshalAs(UnmanagedType.LPStr)] string message);
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Nova64IoInterface
|
|
||||||
{
|
|
||||||
public IntPtr display_flush;
|
|
||||||
public IntPtr audio_output;
|
|
||||||
public IntPtr sd_read_sector;
|
|
||||||
public IntPtr cartridge_status;
|
|
||||||
public IntPtr log_message;
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
public static extern bool nova64_init(IntPtr io_interface);
|
|
||||||
|
|
||||||
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
public static extern int nova64_main();
|
|
||||||
|
|
||||||
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
public static extern bool nova64_shutdown();
|
|
||||||
|
|
||||||
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
public static extern uint nova64_get_version();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
private static readonly Nova64Core.DisplayFlushDelegate DisplayFlush = (buffer, width, height) => { };
|
private static readonly Nova64Core.DisplayFlushDelegate DisplayFlush = (buffer, width, height) => { };
|
||||||
@@ -52,7 +10,7 @@ internal static class Program
|
|||||||
private static readonly Nova64Core.CartridgeStatusDelegate CartridgeStatus = (slotIdx, isInserted) => { };
|
private static readonly Nova64Core.CartridgeStatusDelegate CartridgeStatus = (slotIdx, isInserted) => { };
|
||||||
private static readonly Nova64Core.LogMessageDelegate LogMessage = (message) =>
|
private static readonly Nova64Core.LogMessageDelegate LogMessage = (message) =>
|
||||||
{
|
{
|
||||||
Console.Write($"[Nova64] {message}");
|
Console.Write($"[Core] {message}");
|
||||||
};
|
};
|
||||||
|
|
||||||
private static GCHandle? _ioHandle;
|
private static GCHandle? _ioHandle;
|
||||||
@@ -63,13 +21,13 @@ internal static class Program
|
|||||||
{
|
{
|
||||||
if (_ioHandle == null)
|
if (_ioHandle == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[Nova64] Core thread failed: IO handle missing.");
|
Console.WriteLine("[Sim] Core thread failed: IO handle missing.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Nova64Core.nova64_init(_ioHandle.Value.AddrOfPinnedObject()))
|
if (!Nova64Core.nova64_init(_ioHandle.Value.AddrOfPinnedObject()))
|
||||||
{
|
{
|
||||||
Console.WriteLine("[Nova64] nova64_init failed in core thread.");
|
Console.WriteLine("[Sim] nova64_init failed in core thread.");
|
||||||
_coreStartedEvent.Set();
|
_coreStartedEvent.Set();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -77,17 +35,17 @@ internal static class Program
|
|||||||
_coreStartedEvent.Set();
|
_coreStartedEvent.Set();
|
||||||
|
|
||||||
var result = Nova64Core.nova64_main();
|
var result = Nova64Core.nova64_main();
|
||||||
Console.WriteLine($"[Nova64] nova64_main returned: {result}");
|
Console.WriteLine($"[Sim] nova64_main returned: {result}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Main()
|
private static void Main()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Nova64 simulator starting...");
|
Console.WriteLine("[Sim] simulator starting...");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var version = Nova64Core.nova64_get_version();
|
var version = Nova64Core.nova64_get_version();
|
||||||
Console.WriteLine($"Loaded nova64_core native library. Version: 0x{version:X}");
|
Console.WriteLine($"[Sim] Loaded nova64_core native library. Version: 0x{version:X}");
|
||||||
|
|
||||||
var ioInterface = new Nova64Core.Nova64IoInterface
|
var ioInterface = new Nova64Core.Nova64IoInterface
|
||||||
{
|
{
|
||||||
@@ -108,49 +66,49 @@ internal static class Program
|
|||||||
|
|
||||||
if (_coreStartedEvent.Wait(TimeSpan.FromSeconds(5)))
|
if (_coreStartedEvent.Wait(TimeSpan.FromSeconds(5)))
|
||||||
{
|
{
|
||||||
Console.WriteLine("nova64 core thread started.");
|
Console.WriteLine("[Sim] core thread started.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("nova64 core thread did not signal startup in time.");
|
Console.WriteLine("[Sim] Core thread did not signal startup in time.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Press Enter to stop the simulator.");
|
Console.WriteLine("[Sim] Press Enter to stop the simulator.");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
|
||||||
if (_coreThread != null && _coreThread.IsAlive)
|
if (_coreThread != null && _coreThread.IsAlive)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[Nova64] Requesting core shutdown...");
|
Console.WriteLine("[Sim] Requesting core shutdown...");
|
||||||
if (Nova64Core.nova64_shutdown())
|
if (Nova64Core.nova64_shutdown())
|
||||||
{
|
{
|
||||||
if (!_coreThread.Join(TimeSpan.FromSeconds(5)))
|
if (!_coreThread.Join(TimeSpan.FromSeconds(5)))
|
||||||
{
|
{
|
||||||
Console.WriteLine("[Nova64] Core thread did not exit in time.");
|
Console.WriteLine("[Sim] Core thread did not exit in time.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("[Nova64] Core shutdown request failed.");
|
Console.WriteLine("[Sim] Core shutdown request failed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (DllNotFoundException ex)
|
catch (DllNotFoundException ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Native library not found: {ex.Message}");
|
Console.WriteLine($"[Sim] Native library not found: {ex.Message}");
|
||||||
}
|
}
|
||||||
catch (EntryPointNotFoundException ex)
|
catch (EntryPointNotFoundException ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Native entry point missing: {ex.Message}");
|
Console.WriteLine($"[Sim] Native entry point missing: {ex.Message}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Failed to initialize native library: {ex.Message}");
|
Console.WriteLine($"[Sim] Failed to initialize native library: {ex.Message}");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (_coreThread != null && _coreThread.IsAlive)
|
if (_coreThread != null && _coreThread.IsAlive)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[Nova64] Core thread still running; leaving native handle pinned until process exit.");
|
Console.WriteLine("Core thread still running; leaving native handle pinned until process exit.");
|
||||||
}
|
}
|
||||||
else if (_ioHandle.HasValue && _ioHandle.Value.IsAllocated)
|
else if (_ioHandle.HasValue && _ioHandle.Value.IsAllocated)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user