[Gambatte] upstream cleanup, use upstream for board name and other rom details, remove now unused MULTICART_COMPAT flag

This commit is contained in:
CasualPokePlayer 2022-04-02 23:16:39 -07:00
parent 37a7c69107
commit c33d2cfbe5
6 changed files with 48 additions and 111 deletions

Binary file not shown.

Binary file not shown.

View File

@ -120,11 +120,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
[DefaultValue(ConsoleModeType.Auto)]
public ConsoleModeType ConsoleMode { get; set; }
[DisplayName("Multicart Compatibility")]
[Description("Use special compatibility hacks for certain multicart games. Relevant only for specific multicarts.")]
[DefaultValue(false)]
public bool MulticartCompat { get; set; }
[DisplayName("Cart Bus Pull-Up Time")]
[Description("Time it takes for the cart bus to pull-up to 0xFF in CPU cycles. Used to account for differences in pull-up times between carts/consoles.")]
[DefaultValue(8)]

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
@ -29,9 +30,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
ser.Register<ITraceable>(Tracer);
InitMemoryCallbacks();
ThrowExceptionForBadRom(file);
BoardName = MapperName(file);
DeterministicEmulation = deterministic;
GambatteState = LibGambatte.gambatte_create();
@ -72,11 +70,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
IsSgb = true;
}
if (_syncSettings.MulticartCompat)
{
flags |= LibGambatte.LoadFlags.MULTICART_COMPAT;
}
IsCgb = (flags & LibGambatte.LoadFlags.CGB_MODE) == LibGambatte.LoadFlags.CGB_MODE;
if (_syncSettings.EnableBIOS)
{
@ -95,6 +88,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
}
else
{
if (DeterministicEmulation) // throw a warning if a movie is being recorded with the bios disabled
{
comm.ShowMessage("Detected disabled BIOS during movie recording. It is recommended to use a BIOS for movie recording. Change Sync Settings to run with a BIOS.");
@ -121,7 +115,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
}
// set real default colors (before anyone mucks with them at all)
PutSettings((GambatteSettings)settings ?? new GambatteSettings());
PutSettings(settings ?? new GambatteSettings());
InitSound();
@ -131,16 +125,35 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
InputCallback = new LibGambatte.InputGetter(ControllerCallback);
LibGambatte.gambatte_setinputgetter(GambatteState, InputCallback);
LibGambatte.gambatte_setinputgetter(GambatteState, InputCallback, IntPtr.Zero);
InitMemoryDomains();
RomDetails = $"{game.Name}\r\n{SHA1Checksum.ComputePrefixedHex(file)}\r\n{MD5Checksum.ComputePrefixedHex(file)}\r\n";
byte[] mbcBuf = new byte[32];
uint rambanks = 0;
uint rombanks = 0;
uint crc = 0;
uint headerchecksumok = 0;
LibGambatte.gambatte_pakinfo(GambatteState, mbcBuf, ref rambanks, ref rombanks, ref crc, ref headerchecksumok);
byte[] buff = new byte[32];
LibGambatte.gambatte_romtitle(GambatteState, buff);
string romname = System.Text.Encoding.ASCII.GetString(buff);
Console.WriteLine("Core reported rom name: {0}", romname);
byte[] romNameBuf = new byte[32];
LibGambatte.gambatte_romtitle(GambatteState, romNameBuf);
string romname = Encoding.ASCII.GetString(romNameBuf);
RomDetails = $"{game.Name}\r\n{SHA1Checksum.ComputePrefixedHex(file)}\r\n{MD5Checksum.ComputePrefixedHex(file)}\r\n\r\n";
BoardName = Encoding.ASCII.GetString(mbcBuf);
RomDetails += $"Core reported Header Name: {romname}\r\n";
RomDetails += $"Core reported RAM Banks: {rambanks}\r\n";
RomDetails += $"Core reported ROM Banks: {rombanks}\r\n";
RomDetails += $"Core reported CRC32: {crc:X8}\r\n";
RomDetails += $"Core reported Header Checksum Status: {(headerchecksumok != 0 ? "OK" : "BAD")}\r\n";
if (_syncSettings.EnableBIOS && headerchecksumok == 0)
{
comm.ShowMessage("Core reports the header checksum is bad. This ROM will not boot with the official BIOS.\n" +
"Disable BIOS in sync settings to boot this game");
}
if (!_syncSettings.EnableBIOS && IsCgb && IsCGBDMGMode()) // without a bios, we need to set the palette for cgbdmg ourselves
{
@ -226,7 +239,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
/// <summary>
/// number of reset stall ticks
/// </summary>
private uint ResetStallTicks { get; set; } = 0;
private uint ResetStallTicks { get; }
/// <summary>
/// keep a copy of the input callback delegate so it doesn't get GCed
@ -291,7 +304,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
return ret.MakeImmutable();
}
private LibGambatte.Buttons ControllerCallback()
private LibGambatte.Buttons ControllerCallback(IntPtr p)
{
InputCallbacks.Call();
IsLagFrame = false;
@ -414,89 +427,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
endofframecallback?.Invoke(LibGambatte.gambatte_cpuread(GambatteState, 0xff40));
}
private static string MapperName(byte[] romdata)
{
return (romdata[0x147]) switch
{
0x00 => "Plain ROM",
0x01 => "MBC1 ROM",
0x02 => "MBC1 ROM+RAM",
0x03 => "MBC1 ROM+RAM+BATTERY",
0x05 => "MBC2 ROM",
0x06 => "MBC2 ROM+BATTERY",
0x08 => "Plain ROM+RAM",
0x09 => "Plain ROM+RAM+BATTERY",
0x0B => "MMM01 ROM", // fixme: mmm01's proper header is at the end of the rom!
0x0C => "MMM01 ROM+RAM",
0x0D => "MMM01 ROM+BATTERY",
0x0F => "MBC3 ROM+TIMER+BATTERY",
0x10 => "MBC3 ROM+TIMER+RAM+BATTERY",
0x11 => "MBC3 ROM",
0x12 => "MBC3 ROM+RAM",
0x13 => "MBC3 ROM+RAM+BATTERY",
0x19 => "MBC5 ROM",
0x1A => "MBC5 ROM+RAM",
0x1B => "MBC5 ROM+RAM+BATTERY",
0x1C => "MBC5 ROM+RUMBLE",
0x1D => "MBC5 ROM+RUMBLE+RAM",
0x1E => "MBC5 ROM+RUMBLE+RAM+BATTERY",
0xFC => "Pocket Camera ROM+RAM+BATTERY",
0xFE => "HuC3 ROM+RAM+BATTERY",
0xFF => "HuC1 ROM+RAM+BATTERY",
_ => "UNKNOWN",
};
}
/// <summary>
/// throw exception with intelligible message on some kinds of bad rom
/// </summary>
private static void ThrowExceptionForBadRom(byte[] romdata)
{
if (romdata.Length < 0x148)
{
throw new ArgumentException("ROM is far too small to be a valid GB\\GBC rom!");
}
switch (romdata[0x147])
{
case 0x00: break;
case 0x01: break;
case 0x02: break;
case 0x03: break;
case 0x05: break;
case 0x06: break;
case 0x08: break;
case 0x09: break;
case 0x0B: break;
case 0x0C: break;
case 0x0D: break;
case 0x0F: break;
case 0x10: break;
case 0x11: break;
case 0x12: break;
case 0x13: break;
case 0x19: break;
case 0x1A: break;
case 0x1B: break;
case 0x1C: break; // rumble
case 0x1D: break; // rumble
case 0x1E: break; // rumble
case 0x20: throw new UnsupportedGameException("\"MBC6\" Mapper not supported!");
case 0x22: throw new UnsupportedGameException("\"MBC7\" Mapper not supported!");
case 0xFC: break;
case 0xFD: throw new UnsupportedGameException("\"Bandai TAMA5\" Mapper not supported!");
case 0xFE: break;
case 0xFF: break;
default: throw new UnsupportedGameException($"Unknown mapper: {romdata[0x147]:x2}");
}
}
private static int[] ColorsFromTitleHash(byte[] romdata)
{
int titleHash = 0;

View File

@ -25,8 +25,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
CGB_MODE = 1,
/// <summary>Use GBA intial CPU register values when in CGB mode.</summary>
GBA_FLAG = 2,
/// <summary>Use heuristics to detect and support some multicart MBCs disguised as MBC1.</summary>
MULTICART_COMPAT = 4,
/// <summary>Previously a multicart heuristic enable. Reserved for future use.</summary>
RESERVED_FLAG = 4,
/// <summary>Treat the ROM as having SGB support regardless of what its header advertises.</summary>
SGB_MODE = 8,
/// <summary>Prevent implicit saveSavedata calls for the ROM.</summary>
@ -43,7 +43,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
[Flags]
public enum CDLog_Flags : int
{
ExecFirst = 1,
ExecOpcode = 1,
ExecOperand = 2,
Data = 4
}
@ -157,14 +157,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
/// </summary>
/// <returns>bitfield combination of pressed buttons</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate Buttons InputGetter();
public delegate Buttons InputGetter(IntPtr p);
/// <summary>
/// Sets the callback used for getting input state.
/// </summary>
/// <param name="core">opaque state pointer</param>
[DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)]
public static extern void gambatte_setinputgetter(IntPtr core, InputGetter getinput);
public static extern void gambatte_setinputgetter(IntPtr core, InputGetter getinput, IntPtr p);
/// <summary>
/// Gets which SGB controller is in use, 0 indexed.
@ -394,6 +394,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
[DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)]
public static extern void gambatte_romtitle(IntPtr core, byte[] data);
/// <summary>
/// Pakinfo of currently loaded ROM image.
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="mbc">enough room for 25 ascii chars plus terminator</param>
/// <param name="rambanks">number of rambanks</param>
/// <param name="rombanks">number of rombanks</param>
/// <param name="crc">core reported crc32</param>
/// <param name="headerchecksumok">core reported header checksum status</param>
[DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)]
public static extern void gambatte_pakinfo(IntPtr core, byte[] mbc, ref uint rambanks, ref uint rombanks, ref uint crc, ref uint headerchecksumok);
/// <summary>
/// memory areas that gambatte_getmemoryarea() can return
/// </summary>

@ -1 +1 @@
Subproject commit 3fd41666664ba779116373425b3832fb1994e59e
Subproject commit 08e3ed73f45c2902157b2eba3030fcf007e7947c