2024-07-30 18:53:36 +08:00
|
|
|
|
using AxibugEmuOnline.Client.Assets.Script.NesEmulator;
|
|
|
|
|
using System;
|
2024-07-31 17:40:32 +08:00
|
|
|
|
using System.Runtime.InteropServices;
|
2024-07-30 11:57:09 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
2024-07-30 18:53:36 +08:00
|
|
|
|
using VirtualNes.Core;
|
2024-07-30 11:57:09 +08:00
|
|
|
|
|
|
|
|
|
namespace AxibugEmuOnline.Client
|
|
|
|
|
{
|
|
|
|
|
public class VideoProvider : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public RawImage Image;
|
|
|
|
|
|
2024-08-02 10:58:04 +08:00
|
|
|
|
private UInt32[] wrapTexBuffer;
|
2024-07-31 17:40:32 +08:00
|
|
|
|
private IntPtr wrapTexBufferPointer;
|
2024-07-30 11:57:09 +08:00
|
|
|
|
private Texture2D wrapTex;
|
2024-08-02 10:58:04 +08:00
|
|
|
|
private int TexBufferSize;
|
2024-07-30 11:57:09 +08:00
|
|
|
|
|
2024-08-02 10:58:04 +08:00
|
|
|
|
private uint[] pPal;
|
2024-07-30 18:53:36 +08:00
|
|
|
|
public void SetDrawData(byte[] screenData, byte[] lineColorMode, int screenWidth, int screenHeight)
|
2024-07-30 11:57:09 +08:00
|
|
|
|
{
|
2024-07-31 17:40:32 +08:00
|
|
|
|
if (wrapTex == null)
|
|
|
|
|
{
|
|
|
|
|
wrapTex = new Texture2D(screenWidth, screenHeight, TextureFormat.BGRA32, false);
|
2024-08-02 10:58:04 +08:00
|
|
|
|
wrapTexBuffer = new UInt32[screenWidth * screenHeight];
|
2024-07-31 17:40:32 +08:00
|
|
|
|
// <20>̶<EFBFBD><CCB6><EFBFBD><EFBFBD>飬<EFBFBD><E9A3AC>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>
|
|
|
|
|
GCHandle handle = GCHandle.Alloc(wrapTexBuffer, GCHandleType.Pinned);
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|
|
|
|
wrapTexBufferPointer = handle.AddrOfPinnedObject();
|
2024-08-02 10:58:04 +08:00
|
|
|
|
|
|
|
|
|
Image.texture = wrapTex;
|
|
|
|
|
pPal = PaletteDefine.m_cnPalette[0];
|
|
|
|
|
|
|
|
|
|
TexBufferSize = wrapTexBuffer.Length * 4;
|
2024-07-31 17:40:32 +08:00
|
|
|
|
}
|
2024-07-30 18:53:36 +08:00
|
|
|
|
|
|
|
|
|
int pScn = 0;
|
|
|
|
|
int width;
|
|
|
|
|
|
2024-07-31 17:40:32 +08:00
|
|
|
|
var Dst = wrapTexBuffer;
|
2024-07-30 18:53:36 +08:00
|
|
|
|
var pDst = 0;
|
|
|
|
|
|
|
|
|
|
for (int line = 0; line < screenHeight; line++)
|
|
|
|
|
{
|
|
|
|
|
width = screenWidth;
|
|
|
|
|
|
|
|
|
|
while (width > 0)
|
|
|
|
|
{
|
2024-07-31 17:40:32 +08:00
|
|
|
|
var edx = screenData[pScn + 8];
|
2024-07-30 18:53:36 +08:00
|
|
|
|
|
2024-08-02 10:58:04 +08:00
|
|
|
|
int index = edx & 0xFF;
|
2024-07-30 18:53:36 +08:00
|
|
|
|
var colorData = pPal[index];
|
2024-08-02 10:58:04 +08:00
|
|
|
|
Dst[pDst] = 0xFF000000 | colorData;
|
2024-07-30 18:53:36 +08:00
|
|
|
|
|
|
|
|
|
pScn += 1;
|
|
|
|
|
pDst += 1;
|
|
|
|
|
width -= 1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 10:58:04 +08:00
|
|
|
|
pScn += 16;// PPU.SCREEN_WIDTH - screenWidth;
|
2024-07-30 18:53:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 10:58:04 +08:00
|
|
|
|
wrapTex.LoadRawTextureData(wrapTexBufferPointer, TexBufferSize);
|
2024-07-30 11:57:09 +08:00
|
|
|
|
wrapTex.Apply();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|