Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gameboy memory callback values #3904

Draft
wants to merge 40 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a1b70e2
Added debug value callbacks for sameboy and gambette.
roydmerkel Apr 8, 2024
2bc81d0
temporarily changed gambette version to temporary checkout with value…
roydmerkel Apr 8, 2024
aa7700e
Temporarily committed sameboy and gambette dlls.
roydmerkel Apr 8, 2024
66af7b0
Merge branch 'add-gameboy-memory-callback-values' of https://github.c…
roydmerkel Apr 13, 2024
1157d6c
Merge pull request #2 from roydmerkel/master
roydmerkel Apr 13, 2024
7fd697f
Made sure newest version of sameboy was being used.
roydmerkel Apr 13, 2024
06a3b38
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Apr 13, 2024
1751407
Updated libsameboy module.
roydmerkel Apr 13, 2024
84f4a5c
Merge branch 'master' into add-gameboy-memory-callback-values
roydmerkel Apr 13, 2024
bf64dd0
Fixed bsnes build
roydmerkel Apr 13, 2024
65a6183
Merge pull request #3 from roydmerkel/fix-bsnes-build
roydmerkel Apr 13, 2024
626db79
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Apr 14, 2024
b4c8d61
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Apr 20, 2024
130f0f7
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Apr 21, 2024
bf75ab8
Added methods of getting mapper and bank for bsnes sgb and bsnes 115+…
roydmerkel Apr 23, 2024
ac61c26
Updated dlls.
roydmerkel Apr 23, 2024
8c523f1
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Apr 25, 2024
8d721de
Performance optimizations by moving bank register pulls to separate f…
roydmerkel Apr 26, 2024
dd0d821
Merge branch 'add-gameboy-memory-callback-values' of https://github.c…
roydmerkel Apr 26, 2024
6eda8c8
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Apr 26, 2024
89a40a9
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Apr 27, 2024
dab869f
Updated bsnes dll.
roydmerkel Apr 28, 2024
13aa266
reverted removal of Gambette bank registers from registers call, and …
roydmerkel Apr 28, 2024
6566b47
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Apr 28, 2024
58e309d
updated to upstream master for libsameboy.
roydmerkel Apr 28, 2024
11232d5
Merge branch 'add-gameboy-memory-callback-values' of https://github.c…
roydmerkel Apr 28, 2024
22ad5e5
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Apr 28, 2024
0213628
Review comment: move bank registers back into registers list (was ori…
roydmerkel Apr 29, 2024
e489d1b
Review comment: reverted bsnes changes.
roydmerkel Apr 29, 2024
ca88b56
Updated gambette and sameboy .dll files after syncing sameboy against…
roydmerkel Apr 29, 2024
566c397
Merge branch 'add-gameboy-memory-callback-values' of https://github.c…
roydmerkel Jun 19, 2024
6311d2d
Merge pull request #4 from roydmerkel/master
roydmerkel Jun 19, 2024
c670022
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Jun 19, 2024
317e915
Rolled back libsnes changes since libsnes does not support memory or …
roydmerkel Jun 19, 2024
1af6619
Updated libsameboy to 0.16.6
roydmerkel Jun 19, 2024
170af1e
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Jun 21, 2024
f38aef5
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Jun 21, 2024
4fcb6b6
Rebuilt gambatte using ucrt to fix seg faults in my rig and rebuild l…
roydmerkel Jun 21, 2024
9e824f8
Reverted Memory Domain comparison change as per YoshiRulz.
roydmerkel Dec 1, 2024
5487b83
Merge branch 'TASEmulators:master' into add-gameboy-memory-callback-v…
roydmerkel Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
url = https://github.com/TASEmulators/mednafen.git
[submodule "submodules/gambatte"]
path = submodules/gambatte
url = https://github.com/pokemon-speedrunning/gambatte-core.git
url = https://github.com/roydmerkel/gambatte-core.git
[submodule "submodules/libdarm"]
path = submodules/libdarm
url = https://github.com/jbremer/darm.git
Expand Down
Binary file modified Assets/dll/libgambatte.dll
Binary file not shown.
Binary file modified Assets/dll/libsameboy.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,25 @@ internal void ConnectMemoryCallbackSystem(MemoryCallbackSystem mcs, int which)
private LibGambatte.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Func<bool> getHasCBOfType, string which = "")
{
var rawFlags = (uint)flags;
return (address, cycleOffset) =>
return (address, cycleOffset, data) =>
{
callbackCycleCount = _cycleCount + cycleOffset;
if (getHasCBOfType())
{
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "System Bus");
MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "System Bus");
var bank = LibGambatte.gambatte_getaddrbank(GambatteState, (ushort)address);
switch (address)
{
// usually rom bank 0 for most mbcs, some mbcs might have this at a different rom bank
case < 0x4000u:
address += (uint)(bank * 0x4000);
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "ROM");
MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "ROM");
break;
// rom bank x
case < 0x8000u:
address += (uint)(bank * 0x4000);
address -= 0x4000u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "ROM");
MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "ROM");
break;
// vram (may be banked on CGB in CGB enhanced mode)
case < 0xA000u:
Expand All @@ -107,19 +107,19 @@ private LibGambatte.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Fun
address += (uint)(bank * 0x2000);
}
address -= 0x8000u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "VRAM");
MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "VRAM");
break;
}
// sram (may be banked)
case < 0xC000u:
address += (uint)(bank * 0x2000);
address -= 0xA000u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "SRAM");
MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "SRAM");
break;
// wram bank 0
case < 0xD000u:
address -= 0xC000u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "WRAM");
MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "WRAM");
break;
// wram bank x (always one for dmg/cgb in dmg mode)
case < 0xE000u:
Expand All @@ -129,7 +129,7 @@ private LibGambatte.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Fun
address += (uint)(bank * 0x1000);
}
address -= 0xD000u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "WRAM");
MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "WRAM");
break;
}
// echo ram
Expand All @@ -139,7 +139,7 @@ private LibGambatte.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Fun
// oam
case < 0xFEA0u:
address -= 0xFE00u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "OAM");
MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "OAM");
break;
// "extra" oam
case < 0xFF00u:
Expand All @@ -152,7 +152,7 @@ private LibGambatte.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Fun
// hram
case < 0xFFFF:
address -= 0xFF80u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, which + "HRAM");
MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, which + "HRAM");
break;
// ie reg
case 0xFFFF:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public enum Buttons: uint
/// </summary>
/// <param name="address">the address which the cpu is read\writing</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void MemoryCallback(uint address, ulong cycleOffset);
public delegate void MemoryCallback(uint address, ulong cycleOffset, uint data);

/// <summary>
/// type of the CDLogger callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ public struct GBSInfo
[BizImport(cc)]
public abstract void sameboy_setreg(IntPtr core, int which, int value);

[BizImport(cc)]
public abstract void sameboy_getbankregs(IntPtr core, int[] buf);

[UnmanagedFunctionPointer(cc)]
public delegate void MemoryCallback(ushort address);
public delegate void MemoryCallback(ushort address, byte data);

[BizImport(cc)]
public abstract void sameboy_setmemorycallback(IntPtr core, int which, MemoryCallback callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
int[] data = new int[10];
LibSameboy.sameboy_getregs(SameboyState, data);

int[] banks = new int[5];
LibSameboy.sameboy_getbankregs(SameboyState, banks);

return new Dictionary<string, RegisterValue>
{
["PC"] = (ushort)(data[0] & 0xFFFF),
Expand All @@ -23,6 +26,12 @@ public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
["H"] = (byte)(data[7] & 0xFF),
["L"] = (byte)(data[8] & 0xFF),
["SP"] = (ushort)(data[9] & 0xFFFF),
// banks
["ROM0 BANK"] = (ushort)(banks[0] & 0xFFFF),
["ROMX BANK"] = (ushort)(banks[1] & 0xFFFF),
["VRAM BANK"] = (ushort)(banks[4] & 0xFFFF),
["SRAM BANK"] = (ushort)(banks[3] & 0xFFFF),
["WRAM BANK"] = (ushort)(banks[2] & 0xFFFF),
};
}

Expand Down Expand Up @@ -67,11 +76,11 @@ private void InitMemoryCallbacks()
LibSameboy.MemoryCallback CreateCallback(MemoryCallbackFlags flags, Func<bool> getHasCBOfType)
{
var rawFlags = (uint)flags;
return (address) =>
return (address, data) =>
{
if (getHasCBOfType())
{
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, systemBusScope);
MemoryCallbacks.CallMemoryCallbacks(address, data, rawFlags, systemBusScope);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion submodules/gambatte
24 changes: 20 additions & 4 deletions submodules/sameboy/BizInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef uint64_t u64;
typedef void (*input_callback_t)(void);
typedef void (*rumble_callback_t)(u32);
typedef void (*trace_callback_t)(u16);
typedef void (*memory_callback_t)(u16);
typedef void (*memory_callback_t)(u16, u8);
typedef void (*printer_callback_t)(u32*, u8, u8, u8, u8);
typedef void (*scanline_callback_t)(u32);

Expand Down Expand Up @@ -105,13 +105,13 @@ static void RumbleCallbackRelay(GB_gameboy_t* gb, double rumble_amplitude)

static u8 ReadCallbackRelay(GB_gameboy_t* gb, u16 addr, u8 data)
{
((biz_t*)gb)->read_cb(addr);
((biz_t*)gb)->read_cb(addr, 0);
return data;
}

static bool WriteCallbackRelay(GB_gameboy_t* gb, u16 addr, u8 data)
{
((biz_t*)gb)->write_cb(addr);
((biz_t*)gb)->write_cb(addr, data);
return true;
}

Expand All @@ -124,7 +124,7 @@ static void ExecCallbackRelay(GB_gameboy_t* gb, u16 addr, u8 opcode)
}
if (biz->exec_cb)
{
biz->exec_cb(addr);
biz->exec_cb(addr, 0);
}
}

Expand Down Expand Up @@ -488,6 +488,22 @@ EXPORT void sameboy_setreg(biz_t* biz, u32 which, u32 value)
}
}

EXPORT void sameboy_getbankregs(biz_t* biz, u32* buf)
{
size_t size;
uint16_t bank;
GB_get_direct_access(&biz->gb, GB_DIRECT_ACCESS_ROM0, &size, &bank);
buf[0] = bank;
GB_get_direct_access(&biz->gb, GB_DIRECT_ACCESS_ROM, &size, &bank);
buf[1] = bank;
GB_get_direct_access(&biz->gb, GB_DIRECT_ACCESS_RAM, &size, &bank);
buf[2] = bank;
GB_get_direct_access(&biz->gb, GB_DIRECT_ACCESS_CART_RAM, &size, &bank);
buf[3] = bank;
GB_get_direct_access(&biz->gb, GB_DIRECT_ACCESS_VRAM, &size, &bank);
buf[4] = bank;
}

EXPORT void sameboy_setmemorycallback(biz_t* biz, u32 which, memory_callback_t callback)
{
switch (which)
Expand Down
2 changes: 1 addition & 1 deletion submodules/sameboy/libsameboy
Submodule libsameboy updated 78 files
+25 −6 AppleCommon/GBAudioClient.m
+1 −0 BootROMs/cgb_boot.asm
+48 −33 Cocoa/Document.m
+4 −4 Cocoa/Document.xib
+1 −1 Cocoa/GBApp.m
+1 −1 Cocoa/GBButtons.h
+1 −1 Cocoa/Info.plist
+12 −1 Core/apu.c
+3 −1 Core/apu.h
+3 −1 Core/gb.c
+2 −0 Core/gb.h
+5 −3 Core/save_state.c
+0 −15 HexFiend/HFHexTextView.h
+0 −13 HexFiend/HFHexTextView.m
+6 −0 HexFiend/HFLineCountingView.m
+6 −0 HexFiend/HFRepresenterTextView.m
+11 −1 LICENSE
+22 −15 Makefile
+1 −1 README.md
+15 −3 SDL/main.c
+2 −1 SDL/utils.c
+1 −0 Shaders/MonoLCD.fsh
+2 −0 Windows/limits.h
+5 −0 iOS/GBAboutController.m
+5 −0 iOS/GBBackgroundView.h
+89 −29 iOS/GBBackgroundView.m
+2 −0 iOS/GBHapticManager.h
+70 −20 iOS/GBHapticManager.m
+24 −9 iOS/GBHorizontalLayout.m
+41 −0 iOS/GBHub.h
+344 −0 iOS/GBHub.m
+8 −0 iOS/GBHubCell.h
+4 −0 iOS/GBHubCell.m
+7 −0 iOS/GBHubGameViewController.h
+315 −0 iOS/GBHubGameViewController.m
+6 −0 iOS/GBHubViewController.h
+393 −0 iOS/GBHubViewController.m
+9 −3 iOS/GBLayout.h
+69 −28 iOS/GBLayout.m
+171 −2 iOS/GBLoadROMTableViewController.m
+71 −2 iOS/GBMenuViewController.m
+5 −1 iOS/GBOptionViewController.m
+1 −0 iOS/GBROMManager.h
+1 −0 iOS/GBROMManager.m
+24 −0 iOS/GBSettingsViewController.h
+343 −27 iOS/GBSettingsViewController.m
+26 −0 iOS/GBTheme.h
+226 −0 iOS/GBTheme.m
+7 −0 iOS/GBThemePreviewController.h
+116 −0 iOS/GBThemePreviewController.m
+7 −0 iOS/GBThemesViewController.h
+104 −0 iOS/GBThemesViewController.m
+17 −9 iOS/GBVerticalLayout.m
+1 −1 iOS/GBViewController.h
+351 −81 iOS/GBViewController.m
+25 −0 iOS/GCExtendedGamepad+AllElements.h
+48 −0 iOS/GCExtendedGamepad+AllElements.m
+20 −1 iOS/Info.plist
+40 −0 iOS/LaunchScreen.storyboard
+6 −8 iOS/License.html
+5 −0 iOS/UILabel+TapLocation.h
+27 −0 iOS/UILabel+TapLocation.m
+ iOS/[email protected]
+ iOS/[email protected]
+ iOS/[email protected]
+ iOS/[email protected]
+ iOS/[email protected]
+ iOS/[email protected]
+4 −1 iOS/main.m
+ iOS/[email protected]
+ iOS/[email protected]
+ iOS/[email protected]
+ iOS/[email protected]
+ iOS/[email protected]
+ iOS/[email protected]
+3 −2 libretro/gitlab-ci.yml
+10 −0 libretro/libretro.c
+1 −1 version.mk