2024-07-30 11:57:09 +08:00
|
|
|
using System;
|
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);
|
|
|
|
m_nesIns.Command(NESCOMMAND.NESCMD_HWRESET);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
var screenBuffer = m_nesIns.ppu.GetScreenPtr();
|
|
|
|
VideoProvider.SetDrawData(screenBuffer, PPU.SCREEN_WIDTH, PPU.SCREEN_HEIGHT);
|
|
|
|
}
|
2024-07-24 14:27:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|