Skip to content

Commit

Permalink
Gambatte: Merge improvements from gifvex(mcmaeve)
Browse files Browse the repository at this point in the history
Restores Bios support and loading GB games into GBC
Accuracy imrpovements
  • Loading branch information
alyosha-tas committed Jan 15, 2018
1 parent c6bdae9 commit e5ded9b
Show file tree
Hide file tree
Showing 57 changed files with 7,492 additions and 7,244 deletions.
19 changes: 19 additions & 0 deletions BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ public Gameboy(CoreComm comm, GameInfo game, byte[] file, object settings, objec
throw new InvalidOperationException("gambatte_load() returned non-zero (is this not a gb or gbc rom?)");
}

if ((flags & LibGambatte.LoadFlags.FORCE_DMG) == LibGambatte.LoadFlags.FORCE_DMG)
{
byte[] Bios = comm.CoreFileProvider.GetFirmware("GB", "World", false, "BIOS Not Found, Cannot Load");

if (LibGambatte.gambatte_loaddmgbios(GambatteState, Bios) != 0)
{
throw new InvalidOperationException("gambatte_loaddmgbios() returned non-zero (bios error)");
}
}
else
{
byte[] Bios = comm.CoreFileProvider.GetFirmware("GBC", "World", false, "BIOS Not Found, Cannot Load");

if (LibGambatte.gambatte_loadgbcbios(GambatteState, Bios) != 0)
{
throw new InvalidOperationException("gambatte_loadgbcbios() returned non-zero (bios error)");
}
}

// set real default colors (before anyone mucks with them at all)
PutSettings((GambatteSettings)settings ?? new GambatteSettings());

Expand Down
18 changes: 18 additions & 0 deletions BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ public enum CDLog_Flags : int
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int gambatte_load(IntPtr core, byte[] romdata, uint length, long now, LoadFlags flags);

/// <summary>
/// Load GB BIOS image.
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="biosdata">the bios data, can be disposed of once this function returns</param>
/// <returns>0 on success, negative value on failure.</returns>
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int gambatte_loaddmgbios(IntPtr core, byte[] biosdata);

/// <summary>
/// Load GBC BIOS image.
/// </summary>
/// <param name="core">opaque state pointer</param>
/// <param name="biosdata">the bios data, can be disposed of once this function returns</param>
/// <returns>0 on success, negative value on failure.</returns>
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int gambatte_loadgbcbios(IntPtr core, byte[] biosdata);

/// <summary>
/// Emulates until at least 'samples' stereo sound samples are produced in the supplied buffer,
/// or until a video frame has been drawn.
Expand Down
11 changes: 9 additions & 2 deletions libgambatte/include/gambatte.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class GB {
enum LoadFlag {
FORCE_DMG = 1, /**< Treat the ROM as not having CGB support regardless of what its header advertises. */
GBA_CGB = 2, /**< Use GBA intial CPU register values when in CGB mode. */
MULTICART_COMPAT = 4 /**< Use heuristics to detect and support some multicart MBCs disguised as MBC1. */
MULTICART_COMPAT = 4, /**< Use heuristics to detect and support some multicart MBCs disguised as MBC1. */
TRUE_COLOR = 8 /**< Use GBP color conversion instead of GBC-screen approximation */
};

/** Load ROM image.
Expand All @@ -62,6 +63,9 @@ class GB {
*/
int load(const char *romfiledata, unsigned romfilelength, std::uint32_t now, unsigned flags = 0);

int loadGBCBios(const char* biosfiledata);
int loadDMGBios(const char* biosfiledata);

/** Emulates until at least 'samples' stereo sound samples are produced in the supplied buffer,
* or until a video frame has been drawn.
*
Expand Down Expand Up @@ -109,7 +113,7 @@ class GB {
void setTraceCallback(void (*callback)(void *));
void setScanlineCallback(void (*callback)(), int sl);
void setRTCCallback(std::uint32_t (*callback)());
void setLinkCallback(void (*callback)());
void setLinkCallback(void(*callback)());

/** Returns true if the currently loaded ROM image is treated as having CGB support. */
bool isCgb() const;
Expand All @@ -135,6 +139,9 @@ class GB {

void GetRegs(int *dest);

void SetInterruptAddresses(int *addrs, int numAddrs);
int GetHitInterruptAddress();

template<bool isReader>void SyncState(NewState *ns);

private:
Expand Down
451 changes: 221 additions & 230 deletions libgambatte/libgambatte.vcxproj

Large diffs are not rendered by default.

Loading

0 comments on commit e5ded9b

Please sign in to comment.