优化为仅渲染可视区域 | 紫色问题

This commit is contained in:
sin365 2024-08-07 18:02:16 +08:00
parent 660ce05d0c
commit 3a0e28a68f
7 changed files with 538 additions and 122 deletions

View File

@ -1,21 +1,36 @@
using System;
using System.Runtime.InteropServices;
namespace MAME.Core.AxiBitmap
{
[StructLayout(LayoutKind.Explicit)]
public struct AxiColor
{
public byte r, g, b, a;
// 构造函数
[FieldOffset(0)]
public int sdColor;
[FieldOffset(0)]
public byte r;
[FieldOffset(1)]
public byte g;
[FieldOffset(2)]
public byte b;
[FieldOffset(3)]
public byte a;
public AxiColor(byte _r, byte _g, byte _b)
{
r = g = b = a = 0;
sdColor = 0;
r = _r;
g = _g;
b = _b;
a = 255;
a = byte.MaxValue;
}
public AxiColor(byte _r, byte _g, byte _b, byte _a)
{
r = g = b = a = 0;
sdColor = 0;
r = _r;
g = _g;
b = _b;
@ -23,15 +38,17 @@ namespace MAME.Core.AxiBitmap
}
public static AxiColor FromArgb(int argb)
{
byte a = (byte)((argb >> 24) & 0xFF);
byte r = (byte)((argb >> 16) & 0xFF);
byte g = (byte)((argb >> 8) & 0xFF);
byte b = (byte)(argb & 0xFF);
return new AxiColor { r = r, g = g, b = b, a = a };
return new AxiColor { sdColor = argb };
}
public override string ToString()
{
return String.Format("{0:X8}", sdColor);
}
public static int ToArgb(AxiColor color)
{
return (color.a << 24) | (color.r << 16) | (color.g << 8) | color.b;
return color.sdColor;
}
#region
@ -177,11 +194,70 @@ namespace MAME.Core.AxiBitmap
#endregion
}
public static class AxiBitmapEx
{
public static int ToArgb(this AxiColor color)
{
return (color.a << 24) | (color.r << 16) | (color.g << 8) | color.b;
}
//public static void CloneIntColorArr(int[] baseBitmap, int[] targetBitmap, int baseWidth, int baseHeight, Rectangle rect)
//{
// // 检查矩形是否超出位图边界
// if (rect.X < 0 || rect.X + rect.Width > baseWidth || rect.Y < 0 || rect.Y + rect.Height > baseHeight)
// {
// throw new ArgumentException("Rectangle is out of bitmap bounds.");
// }
// int baseStartIndex = rect.Y * baseWidth + rect.X;
// int targetStartIndex = rect.Y * rect.Width;
// for (int y = 0; y < rect.Height; y++)
// {
// // 注意这里使用了rect.Width作为要拷贝的元素数量而不是baseWidth
// Buffer.BlockCopy(baseBitmap, baseStartIndex + y * baseWidth, targetBitmap, targetStartIndex + y * rect.Width, rect.Width * sizeof(int));
// // 或者使用Array.Copy但要注意类型的大小在这里是int
// // Array.Copy(baseBitmap, baseStartIndex + y * baseWidth, targetBitmap, targetStartIndex + y * rect.Width, rect.Width);
// }
//}
public static void CloneIntColorArr(int[] baseBitmap, int[] targetBitmap, int Width, int Height, Rectangle rect)
{
// 检查矩形是否超出位图边界
if (rect.X < 0 || rect.Right > Width || rect.Y < 0 || rect.Bottom > Height)
{
throw new ArgumentException("out of");
}
int srcStartIndex = rect.Y * Width + rect.X;
for (int y = 0; y < rect.Height; y++)
{
Array.Copy(baseBitmap, srcStartIndex + y * Width, targetBitmap, y * rect.Width, rect.Width);
}
}
public struct Rectangle
{
public int X;
public int Y;
public int Width;
public int Height;
public Rectangle(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
public int Right => X + Width;
public int Bottom => Y + Height;
public int Area { get { return Width * Height; } }
public bool Contains(int pointX, int pointY) { return pointX >= X && pointX < X + Width && pointY >= Y && pointY < Y + Height; }
}
}
}

View File

@ -1,5 +1,6 @@
using mame;
using MAME.Core.run_interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -77,10 +78,14 @@ namespace MAME.Core.Common
return RomInfo.dictName2Rom;
}
public void GetGameScreenSize(out int _width, out int _height)
public void GetGameScreenSize(out int _width, out int _height,out IntPtr _framePtr)
{
_width = Video.fullwidth;
_height = Video.fullheight;
//_width = Video.fullwidth;
//_height = Video.fullheight;
//_framePtr = Video.bitmapcolor_Ptr;
_width = Video.width;
_height = Video.height;
_framePtr = Video.bitmapcolorRect_Ptr;
}
private void showInfoByElements(IEnumerable<XElement> elements)
@ -129,7 +134,10 @@ namespace MAME.Core.Common
case "CPS-1":
case "CPS-1(QSound)":
case "CPS2":
Video.nMode = 3;
Video.nMode = 1;
Video.iMode = 2;
//Video.nMode = 3;
itemSelect();
CPS.CPSInit();
CPS.GDIInit();

View File

@ -1,5 +1,6 @@
using MAME.Core.AxiBitmap;
using System;
using static MAME.Core.AxiBitmap.AxiBitmapEx;
using Color = MAME.Core.AxiBitmap.AxiColor;
namespace mame
@ -163,7 +164,10 @@ namespace mame
// break;
//}
//Machine.FORM.pictureBox1.Image = bbmp[iMode];
SubmitVideo(Video.bitmapcolor);
//AxiBitmapEx.CloneIntColorArr(Video.bitmapcolor,Video.bitmapcolorRect, Video.fullwidth, Video.fullheight, new Rectangle(offsetx, offsety, width, height));
SubmitVideo(Video.bitmapcolorRect);
//SubmitVideo(Video.bitmapcolor);
}
catch (Exception ex)
{

View File

@ -1,5 +1,7 @@
using MAME.Core.Common;
using MAME.Core.run_interface;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;
namespace mame
{
@ -23,43 +25,136 @@ namespace mame
motion_handler_callback();
}
public static void ui_updateC()
{
//不再填充完整画布
//{
// int i;
// int red, green, blue;
// if (single_step || Mame.paused)
// {
// byte bright = 0xa7;
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
// green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
// blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
// Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
// }
// }
// else
// {
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
// }
// }
//}
{
int i;
int target_i = 0;
int x, y;
int red, green, blue;
int startX = Video.offsetx;
int endX = Video.offsetx + Video.width;
int startY = Video.offsety;
int endY = Video.offsety + Video.height;
if (single_step || Mame.paused)
{
byte bright = 0xa7;
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
for (x = startX; x < endX; x++, target_i++)
{
i = (y * Video.fullwidth) + x;
red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
Video.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue);
}
}
}
else
{
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
for (x = startX; x < endX; x++, target_i++)
{
i = (y * Video.fullwidth) + x;
Video.bitmapcolorRect[target_i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
}
}
}
}
}
public static void ui_updateTehkan()
{
//不再填充完整画布
//{
// int i;
// int red, green, blue;
// if (single_step || Mame.paused)
// {
// byte bright = 0xa7;
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// if (Video.bitmapbase[Video.curbitmap][i] < 0x100)
// {
// red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
// green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
// blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
// Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
// }
// else
// {
// int i1 = 1;
// }
// }
// }
// else
// {
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// if (Video.bitmapbase[Video.curbitmap][i] < 0x100)
// {
// Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
// }
// else
// {
// Video.bitmapcolor[i] = (int)Palette.entry_color[0];
// }
// }
// }
//}
{
int i;
int target_i = 0;
int x, y;
int red, green, blue;
int startX = Video.offsetx;
int endX = Video.offsetx + Video.width;
int startY = Video.offsety;
int endY = Video.offsety + Video.height;
if (single_step || Mame.paused)
{
byte bright = 0xa7;
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
for (x = startX; x < endX; x++, target_i++)
{
i = y * Video.fullwidth + x;
if (Video.bitmapbase[Video.curbitmap][i] < 0x100)
{
red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
Video.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue);
}
else
{
@ -67,110 +162,282 @@ namespace mame
}
}
}
else
{
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
{
if (Video.bitmapbase[Video.curbitmap][i] < 0x100)
{
Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
}
else
{
Video.bitmapcolor[i] = (int)Palette.entry_color[0];
for (y = startY; y < endY; y++)
{
for (x = startX; x < endX; x++, target_i++)
{
i = y * Video.fullwidth + x;
if (Video.bitmapbase[Video.curbitmap][i] < 0x100)
{
Video.bitmapcolorRect[target_i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
}
else
{
Video.bitmapcolorRect[target_i] = (int)Palette.entry_color[0];
}
}
}
}
}
}
public static void ui_updateN()
{
//不再填充完整画布
//{
// int i;
// int red, green, blue;
// if (single_step || Mame.paused)
// {
// byte bright = 0xa7;
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// red = ((Video.bitmapbaseN[Video.curbitmap][i] & 0xff0000) >> 16) * bright / 0xff;
// green = ((Video.bitmapbaseN[Video.curbitmap][i] & 0xff00) >> 8) * bright / 0xff;
// blue = (Video.bitmapbaseN[Video.curbitmap][i] & 0xff) * bright / 0xff;
// Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
// }
// }
// else
// {
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// Video.bitmapcolor[i] = (int)(0xff000000 | (uint)Video.bitmapbaseN[Video.curbitmap][i]);
// }
// }
//}
{
int i;
int target_i = 0;
int x, y;
int red, green, blue;
int startX = Video.offsetx;
int endX = Video.offsetx + Video.width;
int startY = Video.offsety;
int endY = Video.offsety + Video.height;
if (single_step || Mame.paused)
{
byte bright = 0xa7;
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
for (x = startX; x < endX; x++, target_i++)
{
i = y * Video.fullwidth + x;
red = ((Video.bitmapbaseN[Video.curbitmap][i] & 0xff0000) >> 16) * bright / 0xff;
green = ((Video.bitmapbaseN[Video.curbitmap][i] & 0xff00) >> 8) * bright / 0xff;
blue = (Video.bitmapbaseN[Video.curbitmap][i] & 0xff) * bright / 0xff;
Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
Video.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue);
}
}
}
else
{
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
Video.bitmapcolor[i] = (int)(0xff000000 | (uint)Video.bitmapbaseN[Video.curbitmap][i]);
for (x = startX; x < endX; x++, target_i++)
{
i = y * Video.fullwidth + x;
Video.bitmapcolorRect[target_i] = (int)(0xff000000 | (uint)Video.bitmapbaseN[Video.curbitmap][i]);
}
}
}
}
}
public static void ui_updateNa()
{
//不再填充完整画布
//{
// int i;
// int red, green, blue;
// if (single_step || Mame.paused)
// {
// byte bright = 0xa7;
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
// green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
// blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
// Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
// }
// }
// else
// {
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
// }
// }
//}
{
int i;
int target_i = 0;
int x, y;
int red, green, blue;
int startX = Video.offsetx;
int endX = Video.offsetx + Video.width;
int startY = Video.offsety;
int endY = Video.offsety + Video.height;
if (single_step || Mame.paused)
{
byte bright = 0xa7;
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
for (x = startX; x < endX; x++, target_i++)
{
i = y * Video.fullwidth + x;
red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
Video.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue);
}
}
}
else
{
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
for (x = startX; x < endX; x++, target_i++)
{
i = y * Video.fullwidth + x;
Video.bitmapcolorRect[target_i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
}
}
}
}
}
public static void ui_updateIGS011()
{
//不再填充完整画布
//{
// int i;
// int red, green, blue;
// if (single_step || Mame.paused)
// {
// byte bright = 0xa7;
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
// green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
// blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
// Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
// }
// }
// else
// {
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
// }
// }
//}
{
int i;
int target_i = 0;
int x, y;
int red, green, blue;
int startX = Video.offsetx;
int endX = Video.offsetx + Video.width;
int startY = Video.offsety;
int endY = Video.offsety + Video.height;
if (single_step || Mame.paused)
{
byte bright = 0xa7;
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
for (x = startX; x < endX; x++, target_i++)
{
i = y * Video.fullwidth + x;
red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
Video.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue);
}
}
}
else
{
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
for (x = startX; x < endX; x++, target_i++)
{
i = y * Video.fullwidth + x;
Video.bitmapcolorRect[target_i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
}
}
}
}
}
public static void ui_updatePGM()
{
//不再填充完整画布
//{
// int i;
// int red, green, blue;
// if (single_step || Mame.paused)
// {
// byte bright = 0xa7;
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
// green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
// blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
// Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
// }
// }
// else
// {
// for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
// {
// Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
// }
// }
//}
{
int i;
int target_i = 0;
int x, y;
int red, green, blue;
int startX = Video.offsetx;
int endX = Video.offsetx + Video.width;
int startY = Video.offsety;
int endY = Video.offsety + Video.height;
if (single_step || Mame.paused)
{
byte bright = 0xa7;
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
for (x = startX; x < endX; x++, target_i++)
{
i = y * Video.fullwidth + x;
red = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff0000) >> 16) * bright / 0xff);
green = (int)(((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff00) >> 8) * bright / 0xff);
blue = (int)((Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]] & 0xff) * bright / 0xff);
Video.bitmapcolor[i] = (int)Palette.make_argb(0xff, red, green, blue);
Video.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue);
}
}
}
else
{
for (i = 0; i < Video.fullwidth * Video.fullheight; i++)
for (y = startY; y < endY; y++)
{
Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
for (x = startX; x < endX; x++, target_i++)
{
i = y * Video.fullwidth + x;
Video.bitmapcolorRect[target_i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]];
}
}
}
}
}

View File

@ -20,19 +20,22 @@ namespace mame
case "CPS-1":
case "CPS-1(QSound)":
case "CPS2":
trans_color = Color.Magenta;
//trans_color = Color.Magenta;
trans_color = Color.Black;
trans_uint = (uint)trans_color.ToArgb();
numcolors = 0xc00;
palette_set_callback = palette_entry_set_color1;
break;
case "Data East":
trans_color = Color.Magenta;
//trans_color = Color.Magenta;
trans_color = Color.Black;
trans_uint = (uint)trans_color.ToArgb();
numcolors = 0x200;
palette_set_callback = palette_entry_set_color2;
break;
case "Tehkan":
trans_color = Color.Magenta;
//trans_color = Color.Magenta;
trans_color = Color.Black;
trans_uint = (uint)trans_color.ToArgb();
numcolors = 0x100;
palette_set_callback = palette_entry_set_color2;
@ -56,7 +59,8 @@ namespace mame
palette_set_callback = palette_entry_set_color1;
break;
case "PGM":
trans_color = Color.Magenta;
//trans_color = Color.Magenta;
trans_color = Color.Black;
trans_uint = (uint)trans_color.ToArgb();
numcolors = 0x901;
palette_set_callback = palette_entry_set_color2;
@ -98,7 +102,8 @@ namespace mame
case "boblcave":
case "bublcave11":
case "bublcave10":
trans_color = Color.Magenta;
//trans_color = Color.Magenta;
trans_color = Color.Black;
numcolors = 0x100;
break;
case "opwolf":
@ -115,7 +120,8 @@ namespace mame
palette_set_callback = palette_entry_set_color2;
break;
case "Taito B":
trans_color = Color.Magenta;
//trans_color = Color.Magenta;
trans_color = Color.Black;
trans_uint = (uint)trans_color.ToArgb();
numcolors = 0x1000;
palette_set_callback = palette_entry_set_color3;

View File

@ -1,6 +1,7 @@
using MAME.Core.run_interface;
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace mame
{
@ -37,7 +38,19 @@ namespace mame
private static int[] popcount;
public static ushort[][] bitmapbase;
public static int[][] bitmapbaseN;
public static int[] bitmapcolor;
//public static int[] bitmapcolor;
/** bitmapcolor的指针管理 **/
//不再拷贝完整画布
//public static int[] bitmapcolor;
//static GCHandle bitmapcolor_handle;
//public static IntPtr bitmapcolor_Ptr;
public static int[] bitmapcolorRect;
static GCHandle bitmapcolorRect_handle;
public static IntPtr bitmapcolorRect_Ptr;
/** end **/
public static int fullwidth, fullheight;
public static bool global_throttle;
public static int scanline_param;
@ -70,7 +83,7 @@ namespace mame
static void SubmitVideo(int[] Bitmap)
{
Act_SubmitVideo?.Invoke(Bitmap);
Act_SubmitVideo.Invoke(Bitmap);
}
#endregion
@ -596,7 +609,48 @@ namespace mame
screenstate.scantime = screenstate.frame_period / screenstate.height;
screenstate.pixeltime = screenstate.frame_period / (screenstate.height * screenstate.width);
screenstate.frame_number = 0;
bitmapcolor = new int[Video.fullwidth * Video.fullheight];
//bitmapcolor = new int[Video.fullwidth * Video.fullheight];
/** bitmapcolor的指针管理 **/
//不再拷贝完整画布
//if (bitmapcolor != null)
//{
// // 释放句柄
// if (bitmapcolor_handle.IsAllocated)
// {
// bitmapcolor_handle.Free();
// }
//}
//bitmapcolor = new int[Video.fullwidth * Video.fullheight];
//// 固定数组,防止垃圾回收器移动它
//bitmapcolor_handle = GCHandle.Alloc(bitmapcolor, GCHandleType.Pinned);
//// 获取数组的指针
//bitmapcolor_Ptr = bitmapcolor_handle.AddrOfPinnedObject();
if (bitmapcolorRect != null)
{
// 释放句柄
if (bitmapcolorRect_handle.IsAllocated)
{
bitmapcolorRect_handle.Free();
}
}
bitmapcolorRect = new int[width * height];
// 固定数组,防止垃圾回收器移动它
bitmapcolorRect_handle = GCHandle.Alloc(bitmapcolorRect, GCHandleType.Pinned);
// 获取数组的指针
bitmapcolorRect_Ptr = bitmapcolorRect_handle.AddrOfPinnedObject();
/** end **/
vblank_begin_timer = Timer.timer_alloc_common(vblank_begin_callback, "vblank_begin_callback", false);
Timer.timer_adjust_periodic(vblank_begin_timer, video_screen_get_time_until_vblank_start(), Attotime.ATTOTIME_NEVER);
scanline0_timer = Timer.timer_alloc_common(scanline0_callback, "scanline0_callback", false);

View File

@ -37,18 +37,19 @@ namespace mame
static void BufferWirte(int Off, byte[] Data)
{
Act_BufferWirte?.Invoke(Off, Data);
Act_BufferWirte.Invoke(Off, Data);
}
static void SubmitSamples(byte[] buffer, int samples_a)
{
Act_SubmitSamples?.Invoke(buffer, samples_a);
Act_SubmitSamples.Invoke(buffer, samples_a);
}
public static void SetVolume(int Vol)
{
Act_SetVolume?.Invoke(Vol);
Act_SetVolume.Invoke(Vol);
}
static void GetCurrentPosition(out int play_position, out int write_position)
{
play_position = 0;