From fef3b526b6c89cac771e173abda878e1dd1e6a27 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 21 Mar 2025 20:24:12 +1000 Subject: [PATCH] Simplify rom padding step in `PCEngine.Init` --- .../Consoles/PC Engine/PCEngine.cs | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs index e72eda3dd7..fdf9be0760 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using BizHawk.Common; +using BizHawk.Common.CollectionExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Components; using BizHawk.Emulation.Cores.Components.H6280; @@ -202,35 +203,29 @@ namespace BizHawk.Emulation.Cores.PCEngine Cpu.ThinkAction = cycles => { SCSI.Think(); ADPCM.Think(cycles); }; } - if (rom.Length == 0x60000) - { - // 384k roms require special loading code. Why ;_; - // In memory, 384k roms look like [1st 256k][Then full 384k] - RomData = new byte[0xA0000]; - var origRom = rom; - for (int i = 0; i < 0x40000; i++) - RomData[i] = origRom[i]; - for (int i = 0; i < 0x60000; i++) - RomData[i + 0x40000] = origRom[i]; - RomLength = RomData.Length; - } - else if (rom.Length > 1024 * 1024) + if (rom.Length > 1024 * 1024) { // If the rom is bigger than 1 megabyte, switch to Street Fighter 2 mapper Cpu.ReadMemory21 = ReadMemorySF2; Cpu.WriteMemory21 = WriteMemorySF2; RomData = rom; - RomLength = RomData.Length; // user request: current value of the SF2MapperLatch on the tracelogger Cpu.Logger = s => Tracer.Put(new(disassembly: $"{SF2MapperLatch:X1}:{s.Disassembly}", registerInfo: string.Empty)); } + else if (rom.Length is 0x60000) + { + // 384k roms require special loading code. Why ;_; + // In memory, 384k roms look like [1st 256k][Then full 384k] + RomData = new byte[0xA0000]; + ((ReadOnlySpan) rom.AsSpan(start: 0, length: 0x40000)).ConcatArray(rom, dest: RomData); + } else { // normal rom. RomData = rom; - RomLength = RomData.Length; } + RomLength = RomData.Length; if (game["BRAM"] || Type == NecSystemType.TurboCD) {