减少不必要的访问器堆栈开销,完全指针化entry_color读写

This commit is contained in:
sin365 2025-09-17 18:33:21 +08:00
parent 7e8d0e8340
commit c457e27bac
7 changed files with 55 additions and 36 deletions

View File

@ -632,7 +632,7 @@ namespace cpu.m68000
void STOP() void STOP()
{ {
if (S) if (s)
{ {
short new_sr = ReadOpWord(PC); PC += 2; short new_sr = ReadOpWord(PC); PC += 2;
stopped = true; stopped = true;

View File

@ -169,7 +169,7 @@ namespace cpu.m68000
void RESET() void RESET()
{ {
if (S) if (s)
{ {
pendingCycles -= 132; pendingCycles -= 132;
} }

View File

@ -8,7 +8,7 @@ namespace cpu.m68000
{ {
int mode = (op >> 3) & 7; int mode = (op >> 3) & 7;
int reg = (op >> 0) & 7; int reg = (op >> 0) & 7;
if (S == false) if (s == false)
{ {
//throw new Exception("Write to SR when not in supervisor mode. supposed to trap or something..."); //throw new Exception("Write to SR when not in supervisor mode. supposed to trap or something...");
TrapVector2(8); TrapVector2(8);
@ -54,7 +54,7 @@ namespace cpu.m68000
{ {
int dir = (op >> 3) & 1; int dir = (op >> 3) & 1;
int reg = op & 7; int reg = op & 7;
if (S == false) if (s == false)
{ {
//throw new Exception("MOVE to USP when not supervisor. needs to trap"); //throw new Exception("MOVE to USP when not supervisor. needs to trap");
TrapVector2(8); TrapVector2(8);
@ -76,7 +76,7 @@ namespace cpu.m68000
void ANDI_SR() void ANDI_SR()
{ {
if (S == false) if (s == false)
throw new Exception("trap!"); throw new Exception("trap!");
SR &= ReadOpWord(PC); PC += 2; SR &= ReadOpWord(PC); PC += 2;
pendingCycles -= 20; pendingCycles -= 20;
@ -85,7 +85,7 @@ namespace cpu.m68000
void EORI_SR() void EORI_SR()
{ {
if (S == false) if (s == false)
throw new Exception("trap!"); throw new Exception("trap!");
SR ^= ReadOpWord(PC); PC += 2; SR ^= ReadOpWord(PC); PC += 2;
pendingCycles -= 20; pendingCycles -= 20;
@ -94,7 +94,7 @@ namespace cpu.m68000
void ORI_SR() void ORI_SR()
{ {
if (S == false) if (s == false)
throw new Exception("trap!"); throw new Exception("trap!");
SR |= ReadOpWord(PC); PC += 2; SR |= ReadOpWord(PC); PC += 2;
pendingCycles -= 20; pendingCycles -= 20;

View File

@ -45,7 +45,7 @@ namespace cpu.m68000
public bool stopped; public bool stopped;
/// <summary>Machine/Interrupt mode</summary> /// <summary>Machine/Interrupt mode</summary>
public bool M { get { return m; } set { m = value; } } // TODO probably have some switch logic maybe //public bool M { get { return m; } set { m = value; } } // TODO probably have some switch logic maybe
public void SetS(bool b1) public void SetS(bool b1)
{ {
@ -60,10 +60,11 @@ namespace cpu.m68000
/// <summary>Supervisor/User mode</summary> /// <summary>Supervisor/User mode</summary>
public bool S public bool S
{ {
get //减少不必要的访问器堆栈
{ //get
return s; //{
} // return s;
//}
set set
{ {
if (value == s) if (value == s)
@ -109,8 +110,8 @@ namespace cpu.m68000
if (Z) value |= 0x0004; if (Z) value |= 0x0004;
if (N) value |= 0x0008; if (N) value |= 0x0008;
if (X) value |= 0x0010; if (X) value |= 0x0010;
if (M) value |= 0x1000; if (m) value |= 0x1000;
if (S) value |= 0x2000; if (s) value |= 0x2000;
value |= (short)((InterruptMaskLevel & 7) << 8); value |= (short)((InterruptMaskLevel & 7) << 8);
return value; return value;
} }
@ -121,7 +122,7 @@ namespace cpu.m68000
Z = (value & 0x0004) != 0; Z = (value & 0x0004) != 0;
N = (value & 0x0008) != 0; N = (value & 0x0008) != 0;
X = (value & 0x0010) != 0; X = (value & 0x0010) != 0;
M = (value & 0x1000) != 0; m = (value & 0x1000) != 0;
S = (value & 0x2000) != 0; S = (value & 0x2000) != 0;
InterruptMaskLevel = (value >> 8) & 7; InterruptMaskLevel = (value >> 8) & 7;
//m68ki_check_interrupts(); //m68ki_check_interrupts();
@ -197,7 +198,7 @@ namespace cpu.m68000
stopped = false; stopped = false;
pendingCycles = 0; pendingCycles = 0;
S = true; S = true;
M = false; m = false;
InterruptMaskLevel = 7; InterruptMaskLevel = 7;
Interrupt = 0; Interrupt = 0;
A[7].s32 = ReadOpLong(0); A[7].s32 = ReadOpLong(0);
@ -287,8 +288,8 @@ namespace cpu.m68000
} }
writer.Write(MC68000.m1.PPC); writer.Write(MC68000.m1.PPC);
writer.Write(MC68000.m1.PC); writer.Write(MC68000.m1.PC);
writer.Write(MC68000.m1.S); writer.Write(MC68000.m1.s);
writer.Write(MC68000.m1.M); writer.Write(MC68000.m1.m);
writer.Write(MC68000.m1.X); writer.Write(MC68000.m1.X);
writer.Write(MC68000.m1.N); writer.Write(MC68000.m1.N);
writer.Write(MC68000.m1.Z); writer.Write(MC68000.m1.Z);
@ -317,7 +318,7 @@ namespace cpu.m68000
MC68000.m1.PPC = reader.ReadInt32(); MC68000.m1.PPC = reader.ReadInt32();
MC68000.m1.PC = reader.ReadInt32(); MC68000.m1.PC = reader.ReadInt32();
MC68000.m1.SetS(reader.ReadBoolean()); MC68000.m1.SetS(reader.ReadBoolean());
MC68000.m1.M = reader.ReadBoolean(); MC68000.m1.m = reader.ReadBoolean();
MC68000.m1.X = reader.ReadBoolean(); MC68000.m1.X = reader.ReadBoolean();
MC68000.m1.N = reader.ReadBoolean(); MC68000.m1.N = reader.ReadBoolean();
MC68000.m1.Z = reader.ReadBoolean(); MC68000.m1.Z = reader.ReadBoolean();

View File

@ -93,7 +93,7 @@
//ushort* curbitmap = curbitmapPtr; //ushort* curbitmap = curbitmapPtr;
ushort* curbitmap = (ushort*)Video.bitmapbase_Ptrs[Video.curbitmap]; ushort* curbitmap = (ushort*)Video.bitmapbase_Ptrs[Video.curbitmap];
//uint* entry_color = entry_colorPtr; //uint* entry_color = entry_colorPtr;
uint* entry_color = (uint*)Palette.entry_color_Ptr; uint* entry_color = (uint*)Palette.entry_color;
//int* bitmapcolorRect = bitmapcolorRectPtr; //int* bitmapcolorRect = bitmapcolorRectPtr;
int* bitmapcolorRect = (int*)Video.bitmapcolorRect_Ptr; int* bitmapcolorRect = (int*)Video.bitmapcolorRect_Ptr;

View File

@ -3,13 +3,28 @@ using System.Runtime.InteropServices;
namespace MAME.Core namespace MAME.Core
{ {
public class Palette public unsafe class Palette
{ {
public static uint[] entry_color; //public static uint[] entry_color;
/** entry_color的指针管理 **/
#region //指针化 entry_color
static uint[] entry_color_src;
static GCHandle entry_color_handle; static GCHandle entry_color_handle;
public static IntPtr entry_color_Ptr; public static uint* entry_color;
/** end **/ public static int entry_colorLength;
public static bool entry_color_IsNull => entry_color == null;
public static uint[] entry_color_set
{
set
{
entry_color_handle.ReleaseGCHandle();
entry_color_src = value;
entry_colorLength = value.Length;
entry_color_src.GetObjectPtr(ref entry_color_handle, ref entry_color);
}
}
#endregion
public static float[] entry_contrast; public static float[] entry_contrast;
private static uint trans_uint; private static uint trans_uint;
@ -174,18 +189,21 @@ namespace MAME.Core
//entry_color = new uint[numcolors]; //entry_color = new uint[numcolors];
entry_color_set = new uint[numcolors];
/** entry_color的指针管理 **/ ///** entry_color的指针管理 **/
// 释放句柄 //// 释放句柄
if (entry_color != null && entry_color_handle.IsAllocated) //if (entry_color != null && entry_color_handle.IsAllocated)
entry_color_handle.Free(); // entry_color_handle.Free();
//entry_color = new uint[numcolors];
//// 固定数组,防止垃圾回收器移动它
//entry_color_handle = GCHandle.Alloc(entry_color, GCHandleType.Pinned);
//// 获取数组的指针
//entry_color_Ptr = entry_color_handle.AddrOfPinnedObject();
///** end **/
///
entry_color = new uint[numcolors];
// 固定数组,防止垃圾回收器移动它
entry_color_handle = GCHandle.Alloc(entry_color, GCHandleType.Pinned);
// 获取数组的指针
entry_color_Ptr = entry_color_handle.AddrOfPinnedObject();
/** end **/

View File

@ -45,7 +45,7 @@ namespace MAME.Core
writer.Write(Sound.mixerstream.output_sampindex); writer.Write(Sound.mixerstream.output_sampindex);
writer.Write(Sound.mixerstream.output_base_sampindex); writer.Write(Sound.mixerstream.output_base_sampindex);
} }
public static void LoadStateBinary_pbaction(System.IO.BinaryReader reader) public unsafe static void LoadStateBinary_pbaction(System.IO.BinaryReader reader)
{ {
int i; int i;
dsw1 = reader.ReadByte(); dsw1 = reader.ReadByte();