AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/Manager/AppEmu.cs

62 lines
1.8 KiB
C#
Raw Normal View History

2024-07-18 15:14:45 +08:00
using AxibugEmuOnline.Client.Input;
2024-07-05 11:24:59 +08:00
using MyNes.Core;
2024-07-03 14:43:11 +08:00
using System.IO;
2024-07-04 21:06:41 +08:00
using UnityEngine;
2024-07-03 14:43:11 +08:00
namespace AxibugEmuOnline.Client.Manager
{
2024-07-18 15:14:45 +08:00
public class AppEmu : IExternalSupporter
2024-07-04 21:06:41 +08:00
{
2024-07-18 15:14:45 +08:00
private InputManager m_inputMgr;
public void Init(IVideoProvider videoCom, IAudioProvider audioCom, InputManager inputManager)
2024-07-04 21:06:41 +08:00
{
2024-07-18 15:14:45 +08:00
m_inputMgr = inputManager;
2024-07-16 16:30:20 +08:00
2024-07-18 15:14:45 +08:00
MyNesMain.Initialize(this, videoCom, audioCom);
NesEmu.SetupControllers(
new NesJoyController(EnumJoyIndex.P1),
new NesJoyController(EnumJoyIndex.P2),
new NesJoyController(EnumJoyIndex.P3),
new NesJoyController(EnumJoyIndex.P4));
2024-07-17 13:18:45 +08:00
NesEmu.LoadGame("kirby.nes", out var successed, true);
2024-07-04 21:06:41 +08:00
}
public void Dispose()
{
MyNesMain.Shutdown();
}
public Stream OpenDatabaseFile()
{
var databaseFile = Resources.Load<TextAsset>("NesCoreRes/database");
MemoryStream ms = new MemoryStream(databaseFile.bytes);
return ms;
}
public Stream OpenPaletteFile()
{
var defaultPalett = Resources.Load<TextAsset>("NesCoreRes/Palettes/default_ntsc.pal");
MemoryStream ms = new MemoryStream(defaultPalett.bytes);
return ms;
}
public string GetWorkingFolderPath()
{
return $"{Application.persistentDataPath}/MyNes";
}
2024-07-16 16:30:20 +08:00
public Stream OpenRomFile(string path)
{
var ta = Resources.Load<TextAsset>($"Roms/{path}");
MemoryStream ms = new MemoryStream(ta.bytes);
return ms;
}
2024-07-18 15:14:45 +08:00
public bool IsKeyPressing(EnumJoyIndex index, EnumKeyKind key)
{
return m_inputMgr.IsKeyPress(index, key);
}
2024-07-03 14:43:11 +08:00
}
}