AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs

63 lines
1.4 KiB
C#
Raw Normal View History

2024-07-30 11:57:09 +08:00
using System;
2024-07-30 18:53:36 +08:00
using System.IO;
2024-07-24 14:27:10 +08:00
using UnityEngine;
using VirtualNes.Core;
using VirtualNes.Core.Debug;
namespace AxibugEmuOnline.Client
{
public class NesEmulator : MonoBehaviour
{
2024-07-25 11:03:58 +08:00
private NES m_nesIns;
2024-07-30 11:57:09 +08:00
public VideoProvider VideoProvider;
2024-07-24 14:27:10 +08:00
private void Start()
{
2024-07-26 17:52:33 +08:00
StartGame("Kirby.nes");
2024-07-24 14:27:10 +08:00
}
public void StartGame(string romName)
{
2024-07-25 11:03:58 +08:00
StopGame();
2024-07-24 14:27:10 +08:00
Supporter.Setup(new CoreSupporter());
Debuger.Setup(new CoreDebuger());
2024-07-30 11:57:09 +08:00
try
{
m_nesIns = new NES(romName);
}
catch (Exception ex)
{
m_nesIns = null;
Debug.LogError(ex);
}
2024-07-25 11:03:58 +08:00
}
public void StopGame()
{
m_nesIns?.Dispose();
m_nesIns = null;
}
private void Update()
{
2024-07-30 11:57:09 +08:00
if (m_nesIns != null)
{
m_nesIns.EmulateFrame(true);
2024-07-30 18:53:36 +08:00
2024-07-30 11:57:09 +08:00
var screenBuffer = m_nesIns.ppu.GetScreenPtr();
2024-07-30 18:53:36 +08:00
var lineColorMode = m_nesIns.ppu.GetLineColorMode();
VideoProvider.SetDrawData(screenBuffer, lineColorMode, 256, 240);
2024-07-30 11:57:09 +08:00
}
2024-07-24 14:27:10 +08:00
}
2024-07-30 18:53:36 +08:00
private void OnDestroy()
{
File.WriteAllLines("E:/log.txt", Debuger.logRecords);
}
2024-07-24 14:27:10 +08:00
}
}