From 9e7b37a70927f6c5123d768ae60cddf1b56c1ea9 Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Thu, 6 Nov 2025 17:06:17 +0800 Subject: [PATCH] =?UTF-8?q?MAME:=E5=87=8F=E5=B0=91M92=E7=9A=84IRQ=20SOUND?= =?UTF-8?q?=E7=9A=84GC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Plugins/Mame.Core/emu/Cpuint.cs | 35 +++++++-- .../Plugins/Mame.Core/mame/m72/Audio.cs | 15 ++-- .../Assets/Plugins/Mame.Core/mame/m92/M92.cs | 18 +++-- .../Plugins/Mame.Core/sound/Iremga20.cs | 72 ++++++++++--------- 4 files changed, 92 insertions(+), 48 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/emu/Cpuint.cs b/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/emu/Cpuint.cs index 1294bd9c..cdd5c87d 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/emu/Cpuint.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/emu/Cpuint.cs @@ -78,6 +78,12 @@ namespace MAME.Core vector = _vector; time = _time; } + public vec setdata(int _vector, Atime _time) + { + vector = _vector; + time = _time; + return this; + } } public class Cpuint { @@ -88,11 +94,29 @@ namespace MAME.Core //public static int[, ,] input_state; public static List lirq; public static List lvec; + + static void lvec_reinit() + { + if (lvec == null) + { + lvec = ObjectPoolAuto.AcquireList(); + } + else + { + for (int i = lvec.Count - 1; i >= 0; i--) + { + ObjectPoolAuto.Release(lvec[i]); + } + lvec.Clear(); + } + } + public static void cpuint_init() { int i, j; lirq = new List(); - lvec = new List(); + //lvec = new List(); + lvec_reinit(); interrupt_vector = new int[8, 35]; input_line_state = new byte[8, 35]; input_line_vector = new int[8, 35]; @@ -112,7 +136,8 @@ namespace MAME.Core { int i, j; lirq = new List(); - lvec = new List(); + //lvec = new List(); + lvec_reinit(); for (i = 0; i < 8; i++) { for (j = 0; j < 35; j++) @@ -282,10 +307,12 @@ namespace MAME.Core { int i, n; n = reader.ReadInt32(); - lvec = new List(); + //lvec = new List(); + lvec_reinit(); for (i = 0; i < n; i++) { - lvec.Add(new vec()); + //lvec.Add(new vec()); + lvec.Add(ObjectPoolAuto.Acquire()); lvec[i].vector = reader.ReadInt32(); lvec[i].time.seconds = reader.ReadInt32(); lvec[i].time.attoseconds = reader.ReadInt64(); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/mame/m72/Audio.cs b/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/mame/m72/Audio.cs index 2b1fa179..68efbb85 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/mame/m72/Audio.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/mame/m72/Audio.cs @@ -44,14 +44,16 @@ { if (irq != 0) { - Cpuint.lvec.Add(new vec(1, EmuTimer.get_current_time())); + //Cpuint.lvec.Add(new vec(1, EmuTimer.get_current_time())); + Cpuint.lvec.Add(ObjectPoolAuto.Acquire().setdata(1, EmuTimer.get_current_time())); setvector_param = 1; EmuTimer.emu_timer timer = EmuTimer.timer_alloc_common(EmuTimer.TIME_ACT.setvector, true); EmuTimer.timer_adjust_periodic(timer, Attotime.ATTOTIME_ZERO, Attotime.ATTOTIME_NEVER); } else { - Cpuint.lvec.Add(new vec(2, EmuTimer.get_current_time())); + //Cpuint.lvec.Add(new vec(2, EmuTimer.get_current_time())); + Cpuint.lvec.Add(ObjectPoolAuto.Acquire().setdata(2, EmuTimer.get_current_time())); setvector_param = 2; EmuTimer.emu_timer timer = EmuTimer.timer_alloc_common(EmuTimer.TIME_ACT.setvector, true); EmuTimer.timer_adjust_periodic(timer, Attotime.ATTOTIME_ZERO, Attotime.ATTOTIME_NEVER); @@ -62,7 +64,8 @@ //if (ACCESSING_BITS_0_7) { Sound.soundlatch_w(data); - Cpuint.lvec.Add(new vec(3, EmuTimer.get_current_time())); + //Cpuint.lvec.Add(new vec(3, EmuTimer.get_current_time())); + Cpuint.lvec.Add(ObjectPoolAuto.Acquire().setdata(3, EmuTimer.get_current_time())); setvector_param = 3; EmuTimer.emu_timer timer = EmuTimer.timer_alloc_common(EmuTimer.TIME_ACT.setvector, true); EmuTimer.timer_adjust_periodic(timer, Attotime.ATTOTIME_ZERO, Attotime.ATTOTIME_NEVER); @@ -71,14 +74,16 @@ public static void m72_sound_command_byte_w(int offset, byte data) { Sound.soundlatch_w(data); - Cpuint.lvec.Add(new vec(3, EmuTimer.get_current_time())); + //Cpuint.lvec.Add(new vec(3, EmuTimer.get_current_time())); + Cpuint.lvec.Add(ObjectPoolAuto.Acquire().setdata(3, EmuTimer.get_current_time())); setvector_param = 3; EmuTimer.emu_timer timer = EmuTimer.timer_alloc_common(EmuTimer.TIME_ACT.setvector, true); EmuTimer.timer_adjust_periodic(timer, Attotime.ATTOTIME_ZERO, Attotime.ATTOTIME_NEVER); } public static void m72_sound_irq_ack_w(int offset, byte data) { - Cpuint.lvec.Add(new vec(4, EmuTimer.get_current_time())); + //Cpuint.lvec.Add(new vec(4, EmuTimer.get_current_time())); + Cpuint.lvec.Add(ObjectPoolAuto.Acquire().setdata(4, EmuTimer.get_current_time())); setvector_param = 4; EmuTimer.emu_timer timer = EmuTimer.timer_alloc_common(EmuTimer.TIME_ACT.setvector, true); EmuTimer.timer_adjust_periodic(timer, Attotime.ATTOTIME_ZERO, Attotime.ATTOTIME_NEVER); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/mame/m92/M92.cs b/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/mame/m92/M92.cs index 51893162..90fa27eb 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/mame/m92/M92.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/mame/m92/M92.cs @@ -468,7 +468,8 @@ namespace MAME.Core } public static void setvector_callback() { - List lsvec = new List(); + List lsvec = ObjectPoolAuto.AcquireList(); + //List lsvec = new List(); foreach (vec v1 in Cpuint.lvec) { if (Attotime.attotime_compare(v1.time, EmuTimer.global_basetime) < 0) @@ -485,7 +486,10 @@ namespace MAME.Core foreach (vec v1 in lsvec) { Cpuint.lvec.Remove(v1); + ObjectPoolAuto.Release(v1); } + + ObjectPoolAuto.Release(lsvec); switch (setvector_param) { case 0: @@ -523,7 +527,8 @@ namespace MAME.Core } public static void m92_soundlatch_w(ushort data) { - Cpuint.lvec.Add(new vec(3, EmuTimer.get_current_time())); + //Cpuint.lvec.Add(new vec(3, EmuTimer.get_current_time())); + Cpuint.lvec.Add(ObjectPoolAuto.Acquire().setdata(3, EmuTimer.get_current_time())); setvector_param = 3; EmuTimer.emu_timer timer = EmuTimer.timer_alloc_common(EmuTimer.TIME_ACT.setvector, true); EmuTimer.timer_adjust_periodic(timer, Attotime.ATTOTIME_ZERO, Attotime.ATTOTIME_NEVER); @@ -539,7 +544,8 @@ namespace MAME.Core } public static void m92_sound_irq_ack_w() { - Cpuint.lvec.Add(new vec(4, EmuTimer.get_current_time())); + //Cpuint.lvec.Add(new vec(4, EmuTimer.get_current_time())); + Cpuint.lvec.Add(ObjectPoolAuto.Acquire().setdata(4, EmuTimer.get_current_time())); setvector_param = 4; EmuTimer.emu_timer timer = EmuTimer.timer_alloc_common(EmuTimer.TIME_ACT.setvector, true); EmuTimer.timer_adjust_periodic(timer, Attotime.ATTOTIME_ZERO, Attotime.ATTOTIME_NEVER); @@ -553,14 +559,16 @@ namespace MAME.Core { if (state != 0) { - Cpuint.lvec.Add(new vec(1, EmuTimer.get_current_time())); + //Cpuint.lvec.Add(new vec(1, EmuTimer.get_current_time())); + Cpuint.lvec.Add(ObjectPoolAuto.Acquire().setdata(1, EmuTimer.get_current_time())); setvector_param = 1; EmuTimer.emu_timer timer = EmuTimer.timer_alloc_common(EmuTimer.TIME_ACT.setvector, true); EmuTimer.timer_adjust_periodic(timer, Attotime.ATTOTIME_ZERO, Attotime.ATTOTIME_NEVER); } else { - Cpuint.lvec.Add(new vec(2, EmuTimer.get_current_time())); + //Cpuint.lvec.Add(new vec(2, EmuTimer.get_current_time())); + Cpuint.lvec.Add(ObjectPoolAuto.Acquire().setdata(2, EmuTimer.get_current_time())); setvector_param = 2; EmuTimer.emu_timer timer = EmuTimer.timer_alloc_common(EmuTimer.TIME_ACT.setvector, true); EmuTimer.timer_adjust_periodic(timer, Attotime.ATTOTIME_ZERO, Attotime.ATTOTIME_NEVER); diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/sound/Iremga20.cs b/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/sound/Iremga20.cs index 748d1cd1..665d8b7c 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/sound/Iremga20.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Mame.Core/sound/Iremga20.cs @@ -23,54 +23,58 @@ namespace MAME.Core }; public static IremGA20_chip_def chip; public static byte[] iremrom; + + + static int[] update_rate = new int[4], update_pos = new int[4], update_frac = new int[4], update_end = new int[4], update_vol = new int[4], update_play = new int[4]; + public static void iremga20_update(int offset, int length) { - int[] rate = new int[4], pos = new int[4], frac = new int[4], end = new int[4], vol = new int[4], play = new int[4]; + //int[] rate = new int[4], pos = new int[4], frac = new int[4], end = new int[4], vol = new int[4], play = new int[4]; int i, sampleout; for (i = 0; i < 4; i++) { - rate[i] = chip.channel[i].rate; - pos[i] = chip.channel[i].pos; - frac[i] = chip.channel[i].frac; - end[i] = chip.channel[i].end - 0x20; - vol[i] = chip.channel[i].volume; - play[i] = chip.channel[i].play; + update_rate[i] = chip.channel[i].rate; + update_pos[i] = chip.channel[i].pos; + update_frac[i] = chip.channel[i].frac; + update_end[i] = chip.channel[i].end - 0x20; + update_vol[i] = chip.channel[i].volume; + update_play[i] = chip.channel[i].play; } i = length; for (i = 0; i < length; i++) { sampleout = 0; - if (play[0] != 0) + if (update_play[0] != 0) { - sampleout += (iremrom[pos[0]] - 0x80) * vol[0]; - frac[0] += rate[0]; - pos[0] += frac[0] >> 24; - frac[0] &= 0xffffff; - play[0] = pos[0] < end[0] ? 1 : 0; + sampleout += (iremrom[update_pos[0]] - 0x80) * update_vol[0]; + update_frac[0] += update_rate[0]; + update_pos[0] += update_frac[0] >> 24; + update_frac[0] &= 0xffffff; + update_play[0] = update_pos[0] < update_end[0] ? 1 : 0; } - if (play[1] != 0) + if (update_play[1] != 0) { - sampleout += (iremrom[pos[1]] - 0x80) * vol[1]; - frac[1] += rate[1]; - pos[1] += frac[1] >> 24; - frac[1] &= 0xffffff; - play[1] = pos[1] < end[1] ? 1 : 0; + sampleout += (iremrom[update_pos[1]] - 0x80) * update_vol[1]; + update_frac[1] += update_rate[1]; + update_pos[1] += update_frac[1] >> 24; + update_frac[1] &= 0xffffff; + update_play[1] = update_pos[1] < update_end[1] ? 1 : 0; } - if (play[2] != 0) + if (update_play[2] != 0) { - sampleout += (iremrom[pos[2]] - 0x80) * vol[2]; - frac[2] += rate[2]; - pos[2] += frac[2] >> 24; - frac[2] &= 0xffffff; - play[2] = pos[2] < end[2] ? 1 : 0; + sampleout += (iremrom[update_pos[2]] - 0x80) * update_vol[2]; + update_frac[2] += update_rate[2]; + update_pos[2] += update_frac[2] >> 24; + update_frac[2] &= 0xffffff; + update_play[2] = update_pos[2] < update_end[2] ? 1 : 0; } - if (play[3] != 0) + if (update_play[3] != 0) { - sampleout += (iremrom[pos[3]] - 0x80) * vol[3]; - frac[3] += rate[3]; - pos[3] += frac[3] >> 24; - frac[3] &= 0xffffff; - play[3] = pos[3] < end[3] ? 1 : 0; + sampleout += (iremrom[update_pos[3]] - 0x80) * update_vol[3]; + update_frac[3] += update_rate[3]; + update_pos[3] += update_frac[3] >> 24; + update_frac[3] &= 0xffffff; + update_play[3] = update_pos[3] < update_end[3] ? 1 : 0; } sampleout >>= 2; Sound.iremga20stream.streamoutput_Ptrs[0][offset + i] = sampleout; @@ -78,9 +82,9 @@ namespace MAME.Core } for (i = 0; i < 4; i++) { - chip.channel[i].pos = pos[i]; - chip.channel[i].frac = frac[i]; - chip.channel[i].play = play[i]; + chip.channel[i].pos = update_pos[i]; + chip.channel[i].frac = update_frac[i]; + chip.channel[i].play = update_play[i]; } } public static void irem_ga20_w(int offset, ushort data)