减少不必要的访问器堆栈开销,完全指针化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()
{
if (S)
if (s)
{
short new_sr = ReadOpWord(PC); PC += 2;
stopped = true;

View File

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

View File

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

View File

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

View File

@ -93,7 +93,7 @@
//ushort* curbitmap = curbitmapPtr;
ushort* curbitmap = (ushort*)Video.bitmapbase_Ptrs[Video.curbitmap];
//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 = (int*)Video.bitmapcolorRect_Ptr;

View File

@ -3,13 +3,28 @@ using System.Runtime.InteropServices;
namespace MAME.Core
{
public class Palette
public unsafe class Palette
{
public static uint[] entry_color;
/** entry_color的指针管理 **/
//public static uint[] entry_color;
#region //指针化 entry_color
static uint[] entry_color_src;
static GCHandle entry_color_handle;
public static IntPtr entry_color_Ptr;
/** end **/
public static uint* entry_color;
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;
private static uint trans_uint;
@ -174,18 +189,21 @@ namespace MAME.Core
//entry_color = new uint[numcolors];
entry_color_set = new uint[numcolors];
/** entry_color的指针管理 **/
// 释放句柄
if (entry_color != null && entry_color_handle.IsAllocated)
entry_color_handle.Free();
///** entry_color的指针管理 **/
//// 释放句柄
//if (entry_color != null && entry_color_handle.IsAllocated)
// 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_base_sampindex);
}
public static void LoadStateBinary_pbaction(System.IO.BinaryReader reader)
public unsafe static void LoadStateBinary_pbaction(System.IO.BinaryReader reader)
{
int i;
dsw1 = reader.ReadByte();