Compare commits
No commits in common. "6edb3b5400f67a2fcccfbebacdf8db8a86d2b19b" and "48c7fe00ebbe882688226f49dfe6ff2e551e75ac" have entirely different histories.
6edb3b5400
...
48c7fe00eb
@ -2350,8 +2350,7 @@ namespace MAME.Core
|
|||||||
}
|
}
|
||||||
public static void cpuexec_timeslice()
|
public static void cpuexec_timeslice()
|
||||||
{
|
{
|
||||||
//Atime target = EmuTimer.lt[0].expire;
|
Atime target = EmuTimer.lt[0].expire;
|
||||||
Atime target = EmuTimer.lt._frist_Timer.expire;
|
|
||||||
Atime tbase = EmuTimer.global_basetime;
|
Atime tbase = EmuTimer.global_basetime;
|
||||||
int ran;
|
int ran;
|
||||||
Atime at;
|
Atime at;
|
||||||
|
|||||||
@ -1,252 +1,85 @@
|
|||||||
using cpu.m6800;
|
using cpu.m6800;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using static MAME.Core.EmuTimer;
|
using static MAME.Core.EmuTimer;
|
||||||
|
|
||||||
namespace MAME.Core
|
namespace MAME.Core
|
||||||
{
|
{
|
||||||
//public class EmuTimerLister
|
|
||||||
//{
|
|
||||||
// List<emu_timer> timerlist;
|
|
||||||
// public int Count = 0;
|
|
||||||
// //缓存首个元素
|
|
||||||
// public emu_timer _frist_Timer;
|
|
||||||
// public emu_timer this[int index]
|
|
||||||
// {
|
|
||||||
// get { return timerlist[index]; }
|
|
||||||
// //set { timerlist[index] = value; } //不需要set
|
|
||||||
// }
|
|
||||||
// public static void GetNewTimerLister(ref EmuTimerLister tlistObj)
|
|
||||||
// {
|
|
||||||
// //如果新旧值替换
|
|
||||||
// if (tlistObj != null)
|
|
||||||
// {
|
|
||||||
// tlistObj.ReleaseLister();
|
|
||||||
// ObjectPoolAuto.Release(tlistObj);
|
|
||||||
// tlistObj = null;
|
|
||||||
// }
|
|
||||||
// tlistObj = ObjectPoolAuto.Acquire<EmuTimerLister>();
|
|
||||||
// tlistObj.InitLister();
|
|
||||||
// }
|
|
||||||
// void InitLister()
|
|
||||||
// {
|
|
||||||
// ReleaseLister();
|
|
||||||
// //对象池产生list
|
|
||||||
// timerlist = ObjectPoolAuto.AcquireList<emu_timer>();
|
|
||||||
// Count = 0;
|
|
||||||
// _frist_Timer = null;
|
|
||||||
// }
|
|
||||||
// void ReleaseLister()
|
|
||||||
// {
|
|
||||||
// if (timerlist != null)
|
|
||||||
// {
|
|
||||||
// Clear();
|
|
||||||
// //对象池回收
|
|
||||||
// ObjectPoolAuto.Release(timerlist);
|
|
||||||
// timerlist = null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// public List<emu_timer> GetSnapshotList()
|
|
||||||
// {
|
|
||||||
// return timerlist;
|
|
||||||
// }
|
|
||||||
// public void Clear()
|
|
||||||
// {
|
|
||||||
// //遍历所有timer减少引用计数后Clear
|
|
||||||
// for (int i = 0; i < Count; i++)
|
|
||||||
// timerlist[i].ReleaseRef();//timer引用计数-1
|
|
||||||
// timerlist.Clear();
|
|
||||||
// Count = 0;
|
|
||||||
// _frist_Timer = null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
// public void Add(emu_timer timer)
|
|
||||||
// {
|
|
||||||
// timerlist.Add(timer);
|
|
||||||
// timer.AddRef();//timer引用计数+1
|
|
||||||
// Count++;
|
|
||||||
// if (Count == 0)
|
|
||||||
// _frist_Timer = timer;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
// public void Remove(emu_timer timer)
|
|
||||||
// {
|
|
||||||
// timerlist.Remove(timer);
|
|
||||||
// timer.ReleaseRef();//timer引用计数-1
|
|
||||||
// Count--;
|
|
||||||
// if(Count == 0)
|
|
||||||
// _frist_Timer = null;
|
|
||||||
// else if(timer == _frist_Timer)
|
|
||||||
// _frist_Timer = timerlist[0];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
// public void Insert(int index, emu_timer timer)
|
|
||||||
// {
|
|
||||||
// timerlist.Insert(index, timer);
|
|
||||||
// timer.AddRef();//timer引用计数+1
|
|
||||||
// Count++;
|
|
||||||
// if (index == 0)
|
|
||||||
// _frist_Timer = timer;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
// public void RemoveAt(int index)
|
|
||||||
// {
|
|
||||||
// timerlist[index].ReleaseRef();//timer引用计数-1
|
|
||||||
// timerlist.RemoveAt(index);
|
|
||||||
// Count--;
|
|
||||||
// if (index == 0)
|
|
||||||
// {
|
|
||||||
// if (Count == 0)
|
|
||||||
// _frist_Timer = null;
|
|
||||||
// else
|
|
||||||
// _frist_Timer = timerlist[0];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //不考虑且禁止使用 IndexOf这种低效的使用方式
|
|
||||||
// //public int IndexOf(emu_timer timer)
|
|
||||||
// //{
|
|
||||||
// // return timerlist.IndexOf(timer);
|
|
||||||
// //}
|
|
||||||
//}
|
|
||||||
|
|
||||||
public class EmuTimerLister
|
public class EmuTimerLister
|
||||||
{
|
{
|
||||||
private emu_timer[] timerArray;
|
public emu_timer this[int index]
|
||||||
private int capacity;
|
|
||||||
public int Count;
|
|
||||||
public emu_timer _frist_Timer;
|
|
||||||
|
|
||||||
public EmuTimerLister()
|
|
||||||
{
|
{
|
||||||
capacity = 32;
|
get { return timerlist[index]; }
|
||||||
timerArray = new emu_timer[capacity];
|
set { timerlist[index] = value; } // 如果需要设置的话
|
||||||
Count = 0;
|
|
||||||
_frist_Timer = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetNewTimerLister(ref EmuTimerLister tlistObj)
|
public static void GetNewTimerLister(ref EmuTimerLister tlistObj)
|
||||||
{
|
{
|
||||||
|
//如果新旧值替换
|
||||||
if (tlistObj != null)
|
if (tlistObj != null)
|
||||||
{
|
{
|
||||||
tlistObj.ReleaseLister();
|
tlistObj.ReleaseLister();
|
||||||
|
ObjectPoolAuto.Release(tlistObj);
|
||||||
tlistObj = null;
|
tlistObj = null;
|
||||||
}
|
}
|
||||||
tlistObj = new EmuTimerLister();
|
|
||||||
|
tlistObj = ObjectPoolAuto.Acquire<EmuTimerLister>();
|
||||||
tlistObj.InitLister();
|
tlistObj.InitLister();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitLister()
|
List<emu_timer> timerlist;
|
||||||
|
|
||||||
|
public List<emu_timer> GetSrcList()
|
||||||
|
{
|
||||||
|
return timerlist;
|
||||||
|
}
|
||||||
|
public int Count
|
||||||
|
{
|
||||||
|
get { return timerlist.Count; }
|
||||||
|
}
|
||||||
|
|
||||||
|
void InitLister()
|
||||||
{
|
{
|
||||||
ReleaseLister();
|
ReleaseLister();
|
||||||
capacity = 16;
|
timerlist = ObjectPoolAuto.AcquireList<emu_timer>();
|
||||||
timerArray = new emu_timer[capacity];
|
|
||||||
Count = 0;
|
|
||||||
_frist_Timer = null;
|
|
||||||
}
|
}
|
||||||
|
void ReleaseLister()
|
||||||
public void ReleaseLister()
|
|
||||||
{
|
{
|
||||||
if (timerArray != null)
|
if (timerlist != null)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
timerArray = null;
|
ObjectPoolAuto.Release(timerlist);
|
||||||
|
timerlist = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<emu_timer> GetSnapshotList()
|
|
||||||
{
|
|
||||||
var list = new List<emu_timer>(Count);
|
|
||||||
for (int i = 0; i < Count; i++)
|
|
||||||
{
|
|
||||||
list.Add(timerArray[i]);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Count; i++)
|
emu_timer.ClearList(ref timerlist);
|
||||||
{
|
|
||||||
timerArray[i] = null;
|
|
||||||
timerArray[i].ReleaseRef();
|
|
||||||
}
|
|
||||||
Count = 0;
|
|
||||||
_frist_Timer = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public emu_timer this[int index] => timerArray[index];
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
private void EnsureCapacity()
|
|
||||||
{
|
|
||||||
if (Count >= capacity)
|
|
||||||
{
|
|
||||||
capacity *= 2;
|
|
||||||
Array.Resize(ref timerArray, capacity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void Add(emu_timer timer)
|
public void Add(emu_timer timer)
|
||||||
{
|
{
|
||||||
EnsureCapacity();
|
emu_timer.AddList(ref timerlist, ref timer);
|
||||||
timerArray[Count] = timer;
|
|
||||||
timer.AddRef();
|
|
||||||
if (Count == 0)
|
|
||||||
_frist_Timer = timer;
|
|
||||||
Count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void Remove(emu_timer timer)
|
public void Remove(emu_timer timer)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Count; i++)
|
emu_timer.RemoveToList(ref timerlist, ref timer);
|
||||||
{
|
|
||||||
if (timerArray[i] == timer)
|
|
||||||
{
|
|
||||||
RemoveAt(i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void Insert(int index, emu_timer timer)
|
public void Insert(int index, emu_timer timer)
|
||||||
{
|
{
|
||||||
EnsureCapacity();
|
emu_timer.InsertToList(ref timerlist, index, ref timer);
|
||||||
if (index < Count)
|
}
|
||||||
{
|
|
||||||
Array.Copy(timerArray, index, timerArray, index + 1, Count - index);
|
public int IndexOf(emu_timer timer)
|
||||||
}
|
{
|
||||||
timerArray[index] = timer;
|
return timerlist.IndexOf(timer);
|
||||||
timer.AddRef();
|
|
||||||
Count++;
|
|
||||||
if (index == 0)
|
|
||||||
_frist_Timer = timer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void RemoveAt(int index)
|
public void RemoveAt(int index)
|
||||||
{
|
{
|
||||||
emu_timer timer = timerArray[index];
|
emu_timer.RemoveAtToList(ref timerlist, index);
|
||||||
timer.ReleaseRef();
|
|
||||||
if (index < Count - 1)
|
|
||||||
{
|
|
||||||
Array.Copy(timerArray, index + 1, timerArray, index, Count - index - 1);
|
|
||||||
}
|
|
||||||
timerArray[Count - 1] = null;
|
|
||||||
Count--;
|
|
||||||
if (Count == 0)
|
|
||||||
_frist_Timer = null;
|
|
||||||
else if (index == 0)
|
|
||||||
_frist_Timer = timerArray[0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EmuTimer
|
public class EmuTimer
|
||||||
{
|
{
|
||||||
public static EmuTimerLister lt;
|
public static EmuTimerLister lt;
|
||||||
@ -348,7 +181,7 @@ namespace MAME.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 增加引用计数
|
/// 增加引用计数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddRef()
|
void AddRef()
|
||||||
{
|
{
|
||||||
//int newCount = Interlocked.Increment(ref _refCount);
|
//int newCount = Interlocked.Increment(ref _refCount);
|
||||||
_refCount++;
|
_refCount++;
|
||||||
@ -357,7 +190,7 @@ namespace MAME.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 减少引用计数,当计数为0时释放对象回池
|
/// 减少引用计数,当计数为0时释放对象回池
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ReleaseRef()
|
void ReleaseRef()
|
||||||
{
|
{
|
||||||
//int newCount = Interlocked.Decrement(ref _refCount);
|
//int newCount = Interlocked.Decrement(ref _refCount);
|
||||||
_refCount--;
|
_refCount--;
|
||||||
@ -412,31 +245,32 @@ namespace MAME.Core
|
|||||||
timer = null;
|
timer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//public static void AddList(ref List<emu_timer> list, ref emu_timer timer)
|
public static void AddList(ref List<emu_timer> list, ref emu_timer timer)
|
||||||
//{
|
{
|
||||||
// list.Add(timer);
|
list.Add(timer);
|
||||||
// timer.AddRef();
|
timer.AddRef();
|
||||||
//}
|
}
|
||||||
//internal static void InsertToList(ref List<emu_timer> list, int index, ref emu_timer timer)
|
internal static void InsertToList(ref List<emu_timer> list, int index, ref emu_timer timer)
|
||||||
//{
|
{
|
||||||
// list.Insert(index, timer);
|
list.Insert(index, timer);
|
||||||
// timer.AddRef();
|
timer.AddRef();
|
||||||
//}
|
}
|
||||||
//public static void RemoveToList(ref List<emu_timer> list, ref emu_timer timer)
|
public static void RemoveToList(ref List<emu_timer> list, ref emu_timer timer)
|
||||||
//{
|
{
|
||||||
// list.Remove(timer);
|
list.Remove(timer);
|
||||||
// timer.ReleaseRef();
|
timer.ReleaseRef();
|
||||||
//}
|
}
|
||||||
//internal static void ClearList(ref List<emu_timer> list)
|
internal static void ClearList(ref List<emu_timer> list)
|
||||||
//{
|
{
|
||||||
// for (int i = 0; i < list.Count; i++)
|
for (int i = 0; i < list.Count; i++)
|
||||||
// list[i].ReleaseRef();
|
list[i].ReleaseRef();
|
||||||
// list.Clear();
|
list.Clear();
|
||||||
//}
|
}
|
||||||
//internal static void RemoveAtToList(ref List<emu_timer> list, int index)
|
|
||||||
//{
|
internal static void RemoveAtToList(ref List<emu_timer> list, int index)
|
||||||
// list.RemoveAt(index);
|
{
|
||||||
//}
|
list.RemoveAt(index);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
/*
|
/*
|
||||||
static void EnqueueObj(emu_timer obj)
|
static void EnqueueObj(emu_timer obj)
|
||||||
@ -886,8 +720,7 @@ namespace MAME.Core
|
|||||||
//timer_list_insert(which);
|
//timer_list_insert(which);
|
||||||
|
|
||||||
//if (lt.IndexOf(which) == 0)
|
//if (lt.IndexOf(which) == 0)
|
||||||
//if (lt[0] == which)
|
if (lt[0] == which)
|
||||||
if (lt._frist_Timer == which)
|
|
||||||
{
|
{
|
||||||
if (Cpuexec.activecpu >= 0 && Cpuexec.activecpu < Cpuexec.ncpu)
|
if (Cpuexec.activecpu >= 0 && Cpuexec.activecpu < Cpuexec.ncpu)
|
||||||
{
|
{
|
||||||
@ -1119,9 +952,9 @@ namespace MAME.Core
|
|||||||
{
|
{
|
||||||
TIME_ACT currAct = timer1.action;
|
TIME_ACT currAct = timer1.action;
|
||||||
int i1 = -1;
|
int i1 = -1;
|
||||||
//var tlist = lt.GetSnapshotList();
|
var tlist = lt.GetSrcList();
|
||||||
int scanCount;
|
int scanCount;
|
||||||
int tempMaxIdx = lt.Count - 1;
|
int tempMaxIdx = tlist.Count - 1;
|
||||||
if (currAct == TIME_ACT.Cpuint_cpunum_empty_event_queue || currAct == TIME_ACT.setvector)
|
if (currAct == TIME_ACT.Cpuint_cpunum_empty_event_queue || currAct == TIME_ACT.setvector)
|
||||||
{
|
{
|
||||||
//foreach (emu_timer et in lt)
|
//foreach (emu_timer et in lt)
|
||||||
@ -1136,7 +969,7 @@ namespace MAME.Core
|
|||||||
scanCount = 0;
|
scanCount = 0;
|
||||||
while (scanCount >= tempMaxIdx)
|
while (scanCount >= tempMaxIdx)
|
||||||
{
|
{
|
||||||
emu_timer et = lt[scanCount];
|
emu_timer et = tlist[scanCount];
|
||||||
if (et.action == currAct && Attotime.attotime_compare(et.expire, global_basetime) <= 0)
|
if (et.action == currAct && Attotime.attotime_compare(et.expire, global_basetime) <= 0)
|
||||||
{
|
{
|
||||||
i1 = scanCount;
|
i1 = scanCount;
|
||||||
@ -1151,7 +984,7 @@ namespace MAME.Core
|
|||||||
scanCount = 0;
|
scanCount = 0;
|
||||||
while (scanCount <= tempMaxIdx)
|
while (scanCount <= tempMaxIdx)
|
||||||
{
|
{
|
||||||
emu_timer et = lt[scanCount];
|
emu_timer et = tlist[scanCount];
|
||||||
if (Attotime.attotime_compare(et.expire, expire) > 0)
|
if (Attotime.attotime_compare(et.expire, expire) > 0)
|
||||||
break;
|
break;
|
||||||
scanCount++;
|
scanCount++;
|
||||||
@ -1219,11 +1052,11 @@ namespace MAME.Core
|
|||||||
//foreach (emu_timer et1 in timer_list_remove_lt1)
|
//foreach (emu_timer et1 in timer_list_remove_lt1)
|
||||||
// lt.Remove(et1);
|
// lt.Remove(et1);
|
||||||
|
|
||||||
//var tlist = lt.GetSnapshotList();
|
var tlist = lt.GetSrcList();
|
||||||
int tempMaxIdx = lt.Count - 1;
|
int tempMaxIdx = tlist.Count - 1;
|
||||||
while (tempMaxIdx >= 0)
|
while (tempMaxIdx >= 0)
|
||||||
{
|
{
|
||||||
emu_timer et = lt[tempMaxIdx];
|
emu_timer et = tlist[tempMaxIdx];
|
||||||
if (et.action == timer1.action && Attotime.attotime_compare(et.expire, timer1.expire) == 0)
|
if (et.action == timer1.action && Attotime.attotime_compare(et.expire, timer1.expire) == 0)
|
||||||
lt.Remove(et);
|
lt.Remove(et);
|
||||||
tempMaxIdx--;
|
tempMaxIdx--;
|
||||||
@ -1242,12 +1075,12 @@ namespace MAME.Core
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//var tlist = lt.GetSnapshotList();
|
var tlist = lt.GetSrcList();
|
||||||
int tempMaxIdx = lt.Count - 1;
|
int tempMaxIdx = tlist.Count - 1;
|
||||||
int scanCount = 0;
|
int scanCount = 0;
|
||||||
while (scanCount <= tempMaxIdx)
|
while (scanCount <= tempMaxIdx)
|
||||||
{
|
{
|
||||||
emu_timer et = lt[scanCount];
|
emu_timer et = tlist[scanCount];
|
||||||
if (et.action == timer1.action)
|
if (et.action == timer1.action)
|
||||||
{
|
{
|
||||||
lt.Remove(et);
|
lt.Remove(et);
|
||||||
@ -1295,13 +1128,10 @@ namespace MAME.Core
|
|||||||
{
|
{
|
||||||
emu_timer timer;
|
emu_timer timer;
|
||||||
global_basetime = newbase;
|
global_basetime = newbase;
|
||||||
//while (Attotime.attotime_compare(lt[0].expire, global_basetime) <= 0)
|
while (Attotime.attotime_compare(lt[0].expire, global_basetime) <= 0)
|
||||||
while (Attotime.attotime_compare(lt._frist_Timer.expire, global_basetime) <= 0)
|
|
||||||
{
|
{
|
||||||
//bool was_enabled = lt[0].enabled;
|
bool was_enabled = lt[0].enabled;
|
||||||
bool was_enabled = lt._frist_Timer.enabled;
|
timer = lt[0];
|
||||||
//timer = lt[0];
|
|
||||||
timer = lt._frist_Timer;
|
|
||||||
if (Attotime.attotime_compare(timer.period, Attotime.ATTOTIME_ZERO) == 0 || Attotime.attotime_compare(timer.period, Attotime.ATTOTIME_NEVER) == 0)
|
if (Attotime.attotime_compare(timer.period, Attotime.ATTOTIME_ZERO) == 0 || Attotime.attotime_compare(timer.period, Attotime.ATTOTIME_NEVER) == 0)
|
||||||
{
|
{
|
||||||
timer.enabled = false;
|
timer.enabled = false;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Mono.Cecil.Cil;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace MAME.Core
|
namespace MAME.Core
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user