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-08-02 16:50:16 +08:00
|
|
|
public AudioProvider AudioProvider;
|
2024-07-30 11:57:09 +08:00
|
|
|
|
2024-07-24 14:27:10 +08:00
|
|
|
private void Start()
|
|
|
|
{
|
2024-08-02 10:58:04 +08:00
|
|
|
Application.targetFrameRate = 60;
|
2024-08-05 17:46:33 +08:00
|
|
|
StartGame("tstd2.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;
|
|
|
|
}
|
|
|
|
|
2024-07-31 17:40:32 +08:00
|
|
|
|
2024-07-25 11:03:58 +08:00
|
|
|
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-08-02 16:50:16 +08:00
|
|
|
|
|
|
|
AudioProvider.ProcessSound(m_nesIns);
|
2024-07-30 11:57:09 +08:00
|
|
|
}
|
2024-07-24 14:27:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|