diff --git a/MAME.Core/AxiBitmap/AxiBitmap.cs b/MAME.Core/AxiBitmap/AxiBitmap.cs index 5d6cd8a..6f31f3e 100644 --- a/MAME.Core/AxiBitmap/AxiBitmap.cs +++ b/MAME.Core/AxiBitmap/AxiBitmap.cs @@ -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; + b = _b; + 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; } + } + } } diff --git a/MAME.Core/Motion/mainMotion.cs b/MAME.Core/Motion/mainMotion.cs index f9b2160..7cde691 100644 --- a/MAME.Core/Motion/mainMotion.cs +++ b/MAME.Core/Motion/mainMotion.cs @@ -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 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(); diff --git a/MAME.Core/emu/Gdi.cs b/MAME.Core/emu/Gdi.cs index a693711..285c0fd 100644 --- a/MAME.Core/emu/Gdi.cs +++ b/MAME.Core/emu/Gdi.cs @@ -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) { diff --git a/MAME.Core/emu/Motion.cs b/MAME.Core/emu/Motion.cs index 0a0a152..1449d8c 100644 --- a/MAME.Core/emu/Motion.cs +++ b/MAME.Core/emu/Motion.cs @@ -1,5 +1,7 @@ using MAME.Core.Common; using MAME.Core.run_interface; +using UnityEngine; +using static UnityEngine.GraphicsBuffer; namespace mame { @@ -24,153 +26,418 @@ namespace mame } public static void ui_updateC() { - int i; - int red, green, blue; - if (single_step || Mame.paused) + //不再填充完整画布 + //{ + // 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]]; + // } + // } + //} + { - byte bright = 0xa7; - for (i = 0; i < Video.fullwidth * Video.fullheight; 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) { - 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); + byte bright = 0xa7; + 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.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue); + } + } } - } - else - { - for (i = 0; i < Video.fullwidth * Video.fullheight; i++) + else { - Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]]; + + for (y = startY; y < endY; y++) + { + 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) + //不再填充完整画布 + //{ + // 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]; + // } + // } + // } + //} + { - byte bright = 0xa7; - for (i = 0; i < Video.fullwidth * Video.fullheight; 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) { - if (Video.bitmapbase[Video.curbitmap][i] < 0x100) + byte bright = 0xa7; + for (y = startY; y < endY; y++) { - 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; + 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.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue); + } + else + { + int i1 = 1; + } + } } } - } - else - { - for (i = 0; i < Video.fullwidth * Video.fullheight; i++) + else { - if (Video.bitmapbase[Video.curbitmap][i] < 0x100) + for (y = startY; y < endY; y++) { - Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]]; - } - else - { - Video.bitmapcolor[i] = (int)Palette.entry_color[0]; + 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) + //不再填充完整画布 + //{ + // 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]); + // } + // } + //} + { - byte bright = 0xa7; - for (i = 0; i < Video.fullwidth * Video.fullheight; 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) { - 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); + byte bright = 0xa7; + 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.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue); + } + } } - } - else - { - for (i = 0; i < Video.fullwidth * Video.fullheight; i++) + else { - Video.bitmapcolor[i] = (int)(0xff000000 | (uint)Video.bitmapbaseN[Video.curbitmap][i]); + for (y = startY; y < endY; y++) + { + 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) + //不再填充完整画布 + //{ + // 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]]; + // } + // } + //} + { - byte bright = 0xa7; - for (i = 0; i < Video.fullwidth * Video.fullheight; 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) { - 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); + byte bright = 0xa7; + 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.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue); + } + } } - } - else - { - for (i = 0; i < Video.fullwidth * Video.fullheight; i++) + else { - Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]]; + for (y = startY; y < endY; y++) + { + 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) + //不再填充完整画布 + //{ + // 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]]; + // } + // } + //} + { - byte bright = 0xa7; - for (i = 0; i < Video.fullwidth * Video.fullheight; 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) { - 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); + byte bright = 0xa7; + 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.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue); + } + } } - } - else - { - for (i = 0; i < Video.fullwidth * Video.fullheight; i++) + else { - Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]]; + for (y = startY; y < endY; y++) + { + 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) + //不再填充完整画布 + //{ + // 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]]; + // } + // } + //} + { - byte bright = 0xa7; - for (i = 0; i < Video.fullwidth * Video.fullheight; 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) { - 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); + byte bright = 0xa7; + 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.bitmapcolorRect[target_i] = (int)Palette.make_argb(0xff, red, green, blue); + } + } } - } - else - { - for (i = 0; i < Video.fullwidth * Video.fullheight; i++) + else { - Video.bitmapcolor[i] = (int)Palette.entry_color[Video.bitmapbase[Video.curbitmap][i]]; + for (y = startY; y < endY; y++) + { + 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]]; + } + } } } } diff --git a/MAME.Core/emu/Palette.cs b/MAME.Core/emu/Palette.cs index 75c7c70..7173a1e 100644 --- a/MAME.Core/emu/Palette.cs +++ b/MAME.Core/emu/Palette.cs @@ -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; diff --git a/MAME.Core/emu/Video.cs b/MAME.Core/emu/Video.cs index da9d3bf..9e97338 100644 --- a/MAME.Core/emu/Video.cs +++ b/MAME.Core/emu/Video.cs @@ -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); diff --git a/MAME.Core/sound/Sound.cs b/MAME.Core/sound/Sound.cs index ce457cb..2d05cdf 100644 --- a/MAME.Core/sound/Sound.cs +++ b/MAME.Core/sound/Sound.cs @@ -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;