-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* basics for sameboy * lol * bleh * lol * push this in * push this in * settings, and also update sameboy bootroms * bleh * build linux * remove some debugging shiz * fix the order of this * debug stuff also do gpu palettes right * use new key mask API * push shit in * bleh * add in replacement impl for joypad, use until opposing directions are allowed upstream * update * finally get this working without needing GB_INTERNAL * hook up acc controls * oops * oops x2 * oh right this doesn't use this * finish this up * also mark this as released * cleanups * Nitpicks Co-authored-by: YoshiRulz <OSSYoshiRulz@gmail.com>
- Loading branch information
1 parent
69d51ab
commit 2348e28
Showing
30 changed files
with
1,707 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/LibSameBoy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy; | ||
|
||
namespace BizHawk.Emulation.Cores.Nintendo.Sameboy | ||
{ | ||
/// <summary> | ||
/// static bindings into libsameboy.dll | ||
/// </summary> | ||
public static class LibSameboy | ||
{ | ||
[Flags] | ||
public enum Buttons : uint | ||
{ | ||
RIGHT = 0x01, | ||
LEFT = 0x02, | ||
UP = 0x04, | ||
DOWN = 0x08, | ||
A = 0x10, | ||
B = 0x20, | ||
SELECT = 0x40, | ||
START = 0x80, | ||
} | ||
|
||
// mirror of GB_direct_access_t | ||
public enum MemoryAreas : uint | ||
{ | ||
ROM, | ||
RAM, | ||
CART_RAM, | ||
VRAM, | ||
HRAM, | ||
IO, | ||
BOOTROM, | ||
OAM, | ||
BGP, | ||
OBP, | ||
IE, | ||
BGPRGB, | ||
OBPRGB, | ||
} | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern IntPtr sameboy_create(byte[] romdata, int romlength, byte[] biosdata, int bioslength, Sameboy.SameboySyncSettings.GBModel model, bool realtime); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_destroy(IntPtr core); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
public delegate void SampleCallback(IntPtr core, IntPtr sample); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setsamplecallback(IntPtr core, SampleCallback callback); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
public delegate void InputCallback(); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setinputcallback(IntPtr core, InputCallback callback); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_frameadvance(IntPtr core, Buttons buttons, ushort x, ushort y, int[] videobuf, bool render, bool border); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_reset(IntPtr core); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern bool sameboy_iscgbdmg(IntPtr core); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_savesram(IntPtr core, byte[] dest); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_loadsram(IntPtr core, byte[] data, int len); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern int sameboy_sramlen(IntPtr core); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_savestate(IntPtr core, byte[] data); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern bool sameboy_loadstate(IntPtr core, byte[] data, int len); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern int sameboy_statelen(IntPtr core); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern bool sameboy_getmemoryarea(IntPtr core, MemoryAreas which, ref IntPtr data, ref int length); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern byte sameboy_cpuread(IntPtr core, ushort addr); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_cpuwrite(IntPtr core, ushort addr, byte val); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern long sameboy_getcyclecount(IntPtr core); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setcyclecount(IntPtr core, long newcc); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
public delegate void TraceCallback(ushort pc); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_settracecallback(IntPtr core, TraceCallback callback); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_getregs(IntPtr core, int[] buf); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setreg(IntPtr core, int which, int value); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
public delegate void MemoryCallback(ushort address); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setmemorycallback(IntPtr core, int which, MemoryCallback callback); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setprintercallback(IntPtr core, PrinterCallback callback); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setscanlinecallback(IntPtr core, ScanlineCallback callback, int sl); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setpalette(IntPtr core, Sameboy.SameboySettings.GBPaletteType which); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setcolorcorrection(IntPtr core, Sameboy.SameboySettings.ColorCorrectionMode which); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setlighttemperature(IntPtr core, int temperature); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_sethighpassfilter(IntPtr core, Sameboy.SameboySettings.HighPassFilterMode which); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setinterferencevolume(IntPtr core, int volume); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setrtcdivisoroffset(IntPtr core, int offset); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setbgwinenabled(IntPtr core, bool enabled); | ||
|
||
[DllImport("libsameboy", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void sameboy_setobjenabled(IntPtr core, bool enabled); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IDebuggable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using BizHawk.Emulation.Common; | ||
|
||
namespace BizHawk.Emulation.Cores.Nintendo.Sameboy | ||
{ | ||
public partial class Sameboy : IDebuggable | ||
{ | ||
public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters() | ||
{ | ||
int[] data = new int[10]; | ||
LibSameboy.sameboy_getregs(SameboyState, data); | ||
|
||
return new Dictionary<string, RegisterValue> | ||
{ | ||
["PC"] = (ushort)(data[0] & 0xFFFF), | ||
["A"] = (byte)(data[1] & 0xFF), | ||
["F"] = (byte)(data[2] & 0xFF), | ||
["B"] = (byte)(data[3] & 0xFF), | ||
["C"] = (byte)(data[4] & 0xFF), | ||
["D"] = (byte)(data[5] & 0xFF), | ||
["E"] = (byte)(data[6] & 0xFF), | ||
["H"] = (byte)(data[7] & 0xFF), | ||
["L"] = (byte)(data[8] & 0xFF), | ||
["SP"] = (ushort)(data[9] & 0xFFFF), | ||
}; | ||
} | ||
|
||
public void SetCpuRegister(string register, int value) | ||
{ | ||
LibSameboy.sameboy_setreg(SameboyState, register.ToUpper() switch | ||
{ | ||
"PC" => 0, | ||
"A" => 1, | ||
"F" => 2, | ||
"B" => 3, | ||
"C" => 4, | ||
"D" => 5, | ||
"E" => 6, | ||
"H" => 7, | ||
"L" => 8, | ||
"SP" => 9, | ||
_ => throw new InvalidOperationException("Invalid Register?"), | ||
}, | ||
value); | ||
} | ||
|
||
public bool CanStep(StepType type) => false; | ||
|
||
[FeatureNotImplemented] | ||
public void Step(StepType type) => throw new NotImplementedException(); | ||
|
||
public long TotalExecutedCycles => CycleCount; | ||
|
||
private const string systemBusScope = "System Bus"; | ||
|
||
private readonly MemoryCallbackSystem _memorycallbacks = new MemoryCallbackSystem(new[] { systemBusScope }); | ||
|
||
public IMemoryCallbackSystem MemoryCallbacks => _memorycallbacks; | ||
|
||
private LibSameboy.MemoryCallback _readcb; | ||
private LibSameboy.MemoryCallback _writecb; | ||
private LibSameboy.MemoryCallback _execcb; | ||
|
||
private void InitMemoryCallbacks() | ||
{ | ||
LibSameboy.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Func<bool> getHasCBOfType) | ||
{ | ||
var rawFlags = (uint)flags; | ||
return (address) => | ||
{ | ||
if (getHasCBOfType()) | ||
{ | ||
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, systemBusScope); | ||
} | ||
}; | ||
} | ||
|
||
_readcb = CreateCallback(MemoryCallbackFlags.AccessRead, () => MemoryCallbacks.HasReads); | ||
_writecb = CreateCallback(MemoryCallbackFlags.AccessWrite, () => MemoryCallbacks.HasWrites); | ||
_execcb = CreateCallback(MemoryCallbackFlags.AccessExecute, () => MemoryCallbacks.HasExecutes); | ||
|
||
_memorycallbacks.ActiveChanged += SetMemoryCallbacks; | ||
} | ||
|
||
private void SetMemoryCallbacks() | ||
{ | ||
LibSameboy.sameboy_setmemorycallback(SameboyState, 0, MemoryCallbacks.HasReads ? _readcb : null); | ||
LibSameboy.sameboy_setmemorycallback(SameboyState, 1, MemoryCallbacks.HasWrites ? _writecb : null); | ||
LibSameboy.sameboy_setmemorycallback(SameboyState, 2, MemoryCallbacks.HasExecutes ? _execcb : null); | ||
} | ||
} | ||
} |
Oops, something went wrong.